ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/EAM_FF.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/EAM_FF.cpp (file contents):
Revision 627 by chuckv, Wed Jul 16 21:49:59 2003 UTC vs.
Revision 657 by chuckv, Wed Jul 30 21:17:01 2003 UTC

# Line 33 | Line 33 | namespace EAM_NS{
33      double eam_dr;    // The distance between each of the rho points.    
34      int eam_nrho;  // Number of points indexed by rho
35      int eam_nr;    // The number of points based on r (Both Phi(r) and Rho(r)).
36 <    int eam_rcut;  // The cutoff radius for eam.
36 >    double eam_rcut;  // The cutoff radius for eam.
37      int eam_ident; // Atomic number
38      int ident;
39      int last;      //  0  -> default
# Line 41 | Line 41 | namespace EAM_NS{
41    } atomStruct;
42  
43    int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile );
44 <  int parseEAM( atomStruct &info, char *eamPotFile );
44 >  int parseEAM( atomStruct &info, char *eamPotFile, double **eam_rvals,
45 >                double **eam_rhovals, double **eam_Frhovals);
46   #ifdef IS_MPI
47    
48    MPI_Datatype mpiAtomStructType;
# Line 135 | Line 136 | namespace EAM_NS{
136      double eam_drho; // The distance between each of the points indexed by rho.
137      int eam_nr;   // The number of points based on r (Both Phi(r) and Rho(r)).
138      double eam_dr;   // The distance between each of the rho points.
139 <    int eam_rcut; // The cutoff radius for eam.
139 >    double eam_rcut; // The cutoff radius for eam.
140  
141      double *eam_rvals;    // Z of r values
142      double *eam_rhovals;  // rho of r values
# Line 150 | Line 151 | using namespace LJ_NS;
151  
152   }
153  
154 < using namespace LJ_NS;
154 > using namespace EAM_NS;
155  
156   //****************************************************************
157   // begins the actual forcefield stuff.  
# Line 261 | Line 262 | EAM_FF::~EAM_FF(){
262   #ifdef IS_MPI
263    }
264   #endif // is_mpi
265 + }
266 +
267 +
268 + void EAM_FF::calcRcut( void ){
269 +  double tempEamRcut;
270 +
271 +  entry_plug->setRcut(eamRcut);
272   }
273  
274 +
275   void EAM_FF::initForceField( int ljMixRule ){
267  
276    initFortran( ljMixRule, 0 );
277   }
278  
# Line 283 | Line 291 | void EAM_FF::readParams( void ){
291   #endif // is_mpi
292   }
293  
294 +
295   void EAM_FF::readParams( void ){
296  
297    atomStruct info;
# Line 335 | Line 344 | void EAM_FF::readParams( void ){
344          // the parser returns 0 if the line was blank
345          if( parseAtom( readLine, lineNum, info, eamPotFile ) ){
346            parseEAM(info,eamPotFile, &eam_rvals,
347 <                   &eam_rhovals, &eam_Frhovals)){
347 >                   &eam_rhovals, &eam_Frhovals);
348            info.ident = identNum;
349            headAtomType->add( info, eam_rvals,
350                               eam_rhovals,eam_Frhovals );
# Line 437 | Line 446 | void EAM_FF::readParams( void ){
446    int isDipole = 0;
447    int isSSD = 0;
448    int isGB = 0;
449 <  int isEam = 1;
449 >  int isEAM= 1;
450    double dipole = 0.0;
451 +  double eamSigma = 0.0;
452 +  double eamEpslon = 0.0;
453    
454    currentAtomType = headAtomType->next;
455    while( currentAtomType != NULL ){
# Line 451 | Line 462 | void EAM_FF::readParams( void ){
462                   &isDipole,
463                   &isGB,
464                   &isEAM,
465 <                 &(currentAtomType->epslon),
466 <                 &(currentAtomType->sigma),
465 >                 &eamEpslon,
466 >                 &eamSigma,
467                   &dipole,
468                   &isError );
469        if( isError ){
# Line 474 | Line 485 | void EAM_FF::readParams( void ){
485      
486      if( currentAtomType->name[0] != '\0' ){
487        isError = 0;
488 +      cerr << "Calling newEAMtype for type "<<currentAtomType->eam_ident <<"\n";
489        newEAMtype( &(currentAtomType->lattice_constant),
490                    &(currentAtomType->eam_nrho),
491                    &(currentAtomType->eam_drho),
492                    &(currentAtomType->eam_nr),
493                    &(currentAtomType->eam_dr),
494 +                  &(currentAtomType->eam_rcut),
495                    currentAtomType->eam_rvals,
496                    currentAtomType->eam_rhovals,
497                    currentAtomType->eam_Frhovals,
498                    &(currentAtomType->eam_ident),
499                    &isError);
500 +      cerr << "Returned from newEAMtype\n";
501        if( isError ){
502          sprintf( painCave.errMsg,
503                   "Error initializing the \"%s\" atom type in fortran EAM\n",
# Line 503 | Line 517 | void EAM_FF::readParams( void ){
517    MPIcheckPoint();
518   #endif // is_mpi
519  
520 +  cerr << "Done sending eamtypes to fortran\n";
521 +
522   }
523  
524  
# Line 533 | Line 549 | void LJ_FF::initializeBonds( int nBonds, Bond** BondAr
549    }
550   }
551  
552 < void LJ_FF::initializeBonds( int nBonds, Bond** BondArray,
552 > void EAM_FF::initializeBonds( int nBonds, Bond** BondArray,
553                               bond_pair* the_bonds ){
554    
555      if( nBonds ){
# Line 657 | Line 673 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
673                       double **eam_rvals,
674                       double **eam_rhovals,
675                       double **eam_Frhovals){
676 <  
676 >  double* myEam_rvals;
677 >  double* myEam_rhovals;
678 >  double* myEam_Frhovals;
679 >
680    char* ffPath_env = "FORCE_PARAM_PATH";
681    char* ffPath;
682    char* the_token;
683 +  char* eam_eof_test;
684    FILE *eamFile;
685 +  const int BUFFERSIZE = 3000;
686 +
687    char temp[200];
688    int linenumber;
689    int nReadLines;
690 +  char eam_read_buffer[BUFFERSIZE];
691  
692 +
693    int i,j;
694  
695    linenumber = 0;
# Line 674 | Line 698 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
698    eamFile = fopen( eamPotFile, "r" );
699    
700    
701 <  if( frcFile == NULL ){
701 >  if( eamFile == NULL ){
702      
703        // next see if the force path enviorment variable is set
704      
# Line 693 | Line 717 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
717  
718      
719      
720 <    if( frcFile == NULL ){
720 >    if( eamFile == NULL ){
721        
722        sprintf( painCave.errMsg,
723                 "Error opening the EAM force parameter file: %s\n"
# Line 706 | Line 730 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
730    }
731  
732    // First line is a comment line, read and toss it....
733 <  eof_test = fgets(read_buffer, sizeof(read_buffer),eamFile);
733 >  eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
734    linenumber++;
735 <  if(eof_test == NULL){
735 >  if(eam_eof_test == NULL){
736      sprintf( painCave.errMsg,
737               "error in reading commment in %s\n", eamPotFile);
738      painCave.isFatal = 1;
# Line 718 | Line 742 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
742  
743  
744    // The Second line contains atomic number, atomic mass and a lattice constant
745 <  eof_test = fgets(read_buffer, sizeof(read_buffer),eamFile);
745 >  eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
746    linenumber++;
747 <  if(eof_test == NULL){
747 >  if(eam_eof_test == NULL){
748      sprintf( painCave.errMsg,
749               "error in reading Identifier line in %s\n", eamPotFile);
750      painCave.isFatal = 1;
# Line 730 | Line 754 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
754  
755  
756      
757 <  if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
757 >  if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
758      sprintf( painCave.errMsg,
759               "Error parseing EAM ident  line in %s\n", eamPotFile );
760      painCave.isFatal = 1;
# Line 756 | Line 780 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
780    info.lattice_constant = atof( the_token);
781  
782    // Next line is nrho, drho, nr, dr and rcut
783 <  eof_test = fgets(read_buffer, sizeof(read_buffer),eamFile)
784 <  if(eof_test == NULL){
783 >  eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
784 >  if(eam_eof_test == NULL){
785      sprintf( painCave.errMsg,
786               "error in reading number of points line in %s\n", eamPotFile);
787      painCave.isFatal = 1;
788      simError();
789    }
790  
791 <  if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
791 >  if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
792      sprintf( painCave.errMsg,
793               "Error parseing EAM nrho: line in %s\n", eamPotFile );
794      painCave.isFatal = 1;
# Line 806 | Line 830 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
830    info.eam_rcut = atof( the_token);
831  
832  
833 +
834 +
835 +
836    // Ok now we have to allocate point arrays and read in number of points
837    // Index the arrays for fortran, starting at 1
838 <  *eam_Frhovals = new double[info.nrho];
839 <  *eam_rvals    = new double[info.nr];
840 <  *eam_rhovals  = new double[info.nr];
838 >  myEam_Frhovals = new double[info.eam_nrho];
839 >  myEam_rvals    = new double[info.eam_nr];
840 >  myEam_rhovals  = new double[info.eam_nr];
841  
842    // Parse F of rho vals.
843  
844    // Assume for now that we have a complete number of lines
845 <  nReadLines = int(info.nrho/5);
845 >  nReadLines = int(info.eam_nrho/5);
846 >  
847  
848 +
849    for (i=0;i<nReadLines;i++){
850      j = i*5;
851 <    
851 >
852      // Read next line
853 <    eof_test = fgets(read_buffer, sizeof(read_buffer),eamFile);
853 >    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
854      linenumber++;
855 <    if(eof_test == NULL){
855 >    if(eam_eof_test == NULL){
856        sprintf( painCave.errMsg,
857                 "error in reading EAM file %s at line %d\n",
858                 eamPotFile,linenumber);
# Line 833 | Line 862 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
862      
863      // Parse 5 values on each line into array
864      // Value 1
865 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
865 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
866        sprintf( painCave.errMsg,
867                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
868        painCave.isFatal = 1;
869        simError();
870      }
871 +
872 +    myEam_Frhovals[j+0] = atof( the_token );
873      
843    *eam_Frhovals[j+0] = atof( the_token );
844    
874      // Value 2
875      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
876        sprintf( painCave.errMsg,
# Line 849 | Line 878 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
878        painCave.isFatal = 1;
879        simError();
880      }
881 <  
882 <    *eam_Frhovals[j+1] = atof( the_token );
881 >
882 >    myEam_Frhovals[j+1] = atof( the_token );
883      
884      // Value 3
885      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
# Line 859 | Line 888 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
888        painCave.isFatal = 1;
889        simError();
890      }
891 +
892 +    myEam_Frhovals[j+2] = atof( the_token );
893      
863    *eam_Frhovals[j+2] = atof( the_token );
864    
894      // Value 4
895      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
896        sprintf( painCave.errMsg,
# Line 869 | Line 898 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
898        painCave.isFatal = 1;
899        simError();
900      }
872    
873    *eam_Frhovals[j+3] = atof( the_token );
901  
902 +    myEam_Frhovals[j+3] = atof( the_token );
903 +
904      // Value 5
905      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
906        sprintf( painCave.errMsg,
# Line 879 | Line 908 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
908        painCave.isFatal = 1;
909        simError();
910      }
911 +
912 +    myEam_Frhovals[j+4] = atof( the_token );
913      
883    *eam_Frhovals[j+4] = atof( the_token );
884    
914    }
915    // Parse Z of r vals
916    
917    // Assume for now that we have a complete number of lines
918 <  nReadLines = int(info.nr/5);
918 >  nReadLines = int(info.eam_nr/5);
919  
920    for (i=0;i<nReadLines;i++){
921      j = i*5;
922  
923      // Read next line
924 <    eof_test = fgets(read_buffer, sizeof(read_buffer),eamFile);
924 >    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
925      linenumber++;
926 <    if(eof_test == NULL){
926 >    if(eam_eof_test == NULL){
927        sprintf( painCave.errMsg,
928                 "error in reading EAM file %s at line %d\n",
929                 eamPotFile,linenumber);
# Line 904 | Line 933 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
933      
934      // Parse 5 values on each line into array
935      // Value 1
936 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
936 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
937        sprintf( painCave.errMsg,
938                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
939        painCave.isFatal = 1;
940        simError();
941      }
942      
943 <    *eam_rvals[j+0] = atof( the_token );
943 >    myEam_rvals[j+0] = atof( the_token );
944  
945      // Value 2
946      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
# Line 921 | Line 950 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
950        simError();
951      }
952    
953 <    *eam_rvals[j+1] = atof( the_token );
953 >    myEam_rvals[j+1] = atof( the_token );
954  
955      // Value 3
956      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
# Line 931 | Line 960 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
960        simError();
961      }
962    
963 <    *eam_rvals[j+2] = atof( the_token );
963 >    myEam_rvals[j+2] = atof( the_token );
964  
965      // Value 4
966      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
# Line 941 | Line 970 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
970        simError();
971      }
972    
973 <    *eam_rvals[j+3] = atof( the_token );
973 >    myEam_rvals[j+3] = atof( the_token );
974  
975      // Value 5
976      if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
# Line 951 | Line 980 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
980        simError();
981      }
982    
983 <    *eam_rvals[j+4] = atof( the_token );
983 >    myEam_rvals[j+4] = atof( the_token );
984  
985    }
986    // Parse rho of r vals
# Line 962 | Line 991 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
991      j = i*5;
992  
993      // Read next line
994 <    eof_test = fgets(read_buffer, sizeof(read_buffer),eamFile);
994 >    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
995      linenumber++;
996 <    if(eof_test == NULL){
996 >    if(eam_eof_test == NULL){
997        sprintf( painCave.errMsg,
998                 "error in reading EAM file %s at line %d\n",
999                 eamPotFile,linenumber);
# Line 974 | Line 1003 | int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil
1003    
1004      // Parse 5 values on each line into array
1005      // Value 1
1006 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
1006 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1007        sprintf( painCave.errMsg,
1008                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1009        painCave.isFatal = 1;
1010        simError();
1011      }
1012    
1013 <    *eam_rhovals[j+0] = atof( the_token );
1013 >    myEam_rhovals[j+0] = atof( the_token );
1014  
1015      // Value 2
1016 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
1016 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1017        sprintf( painCave.errMsg,
1018                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1019        painCave.isFatal = 1;
1020        simError();
1021      }
1022    
1023 <    *eam_rhovals[j+1] = atof( the_token );
1023 >    myEam_rhovals[j+1] = atof( the_token );
1024  
1025      // Value 3
1026 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
1026 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1027        sprintf( painCave.errMsg,
1028                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1029        painCave.isFatal = 1;
1030        simError();
1031      }
1032    
1033 <    *eam_rhovals[j+2] = atof( the_token );
1033 >    myEam_rhovals[j+2] = atof( the_token );
1034  
1035      // Value 4
1036 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
1036 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1037        sprintf( painCave.errMsg,
1038                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1039        painCave.isFatal = 1;
1040        simError();
1041      }
1042    
1043 <    *eam_rhovals[j+3] = atof( the_token );
1043 >    myEam_rhovals[j+3] = atof( the_token );
1044  
1045      // Value 5
1046 <    if ( (the_token = strtok( read_buffer, " \n\t,;")) == NULL){
1046 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1047        sprintf( painCave.errMsg,
1048                 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1049        painCave.isFatal = 1;
1050        simError();
1051      }
1052    
1053 <    *eam_rhovals[j+4] = atof( the_token );
1053 >    myEam_rhovals[j+4] = atof( the_token );
1054  
1055    }
1056 +  *eam_rvals = myEam_rvals;
1057 +  *eam_rhovals = myEam_rhovals;
1058 +  *eam_Frhovals = myEam_Frhovals;
1059  
1060    fclose(eamFile);
1061    return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines