# | Line 55 | Line 55 | namespace OpenMD { | |
---|---|---|
55 | void ForceMatrixDecomposition::distributeInitialData() { | |
56 | snap_ = sman_->getCurrentSnapshot(); | |
57 | storageLayout_ = sman_->getStorageLayout(); | |
58 | + | ff_ = info_->getForceField(); |
59 | nLocal_ = snap_->getNumberOfAtoms(); | |
59 | – | nGroups_ = snap_->getNumberOfCutoffGroups(); |
60 | ||
61 | + | nGroups_ = info_->getNLocalCutoffGroups(); |
62 | + | cerr << "in dId, nGroups = " << nGroups_ << "\n"; |
63 | // gather the information for atomtype IDs (atids): | |
64 | < | vector<int> identsLocal = info_->getIdentArray(); |
64 | > | identsLocal = info_->getIdentArray(); |
65 | AtomLocalToGlobal = info_->getGlobalAtomIndices(); | |
66 | cgLocalToGlobal = info_->getGlobalGroupIndices(); | |
67 | vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); | |
# | Line 68 | Line 70 | namespace OpenMD { | |
70 | PairList oneTwo = info_->getOneTwoInteractions(); | |
71 | PairList oneThree = info_->getOneThreeInteractions(); | |
72 | PairList oneFour = info_->getOneFourInteractions(); | |
71 | – | vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0); |
73 | ||
74 | #ifdef IS_MPI | |
75 | ||
# | Line 76 | Line 77 | namespace OpenMD { | |
77 | AtomCommRealRow = new Communicator<Row,RealType>(nLocal_); | |
78 | AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_); | |
79 | AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_); | |
80 | + | AtomCommPotRow = new Communicator<Row,potVec>(nLocal_); |
81 | ||
82 | AtomCommIntColumn = new Communicator<Column,int>(nLocal_); | |
83 | AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_); | |
84 | AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_); | |
85 | AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_); | |
86 | + | AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_); |
87 | ||
88 | cgCommIntRow = new Communicator<Row,int>(nGroups_); | |
89 | cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_); | |
# | Line 101 | Line 104 | namespace OpenMD { | |
104 | cgRowData.setStorageLayout(DataStorage::dslPosition); | |
105 | cgColData.resize(nGroupsInCol_); | |
106 | cgColData.setStorageLayout(DataStorage::dslPosition); | |
107 | + | |
108 | + | identsRow.resize(nAtomsInRow_); |
109 | + | identsCol.resize(nAtomsInCol_); |
110 | ||
105 | – | vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES, |
106 | – | vector<RealType> (nAtomsInRow_, 0.0)); |
107 | – | vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES, |
108 | – | vector<RealType> (nAtomsInCol_, 0.0)); |
109 | – | |
110 | – | identsRow.reserve(nAtomsInRow_); |
111 | – | identsCol.reserve(nAtomsInCol_); |
112 | – | |
111 | AtomCommIntRow->gather(identsLocal, identsRow); | |
112 | AtomCommIntColumn->gather(identsLocal, identsCol); | |
113 | ||
# | Line 123 | Line 121 | namespace OpenMD { | |
121 | AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol); | |
122 | ||
123 | groupListRow_.clear(); | |
124 | < | groupListRow_.reserve(nGroupsInRow_); |
124 | > | groupListRow_.resize(nGroupsInRow_); |
125 | for (int i = 0; i < nGroupsInRow_; i++) { | |
126 | int gid = cgRowToGlobal[i]; | |
127 | for (int j = 0; j < nAtomsInRow_; j++) { | |
# | Line 134 | Line 132 | namespace OpenMD { | |
132 | } | |
133 | ||
134 | groupListCol_.clear(); | |
135 | < | groupListCol_.reserve(nGroupsInCol_); |
135 | > | groupListCol_.resize(nGroupsInCol_); |
136 | for (int i = 0; i < nGroupsInCol_; i++) { | |
137 | int gid = cgColToGlobal[i]; | |
138 | for (int j = 0; j < nAtomsInCol_; j++) { | |
# | Line 144 | Line 142 | namespace OpenMD { | |
142 | } | |
143 | } | |
144 | ||
145 | < | skipsForRowAtom.clear(); |
146 | < | skipsForRowAtom.reserve(nAtomsInRow_); |
145 | > | skipsForAtom.clear(); |
146 | > | skipsForAtom.resize(nAtomsInRow_); |
147 | > | toposForAtom.clear(); |
148 | > | toposForAtom.resize(nAtomsInRow_); |
149 | > | topoDist.clear(); |
150 | > | topoDist.resize(nAtomsInRow_); |
151 | for (int i = 0; i < nAtomsInRow_; i++) { | |
152 | < | int iglob = AtomColToGlobal[i]; |
151 | < | for (int j = 0; j < nAtomsInCol_; j++) { |
152 | < | int jglob = AtomRowToGlobal[j]; |
153 | < | if (excludes.hasPair(iglob, jglob)) |
154 | < | skipsForRowAtom[i].push_back(j); |
155 | < | } |
156 | < | } |
152 | > | int iglob = AtomRowToGlobal[i]; |
153 | ||
158 | – | toposForRowAtom.clear(); |
159 | – | toposForRowAtom.reserve(nAtomsInRow_); |
160 | – | for (int i = 0; i < nAtomsInRow_; i++) { |
161 | – | int iglob = AtomColToGlobal[i]; |
162 | – | int nTopos = 0; |
154 | for (int j = 0; j < nAtomsInCol_; j++) { | |
155 | < | int jglob = AtomRowToGlobal[j]; |
155 | > | int jglob = AtomColToGlobal[j]; |
156 | > | |
157 | > | if (excludes.hasPair(iglob, jglob)) |
158 | > | skipsForAtom[i].push_back(j); |
159 | > | |
160 | if (oneTwo.hasPair(iglob, jglob)) { | |
161 | < | toposForRowAtom[i].push_back(j); |
162 | < | topoDistRow[i][nTopos] = 1; |
163 | < | nTopos++; |
161 | > | toposForAtom[i].push_back(j); |
162 | > | topoDist[i].push_back(1); |
163 | > | } else { |
164 | > | if (oneThree.hasPair(iglob, jglob)) { |
165 | > | toposForAtom[i].push_back(j); |
166 | > | topoDist[i].push_back(2); |
167 | > | } else { |
168 | > | if (oneFour.hasPair(iglob, jglob)) { |
169 | > | toposForAtom[i].push_back(j); |
170 | > | topoDist[i].push_back(3); |
171 | > | } |
172 | > | } |
173 | } | |
170 | – | if (oneThree.hasPair(iglob, jglob)) { |
171 | – | toposForRowAtom[i].push_back(j); |
172 | – | topoDistRow[i][nTopos] = 2; |
173 | – | nTopos++; |
174 | – | } |
175 | – | if (oneFour.hasPair(iglob, jglob)) { |
176 | – | toposForRowAtom[i].push_back(j); |
177 | – | topoDistRow[i][nTopos] = 3; |
178 | – | nTopos++; |
179 | – | } |
174 | } | |
175 | } | |
176 | ||
177 | #endif | |
178 | ||
179 | groupList_.clear(); | |
180 | < | groupList_.reserve(nGroups_); |
180 | > | groupList_.resize(nGroups_); |
181 | for (int i = 0; i < nGroups_; i++) { | |
182 | int gid = cgLocalToGlobal[i]; | |
183 | for (int j = 0; j < nLocal_; j++) { | |
184 | int aid = AtomLocalToGlobal[j]; | |
185 | < | if (globalGroupMembership[aid] == gid) |
185 | > | if (globalGroupMembership[aid] == gid) { |
186 | groupList_[i].push_back(j); | |
187 | + | } |
188 | } | |
189 | } | |
190 | ||
191 | < | skipsForLocalAtom.clear(); |
192 | < | skipsForLocalAtom.reserve(nLocal_); |
191 | > | skipsForAtom.clear(); |
192 | > | skipsForAtom.resize(nLocal_); |
193 | > | toposForAtom.clear(); |
194 | > | toposForAtom.resize(nLocal_); |
195 | > | topoDist.clear(); |
196 | > | topoDist.resize(nLocal_); |
197 | ||
198 | for (int i = 0; i < nLocal_; i++) { | |
199 | int iglob = AtomLocalToGlobal[i]; | |
200 | + | |
201 | for (int j = 0; j < nLocal_; j++) { | |
202 | < | int jglob = AtomLocalToGlobal[j]; |
202 | > | int jglob = AtomLocalToGlobal[j]; |
203 | > | |
204 | if (excludes.hasPair(iglob, jglob)) | |
205 | < | skipsForLocalAtom[i].push_back(j); |
205 | > | skipsForAtom[i].push_back(j); |
206 | > | |
207 | > | if (oneTwo.hasPair(iglob, jglob)) { |
208 | > | toposForAtom[i].push_back(j); |
209 | > | topoDist[i].push_back(1); |
210 | > | } else { |
211 | > | if (oneThree.hasPair(iglob, jglob)) { |
212 | > | toposForAtom[i].push_back(j); |
213 | > | topoDist[i].push_back(2); |
214 | > | } else { |
215 | > | if (oneFour.hasPair(iglob, jglob)) { |
216 | > | toposForAtom[i].push_back(j); |
217 | > | topoDist[i].push_back(3); |
218 | > | } |
219 | > | } |
220 | > | } |
221 | } | |
222 | } | |
223 | + | |
224 | + | createGtypeCutoffMap(); |
225 | + | } |
226 | + | |
227 | + | void ForceMatrixDecomposition::createGtypeCutoffMap() { |
228 | ||
229 | < | toposForLocalAtom.clear(); |
230 | < | toposForLocalAtom.reserve(nLocal_); |
231 | < | for (int i = 0; i < nLocal_; i++) { |
232 | < | int iglob = AtomLocalToGlobal[i]; |
233 | < | int nTopos = 0; |
234 | < | for (int j = 0; j < nLocal_; j++) { |
235 | < | int jglob = AtomLocalToGlobal[j]; |
236 | < | if (oneTwo.hasPair(iglob, jglob)) { |
237 | < | toposForLocalAtom[i].push_back(j); |
238 | < | topoDistLocal[i][nTopos] = 1; |
239 | < | nTopos++; |
240 | < | } |
241 | < | if (oneThree.hasPair(iglob, jglob)) { |
242 | < | toposForLocalAtom[i].push_back(j); |
243 | < | topoDistLocal[i][nTopos] = 2; |
244 | < | nTopos++; |
245 | < | } |
246 | < | if (oneFour.hasPair(iglob, jglob)) { |
247 | < | toposForLocalAtom[i].push_back(j); |
248 | < | topoDistLocal[i][nTopos] = 3; |
249 | < | nTopos++; |
229 | > | RealType tol = 1e-6; |
230 | > | RealType rc; |
231 | > | int atid; |
232 | > | set<AtomType*> atypes = info_->getSimulatedAtomTypes(); |
233 | > | vector<RealType> atypeCutoff; |
234 | > | atypeCutoff.resize( atypes.size() ); |
235 | > | |
236 | > | for (set<AtomType*>::iterator at = atypes.begin(); |
237 | > | at != atypes.end(); ++at){ |
238 | > | rc = interactionMan_->getSuggestedCutoffRadius(*at); |
239 | > | atid = (*at)->getIdent(); |
240 | > | atypeCutoff[atid] = rc; |
241 | > | } |
242 | > | |
243 | > | vector<RealType> gTypeCutoffs; |
244 | > | |
245 | > | // first we do a single loop over the cutoff groups to find the |
246 | > | // largest cutoff for any atypes present in this group. |
247 | > | #ifdef IS_MPI |
248 | > | vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0); |
249 | > | groupRowToGtype.resize(nGroupsInRow_); |
250 | > | for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) { |
251 | > | vector<int> atomListRow = getAtomsInGroupRow(cg1); |
252 | > | for (vector<int>::iterator ia = atomListRow.begin(); |
253 | > | ia != atomListRow.end(); ++ia) { |
254 | > | int atom1 = (*ia); |
255 | > | atid = identsRow[atom1]; |
256 | > | if (atypeCutoff[atid] > groupCutoffRow[cg1]) { |
257 | > | groupCutoffRow[cg1] = atypeCutoff[atid]; |
258 | } | |
259 | + | } |
260 | + | |
261 | + | bool gTypeFound = false; |
262 | + | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
263 | + | if (abs(groupCutoffRow[cg1] - gTypeCutoffs[gt]) < tol) { |
264 | + | groupRowToGtype[cg1] = gt; |
265 | + | gTypeFound = true; |
266 | + | } |
267 | + | } |
268 | + | if (!gTypeFound) { |
269 | + | gTypeCutoffs.push_back( groupCutoffRow[cg1] ); |
270 | + | groupRowToGtype[cg1] = gTypeCutoffs.size() - 1; |
271 | + | } |
272 | + | |
273 | + | } |
274 | + | vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0); |
275 | + | groupColToGtype.resize(nGroupsInCol_); |
276 | + | for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) { |
277 | + | vector<int> atomListCol = getAtomsInGroupColumn(cg2); |
278 | + | for (vector<int>::iterator jb = atomListCol.begin(); |
279 | + | jb != atomListCol.end(); ++jb) { |
280 | + | int atom2 = (*jb); |
281 | + | atid = identsCol[atom2]; |
282 | + | if (atypeCutoff[atid] > groupCutoffCol[cg2]) { |
283 | + | groupCutoffCol[cg2] = atypeCutoff[atid]; |
284 | + | } |
285 | + | } |
286 | + | bool gTypeFound = false; |
287 | + | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
288 | + | if (abs(groupCutoffCol[cg2] - gTypeCutoffs[gt]) < tol) { |
289 | + | groupColToGtype[cg2] = gt; |
290 | + | gTypeFound = true; |
291 | + | } |
292 | + | } |
293 | + | if (!gTypeFound) { |
294 | + | gTypeCutoffs.push_back( groupCutoffCol[cg2] ); |
295 | + | groupColToGtype[cg2] = gTypeCutoffs.size() - 1; |
296 | + | } |
297 | + | } |
298 | + | #else |
299 | + | |
300 | + | vector<RealType> groupCutoff(nGroups_, 0.0); |
301 | + | groupToGtype.resize(nGroups_); |
302 | + | |
303 | + | cerr << "nGroups = " << nGroups_ << "\n"; |
304 | + | for (int cg1 = 0; cg1 < nGroups_; cg1++) { |
305 | + | |
306 | + | groupCutoff[cg1] = 0.0; |
307 | + | vector<int> atomList = getAtomsInGroupRow(cg1); |
308 | + | |
309 | + | for (vector<int>::iterator ia = atomList.begin(); |
310 | + | ia != atomList.end(); ++ia) { |
311 | + | int atom1 = (*ia); |
312 | + | atid = identsLocal[atom1]; |
313 | + | if (atypeCutoff[atid] > groupCutoff[cg1]) { |
314 | + | groupCutoff[cg1] = atypeCutoff[atid]; |
315 | + | } |
316 | + | } |
317 | + | |
318 | + | bool gTypeFound = false; |
319 | + | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
320 | + | if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) { |
321 | + | groupToGtype[cg1] = gt; |
322 | + | gTypeFound = true; |
323 | + | } |
324 | + | } |
325 | + | if (!gTypeFound) { |
326 | + | gTypeCutoffs.push_back( groupCutoff[cg1] ); |
327 | + | groupToGtype[cg1] = gTypeCutoffs.size() - 1; |
328 | } | |
329 | + | } |
330 | + | #endif |
331 | + | |
332 | + | cerr << "gTypeCutoffs.size() = " << gTypeCutoffs.size() << "\n"; |
333 | + | // Now we find the maximum group cutoff value present in the simulation |
334 | + | |
335 | + | RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end()); |
336 | + | |
337 | + | #ifdef IS_MPI |
338 | + | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX); |
339 | + | #endif |
340 | + | |
341 | + | RealType tradRcut = groupMax; |
342 | + | |
343 | + | for (int i = 0; i < gTypeCutoffs.size(); i++) { |
344 | + | for (int j = 0; j < gTypeCutoffs.size(); j++) { |
345 | + | RealType thisRcut; |
346 | + | switch(cutoffPolicy_) { |
347 | + | case TRADITIONAL: |
348 | + | thisRcut = tradRcut; |
349 | + | break; |
350 | + | case MIX: |
351 | + | thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]); |
352 | + | break; |
353 | + | case MAX: |
354 | + | thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]); |
355 | + | break; |
356 | + | default: |
357 | + | sprintf(painCave.errMsg, |
358 | + | "ForceMatrixDecomposition::createGtypeCutoffMap " |
359 | + | "hit an unknown cutoff policy!\n"); |
360 | + | painCave.severity = OPENMD_ERROR; |
361 | + | painCave.isFatal = 1; |
362 | + | simError(); |
363 | + | break; |
364 | + | } |
365 | + | |
366 | + | pair<int,int> key = make_pair(i,j); |
367 | + | gTypeCutoffMap[key].first = thisRcut; |
368 | + | |
369 | + | if (thisRcut > largestRcut_) largestRcut_ = thisRcut; |
370 | + | |
371 | + | gTypeCutoffMap[key].second = thisRcut*thisRcut; |
372 | + | |
373 | + | gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2); |
374 | + | |
375 | + | // sanity check |
376 | + | |
377 | + | if (userChoseCutoff_) { |
378 | + | if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) { |
379 | + | sprintf(painCave.errMsg, |
380 | + | "ForceMatrixDecomposition::createGtypeCutoffMap " |
381 | + | "user-specified rCut does not match computed group Cutoff\n"); |
382 | + | painCave.severity = OPENMD_ERROR; |
383 | + | painCave.isFatal = 1; |
384 | + | simError(); |
385 | + | } |
386 | + | } |
387 | + | } |
388 | } | |
389 | } | |
390 | < | |
390 | > | |
391 | > | |
392 | > | groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) { |
393 | > | int i, j; |
394 | > | #ifdef IS_MPI |
395 | > | i = groupRowToGtype[cg1]; |
396 | > | j = groupColToGtype[cg2]; |
397 | > | #else |
398 | > | i = groupToGtype[cg1]; |
399 | > | j = groupToGtype[cg2]; |
400 | > | #endif |
401 | > | return gTypeCutoffMap[make_pair(i,j)]; |
402 | > | } |
403 | > | |
404 | > | int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) { |
405 | > | for (int j = 0; j < toposForAtom[atom1].size(); j++) { |
406 | > | if (toposForAtom[atom1][j] == atom2) |
407 | > | return topoDist[atom1][j]; |
408 | > | } |
409 | > | return 0; |
410 | > | } |
411 | > | |
412 | > | void ForceMatrixDecomposition::zeroWorkArrays() { |
413 | > | |
414 | > | for (int j = 0; j < N_INTERACTION_FAMILIES; j++) { |
415 | > | longRangePot_[j] = 0.0; |
416 | > | } |
417 | > | |
418 | > | #ifdef IS_MPI |
419 | > | if (storageLayout_ & DataStorage::dslForce) { |
420 | > | fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero); |
421 | > | fill(atomColData.force.begin(), atomColData.force.end(), V3Zero); |
422 | > | } |
423 | > | |
424 | > | if (storageLayout_ & DataStorage::dslTorque) { |
425 | > | fill(atomRowData.torque.begin(), atomRowData.torque.end(), V3Zero); |
426 | > | fill(atomColData.torque.begin(), atomColData.torque.end(), V3Zero); |
427 | > | } |
428 | > | |
429 | > | fill(pot_row.begin(), pot_row.end(), |
430 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
431 | > | |
432 | > | fill(pot_col.begin(), pot_col.end(), |
433 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
434 | > | |
435 | > | pot_local = Vector<RealType, N_INTERACTION_FAMILIES>(0.0); |
436 | > | |
437 | > | if (storageLayout_ & DataStorage::dslParticlePot) { |
438 | > | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); |
439 | > | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0); |
440 | > | } |
441 | > | |
442 | > | if (storageLayout_ & DataStorage::dslDensity) { |
443 | > | fill(atomRowData.density.begin(), atomRowData.density.end(), 0.0); |
444 | > | fill(atomColData.density.begin(), atomColData.density.end(), 0.0); |
445 | > | } |
446 | > | |
447 | > | if (storageLayout_ & DataStorage::dslFunctional) { |
448 | > | fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0); |
449 | > | fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0); |
450 | > | } |
451 | > | |
452 | > | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
453 | > | fill(atomRowData.functionalDerivative.begin(), |
454 | > | atomRowData.functionalDerivative.end(), 0.0); |
455 | > | fill(atomColData.functionalDerivative.begin(), |
456 | > | atomColData.functionalDerivative.end(), 0.0); |
457 | > | } |
458 | > | |
459 | > | #else |
460 | > | |
461 | > | if (storageLayout_ & DataStorage::dslParticlePot) { |
462 | > | fill(snap_->atomData.particlePot.begin(), |
463 | > | snap_->atomData.particlePot.end(), 0.0); |
464 | > | } |
465 | > | |
466 | > | if (storageLayout_ & DataStorage::dslDensity) { |
467 | > | fill(snap_->atomData.density.begin(), |
468 | > | snap_->atomData.density.end(), 0.0); |
469 | > | } |
470 | > | if (storageLayout_ & DataStorage::dslFunctional) { |
471 | > | fill(snap_->atomData.functional.begin(), |
472 | > | snap_->atomData.functional.end(), 0.0); |
473 | > | } |
474 | > | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
475 | > | fill(snap_->atomData.functionalDerivative.begin(), |
476 | > | snap_->atomData.functionalDerivative.end(), 0.0); |
477 | > | } |
478 | > | #endif |
479 | > | |
480 | > | } |
481 | > | |
482 | > | |
483 | void ForceMatrixDecomposition::distributeData() { | |
484 | snap_ = sman_->getCurrentSnapshot(); | |
485 | storageLayout_ = sman_->getStorageLayout(); | |
# | Line 266 | Line 515 | namespace OpenMD { | |
515 | #endif | |
516 | } | |
517 | ||
518 | + | /* collects information obtained during the pre-pair loop onto local |
519 | + | * data structures. |
520 | + | */ |
521 | void ForceMatrixDecomposition::collectIntermediateData() { | |
522 | snap_ = sman_->getCurrentSnapshot(); | |
523 | storageLayout_ = sman_->getStorageLayout(); | |
# | Line 277 | Line 529 | namespace OpenMD { | |
529 | snap_->atomData.density); | |
530 | ||
531 | int n = snap_->atomData.density.size(); | |
532 | < | std::vector<RealType> rho_tmp(n, 0.0); |
532 | > | vector<RealType> rho_tmp(n, 0.0); |
533 | AtomCommRealColumn->scatter(atomColData.density, rho_tmp); | |
534 | for (int i = 0; i < n; i++) | |
535 | snap_->atomData.density[i] += rho_tmp[i]; | |
536 | } | |
537 | #endif | |
538 | } | |
539 | < | |
539 | > | |
540 | > | /* |
541 | > | * redistributes information obtained during the pre-pair loop out to |
542 | > | * row and column-indexed data structures |
543 | > | */ |
544 | void ForceMatrixDecomposition::distributeIntermediateData() { | |
545 | snap_ = sman_->getCurrentSnapshot(); | |
546 | storageLayout_ = sman_->getStorageLayout(); | |
# | Line 342 | Line 598 | namespace OpenMD { | |
598 | ||
599 | nLocal_ = snap_->getNumberOfAtoms(); | |
600 | ||
601 | < | vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES, |
602 | < | vector<RealType> (nLocal_, 0.0)); |
601 | > | vector<potVec> pot_temp(nLocal_, |
602 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
603 | > | |
604 | > | // scatter/gather pot_row into the members of my column |
605 | > | |
606 | > | AtomCommPotRow->scatter(pot_row, pot_temp); |
607 | > | |
608 | > | for (int ii = 0; ii < pot_temp.size(); ii++ ) |
609 | > | pot_local += pot_temp[ii]; |
610 | ||
611 | < | for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { |
612 | < | AtomCommRealRow->scatter(pot_row[i], pot_temp[i]); |
613 | < | for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { |
614 | < | pot_local[i] += pot_temp[i][ii]; |
615 | < | } |
616 | < | } |
611 | > | fill(pot_temp.begin(), pot_temp.end(), |
612 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
613 | > | |
614 | > | AtomCommPotColumn->scatter(pot_col, pot_temp); |
615 | > | |
616 | > | for (int ii = 0; ii < pot_temp.size(); ii++ ) |
617 | > | pot_local += pot_temp[ii]; |
618 | > | |
619 | #endif | |
620 | } | |
621 | ||
# | Line 452 | Line 717 | namespace OpenMD { | |
717 | return d; | |
718 | } | |
719 | ||
720 | < | vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) { |
721 | < | #ifdef IS_MPI |
457 | < | return skipsForRowAtom[atom1]; |
458 | < | #else |
459 | < | return skipsForLocalAtom[atom1]; |
460 | < | #endif |
720 | > | vector<int> ForceMatrixDecomposition::getSkipsForAtom(int atom1) { |
721 | > | return skipsForAtom[atom1]; |
722 | } | |
723 | ||
724 | /** | |
725 | < | * there are a number of reasons to skip a pair or a particle mostly |
726 | < | * we do this to exclude atoms who are involved in short range |
727 | < | * interactions (bonds, bends, torsions), but we also need to |
728 | < | * exclude some overcounted interactions that result from the |
729 | < | * parallel decomposition. |
725 | > | * There are a number of reasons to skip a pair or a |
726 | > | * particle. Mostly we do this to exclude atoms who are involved in |
727 | > | * short range interactions (bonds, bends, torsions), but we also |
728 | > | * need to exclude some overcounted interactions that result from |
729 | > | * the parallel decomposition. |
730 | */ | |
731 | bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { | |
732 | int unique_id_1, unique_id_2; | |
# | Line 490 | Line 751 | namespace OpenMD { | |
751 | unique_id_2 = atom2; | |
752 | #endif | |
753 | ||
754 | < | #ifdef IS_MPI |
755 | < | for (vector<int>::iterator i = skipsForRowAtom[atom1].begin(); |
495 | < | i != skipsForRowAtom[atom1].end(); ++i) { |
754 | > | for (vector<int>::iterator i = skipsForAtom[atom1].begin(); |
755 | > | i != skipsForAtom[atom1].end(); ++i) { |
756 | if ( (*i) == unique_id_2 ) return true; | |
757 | } | |
498 | – | #else |
499 | – | for (vector<int>::iterator i = skipsForLocalAtom[atom1].begin(); |
500 | – | i != skipsForLocalAtom[atom1].end(); ++i) { |
501 | – | if ( (*i) == unique_id_2 ) return true; |
502 | – | } |
503 | – | #endif |
504 | – | } |
758 | ||
506 | – | int ForceMatrixDecomposition::getTopoDistance(int atom1, int atom2) { |
507 | – | |
508 | – | #ifdef IS_MPI |
509 | – | for (int i = 0; i < toposForRowAtom[atom1].size(); i++) { |
510 | – | if ( toposForRowAtom[atom1][i] == atom2 ) return topoDistRow[atom1][i]; |
511 | – | } |
512 | – | #else |
513 | – | for (int i = 0; i < toposForLocalAtom[atom1].size(); i++) { |
514 | – | if ( toposForLocalAtom[atom1][i] == atom2 ) return topoDistLocal[atom1][i]; |
515 | – | } |
516 | – | #endif |
517 | – | |
518 | – | // zero is default for unconnected (i.e. normal) pair interactions |
519 | – | return 0; |
759 | } | |
760 | ||
761 | + | |
762 | void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ | |
763 | #ifdef IS_MPI | |
764 | atomRowData.force[atom1] += fg; | |
# | Line 540 | Line 780 | namespace OpenMD { | |
780 | InteractionData idat; | |
781 | ||
782 | #ifdef IS_MPI | |
783 | + | |
784 | + | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
785 | + | ff_->getAtomType(identsCol[atom2]) ); |
786 | + | |
787 | + | |
788 | if (storageLayout_ & DataStorage::dslAmat) { | |
789 | idat.A1 = &(atomRowData.aMat[atom1]); | |
790 | idat.A2 = &(atomColData.aMat[atom2]); | |
# | Line 560 | Line 805 | namespace OpenMD { | |
805 | idat.rho2 = &(atomColData.density[atom2]); | |
806 | } | |
807 | ||
808 | + | if (storageLayout_ & DataStorage::dslFunctional) { |
809 | + | idat.frho1 = &(atomRowData.functional[atom1]); |
810 | + | idat.frho2 = &(atomColData.functional[atom2]); |
811 | + | } |
812 | + | |
813 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
814 | idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]); | |
815 | idat.dfrho2 = &(atomColData.functionalDerivative[atom2]); | |
816 | } | |
817 | ||
818 | + | if (storageLayout_ & DataStorage::dslParticlePot) { |
819 | + | idat.particlePot1 = &(atomRowData.particlePot[atom1]); |
820 | + | idat.particlePot2 = &(atomColData.particlePot[atom2]); |
821 | + | } |
822 | + | |
823 | #else | |
824 | + | |
825 | + | idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
826 | + | ff_->getAtomType(identsLocal[atom2]) ); |
827 | + | |
828 | if (storageLayout_ & DataStorage::dslAmat) { | |
829 | idat.A1 = &(snap_->atomData.aMat[atom1]); | |
830 | idat.A2 = &(snap_->atomData.aMat[atom2]); | |
# | Line 586 | Line 845 | namespace OpenMD { | |
845 | idat.rho2 = &(snap_->atomData.density[atom2]); | |
846 | } | |
847 | ||
848 | + | if (storageLayout_ & DataStorage::dslFunctional) { |
849 | + | idat.frho1 = &(snap_->atomData.functional[atom1]); |
850 | + | idat.frho2 = &(snap_->atomData.functional[atom2]); |
851 | + | } |
852 | + | |
853 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
854 | idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]); | |
855 | idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]); | |
856 | } | |
857 | + | |
858 | + | if (storageLayout_ & DataStorage::dslParticlePot) { |
859 | + | idat.particlePot1 = &(snap_->atomData.particlePot[atom1]); |
860 | + | idat.particlePot2 = &(snap_->atomData.particlePot[atom2]); |
861 | + | } |
862 | + | |
863 | #endif | |
864 | return idat; | |
865 | } | |
866 | ||
867 | + | |
868 | + | void ForceMatrixDecomposition::unpackInteractionData(InteractionData idat, int atom1, int atom2) { |
869 | + | #ifdef IS_MPI |
870 | + | pot_row[atom1] += 0.5 * *(idat.pot); |
871 | + | pot_col[atom2] += 0.5 * *(idat.pot); |
872 | + | |
873 | + | atomRowData.force[atom1] += *(idat.f1); |
874 | + | atomColData.force[atom2] -= *(idat.f1); |
875 | + | #else |
876 | + | longRangePot_ += *(idat.pot); |
877 | + | |
878 | + | snap_->atomData.force[atom1] += *(idat.f1); |
879 | + | snap_->atomData.force[atom2] -= *(idat.f1); |
880 | + | #endif |
881 | + | |
882 | + | } |
883 | + | |
884 | + | |
885 | InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){ | |
886 | ||
887 | InteractionData idat; | |
888 | #ifdef IS_MPI | |
889 | + | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
890 | + | ff_->getAtomType(identsCol[atom2]) ); |
891 | + | |
892 | if (storageLayout_ & DataStorage::dslElectroFrame) { | |
893 | idat.eFrame1 = &(atomRowData.electroFrame[atom1]); | |
894 | idat.eFrame2 = &(atomColData.electroFrame[atom2]); | |
# | Line 606 | Line 897 | namespace OpenMD { | |
897 | idat.t1 = &(atomRowData.torque[atom1]); | |
898 | idat.t2 = &(atomColData.torque[atom2]); | |
899 | } | |
609 | – | if (storageLayout_ & DataStorage::dslForce) { |
610 | – | idat.t1 = &(atomRowData.force[atom1]); |
611 | – | idat.t2 = &(atomColData.force[atom2]); |
612 | – | } |
900 | #else | |
901 | + | idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
902 | + | ff_->getAtomType(identsLocal[atom2]) ); |
903 | + | |
904 | if (storageLayout_ & DataStorage::dslElectroFrame) { | |
905 | idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); | |
906 | idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); | |
# | Line 619 | Line 909 | namespace OpenMD { | |
909 | idat.t1 = &(snap_->atomData.torque[atom1]); | |
910 | idat.t2 = &(snap_->atomData.torque[atom2]); | |
911 | } | |
912 | < | if (storageLayout_ & DataStorage::dslForce) { |
623 | < | idat.t1 = &(snap_->atomData.force[atom1]); |
624 | < | idat.t2 = &(snap_->atomData.force[atom2]); |
625 | < | } |
626 | < | #endif |
627 | < | |
912 | > | #endif |
913 | } | |
914 | ||
630 | – | |
631 | – | |
632 | – | |
915 | /* | |
916 | * buildNeighborList | |
917 | * | |
# | Line 639 | Line 921 | namespace OpenMD { | |
921 | vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { | |
922 | ||
923 | vector<pair<int, int> > neighborList; | |
924 | + | groupCutoffs cuts; |
925 | #ifdef IS_MPI | |
926 | cellListRow_.clear(); | |
927 | cellListCol_.clear(); | |
# | Line 646 | Line 929 | namespace OpenMD { | |
929 | cellList_.clear(); | |
930 | #endif | |
931 | ||
932 | < | // dangerous to not do error checking. |
650 | < | RealType rCut_; |
651 | < | |
652 | < | RealType rList_ = (rCut_ + skinThickness_); |
932 | > | RealType rList_ = (largestRcut_ + skinThickness_); |
933 | RealType rl2 = rList_ * rList_; | |
934 | Snapshot* snap_ = sman_->getCurrentSnapshot(); | |
935 | Mat3x3d Hmat = snap_->getHmat(); | |
# | Line 665 | Line 945 | namespace OpenMD { | |
945 | Vector3d rs, scaled, dr; | |
946 | Vector3i whichCell; | |
947 | int cellIndex; | |
948 | + | int nCtot = nCells_.x() * nCells_.y() * nCells_.z(); |
949 | ||
950 | #ifdef IS_MPI | |
951 | + | cellListRow_.resize(nCtot); |
952 | + | cellListCol_.resize(nCtot); |
953 | + | #else |
954 | + | cellList_.resize(nCtot); |
955 | + | #endif |
956 | + | |
957 | + | #ifdef IS_MPI |
958 | for (int i = 0; i < nGroupsInRow_; i++) { | |
959 | rs = cgRowData.position[i]; | |
960 | // scaled positions relative to the box vectors | |
# | Line 728 | Line 1016 | namespace OpenMD { | |
1016 | } | |
1017 | #endif | |
1018 | ||
731 | – | |
732 | – | |
1019 | for (int m1z = 0; m1z < nCells_.z(); m1z++) { | |
1020 | for (int m1y = 0; m1y < nCells_.y(); m1y++) { | |
1021 | for (int m1x = 0; m1x < nCells_.x(); m1x++) { | |
# | Line 774 | Line 1060 | namespace OpenMD { | |
1060 | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { | |
1061 | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; | |
1062 | snap_->wrapVector(dr); | |
1063 | < | if (dr.lengthSquare() < rl2) { |
1063 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1064 | > | if (dr.lengthSquare() < cuts.third) { |
1065 | neighborList.push_back(make_pair((*j1), (*j2))); | |
1066 | } | |
1067 | } | |
# | Line 793 | Line 1080 | namespace OpenMD { | |
1080 | if (m2 != m1 || (*j2) < (*j1)) { | |
1081 | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; | |
1082 | snap_->wrapVector(dr); | |
1083 | < | if (dr.lengthSquare() < rl2) { |
1083 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1084 | > | if (dr.lengthSquare() < cuts.third) { |
1085 | neighborList.push_back(make_pair((*j1), (*j2))); | |
1086 | } | |
1087 | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |