| 1 | gezelter | 507 | /* | 
| 2 | gezelter | 246 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 |  |  | * | 
| 4 |  |  | * The University of Notre Dame grants you ("Licensee") a | 
| 5 |  |  | * non-exclusive, royalty free, license to use, modify and | 
| 6 |  |  | * redistribute this software in source and binary code form, provided | 
| 7 |  |  | * that the following conditions are met: | 
| 8 |  |  | * | 
| 9 | gezelter | 1390 | * 1. Redistributions of source code must retain the above copyright | 
| 10 | gezelter | 246 | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  |  | * | 
| 12 | gezelter | 1390 | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | gezelter | 246 | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  |  | *    documentation and/or other materials provided with the | 
| 15 |  |  | *    distribution. | 
| 16 |  |  | * | 
| 17 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 18 |  |  | * kind. All express or implied conditions, representations and | 
| 19 |  |  | * warranties, including any implied warranty of merchantability, | 
| 20 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 23 |  |  | * using, modifying or distributing the software or its | 
| 24 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 25 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 27 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 28 |  |  | * arising out of the use of or inability to use software, even if the | 
| 29 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 30 |  |  | * such damages. | 
| 31 | gezelter | 1390 | * | 
| 32 |  |  | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 |  |  | * research, please cite the appropriate papers when you publish your | 
| 34 |  |  | * work.  Good starting points are: | 
| 35 |  |  | * | 
| 36 |  |  | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 |  |  | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 |  |  | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). | 
| 39 |  |  | * [4]  Vardeman & Gezelter, in progress (2009). | 
| 40 | gezelter | 246 | */ | 
| 41 |  |  |  | 
| 42 | gezelter | 507 | /** | 
| 43 |  |  | * @file ForceManager.cpp | 
| 44 |  |  | * @author tlin | 
| 45 |  |  | * @date 11/09/2004 | 
| 46 |  |  | * @time 10:39am | 
| 47 |  |  | * @version 1.0 | 
| 48 |  |  | */ | 
| 49 | gezelter | 246 |  | 
| 50 | gezelter | 1576 |  | 
| 51 | gezelter | 246 | #include "brains/ForceManager.hpp" | 
| 52 |  |  | #include "primitives/Molecule.hpp" | 
| 53 | gezelter | 1390 | #define __OPENMD_C | 
| 54 | gezelter | 246 | #include "utils/simError.h" | 
| 55 | xsun | 1215 | #include "primitives/Bond.hpp" | 
| 56 | tim | 749 | #include "primitives/Bend.hpp" | 
| 57 | cli2 | 1275 | #include "primitives/Torsion.hpp" | 
| 58 |  |  | #include "primitives/Inversion.hpp" | 
| 59 | gezelter | 1551 | #include "nonbonded/NonBondedInteraction.hpp" | 
| 60 | gezelter | 1549 | #include "parallel/ForceMatrixDecomposition.hpp" | 
| 61 | gezelter | 1467 |  | 
| 62 | gezelter | 1583 | #include <cstdio> | 
| 63 |  |  | #include <iostream> | 
| 64 |  |  | #include <iomanip> | 
| 65 |  |  |  | 
| 66 | gezelter | 1545 | using namespace std; | 
| 67 | gezelter | 1390 | namespace OpenMD { | 
| 68 | gezelter | 1469 |  | 
| 69 | gezelter | 1545 | ForceManager::ForceManager(SimInfo * info) : info_(info) { | 
| 70 | gezelter | 1576 | forceField_ = info_->getForceField(); | 
| 71 | gezelter | 1577 | interactionMan_ = new InteractionManager(); | 
| 72 | gezelter | 1579 | fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_); | 
| 73 | gezelter | 1469 | } | 
| 74 | gezelter | 1576 |  | 
| 75 |  |  | /** | 
| 76 |  |  | * setupCutoffs | 
| 77 |  |  | * | 
| 78 |  |  | * Sets the values of cutoffRadius, cutoffMethod, and cutoffPolicy | 
| 79 |  |  | * | 
| 80 |  |  | * cutoffRadius : realType | 
| 81 |  |  | *  If the cutoffRadius was explicitly set, use that value. | 
| 82 |  |  | *  If the cutoffRadius was not explicitly set: | 
| 83 |  |  | *      Are there electrostatic atoms?  Use 12.0 Angstroms. | 
| 84 |  |  | *      No electrostatic atoms?  Poll the atom types present in the | 
| 85 |  |  | *      simulation for suggested cutoff values (e.g. 2.5 * sigma). | 
| 86 |  |  | *      Use the maximum suggested value that was found. | 
| 87 |  |  | * | 
| 88 |  |  | * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, SHIFTED_POTENTIAL) | 
| 89 |  |  | *      If cutoffMethod was explicitly set, use that choice. | 
| 90 |  |  | *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE | 
| 91 |  |  | * | 
| 92 |  |  | * cutoffPolicy : (one of MIX, MAX, TRADITIONAL) | 
| 93 |  |  | *      If cutoffPolicy was explicitly set, use that choice. | 
| 94 |  |  | *      If cutoffPolicy was not explicitly set, use TRADITIONAL | 
| 95 |  |  | */ | 
| 96 |  |  | void ForceManager::setupCutoffs() { | 
| 97 |  |  |  | 
| 98 |  |  | Globals* simParams_ = info_->getSimParams(); | 
| 99 |  |  | ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); | 
| 100 |  |  |  | 
| 101 |  |  | if (simParams_->haveCutoffRadius()) { | 
| 102 |  |  | rCut_ = simParams_->getCutoffRadius(); | 
| 103 |  |  | } else { | 
| 104 |  |  | if (info_->usesElectrostaticAtoms()) { | 
| 105 |  |  | sprintf(painCave.errMsg, | 
| 106 |  |  | "ForceManager::setupCutoffs: No value was set for the cutoffRadius.\n" | 
| 107 |  |  | "\tOpenMD will use a default value of 12.0 angstroms" | 
| 108 |  |  | "\tfor the cutoffRadius.\n"); | 
| 109 |  |  | painCave.isFatal = 0; | 
| 110 |  |  | painCave.severity = OPENMD_INFO; | 
| 111 |  |  | simError(); | 
| 112 |  |  | rCut_ = 12.0; | 
| 113 |  |  | } else { | 
| 114 |  |  | RealType thisCut; | 
| 115 |  |  | set<AtomType*>::iterator i; | 
| 116 |  |  | set<AtomType*> atomTypes; | 
| 117 |  |  | atomTypes = info_->getSimulatedAtomTypes(); | 
| 118 |  |  | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | 
| 119 |  |  | thisCut = interactionMan_->getSuggestedCutoffRadius((*i)); | 
| 120 |  |  | rCut_ = max(thisCut, rCut_); | 
| 121 |  |  | } | 
| 122 |  |  | sprintf(painCave.errMsg, | 
| 123 |  |  | "ForceManager::setupCutoffs: No value was set for the cutoffRadius.\n" | 
| 124 |  |  | "\tOpenMD will use %lf angstroms.\n", | 
| 125 |  |  | rCut_); | 
| 126 |  |  | painCave.isFatal = 0; | 
| 127 |  |  | painCave.severity = OPENMD_INFO; | 
| 128 |  |  | simError(); | 
| 129 | gezelter | 1579 | } | 
| 130 | gezelter | 1576 | } | 
| 131 |  |  |  | 
| 132 | gezelter | 1583 | fDecomp_->setUserCutoff(rCut_); | 
| 133 |  |  |  | 
| 134 | gezelter | 1576 | map<string, CutoffMethod> stringToCutoffMethod; | 
| 135 |  |  | stringToCutoffMethod["HARD"] = HARD; | 
| 136 |  |  | stringToCutoffMethod["SWITCHED"] = SWITCHED; | 
| 137 |  |  | stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL; | 
| 138 |  |  | stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE; | 
| 139 | gezelter | 1545 |  | 
| 140 | gezelter | 1576 | if (simParams_->haveCutoffMethod()) { | 
| 141 |  |  | string cutMeth = toUpperCopy(simParams_->getCutoffMethod()); | 
| 142 |  |  | map<string, CutoffMethod>::iterator i; | 
| 143 |  |  | i = stringToCutoffMethod.find(cutMeth); | 
| 144 |  |  | if (i == stringToCutoffMethod.end()) { | 
| 145 |  |  | sprintf(painCave.errMsg, | 
| 146 |  |  | "ForceManager::setupCutoffs: Could not find chosen cutoffMethod %s\n" | 
| 147 |  |  | "\tShould be one of: " | 
| 148 |  |  | "HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n", | 
| 149 |  |  | cutMeth.c_str()); | 
| 150 |  |  | painCave.isFatal = 1; | 
| 151 |  |  | painCave.severity = OPENMD_ERROR; | 
| 152 |  |  | simError(); | 
| 153 |  |  | } else { | 
| 154 |  |  | cutoffMethod_ = i->second; | 
| 155 |  |  | } | 
| 156 |  |  | } else { | 
| 157 |  |  | sprintf(painCave.errMsg, | 
| 158 |  |  | "ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n" | 
| 159 |  |  | "\tOpenMD will use SHIFTED_FORCE.\n"); | 
| 160 |  |  | painCave.isFatal = 0; | 
| 161 |  |  | painCave.severity = OPENMD_INFO; | 
| 162 |  |  | simError(); | 
| 163 |  |  | cutoffMethod_ = SHIFTED_FORCE; | 
| 164 |  |  | } | 
| 165 |  |  |  | 
| 166 |  |  | map<string, CutoffPolicy> stringToCutoffPolicy; | 
| 167 |  |  | stringToCutoffPolicy["MIX"] = MIX; | 
| 168 |  |  | stringToCutoffPolicy["MAX"] = MAX; | 
| 169 |  |  | stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL; | 
| 170 |  |  |  | 
| 171 |  |  | std::string cutPolicy; | 
| 172 |  |  | if (forceFieldOptions_.haveCutoffPolicy()){ | 
| 173 |  |  | cutPolicy = forceFieldOptions_.getCutoffPolicy(); | 
| 174 |  |  | }else if (simParams_->haveCutoffPolicy()) { | 
| 175 |  |  | cutPolicy = simParams_->getCutoffPolicy(); | 
| 176 |  |  | } | 
| 177 |  |  |  | 
| 178 |  |  | if (!cutPolicy.empty()){ | 
| 179 |  |  | toUpper(cutPolicy); | 
| 180 |  |  | map<string, CutoffPolicy>::iterator i; | 
| 181 |  |  | i = stringToCutoffPolicy.find(cutPolicy); | 
| 182 |  |  |  | 
| 183 |  |  | if (i == stringToCutoffPolicy.end()) { | 
| 184 |  |  | sprintf(painCave.errMsg, | 
| 185 |  |  | "ForceManager::setupCutoffs: Could not find chosen cutoffPolicy %s\n" | 
| 186 |  |  | "\tShould be one of: " | 
| 187 |  |  | "MIX, MAX, or TRADITIONAL\n", | 
| 188 |  |  | cutPolicy.c_str()); | 
| 189 |  |  | painCave.isFatal = 1; | 
| 190 |  |  | painCave.severity = OPENMD_ERROR; | 
| 191 |  |  | simError(); | 
| 192 |  |  | } else { | 
| 193 |  |  | cutoffPolicy_ = i->second; | 
| 194 |  |  | } | 
| 195 |  |  | } else { | 
| 196 |  |  | sprintf(painCave.errMsg, | 
| 197 |  |  | "ForceManager::setupCutoffs: No value was set for the cutoffPolicy.\n" | 
| 198 |  |  | "\tOpenMD will use TRADITIONAL.\n"); | 
| 199 |  |  | painCave.isFatal = 0; | 
| 200 |  |  | painCave.severity = OPENMD_INFO; | 
| 201 |  |  | simError(); | 
| 202 |  |  | cutoffPolicy_ = TRADITIONAL; | 
| 203 |  |  | } | 
| 204 | gezelter | 1579 | fDecomp_->setCutoffPolicy(cutoffPolicy_); | 
| 205 | gezelter | 1576 | } | 
| 206 |  |  |  | 
| 207 |  |  | /** | 
| 208 |  |  | * setupSwitching | 
| 209 |  |  | * | 
| 210 |  |  | * Sets the values of switchingRadius and | 
| 211 |  |  | *  If the switchingRadius was explicitly set, use that value (but check it) | 
| 212 |  |  | *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_ | 
| 213 |  |  | */ | 
| 214 |  |  | void ForceManager::setupSwitching() { | 
| 215 |  |  | Globals* simParams_ = info_->getSimParams(); | 
| 216 | gezelter | 1577 |  | 
| 217 |  |  | // create the switching function object: | 
| 218 |  |  | switcher_ = new SwitchingFunction(); | 
| 219 | gezelter | 1126 |  | 
| 220 | gezelter | 1576 | if (simParams_->haveSwitchingRadius()) { | 
| 221 |  |  | rSwitch_ = simParams_->getSwitchingRadius(); | 
| 222 |  |  | if (rSwitch_ > rCut_) { | 
| 223 |  |  | sprintf(painCave.errMsg, | 
| 224 | gezelter | 1577 | "ForceManager::setupSwitching: switchingRadius (%f) is larger " | 
| 225 |  |  | "than the cutoffRadius(%f)\n", rSwitch_, rCut_); | 
| 226 | gezelter | 1576 | painCave.isFatal = 1; | 
| 227 |  |  | painCave.severity = OPENMD_ERROR; | 
| 228 |  |  | simError(); | 
| 229 |  |  | } | 
| 230 |  |  | } else { | 
| 231 |  |  | rSwitch_ = 0.85 * rCut_; | 
| 232 |  |  | sprintf(painCave.errMsg, | 
| 233 |  |  | "ForceManager::setupSwitching: No value was set for the switchingRadius.\n" | 
| 234 |  |  | "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n" | 
| 235 |  |  | "\tswitchingRadius = %f. for this simulation\n", rSwitch_); | 
| 236 |  |  | painCave.isFatal = 0; | 
| 237 |  |  | painCave.severity = OPENMD_WARNING; | 
| 238 |  |  | simError(); | 
| 239 |  |  | } | 
| 240 |  |  |  | 
| 241 | gezelter | 1577 | // Default to cubic switching function. | 
| 242 |  |  | sft_ = cubic; | 
| 243 | gezelter | 1576 | if (simParams_->haveSwitchingFunctionType()) { | 
| 244 |  |  | string funcType = simParams_->getSwitchingFunctionType(); | 
| 245 |  |  | toUpper(funcType); | 
| 246 |  |  | if (funcType == "CUBIC") { | 
| 247 |  |  | sft_ = cubic; | 
| 248 |  |  | } else { | 
| 249 |  |  | if (funcType == "FIFTH_ORDER_POLYNOMIAL") { | 
| 250 |  |  | sft_ = fifth_order_poly; | 
| 251 |  |  | } else { | 
| 252 |  |  | // throw error | 
| 253 |  |  | sprintf( painCave.errMsg, | 
| 254 |  |  | "ForceManager::setupSwitching : Unknown switchingFunctionType. (Input file specified %s .)\n" | 
| 255 |  |  | "\tswitchingFunctionType must be one of: " | 
| 256 |  |  | "\"cubic\" or \"fifth_order_polynomial\".", | 
| 257 |  |  | funcType.c_str() ); | 
| 258 |  |  | painCave.isFatal = 1; | 
| 259 |  |  | painCave.severity = OPENMD_ERROR; | 
| 260 |  |  | simError(); | 
| 261 |  |  | } | 
| 262 |  |  | } | 
| 263 |  |  | } | 
| 264 |  |  | switcher_->setSwitchType(sft_); | 
| 265 |  |  | switcher_->setSwitch(rSwitch_, rCut_); | 
| 266 |  |  | } | 
| 267 |  |  |  | 
| 268 |  |  | void ForceManager::initialize() { | 
| 269 |  |  |  | 
| 270 | gezelter | 1569 | if (!info_->isTopologyDone()) { | 
| 271 | gezelter | 507 | info_->update(); | 
| 272 | gezelter | 1546 | interactionMan_->setSimInfo(info_); | 
| 273 |  |  | interactionMan_->initialize(); | 
| 274 | gezelter | 1576 |  | 
| 275 |  |  | // We want to delay the cutoffs until after the interaction | 
| 276 |  |  | // manager has set up the atom-atom interactions so that we can | 
| 277 |  |  | // query them for suggested cutoff values | 
| 278 |  |  |  | 
| 279 |  |  | setupCutoffs(); | 
| 280 |  |  | setupSwitching(); | 
| 281 |  |  |  | 
| 282 |  |  | info_->prepareTopology(); | 
| 283 | gezelter | 246 | } | 
| 284 | gezelter | 1576 |  | 
| 285 |  |  | ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); | 
| 286 | gezelter | 1126 |  | 
| 287 | gezelter | 1576 | // Force fields can set options on how to scale van der Waals and electrostatic | 
| 288 |  |  | // interactions for atoms connected via bonds, bends and torsions | 
| 289 |  |  | // in this case the topological distance between atoms is: | 
| 290 |  |  | // 0 = topologically unconnected | 
| 291 |  |  | // 1 = bonded together | 
| 292 |  |  | // 2 = connected via a bend | 
| 293 |  |  | // 3 = connected via a torsion | 
| 294 |  |  |  | 
| 295 |  |  | vdwScale_.reserve(4); | 
| 296 |  |  | fill(vdwScale_.begin(), vdwScale_.end(), 0.0); | 
| 297 |  |  |  | 
| 298 |  |  | electrostaticScale_.reserve(4); | 
| 299 |  |  | fill(electrostaticScale_.begin(), electrostaticScale_.end(), 0.0); | 
| 300 |  |  |  | 
| 301 |  |  | vdwScale_[0] = 1.0; | 
| 302 |  |  | vdwScale_[1] = fopts.getvdw12scale(); | 
| 303 |  |  | vdwScale_[2] = fopts.getvdw13scale(); | 
| 304 |  |  | vdwScale_[3] = fopts.getvdw14scale(); | 
| 305 |  |  |  | 
| 306 |  |  | electrostaticScale_[0] = 1.0; | 
| 307 |  |  | electrostaticScale_[1] = fopts.getelectrostatic12scale(); | 
| 308 |  |  | electrostaticScale_[2] = fopts.getelectrostatic13scale(); | 
| 309 |  |  | electrostaticScale_[3] = fopts.getelectrostatic14scale(); | 
| 310 |  |  |  | 
| 311 |  |  | fDecomp_->distributeInitialData(); | 
| 312 |  |  |  | 
| 313 |  |  | initialized_ = true; | 
| 314 |  |  |  | 
| 315 |  |  | } | 
| 316 |  |  |  | 
| 317 |  |  | void ForceManager::calcForces() { | 
| 318 |  |  |  | 
| 319 |  |  | if (!initialized_) initialize(); | 
| 320 |  |  |  | 
| 321 | gezelter | 1544 | preCalculation(); | 
| 322 | gezelter | 1546 | shortRangeInteractions(); | 
| 323 |  |  | longRangeInteractions(); | 
| 324 | gezelter | 1576 | postCalculation(); | 
| 325 | gezelter | 507 | } | 
| 326 | gezelter | 1126 |  | 
| 327 | gezelter | 507 | void ForceManager::preCalculation() { | 
| 328 | gezelter | 246 | SimInfo::MoleculeIterator mi; | 
| 329 |  |  | Molecule* mol; | 
| 330 |  |  | Molecule::AtomIterator ai; | 
| 331 |  |  | Atom* atom; | 
| 332 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 333 |  |  | RigidBody* rb; | 
| 334 | gezelter | 1540 | Molecule::CutoffGroupIterator ci; | 
| 335 |  |  | CutoffGroup* cg; | 
| 336 | gezelter | 246 |  | 
| 337 |  |  | // forces are zeroed here, before any are accumulated. | 
| 338 | chuckv | 1245 |  | 
| 339 | gezelter | 1126 | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 340 |  |  | mol = info_->nextMolecule(mi)) { | 
| 341 | gezelter | 507 | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 342 |  |  | atom->zeroForcesAndTorques(); | 
| 343 |  |  | } | 
| 344 | chuckv | 1245 |  | 
| 345 | gezelter | 507 | //change the positions of atoms which belong to the rigidbodies | 
| 346 | gezelter | 1126 | for (rb = mol->beginRigidBody(rbIter); rb != NULL; | 
| 347 |  |  | rb = mol->nextRigidBody(rbIter)) { | 
| 348 | gezelter | 507 | rb->zeroForcesAndTorques(); | 
| 349 |  |  | } | 
| 350 | gezelter | 1540 |  | 
| 351 |  |  | if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){ | 
| 352 |  |  | for(cg = mol->beginCutoffGroup(ci); cg != NULL; | 
| 353 |  |  | cg = mol->nextCutoffGroup(ci)) { | 
| 354 |  |  | //calculate the center of mass of cutoff group | 
| 355 |  |  | cg->updateCOM(); | 
| 356 |  |  | } | 
| 357 |  |  | } | 
| 358 | gezelter | 246 | } | 
| 359 | gezelter | 1540 |  | 
| 360 | gezelter | 1126 | // Zero out the stress tensor | 
| 361 |  |  | tau *= 0.0; | 
| 362 |  |  |  | 
| 363 | gezelter | 507 | } | 
| 364 | gezelter | 1126 |  | 
| 365 | gezelter | 1546 | void ForceManager::shortRangeInteractions() { | 
| 366 | gezelter | 246 | Molecule* mol; | 
| 367 |  |  | RigidBody* rb; | 
| 368 |  |  | Bond* bond; | 
| 369 |  |  | Bend* bend; | 
| 370 |  |  | Torsion* torsion; | 
| 371 | cli2 | 1275 | Inversion* inversion; | 
| 372 | gezelter | 246 | SimInfo::MoleculeIterator mi; | 
| 373 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 374 |  |  | Molecule::BondIterator bondIter;; | 
| 375 |  |  | Molecule::BendIterator  bendIter; | 
| 376 |  |  | Molecule::TorsionIterator  torsionIter; | 
| 377 | cli2 | 1275 | Molecule::InversionIterator  inversionIter; | 
| 378 | tim | 963 | RealType bondPotential = 0.0; | 
| 379 |  |  | RealType bendPotential = 0.0; | 
| 380 |  |  | RealType torsionPotential = 0.0; | 
| 381 | cli2 | 1275 | RealType inversionPotential = 0.0; | 
| 382 | gezelter | 246 |  | 
| 383 |  |  | //calculate short range interactions | 
| 384 | gezelter | 1126 | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 385 |  |  | mol = info_->nextMolecule(mi)) { | 
| 386 | gezelter | 246 |  | 
| 387 | gezelter | 507 | //change the positions of atoms which belong to the rigidbodies | 
| 388 | gezelter | 1126 | for (rb = mol->beginRigidBody(rbIter); rb != NULL; | 
| 389 |  |  | rb = mol->nextRigidBody(rbIter)) { | 
| 390 |  |  | rb->updateAtoms(); | 
| 391 | gezelter | 507 | } | 
| 392 | gezelter | 246 |  | 
| 393 | gezelter | 1126 | for (bond = mol->beginBond(bondIter); bond != NULL; | 
| 394 |  |  | bond = mol->nextBond(bondIter)) { | 
| 395 | tim | 749 | bond->calcForce(); | 
| 396 |  |  | bondPotential += bond->getPotential(); | 
| 397 | gezelter | 507 | } | 
| 398 | gezelter | 246 |  | 
| 399 | gezelter | 1126 | for (bend = mol->beginBend(bendIter); bend != NULL; | 
| 400 |  |  | bend = mol->nextBend(bendIter)) { | 
| 401 |  |  |  | 
| 402 |  |  | RealType angle; | 
| 403 |  |  | bend->calcForce(angle); | 
| 404 |  |  | RealType currBendPot = bend->getPotential(); | 
| 405 | gezelter | 1448 |  | 
| 406 | gezelter | 1126 | bendPotential += bend->getPotential(); | 
| 407 | gezelter | 1545 | map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); | 
| 408 | gezelter | 1126 | if (i == bendDataSets.end()) { | 
| 409 |  |  | BendDataSet dataSet; | 
| 410 |  |  | dataSet.prev.angle = dataSet.curr.angle = angle; | 
| 411 |  |  | dataSet.prev.potential = dataSet.curr.potential = currBendPot; | 
| 412 |  |  | dataSet.deltaV = 0.0; | 
| 413 | gezelter | 1545 | bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, dataSet)); | 
| 414 | gezelter | 1126 | }else { | 
| 415 |  |  | i->second.prev.angle = i->second.curr.angle; | 
| 416 |  |  | i->second.prev.potential = i->second.curr.potential; | 
| 417 |  |  | i->second.curr.angle = angle; | 
| 418 |  |  | i->second.curr.potential = currBendPot; | 
| 419 |  |  | i->second.deltaV =  fabs(i->second.curr.potential - | 
| 420 |  |  | i->second.prev.potential); | 
| 421 |  |  | } | 
| 422 | gezelter | 507 | } | 
| 423 | gezelter | 1126 |  | 
| 424 |  |  | for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; | 
| 425 |  |  | torsion = mol->nextTorsion(torsionIter)) { | 
| 426 | tim | 963 | RealType angle; | 
| 427 | gezelter | 1126 | torsion->calcForce(angle); | 
| 428 | tim | 963 | RealType currTorsionPot = torsion->getPotential(); | 
| 429 | gezelter | 1126 | torsionPotential += torsion->getPotential(); | 
| 430 | gezelter | 1545 | map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); | 
| 431 | gezelter | 1126 | if (i == torsionDataSets.end()) { | 
| 432 |  |  | TorsionDataSet dataSet; | 
| 433 |  |  | dataSet.prev.angle = dataSet.curr.angle = angle; | 
| 434 |  |  | dataSet.prev.potential = dataSet.curr.potential = currTorsionPot; | 
| 435 |  |  | dataSet.deltaV = 0.0; | 
| 436 | gezelter | 1545 | torsionDataSets.insert(map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); | 
| 437 | gezelter | 1126 | }else { | 
| 438 |  |  | i->second.prev.angle = i->second.curr.angle; | 
| 439 |  |  | i->second.prev.potential = i->second.curr.potential; | 
| 440 |  |  | i->second.curr.angle = angle; | 
| 441 |  |  | i->second.curr.potential = currTorsionPot; | 
| 442 |  |  | i->second.deltaV =  fabs(i->second.curr.potential - | 
| 443 |  |  | i->second.prev.potential); | 
| 444 |  |  | } | 
| 445 |  |  | } | 
| 446 | gezelter | 1545 |  | 
| 447 | cli2 | 1275 | for (inversion = mol->beginInversion(inversionIter); | 
| 448 |  |  | inversion != NULL; | 
| 449 |  |  | inversion = mol->nextInversion(inversionIter)) { | 
| 450 |  |  | RealType angle; | 
| 451 |  |  | inversion->calcForce(angle); | 
| 452 |  |  | RealType currInversionPot = inversion->getPotential(); | 
| 453 |  |  | inversionPotential += inversion->getPotential(); | 
| 454 | gezelter | 1545 | map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); | 
| 455 | cli2 | 1275 | if (i == inversionDataSets.end()) { | 
| 456 |  |  | InversionDataSet dataSet; | 
| 457 |  |  | dataSet.prev.angle = dataSet.curr.angle = angle; | 
| 458 |  |  | dataSet.prev.potential = dataSet.curr.potential = currInversionPot; | 
| 459 |  |  | dataSet.deltaV = 0.0; | 
| 460 | gezelter | 1545 | inversionDataSets.insert(map<Inversion*, InversionDataSet>::value_type(inversion, dataSet)); | 
| 461 | cli2 | 1275 | }else { | 
| 462 |  |  | i->second.prev.angle = i->second.curr.angle; | 
| 463 |  |  | i->second.prev.potential = i->second.curr.potential; | 
| 464 |  |  | i->second.curr.angle = angle; | 
| 465 |  |  | i->second.curr.potential = currInversionPot; | 
| 466 |  |  | i->second.deltaV =  fabs(i->second.curr.potential - | 
| 467 |  |  | i->second.prev.potential); | 
| 468 |  |  | } | 
| 469 |  |  | } | 
| 470 | gezelter | 246 | } | 
| 471 |  |  |  | 
| 472 | gezelter | 1126 | RealType  shortRangePotential = bondPotential + bendPotential + | 
| 473 | cli2 | 1275 | torsionPotential +  inversionPotential; | 
| 474 | gezelter | 246 | Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 475 |  |  | curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential; | 
| 476 | tim | 665 | curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential; | 
| 477 |  |  | curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential; | 
| 478 |  |  | curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential; | 
| 479 | gezelter | 1545 | curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential; | 
| 480 | gezelter | 507 | } | 
| 481 | gezelter | 1126 |  | 
| 482 | gezelter | 1546 | void ForceManager::longRangeInteractions() { | 
| 483 | gezelter | 1581 |  | 
| 484 | gezelter | 1545 | Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 485 |  |  | DataStorage* config = &(curSnapshot->atomData); | 
| 486 |  |  | DataStorage* cgConfig = &(curSnapshot->cgData); | 
| 487 |  |  |  | 
| 488 | gezelter | 1581 | //calculate the center of mass of cutoff group | 
| 489 |  |  |  | 
| 490 |  |  | SimInfo::MoleculeIterator mi; | 
| 491 |  |  | Molecule* mol; | 
| 492 |  |  | Molecule::CutoffGroupIterator ci; | 
| 493 |  |  | CutoffGroup* cg; | 
| 494 |  |  |  | 
| 495 |  |  | if(info_->getNCutoffGroups() > 0){ | 
| 496 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 497 |  |  | mol = info_->nextMolecule(mi)) { | 
| 498 |  |  | for(cg = mol->beginCutoffGroup(ci); cg != NULL; | 
| 499 |  |  | cg = mol->nextCutoffGroup(ci)) { | 
| 500 |  |  | cg->updateCOM(); | 
| 501 |  |  | } | 
| 502 |  |  | } | 
| 503 |  |  | } else { | 
| 504 |  |  | // center of mass of the group is the same as position of the atom | 
| 505 |  |  | // if cutoff group does not exist | 
| 506 |  |  | cgConfig->position = config->position; | 
| 507 |  |  | } | 
| 508 |  |  |  | 
| 509 | gezelter | 1575 | fDecomp_->zeroWorkArrays(); | 
| 510 | gezelter | 1549 | fDecomp_->distributeData(); | 
| 511 | gezelter | 1579 |  | 
| 512 |  |  | int cg1, cg2, atom1, atom2, topoDist; | 
| 513 |  |  | Vector3d d_grp, dag, d; | 
| 514 |  |  | RealType rgrpsq, rgrp, r2, r; | 
| 515 |  |  | RealType electroMult, vdwMult; | 
| 516 | gezelter | 1549 | RealType vij; | 
| 517 | gezelter | 1581 | Vector3d fij, fg, f1; | 
| 518 | gezelter | 1576 | tuple3<RealType, RealType, RealType> cuts; | 
| 519 | gezelter | 1545 | RealType rCutSq; | 
| 520 |  |  | bool in_switching_region; | 
| 521 |  |  | RealType sw, dswdr, swderiv; | 
| 522 | gezelter | 1549 | vector<int> atomListColumn, atomListRow, atomListLocal; | 
| 523 | gezelter | 1545 | InteractionData idat; | 
| 524 | gezelter | 1546 | SelfData sdat; | 
| 525 |  |  | RealType mf; | 
| 526 | gezelter | 1575 | RealType lrPot; | 
| 527 | gezelter | 1579 | RealType vpair; | 
| 528 | gezelter | 1583 | potVec longRangePotential(0.0); | 
| 529 |  |  | potVec workPot(0.0); | 
| 530 | gezelter | 1544 |  | 
| 531 | gezelter | 1545 | int loopStart, loopEnd; | 
| 532 | gezelter | 1544 |  | 
| 533 | gezelter | 1581 | idat.vdwMult = &vdwMult; | 
| 534 |  |  | idat.electroMult = &electroMult; | 
| 535 | gezelter | 1583 | idat.pot = &workPot; | 
| 536 |  |  | sdat.pot = fDecomp_->getEmbeddingPotential(); | 
| 537 | gezelter | 1581 | idat.vpair = &vpair; | 
| 538 |  |  | idat.f1 = &f1; | 
| 539 |  |  | idat.sw = &sw; | 
| 540 | gezelter | 1583 | idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; | 
| 541 |  |  | idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; | 
| 542 |  |  |  | 
| 543 | gezelter | 1545 | loopEnd = PAIR_LOOP; | 
| 544 | gezelter | 1546 | if (info_->requiresPrepair() ) { | 
| 545 | gezelter | 1545 | loopStart = PREPAIR_LOOP; | 
| 546 |  |  | } else { | 
| 547 |  |  | loopStart = PAIR_LOOP; | 
| 548 |  |  | } | 
| 549 | gezelter | 1583 |  | 
| 550 | gezelter | 1579 | for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) { | 
| 551 |  |  |  | 
| 552 | gezelter | 1545 | if (iLoop == loopStart) { | 
| 553 | gezelter | 1549 | bool update_nlist = fDecomp_->checkNeighborList(); | 
| 554 | gezelter | 1545 | if (update_nlist) | 
| 555 | gezelter | 1549 | neighborList = fDecomp_->buildNeighborList(); | 
| 556 | gezelter | 1579 | } | 
| 557 |  |  |  | 
| 558 | gezelter | 1545 | for (vector<pair<int, int> >::iterator it = neighborList.begin(); | 
| 559 |  |  | it != neighborList.end(); ++it) { | 
| 560 | gezelter | 1579 |  | 
| 561 | gezelter | 1545 | cg1 = (*it).first; | 
| 562 |  |  | cg2 = (*it).second; | 
| 563 | gezelter | 1576 |  | 
| 564 |  |  | cuts = fDecomp_->getGroupCutoffs(cg1, cg2); | 
| 565 | gezelter | 1545 |  | 
| 566 | gezelter | 1549 | d_grp  = fDecomp_->getIntergroupVector(cg1, cg2); | 
| 567 | gezelter | 1545 | curSnapshot->wrapVector(d_grp); | 
| 568 |  |  | rgrpsq = d_grp.lengthSquare(); | 
| 569 |  |  |  | 
| 570 | gezelter | 1576 | rCutSq = cuts.second; | 
| 571 |  |  |  | 
| 572 | gezelter | 1545 | if (rgrpsq < rCutSq) { | 
| 573 | gezelter | 1579 | idat.rcut = &cuts.first; | 
| 574 | gezelter | 1545 | if (iLoop == PAIR_LOOP) { | 
| 575 | gezelter | 1546 | vij *= 0.0; | 
| 576 | gezelter | 1545 | fij = V3Zero; | 
| 577 |  |  | } | 
| 578 |  |  |  | 
| 579 | gezelter | 1579 | in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, | 
| 580 | gezelter | 1576 | rgrp); | 
| 581 |  |  |  | 
| 582 | gezelter | 1549 | atomListRow = fDecomp_->getAtomsInGroupRow(cg1); | 
| 583 |  |  | atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2); | 
| 584 | gezelter | 1545 |  | 
| 585 | gezelter | 1549 | for (vector<int>::iterator ia = atomListRow.begin(); | 
| 586 |  |  | ia != atomListRow.end(); ++ia) { | 
| 587 | gezelter | 1545 | atom1 = (*ia); | 
| 588 |  |  |  | 
| 589 | gezelter | 1549 | for (vector<int>::iterator jb = atomListColumn.begin(); | 
| 590 |  |  | jb != atomListColumn.end(); ++jb) { | 
| 591 | gezelter | 1545 | atom2 = (*jb); | 
| 592 | gezelter | 1583 |  | 
| 593 | gezelter | 1549 | if (!fDecomp_->skipAtomPair(atom1, atom2)) { | 
| 594 | gezelter | 1579 | vpair = 0.0; | 
| 595 | gezelter | 1583 | workPot = 0.0; | 
| 596 | gezelter | 1581 | f1 = V3Zero; | 
| 597 | gezelter | 1575 |  | 
| 598 | gezelter | 1581 | fDecomp_->fillInteractionData(idat, atom1, atom2); | 
| 599 | gezelter | 1579 |  | 
| 600 |  |  | topoDist = fDecomp_->getTopologicalDistance(atom1, atom2); | 
| 601 |  |  | vdwMult = vdwScale_[topoDist]; | 
| 602 |  |  | electroMult = electrostaticScale_[topoDist]; | 
| 603 | gezelter | 1546 |  | 
| 604 | gezelter | 1549 | if (atomListRow.size() == 1 && atomListColumn.size() == 1) { | 
| 605 | gezelter | 1579 | idat.d = &d_grp; | 
| 606 |  |  | idat.r2 = &rgrpsq; | 
| 607 | gezelter | 1545 | } else { | 
| 608 | gezelter | 1579 | d = fDecomp_->getInteratomicVector(atom1, atom2); | 
| 609 |  |  | curSnapshot->wrapVector( d ); | 
| 610 |  |  | r2 = d.lengthSquare(); | 
| 611 |  |  | idat.d = &d; | 
| 612 |  |  | idat.r2 = &r2; | 
| 613 | gezelter | 1545 | } | 
| 614 |  |  |  | 
| 615 | gezelter | 1581 | r = sqrt( *(idat.r2) ); | 
| 616 | gezelter | 1579 | idat.rij = &r; | 
| 617 | gezelter | 1546 |  | 
| 618 | gezelter | 1545 | if (iLoop == PREPAIR_LOOP) { | 
| 619 |  |  | interactionMan_->doPrePair(idat); | 
| 620 |  |  | } else { | 
| 621 |  |  | interactionMan_->doPair(idat); | 
| 622 | gezelter | 1575 | fDecomp_->unpackInteractionData(idat, atom1, atom2); | 
| 623 | gezelter | 1581 | vij += vpair; | 
| 624 |  |  | fij += f1; | 
| 625 |  |  | tau -= outProduct( *(idat.d), f1); | 
| 626 | gezelter | 1545 | } | 
| 627 |  |  | } | 
| 628 |  |  | } | 
| 629 |  |  | } | 
| 630 |  |  |  | 
| 631 |  |  | if (iLoop == PAIR_LOOP) { | 
| 632 |  |  | if (in_switching_region) { | 
| 633 |  |  | swderiv = vij * dswdr / rgrp; | 
| 634 |  |  | fg = swderiv * d_grp; | 
| 635 |  |  |  | 
| 636 |  |  | fij += fg; | 
| 637 |  |  |  | 
| 638 | gezelter | 1549 | if (atomListRow.size() == 1 && atomListColumn.size() == 1) { | 
| 639 | gezelter | 1554 | tau -= outProduct( *(idat.d), fg); | 
| 640 | gezelter | 1545 | } | 
| 641 |  |  |  | 
| 642 | gezelter | 1549 | for (vector<int>::iterator ia = atomListRow.begin(); | 
| 643 |  |  | ia != atomListRow.end(); ++ia) { | 
| 644 | gezelter | 1545 | atom1 = (*ia); | 
| 645 | gezelter | 1569 | mf = fDecomp_->getMassFactorRow(atom1); | 
| 646 | gezelter | 1545 | // fg is the force on atom ia due to cutoff group's | 
| 647 |  |  | // presence in switching region | 
| 648 |  |  | fg = swderiv * d_grp * mf; | 
| 649 | gezelter | 1549 | fDecomp_->addForceToAtomRow(atom1, fg); | 
| 650 | gezelter | 1545 |  | 
| 651 | gezelter | 1549 | if (atomListRow.size() > 1) { | 
| 652 | gezelter | 1546 | if (info_->usesAtomicVirial()) { | 
| 653 | gezelter | 1545 | // find the distance between the atom | 
| 654 |  |  | // and the center of the cutoff group: | 
| 655 | gezelter | 1549 | dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1); | 
| 656 | gezelter | 1545 | tau -= outProduct(dag, fg); | 
| 657 |  |  | } | 
| 658 |  |  | } | 
| 659 |  |  | } | 
| 660 | gezelter | 1549 | for (vector<int>::iterator jb = atomListColumn.begin(); | 
| 661 |  |  | jb != atomListColumn.end(); ++jb) { | 
| 662 | gezelter | 1545 | atom2 = (*jb); | 
| 663 | gezelter | 1569 | mf = fDecomp_->getMassFactorColumn(atom2); | 
| 664 | gezelter | 1545 | // fg is the force on atom jb due to cutoff group's | 
| 665 |  |  | // presence in switching region | 
| 666 |  |  | fg = -swderiv * d_grp * mf; | 
| 667 | gezelter | 1549 | fDecomp_->addForceToAtomColumn(atom2, fg); | 
| 668 | gezelter | 1545 |  | 
| 669 | gezelter | 1549 | if (atomListColumn.size() > 1) { | 
| 670 | gezelter | 1546 | if (info_->usesAtomicVirial()) { | 
| 671 | gezelter | 1545 | // find the distance between the atom | 
| 672 |  |  | // and the center of the cutoff group: | 
| 673 | gezelter | 1549 | dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2); | 
| 674 | gezelter | 1545 | tau -= outProduct(dag, fg); | 
| 675 |  |  | } | 
| 676 |  |  | } | 
| 677 |  |  | } | 
| 678 |  |  | } | 
| 679 |  |  | //if (!SIM_uses_AtomicVirial) { | 
| 680 |  |  | //  tau -= outProduct(d_grp, fij); | 
| 681 |  |  | //} | 
| 682 |  |  | } | 
| 683 |  |  | } | 
| 684 |  |  | } | 
| 685 |  |  |  | 
| 686 |  |  | if (iLoop == PREPAIR_LOOP) { | 
| 687 | gezelter | 1546 | if (info_->requiresPrepair()) { | 
| 688 | gezelter | 1549 | fDecomp_->collectIntermediateData(); | 
| 689 | gezelter | 1570 |  | 
| 690 |  |  | for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { | 
| 691 | gezelter | 1581 | fDecomp_->fillSelfData(sdat, atom1); | 
| 692 | gezelter | 1545 | interactionMan_->doPreForce(sdat); | 
| 693 |  |  | } | 
| 694 | gezelter | 1583 |  | 
| 695 |  |  |  | 
| 696 | gezelter | 1549 | fDecomp_->distributeIntermediateData(); | 
| 697 | gezelter | 1545 | } | 
| 698 |  |  | } | 
| 699 |  |  |  | 
| 700 | gezelter | 1544 | } | 
| 701 | gezelter | 1545 |  | 
| 702 | gezelter | 1549 | fDecomp_->collectData(); | 
| 703 | gezelter | 1545 |  | 
| 704 | gezelter | 1570 | if ( info_->requiresSkipCorrection() ) { | 
| 705 |  |  |  | 
| 706 |  |  | for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) { | 
| 707 | gezelter | 1544 |  | 
| 708 | gezelter | 1579 | vector<int> skipList = fDecomp_->getSkipsForAtom( atom1 ); | 
| 709 | gezelter | 1570 |  | 
| 710 |  |  | for (vector<int>::iterator jb = skipList.begin(); | 
| 711 |  |  | jb != skipList.end(); ++jb) { | 
| 712 |  |  |  | 
| 713 |  |  | atom2 = (*jb); | 
| 714 | gezelter | 1581 | fDecomp_->fillSkipData(idat, atom1, atom2); | 
| 715 | gezelter | 1570 | interactionMan_->doSkipCorrection(idat); | 
| 716 | gezelter | 1583 | fDecomp_->unpackSkipData(idat, atom1, atom2); | 
| 717 | gezelter | 1570 |  | 
| 718 | gezelter | 1545 | } | 
| 719 |  |  | } | 
| 720 | gezelter | 246 | } | 
| 721 | gezelter | 1570 |  | 
| 722 |  |  | if (info_->requiresSelfCorrection()) { | 
| 723 | gezelter | 1545 |  | 
| 724 | gezelter | 1570 | for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { | 
| 725 | gezelter | 1581 | fDecomp_->fillSelfData(sdat, atom1); | 
| 726 | gezelter | 1570 | interactionMan_->doSelfCorrection(sdat); | 
| 727 |  |  | } | 
| 728 |  |  |  | 
| 729 |  |  | } | 
| 730 |  |  |  | 
| 731 | gezelter | 1583 | longRangePotential = *(fDecomp_->getEmbeddingPotential()) + | 
| 732 |  |  | *(fDecomp_->getPairwisePotential()); | 
| 733 |  |  |  | 
| 734 | gezelter | 1575 | lrPot = longRangePotential.sum(); | 
| 735 |  |  |  | 
| 736 | gezelter | 246 | //store the tau and long range potential | 
| 737 | chuckv | 664 | curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot; | 
| 738 | gezelter | 1550 | curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY]; | 
| 739 |  |  | curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY]; | 
| 740 | gezelter | 507 | } | 
| 741 | gezelter | 246 |  | 
| 742 | gezelter | 1126 |  | 
| 743 | gezelter | 1464 | void ForceManager::postCalculation() { | 
| 744 | gezelter | 246 | SimInfo::MoleculeIterator mi; | 
| 745 |  |  | Molecule* mol; | 
| 746 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 747 |  |  | RigidBody* rb; | 
| 748 | gezelter | 1126 | Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 749 | gezelter | 246 |  | 
| 750 |  |  | // collect the atomic forces onto rigid bodies | 
| 751 | gezelter | 1126 |  | 
| 752 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 753 |  |  | mol = info_->nextMolecule(mi)) { | 
| 754 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; | 
| 755 |  |  | rb = mol->nextRigidBody(rbIter)) { | 
| 756 | gezelter | 1464 | Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial(); | 
| 757 |  |  | tau += rbTau; | 
| 758 | gezelter | 507 | } | 
| 759 | gezelter | 1126 | } | 
| 760 | gezelter | 1464 |  | 
| 761 | gezelter | 1126 | #ifdef IS_MPI | 
| 762 | gezelter | 1464 | Mat3x3d tmpTau(tau); | 
| 763 |  |  | MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(), | 
| 764 |  |  | 9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); | 
| 765 | gezelter | 1126 | #endif | 
| 766 | gezelter | 1464 | curSnapshot->statData.setTau(tau); | 
| 767 | gezelter | 507 | } | 
| 768 | gezelter | 246 |  | 
| 769 | gezelter | 1390 | } //end namespace OpenMD |