--- trunk/OOPSE/libmdtools/ForceFields.cpp 2003/10/28 16:03:37 829 +++ trunk/OOPSE/libmdtools/ForceFields.cpp 2004/05/11 21:14:26 1158 @@ -10,6 +10,10 @@ using namespace std; #endif // is_mpi +#ifdef PROFILE +#include "mdProfile.hpp" +#endif + #include "simError.h" #include "ForceFields.hpp" #include "Atom.hpp" @@ -26,20 +30,74 @@ void ForceFields::calcRcut( void ){ //calc rCut and rList - entry_plug->setRcut( 2.5 * bigSigma ); + entry_plug->setDefaultRcut( 2.5 * bigSigma ); } +void ForceFields::setRcut( double LJrcut ) { + +#ifdef IS_MPI + double tempBig = bigSigma; + MPI_Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX, + MPI_COMM_WORLD); +#endif //is_mpi + + if (LJrcut < 2.5 * bigSigma) { + sprintf( painCave.errMsg, + "Setting Lennard-Jones cutoff radius to %lf.\n" + "\tThis value is smaller than %lf, which is\n" + "\t2.5 * bigSigma, where bigSigma is the largest\n" + "\tvalue of sigma present in the simulation.\n" + "\tThis is potentially a problem since the LJ potential may\n" + "\tbe appreciable at this distance. If you don't want the\n" + "\tsmaller cutoff, change the LJrcut variable.\n", + LJrcut, 2.5*bigSigma); + painCave.isFatal = 0; + simError(); + } else { + sprintf( painCave.errMsg, + "Setting Lennard-Jones cutoff radius to %lf.\n" + "\tThis value is larger than %lf, which is\n" + "\t2.5 * bigSigma, where bigSigma is the largest\n" + "\tvalue of sigma present in the simulation. This should\n" + "\tnot be a problem, but could adversely effect performance.\n", + LJrcut, 2.5*bigSigma); + painCave.isFatal = 0; + simError(); + } + + //calc rCut and rList + + entry_plug->setDefaultRcut( LJrcut ); +} + void ForceFields::doForces( int calcPot, int calcStress ){ - int i, isError; + int i, j, isError; double* frc; double* pos; double* trq; double* A; - double* u_l;; + double* u_l; + double* rc; + double* massRatio; SimState* config; + Molecule* myMols; + Atom** myAtoms; + int numAtom; + int curIndex; + double mtot; + int numMol; + int numCutoffGroups; + CutoffGroup* myCutoffGroup; + vector::iterator iterCutoff; + Atom* cutoffAtom; + vector::iterator iterAtom; + double com[3]; + double tempPos[3]; + int atomIndex; + short int passedCalcPot = (short int)calcPot; short int passedCalcStress = (short int)calcStress; @@ -50,10 +108,20 @@ void ForceFields::doForces( int calcPot, int calcStres entry_plug->atoms[i]->zeroForces(); } +#ifdef PROFILE + startProfile(pro7); +#endif + for(i=0; in_mol; i++ ){ - entry_plug->molecules[i].calcForces(); + // CalcForces in molecules takes care of mapping rigid body coordinates + // into atomic coordinates + entry_plug->molecules[i].calcForces(); } +#ifdef PROFILE + endProfile( pro7 ); +#endif + config = entry_plug->getConfiguration(); frc = config->getFrcArray(); @@ -62,6 +130,55 @@ void ForceFields::doForces( int calcPot, int calcStres A = config->getAmatArray(); u_l = config->getUlArray(); + if(entry_plug->haveCutoffGroups){ + //if + myMols = entry_plug->molecules; + numMol = entry_plug->n_mol; + for(int i = 0; i < numMol; i++){ + numAtom = myMols[i].getNAtoms(); + myAtoms = myMols[i].getMyAtoms(); + + + for(int j = 0; j < numAtom; j++){ +#ifdef IS_MPI + atomIndex = myAtoms[j]->getGlobalIndex(); +#else + atomIndex = myAtoms[j]->getIndex(); +#endif + + if(myMols[i].belongToCutoffGroup(atomIndex)) + continue; + else{ + myAtoms[j]->getPos(tempPos); + myAtoms[j]->setRc(tempPos); + } + + } + + numCutoffGroups = myMols[i].getNCutoffGroups(); + for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); myCutoffGroup != NULL; + myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){ + //get center of mass of the cutoff group + myCutoffGroup->getCOM(com); + + for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom); cutoffAtom != NULL; + cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){ + cutoffAtom->setRc(com); + } + + }// end for(myCutoffGroup) + + }//end for(int i = 0) + + rc = config->getRcArray(); + } + else{ + // center of mass of the group is the same as position of the atom if cutoff group does not exist + rc = pos; + } + + + isError = 0; entry_plug->lrPot = 0.0; @@ -69,7 +186,13 @@ void ForceFields::doForces( int calcPot, int calcStres entry_plug->tau[i] = 0.0; } + +#ifdef PROFILE + startProfile(pro8); +#endif + fortranForceLoop( pos, + rc, A, u_l, frc, @@ -80,6 +203,12 @@ void ForceFields::doForces( int calcPot, int calcStres &passedCalcStress, &isError ); + +#ifdef PROFILE + endProfile(pro8); +#endif + + if( isError ){ sprintf( painCave.errMsg, "Error returned from the fortran force calculation.\n" ); @@ -87,6 +216,11 @@ void ForceFields::doForces( int calcPot, int calcStres simError(); } + for(i=0; in_mol; i++ ){ + entry_plug->molecules[i].atoms2rigidBodies(); + } + + #ifdef IS_MPI sprintf( checkPointMsg, "returned from the force calculation.\n" );