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

Comparing:
trunk/src/brains/ForceManager.cpp (property svn:keywords), Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (property svn:keywords), Revision 1613 by gezelter, Thu Aug 18 20:18:19 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines