57 |
|
#include "primitives/Bend.hpp" |
58 |
|
#include "primitives/Torsion.hpp" |
59 |
|
#include "primitives/Inversion.hpp" |
60 |
+ |
#include "parallel/ForceDecomposition.hpp" |
61 |
+ |
//#include "parallel/SerialDecomposition.hpp" |
62 |
|
|
63 |
+ |
using namespace std; |
64 |
|
namespace OpenMD { |
65 |
|
|
66 |
< |
ForceManager::ForceManager(SimInfo * info) : info_(info), |
67 |
< |
NBforcesInitialized_(false) { |
66 |
> |
ForceManager::ForceManager(SimInfo * info) : info_(info) { |
67 |
> |
|
68 |
> |
#ifdef IS_MPI |
69 |
> |
decomp_ = new ForceDecomposition(info_); |
70 |
> |
#else |
71 |
> |
// decomp_ = new SerialDecomposition(info); |
72 |
> |
#endif |
73 |
|
} |
74 |
< |
|
74 |
> |
|
75 |
|
void ForceManager::calcForces() { |
76 |
|
|
77 |
|
if (!info_->isFortranInitialized()) { |
78 |
|
info_->update(); |
79 |
+ |
nbiMan_->setSimInfo(info_); |
80 |
+ |
nbiMan_->initialize(); |
81 |
+ |
swfun_ = nbiMan_->getSwitchingFunction(); |
82 |
+ |
decomp_->distributeInitialData(); |
83 |
+ |
info_->setupFortran(); |
84 |
|
} |
85 |
|
|
86 |
< |
preCalculation(); |
74 |
< |
|
86 |
> |
preCalculation(); |
87 |
|
calcShortRangeInteraction(); |
76 |
– |
|
88 |
|
calcLongRangeInteraction(); |
78 |
– |
|
89 |
|
postCalculation(); |
90 |
|
|
91 |
|
} |
97 |
|
Atom* atom; |
98 |
|
Molecule::RigidBodyIterator rbIter; |
99 |
|
RigidBody* rb; |
100 |
+ |
Molecule::CutoffGroupIterator ci; |
101 |
+ |
CutoffGroup* cg; |
102 |
|
|
103 |
|
// forces are zeroed here, before any are accumulated. |
92 |
– |
// NOTE: do not rezero the forces in Fortran. |
104 |
|
|
105 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
106 |
|
mol = info_->nextMolecule(mi)) { |
113 |
|
rb = mol->nextRigidBody(rbIter)) { |
114 |
|
rb->zeroForcesAndTorques(); |
115 |
|
} |
116 |
< |
|
116 |
> |
|
117 |
> |
if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){ |
118 |
> |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
119 |
> |
cg = mol->nextCutoffGroup(ci)) { |
120 |
> |
//calculate the center of mass of cutoff group |
121 |
> |
cg->updateCOM(); |
122 |
> |
} |
123 |
> |
} |
124 |
|
} |
125 |
< |
|
125 |
> |
|
126 |
|
// Zero out the stress tensor |
127 |
|
tau *= 0.0; |
128 |
|
|
170 |
|
RealType currBendPot = bend->getPotential(); |
171 |
|
|
172 |
|
bendPotential += bend->getPotential(); |
173 |
< |
std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); |
173 |
> |
map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); |
174 |
|
if (i == bendDataSets.end()) { |
175 |
|
BendDataSet dataSet; |
176 |
|
dataSet.prev.angle = dataSet.curr.angle = angle; |
177 |
|
dataSet.prev.potential = dataSet.curr.potential = currBendPot; |
178 |
|
dataSet.deltaV = 0.0; |
179 |
< |
bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet)); |
179 |
> |
bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, dataSet)); |
180 |
|
}else { |
181 |
|
i->second.prev.angle = i->second.curr.angle; |
182 |
|
i->second.prev.potential = i->second.curr.potential; |
193 |
|
torsion->calcForce(angle); |
194 |
|
RealType currTorsionPot = torsion->getPotential(); |
195 |
|
torsionPotential += torsion->getPotential(); |
196 |
< |
std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
196 |
> |
map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
197 |
|
if (i == torsionDataSets.end()) { |
198 |
|
TorsionDataSet dataSet; |
199 |
|
dataSet.prev.angle = dataSet.curr.angle = angle; |
200 |
|
dataSet.prev.potential = dataSet.curr.potential = currTorsionPot; |
201 |
|
dataSet.deltaV = 0.0; |
202 |
< |
torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); |
202 |
> |
torsionDataSets.insert(map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); |
203 |
|
}else { |
204 |
|
i->second.prev.angle = i->second.curr.angle; |
205 |
|
i->second.prev.potential = i->second.curr.potential; |
209 |
|
i->second.prev.potential); |
210 |
|
} |
211 |
|
} |
212 |
< |
|
212 |
> |
|
213 |
|
for (inversion = mol->beginInversion(inversionIter); |
214 |
|
inversion != NULL; |
215 |
|
inversion = mol->nextInversion(inversionIter)) { |
217 |
|
inversion->calcForce(angle); |
218 |
|
RealType currInversionPot = inversion->getPotential(); |
219 |
|
inversionPotential += inversion->getPotential(); |
220 |
< |
std::map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); |
220 |
> |
map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); |
221 |
|
if (i == inversionDataSets.end()) { |
222 |
|
InversionDataSet dataSet; |
223 |
|
dataSet.prev.angle = dataSet.curr.angle = angle; |
224 |
|
dataSet.prev.potential = dataSet.curr.potential = currInversionPot; |
225 |
|
dataSet.deltaV = 0.0; |
226 |
< |
inversionDataSets.insert(std::map<Inversion*, InversionDataSet>::value_type(inversion, dataSet)); |
226 |
> |
inversionDataSets.insert(map<Inversion*, InversionDataSet>::value_type(inversion, dataSet)); |
227 |
|
}else { |
228 |
|
i->second.prev.angle = i->second.curr.angle; |
229 |
|
i->second.prev.potential = i->second.curr.potential; |
242 |
|
curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential; |
243 |
|
curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential; |
244 |
|
curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential; |
245 |
< |
curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential; |
228 |
< |
|
245 |
> |
curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential; |
246 |
|
} |
247 |
|
|
248 |
|
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); |
249 |
|
|
250 |
< |
//calculate the center of mass of cutoff group |
251 |
< |
SimInfo::MoleculeIterator mi; |
252 |
< |
Molecule* mol; |
253 |
< |
Molecule::CutoffGroupIterator ci; |
254 |
< |
CutoffGroup* cg; |
255 |
< |
Vector3d com; |
256 |
< |
std::vector<Vector3d> rcGroup; |
257 |
< |
|
258 |
< |
if(info_->getNCutoffGroups() > 0){ |
259 |
< |
|
260 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; |
261 |
< |
mol = info_->nextMolecule(mi)) { |
262 |
< |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
263 |
< |
cg = mol->nextCutoffGroup(ci)) { |
268 |
< |
cg->getCOM(com); |
269 |
< |
rcGroup.push_back(com); |
270 |
< |
} |
271 |
< |
}// end for (mol) |
272 |
< |
|
273 |
< |
rc = rcGroup[0].getArrayPointer(); |
250 |
> |
// some of this initial stuff will go away: |
251 |
> |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
252 |
> |
DataStorage* config = &(curSnapshot->atomData); |
253 |
> |
DataStorage* cgConfig = &(curSnapshot->cgData); |
254 |
> |
RealType* frc = config->getArrayPointer(DataStorage::dslForce); |
255 |
> |
RealType* pos = config->getArrayPointer(DataStorage::dslPosition); |
256 |
> |
RealType* trq = config->getArrayPointer(DataStorage::dslTorque); |
257 |
> |
RealType* A = config->getArrayPointer(DataStorage::dslAmat); |
258 |
> |
RealType* electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); |
259 |
> |
RealType* particlePot = config->getArrayPointer(DataStorage::dslParticlePot); |
260 |
> |
RealType* rc; |
261 |
> |
|
262 |
> |
if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){ |
263 |
> |
rc = cgConfig->getArrayPointer(DataStorage::dslPosition); |
264 |
|
} else { |
265 |
|
// center of mass of the group is the same as position of the atom |
266 |
|
// if cutoff group does not exist |
275 |
|
for (int i=0; i<LR_POT_TYPES;i++){ |
276 |
|
longRangePotential[i]=0.0; //Initialize array |
277 |
|
} |
278 |
< |
|
279 |
< |
doForceLoop(pos, |
280 |
< |
rc, |
281 |
< |
A, |
282 |
< |
electroFrame, |
283 |
< |
frc, |
284 |
< |
trq, |
285 |
< |
tau.getArrayPointer(), |
286 |
< |
longRangePotential, |
287 |
< |
particlePot, |
288 |
< |
&isError ); |
289 |
< |
|
290 |
< |
if( isError ){ |
291 |
< |
sprintf( painCave.errMsg, |
292 |
< |
"Error returned from the fortran force calculation.\n" ); |
293 |
< |
painCave.isFatal = 1; |
294 |
< |
simError(); |
278 |
> |
|
279 |
> |
// new stuff starts here: |
280 |
> |
|
281 |
> |
decomp_->distributeData(); |
282 |
> |
|
283 |
> |
int cg1, cg2; |
284 |
> |
Vector3d d_grp; |
285 |
> |
RealType rgrpsq, rgrp; |
286 |
> |
RealType vij; |
287 |
> |
Vector3d fij, fg; |
288 |
> |
pair<int, int> gtypes; |
289 |
> |
RealType rCutSq; |
290 |
> |
bool in_switching_region; |
291 |
> |
RealType sw, dswdr, swderiv; |
292 |
> |
vector<int> atomListI; |
293 |
> |
vector<int> atomListJ; |
294 |
> |
InteractionData idat; |
295 |
> |
|
296 |
> |
int loopStart, loopEnd; |
297 |
> |
|
298 |
> |
loopEnd = PAIR_LOOP; |
299 |
> |
if (info_->requiresPrepair_) { |
300 |
> |
loopStart = PREPAIR_LOOP; |
301 |
> |
} else { |
302 |
> |
loopStart = PAIR_LOOP; |
303 |
> |
} |
304 |
> |
|
305 |
> |
for (int iLoop = loopStart; iLoop < loopEnd; iLoop++) { |
306 |
> |
|
307 |
> |
if (iLoop == loopStart) { |
308 |
> |
bool update_nlist = decomp_->checkNeighborList(); |
309 |
> |
if (update_nlist) |
310 |
> |
neighborList = decomp_->buildNeighborList(); |
311 |
> |
} |
312 |
> |
|
313 |
> |
for (vector<pair<int, int> >::iterator it = neighborList.begin(); |
314 |
> |
it != neighborList.end(); ++it) { |
315 |
> |
|
316 |
> |
cg1 = (*it).first; |
317 |
> |
cg2 = (*it).second; |
318 |
> |
|
319 |
> |
gtypes = decomp_->getGroupTypes(cg1, cg2); |
320 |
> |
d_grp = decomp_->getIntergroupVector(cg1, cg2); |
321 |
> |
curSnapshot->wrapVector(d_grp); |
322 |
> |
rgrpsq = d_grp.lengthSquare(); |
323 |
> |
rCutSq = groupCutoffMap(gtypes).first; |
324 |
> |
|
325 |
> |
if (rgrpsq < rCutSq) { |
326 |
> |
idat.rcut = groupCutoffMap(gtypes).second; |
327 |
> |
if (iLoop == PAIR_LOOP) { |
328 |
> |
vij = 0.0; |
329 |
> |
fij = V3Zero; |
330 |
> |
} |
331 |
> |
|
332 |
> |
in_switching_region = swfun_->getSwitch(rgrpsq, idat.sw, idat.dswdr, rgrp); |
333 |
> |
|
334 |
> |
atomListI = decomp_->getAtomsInGroupI(cg1); |
335 |
> |
atomListJ = decomp_->getAtomsInGroupJ(cg2); |
336 |
> |
|
337 |
> |
for (vector<int>::iterator ia = atomListI.begin(); |
338 |
> |
ia != atomListI.end(); ++ia) { |
339 |
> |
atom1 = (*ia); |
340 |
> |
|
341 |
> |
for (vector<int>::iterator jb = atomListJ.begin(); |
342 |
> |
jb != atomListJ.end(); ++jb) { |
343 |
> |
atom2 = (*jb); |
344 |
> |
|
345 |
> |
if (!decomp_->skipAtomPair(atom1, atom2)) { |
346 |
> |
|
347 |
> |
if (atomListI.size() == 1 && atomListJ.size() == 1) { |
348 |
> |
idat.d = d_grp; |
349 |
> |
idat.r2 = rgrpsq; |
350 |
> |
} else { |
351 |
> |
idat.d = decomp_->getInteratomicVector(atom1, atom2); |
352 |
> |
curSnapshot->wrapVector(idat.d); |
353 |
> |
idat.r2 = idat.d.lengthSquare(); |
354 |
> |
} |
355 |
> |
|
356 |
> |
idat.r = sqrt(idat.r2); |
357 |
> |
decomp_->fillInteractionData(atom1, atom2, idat); |
358 |
> |
|
359 |
> |
if (iLoop == PREPAIR_LOOP) { |
360 |
> |
interactionMan_->doPrePair(idat); |
361 |
> |
} else { |
362 |
> |
interactionMan_->doPair(idat); |
363 |
> |
vij += idat.vpair; |
364 |
> |
fij += idat.f1; |
365 |
> |
tau -= outProduct(idat.d, idat.f); |
366 |
> |
} |
367 |
> |
} |
368 |
> |
} |
369 |
> |
} |
370 |
> |
|
371 |
> |
if (iLoop == PAIR_LOOP) { |
372 |
> |
if (in_switching_region) { |
373 |
> |
swderiv = vij * dswdr / rgrp; |
374 |
> |
fg = swderiv * d_grp; |
375 |
> |
|
376 |
> |
fij += fg; |
377 |
> |
|
378 |
> |
if (atomListI.size() == 1 && atomListJ.size() == 1) { |
379 |
> |
tau -= outProduct(idat.d, fg); |
380 |
> |
} |
381 |
> |
|
382 |
> |
for (vector<int>::iterator ia = atomListI.begin(); |
383 |
> |
ia != atomListI.end(); ++ia) { |
384 |
> |
atom1 = (*ia); |
385 |
> |
mf = decomp_->getMfactI(atom1); |
386 |
> |
// fg is the force on atom ia due to cutoff group's |
387 |
> |
// presence in switching region |
388 |
> |
fg = swderiv * d_grp * mf; |
389 |
> |
decomp_->addForceToAtomI(atom1, fg); |
390 |
> |
|
391 |
> |
if (atomListI.size() > 1) { |
392 |
> |
if (info_->usesAtomicVirial_) { |
393 |
> |
// find the distance between the atom |
394 |
> |
// and the center of the cutoff group: |
395 |
> |
dag = decomp_->getAtomToGroupVectorI(atom1, cg1); |
396 |
> |
tau -= outProduct(dag, fg); |
397 |
> |
} |
398 |
> |
} |
399 |
> |
} |
400 |
> |
for (vector<int>::iterator jb = atomListJ.begin(); |
401 |
> |
jb != atomListJ.end(); ++jb) { |
402 |
> |
atom2 = (*jb); |
403 |
> |
mf = decomp_->getMfactJ(atom2); |
404 |
> |
// fg is the force on atom jb due to cutoff group's |
405 |
> |
// presence in switching region |
406 |
> |
fg = -swderiv * d_grp * mf; |
407 |
> |
decomp_->addForceToAtomJ(atom2, fg); |
408 |
> |
|
409 |
> |
if (atomListJ.size() > 1) { |
410 |
> |
if (info_->usesAtomicVirial_) { |
411 |
> |
// find the distance between the atom |
412 |
> |
// and the center of the cutoff group: |
413 |
> |
dag = decomp_->getAtomToGroupVectorJ(atom2, cg2); |
414 |
> |
tau -= outProduct(dag, fg); |
415 |
> |
} |
416 |
> |
} |
417 |
> |
} |
418 |
> |
} |
419 |
> |
//if (!SIM_uses_AtomicVirial) { |
420 |
> |
// tau -= outProduct(d_grp, fij); |
421 |
> |
//} |
422 |
> |
} |
423 |
> |
} |
424 |
> |
} |
425 |
> |
|
426 |
> |
if (iLoop == PREPAIR_LOOP) { |
427 |
> |
if (info_->requiresPrepair_) { |
428 |
> |
decomp_->collectIntermediateData(); |
429 |
> |
atomList = decomp_->getAtomList(); |
430 |
> |
for (vector<int>::iterator ia = atomList.begin(); |
431 |
> |
ia != atomList.end(); ++ia) { |
432 |
> |
atom1 = (*ia); |
433 |
> |
decomp_->populateSelfData(atom1, SelfData sdat); |
434 |
> |
interactionMan_->doPreForce(sdat); |
435 |
> |
} |
436 |
> |
decomp_->distributeIntermediateData(); |
437 |
> |
} |
438 |
> |
} |
439 |
> |
|
440 |
|
} |
441 |
+ |
|
442 |
+ |
decomp_->collectData(); |
443 |
+ |
|
444 |
+ |
if (info_->requiresSkipCorrection_ || info_->requiresSelfCorrection_) { |
445 |
+ |
atomList = decomp_->getAtomList(); |
446 |
+ |
for (vector<int>::iterator ia = atomList.begin(); |
447 |
+ |
ia != atomList.end(); ++ia) { |
448 |
+ |
atom1 = (*ia); |
449 |
+ |
|
450 |
+ |
if (info_->requiresSkipCorrection_) { |
451 |
+ |
vector<int> skipList = decomp_->getSkipsForAtom(atom1); |
452 |
+ |
for (vector<int>::iterator jb = skipList.begin(); |
453 |
+ |
jb != skipList.end(); ++jb) { |
454 |
+ |
atom2 = (*jb); |
455 |
+ |
decomp_->populateSkipData(atom1, atom2, InteractionData idat); |
456 |
+ |
interactionMan_->doSkipCorrection(idat); |
457 |
+ |
} |
458 |
+ |
} |
459 |
+ |
|
460 |
+ |
if (info_->requiresSelfCorrection_) { |
461 |
+ |
decomp_->populateSelfData(atom1, SelfData sdat); |
462 |
+ |
interactionMan_->doSelfCorrection(sdat); |
463 |
+ |
} |
464 |
+ |
|
465 |
+ |
|
466 |
+ |
} |
467 |
+ |
|
468 |
|
for (int i=0; i<LR_POT_TYPES;i++){ |
469 |
|
lrPot += longRangePotential[i]; //Quick hack |
470 |
|
} |