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