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 1489 by gezelter, Tue Aug 10 18:34:59 2010 UTC vs.
Revision 1581 by gezelter, Mon Jun 13 22:13:12 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 + using namespace std;
63   namespace OpenMD {
64    
65 <  ForceManager::ForceManager(SimInfo * info) : info_(info),
66 <                                               NBforcesInitialized_(false) {
67 <    lj_ = LJ::Instance();
68 <    lj_->setForceField(info_->getForceField());
65 >  ForceManager::ForceManager(SimInfo * info) : info_(info) {
66 >    forceField_ = info_->getForceField();
67 >    interactionMan_ = new InteractionManager();
68 >    fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_);
69 >  }
70  
71 <    gb_ = GB::Instance();
72 <    gb_->setForceField(info_->getForceField());
71 >  /**
72 >   * setupCutoffs
73 >   *
74 >   * Sets the values of cutoffRadius, cutoffMethod, and cutoffPolicy
75 >   *
76 >   * cutoffRadius : realType
77 >   *  If the cutoffRadius was explicitly set, use that value.
78 >   *  If the cutoffRadius was not explicitly set:
79 >   *      Are there electrostatic atoms?  Use 12.0 Angstroms.
80 >   *      No electrostatic atoms?  Poll the atom types present in the
81 >   *      simulation for suggested cutoff values (e.g. 2.5 * sigma).
82 >   *      Use the maximum suggested value that was found.
83 >   *
84 >   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, SHIFTED_POTENTIAL)
85 >   *      If cutoffMethod was explicitly set, use that choice.
86 >   *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE
87 >   *
88 >   * cutoffPolicy : (one of MIX, MAX, TRADITIONAL)
89 >   *      If cutoffPolicy was explicitly set, use that choice.
90 >   *      If cutoffPolicy was not explicitly set, use TRADITIONAL
91 >   */
92 >  void ForceManager::setupCutoffs() {
93 >    
94 >    Globals* simParams_ = info_->getSimParams();
95 >    ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
96 >    
97 >    if (simParams_->haveCutoffRadius()) {
98 >      rCut_ = simParams_->getCutoffRadius();
99 >    } else {      
100 >      if (info_->usesElectrostaticAtoms()) {
101 >        sprintf(painCave.errMsg,
102 >                "ForceManager::setupCutoffs: No value was set for the cutoffRadius.\n"
103 >                "\tOpenMD will use a default value of 12.0 angstroms"
104 >                "\tfor the cutoffRadius.\n");
105 >        painCave.isFatal = 0;
106 >        painCave.severity = OPENMD_INFO;
107 >        simError();
108 >        rCut_ = 12.0;
109 >      } else {
110 >        RealType thisCut;
111 >        set<AtomType*>::iterator i;
112 >        set<AtomType*> atomTypes;
113 >        atomTypes = info_->getSimulatedAtomTypes();        
114 >        for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
115 >          thisCut = interactionMan_->getSuggestedCutoffRadius((*i));
116 >          rCut_ = max(thisCut, rCut_);
117 >        }
118 >        sprintf(painCave.errMsg,
119 >                "ForceManager::setupCutoffs: No value was set for the cutoffRadius.\n"
120 >                "\tOpenMD will use %lf angstroms.\n",
121 >                rCut_);
122 >        painCave.isFatal = 0;
123 >        painCave.severity = OPENMD_INFO;
124 >        simError();
125 >      }
126 >      fDecomp_->setUserCutoff(rCut_);
127 >    }
128  
129 <    sticky_ = Sticky::Instance();
130 <    sticky_->setForceField(info_->getForceField());
129 >    map<string, CutoffMethod> stringToCutoffMethod;
130 >    stringToCutoffMethod["HARD"] = HARD;
131 >    stringToCutoffMethod["SWITCHED"] = SWITCHED;
132 >    stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL;    
133 >    stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE;
134 >  
135 >    if (simParams_->haveCutoffMethod()) {
136 >      string cutMeth = toUpperCopy(simParams_->getCutoffMethod());
137 >      map<string, CutoffMethod>::iterator i;
138 >      i = stringToCutoffMethod.find(cutMeth);
139 >      if (i == stringToCutoffMethod.end()) {
140 >        sprintf(painCave.errMsg,
141 >                "ForceManager::setupCutoffs: Could not find chosen cutoffMethod %s\n"
142 >                "\tShould be one of: "
143 >                "HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n",
144 >                cutMeth.c_str());
145 >        painCave.isFatal = 1;
146 >        painCave.severity = OPENMD_ERROR;
147 >        simError();
148 >      } else {
149 >        cutoffMethod_ = i->second;
150 >      }
151 >    } else {
152 >      sprintf(painCave.errMsg,
153 >              "ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n"
154 >              "\tOpenMD will use SHIFTED_FORCE.\n");
155 >      painCave.isFatal = 0;
156 >      painCave.severity = OPENMD_INFO;
157 >      simError();
158 >      cutoffMethod_ = SHIFTED_FORCE;        
159 >    }
160  
161 <    eam_ = EAM::Instance();
162 <    eam_->setForceField(info_->getForceField());
161 >    map<string, CutoffPolicy> stringToCutoffPolicy;
162 >    stringToCutoffPolicy["MIX"] = MIX;
163 >    stringToCutoffPolicy["MAX"] = MAX;
164 >    stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL;    
165  
166 <    sc_ = SC::Instance();
167 <    sc_->setForceField(info_->getForceField());
168 <  }
169 <
170 <  void ForceManager::calcForces() {
82 <    
83 <    if (!info_->isFortranInitialized()) {
84 <      info_->update();
166 >    std::string cutPolicy;
167 >    if (forceFieldOptions_.haveCutoffPolicy()){
168 >      cutPolicy = forceFieldOptions_.getCutoffPolicy();
169 >    }else if (simParams_->haveCutoffPolicy()) {
170 >      cutPolicy = simParams_->getCutoffPolicy();
171      }
86    
87    preCalculation();
88    
89    calcShortRangeInteraction();
172  
173 <    calcLongRangeInteraction();
173 >    if (!cutPolicy.empty()){
174 >      toUpper(cutPolicy);
175 >      map<string, CutoffPolicy>::iterator i;
176 >      i = stringToCutoffPolicy.find(cutPolicy);
177  
178 <    postCalculation();
178 >      if (i == stringToCutoffPolicy.end()) {
179 >        sprintf(painCave.errMsg,
180 >                "ForceManager::setupCutoffs: Could not find chosen cutoffPolicy %s\n"
181 >                "\tShould be one of: "
182 >                "MIX, MAX, or TRADITIONAL\n",
183 >                cutPolicy.c_str());
184 >        painCave.isFatal = 1;
185 >        painCave.severity = OPENMD_ERROR;
186 >        simError();
187 >      } else {
188 >        cutoffPolicy_ = i->second;
189 >      }
190 >    } else {
191 >      sprintf(painCave.errMsg,
192 >              "ForceManager::setupCutoffs: No value was set for the cutoffPolicy.\n"
193 >              "\tOpenMD will use TRADITIONAL.\n");
194 >      painCave.isFatal = 0;
195 >      painCave.severity = OPENMD_INFO;
196 >      simError();
197 >      cutoffPolicy_ = TRADITIONAL;        
198 >    }
199 >    fDecomp_->setCutoffPolicy(cutoffPolicy_);
200 >  }
201 >
202 >  /**
203 >   * setupSwitching
204 >   *
205 >   * Sets the values of switchingRadius and
206 >   *  If the switchingRadius was explicitly set, use that value (but check it)
207 >   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
208 >   */
209 >  void ForceManager::setupSwitching() {
210 >    Globals* simParams_ = info_->getSimParams();
211 >
212 >    // create the switching function object:
213 >    switcher_ = new SwitchingFunction();
214      
215 +    if (simParams_->haveSwitchingRadius()) {
216 +      rSwitch_ = simParams_->getSwitchingRadius();
217 +      if (rSwitch_ > rCut_) {        
218 +        sprintf(painCave.errMsg,
219 +                "ForceManager::setupSwitching: switchingRadius (%f) is larger "
220 +                "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
221 +        painCave.isFatal = 1;
222 +        painCave.severity = OPENMD_ERROR;
223 +        simError();
224 +      }
225 +    } else {      
226 +      rSwitch_ = 0.85 * rCut_;
227 +      sprintf(painCave.errMsg,
228 +              "ForceManager::setupSwitching: No value was set for the switchingRadius.\n"
229 +              "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
230 +              "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
231 +      painCave.isFatal = 0;
232 +      painCave.severity = OPENMD_WARNING;
233 +      simError();
234 +    }          
235 +    
236 +    // Default to cubic switching function.
237 +    sft_ = cubic;
238 +    if (simParams_->haveSwitchingFunctionType()) {
239 +      string funcType = simParams_->getSwitchingFunctionType();
240 +      toUpper(funcType);
241 +      if (funcType == "CUBIC") {
242 +        sft_ = cubic;
243 +      } else {
244 +        if (funcType == "FIFTH_ORDER_POLYNOMIAL") {
245 +          sft_ = fifth_order_poly;
246 +        } else {
247 +          // throw error        
248 +          sprintf( painCave.errMsg,
249 +                   "ForceManager::setupSwitching : Unknown switchingFunctionType. (Input file specified %s .)\n"
250 +                   "\tswitchingFunctionType must be one of: "
251 +                   "\"cubic\" or \"fifth_order_polynomial\".",
252 +                   funcType.c_str() );
253 +          painCave.isFatal = 1;
254 +          painCave.severity = OPENMD_ERROR;
255 +          simError();
256 +        }          
257 +      }
258 +    }
259 +    switcher_->setSwitchType(sft_);
260 +    switcher_->setSwitch(rSwitch_, rCut_);
261    }
262    
263 +  void ForceManager::initialize() {
264 +
265 +    if (!info_->isTopologyDone()) {
266 +      info_->update();
267 +      interactionMan_->setSimInfo(info_);
268 +      interactionMan_->initialize();
269 +
270 +      // We want to delay the cutoffs until after the interaction
271 +      // manager has set up the atom-atom interactions so that we can
272 +      // query them for suggested cutoff values
273 +
274 +      setupCutoffs();
275 +      setupSwitching();
276 +
277 +      info_->prepareTopology();      
278 +    }
279 +
280 +    ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
281 +    
282 +    // Force fields can set options on how to scale van der Waals and electrostatic
283 +    // interactions for atoms connected via bonds, bends and torsions
284 +    // in this case the topological distance between atoms is:
285 +    // 0 = topologically unconnected
286 +    // 1 = bonded together
287 +    // 2 = connected via a bend
288 +    // 3 = connected via a torsion
289 +    
290 +    vdwScale_.reserve(4);
291 +    fill(vdwScale_.begin(), vdwScale_.end(), 0.0);
292 +
293 +    electrostaticScale_.reserve(4);
294 +    fill(electrostaticScale_.begin(), electrostaticScale_.end(), 0.0);
295 +
296 +    vdwScale_[0] = 1.0;
297 +    vdwScale_[1] = fopts.getvdw12scale();
298 +    vdwScale_[2] = fopts.getvdw13scale();
299 +    vdwScale_[3] = fopts.getvdw14scale();
300 +    
301 +    electrostaticScale_[0] = 1.0;
302 +    electrostaticScale_[1] = fopts.getelectrostatic12scale();
303 +    electrostaticScale_[2] = fopts.getelectrostatic13scale();
304 +    electrostaticScale_[3] = fopts.getelectrostatic14scale();    
305 +    
306 +    fDecomp_->distributeInitialData();
307 +
308 +    initialized_ = true;
309 +
310 +  }
311 +
312 +  void ForceManager::calcForces() {
313 +    
314 +    if (!initialized_) initialize();
315 +
316 +    preCalculation();  
317 +    shortRangeInteractions();
318 +    longRangeInteractions();
319 +    postCalculation();    
320 +  }
321 +  
322    void ForceManager::preCalculation() {
323      SimInfo::MoleculeIterator mi;
324      Molecule* mol;
# Line 101 | Line 326 | namespace OpenMD {
326      Atom* atom;
327      Molecule::RigidBodyIterator rbIter;
328      RigidBody* rb;
329 +    Molecule::CutoffGroupIterator ci;
330 +    CutoffGroup* cg;
331      
332      // forces are zeroed here, before any are accumulated.
106    // NOTE: do not rezero the forces in Fortran.
333      
334      for (mol = info_->beginMolecule(mi); mol != NULL;
335           mol = info_->nextMolecule(mi)) {
# Line 116 | Line 342 | namespace OpenMD {
342             rb = mol->nextRigidBody(rbIter)) {
343          rb->zeroForcesAndTorques();
344        }        
345 <          
345 >
346 >      if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){
347 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
348 >            cg = mol->nextCutoffGroup(ci)) {
349 >          //calculate the center of mass of cutoff group
350 >          cg->updateCOM();
351 >        }
352 >      }      
353      }
354 <    
354 >  
355      // Zero out the stress tensor
356      tau *= 0.0;
357      
358    }
359    
360 <  void ForceManager::calcShortRangeInteraction() {
360 >  void ForceManager::shortRangeInteractions() {
361      Molecule* mol;
362      RigidBody* rb;
363      Bond* bond;
# Line 166 | Line 399 | namespace OpenMD {
399          RealType currBendPot = bend->getPotential();          
400          
401          bendPotential += bend->getPotential();
402 <        std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend);
402 >        map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend);
403          if (i == bendDataSets.end()) {
404            BendDataSet dataSet;
405            dataSet.prev.angle = dataSet.curr.angle = angle;
406            dataSet.prev.potential = dataSet.curr.potential = currBendPot;
407            dataSet.deltaV = 0.0;
408 <          bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet));
408 >          bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, dataSet));
409          }else {
410            i->second.prev.angle = i->second.curr.angle;
411            i->second.prev.potential = i->second.curr.potential;
# Line 189 | Line 422 | namespace OpenMD {
422          torsion->calcForce(angle);
423          RealType currTorsionPot = torsion->getPotential();
424          torsionPotential += torsion->getPotential();
425 <        std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
425 >        map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
426          if (i == torsionDataSets.end()) {
427            TorsionDataSet dataSet;
428            dataSet.prev.angle = dataSet.curr.angle = angle;
429            dataSet.prev.potential = dataSet.curr.potential = currTorsionPot;
430            dataSet.deltaV = 0.0;
431 <          torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet));
431 >          torsionDataSets.insert(map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet));
432          }else {
433            i->second.prev.angle = i->second.curr.angle;
434            i->second.prev.potential = i->second.curr.potential;
# Line 205 | Line 438 | namespace OpenMD {
438                                     i->second.prev.potential);
439          }      
440        }      
441 <
441 >      
442        for (inversion = mol->beginInversion(inversionIter);
443             inversion != NULL;
444             inversion = mol->nextInversion(inversionIter)) {
# Line 213 | Line 446 | namespace OpenMD {
446          inversion->calcForce(angle);
447          RealType currInversionPot = inversion->getPotential();
448          inversionPotential += inversion->getPotential();
449 <        std::map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
449 >        map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
450          if (i == inversionDataSets.end()) {
451            InversionDataSet dataSet;
452            dataSet.prev.angle = dataSet.curr.angle = angle;
453            dataSet.prev.potential = dataSet.curr.potential = currInversionPot;
454            dataSet.deltaV = 0.0;
455 <          inversionDataSets.insert(std::map<Inversion*, InversionDataSet>::value_type(inversion, dataSet));
455 >          inversionDataSets.insert(map<Inversion*, InversionDataSet>::value_type(inversion, dataSet));
456          }else {
457            i->second.prev.angle = i->second.curr.angle;
458            i->second.prev.potential = i->second.curr.potential;
# Line 238 | Line 471 | namespace OpenMD {
471      curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
472      curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
473      curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
474 <    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;
242 <    
474 >    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;    
475    }
476    
477 <  void ForceManager::calcLongRangeInteraction() {
246 <    Snapshot* curSnapshot;
247 <    DataStorage* config;
248 <    RealType* frc;
249 <    RealType* pos;
250 <    RealType* trq;
251 <    RealType* A;
252 <    RealType* electroFrame;
253 <    RealType* rc;
254 <    RealType* particlePot;
255 <    
256 <    //get current snapshot from SimInfo
257 <    curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
258 <    
259 <    //get array pointers
260 <    config = &(curSnapshot->atomData);
261 <    frc = config->getArrayPointer(DataStorage::dslForce);
262 <    pos = config->getArrayPointer(DataStorage::dslPosition);
263 <    trq = config->getArrayPointer(DataStorage::dslTorque);
264 <    A   = config->getArrayPointer(DataStorage::dslAmat);
265 <    electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
266 <    particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
477 >  void ForceManager::longRangeInteractions() {
478  
479 +    Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
480 +    DataStorage* config = &(curSnapshot->atomData);
481 +    DataStorage* cgConfig = &(curSnapshot->cgData);
482 +
483      //calculate the center of mass of cutoff group
484 +
485      SimInfo::MoleculeIterator mi;
486      Molecule* mol;
487      Molecule::CutoffGroupIterator ci;
488      CutoffGroup* cg;
489 <    Vector3d com;
490 <    std::vector<Vector3d> rcGroup;
275 <    
276 <    if(info_->getNCutoffGroups() > 0){
277 <      
489 >
490 >    if(info_->getNCutoffGroups() > 0){      
491        for (mol = info_->beginMolecule(mi); mol != NULL;
492             mol = info_->nextMolecule(mi)) {
493          for(cg = mol->beginCutoffGroup(ci); cg != NULL;
494              cg = mol->nextCutoffGroup(ci)) {
495 <          cg->getCOM(com);
283 <          rcGroup.push_back(com);
495 >          cg->updateCOM();
496          }
497 <      }// end for (mol)
286 <      
287 <      rc = rcGroup[0].getArrayPointer();
497 >      }      
498      } else {
499        // center of mass of the group is the same as position of the atom  
500        // if cutoff group does not exist
501 <      rc = pos;
501 >      cgConfig->position = config->position;
502      }
503 +
504 +    fDecomp_->zeroWorkArrays();
505 +    fDecomp_->distributeData();
506      
507 <    //initialize data before passing to fortran
508 <    RealType longRangePotential[LR_POT_TYPES];
509 <    RealType lrPot = 0.0;
510 <    Vector3d totalDipole;
511 <    int isError = 0;
507 >    int cg1, cg2, atom1, atom2, topoDist;
508 >    Vector3d d_grp, dag, d;
509 >    RealType rgrpsq, rgrp, r2, r;
510 >    RealType electroMult, vdwMult;
511 >    RealType vij;
512 >    Vector3d fij, fg, f1;
513 >    tuple3<RealType, RealType, RealType> cuts;
514 >    RealType rCutSq;
515 >    bool in_switching_region;
516 >    RealType sw, dswdr, swderiv;
517 >    vector<int> atomListColumn, atomListRow, atomListLocal;
518 >    InteractionData idat;
519 >    SelfData sdat;
520 >    RealType mf;
521 >    potVec pot(0.0);
522 >    potVec longRangePotential(0.0);
523 >    RealType lrPot;
524 >    RealType vpair;
525  
526 <    for (int i=0; i<LR_POT_TYPES;i++){
527 <      longRangePotential[i]=0.0; //Initialize array
526 >    int loopStart, loopEnd;
527 >
528 >    idat.vdwMult = &vdwMult;
529 >    idat.electroMult = &electroMult;
530 >    idat.pot = &pot;
531 >    idat.vpair = &vpair;
532 >    idat.f1 = &f1;
533 >    idat.sw = &sw;
534 >
535 >    loopEnd = PAIR_LOOP;
536 >    if (info_->requiresPrepair() ) {
537 >      loopStart = PREPAIR_LOOP;
538 >    } else {
539 >      loopStart = PAIR_LOOP;
540      }
541      
542 <    doForceLoop(pos,
305 <                rc,
306 <                A,
307 <                electroFrame,
308 <                frc,
309 <                trq,
310 <                tau.getArrayPointer(),
311 <                longRangePotential,
312 <                particlePot,
313 <                &isError );
542 >    for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
543      
544 <    if( isError ){
545 <      sprintf( painCave.errMsg,
546 <               "Error returned from the fortran force calculation.\n" );
547 <      painCave.isFatal = 1;
548 <      simError();
544 >      if (iLoop == loopStart) {
545 >        bool update_nlist = fDecomp_->checkNeighborList();
546 >        if (update_nlist)
547 >          neighborList = fDecomp_->buildNeighborList();
548 >      }      
549 >        
550 >      for (vector<pair<int, int> >::iterator it = neighborList.begin();
551 >             it != neighborList.end(); ++it) {
552 >                
553 >        cg1 = (*it).first;
554 >        cg2 = (*it).second;
555 >        
556 >        cuts = fDecomp_->getGroupCutoffs(cg1, cg2);
557 >
558 >        d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
559 >        curSnapshot->wrapVector(d_grp);        
560 >        rgrpsq = d_grp.lengthSquare();
561 >
562 >        rCutSq = cuts.second;
563 >
564 >        if (rgrpsq < rCutSq) {
565 >          idat.rcut = &cuts.first;
566 >          if (iLoop == PAIR_LOOP) {
567 >            vij *= 0.0;
568 >            fij = V3Zero;
569 >          }
570 >          
571 >          in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
572 >                                                     rgrp);
573 >              
574 >          atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
575 >          atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
576 >
577 >          for (vector<int>::iterator ia = atomListRow.begin();
578 >               ia != atomListRow.end(); ++ia) {            
579 >            atom1 = (*ia);
580 >            
581 >            for (vector<int>::iterator jb = atomListColumn.begin();
582 >                 jb != atomListColumn.end(); ++jb) {              
583 >              atom2 = (*jb);
584 >              
585 >              if (!fDecomp_->skipAtomPair(atom1, atom2)) {
586 >                
587 >                vpair = 0.0;
588 >                f1 = V3Zero;
589 >
590 >                fDecomp_->fillInteractionData(idat, atom1, atom2);
591 >                
592 >                topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
593 >                vdwMult = vdwScale_[topoDist];
594 >                electroMult = electrostaticScale_[topoDist];
595 >
596 >                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
597 >                  idat.d = &d_grp;
598 >                  idat.r2 = &rgrpsq;
599 >                } else {
600 >                  d = fDecomp_->getInteratomicVector(atom1, atom2);
601 >                  curSnapshot->wrapVector( d );
602 >                  r2 = d.lengthSquare();
603 >                  idat.d = &d;
604 >                  idat.r2 = &r2;
605 >                }
606 >                
607 >                r = sqrt( *(idat.r2) );
608 >                idat.rij = &r;
609 >              
610 >                if (iLoop == PREPAIR_LOOP) {
611 >                  interactionMan_->doPrePair(idat);
612 >                } else {
613 >                  interactionMan_->doPair(idat);
614 >                  fDecomp_->unpackInteractionData(idat, atom1, atom2);
615 >                  vij += vpair;
616 >                  fij += f1;
617 >                  tau -= outProduct( *(idat.d), f1);
618 >                }
619 >              }
620 >            }
621 >          }
622 >
623 >          if (iLoop == PAIR_LOOP) {
624 >            if (in_switching_region) {
625 >              swderiv = vij * dswdr / rgrp;
626 >              fg = swderiv * d_grp;
627 >
628 >              fij += fg;
629 >
630 >              if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
631 >                tau -= outProduct( *(idat.d), fg);
632 >              }
633 >          
634 >              for (vector<int>::iterator ia = atomListRow.begin();
635 >                   ia != atomListRow.end(); ++ia) {            
636 >                atom1 = (*ia);                
637 >                mf = fDecomp_->getMassFactorRow(atom1);
638 >                // fg is the force on atom ia due to cutoff group's
639 >                // presence in switching region
640 >                fg = swderiv * d_grp * mf;
641 >                fDecomp_->addForceToAtomRow(atom1, fg);
642 >
643 >                if (atomListRow.size() > 1) {
644 >                  if (info_->usesAtomicVirial()) {
645 >                    // find the distance between the atom
646 >                    // and the center of the cutoff group:
647 >                    dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
648 >                    tau -= outProduct(dag, fg);
649 >                  }
650 >                }
651 >              }
652 >              for (vector<int>::iterator jb = atomListColumn.begin();
653 >                   jb != atomListColumn.end(); ++jb) {              
654 >                atom2 = (*jb);
655 >                mf = fDecomp_->getMassFactorColumn(atom2);
656 >                // fg is the force on atom jb due to cutoff group's
657 >                // presence in switching region
658 >                fg = -swderiv * d_grp * mf;
659 >                fDecomp_->addForceToAtomColumn(atom2, fg);
660 >
661 >                if (atomListColumn.size() > 1) {
662 >                  if (info_->usesAtomicVirial()) {
663 >                    // find the distance between the atom
664 >                    // and the center of the cutoff group:
665 >                    dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
666 >                    tau -= outProduct(dag, fg);
667 >                  }
668 >                }
669 >              }
670 >            }
671 >            //if (!SIM_uses_AtomicVirial) {
672 >            //  tau -= outProduct(d_grp, fij);
673 >            //}
674 >          }
675 >        }
676 >      }
677 >
678 >      if (iLoop == PREPAIR_LOOP) {
679 >        if (info_->requiresPrepair()) {            
680 >          fDecomp_->collectIntermediateData();
681 >
682 >          for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
683 >            fDecomp_->fillSelfData(sdat, atom1);
684 >            interactionMan_->doPreForce(sdat);
685 >          }
686 >
687 >          fDecomp_->distributeIntermediateData();        
688 >        }
689 >      }
690 >
691      }
321    for (int i=0; i<LR_POT_TYPES;i++){
322      lrPot += longRangePotential[i]; //Quick hack
323    }
692      
693 <    // grab the simulation box dipole moment if specified
694 <    if (info_->getCalcBoxDipole()){
695 <      getAccumulatedBoxDipole(totalDipole.getArrayPointer());
693 >    fDecomp_->collectData();
694 >    
695 >    if ( info_->requiresSkipCorrection() ) {
696        
697 <      curSnapshot->statData[Stats::BOX_DIPOLE_X] = totalDipole(0);
698 <      curSnapshot->statData[Stats::BOX_DIPOLE_Y] = totalDipole(1);
699 <      curSnapshot->statData[Stats::BOX_DIPOLE_Z] = totalDipole(2);
697 >      for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
698 >
699 >        vector<int> skipList = fDecomp_->getSkipsForAtom( atom1 );
700 >        
701 >        for (vector<int>::iterator jb = skipList.begin();
702 >             jb != skipList.end(); ++jb) {        
703 >    
704 >          atom2 = (*jb);
705 >          fDecomp_->fillSkipData(idat, atom1, atom2);
706 >          interactionMan_->doSkipCorrection(idat);
707 >
708 >        }
709 >      }
710      }
711      
712 +    if (info_->requiresSelfCorrection()) {
713 +
714 +      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
715 +        fDecomp_->fillSelfData(sdat, atom1);
716 +        interactionMan_->doSelfCorrection(sdat);
717 +      }
718 +
719 +    }
720 +
721 +    longRangePotential = fDecomp_->getLongRangePotential();
722 +    lrPot = longRangePotential.sum();
723 +
724      //store the tau and long range potential    
725      curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
726 <    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
727 <    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
726 >    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
727 >    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
728    }
729  
730    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines