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 1711 by gezelter, Sat May 19 02:58:35 2012 UTC vs.
Revision 1877 by gezelter, Thu Jun 6 15:43:35 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).          
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   */
# Line 44 | Line 44
44   * @file ForceManager.cpp
45   * @author tlin
46   * @date 11/09/2004
47 * @time 10:39am
47   * @version 1.0
48   */
49  
# Line 58 | 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 67 | 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 >                                               initialized_(false) {
72      forceField_ = info_->getForceField();
73      interactionMan_ = new InteractionManager();
74      fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_);
75 +    thermo = new Thermo(info_);
76    }
77  
78 +  ForceManager::~ForceManager() {
79 +    perturbations_.clear();
80 +    
81 +    delete switcher_;
82 +    delete interactionMan_;
83 +    delete fDecomp_;
84 +    delete thermo;
85 +  }
86 +  
87    /**
88     * setupCutoffs
89     *
# Line 87 | Line 98 | namespace OpenMD {
98     *      simulation for suggested cutoff values (e.g. 2.5 * sigma).
99     *      Use the maximum suggested value that was found.
100     *
101 <   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE,
101 >   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, TAYLOR_SHIFTED,
102     *                        or SHIFTED_POTENTIAL)
103     *      If cutoffMethod was explicitly set, use that choice.
104     *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE
# Line 110 | Line 121 | namespace OpenMD {
121      Globals* simParams_ = info_->getSimParams();
122      ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
123      int mdFileVersion;
124 +    rCut_ = 0.0; //Needs a value for a later max() call;  
125      
126      if (simParams_->haveMDfileVersion())
127        mdFileVersion = simParams_->getMDfileVersion();
128      else
129        mdFileVersion = 0;
130    
131 +    // We need the list of simulated atom types to figure out cutoffs
132 +    // as well as long range corrections.
133 +
134 +    set<AtomType*>::iterator i;
135 +    set<AtomType*> atomTypes_;
136 +    atomTypes_ = info_->getSimulatedAtomTypes();
137 +
138      if (simParams_->haveCutoffRadius()) {
139        rCut_ = simParams_->getCutoffRadius();
140      } else {      
# Line 130 | Line 149 | namespace OpenMD {
149          rCut_ = 12.0;
150        } else {
151          RealType thisCut;
152 <        set<AtomType*>::iterator i;
134 <        set<AtomType*> atomTypes;
135 <        atomTypes = info_->getSimulatedAtomTypes();        
136 <        for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
152 >        for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) {
153            thisCut = interactionMan_->getSuggestedCutoffRadius((*i));
154            rCut_ = max(thisCut, rCut_);
155          }
# Line 155 | Line 171 | namespace OpenMD {
171      stringToCutoffMethod["SWITCHED"] = SWITCHED;
172      stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL;    
173      stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE;
174 +    stringToCutoffMethod["TAYLOR_SHIFTED"] = TAYLOR_SHIFTED;
175    
176      if (simParams_->haveCutoffMethod()) {
177        string cutMeth = toUpperCopy(simParams_->getCutoffMethod());
# Line 164 | Line 181 | namespace OpenMD {
181          sprintf(painCave.errMsg,
182                  "ForceManager::setupCutoffs: Could not find chosen cutoffMethod %s\n"
183                  "\tShould be one of: "
184 <                "HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n",
184 >                "HARD, SWITCHED, SHIFTED_POTENTIAL, TAYLOR_SHIFTED,\n"
185 >                "\tor SHIFTED_FORCE\n",
186                  cutMeth.c_str());
187          painCave.isFatal = 1;
188          painCave.severity = OPENMD_ERROR;
# Line 208 | Line 226 | namespace OpenMD {
226              cutoffMethod_ = SHIFTED_POTENTIAL;
227            } else if (myMethod == "SHIFTED_FORCE") {
228              cutoffMethod_ = SHIFTED_FORCE;
229 +          } else if (myMethod == "TAYLOR_SHIFTED") {
230 +            cutoffMethod_ = TAYLOR_SHIFTED;
231            }
232          
233            if (simParams_->haveSwitchingRadius())
234              rSwitch_ = simParams_->getSwitchingRadius();
235  
236 <          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") {
236 >          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE" ||
237 >              myMethod == "TAYLOR_SHIFTED") {
238              if (simParams_->haveSwitchingRadius()){
239                sprintf(painCave.errMsg,
240                        "ForceManager::setupCutoffs : DEPRECATED ERROR MESSAGE\n"
# Line 368 | Line 389 | namespace OpenMD {
389      }
390      switcher_->setSwitchType(sft_);
391      switcher_->setSwitch(rSwitch_, rCut_);
371    interactionMan_->setSwitchingRadius(rSwitch_);
392    }
393  
394  
# Line 390 | Line 410 | namespace OpenMD {
410        info_->prepareTopology();      
411  
412        doParticlePot_ = info_->getSimParams()->getOutputParticlePotential();
413 <      cerr << "dPP = " << doParticlePot_ << "\n";
413 >      doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux();
414 >      if (doHeatFlux_) doParticlePot_ = true;
415 >
416 >      doElectricField_ = info_->getSimParams()->getOutputElectricField();
417    
418      }
419  
# Line 421 | Line 444 | namespace OpenMD {
444      electrostaticScale_[2] = fopts.getelectrostatic13scale();
445      electrostaticScale_[3] = fopts.getelectrostatic14scale();    
446      
447 +    if (info_->getSimParams()->haveElectricField()) {
448 +      ElectricField* eField = new ElectricField(info_);
449 +      perturbations_.push_back(eField);
450 +    }
451 +
452 +    usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions();
453 +    
454      fDecomp_->distributeInitialData();
455 <
455 >    
456      initialized_ = true;
457 <
457 >    
458    }
459 <
459 >  
460    void ForceManager::calcForces() {
461      
462      if (!initialized_) initialize();
463 <
463 >    
464      preCalculation();  
465      shortRangeInteractions();
466      longRangeInteractions();
# Line 447 | Line 477 | namespace OpenMD {
477      Molecule::CutoffGroupIterator ci;
478      CutoffGroup* cg;
479      
480 <    // forces are zeroed here, before any are accumulated.
480 >    // forces and potentials are zeroed here, before any are
481 >    // accumulated.
482      
483 +    Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
484 +
485 +    snap->setBondPotential(0.0);
486 +    snap->setBendPotential(0.0);
487 +    snap->setTorsionPotential(0.0);
488 +    snap->setInversionPotential(0.0);
489 +
490 +    potVec zeroPot(0.0);
491 +    snap->setLongRangePotential(zeroPot);
492 +    snap->setExcludedPotentials(zeroPot);
493 +
494 +    snap->setRestraintPotential(0.0);
495 +    snap->setRawPotential(0.0);
496 +
497      for (mol = info_->beginMolecule(mi); mol != NULL;
498           mol = info_->nextMolecule(mi)) {
499        for(atom = mol->beginAtom(ai); atom != NULL;
# Line 472 | Line 517 | namespace OpenMD {
517      }
518      
519      // Zero out the stress tensor
520 <    tau *= 0.0;
521 <    
520 >    stressTensor *= 0.0;
521 >    // Zero out the heatFlux
522 >    fDecomp_->setHeatFlux( Vector3d(0.0) );    
523    }
524    
525    void ForceManager::shortRangeInteractions() {
# Line 506 | Line 552 | namespace OpenMD {
552  
553        for (bond = mol->beginBond(bondIter); bond != NULL;
554             bond = mol->nextBond(bondIter)) {
555 <        bond->calcForce();
555 >        bond->calcForce(doParticlePot_);
556          bondPotential += bond->getPotential();
557        }
558  
# Line 514 | Line 560 | namespace OpenMD {
560             bend = mol->nextBend(bendIter)) {
561          
562          RealType angle;
563 <        bend->calcForce(angle);
563 >        bend->calcForce(angle, doParticlePot_);
564          RealType currBendPot = bend->getPotential();          
565          
566          bendPotential += bend->getPotential();
# Line 539 | Line 585 | namespace OpenMD {
585        for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
586             torsion = mol->nextTorsion(torsionIter)) {
587          RealType angle;
588 <        torsion->calcForce(angle);
588 >        torsion->calcForce(angle, doParticlePot_);
589          RealType currTorsionPot = torsion->getPotential();
590          torsionPotential += torsion->getPotential();
591          map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
# Line 563 | Line 609 | namespace OpenMD {
609             inversion != NULL;
610             inversion = mol->nextInversion(inversionIter)) {
611          RealType angle;
612 <        inversion->calcForce(angle);
612 >        inversion->calcForce(angle, doParticlePot_);
613          RealType currInversionPot = inversion->getPotential();
614          inversionPotential += inversion->getPotential();
615          map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
# Line 583 | Line 629 | namespace OpenMD {
629          }      
630        }      
631      }
632 <    
633 <    RealType  shortRangePotential = bondPotential + bendPotential +
634 <      torsionPotential +  inversionPotential;    
632 >
633 > #ifdef IS_MPI
634 >    // Collect from all nodes.  This should eventually be moved into a
635 >    // SystemDecomposition, but this is a better place than in
636 >    // Thermo to do the collection.
637 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bondPotential, 1, MPI::REALTYPE,
638 >                              MPI::SUM);
639 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bendPotential, 1, MPI::REALTYPE,
640 >                              MPI::SUM);
641 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &torsionPotential, 1,
642 >                              MPI::REALTYPE, MPI::SUM);
643 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &inversionPotential, 1,
644 >                              MPI::REALTYPE, MPI::SUM);
645 > #endif
646 >
647      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
648 <    curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
649 <    curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
650 <    curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
651 <    curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
652 <    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;    
648 >
649 >    curSnapshot->setBondPotential(bondPotential);
650 >    curSnapshot->setBendPotential(bendPotential);
651 >    curSnapshot->setTorsionPotential(torsionPotential);
652 >    curSnapshot->setInversionPotential(inversionPotential);
653 >    
654 >    // RealType shortRangePotential = bondPotential + bendPotential +
655 >    //   torsionPotential +  inversionPotential;    
656 >
657 >    // curSnapshot->setShortRangePotential(shortRangePotential);
658    }
659    
660    void ForceManager::longRangeInteractions() {
# Line 619 | Line 682 | namespace OpenMD {
682        // center of mass of the group is the same as position of the atom  
683        // if cutoff group does not exist
684        cgConfig->position = config->position;
685 +      cgConfig->velocity = config->velocity;
686      }
687  
688      fDecomp_->zeroWorkArrays();
689      fDecomp_->distributeData();
690      
691      int cg1, cg2, atom1, atom2, topoDist;
692 <    Vector3d d_grp, dag, d;
692 >    Vector3d d_grp, dag, d, gvel2, vel2;
693      RealType rgrpsq, rgrp, r2, r;
694      RealType electroMult, vdwMult;
695      RealType vij;
# Line 634 | Line 698 | namespace OpenMD {
698      RealType rCutSq;
699      bool in_switching_region;
700      RealType sw, dswdr, swderiv;
701 <    vector<int> atomListColumn, atomListRow, atomListLocal;
701 >    vector<int> atomListColumn, atomListRow;
702      InteractionData idat;
703      SelfData sdat;
704      RealType mf;
641    RealType lrPot;
705      RealType vpair;
706 +    RealType dVdFQ1(0.0);
707 +    RealType dVdFQ2(0.0);
708      potVec longRangePotential(0.0);
709      potVec workPot(0.0);
710 +    potVec exPot(0.0);
711 +    Vector3d eField1(0.0);
712 +    Vector3d eField2(0.0);
713 +    vector<int>::iterator ia, jb;
714  
715      int loopStart, loopEnd;
716  
717      idat.vdwMult = &vdwMult;
718      idat.electroMult = &electroMult;
719      idat.pot = &workPot;
720 +    idat.excludedPot = &exPot;
721      sdat.pot = fDecomp_->getEmbeddingPotential();
722 +    sdat.excludedPot = fDecomp_->getExcludedSelfPotential();
723      idat.vpair = &vpair;
724 +    idat.dVdFQ1 = &dVdFQ1;
725 +    idat.dVdFQ2 = &dVdFQ2;
726 +    idat.eField1 = &eField1;
727 +    idat.eField2 = &eField2;  
728      idat.f1 = &f1;
729      idat.sw = &sw;
730      idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
731 <    idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false;
731 >    idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE || cutoffMethod_ == TAYLOR_SHIFTED) ? true : false;
732      idat.doParticlePot = doParticlePot_;
733 +    idat.doElectricField = doElectricField_;
734      sdat.doParticlePot = doParticlePot_;
735      
736      loopEnd = PAIR_LOOP;
# Line 663 | Line 739 | namespace OpenMD {
739      } else {
740        loopStart = PAIR_LOOP;
741      }
666  
742      for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
743      
744        if (iLoop == loopStart) {
745          bool update_nlist = fDecomp_->checkNeighborList();
746 <        if (update_nlist)
746 >        if (update_nlist) {
747 >          if (!usePeriodicBoundaryConditions_)
748 >            Mat3x3d bbox = thermo->getBoundingBox();
749            neighborList = fDecomp_->buildNeighborList();
750 <      }            
750 >        }
751 >      }
752  
753        for (vector<pair<int, int> >::iterator it = neighborList.begin();
754               it != neighborList.end(); ++it) {
# Line 690 | Line 768 | namespace OpenMD {
768            idat.rcut = &cuts.first;
769            if (iLoop == PAIR_LOOP) {
770              vij = 0.0;
771 <            fij = V3Zero;
771 >            fij.zero();
772 >            eField1.zero();
773 >            eField2.zero();
774            }
775            
776            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
777                                                       rgrp);
778 <          
778 >
779            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
780            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
781  
782 <          for (vector<int>::iterator ia = atomListRow.begin();
782 >          if (doHeatFlux_)
783 >            gvel2 = fDecomp_->getGroupVelocityColumn(cg2);
784 >
785 >          for (ia = atomListRow.begin();
786                 ia != atomListRow.end(); ++ia) {            
787              atom1 = (*ia);
788 <            
789 <            for (vector<int>::iterator jb = atomListColumn.begin();
788 >
789 >            for (jb = atomListColumn.begin();
790                   jb != atomListColumn.end(); ++jb) {              
791                atom2 = (*jb);
792  
793 <              if (!fDecomp_->skipAtomPair(atom1, atom2)) {
793 >              if (!fDecomp_->skipAtomPair(atom1, atom2, cg1, cg2)) {
794 >
795                  vpair = 0.0;
796                  workPot = 0.0;
797 <                f1 = V3Zero;
797 >                exPot = 0.0;
798 >                f1.zero();
799 >                dVdFQ1 = 0.0;
800 >                dVdFQ2 = 0.0;
801  
802                  fDecomp_->fillInteractionData(idat, atom1, atom2);
803 <                
803 >
804                  topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
805                  vdwMult = vdwScale_[topoDist];
806                  electroMult = electrostaticScale_[topoDist];
# Line 721 | Line 808 | namespace OpenMD {
808                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
809                    idat.d = &d_grp;
810                    idat.r2 = &rgrpsq;
811 +                  if (doHeatFlux_)
812 +                    vel2 = gvel2;
813                  } else {
814                    d = fDecomp_->getInteratomicVector(atom1, atom2);
815                    curSnapshot->wrapVector( d );
816                    r2 = d.lengthSquare();
817                    idat.d = &d;
818                    idat.r2 = &r2;
819 +                  if (doHeatFlux_)
820 +                    vel2 = fDecomp_->getAtomVelocityColumn(atom2);
821                  }
822                
823                  r = sqrt( *(idat.r2) );
# Line 739 | Line 830 | namespace OpenMD {
830                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
831                    vij += vpair;
832                    fij += f1;
833 <                  tau -= outProduct( *(idat.d), f1);
833 >                  stressTensor -= outProduct( *(idat.d), f1);
834 >                  if (doHeatFlux_)
835 >                    fDecomp_->addToHeatFlux(*(idat.d) * dot(f1, vel2));
836                  }
837                }
838              }
# Line 752 | Line 845 | namespace OpenMD {
845                fij += fg;
846  
847                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
848 <                tau -= outProduct( *(idat.d), fg);
848 >                if (!fDecomp_->skipAtomPair(atomListRow[0],
849 >                                            atomListColumn[0],
850 >                                            cg1, cg2)) {
851 >                  stressTensor -= outProduct( *(idat.d), fg);
852 >                  if (doHeatFlux_)
853 >                    fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2));
854 >                }                
855                }
856            
857 <              for (vector<int>::iterator ia = atomListRow.begin();
857 >              for (ia = atomListRow.begin();
858                     ia != atomListRow.end(); ++ia) {            
859                  atom1 = (*ia);                
860                  mf = fDecomp_->getMassFactorRow(atom1);
# Line 768 | Line 867 | namespace OpenMD {
867                      // find the distance between the atom
868                      // and the center of the cutoff group:
869                      dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
870 <                    tau -= outProduct(dag, fg);
870 >                    stressTensor -= outProduct(dag, fg);
871 >                    if (doHeatFlux_)
872 >                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
873                    }
874                  }
875                }
876 <              for (vector<int>::iterator jb = atomListColumn.begin();
876 >              for (jb = atomListColumn.begin();
877                     jb != atomListColumn.end(); ++jb) {              
878                  atom2 = (*jb);
879                  mf = fDecomp_->getMassFactorColumn(atom2);
# Line 786 | Line 887 | namespace OpenMD {
887                      // find the distance between the atom
888                      // and the center of the cutoff group:
889                      dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
890 <                    tau -= outProduct(dag, fg);
890 >                    stressTensor -= outProduct(dag, fg);
891 >                    if (doHeatFlux_)
892 >                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
893                    }
894                  }
895                }
896              }
897              //if (!info_->usesAtomicVirial()) {
898 <            //  tau -= outProduct(d_grp, fij);
898 >            //  stressTensor -= outProduct(d_grp, fij);
899 >            //  if (doHeatFlux_)
900 >            //     fDecomp_->addToHeatFlux( d_grp * dot(fij, vel2));
901              //}
902            }
903          }
# Line 803 | Line 908 | namespace OpenMD {
908  
909            fDecomp_->collectIntermediateData();
910  
911 <          for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
911 >          for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
912              fDecomp_->fillSelfData(sdat, atom1);
913              interactionMan_->doPreForce(sdat);
914            }
# Line 814 | Line 919 | namespace OpenMD {
919        }
920      }
921      
922 +    // collects pairwise information
923      fDecomp_->collectData();
924          
925      if (info_->requiresSelfCorrection()) {
926 <
821 <      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
926 >      for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
927          fDecomp_->fillSelfData(sdat, atom1);
928          interactionMan_->doSelfCorrection(sdat);
929        }
825
930      }
931  
932 +    // collects single-atom information
933 +    fDecomp_->collectSelfData();
934 +
935      longRangePotential = *(fDecomp_->getEmbeddingPotential()) +
936        *(fDecomp_->getPairwisePotential());
937  
938 <    lrPot = longRangePotential.sum();
938 >    curSnapshot->setLongRangePotential(longRangePotential);
939 >    
940 >    curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedSelfPotential()) +
941 >                                         *(fDecomp_->getExcludedPotential()));
942  
833    //store the tau and long range potential    
834    curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
835    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
836    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
943    }
944  
945    
946    void ForceManager::postCalculation() {
947 +
948 +    vector<Perturbation*>::iterator pi;
949 +    for (pi = perturbations_.begin(); pi != perturbations_.end(); ++pi) {
950 +      (*pi)->applyPerturbation();
951 +    }
952 +
953      SimInfo::MoleculeIterator mi;
954      Molecule* mol;
955      Molecule::RigidBodyIterator rbIter;
956      RigidBody* rb;
957      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
958 <    
958 >  
959      // collect the atomic forces onto rigid bodies
960      
961      for (mol = info_->beginMolecule(mi); mol != NULL;
# Line 851 | Line 963 | namespace OpenMD {
963        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
964             rb = mol->nextRigidBody(rbIter)) {
965          Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial();
966 <        tau += rbTau;
966 >        stressTensor += rbTau;
967        }
968      }
969      
970   #ifdef IS_MPI
971 <    Mat3x3d tmpTau(tau);
972 <    MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(),
861 <                  9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
971 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9,
972 >                              MPI::REALTYPE, MPI::SUM);
973   #endif
974 <    curSnapshot->setTau(tau);
975 <  }
974 >    curSnapshot->setStressTensor(stressTensor);
975 >    
976 >    if (info_->getSimParams()->getUseLongRangeCorrections()) {
977 >      /*
978 >      RealType vol = curSnapshot->getVolume();
979 >      RealType Elrc(0.0);
980 >      RealType Wlrc(0.0);
981  
982 < } //end namespace OpenMD
982 >      set<AtomType*>::iterator i;
983 >      set<AtomType*>::iterator j;
984 >    
985 >      RealType n_i, n_j;
986 >      RealType rho_i, rho_j;
987 >      pair<RealType, RealType> LRI;
988 >      
989 >      for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) {
990 >        n_i = RealType(info_->getGlobalCountOfType(*i));
991 >        rho_i = n_i /  vol;
992 >        for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) {
993 >          n_j = RealType(info_->getGlobalCountOfType(*j));
994 >          rho_j = n_j / vol;
995 >          
996 >          LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) );
997 >
998 >          Elrc += n_i   * rho_j * LRI.first;
999 >          Wlrc -= rho_i * rho_j * LRI.second;
1000 >        }
1001 >      }
1002 >      Elrc *= 2.0 * NumericConstant::PI;
1003 >      Wlrc *= 2.0 * NumericConstant::PI;
1004 >
1005 >      RealType lrp = curSnapshot->getLongRangePotential();
1006 >      curSnapshot->setLongRangePotential(lrp + Elrc);
1007 >      stressTensor += Wlrc * SquareMatrix3<RealType>::identity();
1008 >      curSnapshot->setStressTensor(stressTensor);
1009 >      */
1010 >    
1011 >    }
1012 >  }
1013 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines