--- branches/development/src/brains/SimInfo.cpp 2010/12/29 19:59:21 1532 +++ branches/development/src/brains/SimInfo.cpp 2011/04/27 21:49:59 1550 @@ -54,8 +54,6 @@ #include "math/Vector3.hpp" #include "primitives/Molecule.hpp" #include "primitives/StuntDouble.hpp" -#include "UseTheForce/doForces_interface.h" -#include "UseTheForce/DarkSide/neighborLists_interface.h" #include "utils/MemoryUtils.hpp" #include "utils/simError.h" #include "selection/SelectionManager.hpp" @@ -63,12 +61,6 @@ #include "UseTheForce/ForceField.hpp" #include "nonbonded/SwitchingFunction.hpp" - -#ifdef IS_MPI -#include "UseTheForce/mpiComponentPlan.h" -#include "UseTheForce/DarkSide/simParallel_interface.h" -#endif - using namespace std; namespace OpenMD { @@ -133,7 +125,13 @@ namespace OpenMD { //equal to the total number of atoms minus number of atoms belong to //cutoff group defined in meta-data file plus the number of cutoff //groups defined in meta-data file + std::cerr << "nGA = " << nGlobalAtoms_ << "\n"; + std::cerr << "nCA = " << nCutoffAtoms << "\n"; + std::cerr << "nG = " << nGroups << "\n"; + nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; + + std::cerr << "nGCG = " << nGlobalCutoffGroups_ << "\n"; //every free atom (atom does not belong to rigid bodies) is an //integrable object therefore the total number of integrable objects @@ -657,29 +655,24 @@ namespace OpenMD { /** * update * - * Performs the global checks and variable settings after the objects have been - * created. + * Performs the global checks and variable settings after the + * objects have been created. * */ - void SimInfo::update() { - + void SimInfo::update() { setupSimVariables(); - setupCutoffs(); - setupSwitching(); - setupElectrostatics(); - setupNeighborlists(); - -#ifdef IS_MPI - setupFortranParallel(); -#endif - setupFortranSim(); - fortranInitialized_ = true; - calcNdf(); calcNdfRaw(); calcNdfTrans(); } + /** + * getSimulatedAtomTypes + * + * Returns an STL set of AtomType* that are actually present in this + * simulation. Must query all processors to assemble this information. + * + */ set SimInfo::getSimulatedAtomTypes() { SimInfo::MoleculeIterator mi; Molecule* mol; @@ -692,182 +685,70 @@ namespace OpenMD { atomTypes.insert(atom->getAtomType()); } } - return atomTypes; - } - /** - * setupCutoffs - * - * Sets the values of cutoffRadius and cutoffMethod - * - * cutoffRadius : realType - * If the cutoffRadius was explicitly set, use that value. - * If the cutoffRadius was not explicitly set: - * Are there electrostatic atoms? Use 12.0 Angstroms. - * No electrostatic atoms? Poll the atom types present in the - * simulation for suggested cutoff values (e.g. 2.5 * sigma). - * Use the maximum suggested value that was found. - * - * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, SHIFTED_POTENTIAL) - * If cutoffMethod was explicitly set, use that choice. - * If cutoffMethod was not explicitly set, use SHIFTED_FORCE - */ - void SimInfo::setupCutoffs() { - - if (simParams_->haveCutoffRadius()) { - cutoffRadius_ = simParams_->getCutoffRadius(); - } else { - if (usesElectrostaticAtoms_) { - sprintf(painCave.errMsg, - "SimInfo: No value was set for the cutoffRadius.\n" - "\tOpenMD will use a default value of 12.0 angstroms" - "\tfor the cutoffRadius.\n"); - painCave.isFatal = 0; - painCave.severity = OPENMD_INFO; - simError(); - cutoffRadius_ = 12.0; - } else { - RealType thisCut; - set::iterator i; - set atomTypes; - atomTypes = getSimulatedAtomTypes(); - for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { - thisCut = InteractionManager::Instance()->getSuggestedCutoffRadius((*i)); - cutoffRadius_ = max(thisCut, cutoffRadius_); - } - sprintf(painCave.errMsg, - "SimInfo: No value was set for the cutoffRadius.\n" - "\tOpenMD will use %lf angstroms.\n", - cutoffRadius_); - painCave.isFatal = 0; - painCave.severity = OPENMD_INFO; - simError(); - } - } +#ifdef IS_MPI - InteractionManager::Instance()->setCutoffRadius(cutoffRadius_); - - map stringToCutoffMethod; - stringToCutoffMethod["HARD"] = HARD; - stringToCutoffMethod["SWITCHING_FUNCTION"] = SWITCHING_FUNCTION; - stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL; - stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE; - - if (simParams_->haveCutoffMethod()) { - string cutMeth = toUpperCopy(simParams_->getCutoffMethod()); - map::iterator i; - i = stringToCutoffMethod.find(cutMeth); - if (i == stringToCutoffMethod.end()) { - sprintf(painCave.errMsg, - "SimInfo: Could not find chosen cutoffMethod %s\n" - "\tShould be one of: " - "HARD, SWITCHING_FUNCTION, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n", - cutMeth.c_str()); - painCave.isFatal = 1; - painCave.severity = OPENMD_ERROR; - simError(); - } else { - cutoffMethod_ = i->second; - } - } else { - sprintf(painCave.errMsg, - "SimInfo: No value was set for the cutoffMethod.\n" - "\tOpenMD will use SHIFTED_FORCE.\n"); - painCave.isFatal = 0; - painCave.severity = OPENMD_INFO; - simError(); - cutoffMethod_ = SHIFTED_FORCE; - } + // loop over the found atom types on this processor, and add their + // numerical idents to a vector: - InteractionManager::Instance()->setCutoffMethod(cutoffMethod_); - } - - /** - * setupSwitching - * - * Sets the values of switchingRadius and - * If the switchingRadius was explicitly set, use that value (but check it) - * If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_ - */ - void SimInfo::setupSwitching() { - - if (simParams_->haveSwitchingRadius()) { - switchingRadius_ = simParams_->getSwitchingRadius(); - if (switchingRadius_ > cutoffRadius_) { - sprintf(painCave.errMsg, - "SimInfo: switchingRadius (%f) is larger than cutoffRadius(%f)\n", - switchingRadius_, cutoffRadius_); - painCave.isFatal = 1; - painCave.severity = OPENMD_ERROR; - simError(); - } - } else { - switchingRadius_ = 0.85 * cutoffRadius_; - sprintf(painCave.errMsg, - "SimInfo: No value was set for the switchingRadius.\n" - "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n" - "\tswitchingRadius = %f. for this simulation\n", switchingRadius_); - painCave.isFatal = 0; - painCave.severity = OPENMD_WARNING; - simError(); - } - - InteractionManager::Instance()->setSwitchingRadius(switchingRadius_); + vector foundTypes; + set::iterator i; + for (i = atomTypes.begin(); i != atomTypes.end(); ++i) + foundTypes.push_back( (*i)->getIdent() ); - SwitchingFunctionType ft; + // count_local holds the number of found types on this processor + int count_local = foundTypes.size(); + + // count holds the total number of found types on all processors + // (some will be redundant with the ones found locally): + int count; + MPI::COMM_WORLD.Allreduce(&count_local, &count, 1, MPI::INT, MPI::SUM); + + // create a vector to hold the globally found types, and resize it: + vector ftGlobal; + ftGlobal.resize(count); + vector counts; + + int nproc = MPI::COMM_WORLD.Get_size(); + counts.resize(nproc); + vector disps; + disps.resize(nproc); + + // now spray out the foundTypes to all the other processors: - if (simParams_->haveSwitchingFunctionType()) { - string funcType = simParams_->getSwitchingFunctionType(); - toUpper(funcType); - if (funcType == "CUBIC") { - ft = cubic; - } else { - if (funcType == "FIFTH_ORDER_POLYNOMIAL") { - ft = fifth_order_poly; - } else { - // throw error - sprintf( painCave.errMsg, - "SimInfo : Unknown switchingFunctionType. (Input file specified %s .)\n" - "\tswitchingFunctionType must be one of: " - "\"cubic\" or \"fifth_order_polynomial\".", - funcType.c_str() ); - painCave.isFatal = 1; - painCave.severity = OPENMD_ERROR; - simError(); - } - } - } + MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT, + &ftGlobal[0], &counts[0], &disps[0], MPI::INT); - InteractionManager::Instance()->setSwitchingFunctionType(ft); + // foundIdents is a stl set, so inserting an already found ident + // will have no effect. + set foundIdents; + vector::iterator j; + for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j) + foundIdents.insert((*j)); + + // now iterate over the foundIdents and get the actual atom types + // that correspond to these: + set::iterator it; + for (it = foundIdents.begin(); it != foundIdents.end(); ++it) + atomTypes.insert( forceField_->getAtomType((*it)) ); + +#endif + + return atomTypes; } - /** - * setupSkinThickness - * - * If the skinThickness was explicitly set, use that value (but check it) - * If the skinThickness was not explicitly set: use 1.0 angstroms - */ - void SimInfo::setupSkinThickness() { - if (simParams_->haveSkinThickness()) { - skinThickness_ = simParams_->getSkinThickness(); - } else { - skinThickness_ = 1.0; - sprintf(painCave.errMsg, - "SimInfo Warning: No value was set for the skinThickness.\n" - "\tOpenMD will use a default value of %f Angstroms\n" - "\tfor this simulation\n", skinThickness_); - painCave.isFatal = 0; - simError(); - } - } + void SimInfo::setupSimVariables() { + useAtomicVirial_ = simParams_->getUseAtomicVirial(); + // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true + calcBoxDipole_ = false; + if ( simParams_->haveAccumulateBoxDipole() ) + if ( simParams_->getAccumulateBoxDipole() ) { + calcBoxDipole_ = true; + } - void SimInfo::setupSimType() { set::iterator i; set atomTypes; - atomTypes = getSimulatedAtomTypes(); - - useAtomicVirial_ = simParams_->getUseAtomicVirial(); - + atomTypes = getSimulatedAtomTypes(); int usesElectrostatic = 0; int usesMetallic = 0; int usesDirectional = 0; @@ -897,17 +778,51 @@ namespace OpenMD { fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_; } - void SimInfo::setupFortranSim() { + + vector SimInfo::getGlobalAtomIndices() { + SimInfo::MoleculeIterator mi; + Molecule* mol; + Molecule::AtomIterator ai; + Atom* atom; + + vector GlobalAtomIndices(getNAtoms(), 0); + + for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { + + for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { + GlobalAtomIndices[atom->getLocalIndex()] = atom->getGlobalIndex(); + } + } + return GlobalAtomIndices; + } + + + vector SimInfo::getGlobalGroupIndices() { + SimInfo::MoleculeIterator mi; + Molecule* mol; + Molecule::CutoffGroupIterator ci; + CutoffGroup* cg; + + vector GlobalGroupIndices; + + for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { + + //local index of cutoff group is trivial, it only depends on the + //order of travesing + for (cg = mol->beginCutoffGroup(ci); cg != NULL; + cg = mol->nextCutoffGroup(ci)) { + GlobalGroupIndices.push_back(cg->getGlobalIndex()); + } + } + return GlobalGroupIndices; + } + + + void SimInfo::setupFortran() { int isError; int nExclude, nOneTwo, nOneThree, nOneFour; vector fortranGlobalGroupMembership; - notifyFortranSkinThickness(&skinThickness_); - - int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0; - int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0; - notifyFortranCutoffs(&cutoffRadius_, &switchingRadius_, &ljsp, &ljsf); - isError = 0; //globalGroupMembership_ is filled by SimCreator @@ -942,15 +857,13 @@ namespace OpenMD { } } - //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) - vector identArray; + // Build the identArray_ - //to avoid memory reallocation, reserve enough space identArray - identArray.reserve(getNAtoms()); - + identArray_.clear(); + identArray_.reserve(getNAtoms()); for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { - identArray.push_back(atom->getIdent()); + identArray_.push_back(atom->getIdent()); } } @@ -973,108 +886,72 @@ namespace OpenMD { int* oneThreeList = oneThreeInteractions_.getPairList(); int* oneFourList = oneFourInteractions_.getPairList(); - setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], - &nExclude, excludeList, - &nOneTwo, oneTwoList, - &nOneThree, oneThreeList, - &nOneFour, oneFourList, - &molMembershipArray[0], &mfact[0], &nCutoffGroups_, - &fortranGlobalGroupMembership[0], &isError); + //setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray_[0], + // &nExclude, excludeList, + // &nOneTwo, oneTwoList, + // &nOneThree, oneThreeList, + // &nOneFour, oneFourList, + // &molMembershipArray[0], &mfact[0], &nCutoffGroups_, + // &fortranGlobalGroupMembership[0], &isError); - if( isError ){ - - sprintf( painCave.errMsg, - "There was an error setting the simulation information in fortran.\n" ); - painCave.isFatal = 1; - painCave.severity = OPENMD_ERROR; - simError(); - } + // if( isError ){ + // + // sprintf( painCave.errMsg, + // "There was an error setting the simulation information in fortran.\n" ); + // painCave.isFatal = 1; + // painCave.severity = OPENMD_ERROR; + // simError(); + //} - sprintf( checkPointMsg, - "succesfully sent the simulation information to fortran.\n"); + // sprintf( checkPointMsg, + // "succesfully sent the simulation information to fortran.\n"); - errorCheckPoint(); + // errorCheckPoint(); // Setup number of neighbors in neighbor list if present - if (simParams_->haveNeighborListNeighbors()) { - int nlistNeighbors = simParams_->getNeighborListNeighbors(); - setNeighbors(&nlistNeighbors); - } - - - } - - - void SimInfo::setupFortranParallel() { + //if (simParams_->haveNeighborListNeighbors()) { + // int nlistNeighbors = simParams_->getNeighborListNeighbors(); + // setNeighbors(&nlistNeighbors); + //} + #ifdef IS_MPI - //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex - vector localToGlobalAtomIndex(getNAtoms(), 0); - vector localToGlobalCutoffGroupIndex; - SimInfo::MoleculeIterator mi; - Molecule::AtomIterator ai; - Molecule::CutoffGroupIterator ci; - Molecule* mol; - Atom* atom; - CutoffGroup* cg; - mpiSimData parallelData; - int isError; + // mpiSimData parallelData; - for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { - - //local index(index in DataStorge) of atom is important - for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { - localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; - } - - //local index of cutoff group is trivial, it only depends on the order of travesing - for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { - localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); - } - - } - //fill up mpiSimData struct - parallelData.nMolGlobal = getNGlobalMolecules(); - parallelData.nMolLocal = getNMolecules(); - parallelData.nAtomsGlobal = getNGlobalAtoms(); - parallelData.nAtomsLocal = getNAtoms(); - parallelData.nGroupsGlobal = getNGlobalCutoffGroups(); - parallelData.nGroupsLocal = getNCutoffGroups(); - parallelData.myNode = worldRank; - MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors)); + // parallelData.nMolGlobal = getNGlobalMolecules(); + // parallelData.nMolLocal = getNMolecules(); + // parallelData.nAtomsGlobal = getNGlobalAtoms(); + // parallelData.nAtomsLocal = getNAtoms(); + // parallelData.nGroupsGlobal = getNGlobalCutoffGroups(); + // parallelData.nGroupsLocal = getNCutoffGroups(); + // parallelData.myNode = worldRank; + // MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors)); //pass mpiSimData struct and index arrays to fortran - setFsimParallel(¶llelData, &(parallelData.nAtomsLocal), - &localToGlobalAtomIndex[0], &(parallelData.nGroupsLocal), - &localToGlobalCutoffGroupIndex[0], &isError); + //setFsimParallel(¶llelData, &(parallelData.nAtomsLocal), + // &localToGlobalAtomIndex[0], &(parallelData.nGroupsLocal), + // &localToGlobalCutoffGroupIndex[0], &isError); - if (isError) { - sprintf(painCave.errMsg, - "mpiRefresh errror: fortran didn't like something we gave it.\n"); - painCave.isFatal = 1; - simError(); - } + // if (isError) { + // sprintf(painCave.errMsg, + // "mpiRefresh errror: fortran didn't like something we gave it.\n"); + // painCave.isFatal = 1; + // simError(); + // } - sprintf(checkPointMsg, " mpiRefresh successful.\n"); - errorCheckPoint(); - + // sprintf(checkPointMsg, " mpiRefresh successful.\n"); + // errorCheckPoint(); #endif - } - - void SimInfo::setupSwitchingFunction() { - - } - - void SimInfo::setupAccumulateBoxDipole() { - - // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true - if ( simParams_->haveAccumulateBoxDipole() ) - if ( simParams_->getAccumulateBoxDipole() ) { - calcBoxDipole_ = true; - } - + // initFortranFF(&isError); + // if (isError) { + // sprintf(painCave.errMsg, + // "initFortranFF errror: fortran didn't like something we gave it.\n"); + // painCave.isFatal = 1; + // simError(); + // } + // fortranInitialized_ = true; } void SimInfo::addProperty(GenericData* genData) { @@ -1111,9 +988,11 @@ namespace OpenMD { Molecule* mol; RigidBody* rb; Atom* atom; + CutoffGroup* cg; SimInfo::MoleculeIterator mi; Molecule::RigidBodyIterator rbIter; - Molecule::AtomIterator atomIter;; + Molecule::AtomIterator atomIter; + Molecule::CutoffGroupIterator cgIter; for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { @@ -1124,6 +1003,10 @@ namespace OpenMD { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { rb->setSnapshotManager(sman_); } + + for (cg = mol->beginCutoffGroup(cgIter); cg != NULL; cg = mol->nextCutoffGroup(cgIter)) { + cg->setSnapshotManager(sman_); + } } }