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

Comparing branches/development/src/nonbonded/Sticky.cpp (file contents):
Revision 1505 by gezelter, Sun Oct 3 22:18:59 2010 UTC vs.
Revision 1767 by gezelter, Fri Jul 6 22:01:58 2012 UTC

# Line 36 | Line 36
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).                        
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/Sticky.hpp"
48   #include "nonbonded/LJ.hpp"
49 + #include "types/StickyAdapter.hpp"
50   #include "utils/simError.h"
51  
52   using namespace std;
53   namespace OpenMD {
54    
55    Sticky::Sticky() : name_("Sticky"), initialized_(false), forceField_(NULL) {}
54  
55  StickyParam Sticky::getStickyParam(AtomType* atomType) {
56      
57    // Do sanity checking on the AtomType we were passed before
58    // building any data structures:
59    if (!atomType->isSticky() && !atomType->isStickyPower()) {
60      sprintf( painCave.errMsg,
61               "Sticky::getStickyParam was passed an atomType (%s) that does\n"
62               "\tnot appear to be a Sticky atom.\n",
63               atomType->getName().c_str());
64      painCave.severity = OPENMD_ERROR;
65      painCave.isFatal = 1;
66      simError();
67    }
68    
69    DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType);
70    GenericData* data = daType->getPropertyByName("Sticky");
71    if (data == NULL) {
72      sprintf( painCave.errMsg, "Sticky::getStickyParam could not find\n"
73               "\tSticky parameters for atomType %s.\n",
74               daType->getName().c_str());
75      painCave.severity = OPENMD_ERROR;
76      painCave.isFatal = 1;
77      simError();
78    }
79    
80    StickyParamGenericData* stickyData = dynamic_cast<StickyParamGenericData*>(data);
81    if (stickyData == NULL) {
82      sprintf( painCave.errMsg,
83               "Sticky::getStickyParam could not convert GenericData to\n"
84               "\tStickyParamGenericData for atom type %s\n",
85               daType->getName().c_str());
86      painCave.severity = OPENMD_ERROR;
87      painCave.isFatal = 1;
88      simError();          
89    }
90    
91    return stickyData->getData();
92  }
93  
57    void Sticky::initialize() {    
58      
59      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
# Line 103 | Line 66 | namespace OpenMD {
66      for (at = atomTypes->beginType(i); at != NULL;
67           at = atomTypes->nextType(i)) {
68        
69 <      if (at->isSticky() || at->isStickyPower())
70 <        addType(at);
69 >      StickyAdapter sa = StickyAdapter(at);
70 >      if (sa.isSticky()) addType(at);
71      }
72      
73      initialized_ = true;
# Line 112 | Line 75 | namespace OpenMD {
75        
76    void Sticky::addType(AtomType* atomType){
77      // add it to the map:
115    AtomTypeProperties atp = atomType->getATP();    
78      
79      pair<map<int,AtomType*>::iterator,bool> ret;    
80 <    ret = StickyMap.insert( pair<int, AtomType*>(atp.ident, atomType) );
80 >    ret = StickyMap.insert( pair<int, AtomType*>(atomType->getIdent(),
81 >                                                 atomType) );
82      if (ret.second == false) {
83        sprintf( painCave.errMsg,
84                 "Sticky already had a previous entry with ident %d\n",
85 <               atp.ident);
85 >               atomType->getIdent() );
86        painCave.severity = OPENMD_INFO;
87        painCave.isFatal = 0;
88        simError();        
89 <    }
89 >    }  
90      
91 <    RealType w0i, v0i, v0pi, rli, rui, rlpi, rupi;
129 <    
130 <    StickyParam sticky1 = getStickyParam(atomType);
91 >    StickyAdapter sticky1 = StickyAdapter(atomType);
92  
93      // Now, iterate over all known types and add to the mixing map:
94      
# Line 135 | Line 96 | namespace OpenMD {
96      for( it = StickyMap.begin(); it != StickyMap.end(); ++it) {
97        
98        AtomType* atype2 = (*it).second;
99 <    
100 <      StickyParam sticky2 = getStickyParam(atype2);
99 >      
100 >      StickyAdapter sticky2 = StickyAdapter(atype2);
101  
102        StickyInteractionData mixer;        
103            
# Line 145 | Line 106 | namespace OpenMD {
106        // Lorentz- Berthelot mixing rules (which happen to do the right thing
107        // when atomType and atype2 happen to be the same.
108        
109 <      mixer.rl   = 0.5 * ( sticky1.rl + sticky2.rl );
110 <      mixer.ru   = 0.5 * ( sticky1.ru + sticky2.ru );
111 <      mixer.rlp  = 0.5 * ( sticky1.rlp + sticky2.rlp );
112 <      mixer.rup  = 0.5 * ( sticky1.rup + sticky2.rup );
109 >      mixer.rl   = 0.5 * ( sticky1.getRl() + sticky2.getRl() );
110 >      mixer.ru   = 0.5 * ( sticky1.getRu() + sticky2.getRu() );
111 >      mixer.rlp  = 0.5 * ( sticky1.getRlp() + sticky2.getRlp() );
112 >      mixer.rup  = 0.5 * ( sticky1.getRup() + sticky2.getRup() );
113        mixer.rbig = max(mixer.ru, mixer.rup);
114 <      mixer.w0  = sqrt( sticky1.w0   * sticky2.w0  );
115 <      mixer.v0  = sqrt( sticky1.v0   * sticky2.v0  );
116 <      mixer.v0p = sqrt( sticky1.v0p  * sticky2.v0p );
117 <      mixer.isPower = atomType->isStickyPower() && atype2->isStickyPower();
114 >      mixer.w0  = sqrt( sticky1.getW0()   * sticky2.getW0()  );
115 >      mixer.v0  = sqrt( sticky1.getW0()   * sticky2.getV0()  );
116 >      mixer.v0p = sqrt( sticky1.getV0p()  * sticky2.getV0p() );
117 >      mixer.isPower = sticky1.isStickyPower() && sticky2.isStickyPower();
118  
119        CubicSpline* s = new CubicSpline();
120        s->addPoint(mixer.rl, 1.0);
# Line 186 | Line 147 | namespace OpenMD {
147     * idat structure.
148     */
149    
150 <  void Sticky::calcForce(InteractionData idat) {
150 >  void Sticky::calcForce(InteractionData &idat) {
151    
152      if (!initialized_) initialize();
153      
193    pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
154      map<pair<AtomType*, AtomType*>, StickyInteractionData>::iterator it;
155 <    it = MixingMap.find(key);
155 >    it = MixingMap.find(idat.atypes);
156      if (it != MixingMap.end()) {
157  
158        StickyInteractionData mixer = (*it).second;
# Line 207 | Line 167 | namespace OpenMD {
167        RealType rbig = mixer.rbig;
168        bool isPower = mixer.isPower;
169        
170 <      if (idat.rij <= rbig) {
170 >      if ( *(idat.rij) <= rbig) {
171          
172 <        RealType r3 = idat.r2 * idat.rij;
173 <        RealType r5 = r3 * idat.r2;
172 >        RealType r3 = *(idat.r2) * *(idat.rij);
173 >        RealType r5 = r3 * *(idat.r2);
174          
175 <        RotMat3x3d A1trans = idat.A1.transpose();
176 <        RotMat3x3d A2trans = idat.A2.transpose();
175 >        RotMat3x3d A1trans = idat.A1->transpose();
176 >        RotMat3x3d A2trans = idat.A2->transpose();
177          
178          // rotate the inter-particle separation into the two different
179          // body-fixed coordinate systems:
180          
181 <        Vector3d ri = idat.A1 * idat.d;
181 >        Vector3d ri = *(idat.A1) * *(idat.d);
182          
183          // negative sign because this is the vector from j to i:
184          
185 <        Vector3d rj = - idat.A2 * idat.d;
185 >        Vector3d rj = - *(idat.A2) * *(idat.d);
186          
187          RealType xi = ri.x();
188          RealType yi = ri.y();
# Line 247 | Line 207 | namespace OpenMD {
207          RealType sp = 0.0;
208          RealType dspdr = 0.0;
209          
210 <        if (idat.rij < ru) {
211 <          if (idat.rij < rl) {
210 >        if ( *(idat.rij) < ru) {
211 >          if ( *(idat.rij) < rl) {
212              s = 1.0;
213              dsdr = 0.0;
214            } else {          
215              // we are in the switching region
216              
217 <            pair<RealType, RealType> res = mixer.s->getValueAndDerivativeAt(idat.rij);
217 >            pair<RealType, RealType> res = mixer.s->getValueAndDerivativeAt(*(idat.rij));
218              s = res.first;
219              dsdr = res.second;
220            }
221          }
222          
223 <        if (idat.rij < rup) {
224 <          if (idat.rij < rlp) {
223 >        if (*(idat.rij) < rup) {
224 >          if ( *(idat.rij) < rlp) {
225              sp = 1.0;
226              dspdr = 0.0;
227            } else {
228              // we are in the switching region
229              
230 <            pair<RealType, RealType> res =mixer.sp->getValueAndDerivativeAt(idat.rij);
230 >            pair<RealType, RealType> res =mixer.sp->getValueAndDerivativeAt( *(idat.rij));
231              sp = res.first;
232              dspdr = res.second;
233            }
# Line 278 | Line 238 | namespace OpenMD {
238          RealType w = wi+wj;
239          
240          
241 <        RealType zif = zi/idat.rij - 0.6;
242 <        RealType zis = zi/idat.rij + 0.8;
241 >        RealType zif = zi/ *(idat.rij)  - 0.6;
242 >        RealType zis = zi/ *(idat.rij)  + 0.8;
243          
244 <        RealType zjf = zj/idat.rij - 0.6;
245 <        RealType zjs = zj/idat.rij + 0.8;
244 >        RealType zjf = zj/ *(idat.rij)  - 0.6;
245 >        RealType zjs = zj/ *(idat.rij)  + 0.8;
246          
247          RealType wip = zif*zif*zis*zis - w0;
248          RealType wjp = zjf*zjf*zjs*zjs - w0;
# Line 301 | Line 261 | namespace OpenMD {
261  
262          Vector3d dwip(-2.0*xi*zi*uglyi/r3,
263                        -2.0*yi*zi*uglyi/r3,
264 <                      2.0*(1.0/idat.rij - zi2/r3)*uglyi);
264 >                      2.0*(1.0/ *(idat.rij)  - zi2/r3)*uglyi);
265          
266          Vector3d dwjp(-2.0*xj*zj*uglyj/r3,
267                        -2.0*yj*zj*uglyj/r3,
268 <                      2.0*(1.0/idat.rij - zj2/r3)*uglyj);
268 >                      2.0*(1.0/ *(idat.rij)  - zj2/r3)*uglyj);
269          
270          Vector3d dwidu(4.0*(yi*zi2 + 0.5*yi*(xi2-yi2))/r3,
271                         4.0*(xi*zi2 - 0.5*xi*(xi2-yi2))/r3,
# Line 315 | Line 275 | namespace OpenMD {
275                         4.0*(xj*zj2 - 0.5*xj*(xj2-yj2))/r3,
276                         - 8.0*xj*yj*zj/r3);
277          
278 <        Vector3d dwipdu(2.0*yi*uglyi/idat.rij,
279 <                        -2.0*xi*uglyi/idat.rij,
278 >        Vector3d dwipdu(2.0*yi*uglyi/ *(idat.rij) ,
279 >                        -2.0*xi*uglyi/ *(idat.rij) ,
280                          0.0);
281          
282 <        Vector3d dwjpdu(2.0*yj*uglyj/idat.rij,
283 <                        -2.0*xj*uglyj/idat.rij,
282 >        Vector3d dwjpdu(2.0*yj*uglyj/ *(idat.rij) ,
283 >                        -2.0*xj*uglyj/ *(idat.rij) ,
284                          0.0);
285          
286          if (isPower) {
# Line 331 | Line 291 | namespace OpenMD {
291            // sticky power has no w' function:
292            w = frac1 * wi * wi2 + frac2*wi + frac1*wj*wj2 + frac2*wj + v0p;
293            wp = 0.0;
294 <          dwi = frac1*3.0*wi2*dwi + frac2*dwi;
295 <          dwj = frac1*3.0*wj2*dwi + frac2*dwi;
294 >          dwi = frac1*RealType(3.0)*wi2*dwi + frac2*dwi;
295 >          dwj = frac1*RealType(3.0)*wj2*dwi + frac2*dwi;
296            dwip = V3Zero;
297            dwjp = V3Zero;
298 <          dwidu = frac1*3.0*wi2*dwidu + frac2*dwidu;
299 <          dwidu = frac1*3.0*wj2*dwjdu + frac2*dwjdu;
298 >          dwidu = frac1*RealType(3.0)*wi2*dwidu + frac2*dwidu;
299 >          dwidu = frac1*RealType(3.0)*wj2*dwjdu + frac2*dwjdu;
300            dwipdu = V3Zero;
301            dwjpdu = V3Zero;
302            sp = 0.0;
303            dspdr = 0.0;
304          }
305          
306 <        idat.vpair += 0.5*(v0*s*w + v0p*sp*wp);
307 <        idat.pot += 0.5*(v0*s*w + v0p*sp*wp)*idat.sw;
306 >        *(idat.vpair) += RealType(0.5)*(v0*s*w + v0p*sp*wp);
307 >        (*(idat.pot))[HYDROGENBONDING_FAMILY] += RealType(0.5)*(v0*s*w + v0p*sp*wp)* *(idat.sw) ;
308          
309          // do the torques first since they are easy:
310          // remember that these are still in the body-fixed axes
311          
312 <        Vector3d ti = 0.5*idat.sw*(v0*s*dwidu + v0p*sp*dwipdu);
313 <        Vector3d tj = 0.5*idat.sw*(v0*s*dwjdu + v0p*sp*dwjpdu);
312 >        Vector3d ti = RealType(0.5)* *(idat.sw) *(v0*s*dwidu + v0p*sp*dwipdu);
313 >        Vector3d tj = RealType(0.5)* *(idat.sw) *(v0*s*dwjdu + v0p*sp*dwjpdu);
314          
315          // go back to lab frame using transpose of rotation matrix:
316          
317 <        idat.t1 += A1trans * ti;
318 <        idat.t2 += A2trans * tj;
317 >        *(idat.t1) += A1trans * ti;
318 >        *(idat.t2) += A2trans * tj;
319          
320          // Now, on to the forces:
321          
322          // first rotate the i terms back into the lab frame:
323          
324 <        Vector3d radcomi = (v0 * s * dwi + v0p * sp * dwip) * idat.sw;
325 <        Vector3d radcomj = (v0 * s * dwj + v0p * sp * dwjp) * idat.sw;
324 >        Vector3d radcomi = (v0 * s * dwi + v0p * sp * dwip) *  *(idat.sw);
325 >        Vector3d radcomj = (v0 * s * dwj + v0p * sp * dwjp) *  *(idat.sw);
326          
327          Vector3d fii = A1trans * radcomi;
328          Vector3d fjj = A2trans * radcomj;
329          
330          // now assemble these with the radial-only terms:
331          
332 <        idat.f1 += 0.5 * ((v0*dsdr*w + v0p*dspdr*wp) * idat.d /
333 <                          idat.rij + fii - fjj);
332 >        *(idat.f1) += RealType(0.5) * ((v0*dsdr*w + v0p*dspdr*wp) * *(idat.d) /
333 >                                       *(idat.rij)  + fii - fjj);
334          
335        }
336      }
# Line 378 | Line 338 | namespace OpenMD {
338      return;      
339    }
340  
341 <  RealType Sticky::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
341 >  RealType Sticky::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
342      if (!initialized_) initialize();  
383    pair<AtomType*, AtomType*> key = make_pair(at1, at2);
343      map<pair<AtomType*, AtomType*>, StickyInteractionData>::iterator it;
344 <    it = MixingMap.find(key);
344 >    it = MixingMap.find(atypes);
345      if (it == MixingMap.end())
346        return 0.0;
347      else  {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines