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 1618 by gezelter, Mon Sep 12 17:09:26 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      if (simParams_->haveCutoffRadius()) {
119        rCut_ = simParams_->getCutoffRadius();
120      } else {      
# Line 130 | Line 147 | namespace OpenMD {
147      }
148  
149      fDecomp_->setUserCutoff(rCut_);
150 +    interactionMan_->setCutoffRadius(rCut_);
151  
152      map<string, CutoffMethod> stringToCutoffMethod;
153      stringToCutoffMethod["HARD"] = HARD;
# Line 154 | Line 172 | namespace OpenMD {
172          cutoffMethod_ = i->second;
173        }
174      } else {
175 <      sprintf(painCave.errMsg,
176 <              "ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n"
177 <              "\tOpenMD will use SHIFTED_FORCE.\n");
178 <      painCave.isFatal = 0;
179 <      painCave.severity = OPENMD_INFO;
180 <      simError();
181 <      cutoffMethod_ = SHIFTED_FORCE;        
175 >      if (mdFileVersion > 1) {
176 >        sprintf(painCave.errMsg,
177 >                "ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n"
178 >                "\tOpenMD will use SHIFTED_FORCE.\n");
179 >        painCave.isFatal = 0;
180 >        painCave.severity = OPENMD_INFO;
181 >        simError();
182 >        cutoffMethod_ = SHIFTED_FORCE;        
183 >      } else {
184 >        // handle the case where the old file version was in play
185 >        // (there should be no cutoffMethod, so we have to deduce it
186 >        // from other data).        
187 >
188 >        sprintf(painCave.errMsg,
189 >                "ForceManager::setupCutoffs : DEPRECATED FILE FORMAT!\n"
190 >                "\tOpenMD found a file which does not set a cutoffMethod.\n"
191 >                "\tOpenMD will attempt to deduce a cutoffMethod using the\n"
192 >                "\tbehavior of the older (version 1) code.  To remove this\n"
193 >                "\twarning, add an explicit cutoffMethod and change the top\n"
194 >                "\tof the file so that it begins with <OpenMD version=2>\n");
195 >        painCave.isFatal = 0;
196 >        painCave.severity = OPENMD_WARNING;
197 >        simError();            
198 >                
199 >        // The old file version tethered the shifting behavior to the
200 >        // electrostaticSummationMethod keyword.
201 >        
202 >        if (simParams_->haveElectrostaticSummationMethod()) {
203 >          std::string myMethod = simParams_->getElectrostaticSummationMethod();
204 >          toUpper(myMethod);
205 >        
206 >          if (myMethod == "SHIFTED_POTENTIAL") {
207 >            cutoffMethod_ = SHIFTED_POTENTIAL;
208 >          } else if (myMethod == "SHIFTED_FORCE") {
209 >            cutoffMethod_ = SHIFTED_FORCE;
210 >          }
211 >        
212 >          if (simParams_->haveSwitchingRadius())
213 >            rSwitch_ = simParams_->getSwitchingRadius();
214 >
215 >          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") {
216 >            if (simParams_->haveSwitchingRadius()){
217 >              sprintf(painCave.errMsg,
218 >                      "ForceManager::setupCutoffs : DEPRECATED ERROR MESSAGE\n"
219 >                      "\tA value was set for the switchingRadius\n"
220 >                      "\teven though the electrostaticSummationMethod was\n"
221 >                      "\tset to %s\n", myMethod.c_str());
222 >              painCave.severity = OPENMD_WARNING;
223 >              painCave.isFatal = 1;
224 >              simError();            
225 >            }
226 >          }
227 >          if (abs(rCut_ - rSwitch_) < 0.0001) {
228 >            if (cutoffMethod_ == SHIFTED_FORCE) {              
229 >              sprintf(painCave.errMsg,
230 >                      "ForceManager::setupCutoffs : DEPRECATED BEHAVIOR\n"
231 >                      "\tcutoffRadius and switchingRadius are set to the\n"
232 >                      "\tsame value.  OpenMD will use shifted force\n"
233 >                      "\tpotentials instead of switching functions.\n");
234 >              painCave.isFatal = 0;
235 >              painCave.severity = OPENMD_WARNING;
236 >              simError();            
237 >            } else {
238 >              cutoffMethod_ = SHIFTED_POTENTIAL;
239 >              sprintf(painCave.errMsg,
240 >                      "ForceManager::setupCutoffs : DEPRECATED BEHAVIOR\n"
241 >                      "\tcutoffRadius and switchingRadius are set to the\n"
242 >                      "\tsame value.  OpenMD will use shifted potentials\n"
243 >                      "\tinstead of switching functions.\n");
244 >              painCave.isFatal = 0;
245 >              painCave.severity = OPENMD_WARNING;
246 >              simError();            
247 >            }
248 >          }
249 >        }
250 >      }
251      }
252  
253      map<string, CutoffPolicy> stringToCutoffPolicy;
# Line 201 | Line 288 | namespace OpenMD {
288        simError();
289        cutoffPolicy_ = TRADITIONAL;        
290      }
204    fDecomp_->setCutoffPolicy(cutoffPolicy_);
205  }
291  
292 <  /**
293 <   * 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 <
292 >    fDecomp_->setCutoffPolicy(cutoffPolicy_);
293 >        
294      // create the switching function object:
295 +
296      switcher_ = new SwitchingFunction();
297 <    
298 <    if (simParams_->haveSwitchingRadius()) {
299 <      rSwitch_ = simParams_->getSwitchingRadius();
300 <      if (rSwitch_ > rCut_) {        
297 >  
298 >    if (cutoffMethod_ == SWITCHED) {
299 >      if (simParams_->haveSwitchingRadius()) {
300 >        rSwitch_ = simParams_->getSwitchingRadius();
301 >        if (rSwitch_ > rCut_) {        
302 >          sprintf(painCave.errMsg,
303 >                  "ForceManager::setupCutoffs: switchingRadius (%f) is larger "
304 >                  "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
305 >          painCave.isFatal = 1;
306 >          painCave.severity = OPENMD_ERROR;
307 >          simError();
308 >        }
309 >      } else {      
310 >        rSwitch_ = 0.85 * rCut_;
311          sprintf(painCave.errMsg,
312 <                "ForceManager::setupSwitching: switchingRadius (%f) is larger "
313 <                "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
314 <        painCave.isFatal = 1;
315 <        painCave.severity = OPENMD_ERROR;
312 >                "ForceManager::setupCutoffs: No value was set for the switchingRadius.\n"
313 >                "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
314 >                "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
315 >        painCave.isFatal = 0;
316 >        painCave.severity = OPENMD_WARNING;
317          simError();
318        }
319 <    } else {      
320 <      rSwitch_ = 0.85 * rCut_;
321 <      sprintf(painCave.errMsg,
322 <              "ForceManager::setupSwitching: No value was set for the switchingRadius.\n"
323 <              "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
324 <              "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
325 <      painCave.isFatal = 0;
326 <      painCave.severity = OPENMD_WARNING;
327 <      simError();
328 <    }          
319 >    } else {
320 >      if (mdFileVersion > 1) {
321 >        // throw an error if we define a switching radius and don't need one.
322 >        // older file versions should not do this.
323 >        if (simParams_->haveSwitchingRadius()) {
324 >          map<string, CutoffMethod>::const_iterator it;
325 >          string theMeth;
326 >          for (it = stringToCutoffMethod.begin();
327 >               it != stringToCutoffMethod.end(); ++it) {
328 >            if (it->second == cutoffMethod_) {
329 >              theMeth = it->first;
330 >              break;
331 >            }
332 >          }
333 >          sprintf(painCave.errMsg,
334 >                  "ForceManager::setupCutoffs: the cutoffMethod (%s)\n"
335 >                  "\tis not set to SWITCHED, so switchingRadius value\n"
336 >                  "\twill be ignored for this simulation\n", theMeth.c_str());
337 >          painCave.isFatal = 0;
338 >          painCave.severity = OPENMD_WARNING;
339 >          simError();
340 >        }
341 >      }
342 >      rSwitch_ = rCut_;
343 >    }
344      
345      // Default to cubic switching function.
346      sft_ = cubic;
# Line 263 | Line 367 | namespace OpenMD {
367      }
368      switcher_->setSwitchType(sft_);
369      switcher_->setSwitch(rSwitch_, rCut_);
370 +    interactionMan_->setSwitchingRadius(rSwitch_);
371    }
372 +
373 +
374 +
375    
376    void ForceManager::initialize() {
377  
378      if (!info_->isTopologyDone()) {
379 +
380        info_->update();
381        interactionMan_->setSimInfo(info_);
382        interactionMan_->initialize();
# Line 275 | Line 384 | namespace OpenMD {
384        // We want to delay the cutoffs until after the interaction
385        // manager has set up the atom-atom interactions so that we can
386        // query them for suggested cutoff values
278
387        setupCutoffs();
280      setupSwitching();
388  
389        info_->prepareTopology();      
390      }
391  
392      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
393      
394 <    // Force fields can set options on how to scale van der Waals and electrostatic
395 <    // interactions for atoms connected via bonds, bends and torsions
396 <    // in this case the topological distance between atoms is:
394 >    // Force fields can set options on how to scale van der Waals and
395 >    // electrostatic interactions for atoms connected via bonds, bends
396 >    // and torsions in this case the topological distance between
397 >    // atoms is:
398      // 0 = topologically unconnected
399      // 1 = bonded together
400      // 2 = connected via a bend
# Line 338 | Line 446 | namespace OpenMD {
446      
447      for (mol = info_->beginMolecule(mi); mol != NULL;
448           mol = info_->nextMolecule(mi)) {
449 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
449 >      for(atom = mol->beginAtom(ai); atom != NULL;
450 >          atom = mol->nextAtom(ai)) {
451          atom->zeroForcesAndTorques();
452        }
453 <          
453 >      
454        //change the positions of atoms which belong to the rigidbodies
455        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
456             rb = mol->nextRigidBody(rbIter)) {
457          rb->zeroForcesAndTorques();
458        }        
459 <
459 >      
460        if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){
461          for(cg = mol->beginCutoffGroup(ci); cg != NULL;
462              cg = mol->nextCutoffGroup(ci)) {
# Line 356 | Line 465 | namespace OpenMD {
465          }
466        }      
467      }
468 <  
468 >    
469      // Zero out the stress tensor
470      tau *= 0.0;
471      
# Line 410 | Line 519 | namespace OpenMD {
519            dataSet.prev.angle = dataSet.curr.angle = angle;
520            dataSet.prev.potential = dataSet.curr.potential = currBendPot;
521            dataSet.deltaV = 0.0;
522 <          bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, dataSet));
522 >          bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend,
523 >                                                                  dataSet));
524          }else {
525            i->second.prev.angle = i->second.curr.angle;
526            i->second.prev.potential = i->second.curr.potential;
# Line 553 | Line 663 | namespace OpenMD {
663          bool update_nlist = fDecomp_->checkNeighborList();
664          if (update_nlist)
665            neighborList = fDecomp_->buildNeighborList();
666 <      }      
667 <        
666 >      }            
667 >
668        for (vector<pair<int, int> >::iterator it = neighborList.begin();
669               it != neighborList.end(); ++it) {
670                  
# Line 564 | Line 674 | namespace OpenMD {
674          cuts = fDecomp_->getGroupCutoffs(cg1, cg2);
675  
676          d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
677 +
678          curSnapshot->wrapVector(d_grp);        
679          rgrpsq = d_grp.lengthSquare();
569
680          rCutSq = cuts.second;
681  
682          if (rgrpsq < rCutSq) {
683            idat.rcut = &cuts.first;
684            if (iLoop == PAIR_LOOP) {
685 <            vij *= 0.0;
685 >            vij = 0.0;
686              fij = V3Zero;
687            }
688            
689            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
690                                                       rgrp);
691 <              
691 >          
692            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
693            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
694  
# Line 589 | Line 699 | namespace OpenMD {
699              for (vector<int>::iterator jb = atomListColumn.begin();
700                   jb != atomListColumn.end(); ++jb) {              
701                atom2 = (*jb);
702 <            
702 >
703                if (!fDecomp_->skipAtomPair(atom1, atom2)) {
704                  vpair = 0.0;
705                  workPot = 0.0;
# Line 611 | Line 721 | namespace OpenMD {
721                    idat.d = &d;
722                    idat.r2 = &r2;
723                  }
724 <                
724 >              
725                  r = sqrt( *(idat.r2) );
726                  idat.rij = &r;
727                
# Line 632 | Line 742 | namespace OpenMD {
742              if (in_switching_region) {
743                swderiv = vij * dswdr / rgrp;
744                fg = swderiv * d_grp;
635
745                fij += fg;
746  
747                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
# Line 647 | Line 756 | namespace OpenMD {
756                  // presence in switching region
757                  fg = swderiv * d_grp * mf;
758                  fDecomp_->addForceToAtomRow(atom1, fg);
650
759                  if (atomListRow.size() > 1) {
760                    if (info_->usesAtomicVirial()) {
761                      // find the distance between the atom
# Line 676 | Line 784 | namespace OpenMD {
784                  }
785                }
786              }
787 <            //if (!SIM_uses_AtomicVirial) {
787 >            //if (!info_->usesAtomicVirial()) {
788              //  tau -= outProduct(d_grp, fij);
789              //}
790            }
# Line 684 | Line 792 | namespace OpenMD {
792        }
793  
794        if (iLoop == PREPAIR_LOOP) {
795 <        if (info_->requiresPrepair()) {            
795 >        if (info_->requiresPrepair()) {
796 >
797            fDecomp_->collectIntermediateData();
798  
799            for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
800              fDecomp_->fillSelfData(sdat, atom1);
801              interactionMan_->doPreForce(sdat);
802            }
694          
695          
696          fDecomp_->distributeIntermediateData();        
697        }
698      }
803  
804 <    }
701 <    
702 <    fDecomp_->collectData();
703 <    
704 <    if ( info_->requiresSkipCorrection() ) {
705 <      
706 <      for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
804 >          fDecomp_->distributeIntermediateData();
805  
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
806          }
807        }
808      }
809      
810 +    fDecomp_->collectData();
811 +        
812      if (info_->requiresSelfCorrection()) {
813  
814        for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines