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 1576 by gezelter, Wed Jun 8 16:05:07 2011 UTC vs.
Revision 1581 by gezelter, Mon Jun 13 22:13:12 2011 UTC

# Line 64 | Line 64 | namespace OpenMD {
64    
65    ForceManager::ForceManager(SimInfo * info) : info_(info) {
66      forceField_ = info_->getForceField();
67 <    fDecomp_ = new ForceMatrixDecomposition(info_);
67 >    interactionMan_ = new InteractionManager();
68 >    fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_);
69    }
70  
71    /**
# Line 121 | Line 122 | namespace OpenMD {
122          painCave.isFatal = 0;
123          painCave.severity = OPENMD_INFO;
124          simError();
125 <      }            
125 >      }
126 >      fDecomp_->setUserCutoff(rCut_);
127      }
128  
129      map<string, CutoffMethod> stringToCutoffMethod;
# Line 194 | Line 196 | namespace OpenMD {
196        simError();
197        cutoffPolicy_ = TRADITIONAL;        
198      }
199 +    fDecomp_->setCutoffPolicy(cutoffPolicy_);
200    }
201  
202    /**
# Line 205 | Line 208 | namespace OpenMD {
208     */
209    void ForceManager::setupSwitching() {
210      Globals* simParams_ = info_->getSimParams();
211 +
212 +    // create the switching function object:
213 +    switcher_ = new SwitchingFunction();
214      
215      if (simParams_->haveSwitchingRadius()) {
216        rSwitch_ = simParams_->getSwitchingRadius();
217        if (rSwitch_ > rCut_) {        
218          sprintf(painCave.errMsg,
219 <                "ForceManager::setupSwitching: switchingRadius (%f) is larger than cutoffRadius(%f)\n",
220 <                rSwitch_, rCut_);
219 >                "ForceManager::setupSwitching: switchingRadius (%f) is larger "
220 >                "than the cutoffRadius(%f)\n", rSwitch_, rCut_);
221          painCave.isFatal = 1;
222          painCave.severity = OPENMD_ERROR;
223          simError();
# Line 227 | Line 233 | namespace OpenMD {
233        simError();
234      }          
235      
236 +    // Default to cubic switching function.
237 +    sft_ = cubic;
238      if (simParams_->haveSwitchingFunctionType()) {
239        string funcType = simParams_->getSwitchingFunctionType();
240        toUpper(funcType);
# Line 468 | Line 476 | namespace OpenMD {
476    
477    void ForceManager::longRangeInteractions() {
478  
471    // some of this initial stuff will go away:
479      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
480      DataStorage* config = &(curSnapshot->atomData);
481      DataStorage* cgConfig = &(curSnapshot->cgData);
475    RealType* frc = config->getArrayPointer(DataStorage::dslForce);
476    RealType* pos = config->getArrayPointer(DataStorage::dslPosition);
477    RealType* trq = config->getArrayPointer(DataStorage::dslTorque);
478    RealType* A = config->getArrayPointer(DataStorage::dslAmat);
479    RealType* electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
480    RealType* particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
481    RealType* rc;    
482  
483 <    if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){
484 <      rc = cgConfig->getArrayPointer(DataStorage::dslPosition);
483 >    //calculate the center of mass of cutoff group
484 >
485 >    SimInfo::MoleculeIterator mi;
486 >    Molecule* mol;
487 >    Molecule::CutoffGroupIterator ci;
488 >    CutoffGroup* cg;
489 >
490 >    if(info_->getNCutoffGroups() > 0){      
491 >      for (mol = info_->beginMolecule(mi); mol != NULL;
492 >           mol = info_->nextMolecule(mi)) {
493 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
494 >            cg = mol->nextCutoffGroup(ci)) {
495 >          cg->updateCOM();
496 >        }
497 >      }      
498      } else {
499        // center of mass of the group is the same as position of the atom  
500        // if cutoff group does not exist
501 <      rc = pos;
501 >      cgConfig->position = config->position;
502      }
503 <    
491 <    // new stuff starts here:
503 >
504      fDecomp_->zeroWorkArrays();
505      fDecomp_->distributeData();
506 <
507 <    int cg1, cg2, atom1, atom2;
508 <    Vector3d d_grp, dag;
509 <    RealType rgrpsq, rgrp;
506 >    
507 >    int cg1, cg2, atom1, atom2, topoDist;
508 >    Vector3d d_grp, dag, d;
509 >    RealType rgrpsq, rgrp, r2, r;
510 >    RealType electroMult, vdwMult;
511      RealType vij;
512 <    Vector3d fij, fg;
512 >    Vector3d fij, fg, f1;
513      tuple3<RealType, RealType, RealType> cuts;
514      RealType rCutSq;
515      bool in_switching_region;
# Line 508 | Line 521 | namespace OpenMD {
521      potVec pot(0.0);
522      potVec longRangePotential(0.0);
523      RealType lrPot;
524 +    RealType vpair;
525  
526      int loopStart, loopEnd;
527 +
528 +    idat.vdwMult = &vdwMult;
529 +    idat.electroMult = &electroMult;
530 +    idat.pot = &pot;
531 +    idat.vpair = &vpair;
532 +    idat.f1 = &f1;
533 +    idat.sw = &sw;
534  
535      loopEnd = PAIR_LOOP;
536      if (info_->requiresPrepair() ) {
# Line 517 | Line 538 | namespace OpenMD {
538      } else {
539        loopStart = PAIR_LOOP;
540      }
541 <
542 <    for (int iLoop = loopStart; iLoop < loopEnd; iLoop++) {
543 <      
541 >    
542 >    for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
543 >    
544        if (iLoop == loopStart) {
545          bool update_nlist = fDecomp_->checkNeighborList();
546          if (update_nlist)
547            neighborList = fDecomp_->buildNeighborList();
548 <      }
549 <
548 >      }      
549 >        
550        for (vector<pair<int, int> >::iterator it = neighborList.begin();
551               it != neighborList.end(); ++it) {
552 <        
552 >                
553          cg1 = (*it).first;
554          cg2 = (*it).second;
555          
# Line 541 | Line 562 | namespace OpenMD {
562          rCutSq = cuts.second;
563  
564          if (rgrpsq < rCutSq) {
565 <          *(idat.rcut) = cuts.first;
565 >          idat.rcut = &cuts.first;
566            if (iLoop == PAIR_LOOP) {
567              vij *= 0.0;
568              fij = V3Zero;
569            }
570            
571 <          in_switching_region = switcher_->getSwitch(rgrpsq, *(idat.sw), dswdr,
571 >          in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
572                                                       rgrp);
573                
574            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
# Line 563 | Line 584 | namespace OpenMD {
584                
585                if (!fDecomp_->skipAtomPair(atom1, atom2)) {
586                  
587 <                pot *= 0.0;
587 >                vpair = 0.0;
588 >                f1 = V3Zero;
589  
590 <                idat = fDecomp_->fillInteractionData(atom1, atom2);
591 <                *(idat.pot) = pot;
590 >                fDecomp_->fillInteractionData(idat, atom1, atom2);
591 >                
592 >                topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
593 >                vdwMult = vdwScale_[topoDist];
594 >                electroMult = electrostaticScale_[topoDist];
595  
596                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
597 <                  *(idat.d) = d_grp;
598 <                  *(idat.r2) = rgrpsq;
597 >                  idat.d = &d_grp;
598 >                  idat.r2 = &rgrpsq;
599                  } else {
600 <                  *(idat.d) = fDecomp_->getInteratomicVector(atom1, atom2);
601 <                  curSnapshot->wrapVector( *(idat.d) );
602 <                  *(idat.r2) = idat.d->lengthSquare();
600 >                  d = fDecomp_->getInteratomicVector(atom1, atom2);
601 >                  curSnapshot->wrapVector( d );
602 >                  r2 = d.lengthSquare();
603 >                  idat.d = &d;
604 >                  idat.r2 = &r2;
605                  }
606                  
607 <                *(idat.rij) = sqrt( *(idat.r2) );
607 >                r = sqrt( *(idat.r2) );
608 >                idat.rij = &r;
609                
610                  if (iLoop == PREPAIR_LOOP) {
611                    interactionMan_->doPrePair(idat);
612                  } else {
613                    interactionMan_->doPair(idat);
614                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
615 <                  vij += *(idat.vpair);
616 <                  fij += *(idat.f1);
617 <                  tau -= outProduct( *(idat.d), *(idat.f1));
615 >                  vij += vpair;
616 >                  fij += f1;
617 >                  tau -= outProduct( *(idat.d), f1);
618                  }
619                }
620              }
# Line 652 | Line 680 | namespace OpenMD {
680            fDecomp_->collectIntermediateData();
681  
682            for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
683 <            sdat = fDecomp_->fillSelfData(atom1);
683 >            fDecomp_->fillSelfData(sdat, atom1);
684              interactionMan_->doPreForce(sdat);
685            }
686  
# Line 668 | Line 696 | namespace OpenMD {
696        
697        for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
698  
699 <        vector<int> skipList = fDecomp_->getSkipsForRowAtom( atom1 );
699 >        vector<int> skipList = fDecomp_->getSkipsForAtom( atom1 );
700          
701          for (vector<int>::iterator jb = skipList.begin();
702               jb != skipList.end(); ++jb) {        
703      
704            atom2 = (*jb);
705 <          idat = fDecomp_->fillSkipData(atom1, atom2);
705 >          fDecomp_->fillSkipData(idat, atom1, atom2);
706            interactionMan_->doSkipCorrection(idat);
707  
708          }
# Line 684 | Line 712 | namespace OpenMD {
712      if (info_->requiresSelfCorrection()) {
713  
714        for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
715 <        sdat = fDecomp_->fillSelfData(atom1);
715 >        fDecomp_->fillSelfData(sdat, atom1);
716          interactionMan_->doSelfCorrection(sdat);
717        }
718  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines