ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/InteractionManager.cpp
(Generate patch)

Comparing branches/development/src/nonbonded/InteractionManager.cpp (file contents):
Revision 1504 by gezelter, Sat Oct 2 20:41:53 2010 UTC vs.
Revision 1532 by gezelter, Wed Dec 29 19:59:21 2010 UTC

# Line 44 | Line 44 | namespace OpenMD {
44   namespace OpenMD {
45  
46    bool InteractionManager::initialized_ = false;
47 +  RealType InteractionManager::rCut_ = -1.0;
48 +  RealType InteractionManager::rSwitch_ = -1.0;
49    ForceField* InteractionManager::forceField_ = NULL;  
50    InteractionManager* InteractionManager::_instance = NULL;
51    map<int, AtomType*> InteractionManager::typeMap_;
52    map<pair<AtomType*, AtomType*>, set<NonBondedInteraction*> > InteractionManager::interactions_;
53 +
54 +  LJ* InteractionManager::lj_ = new LJ();
55 +  GB* InteractionManager::gb_ = new GB();
56 +  Sticky* InteractionManager::sticky_ = new Sticky();
57 +  Morse* InteractionManager::morse_ = new Morse();
58 +  EAM* InteractionManager::eam_ = new EAM();
59 +  SC* InteractionManager::sc_ = new SC();
60 +  Electrostatic* InteractionManager::electrostatic_ = new Electrostatic();
61 +  MAW* InteractionManager::maw_ = new MAW();
62 +  SwitchingFunction* InteractionManager::switcher_ = new SwitchingFunction();
63  
64    InteractionManager* InteractionManager::Instance() {
65      if (!_instance) {
# Line 58 | Line 70 | namespace OpenMD {
70  
71    void InteractionManager::initialize() {
72      
61    lj_ = new LJ();
62    gb_ = new GB();
63    sticky_ = new Sticky();
64    eam_ = new EAM();
65    sc_ = new SC();
66    morse_ = new Morse();
67    electrostatic_ = new Electrostatic();
68
73      lj_->setForceField(forceField_);
74      gb_->setForceField(forceField_);
75      sticky_->setForceField(forceField_);
# Line 73 | Line 77 | namespace OpenMD {
77      sc_->setForceField(forceField_);
78      morse_->setForceField(forceField_);
79      electrostatic_->setForceField(forceField_);
80 +    maw_->setForceField(forceField_);
81  
82 +    ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
83 +    // Force fields can set options on how to scale van der Waals and electrostatic
84 +    // interactions for atoms connected via bonds, bends and torsions
85 +    // in this case the topological distance between atoms is:
86 +    // 0 = the atom itself
87 +    // 1 = bonded together
88 +    // 2 = connected via a bend
89 +    // 3 = connected via a torsion
90 +
91 +    vdwScale_[0] = 0.0;
92 +    vdwScale_[1] = fopts.getvdw12scale();
93 +    vdwScale_[2] = fopts.getvdw13scale();
94 +    vdwScale_[3] = fopts.getvdw14scale();
95 +
96 +    electrostaticScale_[0] = 0.0;
97 +    electrostaticScale_[1] = fopts.getelectrostatic12scale();
98 +    electrostaticScale_[2] = fopts.getelectrostatic13scale();
99 +    electrostaticScale_[3] = fopts.getelectrostatic14scale();
100 +
101      ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
102      ForceField::AtomTypeContainer::MapTypeIterator i1, i2;
103      AtomType* atype1;
# Line 209 | Line 233 | namespace OpenMD {
233            interactions_[key].insert(sc_);
234            metExplicit = true;
235          }
236 +
237 +        if (nbiType->isMAW()) {
238 +          if (vdwExplicit) {
239 +            sprintf( painCave.errMsg,
240 +                     "InteractionManager::initialize found more than one explicit\n"
241 +                     "\tvan der Waals interaction for atom types %s - %s\n",
242 +                     atype1->getName().c_str(), atype2->getName().c_str());
243 +            painCave.severity = OPENMD_ERROR;
244 +            painCave.isFatal = 1;
245 +            simError();
246 +          }
247 +          // We found an explicit MAW interaction.  
248 +          // override all other vdw entries for this pair of atom types:
249 +          set<NonBondedInteraction*>::iterator it;
250 +          for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) {
251 +            InteractionFamily ifam = (*it)->getFamily();
252 +            if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
253 +          }
254 +          interactions_[key].insert(maw_);
255 +          vdwExplicit = true;
256 +        }        
257        }
258      }
259      
# Line 232 | Line 277 | namespace OpenMD {
277      }
278    }
279    
280 <  void InteractionManager::do_prepair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){
280 >  void InteractionManager::doPrePair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){
281      
282      if (!initialized_) initialize();
283            
# Line 256 | Line 301 | namespace OpenMD {
301      return;    
302    }
303    
304 <  void InteractionManager::do_preforce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
304 >  void InteractionManager::doPreForce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
305  
306      if (!initialized_) initialize();
307            
# Line 279 | Line 324 | namespace OpenMD {
324      return;    
325    }
326  
327 <  void InteractionManager::do_pair(int *atid1, int *atid2, RealType *d, RealType *r, RealType *r2, RealType *rcut, RealType *sw, RealType *vdwMult,RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2, RealType *t1, RealType *t2, RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2, RealType *fshift1, RealType *fshift2){
327 >  void InteractionManager::doPair(int *atid1, int *atid2, RealType *d, RealType *r, RealType *r2, RealType *rcut, RealType *sw, int *topoDist, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2, RealType *t1, RealType *t2, RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2, RealType *fshift1, RealType *fshift2){
328      
329      if (!initialized_) initialize();
330      
# Line 292 | Line 337 | namespace OpenMD {
337      idat.r2 = *r2;
338      idat.rcut = *rcut;
339      idat.sw = *sw;
340 <    idat.vdwMult = *vdwMult;
341 <    idat.electroMult = *electroMult;
340 >    idat.vdwMult = vdwScale_[*topoDist];
341 >    idat.electroMult = electrostaticScale_[*topoDist];
342      idat.pot = *pot;
343      idat.vpair = *vpair;
344      idat.f1 = Vector3d(f1);
# Line 331 | Line 376 | namespace OpenMD {
376      return;    
377    }
378  
379 <  void InteractionManager::do_skip_correction(int *atid1, int *atid2, RealType *d, RealType *r, RealType *skippedCharge1, RealType *skippedCharge2, RealType *sw, RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *t1, RealType *t2){
379 >  void InteractionManager::doSkipCorrection(int *atid1, int *atid2, RealType *d, RealType *r, RealType *skippedCharge1, RealType *skippedCharge2, RealType *sw, RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *t1, RealType *t2){
380  
381      if (!initialized_) initialize();
382      
# Line 377 | Line 422 | namespace OpenMD {
422      return;    
423    }
424  
425 <  void InteractionManager::do_self_correction(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
425 >  void InteractionManager::doSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
426  
427      if (!initialized_) initialize();
428      
# Line 403 | Line 448 | namespace OpenMD {
448      t[2] = scdat.t.z();
449  
450      return;    
451 +  }
452 +
453 +
454 +  RealType InteractionManager::getSuggestedCutoffRadius(int *atid) {
455 +    if (!initialized_) initialize();
456 +    
457 +    AtomType* atype = typeMap_[*atid];
458 +
459 +    pair<AtomType*, AtomType*> key = make_pair(atype, atype);
460 +    set<NonBondedInteraction*>::iterator it;
461 +    RealType cutoff = 0.0;
462 +    
463 +    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
464 +      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype));  
465 +    return cutoff;    
466 +  }
467 +
468 +  RealType InteractionManager::getSuggestedCutoffRadius(AtomType* atype) {
469 +    if (!initialized_) initialize();
470 +    
471 +    pair<AtomType*, AtomType*> key = make_pair(atype, atype);
472 +    set<NonBondedInteraction*>::iterator it;
473 +    RealType cutoff = 0.0;
474 +    
475 +    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
476 +      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype));  
477 +    return cutoff;    
478 +  }
479 +
480 +
481 +  void InteractionManager::setSwitch(RealType *rIn, RealType *rOut) {
482 +    switcher_->setSwitch(*rIn, *rOut);    
483    }
484  
485 +  void InteractionManager::getSwitch(RealType *r2, RealType *sw, RealType *dswdr, RealType *r,
486 +                                     int *in_switching_region) {
487 +    bool isr = switcher_->getSwitch(*r2, *sw, *dswdr, *r);    
488 +    *in_switching_region = (int)isr;
489 +  }
490 +
491   } //end namespace OpenMD
492  
493   extern "C" {
# Line 415 | Line 498 | extern "C" {
498   #define fortranDoSkipCorrection FC_FUNC(do_skip_correction, DO_SKIP_CORRECTION)
499   #define fortranDoSelfCorrection FC_FUNC(do_self_correction, DO_SELF_CORRECTION)
500   #define fortranGetCutoff FC_FUNC(get_cutoff, GET_CUTOFF)
501 + #define fortranSetSwitch FC_FUNC(set_switch, SET_SWITCH)
502 + #define fortranGetSwitch FC_FUNC(get_switch, GET_SWITCH)
503  
504    void fortranDoPrePair(int *atid1, int *atid2, RealType *rij,
505                          RealType *rho_i_at_j, RealType *rho_j_at_i) {
506              
507 <    return OpenMD::InteractionManager::Instance()->do_prepair(atid1, atid2, rij,
508 <                                                              rho_i_at_j,  
509 <                                                              rho_j_at_i);
507 >    return OpenMD::InteractionManager::Instance()->doPrePair(atid1, atid2, rij,
508 >                                                             rho_i_at_j,  
509 >                                                             rho_j_at_i);
510    }
511 <  void fortranDoPreforce(int *atid, RealType *rho, RealType *frho,
511 >  void fortranDoPreForce(int *atid, RealType *rho, RealType *frho,
512                           RealType *dfrhodrho) {  
513      
514 <    return OpenMD::InteractionManager::Instance()->do_preforce(atid, rho, frho,
515 <                                                               dfrhodrho);    
514 >    return OpenMD::InteractionManager::Instance()->doPreForce(atid, rho, frho,
515 >                                                              dfrhodrho);    
516    }
517    
518    void fortranDoPair(int *atid1, int *atid2, RealType *d, RealType *r,
519 <                     RealType *r2, RealType *rcut, RealType *sw,
520 <                     RealType *vdwMult, RealType *electroMult, RealType *pot,
436 <                     RealType *vpair, RealType *f1, RealType *eFrame1,
519 >                     RealType *r2, RealType *rcut, RealType *sw, int *topoDist,
520 >                     RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1,
521                       RealType *eFrame2, RealType *A1, RealType *A2,
522                       RealType *t1, RealType *t2, RealType *rho1, RealType *rho2,
523                       RealType *dfrho1, RealType *dfrho2, RealType *fshift1,
524                       RealType *fshift2){
525      
526 <    return OpenMD::InteractionManager::Instance()->do_pair(atid1, atid2, d, r, r2, rcut,
527 <                                                           sw, vdwMult, electroMult, pot,
528 <                                                           vpair, f1, eFrame1, eFrame2,
529 <                                                           A1, A2, t1, t2, rho1, rho2,
530 <                                                           dfrho1, dfrho2, fshift1, fshift2);
526 >    return OpenMD::InteractionManager::Instance()->doPair(atid1, atid2, d, r,
527 >                                                          r2, rcut, sw, topoDist,
528 >                                                          pot, vpair, f1,
529 >                                                          eFrame1, eFrame2,
530 >                                                          A1, A2, t1, t2, rho1,
531 >                                                          rho2, dfrho1, dfrho2,
532 >                                                          fshift1, fshift2);
533    }
534 <
535 <  void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d, RealType *r,
536 <                               RealType *skippedCharge1, RealType *skippedCharge2,
537 <                               RealType *sw, RealType *electroMult, RealType *pot,
534 >  
535 >  void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d,
536 >                               RealType *r, RealType *skippedCharge1,
537 >                               RealType *skippedCharge2, RealType *sw,
538 >                               RealType *electroMult, RealType *pot,
539                                 RealType *vpair, RealType *f1,
540                                 RealType *eFrame1, RealType *eFrame2,
541                                 RealType *t1, RealType *t2){
542      
543 <    return OpenMD::InteractionManager::Instance()->do_skip_correction(atid1, atid2, d, r,
544 <                                                                      skippedCharge1,
545 <                                                                      skippedCharge2,
546 <                                                                      sw, electroMult, pot,
547 <                                                                      vpair, f1, eFrame1,
548 <                                                                      eFrame2, t1, t2);
543 >    return OpenMD::InteractionManager::Instance()->doSkipCorrection(atid1,
544 >                                                                    atid2, d,
545 >                                                                    r,
546 >                                                                    skippedCharge1,
547 >                                                                    skippedCharge2,
548 >                                                                    sw, electroMult, pot,
549 >                                                                    vpair, f1, eFrame1,
550 >                                                                    eFrame2, t1, t2);
551    }
552 <
552 >  
553    void fortranDoSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge,
554                                 RealType *pot, RealType *t) {
555      
556 <    return OpenMD::InteractionManager::Instance()->do_self_correction(atid, eFrame,
557 <                                                                      skippedCharge,
558 <                                                                      pot, t);
556 >    return OpenMD::InteractionManager::Instance()->doSelfCorrection(atid,
557 >                                                                    eFrame,
558 >                                                                    skippedCharge,
559 >                                                                    pot, t);
560    }
561 <  RealType fortranGetCutoff() {
562 <    return OpenMD::InteractionManager::Instance()->getCutoff();
561 >  RealType fortranGetCutoff(int *atid) {    
562 >    return OpenMD::InteractionManager::Instance()->getSuggestedCutoffRadius(atid);
563    }
564 +
565 +  void fortranGetSwitch(RealType *r2, RealType *sw, RealType *dswdr, RealType *r,
566 +                        int *in_switching_region) {
567 +    
568 +    return OpenMD::InteractionManager::Instance()->getSwitch(r2, sw, dswdr, r,
569 +                                                             in_switching_region);
570 +  }
571 +
572 +  void fortranSetSwitch(RealType *rIn, RealType *rOut) {    
573 +    return OpenMD::InteractionManager::Instance()->setSwitch(rIn, rOut);
574 +  }
575 +  
576   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines