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> |
50 |
|
|
51 |
|
namespace OpenMD { |
52 |
|
|
52 |
– |
bool SC::initialized_ = false; |
53 |
– |
RealType SC::scRcut_ = 0.0; |
54 |
– |
int SC::np_ = 3000; |
55 |
– |
ForceField* SC::forceField_ = NULL; |
56 |
– |
map<int, AtomType*> SC::SClist; |
57 |
– |
map<AtomType*, SCAtomData> SC::SCMap; |
58 |
– |
map<pair<AtomType*, AtomType*>, SCInteractionData> SC::MixingMap; |
59 |
– |
|
60 |
– |
SC* SC::_instance = NULL; |
53 |
|
|
54 |
< |
SC* SC::Instance() { |
55 |
< |
if (!_instance) { |
64 |
< |
_instance = new SC(); |
65 |
< |
} |
66 |
< |
return _instance; |
67 |
< |
} |
54 |
> |
SC::SC() : name_("SC"), initialized_(false), forceField_(NULL), |
55 |
> |
scRcut_(0.0), np_(3000) {} |
56 |
|
|
69 |
– |
SCParam SC::getSCParam(AtomType* atomType) { |
70 |
– |
|
71 |
– |
// Do sanity checking on the AtomType we were passed before |
72 |
– |
// building any data structures: |
73 |
– |
if (!atomType->isSC()) { |
74 |
– |
sprintf( painCave.errMsg, |
75 |
– |
"SC::getSCParam was passed an atomType (%s) that does not\n" |
76 |
– |
"\tappear to be a Sutton-Chen (SC) atom.\n", |
77 |
– |
atomType->getName().c_str()); |
78 |
– |
painCave.severity = OPENMD_ERROR; |
79 |
– |
painCave.isFatal = 1; |
80 |
– |
simError(); |
81 |
– |
} |
82 |
– |
|
83 |
– |
GenericData* data = atomType->getPropertyByName("SC"); |
84 |
– |
if (data == NULL) { |
85 |
– |
sprintf( painCave.errMsg, "SC::getSCParam could not find SC\n" |
86 |
– |
"\tparameters for atomType %s.\n", |
87 |
– |
atomType->getName().c_str()); |
88 |
– |
painCave.severity = OPENMD_ERROR; |
89 |
– |
painCave.isFatal = 1; |
90 |
– |
simError(); |
91 |
– |
} |
92 |
– |
|
93 |
– |
SCParamGenericData* scData = dynamic_cast<SCParamGenericData*>(data); |
94 |
– |
if (scData == NULL) { |
95 |
– |
sprintf( painCave.errMsg, |
96 |
– |
"SC::getSCParam could not convert GenericData to SCParamGenericData\n" |
97 |
– |
"\tfor atom type %s\n", atomType->getName().c_str()); |
98 |
– |
painCave.severity = OPENMD_ERROR; |
99 |
– |
painCave.isFatal = 1; |
100 |
– |
simError(); |
101 |
– |
} |
102 |
– |
|
103 |
– |
return scData->getData(); |
104 |
– |
} |
105 |
– |
|
106 |
– |
RealType SC::getC(AtomType* atomType) { |
107 |
– |
SCParam scParam = getSCParam(atomType); |
108 |
– |
return scParam.c; |
109 |
– |
} |
110 |
– |
|
111 |
– |
RealType SC::getM(AtomType* atomType) { |
112 |
– |
SCParam scParam = getSCParam(atomType); |
113 |
– |
return scParam.m; |
114 |
– |
} |
115 |
– |
|
57 |
|
RealType SC::getM(AtomType* atomType1, AtomType* atomType2) { |
58 |
< |
RealType m1 = getM(atomType1); |
59 |
< |
RealType m2 = getM(atomType2); |
58 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
59 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
60 |
> |
RealType m1 = sca1.getM(); |
61 |
> |
RealType m2 = sca2.getM(); |
62 |
|
return 0.5 * (m1 + m2); |
63 |
|
} |
64 |
|
|
122 |
– |
RealType SC::getN(AtomType* atomType) { |
123 |
– |
SCParam scParam = getSCParam(atomType); |
124 |
– |
return scParam.n; |
125 |
– |
} |
126 |
– |
|
65 |
|
RealType SC::getN(AtomType* atomType1, AtomType* atomType2) { |
66 |
< |
RealType n1 = getN(atomType1); |
67 |
< |
RealType n2 = getN(atomType2); |
66 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
67 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
68 |
> |
RealType n1 = sca1.getN(); |
69 |
> |
RealType n2 = sca2.getN(); |
70 |
|
return 0.5 * (n1 + n2); |
71 |
|
} |
72 |
|
|
133 |
– |
RealType SC::getAlpha(AtomType* atomType) { |
134 |
– |
SCParam scParam = getSCParam(atomType); |
135 |
– |
return scParam.alpha; |
136 |
– |
} |
137 |
– |
|
73 |
|
RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) { |
74 |
< |
RealType alpha1 = getAlpha(atomType1); |
75 |
< |
RealType alpha2 = getAlpha(atomType2); |
74 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
75 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
76 |
> |
RealType alpha1 = sca1.getAlpha(); |
77 |
> |
RealType alpha2 = sca2.getAlpha(); |
78 |
|
|
79 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
80 |
|
std::string DistanceMix = fopts.getDistanceMixingRule(); |
84 |
|
return sqrt(alpha1 * alpha2); |
85 |
|
else |
86 |
|
return 0.5 * (alpha1 + alpha2); |
150 |
– |
} |
151 |
– |
|
152 |
– |
RealType SC::getEpsilon(AtomType* atomType) { |
153 |
– |
SCParam scParam = getSCParam(atomType); |
154 |
– |
return scParam.epsilon; |
87 |
|
} |
88 |
|
|
89 |
< |
RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
90 |
< |
RealType epsilon1 = getEpsilon(atomType1); |
91 |
< |
RealType epsilon2 = getEpsilon(atomType2); |
89 |
> |
RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
90 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
91 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
92 |
> |
RealType epsilon1 = sca1.getEpsilon(); |
93 |
> |
RealType epsilon2 = sca2.getEpsilon(); |
94 |
|
return sqrt(epsilon1 * epsilon2); |
95 |
|
} |
96 |
|
|
102 |
|
|
103 |
|
for (at = atomTypes->beginType(i); at != NULL; |
104 |
|
at = atomTypes->nextType(i)) { |
105 |
< |
if (at->isSC()) |
105 |
> |
SuttonChenAdapter sca = SuttonChenAdapter(at); |
106 |
> |
if (sca.isSuttonChen()) |
107 |
|
addType(at); |
108 |
|
} |
109 |
|
initialized_ = true; |
113 |
|
|
114 |
|
void SC::addType(AtomType* atomType){ |
115 |
|
|
116 |
+ |
SuttonChenAdapter sca = SuttonChenAdapter(atomType); |
117 |
|
SCAtomData scAtomData; |
118 |
|
|
119 |
< |
scAtomData.c = getC(atomType); |
120 |
< |
scAtomData.m = getM(atomType); |
121 |
< |
scAtomData.n = getN(atomType); |
122 |
< |
scAtomData.alpha = getAlpha(atomType); |
123 |
< |
scAtomData.epsilon = getEpsilon(atomType); |
119 |
> |
scAtomData.c = sca.getC(); |
120 |
> |
scAtomData.m = sca.getM(); |
121 |
> |
scAtomData.n = sca.getN(); |
122 |
> |
scAtomData.alpha = sca.getAlpha(); |
123 |
> |
scAtomData.epsilon = sca.getEpsilon(); |
124 |
|
scAtomData.rCut = 2.0 * scAtomData.alpha; |
125 |
|
|
126 |
|
// add it to the map: |
191 |
– |
AtomTypeProperties atp = atomType->getATP(); |
127 |
|
|
128 |
|
pair<map<int,AtomType*>::iterator,bool> ret; |
129 |
< |
ret = SClist.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
129 |
> |
ret = SClist.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) ); |
130 |
|
if (ret.second == false) { |
131 |
|
sprintf( painCave.errMsg, |
132 |
|
"SC already had a previous entry with ident %d\n", |
133 |
< |
atp.ident); |
133 |
> |
atomType->getIdent() ); |
134 |
|
painCave.severity = OPENMD_INFO; |
135 |
|
painCave.isFatal = 0; |
136 |
|
simError(); |
250 |
|
return; |
251 |
|
} |
252 |
|
|
253 |
< |
void SC::calcDensity(AtomType* at1, AtomType* at2, const RealType rij, |
319 |
< |
RealType &rho_i_at_j, RealType &rho_j_at_i) { |
253 |
> |
void SC::calcDensity(InteractionData &idat) { |
254 |
|
|
255 |
|
if (!initialized_) initialize(); |
256 |
|
|
257 |
< |
SCInteractionData mixer = MixingMap[make_pair(at1, at2)]; |
257 |
> |
SCInteractionData mixer = MixingMap[ idat.atypes ]; |
258 |
|
|
259 |
< |
rho_i_at_j = mixer.phi->getValueAt(rij); |
326 |
< |
rho_j_at_i = rho_i_at_j; |
259 |
> |
RealType rcij = mixer.rCut; |
260 |
|
|
261 |
+ |
if ( *(idat.rij) < rcij) { |
262 |
+ |
RealType rho = mixer.phi->getValueAt( *(idat.rij) ); |
263 |
+ |
*(idat.rho1) += rho; |
264 |
+ |
*(idat.rho2) += rho; |
265 |
+ |
} |
266 |
+ |
|
267 |
|
return; |
268 |
|
} |
269 |
|
|
270 |
< |
void SC::calcFunctional(AtomType* at1, RealType rho, RealType &frho, |
332 |
< |
RealType &dfrhodrho) { |
270 |
> |
void SC::calcFunctional(SelfData &sdat) { |
271 |
|
|
272 |
|
if (!initialized_) initialize(); |
273 |
|
|
274 |
< |
SCAtomData data1 = SCMap[at1]; |
274 |
> |
SCAtomData data1 = SCMap[sdat.atype]; |
275 |
> |
|
276 |
> |
RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) ); |
277 |
> |
*(sdat.frho) = u; |
278 |
> |
*(sdat.dfrhodrho) = 0.5 * *(sdat.frho) / *(sdat.rho); |
279 |
> |
|
280 |
> |
(*(sdat.pot))[METALLIC_FAMILY] += u; |
281 |
> |
*(sdat.particlePot) += u; |
282 |
|
|
338 |
– |
frho = - data1.c * data1.epsilon * sqrt(rho); |
339 |
– |
dfrhodrho = 0.5 * frho / rho; |
340 |
– |
|
283 |
|
return; |
284 |
|
} |
285 |
< |
|
285 |
> |
|
286 |
|
|
287 |
< |
void SC::calcForce(AtomType* at1, AtomType* at2, Vector3d d, |
346 |
< |
RealType rij, RealType r2, RealType sw, |
347 |
< |
RealType &vpair, RealType &pot, Vector3d &f1, |
348 |
< |
RealType rho_i, RealType rho_j, |
349 |
< |
RealType dfrhodrho_i, RealType dfrhodrho_j, |
350 |
< |
RealType &fshift_i, RealType &fshift_j) { |
287 |
> |
void SC::calcForce(InteractionData &idat) { |
288 |
|
|
289 |
|
if (!initialized_) initialize(); |
290 |
|
|
291 |
< |
SCAtomData data1 = SCMap[at1]; |
292 |
< |
SCAtomData data2 = SCMap[at1]; |
291 |
> |
SCAtomData data1 = SCMap[idat.atypes.first]; |
292 |
> |
SCAtomData data2 = SCMap[idat.atypes.second]; |
293 |
|
|
294 |
< |
SCInteractionData mixer = MixingMap[make_pair(at1, at2)]; |
294 |
> |
SCInteractionData mixer = MixingMap[idat.atypes]; |
295 |
|
|
296 |
|
RealType rcij = mixer.rCut; |
360 |
– |
RealType vcij = mixer.vCut; |
297 |
|
|
298 |
< |
pair<RealType, RealType> res; |
299 |
< |
|
300 |
< |
res = mixer.phi->getValueAndDerivativeAt(rij); |
301 |
< |
RealType rhtmp = res.first; |
302 |
< |
RealType drhodr = res.second; |
303 |
< |
|
304 |
< |
res = mixer.V->getValueAndDerivativeAt(rij); |
305 |
< |
RealType vptmp = res.first; |
306 |
< |
RealType dvpdr = res.second; |
307 |
< |
|
308 |
< |
RealType pot_temp = vptmp - vcij; |
309 |
< |
vpair += pot_temp; |
310 |
< |
|
311 |
< |
RealType dudr = drhodr * (dfrhodrho_i + dfrhodrho_j) + dvpdr; |
312 |
< |
|
313 |
< |
f1 += d * dudr / rij; |
298 |
> |
if ( *(idat.rij) < rcij) { |
299 |
> |
RealType vcij = mixer.vCut; |
300 |
> |
|
301 |
> |
pair<RealType, RealType> res; |
302 |
> |
|
303 |
> |
res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) ); |
304 |
> |
RealType rhtmp = res.first; |
305 |
> |
RealType drhodr = res.second; |
306 |
> |
|
307 |
> |
res = mixer.V->getValueAndDerivativeAt( *(idat.rij) ); |
308 |
> |
RealType vptmp = res.first; |
309 |
> |
RealType dvpdr = res.second; |
310 |
> |
|
311 |
> |
RealType pot_temp = vptmp - vcij; |
312 |
> |
*(idat.vpair) += pot_temp; |
313 |
> |
|
314 |
> |
RealType dudr = drhodr * ( *(idat.dfrho1) + *(idat.dfrho2) ) + dvpdr; |
315 |
> |
|
316 |
> |
*(idat.f1) += *(idat.d) * dudr / *(idat.rij) ; |
317 |
|
|
318 |
< |
// particle_pot is the difference between the full potential |
319 |
< |
// and the full potential without the presence of a particular |
320 |
< |
// particle (atom1). |
321 |
< |
// |
322 |
< |
// This reduces the density at other particle locations, so |
323 |
< |
// we need to recompute the density at atom2 assuming atom1 |
324 |
< |
// didn't contribute. This then requires recomputing the |
325 |
< |
// density functional for atom2 as well. |
326 |
< |
// |
327 |
< |
// Most of the particle_pot heavy lifting comes from the |
328 |
< |
// pair interaction, and will be handled by vpair. |
390 |
< |
|
391 |
< |
fshift_i = - data1.c * data1.epsilon * sqrt(rho_i - rhtmp); |
392 |
< |
fshift_j = - data2.c * data2.epsilon * sqrt(rho_j - rhtmp); |
393 |
< |
|
394 |
< |
pot += pot_temp; |
318 |
> |
// particlePot is the difference between the full potential and |
319 |
> |
// the full potential without the presence of a particular |
320 |
> |
// particle (atom1). |
321 |
> |
// |
322 |
> |
// This reduces the density at other particle locations, so we |
323 |
> |
// need to recompute the density at atom2 assuming atom1 didn't |
324 |
> |
// contribute. This then requires recomputing the density |
325 |
> |
// functional for atom2 as well. |
326 |
> |
|
327 |
> |
*(idat.particlePot1) -= data2.c * data2.epsilon * |
328 |
> |
sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2); |
329 |
|
|
330 |
+ |
*(idat.particlePot2) -= data1.c * data1.epsilon * |
331 |
+ |
sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1); |
332 |
+ |
|
333 |
+ |
(*(idat.pot))[METALLIC_FAMILY] += pot_temp; |
334 |
+ |
} |
335 |
+ |
|
336 |
|
return; |
337 |
|
} |
338 |
|
|
339 |
+ |
RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
340 |
+ |
if (!initialized_) initialize(); |
341 |
|
|
342 |
< |
void SC::calc_sc_prepair_rho(int *atid1, int *atid2, RealType *rij, |
343 |
< |
RealType* rho_i_at_j, RealType* rho_j_at_i){ |
344 |
< |
|
345 |
< |
if (!initialized_) initialize(); |
346 |
< |
|
347 |
< |
AtomType* atype1 = SClist[*atid1]; |
348 |
< |
AtomType* atype2 = SClist[*atid2]; |
349 |
< |
|
408 |
< |
calcDensity(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i); |
409 |
< |
|
410 |
< |
return; |
342 |
> |
map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it; |
343 |
> |
it = MixingMap.find(atypes); |
344 |
> |
if (it == MixingMap.end()) |
345 |
> |
return 0.0; |
346 |
> |
else { |
347 |
> |
SCInteractionData mixer = (*it).second; |
348 |
> |
return mixer.rCut; |
349 |
> |
} |
350 |
|
} |
412 |
– |
|
413 |
– |
void SC::calc_sc_preforce_Frho(int *atid1, RealType *rho, RealType *frho, |
414 |
– |
RealType *dfrhodrho) { |
415 |
– |
|
416 |
– |
if (!initialized_) initialize(); |
417 |
– |
|
418 |
– |
AtomType* atype1 = SClist[*atid1]; |
419 |
– |
|
420 |
– |
calcFunctional(atype1, *rho, *frho, *dfrhodrho); |
421 |
– |
|
422 |
– |
return; |
423 |
– |
} |
424 |
– |
|
425 |
– |
RealType SC::getSCcut(int *atid1) { |
426 |
– |
|
427 |
– |
if (!initialized_) initialize(); |
428 |
– |
|
429 |
– |
AtomType* atype1 = SClist[*atid1]; |
430 |
– |
|
431 |
– |
return 2.0 * getAlpha(atype1); |
432 |
– |
} |
433 |
– |
|
434 |
– |
void SC::do_sc_pair(int *atid1, int *atid2, RealType *d, RealType *rij, |
435 |
– |
RealType *r2, RealType *sw, RealType *vpair, |
436 |
– |
RealType *pot, RealType *f1, RealType *rho1, |
437 |
– |
RealType *rho2, RealType *dfrho1, RealType *dfrho2, |
438 |
– |
RealType *fshift1, RealType *fshift2) { |
439 |
– |
|
440 |
– |
if (!initialized_) initialize(); |
441 |
– |
|
442 |
– |
AtomType* atype1 = SClist[*atid1]; |
443 |
– |
AtomType* atype2 = SClist[*atid2]; |
444 |
– |
|
445 |
– |
Vector3d disp(d[0], d[1], d[2]); |
446 |
– |
Vector3d frc(f1[0], f1[1], f1[2]); |
447 |
– |
|
448 |
– |
calcForce(atype1, atype2, disp, *rij, *r2, *sw, *vpair, *pot, frc, |
449 |
– |
*rho1, *rho2, *dfrho1, *dfrho2, *fshift1, *fshift2); |
450 |
– |
|
451 |
– |
f1[0] = frc.x(); |
452 |
– |
f1[1] = frc.y(); |
453 |
– |
f1[2] = frc.z(); |
454 |
– |
|
455 |
– |
return; |
456 |
– |
} |
457 |
– |
|
458 |
– |
void SC::setCutoffSC(RealType *thisRcut) { |
459 |
– |
scRcut_ = *thisRcut; |
460 |
– |
} |
351 |
|
} |
462 |
– |
|
463 |
– |
extern "C" { |
464 |
– |
|
465 |
– |
#define fortranCalcDensity FC_FUNC(calc_sc_prepair_rho, CALC_SC_PREPAIR_RHO) |
466 |
– |
#define fortranCalcFunctional FC_FUNC(calc_sc_preforce_frho, CALC_SC_PREFORCE_FRHO) |
467 |
– |
#define fortranCalcForce FC_FUNC(do_sc_pair, DO_SC_PAIR) |
468 |
– |
#define fortranSetCutoffSC FC_FUNC(setcutoffsc, SETCUTOFFSC) |
469 |
– |
#define fortranGetSCcut FC_FUNC(getsccut, GETSCCUT) |
470 |
– |
|
471 |
– |
|
472 |
– |
void fortranCalcDensity(int *atid1, int *atid2, RealType *rij, |
473 |
– |
RealType *rho_i_at_j, RealType *rho_j_at_i) { |
474 |
– |
|
475 |
– |
return OpenMD::SC::Instance()->calc_sc_prepair_rho(atid1, atid2, rij, |
476 |
– |
rho_i_at_j, |
477 |
– |
rho_j_at_i); |
478 |
– |
} |
479 |
– |
void fortranCalcFunctional(int *atid1, RealType *rho, RealType *frho, |
480 |
– |
RealType *dfrhodrho) { |
481 |
– |
|
482 |
– |
return OpenMD::SC::Instance()->calc_sc_preforce_Frho(atid1, rho, frho, |
483 |
– |
dfrhodrho); |
484 |
– |
|
485 |
– |
} |
486 |
– |
void fortranSetCutoffSC(RealType *rcut) { |
487 |
– |
return OpenMD::SC::Instance()->setCutoffSC(rcut); |
488 |
– |
} |
489 |
– |
void fortranCalcForce(int *atid1, int *atid2, RealType *d, RealType *rij, |
490 |
– |
RealType *r2, RealType *sw, RealType *vpair, |
491 |
– |
RealType *pot, RealType *f1, RealType *rho1, |
492 |
– |
RealType *rho2, RealType *dfrho1, RealType *dfrho2, |
493 |
– |
RealType *fshift1, RealType *fshift2){ |
494 |
– |
|
495 |
– |
return OpenMD::SC::Instance()->do_sc_pair(atid1, atid2, d, rij, |
496 |
– |
r2, sw, vpair, |
497 |
– |
pot, f1, rho1, |
498 |
– |
rho2, dfrho1, dfrho2, |
499 |
– |
fshift1, fshift2); |
500 |
– |
} |
501 |
– |
RealType fortranGetSCcut(int* atid) { |
502 |
– |
return OpenMD::SC::Instance()->getSCcut(atid); |
503 |
– |
} |
504 |
– |
|
505 |
– |
} |