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). |
39 |
< |
* [4] Vardeman & Gezelter, in progress (2009). |
39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
|
/** |
109 |
|
|
110 |
|
Globals* simParams_ = info_->getSimParams(); |
111 |
|
ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); |
112 |
+ |
int mdFileVersion; |
113 |
|
|
114 |
+ |
if (simParams_->haveMDfileVersion()) |
115 |
+ |
mdFileVersion = simParams_->getMDfileVersion(); |
116 |
+ |
else |
117 |
+ |
mdFileVersion = 0; |
118 |
+ |
|
119 |
|
if (simParams_->haveCutoffRadius()) { |
120 |
|
rCut_ = simParams_->getCutoffRadius(); |
121 |
|
} else { |
173 |
|
cutoffMethod_ = i->second; |
174 |
|
} |
175 |
|
} else { |
176 |
< |
sprintf(painCave.errMsg, |
177 |
< |
"ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n" |
178 |
< |
"\tOpenMD will use SHIFTED_FORCE.\n"); |
179 |
< |
painCave.isFatal = 0; |
180 |
< |
painCave.severity = OPENMD_INFO; |
181 |
< |
simError(); |
182 |
< |
cutoffMethod_ = SHIFTED_FORCE; |
176 |
> |
if (mdFileVersion > 1) { |
177 |
> |
sprintf(painCave.errMsg, |
178 |
> |
"ForceManager::setupCutoffs: No value was set for the cutoffMethod.\n" |
179 |
> |
"\tOpenMD will use SHIFTED_FORCE.\n"); |
180 |
> |
painCave.isFatal = 0; |
181 |
> |
painCave.severity = OPENMD_INFO; |
182 |
> |
simError(); |
183 |
> |
cutoffMethod_ = SHIFTED_FORCE; |
184 |
> |
} else { |
185 |
> |
// handle the case where the old file version was in play |
186 |
> |
// (there should be no cutoffMethod, so we have to deduce it |
187 |
> |
// from other data). |
188 |
> |
|
189 |
> |
sprintf(painCave.errMsg, |
190 |
> |
"ForceManager::setupCutoffs : DEPRECATED FILE FORMAT!\n" |
191 |
> |
"\tOpenMD found a file which does not set a cutoffMethod.\n" |
192 |
> |
"\tOpenMD will attempt to deduce a cutoffMethod using the\n" |
193 |
> |
"\tbehavior of the older (version 1) code. To remove this\n" |
194 |
> |
"\twarning, add an explicit cutoffMethod and change the top\n" |
195 |
> |
"\tof the file so that it begins with <OpenMD version=2>\n"); |
196 |
> |
painCave.isFatal = 0; |
197 |
> |
painCave.severity = OPENMD_WARNING; |
198 |
> |
simError(); |
199 |
> |
|
200 |
> |
// The old file version tethered the shifting behavior to the |
201 |
> |
// electrostaticSummationMethod keyword. |
202 |
> |
|
203 |
> |
if (simParams_->haveElectrostaticSummationMethod()) { |
204 |
> |
string myMethod = simParams_->getElectrostaticSummationMethod(); |
205 |
> |
toUpper(myMethod); |
206 |
> |
|
207 |
> |
if (myMethod == "SHIFTED_POTENTIAL") { |
208 |
> |
cutoffMethod_ = SHIFTED_POTENTIAL; |
209 |
> |
} else if (myMethod == "SHIFTED_FORCE") { |
210 |
> |
cutoffMethod_ = SHIFTED_FORCE; |
211 |
> |
} |
212 |
> |
|
213 |
> |
if (simParams_->haveSwitchingRadius()) |
214 |
> |
rSwitch_ = simParams_->getSwitchingRadius(); |
215 |
> |
|
216 |
> |
if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") { |
217 |
> |
if (simParams_->haveSwitchingRadius()){ |
218 |
> |
sprintf(painCave.errMsg, |
219 |
> |
"ForceManager::setupCutoffs : DEPRECATED ERROR MESSAGE\n" |
220 |
> |
"\tA value was set for the switchingRadius\n" |
221 |
> |
"\teven though the electrostaticSummationMethod was\n" |
222 |
> |
"\tset to %s\n", myMethod.c_str()); |
223 |
> |
painCave.severity = OPENMD_WARNING; |
224 |
> |
painCave.isFatal = 1; |
225 |
> |
simError(); |
226 |
> |
} |
227 |
> |
} |
228 |
> |
if (abs(rCut_ - rSwitch_) < 0.0001) { |
229 |
> |
if (cutoffMethod_ == SHIFTED_FORCE) { |
230 |
> |
sprintf(painCave.errMsg, |
231 |
> |
"ForceManager::setupCutoffs : DEPRECATED BEHAVIOR\n" |
232 |
> |
"\tcutoffRadius and switchingRadius are set to the\n" |
233 |
> |
"\tsame value. OpenMD will use shifted force\n" |
234 |
> |
"\tpotentials instead of switching functions.\n"); |
235 |
> |
painCave.isFatal = 0; |
236 |
> |
painCave.severity = OPENMD_WARNING; |
237 |
> |
simError(); |
238 |
> |
} else { |
239 |
> |
cutoffMethod_ = SHIFTED_POTENTIAL; |
240 |
> |
sprintf(painCave.errMsg, |
241 |
> |
"ForceManager::setupCutoffs : DEPRECATED BEHAVIOR\n" |
242 |
> |
"\tcutoffRadius and switchingRadius are set to the\n" |
243 |
> |
"\tsame value. OpenMD will use shifted potentials\n" |
244 |
> |
"\tinstead of switching functions.\n"); |
245 |
> |
painCave.isFatal = 0; |
246 |
> |
painCave.severity = OPENMD_WARNING; |
247 |
> |
simError(); |
248 |
> |
} |
249 |
> |
} |
250 |
> |
} |
251 |
> |
} |
252 |
|
} |
253 |
|
|
254 |
|
map<string, CutoffPolicy> stringToCutoffPolicy; |
256 |
|
stringToCutoffPolicy["MAX"] = MAX; |
257 |
|
stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL; |
258 |
|
|
259 |
< |
std::string cutPolicy; |
259 |
> |
string cutPolicy; |
260 |
|
if (forceFieldOptions_.haveCutoffPolicy()){ |
261 |
|
cutPolicy = forceFieldOptions_.getCutoffPolicy(); |
262 |
|
}else if (simParams_->haveCutoffPolicy()) { |
318 |
|
simError(); |
319 |
|
} |
320 |
|
} else { |
321 |
< |
if (simParams_->haveSwitchingRadius()) { |
322 |
< |
map<string, CutoffMethod>::const_iterator it; |
323 |
< |
string theMeth; |
324 |
< |
for (it = stringToCutoffMethod.begin(); |
325 |
< |
it != stringToCutoffMethod.end(); ++it) { |
326 |
< |
if (it->second == cutoffMethod_) { |
327 |
< |
theMeth = it->first; |
328 |
< |
break; |
321 |
> |
if (mdFileVersion > 1) { |
322 |
> |
// throw an error if we define a switching radius and don't need one. |
323 |
> |
// older file versions should not do this. |
324 |
> |
if (simParams_->haveSwitchingRadius()) { |
325 |
> |
map<string, CutoffMethod>::const_iterator it; |
326 |
> |
string theMeth; |
327 |
> |
for (it = stringToCutoffMethod.begin(); |
328 |
> |
it != stringToCutoffMethod.end(); ++it) { |
329 |
> |
if (it->second == cutoffMethod_) { |
330 |
> |
theMeth = it->first; |
331 |
> |
break; |
332 |
> |
} |
333 |
|
} |
334 |
+ |
sprintf(painCave.errMsg, |
335 |
+ |
"ForceManager::setupCutoffs: the cutoffMethod (%s)\n" |
336 |
+ |
"\tis not set to SWITCHED, so switchingRadius value\n" |
337 |
+ |
"\twill be ignored for this simulation\n", theMeth.c_str()); |
338 |
+ |
painCave.isFatal = 0; |
339 |
+ |
painCave.severity = OPENMD_WARNING; |
340 |
+ |
simError(); |
341 |
|
} |
255 |
– |
sprintf(painCave.errMsg, |
256 |
– |
"ForceManager::setupCutoffs: the cutoffMethod (%s)\n" |
257 |
– |
"\tis not set to SWITCHED, so switchingRadius value\n" |
258 |
– |
"\twill be ignored for this simulation\n", theMeth.c_str()); |
259 |
– |
painCave.isFatal = 0; |
260 |
– |
painCave.severity = OPENMD_WARNING; |
261 |
– |
simError(); |
342 |
|
} |
263 |
– |
|
343 |
|
rSwitch_ = rCut_; |
344 |
|
} |
345 |
|
|
370 |
|
switcher_->setSwitch(rSwitch_, rCut_); |
371 |
|
interactionMan_->setSwitchingRadius(rSwitch_); |
372 |
|
} |
373 |
+ |
|
374 |
+ |
|
375 |
+ |
|
376 |
|
|
377 |
|
void ForceManager::initialize() { |
378 |
|
|
388 |
|
setupCutoffs(); |
389 |
|
|
390 |
|
info_->prepareTopology(); |
391 |
+ |
|
392 |
+ |
doParticlePot_ = info_->getSimParams()->getOutputParticlePotential(); |
393 |
+ |
doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux(); |
394 |
+ |
if (doHeatFlux_) doParticlePot_ = true; |
395 |
+ |
|
396 |
|
} |
397 |
|
|
398 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
473 |
|
} |
474 |
|
|
475 |
|
// Zero out the stress tensor |
476 |
< |
tau *= 0.0; |
477 |
< |
|
476 |
> |
stressTensor *= 0.0; |
477 |
> |
// Zero out the heatFlux |
478 |
> |
fDecomp_->setHeatFlux( V3Zero ); |
479 |
|
} |
480 |
|
|
481 |
|
void ForceManager::shortRangeInteractions() { |
508 |
|
|
509 |
|
for (bond = mol->beginBond(bondIter); bond != NULL; |
510 |
|
bond = mol->nextBond(bondIter)) { |
511 |
< |
bond->calcForce(); |
511 |
> |
bond->calcForce(doParticlePot_); |
512 |
|
bondPotential += bond->getPotential(); |
513 |
|
} |
514 |
|
|
516 |
|
bend = mol->nextBend(bendIter)) { |
517 |
|
|
518 |
|
RealType angle; |
519 |
< |
bend->calcForce(angle); |
519 |
> |
bend->calcForce(angle, doParticlePot_); |
520 |
|
RealType currBendPot = bend->getPotential(); |
521 |
|
|
522 |
|
bendPotential += bend->getPotential(); |
541 |
|
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
542 |
|
torsion = mol->nextTorsion(torsionIter)) { |
543 |
|
RealType angle; |
544 |
< |
torsion->calcForce(angle); |
544 |
> |
torsion->calcForce(angle, doParticlePot_); |
545 |
|
RealType currTorsionPot = torsion->getPotential(); |
546 |
|
torsionPotential += torsion->getPotential(); |
547 |
|
map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
565 |
|
inversion != NULL; |
566 |
|
inversion = mol->nextInversion(inversionIter)) { |
567 |
|
RealType angle; |
568 |
< |
inversion->calcForce(angle); |
568 |
> |
inversion->calcForce(angle, doParticlePot_); |
569 |
|
RealType currInversionPot = inversion->getPotential(); |
570 |
|
inversionPotential += inversion->getPotential(); |
571 |
|
map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); |
598 |
|
|
599 |
|
void ForceManager::longRangeInteractions() { |
600 |
|
|
601 |
+ |
|
602 |
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
603 |
|
DataStorage* config = &(curSnapshot->atomData); |
604 |
|
DataStorage* cgConfig = &(curSnapshot->cgData); |
622 |
|
// center of mass of the group is the same as position of the atom |
623 |
|
// if cutoff group does not exist |
624 |
|
cgConfig->position = config->position; |
625 |
+ |
cgConfig->velocity = config->velocity; |
626 |
|
} |
627 |
|
|
628 |
|
fDecomp_->zeroWorkArrays(); |
629 |
|
fDecomp_->distributeData(); |
630 |
|
|
631 |
|
int cg1, cg2, atom1, atom2, topoDist; |
632 |
< |
Vector3d d_grp, dag, d; |
632 |
> |
Vector3d d_grp, dag, d, gvel2, vel2; |
633 |
|
RealType rgrpsq, rgrp, r2, r; |
634 |
|
RealType electroMult, vdwMult; |
635 |
|
RealType vij; |
646 |
|
RealType vpair; |
647 |
|
potVec longRangePotential(0.0); |
648 |
|
potVec workPot(0.0); |
649 |
+ |
vector<int>::iterator ia, jb; |
650 |
|
|
651 |
|
int loopStart, loopEnd; |
652 |
|
|
659 |
|
idat.sw = &sw; |
660 |
|
idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; |
661 |
|
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; |
662 |
+ |
idat.doParticlePot = doParticlePot_; |
663 |
+ |
sdat.doParticlePot = doParticlePot_; |
664 |
|
|
665 |
|
loopEnd = PAIR_LOOP; |
666 |
|
if (info_->requiresPrepair() ) { |
686 |
|
cuts = fDecomp_->getGroupCutoffs(cg1, cg2); |
687 |
|
|
688 |
|
d_grp = fDecomp_->getIntergroupVector(cg1, cg2); |
689 |
+ |
|
690 |
|
curSnapshot->wrapVector(d_grp); |
691 |
|
rgrpsq = d_grp.lengthSquare(); |
598 |
– |
|
692 |
|
rCutSq = cuts.second; |
693 |
|
|
694 |
|
if (rgrpsq < rCutSq) { |
700 |
|
|
701 |
|
in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, |
702 |
|
rgrp); |
703 |
< |
|
703 |
> |
|
704 |
|
atomListRow = fDecomp_->getAtomsInGroupRow(cg1); |
705 |
|
atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2); |
706 |
|
|
707 |
< |
for (vector<int>::iterator ia = atomListRow.begin(); |
707 |
> |
if (doHeatFlux_) |
708 |
> |
gvel2 = fDecomp_->getGroupVelocityColumn(cg2); |
709 |
> |
|
710 |
> |
for (ia = atomListRow.begin(); |
711 |
|
ia != atomListRow.end(); ++ia) { |
712 |
|
atom1 = (*ia); |
713 |
|
|
714 |
< |
for (vector<int>::iterator jb = atomListColumn.begin(); |
714 |
> |
for (jb = atomListColumn.begin(); |
715 |
|
jb != atomListColumn.end(); ++jb) { |
716 |
|
atom2 = (*jb); |
717 |
|
|
729 |
|
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
730 |
|
idat.d = &d_grp; |
731 |
|
idat.r2 = &rgrpsq; |
732 |
+ |
if (doHeatFlux_) |
733 |
+ |
vel2 = gvel2; |
734 |
|
} else { |
735 |
|
d = fDecomp_->getInteratomicVector(atom1, atom2); |
736 |
|
curSnapshot->wrapVector( d ); |
737 |
|
r2 = d.lengthSquare(); |
738 |
|
idat.d = &d; |
739 |
|
idat.r2 = &r2; |
740 |
+ |
if (doHeatFlux_) |
741 |
+ |
vel2 = fDecomp_->getAtomVelocityColumn(atom2); |
742 |
|
} |
743 |
|
|
744 |
|
r = sqrt( *(idat.r2) ); |
749 |
|
} else { |
750 |
|
interactionMan_->doPair(idat); |
751 |
|
fDecomp_->unpackInteractionData(idat, atom1, atom2); |
652 |
– |
|
752 |
|
vij += vpair; |
753 |
|
fij += f1; |
754 |
< |
tau -= outProduct( *(idat.d), f1); |
754 |
> |
stressTensor -= outProduct( *(idat.d), f1); |
755 |
> |
if (doHeatFlux_) |
756 |
> |
fDecomp_->addToHeatFlux(*(idat.d) * dot(f1, vel2)); |
757 |
|
} |
758 |
|
} |
759 |
|
} |
766 |
|
fij += fg; |
767 |
|
|
768 |
|
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
769 |
< |
tau -= outProduct( *(idat.d), fg); |
769 |
> |
stressTensor -= outProduct( *(idat.d), fg); |
770 |
> |
if (doHeatFlux_) |
771 |
> |
fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2)); |
772 |
> |
|
773 |
|
} |
774 |
|
|
775 |
< |
for (vector<int>::iterator ia = atomListRow.begin(); |
775 |
> |
for (ia = atomListRow.begin(); |
776 |
|
ia != atomListRow.end(); ++ia) { |
777 |
|
atom1 = (*ia); |
778 |
|
mf = fDecomp_->getMassFactorRow(atom1); |
780 |
|
// presence in switching region |
781 |
|
fg = swderiv * d_grp * mf; |
782 |
|
fDecomp_->addForceToAtomRow(atom1, fg); |
679 |
– |
|
783 |
|
if (atomListRow.size() > 1) { |
784 |
|
if (info_->usesAtomicVirial()) { |
785 |
|
// find the distance between the atom |
786 |
|
// and the center of the cutoff group: |
787 |
|
dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1); |
788 |
< |
tau -= outProduct(dag, fg); |
788 |
> |
stressTensor -= outProduct(dag, fg); |
789 |
> |
if (doHeatFlux_) |
790 |
> |
fDecomp_->addToHeatFlux( dag * dot(fg, vel2)); |
791 |
|
} |
792 |
|
} |
793 |
|
} |
794 |
< |
for (vector<int>::iterator jb = atomListColumn.begin(); |
794 |
> |
for (jb = atomListColumn.begin(); |
795 |
|
jb != atomListColumn.end(); ++jb) { |
796 |
|
atom2 = (*jb); |
797 |
|
mf = fDecomp_->getMassFactorColumn(atom2); |
805 |
|
// find the distance between the atom |
806 |
|
// and the center of the cutoff group: |
807 |
|
dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2); |
808 |
< |
tau -= outProduct(dag, fg); |
808 |
> |
stressTensor -= outProduct(dag, fg); |
809 |
> |
if (doHeatFlux_) |
810 |
> |
fDecomp_->addToHeatFlux( dag * dot(fg, vel2)); |
811 |
|
} |
812 |
|
} |
813 |
|
} |
814 |
|
} |
815 |
< |
//if (!SIM_uses_AtomicVirial) { |
816 |
< |
// tau -= outProduct(d_grp, fij); |
815 |
> |
//if (!info_->usesAtomicVirial()) { |
816 |
> |
// stressTensor -= outProduct(d_grp, fij); |
817 |
> |
// if (doHeatFlux_) |
818 |
> |
// fDecomp_->addToHeatFlux( d_grp * dot(fij, vel2)); |
819 |
|
//} |
820 |
|
} |
821 |
|
} |
835 |
|
|
836 |
|
} |
837 |
|
} |
729 |
– |
|
838 |
|
} |
839 |
|
|
840 |
|
fDecomp_->collectData(); |
853 |
|
|
854 |
|
lrPot = longRangePotential.sum(); |
855 |
|
|
856 |
< |
//store the tau and long range potential |
856 |
> |
//store the stressTensor and long range potential |
857 |
|
curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot; |
858 |
|
curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY]; |
859 |
|
curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY]; |
874 |
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
875 |
|
rb = mol->nextRigidBody(rbIter)) { |
876 |
|
Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial(); |
877 |
< |
tau += rbTau; |
877 |
> |
stressTensor += rbTau; |
878 |
|
} |
879 |
|
} |
880 |
|
|
881 |
|
#ifdef IS_MPI |
882 |
< |
Mat3x3d tmpTau(tau); |
883 |
< |
MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(), |
884 |
< |
9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
882 |
> |
|
883 |
> |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9, |
884 |
> |
MPI::REALTYPE, MPI::SUM); |
885 |
|
#endif |
886 |
< |
curSnapshot->statData.setTau(tau); |
886 |
> |
curSnapshot->setStressTensor(stressTensor); |
887 |
> |
|
888 |
|
} |
889 |
|
|
890 |
|
} //end namespace OpenMD |