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 1583 by gezelter, Thu Jun 16 22:00:08 2011 UTC vs.
Revision 1613 by gezelter, Thu Aug 18 20:18:19 2011 UTC

# Line 75 | Line 75 | namespace OpenMD {
75    /**
76     * setupCutoffs
77     *
78 <   * Sets the values of cutoffRadius, cutoffMethod, and cutoffPolicy
78 >   * Sets the values of cutoffRadius, switchingRadius, cutoffMethod,
79 >   * and cutoffPolicy
80     *
81     * cutoffRadius : realType
82     *  If the cutoffRadius was explicitly set, use that value.
# Line 85 | Line 86 | namespace OpenMD {
86     *      simulation for suggested cutoff values (e.g. 2.5 * sigma).
87     *      Use the maximum suggested value that was found.
88     *
89 <   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, SHIFTED_POTENTIAL)
89 >   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE,
90 >   *                        or SHIFTED_POTENTIAL)
91     *      If cutoffMethod was explicitly set, use that choice.
92     *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE
93     *
94     * cutoffPolicy : (one of MIX, MAX, TRADITIONAL)
95     *      If cutoffPolicy was explicitly set, use that choice.
96     *      If cutoffPolicy was not explicitly set, use TRADITIONAL
97 +   *
98 +   * switchingRadius : realType
99 +   *  If the cutoffMethod was set to SWITCHED:
100 +   *      If the switchingRadius was explicitly set, use that value
101 +   *          (but do a sanity check first).
102 +   *      If the switchingRadius was not explicitly set: use 0.85 *
103 +   *      cutoffRadius_
104 +   *  If the cutoffMethod was not set to SWITCHED:
105 +   *      Set switchingRadius equal to cutoffRadius for safety.
106     */
107    void ForceManager::setupCutoffs() {
108      
109      Globals* simParams_ = info_->getSimParams();
110      ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
111 +    int mdFileVersion;
112      
113 +    if (simParams_->haveMDfileVersion())
114 +      mdFileVersion = simParams_->getMDfileVersion();
115 +    else
116 +      mdFileVersion = 0;
117 +  
118 +
119      if (simParams_->haveCutoffRadius()) {
120        rCut_ = simParams_->getCutoffRadius();
121      } else {      
# Line 130 | Line 148 | namespace OpenMD {
148      }
149  
150      fDecomp_->setUserCutoff(rCut_);
151 +    interactionMan_->setCutoffRadius(rCut_);
152  
153      map<string, CutoffMethod> stringToCutoffMethod;
154      stringToCutoffMethod["HARD"] = HARD;
# Line 201 | Line 220 | namespace OpenMD {
220        simError();
221        cutoffPolicy_ = TRADITIONAL;        
222      }
204    fDecomp_->setCutoffPolicy(cutoffPolicy_);
205  }
223  
224 <  /**
225 <   * setupSwitching
209 <   *
210 <   * Sets the values of switchingRadius and
211 <   *  If the switchingRadius was explicitly set, use that value (but check it)
212 <   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
213 <   */
214 <  void ForceManager::setupSwitching() {
215 <    Globals* simParams_ = info_->getSimParams();
216 <
224 >    fDecomp_->setCutoffPolicy(cutoffPolicy_);
225 >        
226      // create the switching function object:
227 +
228      switcher_ = new SwitchingFunction();
229 <    
230 <    if (simParams_->haveSwitchingRadius()) {
231 <      rSwitch_ = simParams_->getSwitchingRadius();
232 <      if (rSwitch_ > rCut_) {        
229 >  
230 >    if (cutoffMethod_ == SWITCHED) {
231 >      if (simParams_->haveSwitchingRadius()) {
232 >        rSwitch_ = simParams_->getSwitchingRadius();
233 >        if (rSwitch_ > rCut_) {        
234 >          sprintf(painCave.errMsg,
235 >                  "ForceManager::setupCutoffs: switchingRadius (%f) is larger "
236 >                  "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
237 >          painCave.isFatal = 1;
238 >          painCave.severity = OPENMD_ERROR;
239 >          simError();
240 >        }
241 >      } else {      
242 >        rSwitch_ = 0.85 * rCut_;
243          sprintf(painCave.errMsg,
244 <                "ForceManager::setupSwitching: switchingRadius (%f) is larger "
245 <                "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
246 <        painCave.isFatal = 1;
247 <        painCave.severity = OPENMD_ERROR;
244 >                "ForceManager::setupCutoffs: No value was set for the switchingRadius.\n"
245 >                "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
246 >                "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
247 >        painCave.isFatal = 0;
248 >        painCave.severity = OPENMD_WARNING;
249          simError();
250        }
251 <    } else {      
252 <      rSwitch_ = 0.85 * rCut_;
253 <      sprintf(painCave.errMsg,
254 <              "ForceManager::setupSwitching: No value was set for the switchingRadius.\n"
255 <              "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
256 <              "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
257 <      painCave.isFatal = 0;
258 <      painCave.severity = OPENMD_WARNING;
259 <      simError();
260 <    }          
251 >    } else {
252 >      if (simParams_->haveSwitchingRadius()) {
253 >        map<string, CutoffMethod>::const_iterator it;
254 >        string theMeth;
255 >        for (it = stringToCutoffMethod.begin();
256 >             it != stringToCutoffMethod.end(); ++it) {
257 >          if (it->second == cutoffMethod_) {
258 >            theMeth = it->first;
259 >            break;
260 >          }
261 >        }
262 >        sprintf(painCave.errMsg,
263 >                "ForceManager::setupCutoffs: the cutoffMethod (%s)\n"
264 >                "\tis not set to SWITCHED, so switchingRadius value\n"
265 >                "\twill be ignored for this simulation\n", theMeth.c_str());
266 >        painCave.isFatal = 0;
267 >        painCave.severity = OPENMD_WARNING;
268 >        simError();
269 >      }
270 >
271 >      rSwitch_ = rCut_;
272 >    }
273      
274      // Default to cubic switching function.
275      sft_ = cubic;
# Line 263 | Line 296 | namespace OpenMD {
296      }
297      switcher_->setSwitchType(sft_);
298      switcher_->setSwitch(rSwitch_, rCut_);
299 +    interactionMan_->setSwitchingRadius(rSwitch_);
300    }
301    
302    void ForceManager::initialize() {
303  
304      if (!info_->isTopologyDone()) {
305 +
306        info_->update();
307        interactionMan_->setSimInfo(info_);
308        interactionMan_->initialize();
# Line 275 | Line 310 | namespace OpenMD {
310        // We want to delay the cutoffs until after the interaction
311        // manager has set up the atom-atom interactions so that we can
312        // query them for suggested cutoff values
278
313        setupCutoffs();
280      setupSwitching();
314  
315        info_->prepareTopology();      
316      }
317  
318      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
319      
320 <    // Force fields can set options on how to scale van der Waals and electrostatic
321 <    // interactions for atoms connected via bonds, bends and torsions
322 <    // in this case the topological distance between atoms is:
320 >    // Force fields can set options on how to scale van der Waals and
321 >    // electrostatic interactions for atoms connected via bonds, bends
322 >    // and torsions in this case the topological distance between
323 >    // atoms is:
324      // 0 = topologically unconnected
325      // 1 = bonded together
326      // 2 = connected via a bend
# Line 338 | Line 372 | namespace OpenMD {
372      
373      for (mol = info_->beginMolecule(mi); mol != NULL;
374           mol = info_->nextMolecule(mi)) {
375 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
375 >      for(atom = mol->beginAtom(ai); atom != NULL;
376 >          atom = mol->nextAtom(ai)) {
377          atom->zeroForcesAndTorques();
378        }
379 <          
379 >      
380        //change the positions of atoms which belong to the rigidbodies
381        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
382             rb = mol->nextRigidBody(rbIter)) {
383          rb->zeroForcesAndTorques();
384        }        
385 <
385 >      
386        if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){
387          for(cg = mol->beginCutoffGroup(ci); cg != NULL;
388              cg = mol->nextCutoffGroup(ci)) {
# Line 356 | Line 391 | namespace OpenMD {
391          }
392        }      
393      }
394 <  
394 >    
395      // Zero out the stress tensor
396      tau *= 0.0;
397      
# Line 410 | Line 445 | namespace OpenMD {
445            dataSet.prev.angle = dataSet.curr.angle = angle;
446            dataSet.prev.potential = dataSet.curr.potential = currBendPot;
447            dataSet.deltaV = 0.0;
448 <          bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, dataSet));
448 >          bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend,
449 >                                                                  dataSet));
450          }else {
451            i->second.prev.angle = i->second.curr.angle;
452            i->second.prev.potential = i->second.curr.potential;
# Line 553 | Line 589 | namespace OpenMD {
589          bool update_nlist = fDecomp_->checkNeighborList();
590          if (update_nlist)
591            neighborList = fDecomp_->buildNeighborList();
592 <      }      
593 <        
592 >      }            
593 >
594        for (vector<pair<int, int> >::iterator it = neighborList.begin();
595               it != neighborList.end(); ++it) {
596                  
# Line 564 | Line 600 | namespace OpenMD {
600          cuts = fDecomp_->getGroupCutoffs(cg1, cg2);
601  
602          d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
603 +
604          curSnapshot->wrapVector(d_grp);        
605          rgrpsq = d_grp.lengthSquare();
569
606          rCutSq = cuts.second;
607  
608          if (rgrpsq < rCutSq) {
609            idat.rcut = &cuts.first;
610            if (iLoop == PAIR_LOOP) {
611 <            vij *= 0.0;
611 >            vij = 0.0;
612              fij = V3Zero;
613            }
614            
# Line 581 | Line 617 | namespace OpenMD {
617                
618            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
619            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
620 +                      
621  
622            for (vector<int>::iterator ia = atomListRow.begin();
623                 ia != atomListRow.end(); ++ia) {            
# Line 589 | Line 626 | namespace OpenMD {
626              for (vector<int>::iterator jb = atomListColumn.begin();
627                   jb != atomListColumn.end(); ++jb) {              
628                atom2 = (*jb);
629 <            
629 >
630                if (!fDecomp_->skipAtomPair(atom1, atom2)) {
631                  vpair = 0.0;
632                  workPot = 0.0;
# Line 611 | Line 648 | namespace OpenMD {
648                    idat.d = &d;
649                    idat.r2 = &r2;
650                  }
651 <                
651 >              
652                  r = sqrt( *(idat.r2) );
653                  idat.rij = &r;
654                
# Line 620 | Line 657 | namespace OpenMD {
657                  } else {
658                    interactionMan_->doPair(idat);
659                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
660 +
661                    vij += vpair;
662                    fij += f1;
663                    tau -= outProduct( *(idat.d), f1);
# Line 632 | Line 670 | namespace OpenMD {
670              if (in_switching_region) {
671                swderiv = vij * dswdr / rgrp;
672                fg = swderiv * d_grp;
635
673                fij += fg;
674  
675                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
# Line 676 | Line 713 | namespace OpenMD {
713                  }
714                }
715              }
716 <            //if (!SIM_uses_AtomicVirial) {
716 >            //if (!info_->usesAtomicVirial()) {
717              //  tau -= outProduct(d_grp, fij);
718              //}
719            }
# Line 684 | Line 721 | namespace OpenMD {
721        }
722  
723        if (iLoop == PREPAIR_LOOP) {
724 <        if (info_->requiresPrepair()) {            
724 >        if (info_->requiresPrepair()) {
725 >
726            fDecomp_->collectIntermediateData();
727  
728            for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
729              fDecomp_->fillSelfData(sdat, atom1);
730              interactionMan_->doPreForce(sdat);
731            }
694          
695          
696          fDecomp_->distributeIntermediateData();        
697        }
698      }
732  
733 <    }
701 <    
702 <    fDecomp_->collectData();
703 <    
704 <    if ( info_->requiresSkipCorrection() ) {
705 <      
706 <      for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
733 >          fDecomp_->distributeIntermediateData();
734  
708        vector<int> skipList = fDecomp_->getSkipsForAtom( atom1 );
709        
710        for (vector<int>::iterator jb = skipList.begin();
711             jb != skipList.end(); ++jb) {        
712    
713          atom2 = (*jb);
714          fDecomp_->fillSkipData(idat, atom1, atom2);
715          interactionMan_->doSkipCorrection(idat);
716          fDecomp_->unpackSkipData(idat, atom1, atom2);
717
735          }
736        }
737      }
738      
739 +    fDecomp_->collectData();
740 +        
741      if (info_->requiresSelfCorrection()) {
742  
743        for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines