# | 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 | > | idents = info_->getIdentArray(); |
65 | AtomLocalToGlobal = info_->getGlobalAtomIndices(); | |
66 | cgLocalToGlobal = info_->getGlobalGroupIndices(); | |
67 | vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); | |
68 | < | vector<RealType> massFactorsLocal = info_->getMassFactors(); |
68 | > | massFactors = info_->getMassFactors(); |
69 | PairList excludes = info_->getExcludedInteractions(); | |
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 | ||
111 | < | vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES, |
112 | < | vector<RealType> (nAtomsInRow_, 0.0)); |
107 | < | vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES, |
108 | < | vector<RealType> (nAtomsInCol_, 0.0)); |
111 | > | AtomCommIntRow->gather(idents, identsRow); |
112 | > | AtomCommIntColumn->gather(idents, identsCol); |
113 | ||
110 | – | identsRow.reserve(nAtomsInRow_); |
111 | – | identsCol.reserve(nAtomsInCol_); |
112 | – | |
113 | – | AtomCommIntRow->gather(identsLocal, identsRow); |
114 | – | AtomCommIntColumn->gather(identsLocal, identsCol); |
115 | – | |
114 | AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); | |
115 | AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); | |
116 | ||
117 | cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); | |
118 | cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); | |
119 | ||
120 | < | AtomCommRealRow->gather(massFactorsLocal, massFactorsRow); |
121 | < | AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol); |
120 | > | AtomCommRealRow->gather(massFactors, massFactorsRow); |
121 | > | AtomCommRealColumn->gather(massFactors, 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 | > | atid = (*at)->getIdent(); |
239 | > | |
240 | > | if (userChoseCutoff_) |
241 | > | atypeCutoff[atid] = userCutoff_; |
242 | > | else |
243 | > | atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at); |
244 | > | } |
245 | > | |
246 | > | vector<RealType> gTypeCutoffs; |
247 | > | |
248 | > | // first we do a single loop over the cutoff groups to find the |
249 | > | // largest cutoff for any atypes present in this group. |
250 | > | #ifdef IS_MPI |
251 | > | vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0); |
252 | > | groupRowToGtype.resize(nGroupsInRow_); |
253 | > | for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) { |
254 | > | vector<int> atomListRow = getAtomsInGroupRow(cg1); |
255 | > | for (vector<int>::iterator ia = atomListRow.begin(); |
256 | > | ia != atomListRow.end(); ++ia) { |
257 | > | int atom1 = (*ia); |
258 | > | atid = identsRow[atom1]; |
259 | > | if (atypeCutoff[atid] > groupCutoffRow[cg1]) { |
260 | > | groupCutoffRow[cg1] = atypeCutoff[atid]; |
261 | } | |
262 | + | } |
263 | + | |
264 | + | bool gTypeFound = false; |
265 | + | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
266 | + | if (abs(groupCutoffRow[cg1] - gTypeCutoffs[gt]) < tol) { |
267 | + | groupRowToGtype[cg1] = gt; |
268 | + | gTypeFound = true; |
269 | + | } |
270 | + | } |
271 | + | if (!gTypeFound) { |
272 | + | gTypeCutoffs.push_back( groupCutoffRow[cg1] ); |
273 | + | groupRowToGtype[cg1] = gTypeCutoffs.size() - 1; |
274 | + | } |
275 | + | |
276 | + | } |
277 | + | vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0); |
278 | + | groupColToGtype.resize(nGroupsInCol_); |
279 | + | for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) { |
280 | + | vector<int> atomListCol = getAtomsInGroupColumn(cg2); |
281 | + | for (vector<int>::iterator jb = atomListCol.begin(); |
282 | + | jb != atomListCol.end(); ++jb) { |
283 | + | int atom2 = (*jb); |
284 | + | atid = identsCol[atom2]; |
285 | + | if (atypeCutoff[atid] > groupCutoffCol[cg2]) { |
286 | + | groupCutoffCol[cg2] = atypeCutoff[atid]; |
287 | + | } |
288 | + | } |
289 | + | bool gTypeFound = false; |
290 | + | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
291 | + | if (abs(groupCutoffCol[cg2] - gTypeCutoffs[gt]) < tol) { |
292 | + | groupColToGtype[cg2] = gt; |
293 | + | gTypeFound = true; |
294 | + | } |
295 | + | } |
296 | + | if (!gTypeFound) { |
297 | + | gTypeCutoffs.push_back( groupCutoffCol[cg2] ); |
298 | + | groupColToGtype[cg2] = gTypeCutoffs.size() - 1; |
299 | + | } |
300 | + | } |
301 | + | #else |
302 | + | |
303 | + | vector<RealType> groupCutoff(nGroups_, 0.0); |
304 | + | groupToGtype.resize(nGroups_); |
305 | + | |
306 | + | cerr << "nGroups = " << nGroups_ << "\n"; |
307 | + | for (int cg1 = 0; cg1 < nGroups_; cg1++) { |
308 | + | |
309 | + | groupCutoff[cg1] = 0.0; |
310 | + | vector<int> atomList = getAtomsInGroupRow(cg1); |
311 | + | |
312 | + | for (vector<int>::iterator ia = atomList.begin(); |
313 | + | ia != atomList.end(); ++ia) { |
314 | + | int atom1 = (*ia); |
315 | + | atid = idents[atom1]; |
316 | + | if (atypeCutoff[atid] > groupCutoff[cg1]) { |
317 | + | groupCutoff[cg1] = atypeCutoff[atid]; |
318 | + | } |
319 | + | } |
320 | + | |
321 | + | bool gTypeFound = false; |
322 | + | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
323 | + | if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) { |
324 | + | groupToGtype[cg1] = gt; |
325 | + | gTypeFound = true; |
326 | + | } |
327 | + | } |
328 | + | if (!gTypeFound) { |
329 | + | gTypeCutoffs.push_back( groupCutoff[cg1] ); |
330 | + | groupToGtype[cg1] = gTypeCutoffs.size() - 1; |
331 | } | |
332 | } | |
333 | + | #endif |
334 | + | |
335 | + | cerr << "gTypeCutoffs.size() = " << gTypeCutoffs.size() << "\n"; |
336 | + | // Now we find the maximum group cutoff value present in the simulation |
337 | + | |
338 | + | RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end()); |
339 | + | |
340 | + | #ifdef IS_MPI |
341 | + | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX); |
342 | + | #endif |
343 | + | |
344 | + | RealType tradRcut = groupMax; |
345 | + | |
346 | + | for (int i = 0; i < gTypeCutoffs.size(); i++) { |
347 | + | for (int j = 0; j < gTypeCutoffs.size(); j++) { |
348 | + | RealType thisRcut; |
349 | + | switch(cutoffPolicy_) { |
350 | + | case TRADITIONAL: |
351 | + | thisRcut = tradRcut; |
352 | + | break; |
353 | + | case MIX: |
354 | + | thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]); |
355 | + | break; |
356 | + | case MAX: |
357 | + | thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]); |
358 | + | break; |
359 | + | default: |
360 | + | sprintf(painCave.errMsg, |
361 | + | "ForceMatrixDecomposition::createGtypeCutoffMap " |
362 | + | "hit an unknown cutoff policy!\n"); |
363 | + | painCave.severity = OPENMD_ERROR; |
364 | + | painCave.isFatal = 1; |
365 | + | simError(); |
366 | + | break; |
367 | + | } |
368 | + | |
369 | + | pair<int,int> key = make_pair(i,j); |
370 | + | gTypeCutoffMap[key].first = thisRcut; |
371 | + | |
372 | + | if (thisRcut > largestRcut_) largestRcut_ = thisRcut; |
373 | + | |
374 | + | gTypeCutoffMap[key].second = thisRcut*thisRcut; |
375 | + | |
376 | + | gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2); |
377 | + | |
378 | + | // sanity check |
379 | + | |
380 | + | if (userChoseCutoff_) { |
381 | + | if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) { |
382 | + | sprintf(painCave.errMsg, |
383 | + | "ForceMatrixDecomposition::createGtypeCutoffMap " |
384 | + | "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_); |
385 | + | painCave.severity = OPENMD_ERROR; |
386 | + | painCave.isFatal = 1; |
387 | + | simError(); |
388 | + | } |
389 | + | } |
390 | + | } |
391 | + | } |
392 | } | |
393 | < | |
393 | > | |
394 | > | |
395 | > | groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) { |
396 | > | int i, j; |
397 | > | #ifdef IS_MPI |
398 | > | i = groupRowToGtype[cg1]; |
399 | > | j = groupColToGtype[cg2]; |
400 | > | #else |
401 | > | i = groupToGtype[cg1]; |
402 | > | j = groupToGtype[cg2]; |
403 | > | #endif |
404 | > | return gTypeCutoffMap[make_pair(i,j)]; |
405 | > | } |
406 | > | |
407 | > | int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) { |
408 | > | for (int j = 0; j < toposForAtom[atom1].size(); j++) { |
409 | > | if (toposForAtom[atom1][j] == atom2) |
410 | > | return topoDist[atom1][j]; |
411 | > | } |
412 | > | return 0; |
413 | > | } |
414 | > | |
415 | > | void ForceMatrixDecomposition::zeroWorkArrays() { |
416 | > | pairwisePot = 0.0; |
417 | > | embeddingPot = 0.0; |
418 | > | |
419 | > | #ifdef IS_MPI |
420 | > | if (storageLayout_ & DataStorage::dslForce) { |
421 | > | fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero); |
422 | > | fill(atomColData.force.begin(), atomColData.force.end(), V3Zero); |
423 | > | } |
424 | > | |
425 | > | if (storageLayout_ & DataStorage::dslTorque) { |
426 | > | fill(atomRowData.torque.begin(), atomRowData.torque.end(), V3Zero); |
427 | > | fill(atomColData.torque.begin(), atomColData.torque.end(), V3Zero); |
428 | > | } |
429 | > | |
430 | > | fill(pot_row.begin(), pot_row.end(), |
431 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
432 | > | |
433 | > | fill(pot_col.begin(), pot_col.end(), |
434 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
435 | > | |
436 | > | if (storageLayout_ & DataStorage::dslParticlePot) { |
437 | > | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); |
438 | > | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0); |
439 | > | } |
440 | > | |
441 | > | if (storageLayout_ & DataStorage::dslDensity) { |
442 | > | fill(atomRowData.density.begin(), atomRowData.density.end(), 0.0); |
443 | > | fill(atomColData.density.begin(), atomColData.density.end(), 0.0); |
444 | > | } |
445 | > | |
446 | > | if (storageLayout_ & DataStorage::dslFunctional) { |
447 | > | fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0); |
448 | > | fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0); |
449 | > | } |
450 | > | |
451 | > | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
452 | > | fill(atomRowData.functionalDerivative.begin(), |
453 | > | atomRowData.functionalDerivative.end(), 0.0); |
454 | > | fill(atomColData.functionalDerivative.begin(), |
455 | > | atomColData.functionalDerivative.end(), 0.0); |
456 | > | } |
457 | > | |
458 | > | #else |
459 | > | |
460 | > | if (storageLayout_ & DataStorage::dslParticlePot) { |
461 | > | fill(snap_->atomData.particlePot.begin(), |
462 | > | snap_->atomData.particlePot.end(), 0.0); |
463 | > | } |
464 | > | |
465 | > | if (storageLayout_ & DataStorage::dslDensity) { |
466 | > | fill(snap_->atomData.density.begin(), |
467 | > | snap_->atomData.density.end(), 0.0); |
468 | > | } |
469 | > | if (storageLayout_ & DataStorage::dslFunctional) { |
470 | > | fill(snap_->atomData.functional.begin(), |
471 | > | snap_->atomData.functional.end(), 0.0); |
472 | > | } |
473 | > | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
474 | > | fill(snap_->atomData.functionalDerivative.begin(), |
475 | > | snap_->atomData.functionalDerivative.end(), 0.0); |
476 | > | } |
477 | > | #endif |
478 | > | |
479 | > | } |
480 | > | |
481 | > | |
482 | void ForceMatrixDecomposition::distributeData() { | |
483 | snap_ = sman_->getCurrentSnapshot(); | |
484 | storageLayout_ = sman_->getStorageLayout(); | |
# | Line 266 | Line 514 | namespace OpenMD { | |
514 | #endif | |
515 | } | |
516 | ||
517 | + | /* collects information obtained during the pre-pair loop onto local |
518 | + | * data structures. |
519 | + | */ |
520 | void ForceMatrixDecomposition::collectIntermediateData() { | |
521 | snap_ = sman_->getCurrentSnapshot(); | |
522 | storageLayout_ = sman_->getStorageLayout(); | |
# | Line 277 | Line 528 | namespace OpenMD { | |
528 | snap_->atomData.density); | |
529 | ||
530 | int n = snap_->atomData.density.size(); | |
531 | < | std::vector<RealType> rho_tmp(n, 0.0); |
531 | > | vector<RealType> rho_tmp(n, 0.0); |
532 | AtomCommRealColumn->scatter(atomColData.density, rho_tmp); | |
533 | for (int i = 0; i < n; i++) | |
534 | snap_->atomData.density[i] += rho_tmp[i]; | |
535 | } | |
536 | #endif | |
537 | } | |
538 | < | |
538 | > | |
539 | > | /* |
540 | > | * redistributes information obtained during the pre-pair loop out to |
541 | > | * row and column-indexed data structures |
542 | > | */ |
543 | void ForceMatrixDecomposition::distributeIntermediateData() { | |
544 | snap_ = sman_->getCurrentSnapshot(); | |
545 | storageLayout_ = sman_->getStorageLayout(); | |
# | Line 342 | Line 597 | namespace OpenMD { | |
597 | ||
598 | nLocal_ = snap_->getNumberOfAtoms(); | |
599 | ||
600 | < | vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES, |
601 | < | vector<RealType> (nLocal_, 0.0)); |
600 | > | vector<potVec> pot_temp(nLocal_, |
601 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
602 | > | |
603 | > | // scatter/gather pot_row into the members of my column |
604 | > | |
605 | > | AtomCommPotRow->scatter(pot_row, pot_temp); |
606 | > | |
607 | > | for (int ii = 0; ii < pot_temp.size(); ii++ ) |
608 | > | pairwisePot += pot_temp[ii]; |
609 | ||
610 | < | for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { |
611 | < | AtomCommRealRow->scatter(pot_row[i], pot_temp[i]); |
612 | < | for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { |
613 | < | pot_local[i] += pot_temp[i][ii]; |
614 | < | } |
615 | < | } |
610 | > | fill(pot_temp.begin(), pot_temp.end(), |
611 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
612 | > | |
613 | > | AtomCommPotColumn->scatter(pot_col, pot_temp); |
614 | > | |
615 | > | for (int ii = 0; ii < pot_temp.size(); ii++ ) |
616 | > | pairwisePot += pot_temp[ii]; |
617 | #endif | |
618 | + | |
619 | } | |
620 | ||
621 | int ForceMatrixDecomposition::getNAtomsInRow() { | |
# | Line 426 | Line 690 | namespace OpenMD { | |
690 | #ifdef IS_MPI | |
691 | return massFactorsRow[atom1]; | |
692 | #else | |
693 | < | return massFactorsLocal[atom1]; |
693 | > | return massFactors[atom1]; |
694 | #endif | |
695 | } | |
696 | ||
# | Line 434 | Line 698 | namespace OpenMD { | |
698 | #ifdef IS_MPI | |
699 | return massFactorsCol[atom2]; | |
700 | #else | |
701 | < | return massFactorsLocal[atom2]; |
701 | > | return massFactors[atom2]; |
702 | #endif | |
703 | ||
704 | } | |
# | Line 452 | Line 716 | namespace OpenMD { | |
716 | return d; | |
717 | } | |
718 | ||
719 | < | vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) { |
720 | < | #ifdef IS_MPI |
457 | < | return skipsForRowAtom[atom1]; |
458 | < | #else |
459 | < | return skipsForLocalAtom[atom1]; |
460 | < | #endif |
719 | > | vector<int> ForceMatrixDecomposition::getSkipsForAtom(int atom1) { |
720 | > | return skipsForAtom[atom1]; |
721 | } | |
722 | ||
723 | /** | |
724 | < | * there are a number of reasons to skip a pair or a particle mostly |
725 | < | * we do this to exclude atoms who are involved in short range |
726 | < | * interactions (bonds, bends, torsions), but we also need to |
727 | < | * exclude some overcounted interactions that result from the |
728 | < | * parallel decomposition. |
724 | > | * There are a number of reasons to skip a pair or a |
725 | > | * particle. Mostly we do this to exclude atoms who are involved in |
726 | > | * short range interactions (bonds, bends, torsions), but we also |
727 | > | * need to exclude some overcounted interactions that result from |
728 | > | * the parallel decomposition. |
729 | */ | |
730 | bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { | |
731 | int unique_id_1, unique_id_2; | |
# | Line 490 | Line 750 | namespace OpenMD { | |
750 | unique_id_2 = atom2; | |
751 | #endif | |
752 | ||
753 | < | #ifdef IS_MPI |
754 | < | for (vector<int>::iterator i = skipsForRowAtom[atom1].begin(); |
495 | < | i != skipsForRowAtom[atom1].end(); ++i) { |
753 | > | for (vector<int>::iterator i = skipsForAtom[atom1].begin(); |
754 | > | i != skipsForAtom[atom1].end(); ++i) { |
755 | if ( (*i) == unique_id_2 ) return true; | |
497 | – | } |
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 | – | } |
505 | – | |
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]; |
756 | } | |
757 | < | #else |
758 | < | 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; |
757 | > | |
758 | > | return false; |
759 | } | |
760 | ||
761 | + | |
762 | void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ | |
763 | #ifdef IS_MPI | |
764 | atomRowData.force[atom1] += fg; | |
# | Line 536 | Line 776 | namespace OpenMD { | |
776 | } | |
777 | ||
778 | // filling interaction blocks with pointers | |
779 | < | InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) { |
780 | < | InteractionData idat; |
541 | < | |
779 | > | void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat, |
780 | > | int atom1, int atom2) { |
781 | #ifdef IS_MPI | |
782 | + | |
783 | + | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
784 | + | ff_->getAtomType(identsCol[atom2]) ); |
785 | + | |
786 | if (storageLayout_ & DataStorage::dslAmat) { | |
787 | idat.A1 = &(atomRowData.aMat[atom1]); | |
788 | idat.A2 = &(atomColData.aMat[atom2]); | |
# | Line 560 | Line 803 | namespace OpenMD { | |
803 | idat.rho2 = &(atomColData.density[atom2]); | |
804 | } | |
805 | ||
806 | + | if (storageLayout_ & DataStorage::dslFunctional) { |
807 | + | idat.frho1 = &(atomRowData.functional[atom1]); |
808 | + | idat.frho2 = &(atomColData.functional[atom2]); |
809 | + | } |
810 | + | |
811 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
812 | idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]); | |
813 | idat.dfrho2 = &(atomColData.functionalDerivative[atom2]); | |
814 | } | |
815 | ||
816 | + | if (storageLayout_ & DataStorage::dslParticlePot) { |
817 | + | idat.particlePot1 = &(atomRowData.particlePot[atom1]); |
818 | + | idat.particlePot2 = &(atomColData.particlePot[atom2]); |
819 | + | } |
820 | + | |
821 | #else | |
822 | + | |
823 | + | idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), |
824 | + | ff_->getAtomType(idents[atom2]) ); |
825 | + | |
826 | if (storageLayout_ & DataStorage::dslAmat) { | |
827 | idat.A1 = &(snap_->atomData.aMat[atom1]); | |
828 | idat.A2 = &(snap_->atomData.aMat[atom2]); | |
# | Line 581 | Line 838 | namespace OpenMD { | |
838 | idat.t2 = &(snap_->atomData.torque[atom2]); | |
839 | } | |
840 | ||
841 | < | if (storageLayout_ & DataStorage::dslDensity) { |
841 | > | if (storageLayout_ & DataStorage::dslDensity) { |
842 | idat.rho1 = &(snap_->atomData.density[atom1]); | |
843 | idat.rho2 = &(snap_->atomData.density[atom2]); | |
844 | } | |
845 | ||
846 | + | if (storageLayout_ & DataStorage::dslFunctional) { |
847 | + | idat.frho1 = &(snap_->atomData.functional[atom1]); |
848 | + | idat.frho2 = &(snap_->atomData.functional[atom2]); |
849 | + | } |
850 | + | |
851 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
852 | idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]); | |
853 | idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]); | |
854 | } | |
855 | + | |
856 | + | if (storageLayout_ & DataStorage::dslParticlePot) { |
857 | + | idat.particlePot1 = &(snap_->atomData.particlePot[atom1]); |
858 | + | idat.particlePot2 = &(snap_->atomData.particlePot[atom2]); |
859 | + | } |
860 | + | |
861 | #endif | |
594 | – | return idat; |
862 | } | |
863 | ||
864 | < | InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){ |
864 | > | |
865 | > | void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) { |
866 | > | #ifdef IS_MPI |
867 | > | pot_row[atom1] += 0.5 * *(idat.pot); |
868 | > | pot_col[atom2] += 0.5 * *(idat.pot); |
869 | ||
870 | < | InteractionData idat; |
870 | > | atomRowData.force[atom1] += *(idat.f1); |
871 | > | atomColData.force[atom2] -= *(idat.f1); |
872 | > | #else |
873 | > | pairwisePot += *(idat.pot); |
874 | > | |
875 | > | snap_->atomData.force[atom1] += *(idat.f1); |
876 | > | snap_->atomData.force[atom2] -= *(idat.f1); |
877 | > | #endif |
878 | > | |
879 | > | } |
880 | > | |
881 | > | |
882 | > | void ForceMatrixDecomposition::fillSkipData(InteractionData &idat, |
883 | > | int atom1, int atom2) { |
884 | > | // Still Missing:: skippedCharge fill must be added to DataStorage |
885 | #ifdef IS_MPI | |
886 | + | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
887 | + | ff_->getAtomType(identsCol[atom2]) ); |
888 | + | |
889 | if (storageLayout_ & DataStorage::dslElectroFrame) { | |
890 | idat.eFrame1 = &(atomRowData.electroFrame[atom1]); | |
891 | idat.eFrame2 = &(atomColData.electroFrame[atom2]); | |
# | Line 606 | Line 894 | namespace OpenMD { | |
894 | idat.t1 = &(atomRowData.torque[atom1]); | |
895 | idat.t2 = &(atomColData.torque[atom2]); | |
896 | } | |
609 | – | if (storageLayout_ & DataStorage::dslForce) { |
610 | – | idat.t1 = &(atomRowData.force[atom1]); |
611 | – | idat.t2 = &(atomColData.force[atom2]); |
612 | – | } |
897 | #else | |
898 | + | idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), |
899 | + | ff_->getAtomType(idents[atom2]) ); |
900 | + | |
901 | if (storageLayout_ & DataStorage::dslElectroFrame) { | |
902 | idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); | |
903 | idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); | |
# | Line 619 | Line 906 | namespace OpenMD { | |
906 | idat.t1 = &(snap_->atomData.torque[atom1]); | |
907 | idat.t2 = &(snap_->atomData.torque[atom2]); | |
908 | } | |
909 | < | if (storageLayout_ & DataStorage::dslForce) { |
623 | < | idat.t1 = &(snap_->atomData.force[atom1]); |
624 | < | idat.t2 = &(snap_->atomData.force[atom2]); |
625 | < | } |
626 | < | #endif |
627 | < | |
909 | > | #endif |
910 | } | |
911 | ||
912 | ||
913 | + | void ForceMatrixDecomposition::unpackSkipData(InteractionData &idat, int atom1, int atom2) { |
914 | + | #ifdef IS_MPI |
915 | + | pot_row[atom1] += 0.5 * *(idat.pot); |
916 | + | pot_col[atom2] += 0.5 * *(idat.pot); |
917 | + | #else |
918 | + | pairwisePot += *(idat.pot); |
919 | + | #endif |
920 | ||
921 | + | } |
922 | ||
923 | + | |
924 | /* | |
925 | * buildNeighborList | |
926 | * | |
# | Line 639 | Line 930 | namespace OpenMD { | |
930 | vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { | |
931 | ||
932 | vector<pair<int, int> > neighborList; | |
933 | + | groupCutoffs cuts; |
934 | #ifdef IS_MPI | |
935 | cellListRow_.clear(); | |
936 | cellListCol_.clear(); | |
# | Line 646 | Line 938 | namespace OpenMD { | |
938 | cellList_.clear(); | |
939 | #endif | |
940 | ||
941 | < | // dangerous to not do error checking. |
650 | < | RealType rCut_; |
651 | < | |
652 | < | RealType rList_ = (rCut_ + skinThickness_); |
941 | > | RealType rList_ = (largestRcut_ + skinThickness_); |
942 | RealType rl2 = rList_ * rList_; | |
943 | Snapshot* snap_ = sman_->getCurrentSnapshot(); | |
944 | Mat3x3d Hmat = snap_->getHmat(); | |
# | Line 665 | Line 954 | namespace OpenMD { | |
954 | Vector3d rs, scaled, dr; | |
955 | Vector3i whichCell; | |
956 | int cellIndex; | |
957 | + | int nCtot = nCells_.x() * nCells_.y() * nCells_.z(); |
958 | ||
959 | #ifdef IS_MPI | |
960 | + | cellListRow_.resize(nCtot); |
961 | + | cellListCol_.resize(nCtot); |
962 | + | #else |
963 | + | cellList_.resize(nCtot); |
964 | + | #endif |
965 | + | |
966 | + | #ifdef IS_MPI |
967 | for (int i = 0; i < nGroupsInRow_; i++) { | |
968 | rs = cgRowData.position[i]; | |
969 | + | |
970 | // scaled positions relative to the box vectors | |
971 | scaled = invHmat * rs; | |
972 | + | |
973 | // wrap the vector back into the unit box by subtracting integer box | |
974 | // numbers | |
975 | < | for (int j = 0; j < 3; j++) |
975 | > | for (int j = 0; j < 3; j++) { |
976 | scaled[j] -= roundMe(scaled[j]); | |
977 | + | scaled[j] += 0.5; |
978 | + | } |
979 | ||
980 | // find xyz-indices of cell that cutoffGroup is in. | |
981 | whichCell.x() = nCells_.x() * scaled.x(); | |
# | Line 683 | Line 984 | namespace OpenMD { | |
984 | ||
985 | // find single index of this cell: | |
986 | cellIndex = Vlinear(whichCell, nCells_); | |
987 | + | |
988 | // add this cutoff group to the list of groups in this cell; | |
989 | cellListRow_[cellIndex].push_back(i); | |
990 | } | |
991 | ||
992 | for (int i = 0; i < nGroupsInCol_; i++) { | |
993 | rs = cgColData.position[i]; | |
994 | + | |
995 | // scaled positions relative to the box vectors | |
996 | scaled = invHmat * rs; | |
997 | + | |
998 | // wrap the vector back into the unit box by subtracting integer box | |
999 | // numbers | |
1000 | < | for (int j = 0; j < 3; j++) |
1000 | > | for (int j = 0; j < 3; j++) { |
1001 | scaled[j] -= roundMe(scaled[j]); | |
1002 | + | scaled[j] += 0.5; |
1003 | + | } |
1004 | ||
1005 | // find xyz-indices of cell that cutoffGroup is in. | |
1006 | whichCell.x() = nCells_.x() * scaled.x(); | |
# | Line 703 | Line 1009 | namespace OpenMD { | |
1009 | ||
1010 | // find single index of this cell: | |
1011 | cellIndex = Vlinear(whichCell, nCells_); | |
1012 | + | |
1013 | // add this cutoff group to the list of groups in this cell; | |
1014 | cellListCol_[cellIndex].push_back(i); | |
1015 | } | |
1016 | #else | |
1017 | for (int i = 0; i < nGroups_; i++) { | |
1018 | rs = snap_->cgData.position[i]; | |
1019 | + | |
1020 | // scaled positions relative to the box vectors | |
1021 | scaled = invHmat * rs; | |
1022 | + | |
1023 | // wrap the vector back into the unit box by subtracting integer box | |
1024 | // numbers | |
1025 | < | for (int j = 0; j < 3; j++) |
1025 | > | for (int j = 0; j < 3; j++) { |
1026 | scaled[j] -= roundMe(scaled[j]); | |
1027 | + | scaled[j] += 0.5; |
1028 | + | } |
1029 | ||
1030 | // find xyz-indices of cell that cutoffGroup is in. | |
1031 | whichCell.x() = nCells_.x() * scaled.x(); | |
# | Line 722 | Line 1033 | namespace OpenMD { | |
1033 | whichCell.z() = nCells_.z() * scaled.z(); | |
1034 | ||
1035 | // find single index of this cell: | |
1036 | < | cellIndex = Vlinear(whichCell, nCells_); |
1036 | > | cellIndex = Vlinear(whichCell, nCells_); |
1037 | > | |
1038 | // add this cutoff group to the list of groups in this cell; | |
1039 | cellList_[cellIndex].push_back(i); | |
1040 | } | |
1041 | #endif | |
1042 | ||
731 | – | |
732 | – | |
1043 | for (int m1z = 0; m1z < nCells_.z(); m1z++) { | |
1044 | for (int m1y = 0; m1y < nCells_.y(); m1y++) { | |
1045 | for (int m1x = 0; m1x < nCells_.x(); m1x++) { | |
# | Line 774 | Line 1084 | namespace OpenMD { | |
1084 | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { | |
1085 | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; | |
1086 | snap_->wrapVector(dr); | |
1087 | < | if (dr.lengthSquare() < rl2) { |
1087 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1088 | > | if (dr.lengthSquare() < cuts.third) { |
1089 | neighborList.push_back(make_pair((*j1), (*j2))); | |
1090 | } | |
1091 | } | |
1092 | } | |
1093 | } | |
1094 | #else | |
1095 | + | |
1096 | for (vector<int>::iterator j1 = cellList_[m1].begin(); | |
1097 | j1 != cellList_[m1].end(); ++j1) { | |
1098 | for (vector<int>::iterator j2 = cellList_[m2].begin(); | |
1099 | j2 != cellList_[m2].end(); ++j2) { | |
1100 | < | |
1100 | > | |
1101 | // Always do this if we're in different cells or if | |
1102 | // we're in the same cell and the global index of the | |
1103 | // j2 cutoff group is less than the j1 cutoff group | |
# | Line 793 | Line 1105 | namespace OpenMD { | |
1105 | if (m2 != m1 || (*j2) < (*j1)) { | |
1106 | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; | |
1107 | snap_->wrapVector(dr); | |
1108 | < | if (dr.lengthSquare() < rl2) { |
1108 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1109 | > | if (dr.lengthSquare() < cuts.third) { |
1110 | neighborList.push_back(make_pair((*j1), (*j2))); | |
1111 | } | |
1112 | } | |
# | Line 804 | Line 1117 | namespace OpenMD { | |
1117 | } | |
1118 | } | |
1119 | } | |
1120 | < | |
1120 | > | |
1121 | // save the local cutoff group positions for the check that is | |
1122 | // done on each loop: | |
1123 | saved_CG_positions_.clear(); | |
1124 | for (int i = 0; i < nGroups_; i++) | |
1125 | saved_CG_positions_.push_back(snap_->cgData.position[i]); | |
1126 | < | |
1126 | > | |
1127 | return neighborList; | |
1128 | } | |
1129 | } //end namespace OpenMD |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |