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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines