--- branches/development/src/nonbonded/EAM.cpp 2010/07/27 14:55:15 1482 +++ branches/development/src/nonbonded/EAM.cpp 2011/11/22 20:38:56 1665 @@ -36,7 +36,8 @@ * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include @@ -50,24 +51,9 @@ namespace OpenMD { namespace OpenMD { - bool EAM::initialized_ = false; - RealType EAM::eamRcut_ = 0.0; - EAMMixingMethod EAM::mixMeth_ = eamJohnson; - ForceField* EAM::forceField_ = NULL; - map EAM::EAMlist; - map EAM::EAMMap; - map, EAMInteractionData> EAM::MixingMap; - + EAM::EAM() : name_("EAM"), initialized_(false), forceField_(NULL), + mixMeth_(eamJohnson), eamRcut_(0.0), haveCutoffRadius_(false) {} - EAM* EAM::_instance = NULL; - - EAM* EAM::Instance() { - if (!_instance) { - _instance = new EAM(); - } - return _instance; - } - EAMParam EAM::getEAMParam(AtomType* atomType) { // Do sanity checking on the AtomType we were passed before @@ -192,8 +178,10 @@ namespace OpenMD { for (int i = 1; i < rvals.size(); i++ ) { r = rvals[i]; - // only use z(r) if we're inside this atoms cutoff radius, otherwise, we'll use zero for the charge. - // This effectively means that our phi grid goes out beyond the cutoff of the pair potential + // only use z(r) if we're inside this atom's cutoff radius, + // otherwise, we'll use zero for the charge. This effectively + // means that our phi grid goes out beyond the cutoff of the + // pair potential zi = r <= eamParam1.rcut ? z1->getValueAt(r) : 0.0; zj = r <= eamParam2.rcut ? z2->getValueAt(r) : 0.0; @@ -208,6 +196,11 @@ namespace OpenMD { return cs; } + void EAM::setCutoffRadius( RealType rCut ) { + eamRcut_ = rCut; + haveCutoffRadius_ = true; + } + void EAM::initialize() { // set up the mixing method: @@ -360,252 +353,174 @@ namespace OpenMD { return; } - void EAM::calcDensity(AtomType* at1, AtomType* at2, const RealType rij, - RealType &rho_i_at_j, RealType &rho_j_at_i) { + void EAM::calcDensity(InteractionData &idat) { if (!initialized_) initialize(); - EAMAtomData data1 = EAMMap[at1]; - EAMAtomData data2 = EAMMap[at2]; - - if (rij < data1.rcut) rho_i_at_j = data1.rho->getValueAt(rij); - if (rij < data2.rcut) rho_j_at_i = data2.rho->getValueAt(rij); - return; - } - - void EAM::calcFunctional(AtomType* at1, RealType rho, RealType &frho, - RealType &dfrhodrho) { - + EAMAtomData data1 = EAMMap[idat.atypes.first]; + EAMAtomData data2 = EAMMap[idat.atypes.second]; + + if (haveCutoffRadius_) + if ( *(idat.rij) > eamRcut_) return; + + if ( *(idat.rij) < data1.rcut) + *(idat.rho1) += data1.rho->getValueAt( *(idat.rij)); + + + if ( *(idat.rij) < data2.rcut) + *(idat.rho2) += data2.rho->getValueAt( *(idat.rij)); + + return; + } + + void EAM::calcFunctional(SelfData &sdat) { + if (!initialized_) initialize(); - EAMAtomData data1 = EAMMap[at1]; + EAMAtomData data1 = EAMMap[ sdat.atype ]; - pair result = data1.F->getValueAndDerivativeAt(rho); + pair result = data1.F->getValueAndDerivativeAt( *(sdat.rho) ); - frho = result.first; - dfrhodrho = result.second; + *(sdat.frho) = result.first; + *(sdat.dfrhodrho) = result.second; + + (*(sdat.pot))[METALLIC_FAMILY] += result.first; + *(sdat.particlePot) += result.first; + return; } - void EAM::calcForce(AtomType* at1, AtomType* at2, Vector3d d, - RealType rij, RealType r2, RealType sw, - RealType &vpair, RealType &pot, Vector3d &f1, - RealType rho_i, RealType rho_j, - RealType dfrhodrho_i, RealType dfrhodrho_j, - RealType &fshift_i, RealType &fshift_j) { + void EAM::calcForce(InteractionData &idat) { if (!initialized_) initialize(); + if (haveCutoffRadius_) + if ( *(idat.rij) > eamRcut_) return; + pair res; - if (rij < eamRcut_) { - - EAMAtomData data1 = EAMMap[at1]; - EAMAtomData data2 = EAMMap[at2]; - - // get type-specific cutoff radii - - RealType rci = data1.rcut; - RealType rcj = data2.rcut; - - RealType rha, drha, rhb, drhb; - RealType pha, dpha, phb, dphb; - RealType phab, dvpdr; - RealType drhoidr, drhojdr, dudr; + EAMAtomData data1 = EAMMap[idat.atypes.first]; + EAMAtomData data2 = EAMMap[idat.atypes.second]; + + // get type-specific cutoff radii + + RealType rci = data1.rcut; + RealType rcj = data2.rcut; + + RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0); + RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0); + RealType phab(0.0), dvpdr(0.0); + RealType drhoidr, drhojdr, dudr; + + if ( *(idat.rij) < rci) { + res = data1.rho->getValueAndDerivativeAt( *(idat.rij)); + rha = res.first; + drha = res.second; - if (rij < rci) { - res = data1.rho->getValueAndDerivativeAt(rij); - rha = res.first; - drha = res.second; + res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) ); + pha = res.first; + dpha = res.second; + } + + if ( *(idat.rij) < rcj) { + res = data2.rho->getValueAndDerivativeAt( *(idat.rij) ); + rhb = res.first; + drhb = res.second; + + res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) ); + phb = res.first; + dphb = res.second; + } - res = MixingMap[make_pair(at1, at1)].phi->getValueAndDerivativeAt(rij); - pha = res.first; - dpha = res.second; + switch(mixMeth_) { + case eamJohnson: + + if ( *(idat.rij) < rci) { + phab = phab + 0.5 * (rhb / rha) * pha; + dvpdr = dvpdr + 0.5*((rhb/rha)*dpha + + pha*((drhb/rha) - (rhb*drha/rha/rha))); } - - if (rij < rcj) { - res = data2.rho->getValueAndDerivativeAt(rij); - rhb = res.first; - drhb = res.second; - - res = MixingMap[make_pair(at2, at2)].phi->getValueAndDerivativeAt(rij); - phb = res.first; - dphb = res.second; - } - - phab = 0.0; - dvpdr = 0.0; - - switch(mixMeth_) { - case eamJohnson: - - if (rij < rci) { - phab = phab + 0.5 * (rhb / rha) * pha; - dvpdr = dvpdr + 0.5*((rhb/rha)*dpha + - pha*((drhb/rha) - (rhb*drha/rha/rha))); - } - - if (rij < rcj) { - phab = phab + 0.5 * (rha / rhb) * phb; - dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb + - phb*((drha/rhb) - (rha*drhb/rhb/rhb))); - } - - break; - - case eamDaw: - res = MixingMap[make_pair(at1,at2)].phi->getValueAndDerivativeAt(rij); - phab = res.first; - dvpdr = res.second; - - break; - case eamUnknown: - default: - - sprintf(painCave.errMsg, - "EAM::calcForce hit a mixing method it doesn't know about!\n" - ); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - - } - drhoidr = drha; - drhojdr = drhb; - - dudr = drhojdr*dfrhodrho_i + drhoidr*dfrhodrho_j + dvpdr; - - f1 = d * dudr / rij; - - // particle_pot is the difference between the full potential - // and the full potential without the presence of a particular - // particle (atom1). - // - // This reduces the density at other particle locations, so - // we need to recompute the density at atom2 assuming atom1 - // didn't contribute. This then requires recomputing the - // density functional for atom2 as well. - // - // Most of the particle_pot heavy lifting comes from the - // pair interaction, and will be handled by vpair. - - fshift_i = data1.F->getValueAt( rho_i - rhb ); - fshift_j = data1.F->getValueAt( rho_j - rha ); - - pot += phab; - - vpair += phab; + + + if ( *(idat.rij) < rcj) { + phab = phab + 0.5 * (rha / rhb) * phb; + dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb + + phb*((drha/rhb) - (rha*drhb/rhb/rhb))); + } + + break; + + case eamDaw: + res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij)); + phab = res.first; + dvpdr = res.second; + + break; + case eamUnknown: + default: + + sprintf(painCave.errMsg, + "EAM::calcForce hit a mixing method it doesn't know about!\n" + ); + painCave.severity = OPENMD_ERROR; + painCave.isFatal = 1; + simError(); + } - - return; - } - - - void EAM::calc_eam_prepair_rho(int *atid1, int *atid2, RealType *rij, - RealType* rho_i_at_j, RealType* rho_j_at_i){ - - if (!initialized_) initialize(); + drhoidr = drha; + drhojdr = drhb; - AtomType* atype1 = EAMlist[*atid1]; - AtomType* atype2 = EAMlist[*atid2]; + dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr; - calcDensity(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i); - - return; - } - - void EAM::calc_eam_preforce_Frho(int *atid1, RealType *rho, RealType *frho, - RealType *dfrhodrho) { - - if (!initialized_) initialize(); - - AtomType* atype1 = EAMlist[*atid1]; - - calcFunctional(atype1, *rho, *frho, *dfrhodrho); + *(idat.f1) += *(idat.d) * dudr / *(idat.rij); + + // particlePot is the difference between the full potential and + // the full potential without the presence of a particular + // particle (atom1). + // + // This reduces the density at other particle locations, so we + // need to recompute the density at atom2 assuming atom1 didn't + // contribute. This then requires recomputing the density + // functional for atom2 as well. - return; - } - RealType EAM::getEAMcut(int *atid1) { - - if (!initialized_) initialize(); + *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha ) + - *(idat.frho2); - AtomType* atype1 = EAMlist[*atid1]; - - return getRcut(atype1); - } - - void EAM::do_eam_pair(int *atid1, int *atid2, RealType *d, RealType *rij, - RealType *r2, RealType *sw, RealType *vpair, - RealType *pot, RealType *f1, RealType *rho1, - RealType *rho2, RealType *dfrho1, RealType *dfrho2, - RealType *fshift1, RealType *fshift2) { - - if (!initialized_) initialize(); + *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb) + - *(idat.frho1); - AtomType* atype1 = EAMlist[*atid1]; - AtomType* atype2 = EAMlist[*atid2]; + (*(idat.pot))[METALLIC_FAMILY] += phab; - Vector3d disp(d[0], d[1], d[2]); - Vector3d frc(f1[0], f1[1], f1[2]); + *(idat.vpair) += phab; + + return; - calcForce(atype1, atype2, disp, *rij, *r2, *sw, *vpair, *pot, frc, - *rho1, *rho2, *dfrho1, *dfrho2, *fshift1, *fshift2); - - f1[0] = frc.x(); - f1[1] = frc.y(); - f1[2] = frc.z(); - - return; } - - void EAM::setCutoffEAM(RealType *thisRcut) { - eamRcut_ = *thisRcut; - } -} -extern "C" { - -#define fortranCalcDensity FC_FUNC(calc_eam_prepair_rho, CALC_EAM_PREPAIR_RHO) -#define fortranCalcFunctional FC_FUNC(calc_eam_preforce_frho, CALC_EAM_PREFORCE_FRHO) -#define fortranCalcForce FC_FUNC(do_eam_pair, DO_EAM_PAIR) -#define fortranSetCutoffEAM FC_FUNC(setcutoffeam, SETCUTOFFEAM) -#define fortranGetEAMcut FC_FUNC(geteamcut, GETEAMCUT) + RealType EAM::getSuggestedCutoffRadius(pair atypes) { + if (!initialized_) initialize(); - - void fortranCalcDensity(int *atid1, int *atid2, RealType *rij, - RealType *rho_i_at_j, RealType *rho_j_at_i) { - - return OpenMD::EAM::Instance()->calc_eam_prepair_rho(atid1, atid2, rij, - rho_i_at_j, - rho_j_at_i); - } - void fortranCalcFunctional(int *atid1, RealType *rho, RealType *frho, - RealType *dfrhodrho) { - - return OpenMD::EAM::Instance()->calc_eam_preforce_Frho(atid1, rho, frho, - dfrhodrho); - - } - void fortranSetCutoffEAM(RealType *rcut) { - return OpenMD::EAM::Instance()->setCutoffEAM(rcut); - } - void fortranCalcForce(int *atid1, int *atid2, RealType *d, RealType *rij, - RealType *r2, RealType *sw, RealType *vpair, - RealType *pot, RealType *f1, RealType *rho1, - RealType *rho2, RealType *dfrho1, RealType *dfrho2, - RealType *fshift1, RealType *fshift2){ - - return OpenMD::EAM::Instance()->do_eam_pair(atid1, atid2, d, rij, - r2, sw, vpair, - pot, f1, rho1, - rho2, dfrho1, dfrho2, - fshift1, fshift2); - } - RealType fortranGetEAMcut(int* atid) { - return OpenMD::EAM::Instance()->getEAMcut(atid); - } + RealType cut = 0.0; + map::iterator it; + + it = EAMMap.find(atypes.first); + if (it != EAMMap.end()) { + EAMAtomData data1 = (*it).second; + cut = data1.rcut; + } + + it = EAMMap.find(atypes.second); + if (it != EAMMap.end()) { + EAMAtomData data2 = (*it).second; + if (data2.rcut > cut) + cut = data2.rcut; + } + + return cut; + } } +