59 |
|
#include "nonbonded/NonBondedInteraction.hpp" |
60 |
|
#include "parallel/ForceMatrixDecomposition.hpp" |
61 |
|
|
62 |
+ |
#include <cstdio> |
63 |
+ |
#include <iostream> |
64 |
+ |
#include <iomanip> |
65 |
+ |
|
66 |
|
using namespace std; |
67 |
|
namespace OpenMD { |
68 |
|
|
75 |
|
/** |
76 |
|
* setupCutoffs |
77 |
|
* |
78 |
< |
* Sets the values of cutoffRadius, cutoffMethod, and cutoffPolicy |
78 |
> |
* Sets the values of cutoffRadius, switchingRadius, cutoffMethod, |
79 |
> |
* and cutoffPolicy |
80 |
|
* |
81 |
|
* cutoffRadius : realType |
82 |
|
* If the cutoffRadius was explicitly set, use that value. |
93 |
|
* cutoffPolicy : (one of MIX, MAX, TRADITIONAL) |
94 |
|
* If cutoffPolicy was explicitly set, use that choice. |
95 |
|
* If cutoffPolicy was not explicitly set, use TRADITIONAL |
96 |
+ |
* |
97 |
+ |
* switchingRadius : realType |
98 |
+ |
* If the cutoffMethod was set to SWITCHED: |
99 |
+ |
* If the switchingRadius was explicitly set, use that value |
100 |
+ |
* (but do a sanity check first). |
101 |
+ |
* If the switchingRadius was not explicitly set: use 0.85 * |
102 |
+ |
* cutoffRadius_ |
103 |
+ |
* If the cutoffMethod was not set to SWITCHED: |
104 |
+ |
* Set switchingRadius equal to cutoffRadius for safety. |
105 |
|
*/ |
106 |
|
void ForceManager::setupCutoffs() { |
107 |
|
|
137 |
|
painCave.severity = OPENMD_INFO; |
138 |
|
simError(); |
139 |
|
} |
126 |
– |
fDecomp_->setUserCutoff(rCut_); |
140 |
|
} |
141 |
|
|
142 |
+ |
fDecomp_->setUserCutoff(rCut_); |
143 |
+ |
interactionMan_->setCutoffRadius(rCut_); |
144 |
+ |
|
145 |
|
map<string, CutoffMethod> stringToCutoffMethod; |
146 |
|
stringToCutoffMethod["HARD"] = HARD; |
147 |
|
stringToCutoffMethod["SWITCHED"] = SWITCHED; |
212 |
|
simError(); |
213 |
|
cutoffPolicy_ = TRADITIONAL; |
214 |
|
} |
199 |
– |
fDecomp_->setCutoffPolicy(cutoffPolicy_); |
200 |
– |
} |
215 |
|
|
216 |
< |
/** |
217 |
< |
* setupSwitching |
204 |
< |
* |
205 |
< |
* Sets the values of switchingRadius and |
206 |
< |
* If the switchingRadius was explicitly set, use that value (but check it) |
207 |
< |
* If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_ |
208 |
< |
*/ |
209 |
< |
void ForceManager::setupSwitching() { |
210 |
< |
Globals* simParams_ = info_->getSimParams(); |
211 |
< |
|
216 |
> |
fDecomp_->setCutoffPolicy(cutoffPolicy_); |
217 |
> |
|
218 |
|
// create the switching function object: |
219 |
+ |
|
220 |
|
switcher_ = new SwitchingFunction(); |
221 |
< |
|
222 |
< |
if (simParams_->haveSwitchingRadius()) { |
223 |
< |
rSwitch_ = simParams_->getSwitchingRadius(); |
224 |
< |
if (rSwitch_ > rCut_) { |
221 |
> |
|
222 |
> |
if (cutoffMethod_ == SWITCHED) { |
223 |
> |
if (simParams_->haveSwitchingRadius()) { |
224 |
> |
rSwitch_ = simParams_->getSwitchingRadius(); |
225 |
> |
if (rSwitch_ > rCut_) { |
226 |
> |
sprintf(painCave.errMsg, |
227 |
> |
"ForceManager::setupCutoffs: switchingRadius (%f) is larger " |
228 |
> |
"than the cutoffRadius(%f)\n", rSwitch_, rCut_); |
229 |
> |
painCave.isFatal = 1; |
230 |
> |
painCave.severity = OPENMD_ERROR; |
231 |
> |
simError(); |
232 |
> |
} |
233 |
> |
} else { |
234 |
> |
rSwitch_ = 0.85 * rCut_; |
235 |
|
sprintf(painCave.errMsg, |
236 |
< |
"ForceManager::setupSwitching: switchingRadius (%f) is larger " |
237 |
< |
"than the cutoffRadius(%f)\n", rSwitch_, rCut_); |
238 |
< |
painCave.isFatal = 1; |
239 |
< |
painCave.severity = OPENMD_ERROR; |
236 |
> |
"ForceManager::setupCutoffs: No value was set for the switchingRadius.\n" |
237 |
> |
"\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n" |
238 |
> |
"\tswitchingRadius = %f. for this simulation\n", rSwitch_); |
239 |
> |
painCave.isFatal = 0; |
240 |
> |
painCave.severity = OPENMD_WARNING; |
241 |
|
simError(); |
242 |
|
} |
243 |
< |
} else { |
244 |
< |
rSwitch_ = 0.85 * rCut_; |
245 |
< |
sprintf(painCave.errMsg, |
246 |
< |
"ForceManager::setupSwitching: No value was set for the switchingRadius.\n" |
247 |
< |
"\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n" |
248 |
< |
"\tswitchingRadius = %f. for this simulation\n", rSwitch_); |
249 |
< |
painCave.isFatal = 0; |
250 |
< |
painCave.severity = OPENMD_WARNING; |
251 |
< |
simError(); |
252 |
< |
} |
243 |
> |
} else { |
244 |
> |
if (simParams_->haveSwitchingRadius()) { |
245 |
> |
map<string, CutoffMethod>::const_iterator it; |
246 |
> |
string theMeth; |
247 |
> |
for (it = stringToCutoffMethod.begin(); |
248 |
> |
it != stringToCutoffMethod.end(); ++it) { |
249 |
> |
if (it->second == cutoffMethod_) { |
250 |
> |
theMeth = it->first; |
251 |
> |
break; |
252 |
> |
} |
253 |
> |
} |
254 |
> |
sprintf(painCave.errMsg, |
255 |
> |
"ForceManager::setupCutoffs: the cutoffMethod (%s)\n" |
256 |
> |
"\tis not set to SWITCHED, so switchingRadius value\n" |
257 |
> |
"\twill be ignored for this simulation\n", theMeth.c_str()); |
258 |
> |
painCave.isFatal = 0; |
259 |
> |
painCave.severity = OPENMD_WARNING; |
260 |
> |
simError(); |
261 |
> |
} |
262 |
> |
|
263 |
> |
rSwitch_ = rCut_; |
264 |
> |
} |
265 |
|
|
266 |
|
// Default to cubic switching function. |
267 |
|
sft_ = cubic; |
288 |
|
} |
289 |
|
switcher_->setSwitchType(sft_); |
290 |
|
switcher_->setSwitch(rSwitch_, rCut_); |
291 |
+ |
interactionMan_->setSwitchingRadius(rSwitch_); |
292 |
|
} |
293 |
|
|
294 |
|
void ForceManager::initialize() { |
303 |
|
// query them for suggested cutoff values |
304 |
|
|
305 |
|
setupCutoffs(); |
275 |
– |
setupSwitching(); |
306 |
|
|
307 |
|
info_->prepareTopology(); |
308 |
|
} |
505 |
|
} |
506 |
|
|
507 |
|
void ForceManager::longRangeInteractions() { |
508 |
< |
// some of this initial stuff will go away: |
508 |
> |
|
509 |
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
510 |
|
DataStorage* config = &(curSnapshot->atomData); |
511 |
|
DataStorage* cgConfig = &(curSnapshot->cgData); |
482 |
– |
RealType* frc = config->getArrayPointer(DataStorage::dslForce); |
483 |
– |
RealType* pos = config->getArrayPointer(DataStorage::dslPosition); |
484 |
– |
RealType* trq = config->getArrayPointer(DataStorage::dslTorque); |
485 |
– |
RealType* A = config->getArrayPointer(DataStorage::dslAmat); |
486 |
– |
RealType* electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); |
487 |
– |
RealType* particlePot = config->getArrayPointer(DataStorage::dslParticlePot); |
512 |
|
|
513 |
< |
// new stuff starts here: |
514 |
< |
|
513 |
> |
//calculate the center of mass of cutoff group |
514 |
> |
|
515 |
> |
SimInfo::MoleculeIterator mi; |
516 |
> |
Molecule* mol; |
517 |
> |
Molecule::CutoffGroupIterator ci; |
518 |
> |
CutoffGroup* cg; |
519 |
> |
|
520 |
> |
if(info_->getNCutoffGroups() > 0){ |
521 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
522 |
> |
mol = info_->nextMolecule(mi)) { |
523 |
> |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
524 |
> |
cg = mol->nextCutoffGroup(ci)) { |
525 |
> |
cg->updateCOM(); |
526 |
> |
} |
527 |
> |
} |
528 |
> |
} else { |
529 |
> |
// center of mass of the group is the same as position of the atom |
530 |
> |
// if cutoff group does not exist |
531 |
> |
cgConfig->position = config->position; |
532 |
> |
} |
533 |
> |
|
534 |
|
fDecomp_->zeroWorkArrays(); |
535 |
|
fDecomp_->distributeData(); |
536 |
|
|
539 |
|
RealType rgrpsq, rgrp, r2, r; |
540 |
|
RealType electroMult, vdwMult; |
541 |
|
RealType vij; |
542 |
< |
Vector3d fij, fg; |
542 |
> |
Vector3d fij, fg, f1; |
543 |
|
tuple3<RealType, RealType, RealType> cuts; |
544 |
|
RealType rCutSq; |
545 |
|
bool in_switching_region; |
548 |
|
InteractionData idat; |
549 |
|
SelfData sdat; |
550 |
|
RealType mf; |
508 |
– |
potVec pot(0.0); |
509 |
– |
potVec longRangePotential(0.0); |
551 |
|
RealType lrPot; |
552 |
|
RealType vpair; |
553 |
+ |
potVec longRangePotential(0.0); |
554 |
+ |
potVec workPot(0.0); |
555 |
|
|
556 |
|
int loopStart, loopEnd; |
557 |
|
|
558 |
+ |
idat.vdwMult = &vdwMult; |
559 |
+ |
idat.electroMult = &electroMult; |
560 |
+ |
idat.pot = &workPot; |
561 |
+ |
sdat.pot = fDecomp_->getEmbeddingPotential(); |
562 |
+ |
idat.vpair = &vpair; |
563 |
+ |
idat.f1 = &f1; |
564 |
+ |
idat.sw = &sw; |
565 |
+ |
idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; |
566 |
+ |
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; |
567 |
+ |
|
568 |
|
loopEnd = PAIR_LOOP; |
569 |
|
if (info_->requiresPrepair() ) { |
570 |
|
loopStart = PREPAIR_LOOP; |
571 |
|
} else { |
572 |
|
loopStart = PAIR_LOOP; |
573 |
|
} |
574 |
< |
|
522 |
< |
|
574 |
> |
|
575 |
|
for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) { |
576 |
|
|
577 |
|
if (iLoop == loopStart) { |
597 |
|
if (rgrpsq < rCutSq) { |
598 |
|
idat.rcut = &cuts.first; |
599 |
|
if (iLoop == PAIR_LOOP) { |
600 |
< |
vij *= 0.0; |
600 |
> |
vij = 0.0; |
601 |
|
fij = V3Zero; |
602 |
|
} |
603 |
|
|
604 |
|
in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, |
605 |
|
rgrp); |
554 |
– |
|
555 |
– |
idat.sw = &sw; |
606 |
|
|
607 |
|
atomListRow = fDecomp_->getAtomsInGroupRow(cg1); |
608 |
|
atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2); |
614 |
|
for (vector<int>::iterator jb = atomListColumn.begin(); |
615 |
|
jb != atomListColumn.end(); ++jb) { |
616 |
|
atom2 = (*jb); |
617 |
< |
|
568 |
< |
cerr << "doing atoms " << atom1 << " " << atom2 << "\n"; |
617 |
> |
|
618 |
|
if (!fDecomp_->skipAtomPair(atom1, atom2)) { |
570 |
– |
|
619 |
|
vpair = 0.0; |
620 |
+ |
workPot = 0.0; |
621 |
+ |
f1 = V3Zero; |
622 |
|
|
623 |
< |
cerr << "filling idat atoms " << atom1 << " " << atom2 << "\n"; |
574 |
< |
idat = fDecomp_->fillInteractionData(atom1, atom2); |
575 |
< |
cerr << "done with idat\n"; |
623 |
> |
fDecomp_->fillInteractionData(idat, atom1, atom2); |
624 |
|
|
625 |
|
topoDist = fDecomp_->getTopologicalDistance(atom1, atom2); |
626 |
|
vdwMult = vdwScale_[topoDist]; |
627 |
|
electroMult = electrostaticScale_[topoDist]; |
628 |
|
|
581 |
– |
idat.vdwMult = &vdwMult; |
582 |
– |
idat.electroMult = &electroMult; |
583 |
– |
idat.pot = &pot; |
584 |
– |
idat.vpair = &vpair; |
585 |
– |
|
629 |
|
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
630 |
|
idat.d = &d_grp; |
631 |
|
idat.r2 = &rgrpsq; |
637 |
|
idat.r2 = &r2; |
638 |
|
} |
639 |
|
|
640 |
< |
cerr << "d = " << d << "\n"; |
598 |
< |
cerr << "r2 = " << r2 << "\n"; |
599 |
< |
r = sqrt( r2 ); |
640 |
> |
r = sqrt( *(idat.r2) ); |
641 |
|
idat.rij = &r; |
642 |
|
|
643 |
|
if (iLoop == PREPAIR_LOOP) { |
644 |
|
interactionMan_->doPrePair(idat); |
645 |
|
} else { |
605 |
– |
cerr << "doing doPair " << atom1 << " " << atom2 << " " << r << "\n"; |
646 |
|
interactionMan_->doPair(idat); |
647 |
|
fDecomp_->unpackInteractionData(idat, atom1, atom2); |
648 |
< |
vij += *(idat.vpair); |
649 |
< |
fij += *(idat.f1); |
650 |
< |
tau -= outProduct( *(idat.d), *(idat.f1)); |
648 |
> |
vij += vpair; |
649 |
> |
fij += f1; |
650 |
> |
tau -= outProduct( *(idat.d), f1); |
651 |
|
} |
652 |
|
} |
653 |
|
} |
657 |
|
if (in_switching_region) { |
658 |
|
swderiv = vij * dswdr / rgrp; |
659 |
|
fg = swderiv * d_grp; |
620 |
– |
|
660 |
|
fij += fg; |
661 |
|
|
662 |
|
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
712 |
|
fDecomp_->collectIntermediateData(); |
713 |
|
|
714 |
|
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
715 |
< |
sdat = fDecomp_->fillSelfData(atom1); |
715 |
> |
fDecomp_->fillSelfData(sdat, atom1); |
716 |
|
interactionMan_->doPreForce(sdat); |
717 |
|
} |
718 |
< |
|
718 |
> |
|
719 |
> |
|
720 |
|
fDecomp_->distributeIntermediateData(); |
721 |
|
} |
722 |
|
} |
724 |
|
} |
725 |
|
|
726 |
|
fDecomp_->collectData(); |
687 |
– |
|
688 |
– |
if ( info_->requiresSkipCorrection() ) { |
689 |
– |
|
690 |
– |
for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) { |
691 |
– |
|
692 |
– |
vector<int> skipList = fDecomp_->getSkipsForAtom( atom1 ); |
727 |
|
|
694 |
– |
for (vector<int>::iterator jb = skipList.begin(); |
695 |
– |
jb != skipList.end(); ++jb) { |
696 |
– |
|
697 |
– |
atom2 = (*jb); |
698 |
– |
idat = fDecomp_->fillSkipData(atom1, atom2); |
699 |
– |
interactionMan_->doSkipCorrection(idat); |
700 |
– |
|
701 |
– |
} |
702 |
– |
} |
703 |
– |
} |
704 |
– |
|
728 |
|
if (info_->requiresSelfCorrection()) { |
729 |
|
|
730 |
|
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
731 |
< |
sdat = fDecomp_->fillSelfData(atom1); |
731 |
> |
fDecomp_->fillSelfData(sdat, atom1); |
732 |
|
interactionMan_->doSelfCorrection(sdat); |
733 |
|
} |
734 |
|
|
735 |
|
} |
736 |
|
|
737 |
< |
longRangePotential = fDecomp_->getLongRangePotential(); |
737 |
> |
longRangePotential = *(fDecomp_->getEmbeddingPotential()) + |
738 |
> |
*(fDecomp_->getPairwisePotential()); |
739 |
> |
|
740 |
|
lrPot = longRangePotential.sum(); |
741 |
|
|
742 |
|
//store the tau and long range potential |