--- trunk/OOPSE/libmdtools/LJ_FF.cpp 2003/03/21 17:42:12 378 +++ trunk/OOPSE/libmdtools/LJ_FF.cpp 2003/03/27 17:32:03 420 @@ -43,6 +43,72 @@ namespace LJ_NS{ MPI_Datatype mpiAtomStructType; #endif + + class LinkedAtomType { + public: + LinkedAtomType(){ + next = NULL; + name[0] = '\0'; + } + ~LinkedAtomType(){ if( next != NULL ) delete next; } + + LinkedAtomType* find(char* key){ + if( !strcmp(name, key) ) return this; + if( next != NULL ) return next->find(key); + return NULL; + } + + + void add( atomStruct &info ){ + + // check for duplicates + + if( !strcmp( info.name, name ) ){ + sprintf( painCave.errMsg, + "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(); + strcpy(next->name, info.name); + 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; + } + + +#endif + + char name[15]; + double mass; + double epslon; + double sigma; + int ident; + LinkedAtomType* next; + }; + + LinkedAtomType* headAtomType; + LinkedAtomType* currentAtomType; + } using namespace LJ_NS; @@ -60,6 +126,9 @@ LJ_FF::LJ_FF(){ char temp[200]; char errMsg[1000]; + headAtomType = NULL; + currentAtomType = NULL; + // do the funtion wrapping wrapMeFF( this ); @@ -142,6 +211,8 @@ LJ_FF::~LJ_FF(){ LJ_FF::~LJ_FF(){ + if( headAtomType != NULL ) delete headAtomType; + #ifdef IS_MPI if( worldRank == 0 ){ #endif // is_mpi @@ -158,73 +229,23 @@ void LJ_FF::initForceField( int ljMixRule ){ initFortran( ljMixRule, 0 ); } +void LJ_FF::cleanMe( void ){ -void LJ_FF::initializeAtoms( void ){ +#ifdef IS_MPI - class LinkedType { - public: - LinkedType(){ - next = NULL; - name[0] = '\0'; - } - ~LinkedType(){ if( next != NULL ) delete next; } + // keep the linked list in the mpi version - LinkedType* find(char* key){ - if( !strcmp(name, key) ) return this; - if( next != NULL ) return next->find(key); - return NULL; - } - +#else // is_mpi - void add( atomStruct &info ){ - - // check for duplicates - - if( !strcmp( info.name, name ) ){ - sprintf( painCave.errMsg, - "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(); - strcpy(next->name, info.name); - next->mass = info.mass; - next->epslon = info.epslon; - next->sigma = info.sigma; - next->ident = info.ident; - } - } - + // delete the linked list in the single processor version -#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; - } + if( headAtomType != NULL ) delete headAtomType; +#endif // is_mpi +} -#endif +void LJ_FF::readParams( void ){ - char name[15]; - double mass; - double epslon; - double sigma; - int ident; - LinkedType* next; - }; - - LinkedType* headAtomType; - LinkedType* currentAtomType; atomStruct info; info.last = 1; // initialize last to have the last set. // if things go well, last will be set to 0 @@ -232,19 +253,15 @@ void LJ_FF::initializeAtoms( void ){ int i; int identNum; - Atom** the_atoms; - int nAtoms; - the_atoms = entry_plug->atoms; - nAtoms = entry_plug->n_atoms; - - + + bigSigma = 0.0; #ifdef IS_MPI if( worldRank == 0 ){ #endif // read in the atom types. - headAtomType = new LinkedType; + headAtomType = new LinkedAtomType; fastForward( "AtomTypes", "initializeAtoms" ); @@ -385,12 +402,17 @@ void LJ_FF::initializeAtoms( void ){ "LJ_FF atom structures successfully sent to fortran\n" ); MPIcheckPoint(); #endif // is_mpi + +} + +void LJ_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){ + int i; // initialize the atoms - double bigSigma = 0.0; + Atom* thisAtom; for( i=0; isigma ) bigSigma = currentAtomType->sigma; } - -#ifdef IS_MPI - double tempBig = bigSigma; - MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX ); -#endif //is_mpi - - //calc rCut and rList - - entry_plug->rCut = 2.5 * bigSigma; - if(entry_plug->rCut > (entry_plug->box_x / 2.0)) - entry_plug->rCut = entry_plug->box_x / 2.0; - if(entry_plug->rCut > (entry_plug->box_y / 2.0)) - entry_plug->rCut = entry_plug->box_y / 2.0; - if(entry_plug->rCut > (entry_plug->box_z / 2.0)) - entry_plug->rCut = entry_plug->box_z / 2.0; - - entry_plug->rList = entry_plug->rCut + 1.0; - entry_plug->useLJ = 1; - // clean up the memory - - delete headAtomType; - #ifdef IS_MPI sprintf( checkPointMsg, "LJ_FF atoms initialized succesfully" ); MPIcheckPoint(); @@ -444,9 +444,10 @@ void LJ_FF::initializeBonds( bond_pair* the_bonds ){ } -void LJ_FF::initializeBonds( bond_pair* the_bonds ){ +void LJ_FF::initializeBonds( int nBonds, Bond** BondArray, + bond_pair* the_bonds ){ - if( entry_plug->n_bonds ){ + if( nBonds ){ sprintf( painCave.errMsg, "LJ_FF does not support bonds.\n" ); painCave.isFatal = 1; @@ -458,9 +459,10 @@ void LJ_FF::initializeBends( bend_set* the_bends ){ } -void LJ_FF::initializeBends( bend_set* the_bends ){ +void LJ_FF::initializeBends( int nBends, Bend** bendArray, + bend_set* the_bends ){ - if( entry_plug->n_bends ){ + if( nBends ){ sprintf( painCave.errMsg, "LJ_FF does not support bends.\n" ); painCave.isFatal = 1; @@ -472,9 +474,10 @@ void LJ_FF::initializeTorsions( torsion_set* the_torsi } -void LJ_FF::initializeTorsions( torsion_set* the_torsions ){ +void LJ_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, + torsion_set* the_torsions ){ - if( entry_plug->n_torsions ){ + if( nTorsions ){ sprintf( painCave.errMsg, "LJ_FF does not support torsions.\n" ); painCave.isFatal = 1;