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 1481 by gezelter, Mon Jul 26 21:55:18 2010 UTC vs.
Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 36 | Line 36
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).                        
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 <  map<int, AtomType*> EAM::EAMlist;
58 <  map<AtomType*, EAMAtomData> EAM::EAMMap;
59 <  map<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    
62  EAM* EAM::_instance = NULL;
63
64  EAM* EAM::Instance() {
65    if (!_instance) {
66      _instance = new EAM();
67    }
68    return _instance;
69  }
70  
57    EAMParam EAM::getEAMParam(AtomType* atomType) {
58      
59      // Do sanity checking on the AtomType we were passed before
# Line 111 | Line 97 | namespace OpenMD {
97      RealType dr = eamParam.dr;
98      vector<RealType> rvals;
99      
100 <    for (int i = 0; i < nr; i++) rvals.push_back(i * dr);
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);
# Line 129 | Line 115 | namespace OpenMD {
115      RealType dr = eamParam.dr;
116      vector<RealType> rvals;
117      
118 <    for (int i = 0; i < nr; i++) rvals.push_back(i * dr);
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);
# Line 144 | Line 130 | namespace OpenMD {
130      vector<RealType> scaledF;
131      
132      for (int i = 0; i < nrho; i++) {
133 <      rhovals.push_back(i * drho);
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, eamParam.F);
138 >    cs->addPoints(rhovals, scaledF);
139      return cs;
140    }
141    
# Line 192 | Line 178 | namespace OpenMD {
178      for (int i = 1; i < rvals.size(); i++ ) {
179        r = rvals[i];
180  
181 <      // only use z(r) if we're inside this atoms cutoff radius, otherwise, we'll use zero for the charge.
182 <      // This effectively means that our phi grid goes out beyond the cutoff of the pair potential
181 >      // only use z(r) if we're inside this atom's cutoff radius,
182 >      // otherwise, we'll use zero for the charge.  This effectively
183 >      // means that our phi grid goes out beyond the cutoff of the
184 >      // pair potential
185  
186        zi = r <= eamParam1.rcut ? z1->getValueAt(r) : 0.0;
187        zj = r <= eamParam2.rcut ? z2->getValueAt(r) : 0.0;
# Line 208 | Line 196 | namespace OpenMD {
196      return cs;
197    }
198  
199 +  void EAM::setCutoffRadius( RealType rCut ) {
200 +    eamRcut_ = rCut;
201 +    haveCutoffRadius_ = true;
202 +  }
203 +
204    void EAM::initialize() {
205  
206      // set up the mixing method:
# Line 360 | Line 353 | namespace OpenMD {
353      return;
354    }
355  
356 <  void EAM::calcDensity(AtomType* at1, AtomType* at2, const RealType rij,
364 <                        RealType &rho_i_at_j, RealType &rho_j_at_i) {
356 >  void EAM::calcDensity(InteractionData &idat) {
357      
358      if (!initialized_) initialize();
359      
360 <    EAMAtomData data1 = EAMMap[at1];
361 <    EAMAtomData data2 = EAMMap[at2];
362 <
363 <    if (rij < data1.rcut) rho_i_at_j = data1.rho->getValueAt(rij);
364 <    if (rij < data2.rcut) rho_j_at_i = data2.rho->getValueAt(rij);
365 <    return;
360 >    EAMAtomData data1 = EAMMap[idat.atypes.first];
361 >    EAMAtomData data2 = EAMMap[idat.atypes.second];
362 >    
363 >    if (haveCutoffRadius_)
364 >      if ( *(idat.rij) > eamRcut_) return;
365 >    
366 >    if ( *(idat.rij) < data1.rcut)
367 >      *(idat.rho1) += data1.rho->getValueAt( *(idat.rij));
368 >    
369 >      
370 >    if ( *(idat.rij) < data2.rcut)
371 >      *(idat.rho2) += data2.rho->getValueAt( *(idat.rij));
372 >    
373 >    return;  
374    }
375 <
376 <  void EAM::calcFunctional(AtomType* at1, RealType rho, RealType &frho,
377 <                           RealType &dfrhodrho) {
378 <
375 >  
376 >  void EAM::calcFunctional(SelfData &sdat) {
377 >    
378      if (!initialized_) initialize();
379  
380 <    EAMAtomData data1 = EAMMap[at1];
380 >    EAMAtomData data1 = EAMMap[ sdat.atype ];
381          
382 <    pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt(rho);
382 >    pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt( *(sdat.rho) );
383  
384 <    frho = result.first;
385 <    dfrhodrho = result.second;
384 >    *(sdat.frho) = result.first;
385 >    *(sdat.dfrhodrho) = result.second;
386 >
387 >    (*(sdat.pot))[METALLIC_FAMILY] += result.first;
388 >    *(sdat.particlePot) += result.first;
389 >
390      return;
391    }
392  
393  
394 <  void EAM::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
392 <                      RealType rij, RealType r2, RealType sw,
393 <                      RealType &vpair, RealType &pot, Vector3d &f1,
394 <                      RealType rho_i, RealType rho_j,
395 <                      RealType dfrhodrho_i, RealType dfrhodrho_j,
396 <                      RealType &fshift_i, RealType &fshift_j) {
394 >  void EAM::calcForce(InteractionData &idat) {
395  
396      if (!initialized_) initialize();
397  
398 +    if (haveCutoffRadius_)
399 +      if ( *(idat.rij) > eamRcut_) return;
400 +  
401      pair<RealType, RealType> res;
402      
403 <    if (rij < eamRcut_) {
404 <
405 <      EAMAtomData data1 = EAMMap[at1];
406 <      EAMAtomData data2 = EAMMap[at2];
407 <
408 <      // get type-specific cutoff radii
409 <
410 <      RealType rci = data1.rcut;
411 <      RealType rcj = data2.rcut;
403 >    EAMAtomData data1 = EAMMap[idat.atypes.first];
404 >    EAMAtomData data2 = EAMMap[idat.atypes.second];
405 >    
406 >    // get type-specific cutoff radii
407 >    
408 >    RealType rci = data1.rcut;
409 >    RealType rcj = data2.rcut;
410 >    
411 >    RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0);
412 >    RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0);
413 >    RealType phab(0.0), dvpdr(0.0);
414 >    RealType drhoidr, drhojdr, dudr;
415 >    
416 >    if ( *(idat.rij) < rci) {
417 >      res = data1.rho->getValueAndDerivativeAt( *(idat.rij));
418 >      rha = res.first;
419 >      drha = res.second;
420        
421 <      RealType rha, drha, rhb, drhb;
422 <      RealType pha, dpha, phb, dphb;
423 <      RealType phab, dvpdr;
424 <      RealType drhoidr, drhojdr, dudr;
421 >      res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) );
422 >      pha = res.first;
423 >      dpha = res.second;
424 >    }
425 >    
426 >    if ( *(idat.rij) < rcj) {
427 >      res = data2.rho->getValueAndDerivativeAt( *(idat.rij) );
428 >      rhb = res.first;
429 >      drhb = res.second;
430        
431 <      if (rij < rci) {
432 <        res = data1.rho->getValueAndDerivativeAt(rij);
433 <        rha = res.first;
434 <        drha = res.second;
431 >      res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) );
432 >      phb = res.first;
433 >      dphb = res.second;
434 >    }
435  
436 <        res = MixingMap[make_pair(at1, at1)].phi->getValueAndDerivativeAt(rij);
437 <        pha = res.first;
438 <        dpha = res.second;
436 >    switch(mixMeth_) {
437 >    case eamJohnson:
438 >      
439 >      if ( *(idat.rij) < rci) {
440 >        phab = phab + 0.5 * (rhb / rha) * pha;
441 >        dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
442 >                             pha*((drhb/rha) - (rhb*drha/rha/rha)));
443        }
444 <
445 <      if (rij < rcj) {
446 <        res = data2.rho->getValueAndDerivativeAt(rij);
447 <        rhb = res.first;
448 <        drhb = res.second;
449 <
450 <        res = MixingMap[make_pair(at2, at2)].phi->getValueAndDerivativeAt(rij);
433 <        phb = res.first;
434 <        dphb = res.second;
435 <      }
436 <
437 <      phab = 0.0;
438 <      dvpdr = 0.0;
439 <
440 <      switch(mixMeth_) {
441 <      case eamJohnson:
442 <      
443 <        if (rij < rci) {
444 <          phab = phab + 0.5 * (rhb / rha) * pha;
445 <          dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
446 <                               pha*((drhb/rha) - (rhb*drha/rha/rha)));
447 <        }
448 <
449 <        if (rij < rcj) {
450 <          phab = phab + 0.5 * (rha / rhb) * phb;
451 <          dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
452 <                                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
453 <        }
454 <
455 <        break;
456 <
457 <      case eamDaw:
458 <        res = MixingMap[make_pair(at1,at2)].phi->getValueAndDerivativeAt(rij);
459 <        phab = res.first;
460 <        dvpdr = res.second;
461 <
462 <        break;
463 <      case eamUnknown:
464 <      default:
465 <
466 <        sprintf(painCave.errMsg,
467 <                "EAM::calcForce hit a mixing method it doesn't know about!\n"
468 <                );
469 <        painCave.severity = OPENMD_ERROR;
470 <        painCave.isFatal = 1;
471 <        simError();        
472 <          
444 >      
445 >      
446 >      
447 >      if ( *(idat.rij) < rcj) {
448 >        phab = phab + 0.5 * (rha / rhb) * phb;
449 >        dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
450 >                               phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
451        }
452        
453 <      drhoidr = drha;
454 <      drhojdr = drhb;
455 <
456 <      dudr = drhojdr*dfrhodrho_i + drhoidr*dfrhodrho_j + dvpdr;
457 <
458 <      f1 = d * dudr / rij;
459 <        
460 <      // particle_pot is the difference between the full potential
461 <      // and the full potential without the presence of a particular
462 <      // particle (atom1).
463 <      //
464 <      // This reduces the density at other particle locations, so
465 <      // we need to recompute the density at atom2 assuming atom1
466 <      // didn't contribute.  This then requires recomputing the
467 <      // density functional for atom2 as well.
468 <      //
469 <      // Most of the particle_pot heavy lifting comes from the
470 <      // pair interaction, and will be handled by vpair.
493 <    
494 <      fshift_i = data1.F->getValueAt( rho_i - rhb );
495 <      fshift_j = data1.F->getValueAt( rho_j - rha );
496 <
497 <      pot += phab;
498 <
499 <      vpair += phab;
453 >      break;
454 >      
455 >    case eamDaw:
456 >      res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij));
457 >      phab = res.first;
458 >      dvpdr = res.second;
459 >      
460 >      break;
461 >    case eamUnknown:
462 >    default:
463 >      
464 >      sprintf(painCave.errMsg,
465 >              "EAM::calcForce hit a mixing method it doesn't know about!\n"
466 >              );
467 >      painCave.severity = OPENMD_ERROR;
468 >      painCave.isFatal = 1;
469 >      simError();        
470 >      
471      }
501
502    return;
472      
473 <  }
474 <
506 <
507 <  void EAM::calc_eam_prepair_rho(int *atid1, int *atid2, RealType *rij,
508 <                                 RealType* rho_i_at_j, RealType* rho_j_at_i){
509 <
510 <    if (!initialized_) initialize();
473 >    drhoidr = drha;
474 >    drhojdr = drhb;
475      
476 <    AtomType* atype1 = EAMlist[*atid1];
513 <    AtomType* atype2 = EAMlist[*atid2];
476 >    dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr;
477      
478 <    calcDensity(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i);
479 <
480 <    return;    
481 <  }
482 <
483 <  void EAM::calc_eam_preforce_Frho(int *atid1, RealType *rho, RealType *frho,
484 <                                   RealType *dfrhodrho) {
485 <
486 <    if (!initialized_) initialize();
487 <
525 <    AtomType* atype1 = EAMlist[*atid1];  
526 <
527 <    calcFunctional(atype1, *rho, *frho, *dfrhodrho);
478 >    *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
479 >        
480 >    // particlePot is the difference between the full potential and
481 >    // the full potential without the presence of a particular
482 >    // particle (atom1).
483 >    //
484 >    // This reduces the density at other particle locations, so we
485 >    // need to recompute the density at atom2 assuming atom1 didn't
486 >    // contribute.  This then requires recomputing the density
487 >    // functional for atom2 as well.
488      
489 <    return;    
490 <  }
531 <  RealType EAM::getEAMcut(int *atid1) {
532 <
533 <    if (!initialized_) initialize();
489 >    *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
490 >      - *(idat.frho2);
491      
492 <    AtomType* atype1 = EAMlist[*atid1];  
493 <      
537 <    return getRcut(atype1);
538 <  }
539 <
540 <  void EAM::do_eam_pair(int *atid1, int *atid2, RealType *d, RealType *rij,
541 <                        RealType *r2, RealType *sw, RealType *vpair,
542 <                        RealType *pot, RealType *f1, RealType *rho1,
543 <                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
544 <                        RealType *fshift1, RealType *fshift2) {
545 <
546 <    if (!initialized_) initialize();
492 >    *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
493 >      - *(idat.frho1);
494      
495 <    AtomType* atype1 = EAMlist[*atid1];
549 <    AtomType* atype2 = EAMlist[*atid2];
495 >    (*(idat.pot))[METALLIC_FAMILY] += phab;
496      
497 <    Vector3d disp(d[0], d[1], d[2]);
498 <    Vector3d frc(f1[0], f1[1], f1[2]);
497 >    *(idat.vpair) += phab;
498 >  
499 >    return;
500      
554    calcForce(atype1, atype2, disp, *rij, *r2, *sw, *vpair,  *pot, frc,
555              *rho1, *rho2, *dfrho1, *dfrho2, *fshift1, *fshift2);
556      
557    f1[0] = frc.x();
558    f1[1] = frc.y();
559    f1[2] = frc.z();
560
561    return;    
501    }
563  
564  void EAM::setCutoffEAM(RealType *thisRcut) {
565    eamRcut_ = *thisRcut;
566  }
567 }
502  
503 < extern "C" {
504 <  
571 < #define fortranCalcDensity FC_FUNC(calc_eam_prepair_rho, CALC_EAM_PREPAIR_RHO)
572 < #define fortranCalcFunctional FC_FUNC(calc_eam_preforce_frho, CALC_EAM_PREFORCE_FRHO)
573 < #define fortranCalcForce FC_FUNC(do_eam_pair, DO_EAM_PAIR)
574 < #define fortranSetCutoffEAM FC_FUNC(setcutoffeam, SETCUTOFFEAM)
575 < #define fortranGetEAMcut FC_FUNC(geteamcut, GETEAMCUT)
503 >  RealType EAM::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
504 >    if (!initialized_) initialize();  
505  
506 <  
578 <  void fortranCalcDensity(int *atid1, int *atid2, RealType *rij,
579 <                          RealType *rho_i_at_j, RealType *rho_j_at_i) {
580 <    
581 <    return OpenMD::EAM::Instance()->calc_eam_prepair_rho(atid1, atid2, rij,
582 <                                                         rho_i_at_j,  
583 <                                                         rho_j_at_i);
584 <  }
585 <  void fortranCalcFunctional(int *atid1, RealType *rho, RealType *frho,
586 <                             RealType *dfrhodrho) {  
587 <    
588 <    return OpenMD::EAM::Instance()->calc_eam_preforce_Frho(atid1, rho, frho,
589 <                                                           dfrhodrho);
590 <    
591 <  }
592 <  void fortranSetCutoffEAM(RealType *rcut) {
593 <    return OpenMD::EAM::Instance()->setCutoffEAM(rcut);
594 <  }
595 <  void fortranCalcForce(int *atid1, int *atid2, RealType *d, RealType *rij,
596 <                        RealType *r2, RealType *sw, RealType *vpair,
597 <                        RealType *pot, RealType *f1, RealType *rho1,
598 <                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
599 <                        RealType *fshift1, RealType *fshift2){
600 <    
601 <    return OpenMD::EAM::Instance()->do_eam_pair(atid1, atid2, d, rij,
602 <                                                r2, sw, vpair,
603 <                                                pot, f1, rho1,
604 <                                                rho2, dfrho1, dfrho2,
605 <                                                fshift1,  fshift2);
606 <  }
607 <  RealType fortranGetEAMcut(int* atid) {
608 <    return OpenMD::EAM::Instance()->getEAMcut(atid);
609 <  }
506 >    RealType cut = 0.0;
507  
508 +    map<AtomType*, EAMAtomData>::iterator it;
509 +
510 +    it = EAMMap.find(atypes.first);
511 +    if (it != EAMMap.end()) {
512 +      EAMAtomData data1 = (*it).second;
513 +      cut = data1.rcut;
514 +    }
515 +
516 +    it = EAMMap.find(atypes.second);
517 +    if (it != EAMMap.end()) {
518 +      EAMAtomData data2 = (*it).second;
519 +      if (data2.rcut > cut)
520 +        cut = data2.rcut;
521 +    }
522 +
523 +    return cut;
524 +  }
525   }
526 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines