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

Comparing:
branches/development/src/nonbonded/RepulsivePower.cpp (file contents), Revision 1624 by gezelter, Tue Sep 13 14:12:54 2011 UTC vs.
trunk/src/nonbonded/RepulsivePower.cpp (file contents), Revision 2031 by jmichalk, Fri Oct 31 18:40:40 2014 UTC

# Line 35 | Line 35
35   *                                                                      
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 < * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 < * [4]  Vardeman & Gezelter, in progress (2009).                        
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <stdio.h>
# Line 45 | Line 46
46   #include <cmath>
47   #include "nonbonded/RepulsivePower.hpp"
48   #include "utils/simError.h"
49 < #include "types/NonBondedInteractionType.hpp"
49 > #include "types/RepulsivePowerInteractionType.hpp"
50  
51   using namespace std;
52  
# Line 56 | Line 57 | namespace OpenMD {
57    
58    void RepulsivePower::initialize() {    
59  
60 +    RPtypes.clear();
61 +    RPtids.clear();
62 +    MixingMap.clear();
63 +    RPtids.resize( forceField_->getNAtomType(), -1);
64 +
65      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
66      ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
67 +    ForceField::NonBondedInteractionTypeContainer::KeyType keys;
68      NonBondedInteractionType* nbt;
69 +    int rptid1, rptid2;
70  
71      for (nbt = nbiTypes->beginType(j); nbt != NULL;
72           nbt = nbiTypes->nextType(j)) {
73        
74        if (nbt->isRepulsivePower()) {
75 <        
76 <        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
77 <        
78 <        GenericData* data = nbt->getPropertyByName("RepulsivePower");
79 <        if (data == NULL) {
80 <          sprintf( painCave.errMsg, "RepulsivePower::initialize could not\n"
81 <                   "\tfind RepulsivePower parameters for %s - %s interaction.\n",
82 <                   atypes.first->getName().c_str(),
83 <                   atypes.second->getName().c_str());
76 <          painCave.severity = OPENMD_ERROR;
77 <          painCave.isFatal = 1;
78 <          simError();
75 >        keys = nbiTypes->getKeys(j);
76 >        AtomType* at1 = forceField_->getAtomType(keys[0]);
77 >        AtomType* at2 = forceField_->getAtomType(keys[1]);
78 >
79 >        int atid1 = at1->getIdent();
80 >        if (RPtids[atid1] == -1) {
81 >          rptid1 = RPtypes.size();
82 >          RPtypes.insert(atid1);
83 >          RPtids[atid1] = rptid1;        
84          }
85 <        
86 <        RepulsivePowerData* rpData = dynamic_cast<RepulsivePowerData*>(data);
87 <        if (rpData == NULL) {
85 >        int atid2 = at2->getIdent();
86 >        if (RPtids[atid2] == -1) {
87 >          rptid2 = RPtypes.size();
88 >          RPtypes.insert(atid2);
89 >          RPtids[atid2] = rptid2;        
90 >        }
91 >          
92 >        RepulsivePowerInteractionType* rpit = dynamic_cast<RepulsivePowerInteractionType*>(nbt);
93 >        if (rpit == NULL) {
94            sprintf( painCave.errMsg,
95 <                   "RepulsivePower::initialize could not convert GenericData\n"
96 <                   "\tto RepulsivePowerData for %s - %s interaction.\n",
97 <                   atypes.first->getName().c_str(),
98 <                   atypes.second->getName().c_str());
95 >                   "RepulsivePower::initialize could not convert NonBondedInteractionType\n"
96 >                   "\tto RepulsivePowerInteractionType for %s - %s interaction.\n",
97 >                   at1->getName().c_str(),
98 >                   at2->getName().c_str());
99            painCave.severity = OPENMD_ERROR;
100            painCave.isFatal = 1;
101            simError();          
102          }
103          
104 <        RepulsivePowerParam rpParam = rpData->getData();
104 >        RealType sigma = rpit->getSigma();
105 >        RealType epsilon = rpit->getEpsilon();
106 >        int nRep = rpit->getNrep();
107  
108 <        RealType sigma = rpParam.sigma;
96 <        RealType epsilon = rpParam.epsilon;
97 <        int nRep = rpParam.nRep;
98 <
99 <        addExplicitInteraction(atypes.first, atypes.second,
100 <                               sigma, epsilon, nRep);
108 >        addExplicitInteraction(at1, at2, sigma, epsilon, nRep);
109        }
110      }
111      initialized_ = true;
# Line 115 | Line 123 | namespace OpenMD {
123      mixer.sigmai = 1.0 / mixer.sigma;
124      mixer.nRep = nRep;
125  
126 <    pair<AtomType*, AtomType*> key1, key2;
127 <    key1 = make_pair(atype1, atype2);
128 <    key2 = make_pair(atype2, atype1);
126 >    int rptid1 = RPtids[atype1->getIdent()];
127 >    int rptid2 = RPtids[atype2->getIdent()];
128 >    int nRP = RPtypes.size();
129 >
130 >    MixingMap.resize(nRP);
131 >    MixingMap[rptid1].resize(nRP);
132      
133 <    MixingMap[key1] = mixer;
134 <    if (key2 != key1) {
135 <      MixingMap[key2] = mixer;
133 >    MixingMap[rptid1][rptid2] = mixer;
134 >    if (rptid2 != rptid1) {
135 >      MixingMap[rptid2].resize(nRP);
136 >      MixingMap[rptid2][rptid1] = mixer;
137      }    
138    }
139    
# Line 129 | Line 141 | namespace OpenMD {
141  
142      if (!initialized_) initialize();
143      
144 <    map<pair<AtomType*, AtomType*>, RPInteractionData>::iterator it;
145 <    it = MixingMap.find( idat.atypes );
146 <
147 <    if (it != MixingMap.end()) {
148 <
149 <      RPInteractionData mixer = (*it).second;
150 <      RealType sigmai = mixer.sigmai;
151 <      RealType epsilon = mixer.epsilon;
152 <      int nRep = mixer.nRep;
153 <      
154 <      RealType ros;
155 <      RealType rcos;
156 <      RealType myPot = 0.0;
157 <      RealType myPotC = 0.0;
158 <      RealType myDeriv = 0.0;
159 <      RealType myDerivC = 0.0;
160 <    
161 <      ros = *(idat.rij) * sigmai;    
162 <      
163 <      getNRepulsionFunc(ros, nRep, myPot, myDeriv);
164 <      
165 <      if (idat.shiftedPot) {
166 <        rcos = *(idat.rcut) * sigmai;
167 <        getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
168 <        myDerivC = 0.0;
169 <      } else if (idat.shiftedForce) {
170 <        rcos = *(idat.rcut) * sigmai;
159 <        getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
160 <        myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
161 <      } else {
162 <        myPotC = 0.0;
163 <        myDerivC = 0.0;        
164 <      }
165 <
166 <      RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
167 <      *(idat.vpair) += pot_temp;
168 <      
169 <      RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
170 <                                                                myDerivC)*sigmai;      
171 <
172 <      (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
173 <      *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
144 >    RPInteractionData &mixer = MixingMap[RPtids[idat.atid1]][RPtids[idat.atid2]];
145 >    RealType sigmai = mixer.sigmai;
146 >    RealType epsilon = mixer.epsilon;
147 >    int nRep = mixer.nRep;
148 >    
149 >    RealType ros;
150 >    RealType rcos;
151 >    RealType myPot = 0.0;
152 >    RealType myPotC = 0.0;
153 >    RealType myDeriv = 0.0;
154 >    RealType myDerivC = 0.0;
155 >    
156 >    ros = *(idat.rij) * sigmai;    
157 >    
158 >    getNRepulsionFunc(ros, nRep, myPot, myDeriv);
159 >    
160 >    if (idat.shiftedPot) {
161 >      rcos = *(idat.rcut) * sigmai;
162 >      getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
163 >      myDerivC = 0.0;
164 >    } else if (idat.shiftedForce) {
165 >      rcos = *(idat.rcut) * sigmai;
166 >      getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
167 >      myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
168 >    } else {
169 >      myPotC = 0.0;
170 >      myDerivC = 0.0;        
171      }
172 +    
173 +    RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
174 +    *(idat.vpair) += pot_temp;
175 +    
176 +    RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
177 +                                                              myDerivC)*sigmai;      
178 +    
179 +    (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
180 +    *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
181 +    
182      return;
183    }
184  
185 <  void RepulsivePower::getNRepulsionFunc(RealType r, int n, RealType &pot, RealType &deriv) {
185 >  void RepulsivePower::getNRepulsionFunc(const RealType &r, int &n, RealType &pot, RealType &deriv) {
186  
187      RealType ri = 1.0 / r;
188      RealType rin = pow(ri, n);
# Line 190 | Line 197 | namespace OpenMD {
197  
198    RealType RepulsivePower::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {  
199      if (!initialized_) initialize();  
200 <    map<pair<AtomType*, AtomType*>, RPInteractionData>::iterator it;
201 <    it = MixingMap.find(atypes);
202 <    if (it == MixingMap.end())
203 <      return 0.0;
204 <    else  {
205 <      RPInteractionData mixer = (*it).second;
200 >    
201 >    int atid1 = atypes.first->getIdent();
202 >    int atid2 = atypes.second->getIdent();
203 >    int rptid1 = RPtids[atid1];
204 >    int rptid2 = RPtids[atid2];
205 >    
206 >    if (rptid1 == -1 || rptid2 == -1) return 0.0;
207 >    else {      
208 >      RPInteractionData mixer = MixingMap[rptid1][rptid2];
209        return 2.5 * mixer.sigma;
210      }
211 <  }
202 <
211 >  }  
212   }
213  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines