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

Comparing trunk/src/nonbonded/EAM.cpp (file contents):
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 1895 by gezelter, Mon Jul 1 21:09:37 2013 UTC

# Line 117 | Line 117 | namespace OpenMD {
117    }
118  
119    void EAM::initialize() {
120
120      // set up the mixing method:
121      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
122      string EAMMixMeth = fopts.getEAMMixingMethod();
# Line 131 | 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 <      
141 <      if (at->isEAM())
142 <        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 202 | Line 209 | namespace OpenMD {
209      eamAtomData.rcut = ea.getRcut();
210  
211      // add it to the map:
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*>(atomType->getIdent(), 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 <               atomType->getIdent());
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;
231 <      key1 = make_pair(atomType, atype2);
232 <      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 257 | 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);
262 <    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 272 | 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 292 | 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;
300 <    *(sdat.dfrhodrho) = result.second;
301 <
302 <    (*(sdat.pot))[METALLIC_FAMILY] += result.first;
308 >    (*(sdat.pot))[METALLIC_FAMILY] += *(sdat.frho);
309      if (sdat.doParticlePot) {
310 <      *(sdat.particlePot) += result.first;
310 >      *(sdat.particlePot) += *(sdat.frho);
311      }
312  
313      return;
# Line 315 | 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 331 | 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;
337 <      
338 <      res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) );
339 <      pha = res.first;
340 <      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;
347 <      
348 <      res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) );
349 <      phb = res.first;
350 <      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 370 | Line 370 | namespace OpenMD {
370        break;
371        
372      case eamDaw:
373 <      res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij));
374 <      phab = res.first;
375 <      dvpdr = res.second;
373 >      MixingMap[eamtid1][eamtid2].phi->getValueAndDerivativeAt( *(idat.rij), phab, dvpdr);
374        
375        break;
376      case eamUnknown:
# Line 424 | 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()) {
437 <      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