--- branches/development/src/brains/SimInfo.cpp 2010/10/03 22:18:59 1505 +++ branches/development/src/brains/SimInfo.cpp 2010/12/17 20:11:05 1528 @@ -64,6 +64,7 @@ #include "selection/SelectionManager.hpp" #include "io/ForceFieldOptions.hpp" #include "UseTheForce/ForceField.hpp" +#include "nonbonded/InteractionManager.hpp" #ifdef IS_MPI @@ -71,16 +72,8 @@ #include "UseTheForce/DarkSide/simParallel_interface.h" #endif +using namespace std; namespace OpenMD { - std::set getRigidSet(int index, std::map >& container) { - std::map >::iterator i = container.find(index); - std::set result; - if (i != container.end()) { - result = i->second; - } - - return result; - } SimInfo::SimInfo(ForceField* ff, Globals* simParams) : forceField_(ff), simParams_(simParams), @@ -90,76 +83,75 @@ namespace OpenMD { nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0), nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), sman_(NULL), fortranInitialized_(false), - calcBoxDipole_(false), useAtomicVirial_(true) { - - - MoleculeStamp* molStamp; - int nMolWithSameStamp; - int nCutoffAtoms = 0; // number of atoms belong to cutoff groups - int nGroups = 0; //total cutoff groups defined in meta-data file - CutoffGroupStamp* cgStamp; - RigidBodyStamp* rbStamp; - int nRigidAtoms = 0; - - std::vector components = simParams->getComponents(); + calcBoxDipole_(false), useAtomicVirial_(true) { + + MoleculeStamp* molStamp; + int nMolWithSameStamp; + int nCutoffAtoms = 0; // number of atoms belong to cutoff groups + int nGroups = 0; //total cutoff groups defined in meta-data file + CutoffGroupStamp* cgStamp; + RigidBodyStamp* rbStamp; + int nRigidAtoms = 0; + + vector components = simParams->getComponents(); + + for (vector::iterator i = components.begin(); i !=components.end(); ++i) { + molStamp = (*i)->getMoleculeStamp(); + nMolWithSameStamp = (*i)->getNMol(); - for (std::vector::iterator i = components.begin(); i !=components.end(); ++i) { - molStamp = (*i)->getMoleculeStamp(); - nMolWithSameStamp = (*i)->getNMol(); - - addMoleculeStamp(molStamp, nMolWithSameStamp); - - //calculate atoms in molecules - nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; - - //calculate atoms in cutoff groups - int nAtomsInGroups = 0; - int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); - - for (int j=0; j < nCutoffGroupsInStamp; j++) { - cgStamp = molStamp->getCutoffGroupStamp(j); - nAtomsInGroups += cgStamp->getNMembers(); - } - - nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; - - nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; - - //calculate atoms in rigid bodies - int nAtomsInRigidBodies = 0; - int nRigidBodiesInStamp = molStamp->getNRigidBodies(); - - for (int j=0; j < nRigidBodiesInStamp; j++) { - rbStamp = molStamp->getRigidBodyStamp(j); - nAtomsInRigidBodies += rbStamp->getNMembers(); - } - - nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; - nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; - + addMoleculeStamp(molStamp, nMolWithSameStamp); + + //calculate atoms in molecules + nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; + + //calculate atoms in cutoff groups + int nAtomsInGroups = 0; + int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); + + for (int j=0; j < nCutoffGroupsInStamp; j++) { + cgStamp = molStamp->getCutoffGroupStamp(j); + nAtomsInGroups += cgStamp->getNMembers(); } - - //every free atom (atom does not belong to cutoff groups) is a cutoff - //group therefore the total number of cutoff groups in the system is - //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 - nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; - - //every free atom (atom does not belong to rigid bodies) is an - //integrable object therefore the total number of integrable objects - //in the system is equal to the total number of atoms minus number of - //atoms belong to rigid body defined in meta-data file plus the number - //of rigid bodies defined in meta-data file - nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms - + nGlobalRigidBodies_; - - nGlobalMols_ = molStampIds_.size(); - molToProcMap_.resize(nGlobalMols_); - } - + + nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; + + nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; + + //calculate atoms in rigid bodies + int nAtomsInRigidBodies = 0; + int nRigidBodiesInStamp = molStamp->getNRigidBodies(); + + for (int j=0; j < nRigidBodiesInStamp; j++) { + rbStamp = molStamp->getRigidBodyStamp(j); + nAtomsInRigidBodies += rbStamp->getNMembers(); + } + + nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; + nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; + + } + + //every free atom (atom does not belong to cutoff groups) is a cutoff + //group therefore the total number of cutoff groups in the system is + //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 + nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; + + //every free atom (atom does not belong to rigid bodies) is an + //integrable object therefore the total number of integrable objects + //in the system is equal to the total number of atoms minus number of + //atoms belong to rigid body defined in meta-data file plus the number + //of rigid bodies defined in meta-data file + nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + + nGlobalRigidBodies_; + + nGlobalMols_ = molStampIds_.size(); + molToProcMap_.resize(nGlobalMols_); + } + SimInfo::~SimInfo() { - std::map::iterator i; + map::iterator i; for (i = molecules_.begin(); i != molecules_.end(); ++i) { delete i->second; } @@ -170,25 +162,15 @@ namespace OpenMD { delete forceField_; } - int SimInfo::getNGlobalConstraints() { - int nGlobalConstraints; -#ifdef IS_MPI - MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, - MPI_COMM_WORLD); -#else - nGlobalConstraints = nConstraints_; -#endif - return nGlobalConstraints; - } bool SimInfo::addMolecule(Molecule* mol) { MoleculeIterator i; - + i = molecules_.find(mol->getGlobalIndex()); if (i == molecules_.end() ) { - - molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol)); - + + molecules_.insert(make_pair(mol->getGlobalIndex(), mol)); + nAtoms_ += mol->getNAtoms(); nBonds_ += mol->getNBonds(); nBends_ += mol->getNBends(); @@ -198,15 +180,15 @@ namespace OpenMD { nIntegrableObjects_ += mol->getNIntegrableObjects(); nCutoffGroups_ += mol->getNCutoffGroups(); nConstraints_ += mol->getNConstraintPairs(); - + addInteractionPairs(mol); - + return true; } else { return false; } } - + bool SimInfo::removeMolecule(Molecule* mol) { MoleculeIterator i; i = molecules_.find(mol->getGlobalIndex()); @@ -234,8 +216,6 @@ namespace OpenMD { } else { return false; } - - } @@ -253,7 +233,7 @@ namespace OpenMD { void SimInfo::calcNdf() { int ndf_local; MoleculeIterator i; - std::vector::iterator j; + vector::iterator j; Molecule* mol; StuntDouble* integrableObject; @@ -304,7 +284,7 @@ namespace OpenMD { int ndfRaw_local; MoleculeIterator i; - std::vector::iterator j; + vector::iterator j; Molecule* mol; StuntDouble* integrableObject; @@ -353,10 +333,10 @@ namespace OpenMD { void SimInfo::addInteractionPairs(Molecule* mol) { ForceFieldOptions& options_ = forceField_->getForceFieldOptions(); - std::vector::iterator bondIter; - std::vector::iterator bendIter; - std::vector::iterator torsionIter; - std::vector::iterator inversionIter; + vector::iterator bondIter; + vector::iterator bendIter; + vector::iterator torsionIter; + vector::iterator inversionIter; Bond* bond; Bend* bend; Torsion* torsion; @@ -374,7 +354,7 @@ namespace OpenMD { // always be excluded. These are done at the bottom of this // function. - std::map > atomGroups; + map > atomGroups; Molecule::RigidBodyIterator rbIter; RigidBody* rb; Molecule::IntegrableObjectIterator ii; @@ -386,18 +366,18 @@ namespace OpenMD { if (integrableObject->isRigidBody()) { rb = static_cast(integrableObject); - std::vector atoms = rb->getAtoms(); - std::set rigidAtoms; + vector atoms = rb->getAtoms(); + set rigidAtoms; for (int i = 0; i < static_cast(atoms.size()); ++i) { rigidAtoms.insert(atoms[i]->getGlobalIndex()); } for (int i = 0; i < static_cast(atoms.size()); ++i) { - atomGroups.insert(std::map >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); + atomGroups.insert(map >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); } } else { - std::set oneAtomSet; + set oneAtomSet; oneAtomSet.insert(integrableObject->getGlobalIndex()); - atomGroups.insert(std::map >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); + atomGroups.insert(map >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); } } @@ -500,7 +480,7 @@ namespace OpenMD { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { - std::vector atoms = rb->getAtoms(); + vector atoms = rb->getAtoms(); for (int i = 0; i < static_cast(atoms.size()) -1 ; ++i) { for (int j = i + 1; j < static_cast(atoms.size()); ++j) { a = atoms[i]->getGlobalIndex(); @@ -514,10 +494,10 @@ namespace OpenMD { void SimInfo::removeInteractionPairs(Molecule* mol) { ForceFieldOptions& options_ = forceField_->getForceFieldOptions(); - std::vector::iterator bondIter; - std::vector::iterator bendIter; - std::vector::iterator torsionIter; - std::vector::iterator inversionIter; + vector::iterator bondIter; + vector::iterator bendIter; + vector::iterator torsionIter; + vector::iterator inversionIter; Bond* bond; Bend* bend; Torsion* torsion; @@ -527,7 +507,7 @@ namespace OpenMD { int c; int d; - std::map > atomGroups; + map > atomGroups; Molecule::RigidBodyIterator rbIter; RigidBody* rb; Molecule::IntegrableObjectIterator ii; @@ -539,18 +519,18 @@ namespace OpenMD { if (integrableObject->isRigidBody()) { rb = static_cast(integrableObject); - std::vector atoms = rb->getAtoms(); - std::set rigidAtoms; + vector atoms = rb->getAtoms(); + set rigidAtoms; for (int i = 0; i < static_cast(atoms.size()); ++i) { rigidAtoms.insert(atoms[i]->getGlobalIndex()); } for (int i = 0; i < static_cast(atoms.size()); ++i) { - atomGroups.insert(std::map >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); + atomGroups.insert(map >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); } } else { - std::set oneAtomSet; + set oneAtomSet; oneAtomSet.insert(integrableObject->getGlobalIndex()); - atomGroups.insert(std::map >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); + atomGroups.insert(map >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); } } @@ -653,7 +633,7 @@ namespace OpenMD { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { - std::vector atoms = rb->getAtoms(); + vector atoms = rb->getAtoms(); for (int i = 0; i < static_cast(atoms.size()) -1 ; ++i) { for (int j = i + 1; j < static_cast(atoms.size()); ++j) { a = atoms[i]->getGlobalIndex(); @@ -679,213 +659,183 @@ namespace OpenMD { void SimInfo::update() { setupSimType(); + setupCutoffRadius(); + setupSwitchingRadius(); + setupCutoffMethod(); + setupSkinThickness(); + setupSwitchingFunction(); + setupAccumulateBoxDipole(); #ifdef IS_MPI setupFortranParallel(); #endif - setupFortranSim(); + fortranInitialized_ = true; - //setup fortran force field - /** @deprecate */ - int isError = 0; - - setupCutoff(); - - setupElectrostaticSummationMethod( isError ); - setupSwitchingFunction(); - setupAccumulateBoxDipole(); - - if(isError){ - sprintf( painCave.errMsg, - "ForceField error: There was an error initializing the forceField in fortran.\n" ); - painCave.isFatal = 1; - simError(); - } - calcNdf(); calcNdfRaw(); calcNdfTrans(); - - fortranInitialized_ = true; } - - std::set SimInfo::getUniqueAtomTypes() { + + set SimInfo::getSimulatedAtomTypes() { SimInfo::MoleculeIterator mi; Molecule* mol; Molecule::AtomIterator ai; Atom* atom; - std::set atomTypes; - + set atomTypes; + for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { - + for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { atomTypes.insert(atom->getAtomType()); } - + } - + return atomTypes; } - void SimInfo::setupSimType() { - std::set::iterator i; - std::set atomTypes; - atomTypes = getUniqueAtomTypes(); - - int useLennardJones = 0; - int useElectrostatic = 0; - int useEAM = 0; - int useSC = 0; - int useCharge = 0; - int useDirectional = 0; - int useDipole = 0; - int useGayBerne = 0; - int useSticky = 0; - int useStickyPower = 0; - int useShape = 0; - int useFLARB = 0; //it is not in AtomType yet - int useDirectionalAtom = 0; - int useElectrostatics = 0; - //usePBC and useRF are from simParams - int usePBC = simParams_->getUsePeriodicBoundaryConditions(); - int useRF; - int useSF; - int useSP; - int useBoxDipole; - - std::string myMethod; - - // set the useRF logical - useRF = 0; - useSF = 0; - useSP = 0; - useBoxDipole = 0; - - if (simParams_->haveElectrostaticSummationMethod()) { - std::string myMethod = simParams_->getElectrostaticSummationMethod(); - toUpper(myMethod); - if (myMethod == "REACTION_FIELD"){ - useRF = 1; - } else if (myMethod == "SHIFTED_FORCE"){ - useSF = 1; - } else if (myMethod == "SHIFTED_POTENTIAL"){ - useSP = 1; - } + /** + * 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(); + } } + + 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() { - if (simParams_->haveAccumulateBoxDipole()) - if (simParams_->getAccumulateBoxDipole()) - useBoxDipole = 1; + 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(); + } + } 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_); + } + + /** + * 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::setupSimType() { + set::iterator i; + set atomTypes; + atomTypes = getSimulatedAtomTypes(); + useAtomicVirial_ = simParams_->getUseAtomicVirial(); + int usesElectrostatic = 0; + int usesMetallic = 0; + int usesDirectional = 0; //loop over all of the atom types for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { - useLennardJones |= (*i)->isLennardJones(); - useElectrostatic |= (*i)->isElectrostatic(); - useEAM |= (*i)->isEAM(); - useSC |= (*i)->isSC(); - useCharge |= (*i)->isCharge(); - useDirectional |= (*i)->isDirectional(); - useDipole |= (*i)->isDipole(); - useGayBerne |= (*i)->isGayBerne(); - useSticky |= (*i)->isSticky(); - useStickyPower |= (*i)->isStickyPower(); - useShape |= (*i)->isShape(); + usesElectrostatic |= (*i)->isElectrostatic(); + usesMetallic |= (*i)->isMetal(); + usesDirectional |= (*i)->isDirectional(); } - if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) { - useDirectionalAtom = 1; - } - - if (useCharge || useDipole) { - useElectrostatics = 1; - } - #ifdef IS_MPI int temp; + temp = usesDirectional; + MPI_Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - temp = usePBC; - MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); + temp = usesMetallic; + MPI_Allreduce(&temp, &usesMetallicAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - temp = useDirectionalAtom; - MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useLennardJones; - MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useElectrostatics; - MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useCharge; - MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useDipole; - MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useSticky; - MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useStickyPower; - MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useGayBerne; - MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useEAM; - MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useSC; - MPI_Allreduce(&temp, &useSC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useShape; - MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useFLARB; - MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useRF; - MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useSF; - MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useSP; - MPI_Allreduce(&temp, &useSP, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useBoxDipole; - MPI_Allreduce(&temp, &useBoxDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - - temp = useAtomicVirial_; - MPI_Allreduce(&temp, &useAtomicVirial_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); - + temp = usesElectrostatic; + MPI_Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); #endif - fInfo_.SIM_uses_PBC = usePBC; - fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom; - fInfo_.SIM_uses_LennardJones = useLennardJones; - fInfo_.SIM_uses_Electrostatics = useElectrostatics; - fInfo_.SIM_uses_Charges = useCharge; - fInfo_.SIM_uses_Dipoles = useDipole; - fInfo_.SIM_uses_Sticky = useSticky; - fInfo_.SIM_uses_StickyPower = useStickyPower; - fInfo_.SIM_uses_GayBerne = useGayBerne; - fInfo_.SIM_uses_EAM = useEAM; - fInfo_.SIM_uses_SC = useSC; - fInfo_.SIM_uses_Shapes = useShape; - fInfo_.SIM_uses_FLARB = useFLARB; - fInfo_.SIM_uses_RF = useRF; - fInfo_.SIM_uses_SF = useSF; - fInfo_.SIM_uses_SP = useSP; - fInfo_.SIM_uses_BoxDipole = useBoxDipole; - fInfo_.SIM_uses_AtomicVirial = useAtomicVirial_; + fInfo_.SIM_uses_PBC = usesPeriodicBoundaries_; + fInfo_.SIM_uses_DirectionalAtoms = usesDirectionalAtoms_; + fInfo_.SIM_uses_MetallicAtoms = usesMetallicAtoms_; + fInfo_.SIM_requires_SkipCorrection = usesElectrostaticAtoms_; + fInfo_.SIM_requires_SelfCorrection = usesElectrostaticAtoms_; + fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_; } void SimInfo::setupFortranSim() { int isError; int nExclude, nOneTwo, nOneThree, nOneFour; - std::vector fortranGlobalGroupMembership; + 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 @@ -894,7 +844,7 @@ namespace OpenMD { } //calculate mass ratio of cutoff group - std::vector mfact; + vector mfact; SimInfo::MoleculeIterator mi; Molecule* mol; Molecule::CutoffGroupIterator ci; @@ -921,7 +871,7 @@ namespace OpenMD { } //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) - std::vector identArray; + vector identArray; //to avoid memory reallocation, reserve enough space identArray identArray.reserve(getNAtoms()); @@ -934,7 +884,7 @@ namespace OpenMD { //fill molMembershipArray //molMembershipArray is filled by SimCreator - std::vector molMembershipArray(nGlobalAtoms_); + vector molMembershipArray(nGlobalAtoms_); for (int i = 0; i < nGlobalAtoms_; i++) { molMembershipArray[i] = globalMolMembership_[i] + 1; } @@ -987,8 +937,8 @@ namespace OpenMD { void SimInfo::setupFortranParallel() { #ifdef IS_MPI //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex - std::vector localToGlobalAtomIndex(getNAtoms(), 0); - std::vector localToGlobalCutoffGroupIndex; + vector localToGlobalAtomIndex(getNAtoms(), 0); + vector localToGlobalCutoffGroupIndex; SimInfo::MoleculeIterator mi; Molecule::AtomIterator ai; Molecule::CutoffGroupIterator ci; @@ -1038,260 +988,14 @@ namespace OpenMD { errorCheckPoint(); #endif - } - - void SimInfo::setupCutoff() { - - ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); - - // Check the cutoff policy - int cp = TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default - - // Set LJ shifting bools to false - ljsp_ = 0; - ljsf_ = 0; - - std::string myPolicy; - if (forceFieldOptions_.haveCutoffPolicy()){ - myPolicy = forceFieldOptions_.getCutoffPolicy(); - }else if (simParams_->haveCutoffPolicy()) { - myPolicy = simParams_->getCutoffPolicy(); - } - - if (!myPolicy.empty()){ - toUpper(myPolicy); - if (myPolicy == "MIX") { - cp = MIX_CUTOFF_POLICY; - } else { - if (myPolicy == "MAX") { - cp = MAX_CUTOFF_POLICY; - } else { - if (myPolicy == "TRADITIONAL") { - cp = TRADITIONAL_CUTOFF_POLICY; - } else { - // throw error - sprintf( painCave.errMsg, - "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() ); - painCave.isFatal = 1; - simError(); - } - } - } - } - notifyFortranCutoffPolicy(&cp); - - // Check the Skin Thickness for neighborlists - RealType skin; - if (simParams_->haveSkinThickness()) { - skin = simParams_->getSkinThickness(); - notifyFortranSkinThickness(&skin); - } - - // Check if the cutoff was set explicitly: - if (simParams_->haveCutoffRadius()) { - rcut_ = simParams_->getCutoffRadius(); - if (simParams_->haveSwitchingRadius()) { - rsw_ = simParams_->getSwitchingRadius(); - } else { - if (fInfo_.SIM_uses_Charges | - fInfo_.SIM_uses_Dipoles | - fInfo_.SIM_uses_RF) { - - rsw_ = 0.85 * rcut_; - sprintf(painCave.errMsg, - "SimCreator 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", rsw_); - painCave.isFatal = 0; - simError(); - } else { - rsw_ = rcut_; - sprintf(painCave.errMsg, - "SimCreator Warning: No value was set for the switchingRadius.\n" - "\tOpenMD will use the same value as the cutoffRadius.\n" - "\tswitchingRadius = %f. for this simulation\n", rsw_); - painCave.isFatal = 0; - simError(); - } - } - - if (simParams_->haveElectrostaticSummationMethod()) { - std::string myMethod = simParams_->getElectrostaticSummationMethod(); - toUpper(myMethod); - - if (myMethod == "SHIFTED_POTENTIAL") { - ljsp_ = 1; - } else if (myMethod == "SHIFTED_FORCE") { - ljsf_ = 1; - } - } - - notifyFortranCutoffs(&rcut_, &rsw_, &ljsp_, &ljsf_); - - } else { - - // For electrostatic atoms, we'll assume a large safe value: - if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { - sprintf(painCave.errMsg, - "SimCreator Warning: No value was set for the cutoffRadius.\n" - "\tOpenMD will use a default value of 15.0 angstroms" - "\tfor the cutoffRadius.\n"); - painCave.isFatal = 0; - simError(); - rcut_ = 15.0; - - if (simParams_->haveElectrostaticSummationMethod()) { - std::string myMethod = simParams_->getElectrostaticSummationMethod(); - toUpper(myMethod); - - // For the time being, we're tethering the LJ shifted behavior to the - // electrostaticSummationMethod keyword options - if (myMethod == "SHIFTED_POTENTIAL") { - ljsp_ = 1; - } else if (myMethod == "SHIFTED_FORCE") { - ljsf_ = 1; - } - if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") { - if (simParams_->haveSwitchingRadius()){ - sprintf(painCave.errMsg, - "SimInfo Warning: A value was set for the switchingRadius\n" - "\teven though the electrostaticSummationMethod was\n" - "\tset to %s\n", myMethod.c_str()); - painCave.isFatal = 1; - simError(); - } - } - } - - if (simParams_->haveSwitchingRadius()){ - rsw_ = simParams_->getSwitchingRadius(); - } else { - sprintf(painCave.errMsg, - "SimCreator Warning: No value was set for switchingRadius.\n" - "\tOpenMD will use a default value of\n" - "\t0.85 * cutoffRadius for the switchingRadius\n"); - painCave.isFatal = 0; - simError(); - rsw_ = 0.85 * rcut_; - } - - Electrostatic::setElectrostaticCutoffRadius(rcut_, rsw_); - notifyFortranCutoffs(&rcut_, &rsw_, &ljsp_, &ljsf_); - - } else { - // We didn't set rcut explicitly, and we don't have electrostatic atoms, so - // We'll punt and let fortran figure out the cutoffs later. - - notifyFortranYouAreOnYourOwn(); - - } - } } - - void SimInfo::setupElectrostaticSummationMethod( int isError ) { - - int errorOut; - ElectrostaticSummationMethod esm = NONE; - ElectrostaticScreeningMethod sm = UNDAMPED; - RealType alphaVal; - RealType dielectric; - - errorOut = isError; - - if (simParams_->haveElectrostaticSummationMethod()) { - std::string myMethod = simParams_->getElectrostaticSummationMethod(); - toUpper(myMethod); - if (myMethod == "NONE") { - esm = NONE; - } else { - if (myMethod == "SWITCHING_FUNCTION") { - esm = SWITCHING_FUNCTION; - } else { - if (myMethod == "SHIFTED_POTENTIAL") { - esm = SHIFTED_POTENTIAL; - } else { - if (myMethod == "SHIFTED_FORCE") { - esm = SHIFTED_FORCE; - } else { - if (myMethod == "REACTION_FIELD") { - esm = REACTION_FIELD; - dielectric = simParams_->getDielectric(); - if (!simParams_->haveDielectric()) { - // throw warning - sprintf( painCave.errMsg, - "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n" - "\tA default value of %f will be used for the dielectric.\n", dielectric); - painCave.isFatal = 0; - simError(); - } - } else { - // throw error - sprintf( painCave.errMsg, - "SimInfo error: Unknown electrostaticSummationMethod.\n" - "\t(Input file specified %s .)\n" - "\telectrostaticSummationMethod must be one of: \"none\",\n" - "\t\"shifted_potential\", \"shifted_force\", or \n" - "\t\"reaction_field\".\n", myMethod.c_str() ); - painCave.isFatal = 1; - simError(); - } - } - } - } - } - } - - if (simParams_->haveElectrostaticScreeningMethod()) { - std::string myScreen = simParams_->getElectrostaticScreeningMethod(); - toUpper(myScreen); - if (myScreen == "UNDAMPED") { - sm = UNDAMPED; - } else { - if (myScreen == "DAMPED") { - sm = DAMPED; - if (!simParams_->haveDampingAlpha()) { - // first set a cutoff dependent alpha value - // we assume alpha depends linearly with rcut from 0 to 20.5 ang - alphaVal = 0.5125 - rcut_* 0.025; - // for values rcut > 20.5, alpha is zero - if (alphaVal < 0) alphaVal = 0; - - // throw warning - sprintf( painCave.errMsg, - "SimInfo warning: dampingAlpha was not specified in the input file.\n" - "\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n", alphaVal, rcut_); - painCave.isFatal = 0; - simError(); - } else { - alphaVal = simParams_->getDampingAlpha(); - } - - } else { - // throw error - sprintf( painCave.errMsg, - "SimInfo error: Unknown electrostaticScreeningMethod.\n" - "\t(Input file specified %s .)\n" - "\telectrostaticScreeningMethod must be one of: \"undamped\"\n" - "or \"damped\".\n", myScreen.c_str() ); - painCave.isFatal = 1; - simError(); - } - } - } - - Electrostatic::setElectrostaticSummationMethod( esm ); - Electrostatic::setElectrostaticScreeningMethod( sm ); - Electrostatic::setDampingAlpha( alphaVal ); - Electrostatic::setReactionFieldDielectric( dielectric ); - initFortranFF( &errorOut ); - } void SimInfo::setupSwitchingFunction() { int ft = CUBIC; - + if (simParams_->haveSwitchingFunctionType()) { - std::string funcType = simParams_->getSwitchingFunctionType(); + string funcType = simParams_->getSwitchingFunctionType(); toUpper(funcType); if (funcType == "CUBIC") { ft = CUBIC; @@ -1318,7 +1022,6 @@ namespace OpenMD { // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true if ( simParams_->haveAccumulateBoxDipole() ) if ( simParams_->getAccumulateBoxDipole() ) { - setAccumulateBoxDipole(); calcBoxDipole_ = true; } @@ -1328,7 +1031,7 @@ namespace OpenMD { properties_.addProperty(genData); } - void SimInfo::removeProperty(const std::string& propName) { + void SimInfo::removeProperty(const string& propName) { properties_.removeProperty(propName); } @@ -1336,15 +1039,15 @@ namespace OpenMD { properties_.clearProperties(); } - std::vector SimInfo::getPropertyNames() { + vector SimInfo::getPropertyNames() { return properties_.getPropertyNames(); } - std::vector SimInfo::getProperties() { + vector SimInfo::getProperties() { return properties_.getProperties(); } - GenericData* SimInfo::getPropertyByName(const std::string& propName) { + GenericData* SimInfo::getPropertyByName(const string& propName) { return properties_.getPropertyByName(propName); } @@ -1427,7 +1130,7 @@ namespace OpenMD { } - std::ostream& operator <<(std::ostream& o, SimInfo& info) { + ostream& operator <<(ostream& o, SimInfo& info) { return o; } @@ -1577,7 +1280,7 @@ namespace OpenMD { return IOIndexToIntegrableObject.at(index); } - void SimInfo::setIOIndexToIntegrableObject(const std::vector& v) { + void SimInfo::setIOIndexToIntegrableObject(const vector& v) { IOIndexToIntegrableObject= v; } @@ -1619,7 +1322,7 @@ namespace OpenMD { return; } /* - void SimInfo::setStuntDoubleFromGlobalIndex(std::vector v) { + void SimInfo::setStuntDoubleFromGlobalIndex(vector v) { assert( v.size() == nAtoms_ + nRigidBodies_); sdByGlobalIndex_ = v; } @@ -1629,5 +1332,16 @@ namespace OpenMD { return sdByGlobalIndex_.at(index); } */ + int SimInfo::getNGlobalConstraints() { + int nGlobalConstraints; +#ifdef IS_MPI + MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, + MPI_COMM_WORLD); +#else + nGlobalConstraints = nConstraints_; +#endif + return nGlobalConstraints; + } + }//end namespace OpenMD