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 1479 by gezelter, Mon Jul 26 19:00:48 2010 UTC vs.
trunk/src/nonbonded/EAM.cpp (file contents), Revision 1928 by gezelter, Sat Aug 17 13:03:17 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 50 | Line 51 | namespace OpenMD {
51  
52   namespace OpenMD {
53  
54 <  bool EAM::initialized_ = false;
55 <  RealType EAM::eamRcut_ = 0.0;
55 <  EAMMixingMethod EAM::mixMeth_ = eamJohnson;
56 <  ForceField* EAM::forceField_ = NULL;
57 <  std::map<int, AtomType*> EAM::EAMlist;
58 <  std::map<AtomType*, EAMAtomData> EAM::EAMMap;
59 <  std::map<std::pair<AtomType*, AtomType*>, EAMInteractionData> EAM::MixingMap;
60 <
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;
69 <  }
70 <  
71 <  EAMParam EAM::getEAMParam(AtomType* atomType) {
72 <    
73 <    // Do sanity checking on the AtomType we were passed before
74 <    // building any data structures:
75 <    if (!atomType->isEAM()) {
76 <      sprintf( painCave.errMsg,
77 <               "EAM::getEAMParam was passed an atomType (%s) that does not\n"
78 <               "\tappear to be an embedded atom method (EAM) atom.\n",
79 <               atomType->getName().c_str());
80 <      painCave.severity = OPENMD_ERROR;
81 <      painCave.isFatal = 1;
82 <      simError();
83 <    }
84 <    
85 <    GenericData* data = atomType->getPropertyByName("EAM");
86 <    if (data == NULL) {
87 <      sprintf( painCave.errMsg, "EAM::getEAMParam could not find EAM\n"
88 <               "\tparameters for atomType %s.\n",
89 <               atomType->getName().c_str());
90 <      painCave.severity = OPENMD_ERROR;
91 <      painCave.isFatal = 1;
92 <      simError();
93 <    }
94 <    
95 <    EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data);
96 <    if (eamData == NULL) {
97 <      sprintf( painCave.errMsg,
98 <               "EAM::getEAMParam could not convert GenericData to EAMParam for\n"
99 <               "\tatom type %s\n", atomType->getName().c_str());
100 <      painCave.severity = OPENMD_ERROR;
101 <      painCave.isFatal = 1;
102 <      simError();          
103 <    }
104 <    
105 <    return eamData->getData();
106 <  }
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) {    
109 <    EAMParam eamParam = getEAMParam(atomType);
110 <    int nr = eamParam.nr;
111 <    RealType dr = eamParam.dr;
112 <    vector<RealType> rvals;
113 <    
114 <    for (int i = 0; i < nr; i++) rvals.push_back(i * dr);
115 <      
116 <    CubicSpline* cs = new CubicSpline();
117 <    cs->addPoints(rvals, eamParam.Z);
118 <    return cs;
119 <  }
69 >    // make the r grid:
70  
71 <  RealType EAM::getRcut(AtomType* atomType) {    
122 <    EAMParam eamParam = getEAMParam(atomType);
123 <    return eamParam.rcut;
124 <  }
125 <
126 <  CubicSpline* EAM::getRho(AtomType* atomType) {    
127 <    EAMParam eamParam = getEAMParam(atomType);
128 <    int nr = eamParam.nr;
129 <    RealType dr = eamParam.dr;
130 <    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();
135 <    cs->addPoints(rvals, eamParam.rho);
136 <    return cs;
137 <  }
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);
141 <    int nrho = eamParam.nrho;
142 <    RealType drho = eamParam.drho;
143 <    vector<RealType> rhovals;
144 <    vector<RealType> scaledF;
145 <    
146 <    for (int i = 0; i < nrho; i++) {
147 <      rhovals.push_back(i * drho);
148 <      scaledF.push_back( eamParam.F[i] * 23.06054 );
149 <    }
150 <      
151 <    CubicSpline* cs = new CubicSpline();
152 <    cs->addPoints(rhovals, eamParam.F);
153 <    return cs;
154 <  }
155 <  
156 <  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {    
157 <    EAMParam eamParam1 = getEAMParam(atomType1);
158 <    EAMParam eamParam2 = getEAMParam(atomType2);
159 <    CubicSpline* z1 = getZ(atomType1);
160 <    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 ?
167 <      eamParam1.rcut : eamParam2.rcut;
84 >    int nr = int(rmax/dr + 0.5);
85  
169    // use the smallest dr (finest grid) to build our grid:
170
171    RealType dr = eamParam1.dr < eamParam2.dr ? eamParam1.dr : eamParam2.dr;
172    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 182 | 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];
187      zi = z1->getValueAt(r);
188      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      }
113        
# Line 196 | Line 116 | namespace OpenMD {
116      return cs;
117    }
118  
119 <  void EAM::initialize() {
119 >  void EAM::setCutoffRadius( RealType rCut ) {
120 >    eamRcut_ = rCut;
121 >    haveCutoffRadius_ = true;
122 >  }
123  
124 +  void EAM::initialize() {
125      // set up the mixing method:
126      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
127 <    string EAMMixMeth = toUpperCopy(fopts.getEAMMixingMethod());
128 <
127 >    string EAMMixMeth = fopts.getEAMMixingMethod();
128 >    toUpper(EAMMixMeth);
129 >  
130      if (EAMMixMeth == "JOHNSON")
131        mixMeth_ = eamJohnson;    
132      else if (EAMMixMeth == "DAW")
# Line 210 | Line 135 | namespace OpenMD {
135        mixMeth_ = eamUnknown;
136        
137      // find all of the EAM atom Types:
138 <    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
139 <    ForceField::AtomTypeContainer::MapTypeIterator i;
140 <    AtomType* at;
138 >    EAMtypes.clear();
139 >    EAMtids.clear();
140 >    EAMdata.clear();
141 >    MixingMap.clear();
142 >    nEAM_ = 0;
143 >    
144 >    EAMtids.resize( forceField_->getNAtomType(), -1);
145  
146 <    for (at = atomTypes->beginType(i); at != NULL;
147 <         at = atomTypes->nextType(i)) {
148 <      
220 <      if (at->isEAM())
221 <        addType(at);
146 >    set<AtomType*>::iterator at;
147 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
148 >      if ((*at)->isEAM()) nEAM_++;
149      }
150 +    EAMdata.resize(nEAM_);
151 +    MixingMap.resize(nEAM_);
152 +
153 +    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
154 +      if ((*at)->isEAM()) addType(*at);
155 +    }
156      
157      // find all of the explicit EAM interactions (setfl):
158      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
# Line 231 | Line 164 | namespace OpenMD {
164        
165        if (nbt->isEAM()) {
166          
167 <        std::pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
167 >        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
168          
169          GenericData* data = nbt->getPropertyByName("EAM");
170          if (data == NULL) {
# Line 272 | Line 205 | namespace OpenMD {
205  
206    void EAM::addType(AtomType* atomType){
207  
208 +    EAMAdapter ea = EAMAdapter(atomType);
209      EAMAtomData eamAtomData;
276    
277    eamAtomData.rho = getRho(atomType);
278    eamAtomData.F = getF(atomType);
279    eamAtomData.Z = getZ(atomType);
280    eamAtomData.rcut = getRcut(atomType);
210  
211 +    eamAtomData.rho = ea.getRho();
212 +    eamAtomData.F = ea.getF();
213 +    eamAtomData.Z = ea.getZ();
214 +    eamAtomData.rcut = ea.getRcut();
215 +    eamAtomData.isFluctuating = atomType->isFluctuatingCharge();
216 +      
217      // add it to the map:
218 <    AtomTypeProperties atp = atomType->getATP();    
218 >    int atid = atomType->getIdent();
219 >    int eamtid = EAMtypes.size();
220  
221 <    std::pair<std::map<int,AtomType*>::iterator,bool> ret;    
222 <    ret = EAMlist.insert( std::pair<int, AtomType*>(atp.ident, atomType) );
221 >    pair<set<int>::iterator,bool> ret;    
222 >    ret = EAMtypes.insert( atid );
223      if (ret.second == false) {
224        sprintf( painCave.errMsg,
225                 "EAM already had a previous entry with ident %d\n",
226 <               atp.ident);
226 >               atid);
227        painCave.severity = OPENMD_INFO;
228        painCave.isFatal = 0;
229        simError();        
230      }
231  
232 <    EAMMap[atomType] = eamAtomData;
232 >    if (eamAtomData.isFluctuating) {
233 >      // compute charge to rho scaling:
234 >      RealType z0 = eamAtomData.Z->getValueAt(0.0);
235 >      RealType dr = ea.getDr();
236 >      RealType rmax = max(eamAtomData.rcut, ea.getNr() * dr);
237 >      int nr = int(rmax/dr + 0.5);
238 >      RealType r;
239 >      RealType sum(0.0);
240 >
241 >      for (int i = 0; i < nr; i++) {
242 >        r = RealType(i*dr);
243 >        sum += r * r * eamAtomData.rho->getValueAt(r) * dr;      
244 >      }
245 >      sum *= 4.0 * M_PI;
246 >      eamAtomData.qToRhoScaling = sum / z0;
247 >    }
248 >
249 >
250 >    EAMtids[atid] = eamtid;
251 >    EAMdata[eamtid] = eamAtomData;
252 >    MixingMap[eamtid].resize(nEAM_);
253      
254      // Now, iterate over all known types and add to the mixing map:
255      
256 <    std::map<AtomType*, EAMAtomData>::iterator it;
257 <    for( it = EAMMap.begin(); it != EAMMap.end(); ++it) {
256 >    std::set<int>::iterator it;
257 >    for( it = EAMtypes.begin(); it != EAMtypes.end(); ++it) {
258        
259 <      AtomType* atype2 = (*it).first;
259 >      int eamtid2 = EAMtids[ (*it) ];
260 >      AtomType* atype2 = forceField_->getAtomType( (*it) );
261  
262        EAMInteractionData mixer;
263        mixer.phi = getPhi(atomType, atype2);
264 +      mixer.rcut = mixer.phi->getLimits().second;
265        mixer.explicitlySet = false;
266  
267 <      std::pair<AtomType*, AtomType*> key1, key2;
310 <      key1 = std::make_pair(atomType, atype2);
311 <      key2 = std::make_pair(atype2, atomType);
267 >      MixingMap[eamtid2].resize( nEAM_ );
268        
269 <      MixingMap[key1] = mixer;
270 <      if (key2 != key1) {
271 <        MixingMap[key2] = mixer;
269 >      MixingMap[eamtid][eamtid2] = mixer;
270 >      if (eamtid2 != eamtid) {
271 >        MixingMap[eamtid2][eamtid] = mixer;
272        }
273      }      
274      return;
# Line 334 | Line 290 | namespace OpenMD {
290  
291      cs->addPoints(rVals, phiVals);
292      mixer.phi = cs;
293 +    mixer.rcut = mixer.phi->getLimits().second;
294      mixer.explicitlySet = true;
295  
296 <    std::pair<AtomType*, AtomType*> key1, key2;
297 <    key1 = std::make_pair(atype1, atype2);
341 <    key2 = std::make_pair(atype2, atype1);
296 >    int eamtid1 = EAMtids[ atype1->getIdent() ];
297 >    int eamtid2 = EAMtids[ atype2->getIdent() ];
298      
299 <    MixingMap[key1] = mixer;
300 <    if (key2 != key1) {
301 <      MixingMap[key2] = mixer;
299 >    MixingMap[eamtid1][eamtid2] = mixer;
300 >    if (eamtid2 != eamtid1) {
301 >      MixingMap[eamtid2][eamtid1] = mixer;
302      }    
303      return;
304    }
305  
306 <  void EAM::calcDensity(AtomType* at1, AtomType* at2, const RealType rij,
351 <                        RealType &rho_i_at_j, RealType &rho_j_at_i) {
306 >  void EAM::calcDensity(InteractionData &idat) {
307      
308      if (!initialized_) initialize();
309      
310 <    EAMAtomData data1 = EAMMap[at1];
311 <    EAMAtomData data2 = EAMMap[at2];
310 >    EAMAtomData &data1 = EAMdata[EAMtids[idat.atid1]];
311 >    EAMAtomData &data2 = EAMdata[EAMtids[idat.atid2]];
312  
313 <    if (rij < data1.rcut) rho_i_at_j = data1.rho->getValueAt(rij);
314 <    if (rij < data2.rcut) rho_j_at_i = data2.rho->getValueAt(rij);
315 <    return;
313 >    if (haveCutoffRadius_)
314 >      if ( *(idat.rij) > eamRcut_) return;
315 >    
316 >    if ( *(idat.rij) < data1.rcut) {
317 >      if (data1.isFluctuating) {
318 >        *(idat.rho2) += (1.0 -  *(idat.flucQ1) * data1.qToRhoScaling ) *
319 >          data1.rho->getValueAt( *(idat.rij) );
320 >      } else {
321 >        *(idat.rho2) += data1.rho->getValueAt( *(idat.rij));
322 >      }
323 >    }
324 >      
325 >    if ( *(idat.rij) < data2.rcut) {
326 >      if (data2.isFluctuating) {
327 >        *(idat.rho1) += (1.0 -  *(idat.flucQ2) * data2.qToRhoScaling ) *
328 >          data2.rho->getValueAt( *(idat.rij) );
329 >      } else {
330 >        *(idat.rho1) += data2.rho->getValueAt( *(idat.rij));
331 >      }
332 >    }
333 >    
334 >    return;  
335    }
336 <
337 <  void EAM::calcFunctional(AtomType* at1, RealType rho, RealType &frho,
338 <                           RealType &dfrhodrho) {
365 <
336 >  
337 >  void EAM::calcFunctional(SelfData &sdat) {
338 >    
339      if (!initialized_) initialize();
340  
341 <    EAMAtomData data1 = EAMMap[at1];
342 <        
343 <    pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt(rho);
341 >    EAMAtomData &data1 = EAMdata[ EAMtids[sdat.atid] ];
342 >            
343 >    data1.F->getValueAndDerivativeAt( *(sdat.rho), *(sdat.frho), *(sdat.dfrhodrho) );
344  
345 <    frho = result.first;
346 <    dfrhodrho = result.second;
345 >    (*(sdat.pot))[METALLIC_FAMILY] += *(sdat.frho);
346 >    if (sdat.doParticlePot) {
347 >      *(sdat.particlePot) += *(sdat.frho);
348 >    }
349 >
350      return;
351    }
352  
353  
354 <  void EAM::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
379 <                      RealType rij, RealType r2, RealType sw,
380 <                      RealType &vpair, RealType &pot, Vector3d &f1,
381 <                      RealType rho_i, RealType rho_j,
382 <                      RealType dfrhodrho_i, RealType dfrhodrho_j,
383 <                      RealType &fshift_i, RealType &fshift_j) {
354 >  void EAM::calcForce(InteractionData &idat) {
355  
356      if (!initialized_) initialize();
357 +
358 +    if (haveCutoffRadius_)
359 +      if ( *(idat.rij) > eamRcut_) return;
360 +  
361 +
362 +    int eamtid1 = EAMtids[idat.atid1];
363 +    int eamtid2 = EAMtids[idat.atid2];
364      
365 <    pair<RealType, RealType> res;
365 >    EAMAtomData &data1 = EAMdata[eamtid1];
366 >    EAMAtomData &data2 = EAMdata[eamtid2];
367      
368 <    if (rij < eamRcut_) {
368 >    // get type-specific cutoff radii
369 >    
370 >    RealType rci = data1.rcut;
371 >    RealType rcj = data2.rcut;
372 >    
373 >    RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0);
374 >    RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0);
375 >    RealType phab(0.0), dvpdr(0.0);
376 >    RealType drhoidr, drhojdr, dudr;
377 >    
378 >    if ( *(idat.rij) < rci) {
379 >      data1.rho->getValueAndDerivativeAt( *(idat.rij), rha, drha);
380 >      CubicSpline* phi = MixingMap[eamtid1][eamtid1].phi;
381 >      phi->getValueAndDerivativeAt( *(idat.rij), pha, dpha);
382 >      if (data1.isFluctuating) {
383 >        *(idat.dVdFQ1) -= *(idat.dfrho2) * rha * data1.qToRhoScaling;
384 >      }
385 >    }
386 >    
387 >    if ( *(idat.rij) < rcj) {
388 >      data2.rho->getValueAndDerivativeAt( *(idat.rij), rhb, drhb );
389 >      CubicSpline* phi = MixingMap[eamtid2][eamtid2].phi;
390 >      phi->getValueAndDerivativeAt( *(idat.rij), phb, dphb);
391 >      if (data2.isFluctuating) {
392 >        *(idat.dVdFQ2) -= *(idat.dfrho1) * rhb * data2.qToRhoScaling;
393 >      }
394 >    }
395  
396 <      EAMAtomData data1 = EAMMap[at1];
397 <      EAMAtomData data2 = EAMMap[at2];
393 <
394 <      // get type-specific cutoff radii
395 <
396 <      RealType rci = data1.rcut;
397 <      RealType rcj = data2.rcut;
396 >    switch(mixMeth_) {
397 >    case eamJohnson:
398        
399 <      RealType rha, drha, rhb, drhb;
400 <      RealType pha, dpha, phb, dphb;
401 <      RealType phab, dvpdr;
402 <      RealType drhoidr, drhojdr, dudr;
399 >      if ( *(idat.rij) < rci) {
400 >        phab = phab + 0.5 * (rhb / rha) * pha;
401 >        dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
402 >                             pha*((drhb/rha) - (rhb*drha/rha/rha)));
403 >      }
404        
405 <      if (rij < rci) {
406 <        res = data1.rho->getValueAndDerivativeAt(rij);
407 <        rha = res.first;
408 <        drha = res.second;
409 <
410 <        res = MixingMap[make_pair(at1, at1)].phi->getValueAndDerivativeAt(rij);
410 <        pha = res.first;
411 <        dpha = res.second;
405 >      
406 >      
407 >      if ( *(idat.rij) < rcj) {
408 >        phab = phab + 0.5 * (rha / rhb) * phb;
409 >        dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
410 >                               phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
411        }
412 <
413 <      if (rij < rcj) {
414 <        res = data2.rho->getValueAndDerivativeAt(rij);
415 <        rhb = res.first;
416 <        drhb = res.second;
417 <
418 <        res = MixingMap[make_pair(at2, at2)].phi->getValueAndDerivativeAt(rij);
419 <        phb = res.first;
421 <        dphb = res.second;
412 >      
413 >      break;
414 >      
415 >    case eamDaw:
416 >      
417 >      if ( *(idat.rij) <  MixingMap[eamtid1][eamtid2].rcut) {
418 >        MixingMap[eamtid1][eamtid2].phi->getValueAndDerivativeAt( *(idat.rij),
419 >                                                                  phab, dvpdr);
420        }
423
424      phab = 0.0;
425      dvpdr = 0.0;
426
427      switch(mixMeth_) {
428      case eamJohnson:
429      
430        if (rij < rci) {
431          phab = phab + 0.5 * (rhb / rha) * pha;
432          dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
433                               pha*((drhb/rha) - (rhb*drha/rha/rha)));
434        }
435
436        if (rij < rcj) {
437          phab = phab + 0.5 * (rha / rhb) * phb;
438          dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
439                                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
440        }
441
442        break;
443
444      case eamDaw:
445                
446        res = MixingMap[make_pair(at1,at2)].phi->getValueAndDerivativeAt(rij);
447        phab = res.first;
448        dvpdr = res.second;
449
450        break;
451      case eamUnknown:
452      default:
453
454        sprintf(painCave.errMsg,
455                "EAM::calcForce hit a mixing method it doesn't know about!\n"
456                );
457        painCave.severity = OPENMD_ERROR;
458        painCave.isFatal = 1;
459        simError();        
460          
461      }
421        
422 <      drhoidr = drha;
423 <      drhojdr = drhb;
422 >      break;
423 >    case eamUnknown:
424 >    default:
425 >      
426 >      sprintf(painCave.errMsg,
427 >              "EAM::calcForce hit a mixing method it doesn't know about!\n"
428 >              );
429 >      painCave.severity = OPENMD_ERROR;
430 >      painCave.isFatal = 1;
431 >      simError();        
432 >      
433 >    }
434 >    
435 >    drhoidr = drha;
436 >    drhojdr = drhb;
437 >    
438 >    dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr;
439 >    
440 >    *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
441  
466      dudr = drhojdr*dfrhodrho_i + drhoidr*dfrhodrho_j + dvpdr;
467
468      f1 = d * dudr / rij;
442          
443 <      // particle_pot is the difference between the full potential
444 <      // and the full potential without the presence of a particular
443 >    if (idat.doParticlePot) {
444 >      // particlePot is the difference between the full potential and
445 >      // the full potential without the presence of a particular
446        // particle (atom1).
447        //
448 <      // This reduces the density at other particle locations, so
449 <      // we need to recompute the density at atom2 assuming atom1
450 <      // didn't contribute.  This then requires recomputing the
451 <      // density functional for atom2 as well.
452 <      //
453 <      // Most of the particle_pot heavy lifting comes from the
454 <      // pair interaction, and will be handled by vpair.
455 <    
456 <      fshift_i = data1.F->getValueAt( rho_i - rhb );
457 <      fshift_j = data1.F->getValueAt( rho_j - rha );
484 <
485 <      pot += phab;
486 <
487 <      vpair += phab;
448 >      // This reduces the density at other particle locations, so we
449 >      // need to recompute the density at atom2 assuming atom1 didn't
450 >      // contribute.  This then requires recomputing the density
451 >      // functional for atom2 as well.
452 >      
453 >      *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
454 >        - *(idat.frho2);
455 >      
456 >      *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
457 >        - *(idat.frho1);
458      }
489
490    return;
459      
460 <  }
493 <
494 <
495 <  void EAM::calc_eam_prepair_rho(int *atid1, int *atid2, RealType *rij,
496 <                                 RealType* rho_i_at_j, RealType* rho_j_at_i){
497 <
498 <    if (!initialized_) initialize();
460 >    (*(idat.pot))[METALLIC_FAMILY] += phab;
461      
462 <    AtomType* atype1 = EAMlist[*atid1];
463 <    AtomType* atype2 = EAMlist[*atid2];
462 >    *(idat.vpair) += phab;
463 >  
464 >    return;
465      
503    calcDensity(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i);
504
505    return;    
466    }
467  
468 <  void EAM::calc_eam_preforce_Frho(int *atid1, RealType *rho, RealType *frho,
469 <                                   RealType *dfrhodrho) {
468 >  RealType EAM::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
469 >    if (!initialized_) initialize();  
470  
471 <    if (!initialized_) initialize();
471 >    RealType cut = 0.0;
472  
473 <    AtomType* atype1 = EAMlist[*atid1];  
474 <
475 <    calcFunctional(atype1, *rho, *frho, *dfrhodrho);
473 >    int atid1 = atypes.first->getIdent();
474 >    int atid2 = atypes.second->getIdent();
475 >    int eamtid1 = EAMtids[atid1];
476 >    int eamtid2 = EAMtids[atid2];
477      
478 <    return;    
479 <  }
480 <  RealType EAM::getEAMcut(int *atid1) {
478 >    if (eamtid1 != -1) {
479 >      EAMAtomData data1 = EAMdata[eamtid1];
480 >      cut = data1.rcut;
481 >    }
482  
483 <    if (!initialized_) initialize();
483 >    if (eamtid2 != -1) {
484 >      EAMAtomData data2 = EAMdata[eamtid2];
485 >      if (data2.rcut > cut)
486 >        cut = data2.rcut;
487 >    }
488      
489 <    AtomType* atype1 = EAMlist[*atid1];  
524 <      
525 <    return getRcut(atype1);
489 >    return cut;
490    }
527
528  void EAM::do_eam_pair(int *atid1, int *atid2, RealType *d, RealType *rij,
529                        RealType *r2, RealType *sw, RealType *vpair,
530                        RealType *pot, RealType *f1, RealType *rho1,
531                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
532                        RealType *fshift1, RealType *fshift2) {
533
534    if (!initialized_) initialize();
535    
536    AtomType* atype1 = EAMlist[*atid1];
537    AtomType* atype2 = EAMlist[*atid2];
538    
539    Vector3d disp(d[0], d[1], d[2]);
540    Vector3d frc(f1[0], f1[1], f1[2]);
541    
542    calcForce(atype1, atype2, disp, *rij, *r2, *sw, *vpair,  *pot, frc,
543              *rho1, *rho2, *dfrho1, *dfrho2, *fshift1, *fshift2);
544      
545    f1[0] = frc.x();
546    f1[1] = frc.y();
547    f1[2] = frc.z();
548
549    return;    
550  }
551  
552  void EAM::setCutoffEAM(RealType *thisRcut) {
553    eamRcut_ = *thisRcut;
554  }
491   }
492  
557 extern "C" {
558  
559 #define fortranCalcDensity FC_FUNC(calc_eam_prepair_rho, CALC_EAM_PREPAIR_RHO)
560 #define fortranCalcFunctional FC_FUNC(calc_eam_preforce_frho, CALC_EAM_PREFORCE_FRHO)
561 #define fortranCalcForce FC_FUNC(do_eam_pair, DO_EAM_PAIR)
562 #define fortranSetCutoffEAM FC_FUNC(setcutoffeam, SETCUTOFFEAM)
563 #define fortranGetEAMcut FC_FUNC(geteamcut, GETEAMCUT)
564
565  
566  void fortranCalcDensity(int *atid1, int *atid2, RealType *rij,
567                          RealType *rho_i_at_j, RealType *rho_j_at_i) {
568    
569    return OpenMD::EAM::Instance()->calc_eam_prepair_rho(atid1, atid2, rij,
570                                                         rho_i_at_j,  
571                                                         rho_j_at_i);
572  }
573  void fortranCalcFunctional(int *atid1, RealType *rho, RealType *frho,
574                             RealType *dfrhodrho) {  
575    
576    return OpenMD::EAM::Instance()->calc_eam_preforce_Frho(atid1, rho, frho,
577                                                           dfrhodrho);
578    
579  }
580  void fortranSetCutoffEAM(RealType *rcut) {
581    return OpenMD::EAM::Instance()->setCutoffEAM(rcut);
582  }
583  void fortranCalcForce(int *atid1, int *atid2, RealType *d, RealType *rij,
584                        RealType *r2, RealType *sw, RealType *vpair,
585                        RealType *pot, RealType *f1, RealType *rho1,
586                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
587                        RealType *fshift1, RealType *fshift2){
588    
589    return OpenMD::EAM::Instance()->do_eam_pair(atid1, atid2, d, rij,
590                                                r2, sw, vpair,
591                                                pot, f1, rho1,
592                                                rho2, dfrho1, dfrho2,
593                                                fshift1,  fshift2);
594  }
595  RealType fortranGetEAMcut(int* atid) {
596    return OpenMD::EAM::Instance()->getEAMcut(atid);
597  }
598
599 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines