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

Comparing branches/development/src/nonbonded/EAM.cpp (file contents):
Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC vs.
Revision 1711 by gezelter, Sat May 19 02:58:35 2012 UTC

# Line 54 | 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()) {
62 <      sprintf( painCave.errMsg,
63 <               "EAM::getEAMParam was passed an atomType (%s) that does not\n"
64 <               "\tappear to be an embedded atom method (EAM) atom.\n",
65 <               atomType->getName().c_str());
66 <      painCave.severity = OPENMD_ERROR;
67 <      painCave.isFatal = 1;
68 <      simError();
69 <    }
70 <    
71 <    GenericData* data = atomType->getPropertyByName("EAM");
72 <    if (data == NULL) {
73 <      sprintf( painCave.errMsg, "EAM::getEAMParam could not find EAM\n"
74 <               "\tparameters for atomType %s.\n",
75 <               atomType->getName().c_str());
76 <      painCave.severity = OPENMD_ERROR;
77 <      painCave.isFatal = 1;
78 <      simError();
79 <    }
80 <    
81 <    EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data);
82 <    if (eamData == NULL) {
83 <      sprintf( painCave.errMsg,
84 <               "EAM::getEAMParam could not convert GenericData to EAMParam for\n"
85 <               "\tatom type %s\n", atomType->getName().c_str());
86 <      painCave.severity = OPENMD_ERROR;
87 <      painCave.isFatal = 1;
88 <      simError();          
89 <    }
90 <    
91 <    return eamData->getData();
92 <  }
93 <
94 <  CubicSpline* EAM::getZ(AtomType* atomType) {    
95 <    EAMParam eamParam = getEAMParam(atomType);
96 <    int nr = eamParam.nr;
97 <    RealType dr = eamParam.dr;
98 <    vector<RealType> rvals;
99 <    
100 <    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i) * dr);
101 <      
102 <    CubicSpline* cs = new CubicSpline();
103 <    cs->addPoints(rvals, eamParam.Z);
104 <    return cs;
105 <  }
106 <
107 <  RealType EAM::getRcut(AtomType* atomType) {    
108 <    EAMParam eamParam = getEAMParam(atomType);
109 <    return eamParam.rcut;
110 <  }
111 <
112 <  CubicSpline* EAM::getRho(AtomType* atomType) {    
113 <    EAMParam eamParam = getEAMParam(atomType);
114 <    int nr = eamParam.nr;
115 <    RealType dr = eamParam.dr;
116 <    vector<RealType> rvals;
117 <    
118 <    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i) * dr);
119 <      
120 <    CubicSpline* cs = new CubicSpline();
121 <    cs->addPoints(rvals, eamParam.rho);
122 <    return cs;
123 <  }
124 <
125 <  CubicSpline* EAM::getF(AtomType* atomType) {    
126 <    EAMParam eamParam = getEAMParam(atomType);
127 <    int nrho = eamParam.nrho;
128 <    RealType drho = eamParam.drho;
129 <    vector<RealType> rhovals;
130 <    vector<RealType> scaledF;
131 <    
132 <    for (int i = 0; i < nrho; i++) {
133 <      rhovals.push_back(RealType(i) * drho);
134 <      scaledF.push_back( eamParam.F[i] * 23.06054 );
135 <    }
136 <      
137 <    CubicSpline* cs = new CubicSpline();
138 <    cs->addPoints(rhovals, scaledF);
139 <    return cs;
140 <  }
141 <  
142 <  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {    
143 <    EAMParam eamParam1 = getEAMParam(atomType1);
144 <    EAMParam eamParam2 = getEAMParam(atomType2);
145 <    CubicSpline* z1 = getZ(atomType1);
146 <    CubicSpline* z2 = getZ(atomType2);
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      // make the r grid:
64  
# Line 151 | Line 66 | namespace OpenMD {
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 183 | 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 278 | Line 193 | namespace OpenMD {
193  
194    void EAM::addType(AtomType* atomType){
195  
196 +    EAMAdapter ea = EAMAdapter(atomType);
197      EAMAtomData eamAtomData;
198 <    
199 <    eamAtomData.rho = getRho(atomType);
200 <    eamAtomData.F = getF(atomType);
201 <    eamAtomData.Z = getZ(atomType);
202 <    eamAtomData.rcut = getRcut(atomType);
198 >
199 >    eamAtomData.rho = ea.getRho();
200 >    eamAtomData.F = ea.getF();
201 >    eamAtomData.Z = ea.getZ();
202 >    eamAtomData.rcut = ea.getRcut();
203  
204      // add it to the map:
289    AtomTypeProperties atp = atomType->getATP();    
205  
206      pair<map<int,AtomType*>::iterator,bool> ret;    
207 <    ret = EAMlist.insert( pair<int, AtomType*>(atp.ident, atomType) );
207 >    ret = EAMlist.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) );
208      if (ret.second == false) {
209        sprintf( painCave.errMsg,
210                 "EAM already had a previous entry with ident %d\n",
211 <               atp.ident);
211 >               atomType->getIdent());
212        painCave.severity = OPENMD_INFO;
213        painCave.isFatal = 0;
214        simError();        
# Line 385 | Line 300 | namespace OpenMD {
300      *(sdat.dfrhodrho) = result.second;
301  
302      (*(sdat.pot))[METALLIC_FAMILY] += result.first;
303 <    *(sdat.particlePot) += result.first;
303 >    if (sdat.doParticlePot) {
304 >      *(sdat.particlePot) += result.first;
305 >    }
306  
307      return;
308    }
# Line 477 | Line 394 | namespace OpenMD {
394      
395      *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
396          
397 <    // particlePot is the difference between the full potential and
398 <    // the full potential without the presence of a particular
399 <    // particle (atom1).
400 <    //
401 <    // This reduces the density at other particle locations, so we
402 <    // need to recompute the density at atom2 assuming atom1 didn't
403 <    // contribute.  This then requires recomputing the density
404 <    // functional for atom2 as well.
397 >    if (idat.doParticlePot) {
398 >      // particlePot is the difference between the full potential and
399 >      // the full potential without the presence of a particular
400 >      // particle (atom1).
401 >      //
402 >      // This reduces the density at other particle locations, so we
403 >      // need to recompute the density at atom2 assuming atom1 didn't
404 >      // contribute.  This then requires recomputing the density
405 >      // functional for atom2 as well.
406 >      
407 >      *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
408 >        - *(idat.frho2);
409 >      
410 >      *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
411 >        - *(idat.frho1);
412 >    }
413      
489    *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
490      - *(idat.frho2);
491    
492    *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
493      - *(idat.frho1);
494    
414      (*(idat.pot))[METALLIC_FAMILY] += phab;
415      
416      *(idat.vpair) += phab;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines