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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines