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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines