44 |
|
namespace OpenMD { |
45 |
|
|
46 |
|
bool InteractionManager::initialized_ = false; |
47 |
+ |
RealType InteractionManager::rCut_ = -1.0; |
48 |
+ |
RealType InteractionManager::rSwitch_ = -1.0; |
49 |
|
ForceField* InteractionManager::forceField_ = NULL; |
50 |
|
InteractionManager* InteractionManager::_instance = NULL; |
51 |
|
map<int, AtomType*> InteractionManager::typeMap_; |
52 |
|
map<pair<AtomType*, AtomType*>, set<NonBondedInteraction*> > InteractionManager::interactions_; |
53 |
+ |
|
54 |
+ |
LJ* InteractionManager::lj_ = new LJ(); |
55 |
+ |
GB* InteractionManager::gb_ = new GB(); |
56 |
+ |
Sticky* InteractionManager::sticky_ = new Sticky(); |
57 |
+ |
Morse* InteractionManager::morse_ = new Morse(); |
58 |
+ |
EAM* InteractionManager::eam_ = new EAM(); |
59 |
+ |
SC* InteractionManager::sc_ = new SC(); |
60 |
+ |
Electrostatic* InteractionManager::electrostatic_ = new Electrostatic(); |
61 |
|
|
62 |
|
InteractionManager* InteractionManager::Instance() { |
63 |
|
if (!_instance) { |
68 |
|
|
69 |
|
void InteractionManager::initialize() { |
70 |
|
|
61 |
– |
lj_ = new LJ(); |
62 |
– |
gb_ = new GB(); |
63 |
– |
sticky_ = new Sticky(); |
64 |
– |
eam_ = new EAM(); |
65 |
– |
sc_ = new SC(); |
66 |
– |
morse_ = new Morse(); |
67 |
– |
electrostatic_ = new Electrostatic(); |
68 |
– |
|
71 |
|
lj_->setForceField(forceField_); |
72 |
|
gb_->setForceField(forceField_); |
73 |
|
sticky_->setForceField(forceField_); |
233 |
|
} |
234 |
|
} |
235 |
|
} |
236 |
+ |
|
237 |
+ |
void InteractionManager::doPrePair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){ |
238 |
+ |
|
239 |
+ |
if (!initialized_) initialize(); |
240 |
+ |
|
241 |
+ |
DensityData ddat; |
242 |
|
|
243 |
+ |
ddat.atype1 = typeMap_[*atid1]; |
244 |
+ |
ddat.atype2 = typeMap_[*atid2]; |
245 |
+ |
ddat.rij = *rij; |
246 |
+ |
ddat.rho_i_at_j = *rho_i_at_j; |
247 |
+ |
ddat.rho_j_at_i = *rho_j_at_i; |
248 |
|
|
249 |
< |
void InteractionManager::doPrePair(AtomType* atype1, |
250 |
< |
AtomType* atype2, |
238 |
< |
RealType rij, |
239 |
< |
RealType &rho_i_at_j, |
240 |
< |
RealType &rho_j_at_i) { |
241 |
< |
|
242 |
< |
} |
243 |
< |
|
244 |
< |
void InteractionManager::doPreForce(AtomType* atype, |
245 |
< |
RealType rho, |
246 |
< |
RealType &frho, |
247 |
< |
RealType &dfrhodrho) { |
248 |
< |
} |
249 |
> |
pair<AtomType*, AtomType*> key = make_pair(ddat.atype1, ddat.atype2); |
250 |
> |
set<NonBondedInteraction*>::iterator it; |
251 |
|
|
252 |
< |
void InteractionManager::doSkipCorrection(AtomType* atype1, |
253 |
< |
AtomType* atype2, |
254 |
< |
Vector3d d, |
255 |
< |
RealType rij, |
256 |
< |
RealType &skippedCharge1, |
257 |
< |
RealType &skippedCharge2, |
258 |
< |
RealType sw, |
257 |
< |
RealType electroMult, |
258 |
< |
RealType &pot, |
259 |
< |
RealType &vpair, |
260 |
< |
Vector3d &f1, |
261 |
< |
Mat3x3d eFrame1, |
262 |
< |
Mat3x3d eFrame2, |
263 |
< |
Vector3d &t1, |
264 |
< |
Vector3d &t2) { |
252 |
> |
for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){ |
253 |
> |
if ((*it)->getFamily() == METALLIC_FAMILY) { |
254 |
> |
dynamic_cast<MetallicInteraction*>(*it)->calcDensity(ddat); |
255 |
> |
} |
256 |
> |
} |
257 |
> |
|
258 |
> |
return; |
259 |
|
} |
260 |
|
|
261 |
< |
void InteractionManager::doSelfCorrection(AtomType* atype, |
268 |
< |
Mat3x3d eFrame, |
269 |
< |
RealType skippedCharge, |
270 |
< |
RealType &pot, |
271 |
< |
Vector3d &t) { |
272 |
< |
} |
261 |
> |
void InteractionManager::doPreForce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){ |
262 |
|
|
274 |
– |
void InteractionManager::do_prepair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){ |
275 |
– |
|
263 |
|
if (!initialized_) initialize(); |
264 |
< |
AtomType* atype1 = typeMap_[*atid1]; |
265 |
< |
AtomType* atype2 = typeMap_[*atid2]; |
279 |
< |
|
280 |
< |
doPrePair(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i); |
281 |
< |
|
282 |
< |
return; |
283 |
< |
} |
264 |
> |
|
265 |
> |
FunctionalData fdat; |
266 |
|
|
267 |
< |
void InteractionManager::do_preforce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){ |
267 |
> |
fdat.atype = typeMap_[*atid]; |
268 |
> |
fdat.rho = *rho; |
269 |
> |
fdat.frho = *frho; |
270 |
> |
fdat.dfrhodrho = *dfrhodrho; |
271 |
|
|
272 |
< |
if (!initialized_) initialize(); |
273 |
< |
AtomType* atype = typeMap_[*atid]; |
289 |
< |
|
290 |
< |
doPreForce(atype, *rho, *frho, *dfrhodrho); |
272 |
> |
pair<AtomType*, AtomType*> key = make_pair(fdat.atype, fdat.atype); |
273 |
> |
set<NonBondedInteraction*>::iterator it; |
274 |
|
|
275 |
+ |
for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){ |
276 |
+ |
if ((*it)->getFamily() == METALLIC_FAMILY) { |
277 |
+ |
dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(fdat); |
278 |
+ |
} |
279 |
+ |
} |
280 |
+ |
|
281 |
|
return; |
282 |
|
} |
283 |
|
|
284 |
< |
void InteractionManager::do_pair(int *atid1, int *atid2, RealType *d, RealType *r, RealType *r2, RealType *rcut, RealType *sw, RealType *vdwMult,RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2, RealType *t1, RealType *t2, RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2, RealType *fshift1, RealType *fshift2){ |
285 |
< |
|
284 |
> |
void InteractionManager::doPair(int *atid1, int *atid2, RealType *d, RealType *r, RealType *r2, RealType *rcut, RealType *sw, RealType *vdwMult,RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2, RealType *t1, RealType *t2, RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2, RealType *fshift1, RealType *fshift2){ |
285 |
> |
|
286 |
|
if (!initialized_) initialize(); |
287 |
< |
|
287 |
> |
|
288 |
|
InteractionData idat; |
289 |
< |
|
289 |
> |
|
290 |
|
idat.atype1 = typeMap_[*atid1]; |
291 |
|
idat.atype2 = typeMap_[*atid2]; |
292 |
|
idat.d = Vector3d(d); |
333 |
|
return; |
334 |
|
} |
335 |
|
|
336 |
< |
void InteractionManager::do_skip_correction(int *atid1, int *atid2, RealType *d, RealType *r, RealType *skippedCharge1, RealType *skippedCharge2, RealType *sw, RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *t1, RealType *t2){ |
336 |
> |
void InteractionManager::doSkipCorrection(int *atid1, int *atid2, RealType *d, RealType *r, RealType *skippedCharge1, RealType *skippedCharge2, RealType *sw, RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *t1, RealType *t2){ |
337 |
|
|
338 |
|
if (!initialized_) initialize(); |
350 |
– |
|
351 |
– |
AtomType* atype1 = typeMap_[*atid1]; |
352 |
– |
AtomType* atype2 = typeMap_[*atid2]; |
353 |
– |
Vector3d disp(d); |
354 |
– |
Vector3d frc(f1); |
355 |
– |
Vector3d trq1(t1); |
356 |
– |
Vector3d trq2(t2); |
357 |
– |
Mat3x3d eFi(eFrame1); |
358 |
– |
Mat3x3d eFj(eFrame2); |
359 |
– |
|
360 |
– |
doSkipCorrection(atype1, atype2, disp, *r, *skippedCharge1, *skippedCharge2, *sw, |
361 |
– |
*electroMult, *pot, *vpair, frc, eFi, eFj, trq1, trq2); |
362 |
– |
|
363 |
– |
f1[0] = frc.x(); |
364 |
– |
f1[1] = frc.y(); |
365 |
– |
f1[2] = frc.z(); |
339 |
|
|
340 |
< |
t1[0] = trq1.x(); |
368 |
< |
t1[1] = trq1.y(); |
369 |
< |
t1[2] = trq1.z(); |
340 |
> |
SkipCorrectionData skdat; |
341 |
|
|
342 |
< |
t2[0] = trq2.x(); |
343 |
< |
t2[1] = trq2.y(); |
344 |
< |
t2[2] = trq2.z(); |
342 |
> |
skdat.atype1 = typeMap_[*atid1]; |
343 |
> |
skdat.atype2 = typeMap_[*atid2]; |
344 |
> |
skdat.d = Vector3d(d); |
345 |
> |
skdat.rij = *r; |
346 |
> |
skdat.skippedCharge1 = *skippedCharge1; |
347 |
> |
skdat.skippedCharge2 = *skippedCharge2; |
348 |
> |
skdat.sw = *sw; |
349 |
> |
skdat.electroMult = *electroMult; |
350 |
> |
skdat.pot = *pot; |
351 |
> |
skdat.vpair = *vpair; |
352 |
> |
skdat.f1 = Vector3d(f1); |
353 |
> |
skdat.eFrame1 = Mat3x3d(eFrame1); |
354 |
> |
skdat.eFrame2 = Mat3x3d(eFrame2); |
355 |
> |
skdat.t1 = Vector3d(t1); |
356 |
> |
skdat.t2 = Vector3d(t2); |
357 |
|
|
358 |
< |
return; |
358 |
> |
pair<AtomType*, AtomType*> key = make_pair(skdat.atype1, skdat.atype2); |
359 |
> |
set<NonBondedInteraction*>::iterator it; |
360 |
> |
|
361 |
> |
for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){ |
362 |
> |
if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) { |
363 |
> |
dynamic_cast<ElectrostaticInteraction*>(*it)->calcSkipCorrection(skdat); |
364 |
> |
} |
365 |
> |
} |
366 |
> |
|
367 |
> |
f1[0] = skdat.f1.x(); |
368 |
> |
f1[1] = skdat.f1.y(); |
369 |
> |
f1[2] = skdat.f1.z(); |
370 |
> |
|
371 |
> |
t1[0] = skdat.t1.x(); |
372 |
> |
t1[1] = skdat.t1.y(); |
373 |
> |
t1[2] = skdat.t1.z(); |
374 |
> |
|
375 |
> |
t2[0] = skdat.t2.x(); |
376 |
> |
t2[1] = skdat.t2.y(); |
377 |
> |
t2[2] = skdat.t2.z(); |
378 |
> |
|
379 |
> |
return; |
380 |
|
} |
381 |
|
|
382 |
< |
void InteractionManager::do_self_correction(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){ |
382 |
> |
void InteractionManager::doSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){ |
383 |
|
|
384 |
|
if (!initialized_) initialize(); |
385 |
< |
|
385 |
> |
|
386 |
> |
SelfCorrectionData scdat; |
387 |
> |
|
388 |
> |
scdat.atype = typeMap_[*atid]; |
389 |
> |
scdat.eFrame = Mat3x3d(eFrame); |
390 |
> |
scdat.skippedCharge = *skippedCharge; |
391 |
> |
scdat.pot = *pot; |
392 |
> |
scdat.t = Vector3d(t); |
393 |
> |
|
394 |
> |
pair<AtomType*, AtomType*> key = make_pair(scdat.atype, scdat.atype); |
395 |
> |
set<NonBondedInteraction*>::iterator it; |
396 |
> |
|
397 |
> |
for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){ |
398 |
> |
if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) { |
399 |
> |
dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(scdat); |
400 |
> |
} |
401 |
> |
} |
402 |
> |
|
403 |
> |
t[0] = scdat.t.x(); |
404 |
> |
t[1] = scdat.t.y(); |
405 |
> |
t[2] = scdat.t.z(); |
406 |
> |
|
407 |
> |
return; |
408 |
> |
} |
409 |
> |
|
410 |
> |
|
411 |
> |
RealType InteractionManager::getSuggestedCutoffRadius(int *atid) { |
412 |
> |
if (!initialized_) initialize(); |
413 |
> |
|
414 |
|
AtomType* atype = typeMap_[*atid]; |
383 |
– |
Mat3x3d eFi(eFrame); |
384 |
– |
Vector3d trq1(t); |
385 |
– |
|
386 |
– |
doSelfCorrection(atype, eFi, *skippedCharge, *pot, trq1); |
415 |
|
|
416 |
< |
t[0] = trq1.x(); |
417 |
< |
t[1] = trq1.y(); |
418 |
< |
t[2] = trq1.z(); |
416 |
> |
pair<AtomType*, AtomType*> key = make_pair(atype, atype); |
417 |
> |
set<NonBondedInteraction*>::iterator it; |
418 |
> |
RealType cutoff = 0.0; |
419 |
> |
|
420 |
> |
for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) |
421 |
> |
cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype)); |
422 |
> |
return cutoff; |
423 |
> |
} |
424 |
|
|
425 |
< |
return; |
425 |
> |
RealType InteractionManager::getSuggestedCutoffRadius(AtomType* atype) { |
426 |
> |
if (!initialized_) initialize(); |
427 |
> |
|
428 |
> |
pair<AtomType*, AtomType*> key = make_pair(atype, atype); |
429 |
> |
set<NonBondedInteraction*>::iterator it; |
430 |
> |
RealType cutoff = 0.0; |
431 |
> |
|
432 |
> |
for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) |
433 |
> |
cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype)); |
434 |
> |
return cutoff; |
435 |
|
} |
436 |
|
|
437 |
|
} //end namespace OpenMD |
448 |
|
void fortranDoPrePair(int *atid1, int *atid2, RealType *rij, |
449 |
|
RealType *rho_i_at_j, RealType *rho_j_at_i) { |
450 |
|
|
451 |
< |
return OpenMD::InteractionManager::Instance()->do_prepair(atid1, atid2, rij, |
452 |
< |
rho_i_at_j, |
453 |
< |
rho_j_at_i); |
451 |
> |
return OpenMD::InteractionManager::Instance()->doPrePair(atid1, atid2, rij, |
452 |
> |
rho_i_at_j, |
453 |
> |
rho_j_at_i); |
454 |
|
} |
455 |
< |
void fortranDoPreforce(int *atid, RealType *rho, RealType *frho, |
455 |
> |
void fortranDoPreForce(int *atid, RealType *rho, RealType *frho, |
456 |
|
RealType *dfrhodrho) { |
457 |
|
|
458 |
< |
return OpenMD::InteractionManager::Instance()->do_preforce(atid, rho, frho, |
459 |
< |
dfrhodrho); |
458 |
> |
return OpenMD::InteractionManager::Instance()->doPreForce(atid, rho, frho, |
459 |
> |
dfrhodrho); |
460 |
|
} |
461 |
|
|
462 |
|
void fortranDoPair(int *atid1, int *atid2, RealType *d, RealType *r, |
463 |
< |
RealType *r2, RealType *rcut, RealType *sw, RealType *vdwMult, |
464 |
< |
RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, |
465 |
< |
RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2, |
466 |
< |
RealType *t1, RealType *t2, |
467 |
< |
RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2, |
468 |
< |
RealType *fshift1, RealType *fshift2){ |
463 |
> |
RealType *r2, RealType *rcut, RealType *sw, |
464 |
> |
RealType *vdwMult, RealType *electroMult, RealType *pot, |
465 |
> |
RealType *vpair, RealType *f1, RealType *eFrame1, |
466 |
> |
RealType *eFrame2, RealType *A1, RealType *A2, |
467 |
> |
RealType *t1, RealType *t2, RealType *rho1, RealType *rho2, |
468 |
> |
RealType *dfrho1, RealType *dfrho2, RealType *fshift1, |
469 |
> |
RealType *fshift2){ |
470 |
|
|
471 |
< |
return OpenMD::InteractionManager::Instance()->do_pair(atid1, atid2, d, r, r2, rcut, |
472 |
< |
sw, vdwMult, electroMult, pot, |
473 |
< |
vpair, f1, eFrame1, eFrame2, |
474 |
< |
A1, A2, t1, t2, rho1, rho2, |
475 |
< |
dfrho1, dfrho2, fshift1, fshift2); |
471 |
> |
return OpenMD::InteractionManager::Instance()->doPair(atid1, atid2, d, r, |
472 |
> |
r2, rcut, sw, |
473 |
> |
vdwMult, electroMult, |
474 |
> |
pot, vpair, f1, |
475 |
> |
eFrame1, eFrame2, |
476 |
> |
A1, A2, t1, t2, rho1, |
477 |
> |
rho2, dfrho1, dfrho2, |
478 |
> |
fshift1, fshift2); |
479 |
|
} |
480 |
< |
|
481 |
< |
void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d, RealType *r, |
482 |
< |
RealType *skippedCharge1, RealType *skippedCharge2, |
483 |
< |
RealType *sw, RealType *electroMult, RealType *pot, |
480 |
> |
|
481 |
> |
void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d, |
482 |
> |
RealType *r, RealType *skippedCharge1, |
483 |
> |
RealType *skippedCharge2, RealType *sw, |
484 |
> |
RealType *electroMult, RealType *pot, |
485 |
|
RealType *vpair, RealType *f1, |
486 |
|
RealType *eFrame1, RealType *eFrame2, |
487 |
|
RealType *t1, RealType *t2){ |
488 |
|
|
489 |
< |
return OpenMD::InteractionManager::Instance()->do_skip_correction(atid1, atid2, d, r, |
490 |
< |
skippedCharge1, |
491 |
< |
skippedCharge2, |
492 |
< |
sw, electroMult, pot, |
493 |
< |
vpair, f1, eFrame1, |
494 |
< |
eFrame2, t1, t2); |
489 |
> |
return OpenMD::InteractionManager::Instance()->doSkipCorrection(atid1, |
490 |
> |
atid2, d, |
491 |
> |
r, |
492 |
> |
skippedCharge1, |
493 |
> |
skippedCharge2, |
494 |
> |
sw, electroMult, pot, |
495 |
> |
vpair, f1, eFrame1, |
496 |
> |
eFrame2, t1, t2); |
497 |
|
} |
498 |
< |
|
498 |
> |
|
499 |
|
void fortranDoSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge, |
500 |
|
RealType *pot, RealType *t) { |
501 |
|
|
502 |
< |
return OpenMD::InteractionManager::Instance()->do_self_correction(atid, eFrame, |
503 |
< |
skippedCharge, |
504 |
< |
pot, t); |
502 |
> |
return OpenMD::InteractionManager::Instance()->doSelfCorrection(atid, |
503 |
> |
eFrame, |
504 |
> |
skippedCharge, |
505 |
> |
pot, t); |
506 |
|
} |
507 |
< |
RealType fortranGetCutoff() { |
508 |
< |
return OpenMD::InteractionManager::Instance()->getCutoff(); |
507 |
> |
RealType fortranGetCutoff(int *atid) { |
508 |
> |
return OpenMD::InteractionManager::Instance()->getSuggestedCutoffRadius(atid); |
509 |
|
} |
510 |
|
} |