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 |
> |
initialized_(false) { |
72 |
|
forceField_ = info_->getForceField(); |
73 |
|
interactionMan_ = new InteractionManager(); |
74 |
|
fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_); |
75 |
+ |
thermo = new Thermo(info_); |
76 |
|
} |
77 |
|
|
78 |
+ |
ForceManager::~ForceManager() { |
79 |
+ |
perturbations_.clear(); |
80 |
+ |
|
81 |
+ |
delete switcher_; |
82 |
+ |
delete interactionMan_; |
83 |
+ |
delete fDecomp_; |
84 |
+ |
delete thermo; |
85 |
+ |
} |
86 |
+ |
|
87 |
|
/** |
88 |
|
* setupCutoffs |
89 |
|
* |
128 |
|
else |
129 |
|
mdFileVersion = 0; |
130 |
|
|
131 |
+ |
// We need the list of simulated atom types to figure out cutoffs |
132 |
+ |
// as well as long range corrections. |
133 |
+ |
|
134 |
+ |
set<AtomType*>::iterator i; |
135 |
+ |
set<AtomType*> atomTypes_; |
136 |
+ |
atomTypes_ = info_->getSimulatedAtomTypes(); |
137 |
+ |
|
138 |
|
if (simParams_->haveCutoffRadius()) { |
139 |
|
rCut_ = simParams_->getCutoffRadius(); |
140 |
|
} else { |
149 |
|
rCut_ = 12.0; |
150 |
|
} else { |
151 |
|
RealType thisCut; |
152 |
< |
set<AtomType*>::iterator i; |
135 |
< |
set<AtomType*> atomTypes; |
136 |
< |
atomTypes = info_->getSimulatedAtomTypes(); |
137 |
< |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
152 |
> |
for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) { |
153 |
|
thisCut = interactionMan_->getSuggestedCutoffRadius((*i)); |
154 |
|
rCut_ = max(thisCut, rCut_); |
155 |
|
} |
384 |
|
} |
385 |
|
switcher_->setSwitchType(sft_); |
386 |
|
switcher_->setSwitch(rSwitch_, rCut_); |
372 |
– |
interactionMan_->setSwitchingRadius(rSwitch_); |
387 |
|
} |
388 |
|
|
389 |
|
|
407 |
|
doParticlePot_ = info_->getSimParams()->getOutputParticlePotential(); |
408 |
|
doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux(); |
409 |
|
if (doHeatFlux_) doParticlePot_ = true; |
410 |
+ |
|
411 |
+ |
doElectricField_ = info_->getSimParams()->getOutputElectricField(); |
412 |
|
|
413 |
|
} |
414 |
|
|
439 |
|
electrostaticScale_[2] = fopts.getelectrostatic13scale(); |
440 |
|
electrostaticScale_[3] = fopts.getelectrostatic14scale(); |
441 |
|
|
442 |
< |
fDecomp_->distributeInitialData(); |
443 |
< |
|
444 |
< |
initialized_ = true; |
442 |
> |
if (info_->getSimParams()->haveElectricField()) { |
443 |
> |
ElectricField* eField = new ElectricField(info_); |
444 |
> |
perturbations_.push_back(eField); |
445 |
> |
} |
446 |
|
|
447 |
+ |
usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions(); |
448 |
+ |
|
449 |
+ |
fDecomp_->distributeInitialData(); |
450 |
+ |
|
451 |
+ |
initialized_ = true; |
452 |
+ |
|
453 |
|
} |
454 |
< |
|
454 |
> |
|
455 |
|
void ForceManager::calcForces() { |
456 |
|
|
457 |
|
if (!initialized_) initialize(); |
458 |
< |
|
458 |
> |
|
459 |
|
preCalculation(); |
460 |
|
shortRangeInteractions(); |
461 |
|
longRangeInteractions(); |
694 |
|
RealType rCutSq; |
695 |
|
bool in_switching_region; |
696 |
|
RealType sw, dswdr, swderiv; |
697 |
< |
vector<int> atomListColumn, atomListRow, atomListLocal; |
697 |
> |
vector<int> atomListColumn, atomListRow; |
698 |
|
InteractionData idat; |
699 |
|
SelfData sdat; |
700 |
|
RealType mf; |
678 |
– |
RealType lrPot; |
701 |
|
RealType vpair; |
702 |
|
RealType dVdFQ1(0.0); |
703 |
|
RealType dVdFQ2(0.0); |
704 |
|
potVec longRangePotential(0.0); |
705 |
|
potVec workPot(0.0); |
706 |
|
potVec exPot(0.0); |
707 |
+ |
Vector3d eField1(0.0); |
708 |
+ |
Vector3d eField2(0.0); |
709 |
|
vector<int>::iterator ia, jb; |
710 |
|
|
711 |
|
int loopStart, loopEnd; |
719 |
|
idat.vpair = &vpair; |
720 |
|
idat.dVdFQ1 = &dVdFQ1; |
721 |
|
idat.dVdFQ2 = &dVdFQ2; |
722 |
+ |
idat.eField1 = &eField1; |
723 |
+ |
idat.eField2 = &eField2; |
724 |
|
idat.f1 = &f1; |
725 |
|
idat.sw = &sw; |
726 |
|
idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; |
727 |
|
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; |
728 |
|
idat.doParticlePot = doParticlePot_; |
729 |
+ |
idat.doElectricField = doElectricField_; |
730 |
|
sdat.doParticlePot = doParticlePot_; |
731 |
|
|
732 |
|
loopEnd = PAIR_LOOP; |
739 |
|
|
740 |
|
if (iLoop == loopStart) { |
741 |
|
bool update_nlist = fDecomp_->checkNeighborList(); |
742 |
< |
if (update_nlist) |
742 |
> |
if (update_nlist) { |
743 |
> |
if (!usePeriodicBoundaryConditions_) |
744 |
> |
Mat3x3d bbox = thermo->getBoundingBox(); |
745 |
|
neighborList = fDecomp_->buildNeighborList(); |
746 |
< |
} |
746 |
> |
} |
747 |
> |
} |
748 |
|
|
749 |
|
for (vector<pair<int, int> >::iterator it = neighborList.begin(); |
750 |
|
it != neighborList.end(); ++it) { |
765 |
|
if (iLoop == PAIR_LOOP) { |
766 |
|
vij = 0.0; |
767 |
|
fij = V3Zero; |
768 |
+ |
eField1 = V3Zero; |
769 |
+ |
eField2 = V3Zero; |
770 |
|
} |
771 |
|
|
772 |
|
in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, |
841 |
|
fij += fg; |
842 |
|
|
843 |
|
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
844 |
< |
stressTensor -= outProduct( *(idat.d), fg); |
845 |
< |
if (doHeatFlux_) |
846 |
< |
fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2)); |
847 |
< |
|
844 |
> |
if (!fDecomp_->skipAtomPair(atomListRow[0], |
845 |
> |
atomListColumn[0], |
846 |
> |
cg1, cg2)) { |
847 |
> |
stressTensor -= outProduct( *(idat.d), fg); |
848 |
> |
if (doHeatFlux_) |
849 |
> |
fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2)); |
850 |
> |
} |
851 |
|
} |
852 |
|
|
853 |
|
for (ia = atomListRow.begin(); |
904 |
|
|
905 |
|
fDecomp_->collectIntermediateData(); |
906 |
|
|
907 |
< |
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
907 |
> |
for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
908 |
|
fDecomp_->fillSelfData(sdat, atom1); |
909 |
|
interactionMan_->doPreForce(sdat); |
910 |
|
} |
919 |
|
fDecomp_->collectData(); |
920 |
|
|
921 |
|
if (info_->requiresSelfCorrection()) { |
922 |
< |
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
922 |
> |
for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
923 |
|
fDecomp_->fillSelfData(sdat, atom1); |
924 |
|
interactionMan_->doSelfCorrection(sdat); |
925 |
|
} |
932 |
|
*(fDecomp_->getPairwisePotential()); |
933 |
|
|
934 |
|
curSnapshot->setLongRangePotential(longRangePotential); |
900 |
– |
|
901 |
– |
// lrPot = longRangePotential.sum(); |
902 |
– |
|
903 |
– |
// //store the long range potential |
904 |
– |
// curSnapshot->setLongRangePotential(lrPot); |
935 |
|
|
936 |
|
curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedSelfPotential()) + |
937 |
|
*(fDecomp_->getExcludedPotential())); |
940 |
|
|
941 |
|
|
942 |
|
void ForceManager::postCalculation() { |
943 |
+ |
|
944 |
+ |
vector<Perturbation*>::iterator pi; |
945 |
+ |
for (pi = perturbations_.begin(); pi != perturbations_.end(); ++pi) { |
946 |
+ |
(*pi)->applyPerturbation(); |
947 |
+ |
} |
948 |
+ |
|
949 |
|
SimInfo::MoleculeIterator mi; |
950 |
|
Molecule* mol; |
951 |
|
Molecule::RigidBodyIterator rbIter; |
969 |
|
#endif |
970 |
|
curSnapshot->setStressTensor(stressTensor); |
971 |
|
|
972 |
< |
} |
972 |
> |
if (info_->getSimParams()->getUseLongRangeCorrections()) { |
973 |
> |
/* |
974 |
> |
RealType vol = curSnapshot->getVolume(); |
975 |
> |
RealType Elrc(0.0); |
976 |
> |
RealType Wlrc(0.0); |
977 |
|
|
978 |
< |
} //end namespace OpenMD |
978 |
> |
set<AtomType*>::iterator i; |
979 |
> |
set<AtomType*>::iterator j; |
980 |
> |
|
981 |
> |
RealType n_i, n_j; |
982 |
> |
RealType rho_i, rho_j; |
983 |
> |
pair<RealType, RealType> LRI; |
984 |
> |
|
985 |
> |
for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) { |
986 |
> |
n_i = RealType(info_->getGlobalCountOfType(*i)); |
987 |
> |
rho_i = n_i / vol; |
988 |
> |
for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) { |
989 |
> |
n_j = RealType(info_->getGlobalCountOfType(*j)); |
990 |
> |
rho_j = n_j / vol; |
991 |
> |
|
992 |
> |
LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) ); |
993 |
> |
|
994 |
> |
Elrc += n_i * rho_j * LRI.first; |
995 |
> |
Wlrc -= rho_i * rho_j * LRI.second; |
996 |
> |
} |
997 |
> |
} |
998 |
> |
Elrc *= 2.0 * NumericConstant::PI; |
999 |
> |
Wlrc *= 2.0 * NumericConstant::PI; |
1000 |
> |
|
1001 |
> |
RealType lrp = curSnapshot->getLongRangePotential(); |
1002 |
> |
curSnapshot->setLongRangePotential(lrp + Elrc); |
1003 |
> |
stressTensor += Wlrc * SquareMatrix3<RealType>::identity(); |
1004 |
> |
curSnapshot->setStressTensor(stressTensor); |
1005 |
> |
*/ |
1006 |
> |
|
1007 |
> |
} |
1008 |
> |
} |
1009 |
> |
} |