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 1535 by gezelter, Fri Dec 31 18:31:56 2010 UTC vs.
Revision 1568 by gezelter, Wed May 25 16:20:37 2011 UTC

# Line 40 | Line 40
40   */
41  
42   #include "nonbonded/InteractionManager.hpp"
43 #include "UseTheForce/doForces_interface.h"
43  
44   namespace OpenMD {
45  
# Line 50 | Line 49 | namespace OpenMD {
49  
50    RealType InteractionManager::rCut_ = 0.0;
51    RealType InteractionManager::rSwitch_ = 0.0;
53  RealType InteractionManager::skinThickness_ = 0.0;
54  RealType InteractionManager::listRadius_ = 0.0;
52    CutoffMethod InteractionManager::cutoffMethod_ = SHIFTED_FORCE;
53    SwitchingFunctionType InteractionManager::sft_ = cubic;
54 <  RealType InteractionManager::vdwScale_[4] = {0.0, 0.0, 0.0, 0.0};
55 <  RealType InteractionManager::electrostaticScale_[4] = {0.0, 0.0, 0.0, 0.0};
54 >  RealType InteractionManager::vdwScale_[4] = {1.0, 0.0, 0.0, 0.0};
55 >  RealType InteractionManager::electrostaticScale_[4] = {1.0, 0.0, 0.0, 0.0};
56  
57    map<int, AtomType*> InteractionManager::typeMap_;
58    map<pair<AtomType*, AtomType*>, set<NonBondedInteraction*> > InteractionManager::interactions_;
# Line 95 | Line 92 | namespace OpenMD {
92      // Force fields can set options on how to scale van der Waals and electrostatic
93      // interactions for atoms connected via bonds, bends and torsions
94      // in this case the topological distance between atoms is:
95 <    // 0 = the atom itself
95 >    // 0 = topologically unconnected
96      // 1 = bonded together
97      // 2 = connected via a bend
98      // 3 = connected via a torsion
99  
100 <    vdwScale_[0] = 0.0;
100 >    vdwScale_[0] = 1.0;
101      vdwScale_[1] = fopts.getvdw12scale();
102      vdwScale_[2] = fopts.getvdw13scale();
103      vdwScale_[3] = fopts.getvdw14scale();
104  
105 <    electrostaticScale_[0] = 0.0;
105 >    electrostaticScale_[0] = 1.0;
106      electrostaticScale_[1] = fopts.getelectrostatic12scale();
107      electrostaticScale_[2] = fopts.getelectrostatic13scale();
108      electrostaticScale_[3] = fopts.getelectrostatic14scale();    
# Line 306 | Line 303 | namespace OpenMD {
303  
304      setupCutoffs();
305      setupSwitching();
309    setupNeighborlists();
310    notifyFortranSkinThickness(&skinThickness_);
311
312    int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0;
313    int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0;
314    notifyFortranCutoffs(&rCut_, &rSwitch_, &ljsp, &ljsf);
306  
307 <    int isError;
308 <    initFortranFF(&isError);
307 >    //int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0;
308 >    //int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0;
309 >    //notifyFortranCutoffs(&rCut_, &rSwitch_, &ljsp, &ljsf);
310  
311      initialized_ = true;
312    }
# Line 457 | Line 449 | namespace OpenMD {
449          }          
450        }
451      }
460  }
452  
453 <  /**
454 <   * setupNeighborlists
464 <   *
465 <   *  If the skinThickness was explicitly set, use that value (but check it)
466 <   *  If the skinThickness was not explicitly set: use 1.0 angstroms
467 <   */
468 <  void InteractionManager::setupNeighborlists() {  
469 <
470 <    Globals* simParams_ = info_->getSimParams();    
471 <  
472 <    if (simParams_->haveSkinThickness()) {
473 <      skinThickness_ = simParams_->getSkinThickness();
474 <    } else {      
475 <      skinThickness_ = 1.0;
476 <      sprintf(painCave.errMsg,
477 <              "InteractionManager::setupNeighborlists: No value was set for the skinThickness.\n"
478 <              "\tOpenMD will use a default value of %f Angstroms\n"
479 <              "\tfor this simulation\n", skinThickness_);
480 <      painCave.severity = OPENMD_INFO;
481 <      painCave.isFatal = 0;
482 <      simError();
483 <    }            
484 <
485 <    listRadius_ = rCut_ + skinThickness_;
486 <
453 >    switcher_->setSwitchType(sft_);
454 >    switcher_->setSwitch(rSwitch_, rCut_);
455    }
456  
457 <
490 <  void InteractionManager::doPrePair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){
457 >  void InteractionManager::doPrePair(InteractionData idat){
458      
459      if (!initialized_) initialize();
460 <          
494 <    DensityData ddat;
495 <
496 <    ddat.atype1 = typeMap_[*atid1];
497 <    ddat.atype2 = typeMap_[*atid2];
498 <    ddat.rij = *rij;
499 <    ddat.rho_i_at_j = *rho_i_at_j;
500 <    ddat.rho_j_at_i = *rho_j_at_i;
501 <
502 <    pair<AtomType*, AtomType*> key = make_pair(ddat.atype1, ddat.atype2);
460 >        
461      set<NonBondedInteraction*>::iterator it;
462  
463 <    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
463 >    for (it = interactions_[ *(idat.atypes) ].begin();
464 >         it != interactions_[ *(idat.atypes) ].end(); ++it){
465        if ((*it)->getFamily() == METALLIC_FAMILY) {
466 <        dynamic_cast<MetallicInteraction*>(*it)->calcDensity(ddat);
466 >        dynamic_cast<MetallicInteraction*>(*it)->calcDensity(idat);
467        }
468      }
469      
470      return;    
471    }
472    
473 <  void InteractionManager::doPreForce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
473 >  void InteractionManager::doPreForce(SelfData sdat){
474  
475      if (!initialized_) initialize();
476 <          
477 <    FunctionalData fdat;
519 <
520 <    fdat.atype = typeMap_[*atid];
521 <    fdat.rho = *rho;
522 <    fdat.frho = *frho;
523 <    fdat.dfrhodrho = *dfrhodrho;
524 <
525 <    pair<AtomType*, AtomType*> key = make_pair(fdat.atype, fdat.atype);
476 >    
477 >    pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
478      set<NonBondedInteraction*>::iterator it;
479      
480      for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
481        if ((*it)->getFamily() == METALLIC_FAMILY) {
482 <        dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(fdat);
482 >        dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(sdat);
483        }
484      }
485      
486      return;    
487    }
488  
489 <  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){
489 >  void InteractionManager::doPair(InteractionData idat){
490      
491      if (!initialized_) initialize();
492 <    
541 <    InteractionData idat;
542 <    
543 <    idat.atype1 = typeMap_[*atid1];
544 <    idat.atype2 = typeMap_[*atid2];
545 <    idat.d = Vector3d(d);
546 <    idat.rij = *r;
547 <    idat.r2 = *r2;
548 <    idat.rcut = *rcut;
549 <    idat.sw = *sw;
550 <    idat.vdwMult = vdwScale_[*topoDist];
551 <    idat.electroMult = electrostaticScale_[*topoDist];
552 <    idat.pot = *pot;
553 <    idat.vpair = *vpair;
554 <    idat.f1 = Vector3d(f1);
555 <    idat.eFrame1 = Mat3x3d(eFrame1);
556 <    idat.eFrame2 = Mat3x3d(eFrame2);
557 <    idat.A1 = RotMat3x3d(A1);
558 <    idat.A2 = RotMat3x3d(A2);
559 <    idat.t1 = Vector3d(t1);
560 <    idat.t2 = Vector3d(t2);
561 <    idat.rho1 = *rho1;
562 <    idat.rho2 = *rho2;
563 <    idat.dfrho1 = *dfrho1;
564 <    idat.dfrho2 = *dfrho2;
565 <    idat.fshift1 = *fshift1;
566 <    idat.fshift2 = *fshift2;
567 <
568 <    pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
492 >  
493      set<NonBondedInteraction*>::iterator it;
494  
495 <    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
495 >    for (it = interactions_[ *(idat.atypes) ].begin();
496 >         it != interactions_[ *(idat.atypes) ].end(); ++it)
497        (*it)->calcForce(idat);
498      
574    f1[0] = idat.f1.x();
575    f1[1] = idat.f1.y();
576    f1[2] = idat.f1.z();
577    
578    t1[0] = idat.t1.x();
579    t1[1] = idat.t1.y();
580    t1[2] = idat.t1.z();
581    
582    t2[0] = idat.t2.x();
583    t2[1] = idat.t2.y();
584    t2[2] = idat.t2.z();
585
499      return;    
500    }
501  
502 <  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){
502 >  void InteractionManager::doSkipCorrection(InteractionData idat){
503  
504 <    if (!initialized_) initialize();
504 >    if (!initialized_) initialize();  
505      
593    SkipCorrectionData skdat;
594    
595    skdat.atype1 = typeMap_[*atid1];
596    skdat.atype2 = typeMap_[*atid2];
597    skdat.d = Vector3d(d);
598    skdat.rij = *r;
599    skdat.skippedCharge1 = *skippedCharge1;
600    skdat.skippedCharge2 = *skippedCharge2;
601    skdat.sw = *sw;
602    skdat.electroMult = *electroMult;
603    skdat.pot = *pot;
604    skdat.vpair = *vpair;
605    skdat.f1 = Vector3d(f1);
606    skdat.eFrame1 = Mat3x3d(eFrame1);
607    skdat.eFrame2 = Mat3x3d(eFrame2);
608    skdat.t1 = Vector3d(t1);
609    skdat.t2 = Vector3d(t2);
610
611    pair<AtomType*, AtomType*> key = make_pair(skdat.atype1, skdat.atype2);
506      set<NonBondedInteraction*>::iterator it;
507  
508 <    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
508 >    for (it = interactions_[ *(idat.atypes) ].begin();
509 >         it != interactions_[ *(idat.atypes) ].end(); ++it){
510        if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
511 <        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSkipCorrection(skdat);
511 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSkipCorrection(idat);
512        }
513      }
514      
620    f1[0] = skdat.f1.x();
621    f1[1] = skdat.f1.y();
622    f1[2] = skdat.f1.z();
623    
624    t1[0] = skdat.t1.x();
625    t1[1] = skdat.t1.y();
626    t1[2] = skdat.t1.z();
627    
628    t2[0] = skdat.t2.x();
629    t2[1] = skdat.t2.y();
630    t2[2] = skdat.t2.z();
631
515      return;    
516    }
517  
518 <  void InteractionManager::doSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
518 >  void InteractionManager::doSelfCorrection(SelfData sdat){
519  
520      if (!initialized_) initialize();
521      
522 <    SelfCorrectionData scdat;
640 <    
641 <    scdat.atype = typeMap_[*atid];
642 <    scdat.eFrame = Mat3x3d(eFrame);
643 <    scdat.skippedCharge = *skippedCharge;
644 <    scdat.pot = *pot;
645 <    scdat.t = Vector3d(t);
646 <
647 <    pair<AtomType*, AtomType*> key = make_pair(scdat.atype, scdat.atype);
522 >    pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
523      set<NonBondedInteraction*>::iterator it;
524  
525      for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
526        if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
527 <        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(scdat);
527 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(sdat);
528        }
529      }
530 <        
656 <    t[0] = scdat.t.x();
657 <    t[1] = scdat.t.y();
658 <    t[2] = scdat.t.z();
659 <
530 >      
531      return;    
532    }
533  
663
534    RealType InteractionManager::getSuggestedCutoffRadius(int *atid) {
535      if (!initialized_) initialize();
536      
# Line 671 | Line 541 | namespace OpenMD {
541      RealType cutoff = 0.0;
542      
543      for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
544 <      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype));  
544 >      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));  
545      return cutoff;    
546    }
547  
# Line 683 | Line 553 | namespace OpenMD {
553      RealType cutoff = 0.0;
554      
555      for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
556 <      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype));  
556 >      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));  
557      return cutoff;    
558    }
689
690
691  void InteractionManager::setSwitch(RealType *rIn, RealType *rOut) {
692    switcher_->setSwitch(*rIn, *rOut);    
693  }
694
695  void InteractionManager::getSwitch(RealType *r2, RealType *sw, RealType *dswdr, RealType *r,
696                                     int *in_switching_region) {
697    bool isr = switcher_->getSwitch(*r2, *sw, *dswdr, *r);    
698    *in_switching_region = (int)isr;
699  }
700
559   } //end namespace OpenMD
702
703 extern "C" {
704  
705 #define fortranDoPrePair FC_FUNC(do_prepair, DO_PREPAIR)
706 #define fortranDoPreForce FC_FUNC(do_preforce, DO_PREFORCE)
707 #define fortranDoPair FC_FUNC(do_pair, DO_PAIR)
708 #define fortranDoSkipCorrection FC_FUNC(do_skip_correction, DO_SKIP_CORRECTION)
709 #define fortranDoSelfCorrection FC_FUNC(do_self_correction, DO_SELF_CORRECTION)
710 #define fortranGetCutoff FC_FUNC(get_cutoff, GET_CUTOFF)
711 #define fortranSetSwitch FC_FUNC(set_switch, SET_SWITCH)
712 #define fortranGetSwitch FC_FUNC(get_switch, GET_SWITCH)
713
714  void fortranDoPrePair(int *atid1, int *atid2, RealType *rij,
715                        RealType *rho_i_at_j, RealType *rho_j_at_i) {
716            
717    return OpenMD::InteractionManager::Instance()->doPrePair(atid1, atid2, rij,
718                                                             rho_i_at_j,  
719                                                             rho_j_at_i);
720  }
721  void fortranDoPreForce(int *atid, RealType *rho, RealType *frho,
722                         RealType *dfrhodrho) {  
723    
724    return OpenMD::InteractionManager::Instance()->doPreForce(atid, rho, frho,
725                                                              dfrhodrho);    
726  }
727  
728  void fortranDoPair(int *atid1, int *atid2, RealType *d, RealType *r,
729                     RealType *r2, RealType *rcut, RealType *sw, int *topoDist,
730                     RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1,
731                     RealType *eFrame2, RealType *A1, RealType *A2,
732                     RealType *t1, RealType *t2, RealType *rho1, RealType *rho2,
733                     RealType *dfrho1, RealType *dfrho2, RealType *fshift1,
734                     RealType *fshift2){
735    
736    return OpenMD::InteractionManager::Instance()->doPair(atid1, atid2, d, r,
737                                                          r2, rcut, sw, topoDist,
738                                                          pot, vpair, f1,
739                                                          eFrame1, eFrame2,
740                                                          A1, A2, t1, t2, rho1,
741                                                          rho2, dfrho1, dfrho2,
742                                                          fshift1, fshift2);
743  }
744  
745  void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d,
746                               RealType *r, RealType *skippedCharge1,
747                               RealType *skippedCharge2, RealType *sw,
748                               RealType *electroMult, RealType *pot,
749                               RealType *vpair, RealType *f1,
750                               RealType *eFrame1, RealType *eFrame2,
751                               RealType *t1, RealType *t2){
752    
753    return OpenMD::InteractionManager::Instance()->doSkipCorrection(atid1,
754                                                                    atid2, d,
755                                                                    r,
756                                                                    skippedCharge1,
757                                                                    skippedCharge2,
758                                                                    sw, electroMult, pot,
759                                                                    vpair, f1, eFrame1,
760                                                                    eFrame2, t1, t2);
761  }
762  
763  void fortranDoSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge,
764                               RealType *pot, RealType *t) {
765    
766    return OpenMD::InteractionManager::Instance()->doSelfCorrection(atid,
767                                                                    eFrame,
768                                                                    skippedCharge,
769                                                                    pot, t);
770  }
771  RealType fortranGetCutoff(int *atid) {    
772    return OpenMD::InteractionManager::Instance()->getSuggestedCutoffRadius(atid);
773  }
774
775  void fortranGetSwitch(RealType *r2, RealType *sw, RealType *dswdr, RealType *r,
776                        int *in_switching_region) {
777    
778    return OpenMD::InteractionManager::Instance()->getSwitch(r2, sw, dswdr, r,
779                                                             in_switching_region);
780  }
781
782  void fortranSetSwitch(RealType *rIn, RealType *rOut) {    
783    return OpenMD::InteractionManager::Instance()->setSwitch(rIn, rOut);
784  }
785  
786 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines