--- trunk/OOPSE/libmdtools/EAM_FF.cpp 2003/07/30 21:17:01 657 +++ trunk/OOPSE/libmdtools/EAM_FF.cpp 2004/06/11 16:46:13 1266 @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include using namespace std; @@ -30,10 +30,10 @@ namespace EAM_NS{ double mass; double lattice_constant; double eam_drho; // The distance between each of the points indexed by rho. + double eam_rcut; // The cutoff radius for eam. double eam_dr; // The distance between each of the rho points. int eam_nrho; // Number of points indexed by rho int eam_nr; // The number of points based on r (Both Phi(r) and Rho(r)). - double eam_rcut; // The cutoff radius for eam. int eam_ident; // Atomic number int ident; int last; // 0 -> default @@ -76,14 +76,12 @@ namespace EAM_NS{ void add( atomStruct &info, double *the_eam_rvals, double *the_eam_rhovals,double *the_eam_Frhovals ){ - int i; - // check for duplicates if( !strcmp( info.name, name ) ){ sprintf( painCave.errMsg, - "Duplicate LJ atom type \"%s\" found in " - "the LJ_FF param file./n", + "Duplicate EAM atom type \"%s\" found in " + "the EAM_FF param file./n", name ); painCave.isFatal = 1; simError(); @@ -157,18 +155,23 @@ using namespace EAM_NS; // begins the actual forcefield stuff. //**************************************************************** +EAM_FF::EAM_FF() { + EAM_FF(""); +} -EAM_FF::EAM_FF(){ +EAM_FF::EAM_FF(char* the_variant){ char fileName[200]; char* ffPath_env = "FORCE_PARAM_PATH"; char* ffPath; char temp[200]; - char errMsg[1000]; headAtomType = NULL; currentAtomType = NULL; + // Set eamRcut to 0.0 + eamRcut = 0.0; + // do the funtion wrapping wrapMeFF( this ); @@ -179,7 +182,7 @@ EAM_FF::EAM_FF(){ // Init the atomStruct mpi type atomStruct atomProto; // mpiPrototype - int atomBC[3] = {15,4,6}; // block counts + int atomBC[3] = {15,5,5}; // block counts MPI_Aint atomDspls[3]; // displacements MPI_Datatype atomMbrTypes[3]; // member mpi types @@ -201,10 +204,26 @@ EAM_FF::EAM_FF(){ if( worldRank == 0 ){ #endif - // generate the force file name - - strcpy( fileName, "EAM_FF.frc" ); - // fprintf( stderr,"Trying to open %s\n", fileName ); + // generate the force file name + + strcpy( fileName, "EAM" ); + + if (strlen(the_variant) > 0) { + has_variant = 1; + strcpy( variant, the_variant); + strcat( fileName, "."); + strcat( fileName, variant ); + + sprintf( painCave.errMsg, + "Using %s variant of EAM force field.\n", + variant ); + painCave.severity = OOPSE_INFO; + painCave.isFatal = 0; + simError(); + } + strcat( fileName, ".frc"); + + //fprintf( stderr,"Trying to open %s\n", fileName ); // attempt to open the file in the current directory first. @@ -228,16 +247,19 @@ EAM_FF::EAM_FF(){ frcFile = fopen( fileName, "r" ); if( frcFile == NULL ){ - + sprintf( painCave.errMsg, - "Error opening the force field parameter file: %s\n" - "Have you tried setting the FORCE_PARAM_PATH environment " - "vairable?\n", + "Error opening the force field parameter file:\n" + "\t%s\n" + "\tHave you tried setting the FORCE_PARAM_PATH environment " + "variable?\n", fileName ); + painCave.severity = OOPSE_ERROR; painCave.isFatal = 1; simError(); } } + #ifdef IS_MPI } @@ -266,9 +288,13 @@ void EAM_FF::calcRcut( void ){ void EAM_FF::calcRcut( void ){ - double tempEamRcut; - - entry_plug->setRcut(eamRcut); + +#ifdef IS_MPI + double tempEamRcut = eamRcut; + MPI_Allreduce( &tempEamRcut, &eamRcut, 1, MPI_DOUBLE, MPI_MAX, + MPI_COMM_WORLD); +#endif //is_mpi + entry_plug->setDefaultRcut(eamRcut); } @@ -298,7 +324,6 @@ void EAM_FF::readParams( void ){ info.last = 1; // initialize last to have the last set. // if things go well, last will be set to 0 - int i; int identNum; double *eam_rvals; // Z of r values double *eam_rhovals; // rho of r values @@ -314,7 +339,7 @@ void EAM_FF::readParams( void ){ // read in the atom types. headAtomType = new LinkedAtomType; - + fastForward( "AtomTypes", "eam atom readParams" ); // we are now at the AtomTypes section. @@ -404,7 +429,7 @@ void EAM_FF::readParams( void ){ MPIcheckPoint(); headAtomType = new LinkedAtomType; - recieveFrcStruct( &info, mpiAtomStructType ); + receiveFrcStruct( &info, mpiAtomStructType ); while( !info.last ){ @@ -430,7 +455,7 @@ void EAM_FF::readParams( void ){ MPIcheckPoint(); - recieveFrcStruct( &info, mpiAtomStructType ); + receiveFrcStruct( &info, mpiAtomStructType ); } @@ -446,8 +471,10 @@ void EAM_FF::readParams( void ){ int isDipole = 0; int isSSD = 0; int isGB = 0; - int isEAM= 1; + int isEAM = 1; + int isCharge = 0; double dipole = 0.0; + double charge = 0.0; double eamSigma = 0.0; double eamEpslon = 0.0; @@ -462,8 +489,10 @@ void EAM_FF::readParams( void ){ &isDipole, &isGB, &isEAM, + &isCharge, &eamEpslon, &eamSigma, + &charge, &dipole, &isError ); if( isError ){ @@ -478,14 +507,14 @@ void EAM_FF::readParams( void ){ } entry_plug->useLJ = 0; - + entry_plug->useEAM = 1; // Walk down again and send out EAM type currentAtomType = headAtomType->next; while( currentAtomType != NULL ){ if( currentAtomType->name[0] != '\0' ){ isError = 0; - cerr << "Calling newEAMtype for type "<eam_ident <<"\n"; + newEAMtype( &(currentAtomType->lattice_constant), &(currentAtomType->eam_nrho), &(currentAtomType->eam_drho), @@ -497,7 +526,7 @@ void EAM_FF::readParams( void ){ currentAtomType->eam_Frhovals, &(currentAtomType->eam_ident), &isError); - cerr << "Returned from newEAMtype\n"; + if( isError ){ sprintf( painCave.errMsg, "Error initializing the \"%s\" atom type in fortran EAM\n", @@ -517,20 +546,17 @@ void EAM_FF::readParams( void ){ MPIcheckPoint(); #endif // is_mpi - cerr << "Done sending eamtypes to fortran\n"; + } void EAM_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){ int i; - + // initialize the atoms - - Atom* thisAtom; - for( i=0; ifind( the_atoms[i]->getType() ); @@ -544,8 +570,9 @@ void EAM_FF::initializeAtoms( int nAtoms, Atom** the_a the_atoms[i]->setMass( currentAtomType->mass ); the_atoms[i]->setIdent( currentAtomType->ident ); - the_atoms[i]->setEAM(); + if (eamRcut < currentAtomType->eam_rcut) eamRcut = currentAtomType->eam_rcut; + } } @@ -722,7 +749,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil sprintf( painCave.errMsg, "Error opening the EAM force parameter file: %s\n" "Have you tried setting the FORCE_PARAM_PATH environment " - "vairable?\n", + "variable?\n", eamPotFile ); painCave.isFatal = 1; simError(); @@ -756,7 +783,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM ident line in %s\n", eamPotFile ); + "Error parsing EAM ident line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -765,7 +792,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ sprintf( painCave.errMsg, - "Error parseing EAM mass in %s\n", eamPotFile ); + "Error parsing EAM mass in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -773,7 +800,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ sprintf( painCave.errMsg, - "Error parseing EAM Lattice Constant %s\n", eamPotFile ); + "Error parsing EAM Lattice Constant %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -799,7 +826,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ sprintf( painCave.errMsg, - "Error parseing EAM drho in %s\n", eamPotFile ); + "Error parsing EAM drho in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -807,7 +834,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ sprintf( painCave.errMsg, - "Error parseing EAM # r in %s\n", eamPotFile ); + "Error parsing EAM # r in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -815,7 +842,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ sprintf( painCave.errMsg, - "Error parseing EAM dr in %s\n", eamPotFile ); + "Error parsing EAM dr in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -823,7 +850,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ sprintf( painCave.errMsg, - "Error parseing EAM rcut in %s\n", eamPotFile ); + "Error parsing EAM rcut in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -864,7 +891,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 1 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -874,7 +901,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 2 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -884,7 +911,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 3 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -894,7 +921,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 4 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -904,7 +931,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 5 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -935,7 +962,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 1 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -945,7 +972,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 2 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -955,7 +982,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 3 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -965,7 +992,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 4 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -975,7 +1002,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 5 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -1005,7 +1032,7 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil // Value 1 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -1013,9 +1040,9 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil myEam_rhovals[j+0] = atof( the_token ); // Value 2 - if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ + if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -1023,9 +1050,9 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil myEam_rhovals[j+1] = atof( the_token ); // Value 3 - if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ + if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -1033,9 +1060,9 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil myEam_rhovals[j+2] = atof( the_token ); // Value 4 - if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ + if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } @@ -1043,15 +1070,15 @@ int EAM_NS::parseEAM(atomStruct &info, char *eamPotFil myEam_rhovals[j+3] = atof( the_token ); // Value 5 - if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ + if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ sprintf( painCave.errMsg, - "Error parseing EAM nrho: line in %s\n", eamPotFile ); + "Error parsing EAM nrho: line in %s\n", eamPotFile ); painCave.isFatal = 1; simError(); } myEam_rhovals[j+4] = atof( the_token ); - + } *eam_rvals = myEam_rvals; *eam_rhovals = myEam_rhovals;