50 |
|
|
51 |
|
namespace OpenMD { |
52 |
|
|
53 |
< |
bool EAM::initialized_ = false; |
54 |
< |
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 |
< |
|
61 |
< |
|
62 |
< |
EAM* EAM::_instance = NULL; |
63 |
< |
|
64 |
< |
EAM* EAM::Instance() { |
65 |
< |
if (!_instance) { |
66 |
< |
_instance = new EAM(); |
67 |
< |
} |
68 |
< |
return _instance; |
69 |
< |
} |
53 |
> |
EAM::EAM() : name_("EAM"), initialized_(false), forceField_(NULL), |
54 |
> |
mixMeth_(eamJohnson), eamRcut_(0.0) {} |
55 |
|
|
56 |
|
EAMParam EAM::getEAMParam(AtomType* atomType) { |
57 |
|
|
177 |
|
for (int i = 1; i < rvals.size(); i++ ) { |
178 |
|
r = rvals[i]; |
179 |
|
|
180 |
< |
// only use z(r) if we're inside this atoms cutoff radius, otherwise, we'll use zero for the charge. |
181 |
< |
// This effectively means that our phi grid goes out beyond the cutoff of the pair potential |
180 |
> |
// only use z(r) if we're inside this atom's cutoff radius, |
181 |
> |
// otherwise, we'll use zero for the charge. This effectively |
182 |
> |
// means that our phi grid goes out beyond the cutoff of the |
183 |
> |
// pair potential |
184 |
|
|
185 |
|
zi = r <= eamParam1.rcut ? z1->getValueAt(r) : 0.0; |
186 |
|
zj = r <= eamParam2.rcut ? z2->getValueAt(r) : 0.0; |
347 |
|
return; |
348 |
|
} |
349 |
|
|
350 |
< |
void EAM::calcDensity(AtomType* at1, AtomType* at2, const RealType rij, |
364 |
< |
RealType &rho_i_at_j, RealType &rho_j_at_i) { |
350 |
> |
void EAM::calcDensity(InteractionData &idat) { |
351 |
|
|
352 |
|
if (!initialized_) initialize(); |
353 |
|
|
354 |
< |
EAMAtomData data1 = EAMMap[at1]; |
355 |
< |
EAMAtomData data2 = EAMMap[at2]; |
354 |
> |
EAMAtomData data1 = EAMMap[idat.atypes.first]; |
355 |
> |
EAMAtomData data2 = EAMMap[idat.atypes.second]; |
356 |
|
|
357 |
< |
if (rij < data1.rcut) rho_i_at_j = data1.rho->getValueAt(rij); |
358 |
< |
if (rij < data2.rcut) rho_j_at_i = data2.rho->getValueAt(rij); |
357 |
> |
if ( *(idat.rij) < data1.rcut) |
358 |
> |
*(idat.rho1) += data1.rho->getValueAt( *(idat.rij)); |
359 |
> |
|
360 |
> |
|
361 |
> |
if ( *(idat.rij) < data2.rcut) |
362 |
> |
*(idat.rho2) += data2.rho->getValueAt( *(idat.rij)); |
363 |
> |
|
364 |
|
return; |
365 |
|
} |
366 |
|
|
367 |
< |
void EAM::calcFunctional(AtomType* at1, RealType rho, RealType &frho, |
377 |
< |
RealType &dfrhodrho) { |
367 |
> |
void EAM::calcFunctional(SelfData &sdat) { |
368 |
|
|
369 |
|
if (!initialized_) initialize(); |
370 |
|
|
371 |
< |
EAMAtomData data1 = EAMMap[at1]; |
371 |
> |
EAMAtomData data1 = EAMMap[ sdat.atype ]; |
372 |
|
|
373 |
< |
pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt(rho); |
373 |
> |
pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt( *(sdat.rho) ); |
374 |
|
|
375 |
< |
frho = result.first; |
376 |
< |
dfrhodrho = result.second; |
375 |
> |
*(sdat.frho) = result.first; |
376 |
> |
*(sdat.dfrhodrho) = result.second; |
377 |
> |
|
378 |
> |
sdat.pot[METALLIC_FAMILY] += result.first; |
379 |
> |
*(sdat.particlePot) += result.first; |
380 |
> |
|
381 |
|
return; |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
< |
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) { |
385 |
> |
void EAM::calcForce(InteractionData &idat) { |
386 |
|
|
387 |
|
if (!initialized_) initialize(); |
388 |
|
|
389 |
|
pair<RealType, RealType> res; |
390 |
|
|
391 |
< |
if (rij < eamRcut_) { |
391 |
> |
if ( *(idat.rij) < eamRcut_) { |
392 |
|
|
393 |
< |
EAMAtomData data1 = EAMMap[at1]; |
394 |
< |
EAMAtomData data2 = EAMMap[at2]; |
393 |
> |
EAMAtomData data1 = EAMMap[idat.atypes.first]; |
394 |
> |
EAMAtomData data2 = EAMMap[idat.atypes.second]; |
395 |
|
|
396 |
|
// get type-specific cutoff radii |
397 |
|
|
398 |
|
RealType rci = data1.rcut; |
399 |
|
RealType rcj = data2.rcut; |
400 |
|
|
401 |
< |
RealType rha, drha, rhb, drhb; |
402 |
< |
RealType pha, dpha, phb, dphb; |
403 |
< |
RealType phab, dvpdr; |
401 |
> |
RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0); |
402 |
> |
RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0); |
403 |
> |
RealType phab(0.0), dvpdr(0.0); |
404 |
|
RealType drhoidr, drhojdr, dudr; |
405 |
|
|
406 |
< |
if (rij < rci) { |
407 |
< |
res = data1.rho->getValueAndDerivativeAt(rij); |
406 |
> |
if ( *(idat.rij) < rci) { |
407 |
> |
res = data1.rho->getValueAndDerivativeAt( *(idat.rij)); |
408 |
|
rha = res.first; |
409 |
|
drha = res.second; |
410 |
|
|
411 |
< |
res = MixingMap[make_pair(at1, at1)].phi->getValueAndDerivativeAt(rij); |
411 |
> |
res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) ); |
412 |
|
pha = res.first; |
413 |
|
dpha = res.second; |
414 |
|
} |
415 |
|
|
416 |
< |
if (rij < rcj) { |
417 |
< |
res = data2.rho->getValueAndDerivativeAt(rij); |
416 |
> |
if ( *(idat.rij) < rcj) { |
417 |
> |
res = data2.rho->getValueAndDerivativeAt( *(idat.rij) ); |
418 |
|
rhb = res.first; |
419 |
|
drhb = res.second; |
420 |
|
|
421 |
< |
res = MixingMap[make_pair(at2, at2)].phi->getValueAndDerivativeAt(rij); |
421 |
> |
res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) ); |
422 |
|
phb = res.first; |
423 |
|
dphb = res.second; |
424 |
|
} |
425 |
|
|
437 |
– |
phab = 0.0; |
438 |
– |
dvpdr = 0.0; |
439 |
– |
|
426 |
|
switch(mixMeth_) { |
427 |
|
case eamJohnson: |
428 |
|
|
429 |
< |
if (rij < rci) { |
429 |
> |
if ( *(idat.rij) < rci) { |
430 |
|
phab = phab + 0.5 * (rhb / rha) * pha; |
431 |
|
dvpdr = dvpdr + 0.5*((rhb/rha)*dpha + |
432 |
|
pha*((drhb/rha) - (rhb*drha/rha/rha))); |
433 |
|
} |
434 |
+ |
|
435 |
+ |
|
436 |
|
|
437 |
< |
if (rij < rcj) { |
437 |
> |
if ( *(idat.rij) < rcj) { |
438 |
|
phab = phab + 0.5 * (rha / rhb) * phb; |
439 |
|
dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb + |
440 |
|
phb*((drha/rhb) - (rha*drhb/rhb/rhb))); |
443 |
|
break; |
444 |
|
|
445 |
|
case eamDaw: |
446 |
< |
res = MixingMap[make_pair(at1,at2)].phi->getValueAndDerivativeAt(rij); |
446 |
> |
res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij)); |
447 |
|
phab = res.first; |
448 |
|
dvpdr = res.second; |
449 |
|
|
463 |
|
drhoidr = drha; |
464 |
|
drhojdr = drhb; |
465 |
|
|
466 |
< |
dudr = drhojdr*dfrhodrho_i + drhoidr*dfrhodrho_j + dvpdr; |
466 |
> |
dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr; |
467 |
|
|
468 |
< |
f1 = d * dudr / rij; |
468 |
> |
*(idat.f1) = *(idat.d) * dudr / *(idat.rij); |
469 |
|
|
470 |
< |
// particle_pot is the difference between the full potential |
471 |
< |
// and the full potential without the presence of a particular |
470 |
> |
// particlePot is the difference between the full potential and |
471 |
> |
// the full potential without the presence of a particular |
472 |
|
// particle (atom1). |
473 |
|
// |
474 |
< |
// This reduces the density at other particle locations, so |
475 |
< |
// we need to recompute the density at atom2 assuming atom1 |
476 |
< |
// didn't contribute. This then requires recomputing the |
477 |
< |
// density functional for atom2 as well. |
490 |
< |
// |
491 |
< |
// Most of the particle_pot heavy lifting comes from the |
492 |
< |
// 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 ); |
474 |
> |
// This reduces the density at other particle locations, so we |
475 |
> |
// need to recompute the density at atom2 assuming atom1 didn't |
476 |
> |
// contribute. This then requires recomputing the density |
477 |
> |
// functional for atom2 as well. |
478 |
|
|
479 |
< |
pot += phab; |
479 |
> |
*(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha ) |
480 |
> |
- *(idat.frho2); |
481 |
|
|
482 |
< |
vpair += phab; |
482 |
> |
*(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb) |
483 |
> |
- *(idat.frho1); |
484 |
> |
|
485 |
> |
idat.pot[METALLIC_FAMILY] += phab; |
486 |
> |
|
487 |
> |
*(idat.vpair) += phab; |
488 |
|
} |
489 |
|
|
490 |
|
return; |
491 |
|
|
492 |
|
} |
493 |
|
|
494 |
+ |
RealType EAM::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
495 |
+ |
if (!initialized_) initialize(); |
496 |
|
|
497 |
< |
void EAM::calc_eam_prepair_rho(int *atid1, int *atid2, RealType *rij, |
508 |
< |
RealType* rho_i_at_j, RealType* rho_j_at_i){ |
497 |
> |
RealType cut = 0.0; |
498 |
|
|
499 |
< |
if (!initialized_) initialize(); |
511 |
< |
|
512 |
< |
AtomType* atype1 = EAMlist[*atid1]; |
513 |
< |
AtomType* atype2 = EAMlist[*atid2]; |
514 |
< |
|
515 |
< |
calcDensity(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i); |
499 |
> |
map<AtomType*, EAMAtomData>::iterator it; |
500 |
|
|
501 |
< |
return; |
502 |
< |
} |
501 |
> |
it = EAMMap.find(atypes.first); |
502 |
> |
if (it != EAMMap.end()) { |
503 |
> |
EAMAtomData data1 = (*it).second; |
504 |
> |
cut = data1.rcut; |
505 |
> |
} |
506 |
|
|
507 |
< |
void EAM::calc_eam_preforce_Frho(int *atid1, RealType *rho, RealType *frho, |
508 |
< |
RealType *dfrhodrho) { |
507 |
> |
it = EAMMap.find(atypes.second); |
508 |
> |
if (it != EAMMap.end()) { |
509 |
> |
EAMAtomData data2 = (*it).second; |
510 |
> |
if (data2.rcut > cut) |
511 |
> |
cut = data2.rcut; |
512 |
> |
} |
513 |
|
|
514 |
< |
if (!initialized_) initialize(); |
524 |
< |
|
525 |
< |
AtomType* atype1 = EAMlist[*atid1]; |
526 |
< |
|
527 |
< |
calcFunctional(atype1, *rho, *frho, *dfrhodrho); |
528 |
< |
|
529 |
< |
return; |
514 |
> |
return cut; |
515 |
|
} |
531 |
– |
RealType EAM::getEAMcut(int *atid1) { |
532 |
– |
|
533 |
– |
if (!initialized_) initialize(); |
534 |
– |
|
535 |
– |
AtomType* atype1 = EAMlist[*atid1]; |
536 |
– |
|
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(); |
547 |
– |
|
548 |
– |
AtomType* atype1 = EAMlist[*atid1]; |
549 |
– |
AtomType* atype2 = EAMlist[*atid2]; |
550 |
– |
|
551 |
– |
Vector3d disp(d[0], d[1], d[2]); |
552 |
– |
Vector3d frc(f1[0], f1[1], f1[2]); |
553 |
– |
|
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; |
562 |
– |
} |
563 |
– |
|
564 |
– |
void EAM::setCutoffEAM(RealType *thisRcut) { |
565 |
– |
eamRcut_ = *thisRcut; |
566 |
– |
} |
516 |
|
} |
517 |
|
|
569 |
– |
extern "C" { |
570 |
– |
|
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) |
576 |
– |
|
577 |
– |
|
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 |
– |
} |
610 |
– |
|
611 |
– |
} |