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 1478 by gezelter, Fri Jul 23 20:45:40 2010 UTC vs.
trunk/src/nonbonded/EAM.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/EAM.hpp"
48   #include "utils/simError.h"
49 + #include "types/NonBondedInteractionType.hpp"
50  
51  
52   namespace OpenMD {
53  
54 <  bool EAM::initialized_ = false;
55 <  ForceField* EAM::forceField_ = NULL;
54 <  std::map<int, AtomType*> EAM::EAMlist;
55 <  std::map<AtomType*, EAMAtomData> EAM::EAMMap;
56 <  std::map<std::pair<AtomType*, AtomType*>, EAMInteractionData> EAM::MixingMap;
54 >  EAM::EAM() : name_("EAM"), initialized_(false), forceField_(NULL),
55 >               mixMeth_(eamJohnson), eamRcut_(0.0), haveCutoffRadius_(false) {}
56    
57 <  EAM* EAM::_instance = NULL;
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  
63 <  EAM* EAM::Instance() {
64 <    if (!_instance) {
65 <      _instance = new EAM();
66 <    }
67 <    return _instance;
65 <  }
66 <  
67 <  EAMParam EAM::getEAMParam(AtomType* atomType) {
68 <    
69 <    // Do sanity checking on the AtomType we were passed before
70 <    // building any data structures:
71 <    if (!atomType->isEAM()) {
72 <      sprintf( painCave.errMsg,
73 <               "EAM::getEAMParam was passed an atomType (%s) that does not\n"
74 <               "\tappear to be an embedded atom method (EAM) atom.\n",
75 <               atomType->getName().c_str());
76 <      painCave.severity = OPENMD_ERROR;
77 <      painCave.isFatal = 1;
78 <      simError();
79 <    }
80 <    
81 <    GenericData* data = atomType->getPropertyByName("EAM");
82 <    if (data == NULL) {
83 <      sprintf( painCave.errMsg, "EAM::getEAMParam could not find EAM\n"
84 <               "\tparameters for atomType %s.\n",
85 <               atomType->getName().c_str());
86 <      painCave.severity = OPENMD_ERROR;
87 <      painCave.isFatal = 1;
88 <      simError();
89 <    }
90 <    
91 <    EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data);
92 <    if (eamData == NULL) {
93 <      sprintf( painCave.errMsg,
94 <               "EAM::getEAMParam could not convert GenericData to EAMParam for\n"
95 <               "\tatom type %s\n", atomType->getName().c_str());
96 <      painCave.severity = OPENMD_ERROR;
97 <      painCave.isFatal = 1;
98 <      simError();          
99 <    }
100 <    
101 <    return eamData->getData();
102 <  }
63 >    // Thise prefactors convert the charge-charge interactions into
64 >    // kcal / mol all were computed assuming distances are measured in
65 >    // angstroms Charge-Charge, assuming charges are measured in
66 >    // electrons.  Matches value in Electrostatics.cpp
67 >    pre11_ = 332.0637778;
68  
69 <  CubicSpline* EAM::getZ(AtomType* atomType) {    
105 <    EAMParam eamParam = getEAMParam(atomType);
106 <    int nr = eamParam.nr;
107 <    RealType dr = eamParam.dr;
108 <    vector<RealType> rvals;
109 <    
110 <    for (int i = 0; i < nr; i++) rvals.push_back(i * dr);
111 <      
112 <    CubicSpline* cs = new CubicSpline();
113 <    cs->addPoints(rvals, eamParam.Z);
114 <    return cs;
115 <  }
69 >    // make the r grid:
70  
71 <  CubicSpline* EAM::getRho(AtomType* atomType) {    
118 <    EAMParam eamParam = getEAMParam(atomType);
119 <    int nr = eamParam.nr;
120 <    RealType dr = eamParam.dr;
121 <    vector<RealType> rvals;
71 >    // we need phi out to the largest value we'll encounter in the radial space;
72      
73 <    for (int i = 0; i < nr; i++) rvals.push_back(i * dr);
74 <      
75 <    CubicSpline* cs = new CubicSpline();
126 <    cs->addPoints(rvals, eamParam.rho);
127 <    return cs;
128 <  }
73 >    RealType rmax = 0.0;
74 >    rmax = max(rmax, ea1.getRcut());
75 >    rmax = max(rmax, ea1.getNr() * ea1.getDr());
76  
77 <  CubicSpline* EAM::getF(AtomType* atomType) {    
78 <    EAMParam eamParam = getEAMParam(atomType);
132 <    int nrho = eamParam.nrho;
133 <    RealType drho = eamParam.drho;
134 <    vector<RealType> rhovals;
135 <    vector<RealType> scaledF;
136 <    
137 <    for (int i = 0; i < nrho; i++) {
138 <      rhovals.push_back(i * drho);
139 <      scaledF.push_back( eamParam.F[i] * 23.06054 );
140 <    }
141 <      
142 <    CubicSpline* cs = new CubicSpline();
143 <    cs->addPoints(rhovals, eamParam.F);
144 <    return cs;
145 <  }
146 <  
147 <  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {    
148 <    EAMParam eamParam1 = getEAMParam(atomType1);
149 <    EAMParam eamParam2 = getEAMParam(atomType2);
150 <    CubicSpline* z1 = getZ(atomType1);
151 <    CubicSpline* z2 = getZ(atomType2);
77 >    rmax = max(rmax, ea2.getRcut());
78 >    rmax = max(rmax, ea2.getNr() * ea2.getDr());
79  
80 <    // make the r grid:
80 >    // use the smallest dr (finest grid) to build our grid:
81  
82 <    // set rcut to be the smaller of the two atomic rcuts
82 >    RealType dr = min(ea1.getDr(), ea2.getDr());
83  
84 <    RealType rcut = eamParam1.rcut < eamParam2.rcut ?
158 <      eamParam1.rcut : eamParam2.rcut;
84 >    int nr = int(rmax/dr + 0.5);
85  
160    // use the smallest dr (finest grid) to build our grid:
161
162    RealType dr = eamParam1.dr < eamParam2.dr ? eamParam1.dr : eamParam2.dr;
163    int nr = int(rcut/dr);
86      vector<RealType> rvals;
87 <    for (int i = 0; i < nr; i++) rvals.push_back(i*dr);
87 >    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i*dr));
88  
89      // construct the pair potential:
90  
# Line 173 | Line 95 | namespace OpenMD {
95  
96      phivals.push_back(0.0);
97  
98 <    for (int i = 1; i < rvals.size(); i++ ) {
98 >    for (unsigned int i = 1; i < rvals.size(); i++ ) {
99        r = rvals[i];
178      zi = z1->getValueAt(r);
179      zj = z2->getValueAt(r);
100  
101 <      phi = 331.999296 * (zi * zj) / r;
101 >      // only use z(r) if we're inside this atom's cutoff radius,
102 >      // otherwise, we'll use zero for the charge.  This effectively
103 >      // means that our phi grid goes out beyond the cutoff of the
104 >      // pair potential
105 >
106 >      zi = r <= ea1.getRcut() ? z1->getValueAt(r) : 0.0;
107 >      zj = r <= ea2.getRcut() ? z2->getValueAt(r) : 0.0;
108 >
109 >      phi = pre11_ * (zi * zj) / r;
110 >      
111        phivals.push_back(phi);
112      }
184      
113      CubicSpline* cs = new CubicSpline();
114      cs->addPoints(rvals, phivals);
115      return cs;
116    }
117  
118 <  void EAM::initialize() {
118 >  void EAM::setCutoffRadius( RealType rCut ) {
119 >    eamRcut_ = rCut;
120 >    haveCutoffRadius_ = true;
121 >  }
122  
123 +  void EAM::initialize() {
124      // set up the mixing method:
125 <    ForceFieldOptions ffo = forceField_->getForceFieldOptions();
126 <    string EAMMixMeth = toUpperCopy(ffo.getEAMMixingMethod());
127 <
125 >    ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
126 >    string EAMMixMeth = fopts.getEAMMixingMethod();
127 >    toUpper(EAMMixMeth);
128 >  
129      if (EAMMixMeth == "JOHNSON")
130        mixMeth_ = eamJohnson;    
131      else if (EAMMixMeth == "DAW")
# Line 201 | Line 134 | namespace OpenMD {
134        mixMeth_ = eamUnknown;
135        
136      // find all of the EAM atom Types:
137 <    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
138 <    ForceField::AtomTypeContainer::MapTypeIterator i;
139 <    AtomType* at;
137 >    EAMtypes.clear();
138 >    EAMtids.clear();
139 >    EAMdata.clear();
140 >    MixingMap.clear();
141 >    nEAM_ = 0;
142 >    
143 >    EAMtids.resize( forceField_->getNAtomType(), -1);
144  
145 <    for (at = atomTypes->beginType(i); at != NULL;
146 <         at = atomTypes->nextType(i)) {
147 <      
211 <      if (at->isEAM())
212 <        addType(at);
145 >    set<AtomType*>::iterator at;
146 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
147 >      if ((*at)->isEAM()) nEAM_++;
148      }
149 +    EAMdata.resize(nEAM_);
150 +    MixingMap.resize(nEAM_);
151 +
152 +    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
153 +      if ((*at)->isEAM()) addType(*at);
154 +    }
155      
156      // find all of the explicit EAM interactions (setfl):
157      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
# Line 222 | Line 163 | namespace OpenMD {
163        
164        if (nbt->isEAM()) {
165          
166 <        std::pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
166 >        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
167          
168          GenericData* data = nbt->getPropertyByName("EAM");
169          if (data == NULL) {
# Line 247 | Line 188 | namespace OpenMD {
188            simError();          
189          }
190          
191 <        EAMMix eamParam = eamData->getData();
191 >        EAMMixingParam eamParam = eamData->getData();
192  
193 <        vector<RealType> phiAB = eamParam.phiAB;
193 >        vector<RealType> phiAB = eamParam.phi;
194          RealType dr = eamParam.dr;
195          int nr = eamParam.nr;
196  
# Line 263 | Line 204 | namespace OpenMD {
204  
205    void EAM::addType(AtomType* atomType){
206  
207 +    EAMAdapter ea = EAMAdapter(atomType);
208      EAMAtomData eamAtomData;
209  
210 <    eamAtomData.rho = getRho(atomType);
211 <    eamAtomData.F = getF(atomType);
212 <    eamAtomData.Z = getZ(atomType);
213 <    eamAtomData.rcut = getRcut(atomType);
214 <
210 >    eamAtomData.rho = ea.getRho();
211 >    eamAtomData.F = ea.getF();
212 >    eamAtomData.Z = ea.getZ();
213 >    eamAtomData.rcut = ea.getRcut();
214 >      
215      // add it to the map:
216 <    AtomTypeProperties atp = atomType->getATP();    
216 >    int atid = atomType->getIdent();
217 >    int eamtid = EAMtypes.size();
218  
219 <    std::pair<std::map<int,AtomType*>::iterator,bool> ret;    
220 <    ret = EAMlist.insert( std::pair<int, AtomType*>(atp.ident, atomType) );
219 >    pair<set<int>::iterator,bool> ret;    
220 >    ret = EAMtypes.insert( atid );
221      if (ret.second == false) {
222        sprintf( painCave.errMsg,
223                 "EAM already had a previous entry with ident %d\n",
224 <               atp.ident);
224 >               atid);
225        painCave.severity = OPENMD_INFO;
226        painCave.isFatal = 0;
227        simError();        
228      }
229  
230 <    EAMMap[atomType] = eamAtomData;
230 >
231 >    EAMtids[atid] = eamtid;
232 >    EAMdata[eamtid] = eamAtomData;
233 >    MixingMap[eamtid].resize(nEAM_);
234      
235      // Now, iterate over all known types and add to the mixing map:
236      
237 <    std::map<int, AtomType*>::iterator it;
238 <    for( it = EAMMap.begin(); it != EAMMap.end(); ++it) {
237 >    std::set<int>::iterator it;
238 >    for( it = EAMtypes.begin(); it != EAMtypes.end(); ++it) {
239        
240 <      AtomType* atype2 = (*it).second;
240 >      int eamtid2 = EAMtids[ (*it) ];
241 >      AtomType* atype2 = forceField_->getAtomType( (*it) );
242  
243        EAMInteractionData mixer;
244        mixer.phi = getPhi(atomType, atype2);
245 +      mixer.rcut = mixer.phi->getLimits().second;
246        mixer.explicitlySet = false;
247  
248 <      std::pair<AtomType*, AtomType*> key1, key2;
301 <      key1 = std::make_pair(atomType, atype2);
302 <      key2 = std::make_pair(atype2, atomType);
248 >      MixingMap[eamtid2].resize( nEAM_ );
249        
250 <      MixingMap[key1] = mixer;
251 <      if (key2 != key1) {
252 <        MixingMap[key2] = mixer;
250 >      MixingMap[eamtid][eamtid2] = mixer;
251 >      if (eamtid2 != eamtid) {
252 >        MixingMap[eamtid2][eamtid] = mixer;
253        }
254      }      
255      return;
# Line 319 | Line 265 | namespace OpenMD {
265  
266      EAMInteractionData mixer;
267      CubicSpline* cs = new CubicSpline();
268 <    vector<RealType> rvals;
268 >    vector<RealType> rVals;
269  
270 <    for (int i = 0; i < nr; i++) rvals.push_back(i * dr);
270 >    for (int i = 0; i < nr; i++) rVals.push_back(i * dr);
271  
272      cs->addPoints(rVals, phiVals);
273      mixer.phi = cs;
274 +    mixer.rcut = mixer.phi->getLimits().second;
275      mixer.explicitlySet = true;
276  
277 <    std::pair<AtomType*, AtomType*> key1, key2;
278 <    key1 = std::make_pair(atype1, atype2);
332 <    key2 = std::make_pair(atype2, atype1);
277 >    int eamtid1 = EAMtids[ atype1->getIdent() ];
278 >    int eamtid2 = EAMtids[ atype2->getIdent() ];
279      
280 <    MixingMap[key1] = mixer;
281 <    if (key2 != key1) {
282 <      MixingMap[key2] = mixer;
280 >    MixingMap[eamtid1][eamtid2] = mixer;
281 >    if (eamtid2 != eamtid1) {
282 >      MixingMap[eamtid2][eamtid1] = mixer;
283      }    
284      return;
285    }
286  
287 <  void EAM::calcDensity(AtomType* at1, AtomType* at2, Vector3d d,
288 <                        RealType rij, RealType r2, RealType rho_i_at_j,
343 <                        RealType rho_j_at_i) {
344 <
287 >  void EAM::calcDensity(InteractionData &idat) {
288 >    
289      if (!initialized_) initialize();
290 +    
291 +    EAMAtomData &data1 = EAMdata[EAMtids[idat.atid1]];
292 +    EAMAtomData &data2 = EAMdata[EAMtids[idat.atid2]];
293  
294 <    EAMAtomData data1 = EAMMap[at1];
295 <    EAMAtomData data2 = EAMMap[at2];
296 <
297 <    if (rij < data1.rcut) rho_i_at_j = data1.rho->getValueAt(rij);
298 <    if (rij < data2.rcut) rho_j_at_i = data2.rho->getValueAt(rij);
299 <    return;
294 >    if (haveCutoffRadius_)
295 >      if ( *(idat.rij) > eamRcut_) return;
296 >    
297 >    if ( *(idat.rij) < data1.rcut) {
298 >      *(idat.rho2) += data1.rho->getValueAt( *(idat.rij));
299 >    }
300 >      
301 >    if ( *(idat.rij) < data2.rcut) {
302 >      *(idat.rho1) += data2.rho->getValueAt( *(idat.rij));
303 >    }
304 >    
305 >    return;  
306    }
307 <
308 <  void EAM::calcFunctional(AtomType* at1, RealType rho, RealType frho,
309 <                           RealType dfrhodrho) {
357 <
307 >  
308 >  void EAM::calcFunctional(SelfData &sdat) {
309 >    
310      if (!initialized_) initialize();
311 +    EAMAtomData &data1 = EAMdata[ EAMtids[sdat.atid] ];
312 +            
313 +    data1.F->getValueAndDerivativeAt( *(sdat.rho), *(sdat.frho), *(sdat.dfrhodrho) );
314  
315 <    EAMAtomData data1 = EAMMap[at1];
316 <        
317 <    pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt(rho);
315 >    (*(sdat.pot))[METALLIC_FAMILY] += *(sdat.frho);
316 >    if (sdat.doParticlePot) {
317 >      *(sdat.particlePot) += *(sdat.frho);
318 >    }
319  
364    frho = result.first;
365    dfrhodrho = result.second;
320      return;
321    }
322  
323  
324 <  void EAM::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
371 <                      RealType rij, RealType r2, RealType sw,
372 <                      RealType &vpair, RealType &pot, Vector3d &f1,
373 <                      RealType rho1, RealType rho2, RealType dfrho1,
374 <                      RealType dfrho2, RealType fshift1, RealType fshift2) {
324 >  void EAM::calcForce(InteractionData &idat) {
325  
326      if (!initialized_) initialize();
327 +
328 +    if (haveCutoffRadius_)
329 +      if ( *(idat.rij) > eamRcut_) return;
330 +  
331 +
332 +    int eamtid1 = EAMtids[idat.atid1];
333 +    int eamtid2 = EAMtids[idat.atid2];
334 +    EAMAtomData &data1 = EAMdata[eamtid1];
335 +    EAMAtomData &data2 = EAMdata[eamtid2];
336      
337 <    pair<RealType, RealType> res;
337 >    // get type-specific cutoff radii
338      
339 <    if (rij < eamRcut_) {
339 >    RealType rci = data1.rcut;
340 >    RealType rcj = data2.rcut;
341  
342 <      EAMAtomData data1 = EAMMap[at1];
343 <      EAMAtomData data2 = EAMMap[at2];
344 <
345 <      // get type-specific cutoff radii
346 <
347 <      RealType rci = data1.rcut;
348 <      RealType rcj = data2.rcut;
342 >    
343 >    RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0);
344 >    RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0);
345 >    RealType phab(0.0), dvpdr(0.0);
346 >    RealType drhoidr, drhojdr, dudr;
347 >    
348 >    if ( *(idat.rij) < rci) {
349 >      data1.rho->getValueAndDerivativeAt( *(idat.rij), rha, drha);
350 >      CubicSpline* phi = MixingMap[eamtid1][eamtid1].phi;
351 >      phi->getValueAndDerivativeAt( *(idat.rij), pha, dpha);
352 >    }
353 >    
354 >    if ( *(idat.rij) < rcj) {
355 >      data2.rho->getValueAndDerivativeAt( *(idat.rij), rhb, drhb );
356 >      CubicSpline* phi = MixingMap[eamtid2][eamtid2].phi;
357 >      phi->getValueAndDerivativeAt( *(idat.rij), phb, dphb);
358 >    }
359 >    switch(mixMeth_) {
360 >    case eamJohnson:
361 >      if ( *(idat.rij) < rci) {
362 >        phab = phab + 0.5 * (rhb / rha) * pha;
363 >        dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
364 >                             pha*((drhb/rha) - (rhb*drha/rha/rha)));
365 >      }
366        
390      RealType rha, drha, rhb, drhb;
391      RealType pha, dpha, phb, dphb;
392      RealType phab, dvpdr;
393      RealType drhoidr, drhojdr, dudr;
367        
368 <      if (rij < rci) {
369 <        res = data1.rho->getValueAndDerivativeAt(rij);
370 <        rha = res.first;
371 <        drha = res.second;
372 <
400 <        res = MixingMap[make_pair(at1, at1)].phi->getValueAndDerivativeAt(rij);
401 <        pha = res.first;
402 <        dpha = res.second;
368 >      
369 >      if ( *(idat.rij) < rcj) {
370 >        phab = phab + 0.5 * (rha / rhb) * phb;
371 >        dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
372 >                               phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
373        }
374 <
375 <      if (rij < rcj) {
376 <        res = data2.rho->getValueAndDerivativeAt(rij);
377 <        rhb = res.first;
378 <        drhb = res.second;
409 <
410 <        res = MixingMap[make_pair(at2, at2)].phi->getValueAndDerivativeAt(rij);
411 <        phb = res.first;
412 <        dphb = res.second;
374 >      break;
375 >    case eamDaw:
376 >      if ( *(idat.rij) <  MixingMap[eamtid1][eamtid2].rcut) {
377 >        MixingMap[eamtid1][eamtid2].phi->getValueAndDerivativeAt( *(idat.rij),
378 >                                                                  phab, dvpdr);
379        }
380 <
381 <      phab = 0.0;
382 <      dvpdr = 0.0;
417 <
418 <      switch(mixMeth_) {
419 <      case eamJohnson:
420 <      
421 <        if (rij < rci) {
422 <          phab = phab + 0.5 * (rhb / rha) * pha;
423 <          dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
424 <                               pha*((drhb/rha) - (rhb*drha/rha/rha)));
425 <        }
426 <
427 <        if (rij < rcj) {
428 <          phab = phab + 0.5 * (rha / rhb) * phb;
429 <          dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
430 <                                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
431 <        }
432 <
433 <        break;
434 <
435 <      case eamDaw:
436 <                
437 <        res = MixingMap[make_pair(at1,at2)].phi->getValueAndDerivativeAt(rij);
438 <        phab = res.first;
439 <        dvpdr = res.second;
440 <
441 <        break;
442 <      case eamUnknown:
443 <      default:
444 <
445 <        sprintf(painCave.errMsg,
446 <                "EAM::calcForce hit a mixing method it doesn't know about!\n"
447 <                );
448 <        painCave.severity = OPENMD_ERROR;
449 <        painCave.isFatal = 1;
450 <        simError();        
451 <          
452 <      }
380 >      break;
381 >    case eamUnknown:
382 >    default:
383        
384 <      drhoidr = drha;
385 <      drhojdr = drhb;
384 >      sprintf(painCave.errMsg,
385 >              "EAM::calcForce hit a mixing method it doesn't know about!\n"
386 >              );
387 >      painCave.severity = OPENMD_ERROR;
388 >      painCave.isFatal = 1;
389 >      simError();        
390 >      
391 >    }
392 >    
393 >    drhoidr = drha;
394 >    drhojdr = drhb;
395 >    
396 >    dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr;
397 >    
398 >    *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
399  
457      dudr = drhojdr*dfrhodrho_i + drhoidr*dfrhodrho_j + dvpdr;
458
459      f1 = d * dudr / rij;
400          
401 <      // particle_pot is the difference between the full potential
402 <      // and the full potential without the presence of a particular
401 >    if (idat.doParticlePot) {
402 >      // particlePot is the difference between the full potential and
403 >      // the full potential without the presence of a particular
404        // particle (atom1).
405        //
406 <      // This reduces the density at other particle locations, so
407 <      // we need to recompute the density at atom2 assuming atom1
408 <      // didn't contribute.  This then requires recomputing the
409 <      // density functional for atom2 as well.
410 <      //
411 <      // Most of the particle_pot heavy lifting comes from the
412 <      // pair interaction, and will be handled by vpair.
413 <    
414 <      fshift_i = data1.F->getValueAt( rho_i - rhb );
415 <      fshift_j = data1.F->getValueAt( rho_j - rha );
475 <
476 <      pot += phab;
477 <
478 <      vpair += phab;
406 >      // This reduces the density at other particle locations, so we
407 >      // need to recompute the density at atom2 assuming atom1 didn't
408 >      // contribute.  This then requires recomputing the density
409 >      // functional for atom2 as well.
410 >      
411 >      *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
412 >        - *(idat.frho2);
413 >      
414 >      *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
415 >        - *(idat.frho1);
416      }
417 <
417 >    
418 >    (*(idat.pot))[METALLIC_FAMILY] += phab;
419 >    
420 >    *(idat.vpair) += phab;
421 >  
422      return;
423      
424    }
425  
426 +  RealType EAM::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
427 +    if (!initialized_) initialize();  
428  
429 <  void EAM::calc_eam_prepair_rho(int *atid1, int *atid2, RealType *d,
487 <                                 RealType *rij, RealType *r2,
488 <                                 RealType* rho_i_at_j, RealType* rho_j_at_i){
489 <    if (!initialized_) initialize();
429 >    RealType cut = 0.0;
430  
431 <    AtomType* atype1 = EAMlist[*atid1];
432 <    AtomType* atype2 = EAMlist[*atid2];
431 >    int atid1 = atypes.first->getIdent();
432 >    int atid2 = atypes.second->getIdent();
433 >    int eamtid1 = EAMtids[atid1];
434 >    int eamtid2 = EAMtids[atid2];
435      
436 <    Vector3d disp(d[0], d[1], d[2]);
436 >    if (eamtid1 != -1) {
437 >      EAMAtomData data1 = EAMdata[eamtid1];
438 >      cut = data1.rcut;
439 >    }
440  
441 <    calcDensity(atype1, atype2, disp, *rij, *r2, *rho_i_at_j, *rho_j_at_i);
442 <
443 <    return;    
444 <  }
445 <
501 <  void EAM::calc_eam_preforce_Frho(int *atid1, RealType *rho, RealType *frho,
502 <                                   RealType *dfrhodrho) {
503 <
504 <    if (!initialized_) initialize();
505 <
506 <    AtomType* atype1 = EAMlist[*atid1];  
507 <
508 <    calcFunctional(atype1, *rho, *frho, *dfrhodrho);
441 >    if (eamtid2 != -1) {
442 >      EAMAtomData data2 = EAMdata[eamtid2];
443 >      if (data2.rcut > cut)
444 >        cut = data2.rcut;
445 >    }
446      
447 <    return;    
447 >    return cut;
448    }
512
513  void EAM::do_eam_pair(int *atid1, int *atid2, RealType *d, RealType *rij,
514                        RealType *r2, RealType *sw, RealType *vpair,
515                        RealType *pot, RealType *f1, RealType *rho1,
516                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
517                        RealType *fshift1, RealType *fshift2) {
518
519    if (!initialized_) initialize();
520    
521    AtomType* atype1 = EAMMap[*atid1];
522    AtomType* atype2 = EAMMap[*atid2];
523    
524    Vector3d disp(d[0], d[1], d[2]);
525    Vector3d frc(f1[0], f1[1], f1[2]);
526    
527    calcForce(atype1, atype2, disp, *rij, *r2, *sw, *vpair,  *pot, frc,
528              *rho1, *rho2, *dfrho1, *dfrho2, *fshift1, *fshift2);
529      
530    f1[0] = frc.x();
531    f1[1] = frc.y();
532    f1[2] = frc.z();
533
534    return;    
535  }
536  
537  void EAM::setCutoffEAM(RealType *thisRcut) {
538    eamRcut_ = thisRcut;
539  }
449   }
450  
542 extern "C" {
543  
544 #define fortranCalcDensity FC_FUNC(calc_eam_prepair_rho, CALC_EAM_PREPAIR_RHO)
545 #define fortranCalcFunctional FC_FUNC(calc_eam_preforce_frho, CALC_EAM_PREFORCE_FRHO)
546 #define fortranCalcForce FC_FUNC(do_eam_pair, DO_EAM_PAIR)
547 #define fortranSetCutoffEAM FC_FUNC(setcutoffeam, SETCUTOFFEAM)
548  
549  RealType fortranCalcDensity(int *atid1, int *atid2, RealType *d,
550                              RealType *rij, RealType *r2,
551                              RealType *rho_i_at_j, RealType *rho_j_at_i) {
552
553    return OpenMD::EAM::Instance()->calc_eam_prepair_rho(*atid1, *atid2, *d,
554                                                         *rij, *r2,
555                                                         *rho_i_at_j,  
556                                                         *rho_j_at_i);
557  }
558  RealType fortranCalcFunctional(int *atid1, RealType *rho, RealType *frho,
559                                 RealType *dfrhodrho) {  
560
561    return OpenMD::EAM::Instance()->calc_eam_preforce_Frho(*atid1,
562                                                           *rho,
563                                                           *frho,
564                                                           *dfrhodrho);
565
566  }
567  void fortranSetEAMCutoff(RealType *rcut) {
568    return OpenMD::EAM::Instance()->setCutoffEAM(rcut);
569  }
570  void fortranDoEAMPair(int *atid1, int *atid2, RealType *d, RealType *rij,
571                        RealType *r2, RealType *sw, RealType *vpair,
572                        RealType *pot, RealType *f1, RealType *rho1,
573                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
574                        RealType *fshift1, RealType *fshift2){
575    
576    return OpenMD::EAM::Instance()->do_eam_pair(*atid1, *atid2, *d, *rij,
577                                                *r2, *sw,  *vpair,
578                                                *pot, *f1,  *rho1,
579                                                *rho2,  *dfrho1,  *dfrho2,
580                                                *fshift1,  *fshift2);
581  }
582 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines