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 1577 by gezelter, Wed Jun 8 20:26:56 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    
69    ForceManager::ForceManager(SimInfo * info) : info_(info) {
70      forceField_ = info_->getForceField();
67    fDecomp_ = new ForceMatrixDecomposition(info_);
71      interactionMan_ = new InteractionManager();
72 +    fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_);
73    }
74  
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 122 | Line 144 | namespace OpenMD {
144          painCave.isFatal = 0;
145          painCave.severity = OPENMD_INFO;
146          simError();
147 <      }            
147 >      }
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 195 | Line 220 | namespace OpenMD {
220        simError();
221        cutoffPolicy_ = TRADITIONAL;        
222      }
198  }
223  
224 <  /**
225 <   * setupSwitching
202 <   *
203 <   * Sets the values of switchingRadius and
204 <   *  If the switchingRadius was explicitly set, use that value (but check it)
205 <   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
206 <   */
207 <  void ForceManager::setupSwitching() {
208 <    Globals* simParams_ = info_->getSimParams();
209 <
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 256 | 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 268 | 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
271
313        setupCutoffs();
273      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 331 | 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 349 | Line 391 | namespace OpenMD {
391          }
392        }      
393      }
394 <  
394 >    
395      // Zero out the stress tensor
396      tau *= 0.0;
397      
# Line 403 | 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 474 | Line 517 | namespace OpenMD {
517    
518    void ForceManager::longRangeInteractions() {
519  
477    // some of this initial stuff will go away:
520      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
521      DataStorage* config = &(curSnapshot->atomData);
522      DataStorage* cgConfig = &(curSnapshot->cgData);
481    RealType* frc = config->getArrayPointer(DataStorage::dslForce);
482    RealType* pos = config->getArrayPointer(DataStorage::dslPosition);
483    RealType* trq = config->getArrayPointer(DataStorage::dslTorque);
484    RealType* A = config->getArrayPointer(DataStorage::dslAmat);
485    RealType* electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
486    RealType* particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
487    RealType* rc;    
523  
524 <    if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){
525 <      rc = cgConfig->getArrayPointer(DataStorage::dslPosition);
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 <      rc = pos;
542 >      cgConfig->position = config->position;
543      }
544 <    
497 <    // new stuff starts here:
544 >
545      fDecomp_->zeroWorkArrays();
546      fDecomp_->distributeData();
547 <
548 <    int cg1, cg2, atom1, atom2;
549 <    Vector3d d_grp, dag;
550 <    RealType rgrpsq, rgrp;
547 >    
548 >    int cg1, cg2, atom1, atom2, topoDist;
549 >    Vector3d d_grp, dag, d;
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 511 | Line 559 | namespace OpenMD {
559      InteractionData idat;
560      SelfData sdat;
561      RealType mf;
514    potVec pot(0.0);
515    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 <
586 <    for (int iLoop = loopStart; iLoop < loopEnd; iLoop++) {
587 <      
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 <      }
592 >      }            
593  
594        for (vector<pair<int, int> >::iterator it = neighborList.begin();
595               it != neighborList.end(); ++it) {
596 <        
596 >                
597          cg1 = (*it).first;
598          cg2 = (*it).second;
599          
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();
546
606          rCutSq = cuts.second;
607  
608          if (rgrpsq < rCutSq) {
609 <          *(idat.rcut) = cuts.first;
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, *(idat.sw), dswdr,
615 >          in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
616                                                       rgrp);
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 566 | 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;
633 +                f1 = V3Zero;
634 +
635 +                fDecomp_->fillInteractionData(idat, atom1, atom2);
636                  
637 <                pot *= 0.0;
637 >                topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
638 >                vdwMult = vdwScale_[topoDist];
639 >                electroMult = electrostaticScale_[topoDist];
640  
574                idat = fDecomp_->fillInteractionData(atom1, atom2);
575                *(idat.pot) = pot;
576
641                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
642 <                  *(idat.d) = d_grp;
643 <                  *(idat.r2) = rgrpsq;
642 >                  idat.d = &d_grp;
643 >                  idat.r2 = &rgrpsq;
644                  } else {
645 <                  *(idat.d) = fDecomp_->getInteratomicVector(atom1, atom2);
646 <                  curSnapshot->wrapVector( *(idat.d) );
647 <                  *(idat.r2) = idat.d->lengthSquare();
645 >                  d = fDecomp_->getInteratomicVector(atom1, atom2);
646 >                  curSnapshot->wrapVector( d );
647 >                  r2 = d.lengthSquare();
648 >                  idat.d = &d;
649 >                  idat.r2 = &r2;
650                  }
585                
586                *(idat.rij) = sqrt( *(idat.r2) );
651                
652 +                r = sqrt( *(idat.r2) );
653 +                idat.rij = &r;
654 +              
655                  if (iLoop == PREPAIR_LOOP) {
656                    interactionMan_->doPrePair(idat);
657                  } else {
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 602 | Line 670 | namespace OpenMD {
670              if (in_switching_region) {
671                swderiv = vij * dswdr / rgrp;
672                fg = swderiv * d_grp;
605
673                fij += fg;
674  
675                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
# Line 646 | 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 654 | 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        }
668
737      }
738      
739      fDecomp_->collectData();
672    
673    if ( info_->requiresSkipCorrection() ) {
674      
675      for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
676
677        vector<int> skipList = fDecomp_->getSkipsForRowAtom( atom1 );
740          
679        for (vector<int>::iterator jb = skipList.begin();
680             jb != skipList.end(); ++jb) {        
681    
682          atom2 = (*jb);
683          idat = fDecomp_->fillSkipData(atom1, atom2);
684          interactionMan_->doSkipCorrection(idat);
685
686        }
687      }
688    }
689    
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