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 1587 by gezelter, Fri Jul 8 20:25:32 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 88 | Line 93 | namespace OpenMD {
93     * cutoffPolicy : (one of MIX, MAX, TRADITIONAL)
94     *      If cutoffPolicy was explicitly set, use that choice.
95     *      If cutoffPolicy was not explicitly set, use TRADITIONAL
96 +   *
97 +   * switchingRadius : realType
98 +   *  If the cutoffMethod was set to SWITCHED:
99 +   *      If the switchingRadius was explicitly set, use that value
100 +   *          (but do a sanity check first).
101 +   *      If the switchingRadius was not explicitly set: use 0.85 *
102 +   *      cutoffRadius_
103 +   *  If the cutoffMethod was not set to SWITCHED:
104 +   *      Set switchingRadius equal to cutoffRadius for safety.
105     */
106    void ForceManager::setupCutoffs() {
107      
# Line 122 | Line 136 | namespace OpenMD {
136          painCave.isFatal = 0;
137          painCave.severity = OPENMD_INFO;
138          simError();
139 <      }            
139 >      }
140      }
141  
142 +    fDecomp_->setUserCutoff(rCut_);
143 +    interactionMan_->setCutoffRadius(rCut_);
144 +
145      map<string, CutoffMethod> stringToCutoffMethod;
146      stringToCutoffMethod["HARD"] = HARD;
147      stringToCutoffMethod["SWITCHED"] = SWITCHED;
# Line 195 | Line 212 | namespace OpenMD {
212        simError();
213        cutoffPolicy_ = TRADITIONAL;        
214      }
198  }
215  
216 <  /**
217 <   * 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 <
216 >    fDecomp_->setCutoffPolicy(cutoffPolicy_);
217 >        
218      // create the switching function object:
219 +
220      switcher_ = new SwitchingFunction();
221 <    
222 <    if (simParams_->haveSwitchingRadius()) {
223 <      rSwitch_ = simParams_->getSwitchingRadius();
224 <      if (rSwitch_ > rCut_) {        
221 >  
222 >    if (cutoffMethod_ == SWITCHED) {
223 >      if (simParams_->haveSwitchingRadius()) {
224 >        rSwitch_ = simParams_->getSwitchingRadius();
225 >        if (rSwitch_ > rCut_) {        
226 >          sprintf(painCave.errMsg,
227 >                  "ForceManager::setupCutoffs: switchingRadius (%f) is larger "
228 >                  "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
229 >          painCave.isFatal = 1;
230 >          painCave.severity = OPENMD_ERROR;
231 >          simError();
232 >        }
233 >      } else {      
234 >        rSwitch_ = 0.85 * rCut_;
235          sprintf(painCave.errMsg,
236 <                "ForceManager::setupSwitching: switchingRadius (%f) is larger "
237 <                "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
238 <        painCave.isFatal = 1;
239 <        painCave.severity = OPENMD_ERROR;
236 >                "ForceManager::setupCutoffs: No value was set for the switchingRadius.\n"
237 >                "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
238 >                "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
239 >        painCave.isFatal = 0;
240 >        painCave.severity = OPENMD_WARNING;
241          simError();
242        }
243 <    } else {      
244 <      rSwitch_ = 0.85 * rCut_;
245 <      sprintf(painCave.errMsg,
246 <              "ForceManager::setupSwitching: No value was set for the switchingRadius.\n"
247 <              "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
248 <              "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
249 <      painCave.isFatal = 0;
250 <      painCave.severity = OPENMD_WARNING;
251 <      simError();
252 <    }          
243 >    } else {
244 >      if (simParams_->haveSwitchingRadius()) {
245 >        map<string, CutoffMethod>::const_iterator it;
246 >        string theMeth;
247 >        for (it = stringToCutoffMethod.begin();
248 >             it != stringToCutoffMethod.end(); ++it) {
249 >          if (it->second == cutoffMethod_) {
250 >            theMeth = it->first;
251 >            break;
252 >          }
253 >        }
254 >        sprintf(painCave.errMsg,
255 >                "ForceManager::setupCutoffs: the cutoffMethod (%s)\n"
256 >                "\tis not set to SWITCHED, so switchingRadius value\n"
257 >                "\twill be ignored for this simulation\n", theMeth.c_str());
258 >        painCave.isFatal = 0;
259 >        painCave.severity = OPENMD_WARNING;
260 >        simError();
261 >      }
262 >
263 >      rSwitch_ = rCut_;
264 >    }
265      
266      // Default to cubic switching function.
267      sft_ = cubic;
# Line 256 | Line 288 | namespace OpenMD {
288      }
289      switcher_->setSwitchType(sft_);
290      switcher_->setSwitch(rSwitch_, rCut_);
291 +    interactionMan_->setSwitchingRadius(rSwitch_);
292    }
293    
294    void ForceManager::initialize() {
# Line 270 | Line 303 | namespace OpenMD {
303        // query them for suggested cutoff values
304  
305        setupCutoffs();
273      setupSwitching();
306  
307        info_->prepareTopology();      
308      }
# Line 474 | Line 506 | namespace OpenMD {
506    
507    void ForceManager::longRangeInteractions() {
508  
477    // some of this initial stuff will go away:
509      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
510      DataStorage* config = &(curSnapshot->atomData);
511      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;    
512  
513 <    if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){
514 <      rc = cgConfig->getArrayPointer(DataStorage::dslPosition);
513 >    //calculate the center of mass of cutoff group
514 >
515 >    SimInfo::MoleculeIterator mi;
516 >    Molecule* mol;
517 >    Molecule::CutoffGroupIterator ci;
518 >    CutoffGroup* cg;
519 >
520 >    if(info_->getNCutoffGroups() > 0){      
521 >      for (mol = info_->beginMolecule(mi); mol != NULL;
522 >           mol = info_->nextMolecule(mi)) {
523 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
524 >            cg = mol->nextCutoffGroup(ci)) {
525 >          cg->updateCOM();
526 >        }
527 >      }      
528      } else {
529        // center of mass of the group is the same as position of the atom  
530        // if cutoff group does not exist
531 <      rc = pos;
531 >      cgConfig->position = config->position;
532      }
533 <    
497 <    // new stuff starts here:
533 >
534      fDecomp_->zeroWorkArrays();
535      fDecomp_->distributeData();
536 <
537 <    int cg1, cg2, atom1, atom2;
538 <    Vector3d d_grp, dag;
539 <    RealType rgrpsq, rgrp;
536 >    
537 >    int cg1, cg2, atom1, atom2, topoDist;
538 >    Vector3d d_grp, dag, d;
539 >    RealType rgrpsq, rgrp, r2, r;
540 >    RealType electroMult, vdwMult;
541      RealType vij;
542 <    Vector3d fij, fg;
542 >    Vector3d fij, fg, f1;
543      tuple3<RealType, RealType, RealType> cuts;
544      RealType rCutSq;
545      bool in_switching_region;
# Line 511 | Line 548 | namespace OpenMD {
548      InteractionData idat;
549      SelfData sdat;
550      RealType mf;
514    potVec pot(0.0);
515    potVec longRangePotential(0.0);
551      RealType lrPot;
552 +    RealType vpair;
553 +    potVec longRangePotential(0.0);
554 +    potVec workPot(0.0);
555  
556      int loopStart, loopEnd;
557  
558 +    idat.vdwMult = &vdwMult;
559 +    idat.electroMult = &electroMult;
560 +    idat.pot = &workPot;
561 +    sdat.pot = fDecomp_->getEmbeddingPotential();
562 +    idat.vpair = &vpair;
563 +    idat.f1 = &f1;
564 +    idat.sw = &sw;
565 +    idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
566 +    idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false;
567 +    
568      loopEnd = PAIR_LOOP;
569      if (info_->requiresPrepair() ) {
570        loopStart = PREPAIR_LOOP;
571      } else {
572        loopStart = PAIR_LOOP;
573      }
574 <
575 <    for (int iLoop = loopStart; iLoop < loopEnd; iLoop++) {
576 <      
574 >  
575 >    for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
576 >    
577        if (iLoop == loopStart) {
578          bool update_nlist = fDecomp_->checkNeighborList();
579          if (update_nlist)
580            neighborList = fDecomp_->buildNeighborList();
581 <      }
582 <
581 >      }      
582 >        
583        for (vector<pair<int, int> >::iterator it = neighborList.begin();
584               it != neighborList.end(); ++it) {
585 <        
585 >                
586          cg1 = (*it).first;
587          cg2 = (*it).second;
588          
# Line 547 | Line 595 | namespace OpenMD {
595          rCutSq = cuts.second;
596  
597          if (rgrpsq < rCutSq) {
598 <          *(idat.rcut) = cuts.first;
598 >          idat.rcut = &cuts.first;
599            if (iLoop == PAIR_LOOP) {
600 <            vij *= 0.0;
600 >            vij = 0.0;
601              fij = V3Zero;
602            }
603            
604 <          in_switching_region = switcher_->getSwitch(rgrpsq, *(idat.sw), dswdr,
604 >          in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
605                                                       rgrp);
606                
607            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
# Line 566 | Line 614 | namespace OpenMD {
614              for (vector<int>::iterator jb = atomListColumn.begin();
615                   jb != atomListColumn.end(); ++jb) {              
616                atom2 = (*jb);
617 <              
617 >            
618                if (!fDecomp_->skipAtomPair(atom1, atom2)) {
619 +                vpair = 0.0;
620 +                workPot = 0.0;
621 +                f1 = V3Zero;
622 +
623 +                fDecomp_->fillInteractionData(idat, atom1, atom2);
624                  
625 <                pot *= 0.0;
625 >                topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
626 >                vdwMult = vdwScale_[topoDist];
627 >                electroMult = electrostaticScale_[topoDist];
628  
574                idat = fDecomp_->fillInteractionData(atom1, atom2);
575                *(idat.pot) = pot;
576
629                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
630 <                  *(idat.d) = d_grp;
631 <                  *(idat.r2) = rgrpsq;
630 >                  idat.d = &d_grp;
631 >                  idat.r2 = &rgrpsq;
632                  } else {
633 <                  *(idat.d) = fDecomp_->getInteratomicVector(atom1, atom2);
634 <                  curSnapshot->wrapVector( *(idat.d) );
635 <                  *(idat.r2) = idat.d->lengthSquare();
633 >                  d = fDecomp_->getInteratomicVector(atom1, atom2);
634 >                  curSnapshot->wrapVector( d );
635 >                  r2 = d.lengthSquare();
636 >                  idat.d = &d;
637 >                  idat.r2 = &r2;
638                  }
639                  
640 <                *(idat.rij) = sqrt( *(idat.r2) );
640 >                r = sqrt( *(idat.r2) );
641 >                idat.rij = &r;
642                
643                  if (iLoop == PREPAIR_LOOP) {
644                    interactionMan_->doPrePair(idat);
645                  } else {
646                    interactionMan_->doPair(idat);
647                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
648 <                  vij += *(idat.vpair);
649 <                  fij += *(idat.f1);
650 <                  tau -= outProduct( *(idat.d), *(idat.f1));
648 >                  vij += vpair;
649 >                  fij += f1;
650 >                  tau -= outProduct( *(idat.d), f1);
651                  }
652                }
653              }
# Line 602 | Line 657 | namespace OpenMD {
657              if (in_switching_region) {
658                swderiv = vij * dswdr / rgrp;
659                fg = swderiv * d_grp;
605
660                fij += fg;
661  
662                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
# Line 658 | Line 712 | namespace OpenMD {
712            fDecomp_->collectIntermediateData();
713  
714            for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
715 <            sdat = fDecomp_->fillSelfData(atom1);
715 >            fDecomp_->fillSelfData(sdat, atom1);
716              interactionMan_->doPreForce(sdat);
717            }
718 <
718 >          
719 >          
720            fDecomp_->distributeIntermediateData();        
721          }
722        }
# Line 669 | Line 724 | namespace OpenMD {
724      }
725      
726      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 );
727          
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    
728      if (info_->requiresSelfCorrection()) {
729  
730        for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
731 <        sdat = fDecomp_->fillSelfData(atom1);
731 >        fDecomp_->fillSelfData(sdat, atom1);
732          interactionMan_->doSelfCorrection(sdat);
733        }
734  
735      }
736  
737 <    longRangePotential = fDecomp_->getLongRangePotential();
737 >    longRangePotential = *(fDecomp_->getEmbeddingPotential()) +
738 >      *(fDecomp_->getPairwisePotential());
739 >
740      lrPot = longRangePotential.sum();
741  
742      //store the tau and long range potential    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines