35 |
|
* |
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). |
38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
44 |
|
* @file ForceManager.cpp |
45 |
|
* @author tlin |
46 |
|
* @date 11/09/2004 |
47 |
– |
* @time 10:39am |
47 |
|
* @version 1.0 |
48 |
|
*/ |
49 |
|
|
57 |
|
#include "primitives/Torsion.hpp" |
58 |
|
#include "primitives/Inversion.hpp" |
59 |
|
#include "nonbonded/NonBondedInteraction.hpp" |
60 |
+ |
#include "perturbations/ElectricField.hpp" |
61 |
|
#include "parallel/ForceMatrixDecomposition.hpp" |
62 |
|
|
63 |
|
#include <cstdio> |
67 |
|
using namespace std; |
68 |
|
namespace OpenMD { |
69 |
|
|
70 |
< |
ForceManager::ForceManager(SimInfo * info) : info_(info) { |
70 |
> |
ForceManager::ForceManager(SimInfo * info) : info_(info), switcher_(NULL) { |
71 |
|
forceField_ = info_->getForceField(); |
72 |
|
interactionMan_ = new InteractionManager(); |
73 |
|
fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_); |
74 |
+ |
thermo = new Thermo(info_); |
75 |
|
} |
76 |
|
|
77 |
+ |
ForceManager::~ForceManager() { |
78 |
+ |
perturbations_.clear(); |
79 |
+ |
|
80 |
+ |
delete switcher_; |
81 |
+ |
delete interactionMan_; |
82 |
+ |
delete fDecomp_; |
83 |
+ |
delete thermo; |
84 |
+ |
} |
85 |
+ |
|
86 |
|
/** |
87 |
|
* setupCutoffs |
88 |
|
* |
127 |
|
else |
128 |
|
mdFileVersion = 0; |
129 |
|
|
130 |
+ |
// We need the list of simulated atom types to figure out cutoffs |
131 |
+ |
// as well as long range corrections. |
132 |
+ |
|
133 |
+ |
set<AtomType*>::iterator i; |
134 |
+ |
set<AtomType*> atomTypes_; |
135 |
+ |
atomTypes_ = info_->getSimulatedAtomTypes(); |
136 |
+ |
|
137 |
|
if (simParams_->haveCutoffRadius()) { |
138 |
|
rCut_ = simParams_->getCutoffRadius(); |
139 |
|
} else { |
148 |
|
rCut_ = 12.0; |
149 |
|
} else { |
150 |
|
RealType thisCut; |
151 |
< |
set<AtomType*>::iterator i; |
135 |
< |
set<AtomType*> atomTypes; |
136 |
< |
atomTypes = info_->getSimulatedAtomTypes(); |
137 |
< |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
151 |
> |
for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) { |
152 |
|
thisCut = interactionMan_->getSuggestedCutoffRadius((*i)); |
153 |
|
rCut_ = max(thisCut, rCut_); |
154 |
|
} |
383 |
|
} |
384 |
|
switcher_->setSwitchType(sft_); |
385 |
|
switcher_->setSwitch(rSwitch_, rCut_); |
372 |
– |
interactionMan_->setSwitchingRadius(rSwitch_); |
386 |
|
} |
387 |
|
|
388 |
|
|
406 |
|
doParticlePot_ = info_->getSimParams()->getOutputParticlePotential(); |
407 |
|
doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux(); |
408 |
|
if (doHeatFlux_) doParticlePot_ = true; |
409 |
+ |
|
410 |
+ |
doElectricField_ = info_->getSimParams()->getOutputElectricField(); |
411 |
|
|
412 |
|
} |
413 |
|
|
438 |
|
electrostaticScale_[2] = fopts.getelectrostatic13scale(); |
439 |
|
electrostaticScale_[3] = fopts.getelectrostatic14scale(); |
440 |
|
|
441 |
< |
fDecomp_->distributeInitialData(); |
442 |
< |
|
443 |
< |
initialized_ = true; |
441 |
> |
if (info_->getSimParams()->haveElectricField()) { |
442 |
> |
ElectricField* eField = new ElectricField(info_); |
443 |
> |
perturbations_.push_back(eField); |
444 |
> |
} |
445 |
|
|
446 |
+ |
usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions(); |
447 |
+ |
|
448 |
+ |
fDecomp_->distributeInitialData(); |
449 |
+ |
|
450 |
+ |
initialized_ = true; |
451 |
+ |
|
452 |
|
} |
453 |
< |
|
453 |
> |
|
454 |
|
void ForceManager::calcForces() { |
455 |
|
|
456 |
|
if (!initialized_) initialize(); |
457 |
< |
|
457 |
> |
|
458 |
|
preCalculation(); |
459 |
|
shortRangeInteractions(); |
460 |
|
longRangeInteractions(); |
471 |
|
Molecule::CutoffGroupIterator ci; |
472 |
|
CutoffGroup* cg; |
473 |
|
|
474 |
< |
// forces are zeroed here, before any are accumulated. |
474 |
> |
// forces and potentials are zeroed here, before any are |
475 |
> |
// accumulated. |
476 |
|
|
477 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
478 |
+ |
|
479 |
+ |
snap->setBondPotential(0.0); |
480 |
+ |
snap->setBendPotential(0.0); |
481 |
+ |
snap->setTorsionPotential(0.0); |
482 |
+ |
snap->setInversionPotential(0.0); |
483 |
+ |
|
484 |
+ |
potVec zeroPot(0.0); |
485 |
+ |
snap->setLongRangePotential(zeroPot); |
486 |
+ |
snap->setExcludedPotentials(zeroPot); |
487 |
+ |
|
488 |
+ |
snap->setRestraintPotential(0.0); |
489 |
+ |
snap->setRawPotential(0.0); |
490 |
+ |
|
491 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
492 |
|
mol = info_->nextMolecule(mi)) { |
493 |
|
for(atom = mol->beginAtom(ai); atom != NULL; |
645 |
|
curSnapshot->setTorsionPotential(torsionPotential); |
646 |
|
curSnapshot->setInversionPotential(inversionPotential); |
647 |
|
|
648 |
< |
RealType shortRangePotential = bondPotential + bendPotential + |
649 |
< |
torsionPotential + inversionPotential; |
648 |
> |
// RealType shortRangePotential = bondPotential + bendPotential + |
649 |
> |
// torsionPotential + inversionPotential; |
650 |
|
|
651 |
< |
curSnapshot->setShortRangePotential(shortRangePotential); |
651 |
> |
// curSnapshot->setShortRangePotential(shortRangePotential); |
652 |
|
} |
653 |
|
|
654 |
|
void ForceManager::longRangeInteractions() { |
697 |
|
InteractionData idat; |
698 |
|
SelfData sdat; |
699 |
|
RealType mf; |
663 |
– |
RealType lrPot; |
700 |
|
RealType vpair; |
701 |
|
RealType dVdFQ1(0.0); |
702 |
|
RealType dVdFQ2(0.0); |
703 |
|
potVec longRangePotential(0.0); |
704 |
|
potVec workPot(0.0); |
705 |
|
potVec exPot(0.0); |
706 |
+ |
Vector3d eField1(0.0); |
707 |
+ |
Vector3d eField2(0.0); |
708 |
|
vector<int>::iterator ia, jb; |
709 |
|
|
710 |
|
int loopStart, loopEnd; |
714 |
|
idat.pot = &workPot; |
715 |
|
idat.excludedPot = &exPot; |
716 |
|
sdat.pot = fDecomp_->getEmbeddingPotential(); |
717 |
+ |
sdat.excludedPot = fDecomp_->getExcludedSelfPotential(); |
718 |
|
idat.vpair = &vpair; |
719 |
|
idat.dVdFQ1 = &dVdFQ1; |
720 |
|
idat.dVdFQ2 = &dVdFQ2; |
721 |
+ |
idat.eField1 = &eField1; |
722 |
+ |
idat.eField2 = &eField2; |
723 |
|
idat.f1 = &f1; |
724 |
|
idat.sw = &sw; |
725 |
|
idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; |
726 |
|
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; |
727 |
|
idat.doParticlePot = doParticlePot_; |
728 |
+ |
idat.doElectricField = doElectricField_; |
729 |
|
sdat.doParticlePot = doParticlePot_; |
730 |
|
|
731 |
|
loopEnd = PAIR_LOOP; |
738 |
|
|
739 |
|
if (iLoop == loopStart) { |
740 |
|
bool update_nlist = fDecomp_->checkNeighborList(); |
741 |
< |
if (update_nlist) |
741 |
> |
if (update_nlist) { |
742 |
> |
if (!usePeriodicBoundaryConditions_) |
743 |
> |
Mat3x3d bbox = thermo->getBoundingBox(); |
744 |
|
neighborList = fDecomp_->buildNeighborList(); |
745 |
< |
} |
745 |
> |
} |
746 |
> |
} |
747 |
|
|
748 |
|
for (vector<pair<int, int> >::iterator it = neighborList.begin(); |
749 |
|
it != neighborList.end(); ++it) { |
764 |
|
if (iLoop == PAIR_LOOP) { |
765 |
|
vij = 0.0; |
766 |
|
fij = V3Zero; |
767 |
+ |
eField1 = V3Zero; |
768 |
+ |
eField2 = V3Zero; |
769 |
|
} |
770 |
|
|
771 |
|
in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, |
840 |
|
fij += fg; |
841 |
|
|
842 |
|
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
843 |
< |
stressTensor -= outProduct( *(idat.d), fg); |
844 |
< |
if (doHeatFlux_) |
845 |
< |
fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2)); |
846 |
< |
|
843 |
> |
if (!fDecomp_->skipAtomPair(atomListRow[0], |
844 |
> |
atomListColumn[0], |
845 |
> |
cg1, cg2)) { |
846 |
> |
stressTensor -= outProduct( *(idat.d), fg); |
847 |
> |
if (doHeatFlux_) |
848 |
> |
fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2)); |
849 |
> |
} |
850 |
|
} |
851 |
|
|
852 |
|
for (ia = atomListRow.begin(); |
903 |
|
|
904 |
|
fDecomp_->collectIntermediateData(); |
905 |
|
|
906 |
< |
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
906 |
> |
for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
907 |
|
fDecomp_->fillSelfData(sdat, atom1); |
908 |
|
interactionMan_->doPreForce(sdat); |
909 |
|
} |
918 |
|
fDecomp_->collectData(); |
919 |
|
|
920 |
|
if (info_->requiresSelfCorrection()) { |
921 |
< |
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
921 |
> |
for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
922 |
|
fDecomp_->fillSelfData(sdat, atom1); |
923 |
|
interactionMan_->doSelfCorrection(sdat); |
924 |
|
} |
930 |
|
longRangePotential = *(fDecomp_->getEmbeddingPotential()) + |
931 |
|
*(fDecomp_->getPairwisePotential()); |
932 |
|
|
933 |
< |
curSnapshot->setLongRangePotentialFamilies(longRangePotential); |
933 |
> |
curSnapshot->setLongRangePotential(longRangePotential); |
934 |
> |
|
935 |
> |
curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedSelfPotential()) + |
936 |
> |
*(fDecomp_->getExcludedPotential())); |
937 |
|
|
885 |
– |
lrPot = longRangePotential.sum(); |
886 |
– |
|
887 |
– |
//store the long range potential |
888 |
– |
curSnapshot->setLongRangePotential(lrPot); |
889 |
– |
|
890 |
– |
curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedPotential())); |
891 |
– |
|
938 |
|
} |
939 |
|
|
940 |
|
|
941 |
|
void ForceManager::postCalculation() { |
942 |
+ |
|
943 |
+ |
vector<Perturbation*>::iterator pi; |
944 |
+ |
for (pi = perturbations_.begin(); pi != perturbations_.end(); ++pi) { |
945 |
+ |
(*pi)->applyPerturbation(); |
946 |
+ |
} |
947 |
+ |
|
948 |
|
SimInfo::MoleculeIterator mi; |
949 |
|
Molecule* mol; |
950 |
|
Molecule::RigidBodyIterator rbIter; |
951 |
|
RigidBody* rb; |
952 |
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
953 |
< |
|
953 |
> |
|
954 |
|
// collect the atomic forces onto rigid bodies |
955 |
|
|
956 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
968 |
|
#endif |
969 |
|
curSnapshot->setStressTensor(stressTensor); |
970 |
|
|
971 |
< |
} |
971 |
> |
if (info_->getSimParams()->getUseLongRangeCorrections()) { |
972 |
> |
/* |
973 |
> |
RealType vol = curSnapshot->getVolume(); |
974 |
> |
RealType Elrc(0.0); |
975 |
> |
RealType Wlrc(0.0); |
976 |
|
|
977 |
< |
} //end namespace OpenMD |
977 |
> |
set<AtomType*>::iterator i; |
978 |
> |
set<AtomType*>::iterator j; |
979 |
> |
|
980 |
> |
RealType n_i, n_j; |
981 |
> |
RealType rho_i, rho_j; |
982 |
> |
pair<RealType, RealType> LRI; |
983 |
> |
|
984 |
> |
for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) { |
985 |
> |
n_i = RealType(info_->getGlobalCountOfType(*i)); |
986 |
> |
rho_i = n_i / vol; |
987 |
> |
for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) { |
988 |
> |
n_j = RealType(info_->getGlobalCountOfType(*j)); |
989 |
> |
rho_j = n_j / vol; |
990 |
> |
|
991 |
> |
LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) ); |
992 |
> |
|
993 |
> |
Elrc += n_i * rho_j * LRI.first; |
994 |
> |
Wlrc -= rho_i * rho_j * LRI.second; |
995 |
> |
} |
996 |
> |
} |
997 |
> |
Elrc *= 2.0 * NumericConstant::PI; |
998 |
> |
Wlrc *= 2.0 * NumericConstant::PI; |
999 |
> |
|
1000 |
> |
RealType lrp = curSnapshot->getLongRangePotential(); |
1001 |
> |
curSnapshot->setLongRangePotential(lrp + Elrc); |
1002 |
> |
stressTensor += Wlrc * SquareMatrix3<RealType>::identity(); |
1003 |
> |
curSnapshot->setStressTensor(stressTensor); |
1004 |
> |
*/ |
1005 |
> |
|
1006 |
> |
} |
1007 |
> |
} |
1008 |
> |
} |