47 |
|
* @version 1.0 |
48 |
|
*/ |
49 |
|
|
50 |
+ |
|
51 |
|
#include "brains/ForceManager.hpp" |
52 |
|
#include "primitives/Molecule.hpp" |
52 |
– |
#include "UseTheForce/doForces_interface.h" |
53 |
|
#define __OPENMD_C |
54 |
– |
#include "UseTheForce/DarkSide/fInteractionMap.h" |
54 |
|
#include "utils/simError.h" |
55 |
|
#include "primitives/Bond.hpp" |
56 |
|
#include "primitives/Bend.hpp" |
57 |
|
#include "primitives/Torsion.hpp" |
58 |
|
#include "primitives/Inversion.hpp" |
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 |
|
|
69 |
< |
ForceManager::ForceManager(SimInfo * info) : info_(info), |
70 |
< |
NBforcesInitialized_(false) { |
69 |
> |
ForceManager::ForceManager(SimInfo * info) : info_(info) { |
70 |
> |
forceField_ = info_->getForceField(); |
71 |
> |
interactionMan_ = new InteractionManager(); |
72 |
> |
fDecomp_ = new ForceMatrixDecomposition(info_, interactionMan_); |
73 |
|
} |
74 |
< |
|
75 |
< |
void ForceManager::calcForces() { |
74 |
> |
|
75 |
> |
/** |
76 |
> |
* setupCutoffs |
77 |
> |
* |
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. |
83 |
> |
* If the cutoffRadius was not explicitly set: |
84 |
> |
* Are there electrostatic atoms? Use 12.0 Angstroms. |
85 |
> |
* No electrostatic atoms? Poll the atom types present in the |
86 |
> |
* simulation for suggested cutoff values (e.g. 2.5 * sigma). |
87 |
> |
* Use the maximum suggested value that was found. |
88 |
> |
* |
89 |
> |
* cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, |
90 |
> |
* or SHIFTED_POTENTIAL) |
91 |
> |
* If cutoffMethod was explicitly set, use that choice. |
92 |
> |
* If cutoffMethod was not explicitly set, use SHIFTED_FORCE |
93 |
> |
* |
94 |
> |
* cutoffPolicy : (one of MIX, MAX, TRADITIONAL) |
95 |
> |
* If cutoffPolicy was explicitly set, use that choice. |
96 |
> |
* If cutoffPolicy was not explicitly set, use TRADITIONAL |
97 |
> |
* |
98 |
> |
* switchingRadius : realType |
99 |
> |
* If the cutoffMethod was set to SWITCHED: |
100 |
> |
* If the switchingRadius was explicitly set, use that value |
101 |
> |
* (but do a sanity check first). |
102 |
> |
* If the switchingRadius was not explicitly set: use 0.85 * |
103 |
> |
* cutoffRadius_ |
104 |
> |
* If the cutoffMethod was not set to SWITCHED: |
105 |
> |
* Set switchingRadius equal to cutoffRadius for safety. |
106 |
> |
*/ |
107 |
> |
void ForceManager::setupCutoffs() { |
108 |
|
|
109 |
< |
if (!info_->isFortranInitialized()) { |
109 |
> |
Globals* simParams_ = info_->getSimParams(); |
110 |
> |
ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); |
111 |
> |
int mdFileVersion; |
112 |
> |
|
113 |
> |
if (simParams_->haveMDfileVersion()) |
114 |
> |
mdFileVersion = simParams_->getMDfileVersion(); |
115 |
> |
else |
116 |
> |
mdFileVersion = 0; |
117 |
> |
|
118 |
> |
|
119 |
> |
if (simParams_->haveCutoffRadius()) { |
120 |
> |
rCut_ = simParams_->getCutoffRadius(); |
121 |
> |
} else { |
122 |
> |
if (info_->usesElectrostaticAtoms()) { |
123 |
> |
sprintf(painCave.errMsg, |
124 |
> |
"ForceManager::setupCutoffs: No value was set for the cutoffRadius.\n" |
125 |
> |
"\tOpenMD will use a default value of 12.0 angstroms" |
126 |
> |
"\tfor the cutoffRadius.\n"); |
127 |
> |
painCave.isFatal = 0; |
128 |
> |
painCave.severity = OPENMD_INFO; |
129 |
> |
simError(); |
130 |
> |
rCut_ = 12.0; |
131 |
> |
} else { |
132 |
> |
RealType thisCut; |
133 |
> |
set<AtomType*>::iterator i; |
134 |
> |
set<AtomType*> atomTypes; |
135 |
> |
atomTypes = info_->getSimulatedAtomTypes(); |
136 |
> |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
137 |
> |
thisCut = interactionMan_->getSuggestedCutoffRadius((*i)); |
138 |
> |
rCut_ = max(thisCut, rCut_); |
139 |
> |
} |
140 |
> |
sprintf(painCave.errMsg, |
141 |
> |
"ForceManager::setupCutoffs: No value was set for the cutoffRadius.\n" |
142 |
> |
"\tOpenMD will use %lf angstroms.\n", |
143 |
> |
rCut_); |
144 |
> |
painCave.isFatal = 0; |
145 |
> |
painCave.severity = OPENMD_INFO; |
146 |
> |
simError(); |
147 |
> |
} |
148 |
> |
} |
149 |
> |
|
150 |
> |
fDecomp_->setUserCutoff(rCut_); |
151 |
> |
interactionMan_->setCutoffRadius(rCut_); |
152 |
> |
|
153 |
> |
map<string, CutoffMethod> stringToCutoffMethod; |
154 |
> |
stringToCutoffMethod["HARD"] = HARD; |
155 |
> |
stringToCutoffMethod["SWITCHED"] = SWITCHED; |
156 |
> |
stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL; |
157 |
> |
stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE; |
158 |
> |
|
159 |
> |
if (simParams_->haveCutoffMethod()) { |
160 |
> |
string cutMeth = toUpperCopy(simParams_->getCutoffMethod()); |
161 |
> |
map<string, CutoffMethod>::iterator i; |
162 |
> |
i = stringToCutoffMethod.find(cutMeth); |
163 |
> |
if (i == stringToCutoffMethod.end()) { |
164 |
> |
sprintf(painCave.errMsg, |
165 |
> |
"ForceManager::setupCutoffs: Could not find chosen cutoffMethod %s\n" |
166 |
> |
"\tShould be one of: " |
167 |
> |
"HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n", |
168 |
> |
cutMeth.c_str()); |
169 |
> |
painCave.isFatal = 1; |
170 |
> |
painCave.severity = OPENMD_ERROR; |
171 |
> |
simError(); |
172 |
> |
} 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; |
183 |
> |
} |
184 |
> |
|
185 |
> |
map<string, CutoffPolicy> stringToCutoffPolicy; |
186 |
> |
stringToCutoffPolicy["MIX"] = MIX; |
187 |
> |
stringToCutoffPolicy["MAX"] = MAX; |
188 |
> |
stringToCutoffPolicy["TRADITIONAL"] = TRADITIONAL; |
189 |
> |
|
190 |
> |
std::string cutPolicy; |
191 |
> |
if (forceFieldOptions_.haveCutoffPolicy()){ |
192 |
> |
cutPolicy = forceFieldOptions_.getCutoffPolicy(); |
193 |
> |
}else if (simParams_->haveCutoffPolicy()) { |
194 |
> |
cutPolicy = simParams_->getCutoffPolicy(); |
195 |
> |
} |
196 |
> |
|
197 |
> |
if (!cutPolicy.empty()){ |
198 |
> |
toUpper(cutPolicy); |
199 |
> |
map<string, CutoffPolicy>::iterator i; |
200 |
> |
i = stringToCutoffPolicy.find(cutPolicy); |
201 |
> |
|
202 |
> |
if (i == stringToCutoffPolicy.end()) { |
203 |
> |
sprintf(painCave.errMsg, |
204 |
> |
"ForceManager::setupCutoffs: Could not find chosen cutoffPolicy %s\n" |
205 |
> |
"\tShould be one of: " |
206 |
> |
"MIX, MAX, or TRADITIONAL\n", |
207 |
> |
cutPolicy.c_str()); |
208 |
> |
painCave.isFatal = 1; |
209 |
> |
painCave.severity = OPENMD_ERROR; |
210 |
> |
simError(); |
211 |
> |
} else { |
212 |
> |
cutoffPolicy_ = i->second; |
213 |
> |
} |
214 |
> |
} else { |
215 |
> |
sprintf(painCave.errMsg, |
216 |
> |
"ForceManager::setupCutoffs: No value was set for the cutoffPolicy.\n" |
217 |
> |
"\tOpenMD will use TRADITIONAL.\n"); |
218 |
> |
painCave.isFatal = 0; |
219 |
> |
painCave.severity = OPENMD_INFO; |
220 |
> |
simError(); |
221 |
> |
cutoffPolicy_ = TRADITIONAL; |
222 |
> |
} |
223 |
> |
|
224 |
> |
fDecomp_->setCutoffPolicy(cutoffPolicy_); |
225 |
> |
|
226 |
> |
// create the switching function object: |
227 |
> |
|
228 |
> |
switcher_ = new SwitchingFunction(); |
229 |
> |
|
230 |
> |
if (cutoffMethod_ == SWITCHED) { |
231 |
> |
if (simParams_->haveSwitchingRadius()) { |
232 |
> |
rSwitch_ = simParams_->getSwitchingRadius(); |
233 |
> |
if (rSwitch_ > rCut_) { |
234 |
> |
sprintf(painCave.errMsg, |
235 |
> |
"ForceManager::setupCutoffs: switchingRadius (%f) is larger " |
236 |
> |
"than the cutoffRadius(%f)\n", rSwitch_, rCut_); |
237 |
> |
painCave.isFatal = 1; |
238 |
> |
painCave.severity = OPENMD_ERROR; |
239 |
> |
simError(); |
240 |
> |
} |
241 |
> |
} else { |
242 |
> |
rSwitch_ = 0.85 * rCut_; |
243 |
> |
sprintf(painCave.errMsg, |
244 |
> |
"ForceManager::setupCutoffs: No value was set for the switchingRadius.\n" |
245 |
> |
"\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n" |
246 |
> |
"\tswitchingRadius = %f. for this simulation\n", rSwitch_); |
247 |
> |
painCave.isFatal = 0; |
248 |
> |
painCave.severity = OPENMD_WARNING; |
249 |
> |
simError(); |
250 |
> |
} |
251 |
> |
} else { |
252 |
> |
if (simParams_->haveSwitchingRadius()) { |
253 |
> |
map<string, CutoffMethod>::const_iterator it; |
254 |
> |
string theMeth; |
255 |
> |
for (it = stringToCutoffMethod.begin(); |
256 |
> |
it != stringToCutoffMethod.end(); ++it) { |
257 |
> |
if (it->second == cutoffMethod_) { |
258 |
> |
theMeth = it->first; |
259 |
> |
break; |
260 |
> |
} |
261 |
> |
} |
262 |
> |
sprintf(painCave.errMsg, |
263 |
> |
"ForceManager::setupCutoffs: the cutoffMethod (%s)\n" |
264 |
> |
"\tis not set to SWITCHED, so switchingRadius value\n" |
265 |
> |
"\twill be ignored for this simulation\n", theMeth.c_str()); |
266 |
> |
painCave.isFatal = 0; |
267 |
> |
painCave.severity = OPENMD_WARNING; |
268 |
> |
simError(); |
269 |
> |
} |
270 |
> |
|
271 |
> |
rSwitch_ = rCut_; |
272 |
> |
} |
273 |
> |
|
274 |
> |
// Default to cubic switching function. |
275 |
> |
sft_ = cubic; |
276 |
> |
if (simParams_->haveSwitchingFunctionType()) { |
277 |
> |
string funcType = simParams_->getSwitchingFunctionType(); |
278 |
> |
toUpper(funcType); |
279 |
> |
if (funcType == "CUBIC") { |
280 |
> |
sft_ = cubic; |
281 |
> |
} else { |
282 |
> |
if (funcType == "FIFTH_ORDER_POLYNOMIAL") { |
283 |
> |
sft_ = fifth_order_poly; |
284 |
> |
} else { |
285 |
> |
// throw error |
286 |
> |
sprintf( painCave.errMsg, |
287 |
> |
"ForceManager::setupSwitching : Unknown switchingFunctionType. (Input file specified %s .)\n" |
288 |
> |
"\tswitchingFunctionType must be one of: " |
289 |
> |
"\"cubic\" or \"fifth_order_polynomial\".", |
290 |
> |
funcType.c_str() ); |
291 |
> |
painCave.isFatal = 1; |
292 |
> |
painCave.severity = OPENMD_ERROR; |
293 |
> |
simError(); |
294 |
> |
} |
295 |
> |
} |
296 |
> |
} |
297 |
> |
switcher_->setSwitchType(sft_); |
298 |
> |
switcher_->setSwitch(rSwitch_, rCut_); |
299 |
> |
interactionMan_->setSwitchingRadius(rSwitch_); |
300 |
> |
} |
301 |
> |
|
302 |
> |
void ForceManager::initialize() { |
303 |
> |
|
304 |
> |
if (!info_->isTopologyDone()) { |
305 |
> |
|
306 |
|
info_->update(); |
307 |
+ |
interactionMan_->setSimInfo(info_); |
308 |
+ |
interactionMan_->initialize(); |
309 |
+ |
|
310 |
+ |
// We want to delay the cutoffs until after the interaction |
311 |
+ |
// manager has set up the atom-atom interactions so that we can |
312 |
+ |
// query them for suggested cutoff values |
313 |
+ |
setupCutoffs(); |
314 |
+ |
|
315 |
+ |
info_->prepareTopology(); |
316 |
|
} |
317 |
+ |
|
318 |
+ |
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
319 |
|
|
320 |
< |
preCalculation(); |
320 |
> |
// Force fields can set options on how to scale van der Waals and |
321 |
> |
// electrostatic interactions for atoms connected via bonds, bends |
322 |
> |
// and torsions in this case the topological distance between |
323 |
> |
// atoms is: |
324 |
> |
// 0 = topologically unconnected |
325 |
> |
// 1 = bonded together |
326 |
> |
// 2 = connected via a bend |
327 |
> |
// 3 = connected via a torsion |
328 |
|
|
329 |
< |
calcShortRangeInteraction(); |
329 |
> |
vdwScale_.reserve(4); |
330 |
> |
fill(vdwScale_.begin(), vdwScale_.end(), 0.0); |
331 |
|
|
332 |
< |
calcLongRangeInteraction(); |
332 |
> |
electrostaticScale_.reserve(4); |
333 |
> |
fill(electrostaticScale_.begin(), electrostaticScale_.end(), 0.0); |
334 |
|
|
335 |
< |
postCalculation(); |
335 |
> |
vdwScale_[0] = 1.0; |
336 |
> |
vdwScale_[1] = fopts.getvdw12scale(); |
337 |
> |
vdwScale_[2] = fopts.getvdw13scale(); |
338 |
> |
vdwScale_[3] = fopts.getvdw14scale(); |
339 |
|
|
340 |
+ |
electrostaticScale_[0] = 1.0; |
341 |
+ |
electrostaticScale_[1] = fopts.getelectrostatic12scale(); |
342 |
+ |
electrostaticScale_[2] = fopts.getelectrostatic13scale(); |
343 |
+ |
electrostaticScale_[3] = fopts.getelectrostatic14scale(); |
344 |
+ |
|
345 |
+ |
fDecomp_->distributeInitialData(); |
346 |
+ |
|
347 |
+ |
initialized_ = true; |
348 |
+ |
|
349 |
|
} |
350 |
+ |
|
351 |
+ |
void ForceManager::calcForces() { |
352 |
+ |
|
353 |
+ |
if (!initialized_) initialize(); |
354 |
+ |
|
355 |
+ |
preCalculation(); |
356 |
+ |
shortRangeInteractions(); |
357 |
+ |
longRangeInteractions(); |
358 |
+ |
postCalculation(); |
359 |
+ |
} |
360 |
|
|
361 |
|
void ForceManager::preCalculation() { |
362 |
|
SimInfo::MoleculeIterator mi; |
365 |
|
Atom* atom; |
366 |
|
Molecule::RigidBodyIterator rbIter; |
367 |
|
RigidBody* rb; |
368 |
+ |
Molecule::CutoffGroupIterator ci; |
369 |
+ |
CutoffGroup* cg; |
370 |
|
|
371 |
|
// forces are zeroed here, before any are accumulated. |
92 |
– |
// NOTE: do not rezero the forces in Fortran. |
372 |
|
|
373 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
374 |
|
mol = info_->nextMolecule(mi)) { |
375 |
< |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
375 |
> |
for(atom = mol->beginAtom(ai); atom != NULL; |
376 |
> |
atom = mol->nextAtom(ai)) { |
377 |
|
atom->zeroForcesAndTorques(); |
378 |
|
} |
379 |
< |
|
379 |
> |
|
380 |
|
//change the positions of atoms which belong to the rigidbodies |
381 |
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
382 |
|
rb = mol->nextRigidBody(rbIter)) { |
383 |
|
rb->zeroForcesAndTorques(); |
384 |
|
} |
385 |
< |
|
385 |
> |
|
386 |
> |
if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){ |
387 |
> |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
388 |
> |
cg = mol->nextCutoffGroup(ci)) { |
389 |
> |
//calculate the center of mass of cutoff group |
390 |
> |
cg->updateCOM(); |
391 |
> |
} |
392 |
> |
} |
393 |
|
} |
394 |
|
|
395 |
|
// Zero out the stress tensor |
397 |
|
|
398 |
|
} |
399 |
|
|
400 |
< |
void ForceManager::calcShortRangeInteraction() { |
400 |
> |
void ForceManager::shortRangeInteractions() { |
401 |
|
Molecule* mol; |
402 |
|
RigidBody* rb; |
403 |
|
Bond* bond; |
439 |
|
RealType currBendPot = bend->getPotential(); |
440 |
|
|
441 |
|
bendPotential += bend->getPotential(); |
442 |
< |
std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); |
442 |
> |
map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); |
443 |
|
if (i == bendDataSets.end()) { |
444 |
|
BendDataSet dataSet; |
445 |
|
dataSet.prev.angle = dataSet.curr.angle = angle; |
446 |
|
dataSet.prev.potential = dataSet.curr.potential = currBendPot; |
447 |
|
dataSet.deltaV = 0.0; |
448 |
< |
bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet)); |
448 |
> |
bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, |
449 |
> |
dataSet)); |
450 |
|
}else { |
451 |
|
i->second.prev.angle = i->second.curr.angle; |
452 |
|
i->second.prev.potential = i->second.curr.potential; |
463 |
|
torsion->calcForce(angle); |
464 |
|
RealType currTorsionPot = torsion->getPotential(); |
465 |
|
torsionPotential += torsion->getPotential(); |
466 |
< |
std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
466 |
> |
map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
467 |
|
if (i == torsionDataSets.end()) { |
468 |
|
TorsionDataSet dataSet; |
469 |
|
dataSet.prev.angle = dataSet.curr.angle = angle; |
470 |
|
dataSet.prev.potential = dataSet.curr.potential = currTorsionPot; |
471 |
|
dataSet.deltaV = 0.0; |
472 |
< |
torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); |
472 |
> |
torsionDataSets.insert(map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); |
473 |
|
}else { |
474 |
|
i->second.prev.angle = i->second.curr.angle; |
475 |
|
i->second.prev.potential = i->second.curr.potential; |
479 |
|
i->second.prev.potential); |
480 |
|
} |
481 |
|
} |
482 |
< |
|
482 |
> |
|
483 |
|
for (inversion = mol->beginInversion(inversionIter); |
484 |
|
inversion != NULL; |
485 |
|
inversion = mol->nextInversion(inversionIter)) { |
487 |
|
inversion->calcForce(angle); |
488 |
|
RealType currInversionPot = inversion->getPotential(); |
489 |
|
inversionPotential += inversion->getPotential(); |
490 |
< |
std::map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); |
490 |
> |
map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); |
491 |
|
if (i == inversionDataSets.end()) { |
492 |
|
InversionDataSet dataSet; |
493 |
|
dataSet.prev.angle = dataSet.curr.angle = angle; |
494 |
|
dataSet.prev.potential = dataSet.curr.potential = currInversionPot; |
495 |
|
dataSet.deltaV = 0.0; |
496 |
< |
inversionDataSets.insert(std::map<Inversion*, InversionDataSet>::value_type(inversion, dataSet)); |
496 |
> |
inversionDataSets.insert(map<Inversion*, InversionDataSet>::value_type(inversion, dataSet)); |
497 |
|
}else { |
498 |
|
i->second.prev.angle = i->second.curr.angle; |
499 |
|
i->second.prev.potential = i->second.curr.potential; |
512 |
|
curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential; |
513 |
|
curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential; |
514 |
|
curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential; |
515 |
< |
curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential; |
228 |
< |
|
515 |
> |
curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential; |
516 |
|
} |
517 |
|
|
518 |
< |
void ForceManager::calcLongRangeInteraction() { |
232 |
< |
Snapshot* curSnapshot; |
233 |
< |
DataStorage* config; |
234 |
< |
RealType* frc; |
235 |
< |
RealType* pos; |
236 |
< |
RealType* trq; |
237 |
< |
RealType* A; |
238 |
< |
RealType* electroFrame; |
239 |
< |
RealType* rc; |
240 |
< |
RealType* particlePot; |
241 |
< |
|
242 |
< |
//get current snapshot from SimInfo |
243 |
< |
curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
244 |
< |
|
245 |
< |
//get array pointers |
246 |
< |
config = &(curSnapshot->atomData); |
247 |
< |
frc = config->getArrayPointer(DataStorage::dslForce); |
248 |
< |
pos = config->getArrayPointer(DataStorage::dslPosition); |
249 |
< |
trq = config->getArrayPointer(DataStorage::dslTorque); |
250 |
< |
A = config->getArrayPointer(DataStorage::dslAmat); |
251 |
< |
electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); |
252 |
< |
particlePot = config->getArrayPointer(DataStorage::dslParticlePot); |
518 |
> |
void ForceManager::longRangeInteractions() { |
519 |
|
|
520 |
+ |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
521 |
+ |
DataStorage* config = &(curSnapshot->atomData); |
522 |
+ |
DataStorage* cgConfig = &(curSnapshot->cgData); |
523 |
+ |
|
524 |
|
//calculate the center of mass of cutoff group |
525 |
+ |
|
526 |
|
SimInfo::MoleculeIterator mi; |
527 |
|
Molecule* mol; |
528 |
|
Molecule::CutoffGroupIterator ci; |
529 |
|
CutoffGroup* cg; |
530 |
< |
Vector3d com; |
531 |
< |
std::vector<Vector3d> rcGroup; |
261 |
< |
|
262 |
< |
if(info_->getNCutoffGroups() > 0){ |
263 |
< |
|
530 |
> |
|
531 |
> |
if(info_->getNCutoffGroups() > 0){ |
532 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
533 |
|
mol = info_->nextMolecule(mi)) { |
534 |
|
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
535 |
|
cg = mol->nextCutoffGroup(ci)) { |
536 |
< |
cg->getCOM(com); |
269 |
< |
rcGroup.push_back(com); |
536 |
> |
cg->updateCOM(); |
537 |
|
} |
538 |
< |
}// end for (mol) |
272 |
< |
|
273 |
< |
rc = rcGroup[0].getArrayPointer(); |
538 |
> |
} |
539 |
|
} else { |
540 |
|
// center of mass of the group is the same as position of the atom |
541 |
|
// if cutoff group does not exist |
542 |
< |
rc = pos; |
542 |
> |
cgConfig->position = config->position; |
543 |
|
} |
544 |
+ |
|
545 |
+ |
fDecomp_->zeroWorkArrays(); |
546 |
+ |
fDecomp_->distributeData(); |
547 |
|
|
548 |
< |
//initialize data before passing to fortran |
549 |
< |
RealType longRangePotential[LR_POT_TYPES]; |
550 |
< |
RealType lrPot = 0.0; |
551 |
< |
int isError = 0; |
548 |
> |
int cg1, cg2, atom1, atom2, topoDist; |
549 |
> |
Vector3d d_grp, dag, d; |
550 |
> |
RealType rgrpsq, rgrp, r2, r; |
551 |
> |
RealType electroMult, vdwMult; |
552 |
> |
RealType vij; |
553 |
> |
Vector3d fij, fg, f1; |
554 |
> |
tuple3<RealType, RealType, RealType> cuts; |
555 |
> |
RealType rCutSq; |
556 |
> |
bool in_switching_region; |
557 |
> |
RealType sw, dswdr, swderiv; |
558 |
> |
vector<int> atomListColumn, atomListRow, atomListLocal; |
559 |
> |
InteractionData idat; |
560 |
> |
SelfData sdat; |
561 |
> |
RealType mf; |
562 |
> |
RealType lrPot; |
563 |
> |
RealType vpair; |
564 |
> |
potVec longRangePotential(0.0); |
565 |
> |
potVec workPot(0.0); |
566 |
|
|
567 |
< |
for (int i=0; i<LR_POT_TYPES;i++){ |
568 |
< |
longRangePotential[i]=0.0; //Initialize array |
569 |
< |
} |
567 |
> |
int loopStart, loopEnd; |
568 |
> |
|
569 |
> |
idat.vdwMult = &vdwMult; |
570 |
> |
idat.electroMult = &electroMult; |
571 |
> |
idat.pot = &workPot; |
572 |
> |
sdat.pot = fDecomp_->getEmbeddingPotential(); |
573 |
> |
idat.vpair = &vpair; |
574 |
> |
idat.f1 = &f1; |
575 |
> |
idat.sw = &sw; |
576 |
> |
idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false; |
577 |
> |
idat.shiftedForce = (cutoffMethod_ == SHIFTED_FORCE) ? true : false; |
578 |
|
|
579 |
< |
doForceLoop(pos, |
580 |
< |
rc, |
581 |
< |
A, |
582 |
< |
electroFrame, |
583 |
< |
frc, |
294 |
< |
trq, |
295 |
< |
tau.getArrayPointer(), |
296 |
< |
longRangePotential, |
297 |
< |
particlePot, |
298 |
< |
&isError ); |
299 |
< |
|
300 |
< |
if( isError ){ |
301 |
< |
sprintf( painCave.errMsg, |
302 |
< |
"Error returned from the fortran force calculation.\n" ); |
303 |
< |
painCave.isFatal = 1; |
304 |
< |
simError(); |
579 |
> |
loopEnd = PAIR_LOOP; |
580 |
> |
if (info_->requiresPrepair() ) { |
581 |
> |
loopStart = PREPAIR_LOOP; |
582 |
> |
} else { |
583 |
> |
loopStart = PAIR_LOOP; |
584 |
|
} |
585 |
< |
for (int i=0; i<LR_POT_TYPES;i++){ |
586 |
< |
lrPot += longRangePotential[i]; //Quick hack |
585 |
> |
|
586 |
> |
for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) { |
587 |
> |
|
588 |
> |
if (iLoop == loopStart) { |
589 |
> |
bool update_nlist = fDecomp_->checkNeighborList(); |
590 |
> |
if (update_nlist) |
591 |
> |
neighborList = fDecomp_->buildNeighborList(); |
592 |
> |
} |
593 |
> |
|
594 |
> |
for (vector<pair<int, int> >::iterator it = neighborList.begin(); |
595 |
> |
it != neighborList.end(); ++it) { |
596 |
> |
|
597 |
> |
cg1 = (*it).first; |
598 |
> |
cg2 = (*it).second; |
599 |
> |
|
600 |
> |
cuts = fDecomp_->getGroupCutoffs(cg1, cg2); |
601 |
> |
|
602 |
> |
d_grp = fDecomp_->getIntergroupVector(cg1, cg2); |
603 |
> |
|
604 |
> |
curSnapshot->wrapVector(d_grp); |
605 |
> |
rgrpsq = d_grp.lengthSquare(); |
606 |
> |
rCutSq = cuts.second; |
607 |
> |
|
608 |
> |
if (rgrpsq < rCutSq) { |
609 |
> |
idat.rcut = &cuts.first; |
610 |
> |
if (iLoop == PAIR_LOOP) { |
611 |
> |
vij = 0.0; |
612 |
> |
fij = V3Zero; |
613 |
> |
} |
614 |
> |
|
615 |
> |
in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr, |
616 |
> |
rgrp); |
617 |
> |
|
618 |
> |
atomListRow = fDecomp_->getAtomsInGroupRow(cg1); |
619 |
> |
atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2); |
620 |
> |
|
621 |
> |
|
622 |
> |
for (vector<int>::iterator ia = atomListRow.begin(); |
623 |
> |
ia != atomListRow.end(); ++ia) { |
624 |
> |
atom1 = (*ia); |
625 |
> |
|
626 |
> |
for (vector<int>::iterator jb = atomListColumn.begin(); |
627 |
> |
jb != atomListColumn.end(); ++jb) { |
628 |
> |
atom2 = (*jb); |
629 |
> |
|
630 |
> |
if (!fDecomp_->skipAtomPair(atom1, atom2)) { |
631 |
> |
vpair = 0.0; |
632 |
> |
workPot = 0.0; |
633 |
> |
f1 = V3Zero; |
634 |
> |
|
635 |
> |
fDecomp_->fillInteractionData(idat, atom1, atom2); |
636 |
> |
|
637 |
> |
topoDist = fDecomp_->getTopologicalDistance(atom1, atom2); |
638 |
> |
vdwMult = vdwScale_[topoDist]; |
639 |
> |
electroMult = electrostaticScale_[topoDist]; |
640 |
> |
|
641 |
> |
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
642 |
> |
idat.d = &d_grp; |
643 |
> |
idat.r2 = &rgrpsq; |
644 |
> |
} else { |
645 |
> |
d = fDecomp_->getInteratomicVector(atom1, atom2); |
646 |
> |
curSnapshot->wrapVector( d ); |
647 |
> |
r2 = d.lengthSquare(); |
648 |
> |
idat.d = &d; |
649 |
> |
idat.r2 = &r2; |
650 |
> |
} |
651 |
> |
|
652 |
> |
r = sqrt( *(idat.r2) ); |
653 |
> |
idat.rij = &r; |
654 |
> |
|
655 |
> |
if (iLoop == PREPAIR_LOOP) { |
656 |
> |
interactionMan_->doPrePair(idat); |
657 |
> |
} else { |
658 |
> |
interactionMan_->doPair(idat); |
659 |
> |
fDecomp_->unpackInteractionData(idat, atom1, atom2); |
660 |
> |
|
661 |
> |
vij += vpair; |
662 |
> |
fij += f1; |
663 |
> |
tau -= outProduct( *(idat.d), f1); |
664 |
> |
} |
665 |
> |
} |
666 |
> |
} |
667 |
> |
} |
668 |
> |
|
669 |
> |
if (iLoop == PAIR_LOOP) { |
670 |
> |
if (in_switching_region) { |
671 |
> |
swderiv = vij * dswdr / rgrp; |
672 |
> |
fg = swderiv * d_grp; |
673 |
> |
fij += fg; |
674 |
> |
|
675 |
> |
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
676 |
> |
tau -= outProduct( *(idat.d), fg); |
677 |
> |
} |
678 |
> |
|
679 |
> |
for (vector<int>::iterator ia = atomListRow.begin(); |
680 |
> |
ia != atomListRow.end(); ++ia) { |
681 |
> |
atom1 = (*ia); |
682 |
> |
mf = fDecomp_->getMassFactorRow(atom1); |
683 |
> |
// fg is the force on atom ia due to cutoff group's |
684 |
> |
// presence in switching region |
685 |
> |
fg = swderiv * d_grp * mf; |
686 |
> |
fDecomp_->addForceToAtomRow(atom1, fg); |
687 |
> |
|
688 |
> |
if (atomListRow.size() > 1) { |
689 |
> |
if (info_->usesAtomicVirial()) { |
690 |
> |
// find the distance between the atom |
691 |
> |
// and the center of the cutoff group: |
692 |
> |
dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1); |
693 |
> |
tau -= outProduct(dag, fg); |
694 |
> |
} |
695 |
> |
} |
696 |
> |
} |
697 |
> |
for (vector<int>::iterator jb = atomListColumn.begin(); |
698 |
> |
jb != atomListColumn.end(); ++jb) { |
699 |
> |
atom2 = (*jb); |
700 |
> |
mf = fDecomp_->getMassFactorColumn(atom2); |
701 |
> |
// fg is the force on atom jb due to cutoff group's |
702 |
> |
// presence in switching region |
703 |
> |
fg = -swderiv * d_grp * mf; |
704 |
> |
fDecomp_->addForceToAtomColumn(atom2, fg); |
705 |
> |
|
706 |
> |
if (atomListColumn.size() > 1) { |
707 |
> |
if (info_->usesAtomicVirial()) { |
708 |
> |
// find the distance between the atom |
709 |
> |
// and the center of the cutoff group: |
710 |
> |
dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2); |
711 |
> |
tau -= outProduct(dag, fg); |
712 |
> |
} |
713 |
> |
} |
714 |
> |
} |
715 |
> |
} |
716 |
> |
//if (!info_->usesAtomicVirial()) { |
717 |
> |
// tau -= outProduct(d_grp, fij); |
718 |
> |
//} |
719 |
> |
} |
720 |
> |
} |
721 |
> |
} |
722 |
> |
|
723 |
> |
if (iLoop == PREPAIR_LOOP) { |
724 |
> |
if (info_->requiresPrepair()) { |
725 |
> |
|
726 |
> |
fDecomp_->collectIntermediateData(); |
727 |
> |
|
728 |
> |
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
729 |
> |
fDecomp_->fillSelfData(sdat, atom1); |
730 |
> |
interactionMan_->doPreForce(sdat); |
731 |
> |
} |
732 |
> |
|
733 |
> |
fDecomp_->distributeIntermediateData(); |
734 |
> |
|
735 |
> |
} |
736 |
> |
} |
737 |
|
} |
738 |
+ |
|
739 |
+ |
fDecomp_->collectData(); |
740 |
|
|
741 |
+ |
if (info_->requiresSelfCorrection()) { |
742 |
+ |
|
743 |
+ |
for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) { |
744 |
+ |
fDecomp_->fillSelfData(sdat, atom1); |
745 |
+ |
interactionMan_->doSelfCorrection(sdat); |
746 |
+ |
} |
747 |
+ |
|
748 |
+ |
} |
749 |
+ |
|
750 |
+ |
longRangePotential = *(fDecomp_->getEmbeddingPotential()) + |
751 |
+ |
*(fDecomp_->getPairwisePotential()); |
752 |
+ |
|
753 |
+ |
lrPot = longRangePotential.sum(); |
754 |
+ |
|
755 |
|
//store the tau and long range potential |
756 |
|
curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot; |
757 |
< |
curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT]; |
758 |
< |
curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT]; |
757 |
> |
curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY]; |
758 |
> |
curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY]; |
759 |
|
} |
760 |
|
|
761 |
|
|