ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/UseTheForce/EAM_FF.cpp
(Generate patch)

Comparing:
trunk/OOPSE-3.0/src/UseTheForce/EAM_FF.cpp (file contents), Revision 1634 by gezelter, Fri Oct 22 21:21:02 2004 UTC vs.
branches/new_design/OOPSE-3.0/src/UseTheForce/EAM_FF.cpp (file contents), Revision 1683, Thu Oct 28 22:34:02 2004 UTC

# Line 42 | Line 42 | namespace EAM_NS{
42                     //  1  -> in MPI: tells nodes to stop listening
43    } atomStruct;
44  
45 <  int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile );
46 <  int parseEAM( atomStruct &info, char *eamPotFile, double **eam_rvals,
47 <                double **eam_rhovals, double **eam_Frhovals);
45 >  int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, string eamPotFile );
46 >  int parseEAM( atomStruct &info, string ffPath, string eamPotFile,
47 >                double **eam_rvals, double **eam_rhovals,
48 >                double **eam_Frhovals);
49   #ifdef IS_MPI
50    
51    MPI_Datatype mpiAtomStructType;
# Line 157 | Line 158 | EAM_FF::EAM_FF() {
158   // begins the actual forcefield stuff.  
159   //****************************************************************
160  
161 < EAM_FF::EAM_FF() {
161 > EAM_FF::EAM_FF(){
162    EAM_FF("");
163   }
164  
165 < EAM_FF::EAM_FF(char* the_variant){
165 > EAM_FF::EAM_FF(const string &the_variant) : ForceFields(the_variant) {
166  
167 <  char fileName[200];
168 <  char* ffPath_env = "FORCE_PARAM_PATH";
168 <  char* ffPath;
169 <  char temp[200];
167 >  string fileName;
168 >  string tempString;
169  
170    headAtomType = NULL;
171    currentAtomType = NULL;
# Line 205 | Line 204 | EAM_FF::EAM_FF(char* the_variant){
204      
205      // generate the force file name  
206  
207 <    strcpy( fileName, "EAM" );
207 >    fileName = "EAM";
208  
209 <    if (strlen(the_variant) > 0) {
209 >    if (!the_variant.empty()) {
210        has_variant = 1;
211 <      strcpy( variant, the_variant);
212 <      strcat( fileName, ".");
214 <      strcat( fileName, variant );
215 <
211 >      fileName += "." + the_variant;
212 >      
213        sprintf( painCave.errMsg,
214                 "Using %s variant of EAM force field.\n",
215 <               variant );
215 >               the_variant.c_str() );
216        painCave.severity = OOPSE_INFO;
217        painCave.isFatal = 0;
218        simError();
219 <    }
223 <    strcat( fileName, ".frc");
219 >    }  
220  
221 +    fileName += ".frc";
222 +
223      //fprintf( stderr,"Trying to open %s\n", fileName );
224      
225      // attempt to open the file in the current directory first.
226      
227 <    frcFile = fopen( fileName, "r" );
227 >    frcFile = fopen( fileName.c_str(), "r" );
228      
229      if( frcFile == NULL ){
230        
231        // next see if the force path enviorment variable is set
234      
235      ffPath = getenv( ffPath_env );
236      if( ffPath == NULL ) {
237        STR_DEFINE(ffPath, FRC_PATH );
238      }
239      
232        
233 <      strcpy( temp, ffPath );
234 <      strcat( temp, "/" );
235 <      strcat( temp, fileName );
236 <      strcpy( fileName, temp );
233 >      tempString = ffPath + "/" + fileName;
234 >      fileName = tempString;
235 >            
236 >      frcFile = fopen( fileName.c_str(), "r" );
237        
246      frcFile = fopen( fileName, "r" );
247      
238        if( frcFile == NULL ){
239          
240          sprintf( painCave.errMsg,
# Line 252 | Line 242 | EAM_FF::EAM_FF(char* the_variant){
242                   "\t%s\n"
243                   "\tHave you tried setting the FORCE_PARAM_PATH environment "
244                   "variable?\n",
245 <                 fileName );
245 >                 fileName.c_str() );
246          painCave.severity = OOPSE_ERROR;
247          painCave.isFatal = 1;
248          simError();
# Line 327 | Line 317 | void EAM_FF::readParams( void ){
317    double *eam_rvals;    // Z of r values
318    double *eam_rhovals;  // rho of r values
319    double *eam_Frhovals; // F of rho values
320 <  char eamPotFile[1000];
320 >  string eamPotFile;
321  
322    
323  
# Line 368 | Line 358 | void EAM_FF::readParams( void ){
358          
359          // the parser returns 0 if the line was blank
360          if( parseAtom( readLine, lineNum, info, eamPotFile ) ){
361 <          parseEAM(info,eamPotFile, &eam_rvals,
361 >          parseEAM(info, ffPath, eamPotFile, &eam_rvals,
362                     &eam_rhovals, &eam_Frhovals);
363            info.ident = identNum;
364            headAtomType->add( info, eam_rvals,
# Line 484 | Line 474 | void EAM_FF::readParams( void ){
474      currentAtomType = currentAtomType->next;
475    }
476        
477 <  entry_plug->useLJ = 0;
477 >  entry_plug->useLennardJones = 0;
478    entry_plug->useEAM = 1;
479    // Walk down again and send out EAM type
480    currentAtomType = headAtomType->next;
# Line 643 | Line 633 | int EAM_NS::parseAtom( char *lineBuffer, int lineNum,
633  
634  
635  
636 < int EAM_NS::parseAtom( char *lineBuffer, int lineNum,   atomStruct &info, char *eamPotFile ){
636 > int EAM_NS::parseAtom( char *lineBuffer, int lineNum,   atomStruct &info, string eamPotFile ){
637  
638    char* the_token;
639    
# Line 667 | Line 657 | int EAM_NS::parseAtom( char *lineBuffer, int lineNum,
657        painCave.isFatal = 1;
658        simError();
659      }
660 <        
661 <    strcpy( eamPotFile, the_token );
660 >    
661 >    eamPotFile = the_token;
662 >
663      return 1;
664    }
665    else return 0;
666   }
667  
668 < int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile,
668 > int EAM_NS::parseEAM(atomStruct &info, string ffPath, string eamPotFile,
669                       double **eam_rvals,
670                       double **eam_rhovals,
671                       double **eam_Frhovals){
# Line 682 | Line 673 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
673    double* myEam_rhovals;
674    double* myEam_Frhovals;
675  
685  char* ffPath_env = "FORCE_PARAM_PATH";
686  char* ffPath;
676    char* the_token;
677    char* eam_eof_test;
678    FILE *eamFile;
679    const int BUFFERSIZE = 3000;
680  
681 <  char temp[200];
681 >  string tempString;
682    int linenumber;
683    int nReadLines;
684    char eam_read_buffer[BUFFERSIZE];
685  
697
686    int i,j;
687  
688    linenumber = 0;
689  
690    // Open eam file
691 <  eamFile = fopen( eamPotFile, "r" );
691 >  eamFile = fopen( eamPotFile.c_str(), "r" );
692    
705  
693    if( eamFile == NULL ){
694      
695        // next see if the force path enviorment variable is set
696      
697 <    ffPath = getenv( ffPath_env );
698 <    if( ffPath == NULL ) {
712 <      STR_DEFINE(ffPath, FRC_PATH );
713 <    }
697 >    tempString = ffPath + "/" + eamPotFile;
698 >    eamPotFile = tempString;
699      
700 <    
716 <    strcpy( temp, ffPath );
717 <    strcat( temp, "/" );
718 <    strcat( temp, eamPotFile );
719 <    strcpy( eamPotFile, temp );
700 >    eamFile = fopen( eamPotFile.c_str(), "r" );
701      
721    eamFile = fopen( eamPotFile, "r" );
722
723    
724    
702      if( eamFile == NULL ){
703        
704        sprintf( painCave.errMsg,
705                 "Error opening the EAM force parameter file: %s\n"
706                 "Have you tried setting the FORCE_PARAM_PATH environment "
707                 "variable?\n",
708 <               eamPotFile );
708 >               eamPotFile.c_str() );
709        painCave.isFatal = 1;
710        simError();
711      }
# Line 739 | Line 716 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
716    linenumber++;
717    if(eam_eof_test == NULL){
718      sprintf( painCave.errMsg,
719 <             "error in reading commment in %s\n", eamPotFile);
719 >             "error in reading commment in %s\n", eamPotFile.c_str());
720      painCave.isFatal = 1;
721      simError();
722    }
# Line 751 | Line 728 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
728    linenumber++;
729    if(eam_eof_test == NULL){
730      sprintf( painCave.errMsg,
731 <             "error in reading Identifier line in %s\n", eamPotFile);
731 >             "error in reading Identifier line in %s\n", eamPotFile.c_str());
732      painCave.isFatal = 1;
733      simError();
734    }
# Line 761 | Line 738 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
738      
739    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
740      sprintf( painCave.errMsg,
741 <             "Error parsing EAM ident  line in %s\n", eamPotFile );
741 >             "Error parsing EAM ident  line in %s\n", eamPotFile.c_str() );
742      painCave.isFatal = 1;
743      simError();
744    }
# Line 770 | Line 747 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
747  
748    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
749      sprintf( painCave.errMsg,
750 <             "Error parsing EAM mass in %s\n", eamPotFile );
750 >             "Error parsing EAM mass in %s\n", eamPotFile.c_str() );
751      painCave.isFatal = 1;
752      simError();
753    }
# Line 778 | Line 755 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
755  
756    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
757      sprintf( painCave.errMsg,
758 <             "Error parsing EAM Lattice Constant %s\n", eamPotFile );
758 >             "Error parsing EAM Lattice Constant %s\n", eamPotFile.c_str() );
759      painCave.isFatal = 1;
760      simError();
761    }
# Line 788 | Line 765 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
765    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
766    if(eam_eof_test == NULL){
767      sprintf( painCave.errMsg,
768 <             "error in reading number of points line in %s\n", eamPotFile);
768 >             "error in reading number of points line in %s\n",
769 >             eamPotFile.c_str());
770      painCave.isFatal = 1;
771      simError();
772    }
773  
774    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
775      sprintf( painCave.errMsg,
776 <             "Error parseing EAM nrho: line in %s\n", eamPotFile );
776 >             "Error parseing EAM nrho: line in %s\n", eamPotFile.c_str() );
777      painCave.isFatal = 1;
778      simError();
779    }
# Line 804 | Line 782 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
782    
783    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
784      sprintf( painCave.errMsg,
785 <             "Error parsing EAM drho in %s\n", eamPotFile );
785 >             "Error parsing EAM drho in %s\n", eamPotFile.c_str() );
786      painCave.isFatal = 1;
787      simError();
788    }
# Line 812 | Line 790 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
790  
791    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
792      sprintf( painCave.errMsg,
793 <             "Error parsing EAM # r in %s\n", eamPotFile );
793 >             "Error parsing EAM # r in %s\n", eamPotFile.c_str() );
794      painCave.isFatal = 1;
795      simError();
796    }
# Line 820 | Line 798 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
798    
799    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
800      sprintf( painCave.errMsg,
801 <             "Error parsing EAM dr in %s\n", eamPotFile );
801 >             "Error parsing EAM dr in %s\n", eamPotFile.c_str() );
802      painCave.isFatal = 1;
803      simError();
804    }
# Line 828 | Line 806 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
806  
807    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
808      sprintf( painCave.errMsg,
809 <             "Error parsing EAM rcut in %s\n", eamPotFile );
809 >             "Error parsing EAM rcut in %s\n", eamPotFile.c_str() );
810      painCave.isFatal = 1;
811      simError();
812    }
# Line 860 | Line 838 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
838      if(eam_eof_test == NULL){
839        sprintf( painCave.errMsg,
840                 "error in reading EAM file %s at line %d\n",
841 <               eamPotFile,linenumber);
841 >               eamPotFile.c_str(), linenumber);
842        painCave.isFatal = 1;
843        simError();
844      }
# Line 869 | Line 847 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
847      // Value 1
848      if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
849        sprintf( painCave.errMsg,
850 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
850 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
851        painCave.isFatal = 1;
852        simError();
853      }
# Line 879 | Line 857 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
857      // Value 2
858      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
859        sprintf( painCave.errMsg,
860 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
860 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
861        painCave.isFatal = 1;
862        simError();
863      }
# Line 889 | Line 867 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
867      // Value 3
868      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
869        sprintf( painCave.errMsg,
870 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
870 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
871        painCave.isFatal = 1;
872        simError();
873      }
# Line 899 | Line 877 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
877      // Value 4
878      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
879        sprintf( painCave.errMsg,
880 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
880 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
881        painCave.isFatal = 1;
882        simError();
883      }
# Line 909 | Line 887 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
887      // Value 5
888      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
889        sprintf( painCave.errMsg,
890 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
890 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
891        painCave.isFatal = 1;
892        simError();
893      }
# Line 931 | Line 909 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
909      if(eam_eof_test == NULL){
910        sprintf( painCave.errMsg,
911                 "error in reading EAM file %s at line %d\n",
912 <               eamPotFile,linenumber);
912 >               eamPotFile.c_str(), linenumber);
913        painCave.isFatal = 1;
914        simError();
915      }
# Line 940 | Line 918 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
918      // Value 1
919      if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
920        sprintf( painCave.errMsg,
921 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
921 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
922        painCave.isFatal = 1;
923        simError();
924      }
# Line 950 | Line 928 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
928      // Value 2
929      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
930        sprintf( painCave.errMsg,
931 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
931 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
932        painCave.isFatal = 1;
933        simError();
934      }
# Line 960 | Line 938 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
938      // Value 3
939      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
940        sprintf( painCave.errMsg,
941 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
941 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
942        painCave.isFatal = 1;
943        simError();
944      }
# Line 970 | Line 948 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
948      // Value 4
949      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
950        sprintf( painCave.errMsg,
951 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
951 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
952        painCave.isFatal = 1;
953        simError();
954      }
# Line 980 | Line 958 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
958      // Value 5
959      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
960        sprintf( painCave.errMsg,
961 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
961 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
962        painCave.isFatal = 1;
963        simError();
964      }
# Line 1001 | Line 979 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
979      if(eam_eof_test == NULL){
980        sprintf( painCave.errMsg,
981                 "error in reading EAM file %s at line %d\n",
982 <               eamPotFile,linenumber);
982 >               eamPotFile.c_str(), linenumber);
983        painCave.isFatal = 1;
984        simError();
985      }
# Line 1010 | Line 988 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
988      // Value 1
989      if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
990        sprintf( painCave.errMsg,
991 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
991 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
992        painCave.isFatal = 1;
993        simError();
994      }
# Line 1020 | Line 998 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
998      // Value 2
999      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1000        sprintf( painCave.errMsg,
1001 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1001 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1002        painCave.isFatal = 1;
1003        simError();
1004      }
# Line 1030 | Line 1008 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1008      // Value 3
1009      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1010        sprintf( painCave.errMsg,
1011 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1011 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1012        painCave.isFatal = 1;
1013        simError();
1014      }
# Line 1040 | Line 1018 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1018      // Value 4
1019      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1020        sprintf( painCave.errMsg,
1021 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1021 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1022        painCave.isFatal = 1;
1023        simError();
1024      }
# Line 1050 | Line 1028 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1028      // Value 5
1029      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1030        sprintf( painCave.errMsg,
1031 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1031 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1032        painCave.isFatal = 1;
1033        simError();
1034      }
# Line 1065 | Line 1043 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1043    fclose(eamFile);
1044    return 0;
1045   }
1068
1069 double EAM_FF::getAtomTypeMass (char* atomType) {
1070
1071  currentAtomType = headAtomType->find( atomType );
1072  if( currentAtomType == NULL ){
1073    sprintf( painCave.errMsg,
1074            "AtomType error, %s not found in force file.\n",
1075             atomType );
1076    painCave.isFatal = 1;
1077    simError();
1078  }
1079
1080  return currentAtomType->mass;
1081 }
1082

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines