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 2047 by gezelter, Thu Dec 11 16:16:43 2014 UTC vs.
Revision 2060 by gezelter, Tue Mar 3 16:19:47 2015 UTC

# Line 88 | Line 88 | namespace OpenMD {
88    /**
89     * setupCutoffs
90     *
91 <   * Sets the values of cutoffRadius, switchingRadius, cutoffMethod,
92 <   * and cutoffPolicy
91 >   * Sets the values of cutoffRadius, switchingRadius, and cutoffMethod
92     *
93     * cutoffRadius : realType
94     *  If the cutoffRadius was explicitly set, use that value.
# Line 104 | Line 103 | namespace OpenMD {
103     *      If cutoffMethod was explicitly set, use that choice.
104     *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE
105     *
107   * cutoffPolicy : (one of MIX, MAX, TRADITIONAL)
108   *      If cutoffPolicy was explicitly set, use that choice.
109   *      If cutoffPolicy was not explicitly set, use TRADITIONAL
110   *
106     * switchingRadius : realType
107     *  If the cutoffMethod was set to SWITCHED:
108     *      If the switchingRadius was explicitly set, use that value
# Line 164 | Line 159 | namespace OpenMD {
159        }
160      }
161  
162 <    fDecomp_->setUserCutoff(rCut_);
162 >    fDecomp_->setCutoffRadius(rCut_);
163      interactionMan_->setCutoffRadius(rCut_);
164 +    rCutSq_ = rCut_ * rCut_;
165  
166      map<string, CutoffMethod> stringToCutoffMethod;
167      stringToCutoffMethod["HARD"] = HARD;
# Line 274 | Line 270 | namespace OpenMD {
270            }
271          }
272        }
277    }
278
279    map<string, CutoffPolicy> stringToCutoffPolicy;
280    stringToCutoffPolicy["MIX"] = MIX;
281    stringToCutoffPolicy["MAX"] = MAX;
282    stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL;    
283
284    string cutPolicy;
285    if (forceFieldOptions_.haveCutoffPolicy()){
286      cutPolicy = forceFieldOptions_.getCutoffPolicy();
287    }else if (simParams_->haveCutoffPolicy()) {
288      cutPolicy = simParams_->getCutoffPolicy();
289    }
290
291    if (!cutPolicy.empty()){
292      toUpper(cutPolicy);
293      map<string, CutoffPolicy>::iterator i;
294      i = stringToCutoffPolicy.find(cutPolicy);
295
296      if (i == stringToCutoffPolicy.end()) {
297        sprintf(painCave.errMsg,
298                "ForceManager::setupCutoffs: Could not find chosen cutoffPolicy %s\n"
299                "\tShould be one of: "
300                "MIX, MAX, or TRADITIONAL\n",
301                cutPolicy.c_str());
302        painCave.isFatal = 1;
303        painCave.severity = OPENMD_ERROR;
304        simError();
305      } else {
306        cutoffPolicy_ = i->second;
307      }
308    } else {
309      sprintf(painCave.errMsg,
310              "ForceManager::setupCutoffs: No value was set for the cutoffPolicy.\n"
311              "\tOpenMD will use TRADITIONAL.\n");
312      painCave.isFatal = 0;
313      painCave.severity = OPENMD_INFO;
314      simError();
315      cutoffPolicy_ = TRADITIONAL;        
273      }
317
318    fDecomp_->setCutoffPolicy(cutoffPolicy_);
274          
275      // create the switching function object:
276  
# Line 672 | Line 627 | namespace OpenMD {
627      DataStorage* config = &(curSnapshot->atomData);
628      DataStorage* cgConfig = &(curSnapshot->cgData);
629  
675
630      //calculate the center of mass of cutoff group
631  
632      SimInfo::MoleculeIterator mi;
633      Molecule* mol;
634      Molecule::CutoffGroupIterator ci;
635      CutoffGroup* cg;
636 <
637 <    if(info_->getNCutoffGroups() > 0){      
636 >    
637 >    if(info_->getNCutoffGroups() != info_->getNAtoms()){
638        for (mol = info_->beginMolecule(mi); mol != NULL;
639             mol = info_->nextMolecule(mi)) {
640          for(cg = mol->beginCutoffGroup(ci); cg != NULL;
# Line 704 | Line 658 | namespace OpenMD {
658      RealType electroMult, vdwMult;
659      RealType vij;
660      Vector3d fij, fg, f1;
707    tuple3<RealType, RealType, RealType> cuts;
708    RealType rCut, rCutSq, rListSq;
661      bool in_switching_region;
662      RealType sw, dswdr, swderiv;
663      vector<int> atomListColumn, atomListRow;
# Line 723 | Line 675 | namespace OpenMD {
675      Vector3d eField2(0.0);
676      RealType sPot1(0.0);
677      RealType sPot2(0.0);
678 +    bool newAtom1;
679                    
680      vector<int>::iterator ia, jb;
681  
682      int loopStart, loopEnd;
683      
684 <    idat.rcut = &rCut;
684 >    idat.rcut = &rCut_;
685      idat.vdwMult = &vdwMult;
686      idat.electroMult = &electroMult;
687      idat.pot = &workPot;
# Line 765 | Line 718 | namespace OpenMD {
718          if (update_nlist) {
719            if (!usePeriodicBoundaryConditions_)
720              Mat3x3d bbox = thermo->getBoundingBox();
721 <          fDecomp_->buildNeighborList(neighborList_);
721 >          fDecomp_->buildNeighborList(neighborList_, point_);
722          }
723        }
724  
725 <      for (vector<pair<int, int> >::iterator it = neighborList_.begin();
773 <           it != neighborList_.end(); ++it) {
774 <                
775 <        cg1 = (*it).first;
776 <        cg2 = (*it).second;
725 >      for (cg1 = 0; cg1 < point_.size() - 1; cg1++) {
726          
727 <        fDecomp_->getGroupCutoffs(cg1, cg2, rCut, rCutSq, rListSq);
728 <
729 <        d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
730 <
782 <        // already wrapped in the getIntergroupVector call:
783 <        // curSnapshot->wrapVector(d_grp);        
784 <        rgrpsq = d_grp.lengthSquare();
785 <
786 <        if (rgrpsq < rCutSq) {
787 <          if (iLoop == PAIR_LOOP) {
788 <            vij = 0.0;
789 <            fij.zero();
790 <            eField1.zero();
791 <            eField2.zero();
792 <            sPot1 = 0.0;
793 <            sPot2 = 0.0;
794 <          }
795 <          
796 <          in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
797 <                                                     rgrp);
727 >        atomListRow = fDecomp_->getAtomsInGroupRow(cg1);        
728 >        newAtom1 = true;
729 >        
730 >        for (int m2 = point_[cg1]; m2 < point_[cg1+1]; m2++) {
731  
732 <          atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
733 <          atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
734 <
735 <          if (doHeatFlux_)
736 <            gvel2 = fDecomp_->getGroupVelocityColumn(cg2);
737 <
738 <          for (ia = atomListRow.begin();
739 <               ia != atomListRow.end(); ++ia) {            
740 <            atom1 = (*ia);
741 <
742 <            for (jb = atomListColumn.begin();
743 <                 jb != atomListColumn.end(); ++jb) {              
744 <              atom2 = (*jb);
745 <
746 <              if (!fDecomp_->skipAtomPair(atom1, atom2, cg1, cg2)) {
747 <
748 <                vpair = 0.0;
749 <                workPot = 0.0;
750 <                exPot = 0.0;
751 <                f1.zero();
752 <                dVdFQ1 = 0.0;
753 <                dVdFQ2 = 0.0;
754 <
755 <                fDecomp_->fillInteractionData(idat, atom1, atom2);
756 <
757 <                topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
758 <                vdwMult = vdwScale_[topoDist];
759 <                electroMult = electrostaticScale_[topoDist];
760 <
761 <                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
762 <                  idat.d = &d_grp;
763 <                  idat.r2 = &rgrpsq;
764 <                  if (doHeatFlux_)
765 <                    vel2 = gvel2;
766 <                } else {
767 <                  d = fDecomp_->getInteratomicVector(atom1, atom2);
768 <                  curSnapshot->wrapVector( d );
769 <                  r2 = d.lengthSquare();
770 <                  idat.d = &d;
771 <                  idat.r2 = &r2;
772 <                  if (doHeatFlux_)
773 <                    vel2 = fDecomp_->getAtomVelocityColumn(atom2);
774 <                }
775 <              
776 <                r = sqrt( *(idat.r2) );
777 <                idat.rij = &r;
778 <
779 <                if (iLoop == PREPAIR_LOOP) {
780 <                  interactionMan_->doPrePair(idat);
781 <                } else {
782 <                  interactionMan_->doPair(idat);
783 <                  fDecomp_->unpackInteractionData(idat, atom1, atom2);
784 <                  vij += vpair;
785 <                  fij += f1;
786 <                  stressTensor -= outProduct( *(idat.d), f1);
787 <                  if (doHeatFlux_)
788 <                    fDecomp_->addToHeatFlux(*(idat.d) * dot(f1, vel2));
732 >          cg2 = neighborList_[m2];
733 >          
734 >          d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
735 >        
736 >          // already wrapped in the getIntergroupVector call:
737 >          // curSnapshot->wrapVector(d_grp);        
738 >          rgrpsq = d_grp.lengthSquare();
739 >          
740 >          if (rgrpsq < rCutSq_) {
741 >            if (iLoop == PAIR_LOOP) {
742 >              vij = 0.0;
743 >              fij.zero();
744 >              eField1.zero();
745 >              eField2.zero();
746 >              sPot1 = 0.0;
747 >              sPot2 = 0.0;
748 >            }
749 >            
750 >            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
751 >                                                       rgrp);
752 >            
753 >            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
754 >            
755 >            if (doHeatFlux_)
756 >              gvel2 = fDecomp_->getGroupVelocityColumn(cg2);
757 >            
758 >            for (ia = atomListRow.begin();
759 >                 ia != atomListRow.end(); ++ia) {            
760 >              atom1 = (*ia);
761 >              
762 >              for (jb = atomListColumn.begin();
763 >                   jb != atomListColumn.end(); ++jb) {              
764 >                atom2 = (*jb);
765 >                
766 >                if (!fDecomp_->skipAtomPair(atom1, atom2, cg1, cg2)) {
767 >                  
768 >                  vpair = 0.0;
769 >                  workPot = 0.0;
770 >                  exPot = 0.0;
771 >                  f1.zero();
772 >                  dVdFQ1 = 0.0;
773 >                  dVdFQ2 = 0.0;
774 >                  
775 >                  fDecomp_->fillInteractionData(idat, atom1, atom2, newAtom1);
776 >                  
777 >                  topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
778 >                  vdwMult = vdwScale_[topoDist];
779 >                  electroMult = electrostaticScale_[topoDist];
780 >                  
781 >                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
782 >                    idat.d = &d_grp;
783 >                    idat.r2 = &rgrpsq;
784 >                    if (doHeatFlux_)
785 >                      vel2 = gvel2;
786 >                  } else {
787 >                    d = fDecomp_->getInteratomicVector(atom1, atom2);
788 >                    curSnapshot->wrapVector( d );
789 >                    r2 = d.lengthSquare();
790 >                    idat.d = &d;
791 >                    idat.r2 = &r2;
792 >                    if (doHeatFlux_)
793 >                      vel2 = fDecomp_->getAtomVelocityColumn(atom2);
794 >                  }
795 >                  
796 >                  r = sqrt( *(idat.r2) );
797 >                  idat.rij = &r;
798 >                  
799 >                  if (iLoop == PREPAIR_LOOP) {
800 >                    interactionMan_->doPrePair(idat);
801 >                  } else {
802 >                    interactionMan_->doPair(idat);
803 >                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
804 >                    vij += vpair;
805 >                    fij += f1;
806 >                    stressTensor -= outProduct( *(idat.d), f1);
807 >                    if (doHeatFlux_)
808 >                      fDecomp_->addToHeatFlux(*(idat.d) * dot(f1, vel2));
809 >                  }
810                  }
811                }
812              }
813 <          }
814 <
815 <          if (iLoop == PAIR_LOOP) {
816 <            if (in_switching_region) {
817 <              swderiv = vij * dswdr / rgrp;
818 <              fg = swderiv * d_grp;
819 <              fij += fg;
820 <
821 <              if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
822 <                if (!fDecomp_->skipAtomPair(atomListRow[0],
823 <                                            atomListColumn[0],
870 <                                            cg1, cg2)) {
813 >            
814 >            if (iLoop == PAIR_LOOP) {
815 >              if (in_switching_region) {
816 >                swderiv = vij * dswdr / rgrp;
817 >                fg = swderiv * d_grp;
818 >                fij += fg;
819 >                
820 >                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
821 >                  if (!fDecomp_->skipAtomPair(atomListRow[0],
822 >                                              atomListColumn[0],
823 >                                              cg1, cg2)) {
824                    stressTensor -= outProduct( *(idat.d), fg);
825                    if (doHeatFlux_)
826                      fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2));
827 <                }                
828 <              }
829 <          
830 <              for (ia = atomListRow.begin();
831 <                   ia != atomListRow.end(); ++ia) {            
832 <                atom1 = (*ia);                
833 <                mf = fDecomp_->getMassFactorRow(atom1);
834 <                // fg is the force on atom ia due to cutoff group's
835 <                // presence in switching region
836 <                fg = swderiv * d_grp * mf;
837 <                fDecomp_->addForceToAtomRow(atom1, fg);
838 <                if (atomListRow.size() > 1) {
839 <                  if (info_->usesAtomicVirial()) {
840 <                    // find the distance between the atom
841 <                    // and the center of the cutoff group:
842 <                    dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
843 <                    stressTensor -= outProduct(dag, fg);
844 <                    if (doHeatFlux_)
845 <                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
827 >                  }                
828 >                }
829 >                
830 >                for (ia = atomListRow.begin();
831 >                     ia != atomListRow.end(); ++ia) {            
832 >                  atom1 = (*ia);                
833 >                  mf = fDecomp_->getMassFactorRow(atom1);
834 >                  // fg is the force on atom ia due to cutoff group's
835 >                  // presence in switching region
836 >                  fg = swderiv * d_grp * mf;
837 >                  fDecomp_->addForceToAtomRow(atom1, fg);
838 >                  if (atomListRow.size() > 1) {
839 >                    if (info_->usesAtomicVirial()) {
840 >                      // find the distance between the atom
841 >                      // and the center of the cutoff group:
842 >                      dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
843 >                      stressTensor -= outProduct(dag, fg);
844 >                      if (doHeatFlux_)
845 >                        fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
846 >                    }
847                    }
848                  }
849 <              }
850 <              for (jb = atomListColumn.begin();
851 <                   jb != atomListColumn.end(); ++jb) {              
852 <                atom2 = (*jb);
853 <                mf = fDecomp_->getMassFactorColumn(atom2);
854 <                // fg is the force on atom jb due to cutoff group's
855 <                // presence in switching region
856 <                fg = -swderiv * d_grp * mf;
857 <                fDecomp_->addForceToAtomColumn(atom2, fg);
858 <
859 <                if (atomListColumn.size() > 1) {
860 <                  if (info_->usesAtomicVirial()) {
861 <                    // find the distance between the atom
862 <                    // and the center of the cutoff group:
863 <                    dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
864 <                    stressTensor -= outProduct(dag, fg);
865 <                    if (doHeatFlux_)
866 <                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
849 >                for (jb = atomListColumn.begin();
850 >                     jb != atomListColumn.end(); ++jb) {              
851 >                  atom2 = (*jb);
852 >                  mf = fDecomp_->getMassFactorColumn(atom2);
853 >                  // fg is the force on atom jb due to cutoff group's
854 >                  // presence in switching region
855 >                  fg = -swderiv * d_grp * mf;
856 >                  fDecomp_->addForceToAtomColumn(atom2, fg);
857 >                  
858 >                  if (atomListColumn.size() > 1) {
859 >                    if (info_->usesAtomicVirial()) {
860 >                      // find the distance between the atom
861 >                      // and the center of the cutoff group:
862 >                      dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
863 >                      stressTensor -= outProduct(dag, fg);
864 >                      if (doHeatFlux_)
865 >                        fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
866 >                    }
867                    }
868                  }
869                }
870 +              //if (!info_->usesAtomicVirial()) {
871 +              //  stressTensor -= outProduct(d_grp, fij);
872 +              //  if (doHeatFlux_)
873 +              //     fDecomp_->addToHeatFlux( d_grp * dot(fij, vel2));
874 +              //}
875              }
917            //if (!info_->usesAtomicVirial()) {
918            //  stressTensor -= outProduct(d_grp, fij);
919            //  if (doHeatFlux_)
920            //     fDecomp_->addToHeatFlux( d_grp * dot(fij, vel2));
921            //}
876            }
877          }
878 +        newAtom1 = false;
879        }
880 <
880 >        
881        if (iLoop == PREPAIR_LOOP) {
882          if (info_->requiresPrepair()) {
883 <
883 >          
884            fDecomp_->collectIntermediateData();
885 <
885 >          
886            for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
887              fDecomp_->fillSelfData(sdat, atom1);
888              interactionMan_->doPreForce(sdat);
889            }
890 <
890 >          
891            fDecomp_->distributeIntermediateData();
892 <
892 >          
893          }
894        }
895      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines