--- branches/development/src/brains/SimInfo.cpp 2010/12/27 18:35:59 1529 +++ branches/development/src/brains/SimInfo.cpp 2010/12/31 18:31:56 1535 @@ -54,18 +54,13 @@ #include "math/Vector3.hpp" #include "primitives/Molecule.hpp" #include "primitives/StuntDouble.hpp" -#include "UseTheForce/fCutoffPolicy.h" -#include "UseTheForce/DarkSide/fSwitchingFunctionType.h" -#include "UseTheForce/doForces_interface.h" #include "UseTheForce/DarkSide/neighborLists_interface.h" -#include "UseTheForce/DarkSide/switcheroo_interface.h" #include "utils/MemoryUtils.hpp" #include "utils/simError.h" #include "selection/SelectionManager.hpp" #include "io/ForceFieldOptions.hpp" #include "UseTheForce/ForceField.hpp" -#include "nonbonded/InteractionManager.hpp" - +#include "nonbonded/SwitchingFunction.hpp" #ifdef IS_MPI #include "UseTheForce/mpiComponentPlan.h" @@ -655,28 +650,29 @@ namespace OpenMD { moleculeStamps_.push_back(molStamp); molStampIds_.insert(molStampIds_.end(), nmol, curStampId); } - - void SimInfo::update() { - setupSimType(); - setupCutoffRadius(); - setupSwitchingRadius(); - setupCutoffMethod(); - setupSkinThickness(); - setupSwitchingFunction(); - setupAccumulateBoxDipole(); -#ifdef IS_MPI - setupFortranParallel(); -#endif - setupFortranSim(); - fortranInitialized_ = true; - + /** + * update + * + * Performs the global checks and variable settings after the + * objects have been created. + * + */ + void SimInfo::update() { + setupSimVariables(); 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; @@ -689,110 +685,70 @@ namespace OpenMD { atomTypes.insert(atom->getAtomType()); } } - return atomTypes; - } - /** - * setupCutoffRadius - * - * 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. - */ - void SimInfo::setupCutoffRadius() { - - if (simParams_->haveCutoffRadius()) { - cutoffRadius_ = simParams_->getCutoffRadius(); - } else { - if (usesElectrostaticAtoms_) { - sprintf(painCave.errMsg, - "SimInfo Warning: 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; - 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 Warning: No value was set for the cutoffRadius.\n" - "\tOpenMD will use %lf angstroms.\n", - cutoffRadius_); - painCave.isFatal = 0; - simError(); - } - } +#ifdef IS_MPI + + // loop over the found atom types on this processor, and add their + // numerical idents to a vector: + + vector foundTypes; + set::iterator i; + for (i = atomTypes.begin(); i != atomTypes.end(); ++i) + foundTypes.push_back( (*i)->getIdent() ); + + // 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); - InteractionManager::Instance()->setCutoffRadius(cutoffRadius_); - } - - /** - * setupSwitchingRadius - * - * 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::setupSwitchingRadius() { + // 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_->haveSwitchingRadius()) { - switchingRadius_ = simParams_->getSwitchingRadius(); - if (switchingRadius_ > cutoffRadius_) { - sprintf(painCave.errMsg, - "SimInfo Error: switchingRadius (%f) is larger than cutoffRadius(%f)\n", - switchingRadius_, cutoffRadius_); - painCave.isFatal = 1; - simError(); + MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT, + &ftGlobal[0], &counts[0], &disps[0], MPI::INT); - } - } else { - switchingRadius_ = 0.85 * cutoffRadius_; - sprintf(painCave.errMsg, - "SimInfo Warning: 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; - simError(); - } - InteractionManager::Instance()->setSwitchingRadius(switchingRadius_); + // 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; @@ -822,17 +778,11 @@ namespace OpenMD { fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_; } - void SimInfo::setupFortranSim() { + 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 @@ -867,7 +817,8 @@ namespace OpenMD { } } - //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) + //fill ident array of local atoms (it is actually ident of + //AtomType, it is so confusing !!!) vector identArray; //to avoid memory reallocation, reserve enough space identArray @@ -927,23 +878,12 @@ namespace OpenMD { setNeighbors(&nlistNeighbors); } - - } - - - void SimInfo::setupFortranParallel() { #ifdef IS_MPI - //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex + //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; for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { @@ -983,47 +923,8 @@ namespace OpenMD { sprintf(checkPointMsg, " mpiRefresh successful.\n"); errorCheckPoint(); - #endif - } - - - void SimInfo::setupSwitchingFunction() { - int ft = CUBIC; - - 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 error: Unknown switchingFunctionType. (Input file specified %s .)\n" - "\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".", - funcType.c_str() ); - painCave.isFatal = 1; - simError(); - } - } - } - - // send switching function notification to switcheroo - setFunctionType(&ft); - - } - - void SimInfo::setupAccumulateBoxDipole() { - - // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true - if ( simParams_->haveAccumulateBoxDipole() ) - if ( simParams_->getAccumulateBoxDipole() ) { - calcBoxDipole_ = true; - } - + fortranInitialized_ = true; } void SimInfo::addProperty(GenericData* genData) {