# | Line 57 | Line 57 | namespace OpenMD { | |
---|---|---|
57 | storageLayout_ = sman_->getStorageLayout(); | |
58 | ff_ = info_->getForceField(); | |
59 | nLocal_ = snap_->getNumberOfAtoms(); | |
60 | < | nGroups_ = snap_->getNumberOfCutoffGroups(); |
61 | < | |
60 | > | |
61 | > | nGroups_ = info_->getNLocalCutoffGroups(); |
62 | // gather the information for atomtype IDs (atids): | |
63 | < | identsLocal = info_->getIdentArray(); |
63 | > | idents = 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(); |
67 | ||
68 | + | massFactors = info_->getMassFactors(); |
69 | + | |
70 | + | PairList* excludes = info_->getExcludedInteractions(); |
71 | + | PairList* oneTwo = info_->getOneTwoInteractions(); |
72 | + | PairList* oneThree = info_->getOneThreeInteractions(); |
73 | + | PairList* oneFour = info_->getOneFourInteractions(); |
74 | + | |
75 | #ifdef IS_MPI | |
76 | ||
77 | AtomCommIntRow = new Communicator<Row,int>(nLocal_); | |
# | Line 104 | Line 106 | namespace OpenMD { | |
106 | cgColData.resize(nGroupsInCol_); | |
107 | cgColData.setStorageLayout(DataStorage::dslPosition); | |
108 | ||
109 | < | identsRow.reserve(nAtomsInRow_); |
110 | < | identsCol.reserve(nAtomsInCol_); |
109 | > | identsRow.resize(nAtomsInRow_); |
110 | > | identsCol.resize(nAtomsInCol_); |
111 | ||
112 | < | AtomCommIntRow->gather(identsLocal, identsRow); |
113 | < | AtomCommIntColumn->gather(identsLocal, identsCol); |
112 | > | AtomCommIntRow->gather(idents, identsRow); |
113 | > | AtomCommIntColumn->gather(idents, identsCol); |
114 | ||
115 | + | // allocate memory for the parallel objects |
116 | + | atypesRow.resize(nAtomsInRow_); |
117 | + | atypesCol.resize(nAtomsInCol_); |
118 | + | |
119 | + | for (int i = 0; i < nAtomsInRow_; i++) |
120 | + | atypesRow[i] = ff_->getAtomType(identsRow[i]); |
121 | + | for (int i = 0; i < nAtomsInCol_; i++) |
122 | + | atypesCol[i] = ff_->getAtomType(identsCol[i]); |
123 | + | |
124 | + | pot_row.resize(nAtomsInRow_); |
125 | + | pot_col.resize(nAtomsInCol_); |
126 | + | |
127 | + | AtomRowToGlobal.resize(nAtomsInRow_); |
128 | + | AtomColToGlobal.resize(nAtomsInCol_); |
129 | AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); | |
130 | AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); | |
131 | ||
132 | + | cgRowToGlobal.resize(nGroupsInRow_); |
133 | + | cgColToGlobal.resize(nGroupsInCol_); |
134 | cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); | |
135 | cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); | |
136 | ||
137 | < | AtomCommRealRow->gather(massFactorsLocal, massFactorsRow); |
138 | < | AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol); |
137 | > | massFactorsRow.resize(nAtomsInRow_); |
138 | > | massFactorsCol.resize(nAtomsInCol_); |
139 | > | AtomCommRealRow->gather(massFactors, massFactorsRow); |
140 | > | AtomCommRealColumn->gather(massFactors, massFactorsCol); |
141 | ||
142 | groupListRow_.clear(); | |
143 | < | groupListRow_.reserve(nGroupsInRow_); |
143 | > | groupListRow_.resize(nGroupsInRow_); |
144 | for (int i = 0; i < nGroupsInRow_; i++) { | |
145 | int gid = cgRowToGlobal[i]; | |
146 | for (int j = 0; j < nAtomsInRow_; j++) { | |
# | Line 131 | Line 151 | namespace OpenMD { | |
151 | } | |
152 | ||
153 | groupListCol_.clear(); | |
154 | < | groupListCol_.reserve(nGroupsInCol_); |
154 | > | groupListCol_.resize(nGroupsInCol_); |
155 | for (int i = 0; i < nGroupsInCol_; i++) { | |
156 | int gid = cgColToGlobal[i]; | |
157 | for (int j = 0; j < nAtomsInCol_; j++) { | |
# | Line 141 | Line 161 | namespace OpenMD { | |
161 | } | |
162 | } | |
163 | ||
164 | < | skipsForRowAtom.clear(); |
165 | < | skipsForRowAtom.reserve(nAtomsInRow_); |
164 | > | excludesForAtom.clear(); |
165 | > | excludesForAtom.resize(nAtomsInRow_); |
166 | > | toposForAtom.clear(); |
167 | > | toposForAtom.resize(nAtomsInRow_); |
168 | > | topoDist.clear(); |
169 | > | topoDist.resize(nAtomsInRow_); |
170 | for (int i = 0; i < nAtomsInRow_; i++) { | |
171 | int iglob = AtomRowToGlobal[i]; | |
148 | – | for (int j = 0; j < nAtomsInCol_; j++) { |
149 | – | int jglob = AtomColToGlobal[j]; |
150 | – | if (excludes.hasPair(iglob, jglob)) |
151 | – | skipsForRowAtom[i].push_back(j); |
152 | – | } |
153 | – | } |
172 | ||
155 | – | toposForRowAtom.clear(); |
156 | – | toposForRowAtom.reserve(nAtomsInRow_); |
157 | – | for (int i = 0; i < nAtomsInRow_; i++) { |
158 | – | int iglob = AtomRowToGlobal[i]; |
159 | – | int nTopos = 0; |
173 | for (int j = 0; j < nAtomsInCol_; j++) { | |
174 | < | int jglob = AtomColToGlobal[j]; |
175 | < | if (oneTwo.hasPair(iglob, jglob)) { |
176 | < | toposForRowAtom[i].push_back(j); |
177 | < | topoDistRow[i][nTopos] = 1; |
178 | < | nTopos++; |
174 | > | int jglob = AtomColToGlobal[j]; |
175 | > | |
176 | > | if (excludes->hasPair(iglob, jglob)) |
177 | > | excludesForAtom[i].push_back(j); |
178 | > | |
179 | > | if (oneTwo->hasPair(iglob, jglob)) { |
180 | > | toposForAtom[i].push_back(j); |
181 | > | topoDist[i].push_back(1); |
182 | > | } else { |
183 | > | if (oneThree->hasPair(iglob, jglob)) { |
184 | > | toposForAtom[i].push_back(j); |
185 | > | topoDist[i].push_back(2); |
186 | > | } else { |
187 | > | if (oneFour->hasPair(iglob, jglob)) { |
188 | > | toposForAtom[i].push_back(j); |
189 | > | topoDist[i].push_back(3); |
190 | > | } |
191 | > | } |
192 | } | |
167 | – | if (oneThree.hasPair(iglob, jglob)) { |
168 | – | toposForRowAtom[i].push_back(j); |
169 | – | topoDistRow[i][nTopos] = 2; |
170 | – | nTopos++; |
171 | – | } |
172 | – | if (oneFour.hasPair(iglob, jglob)) { |
173 | – | toposForRowAtom[i].push_back(j); |
174 | – | topoDistRow[i][nTopos] = 3; |
175 | – | nTopos++; |
176 | – | } |
193 | } | |
194 | } | |
195 | ||
196 | #endif | |
197 | ||
198 | + | // allocate memory for the parallel objects |
199 | + | atypesLocal.resize(nLocal_); |
200 | + | |
201 | + | for (int i = 0; i < nLocal_; i++) |
202 | + | atypesLocal[i] = ff_->getAtomType(idents[i]); |
203 | + | |
204 | groupList_.clear(); | |
205 | < | groupList_.reserve(nGroups_); |
205 | > | groupList_.resize(nGroups_); |
206 | for (int i = 0; i < nGroups_; i++) { | |
207 | int gid = cgLocalToGlobal[i]; | |
208 | for (int j = 0; j < nLocal_; j++) { | |
209 | int aid = AtomLocalToGlobal[j]; | |
210 | < | if (globalGroupMembership[aid] == gid) |
210 | > | if (globalGroupMembership[aid] == gid) { |
211 | groupList_[i].push_back(j); | |
212 | + | } |
213 | } | |
214 | } | |
215 | ||
216 | < | skipsForLocalAtom.clear(); |
217 | < | skipsForLocalAtom.reserve(nLocal_); |
216 | > | excludesForAtom.clear(); |
217 | > | excludesForAtom.resize(nLocal_); |
218 | > | toposForAtom.clear(); |
219 | > | toposForAtom.resize(nLocal_); |
220 | > | topoDist.clear(); |
221 | > | topoDist.resize(nLocal_); |
222 | ||
223 | for (int i = 0; i < nLocal_; i++) { | |
224 | int iglob = AtomLocalToGlobal[i]; | |
198 | – | for (int j = 0; j < nLocal_; j++) { |
199 | – | int jglob = AtomLocalToGlobal[j]; |
200 | – | if (excludes.hasPair(iglob, jglob)) |
201 | – | skipsForLocalAtom[i].push_back(j); |
202 | – | } |
203 | – | } |
225 | ||
205 | – | toposForLocalAtom.clear(); |
206 | – | toposForLocalAtom.reserve(nLocal_); |
207 | – | for (int i = 0; i < nLocal_; i++) { |
208 | – | int iglob = AtomLocalToGlobal[i]; |
209 | – | int nTopos = 0; |
226 | for (int j = 0; j < nLocal_; j++) { | |
227 | < | int jglob = AtomLocalToGlobal[j]; |
228 | < | if (oneTwo.hasPair(iglob, jglob)) { |
229 | < | toposForLocalAtom[i].push_back(j); |
230 | < | topoDistLocal[i][nTopos] = 1; |
231 | < | nTopos++; |
227 | > | int jglob = AtomLocalToGlobal[j]; |
228 | > | |
229 | > | if (excludes->hasPair(iglob, jglob)) |
230 | > | excludesForAtom[i].push_back(j); |
231 | > | |
232 | > | if (oneTwo->hasPair(iglob, jglob)) { |
233 | > | toposForAtom[i].push_back(j); |
234 | > | topoDist[i].push_back(1); |
235 | > | } else { |
236 | > | if (oneThree->hasPair(iglob, jglob)) { |
237 | > | toposForAtom[i].push_back(j); |
238 | > | topoDist[i].push_back(2); |
239 | > | } else { |
240 | > | if (oneFour->hasPair(iglob, jglob)) { |
241 | > | toposForAtom[i].push_back(j); |
242 | > | topoDist[i].push_back(3); |
243 | > | } |
244 | > | } |
245 | } | |
217 | – | if (oneThree.hasPair(iglob, jglob)) { |
218 | – | toposForLocalAtom[i].push_back(j); |
219 | – | topoDistLocal[i][nTopos] = 2; |
220 | – | nTopos++; |
221 | – | } |
222 | – | if (oneFour.hasPair(iglob, jglob)) { |
223 | – | toposForLocalAtom[i].push_back(j); |
224 | – | topoDistLocal[i][nTopos] = 3; |
225 | – | nTopos++; |
226 | – | } |
246 | } | |
247 | } | |
248 | + | |
249 | + | createGtypeCutoffMap(); |
250 | + | |
251 | } | |
252 | ||
253 | < | void ForceMatrixDecomposition::zeroWorkArrays() { |
253 | > | void ForceMatrixDecomposition::createGtypeCutoffMap() { |
254 | > | |
255 | > | RealType tol = 1e-6; |
256 | > | largestRcut_ = 0.0; |
257 | > | RealType rc; |
258 | > | int atid; |
259 | > | set<AtomType*> atypes = info_->getSimulatedAtomTypes(); |
260 | > | |
261 | > | map<int, RealType> atypeCutoff; |
262 | > | |
263 | > | for (set<AtomType*>::iterator at = atypes.begin(); |
264 | > | at != atypes.end(); ++at){ |
265 | > | atid = (*at)->getIdent(); |
266 | > | if (userChoseCutoff_) |
267 | > | atypeCutoff[atid] = userCutoff_; |
268 | > | else |
269 | > | atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at); |
270 | > | } |
271 | > | |
272 | > | vector<RealType> gTypeCutoffs; |
273 | > | // first we do a single loop over the cutoff groups to find the |
274 | > | // largest cutoff for any atypes present in this group. |
275 | > | #ifdef IS_MPI |
276 | > | vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0); |
277 | > | groupRowToGtype.resize(nGroupsInRow_); |
278 | > | for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) { |
279 | > | vector<int> atomListRow = getAtomsInGroupRow(cg1); |
280 | > | for (vector<int>::iterator ia = atomListRow.begin(); |
281 | > | ia != atomListRow.end(); ++ia) { |
282 | > | int atom1 = (*ia); |
283 | > | atid = identsRow[atom1]; |
284 | > | if (atypeCutoff[atid] > groupCutoffRow[cg1]) { |
285 | > | groupCutoffRow[cg1] = atypeCutoff[atid]; |
286 | > | } |
287 | > | } |
288 | ||
289 | < | for (int j = 0; j < N_INTERACTION_FAMILIES; j++) { |
290 | < | longRangePot_[j] = 0.0; |
289 | > | bool gTypeFound = false; |
290 | > | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
291 | > | if (abs(groupCutoffRow[cg1] - gTypeCutoffs[gt]) < tol) { |
292 | > | groupRowToGtype[cg1] = gt; |
293 | > | gTypeFound = true; |
294 | > | } |
295 | > | } |
296 | > | if (!gTypeFound) { |
297 | > | gTypeCutoffs.push_back( groupCutoffRow[cg1] ); |
298 | > | groupRowToGtype[cg1] = gTypeCutoffs.size() - 1; |
299 | > | } |
300 | > | |
301 | > | } |
302 | > | vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0); |
303 | > | groupColToGtype.resize(nGroupsInCol_); |
304 | > | for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) { |
305 | > | vector<int> atomListCol = getAtomsInGroupColumn(cg2); |
306 | > | for (vector<int>::iterator jb = atomListCol.begin(); |
307 | > | jb != atomListCol.end(); ++jb) { |
308 | > | int atom2 = (*jb); |
309 | > | atid = identsCol[atom2]; |
310 | > | if (atypeCutoff[atid] > groupCutoffCol[cg2]) { |
311 | > | groupCutoffCol[cg2] = atypeCutoff[atid]; |
312 | > | } |
313 | > | } |
314 | > | bool gTypeFound = false; |
315 | > | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
316 | > | if (abs(groupCutoffCol[cg2] - gTypeCutoffs[gt]) < tol) { |
317 | > | groupColToGtype[cg2] = gt; |
318 | > | gTypeFound = true; |
319 | > | } |
320 | > | } |
321 | > | if (!gTypeFound) { |
322 | > | gTypeCutoffs.push_back( groupCutoffCol[cg2] ); |
323 | > | groupColToGtype[cg2] = gTypeCutoffs.size() - 1; |
324 | > | } |
325 | > | } |
326 | > | #else |
327 | > | |
328 | > | vector<RealType> groupCutoff(nGroups_, 0.0); |
329 | > | groupToGtype.resize(nGroups_); |
330 | > | for (int cg1 = 0; cg1 < nGroups_; cg1++) { |
331 | > | groupCutoff[cg1] = 0.0; |
332 | > | vector<int> atomList = getAtomsInGroupRow(cg1); |
333 | > | for (vector<int>::iterator ia = atomList.begin(); |
334 | > | ia != atomList.end(); ++ia) { |
335 | > | int atom1 = (*ia); |
336 | > | atid = idents[atom1]; |
337 | > | if (atypeCutoff[atid] > groupCutoff[cg1]) |
338 | > | groupCutoff[cg1] = atypeCutoff[atid]; |
339 | > | } |
340 | > | |
341 | > | bool gTypeFound = false; |
342 | > | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
343 | > | if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) { |
344 | > | groupToGtype[cg1] = gt; |
345 | > | gTypeFound = true; |
346 | > | } |
347 | > | } |
348 | > | if (!gTypeFound) { |
349 | > | gTypeCutoffs.push_back( groupCutoff[cg1] ); |
350 | > | groupToGtype[cg1] = gTypeCutoffs.size() - 1; |
351 | > | } |
352 | > | } |
353 | > | #endif |
354 | > | |
355 | > | // Now we find the maximum group cutoff value present in the simulation |
356 | > | |
357 | > | RealType groupMax = *max_element(gTypeCutoffs.begin(), |
358 | > | gTypeCutoffs.end()); |
359 | > | |
360 | > | #ifdef IS_MPI |
361 | > | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, |
362 | > | MPI::MAX); |
363 | > | #endif |
364 | > | |
365 | > | RealType tradRcut = groupMax; |
366 | > | |
367 | > | for (int i = 0; i < gTypeCutoffs.size(); i++) { |
368 | > | for (int j = 0; j < gTypeCutoffs.size(); j++) { |
369 | > | RealType thisRcut; |
370 | > | switch(cutoffPolicy_) { |
371 | > | case TRADITIONAL: |
372 | > | thisRcut = tradRcut; |
373 | > | break; |
374 | > | case MIX: |
375 | > | thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]); |
376 | > | break; |
377 | > | case MAX: |
378 | > | thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]); |
379 | > | break; |
380 | > | default: |
381 | > | sprintf(painCave.errMsg, |
382 | > | "ForceMatrixDecomposition::createGtypeCutoffMap " |
383 | > | "hit an unknown cutoff policy!\n"); |
384 | > | painCave.severity = OPENMD_ERROR; |
385 | > | painCave.isFatal = 1; |
386 | > | simError(); |
387 | > | break; |
388 | > | } |
389 | > | |
390 | > | pair<int,int> key = make_pair(i,j); |
391 | > | gTypeCutoffMap[key].first = thisRcut; |
392 | > | if (thisRcut > largestRcut_) largestRcut_ = thisRcut; |
393 | > | gTypeCutoffMap[key].second = thisRcut*thisRcut; |
394 | > | gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2); |
395 | > | // sanity check |
396 | > | |
397 | > | if (userChoseCutoff_) { |
398 | > | if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) { |
399 | > | sprintf(painCave.errMsg, |
400 | > | "ForceMatrixDecomposition::createGtypeCutoffMap " |
401 | > | "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_); |
402 | > | painCave.severity = OPENMD_ERROR; |
403 | > | painCave.isFatal = 1; |
404 | > | simError(); |
405 | > | } |
406 | > | } |
407 | > | } |
408 | > | } |
409 | > | } |
410 | > | |
411 | > | |
412 | > | groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) { |
413 | > | int i, j; |
414 | > | #ifdef IS_MPI |
415 | > | i = groupRowToGtype[cg1]; |
416 | > | j = groupColToGtype[cg2]; |
417 | > | #else |
418 | > | i = groupToGtype[cg1]; |
419 | > | j = groupToGtype[cg2]; |
420 | > | #endif |
421 | > | return gTypeCutoffMap[make_pair(i,j)]; |
422 | > | } |
423 | > | |
424 | > | int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) { |
425 | > | for (int j = 0; j < toposForAtom[atom1].size(); j++) { |
426 | > | if (toposForAtom[atom1][j] == atom2) |
427 | > | return topoDist[atom1][j]; |
428 | } | |
429 | + | return 0; |
430 | + | } |
431 | ||
432 | + | void ForceMatrixDecomposition::zeroWorkArrays() { |
433 | + | pairwisePot = 0.0; |
434 | + | embeddingPot = 0.0; |
435 | + | |
436 | #ifdef IS_MPI | |
437 | if (storageLayout_ & DataStorage::dslForce) { | |
438 | fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero); | |
# | Line 249 | Line 448 | namespace OpenMD { | |
448 | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); | |
449 | ||
450 | fill(pot_col.begin(), pot_col.end(), | |
451 | < | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
253 | < | |
254 | < | pot_local = Vector<RealType, N_INTERACTION_FAMILIES>(0.0); |
451 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
452 | ||
453 | if (storageLayout_ & DataStorage::dslParticlePot) { | |
454 | < | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); |
455 | < | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0); |
454 | > | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), |
455 | > | 0.0); |
456 | > | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), |
457 | > | 0.0); |
458 | } | |
459 | ||
460 | if (storageLayout_ & DataStorage::dslDensity) { | |
# | Line 264 | Line 463 | namespace OpenMD { | |
463 | } | |
464 | ||
465 | if (storageLayout_ & DataStorage::dslFunctional) { | |
466 | < | fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0); |
467 | < | fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0); |
466 | > | fill(atomRowData.functional.begin(), atomRowData.functional.end(), |
467 | > | 0.0); |
468 | > | fill(atomColData.functional.begin(), atomColData.functional.end(), |
469 | > | 0.0); |
470 | } | |
471 | ||
472 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
# | Line 275 | Line 476 | namespace OpenMD { | |
476 | atomColData.functionalDerivative.end(), 0.0); | |
477 | } | |
478 | ||
479 | < | #else |
480 | < | |
479 | > | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
480 | > | fill(atomRowData.skippedCharge.begin(), |
481 | > | atomRowData.skippedCharge.end(), 0.0); |
482 | > | fill(atomColData.skippedCharge.begin(), |
483 | > | atomColData.skippedCharge.end(), 0.0); |
484 | > | } |
485 | > | |
486 | > | #endif |
487 | > | // even in parallel, we need to zero out the local arrays: |
488 | > | |
489 | if (storageLayout_ & DataStorage::dslParticlePot) { | |
490 | fill(snap_->atomData.particlePot.begin(), | |
491 | snap_->atomData.particlePot.end(), 0.0); | |
# | Line 294 | Line 503 | namespace OpenMD { | |
503 | fill(snap_->atomData.functionalDerivative.begin(), | |
504 | snap_->atomData.functionalDerivative.end(), 0.0); | |
505 | } | |
506 | < | #endif |
506 | > | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
507 | > | fill(snap_->atomData.skippedCharge.begin(), |
508 | > | snap_->atomData.skippedCharge.end(), 0.0); |
509 | > | } |
510 | ||
511 | } | |
512 | ||
# | Line 331 | Line 543 | namespace OpenMD { | |
543 | AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, | |
544 | atomColData.electroFrame); | |
545 | } | |
546 | + | |
547 | #endif | |
548 | } | |
549 | ||
# | Line 397 | Line 610 | namespace OpenMD { | |
610 | AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); | |
611 | for (int i = 0; i < n; i++) | |
612 | snap_->atomData.force[i] += frc_tmp[i]; | |
613 | < | |
401 | < | |
613 | > | |
614 | if (storageLayout_ & DataStorage::dslTorque) { | |
615 | ||
616 | < | int nt = snap_->atomData.force.size(); |
616 | > | int nt = snap_->atomData.torque.size(); |
617 | vector<Vector3d> trq_tmp(nt, V3Zero); | |
618 | ||
619 | AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); | |
620 | < | for (int i = 0; i < n; i++) { |
620 | > | for (int i = 0; i < nt; i++) { |
621 | snap_->atomData.torque[i] += trq_tmp[i]; | |
622 | trq_tmp[i] = 0.0; | |
623 | } | |
624 | ||
625 | AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); | |
626 | < | for (int i = 0; i < n; i++) |
626 | > | for (int i = 0; i < nt; i++) |
627 | snap_->atomData.torque[i] += trq_tmp[i]; | |
628 | } | |
629 | + | |
630 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
631 | + | |
632 | + | int ns = snap_->atomData.skippedCharge.size(); |
633 | + | vector<RealType> skch_tmp(ns, 0.0); |
634 | + | |
635 | + | AtomCommRealRow->scatter(atomRowData.skippedCharge, skch_tmp); |
636 | + | for (int i = 0; i < ns; i++) { |
637 | + | snap_->atomData.skippedCharge[i] += skch_tmp[i]; |
638 | + | skch_tmp[i] = 0.0; |
639 | + | } |
640 | + | |
641 | + | AtomCommRealColumn->scatter(atomColData.skippedCharge, skch_tmp); |
642 | + | for (int i = 0; i < ns; i++) |
643 | + | snap_->atomData.skippedCharge[i] += skch_tmp[i]; |
644 | + | } |
645 | ||
646 | nLocal_ = snap_->getNumberOfAtoms(); | |
647 | ||
# | Line 425 | Line 653 | namespace OpenMD { | |
653 | AtomCommPotRow->scatter(pot_row, pot_temp); | |
654 | ||
655 | for (int ii = 0; ii < pot_temp.size(); ii++ ) | |
656 | < | pot_local += pot_temp[ii]; |
656 | > | pairwisePot += pot_temp[ii]; |
657 | ||
658 | fill(pot_temp.begin(), pot_temp.end(), | |
659 | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); | |
# | Line 433 | Line 661 | namespace OpenMD { | |
661 | AtomCommPotColumn->scatter(pot_col, pot_temp); | |
662 | ||
663 | for (int ii = 0; ii < pot_temp.size(); ii++ ) | |
664 | < | pot_local += pot_temp[ii]; |
437 | < | |
664 | > | pairwisePot += pot_temp[ii]; |
665 | #endif | |
666 | + | |
667 | } | |
668 | ||
669 | int ForceMatrixDecomposition::getNAtomsInRow() { | |
# | Line 510 | Line 738 | namespace OpenMD { | |
738 | #ifdef IS_MPI | |
739 | return massFactorsRow[atom1]; | |
740 | #else | |
741 | < | return massFactorsLocal[atom1]; |
741 | > | return massFactors[atom1]; |
742 | #endif | |
743 | } | |
744 | ||
# | Line 518 | Line 746 | namespace OpenMD { | |
746 | #ifdef IS_MPI | |
747 | return massFactorsCol[atom2]; | |
748 | #else | |
749 | < | return massFactorsLocal[atom2]; |
749 | > | return massFactors[atom2]; |
750 | #endif | |
751 | ||
752 | } | |
# | Line 536 | Line 764 | namespace OpenMD { | |
764 | return d; | |
765 | } | |
766 | ||
767 | < | vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) { |
768 | < | #ifdef IS_MPI |
541 | < | return skipsForRowAtom[atom1]; |
542 | < | #else |
543 | < | return skipsForLocalAtom[atom1]; |
544 | < | #endif |
767 | > | vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) { |
768 | > | return excludesForAtom[atom1]; |
769 | } | |
770 | ||
771 | /** | |
772 | < | * There are a number of reasons to skip a pair or a |
549 | < | * particle. Mostly we do this to exclude atoms who are involved in |
550 | < | * short range interactions (bonds, bends, torsions), but we also |
551 | < | * need to exclude some overcounted interactions that result from |
772 | > | * We need to exclude some overcounted interactions that result from |
773 | * the parallel decomposition. | |
774 | */ | |
775 | bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { | |
# | Line 568 | Line 789 | namespace OpenMD { | |
789 | } else { | |
790 | if ((unique_id_1 + unique_id_2) % 2 == 1) return true; | |
791 | } | |
792 | + | #endif |
793 | + | return false; |
794 | + | } |
795 | + | |
796 | + | /** |
797 | + | * We need to handle the interactions for atoms who are involved in |
798 | + | * the same rigid body as well as some short range interactions |
799 | + | * (bonds, bends, torsions) differently from other interactions. |
800 | + | * We'll still visit the pairwise routines, but with a flag that |
801 | + | * tells those routines to exclude the pair from direct long range |
802 | + | * interactions. Some indirect interactions (notably reaction |
803 | + | * field) must still be handled for these pairs. |
804 | + | */ |
805 | + | bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) { |
806 | + | int unique_id_2; |
807 | + | |
808 | + | #ifdef IS_MPI |
809 | + | // in MPI, we have to look up the unique IDs for the row atom. |
810 | + | unique_id_2 = AtomColToGlobal[atom2]; |
811 | #else | |
812 | // in the normal loop, the atom numbers are unique | |
573 | – | unique_id_1 = atom1; |
813 | unique_id_2 = atom2; | |
814 | #endif | |
815 | ||
816 | < | #ifdef IS_MPI |
817 | < | for (vector<int>::iterator i = skipsForRowAtom[atom1].begin(); |
579 | < | i != skipsForRowAtom[atom1].end(); ++i) { |
816 | > | for (vector<int>::iterator i = excludesForAtom[atom1].begin(); |
817 | > | i != excludesForAtom[atom1].end(); ++i) { |
818 | if ( (*i) == unique_id_2 ) return true; | |
581 | – | } |
582 | – | #else |
583 | – | for (vector<int>::iterator i = skipsForLocalAtom[atom1].begin(); |
584 | – | i != skipsForLocalAtom[atom1].end(); ++i) { |
585 | – | if ( (*i) == unique_id_2 ) return true; |
586 | – | } |
587 | – | #endif |
588 | – | } |
589 | – | |
590 | – | int ForceMatrixDecomposition::getTopoDistance(int atom1, int atom2) { |
591 | – | |
592 | – | #ifdef IS_MPI |
593 | – | for (int i = 0; i < toposForRowAtom[atom1].size(); i++) { |
594 | – | if ( toposForRowAtom[atom1][i] == atom2 ) return topoDistRow[atom1][i]; |
819 | } | |
596 | – | #else |
597 | – | for (int i = 0; i < toposForLocalAtom[atom1].size(); i++) { |
598 | – | if ( toposForLocalAtom[atom1][i] == atom2 ) return topoDistLocal[atom1][i]; |
599 | – | } |
600 | – | #endif |
820 | ||
821 | < | // zero is default for unconnected (i.e. normal) pair interactions |
603 | < | return 0; |
821 | > | return false; |
822 | } | |
823 | ||
824 | + | |
825 | void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ | |
826 | #ifdef IS_MPI | |
827 | atomRowData.force[atom1] += fg; | |
# | Line 620 | Line 839 | namespace OpenMD { | |
839 | } | |
840 | ||
841 | // filling interaction blocks with pointers | |
842 | < | InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) { |
843 | < | InteractionData idat; |
842 | > | void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat, |
843 | > | int atom1, int atom2) { |
844 | ||
845 | + | idat.excluded = excludeAtomPair(atom1, atom2); |
846 | + | |
847 | #ifdef IS_MPI | |
848 | + | idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]); |
849 | + | //idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
850 | + | // ff_->getAtomType(identsCol[atom2]) ); |
851 | ||
628 | – | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
629 | – | ff_->getAtomType(identsCol[atom2]) ); |
630 | – | |
631 | – | |
852 | if (storageLayout_ & DataStorage::dslAmat) { | |
853 | idat.A1 = &(atomRowData.aMat[atom1]); | |
854 | idat.A2 = &(atomColData.aMat[atom2]); | |
# | Line 664 | Line 884 | namespace OpenMD { | |
884 | idat.particlePot2 = &(atomColData.particlePot[atom2]); | |
885 | } | |
886 | ||
887 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
888 | + | idat.skippedCharge1 = &(atomRowData.skippedCharge[atom1]); |
889 | + | idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]); |
890 | + | } |
891 | + | |
892 | #else | |
893 | ||
894 | < | idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
895 | < | ff_->getAtomType(identsLocal[atom2]) ); |
894 | > | idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]); |
895 | > | //idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), |
896 | > | // ff_->getAtomType(idents[atom2]) ); |
897 | ||
898 | if (storageLayout_ & DataStorage::dslAmat) { | |
899 | idat.A1 = &(snap_->atomData.aMat[atom1]); | |
# | Line 684 | Line 910 | namespace OpenMD { | |
910 | idat.t2 = &(snap_->atomData.torque[atom2]); | |
911 | } | |
912 | ||
913 | < | if (storageLayout_ & DataStorage::dslDensity) { |
913 | > | if (storageLayout_ & DataStorage::dslDensity) { |
914 | idat.rho1 = &(snap_->atomData.density[atom1]); | |
915 | idat.rho2 = &(snap_->atomData.density[atom2]); | |
916 | } | |
# | Line 704 | Line 930 | namespace OpenMD { | |
930 | idat.particlePot2 = &(snap_->atomData.particlePot[atom2]); | |
931 | } | |
932 | ||
933 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
934 | + | idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]); |
935 | + | idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]); |
936 | + | } |
937 | #endif | |
708 | – | return idat; |
938 | } | |
939 | ||
940 | ||
941 | < | void ForceMatrixDecomposition::unpackInteractionData(InteractionData idat, int atom1, int atom2) { |
941 | > | void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) { |
942 | #ifdef IS_MPI | |
943 | pot_row[atom1] += 0.5 * *(idat.pot); | |
944 | pot_col[atom2] += 0.5 * *(idat.pot); | |
# | Line 717 | Line 946 | namespace OpenMD { | |
946 | atomRowData.force[atom1] += *(idat.f1); | |
947 | atomColData.force[atom2] -= *(idat.f1); | |
948 | #else | |
949 | < | longRangePot_ += *(idat.pot); |
950 | < | |
949 | > | pairwisePot += *(idat.pot); |
950 | > | |
951 | snap_->atomData.force[atom1] += *(idat.f1); | |
952 | snap_->atomData.force[atom2] -= *(idat.f1); | |
953 | #endif | |
954 | < | |
726 | < | } |
727 | < | |
728 | < | |
729 | < | InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){ |
730 | < | |
731 | < | InteractionData idat; |
732 | < | #ifdef IS_MPI |
733 | < | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
734 | < | ff_->getAtomType(identsCol[atom2]) ); |
735 | < | |
736 | < | if (storageLayout_ & DataStorage::dslElectroFrame) { |
737 | < | idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
738 | < | idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
739 | < | } |
740 | < | if (storageLayout_ & DataStorage::dslTorque) { |
741 | < | idat.t1 = &(atomRowData.torque[atom1]); |
742 | < | idat.t2 = &(atomColData.torque[atom2]); |
743 | < | } |
744 | < | #else |
745 | < | idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
746 | < | ff_->getAtomType(identsLocal[atom2]) ); |
747 | < | |
748 | < | if (storageLayout_ & DataStorage::dslElectroFrame) { |
749 | < | idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
750 | < | idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
751 | < | } |
752 | < | if (storageLayout_ & DataStorage::dslTorque) { |
753 | < | idat.t1 = &(snap_->atomData.torque[atom1]); |
754 | < | idat.t2 = &(snap_->atomData.torque[atom2]); |
755 | < | } |
756 | < | #endif |
954 | > | |
955 | } | |
956 | ||
957 | /* | |
# | Line 765 | Line 963 | namespace OpenMD { | |
963 | vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { | |
964 | ||
965 | vector<pair<int, int> > neighborList; | |
966 | + | groupCutoffs cuts; |
967 | + | bool doAllPairs = false; |
968 | + | |
969 | #ifdef IS_MPI | |
970 | cellListRow_.clear(); | |
971 | cellListCol_.clear(); | |
# | Line 772 | Line 973 | namespace OpenMD { | |
973 | cellList_.clear(); | |
974 | #endif | |
975 | ||
976 | < | // dangerous to not do error checking. |
776 | < | RealType rCut_; |
777 | < | |
778 | < | RealType rList_ = (rCut_ + skinThickness_); |
976 | > | RealType rList_ = (largestRcut_ + skinThickness_); |
977 | RealType rl2 = rList_ * rList_; | |
978 | Snapshot* snap_ = sman_->getCurrentSnapshot(); | |
979 | Mat3x3d Hmat = snap_->getHmat(); | |
# | Line 787 | Line 985 | namespace OpenMD { | |
985 | nCells_.y() = (int) ( Hy.length() )/ rList_; | |
986 | nCells_.z() = (int) ( Hz.length() )/ rList_; | |
987 | ||
988 | + | // handle small boxes where the cell offsets can end up repeating cells |
989 | + | |
990 | + | if (nCells_.x() < 3) doAllPairs = true; |
991 | + | if (nCells_.y() < 3) doAllPairs = true; |
992 | + | if (nCells_.z() < 3) doAllPairs = true; |
993 | + | |
994 | Mat3x3d invHmat = snap_->getInvHmat(); | |
995 | Vector3d rs, scaled, dr; | |
996 | Vector3i whichCell; | |
997 | int cellIndex; | |
998 | + | int nCtot = nCells_.x() * nCells_.y() * nCells_.z(); |
999 | ||
1000 | #ifdef IS_MPI | |
1001 | < | for (int i = 0; i < nGroupsInRow_; i++) { |
1002 | < | rs = cgRowData.position[i]; |
798 | < | // scaled positions relative to the box vectors |
799 | < | scaled = invHmat * rs; |
800 | < | // wrap the vector back into the unit box by subtracting integer box |
801 | < | // numbers |
802 | < | for (int j = 0; j < 3; j++) |
803 | < | scaled[j] -= roundMe(scaled[j]); |
804 | < | |
805 | < | // find xyz-indices of cell that cutoffGroup is in. |
806 | < | whichCell.x() = nCells_.x() * scaled.x(); |
807 | < | whichCell.y() = nCells_.y() * scaled.y(); |
808 | < | whichCell.z() = nCells_.z() * scaled.z(); |
809 | < | |
810 | < | // find single index of this cell: |
811 | < | cellIndex = Vlinear(whichCell, nCells_); |
812 | < | // add this cutoff group to the list of groups in this cell; |
813 | < | cellListRow_[cellIndex].push_back(i); |
814 | < | } |
815 | < | |
816 | < | for (int i = 0; i < nGroupsInCol_; i++) { |
817 | < | rs = cgColData.position[i]; |
818 | < | // scaled positions relative to the box vectors |
819 | < | scaled = invHmat * rs; |
820 | < | // wrap the vector back into the unit box by subtracting integer box |
821 | < | // numbers |
822 | < | for (int j = 0; j < 3; j++) |
823 | < | scaled[j] -= roundMe(scaled[j]); |
824 | < | |
825 | < | // find xyz-indices of cell that cutoffGroup is in. |
826 | < | whichCell.x() = nCells_.x() * scaled.x(); |
827 | < | whichCell.y() = nCells_.y() * scaled.y(); |
828 | < | whichCell.z() = nCells_.z() * scaled.z(); |
829 | < | |
830 | < | // find single index of this cell: |
831 | < | cellIndex = Vlinear(whichCell, nCells_); |
832 | < | // add this cutoff group to the list of groups in this cell; |
833 | < | cellListCol_[cellIndex].push_back(i); |
834 | < | } |
1001 | > | cellListRow_.resize(nCtot); |
1002 | > | cellListCol_.resize(nCtot); |
1003 | #else | |
1004 | < | for (int i = 0; i < nGroups_; i++) { |
837 | < | rs = snap_->cgData.position[i]; |
838 | < | // scaled positions relative to the box vectors |
839 | < | scaled = invHmat * rs; |
840 | < | // wrap the vector back into the unit box by subtracting integer box |
841 | < | // numbers |
842 | < | for (int j = 0; j < 3; j++) |
843 | < | scaled[j] -= roundMe(scaled[j]); |
844 | < | |
845 | < | // find xyz-indices of cell that cutoffGroup is in. |
846 | < | whichCell.x() = nCells_.x() * scaled.x(); |
847 | < | whichCell.y() = nCells_.y() * scaled.y(); |
848 | < | whichCell.z() = nCells_.z() * scaled.z(); |
849 | < | |
850 | < | // find single index of this cell: |
851 | < | cellIndex = Vlinear(whichCell, nCells_); |
852 | < | // add this cutoff group to the list of groups in this cell; |
853 | < | cellList_[cellIndex].push_back(i); |
854 | < | } |
1004 | > | cellList_.resize(nCtot); |
1005 | #endif | |
1006 | ||
1007 | < | for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
1008 | < | for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
859 | < | for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
860 | < | Vector3i m1v(m1x, m1y, m1z); |
861 | < | int m1 = Vlinear(m1v, nCells_); |
1007 | > | if (!doAllPairs) { |
1008 | > | #ifdef IS_MPI |
1009 | ||
1010 | < | for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
1011 | < | os != cellOffsets_.end(); ++os) { |
1012 | < | |
1013 | < | Vector3i m2v = m1v + (*os); |
1014 | < | |
1015 | < | if (m2v.x() >= nCells_.x()) { |
1016 | < | m2v.x() = 0; |
1017 | < | } else if (m2v.x() < 0) { |
1018 | < | m2v.x() = nCells_.x() - 1; |
1019 | < | } |
1020 | < | |
1021 | < | if (m2v.y() >= nCells_.y()) { |
1022 | < | m2v.y() = 0; |
1023 | < | } else if (m2v.y() < 0) { |
1024 | < | m2v.y() = nCells_.y() - 1; |
1025 | < | } |
1026 | < | |
1027 | < | if (m2v.z() >= nCells_.z()) { |
1028 | < | m2v.z() = 0; |
1029 | < | } else if (m2v.z() < 0) { |
1030 | < | m2v.z() = nCells_.z() - 1; |
1031 | < | } |
1032 | < | |
1033 | < | int m2 = Vlinear (m2v, nCells_); |
1010 | > | for (int i = 0; i < nGroupsInRow_; i++) { |
1011 | > | rs = cgRowData.position[i]; |
1012 | > | |
1013 | > | // scaled positions relative to the box vectors |
1014 | > | scaled = invHmat * rs; |
1015 | > | |
1016 | > | // wrap the vector back into the unit box by subtracting integer box |
1017 | > | // numbers |
1018 | > | for (int j = 0; j < 3; j++) { |
1019 | > | scaled[j] -= roundMe(scaled[j]); |
1020 | > | scaled[j] += 0.5; |
1021 | > | } |
1022 | > | |
1023 | > | // find xyz-indices of cell that cutoffGroup is in. |
1024 | > | whichCell.x() = nCells_.x() * scaled.x(); |
1025 | > | whichCell.y() = nCells_.y() * scaled.y(); |
1026 | > | whichCell.z() = nCells_.z() * scaled.z(); |
1027 | > | |
1028 | > | // find single index of this cell: |
1029 | > | cellIndex = Vlinear(whichCell, nCells_); |
1030 | > | |
1031 | > | // add this cutoff group to the list of groups in this cell; |
1032 | > | cellListRow_[cellIndex].push_back(i); |
1033 | > | } |
1034 | > | |
1035 | > | for (int i = 0; i < nGroupsInCol_; i++) { |
1036 | > | rs = cgColData.position[i]; |
1037 | > | |
1038 | > | // scaled positions relative to the box vectors |
1039 | > | scaled = invHmat * rs; |
1040 | > | |
1041 | > | // wrap the vector back into the unit box by subtracting integer box |
1042 | > | // numbers |
1043 | > | for (int j = 0; j < 3; j++) { |
1044 | > | scaled[j] -= roundMe(scaled[j]); |
1045 | > | scaled[j] += 0.5; |
1046 | > | } |
1047 | > | |
1048 | > | // find xyz-indices of cell that cutoffGroup is in. |
1049 | > | whichCell.x() = nCells_.x() * scaled.x(); |
1050 | > | whichCell.y() = nCells_.y() * scaled.y(); |
1051 | > | whichCell.z() = nCells_.z() * scaled.z(); |
1052 | > | |
1053 | > | // find single index of this cell: |
1054 | > | cellIndex = Vlinear(whichCell, nCells_); |
1055 | > | |
1056 | > | // add this cutoff group to the list of groups in this cell; |
1057 | > | cellListCol_[cellIndex].push_back(i); |
1058 | > | } |
1059 | > | #else |
1060 | > | for (int i = 0; i < nGroups_; i++) { |
1061 | > | rs = snap_->cgData.position[i]; |
1062 | > | |
1063 | > | // scaled positions relative to the box vectors |
1064 | > | scaled = invHmat * rs; |
1065 | > | |
1066 | > | // wrap the vector back into the unit box by subtracting integer box |
1067 | > | // numbers |
1068 | > | for (int j = 0; j < 3; j++) { |
1069 | > | scaled[j] -= roundMe(scaled[j]); |
1070 | > | scaled[j] += 0.5; |
1071 | > | } |
1072 | > | |
1073 | > | // find xyz-indices of cell that cutoffGroup is in. |
1074 | > | whichCell.x() = nCells_.x() * scaled.x(); |
1075 | > | whichCell.y() = nCells_.y() * scaled.y(); |
1076 | > | whichCell.z() = nCells_.z() * scaled.z(); |
1077 | > | |
1078 | > | // find single index of this cell: |
1079 | > | cellIndex = Vlinear(whichCell, nCells_); |
1080 | > | |
1081 | > | // add this cutoff group to the list of groups in this cell; |
1082 | > | cellList_[cellIndex].push_back(i); |
1083 | > | } |
1084 | > | #endif |
1085 | ||
1086 | + | for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
1087 | + | for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
1088 | + | for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
1089 | + | Vector3i m1v(m1x, m1y, m1z); |
1090 | + | int m1 = Vlinear(m1v, nCells_); |
1091 | + | |
1092 | + | for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
1093 | + | os != cellOffsets_.end(); ++os) { |
1094 | + | |
1095 | + | Vector3i m2v = m1v + (*os); |
1096 | + | |
1097 | + | if (m2v.x() >= nCells_.x()) { |
1098 | + | m2v.x() = 0; |
1099 | + | } else if (m2v.x() < 0) { |
1100 | + | m2v.x() = nCells_.x() - 1; |
1101 | + | } |
1102 | + | |
1103 | + | if (m2v.y() >= nCells_.y()) { |
1104 | + | m2v.y() = 0; |
1105 | + | } else if (m2v.y() < 0) { |
1106 | + | m2v.y() = nCells_.y() - 1; |
1107 | + | } |
1108 | + | |
1109 | + | if (m2v.z() >= nCells_.z()) { |
1110 | + | m2v.z() = 0; |
1111 | + | } else if (m2v.z() < 0) { |
1112 | + | m2v.z() = nCells_.z() - 1; |
1113 | + | } |
1114 | + | |
1115 | + | int m2 = Vlinear (m2v, nCells_); |
1116 | + | |
1117 | #ifdef IS_MPI | |
1118 | < | for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
1119 | < | j1 != cellListRow_[m1].end(); ++j1) { |
1120 | < | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
1121 | < | j2 != cellListCol_[m2].end(); ++j2) { |
1122 | < | |
1123 | < | // Always do this if we're in different cells or if |
1124 | < | // we're in the same cell and the global index of the |
1125 | < | // j2 cutoff group is less than the j1 cutoff group |
1126 | < | |
1127 | < | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
1128 | < | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
1129 | < | snap_->wrapVector(dr); |
1130 | < | if (dr.lengthSquare() < rl2) { |
1131 | < | neighborList.push_back(make_pair((*j1), (*j2))); |
1118 | > | for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
1119 | > | j1 != cellListRow_[m1].end(); ++j1) { |
1120 | > | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
1121 | > | j2 != cellListCol_[m2].end(); ++j2) { |
1122 | > | |
1123 | > | // Always do this if we're in different cells or if |
1124 | > | // we're in the same cell and the global index of the |
1125 | > | // j2 cutoff group is less than the j1 cutoff group |
1126 | > | |
1127 | > | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
1128 | > | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
1129 | > | snap_->wrapVector(dr); |
1130 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1131 | > | if (dr.lengthSquare() < cuts.third) { |
1132 | > | neighborList.push_back(make_pair((*j1), (*j2))); |
1133 | > | } |
1134 | } | |
1135 | } | |
1136 | } | |
906 | – | } |
1137 | #else | |
1138 | < | for (vector<int>::iterator j1 = cellList_[m1].begin(); |
1139 | < | j1 != cellList_[m1].end(); ++j1) { |
1140 | < | for (vector<int>::iterator j2 = cellList_[m2].begin(); |
1141 | < | j2 != cellList_[m2].end(); ++j2) { |
1142 | < | |
1143 | < | // Always do this if we're in different cells or if |
1144 | < | // we're in the same cell and the global index of the |
1145 | < | // j2 cutoff group is less than the j1 cutoff group |
1146 | < | |
1147 | < | if (m2 != m1 || (*j2) < (*j1)) { |
1148 | < | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
1149 | < | snap_->wrapVector(dr); |
1150 | < | if (dr.lengthSquare() < rl2) { |
1151 | < | neighborList.push_back(make_pair((*j1), (*j2))); |
1138 | > | |
1139 | > | for (vector<int>::iterator j1 = cellList_[m1].begin(); |
1140 | > | j1 != cellList_[m1].end(); ++j1) { |
1141 | > | for (vector<int>::iterator j2 = cellList_[m2].begin(); |
1142 | > | j2 != cellList_[m2].end(); ++j2) { |
1143 | > | |
1144 | > | // Always do this if we're in different cells or if |
1145 | > | // we're in the same cell and the global index of the |
1146 | > | // j2 cutoff group is less than the j1 cutoff group |
1147 | > | |
1148 | > | if (m2 != m1 || (*j2) < (*j1)) { |
1149 | > | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
1150 | > | snap_->wrapVector(dr); |
1151 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1152 | > | if (dr.lengthSquare() < cuts.third) { |
1153 | > | neighborList.push_back(make_pair((*j1), (*j2))); |
1154 | > | } |
1155 | } | |
1156 | } | |
1157 | } | |
925 | – | } |
1158 | #endif | |
1159 | + | } |
1160 | } | |
1161 | } | |
1162 | } | |
1163 | + | } else { |
1164 | + | // branch to do all cutoff group pairs |
1165 | + | #ifdef IS_MPI |
1166 | + | for (int j1 = 0; j1 < nGroupsInRow_; j1++) { |
1167 | + | for (int j2 = 0; j2 < nGroupsInCol_; j2++) { |
1168 | + | dr = cgColData.position[j2] - cgRowData.position[j1]; |
1169 | + | snap_->wrapVector(dr); |
1170 | + | cuts = getGroupCutoffs( j1, j2 ); |
1171 | + | if (dr.lengthSquare() < cuts.third) { |
1172 | + | neighborList.push_back(make_pair(j1, j2)); |
1173 | + | } |
1174 | + | } |
1175 | + | } |
1176 | + | #else |
1177 | + | for (int j1 = 0; j1 < nGroups_ - 1; j1++) { |
1178 | + | for (int j2 = j1 + 1; j2 < nGroups_; j2++) { |
1179 | + | dr = snap_->cgData.position[j2] - snap_->cgData.position[j1]; |
1180 | + | snap_->wrapVector(dr); |
1181 | + | cuts = getGroupCutoffs( j1, j2 ); |
1182 | + | if (dr.lengthSquare() < cuts.third) { |
1183 | + | neighborList.push_back(make_pair(j1, j2)); |
1184 | + | } |
1185 | + | } |
1186 | + | } |
1187 | + | #endif |
1188 | } | |
1189 | < | |
1189 | > | |
1190 | // save the local cutoff group positions for the check that is | |
1191 | // done on each loop: | |
1192 | saved_CG_positions_.clear(); | |
1193 | for (int i = 0; i < nGroups_; i++) | |
1194 | saved_CG_positions_.push_back(snap_->cgData.position[i]); | |
1195 | < | |
1195 | > | |
1196 | return neighborList; | |
1197 | } | |
1198 | } //end namespace OpenMD |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |