ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/brains/ForceManager.cpp
(Generate patch)

Comparing trunk/src/brains/ForceManager.cpp (file contents):
Revision 1809 by gezelter, Mon Nov 5 19:41:28 2012 UTC vs.
Revision 1969 by gezelter, Wed Feb 26 14:14:50 2014 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 68 | 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 88 | 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,
102 <   *                        or SHIFTED_POTENTIAL)
101 >   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, TAYLOR_SHIFTED,
102 >   *                        SHIFTED_POTENTIAL, or EWALD_FULL)
103     *      If cutoffMethod was explicitly set, use that choice.
104     *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE
105     *
# Line 118 | Line 128 | namespace OpenMD {
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 132 | Line 149 | namespace OpenMD {
149          rCut_ = 12.0;
150        } else {
151          RealType thisCut;
152 <        set<AtomType*>::iterator i;
136 <        set<AtomType*> atomTypes;
137 <        atomTypes = info_->getSimulatedAtomTypes();        
138 <        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 157 | 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 +    stringToCutoffMethod["EWALD_FULL"] = EWALD_FULL;
176    
177      if (simParams_->haveCutoffMethod()) {
178        string cutMeth = toUpperCopy(simParams_->getCutoffMethod());
# Line 166 | Line 182 | namespace OpenMD {
182          sprintf(painCave.errMsg,
183                  "ForceManager::setupCutoffs: Could not find chosen cutoffMethod %s\n"
184                  "\tShould be one of: "
185 <                "HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n",
185 >                "HARD, SWITCHED, SHIFTED_POTENTIAL, TAYLOR_SHIFTED,\n"
186 >                "\tSHIFTED_FORCE, or EWALD_FULL\n",
187                  cutMeth.c_str());
188          painCave.isFatal = 1;
189          painCave.severity = OPENMD_ERROR;
# Line 210 | Line 227 | namespace OpenMD {
227              cutoffMethod_ = SHIFTED_POTENTIAL;
228            } else if (myMethod == "SHIFTED_FORCE") {
229              cutoffMethod_ = SHIFTED_FORCE;
230 +          } else if (myMethod == "TAYLOR_SHIFTED") {
231 +            cutoffMethod_ = TAYLOR_SHIFTED;
232 +          } else if (myMethod == "EWALD_FULL") {
233 +            cutoffMethod_ = EWALD_FULL;
234            }
235          
236            if (simParams_->haveSwitchingRadius())
237              rSwitch_ = simParams_->getSwitchingRadius();
238  
239 <          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") {
239 >          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE" ||
240 >              myMethod == "TAYLOR_SHIFTED" || myMethod == "EWALD_FULL") {
241              if (simParams_->haveSwitchingRadius()){
242                sprintf(painCave.errMsg,
243                        "ForceManager::setupCutoffs : DEPRECATED ERROR MESSAGE\n"
# Line 370 | Line 392 | namespace OpenMD {
392      }
393      switcher_->setSwitchType(sft_);
394      switcher_->setSwitch(rSwitch_, rCut_);
373    interactionMan_->setSwitchingRadius(rSwitch_);
395    }
396  
397  
# Line 394 | Line 415 | namespace OpenMD {
415        doParticlePot_ = info_->getSimParams()->getOutputParticlePotential();
416        doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux();
417        if (doHeatFlux_) doParticlePot_ = true;
418 +
419 +      doElectricField_ = info_->getSimParams()->getOutputElectricField();
420    
421      }
422  
# Line 429 | Line 452 | namespace OpenMD {
452        perturbations_.push_back(eField);
453      }
454  
455 <    fDecomp_->distributeInitialData();
456 <
457 <    initialized_ = true;
458 <
455 >    usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions();
456 >    
457 >    fDecomp_->distributeInitialData();
458 >    
459 >    initialized_ = true;
460 >    
461    }
462 <
462 >  
463    void ForceManager::calcForces() {
464      
465      if (!initialized_) initialize();
466 <
466 >    
467      preCalculation();  
468      shortRangeInteractions();
469      longRangeInteractions();
# Line 612 | Line 637 | namespace OpenMD {
637      // Collect from all nodes.  This should eventually be moved into a
638      // SystemDecomposition, but this is a better place than in
639      // Thermo to do the collection.
640 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bondPotential, 1, MPI::REALTYPE,
641 <                              MPI::SUM);
642 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bendPotential, 1, MPI::REALTYPE,
643 <                              MPI::SUM);
644 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &torsionPotential, 1,
645 <                              MPI::REALTYPE, MPI::SUM);
646 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &inversionPotential, 1,
647 <                              MPI::REALTYPE, MPI::SUM);
640 >
641 >    MPI_Allreduce(MPI_IN_PLACE, &bondPotential, 1, MPI_REALTYPE,
642 >                  MPI_SUM, MPI_COMM_WORLD);
643 >    MPI_Allreduce(MPI_IN_PLACE, &bendPotential, 1, MPI_REALTYPE,
644 >                  MPI_SUM, MPI_COMM_WORLD);
645 >    MPI_Allreduce(MPI_IN_PLACE, &torsionPotential, 1,
646 >                  MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
647 >    MPI_Allreduce(MPI_IN_PLACE, &inversionPotential, 1,
648 >                  MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
649 >    // MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bondPotential, 1, MPI::REALTYPE,
650 >    //                           MPI::SUM);
651 >    // MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bendPotential, 1, MPI::REALTYPE,
652 >    //                           MPI::SUM);
653 >    // MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &torsionPotential, 1,
654 >    //                           MPI::REALTYPE, MPI::SUM);
655 >    // MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &inversionPotential, 1,
656 >    //                           MPI::REALTYPE, MPI::SUM);
657   #endif
658  
659      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
# Line 637 | Line 671 | namespace OpenMD {
671    
672    void ForceManager::longRangeInteractions() {
673  
640
674      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
675      DataStorage* config = &(curSnapshot->atomData);
676      DataStorage* cgConfig = &(curSnapshot->cgData);
677  
678 +
679      //calculate the center of mass of cutoff group
680  
681      SimInfo::MoleculeIterator mi;
# Line 674 | Line 708 | namespace OpenMD {
708      RealType vij;
709      Vector3d fij, fg, f1;
710      tuple3<RealType, RealType, RealType> cuts;
711 <    RealType rCutSq;
711 >    RealType rCut, rCutSq, rListSq;
712      bool in_switching_region;
713      RealType sw, dswdr, swderiv;
714 <    vector<int> atomListColumn, atomListRow, atomListLocal;
714 >    vector<int> atomListColumn, atomListRow;
715      InteractionData idat;
716      SelfData sdat;
717      RealType mf;
718      RealType vpair;
719      RealType dVdFQ1(0.0);
720      RealType dVdFQ2(0.0);
687    Vector3d eField1(0.0);
688    Vector3d eField2(0.0);
721      potVec longRangePotential(0.0);
722 +    RealType reciprocalPotential(0.0);
723      potVec workPot(0.0);
724      potVec exPot(0.0);
725 +    Vector3d eField1(0.0);
726 +    Vector3d eField2(0.0);
727      vector<int>::iterator ia, jb;
728  
729      int loopStart, loopEnd;
730 <
730 >    
731 >    idat.rcut = &rCut;
732      idat.vdwMult = &vdwMult;
733      idat.electroMult = &electroMult;
734      idat.pot = &workPot;
# Line 703 | Line 739 | namespace OpenMD {
739      idat.dVdFQ1 = &dVdFQ1;
740      idat.dVdFQ2 = &dVdFQ2;
741      idat.eField1 = &eField1;
742 <    idat.eField2 = &eField2;
742 >    idat.eField2 = &eField2;  
743      idat.f1 = &f1;
744      idat.sw = &sw;
745      idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
746 <    idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false;
746 >    idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE || cutoffMethod_ == TAYLOR_SHIFTED) ? true : false;
747      idat.doParticlePot = doParticlePot_;
748 +    idat.doElectricField = doElectricField_;
749      sdat.doParticlePot = doParticlePot_;
750      
751      loopEnd = PAIR_LOOP;
# Line 721 | Line 758 | namespace OpenMD {
758      
759        if (iLoop == loopStart) {
760          bool update_nlist = fDecomp_->checkNeighborList();
761 <        if (update_nlist)
762 <          neighborList = fDecomp_->buildNeighborList();
763 <      }            
761 >        if (update_nlist) {
762 >          if (!usePeriodicBoundaryConditions_)
763 >            Mat3x3d bbox = thermo->getBoundingBox();
764 >          fDecomp_->buildNeighborList(neighborList_);
765 >        }
766 >      }
767  
768 <      for (vector<pair<int, int> >::iterator it = neighborList.begin();
769 <             it != neighborList.end(); ++it) {
768 >      for (vector<pair<int, int> >::iterator it = neighborList_.begin();
769 >             it != neighborList_.end(); ++it) {
770                  
771          cg1 = (*it).first;
772          cg2 = (*it).second;
773          
774 <        cuts = fDecomp_->getGroupCutoffs(cg1, cg2);
774 >        fDecomp_->getGroupCutoffs(cg1, cg2, rCut, rCutSq, rListSq);
775  
776          d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
777  
778 <        curSnapshot->wrapVector(d_grp);        
778 >        // already wrapped in the getIntergroupVector call:
779 >        // curSnapshot->wrapVector(d_grp);        
780          rgrpsq = d_grp.lengthSquare();
740        rCutSq = cuts.second;
781  
782          if (rgrpsq < rCutSq) {
743          idat.rcut = &cuts.first;
783            if (iLoop == PAIR_LOOP) {
784              vij = 0.0;
785 <            fij = V3Zero;
785 >            fij.zero();
786 >            eField1.zero();
787 >            eField2.zero();
788            }
789            
790            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
# Line 768 | Line 809 | namespace OpenMD {
809                  vpair = 0.0;
810                  workPot = 0.0;
811                  exPot = 0.0;
812 <                f1 = V3Zero;
812 >                f1.zero();
813                  dVdFQ1 = 0.0;
814                  dVdFQ2 = 0.0;
815  
# Line 795 | Line 836 | namespace OpenMD {
836                
837                  r = sqrt( *(idat.r2) );
838                  idat.rij = &r;
839 <              
839 >
840                  if (iLoop == PREPAIR_LOOP) {
841                    interactionMan_->doPrePair(idat);
842                  } else {
# Line 891 | Line 932 | namespace OpenMD {
932          }
933        }
934      }
935 <  
935 >    
936      // collects pairwise information
937      fDecomp_->collectData();
938 +    if (cutoffMethod_ == EWALD_FULL) {
939 +      interactionMan_->doReciprocalSpaceSum(reciprocalPotential);
940 +
941 +      curSnapshot->setReciprocalPotential(reciprocalPotential);
942 +    }
943          
944      if (info_->requiresSelfCorrection()) {
945        for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
# Line 915 | Line 961 | namespace OpenMD {
961  
962    }
963  
918  
964    void ForceManager::postCalculation() {
965  
966      vector<Perturbation*>::iterator pi;
# Line 941 | Line 986 | namespace OpenMD {
986      }
987      
988   #ifdef IS_MPI
989 <    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9,
990 <                              MPI::REALTYPE, MPI::SUM);
989 >    MPI_Allreduce(MPI_IN_PLACE, stressTensor.getArrayPointer(), 9,
990 >      MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
991 >    // MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9,
992 >    //                           MPI::REALTYPE, MPI::SUM);
993   #endif
994      curSnapshot->setStressTensor(stressTensor);
995      
996 +    if (info_->getSimParams()->getUseLongRangeCorrections()) {
997 +      /*
998 +      RealType vol = curSnapshot->getVolume();
999 +      RealType Elrc(0.0);
1000 +      RealType Wlrc(0.0);
1001 +
1002 +      set<AtomType*>::iterator i;
1003 +      set<AtomType*>::iterator j;
1004 +    
1005 +      RealType n_i, n_j;
1006 +      RealType rho_i, rho_j;
1007 +      pair<RealType, RealType> LRI;
1008 +      
1009 +      for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) {
1010 +        n_i = RealType(info_->getGlobalCountOfType(*i));
1011 +        rho_i = n_i /  vol;
1012 +        for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) {
1013 +          n_j = RealType(info_->getGlobalCountOfType(*j));
1014 +          rho_j = n_j / vol;
1015 +          
1016 +          LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) );
1017 +
1018 +          Elrc += n_i   * rho_j * LRI.first;
1019 +          Wlrc -= rho_i * rho_j * LRI.second;
1020 +        }
1021 +      }
1022 +      Elrc *= 2.0 * NumericConstant::PI;
1023 +      Wlrc *= 2.0 * NumericConstant::PI;
1024 +
1025 +      RealType lrp = curSnapshot->getLongRangePotential();
1026 +      curSnapshot->setLongRangePotential(lrp + Elrc);
1027 +      stressTensor += Wlrc * SquareMatrix3<RealType>::identity();
1028 +      curSnapshot->setStressTensor(stressTensor);
1029 +      */
1030 +    
1031 +    }
1032    }
1033 < } //end namespace OpenMD
1033 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines