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 1597 by gezelter, Tue Jul 26 15:49:24 2011 UTC vs.
Revision 1868 by gezelter, Tue Apr 30 15:56:54 2013 UTC

# Line 35 | Line 35
35   *                                                                      
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 < * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 < * [4]  Vardeman & Gezelter, in progress (2009).                        
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   /**
44   * @file ForceManager.cpp
45   * @author tlin
46   * @date 11/09/2004
46 * @time 10:39am
47   * @version 1.0
48   */
49  
# Line 57 | Line 57
57   #include "primitives/Torsion.hpp"
58   #include "primitives/Inversion.hpp"
59   #include "nonbonded/NonBondedInteraction.hpp"
60 + #include "perturbations/ElectricField.hpp"
61   #include "parallel/ForceMatrixDecomposition.hpp"
62  
63   #include <cstdio>
# Line 66 | Line 67 | namespace OpenMD {
67   using namespace std;
68   namespace OpenMD {
69    
70 <  ForceManager::ForceManager(SimInfo * info) : info_(info) {
70 >  ForceManager::ForceManager(SimInfo * info) : info_(info), switcher_(NULL) {
71      forceField_ = info_->getForceField();
72      interactionMan_ = new InteractionManager();
73      fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_);
74 +    thermo = new Thermo(info_);
75    }
76  
77 +  ForceManager::~ForceManager() {
78 +    perturbations_.clear();
79 +    
80 +    delete switcher_;
81 +    delete interactionMan_;
82 +    delete fDecomp_;
83 +    delete thermo;
84 +  }
85 +  
86    /**
87     * setupCutoffs
88     *
# Line 108 | Line 119 | namespace OpenMD {
119      
120      Globals* simParams_ = info_->getSimParams();
121      ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
122 +    int mdFileVersion;
123 +    rCut_ = 0.0; //Needs a value for a later max() call;  
124      
125 +    if (simParams_->haveMDfileVersion())
126 +      mdFileVersion = simParams_->getMDfileVersion();
127 +    else
128 +      mdFileVersion = 0;
129 +  
130 +    // We need the list of simulated atom types to figure out cutoffs
131 +    // as well as long range corrections.
132 +
133 +    set<AtomType*>::iterator i;
134 +    set<AtomType*> atomTypes_;
135 +    atomTypes_ = info_->getSimulatedAtomTypes();
136 +
137      if (simParams_->haveCutoffRadius()) {
138        rCut_ = simParams_->getCutoffRadius();
139      } else {      
# Line 123 | Line 148 | namespace OpenMD {
148          rCut_ = 12.0;
149        } else {
150          RealType thisCut;
151 <        set<AtomType*>::iterator i;
127 <        set<AtomType*> atomTypes;
128 <        atomTypes = info_->getSimulatedAtomTypes();        
129 <        for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
151 >        for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) {
152            thisCut = interactionMan_->getSuggestedCutoffRadius((*i));
153            rCut_ = max(thisCut, rCut_);
154          }
# Line 166 | Line 188 | namespace OpenMD {
188          cutoffMethod_ = i->second;
189        }
190      } else {
191 <      sprintf(painCave.errMsg,
192 <              "ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n"
193 <              "\tOpenMD will use SHIFTED_FORCE.\n");
194 <      painCave.isFatal = 0;
195 <      painCave.severity = OPENMD_INFO;
196 <      simError();
197 <      cutoffMethod_ = SHIFTED_FORCE;        
191 >      if (mdFileVersion > 1) {
192 >        sprintf(painCave.errMsg,
193 >                "ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n"
194 >                "\tOpenMD will use SHIFTED_FORCE.\n");
195 >        painCave.isFatal = 0;
196 >        painCave.severity = OPENMD_INFO;
197 >        simError();
198 >        cutoffMethod_ = SHIFTED_FORCE;        
199 >      } else {
200 >        // handle the case where the old file version was in play
201 >        // (there should be no cutoffMethod, so we have to deduce it
202 >        // from other data).        
203 >
204 >        sprintf(painCave.errMsg,
205 >                "ForceManager::setupCutoffs : DEPRECATED FILE FORMAT!\n"
206 >                "\tOpenMD found a file which does not set a cutoffMethod.\n"
207 >                "\tOpenMD will attempt to deduce a cutoffMethod using the\n"
208 >                "\tbehavior of the older (version 1) code.  To remove this\n"
209 >                "\twarning, add an explicit cutoffMethod and change the top\n"
210 >                "\tof the file so that it begins with <OpenMD version=2>\n");
211 >        painCave.isFatal = 0;
212 >        painCave.severity = OPENMD_WARNING;
213 >        simError();            
214 >                
215 >        // The old file version tethered the shifting behavior to the
216 >        // electrostaticSummationMethod keyword.
217 >        
218 >        if (simParams_->haveElectrostaticSummationMethod()) {
219 >          string myMethod = simParams_->getElectrostaticSummationMethod();
220 >          toUpper(myMethod);
221 >        
222 >          if (myMethod == "SHIFTED_POTENTIAL") {
223 >            cutoffMethod_ = SHIFTED_POTENTIAL;
224 >          } else if (myMethod == "SHIFTED_FORCE") {
225 >            cutoffMethod_ = SHIFTED_FORCE;
226 >          }
227 >        
228 >          if (simParams_->haveSwitchingRadius())
229 >            rSwitch_ = simParams_->getSwitchingRadius();
230 >
231 >          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") {
232 >            if (simParams_->haveSwitchingRadius()){
233 >              sprintf(painCave.errMsg,
234 >                      "ForceManager::setupCutoffs : DEPRECATED ERROR MESSAGE\n"
235 >                      "\tA value was set for the switchingRadius\n"
236 >                      "\teven though the electrostaticSummationMethod was\n"
237 >                      "\tset to %s\n", myMethod.c_str());
238 >              painCave.severity = OPENMD_WARNING;
239 >              painCave.isFatal = 1;
240 >              simError();            
241 >            }
242 >          }
243 >          if (abs(rCut_ - rSwitch_) < 0.0001) {
244 >            if (cutoffMethod_ == SHIFTED_FORCE) {              
245 >              sprintf(painCave.errMsg,
246 >                      "ForceManager::setupCutoffs : DEPRECATED BEHAVIOR\n"
247 >                      "\tcutoffRadius and switchingRadius are set to the\n"
248 >                      "\tsame value.  OpenMD will use shifted force\n"
249 >                      "\tpotentials instead of switching functions.\n");
250 >              painCave.isFatal = 0;
251 >              painCave.severity = OPENMD_WARNING;
252 >              simError();            
253 >            } else {
254 >              cutoffMethod_ = SHIFTED_POTENTIAL;
255 >              sprintf(painCave.errMsg,
256 >                      "ForceManager::setupCutoffs : DEPRECATED BEHAVIOR\n"
257 >                      "\tcutoffRadius and switchingRadius are set to the\n"
258 >                      "\tsame value.  OpenMD will use shifted potentials\n"
259 >                      "\tinstead of switching functions.\n");
260 >              painCave.isFatal = 0;
261 >              painCave.severity = OPENMD_WARNING;
262 >              simError();            
263 >            }
264 >          }
265 >        }
266 >      }
267      }
268  
269      map<string, CutoffPolicy> stringToCutoffPolicy;
# Line 180 | Line 271 | namespace OpenMD {
271      stringToCutoffPolicy["MAX"] = MAX;
272      stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL;    
273  
274 <    std::string cutPolicy;
274 >    string cutPolicy;
275      if (forceFieldOptions_.haveCutoffPolicy()){
276        cutPolicy = forceFieldOptions_.getCutoffPolicy();
277      }else if (simParams_->haveCutoffPolicy()) {
# Line 242 | Line 333 | namespace OpenMD {
333          simError();
334        }
335      } else {
336 <      if (simParams_->haveSwitchingRadius()) {
337 <        map<string, CutoffMethod>::const_iterator it;
338 <        string theMeth;
339 <        for (it = stringToCutoffMethod.begin();
340 <             it != stringToCutoffMethod.end(); ++it) {
341 <          if (it->second == cutoffMethod_) {
342 <            theMeth = it->first;
343 <            break;
336 >      if (mdFileVersion > 1) {
337 >        // throw an error if we define a switching radius and don't need one.
338 >        // older file versions should not do this.
339 >        if (simParams_->haveSwitchingRadius()) {
340 >          map<string, CutoffMethod>::const_iterator it;
341 >          string theMeth;
342 >          for (it = stringToCutoffMethod.begin();
343 >               it != stringToCutoffMethod.end(); ++it) {
344 >            if (it->second == cutoffMethod_) {
345 >              theMeth = it->first;
346 >              break;
347 >            }
348            }
349 +          sprintf(painCave.errMsg,
350 +                  "ForceManager::setupCutoffs: the cutoffMethod (%s)\n"
351 +                  "\tis not set to SWITCHED, so switchingRadius value\n"
352 +                  "\twill be ignored for this simulation\n", theMeth.c_str());
353 +          painCave.isFatal = 0;
354 +          painCave.severity = OPENMD_WARNING;
355 +          simError();
356          }
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();
357        }
263
358        rSwitch_ = rCut_;
359      }
360      
# Line 289 | Line 383 | namespace OpenMD {
383      }
384      switcher_->setSwitchType(sft_);
385      switcher_->setSwitch(rSwitch_, rCut_);
292    interactionMan_->setSwitchingRadius(rSwitch_);
386    }
387 +
388 +
389 +
390    
391    void ForceManager::initialize() {
392  
# Line 306 | Line 402 | namespace OpenMD {
402        setupCutoffs();
403  
404        info_->prepareTopology();      
405 +
406 +      doParticlePot_ = info_->getSimParams()->getOutputParticlePotential();
407 +      doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux();
408 +      if (doHeatFlux_) doParticlePot_ = true;
409 +
410 +      doElectricField_ = info_->getSimParams()->getOutputElectricField();
411 +  
412      }
413  
414      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
# Line 335 | Line 438 | namespace OpenMD {
438      electrostaticScale_[2] = fopts.getelectrostatic13scale();
439      electrostaticScale_[3] = fopts.getelectrostatic14scale();    
440      
441 +    if (info_->getSimParams()->haveElectricField()) {
442 +      ElectricField* eField = new ElectricField(info_);
443 +      perturbations_.push_back(eField);
444 +    }
445 +
446 +    usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions();
447 +    
448      fDecomp_->distributeInitialData();
449 <
449 >    
450      initialized_ = true;
451 <
451 >    
452    }
453 <
453 >  
454    void ForceManager::calcForces() {
455      
456      if (!initialized_) initialize();
457 <
457 >    
458      preCalculation();  
459      shortRangeInteractions();
460      longRangeInteractions();
# Line 361 | Line 471 | namespace OpenMD {
471      Molecule::CutoffGroupIterator ci;
472      CutoffGroup* cg;
473      
474 <    // forces are zeroed here, before any are accumulated.
474 >    // forces and potentials are zeroed here, before any are
475 >    // accumulated.
476      
477 +    Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
478 +
479 +    snap->setBondPotential(0.0);
480 +    snap->setBendPotential(0.0);
481 +    snap->setTorsionPotential(0.0);
482 +    snap->setInversionPotential(0.0);
483 +
484 +    potVec zeroPot(0.0);
485 +    snap->setLongRangePotential(zeroPot);
486 +    snap->setExcludedPotentials(zeroPot);
487 +
488 +    snap->setRestraintPotential(0.0);
489 +    snap->setRawPotential(0.0);
490 +
491      for (mol = info_->beginMolecule(mi); mol != NULL;
492           mol = info_->nextMolecule(mi)) {
493        for(atom = mol->beginAtom(ai); atom != NULL;
494            atom = mol->nextAtom(ai)) {
495          atom->zeroForcesAndTorques();
371        cerr << "apos = " << atom->getPos() << "\n";
496        }
497        
498        //change the positions of atoms which belong to the rigidbodies
# Line 382 | Line 506 | namespace OpenMD {
506              cg = mol->nextCutoffGroup(ci)) {
507            //calculate the center of mass of cutoff group
508            cg->updateCOM();
385          cerr << "cgpos = " << cg->getPos() << "\n";
509          }
510        }      
511      }
512      
513      // Zero out the stress tensor
514 <    tau *= 0.0;
515 <    
514 >    stressTensor *= 0.0;
515 >    // Zero out the heatFlux
516 >    fDecomp_->setHeatFlux( Vector3d(0.0) );    
517    }
518    
519    void ForceManager::shortRangeInteractions() {
# Line 422 | Line 546 | namespace OpenMD {
546  
547        for (bond = mol->beginBond(bondIter); bond != NULL;
548             bond = mol->nextBond(bondIter)) {
549 <        bond->calcForce();
549 >        bond->calcForce(doParticlePot_);
550          bondPotential += bond->getPotential();
551        }
552  
# Line 430 | Line 554 | namespace OpenMD {
554             bend = mol->nextBend(bendIter)) {
555          
556          RealType angle;
557 <        bend->calcForce(angle);
557 >        bend->calcForce(angle, doParticlePot_);
558          RealType currBendPot = bend->getPotential();          
559          
560          bendPotential += bend->getPotential();
# Line 455 | Line 579 | namespace OpenMD {
579        for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
580             torsion = mol->nextTorsion(torsionIter)) {
581          RealType angle;
582 <        torsion->calcForce(angle);
582 >        torsion->calcForce(angle, doParticlePot_);
583          RealType currTorsionPot = torsion->getPotential();
584          torsionPotential += torsion->getPotential();
585          map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
# Line 479 | Line 603 | namespace OpenMD {
603             inversion != NULL;
604             inversion = mol->nextInversion(inversionIter)) {
605          RealType angle;
606 <        inversion->calcForce(angle);
606 >        inversion->calcForce(angle, doParticlePot_);
607          RealType currInversionPot = inversion->getPotential();
608          inversionPotential += inversion->getPotential();
609          map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
# Line 499 | Line 623 | namespace OpenMD {
623          }      
624        }      
625      }
626 <    
627 <    RealType  shortRangePotential = bondPotential + bendPotential +
628 <      torsionPotential +  inversionPotential;    
626 >
627 > #ifdef IS_MPI
628 >    // Collect from all nodes.  This should eventually be moved into a
629 >    // SystemDecomposition, but this is a better place than in
630 >    // Thermo to do the collection.
631 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bondPotential, 1, MPI::REALTYPE,
632 >                              MPI::SUM);
633 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bendPotential, 1, MPI::REALTYPE,
634 >                              MPI::SUM);
635 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &torsionPotential, 1,
636 >                              MPI::REALTYPE, MPI::SUM);
637 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &inversionPotential, 1,
638 >                              MPI::REALTYPE, MPI::SUM);
639 > #endif
640 >
641      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
642 <    curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
643 <    curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
644 <    curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
645 <    curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
646 <    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;    
642 >
643 >    curSnapshot->setBondPotential(bondPotential);
644 >    curSnapshot->setBendPotential(bendPotential);
645 >    curSnapshot->setTorsionPotential(torsionPotential);
646 >    curSnapshot->setInversionPotential(inversionPotential);
647 >    
648 >    // RealType shortRangePotential = bondPotential + bendPotential +
649 >    //   torsionPotential +  inversionPotential;    
650 >
651 >    // curSnapshot->setShortRangePotential(shortRangePotential);
652    }
653    
654    void ForceManager::longRangeInteractions() {
655  
656 +
657      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
658      DataStorage* config = &(curSnapshot->atomData);
659      DataStorage* cgConfig = &(curSnapshot->cgData);
# Line 528 | Line 670 | namespace OpenMD {
670             mol = info_->nextMolecule(mi)) {
671          for(cg = mol->beginCutoffGroup(ci); cg != NULL;
672              cg = mol->nextCutoffGroup(ci)) {
531          cerr << "branch1\n";
532          cerr << "globind = " << cg->getGlobalIndex() << "\n";
673            cg->updateCOM();
674          }
675        }      
676      } else {
677        // center of mass of the group is the same as position of the atom  
678        // if cutoff group does not exist
539      cerr << "branch2\n";
679        cgConfig->position = config->position;
680 +      cgConfig->velocity = config->velocity;
681      }
682  
683      fDecomp_->zeroWorkArrays();
684      fDecomp_->distributeData();
685      
686      int cg1, cg2, atom1, atom2, topoDist;
687 <    Vector3d d_grp, dag, d;
687 >    Vector3d d_grp, dag, d, gvel2, vel2;
688      RealType rgrpsq, rgrp, r2, r;
689      RealType electroMult, vdwMult;
690      RealType vij;
# Line 557 | Line 697 | namespace OpenMD {
697      InteractionData idat;
698      SelfData sdat;
699      RealType mf;
560    RealType lrPot;
700      RealType vpair;
701 +    RealType dVdFQ1(0.0);
702 +    RealType dVdFQ2(0.0);
703      potVec longRangePotential(0.0);
704      potVec workPot(0.0);
705 +    potVec exPot(0.0);
706 +    Vector3d eField1(0.0);
707 +    Vector3d eField2(0.0);
708 +    vector<int>::iterator ia, jb;
709  
710      int loopStart, loopEnd;
711  
712      idat.vdwMult = &vdwMult;
713      idat.electroMult = &electroMult;
714      idat.pot = &workPot;
715 +    idat.excludedPot = &exPot;
716      sdat.pot = fDecomp_->getEmbeddingPotential();
717 +    sdat.excludedPot = fDecomp_->getExcludedSelfPotential();
718      idat.vpair = &vpair;
719 +    idat.dVdFQ1 = &dVdFQ1;
720 +    idat.dVdFQ2 = &dVdFQ2;
721 +    idat.eField1 = &eField1;
722 +    idat.eField2 = &eField2;  
723      idat.f1 = &f1;
724      idat.sw = &sw;
725      idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
726      idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false;
727 +    idat.doParticlePot = doParticlePot_;
728 +    idat.doElectricField = doElectricField_;
729 +    sdat.doParticlePot = doParticlePot_;
730      
731      loopEnd = PAIR_LOOP;
732      if (info_->requiresPrepair() ) {
# Line 580 | Line 734 | namespace OpenMD {
734      } else {
735        loopStart = PAIR_LOOP;
736      }
583  
737      for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
738      
739        if (iLoop == loopStart) {
740          bool update_nlist = fDecomp_->checkNeighborList();
741 <        if (update_nlist)
741 >        if (update_nlist) {
742 >          if (!usePeriodicBoundaryConditions_)
743 >            Mat3x3d bbox = thermo->getBoundingBox();
744            neighborList = fDecomp_->buildNeighborList();
745 <      }      
746 <        
745 >        }
746 >      }
747 >
748        for (vector<pair<int, int> >::iterator it = neighborList.begin();
749               it != neighborList.end(); ++it) {
750                  
# Line 598 | Line 754 | namespace OpenMD {
754          cuts = fDecomp_->getGroupCutoffs(cg1, cg2);
755  
756          d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
757 +
758          curSnapshot->wrapVector(d_grp);        
759          rgrpsq = d_grp.lengthSquare();
603
760          rCutSq = cuts.second;
761  
762          if (rgrpsq < rCutSq) {
# Line 608 | Line 764 | namespace OpenMD {
764            if (iLoop == PAIR_LOOP) {
765              vij = 0.0;
766              fij = V3Zero;
767 +            eField1 = V3Zero;
768 +            eField2 = V3Zero;
769            }
770            
771            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
772                                                       rgrp);
773 <              
773 >
774            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
775            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
776  
777 <          for (vector<int>::iterator ia = atomListRow.begin();
777 >          if (doHeatFlux_)
778 >            gvel2 = fDecomp_->getGroupVelocityColumn(cg2);
779 >
780 >          for (ia = atomListRow.begin();
781                 ia != atomListRow.end(); ++ia) {            
782              atom1 = (*ia);
783 <            
784 <            for (vector<int>::iterator jb = atomListColumn.begin();
783 >
784 >            for (jb = atomListColumn.begin();
785                   jb != atomListColumn.end(); ++jb) {              
786                atom2 = (*jb);
787  
788 <              if (!fDecomp_->skipAtomPair(atom1, atom2)) {
788 >              if (!fDecomp_->skipAtomPair(atom1, atom2, cg1, cg2)) {
789 >
790                  vpair = 0.0;
791                  workPot = 0.0;
792 +                exPot = 0.0;
793                  f1 = V3Zero;
794 +                dVdFQ1 = 0.0;
795 +                dVdFQ2 = 0.0;
796  
797                  fDecomp_->fillInteractionData(idat, atom1, atom2);
798 <                
798 >
799                  topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
800                  vdwMult = vdwScale_[topoDist];
801                  electroMult = electrostaticScale_[topoDist];
# Line 638 | Line 803 | namespace OpenMD {
803                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
804                    idat.d = &d_grp;
805                    idat.r2 = &rgrpsq;
806 <                  cerr << "dgrp = " << d_grp << "\n";
806 >                  if (doHeatFlux_)
807 >                    vel2 = gvel2;
808                  } else {
809                    d = fDecomp_->getInteratomicVector(atom1, atom2);
810                    curSnapshot->wrapVector( d );
811                    r2 = d.lengthSquare();
646                  cerr << "datm = " << d<< "\n";
812                    idat.d = &d;
813                    idat.r2 = &r2;
814 +                  if (doHeatFlux_)
815 +                    vel2 = fDecomp_->getAtomVelocityColumn(atom2);
816                  }
817 <                
651 <                cerr << "idat.d = " << *(idat.d) << "\n";
817 >              
818                  r = sqrt( *(idat.r2) );
819                  idat.rij = &r;
820                
# Line 657 | Line 823 | namespace OpenMD {
823                  } else {
824                    interactionMan_->doPair(idat);
825                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
660
661                  cerr << "d = " << *(idat.d) << "\tv=" << vpair << "\tf=" << f1 << "\n";
826                    vij += vpair;
827                    fij += f1;
828 <                  tau -= outProduct( *(idat.d), f1);
828 >                  stressTensor -= outProduct( *(idat.d), f1);
829 >                  if (doHeatFlux_)
830 >                    fDecomp_->addToHeatFlux(*(idat.d) * dot(f1, vel2));
831                  }
832                }
833              }
# Line 674 | Line 840 | namespace OpenMD {
840                fij += fg;
841  
842                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
843 <                tau -= outProduct( *(idat.d), fg);
843 >                if (!fDecomp_->skipAtomPair(atomListRow[0],
844 >                                            atomListColumn[0],
845 >                                            cg1, cg2)) {
846 >                  stressTensor -= outProduct( *(idat.d), fg);
847 >                  if (doHeatFlux_)
848 >                    fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2));
849 >                }                
850                }
851            
852 <              for (vector<int>::iterator ia = atomListRow.begin();
852 >              for (ia = atomListRow.begin();
853                     ia != atomListRow.end(); ++ia) {            
854                  atom1 = (*ia);                
855                  mf = fDecomp_->getMassFactorRow(atom1);
# Line 685 | Line 857 | namespace OpenMD {
857                  // presence in switching region
858                  fg = swderiv * d_grp * mf;
859                  fDecomp_->addForceToAtomRow(atom1, fg);
688
860                  if (atomListRow.size() > 1) {
861                    if (info_->usesAtomicVirial()) {
862                      // find the distance between the atom
863                      // and the center of the cutoff group:
864                      dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
865 <                    tau -= outProduct(dag, fg);
865 >                    stressTensor -= outProduct(dag, fg);
866 >                    if (doHeatFlux_)
867 >                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
868                    }
869                  }
870                }
871 <              for (vector<int>::iterator jb = atomListColumn.begin();
871 >              for (jb = atomListColumn.begin();
872                     jb != atomListColumn.end(); ++jb) {              
873                  atom2 = (*jb);
874                  mf = fDecomp_->getMassFactorColumn(atom2);
# Line 709 | Line 882 | namespace OpenMD {
882                      // find the distance between the atom
883                      // and the center of the cutoff group:
884                      dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
885 <                    tau -= outProduct(dag, fg);
885 >                    stressTensor -= outProduct(dag, fg);
886 >                    if (doHeatFlux_)
887 >                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
888                    }
889                  }
890                }
891              }
892 <            //if (!SIM_uses_AtomicVirial) {
893 <            //  tau -= outProduct(d_grp, fij);
892 >            //if (!info_->usesAtomicVirial()) {
893 >            //  stressTensor -= outProduct(d_grp, fij);
894 >            //  if (doHeatFlux_)
895 >            //     fDecomp_->addToHeatFlux( d_grp * dot(fij, vel2));
896              //}
897            }
898          }
# Line 726 | Line 903 | namespace OpenMD {
903  
904            fDecomp_->collectIntermediateData();
905  
906 <          for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
906 >          for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
907              fDecomp_->fillSelfData(sdat, atom1);
908              interactionMan_->doPreForce(sdat);
909            }
# Line 735 | Line 912 | namespace OpenMD {
912  
913          }
914        }
738
915      }
916      
917 +    // collects pairwise information
918      fDecomp_->collectData();
919          
920      if (info_->requiresSelfCorrection()) {
921 <
745 <      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
921 >      for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
922          fDecomp_->fillSelfData(sdat, atom1);
923          interactionMan_->doSelfCorrection(sdat);
924        }
749
925      }
926  
927 +    // collects single-atom information
928 +    fDecomp_->collectSelfData();
929 +
930      longRangePotential = *(fDecomp_->getEmbeddingPotential()) +
931        *(fDecomp_->getPairwisePotential());
932  
933 <    lrPot = longRangePotential.sum();
933 >    curSnapshot->setLongRangePotential(longRangePotential);
934 >    
935 >    curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedSelfPotential()) +
936 >                                         *(fDecomp_->getExcludedPotential()));
937  
757    //store the tau and long range potential    
758    curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
759    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
760    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
938    }
939  
940    
941    void ForceManager::postCalculation() {
942 +
943 +    vector<Perturbation*>::iterator pi;
944 +    for (pi = perturbations_.begin(); pi != perturbations_.end(); ++pi) {
945 +      (*pi)->applyPerturbation();
946 +    }
947 +
948      SimInfo::MoleculeIterator mi;
949      Molecule* mol;
950      Molecule::RigidBodyIterator rbIter;
951      RigidBody* rb;
952      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
953 <    
953 >  
954      // collect the atomic forces onto rigid bodies
955      
956      for (mol = info_->beginMolecule(mi); mol != NULL;
# Line 775 | Line 958 | namespace OpenMD {
958        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
959             rb = mol->nextRigidBody(rbIter)) {
960          Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial();
961 <        tau += rbTau;
961 >        stressTensor += rbTau;
962        }
963      }
964      
965   #ifdef IS_MPI
966 <    Mat3x3d tmpTau(tau);
967 <    MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(),
785 <                  9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
966 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9,
967 >                              MPI::REALTYPE, MPI::SUM);
968   #endif
969 <    curSnapshot->statData.setTau(tau);
970 <  }
969 >    curSnapshot->setStressTensor(stressTensor);
970 >    
971 >    if (info_->getSimParams()->getUseLongRangeCorrections()) {
972 >      /*
973 >      RealType vol = curSnapshot->getVolume();
974 >      RealType Elrc(0.0);
975 >      RealType Wlrc(0.0);
976  
977 < } //end namespace OpenMD
977 >      set<AtomType*>::iterator i;
978 >      set<AtomType*>::iterator j;
979 >    
980 >      RealType n_i, n_j;
981 >      RealType rho_i, rho_j;
982 >      pair<RealType, RealType> LRI;
983 >      
984 >      for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) {
985 >        n_i = RealType(info_->getGlobalCountOfType(*i));
986 >        rho_i = n_i /  vol;
987 >        for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) {
988 >          n_j = RealType(info_->getGlobalCountOfType(*j));
989 >          rho_j = n_j / vol;
990 >          
991 >          LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) );
992 >
993 >          Elrc += n_i   * rho_j * LRI.first;
994 >          Wlrc -= rho_i * rho_j * LRI.second;
995 >        }
996 >      }
997 >      Elrc *= 2.0 * NumericConstant::PI;
998 >      Wlrc *= 2.0 * NumericConstant::PI;
999 >
1000 >      RealType lrp = curSnapshot->getLongRangePotential();
1001 >      curSnapshot->setLongRangePotential(lrp + Elrc);
1002 >      stressTensor += Wlrc * SquareMatrix3<RealType>::identity();
1003 >      curSnapshot->setStressTensor(stressTensor);
1004 >      */
1005 >    
1006 >    }
1007 >  }
1008 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines