--- branches/development/src/nonbonded/InteractionManager.cpp 2011/05/25 16:20:37 1568 +++ branches/development/src/nonbonded/InteractionManager.cpp 2011/06/08 16:05:07 1576 @@ -43,35 +43,18 @@ namespace OpenMD { namespace OpenMD { - InteractionManager* InteractionManager::_instance = NULL; - SimInfo* InteractionManager::info_ = NULL; - bool InteractionManager::initialized_ = false; + InteractionManager::InteractionManager() { - RealType InteractionManager::rCut_ = 0.0; - RealType InteractionManager::rSwitch_ = 0.0; - CutoffMethod InteractionManager::cutoffMethod_ = SHIFTED_FORCE; - SwitchingFunctionType InteractionManager::sft_ = cubic; - RealType InteractionManager::vdwScale_[4] = {1.0, 0.0, 0.0, 0.0}; - RealType InteractionManager::electrostaticScale_[4] = {1.0, 0.0, 0.0, 0.0}; - - map InteractionManager::typeMap_; - map, set > InteractionManager::interactions_; - - LJ* InteractionManager::lj_ = new LJ(); - GB* InteractionManager::gb_ = new GB(); - Sticky* InteractionManager::sticky_ = new Sticky(); - Morse* InteractionManager::morse_ = new Morse(); - EAM* InteractionManager::eam_ = new EAM(); - SC* InteractionManager::sc_ = new SC(); - Electrostatic* InteractionManager::electrostatic_ = new Electrostatic(); - MAW* InteractionManager::maw_ = new MAW(); - SwitchingFunction* InteractionManager::switcher_ = new SwitchingFunction(); - - InteractionManager* InteractionManager::Instance() { - if (!_instance) { - _instance = new InteractionManager(); - } - return _instance; + initialized_ = false; + + lj_ = new LJ(); + gb_ = new GB(); + sticky_ = new Sticky(); + morse_ = new Morse(); + eam_ = new EAM(); + sc_ = new SC(); + electrostatic_ = new Electrostatic(); + maw_ = new MAW(); } void InteractionManager::initialize() { @@ -86,26 +69,6 @@ namespace OpenMD { morse_->setForceField(forceField_); electrostatic_->setForceField(forceField_); maw_->setForceField(forceField_); - - ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); - - // Force fields can set options on how to scale van der Waals and electrostatic - // interactions for atoms connected via bonds, bends and torsions - // in this case the topological distance between atoms is: - // 0 = topologically unconnected - // 1 = bonded together - // 2 = connected via a bend - // 3 = connected via a torsion - - vdwScale_[0] = 1.0; - vdwScale_[1] = fopts.getvdw12scale(); - vdwScale_[2] = fopts.getvdw13scale(); - vdwScale_[3] = fopts.getvdw14scale(); - - electrostaticScale_[0] = 1.0; - electrostaticScale_[1] = fopts.getelectrostatic12scale(); - electrostaticScale_[2] = fopts.getelectrostatic13scale(); - electrostaticScale_[3] = fopts.getelectrostatic14scale(); ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); ForceField::AtomTypeContainer::MapTypeIterator i1, i2; @@ -301,167 +264,17 @@ namespace OpenMD { } } - setupCutoffs(); - setupSwitching(); - - //int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0; - //int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0; - //notifyFortranCutoffs(&rCut_, &rSwitch_, &ljsp, &ljsf); - initialized_ = true; } - /** - * 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 InteractionManager::setupCutoffs() { - - Globals* simParams_ = info_->getSimParams(); - - if (simParams_->haveCutoffRadius()) { - rCut_ = simParams_->getCutoffRadius(); - } else { - if (info_->usesElectrostaticAtoms()) { - sprintf(painCave.errMsg, - "InteractionManager::setupCutoffs: 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(); - rCut_ = 12.0; - } else { - RealType thisCut; - set::iterator i; - set atomTypes; - atomTypes = info_->getSimulatedAtomTypes(); - for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { - thisCut = getSuggestedCutoffRadius((*i)); - rCut_ = max(thisCut, rCut_); - } - sprintf(painCave.errMsg, - "InteractionManager::setupCutoffs: No value was set for the cutoffRadius.\n" - "\tOpenMD will use %lf angstroms.\n", - rCut_); - painCave.isFatal = 0; - painCave.severity = OPENMD_INFO; - simError(); - } - } - - map stringToCutoffMethod; - stringToCutoffMethod["HARD"] = HARD; - stringToCutoffMethod["SWITCHED"] = SWITCHED; - 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, - "InteractionManager::setupCutoffs: Could not find chosen cutoffMethod %s\n" - "\tShould be one of: " - "HARD, SWITCHED, 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, - "InteractionManager::setupCutoffs: 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; - } - } - - - /** - * 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 InteractionManager::setupSwitching() { - Globals* simParams_ = info_->getSimParams(); - - if (simParams_->haveSwitchingRadius()) { - rSwitch_ = simParams_->getSwitchingRadius(); - if (rSwitch_ > rCut_) { - sprintf(painCave.errMsg, - "InteractionManager::setupSwitching: switchingRadius (%f) is larger than cutoffRadius(%f)\n", - rSwitch_, rCut_); - painCave.isFatal = 1; - painCave.severity = OPENMD_ERROR; - simError(); - } - } else { - rSwitch_ = 0.85 * rCut_; - sprintf(painCave.errMsg, - "InteractionManager::setupSwitching: 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", rSwitch_); - painCave.isFatal = 0; - painCave.severity = OPENMD_WARNING; - simError(); - } - - if (simParams_->haveSwitchingFunctionType()) { - string funcType = simParams_->getSwitchingFunctionType(); - toUpper(funcType); - if (funcType == "CUBIC") { - sft_ = cubic; - } else { - if (funcType == "FIFTH_ORDER_POLYNOMIAL") { - sft_ = fifth_order_poly; - } else { - // throw error - sprintf( painCave.errMsg, - "InteractionManager::setupSwitching : 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(); - } - } - } - - switcher_->setSwitchType(sft_); - switcher_->setSwitch(rSwitch_, rCut_); - } - void InteractionManager::doPrePair(InteractionData idat){ if (!initialized_) initialize(); set::iterator it; - for (it = interactions_[ *(idat.atypes) ].begin(); - it != interactions_[ *(idat.atypes) ].end(); ++it){ + for (it = interactions_[ idat.atypes ].begin(); + it != interactions_[ idat.atypes ].end(); ++it){ if ((*it)->getFamily() == METALLIC_FAMILY) { dynamic_cast(*it)->calcDensity(idat); } @@ -492,8 +305,8 @@ namespace OpenMD { set::iterator it; - for (it = interactions_[ *(idat.atypes) ].begin(); - it != interactions_[ *(idat.atypes) ].end(); ++it) + for (it = interactions_[ idat.atypes ].begin(); + it != interactions_[ idat.atypes ].end(); ++it) (*it)->calcForce(idat); return; @@ -505,8 +318,8 @@ namespace OpenMD { set::iterator it; - for (it = interactions_[ *(idat.atypes) ].begin(); - it != interactions_[ *(idat.atypes) ].end(); ++it){ + for (it = interactions_[ idat.atypes ].begin(); + it != interactions_[ idat.atypes ].end(); ++it){ if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) { dynamic_cast(*it)->calcSkipCorrection(idat); }