--- trunk/OOPSE/libmdtools/SimSetup.cpp 2004/06/01 15:57:30 1211 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2004/06/04 03:15:31 1234 @@ -11,8 +11,9 @@ #include "simError.h" #include "RigidBody.hpp" #include "OOPSEMinimizer.hpp" -//#include "ConstraintElement.hpp" -//#include "ConstraintPair.hpp" +#include "ConstraintElement.hpp" +#include "ConstraintPair.hpp" +#include "ConstraintManager.hpp" #ifdef IS_MPI #include "mpiBASS.h" @@ -157,6 +158,10 @@ void SimSetup::createSim(void){ initFortran(); + //creat constraint manager + for(int i = 0; i < nInfo; i++) + info[i].consMan = new ConstraintManager(&info[i]); + if (globals->haveMinimizer()) // make minimizer makeMinimizer(); @@ -171,8 +176,8 @@ void SimSetup::makeMolecules(void){ int i, j, k; int exI, exJ, exK, exL, slI, slJ; int tempI, tempJ, tempK, tempL; - int molI; - int stampID, atomOffset, rbOffset; + int molI, globalID; + int stampID, atomOffset, rbOffset, groupOffset; molInit molInfo; DirectionalAtom* dAtom; RigidBody* myRB; @@ -199,12 +204,13 @@ void SimSetup::makeMolecules(void){ char* molName; char rbName[100]; - //ConstraintPair* consPair; //constraint pair - //ConstraintElement* consElement1; //first element of constraint pair - //ConstraintElement* consElement2; //second element of constraint pair - //int whichRigidBody; - //int consAtomIndex; //index of constraint atom in rigid body's atom array - //vector > jointAtoms; + ConstraintPair* consPair; //constraint pair + ConstraintElement* consElement1; //first element of constraint pair + ConstraintElement* consElement2; //second element of constraint pair + int whichRigidBody; + int consAtomIndex; //index of constraint atom in rigid body's atom array + vector > jointAtoms; + double bondLength2; //init the forceField paramters the_ff->readParams(); @@ -216,6 +222,16 @@ void SimSetup::makeMolecules(void){ for (k = 0; k < nInfo; k++){ the_ff->setSimInfo(&(info[k])); +#ifdef IS_MPI + info[k].globalGroupMembership = new int[mpiSim->getNAtomsGlobal()]; + for (i = 0; i < mpiSim->getNAtomsGlobal(); i++) + info[k].globalGroupMembership[i] = 0; +#else + info[k].globalGroupMembership = new int[info[k].n_atoms]; + for (i = 0; i < info[k].n_atoms; i++) + info[k].globalGroupMembership[i] = 0; +#endif + atomOffset = 0; groupOffset = 0; @@ -282,9 +298,7 @@ void SimSetup::makeMolecules(void){ molInfo.myAtoms[j]->setType(currentAtom->getType()); #ifdef IS_MPI - molInfo.myAtoms[j]->setGlobalIndex(globalAtomIndex[j + atomOffset]); - #endif // is_mpi } @@ -506,8 +520,13 @@ void SimSetup::makeMolecules(void){ nMembers = currentCutoffGroup->getNMembers(); myCutoffGroup = new CutoffGroup(); - myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); +#ifdef IS_MPI + myCutoffGroup->setGlobalIndex(globalGroupIndex[groupOffset]); +#else + myCutoffGroup->setGlobalIndex(groupOffset); +#endif + for (int cg = 0; cg < nMembers; cg++) { // molI is atom numbering inside this molecule @@ -517,41 +536,43 @@ void SimSetup::makeMolecules(void){ tempI = molI + atomOffset; #ifdef IS_MPI - globalID = info[k].atoms[tempI]->getGlobalIndex() + globalID = info[k].atoms[tempI]->getGlobalIndex(); + info[k].globalGroupMembership[globalID] = globalGroupIndex[groupOffset]; #else globalID = info[k].atoms[tempI]->getIndex(); -#endif - - globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; - - myCutoffGroup->addAtom(info[k].atoms[tempI]); - + info[k].globalGroupMembership[globalID] = groupOffset; +#endif + myCutoffGroup->addAtom(info[k].atoms[tempI]); cutoffAtomSet.insert(tempI); } - + molInfo.myCutoffGroups.push_back(myCutoffGroup); groupOffset++; }//end for (j = 0; j < molInfo.nCutoffGroups; j++) - - //creat a cutoff group for every atom in current molecule which does not belong to cutoffgroup defined at mdl file - + + + // create a cutoff group for every atom in current molecule which + // does not belong to cutoffgroup defined at mdl file + for(j = 0; j < molInfo.nAtoms; j++){ - + if(cutoffAtomSet.find(molInfo.myAtoms[j]->getIndex()) == cutoffAtomSet.end()){ myCutoffGroup = new CutoffGroup(); myCutoffGroup->addAtom(molInfo.myAtoms[j]); - myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); + #ifdef IS_MPI - globalID = info[k].atoms[atomOffset + j]->getGlobalIndex() -#else + myCutoffGroup->setGlobalIndex(globalGroupIndex[groupOffset]); + globalID = info[k].atoms[atomOffset + j]->getGlobalIndex(); + info[k].globalGroupMembership[globalID] = globalGroupIndex[groupOffset]; +#else + myCutoffGroup->setGlobalIndex(groupOffset); globalID = info[k].atoms[atomOffset + j]->getIndex(); + info[k].globalGroupMembership[globalID] = groupOffset; #endif - globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; molInfo.myCutoffGroups.push_back(myCutoffGroup); groupOffset++; - } - + } } // After this is all set up, scan through the atoms to @@ -584,37 +605,50 @@ void SimSetup::makeMolecules(void){ info[k].integrableObjects.push_back(mySD); molInfo.myIntegrableObjects.push_back(mySD); } + + // send the arrays off to the forceField for init. + + the_ff->initializeAtoms(molInfo.nAtoms, molInfo.myAtoms); + the_ff->initializeBonds(molInfo.nBonds, molInfo.myBonds, theBonds); + the_ff->initializeBends(molInfo.nBends, molInfo.myBends, theBends); + the_ff->initializeTorsions(molInfo.nTorsions, molInfo.myTorsions, + theTorsions); - /* - //creat ConstraintPair. - molInfo.myConstraintPair.clear(); + molInfo.myConstraintPairs.clear(); for (j = 0; j < molInfo.nBonds; j++){ - //if both atoms are in the same rigid body, just skip it - currentBond = comp_stamps[stampID]->getBond(j); - if(!comp_stamps[stampID]->isBondInSameRigidBody(currentBond)){ + //if bond is constrained bond, add it into constraint pair + if(molInfo.myBonds[j]->is_constrained()){ - tempI = currentBond->getA() + atomOffset; - if( comp_stamps[stampID]->isAtomInRigidBody(currentBond->getA(), whichRigidBody, consAtomIndex)) - consElement1 = new ConstraintRigidBody(molInfo.myRigidBodies[whichRigidBody], consAtomIndex); - else - consElement1 = new ConstraintAtom(info[k].atoms[tempI]); - - tempJ = currentBond->getB() + atomOffset; - if(comp_stamps[stampID]->isAtomInRigidBody(currentBond->getB(), whichRigidBody, consAtomIndex)) - consElement2 = new ConstraintRigidBody(molInfo.myRigidBodies[whichRigidBody], consAtomIndex); - else - consElement2 = new ConstraintAtom(info[k].atoms[tempJ]); + //if both atoms are in the same rigid body, just skip it + currentBond = comp_stamps[stampID]->getBond(j); + + if(!comp_stamps[stampID]->isBondInSameRigidBody(currentBond)){ - consPair = new DistanceConstraintPair(consElement1, consElement2); - molInfo.myConstraintPairs.push_back(consPair); - } + tempI = currentBond->getA() + atomOffset; + if( comp_stamps[stampID]->isAtomInRigidBody(currentBond->getA(), whichRigidBody, consAtomIndex)) + consElement1 = new ConstraintRigidBody(molInfo.myRigidBodies[whichRigidBody], consAtomIndex); + else + consElement1 = new ConstraintAtom(info[k].atoms[tempI]); + + tempJ = currentBond->getB() + atomOffset; + if(comp_stamps[stampID]->isAtomInRigidBody(currentBond->getB(), whichRigidBody, consAtomIndex)) + consElement2 = new ConstraintRigidBody(molInfo.myRigidBodies[whichRigidBody], consAtomIndex); + else + consElement2 = new ConstraintAtom(info[k].atoms[tempJ]); + + bondLength2 = molInfo.myBonds[j]->get_constraint()->get_dsqr(); + consPair = new DistanceConstraintPair(consElement1, consElement2, bondLength2); + + molInfo.myConstraintPairs.push_back(consPair); + } + }//end if(molInfo.myBonds[j]->is_constrained()) } - //loop over rigid bodies, if two rigid bodies share same joint, creat a HingeConstraintPair + //loop over rigid bodies, if two rigid bodies share same joint, creat a JointConstraintPair for (int rb1 = 0; rb1 < molInfo.nRigidBodies -1 ; rb1++){ for (int rb2 = rb1 + 1; rb2 < molInfo.nRigidBodies ; rb2++){ @@ -631,23 +665,41 @@ void SimSetup::makeMolecules(void){ } } -*/ - // send the arrays off to the forceField for init. - - the_ff->initializeAtoms(molInfo.nAtoms, molInfo.myAtoms); - the_ff->initializeBonds(molInfo.nBonds, molInfo.myBonds, theBonds); - the_ff->initializeBends(molInfo.nBends, molInfo.myBends, theBends); - the_ff->initializeTorsions(molInfo.nTorsions, molInfo.myTorsions, - theTorsions); info[k].molecules[i].initialize(molInfo); - - + + atomOffset += molInfo.nAtoms; delete[] theBonds; delete[] theBends; delete[] theTorsions; - } + } + + + +#ifdef IS_MPI + // Since the globalGroupMembership has been zero filled and we've only + // poked values into the atoms we know, we can do an Allreduce + // to get the full globalGroupMembership array (We think). + // This would be prettier if we could use MPI_IN_PLACE like the MPI-2 + // docs said we could. + + int* ggMjunk = new int[mpiSim->getNAtomsGlobal()]; + + MPI_Allreduce(info[k].globalGroupMembership, + ggMjunk, + mpiSim->getNAtomsGlobal(), + MPI_INT, MPI_SUM, MPI_COMM_WORLD); + + for (i = 0; i < mpiSim->getNAtomsGlobal(); i++) + info[k].globalGroupMembership[i] = ggMjunk[i]; + + delete[] ggMjunk; + +#endif + + + } #ifdef IS_MPI @@ -1020,9 +1072,9 @@ void SimSetup::gatherInfo(void){ info[i].orthoTolerance = globals->getOrthoBoxTolerance(); // check for thermodynamic integration - if (globals->getUseThermInt()) { + if (globals->getUseSolidThermInt() && !globals->getUseLiquidThermInt()) { if (globals->haveThermIntLambda() && globals->haveThermIntK()) { - info[i].useThermInt = globals->getUseThermInt(); + info[i].useSolidThermInt = globals->getUseSolidThermInt(); info[i].thermIntLambda = globals->getThermIntLambda(); info[i].thermIntK = globals->getThermIntK(); @@ -1032,7 +1084,7 @@ void SimSetup::gatherInfo(void){ else { sprintf(painCave.errMsg, "SimSetup Error:\n" - "\tKeyword useThermInt was set to 'true' but\n" + "\tKeyword useSolidThermInt was set to 'true' but\n" "\tthermodynamicIntegrationLambda (and/or\n" "\tthermodynamicIntegrationK) was not specified.\n" "\tPlease provide a lambda value and k value in your .bass file.\n"); @@ -1040,12 +1092,42 @@ void SimSetup::gatherInfo(void){ simError(); } } + else if(globals->getUseLiquidThermInt()) { + if (globals->getUseSolidThermInt()) { + sprintf( painCave.errMsg, + "SimSetup Warning: It appears that you have both solid and\n" + "\tliquid thermodynamic integration activated in your .bass\n" + "\tfile. To avoid confusion, specify only one technique in\n" + "\tyour .bass file. Liquid-state thermodynamic integration\n" + "\twill be assumed for the current simulation. If this is not\n" + "\twhat you desire, set useSolidThermInt to 'true' and\n" + "\tuseLiquidThermInt to 'false' in your .bass file.\n"); + painCave.isFatal = 0; + simError(); + } + if (globals->haveThermIntLambda() && globals->haveThermIntK()) { + info[i].useLiquidThermInt = globals->getUseLiquidThermInt(); + info[i].thermIntLambda = globals->getThermIntLambda(); + info[i].thermIntK = globals->getThermIntK(); + } + else { + sprintf(painCave.errMsg, + "SimSetup Error:\n" + "\tKeyword useLiquidThermInt was set to 'true' but\n" + "\tthermodynamicIntegrationLambda (and/or\n" + "\tthermodynamicIntegrationK) was not specified.\n" + "\tPlease provide a lambda value and k value in your .bass file.\n"); + painCave.isFatal = 1; + simError(); + } + } else if(globals->haveThermIntLambda() || globals->haveThermIntK()){ sprintf(painCave.errMsg, "SimSetup Warning: If you want to use Thermodynamic\n" - "\tIntegration, set useThermInt to 'true' in your .bass file.\n" - "\tThe useThermInt keyword is 'false' by default, so your\n" - "\tlambda and/or k values are being ignored.\n"); + "\tIntegration, set useSolidThermInt or useLiquidThermInt to\n" + "\t'true' in your .bass file. These keywords are set to\n" + "\t'false' by default, so your lambda and/or k values are\n" + "\tbeing ignored.\n"); painCave.isFatal = 0; simError(); } @@ -1579,6 +1661,7 @@ void SimSetup::mpiMolDivide(void){ mpiSim->divideLabor(); globalAtomIndex = mpiSim->getGlobalAtomIndex(); + globalGroupIndex = mpiSim->getGlobalGroupIndex(); //globalMolIndex = mpiSim->getGlobalMolIndex(); // set up the local variables