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 1733 by jmichalk, Tue Jun 5 17:48:40 2012 UTC vs.
Revision 1874 by gezelter, Wed May 15 15:09: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 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 368 | Line 384 | namespace OpenMD {
384      }
385      switcher_->setSwitchType(sft_);
386      switcher_->setSwitch(rSwitch_, rCut_);
371    interactionMan_->setSwitchingRadius(rSwitch_);
387    }
388  
389  
# Line 392 | Line 407 | namespace OpenMD {
407        doParticlePot_ = info_->getSimParams()->getOutputParticlePotential();
408        doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux();
409        if (doHeatFlux_) doParticlePot_ = true;
410 +
411 +      doElectricField_ = info_->getSimParams()->getOutputElectricField();
412    
413      }
414  
# Line 422 | Line 439 | namespace OpenMD {
439      electrostaticScale_[2] = fopts.getelectrostatic13scale();
440      electrostaticScale_[3] = fopts.getelectrostatic14scale();    
441      
442 +    if (info_->getSimParams()->haveElectricField()) {
443 +      ElectricField* eField = new ElectricField(info_);
444 +      perturbations_.push_back(eField);
445 +    }
446 +
447 +    usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions();
448 +    
449      fDecomp_->distributeInitialData();
450 <
450 >    
451      initialized_ = true;
452 <
452 >    
453    }
454 <
454 >  
455    void ForceManager::calcForces() {
456      
457      if (!initialized_) initialize();
458 <
458 >    
459      preCalculation();  
460      shortRangeInteractions();
461      longRangeInteractions();
# Line 448 | Line 472 | namespace OpenMD {
472      Molecule::CutoffGroupIterator ci;
473      CutoffGroup* cg;
474      
475 <    // forces are zeroed here, before any are accumulated.
475 >    // forces and potentials are zeroed here, before any are
476 >    // accumulated.
477      
478 +    Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
479 +
480 +    snap->setBondPotential(0.0);
481 +    snap->setBendPotential(0.0);
482 +    snap->setTorsionPotential(0.0);
483 +    snap->setInversionPotential(0.0);
484 +
485 +    potVec zeroPot(0.0);
486 +    snap->setLongRangePotential(zeroPot);
487 +    snap->setExcludedPotentials(zeroPot);
488 +
489 +    snap->setRestraintPotential(0.0);
490 +    snap->setRawPotential(0.0);
491 +
492      for (mol = info_->beginMolecule(mi); mol != NULL;
493           mol = info_->nextMolecule(mi)) {
494        for(atom = mol->beginAtom(ai); atom != NULL;
# Line 475 | Line 514 | namespace OpenMD {
514      // Zero out the stress tensor
515      stressTensor *= 0.0;
516      // Zero out the heatFlux
517 <    fDecomp_->setHeatFlux( V3Zero );    
517 >    fDecomp_->setHeatFlux( Vector3d(0.0) );    
518    }
519    
520    void ForceManager::shortRangeInteractions() {
# Line 585 | Line 624 | namespace OpenMD {
624          }      
625        }      
626      }
627 <    
628 <    RealType  shortRangePotential = bondPotential + bendPotential +
629 <      torsionPotential +  inversionPotential;    
627 >
628 > #ifdef IS_MPI
629 >    // Collect from all nodes.  This should eventually be moved into a
630 >    // SystemDecomposition, but this is a better place than in
631 >    // Thermo to do the collection.
632 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bondPotential, 1, MPI::REALTYPE,
633 >                              MPI::SUM);
634 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bendPotential, 1, MPI::REALTYPE,
635 >                              MPI::SUM);
636 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &torsionPotential, 1,
637 >                              MPI::REALTYPE, MPI::SUM);
638 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &inversionPotential, 1,
639 >                              MPI::REALTYPE, MPI::SUM);
640 > #endif
641 >
642      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
643 <    curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
644 <    curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
645 <    curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
646 <    curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
647 <    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;    
643 >
644 >    curSnapshot->setBondPotential(bondPotential);
645 >    curSnapshot->setBendPotential(bendPotential);
646 >    curSnapshot->setTorsionPotential(torsionPotential);
647 >    curSnapshot->setInversionPotential(inversionPotential);
648 >    
649 >    // RealType shortRangePotential = bondPotential + bendPotential +
650 >    //   torsionPotential +  inversionPotential;    
651 >
652 >    // curSnapshot->setShortRangePotential(shortRangePotential);
653    }
654    
655    void ForceManager::longRangeInteractions() {
# Line 638 | Line 694 | namespace OpenMD {
694      RealType rCutSq;
695      bool in_switching_region;
696      RealType sw, dswdr, swderiv;
697 <    vector<int> atomListColumn, atomListRow, atomListLocal;
697 >    vector<int> atomListColumn, atomListRow;
698      InteractionData idat;
699      SelfData sdat;
700      RealType mf;
645    RealType lrPot;
701      RealType vpair;
702      RealType dVdFQ1(0.0);
703      RealType dVdFQ2(0.0);
704      potVec longRangePotential(0.0);
705      potVec workPot(0.0);
706 +    potVec exPot(0.0);
707 +    Vector3d eField1(0.0);
708 +    Vector3d eField2(0.0);
709      vector<int>::iterator ia, jb;
710  
711      int loopStart, loopEnd;
# Line 655 | Line 713 | namespace OpenMD {
713      idat.vdwMult = &vdwMult;
714      idat.electroMult = &electroMult;
715      idat.pot = &workPot;
716 +    idat.excludedPot = &exPot;
717      sdat.pot = fDecomp_->getEmbeddingPotential();
718 +    sdat.excludedPot = fDecomp_->getExcludedSelfPotential();
719      idat.vpair = &vpair;
720      idat.dVdFQ1 = &dVdFQ1;
721      idat.dVdFQ2 = &dVdFQ2;
722 +    idat.eField1 = &eField1;
723 +    idat.eField2 = &eField2;  
724      idat.f1 = &f1;
725      idat.sw = &sw;
726      idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
727      idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false;
728      idat.doParticlePot = doParticlePot_;
729 +    idat.doElectricField = doElectricField_;
730      sdat.doParticlePot = doParticlePot_;
731      
732      loopEnd = PAIR_LOOP;
# Line 672 | Line 735 | namespace OpenMD {
735      } else {
736        loopStart = PAIR_LOOP;
737      }
675  
738      for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
739      
740        if (iLoop == loopStart) {
741          bool update_nlist = fDecomp_->checkNeighborList();
742 <        if (update_nlist)
742 >        if (update_nlist) {
743 >          if (!usePeriodicBoundaryConditions_)
744 >            Mat3x3d bbox = thermo->getBoundingBox();
745            neighborList = fDecomp_->buildNeighborList();
746 <      }            
746 >        }
747 >      }
748  
749        for (vector<pair<int, int> >::iterator it = neighborList.begin();
750               it != neighborList.end(); ++it) {
# Line 700 | Line 765 | namespace OpenMD {
765            if (iLoop == PAIR_LOOP) {
766              vij = 0.0;
767              fij = V3Zero;
768 +            eField1 = V3Zero;
769 +            eField2 = V3Zero;
770            }
771            
772            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
773                                                       rgrp);
774 <          
774 >
775            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
776            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
777  
778            if (doHeatFlux_)
779              gvel2 = fDecomp_->getGroupVelocityColumn(cg2);
780 <        
780 >
781            for (ia = atomListRow.begin();
782                 ia != atomListRow.end(); ++ia) {            
783              atom1 = (*ia);
784 <            
784 >
785              for (jb = atomListColumn.begin();
786                   jb != atomListColumn.end(); ++jb) {              
787                atom2 = (*jb);
788  
789 <              if (!fDecomp_->skipAtomPair(atom1, atom2)) {
789 >              if (!fDecomp_->skipAtomPair(atom1, atom2, cg1, cg2)) {
790 >
791                  vpair = 0.0;
792                  workPot = 0.0;
793 +                exPot = 0.0;
794                  f1 = V3Zero;
795                  dVdFQ1 = 0.0;
796                  dVdFQ2 = 0.0;
797  
798                  fDecomp_->fillInteractionData(idat, atom1, atom2);
799 <                
799 >
800                  topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
801                  vdwMult = vdwScale_[topoDist];
802                  electroMult = electrostaticScale_[topoDist];
# Line 772 | Line 841 | namespace OpenMD {
841                fij += fg;
842  
843                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
844 <                stressTensor -= outProduct( *(idat.d), fg);
845 <                if (doHeatFlux_)
846 <                  fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2));
847 <                
844 >                if (!fDecomp_->skipAtomPair(atomListRow[0],
845 >                                            atomListColumn[0],
846 >                                            cg1, cg2)) {
847 >                  stressTensor -= outProduct( *(idat.d), fg);
848 >                  if (doHeatFlux_)
849 >                    fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2));
850 >                }                
851                }
852            
853                for (ia = atomListRow.begin();
# Line 832 | Line 904 | namespace OpenMD {
904  
905            fDecomp_->collectIntermediateData();
906  
907 <          for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
907 >          for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
908              fDecomp_->fillSelfData(sdat, atom1);
909              interactionMan_->doPreForce(sdat);
910            }
# Line 843 | Line 915 | namespace OpenMD {
915        }
916      }
917      
918 +    // collects pairwise information
919      fDecomp_->collectData();
920          
921      if (info_->requiresSelfCorrection()) {
922 <
850 <      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
922 >      for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
923          fDecomp_->fillSelfData(sdat, atom1);
924          interactionMan_->doSelfCorrection(sdat);
925        }
854
926      }
927  
928 +    // collects single-atom information
929 +    fDecomp_->collectSelfData();
930 +
931      longRangePotential = *(fDecomp_->getEmbeddingPotential()) +
932        *(fDecomp_->getPairwisePotential());
933  
934 <    lrPot = longRangePotential.sum();
934 >    curSnapshot->setLongRangePotential(longRangePotential);
935 >    
936 >    curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedSelfPotential()) +
937 >                                         *(fDecomp_->getExcludedPotential()));
938  
862    //store the stressTensor and long range potential    
863    curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
864    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
865    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
939    }
940  
941    
942    void ForceManager::postCalculation() {
943 +
944 +    vector<Perturbation*>::iterator pi;
945 +    for (pi = perturbations_.begin(); pi != perturbations_.end(); ++pi) {
946 +      (*pi)->applyPerturbation();
947 +    }
948 +
949      SimInfo::MoleculeIterator mi;
950      Molecule* mol;
951      Molecule::RigidBodyIterator rbIter;
952      RigidBody* rb;
953      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
954 <    
954 >  
955      // collect the atomic forces onto rigid bodies
956      
957      for (mol = info_->beginMolecule(mi); mol != NULL;
# Line 885 | Line 964 | namespace OpenMD {
964      }
965      
966   #ifdef IS_MPI
888
967      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9,
968                                MPI::REALTYPE, MPI::SUM);
969   #endif
970      curSnapshot->setStressTensor(stressTensor);
971      
972 <  }
972 >    if (info_->getSimParams()->getUseLongRangeCorrections()) {
973 >      /*
974 >      RealType vol = curSnapshot->getVolume();
975 >      RealType Elrc(0.0);
976 >      RealType Wlrc(0.0);
977  
978 < } //end namespace OpenMD
978 >      set<AtomType*>::iterator i;
979 >      set<AtomType*>::iterator j;
980 >    
981 >      RealType n_i, n_j;
982 >      RealType rho_i, rho_j;
983 >      pair<RealType, RealType> LRI;
984 >      
985 >      for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) {
986 >        n_i = RealType(info_->getGlobalCountOfType(*i));
987 >        rho_i = n_i /  vol;
988 >        for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) {
989 >          n_j = RealType(info_->getGlobalCountOfType(*j));
990 >          rho_j = n_j / vol;
991 >          
992 >          LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) );
993 >
994 >          Elrc += n_i   * rho_j * LRI.first;
995 >          Wlrc -= rho_i * rho_j * LRI.second;
996 >        }
997 >      }
998 >      Elrc *= 2.0 * NumericConstant::PI;
999 >      Wlrc *= 2.0 * NumericConstant::PI;
1000 >
1001 >      RealType lrp = curSnapshot->getLongRangePotential();
1002 >      curSnapshot->setLongRangePotential(lrp + Elrc);
1003 >      stressTensor += Wlrc * SquareMatrix3<RealType>::identity();
1004 >      curSnapshot->setStressTensor(stressTensor);
1005 >      */
1006 >    
1007 >    }
1008 >  }
1009 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines