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 1502 by gezelter, Sat Oct 2 19:53:32 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 231 | Line 276 | namespace OpenMD {
276        }
277      }
278    }
234
235
236  void InteractionManager::doPrePair(AtomType* atype1,
237                                     AtomType* atype2,
238                                     RealType rij,
239                                     RealType &rho_i_at_j,
240                                     RealType &rho_j_at_i) {
241    
242  }
279    
280 <  void InteractionManager::doPreForce(AtomType* atype,
245 <                                      RealType rho,      
246 <                                      RealType &frho,
247 <                                      RealType &dfrhodrho) {
248 <  }
249 <
250 <  void InteractionManager::doSkipCorrection(AtomType* atype1,      
251 <                                            AtomType* atype2,
252 <                                            Vector3d d,
253 <                                            RealType rij,
254 <                                            RealType &skippedCharge1,
255 <                                            RealType &skippedCharge2,
256 <                                            RealType sw,
257 <                                            RealType electroMult,
258 <                                            RealType &pot,
259 <                                            RealType &vpair,
260 <                                            Vector3d &f1,
261 <                                            Mat3x3d eFrame1,
262 <                                            Mat3x3d eFrame2,
263 <                                            Vector3d &t1,
264 <                                            Vector3d &t2) {
265 <  }
266 <  
267 <  void InteractionManager::doSelfCorrection(AtomType* atype,
268 <                                            Mat3x3d eFrame,
269 <                                            RealType skippedCharge,
270 <                                            RealType &pot,
271 <                                            Vector3d &t) {
272 <  }
273 <
274 <  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 <    AtomType* atype1 = typeMap_[*atid1];
284 <    AtomType* atype2 = typeMap_[*atid2];
285 <    
286 <    doPrePair(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i);
283 >          
284 >    DensityData ddat;
285 >
286 >    ddat.atype1 = typeMap_[*atid1];
287 >    ddat.atype2 = typeMap_[*atid2];
288 >    ddat.rij = *rij;
289 >    ddat.rho_i_at_j = *rho_i_at_j;
290 >    ddat.rho_j_at_i = *rho_j_at_i;
291 >
292 >    pair<AtomType*, AtomType*> key = make_pair(ddat.atype1, ddat.atype2);
293 >    set<NonBondedInteraction*>::iterator it;
294 >
295 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
296 >      if ((*it)->getFamily() == METALLIC_FAMILY) {
297 >        dynamic_cast<MetallicInteraction*>(*it)->calcDensity(ddat);
298 >      }
299 >    }
300      
301      return;    
302    }
303 +  
304 +  void InteractionManager::doPreForce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
305  
306 <  void InteractionManager::do_preforce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
306 >    if (!initialized_) initialize();
307 >          
308 >    FunctionalData fdat;
309  
310 <    if (!initialized_) initialize();    
311 <    AtomType* atype = typeMap_[*atid];
310 >    fdat.atype = typeMap_[*atid];
311 >    fdat.rho = *rho;
312 >    fdat.frho = *frho;
313 >    fdat.dfrhodrho = *dfrhodrho;
314  
315 <    doPreForce(atype, *rho, *frho, *dfrhodrho);
315 >    pair<AtomType*, AtomType*> key = make_pair(fdat.atype, fdat.atype);
316 >    set<NonBondedInteraction*>::iterator it;
317      
318 +    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
319 +      if ((*it)->getFamily() == METALLIC_FAMILY) {
320 +        dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(fdat);
321 +      }
322 +    }
323 +    
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){
328 <
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 <          
330 >    
331      InteractionData idat;
332 <
332 >    
333      idat.atype1 = typeMap_[*atid1];
334      idat.atype2 = typeMap_[*atid2];
335      idat.d = Vector3d(d);
# Line 305 | 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 344 | 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();
350          
351    AtomType* atype1 = typeMap_[*atid1];
352    AtomType* atype2 = typeMap_[*atid2];
353    Vector3d disp(d);
354    Vector3d frc(f1);
355    Vector3d trq1(t1);
356    Vector3d trq2(t2);
357    Mat3x3d eFi(eFrame1);
358    Mat3x3d eFj(eFrame2);
359      
360    doSkipCorrection(atype1, atype2, disp, *r, *skippedCharge1, *skippedCharge2, *sw,
361                     *electroMult, *pot,  *vpair, frc, eFi, eFj, trq1, trq2);
362
363    f1[0] = frc.x();
364    f1[1] = frc.y();
365    f1[2] = frc.z();
382      
383 <    t1[0] = trq1.x();
368 <    t1[1] = trq1.y();
369 <    t1[2] = trq1.z();
383 >    SkipCorrectionData skdat;
384      
385 <    t2[0] = trq2.x();
386 <    t2[1] = trq2.y();
387 <    t2[2] = trq2.z();
385 >    skdat.atype1 = typeMap_[*atid1];
386 >    skdat.atype2 = typeMap_[*atid2];
387 >    skdat.d = Vector3d(d);
388 >    skdat.rij = *r;
389 >    skdat.skippedCharge1 = *skippedCharge1;
390 >    skdat.skippedCharge2 = *skippedCharge2;
391 >    skdat.sw = *sw;
392 >    skdat.electroMult = *electroMult;
393 >    skdat.pot = *pot;
394 >    skdat.vpair = *vpair;
395 >    skdat.f1 = Vector3d(f1);
396 >    skdat.eFrame1 = Mat3x3d(eFrame1);
397 >    skdat.eFrame2 = Mat3x3d(eFrame2);
398 >    skdat.t1 = Vector3d(t1);
399 >    skdat.t2 = Vector3d(t2);
400  
401 <    return;
402 <  }
401 >    pair<AtomType*, AtomType*> key = make_pair(skdat.atype1, skdat.atype2);
402 >    set<NonBondedInteraction*>::iterator it;
403  
404 <  void InteractionManager::do_self_correction(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
404 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
405 >      if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
406 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSkipCorrection(skdat);
407 >      }
408 >    }
409 >    
410 >    f1[0] = skdat.f1.x();
411 >    f1[1] = skdat.f1.y();
412 >    f1[2] = skdat.f1.z();
413 >    
414 >    t1[0] = skdat.t1.x();
415 >    t1[1] = skdat.t1.y();
416 >    t1[2] = skdat.t1.z();
417 >    
418 >    t2[0] = skdat.t2.x();
419 >    t2[1] = skdat.t2.y();
420 >    t2[2] = skdat.t2.z();
421  
422 +    return;    
423 +  }
424 +
425 +  void InteractionManager::doSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
426 +
427      if (!initialized_) initialize();
428 <          
428 >    
429 >    SelfCorrectionData scdat;
430 >    
431 >    scdat.atype = typeMap_[*atid];
432 >    scdat.eFrame = Mat3x3d(eFrame);
433 >    scdat.skippedCharge = *skippedCharge;
434 >    scdat.pot = *pot;
435 >    scdat.t = Vector3d(t);
436 >
437 >    pair<AtomType*, AtomType*> key = make_pair(scdat.atype, scdat.atype);
438 >    set<NonBondedInteraction*>::iterator it;
439 >
440 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
441 >      if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
442 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(scdat);
443 >      }
444 >    }
445 >        
446 >    t[0] = scdat.t.x();
447 >    t[1] = scdat.t.y();
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];
383    Mat3x3d eFi(eFrame);
384    Vector3d trq1(t);
385      
386    doSelfCorrection(atype, eFi, *skippedCharge, *pot, trq1);
458  
459 <    t[0] = trq1.x();
460 <    t[1] = trq1.y();
461 <    t[2] = trq1.z();
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 <    return;
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 402 | 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, RealType *vdwMult,
520 <                     RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1,
521 <                     RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2,
522 <                     RealType *t1, RealType *t2,
523 <                     RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2,
524 <                     RealType *fshift1, RealType *fshift2){
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