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 1479 by gezelter, Mon Jul 26 19:00:48 2010 UTC vs.
Revision 1481 by gezelter, Mon Jul 26 21:55:18 2010 UTC

# Line 54 | Line 54 | namespace OpenMD {
54    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;
57 >  map<int, AtomType*> EAM::EAMlist;
58 >  map<AtomType*, EAMAtomData> EAM::EAMMap;
59 >  map<pair<AtomType*, AtomType*>, EAMInteractionData> EAM::MixingMap;
60  
61    
62    EAM* EAM::_instance = NULL;
# Line 161 | Line 161 | namespace OpenMD {
161  
162      // make the r grid:
163  
164    // set rcut to be the smaller of the two atomic rcuts
164  
165 <    RealType rcut = eamParam1.rcut < eamParam2.rcut ?
166 <      eamParam1.rcut : eamParam2.rcut;
165 >    // we need phi out to the largest value we'll encounter in the radial space;
166 >    
167 >    RealType rmax = 0.0;
168 >    rmax = max(rmax, eamParam1.rcut);
169 >    rmax = max(rmax, eamParam1.nr * eamParam1.dr);
170  
171 +    rmax = max(rmax, eamParam2.rcut);
172 +    rmax = max(rmax, eamParam2.nr * eamParam2.dr);
173 +
174      // use the smallest dr (finest grid) to build our grid:
175  
176 <    RealType dr = eamParam1.dr < eamParam2.dr ? eamParam1.dr : eamParam2.dr;
177 <    int nr = int(rcut/dr);
176 >    RealType dr = min(eamParam1.dr, eamParam2.dr);
177 >
178 >    int nr = int(rmax/dr + 0.5);
179 >
180      vector<RealType> rvals;
181 <    for (int i = 0; i < nr; i++) rvals.push_back(i*dr);
181 >    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i*dr));
182  
183      // construct the pair potential:
184  
# Line 184 | Line 191 | namespace OpenMD {
191  
192      for (int i = 1; i < rvals.size(); i++ ) {
193        r = rvals[i];
194 <      zi = z1->getValueAt(r);
195 <      zj = z2->getValueAt(r);
194 >
195 >      // only use z(r) if we're inside this atoms cutoff radius, otherwise, we'll use zero for the charge.
196 >      // This effectively means that our phi grid goes out beyond the cutoff of the pair potential
197 >
198 >      zi = r <= eamParam1.rcut ? z1->getValueAt(r) : 0.0;
199 >      zj = r <= eamParam2.rcut ? z2->getValueAt(r) : 0.0;
200  
201        phi = 331.999296 * (zi * zj) / r;
202 +
203        phivals.push_back(phi);
204      }
205        
# Line 200 | Line 212 | namespace OpenMD {
212  
213      // set up the mixing method:
214      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
215 <    string EAMMixMeth = toUpperCopy(fopts.getEAMMixingMethod());
216 <
215 >    string EAMMixMeth = fopts.getEAMMixingMethod();
216 >    toUpper(EAMMixMeth);
217 >  
218      if (EAMMixMeth == "JOHNSON")
219        mixMeth_ = eamJohnson;    
220      else if (EAMMixMeth == "DAW")
# Line 231 | Line 244 | namespace OpenMD {
244        
245        if (nbt->isEAM()) {
246          
247 <        std::pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
247 >        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
248          
249          GenericData* data = nbt->getPropertyByName("EAM");
250          if (data == NULL) {
# Line 282 | Line 295 | namespace OpenMD {
295      // add it to the map:
296      AtomTypeProperties atp = atomType->getATP();    
297  
298 <    std::pair<std::map<int,AtomType*>::iterator,bool> ret;    
299 <    ret = EAMlist.insert( std::pair<int, AtomType*>(atp.ident, atomType) );
298 >    pair<map<int,AtomType*>::iterator,bool> ret;    
299 >    ret = EAMlist.insert( pair<int, AtomType*>(atp.ident, atomType) );
300      if (ret.second == false) {
301        sprintf( painCave.errMsg,
302                 "EAM already had a previous entry with ident %d\n",
# Line 297 | Line 310 | namespace OpenMD {
310      
311      // Now, iterate over all known types and add to the mixing map:
312      
313 <    std::map<AtomType*, EAMAtomData>::iterator it;
313 >    map<AtomType*, EAMAtomData>::iterator it;
314      for( it = EAMMap.begin(); it != EAMMap.end(); ++it) {
315        
316        AtomType* atype2 = (*it).first;
# Line 306 | Line 319 | namespace OpenMD {
319        mixer.phi = getPhi(atomType, atype2);
320        mixer.explicitlySet = false;
321  
322 <      std::pair<AtomType*, AtomType*> key1, key2;
323 <      key1 = std::make_pair(atomType, atype2);
324 <      key2 = std::make_pair(atype2, atomType);
322 >      pair<AtomType*, AtomType*> key1, key2;
323 >      key1 = make_pair(atomType, atype2);
324 >      key2 = make_pair(atype2, atomType);
325        
326        MixingMap[key1] = mixer;
327        if (key2 != key1) {
# Line 336 | Line 349 | namespace OpenMD {
349      mixer.phi = cs;
350      mixer.explicitlySet = true;
351  
352 <    std::pair<AtomType*, AtomType*> key1, key2;
353 <    key1 = std::make_pair(atype1, atype2);
354 <    key2 = std::make_pair(atype2, atype1);
352 >    pair<AtomType*, AtomType*> key1, key2;
353 >    key1 = make_pair(atype1, atype2);
354 >    key2 = make_pair(atype2, atype1);
355      
356      MixingMap[key1] = mixer;
357      if (key2 != key1) {
# Line 383 | Line 396 | namespace OpenMD {
396                        RealType &fshift_i, RealType &fshift_j) {
397  
398      if (!initialized_) initialize();
399 <    
399 >
400      pair<RealType, RealType> res;
401      
402      if (rij < eamRcut_) {
# Line 442 | Line 455 | namespace OpenMD {
455          break;
456  
457        case eamDaw:
445                
458          res = MixingMap[make_pair(at1,at2)].phi->getValueAndDerivativeAt(rij);
459          phab = res.first;
460          dvpdr = res.second;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines