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 1579 by gezelter, Thu Jun 9 20:26:29 2011 UTC vs.
Revision 1613 by gezelter, Thu Aug 18 20:18:19 2011 UTC

# Line 59 | Line 59
59   #include "nonbonded/NonBondedInteraction.hpp"
60   #include "parallel/ForceMatrixDecomposition.hpp"
61  
62 + #include <cstdio>
63 + #include <iostream>
64 + #include <iomanip>
65 +
66   using namespace std;
67   namespace OpenMD {
68    
# Line 71 | 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 81 | 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 123 | Line 145 | namespace OpenMD {
145          painCave.severity = OPENMD_INFO;
146          simError();
147        }
126      fDecomp_->setUserCutoff(rCut_);
148      }
149  
150 +    fDecomp_->setUserCutoff(rCut_);
151 +    interactionMan_->setCutoffRadius(rCut_);
152 +
153      map<string, CutoffMethod> stringToCutoffMethod;
154      stringToCutoffMethod["HARD"] = HARD;
155      stringToCutoffMethod["SWITCHED"] = SWITCHED;
# Line 196 | Line 220 | namespace OpenMD {
220        simError();
221        cutoffPolicy_ = TRADITIONAL;        
222      }
199    fDecomp_->setCutoffPolicy(cutoffPolicy_);
200  }
223  
224 <  /**
225 <   * setupSwitching
204 <   *
205 <   * Sets the values of switchingRadius and
206 <   *  If the switchingRadius was explicitly set, use that value (but check it)
207 <   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
208 <   */
209 <  void ForceManager::setupSwitching() {
210 <    Globals* simParams_ = info_->getSimParams();
211 <
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 258 | 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 270 | 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
273
313        setupCutoffs();
275      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 333 | 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 351 | Line 391 | namespace OpenMD {
391          }
392        }      
393      }
394 <  
394 >    
395      // Zero out the stress tensor
396      tau *= 0.0;
397      
# Line 405 | 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 475 | Line 516 | namespace OpenMD {
516    }
517    
518    void ForceManager::longRangeInteractions() {
519 <    // some of this initial stuff will go away:
519 >
520      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
521      DataStorage* config = &(curSnapshot->atomData);
522      DataStorage* cgConfig = &(curSnapshot->cgData);
482    RealType* frc = config->getArrayPointer(DataStorage::dslForce);
483    RealType* pos = config->getArrayPointer(DataStorage::dslPosition);
484    RealType* trq = config->getArrayPointer(DataStorage::dslTorque);
485    RealType* A = config->getArrayPointer(DataStorage::dslAmat);
486    RealType* electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
487    RealType* particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
523  
524 <    // new stuff starts here:
525 <    
524 >    //calculate the center of mass of cutoff group
525 >
526 >    SimInfo::MoleculeIterator mi;
527 >    Molecule* mol;
528 >    Molecule::CutoffGroupIterator ci;
529 >    CutoffGroup* cg;
530 >
531 >    if(info_->getNCutoffGroups() > 0){      
532 >      for (mol = info_->beginMolecule(mi); mol != NULL;
533 >           mol = info_->nextMolecule(mi)) {
534 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
535 >            cg = mol->nextCutoffGroup(ci)) {
536 >          cg->updateCOM();
537 >        }
538 >      }      
539 >    } else {
540 >      // center of mass of the group is the same as position of the atom  
541 >      // if cutoff group does not exist
542 >      cgConfig->position = config->position;
543 >    }
544 >
545      fDecomp_->zeroWorkArrays();
546      fDecomp_->distributeData();
547      
# Line 496 | Line 550 | namespace OpenMD {
550      RealType rgrpsq, rgrp, r2, r;
551      RealType electroMult, vdwMult;
552      RealType vij;
553 <    Vector3d fij, fg;
553 >    Vector3d fij, fg, f1;
554      tuple3<RealType, RealType, RealType> cuts;
555      RealType rCutSq;
556      bool in_switching_region;
# Line 505 | Line 559 | namespace OpenMD {
559      InteractionData idat;
560      SelfData sdat;
561      RealType mf;
508    potVec pot(0.0);
509    potVec longRangePotential(0.0);
562      RealType lrPot;
563      RealType vpair;
564 +    potVec longRangePotential(0.0);
565 +    potVec workPot(0.0);
566  
567      int loopStart, loopEnd;
568  
569 +    idat.vdwMult = &vdwMult;
570 +    idat.electroMult = &electroMult;
571 +    idat.pot = &workPot;
572 +    sdat.pot = fDecomp_->getEmbeddingPotential();
573 +    idat.vpair = &vpair;
574 +    idat.f1 = &f1;
575 +    idat.sw = &sw;
576 +    idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
577 +    idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false;
578 +    
579      loopEnd = PAIR_LOOP;
580      if (info_->requiresPrepair() ) {
581        loopStart = PREPAIR_LOOP;
582      } else {
583        loopStart = PAIR_LOOP;
584      }
585 <    
522 <
585 >  
586      for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
587      
588        if (iLoop == loopStart) {
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 537 | 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();
542
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            
615            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
616                                                       rgrp);
554
555          idat.sw = &sw;
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 564 | Line 626 | namespace OpenMD {
626              for (vector<int>::iterator jb = atomListColumn.begin();
627                   jb != atomListColumn.end(); ++jb) {              
628                atom2 = (*jb);
629 <              
568 <              cerr << "doing atoms " << atom1 << " " << atom2 << "\n";
629 >
630                if (!fDecomp_->skipAtomPair(atom1, atom2)) {
570                
631                  vpair = 0.0;
632 +                workPot = 0.0;
633 +                f1 = V3Zero;
634  
635 <                cerr << "filling idat atoms " << atom1 << " " << atom2 << "\n";
574 <                idat = fDecomp_->fillInteractionData(atom1, atom2);
575 <                cerr << "done with idat\n";
635 >                fDecomp_->fillInteractionData(idat, atom1, atom2);
636                  
637                  topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
638                  vdwMult = vdwScale_[topoDist];
639                  electroMult = electrostaticScale_[topoDist];
640  
581                idat.vdwMult = &vdwMult;
582                idat.electroMult = &electroMult;
583                idat.pot = &pot;
584                idat.vpair = &vpair;
585
641                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
642                    idat.d = &d_grp;
643                    idat.r2 = &rgrpsq;
# Line 593 | Line 648 | namespace OpenMD {
648                    idat.d = &d;
649                    idat.r2 = &r2;
650                  }
651 <                
652 <                cerr << "d = " << d << "\n";
598 <                cerr << "r2 = " << r2 << "\n";
599 <                r = sqrt( r2 );
651 >              
652 >                r = sqrt( *(idat.r2) );
653                  idat.rij = &r;
654                
655                  if (iLoop == PREPAIR_LOOP) {
656                    interactionMan_->doPrePair(idat);
657                  } else {
605                  cerr << "doing doPair " << atom1 << " " << atom2 << " " << r << "\n";
658                    interactionMan_->doPair(idat);
659                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
660 <                  vij += *(idat.vpair);
661 <                  fij += *(idat.f1);
662 <                  tau -= outProduct( *(idat.d), *(idat.f1));
660 >
661 >                  vij += vpair;
662 >                  fij += f1;
663 >                  tau -= outProduct( *(idat.d), f1);
664                  }
665                }
666              }
# Line 617 | Line 670 | namespace OpenMD {
670              if (in_switching_region) {
671                swderiv = vij * dswdr / rgrp;
672                fg = swderiv * d_grp;
620
673                fij += fg;
674  
675                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
# Line 661 | 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 669 | 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 <            sdat = fDecomp_->fillSelfData(atom1);
729 >            fDecomp_->fillSelfData(sdat, atom1);
730              interactionMan_->doPreForce(sdat);
731            }
732  
733 <          fDecomp_->distributeIntermediateData();        
733 >          fDecomp_->distributeIntermediateData();
734 >
735          }
736        }
683
737      }
738      
739      fDecomp_->collectData();
687    
688    if ( info_->requiresSkipCorrection() ) {
689      
690      for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
691
692        vector<int> skipList = fDecomp_->getSkipsForAtom( atom1 );
740          
694        for (vector<int>::iterator jb = skipList.begin();
695             jb != skipList.end(); ++jb) {        
696    
697          atom2 = (*jb);
698          idat = fDecomp_->fillSkipData(atom1, atom2);
699          interactionMan_->doSkipCorrection(idat);
700
701        }
702      }
703    }
704    
741      if (info_->requiresSelfCorrection()) {
742  
743        for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
744 <        sdat = fDecomp_->fillSelfData(atom1);
744 >        fDecomp_->fillSelfData(sdat, atom1);
745          interactionMan_->doSelfCorrection(sdat);
746        }
747  
748      }
749  
750 <    longRangePotential = fDecomp_->getLongRangePotential();
750 >    longRangePotential = *(fDecomp_->getEmbeddingPotential()) +
751 >      *(fDecomp_->getPairwisePotential());
752 >
753      lrPot = longRangePotential.sum();
754  
755      //store the tau and long range potential    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines