--- trunk/mdtools/interface_implementation/LJ_FF.cpp 2002/12/19 21:59:51 215 +++ trunk/mdtools/interface_implementation/LJ_FF.cpp 2003/01/10 21:56:06 234 @@ -10,27 +10,38 @@ using namespace std; #include "simError.h" -#ifdef IS_MPI +// Declare the structures that will be passed by the parser and MPI -#include "mpiForceField.h" - - -// Declare the structures that will be passed by MPI - typedef struct{ char name[15]; double mass; double epslon; double sigma; + int ident; int last; // 0 -> default - // 1 -> tells nodes to stop listening + // 1 -> in MPI: tells nodes to stop listening } atomStruct; + +int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ); + +#ifdef IS_MPI + +#include "mpiForceField.h" + MPI_Datatype mpiAtomStructType; #endif +// declaration of functions needed to wrap the fortran module +extern "C" { + void forcefactory_( char* forceName, + int* status, + void (*wrapFunction)( void (* + + + LJ_FF::LJ_FF(){ char fileName[200]; @@ -46,13 +57,13 @@ LJ_FF::LJ_FF(){ // Init the atomStruct mpi type atomStruct atomProto; // mpiPrototype - int atomBC[3] = {15,3,1}; // block counts + int atomBC[3] = {15,3,2}; // block counts MPI_Aint atomDspls[3]; // displacements MPI_Datatype atomMbrTypes[3]; // member mpi types MPI_Address(&atomProto.name, &atomDspls[0]); MPI_Address(&atomProto.mass, &atomDspls[1]); - MPI_Address(&atomProto.last, &atomDspls[2]); + MPI_Address(&atomProto.ident, &atomDspls[2]); atomMbrTypes[0] = MPI_CHAR; atomMbrTypes[1] = MPI_DOUBLE; @@ -151,8 +162,20 @@ void LJ_FF::initializeAtoms( void ){ return NULL; } -#ifdef IS_MPI + void add( atomStruct &info ){ + + // check for duplicates + + if( !strcmp( info.name, name ) ){ + sprintf( simError.painCave, + "Duplicate LJ atom type \"%s\" found in " + "the LJ_FF param file./n", + name ); + painCave.isFatal = 1; + simError(); + } + if( next != NULL ) next->add(info); else{ next = new LinkedType(); @@ -160,14 +183,19 @@ void LJ_FF::initializeAtoms( void ){ next->mass = info.mass; next->epslon = info.epslon; next->sigma = info.sigma; + next->ident = info.ident; } } + +#ifdef IS_MPI + void duplicate( atomStruct &info ){ strcpy(info.name, name); info.mass = mass; info.epslon = epslon; info.sigma = sigma; + info.ident = ident; info.last = 0; } @@ -178,62 +206,19 @@ void LJ_FF::initializeAtoms( void ){ double mass; double epslon; double sigma; + int ident; LinkedType* next; }; LinkedType* headAtomType; LinkedType* currentAtomType; - LinkedType* tempAtomType; - -#ifdef IS_MPI atomStruct info; info.last = 1; // initialize last to have the last set. // if things go well, last will be set to 0 -#endif - - char readLine[500]; - char* the_token; - char* eof_test; - int foundAtom = 0; - int lineNum = 0; int i; - - - ////////////////////////////////////////////////// - // a quick water fix - - double waterI[3][3]; - waterI[0][0] = 1.76958347772500; - waterI[0][1] = 0.0; - waterI[0][2] = 0.0; - - waterI[1][0] = 0.0; - waterI[1][1] = 0.614537057924513; - waterI[1][2] = 0.0; - - waterI[2][0] = 0.0; - waterI[2][1] = 0.0; - waterI[2][2] = 1.15504641980049; - - - double headI[3][3]; - headI[0][0] = 1125; - headI[0][1] = 0.0; - headI[0][2] = 0.0; - - headI[1][0] = 0.0; - headI[1][1] = 1125; - headI[1][2] = 0.0; - - headI[2][0] = 0.0; - headI[2][1] = 0.0; - headI[2][2] = 250; - + int identNum; - - ////////////////////////////////////////////////// - Atom** the_atoms; int nAtoms; the_atoms = entry_plug->atoms; @@ -245,55 +230,19 @@ void LJ_FF::initializeAtoms( void ){ #endif // read in the atom types. - - rewind( frcFile ); + headAtomType = new LinkedType; - currentAtomType = headAtomType; - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - if( eof_test == NULL ){ - sprintf( painCave.errMsg, "Error in reading Atoms from force file.\n" ); - painCave.isFatal = 1; - simError(); - } - - - while( !foundAtom ){ - while( eof_test != NULL && readLine[0] != '#' ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - } - if( eof_test == NULL ){ - sprintf( painCave.errMsg, - "Error in reading Atoms from force file at line %d.\n", - lineNum ); - painCave.isFatal = 1; - simError(); - } - - the_token = strtok( readLine, " ,;\t#\n" ); - foundAtom = !strcmp( "AtomTypes", the_token ); - - if( !foundAtom ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - - if( eof_test == NULL ){ - sprintf( painCave.errMsg, - "Error in reading Atoms from force file at line %d.\n", - lineNum ); - painCave.isFatal = 1; - simError(); - } - } - } - + fastFoward( "AtomTypes", "initializeAtoms" ); + // we are now at the AtomTypes section. eof_test = fgets( readLine, sizeof(readLine), frcFile ); lineNum++; + + // read a line, and start parseing out the atom types + if( eof_test == NULL ){ sprintf( painCave.errMsg, "Error in reading Atoms from force file at line %d.\n", @@ -302,48 +251,20 @@ void LJ_FF::initializeAtoms( void ){ simError(); } + identNum = 1; + // stop reading at end of file, or at next section while( readLine[0] != '#' && eof_test != NULL ){ - + + // toss comment lines if( readLine[0] != '!' ){ - the_token = strtok( readLine, " \n\t,;" ); - if( the_token != NULL ){ - - strcpy( currentAtomType->name, the_token ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( painCave.errMsg, - "Error parseing AtomTypes: line %d\n", lineNum ); - painCave.isFatal = 1; - simError(); - } - - sscanf( the_token, "%lf", ¤tAtomType->mass ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( painCave.errMsg, - "Error parseing AtomTypes: line %d\n", lineNum ); - painCave.isFatal = 1; - simError(); - } - - sscanf( the_token, "%lf", ¤tAtomType->epslon ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( painCave.errMsg, - "Error parseing AtomTypes: line %d\n", lineNum ); - painCave.isFatal = 1; - simError(); - } - - sscanf( the_token, "%lf", ¤tAtomType->sigma ); + // the parser returns 0 if the line was blank + if( parseAtomLJ( readLine, lineNum, info ) ){ + info.ident = identNum; + headAtomType->add( info );; + identNum++; } } - - tempAtomType = new LinkedType; - currentAtomType->next = tempAtomType; - currentAtomType = tempAtomType; - eof_test = fgets( readLine, sizeof(readLine), frcFile ); lineNum++; } @@ -383,7 +304,9 @@ void LJ_FF::initializeAtoms( void ){ } #endif // is_mpi - + // call new A_types in fortran + + // initialize the atoms Atom* thisAtom; @@ -402,6 +325,7 @@ void LJ_FF::initializeAtoms( void ){ the_atoms[i]->setMass( currentAtomType->mass ); the_atoms[i]->setEpslon( currentAtomType->epslon ); the_atoms[i]->setSigma( currentAtomType->sigma ); + the_atoms[i]->setIdent( currentAtomType->ident ); the_atoms[i]->setLJ(); } @@ -458,3 +382,101 @@ void LJ_FF::initializeTorsions( torsion_set* the_torsi #endif // is_mpi } + + +void LJ_FF::fastForward( char* stopText, char* searchOwner ){ + + int foundText = 0; + char* the_token; + + rewind( frcFile ); + lineNum = 0; + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + if( eof_test == NULL ){ + sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " + " file is empty.\n", + searchOwner ); + painCave.isFatal = 1; + simError(); + } + + + while( !foundText ){ + while( eof_test != NULL && readLine[0] != '#' ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + } + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error fast forwarding force file for %s at " + "line %d: file ended unexpectedly.\n", + searchOwner, + lineNum ); + painCave.isFatal = 1; + simError(); + } + + the_token = strtok( readLine, " ,;\t#\n" ); + foundText = !strcmp( stopText, the_token ); + + if( !foundText ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error fast forwarding force file for %s at " + "line %d: file ended unexpectedly.\n", + searchOwner, + lineNum ); + painCave.isFatal = 1; + simError(); + } + } + } +} + + + +int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info ){ + + char* the_token; + + the_token = strtok( lineBuffer, " \n\t,;" ); + if( the_token != NULL ){ + + strcpy( info.name, the_token ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } + + info.mass = atof( the_token ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } + + info.epslon = atof( the_token ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } + + info.sigma = atof( the_token ); + + return 1; + } + else return 0; +}