--- trunk/OOPSE/libmdtools/ForceFields.cpp 2003/04/03 20:21:54 447 +++ trunk/OOPSE/libmdtools/ForceFields.cpp 2004/05/01 18:52:38 1144 @@ -1,10 +1,19 @@ -#include +#include +using namespace std; + + +#include + #ifdef IS_MPI #include #endif // is_mpi +#ifdef PROFILE +#include "mdProfile.hpp" +#endif + #include "simError.h" #include "ForceFields.hpp" #include "Atom.hpp" @@ -21,16 +30,45 @@ void ForceFields::calcRcut( void ){ //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->setDefaultRcut( 2.5 * bigSigma ); + +} + +void ForceFields::setRcut( double LJrcut ) { - entry_plug->rList = entry_plug->rCut + 1.0; +#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 ){ @@ -39,69 +77,76 @@ void ForceFields::doForces( int calcPot, int calcStres double* frc; double* pos; double* trq; - double* tau; double* A; - double* u_l;; - DirectionalAtom* dAtom; + double* u_l; + double* rc; + double* massRatio; + SimState* config; - double ut[3]; - - //u_l = new double[entry_plug->n_atoms]; - short int passedCalcPot = (short int)calcPot; short int passedCalcStress = (short int)calcStress; - // forces are zeroed here, before any are acumulated. + // forces are zeroed here, before any are accumulated. // NOTE: do not rezero the forces in Fortran. - for(i=0; in_atoms; i++){ - entry_plug->atoms[i]->zeroForces(); - -// if( entry_plug->atoms[i]->isDirectional() ){ -// dAtom = (DirectionalAtom *)entry_plug->atoms[i]; -// dAtom->getU(ut); - - -// if(dAtom->getIndex()== 1){ -// std::cerr << "atom 2's u_l = " << ut[0] << ", " << ut[1] -// << ", " << ut[2] << "\n"; -// } -// } - + entry_plug->atoms[i]->zeroForces(); } +#ifdef PROFILE + startProfile(pro7); +#endif + for(i=0; in_mol; i++ ){ + // CalcForces in molecules takes care of mapping rigid body coordinates + // into atomic coordinates entry_plug->molecules[i].calcForces(); } - frc = Atom::getFrcArray(); - pos = Atom::getPosArray(); - trq = Atom::getTrqArray(); - A = Atom::getAmatArray(); - u_l = Atom::getUlArray(); - tau = entry_plug->tau; +#ifdef PROFILE + endProfile( pro7 ); +#endif + config = entry_plug->getConfiguration(); + frc = config->getFrcArray(); + pos = config->getPosArray(); + trq = config->getTrqArray(); + A = config->getAmatArray(); + u_l = config->getUlArray(); + rc = config->getRcArray(); + massRatio = config->getMassRatioArray(); + isError = 0; entry_plug->lrPot = 0.0; + for (i=0; i<9; i++) { + entry_plug->tau[i] = 0.0; + } - + +#ifdef PROFILE + startProfile(pro8); +#endif + fortranForceLoop( pos, + rc, A, u_l, frc, trq, - tau, + entry_plug->tau, &(entry_plug->lrPot), &passedCalcPot, &passedCalcStress, &isError ); - // delete[] u_l; +#ifdef PROFILE + endProfile(pro8); +#endif + if( isError ){ sprintf( painCave.errMsg, "Error returned from the fortran force calculation.\n" ); @@ -109,11 +154,17 @@ 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" ); MPIcheckPoint(); #endif // is_mpi + }