| 1 |
gezelter |
1539 |
/* |
| 2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
chuckv |
1538 |
* |
| 4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
| 6 |
|
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
|
* that the following conditions are met: |
| 8 |
|
|
* |
| 9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
| 10 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
* |
| 12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
|
* documentation and/or other materials provided with the |
| 15 |
|
|
* distribution. |
| 16 |
|
|
* |
| 17 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 18 |
|
|
* kind. All express or implied conditions, representations and |
| 19 |
|
|
* warranties, including any implied warranty of merchantability, |
| 20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 22 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 23 |
|
|
* using, modifying or distributing the software or its |
| 24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 27 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 28 |
|
|
* arising out of the use of or inability to use software, even if the |
| 29 |
|
|
* University of Notre Dame has been advised of the possibility of |
| 30 |
|
|
* such damages. |
| 31 |
|
|
* |
| 32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
| 33 |
|
|
* research, please cite the appropriate papers when you publish your |
| 34 |
|
|
* work. Good starting points are: |
| 35 |
|
|
* |
| 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). |
| 40 |
|
|
*/ |
| 41 |
gezelter |
1549 |
#include "parallel/ForceMatrixDecomposition.hpp" |
| 42 |
gezelter |
1539 |
#include "math/SquareMatrix3.hpp" |
| 43 |
gezelter |
1544 |
#include "nonbonded/NonBondedInteraction.hpp" |
| 44 |
|
|
#include "brains/SnapshotManager.hpp" |
| 45 |
gezelter |
1570 |
#include "brains/PairList.hpp" |
| 46 |
chuckv |
1538 |
|
| 47 |
gezelter |
1541 |
using namespace std; |
| 48 |
gezelter |
1539 |
namespace OpenMD { |
| 49 |
chuckv |
1538 |
|
| 50 |
gezelter |
1544 |
/** |
| 51 |
|
|
* distributeInitialData is essentially a copy of the older fortran |
| 52 |
|
|
* SimulationSetup |
| 53 |
|
|
*/ |
| 54 |
|
|
|
| 55 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeInitialData() { |
| 56 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
| 57 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
| 58 |
gezelter |
1571 |
ff_ = info_->getForceField(); |
| 59 |
gezelter |
1567 |
nLocal_ = snap_->getNumberOfAtoms(); |
| 60 |
|
|
nGroups_ = snap_->getNumberOfCutoffGroups(); |
| 61 |
chuckv |
1538 |
|
| 62 |
gezelter |
1569 |
// gather the information for atomtype IDs (atids): |
| 63 |
gezelter |
1571 |
identsLocal = info_->getIdentArray(); |
| 64 |
gezelter |
1569 |
AtomLocalToGlobal = info_->getGlobalAtomIndices(); |
| 65 |
|
|
cgLocalToGlobal = info_->getGlobalGroupIndices(); |
| 66 |
|
|
vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); |
| 67 |
|
|
vector<RealType> massFactorsLocal = info_->getMassFactors(); |
| 68 |
gezelter |
1570 |
PairList excludes = info_->getExcludedInteractions(); |
| 69 |
|
|
PairList oneTwo = info_->getOneTwoInteractions(); |
| 70 |
|
|
PairList oneThree = info_->getOneThreeInteractions(); |
| 71 |
|
|
PairList oneFour = info_->getOneFourInteractions(); |
| 72 |
gezelter |
1569 |
vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0); |
| 73 |
|
|
|
| 74 |
gezelter |
1567 |
#ifdef IS_MPI |
| 75 |
|
|
|
| 76 |
|
|
AtomCommIntRow = new Communicator<Row,int>(nLocal_); |
| 77 |
|
|
AtomCommRealRow = new Communicator<Row,RealType>(nLocal_); |
| 78 |
|
|
AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_); |
| 79 |
|
|
AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_); |
| 80 |
chuckv |
1538 |
|
| 81 |
gezelter |
1567 |
AtomCommIntColumn = new Communicator<Column,int>(nLocal_); |
| 82 |
|
|
AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_); |
| 83 |
|
|
AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_); |
| 84 |
|
|
AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_); |
| 85 |
gezelter |
1541 |
|
| 86 |
gezelter |
1567 |
cgCommIntRow = new Communicator<Row,int>(nGroups_); |
| 87 |
|
|
cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_); |
| 88 |
|
|
cgCommIntColumn = new Communicator<Column,int>(nGroups_); |
| 89 |
|
|
cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_); |
| 90 |
gezelter |
1551 |
|
| 91 |
gezelter |
1567 |
nAtomsInRow_ = AtomCommIntRow->getSize(); |
| 92 |
|
|
nAtomsInCol_ = AtomCommIntColumn->getSize(); |
| 93 |
|
|
nGroupsInRow_ = cgCommIntRow->getSize(); |
| 94 |
|
|
nGroupsInCol_ = cgCommIntColumn->getSize(); |
| 95 |
|
|
|
| 96 |
gezelter |
1551 |
// Modify the data storage objects with the correct layouts and sizes: |
| 97 |
gezelter |
1567 |
atomRowData.resize(nAtomsInRow_); |
| 98 |
gezelter |
1551 |
atomRowData.setStorageLayout(storageLayout_); |
| 99 |
gezelter |
1567 |
atomColData.resize(nAtomsInCol_); |
| 100 |
gezelter |
1551 |
atomColData.setStorageLayout(storageLayout_); |
| 101 |
gezelter |
1567 |
cgRowData.resize(nGroupsInRow_); |
| 102 |
gezelter |
1551 |
cgRowData.setStorageLayout(DataStorage::dslPosition); |
| 103 |
gezelter |
1567 |
cgColData.resize(nGroupsInCol_); |
| 104 |
gezelter |
1551 |
cgColData.setStorageLayout(DataStorage::dslPosition); |
| 105 |
gezelter |
1549 |
|
| 106 |
gezelter |
1544 |
vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES, |
| 107 |
gezelter |
1567 |
vector<RealType> (nAtomsInRow_, 0.0)); |
| 108 |
gezelter |
1544 |
vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES, |
| 109 |
gezelter |
1567 |
vector<RealType> (nAtomsInCol_, 0.0)); |
| 110 |
gezelter |
1549 |
|
| 111 |
gezelter |
1567 |
identsRow.reserve(nAtomsInRow_); |
| 112 |
|
|
identsCol.reserve(nAtomsInCol_); |
| 113 |
gezelter |
1549 |
|
| 114 |
|
|
AtomCommIntRow->gather(identsLocal, identsRow); |
| 115 |
|
|
AtomCommIntColumn->gather(identsLocal, identsCol); |
| 116 |
|
|
|
| 117 |
|
|
AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
| 118 |
|
|
AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
| 119 |
|
|
|
| 120 |
|
|
cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
| 121 |
|
|
cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
| 122 |
gezelter |
1541 |
|
| 123 |
gezelter |
1569 |
AtomCommRealRow->gather(massFactorsLocal, massFactorsRow); |
| 124 |
|
|
AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol); |
| 125 |
|
|
|
| 126 |
|
|
groupListRow_.clear(); |
| 127 |
|
|
groupListRow_.reserve(nGroupsInRow_); |
| 128 |
|
|
for (int i = 0; i < nGroupsInRow_; i++) { |
| 129 |
|
|
int gid = cgRowToGlobal[i]; |
| 130 |
|
|
for (int j = 0; j < nAtomsInRow_; j++) { |
| 131 |
|
|
int aid = AtomRowToGlobal[j]; |
| 132 |
|
|
if (globalGroupMembership[aid] == gid) |
| 133 |
|
|
groupListRow_[i].push_back(j); |
| 134 |
|
|
} |
| 135 |
|
|
} |
| 136 |
|
|
|
| 137 |
|
|
groupListCol_.clear(); |
| 138 |
|
|
groupListCol_.reserve(nGroupsInCol_); |
| 139 |
|
|
for (int i = 0; i < nGroupsInCol_; i++) { |
| 140 |
|
|
int gid = cgColToGlobal[i]; |
| 141 |
|
|
for (int j = 0; j < nAtomsInCol_; j++) { |
| 142 |
|
|
int aid = AtomColToGlobal[j]; |
| 143 |
|
|
if (globalGroupMembership[aid] == gid) |
| 144 |
|
|
groupListCol_[i].push_back(j); |
| 145 |
|
|
} |
| 146 |
|
|
} |
| 147 |
|
|
|
| 148 |
gezelter |
1570 |
skipsForRowAtom.clear(); |
| 149 |
|
|
skipsForRowAtom.reserve(nAtomsInRow_); |
| 150 |
|
|
for (int i = 0; i < nAtomsInRow_; i++) { |
| 151 |
gezelter |
1571 |
int iglob = AtomRowToGlobal[i]; |
| 152 |
gezelter |
1570 |
for (int j = 0; j < nAtomsInCol_; j++) { |
| 153 |
gezelter |
1571 |
int jglob = AtomColToGlobal[j]; |
| 154 |
gezelter |
1570 |
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 |
gezelter |
1571 |
int iglob = AtomRowToGlobal[i]; |
| 163 |
gezelter |
1570 |
int nTopos = 0; |
| 164 |
|
|
for (int j = 0; j < nAtomsInCol_; j++) { |
| 165 |
gezelter |
1571 |
int jglob = AtomColToGlobal[j]; |
| 166 |
gezelter |
1570 |
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 |
gezelter |
1569 |
#endif |
| 185 |
|
|
|
| 186 |
|
|
groupList_.clear(); |
| 187 |
|
|
groupList_.reserve(nGroups_); |
| 188 |
|
|
for (int i = 0; i < nGroups_; i++) { |
| 189 |
|
|
int gid = cgLocalToGlobal[i]; |
| 190 |
|
|
for (int j = 0; j < nLocal_; j++) { |
| 191 |
|
|
int aid = AtomLocalToGlobal[j]; |
| 192 |
|
|
if (globalGroupMembership[aid] == gid) |
| 193 |
|
|
groupList_[i].push_back(j); |
| 194 |
|
|
} |
| 195 |
|
|
} |
| 196 |
|
|
|
| 197 |
gezelter |
1570 |
skipsForLocalAtom.clear(); |
| 198 |
|
|
skipsForLocalAtom.reserve(nLocal_); |
| 199 |
gezelter |
1569 |
|
| 200 |
gezelter |
1570 |
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 |
|
|
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 |
gezelter |
1539 |
} |
| 234 |
gezelter |
1570 |
|
| 235 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeData() { |
| 236 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
| 237 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
| 238 |
chuckv |
1538 |
#ifdef IS_MPI |
| 239 |
gezelter |
1540 |
|
| 240 |
gezelter |
1539 |
// gather up the atomic positions |
| 241 |
gezelter |
1551 |
AtomCommVectorRow->gather(snap_->atomData.position, |
| 242 |
|
|
atomRowData.position); |
| 243 |
|
|
AtomCommVectorColumn->gather(snap_->atomData.position, |
| 244 |
|
|
atomColData.position); |
| 245 |
gezelter |
1539 |
|
| 246 |
|
|
// gather up the cutoff group positions |
| 247 |
gezelter |
1551 |
cgCommVectorRow->gather(snap_->cgData.position, |
| 248 |
|
|
cgRowData.position); |
| 249 |
|
|
cgCommVectorColumn->gather(snap_->cgData.position, |
| 250 |
|
|
cgColData.position); |
| 251 |
gezelter |
1539 |
|
| 252 |
|
|
// if needed, gather the atomic rotation matrices |
| 253 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslAmat) { |
| 254 |
|
|
AtomCommMatrixRow->gather(snap_->atomData.aMat, |
| 255 |
|
|
atomRowData.aMat); |
| 256 |
|
|
AtomCommMatrixColumn->gather(snap_->atomData.aMat, |
| 257 |
|
|
atomColData.aMat); |
| 258 |
gezelter |
1539 |
} |
| 259 |
|
|
|
| 260 |
|
|
// if needed, gather the atomic eletrostatic frames |
| 261 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 262 |
|
|
AtomCommMatrixRow->gather(snap_->atomData.electroFrame, |
| 263 |
|
|
atomRowData.electroFrame); |
| 264 |
|
|
AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, |
| 265 |
|
|
atomColData.electroFrame); |
| 266 |
gezelter |
1539 |
} |
| 267 |
|
|
#endif |
| 268 |
|
|
} |
| 269 |
|
|
|
| 270 |
gezelter |
1549 |
void ForceMatrixDecomposition::collectIntermediateData() { |
| 271 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
| 272 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
| 273 |
gezelter |
1539 |
#ifdef IS_MPI |
| 274 |
|
|
|
| 275 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslDensity) { |
| 276 |
|
|
|
| 277 |
|
|
AtomCommRealRow->scatter(atomRowData.density, |
| 278 |
|
|
snap_->atomData.density); |
| 279 |
|
|
|
| 280 |
|
|
int n = snap_->atomData.density.size(); |
| 281 |
gezelter |
1541 |
std::vector<RealType> rho_tmp(n, 0.0); |
| 282 |
gezelter |
1551 |
AtomCommRealColumn->scatter(atomColData.density, rho_tmp); |
| 283 |
gezelter |
1539 |
for (int i = 0; i < n; i++) |
| 284 |
gezelter |
1551 |
snap_->atomData.density[i] += rho_tmp[i]; |
| 285 |
gezelter |
1539 |
} |
| 286 |
chuckv |
1538 |
#endif |
| 287 |
gezelter |
1539 |
} |
| 288 |
|
|
|
| 289 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeIntermediateData() { |
| 290 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
| 291 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
| 292 |
chuckv |
1538 |
#ifdef IS_MPI |
| 293 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctional) { |
| 294 |
|
|
AtomCommRealRow->gather(snap_->atomData.functional, |
| 295 |
|
|
atomRowData.functional); |
| 296 |
|
|
AtomCommRealColumn->gather(snap_->atomData.functional, |
| 297 |
|
|
atomColData.functional); |
| 298 |
gezelter |
1539 |
} |
| 299 |
|
|
|
| 300 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
| 301 |
|
|
AtomCommRealRow->gather(snap_->atomData.functionalDerivative, |
| 302 |
|
|
atomRowData.functionalDerivative); |
| 303 |
|
|
AtomCommRealColumn->gather(snap_->atomData.functionalDerivative, |
| 304 |
|
|
atomColData.functionalDerivative); |
| 305 |
gezelter |
1539 |
} |
| 306 |
chuckv |
1538 |
#endif |
| 307 |
|
|
} |
| 308 |
gezelter |
1539 |
|
| 309 |
|
|
|
| 310 |
gezelter |
1549 |
void ForceMatrixDecomposition::collectData() { |
| 311 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
| 312 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
| 313 |
|
|
#ifdef IS_MPI |
| 314 |
|
|
int n = snap_->atomData.force.size(); |
| 315 |
gezelter |
1544 |
vector<Vector3d> frc_tmp(n, V3Zero); |
| 316 |
gezelter |
1541 |
|
| 317 |
gezelter |
1551 |
AtomCommVectorRow->scatter(atomRowData.force, frc_tmp); |
| 318 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
| 319 |
gezelter |
1551 |
snap_->atomData.force[i] += frc_tmp[i]; |
| 320 |
gezelter |
1541 |
frc_tmp[i] = 0.0; |
| 321 |
|
|
} |
| 322 |
gezelter |
1540 |
|
| 323 |
gezelter |
1551 |
AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); |
| 324 |
gezelter |
1540 |
for (int i = 0; i < n; i++) |
| 325 |
gezelter |
1551 |
snap_->atomData.force[i] += frc_tmp[i]; |
| 326 |
gezelter |
1540 |
|
| 327 |
|
|
|
| 328 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslTorque) { |
| 329 |
gezelter |
1541 |
|
| 330 |
gezelter |
1551 |
int nt = snap_->atomData.force.size(); |
| 331 |
gezelter |
1544 |
vector<Vector3d> trq_tmp(nt, V3Zero); |
| 332 |
gezelter |
1541 |
|
| 333 |
gezelter |
1551 |
AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); |
| 334 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
| 335 |
gezelter |
1551 |
snap_->atomData.torque[i] += trq_tmp[i]; |
| 336 |
gezelter |
1541 |
trq_tmp[i] = 0.0; |
| 337 |
|
|
} |
| 338 |
gezelter |
1540 |
|
| 339 |
gezelter |
1551 |
AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); |
| 340 |
gezelter |
1540 |
for (int i = 0; i < n; i++) |
| 341 |
gezelter |
1551 |
snap_->atomData.torque[i] += trq_tmp[i]; |
| 342 |
gezelter |
1540 |
} |
| 343 |
|
|
|
| 344 |
gezelter |
1567 |
nLocal_ = snap_->getNumberOfAtoms(); |
| 345 |
gezelter |
1544 |
|
| 346 |
|
|
vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES, |
| 347 |
gezelter |
1567 |
vector<RealType> (nLocal_, 0.0)); |
| 348 |
gezelter |
1540 |
|
| 349 |
gezelter |
1544 |
for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { |
| 350 |
gezelter |
1549 |
AtomCommRealRow->scatter(pot_row[i], pot_temp[i]); |
| 351 |
gezelter |
1541 |
for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { |
| 352 |
|
|
pot_local[i] += pot_temp[i][ii]; |
| 353 |
|
|
} |
| 354 |
|
|
} |
| 355 |
gezelter |
1539 |
#endif |
| 356 |
chuckv |
1538 |
} |
| 357 |
gezelter |
1551 |
|
| 358 |
gezelter |
1570 |
int ForceMatrixDecomposition::getNAtomsInRow() { |
| 359 |
|
|
#ifdef IS_MPI |
| 360 |
|
|
return nAtomsInRow_; |
| 361 |
|
|
#else |
| 362 |
|
|
return nLocal_; |
| 363 |
|
|
#endif |
| 364 |
|
|
} |
| 365 |
|
|
|
| 366 |
gezelter |
1569 |
/** |
| 367 |
|
|
* returns the list of atoms belonging to this group. |
| 368 |
|
|
*/ |
| 369 |
|
|
vector<int> ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){ |
| 370 |
|
|
#ifdef IS_MPI |
| 371 |
|
|
return groupListRow_[cg1]; |
| 372 |
|
|
#else |
| 373 |
|
|
return groupList_[cg1]; |
| 374 |
|
|
#endif |
| 375 |
|
|
} |
| 376 |
|
|
|
| 377 |
|
|
vector<int> ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){ |
| 378 |
|
|
#ifdef IS_MPI |
| 379 |
|
|
return groupListCol_[cg2]; |
| 380 |
|
|
#else |
| 381 |
|
|
return groupList_[cg2]; |
| 382 |
|
|
#endif |
| 383 |
|
|
} |
| 384 |
chuckv |
1538 |
|
| 385 |
gezelter |
1551 |
Vector3d ForceMatrixDecomposition::getIntergroupVector(int cg1, int cg2){ |
| 386 |
|
|
Vector3d d; |
| 387 |
|
|
|
| 388 |
|
|
#ifdef IS_MPI |
| 389 |
|
|
d = cgColData.position[cg2] - cgRowData.position[cg1]; |
| 390 |
|
|
#else |
| 391 |
|
|
d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1]; |
| 392 |
|
|
#endif |
| 393 |
|
|
|
| 394 |
|
|
snap_->wrapVector(d); |
| 395 |
|
|
return d; |
| 396 |
|
|
} |
| 397 |
|
|
|
| 398 |
|
|
|
| 399 |
|
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){ |
| 400 |
|
|
|
| 401 |
|
|
Vector3d d; |
| 402 |
|
|
|
| 403 |
|
|
#ifdef IS_MPI |
| 404 |
|
|
d = cgRowData.position[cg1] - atomRowData.position[atom1]; |
| 405 |
|
|
#else |
| 406 |
|
|
d = snap_->cgData.position[cg1] - snap_->atomData.position[atom1]; |
| 407 |
|
|
#endif |
| 408 |
|
|
|
| 409 |
|
|
snap_->wrapVector(d); |
| 410 |
|
|
return d; |
| 411 |
|
|
} |
| 412 |
|
|
|
| 413 |
|
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorColumn(int atom2, int cg2){ |
| 414 |
|
|
Vector3d d; |
| 415 |
|
|
|
| 416 |
|
|
#ifdef IS_MPI |
| 417 |
|
|
d = cgColData.position[cg2] - atomColData.position[atom2]; |
| 418 |
|
|
#else |
| 419 |
|
|
d = snap_->cgData.position[cg2] - snap_->atomData.position[atom2]; |
| 420 |
|
|
#endif |
| 421 |
|
|
|
| 422 |
|
|
snap_->wrapVector(d); |
| 423 |
|
|
return d; |
| 424 |
|
|
} |
| 425 |
gezelter |
1569 |
|
| 426 |
|
|
RealType ForceMatrixDecomposition::getMassFactorRow(int atom1) { |
| 427 |
|
|
#ifdef IS_MPI |
| 428 |
|
|
return massFactorsRow[atom1]; |
| 429 |
|
|
#else |
| 430 |
|
|
return massFactorsLocal[atom1]; |
| 431 |
|
|
#endif |
| 432 |
|
|
} |
| 433 |
|
|
|
| 434 |
|
|
RealType ForceMatrixDecomposition::getMassFactorColumn(int atom2) { |
| 435 |
|
|
#ifdef IS_MPI |
| 436 |
|
|
return massFactorsCol[atom2]; |
| 437 |
|
|
#else |
| 438 |
|
|
return massFactorsLocal[atom2]; |
| 439 |
|
|
#endif |
| 440 |
|
|
|
| 441 |
|
|
} |
| 442 |
gezelter |
1551 |
|
| 443 |
|
|
Vector3d ForceMatrixDecomposition::getInteratomicVector(int atom1, int atom2){ |
| 444 |
|
|
Vector3d d; |
| 445 |
|
|
|
| 446 |
|
|
#ifdef IS_MPI |
| 447 |
|
|
d = atomColData.position[atom2] - atomRowData.position[atom1]; |
| 448 |
|
|
#else |
| 449 |
|
|
d = snap_->atomData.position[atom2] - snap_->atomData.position[atom1]; |
| 450 |
|
|
#endif |
| 451 |
|
|
|
| 452 |
|
|
snap_->wrapVector(d); |
| 453 |
|
|
return d; |
| 454 |
|
|
} |
| 455 |
|
|
|
| 456 |
gezelter |
1570 |
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 |
gezelter |
1551 |
void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ |
| 524 |
|
|
#ifdef IS_MPI |
| 525 |
|
|
atomRowData.force[atom1] += fg; |
| 526 |
|
|
#else |
| 527 |
|
|
snap_->atomData.force[atom1] += fg; |
| 528 |
|
|
#endif |
| 529 |
|
|
} |
| 530 |
|
|
|
| 531 |
|
|
void ForceMatrixDecomposition::addForceToAtomColumn(int atom2, Vector3d fg){ |
| 532 |
|
|
#ifdef IS_MPI |
| 533 |
|
|
atomColData.force[atom2] += fg; |
| 534 |
|
|
#else |
| 535 |
|
|
snap_->atomData.force[atom2] += fg; |
| 536 |
|
|
#endif |
| 537 |
|
|
} |
| 538 |
|
|
|
| 539 |
|
|
// filling interaction blocks with pointers |
| 540 |
|
|
InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) { |
| 541 |
gezelter |
1567 |
InteractionData idat; |
| 542 |
gezelter |
1551 |
|
| 543 |
|
|
#ifdef IS_MPI |
| 544 |
gezelter |
1571 |
|
| 545 |
|
|
idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
| 546 |
|
|
ff_->getAtomType(identsCol[atom2]) ); |
| 547 |
|
|
|
| 548 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslAmat) { |
| 549 |
gezelter |
1554 |
idat.A1 = &(atomRowData.aMat[atom1]); |
| 550 |
|
|
idat.A2 = &(atomColData.aMat[atom2]); |
| 551 |
gezelter |
1551 |
} |
| 552 |
gezelter |
1567 |
|
| 553 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 554 |
gezelter |
1554 |
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
| 555 |
|
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
| 556 |
gezelter |
1551 |
} |
| 557 |
|
|
|
| 558 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
| 559 |
gezelter |
1554 |
idat.t1 = &(atomRowData.torque[atom1]); |
| 560 |
|
|
idat.t2 = &(atomColData.torque[atom2]); |
| 561 |
gezelter |
1551 |
} |
| 562 |
|
|
|
| 563 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
| 564 |
gezelter |
1554 |
idat.rho1 = &(atomRowData.density[atom1]); |
| 565 |
|
|
idat.rho2 = &(atomColData.density[atom2]); |
| 566 |
gezelter |
1551 |
} |
| 567 |
|
|
|
| 568 |
|
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
| 569 |
gezelter |
1554 |
idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]); |
| 570 |
|
|
idat.dfrho2 = &(atomColData.functionalDerivative[atom2]); |
| 571 |
gezelter |
1551 |
} |
| 572 |
gezelter |
1570 |
|
| 573 |
gezelter |
1562 |
#else |
| 574 |
gezelter |
1571 |
|
| 575 |
|
|
idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
| 576 |
|
|
ff_->getAtomType(identsLocal[atom2]) ); |
| 577 |
|
|
|
| 578 |
gezelter |
1562 |
if (storageLayout_ & DataStorage::dslAmat) { |
| 579 |
|
|
idat.A1 = &(snap_->atomData.aMat[atom1]); |
| 580 |
|
|
idat.A2 = &(snap_->atomData.aMat[atom2]); |
| 581 |
|
|
} |
| 582 |
|
|
|
| 583 |
|
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 584 |
|
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
| 585 |
|
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
| 586 |
|
|
} |
| 587 |
|
|
|
| 588 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
| 589 |
|
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
| 590 |
|
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
| 591 |
|
|
} |
| 592 |
|
|
|
| 593 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
| 594 |
|
|
idat.rho1 = &(snap_->atomData.density[atom1]); |
| 595 |
|
|
idat.rho2 = &(snap_->atomData.density[atom2]); |
| 596 |
|
|
} |
| 597 |
|
|
|
| 598 |
|
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
| 599 |
|
|
idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]); |
| 600 |
|
|
idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]); |
| 601 |
|
|
} |
| 602 |
gezelter |
1551 |
#endif |
| 603 |
gezelter |
1567 |
return idat; |
| 604 |
gezelter |
1551 |
} |
| 605 |
gezelter |
1567 |
|
| 606 |
gezelter |
1551 |
InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){ |
| 607 |
gezelter |
1567 |
|
| 608 |
gezelter |
1562 |
InteractionData idat; |
| 609 |
|
|
#ifdef IS_MPI |
| 610 |
gezelter |
1571 |
idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
| 611 |
|
|
ff_->getAtomType(identsCol[atom2]) ); |
| 612 |
|
|
|
| 613 |
gezelter |
1562 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 614 |
|
|
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
| 615 |
|
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
| 616 |
|
|
} |
| 617 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
| 618 |
|
|
idat.t1 = &(atomRowData.torque[atom1]); |
| 619 |
|
|
idat.t2 = &(atomColData.torque[atom2]); |
| 620 |
|
|
} |
| 621 |
gezelter |
1567 |
if (storageLayout_ & DataStorage::dslForce) { |
| 622 |
|
|
idat.t1 = &(atomRowData.force[atom1]); |
| 623 |
|
|
idat.t2 = &(atomColData.force[atom2]); |
| 624 |
|
|
} |
| 625 |
|
|
#else |
| 626 |
gezelter |
1571 |
idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
| 627 |
|
|
ff_->getAtomType(identsLocal[atom2]) ); |
| 628 |
|
|
|
| 629 |
gezelter |
1567 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
| 630 |
|
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
| 631 |
|
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
| 632 |
|
|
} |
| 633 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
| 634 |
|
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
| 635 |
|
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
| 636 |
|
|
} |
| 637 |
|
|
if (storageLayout_ & DataStorage::dslForce) { |
| 638 |
|
|
idat.t1 = &(snap_->atomData.force[atom1]); |
| 639 |
|
|
idat.t2 = &(snap_->atomData.force[atom2]); |
| 640 |
|
|
} |
| 641 |
gezelter |
1571 |
#endif |
| 642 |
gezelter |
1551 |
} |
| 643 |
gezelter |
1567 |
|
| 644 |
gezelter |
1562 |
/* |
| 645 |
|
|
* buildNeighborList |
| 646 |
|
|
* |
| 647 |
|
|
* first element of pair is row-indexed CutoffGroup |
| 648 |
|
|
* second element of pair is column-indexed CutoffGroup |
| 649 |
|
|
*/ |
| 650 |
gezelter |
1567 |
vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { |
| 651 |
|
|
|
| 652 |
|
|
vector<pair<int, int> > neighborList; |
| 653 |
|
|
#ifdef IS_MPI |
| 654 |
gezelter |
1568 |
cellListRow_.clear(); |
| 655 |
|
|
cellListCol_.clear(); |
| 656 |
gezelter |
1567 |
#else |
| 657 |
gezelter |
1568 |
cellList_.clear(); |
| 658 |
gezelter |
1567 |
#endif |
| 659 |
gezelter |
1562 |
|
| 660 |
gezelter |
1567 |
// dangerous to not do error checking. |
| 661 |
|
|
RealType rCut_; |
| 662 |
|
|
|
| 663 |
|
|
RealType rList_ = (rCut_ + skinThickness_); |
| 664 |
|
|
RealType rl2 = rList_ * rList_; |
| 665 |
|
|
Snapshot* snap_ = sman_->getCurrentSnapshot(); |
| 666 |
gezelter |
1562 |
Mat3x3d Hmat = snap_->getHmat(); |
| 667 |
|
|
Vector3d Hx = Hmat.getColumn(0); |
| 668 |
|
|
Vector3d Hy = Hmat.getColumn(1); |
| 669 |
|
|
Vector3d Hz = Hmat.getColumn(2); |
| 670 |
|
|
|
| 671 |
gezelter |
1568 |
nCells_.x() = (int) ( Hx.length() )/ rList_; |
| 672 |
|
|
nCells_.y() = (int) ( Hy.length() )/ rList_; |
| 673 |
|
|
nCells_.z() = (int) ( Hz.length() )/ rList_; |
| 674 |
gezelter |
1562 |
|
| 675 |
gezelter |
1567 |
Mat3x3d invHmat = snap_->getInvHmat(); |
| 676 |
|
|
Vector3d rs, scaled, dr; |
| 677 |
|
|
Vector3i whichCell; |
| 678 |
|
|
int cellIndex; |
| 679 |
|
|
|
| 680 |
|
|
#ifdef IS_MPI |
| 681 |
|
|
for (int i = 0; i < nGroupsInRow_; i++) { |
| 682 |
gezelter |
1562 |
rs = cgRowData.position[i]; |
| 683 |
gezelter |
1567 |
// scaled positions relative to the box vectors |
| 684 |
|
|
scaled = invHmat * rs; |
| 685 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
| 686 |
|
|
// numbers |
| 687 |
|
|
for (int j = 0; j < 3; j++) |
| 688 |
|
|
scaled[j] -= roundMe(scaled[j]); |
| 689 |
|
|
|
| 690 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
| 691 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
| 692 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
| 693 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
| 694 |
gezelter |
1567 |
|
| 695 |
|
|
// find single index of this cell: |
| 696 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
| 697 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
| 698 |
gezelter |
1568 |
cellListRow_[cellIndex].push_back(i); |
| 699 |
gezelter |
1562 |
} |
| 700 |
|
|
|
| 701 |
gezelter |
1567 |
for (int i = 0; i < nGroupsInCol_; i++) { |
| 702 |
|
|
rs = cgColData.position[i]; |
| 703 |
|
|
// scaled positions relative to the box vectors |
| 704 |
|
|
scaled = invHmat * rs; |
| 705 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
| 706 |
|
|
// numbers |
| 707 |
|
|
for (int j = 0; j < 3; j++) |
| 708 |
|
|
scaled[j] -= roundMe(scaled[j]); |
| 709 |
|
|
|
| 710 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
| 711 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
| 712 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
| 713 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
| 714 |
gezelter |
1567 |
|
| 715 |
|
|
// find single index of this cell: |
| 716 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
| 717 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
| 718 |
gezelter |
1568 |
cellListCol_[cellIndex].push_back(i); |
| 719 |
gezelter |
1562 |
} |
| 720 |
gezelter |
1567 |
#else |
| 721 |
|
|
for (int i = 0; i < nGroups_; i++) { |
| 722 |
|
|
rs = snap_->cgData.position[i]; |
| 723 |
|
|
// scaled positions relative to the box vectors |
| 724 |
|
|
scaled = invHmat * rs; |
| 725 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
| 726 |
|
|
// numbers |
| 727 |
|
|
for (int j = 0; j < 3; j++) |
| 728 |
|
|
scaled[j] -= roundMe(scaled[j]); |
| 729 |
|
|
|
| 730 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
| 731 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
| 732 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
| 733 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
| 734 |
gezelter |
1567 |
|
| 735 |
|
|
// find single index of this cell: |
| 736 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
| 737 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
| 738 |
gezelter |
1568 |
cellList_[cellIndex].push_back(i); |
| 739 |
gezelter |
1567 |
} |
| 740 |
|
|
#endif |
| 741 |
|
|
|
| 742 |
|
|
|
| 743 |
|
|
|
| 744 |
gezelter |
1568 |
for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
| 745 |
|
|
for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
| 746 |
|
|
for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
| 747 |
gezelter |
1562 |
Vector3i m1v(m1x, m1y, m1z); |
| 748 |
gezelter |
1568 |
int m1 = Vlinear(m1v, nCells_); |
| 749 |
gezelter |
1562 |
|
| 750 |
gezelter |
1568 |
for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
| 751 |
|
|
os != cellOffsets_.end(); ++os) { |
| 752 |
|
|
|
| 753 |
|
|
Vector3i m2v = m1v + (*os); |
| 754 |
|
|
|
| 755 |
|
|
if (m2v.x() >= nCells_.x()) { |
| 756 |
gezelter |
1562 |
m2v.x() = 0; |
| 757 |
|
|
} else if (m2v.x() < 0) { |
| 758 |
gezelter |
1568 |
m2v.x() = nCells_.x() - 1; |
| 759 |
gezelter |
1562 |
} |
| 760 |
gezelter |
1568 |
|
| 761 |
|
|
if (m2v.y() >= nCells_.y()) { |
| 762 |
gezelter |
1562 |
m2v.y() = 0; |
| 763 |
|
|
} else if (m2v.y() < 0) { |
| 764 |
gezelter |
1568 |
m2v.y() = nCells_.y() - 1; |
| 765 |
gezelter |
1562 |
} |
| 766 |
gezelter |
1568 |
|
| 767 |
|
|
if (m2v.z() >= nCells_.z()) { |
| 768 |
gezelter |
1567 |
m2v.z() = 0; |
| 769 |
|
|
} else if (m2v.z() < 0) { |
| 770 |
gezelter |
1568 |
m2v.z() = nCells_.z() - 1; |
| 771 |
gezelter |
1567 |
} |
| 772 |
gezelter |
1568 |
|
| 773 |
|
|
int m2 = Vlinear (m2v, nCells_); |
| 774 |
gezelter |
1567 |
|
| 775 |
|
|
#ifdef IS_MPI |
| 776 |
gezelter |
1568 |
for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
| 777 |
|
|
j1 != cellListRow_[m1].end(); ++j1) { |
| 778 |
|
|
for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
| 779 |
|
|
j2 != cellListCol_[m2].end(); ++j2) { |
| 780 |
gezelter |
1567 |
|
| 781 |
|
|
// Always do this if we're in different cells or if |
| 782 |
|
|
// we're in the same cell and the global index of the |
| 783 |
|
|
// j2 cutoff group is less than the j1 cutoff group |
| 784 |
|
|
|
| 785 |
|
|
if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
| 786 |
|
|
dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
| 787 |
|
|
snap_->wrapVector(dr); |
| 788 |
|
|
if (dr.lengthSquare() < rl2) { |
| 789 |
|
|
neighborList.push_back(make_pair((*j1), (*j2))); |
| 790 |
gezelter |
1562 |
} |
| 791 |
|
|
} |
| 792 |
|
|
} |
| 793 |
|
|
} |
| 794 |
gezelter |
1567 |
#else |
| 795 |
gezelter |
1568 |
for (vector<int>::iterator j1 = cellList_[m1].begin(); |
| 796 |
|
|
j1 != cellList_[m1].end(); ++j1) { |
| 797 |
|
|
for (vector<int>::iterator j2 = cellList_[m2].begin(); |
| 798 |
|
|
j2 != cellList_[m2].end(); ++j2) { |
| 799 |
gezelter |
1567 |
|
| 800 |
|
|
// Always do this if we're in different cells or if |
| 801 |
|
|
// we're in the same cell and the global index of the |
| 802 |
|
|
// j2 cutoff group is less than the j1 cutoff group |
| 803 |
|
|
|
| 804 |
|
|
if (m2 != m1 || (*j2) < (*j1)) { |
| 805 |
|
|
dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
| 806 |
|
|
snap_->wrapVector(dr); |
| 807 |
|
|
if (dr.lengthSquare() < rl2) { |
| 808 |
|
|
neighborList.push_back(make_pair((*j1), (*j2))); |
| 809 |
|
|
} |
| 810 |
|
|
} |
| 811 |
|
|
} |
| 812 |
|
|
} |
| 813 |
|
|
#endif |
| 814 |
gezelter |
1562 |
} |
| 815 |
|
|
} |
| 816 |
|
|
} |
| 817 |
|
|
} |
| 818 |
gezelter |
1568 |
|
| 819 |
|
|
// save the local cutoff group positions for the check that is |
| 820 |
|
|
// done on each loop: |
| 821 |
|
|
saved_CG_positions_.clear(); |
| 822 |
|
|
for (int i = 0; i < nGroups_; i++) |
| 823 |
|
|
saved_CG_positions_.push_back(snap_->cgData.position[i]); |
| 824 |
|
|
|
| 825 |
gezelter |
1567 |
return neighborList; |
| 826 |
gezelter |
1562 |
} |
| 827 |
gezelter |
1539 |
} //end namespace OpenMD |