ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/ForceManager.cpp
(Generate patch)

Comparing:
trunk/src/brains/ForceManager.cpp (file contents), Revision 665 by tim, Thu Oct 13 22:26:47 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (file contents), Revision 1601 by gezelter, Thu Aug 4 20:04:35 2011 UTC

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

Comparing:
trunk/src/brains/ForceManager.cpp (property svn:keywords), Revision 665 by tim, Thu Oct 13 22:26:47 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (property svn:keywords), Revision 1601 by gezelter, Thu Aug 4 20:04:35 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines