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

Comparing:
branches/development/src/nonbonded/EAM.cpp (file contents), Revision 1629 by gezelter, Wed Sep 14 21:15:17 2011 UTC vs.
trunk/src/nonbonded/EAM.cpp (file contents), Revision 1895 by gezelter, Mon Jul 1 21:09:37 2013 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 53 | Line 54 | namespace OpenMD {
54    EAM::EAM() : name_("EAM"), initialized_(false), forceField_(NULL),
55                 mixMeth_(eamJohnson), eamRcut_(0.0), haveCutoffRadius_(false) {}
56    
57 <  EAMParam EAM::getEAMParam(AtomType* atomType) {
58 <    
59 <    // Do sanity checking on the AtomType we were passed before
60 <    // building any data structures:
61 <    if (!atomType->isEAM()) {
61 <      sprintf( painCave.errMsg,
62 <               "EAM::getEAMParam was passed an atomType (%s) that does not\n"
63 <               "\tappear to be an embedded atom method (EAM) atom.\n",
64 <               atomType->getName().c_str());
65 <      painCave.severity = OPENMD_ERROR;
66 <      painCave.isFatal = 1;
67 <      simError();
68 <    }
69 <    
70 <    GenericData* data = atomType->getPropertyByName("EAM");
71 <    if (data == NULL) {
72 <      sprintf( painCave.errMsg, "EAM::getEAMParam could not find EAM\n"
73 <               "\tparameters for atomType %s.\n",
74 <               atomType->getName().c_str());
75 <      painCave.severity = OPENMD_ERROR;
76 <      painCave.isFatal = 1;
77 <      simError();
78 <    }
79 <    
80 <    EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data);
81 <    if (eamData == NULL) {
82 <      sprintf( painCave.errMsg,
83 <               "EAM::getEAMParam could not convert GenericData to EAMParam for\n"
84 <               "\tatom type %s\n", atomType->getName().c_str());
85 <      painCave.severity = OPENMD_ERROR;
86 <      painCave.isFatal = 1;
87 <      simError();          
88 <    }
89 <    
90 <    return eamData->getData();
91 <  }
57 >  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {  
58 >    EAMAdapter ea1 = EAMAdapter(atomType1);
59 >    EAMAdapter ea2 = EAMAdapter(atomType2);
60 >    CubicSpline* z1 = ea1.getZ();
61 >    CubicSpline* z2 = ea2.getZ();
62  
93  CubicSpline* EAM::getZ(AtomType* atomType) {    
94    EAMParam eamParam = getEAMParam(atomType);
95    int nr = eamParam.nr;
96    RealType dr = eamParam.dr;
97    vector<RealType> rvals;
98    
99    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i) * dr);
100      
101    CubicSpline* cs = new CubicSpline();
102    cs->addPoints(rvals, eamParam.Z);
103    return cs;
104  }
105
106  RealType EAM::getRcut(AtomType* atomType) {    
107    EAMParam eamParam = getEAMParam(atomType);
108    return eamParam.rcut;
109  }
110
111  CubicSpline* EAM::getRho(AtomType* atomType) {    
112    EAMParam eamParam = getEAMParam(atomType);
113    int nr = eamParam.nr;
114    RealType dr = eamParam.dr;
115    vector<RealType> rvals;
116    
117    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i) * dr);
118      
119    CubicSpline* cs = new CubicSpline();
120    cs->addPoints(rvals, eamParam.rho);
121    return cs;
122  }
123
124  CubicSpline* EAM::getF(AtomType* atomType) {    
125    EAMParam eamParam = getEAMParam(atomType);
126    int nrho = eamParam.nrho;
127    RealType drho = eamParam.drho;
128    vector<RealType> rhovals;
129    vector<RealType> scaledF;
130    
131    for (int i = 0; i < nrho; i++) {
132      rhovals.push_back(RealType(i) * drho);
133      scaledF.push_back( eamParam.F[i] * 23.06054 );
134    }
135      
136    CubicSpline* cs = new CubicSpline();
137    cs->addPoints(rhovals, scaledF);
138    return cs;
139  }
140  
141  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {    
142    EAMParam eamParam1 = getEAMParam(atomType1);
143    EAMParam eamParam2 = getEAMParam(atomType2);
144    CubicSpline* z1 = getZ(atomType1);
145    CubicSpline* z2 = getZ(atomType2);
146
63      // make the r grid:
64  
65  
66      // we need phi out to the largest value we'll encounter in the radial space;
67      
68      RealType rmax = 0.0;
69 <    rmax = max(rmax, eamParam1.rcut);
70 <    rmax = max(rmax, eamParam1.nr * eamParam1.dr);
69 >    rmax = max(rmax, ea1.getRcut());
70 >    rmax = max(rmax, ea1.getNr() * ea1.getDr());
71  
72 <    rmax = max(rmax, eamParam2.rcut);
73 <    rmax = max(rmax, eamParam2.nr * eamParam2.dr);
72 >    rmax = max(rmax, ea2.getRcut());
73 >    rmax = max(rmax, ea2.getNr() * ea2.getDr());
74  
75      // use the smallest dr (finest grid) to build our grid:
76  
77 <    RealType dr = min(eamParam1.dr, eamParam2.dr);
77 >    RealType dr = min(ea1.getDr(), ea2.getDr());
78  
79      int nr = int(rmax/dr + 0.5);
80  
# Line 174 | Line 90 | namespace OpenMD {
90  
91      phivals.push_back(0.0);
92  
93 <    for (int i = 1; i < rvals.size(); i++ ) {
93 >    for (unsigned int i = 1; i < rvals.size(); i++ ) {
94        r = rvals[i];
95  
96        // only use z(r) if we're inside this atom's cutoff radius,
# Line 182 | Line 98 | namespace OpenMD {
98        // means that our phi grid goes out beyond the cutoff of the
99        // pair potential
100  
101 <      zi = r <= eamParam1.rcut ? z1->getValueAt(r) : 0.0;
102 <      zj = r <= eamParam2.rcut ? z2->getValueAt(r) : 0.0;
101 >      zi = r <= ea1.getRcut() ? z1->getValueAt(r) : 0.0;
102 >      zj = r <= ea2.getRcut() ? z2->getValueAt(r) : 0.0;
103  
104        phi = 331.999296 * (zi * zj) / r;
105  
# Line 201 | Line 117 | namespace OpenMD {
117    }
118  
119    void EAM::initialize() {
204
120      // set up the mixing method:
121      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
122      string EAMMixMeth = fopts.getEAMMixingMethod();
# Line 215 | Line 130 | namespace OpenMD {
130        mixMeth_ = eamUnknown;
131        
132      // find all of the EAM atom Types:
133 <    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
134 <    ForceField::AtomTypeContainer::MapTypeIterator i;
135 <    AtomType* at;
133 >    EAMtypes.clear();
134 >    EAMtids.clear();
135 >    EAMdata.clear();
136 >    MixingMap.clear();
137 >    nEAM_ = 0;
138 >    
139 >    EAMtids.resize( forceField_->getNAtomType(), -1);
140  
141 <    for (at = atomTypes->beginType(i); at != NULL;
142 <         at = atomTypes->nextType(i)) {
143 <      
225 <      if (at->isEAM())
226 <        addType(at);
141 >    set<AtomType*>::iterator at;
142 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
143 >      if ((*at)->isEAM()) nEAM_++;
144      }
145 +    EAMdata.resize(nEAM_);
146 +    MixingMap.resize(nEAM_);
147 +
148 +    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
149 +      if ((*at)->isEAM()) addType(*at);
150 +    }
151      
152      // find all of the explicit EAM interactions (setfl):
153      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
# Line 277 | Line 200 | namespace OpenMD {
200  
201    void EAM::addType(AtomType* atomType){
202  
203 +    EAMAdapter ea = EAMAdapter(atomType);
204      EAMAtomData eamAtomData;
281    
282    eamAtomData.rho = getRho(atomType);
283    eamAtomData.F = getF(atomType);
284    eamAtomData.Z = getZ(atomType);
285    eamAtomData.rcut = getRcut(atomType);
205  
206 +    eamAtomData.rho = ea.getRho();
207 +    eamAtomData.F = ea.getF();
208 +    eamAtomData.Z = ea.getZ();
209 +    eamAtomData.rcut = ea.getRcut();
210 +
211      // add it to the map:
212 <    AtomTypeProperties atp = atomType->getATP();    
212 >    int atid = atomType->getIdent();
213 >    int eamtid = EAMtypes.size();
214  
215 <    pair<map<int,AtomType*>::iterator,bool> ret;    
216 <    ret = EAMlist.insert( pair<int, AtomType*>(atp.ident, atomType) );
215 >    pair<set<int>::iterator,bool> ret;    
216 >    ret = EAMtypes.insert( atid );
217      if (ret.second == false) {
218        sprintf( painCave.errMsg,
219                 "EAM already had a previous entry with ident %d\n",
220 <               atp.ident);
220 >               atid);
221        painCave.severity = OPENMD_INFO;
222        painCave.isFatal = 0;
223        simError();        
224      }
225  
226 <    EAMMap[atomType] = eamAtomData;
226 >    EAMtids[atid] = eamtid;
227 >    EAMdata[eamtid] = eamAtomData;
228 >    MixingMap[eamtid].resize(nEAM_);
229      
230      // Now, iterate over all known types and add to the mixing map:
231      
232 <    map<AtomType*, EAMAtomData>::iterator it;
233 <    for( it = EAMMap.begin(); it != EAMMap.end(); ++it) {
232 >    std::set<int>::iterator it;
233 >    for( it = EAMtypes.begin(); it != EAMtypes.end(); ++it) {
234        
235 <      AtomType* atype2 = (*it).first;
235 >      int eamtid2 = EAMtids[ (*it) ];
236 >      AtomType* atype2 = forceField_->getAtomType( (*it) );
237  
238        EAMInteractionData mixer;
239        mixer.phi = getPhi(atomType, atype2);
240        mixer.explicitlySet = false;
241  
242 <      pair<AtomType*, AtomType*> key1, key2;
315 <      key1 = make_pair(atomType, atype2);
316 <      key2 = make_pair(atype2, atomType);
242 >      MixingMap[eamtid2].resize( nEAM_ );
243        
244 <      MixingMap[key1] = mixer;
245 <      if (key2 != key1) {
246 <        MixingMap[key2] = mixer;
244 >      MixingMap[eamtid][eamtid2] = mixer;
245 >      if (eamtid2 != eamtid) {
246 >        MixingMap[eamtid2][eamtid] = mixer;
247        }
248      }      
249      return;
# Line 341 | Line 267 | namespace OpenMD {
267      mixer.phi = cs;
268      mixer.explicitlySet = true;
269  
270 <    pair<AtomType*, AtomType*> key1, key2;
271 <    key1 = make_pair(atype1, atype2);
346 <    key2 = make_pair(atype2, atype1);
270 >    int eamtid1 = EAMtids[ atype1->getIdent() ];
271 >    int eamtid2 = EAMtids[ atype2->getIdent() ];
272      
273 <    MixingMap[key1] = mixer;
274 <    if (key2 != key1) {
275 <      MixingMap[key2] = mixer;
273 >    MixingMap[eamtid1][eamtid2] = mixer;
274 >    if (eamtid2 != eamtid1) {
275 >      MixingMap[eamtid2][eamtid1] = mixer;
276      }    
277      return;
278    }
# Line 356 | Line 281 | namespace OpenMD {
281      
282      if (!initialized_) initialize();
283      
284 <    EAMAtomData data1 = EAMMap[idat.atypes.first];
285 <    EAMAtomData data2 = EAMMap[idat.atypes.second];
286 <    
284 >    EAMAtomData &data1 = EAMdata[EAMtids[idat.atid1]];
285 >    EAMAtomData &data2 = EAMdata[EAMtids[idat.atid2]];
286 >
287      if (haveCutoffRadius_)
288        if ( *(idat.rij) > eamRcut_) return;
289      
# Line 376 | Line 301 | namespace OpenMD {
301      
302      if (!initialized_) initialize();
303  
304 <    EAMAtomData data1 = EAMMap[ sdat.atype ];
304 >    EAMAtomData &data1 = EAMdata[ EAMtids[sdat.atid] ];
305          
306 <    pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt( *(sdat.rho) );
306 >    data1.F->getValueAndDerivativeAt( *(sdat.rho), *(sdat.frho), *(sdat.dfrhodrho) );
307  
308 <    *(sdat.frho) = result.first;
309 <    *(sdat.dfrhodrho) = result.second;
308 >    (*(sdat.pot))[METALLIC_FAMILY] += *(sdat.frho);
309 >    if (sdat.doParticlePot) {
310 >      *(sdat.particlePot) += *(sdat.frho);
311 >    }
312  
386    (*(sdat.pot))[METALLIC_FAMILY] += result.first;
387    *(sdat.particlePot) += result.first;
388
313      return;
314    }
315  
# Line 397 | Line 321 | namespace OpenMD {
321      if (haveCutoffRadius_)
322        if ( *(idat.rij) > eamRcut_) return;
323    
324 <    pair<RealType, RealType> res;
324 >
325 >    int eamtid1 = EAMtids[idat.atid1];
326 >    int eamtid2 = EAMtids[idat.atid2];
327      
328 <    EAMAtomData data1 = EAMMap[idat.atypes.first];
329 <    EAMAtomData data2 = EAMMap[idat.atypes.second];
328 >    EAMAtomData &data1 = EAMdata[eamtid1];
329 >    EAMAtomData &data2 = EAMdata[eamtid2];
330      
331      // get type-specific cutoff radii
332      
# Line 413 | Line 339 | namespace OpenMD {
339      RealType drhoidr, drhojdr, dudr;
340      
341      if ( *(idat.rij) < rci) {
342 <      res = data1.rho->getValueAndDerivativeAt( *(idat.rij));
343 <      rha = res.first;
344 <      drha = res.second;
419 <      
420 <      res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) );
421 <      pha = res.first;
422 <      dpha = res.second;
342 >      data1.rho->getValueAndDerivativeAt( *(idat.rij), rha, drha);
343 >      CubicSpline* phi = MixingMap[eamtid1][eamtid1].phi;
344 >      phi->getValueAndDerivativeAt( *(idat.rij), pha, dpha);
345      }
346      
347      if ( *(idat.rij) < rcj) {
348 <      res = data2.rho->getValueAndDerivativeAt( *(idat.rij) );
349 <      rhb = res.first;
350 <      drhb = res.second;
429 <      
430 <      res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) );
431 <      phb = res.first;
432 <      dphb = res.second;
348 >      data2.rho->getValueAndDerivativeAt( *(idat.rij), rhb, drhb );
349 >      CubicSpline* phi = MixingMap[eamtid2][eamtid2].phi;
350 >      phi->getValueAndDerivativeAt( *(idat.rij), phb, dphb);
351      }
352  
353      switch(mixMeth_) {
# Line 452 | Line 370 | namespace OpenMD {
370        break;
371        
372      case eamDaw:
373 <      res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij));
456 <      phab = res.first;
457 <      dvpdr = res.second;
373 >      MixingMap[eamtid1][eamtid2].phi->getValueAndDerivativeAt( *(idat.rij), phab, dvpdr);
374        
375        break;
376      case eamUnknown:
# Line 476 | Line 392 | namespace OpenMD {
392      
393      *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
394          
395 <    // particlePot is the difference between the full potential and
396 <    // the full potential without the presence of a particular
397 <    // particle (atom1).
398 <    //
399 <    // This reduces the density at other particle locations, so we
400 <    // need to recompute the density at atom2 assuming atom1 didn't
401 <    // contribute.  This then requires recomputing the density
402 <    // functional for atom2 as well.
395 >    if (idat.doParticlePot) {
396 >      // particlePot is the difference between the full potential and
397 >      // the full potential without the presence of a particular
398 >      // particle (atom1).
399 >      //
400 >      // This reduces the density at other particle locations, so we
401 >      // need to recompute the density at atom2 assuming atom1 didn't
402 >      // contribute.  This then requires recomputing the density
403 >      // functional for atom2 as well.
404 >      
405 >      *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
406 >        - *(idat.frho2);
407 >      
408 >      *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
409 >        - *(idat.frho1);
410 >    }
411      
488    *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
489      - *(idat.frho2);
490    
491    *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
492      - *(idat.frho1);
493    
412      (*(idat.pot))[METALLIC_FAMILY] += phab;
413      
414      *(idat.vpair) += phab;
# Line 504 | Line 422 | namespace OpenMD {
422  
423      RealType cut = 0.0;
424  
425 <    map<AtomType*, EAMAtomData>::iterator it;
426 <
427 <    it = EAMMap.find(atypes.first);
428 <    if (it != EAMMap.end()) {
429 <      EAMAtomData data1 = (*it).second;
425 >    int atid1 = atypes.first->getIdent();
426 >    int atid2 = atypes.second->getIdent();
427 >    int eamtid1 = EAMtids[atid1];
428 >    int eamtid2 = EAMtids[atid2];
429 >    
430 >    if (eamtid1 != -1) {
431 >      EAMAtomData data1 = EAMdata[eamtid1];
432        cut = data1.rcut;
433      }
434  
435 <    it = EAMMap.find(atypes.second);
436 <    if (it != EAMMap.end()) {
517 <      EAMAtomData data2 = (*it).second;
435 >    if (eamtid2 != -1) {
436 >      EAMAtomData data2 = EAMdata[eamtid2];
437        if (data2.rcut > cut)
438          cut = data2.rcut;
439      }
440 <
440 >    
441      return cut;
442    }
443   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines