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" |
60 |
> |
#include "perturbations/UniformField.hpp" |
61 |
> |
#include "perturbations/UniformGradient.hpp" |
62 |
|
#include "parallel/ForceMatrixDecomposition.hpp" |
63 |
|
|
64 |
|
#include <cstdio> |
68 |
|
using namespace std; |
69 |
|
namespace OpenMD { |
70 |
|
|
71 |
< |
ForceManager::ForceManager(SimInfo * info) : info_(info) { |
71 |
> |
ForceManager::ForceManager(SimInfo * info) : info_(info), switcher_(NULL), |
72 |
> |
initialized_(false) { |
73 |
|
forceField_ = info_->getForceField(); |
74 |
|
interactionMan_ = new InteractionManager(); |
75 |
|
fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_); |
76 |
+ |
thermo = new Thermo(info_); |
77 |
|
} |
78 |
|
|
79 |
+ |
ForceManager::~ForceManager() { |
80 |
+ |
perturbations_.clear(); |
81 |
+ |
|
82 |
+ |
delete switcher_; |
83 |
+ |
delete interactionMan_; |
84 |
+ |
delete fDecomp_; |
85 |
+ |
delete thermo; |
86 |
+ |
} |
87 |
+ |
|
88 |
|
/** |
89 |
|
* setupCutoffs |
90 |
|
* |
99 |
|
* simulation for suggested cutoff values (e.g. 2.5 * sigma). |
100 |
|
* Use the maximum suggested value that was found. |
101 |
|
* |
102 |
< |
* cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, |
103 |
< |
* or SHIFTED_POTENTIAL) |
102 |
> |
* cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, TAYLOR_SHIFTED, |
103 |
> |
* SHIFTED_POTENTIAL, or EWALD_FULL) |
104 |
|
* If cutoffMethod was explicitly set, use that choice. |
105 |
|
* If cutoffMethod was not explicitly set, use SHIFTED_FORCE |
106 |
|
* |
129 |
|
else |
130 |
|
mdFileVersion = 0; |
131 |
|
|
132 |
+ |
// We need the list of simulated atom types to figure out cutoffs |
133 |
+ |
// as well as long range corrections. |
134 |
+ |
|
135 |
+ |
set<AtomType*>::iterator i; |
136 |
+ |
set<AtomType*> atomTypes_; |
137 |
+ |
atomTypes_ = info_->getSimulatedAtomTypes(); |
138 |
+ |
|
139 |
|
if (simParams_->haveCutoffRadius()) { |
140 |
|
rCut_ = simParams_->getCutoffRadius(); |
141 |
|
} else { |
150 |
|
rCut_ = 12.0; |
151 |
|
} else { |
152 |
|
RealType thisCut; |
153 |
< |
set<AtomType*>::iterator i; |
136 |
< |
set<AtomType*> atomTypes; |
137 |
< |
atomTypes = info_->getSimulatedAtomTypes(); |
138 |
< |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
153 |
> |
for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) { |
154 |
|
thisCut = interactionMan_->getSuggestedCutoffRadius((*i)); |
155 |
|
rCut_ = max(thisCut, rCut_); |
156 |
|
} |
172 |
|
stringToCutoffMethod["SWITCHED"] = SWITCHED; |
173 |
|
stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL; |
174 |
|
stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE; |
175 |
+ |
stringToCutoffMethod["TAYLOR_SHIFTED"] = TAYLOR_SHIFTED; |
176 |
+ |
stringToCutoffMethod["EWALD_FULL"] = EWALD_FULL; |
177 |
|
|
178 |
|
if (simParams_->haveCutoffMethod()) { |
179 |
|
string cutMeth = toUpperCopy(simParams_->getCutoffMethod()); |
183 |
|
sprintf(painCave.errMsg, |
184 |
|
"ForceManager::setupCutoffs: Could not find chosen cutoffMethod %s\n" |
185 |
|
"\tShould be one of: " |
186 |
< |
"HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n", |
186 |
> |
"HARD, SWITCHED, SHIFTED_POTENTIAL, TAYLOR_SHIFTED,\n" |
187 |
> |
"\tSHIFTED_FORCE, or EWALD_FULL\n", |
188 |
|
cutMeth.c_str()); |
189 |
|
painCave.isFatal = 1; |
190 |
|
painCave.severity = OPENMD_ERROR; |
228 |
|
cutoffMethod_ = SHIFTED_POTENTIAL; |
229 |
|
} else if (myMethod == "SHIFTED_FORCE") { |
230 |
|
cutoffMethod_ = SHIFTED_FORCE; |
231 |
+ |
} else if (myMethod == "TAYLOR_SHIFTED") { |
232 |
+ |
cutoffMethod_ = TAYLOR_SHIFTED; |
233 |
+ |
} else if (myMethod == "EWALD_FULL") { |
234 |
+ |
cutoffMethod_ = EWALD_FULL; |
235 |
|
} |
236 |
|
|
237 |
|
if (simParams_->haveSwitchingRadius()) |
238 |
|
rSwitch_ = simParams_->getSwitchingRadius(); |
239 |
|
|
240 |
< |
if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") { |
240 |
> |
if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE" || |
241 |
> |
myMethod == "TAYLOR_SHIFTED" || myMethod == "EWALD_FULL") { |
242 |
|
if (simParams_->haveSwitchingRadius()){ |
243 |
|
sprintf(painCave.errMsg, |
244 |
|
"ForceManager::setupCutoffs : DEPRECATED ERROR MESSAGE\n" |
393 |
|
} |
394 |
|
switcher_->setSwitchType(sft_); |
395 |
|
switcher_->setSwitch(rSwitch_, rCut_); |
373 |
– |
interactionMan_->setSwitchingRadius(rSwitch_); |
396 |
|
} |
397 |
|
|
376 |
– |
|
377 |
– |
|
378 |
– |
|
398 |
|
void ForceManager::initialize() { |
399 |
|
|
400 |
|
if (!info_->isTopologyDone()) { |
403 |
|
interactionMan_->setSimInfo(info_); |
404 |
|
interactionMan_->initialize(); |
405 |
|
|
406 |
< |
// We want to delay the cutoffs until after the interaction |
407 |
< |
// manager has set up the atom-atom interactions so that we can |
408 |
< |
// query them for suggested cutoff values |
406 |
> |
//! We want to delay the cutoffs until after the interaction |
407 |
> |
//! manager has set up the atom-atom interactions so that we can |
408 |
> |
//! query them for suggested cutoff values |
409 |
|
setupCutoffs(); |
410 |
|
|
411 |
|
info_->prepareTopology(); |
413 |
|
doParticlePot_ = info_->getSimParams()->getOutputParticlePotential(); |
414 |
|
doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux(); |
415 |
|
if (doHeatFlux_) doParticlePot_ = true; |
416 |
+ |
|
417 |
+ |
doElectricField_ = info_->getSimParams()->getOutputElectricField(); |
418 |
+ |
doSitePotential_ = info_->getSimParams()->getOutputSitePotential(); |
419 |
|
|
420 |
|
} |
421 |
|
|
422 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
423 |
|
|
424 |
< |
// Force fields can set options on how to scale van der Waals and |
425 |
< |
// electrostatic interactions for atoms connected via bonds, bends |
426 |
< |
// and torsions in this case the topological distance between |
427 |
< |
// atoms is: |
428 |
< |
// 0 = topologically unconnected |
429 |
< |
// 1 = bonded together |
430 |
< |
// 2 = connected via a bend |
431 |
< |
// 3 = connected via a torsion |
424 |
> |
//! Force fields can set options on how to scale van der Waals and |
425 |
> |
//! electrostatic interactions for atoms connected via bonds, bends |
426 |
> |
//! and torsions in this case the topological distance between |
427 |
> |
//! atoms is: |
428 |
> |
//! 0 = topologically unconnected |
429 |
> |
//! 1 = bonded together |
430 |
> |
//! 2 = connected via a bend |
431 |
> |
//! 3 = connected via a torsion |
432 |
|
|
433 |
|
vdwScale_.reserve(4); |
434 |
|
fill(vdwScale_.begin(), vdwScale_.end(), 0.0); |
446 |
|
electrostaticScale_[2] = fopts.getelectrostatic13scale(); |
447 |
|
electrostaticScale_[3] = fopts.getelectrostatic14scale(); |
448 |
|
|
449 |
< |
if (info_->getSimParams()->haveElectricField()) { |
450 |
< |
ElectricField* eField = new ElectricField(info_); |
449 |
> |
if (info_->getSimParams()->haveUniformField()) { |
450 |
> |
UniformField* eField = new UniformField(info_); |
451 |
|
perturbations_.push_back(eField); |
452 |
|
} |
453 |
< |
|
453 |
> |
if (info_->getSimParams()->haveUniformGradientStrength() || |
454 |
> |
info_->getSimParams()->haveUniformGradientDirection1() || |
455 |
> |
info_->getSimParams()->haveUniformGradientDirection2() ) { |
456 |
> |
UniformGradient* eGrad = new UniformGradient(info_); |
457 |
> |
perturbations_.push_back(eGrad); |
458 |
> |
} |
459 |
> |
|
460 |
> |
usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions(); |
461 |
> |
|
462 |
|
fDecomp_->distributeInitialData(); |
463 |
< |
|
463 |
> |
|
464 |
|
initialized_ = true; |
465 |
< |
|
465 |
> |
|
466 |
|
} |
467 |
< |
|
467 |
> |
|
468 |
|
void ForceManager::calcForces() { |
469 |
|
|
470 |
|
if (!initialized_) initialize(); |
471 |
< |
|
471 |
> |
|
472 |
|
preCalculation(); |
473 |
|
shortRangeInteractions(); |
474 |
|
longRangeInteractions(); |
642 |
|
// Collect from all nodes. This should eventually be moved into a |
643 |
|
// SystemDecomposition, but this is a better place than in |
644 |
|
// Thermo to do the collection. |
645 |
< |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bondPotential, 1, MPI::REALTYPE, |
646 |
< |
MPI::SUM); |
647 |
< |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bendPotential, 1, MPI::REALTYPE, |
648 |
< |
MPI::SUM); |
649 |
< |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &torsionPotential, 1, |
650 |
< |
MPI::REALTYPE, MPI::SUM); |
651 |
< |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &inversionPotential, 1, |
652 |
< |
MPI::REALTYPE, MPI::SUM); |
645 |
> |
|
646 |
> |
MPI_Allreduce(MPI_IN_PLACE, &bondPotential, 1, MPI_REALTYPE, |
647 |
> |
MPI_SUM, MPI_COMM_WORLD); |
648 |
> |
MPI_Allreduce(MPI_IN_PLACE, &bendPotential, 1, MPI_REALTYPE, |
649 |
> |
MPI_SUM, MPI_COMM_WORLD); |
650 |
> |
MPI_Allreduce(MPI_IN_PLACE, &torsionPotential, 1, |
651 |
> |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
652 |
> |
MPI_Allreduce(MPI_IN_PLACE, &inversionPotential, 1, |
653 |
> |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
654 |
|
#endif |
655 |
|
|
656 |
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
668 |
|
|
669 |
|
void ForceManager::longRangeInteractions() { |
670 |
|
|
640 |
– |
|
671 |
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
672 |
|
DataStorage* config = &(curSnapshot->atomData); |
673 |
|
DataStorage* cgConfig = &(curSnapshot->cgData); |
674 |
|
|
675 |
+ |
|
676 |
|
//calculate the center of mass of cutoff group |
677 |
|
|
678 |
|
SimInfo::MoleculeIterator mi; |
705 |
|
RealType vij; |
706 |
|
Vector3d fij, fg, f1; |
707 |
|
tuple3<RealType, RealType, RealType> cuts; |
708 |
< |
RealType rCutSq; |
708 |
> |
RealType rCut, rCutSq, rListSq; |
709 |
|
bool in_switching_region; |
710 |
|
RealType sw, dswdr, swderiv; |
711 |
< |
vector<int> atomListColumn, atomListRow, atomListLocal; |
711 |
> |
vector<int> atomListColumn, atomListRow; |
712 |
|
InteractionData idat; |
713 |
|
SelfData sdat; |
714 |
|
RealType mf; |
715 |
|
RealType vpair; |
716 |
|
RealType dVdFQ1(0.0); |
717 |
|
RealType dVdFQ2(0.0); |
687 |
– |
Vector3d eField1(0.0); |
688 |
– |
Vector3d eField2(0.0); |
718 |
|
potVec longRangePotential(0.0); |
719 |
+ |
RealType reciprocalPotential(0.0); |
720 |
|
potVec workPot(0.0); |
721 |
|
potVec exPot(0.0); |
722 |
+ |
Vector3d eField1(0.0); |
723 |
+ |
Vector3d eField2(0.0); |
724 |
+ |
RealType sPot1(0.0); |
725 |
+ |
RealType sPot2(0.0); |
726 |
+ |
|
727 |
|
vector<int>::iterator ia, jb; |
728 |
|
|
729 |
|
int loopStart, loopEnd; |
730 |
< |
|
730 |
> |
|
731 |
> |
idat.rcut = &rCut; |
732 |
|
idat.vdwMult = &vdwMult; |
733 |
|
idat.electroMult = &electroMult; |
734 |
|
idat.pot = &workPot; |
739 |
|
idat.dVdFQ1 = &dVdFQ1; |
740 |
|
idat.dVdFQ2 = &dVdFQ2; |
741 |
|
idat.eField1 = &eField1; |
742 |
< |
idat.eField2 = &eField2; |
742 |
> |
idat.eField2 = &eField2; |
743 |
> |
idat.sPot1 = &sPot1; |
744 |
> |
idat.sPot2 = &sPot2; |
745 |
|
idat.f1 = &f1; |
746 |
|
idat.sw = &sw; |
747 |
|
idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; |
748 |
< |
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; |
748 |
> |
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE || |
749 |
> |
cutoffMethod_ == TAYLOR_SHIFTED) ? true : false; |
750 |
|
idat.doParticlePot = doParticlePot_; |
751 |
+ |
idat.doElectricField = doElectricField_; |
752 |
+ |
idat.doSitePotential = doSitePotential_; |
753 |
|
sdat.doParticlePot = doParticlePot_; |
754 |
|
|
755 |
|
loopEnd = PAIR_LOOP; |
762 |
|
|
763 |
|
if (iLoop == loopStart) { |
764 |
|
bool update_nlist = fDecomp_->checkNeighborList(); |
765 |
< |
if (update_nlist) |
766 |
< |
neighborList = fDecomp_->buildNeighborList(); |
767 |
< |
} |
765 |
> |
if (update_nlist) { |
766 |
> |
if (!usePeriodicBoundaryConditions_) |
767 |
> |
Mat3x3d bbox = thermo->getBoundingBox(); |
768 |
> |
fDecomp_->buildNeighborList(neighborList_); |
769 |
> |
} |
770 |
> |
} |
771 |
|
|
772 |
< |
for (vector<pair<int, int> >::iterator it = neighborList.begin(); |
773 |
< |
it != neighborList.end(); ++it) { |
772 |
> |
for (vector<pair<int, int> >::iterator it = neighborList_.begin(); |
773 |
> |
it != neighborList_.end(); ++it) { |
774 |
|
|
775 |
|
cg1 = (*it).first; |
776 |
|
cg2 = (*it).second; |
777 |
|
|
778 |
< |
cuts = fDecomp_->getGroupCutoffs(cg1, cg2); |
778 |
> |
fDecomp_->getGroupCutoffs(cg1, cg2, rCut, rCutSq, rListSq); |
779 |
|
|
780 |
|
d_grp = fDecomp_->getIntergroupVector(cg1, cg2); |
781 |
|
|
782 |
< |
curSnapshot->wrapVector(d_grp); |
782 |
> |
// already wrapped in the getIntergroupVector call: |
783 |
> |
// curSnapshot->wrapVector(d_grp); |
784 |
|
rgrpsq = d_grp.lengthSquare(); |
740 |
– |
rCutSq = cuts.second; |
785 |
|
|
786 |
|
if (rgrpsq < rCutSq) { |
743 |
– |
idat.rcut = &cuts.first; |
787 |
|
if (iLoop == PAIR_LOOP) { |
788 |
|
vij = 0.0; |
789 |
< |
fij = V3Zero; |
789 |
> |
fij.zero(); |
790 |
> |
eField1.zero(); |
791 |
> |
eField2.zero(); |
792 |
> |
sPot1 = 0.0; |
793 |
> |
sPot2 = 0.0; |
794 |
|
} |
795 |
|
|
796 |
|
in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, |
815 |
|
vpair = 0.0; |
816 |
|
workPot = 0.0; |
817 |
|
exPot = 0.0; |
818 |
< |
f1 = V3Zero; |
818 |
> |
f1.zero(); |
819 |
|
dVdFQ1 = 0.0; |
820 |
|
dVdFQ2 = 0.0; |
821 |
|
|
842 |
|
|
843 |
|
r = sqrt( *(idat.r2) ); |
844 |
|
idat.rij = &r; |
845 |
< |
|
845 |
> |
|
846 |
|
if (iLoop == PREPAIR_LOOP) { |
847 |
|
interactionMan_->doPrePair(idat); |
848 |
|
} else { |
938 |
|
} |
939 |
|
} |
940 |
|
} |
941 |
< |
|
941 |
> |
|
942 |
|
// collects pairwise information |
943 |
|
fDecomp_->collectData(); |
944 |
+ |
if (cutoffMethod_ == EWALD_FULL) { |
945 |
+ |
interactionMan_->doReciprocalSpaceSum(reciprocalPotential); |
946 |
+ |
|
947 |
+ |
curSnapshot->setReciprocalPotential(reciprocalPotential); |
948 |
+ |
} |
949 |
|
|
950 |
|
if (info_->requiresSelfCorrection()) { |
951 |
|
for (unsigned int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
963 |
|
curSnapshot->setLongRangePotential(longRangePotential); |
964 |
|
|
965 |
|
curSnapshot->setExcludedPotentials(*(fDecomp_->getExcludedSelfPotential()) + |
966 |
< |
*(fDecomp_->getExcludedPotential())); |
966 |
> |
*(fDecomp_->getExcludedPotential())); |
967 |
|
|
968 |
|
} |
969 |
|
|
918 |
– |
|
970 |
|
void ForceManager::postCalculation() { |
971 |
|
|
972 |
|
vector<Perturbation*>::iterator pi; |
992 |
|
} |
993 |
|
|
994 |
|
#ifdef IS_MPI |
995 |
< |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9, |
996 |
< |
MPI::REALTYPE, MPI::SUM); |
995 |
> |
MPI_Allreduce(MPI_IN_PLACE, stressTensor.getArrayPointer(), 9, |
996 |
> |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
997 |
|
#endif |
998 |
|
curSnapshot->setStressTensor(stressTensor); |
999 |
|
|
1000 |
+ |
if (info_->getSimParams()->getUseLongRangeCorrections()) { |
1001 |
+ |
/* |
1002 |
+ |
RealType vol = curSnapshot->getVolume(); |
1003 |
+ |
RealType Elrc(0.0); |
1004 |
+ |
RealType Wlrc(0.0); |
1005 |
+ |
|
1006 |
+ |
set<AtomType*>::iterator i; |
1007 |
+ |
set<AtomType*>::iterator j; |
1008 |
+ |
|
1009 |
+ |
RealType n_i, n_j; |
1010 |
+ |
RealType rho_i, rho_j; |
1011 |
+ |
pair<RealType, RealType> LRI; |
1012 |
+ |
|
1013 |
+ |
for (i = atomTypes_.begin(); i != atomTypes_.end(); ++i) { |
1014 |
+ |
n_i = RealType(info_->getGlobalCountOfType(*i)); |
1015 |
+ |
rho_i = n_i / vol; |
1016 |
+ |
for (j = atomTypes_.begin(); j != atomTypes_.end(); ++j) { |
1017 |
+ |
n_j = RealType(info_->getGlobalCountOfType(*j)); |
1018 |
+ |
rho_j = n_j / vol; |
1019 |
+ |
|
1020 |
+ |
LRI = interactionMan_->getLongRangeIntegrals( (*i), (*j) ); |
1021 |
+ |
|
1022 |
+ |
Elrc += n_i * rho_j * LRI.first; |
1023 |
+ |
Wlrc -= rho_i * rho_j * LRI.second; |
1024 |
+ |
} |
1025 |
+ |
} |
1026 |
+ |
Elrc *= 2.0 * NumericConstant::PI; |
1027 |
+ |
Wlrc *= 2.0 * NumericConstant::PI; |
1028 |
+ |
|
1029 |
+ |
RealType lrp = curSnapshot->getLongRangePotential(); |
1030 |
+ |
curSnapshot->setLongRangePotential(lrp + Elrc); |
1031 |
+ |
stressTensor += Wlrc * SquareMatrix3<RealType>::identity(); |
1032 |
+ |
curSnapshot->setStressTensor(stressTensor); |
1033 |
+ |
*/ |
1034 |
+ |
|
1035 |
+ |
} |
1036 |
|
} |
1037 |
< |
} //end namespace OpenMD |
1037 |
> |
} |