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

Comparing branches/development/src/brains/ForceManager.cpp (file contents):
Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC vs.
Revision 1587 by gezelter, Fri Jul 8 20:25:32 2011 UTC

# Line 47 | Line 47
47   * @version 1.0
48   */
49  
50 +
51   #include "brains/ForceManager.hpp"
52   #include "primitives/Molecule.hpp"
52 #include "UseTheForce/doForces_interface.h"
53   #define __OPENMD_C
54 #include "UseTheForce/DarkSide/fInteractionMap.h"
54   #include "utils/simError.h"
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 + #include <cstdio>
63 + #include <iostream>
64 + #include <iomanip>
65 +
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 <  void ForceManager::calcForces() {
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 <    if (!info_->isFortranInitialized()) {
109 <      info_->update();
66 <    }
108 >    Globals* simParams_ = info_->getSimParams();
109 >    ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
110      
111 <    preCalculation();
112 <    
113 <    calcShortRangeInteraction();
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 <    calcLongRangeInteraction();
142 >    fDecomp_->setUserCutoff(rCut_);
143 >    interactionMan_->setCutoffRadius(rCut_);
144  
145 <    postCalculation();
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 >    map<string, CutoffPolicy> stringToCutoffPolicy;
178 >    stringToCutoffPolicy["MIX"] = MIX;
179 >    stringToCutoffPolicy["MAX"] = MAX;
180 >    stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL;    
181 >
182 >    std::string cutPolicy;
183 >    if (forceFieldOptions_.haveCutoffPolicy()){
184 >      cutPolicy = forceFieldOptions_.getCutoffPolicy();
185 >    }else if (simParams_->haveCutoffPolicy()) {
186 >      cutPolicy = simParams_->getCutoffPolicy();
187 >    }
188 >
189 >    if (!cutPolicy.empty()){
190 >      toUpper(cutPolicy);
191 >      map<string, CutoffPolicy>::iterator i;
192 >      i = stringToCutoffPolicy.find(cutPolicy);
193 >
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 >    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 +    // 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 +    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 +
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 82 | Line 356 | namespace OpenMD {
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.
87    // NOTE: do not rezero the forces in Fortran.
363      
364      for (mol = info_->beginMolecule(mi); mol != NULL;
365           mol = info_->nextMolecule(mi)) {
# Line 97 | Line 372 | namespace OpenMD {
372             rb = mol->nextRigidBody(rbIter)) {
373          rb->zeroForcesAndTorques();
374        }        
375 <          
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 <    
384 >  
385      // Zero out the stress tensor
386      tau *= 0.0;
387      
388    }
389    
390 <  void ForceManager::calcShortRangeInteraction() {
390 >  void ForceManager::shortRangeInteractions() {
391      Molecule* mol;
392      RigidBody* rb;
393      Bond* bond;
# Line 147 | Line 429 | namespace OpenMD {
429          RealType currBendPot = bend->getPotential();          
430          
431          bendPotential += bend->getPotential();
432 <        std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend);
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(std::map<Bend*, BendDataSet>::value_type(bend, dataSet));
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;
# Line 170 | Line 452 | namespace OpenMD {
452          torsion->calcForce(angle);
453          RealType currTorsionPot = torsion->getPotential();
454          torsionPotential += torsion->getPotential();
455 <        std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
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(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet));
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;
# Line 186 | Line 468 | namespace OpenMD {
468                                     i->second.prev.potential);
469          }      
470        }      
471 <
471 >      
472        for (inversion = mol->beginInversion(inversionIter);
473             inversion != NULL;
474             inversion = mol->nextInversion(inversionIter)) {
# Line 194 | Line 476 | namespace OpenMD {
476          inversion->calcForce(angle);
477          RealType currInversionPot = inversion->getPotential();
478          inversionPotential += inversion->getPotential();
479 <        std::map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
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(std::map<Inversion*, InversionDataSet>::value_type(inversion, dataSet));
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;
# Line 219 | Line 501 | namespace OpenMD {
501      curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
502      curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
503      curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
504 <    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;
223 <    
504 >    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;    
505    }
506    
507 <  void ForceManager::calcLongRangeInteraction() {
227 <    Snapshot* curSnapshot;
228 <    DataStorage* config;
229 <    RealType* frc;
230 <    RealType* pos;
231 <    RealType* trq;
232 <    RealType* A;
233 <    RealType* electroFrame;
234 <    RealType* rc;
235 <    RealType* particlePot;
236 <    
237 <    //get current snapshot from SimInfo
238 <    curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
239 <    
240 <    //get array pointers
241 <    config = &(curSnapshot->atomData);
242 <    frc = config->getArrayPointer(DataStorage::dslForce);
243 <    pos = config->getArrayPointer(DataStorage::dslPosition);
244 <    trq = config->getArrayPointer(DataStorage::dslTorque);
245 <    A   = config->getArrayPointer(DataStorage::dslAmat);
246 <    electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
247 <    particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
507 >  void ForceManager::longRangeInteractions() {
508  
509 +    Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
510 +    DataStorage* config = &(curSnapshot->atomData);
511 +    DataStorage* cgConfig = &(curSnapshot->cgData);
512 +
513      //calculate the center of mass of cutoff group
514 +
515      SimInfo::MoleculeIterator mi;
516      Molecule* mol;
517      Molecule::CutoffGroupIterator ci;
518      CutoffGroup* cg;
519 <    Vector3d com;
520 <    std::vector<Vector3d> rcGroup;
256 <    
257 <    if(info_->getNCutoffGroups() > 0){
258 <      
519 >
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->getCOM(com);
264 <          rcGroup.push_back(com);
525 >          cg->updateCOM();
526          }
527 <      }// end for (mol)
267 <      
268 <      rc = rcGroup[0].getArrayPointer();
527 >      }      
528      } else {
529        // center of mass of the group is the same as position of the atom  
530        // if cutoff group does not exist
531 <      rc = pos;
531 >      cgConfig->position = config->position;
532      }
533 +
534 +    fDecomp_->zeroWorkArrays();
535 +    fDecomp_->distributeData();
536      
537 <    //initialize data before passing to fortran
538 <    RealType longRangePotential[LR_POT_TYPES];
539 <    RealType lrPot = 0.0;
540 <    Vector3d totalDipole;
541 <    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
558 <    }
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 <    doForceLoop(pos,
569 <                rc,
570 <                A,
571 <                electroFrame,
572 <                frc,
290 <                trq,
291 <                tau.getArrayPointer(),
292 <                longRangePotential,
293 <                particlePot,
294 <                &isError );
295 <    
296 <    if( isError ){
297 <      sprintf( painCave.errMsg,
298 <               "Error returned from the fortran force calculation.\n" );
299 <      painCave.isFatal = 1;
300 <      simError();
568 >    loopEnd = PAIR_LOOP;
569 >    if (info_->requiresPrepair() ) {
570 >      loopStart = PREPAIR_LOOP;
571 >    } else {
572 >      loopStart = PAIR_LOOP;
573      }
574 <    for (int i=0; i<LR_POT_TYPES;i++){
575 <      lrPot += longRangePotential[i]; //Quick hack
304 <    }
574 >  
575 >    for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
576      
577 <    // grab the simulation box dipole moment if specified
578 <    if (info_->getCalcBoxDipole()){
579 <      getAccumulatedBoxDipole(totalDipole.getArrayPointer());
580 <      
581 <      curSnapshot->statData[Stats::BOX_DIPOLE_X] = totalDipole(0);
582 <      curSnapshot->statData[Stats::BOX_DIPOLE_Y] = totalDipole(1);
583 <      curSnapshot->statData[Stats::BOX_DIPOLE_Z] = totalDipole(2);
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 >        d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
592 >        curSnapshot->wrapVector(d_grp);        
593 >        rgrpsq = d_grp.lengthSquare();
594 >
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      
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];
744 >    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
745 >    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
746    }
747  
748    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines