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

Comparing branches/development/src/nonbonded/LJ.cpp (file contents):
Revision 1476 by gezelter, Wed Jul 21 18:31:05 2010 UTC vs.
Revision 1505 by gezelter, Sun Oct 3 22:18:59 2010 UTC

# Line 46 | Line 46
46   #include "nonbonded/LJ.hpp"
47   #include "utils/simError.h"
48  
49
49   namespace OpenMD {
50  
51 <  bool LJ::initialized_ = false;
52 <  bool LJ::shiftedPot_ = false;
54 <  bool LJ::shiftedFrc_ = false;
55 <  ForceField* LJ::forceField_ = NULL;
56 <  std::map<int, AtomType*> LJ::LJMap;
57 <  std::map<std::pair<AtomType*, AtomType*>, LJInteractionData> LJ::MixingMap;
58 <  
59 <  LJ* LJ::_instance = NULL;
51 >  LJ::LJ() : name_("LJ"), initialized_(false), shiftedPot_(false),
52 >             shiftedFrc_(false), forceField_(NULL) {}
53  
61  LJ* LJ::Instance() {
62    if (!_instance) {
63      _instance = new LJ();
64    }
65    return _instance;
66  }
67
54    LJParam LJ::getLJParam(AtomType* atomType) {
55      
56      // Do sanity checking on the AtomType we were passed before
# Line 106 | Line 92 | namespace OpenMD {
92      return ljParam.sigma;
93    }
94  
109  RealType LJ::getSigma(int atid) {
110    if (!initialized_) initialize();
111    std::map<int, AtomType*> :: const_iterator it;
112    it = LJMap.find(atid);
113    if (it == LJMap.end()) {
114      sprintf( painCave.errMsg,
115               "LJ::getSigma could not find atid %d in LJMap\n",
116               (atid));
117      painCave.severity = OPENMD_ERROR;
118      painCave.isFatal = 1;
119      simError();          
120    }
121    AtomType* atype = it->second;
122
123    return getSigma(atype);    
124  }
125
95    RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) {    
96      RealType sigma1 = getSigma(atomType1);
97      RealType sigma2 = getSigma(atomType2);
98      
99      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
100 <    std::string DistanceMix = fopts.getDistanceMixingRule();
100 >    string DistanceMix = fopts.getDistanceMixingRule();
101      toUpper(DistanceMix);
102  
103      if (DistanceMix == "GEOMETRIC")
# Line 140 | Line 109 | namespace OpenMD {
109    RealType LJ::getEpsilon(AtomType* atomType) {    
110      LJParam ljParam = getLJParam(atomType);
111      return ljParam.epsilon;
143  }
144
145  RealType LJ::getEpsilon(int atid) {    
146    if (!initialized_) initialize();
147    std::map<int, AtomType*> :: const_iterator it;
148    it = LJMap.find(atid);
149    if (it == LJMap.end()) {
150      sprintf( painCave.errMsg,
151               "LJ::getEpsilon could not find atid %d in LJMap\n",
152               (atid));
153      painCave.severity = OPENMD_ERROR;
154      painCave.isFatal = 1;
155      simError();          
156    }
157    AtomType* atype = it->second;
158
159    return getEpsilon(atype);    
112    }
113  
114    RealType LJ::getEpsilon(AtomType* atomType1, AtomType* atomType2) {    
# Line 186 | Line 138 | namespace OpenMD {
138        
139        if (nbt->isLennardJones()) {
140          
141 <        std::pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
141 >        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
142          
143          GenericData* data = nbt->getPropertyByName("LennardJones");
144          if (data == NULL) {
# Line 227 | Line 179 | namespace OpenMD {
179    void LJ::addType(AtomType* atomType){
180      RealType sigma1 = getSigma(atomType);
181      RealType epsilon1 = getEpsilon(atomType);
182 <
182 >    
183      // add it to the map:
184      AtomTypeProperties atp = atomType->getATP();    
185  
186 <    std::pair<std::map<int,AtomType*>::iterator,bool> ret;    
187 <    ret = LJMap.insert( std::pair<int, AtomType*>(atp.ident, atomType) );
186 >    pair<map<int,AtomType*>::iterator,bool> ret;    
187 >    ret = LJMap.insert( pair<int, AtomType*>(atp.ident, atomType) );
188      if (ret.second == false) {
189        sprintf( painCave.errMsg,
190                 "LJ already had a previous entry with ident %d\n",
# Line 288 | Line 240 | namespace OpenMD {
240      }    
241    }
242  
243 <  void LJ::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
244 <                     RealType rij, RealType r2, RealType rcut, RealType sw,
293 <                     RealType vdwMult, RealType &vpair, RealType &pot,
294 <                     Vector3d &f1) {
295 <
243 >  void LJ::calcForce(InteractionData idat) {
244 >    
245      if (!initialized_) initialize();
246      
247 <    RealType ros;
248 <    RealType rcos;
249 <    RealType myPot = 0.0;
301 <    RealType myPotC = 0.0;
302 <    RealType myDeriv = 0.0;
303 <    RealType myDerivC = 0.0;
304 <
305 <    std::pair<AtomType*, AtomType*> key = std::make_pair(at1, at2);
306 <    LJInteractionData mixer = MixingMap[key];
307 <
308 <    RealType sigmai = mixer.sigmai;
309 <    RealType epsilon = mixer.epsilon;
247 >    pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
248 >    map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it;
249 >    it = MixingMap.find(key);
250      
251 <
252 <    ros = rij * sigmai;
253 <
254 <    getLJfunc(ros, myPot, myDeriv);
251 >    if (it != MixingMap.end())  {
252 >      
253 >      LJInteractionData mixer = (*it).second;
254 >      
255 >      RealType sigmai = mixer.sigmai;
256 >      RealType epsilon = mixer.epsilon;
257 >      
258 >      RealType ros;
259 >      RealType rcos;
260 >      RealType myPot = 0.0;
261 >      RealType myPotC = 0.0;
262 >      RealType myDeriv = 0.0;
263 >      RealType myDerivC = 0.0;
264 >    
265 >      ros = idat.rij * sigmai;
266 >      
267 >      getLJfunc(ros, myPot, myDeriv);
268 >      
269 >      if (shiftedPot_) {
270 >        rcos = idat.rcut * sigmai;
271 >        getLJfunc(rcos, myPotC, myDerivC);
272 >        myDerivC = 0.0;
273 >      } else if (LJ::shiftedFrc_) {
274 >        rcos = idat.rcut * sigmai;
275 >        getLJfunc(rcos, myPotC, myDerivC);
276 >        myPotC = myPotC + myDerivC * (idat.rij - idat.rcut) * sigmai;
277 >      } else {
278 >        myPotC = 0.0;
279 >        myDerivC = 0.0;        
280 >      }
281  
282 <    if (shiftedPot_) {
283 <      rcos = rcut * sigmai;
284 <      getLJfunc(rcos, myPotC, myDerivC);
285 <      myDerivC = 0.0;
286 <    } else if (LJ::shiftedFrc_) {
287 <      rcos = rcut * sigmai;
288 <      getLJfunc(rcos, myPotC, myDerivC);
289 <      myPotC = myPotC + myDerivC * (rij - rcut) * sigmai;
290 <    } else {
325 <      myPotC = 0.0;
326 <      myDerivC = 0.0;
282 >      RealType pot_temp = idat.vdwMult * epsilon * (myPot - myPotC);
283 >      idat.vpair += pot_temp;
284 >      
285 >      RealType dudr = idat.sw * idat.vdwMult * epsilon * (myDeriv -
286 >                                                          myDerivC)*sigmai;
287 >      
288 >      idat.pot += idat.sw * pot_temp;
289 >      idat.f1 = idat.d * dudr / idat.rij;
290 >      
291      }
328
329    RealType pot_temp = vdwMult * epsilon * (myPot - myPotC);
330    vpair += pot_temp;
331
332    RealType dudr = sw * vdwMult * epsilon * (myDeriv - myDerivC)*sigmai;
333    
334    pot += sw * pot_temp;
335    f1 = d * dudr / rij;
336
292      return;
338
293    }
340
341  void LJ::do_lj_pair(int *atid1, int *atid2, RealType *d, RealType *rij,
342                      RealType *r2, RealType *rcut, RealType *sw,
343                      RealType *vdwMult,
344                      RealType *vpair, RealType *pot, RealType *f1) {
345
346    if (!initialized_) initialize();
347    
348    AtomType* atype1 = LJMap[*atid1];
349    AtomType* atype2 = LJMap[*atid2];
350    
351    Vector3d disp(d[0], d[1], d[2]);
352    Vector3d frc(f1[0], f1[1], f1[2]);
353    
354    calcForce(atype1, atype2, disp, *rij, *r2, *rcut, *sw, *vdwMult, *vpair,
355              *pot, frc);
356      
357    f1[0] = frc.x();
358    f1[1] = frc.y();
359    f1[2] = frc.z();
360
361    return;    
362  }
294    
295    void LJ::getLJfunc(RealType r, RealType &pot, RealType &deriv) {
296  
# Line 376 | Line 307 | namespace OpenMD {
307      return;
308    }
309    
310 <
311 <  void LJ::setLJDefaultCutoff(RealType *thisRcut, int *sP, int *sF) {
312 <    shiftedPot_ = (bool)(*sP);
313 <    shiftedFrc_ = (bool)(*sF);
310 >  RealType LJ::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
311 >    if (!initialized_) initialize();  
312 >    pair<AtomType*, AtomType*> key = make_pair(at1, at2);
313 >    map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it;
314 >    it = MixingMap.find(key);
315 >    if (it == MixingMap.end())
316 >      return 0.0;
317 >    else  {
318 >      LJInteractionData mixer = (*it).second;
319 >      return 2.5 * mixer.sigma;
320 >    }
321    }
384 }
322  
386 extern "C" {
387  
388 #define fortranGetSigma FC_FUNC(getsigma, GETSIGMA)
389 #define fortranGetEpsilon FC_FUNC(getepsilon, GETEPSILON)
390 #define fortranSetLJCutoff FC_FUNC(setljdefaultcutoff, SETLJDEFAULTCUTOFF)
391 #define fortranDoLJPair FC_FUNC(do_lj_pair, DO_LJ_PAIR)
392  
393  RealType fortranGetSigma(int* atid) {
394    return OpenMD::LJ::Instance()->getSigma(*atid);
395  }
396  RealType fortranGetEpsilon(int* atid) {  
397    return OpenMD::LJ::Instance()->getEpsilon(*atid);
398  }
399  void fortranSetLJCutoff(RealType *rcut, int *shiftedPot, int *shiftedFrc) {
400    return OpenMD::LJ::Instance()->setLJDefaultCutoff(rcut, shiftedPot,
401                                                      shiftedFrc);
402  }
403  void fortranDoLJPair(int *atid1, int *atid2, RealType *d, RealType *rij,
404                       RealType *r2, RealType *rcut, RealType *sw,
405                       RealType *vdwMult, RealType* vpair, RealType* pot,
406                       RealType *f1){
407    
408    return OpenMD::LJ::Instance()->do_lj_pair(atid1, atid2, d, rij, r2, rcut,
409                                              sw, vdwMult, vpair, pot, f1);
410  }
323   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines