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.
Revision 1654 by gezelter, Wed Oct 27 02:16:34 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,
45 >  int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, string eamPotFile );
46 >  int parseEAM( atomStruct &info, string eamPotFile, double **eam_rvals,
47                  double **eam_rhovals, double **eam_Frhovals);
48   #ifdef IS_MPI
49    
# Line 161 | Line 161 | EAM_FF::EAM_FF(char* the_variant){
161    EAM_FF("");
162   }
163  
164 < EAM_FF::EAM_FF(char* the_variant){
164 > EAM_FF::EAM_FF(string the_variant){
165  
166 <  char fileName[200];
167 <  char* ffPath_env = "FORCE_PARAM_PATH";
168 <  char* ffPath;
169 <  char temp[200];
166 >  string fileName;
167 >  string tempString;
168  
169    headAtomType = NULL;
170    currentAtomType = NULL;
# Line 205 | Line 203 | EAM_FF::EAM_FF(char* the_variant){
203      
204      // generate the force file name  
205  
206 <    strcpy( fileName, "EAM" );
206 >    fileName = "EAM";
207  
208 <    if (strlen(the_variant) > 0) {
208 >    if (!the_variant.empty()) {
209        has_variant = 1;
210 <      strcpy( variant, the_variant);
211 <      strcat( fileName, ".");
214 <      strcat( fileName, variant );
215 <
210 >      fileName += "." + the_variant;
211 >      
212        sprintf( painCave.errMsg,
213                 "Using %s variant of EAM force field.\n",
214 <               variant );
214 >               the_variant.c_str() );
215        painCave.severity = OOPSE_INFO;
216        painCave.isFatal = 0;
217        simError();
218 <    }
223 <    strcat( fileName, ".frc");
218 >    }  
219  
220 +    fileName += ".frc";
221 +
222      //fprintf( stderr,"Trying to open %s\n", fileName );
223      
224      // attempt to open the file in the current directory first.
225      
226 <    frcFile = fopen( fileName, "r" );
226 >    frcFile = fopen( fileName.c_str(), "r" );
227      
228      if( frcFile == NULL ){
229        
230        // next see if the force path enviorment variable is set
231        
232 <      ffPath = getenv( ffPath_env );
233 <      if( ffPath == NULL ) {
234 <        STR_DEFINE(ffPath, FRC_PATH );
235 <      }
239 <      
240 <      
241 <      strcpy( temp, ffPath );
242 <      strcat( temp, "/" );
243 <      strcat( temp, fileName );
244 <      strcpy( fileName, temp );
232 >      tempString = ffPath + "/" + fileName;
233 >      fileName = tempString;
234 >            
235 >      frcFile = fopen( fileName.c_str(), "r" );
236        
246      frcFile = fopen( fileName, "r" );
247      
237        if( frcFile == NULL ){
238          
239          sprintf( painCave.errMsg,
# Line 252 | Line 241 | EAM_FF::EAM_FF(char* the_variant){
241                   "\t%s\n"
242                   "\tHave you tried setting the FORCE_PARAM_PATH environment "
243                   "variable?\n",
244 <                 fileName );
244 >                 fileName.c_str() );
245          painCave.severity = OOPSE_ERROR;
246          painCave.isFatal = 1;
247          simError();
# Line 327 | Line 316 | void EAM_FF::readParams( void ){
316    double *eam_rvals;    // Z of r values
317    double *eam_rhovals;  // rho of r values
318    double *eam_Frhovals; // F of rho values
319 <  char eamPotFile[1000];
319 >  string eamPotFile;
320  
321    
322  
# Line 484 | Line 473 | void EAM_FF::readParams( void ){
473      currentAtomType = currentAtomType->next;
474    }
475        
476 <  entry_plug->useLJ = 0;
476 >  entry_plug->useLennardJones = 0;
477    entry_plug->useEAM = 1;
478    // Walk down again and send out EAM type
479    currentAtomType = headAtomType->next;
# Line 643 | Line 632 | int EAM_NS::parseAtom( char *lineBuffer, int lineNum,
632  
633  
634  
635 < int EAM_NS::parseAtom( char *lineBuffer, int lineNum,   atomStruct &info, char *eamPotFile ){
635 > int EAM_NS::parseAtom( char *lineBuffer, int lineNum,   atomStruct &info, string eamPotFile ){
636  
637    char* the_token;
638    
# Line 667 | Line 656 | int EAM_NS::parseAtom( char *lineBuffer, int lineNum,
656        painCave.isFatal = 1;
657        simError();
658      }
659 <        
660 <    strcpy( eamPotFile, the_token );
659 >    
660 >    eamPotFile = the_token;
661 >
662      return 1;
663    }
664    else return 0;
665   }
666  
667 < int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile,
667 > int EAM_NS::parseEAM(atomStruct &info, string eamPotFile,
668                       double **eam_rvals,
669                       double **eam_rhovals,
670                       double **eam_Frhovals){
# Line 682 | Line 672 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
672    double* myEam_rhovals;
673    double* myEam_Frhovals;
674  
685  char* ffPath_env = "FORCE_PARAM_PATH";
686  char* ffPath;
675    char* the_token;
676    char* eam_eof_test;
677    FILE *eamFile;
678    const int BUFFERSIZE = 3000;
679  
680 <  char temp[200];
680 >  string tempString;
681    int linenumber;
682    int nReadLines;
683    char eam_read_buffer[BUFFERSIZE];
684  
697
685    int i,j;
686  
687    linenumber = 0;
688  
689    // Open eam file
690 <  eamFile = fopen( eamPotFile, "r" );
690 >  eamFile = fopen( eamPotFile.c_str(), "r" );
691    
705  
692    if( eamFile == NULL ){
693      
694        // next see if the force path enviorment variable is set
695      
696 <    ffPath = getenv( ffPath_env );
697 <    if( ffPath == NULL ) {
712 <      STR_DEFINE(ffPath, FRC_PATH );
713 <    }
714 <    
715 <    
716 <    strcpy( temp, ffPath );
717 <    strcat( temp, "/" );
718 <    strcat( temp, eamPotFile );
719 <    strcpy( eamPotFile, temp );
696 >    tempString = ffPath + "/" + eamPotFile;
697 >    eamPotFile = tempString;
698      
699 <    eamFile = fopen( eamPotFile, "r" );
722 <
699 >    eamFile = fopen( eamPotFile.c_str(), "r" );
700      
724    
701      if( eamFile == NULL ){
702        
703        sprintf( painCave.errMsg,
704                 "Error opening the EAM force parameter file: %s\n"
705                 "Have you tried setting the FORCE_PARAM_PATH environment "
706                 "variable?\n",
707 <               eamPotFile );
707 >               eamPotFile.c_str() );
708        painCave.isFatal = 1;
709        simError();
710      }
# Line 739 | Line 715 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
715    linenumber++;
716    if(eam_eof_test == NULL){
717      sprintf( painCave.errMsg,
718 <             "error in reading commment in %s\n", eamPotFile);
718 >             "error in reading commment in %s\n", eamPotFile.c_str());
719      painCave.isFatal = 1;
720      simError();
721    }
# Line 751 | Line 727 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
727    linenumber++;
728    if(eam_eof_test == NULL){
729      sprintf( painCave.errMsg,
730 <             "error in reading Identifier line in %s\n", eamPotFile);
730 >             "error in reading Identifier line in %s\n", eamPotFile.c_str());
731      painCave.isFatal = 1;
732      simError();
733    }
# Line 761 | Line 737 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
737      
738    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
739      sprintf( painCave.errMsg,
740 <             "Error parsing EAM ident  line in %s\n", eamPotFile );
740 >             "Error parsing EAM ident  line in %s\n", eamPotFile.c_str() );
741      painCave.isFatal = 1;
742      simError();
743    }
# Line 770 | Line 746 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
746  
747    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
748      sprintf( painCave.errMsg,
749 <             "Error parsing EAM mass in %s\n", eamPotFile );
749 >             "Error parsing EAM mass in %s\n", eamPotFile.c_str() );
750      painCave.isFatal = 1;
751      simError();
752    }
# Line 778 | Line 754 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
754  
755    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
756      sprintf( painCave.errMsg,
757 <             "Error parsing EAM Lattice Constant %s\n", eamPotFile );
757 >             "Error parsing EAM Lattice Constant %s\n", eamPotFile.c_str() );
758      painCave.isFatal = 1;
759      simError();
760    }
# Line 788 | Line 764 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
764    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
765    if(eam_eof_test == NULL){
766      sprintf( painCave.errMsg,
767 <             "error in reading number of points line in %s\n", eamPotFile);
767 >             "error in reading number of points line in %s\n",
768 >             eamPotFile.c_str());
769      painCave.isFatal = 1;
770      simError();
771    }
772  
773    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
774      sprintf( painCave.errMsg,
775 <             "Error parseing EAM nrho: line in %s\n", eamPotFile );
775 >             "Error parseing EAM nrho: line in %s\n", eamPotFile.c_str() );
776      painCave.isFatal = 1;
777      simError();
778    }
# Line 804 | Line 781 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
781    
782    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
783      sprintf( painCave.errMsg,
784 <             "Error parsing EAM drho in %s\n", eamPotFile );
784 >             "Error parsing EAM drho in %s\n", eamPotFile.c_str() );
785      painCave.isFatal = 1;
786      simError();
787    }
# Line 812 | Line 789 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
789  
790    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
791      sprintf( painCave.errMsg,
792 <             "Error parsing EAM # r in %s\n", eamPotFile );
792 >             "Error parsing EAM # r in %s\n", eamPotFile.c_str() );
793      painCave.isFatal = 1;
794      simError();
795    }
# Line 820 | Line 797 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
797    
798    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
799      sprintf( painCave.errMsg,
800 <             "Error parsing EAM dr in %s\n", eamPotFile );
800 >             "Error parsing EAM dr in %s\n", eamPotFile.c_str() );
801      painCave.isFatal = 1;
802      simError();
803    }
# Line 828 | Line 805 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
805  
806    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
807      sprintf( painCave.errMsg,
808 <             "Error parsing EAM rcut in %s\n", eamPotFile );
808 >             "Error parsing EAM rcut in %s\n", eamPotFile.c_str() );
809      painCave.isFatal = 1;
810      simError();
811    }
# Line 860 | Line 837 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
837      if(eam_eof_test == NULL){
838        sprintf( painCave.errMsg,
839                 "error in reading EAM file %s at line %d\n",
840 <               eamPotFile,linenumber);
840 >               eamPotFile.c_str(), linenumber);
841        painCave.isFatal = 1;
842        simError();
843      }
# Line 869 | Line 846 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
846      // Value 1
847      if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
848        sprintf( painCave.errMsg,
849 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
849 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
850        painCave.isFatal = 1;
851        simError();
852      }
# Line 879 | Line 856 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
856      // Value 2
857      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
858        sprintf( painCave.errMsg,
859 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
859 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
860        painCave.isFatal = 1;
861        simError();
862      }
# Line 889 | Line 866 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
866      // Value 3
867      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
868        sprintf( painCave.errMsg,
869 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
869 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
870        painCave.isFatal = 1;
871        simError();
872      }
# Line 899 | Line 876 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
876      // Value 4
877      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
878        sprintf( painCave.errMsg,
879 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
879 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
880        painCave.isFatal = 1;
881        simError();
882      }
# Line 909 | Line 886 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
886      // Value 5
887      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
888        sprintf( painCave.errMsg,
889 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
889 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
890        painCave.isFatal = 1;
891        simError();
892      }
# Line 931 | Line 908 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
908      if(eam_eof_test == NULL){
909        sprintf( painCave.errMsg,
910                 "error in reading EAM file %s at line %d\n",
911 <               eamPotFile,linenumber);
911 >               eamPotFile.c_str(), linenumber);
912        painCave.isFatal = 1;
913        simError();
914      }
# Line 940 | Line 917 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
917      // Value 1
918      if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
919        sprintf( painCave.errMsg,
920 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
920 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
921        painCave.isFatal = 1;
922        simError();
923      }
# Line 950 | Line 927 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
927      // Value 2
928      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
929        sprintf( painCave.errMsg,
930 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
930 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
931        painCave.isFatal = 1;
932        simError();
933      }
# Line 960 | Line 937 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
937      // Value 3
938      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
939        sprintf( painCave.errMsg,
940 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
940 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
941        painCave.isFatal = 1;
942        simError();
943      }
# Line 970 | Line 947 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
947      // Value 4
948      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
949        sprintf( painCave.errMsg,
950 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
950 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
951        painCave.isFatal = 1;
952        simError();
953      }
# Line 980 | Line 957 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
957      // Value 5
958      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
959        sprintf( painCave.errMsg,
960 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
960 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
961        painCave.isFatal = 1;
962        simError();
963      }
# Line 1001 | Line 978 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
978      if(eam_eof_test == NULL){
979        sprintf( painCave.errMsg,
980                 "error in reading EAM file %s at line %d\n",
981 <               eamPotFile,linenumber);
981 >               eamPotFile.c_str(), linenumber);
982        painCave.isFatal = 1;
983        simError();
984      }
# Line 1010 | Line 987 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
987      // Value 1
988      if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
989        sprintf( painCave.errMsg,
990 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
990 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
991        painCave.isFatal = 1;
992        simError();
993      }
# Line 1020 | Line 997 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
997      // Value 2
998      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
999        sprintf( painCave.errMsg,
1000 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1000 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1001        painCave.isFatal = 1;
1002        simError();
1003      }
# Line 1030 | Line 1007 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1007      // Value 3
1008      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1009        sprintf( painCave.errMsg,
1010 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1010 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1011        painCave.isFatal = 1;
1012        simError();
1013      }
# Line 1040 | Line 1017 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1017      // Value 4
1018      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1019        sprintf( painCave.errMsg,
1020 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1020 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1021        painCave.isFatal = 1;
1022        simError();
1023      }
# Line 1050 | Line 1027 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1027      // Value 5
1028      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1029        sprintf( painCave.errMsg,
1030 <               "Error parsing EAM nrho: line in %s\n", eamPotFile );
1030 >               "Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() );
1031        painCave.isFatal = 1;
1032        simError();
1033      }
# Line 1065 | Line 1042 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1042    fclose(eamFile);
1043    return 0;
1044   }
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