| 42 |
|
#include "math/SquareMatrix3.hpp" |
| 43 |
|
#include "nonbonded/NonBondedInteraction.hpp" |
| 44 |
|
#include "brains/SnapshotManager.hpp" |
| 45 |
+ |
#include "brains/PairList.hpp" |
| 46 |
|
|
| 47 |
|
using namespace std; |
| 48 |
|
namespace OpenMD { |
| 55 |
|
void ForceMatrixDecomposition::distributeInitialData() { |
| 56 |
|
snap_ = sman_->getCurrentSnapshot(); |
| 57 |
|
storageLayout_ = sman_->getStorageLayout(); |
| 58 |
+ |
ff_ = info_->getForceField(); |
| 59 |
|
nLocal_ = snap_->getNumberOfAtoms(); |
| 60 |
|
nGroups_ = snap_->getNumberOfCutoffGroups(); |
| 61 |
|
|
| 62 |
|
// gather the information for atomtype IDs (atids): |
| 63 |
< |
vector<int> identsLocal = info_->getIdentArray(); |
| 63 |
> |
identsLocal = info_->getIdentArray(); |
| 64 |
|
AtomLocalToGlobal = info_->getGlobalAtomIndices(); |
| 65 |
|
cgLocalToGlobal = info_->getGlobalGroupIndices(); |
| 66 |
|
vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); |
| 67 |
|
vector<RealType> massFactorsLocal = info_->getMassFactors(); |
| 68 |
+ |
PairList excludes = info_->getExcludedInteractions(); |
| 69 |
+ |
PairList oneTwo = info_->getOneTwoInteractions(); |
| 70 |
+ |
PairList oneThree = info_->getOneThreeInteractions(); |
| 71 |
+ |
PairList oneFour = info_->getOneFourInteractions(); |
| 72 |
|
vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0); |
| 73 |
|
|
| 74 |
|
#ifdef IS_MPI |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
| 148 |
+ |
skipsForRowAtom.clear(); |
| 149 |
+ |
skipsForRowAtom.reserve(nAtomsInRow_); |
| 150 |
+ |
for (int i = 0; i < nAtomsInRow_; i++) { |
| 151 |
+ |
int iglob = AtomRowToGlobal[i]; |
| 152 |
+ |
for (int j = 0; j < nAtomsInCol_; j++) { |
| 153 |
+ |
int jglob = AtomColToGlobal[j]; |
| 154 |
+ |
if (excludes.hasPair(iglob, jglob)) |
| 155 |
+ |
skipsForRowAtom[i].push_back(j); |
| 156 |
+ |
} |
| 157 |
+ |
} |
| 158 |
+ |
|
| 159 |
+ |
toposForRowAtom.clear(); |
| 160 |
+ |
toposForRowAtom.reserve(nAtomsInRow_); |
| 161 |
+ |
for (int i = 0; i < nAtomsInRow_; i++) { |
| 162 |
+ |
int iglob = AtomRowToGlobal[i]; |
| 163 |
+ |
int nTopos = 0; |
| 164 |
+ |
for (int j = 0; j < nAtomsInCol_; j++) { |
| 165 |
+ |
int jglob = AtomColToGlobal[j]; |
| 166 |
+ |
if (oneTwo.hasPair(iglob, jglob)) { |
| 167 |
+ |
toposForRowAtom[i].push_back(j); |
| 168 |
+ |
topoDistRow[i][nTopos] = 1; |
| 169 |
+ |
nTopos++; |
| 170 |
+ |
} |
| 171 |
+ |
if (oneThree.hasPair(iglob, jglob)) { |
| 172 |
+ |
toposForRowAtom[i].push_back(j); |
| 173 |
+ |
topoDistRow[i][nTopos] = 2; |
| 174 |
+ |
nTopos++; |
| 175 |
+ |
} |
| 176 |
+ |
if (oneFour.hasPair(iglob, jglob)) { |
| 177 |
+ |
toposForRowAtom[i].push_back(j); |
| 178 |
+ |
topoDistRow[i][nTopos] = 3; |
| 179 |
+ |
nTopos++; |
| 180 |
+ |
} |
| 181 |
+ |
} |
| 182 |
+ |
} |
| 183 |
+ |
|
| 184 |
|
#endif |
| 185 |
|
|
| 186 |
|
groupList_.clear(); |
| 194 |
|
} |
| 195 |
|
} |
| 196 |
|
|
| 197 |
< |
|
| 198 |
< |
// still need: |
| 157 |
< |
// topoDist |
| 158 |
< |
// exclude |
| 197 |
> |
skipsForLocalAtom.clear(); |
| 198 |
> |
skipsForLocalAtom.reserve(nLocal_); |
| 199 |
|
|
| 200 |
< |
} |
| 201 |
< |
|
| 200 |
> |
for (int i = 0; i < nLocal_; i++) { |
| 201 |
> |
int iglob = AtomLocalToGlobal[i]; |
| 202 |
> |
for (int j = 0; j < nLocal_; j++) { |
| 203 |
> |
int jglob = AtomLocalToGlobal[j]; |
| 204 |
> |
if (excludes.hasPair(iglob, jglob)) |
| 205 |
> |
skipsForLocalAtom[i].push_back(j); |
| 206 |
> |
} |
| 207 |
> |
} |
| 208 |
|
|
| 209 |
< |
|
| 209 |
> |
toposForLocalAtom.clear(); |
| 210 |
> |
toposForLocalAtom.reserve(nLocal_); |
| 211 |
> |
for (int i = 0; i < nLocal_; i++) { |
| 212 |
> |
int iglob = AtomLocalToGlobal[i]; |
| 213 |
> |
int nTopos = 0; |
| 214 |
> |
for (int j = 0; j < nLocal_; j++) { |
| 215 |
> |
int jglob = AtomLocalToGlobal[j]; |
| 216 |
> |
if (oneTwo.hasPair(iglob, jglob)) { |
| 217 |
> |
toposForLocalAtom[i].push_back(j); |
| 218 |
> |
topoDistLocal[i][nTopos] = 1; |
| 219 |
> |
nTopos++; |
| 220 |
> |
} |
| 221 |
> |
if (oneThree.hasPair(iglob, jglob)) { |
| 222 |
> |
toposForLocalAtom[i].push_back(j); |
| 223 |
> |
topoDistLocal[i][nTopos] = 2; |
| 224 |
> |
nTopos++; |
| 225 |
> |
} |
| 226 |
> |
if (oneFour.hasPair(iglob, jglob)) { |
| 227 |
> |
toposForLocalAtom[i].push_back(j); |
| 228 |
> |
topoDistLocal[i][nTopos] = 3; |
| 229 |
> |
nTopos++; |
| 230 |
> |
} |
| 231 |
> |
} |
| 232 |
> |
} |
| 233 |
> |
} |
| 234 |
> |
|
| 235 |
|
void ForceMatrixDecomposition::distributeData() { |
| 236 |
|
snap_ = sman_->getCurrentSnapshot(); |
| 237 |
|
storageLayout_ = sman_->getStorageLayout(); |
| 355 |
|
#endif |
| 356 |
|
} |
| 357 |
|
|
| 358 |
+ |
int ForceMatrixDecomposition::getNAtomsInRow() { |
| 359 |
+ |
#ifdef IS_MPI |
| 360 |
+ |
return nAtomsInRow_; |
| 361 |
+ |
#else |
| 362 |
+ |
return nLocal_; |
| 363 |
+ |
#endif |
| 364 |
+ |
} |
| 365 |
+ |
|
| 366 |
|
/** |
| 367 |
|
* returns the list of atoms belonging to this group. |
| 368 |
|
*/ |
| 453 |
|
return d; |
| 454 |
|
} |
| 455 |
|
|
| 456 |
+ |
vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) { |
| 457 |
+ |
#ifdef IS_MPI |
| 458 |
+ |
return skipsForRowAtom[atom1]; |
| 459 |
+ |
#else |
| 460 |
+ |
return skipsForLocalAtom[atom1]; |
| 461 |
+ |
#endif |
| 462 |
+ |
} |
| 463 |
+ |
|
| 464 |
+ |
/** |
| 465 |
+ |
* there are a number of reasons to skip a pair or a particle mostly |
| 466 |
+ |
* we do this to exclude atoms who are involved in short range |
| 467 |
+ |
* interactions (bonds, bends, torsions), but we also need to |
| 468 |
+ |
* exclude some overcounted interactions that result from the |
| 469 |
+ |
* parallel decomposition. |
| 470 |
+ |
*/ |
| 471 |
+ |
bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { |
| 472 |
+ |
int unique_id_1, unique_id_2; |
| 473 |
+ |
|
| 474 |
+ |
#ifdef IS_MPI |
| 475 |
+ |
// in MPI, we have to look up the unique IDs for each atom |
| 476 |
+ |
unique_id_1 = AtomRowToGlobal[atom1]; |
| 477 |
+ |
unique_id_2 = AtomColToGlobal[atom2]; |
| 478 |
+ |
|
| 479 |
+ |
// this situation should only arise in MPI simulations |
| 480 |
+ |
if (unique_id_1 == unique_id_2) return true; |
| 481 |
+ |
|
| 482 |
+ |
// this prevents us from doing the pair on multiple processors |
| 483 |
+ |
if (unique_id_1 < unique_id_2) { |
| 484 |
+ |
if ((unique_id_1 + unique_id_2) % 2 == 0) return true; |
| 485 |
+ |
} else { |
| 486 |
+ |
if ((unique_id_1 + unique_id_2) % 2 == 1) return true; |
| 487 |
+ |
} |
| 488 |
+ |
#else |
| 489 |
+ |
// in the normal loop, the atom numbers are unique |
| 490 |
+ |
unique_id_1 = atom1; |
| 491 |
+ |
unique_id_2 = atom2; |
| 492 |
+ |
#endif |
| 493 |
+ |
|
| 494 |
+ |
#ifdef IS_MPI |
| 495 |
+ |
for (vector<int>::iterator i = skipsForRowAtom[atom1].begin(); |
| 496 |
+ |
i != skipsForRowAtom[atom1].end(); ++i) { |
| 497 |
+ |
if ( (*i) == unique_id_2 ) return true; |
| 498 |
+ |
} |
| 499 |
+ |
#else |
| 500 |
+ |
for (vector<int>::iterator i = skipsForLocalAtom[atom1].begin(); |
| 501 |
+ |
i != skipsForLocalAtom[atom1].end(); ++i) { |
| 502 |
+ |
if ( (*i) == unique_id_2 ) return true; |
| 503 |
+ |
} |
| 504 |
+ |
#endif |
| 505 |
+ |
} |
| 506 |
+ |
|
| 507 |
+ |
int ForceMatrixDecomposition::getTopoDistance(int atom1, int atom2) { |
| 508 |
+ |
|
| 509 |
+ |
#ifdef IS_MPI |
| 510 |
+ |
for (int i = 0; i < toposForRowAtom[atom1].size(); i++) { |
| 511 |
+ |
if ( toposForRowAtom[atom1][i] == atom2 ) return topoDistRow[atom1][i]; |
| 512 |
+ |
} |
| 513 |
+ |
#else |
| 514 |
+ |
for (int i = 0; i < toposForLocalAtom[atom1].size(); i++) { |
| 515 |
+ |
if ( toposForLocalAtom[atom1][i] == atom2 ) return topoDistLocal[atom1][i]; |
| 516 |
+ |
} |
| 517 |
+ |
#endif |
| 518 |
+ |
|
| 519 |
+ |
// zero is default for unconnected (i.e. normal) pair interactions |
| 520 |
+ |
return 0; |
| 521 |
+ |
} |
| 522 |
+ |
|
| 523 |
|
void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ |
| 524 |
|
#ifdef IS_MPI |
| 525 |
|
atomRowData.force[atom1] += fg; |
| 541 |
|
InteractionData idat; |
| 542 |
|
|
| 543 |
|
#ifdef IS_MPI |
| 544 |
+ |
|
| 545 |
+ |
idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
| 546 |
+ |
ff_->getAtomType(identsCol[atom2]) ); |
| 547 |
+ |
|
| 548 |
|
if (storageLayout_ & DataStorage::dslAmat) { |
| 549 |
|
idat.A1 = &(atomRowData.aMat[atom1]); |
| 550 |
|
idat.A2 = &(atomColData.aMat[atom2]); |
| 569 |
|
idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]); |
| 570 |
|
idat.dfrho2 = &(atomColData.functionalDerivative[atom2]); |
| 571 |
|
} |
| 572 |
+ |
|
| 573 |
|
#else |
| 574 |
+ |
|
| 575 |
+ |
idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
| 576 |
+ |
ff_->getAtomType(identsLocal[atom2]) ); |
| 577 |
+ |
|
| 578 |
|
if (storageLayout_ & DataStorage::dslAmat) { |
| 579 |
|
idat.A1 = &(snap_->atomData.aMat[atom1]); |
| 580 |
|
idat.A2 = &(snap_->atomData.aMat[atom2]); |
| 607 |
|
|
| 608 |
|
InteractionData idat; |
| 609 |
|
#ifdef IS_MPI |
| 610 |
+ |
idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
| 611 |
+ |
ff_->getAtomType(identsCol[atom2]) ); |
| 612 |
+ |
|
| 613 |
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 614 |
|
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
| 615 |
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
| 623 |
|
idat.t2 = &(atomColData.force[atom2]); |
| 624 |
|
} |
| 625 |
|
#else |
| 626 |
+ |
idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
| 627 |
+ |
ff_->getAtomType(identsLocal[atom2]) ); |
| 628 |
+ |
|
| 629 |
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 630 |
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
| 631 |
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
| 638 |
|
idat.t1 = &(snap_->atomData.force[atom1]); |
| 639 |
|
idat.t2 = &(snap_->atomData.force[atom2]); |
| 640 |
|
} |
| 641 |
< |
#endif |
| 481 |
< |
|
| 641 |
> |
#endif |
| 642 |
|
} |
| 643 |
|
|
| 484 |
– |
|
| 485 |
– |
|
| 486 |
– |
|
| 644 |
|
/* |
| 645 |
|
* buildNeighborList |
| 646 |
|
* |