# | Line 47 | Line 47 | namespace OpenMD { | |
---|---|---|
47 | using namespace std; | |
48 | namespace OpenMD { | |
49 | ||
50 | + | ForceMatrixDecomposition::ForceMatrixDecomposition(SimInfo* info, InteractionManager* iMan) : ForceDecomposition(info, iMan) { |
51 | + | |
52 | + | // In a parallel computation, row and colum scans must visit all |
53 | + | // surrounding cells (not just the 14 upper triangular blocks that |
54 | + | // are used when the processor can see all pairs) |
55 | + | #ifdef IS_MPI |
56 | + | cellOffsets_.push_back( Vector3i(-1, 0, 0) ); |
57 | + | cellOffsets_.push_back( Vector3i(-1,-1, 0) ); |
58 | + | cellOffsets_.push_back( Vector3i( 0,-1, 0) ); |
59 | + | cellOffsets_.push_back( Vector3i( 1,-1, 0) ); |
60 | + | cellOffsets_.push_back( Vector3i( 0, 0,-1) ); |
61 | + | cellOffsets_.push_back( Vector3i(-1, 0, 1) ); |
62 | + | cellOffsets_.push_back( Vector3i(-1,-1,-1) ); |
63 | + | cellOffsets_.push_back( Vector3i( 0,-1,-1) ); |
64 | + | cellOffsets_.push_back( Vector3i( 1,-1,-1) ); |
65 | + | cellOffsets_.push_back( Vector3i( 1, 0,-1) ); |
66 | + | cellOffsets_.push_back( Vector3i( 1, 1,-1) ); |
67 | + | cellOffsets_.push_back( Vector3i( 0, 1,-1) ); |
68 | + | cellOffsets_.push_back( Vector3i(-1, 1,-1) ); |
69 | + | #endif |
70 | + | } |
71 | + | |
72 | + | |
73 | /** | |
74 | * distributeInitialData is essentially a copy of the older fortran | |
75 | * SimulationSetup | |
76 | */ | |
54 | – | |
77 | void ForceMatrixDecomposition::distributeInitialData() { | |
78 | snap_ = sman_->getCurrentSnapshot(); | |
79 | storageLayout_ = sman_->getStorageLayout(); | |
80 | ff_ = info_->getForceField(); | |
81 | nLocal_ = snap_->getNumberOfAtoms(); | |
82 | < | |
82 | > | |
83 | nGroups_ = info_->getNLocalCutoffGroups(); | |
62 | – | cerr << "in dId, nGroups = " << nGroups_ << "\n"; |
84 | // gather the information for atomtype IDs (atids): | |
85 | < | identsLocal = info_->getIdentArray(); |
85 | > | idents = info_->getIdentArray(); |
86 | AtomLocalToGlobal = info_->getGlobalAtomIndices(); | |
87 | cgLocalToGlobal = info_->getGlobalGroupIndices(); | |
88 | vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); | |
68 | – | vector<RealType> massFactorsLocal = info_->getMassFactors(); |
69 | – | PairList excludes = info_->getExcludedInteractions(); |
70 | – | PairList oneTwo = info_->getOneTwoInteractions(); |
71 | – | PairList oneThree = info_->getOneThreeInteractions(); |
72 | – | PairList oneFour = info_->getOneFourInteractions(); |
89 | ||
90 | + | massFactors = info_->getMassFactors(); |
91 | + | |
92 | + | PairList* excludes = info_->getExcludedInteractions(); |
93 | + | PairList* oneTwo = info_->getOneTwoInteractions(); |
94 | + | PairList* oneThree = info_->getOneThreeInteractions(); |
95 | + | PairList* oneFour = info_->getOneFourInteractions(); |
96 | + | |
97 | #ifdef IS_MPI | |
98 | ||
99 | < | AtomCommIntRow = new Communicator<Row,int>(nLocal_); |
100 | < | 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_); |
99 | > | MPI::Intracomm row = rowComm.getComm(); |
100 | > | MPI::Intracomm col = colComm.getComm(); |
101 | ||
102 | < | AtomCommIntColumn = new Communicator<Column,int>(nLocal_); |
103 | < | AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_); |
104 | < | AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_); |
105 | < | AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_); |
106 | < | AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_); |
102 | > | AtomPlanIntRow = new Plan<int>(row, nLocal_); |
103 | > | AtomPlanRealRow = new Plan<RealType>(row, nLocal_); |
104 | > | AtomPlanVectorRow = new Plan<Vector3d>(row, nLocal_); |
105 | > | AtomPlanMatrixRow = new Plan<Mat3x3d>(row, nLocal_); |
106 | > | AtomPlanPotRow = new Plan<potVec>(row, nLocal_); |
107 | ||
108 | < | cgCommIntRow = new Communicator<Row,int>(nGroups_); |
109 | < | cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_); |
110 | < | cgCommIntColumn = new Communicator<Column,int>(nGroups_); |
111 | < | cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_); |
108 | > | AtomPlanIntColumn = new Plan<int>(col, nLocal_); |
109 | > | AtomPlanRealColumn = new Plan<RealType>(col, nLocal_); |
110 | > | AtomPlanVectorColumn = new Plan<Vector3d>(col, nLocal_); |
111 | > | AtomPlanMatrixColumn = new Plan<Mat3x3d>(col, nLocal_); |
112 | > | AtomPlanPotColumn = new Plan<potVec>(col, nLocal_); |
113 | ||
114 | < | nAtomsInRow_ = AtomCommIntRow->getSize(); |
115 | < | nAtomsInCol_ = AtomCommIntColumn->getSize(); |
116 | < | nGroupsInRow_ = cgCommIntRow->getSize(); |
117 | < | nGroupsInCol_ = cgCommIntColumn->getSize(); |
114 | > | cgPlanIntRow = new Plan<int>(row, nGroups_); |
115 | > | cgPlanVectorRow = new Plan<Vector3d>(row, nGroups_); |
116 | > | cgPlanIntColumn = new Plan<int>(col, nGroups_); |
117 | > | cgPlanVectorColumn = new Plan<Vector3d>(col, nGroups_); |
118 | ||
119 | + | nAtomsInRow_ = AtomPlanIntRow->getSize(); |
120 | + | nAtomsInCol_ = AtomPlanIntColumn->getSize(); |
121 | + | nGroupsInRow_ = cgPlanIntRow->getSize(); |
122 | + | nGroupsInCol_ = cgPlanIntColumn->getSize(); |
123 | + | |
124 | // Modify the data storage objects with the correct layouts and sizes: | |
125 | atomRowData.resize(nAtomsInRow_); | |
126 | atomRowData.setStorageLayout(storageLayout_); | |
# | Line 108 | Line 134 | namespace OpenMD { | |
134 | identsRow.resize(nAtomsInRow_); | |
135 | identsCol.resize(nAtomsInCol_); | |
136 | ||
137 | < | AtomCommIntRow->gather(identsLocal, identsRow); |
138 | < | AtomCommIntColumn->gather(identsLocal, identsCol); |
137 | > | AtomPlanIntRow->gather(idents, identsRow); |
138 | > | AtomPlanIntColumn->gather(idents, identsCol); |
139 | ||
140 | < | AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
141 | < | AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
142 | < | |
117 | < | cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
118 | < | cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
140 | > | // allocate memory for the parallel objects |
141 | > | atypesRow.resize(nAtomsInRow_); |
142 | > | atypesCol.resize(nAtomsInCol_); |
143 | ||
144 | < | AtomCommRealRow->gather(massFactorsLocal, massFactorsRow); |
145 | < | AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol); |
144 | > | for (int i = 0; i < nAtomsInRow_; i++) |
145 | > | atypesRow[i] = ff_->getAtomType(identsRow[i]); |
146 | > | for (int i = 0; i < nAtomsInCol_; i++) |
147 | > | atypesCol[i] = ff_->getAtomType(identsCol[i]); |
148 | ||
149 | + | pot_row.resize(nAtomsInRow_); |
150 | + | pot_col.resize(nAtomsInCol_); |
151 | + | |
152 | + | AtomRowToGlobal.resize(nAtomsInRow_); |
153 | + | AtomColToGlobal.resize(nAtomsInCol_); |
154 | + | AtomPlanIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
155 | + | AtomPlanIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
156 | + | |
157 | + | cerr << "Atoms in Local:\n"; |
158 | + | for (int i = 0; i < AtomLocalToGlobal.size(); i++) { |
159 | + | cerr << "i =\t" << i << "\t localAt =\t" << AtomLocalToGlobal[i] << "\n"; |
160 | + | } |
161 | + | cerr << "Atoms in Row:\n"; |
162 | + | for (int i = 0; i < AtomRowToGlobal.size(); i++) { |
163 | + | cerr << "i =\t" << i << "\t rowAt =\t" << AtomRowToGlobal[i] << "\n"; |
164 | + | } |
165 | + | cerr << "Atoms in Col:\n"; |
166 | + | for (int i = 0; i < AtomColToGlobal.size(); i++) { |
167 | + | cerr << "i =\t" << i << "\t colAt =\t" << AtomColToGlobal[i] << "\n"; |
168 | + | } |
169 | + | |
170 | + | cgRowToGlobal.resize(nGroupsInRow_); |
171 | + | cgColToGlobal.resize(nGroupsInCol_); |
172 | + | cgPlanIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
173 | + | cgPlanIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
174 | + | |
175 | + | cerr << "Gruops in Local:\n"; |
176 | + | for (int i = 0; i < cgLocalToGlobal.size(); i++) { |
177 | + | cerr << "i =\t" << i << "\t localCG =\t" << cgLocalToGlobal[i] << "\n"; |
178 | + | } |
179 | + | cerr << "Groups in Row:\n"; |
180 | + | for (int i = 0; i < cgRowToGlobal.size(); i++) { |
181 | + | cerr << "i =\t" << i << "\t rowCG =\t" << cgRowToGlobal[i] << "\n"; |
182 | + | } |
183 | + | cerr << "Groups in Col:\n"; |
184 | + | for (int i = 0; i < cgColToGlobal.size(); i++) { |
185 | + | cerr << "i =\t" << i << "\t colCG =\t" << cgColToGlobal[i] << "\n"; |
186 | + | } |
187 | + | |
188 | + | |
189 | + | massFactorsRow.resize(nAtomsInRow_); |
190 | + | massFactorsCol.resize(nAtomsInCol_); |
191 | + | AtomPlanRealRow->gather(massFactors, massFactorsRow); |
192 | + | AtomPlanRealColumn->gather(massFactors, massFactorsCol); |
193 | + | |
194 | groupListRow_.clear(); | |
195 | groupListRow_.resize(nGroupsInRow_); | |
196 | for (int i = 0; i < nGroupsInRow_; i++) { | |
# | Line 142 | Line 213 | namespace OpenMD { | |
213 | } | |
214 | } | |
215 | ||
216 | < | skipsForAtom.clear(); |
217 | < | skipsForAtom.resize(nAtomsInRow_); |
216 | > | excludesForAtom.clear(); |
217 | > | excludesForAtom.resize(nAtomsInRow_); |
218 | toposForAtom.clear(); | |
219 | toposForAtom.resize(nAtomsInRow_); | |
220 | topoDist.clear(); | |
# | Line 154 | Line 225 | namespace OpenMD { | |
225 | for (int j = 0; j < nAtomsInCol_; j++) { | |
226 | int jglob = AtomColToGlobal[j]; | |
227 | ||
228 | < | if (excludes.hasPair(iglob, jglob)) |
229 | < | skipsForAtom[i].push_back(j); |
228 | > | if (excludes->hasPair(iglob, jglob)) |
229 | > | excludesForAtom[i].push_back(j); |
230 | ||
231 | < | if (oneTwo.hasPair(iglob, jglob)) { |
231 | > | if (oneTwo->hasPair(iglob, jglob)) { |
232 | toposForAtom[i].push_back(j); | |
233 | topoDist[i].push_back(1); | |
234 | } else { | |
235 | < | if (oneThree.hasPair(iglob, jglob)) { |
235 | > | if (oneThree->hasPair(iglob, jglob)) { |
236 | toposForAtom[i].push_back(j); | |
237 | topoDist[i].push_back(2); | |
238 | } else { | |
239 | < | if (oneFour.hasPair(iglob, jglob)) { |
239 | > | if (oneFour->hasPair(iglob, jglob)) { |
240 | toposForAtom[i].push_back(j); | |
241 | topoDist[i].push_back(3); | |
242 | } | |
# | Line 176 | Line 247 | namespace OpenMD { | |
247 | ||
248 | #endif | |
249 | ||
250 | + | // allocate memory for the parallel objects |
251 | + | atypesLocal.resize(nLocal_); |
252 | + | |
253 | + | for (int i = 0; i < nLocal_; i++) |
254 | + | atypesLocal[i] = ff_->getAtomType(idents[i]); |
255 | + | |
256 | groupList_.clear(); | |
257 | groupList_.resize(nGroups_); | |
258 | for (int i = 0; i < nGroups_; i++) { | |
# | Line 188 | Line 265 | namespace OpenMD { | |
265 | } | |
266 | } | |
267 | ||
268 | < | skipsForAtom.clear(); |
269 | < | skipsForAtom.resize(nLocal_); |
268 | > | excludesForAtom.clear(); |
269 | > | excludesForAtom.resize(nLocal_); |
270 | toposForAtom.clear(); | |
271 | toposForAtom.resize(nLocal_); | |
272 | topoDist.clear(); | |
# | Line 201 | Line 278 | namespace OpenMD { | |
278 | for (int j = 0; j < nLocal_; j++) { | |
279 | int jglob = AtomLocalToGlobal[j]; | |
280 | ||
281 | < | if (excludes.hasPair(iglob, jglob)) |
282 | < | skipsForAtom[i].push_back(j); |
281 | > | if (excludes->hasPair(iglob, jglob)) |
282 | > | excludesForAtom[i].push_back(j); |
283 | ||
284 | < | if (oneTwo.hasPair(iglob, jglob)) { |
284 | > | if (oneTwo->hasPair(iglob, jglob)) { |
285 | toposForAtom[i].push_back(j); | |
286 | topoDist[i].push_back(1); | |
287 | } else { | |
288 | < | if (oneThree.hasPair(iglob, jglob)) { |
288 | > | if (oneThree->hasPair(iglob, jglob)) { |
289 | toposForAtom[i].push_back(j); | |
290 | topoDist[i].push_back(2); | |
291 | } else { | |
292 | < | if (oneFour.hasPair(iglob, jglob)) { |
292 | > | if (oneFour->hasPair(iglob, jglob)) { |
293 | toposForAtom[i].push_back(j); | |
294 | topoDist[i].push_back(3); | |
295 | } | |
# | Line 222 | Line 299 | namespace OpenMD { | |
299 | } | |
300 | ||
301 | createGtypeCutoffMap(); | |
302 | + | |
303 | } | |
304 | ||
305 | void ForceMatrixDecomposition::createGtypeCutoffMap() { | |
306 | < | |
306 | > | |
307 | RealType tol = 1e-6; | |
308 | + | largestRcut_ = 0.0; |
309 | RealType rc; | |
310 | int atid; | |
311 | set<AtomType*> atypes = info_->getSimulatedAtomTypes(); | |
312 | < | vector<RealType> atypeCutoff; |
313 | < | atypeCutoff.resize( atypes.size() ); |
314 | < | |
312 | > | |
313 | > | map<int, RealType> atypeCutoff; |
314 | > | |
315 | for (set<AtomType*>::iterator at = atypes.begin(); | |
316 | at != atypes.end(); ++at){ | |
238 | – | rc = interactionMan_->getSuggestedCutoffRadius(*at); |
317 | atid = (*at)->getIdent(); | |
318 | < | atypeCutoff[atid] = rc; |
318 | > | if (userChoseCutoff_) |
319 | > | atypeCutoff[atid] = userCutoff_; |
320 | > | else |
321 | > | atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at); |
322 | } | |
323 | < | |
323 | > | |
324 | vector<RealType> gTypeCutoffs; | |
244 | – | |
325 | // first we do a single loop over the cutoff groups to find the | |
326 | // largest cutoff for any atypes present in this group. | |
327 | #ifdef IS_MPI | |
# | Line 299 | Line 379 | namespace OpenMD { | |
379 | ||
380 | vector<RealType> groupCutoff(nGroups_, 0.0); | |
381 | groupToGtype.resize(nGroups_); | |
302 | – | |
303 | – | cerr << "nGroups = " << nGroups_ << "\n"; |
382 | for (int cg1 = 0; cg1 < nGroups_; cg1++) { | |
305 | – | |
383 | groupCutoff[cg1] = 0.0; | |
384 | vector<int> atomList = getAtomsInGroupRow(cg1); | |
308 | – | |
385 | for (vector<int>::iterator ia = atomList.begin(); | |
386 | ia != atomList.end(); ++ia) { | |
387 | int atom1 = (*ia); | |
388 | < | atid = identsLocal[atom1]; |
389 | < | if (atypeCutoff[atid] > groupCutoff[cg1]) { |
390 | < | groupCutoff[cg1] = atypeCutoff[atid]; |
315 | < | } |
388 | > | atid = idents[atom1]; |
389 | > | if (atypeCutoff[atid] > groupCutoff[cg1]) |
390 | > | groupCutoff[cg1] = atypeCutoff[atid]; |
391 | } | |
392 | < | |
392 | > | |
393 | bool gTypeFound = false; | |
394 | for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { | |
395 | if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) { | |
# | Line 322 | Line 397 | namespace OpenMD { | |
397 | gTypeFound = true; | |
398 | } | |
399 | } | |
400 | < | if (!gTypeFound) { |
400 | > | if (!gTypeFound) { |
401 | gTypeCutoffs.push_back( groupCutoff[cg1] ); | |
402 | groupToGtype[cg1] = gTypeCutoffs.size() - 1; | |
403 | } | |
404 | } | |
405 | #endif | |
406 | ||
332 | – | cerr << "gTypeCutoffs.size() = " << gTypeCutoffs.size() << "\n"; |
407 | // Now we find the maximum group cutoff value present in the simulation | |
408 | ||
409 | < | RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end()); |
409 | > | RealType groupMax = *max_element(gTypeCutoffs.begin(), |
410 | > | gTypeCutoffs.end()); |
411 | ||
412 | #ifdef IS_MPI | |
413 | < | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX); |
413 | > | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, |
414 | > | MPI::MAX); |
415 | #endif | |
416 | ||
417 | RealType tradRcut = groupMax; | |
# | Line 365 | Line 441 | namespace OpenMD { | |
441 | ||
442 | pair<int,int> key = make_pair(i,j); | |
443 | gTypeCutoffMap[key].first = thisRcut; | |
368 | – | |
444 | if (thisRcut > largestRcut_) largestRcut_ = thisRcut; | |
370 | – | |
445 | gTypeCutoffMap[key].second = thisRcut*thisRcut; | |
372 | – | |
446 | gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2); | |
374 | – | |
447 | // sanity check | |
448 | ||
449 | if (userChoseCutoff_) { | |
450 | if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) { | |
451 | sprintf(painCave.errMsg, | |
452 | "ForceMatrixDecomposition::createGtypeCutoffMap " | |
453 | < | "user-specified rCut does not match computed group Cutoff\n"); |
453 | > | "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_); |
454 | painCave.severity = OPENMD_ERROR; | |
455 | painCave.isFatal = 1; | |
456 | simError(); | |
# | Line 410 | Line 482 | namespace OpenMD { | |
482 | } | |
483 | ||
484 | void ForceMatrixDecomposition::zeroWorkArrays() { | |
485 | + | pairwisePot = 0.0; |
486 | + | embeddingPot = 0.0; |
487 | ||
414 | – | for (int j = 0; j < N_INTERACTION_FAMILIES; j++) { |
415 | – | longRangePot_[j] = 0.0; |
416 | – | } |
417 | – | |
488 | #ifdef IS_MPI | |
489 | if (storageLayout_ & DataStorage::dslForce) { | |
490 | fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero); | |
# | Line 430 | Line 500 | namespace OpenMD { | |
500 | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); | |
501 | ||
502 | fill(pot_col.begin(), pot_col.end(), | |
503 | < | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
434 | < | |
435 | < | pot_local = Vector<RealType, N_INTERACTION_FAMILIES>(0.0); |
503 | > | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
504 | ||
505 | if (storageLayout_ & DataStorage::dslParticlePot) { | |
506 | < | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); |
507 | < | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0); |
506 | > | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), |
507 | > | 0.0); |
508 | > | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), |
509 | > | 0.0); |
510 | } | |
511 | ||
512 | if (storageLayout_ & DataStorage::dslDensity) { | |
# | Line 445 | Line 515 | namespace OpenMD { | |
515 | } | |
516 | ||
517 | if (storageLayout_ & DataStorage::dslFunctional) { | |
518 | < | fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0); |
519 | < | fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0); |
518 | > | fill(atomRowData.functional.begin(), atomRowData.functional.end(), |
519 | > | 0.0); |
520 | > | fill(atomColData.functional.begin(), atomColData.functional.end(), |
521 | > | 0.0); |
522 | } | |
523 | ||
524 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
# | Line 456 | Line 528 | namespace OpenMD { | |
528 | atomColData.functionalDerivative.end(), 0.0); | |
529 | } | |
530 | ||
531 | < | #else |
532 | < | |
531 | > | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
532 | > | fill(atomRowData.skippedCharge.begin(), |
533 | > | atomRowData.skippedCharge.end(), 0.0); |
534 | > | fill(atomColData.skippedCharge.begin(), |
535 | > | atomColData.skippedCharge.end(), 0.0); |
536 | > | } |
537 | > | |
538 | > | #endif |
539 | > | // even in parallel, we need to zero out the local arrays: |
540 | > | |
541 | if (storageLayout_ & DataStorage::dslParticlePot) { | |
542 | fill(snap_->atomData.particlePot.begin(), | |
543 | snap_->atomData.particlePot.end(), 0.0); | |
# | Line 475 | Line 555 | namespace OpenMD { | |
555 | fill(snap_->atomData.functionalDerivative.begin(), | |
556 | snap_->atomData.functionalDerivative.end(), 0.0); | |
557 | } | |
558 | < | #endif |
558 | > | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
559 | > | fill(snap_->atomData.skippedCharge.begin(), |
560 | > | snap_->atomData.skippedCharge.end(), 0.0); |
561 | > | } |
562 | ||
563 | } | |
564 | ||
# | Line 486 | Line 569 | namespace OpenMD { | |
569 | #ifdef IS_MPI | |
570 | ||
571 | // gather up the atomic positions | |
572 | < | AtomCommVectorRow->gather(snap_->atomData.position, |
572 | > | AtomPlanVectorRow->gather(snap_->atomData.position, |
573 | atomRowData.position); | |
574 | < | AtomCommVectorColumn->gather(snap_->atomData.position, |
574 | > | AtomPlanVectorColumn->gather(snap_->atomData.position, |
575 | atomColData.position); | |
576 | ||
577 | // gather up the cutoff group positions | |
578 | < | cgCommVectorRow->gather(snap_->cgData.position, |
578 | > | |
579 | > | cerr << "before gather\n"; |
580 | > | for (int i = 0; i < snap_->cgData.position.size(); i++) { |
581 | > | cerr << "cgpos = " << snap_->cgData.position[i] << "\n"; |
582 | > | } |
583 | > | |
584 | > | cgPlanVectorRow->gather(snap_->cgData.position, |
585 | cgRowData.position); | |
586 | < | cgCommVectorColumn->gather(snap_->cgData.position, |
586 | > | |
587 | > | cerr << "after gather\n"; |
588 | > | for (int i = 0; i < cgRowData.position.size(); i++) { |
589 | > | cerr << "cgRpos = " << cgRowData.position[i] << "\n"; |
590 | > | } |
591 | > | |
592 | > | cgPlanVectorColumn->gather(snap_->cgData.position, |
593 | cgColData.position); | |
594 | + | for (int i = 0; i < cgColData.position.size(); i++) { |
595 | + | cerr << "cgCpos = " << cgColData.position[i] << "\n"; |
596 | + | } |
597 | + | |
598 | ||
599 | // if needed, gather the atomic rotation matrices | |
600 | if (storageLayout_ & DataStorage::dslAmat) { | |
601 | < | AtomCommMatrixRow->gather(snap_->atomData.aMat, |
601 | > | AtomPlanMatrixRow->gather(snap_->atomData.aMat, |
602 | atomRowData.aMat); | |
603 | < | AtomCommMatrixColumn->gather(snap_->atomData.aMat, |
603 | > | AtomPlanMatrixColumn->gather(snap_->atomData.aMat, |
604 | atomColData.aMat); | |
605 | } | |
606 | ||
607 | // if needed, gather the atomic eletrostatic frames | |
608 | if (storageLayout_ & DataStorage::dslElectroFrame) { | |
609 | < | AtomCommMatrixRow->gather(snap_->atomData.electroFrame, |
609 | > | AtomPlanMatrixRow->gather(snap_->atomData.electroFrame, |
610 | atomRowData.electroFrame); | |
611 | < | AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, |
611 | > | AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame, |
612 | atomColData.electroFrame); | |
613 | } | |
614 | + | |
615 | #endif | |
616 | } | |
617 | ||
# | Line 525 | Line 625 | namespace OpenMD { | |
625 | ||
626 | if (storageLayout_ & DataStorage::dslDensity) { | |
627 | ||
628 | < | AtomCommRealRow->scatter(atomRowData.density, |
628 | > | AtomPlanRealRow->scatter(atomRowData.density, |
629 | snap_->atomData.density); | |
630 | ||
631 | int n = snap_->atomData.density.size(); | |
632 | vector<RealType> rho_tmp(n, 0.0); | |
633 | < | AtomCommRealColumn->scatter(atomColData.density, rho_tmp); |
633 | > | AtomPlanRealColumn->scatter(atomColData.density, rho_tmp); |
634 | for (int i = 0; i < n; i++) | |
635 | snap_->atomData.density[i] += rho_tmp[i]; | |
636 | } | |
# | Line 546 | Line 646 | namespace OpenMD { | |
646 | storageLayout_ = sman_->getStorageLayout(); | |
647 | #ifdef IS_MPI | |
648 | if (storageLayout_ & DataStorage::dslFunctional) { | |
649 | < | AtomCommRealRow->gather(snap_->atomData.functional, |
649 | > | AtomPlanRealRow->gather(snap_->atomData.functional, |
650 | atomRowData.functional); | |
651 | < | AtomCommRealColumn->gather(snap_->atomData.functional, |
651 | > | AtomPlanRealColumn->gather(snap_->atomData.functional, |
652 | atomColData.functional); | |
653 | } | |
654 | ||
655 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
656 | < | AtomCommRealRow->gather(snap_->atomData.functionalDerivative, |
656 | > | AtomPlanRealRow->gather(snap_->atomData.functionalDerivative, |
657 | atomRowData.functionalDerivative); | |
658 | < | AtomCommRealColumn->gather(snap_->atomData.functionalDerivative, |
658 | > | AtomPlanRealColumn->gather(snap_->atomData.functionalDerivative, |
659 | atomColData.functionalDerivative); | |
660 | } | |
661 | #endif | |
# | Line 569 | Line 669 | namespace OpenMD { | |
669 | int n = snap_->atomData.force.size(); | |
670 | vector<Vector3d> frc_tmp(n, V3Zero); | |
671 | ||
672 | < | AtomCommVectorRow->scatter(atomRowData.force, frc_tmp); |
672 | > | AtomPlanVectorRow->scatter(atomRowData.force, frc_tmp); |
673 | for (int i = 0; i < n; i++) { | |
674 | snap_->atomData.force[i] += frc_tmp[i]; | |
675 | frc_tmp[i] = 0.0; | |
676 | } | |
677 | ||
678 | < | AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); |
679 | < | for (int i = 0; i < n; i++) |
678 | > | AtomPlanVectorColumn->scatter(atomColData.force, frc_tmp); |
679 | > | for (int i = 0; i < n; i++) { |
680 | snap_->atomData.force[i] += frc_tmp[i]; | |
681 | < | |
682 | < | |
681 | > | } |
682 | > | |
683 | if (storageLayout_ & DataStorage::dslTorque) { | |
684 | ||
685 | < | int nt = snap_->atomData.force.size(); |
685 | > | int nt = snap_->atomData.torque.size(); |
686 | vector<Vector3d> trq_tmp(nt, V3Zero); | |
687 | ||
688 | < | AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); |
689 | < | for (int i = 0; i < n; i++) { |
688 | > | AtomPlanVectorRow->scatter(atomRowData.torque, trq_tmp); |
689 | > | for (int i = 0; i < nt; i++) { |
690 | snap_->atomData.torque[i] += trq_tmp[i]; | |
691 | trq_tmp[i] = 0.0; | |
692 | } | |
693 | ||
694 | < | AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); |
695 | < | for (int i = 0; i < n; i++) |
694 | > | AtomPlanVectorColumn->scatter(atomColData.torque, trq_tmp); |
695 | > | for (int i = 0; i < nt; i++) |
696 | snap_->atomData.torque[i] += trq_tmp[i]; | |
697 | } | |
698 | + | |
699 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
700 | + | |
701 | + | int ns = snap_->atomData.skippedCharge.size(); |
702 | + | vector<RealType> skch_tmp(ns, 0.0); |
703 | + | |
704 | + | AtomPlanRealRow->scatter(atomRowData.skippedCharge, skch_tmp); |
705 | + | for (int i = 0; i < ns; i++) { |
706 | + | snap_->atomData.skippedCharge[i] += skch_tmp[i]; |
707 | + | skch_tmp[i] = 0.0; |
708 | + | } |
709 | + | |
710 | + | AtomPlanRealColumn->scatter(atomColData.skippedCharge, skch_tmp); |
711 | + | for (int i = 0; i < ns; i++) |
712 | + | snap_->atomData.skippedCharge[i] += skch_tmp[i]; |
713 | + | } |
714 | ||
715 | nLocal_ = snap_->getNumberOfAtoms(); | |
716 | ||
# | Line 603 | Line 719 | namespace OpenMD { | |
719 | ||
720 | // scatter/gather pot_row into the members of my column | |
721 | ||
722 | < | AtomCommPotRow->scatter(pot_row, pot_temp); |
722 | > | AtomPlanPotRow->scatter(pot_row, pot_temp); |
723 | ||
724 | for (int ii = 0; ii < pot_temp.size(); ii++ ) | |
725 | < | pot_local += pot_temp[ii]; |
725 | > | pairwisePot += pot_temp[ii]; |
726 | ||
727 | fill(pot_temp.begin(), pot_temp.end(), | |
728 | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); | |
729 | ||
730 | < | AtomCommPotColumn->scatter(pot_col, pot_temp); |
730 | > | AtomPlanPotColumn->scatter(pot_col, pot_temp); |
731 | ||
732 | for (int ii = 0; ii < pot_temp.size(); ii++ ) | |
733 | < | pot_local += pot_temp[ii]; |
618 | < | |
733 | > | pairwisePot += pot_temp[ii]; |
734 | #endif | |
735 | + | |
736 | + | cerr << "pairwisePot = " << pairwisePot << "\n"; |
737 | } | |
738 | ||
739 | int ForceMatrixDecomposition::getNAtomsInRow() { | |
# | Line 651 | Line 768 | namespace OpenMD { | |
768 | ||
769 | #ifdef IS_MPI | |
770 | d = cgColData.position[cg2] - cgRowData.position[cg1]; | |
771 | + | cerr << "cg1 = " << cg1 << "\tcg1p = " << cgRowData.position[cg1] << "\n"; |
772 | + | cerr << "cg2 = " << cg2 << "\tcg2p = " << cgColData.position[cg2] << "\n"; |
773 | #else | |
774 | d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1]; | |
775 | + | cerr << "cg1 = " << cg1 << "\tcg1p = " << snap_->cgData.position[cg1] << "\n"; |
776 | + | cerr << "cg2 = " << cg2 << "\tcg2p = " << snap_->cgData.position[cg2] << "\n"; |
777 | #endif | |
778 | ||
779 | snap_->wrapVector(d); | |
# | Line 691 | Line 812 | namespace OpenMD { | |
812 | #ifdef IS_MPI | |
813 | return massFactorsRow[atom1]; | |
814 | #else | |
815 | < | return massFactorsLocal[atom1]; |
815 | > | return massFactors[atom1]; |
816 | #endif | |
817 | } | |
818 | ||
# | Line 699 | Line 820 | namespace OpenMD { | |
820 | #ifdef IS_MPI | |
821 | return massFactorsCol[atom2]; | |
822 | #else | |
823 | < | return massFactorsLocal[atom2]; |
823 | > | return massFactors[atom2]; |
824 | #endif | |
825 | ||
826 | } | |
# | Line 717 | Line 838 | namespace OpenMD { | |
838 | return d; | |
839 | } | |
840 | ||
841 | < | vector<int> ForceMatrixDecomposition::getSkipsForAtom(int atom1) { |
842 | < | return skipsForAtom[atom1]; |
841 | > | vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) { |
842 | > | return excludesForAtom[atom1]; |
843 | } | |
844 | ||
845 | /** | |
846 | < | * 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 |
846 | > | * We need to exclude some overcounted interactions that result from |
847 | * the parallel decomposition. | |
848 | */ | |
849 | bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { | |
850 | int unique_id_1, unique_id_2; | |
851 | + | |
852 | ||
853 | + | cerr << "sap with atom1, atom2 =\t" << atom1 << "\t" << atom2 << "\n"; |
854 | #ifdef IS_MPI | |
855 | // in MPI, we have to look up the unique IDs for each atom | |
856 | unique_id_1 = AtomRowToGlobal[atom1]; | |
857 | unique_id_2 = AtomColToGlobal[atom2]; | |
858 | ||
859 | + | cerr << "sap with uid1, uid2 =\t" << unique_id_1 << "\t" << unique_id_2 << "\n"; |
860 | // this situation should only arise in MPI simulations | |
861 | if (unique_id_1 == unique_id_2) return true; | |
862 | ||
# | Line 745 | Line 866 | namespace OpenMD { | |
866 | } else { | |
867 | if ((unique_id_1 + unique_id_2) % 2 == 1) return true; | |
868 | } | |
869 | + | #endif |
870 | + | return false; |
871 | + | } |
872 | + | |
873 | + | /** |
874 | + | * We need to handle the interactions for atoms who are involved in |
875 | + | * the same rigid body as well as some short range interactions |
876 | + | * (bonds, bends, torsions) differently from other interactions. |
877 | + | * We'll still visit the pairwise routines, but with a flag that |
878 | + | * tells those routines to exclude the pair from direct long range |
879 | + | * interactions. Some indirect interactions (notably reaction |
880 | + | * field) must still be handled for these pairs. |
881 | + | */ |
882 | + | bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) { |
883 | + | int unique_id_2; |
884 | + | #ifdef IS_MPI |
885 | + | // in MPI, we have to look up the unique IDs for the row atom. |
886 | + | unique_id_2 = AtomColToGlobal[atom2]; |
887 | #else | |
888 | // in the normal loop, the atom numbers are unique | |
750 | – | unique_id_1 = atom1; |
889 | unique_id_2 = atom2; | |
890 | #endif | |
891 | ||
892 | < | for (vector<int>::iterator i = skipsForAtom[atom1].begin(); |
893 | < | i != skipsForAtom[atom1].end(); ++i) { |
892 | > | for (vector<int>::iterator i = excludesForAtom[atom1].begin(); |
893 | > | i != excludesForAtom[atom1].end(); ++i) { |
894 | if ( (*i) == unique_id_2 ) return true; | |
895 | < | } |
895 | > | } |
896 | ||
897 | + | return false; |
898 | } | |
899 | ||
900 | ||
# | Line 776 | Line 915 | namespace OpenMD { | |
915 | } | |
916 | ||
917 | // filling interaction blocks with pointers | |
918 | < | InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) { |
919 | < | InteractionData idat; |
918 | > | void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat, |
919 | > | int atom1, int atom2) { |
920 | ||
921 | + | idat.excluded = excludeAtomPair(atom1, atom2); |
922 | + | |
923 | #ifdef IS_MPI | |
924 | + | idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]); |
925 | + | //idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
926 | + | // ff_->getAtomType(identsCol[atom2]) ); |
927 | ||
784 | – | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
785 | – | ff_->getAtomType(identsCol[atom2]) ); |
786 | – | |
787 | – | |
928 | if (storageLayout_ & DataStorage::dslAmat) { | |
929 | idat.A1 = &(atomRowData.aMat[atom1]); | |
930 | idat.A2 = &(atomColData.aMat[atom2]); | |
# | Line 820 | Line 960 | namespace OpenMD { | |
960 | idat.particlePot2 = &(atomColData.particlePot[atom2]); | |
961 | } | |
962 | ||
963 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
964 | + | idat.skippedCharge1 = &(atomRowData.skippedCharge[atom1]); |
965 | + | idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]); |
966 | + | } |
967 | + | |
968 | #else | |
969 | ||
970 | < | idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
971 | < | ff_->getAtomType(identsLocal[atom2]) ); |
970 | > | idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]); |
971 | > | //idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), |
972 | > | // ff_->getAtomType(idents[atom2]) ); |
973 | ||
974 | if (storageLayout_ & DataStorage::dslAmat) { | |
975 | idat.A1 = &(snap_->atomData.aMat[atom1]); | |
# | Line 840 | Line 986 | namespace OpenMD { | |
986 | idat.t2 = &(snap_->atomData.torque[atom2]); | |
987 | } | |
988 | ||
989 | < | if (storageLayout_ & DataStorage::dslDensity) { |
989 | > | if (storageLayout_ & DataStorage::dslDensity) { |
990 | idat.rho1 = &(snap_->atomData.density[atom1]); | |
991 | idat.rho2 = &(snap_->atomData.density[atom2]); | |
992 | } | |
# | Line 860 | Line 1006 | namespace OpenMD { | |
1006 | idat.particlePot2 = &(snap_->atomData.particlePot[atom2]); | |
1007 | } | |
1008 | ||
1009 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { |
1010 | + | idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]); |
1011 | + | idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]); |
1012 | + | } |
1013 | #endif | |
864 | – | return idat; |
1014 | } | |
1015 | ||
1016 | ||
1017 | < | void ForceMatrixDecomposition::unpackInteractionData(InteractionData idat, int atom1, int atom2) { |
1017 | > | void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) { |
1018 | #ifdef IS_MPI | |
1019 | pot_row[atom1] += 0.5 * *(idat.pot); | |
1020 | pot_col[atom2] += 0.5 * *(idat.pot); | |
# | Line 873 | Line 1022 | namespace OpenMD { | |
1022 | atomRowData.force[atom1] += *(idat.f1); | |
1023 | atomColData.force[atom2] -= *(idat.f1); | |
1024 | #else | |
1025 | < | longRangePot_ += *(idat.pot); |
1026 | < | |
1025 | > | pairwisePot += *(idat.pot); |
1026 | > | |
1027 | snap_->atomData.force[atom1] += *(idat.f1); | |
1028 | snap_->atomData.force[atom2] -= *(idat.f1); | |
1029 | #endif | |
1030 | < | |
1030 | > | |
1031 | } | |
1032 | ||
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]); |
895 | – | } |
896 | – | if (storageLayout_ & DataStorage::dslTorque) { |
897 | – | idat.t1 = &(atomRowData.torque[atom1]); |
898 | – | idat.t2 = &(atomColData.torque[atom2]); |
899 | – | } |
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]); |
907 | – | } |
908 | – | if (storageLayout_ & DataStorage::dslTorque) { |
909 | – | idat.t1 = &(snap_->atomData.torque[atom1]); |
910 | – | idat.t2 = &(snap_->atomData.torque[atom2]); |
911 | – | } |
912 | – | #endif |
913 | – | } |
914 | – | |
1033 | /* | |
1034 | * buildNeighborList | |
1035 | * | |
# | Line 922 | Line 1040 | namespace OpenMD { | |
1040 | ||
1041 | vector<pair<int, int> > neighborList; | |
1042 | groupCutoffs cuts; | |
1043 | + | bool doAllPairs = false; |
1044 | + | |
1045 | #ifdef IS_MPI | |
1046 | cellListRow_.clear(); | |
1047 | cellListCol_.clear(); | |
# | Line 940 | Line 1060 | namespace OpenMD { | |
1060 | nCells_.x() = (int) ( Hx.length() )/ rList_; | |
1061 | nCells_.y() = (int) ( Hy.length() )/ rList_; | |
1062 | nCells_.z() = (int) ( Hz.length() )/ rList_; | |
1063 | + | |
1064 | + | // handle small boxes where the cell offsets can end up repeating cells |
1065 | + | |
1066 | + | if (nCells_.x() < 3) doAllPairs = true; |
1067 | + | if (nCells_.y() < 3) doAllPairs = true; |
1068 | + | if (nCells_.z() < 3) doAllPairs = true; |
1069 | ||
1070 | Mat3x3d invHmat = snap_->getInvHmat(); | |
1071 | Vector3d rs, scaled, dr; | |
# | Line 954 | Line 1080 | namespace OpenMD { | |
1080 | cellList_.resize(nCtot); | |
1081 | #endif | |
1082 | ||
1083 | + | if (!doAllPairs) { |
1084 | #ifdef IS_MPI | |
958 | – | for (int i = 0; i < nGroupsInRow_; i++) { |
959 | – | rs = cgRowData.position[i]; |
960 | – | // scaled positions relative to the box vectors |
961 | – | scaled = invHmat * rs; |
962 | – | // wrap the vector back into the unit box by subtracting integer box |
963 | – | // numbers |
964 | – | for (int j = 0; j < 3; j++) |
965 | – | scaled[j] -= roundMe(scaled[j]); |
966 | – | |
967 | – | // find xyz-indices of cell that cutoffGroup is in. |
968 | – | whichCell.x() = nCells_.x() * scaled.x(); |
969 | – | whichCell.y() = nCells_.y() * scaled.y(); |
970 | – | whichCell.z() = nCells_.z() * scaled.z(); |
1085 | ||
1086 | < | // find single index of this cell: |
1087 | < | cellIndex = Vlinear(whichCell, nCells_); |
1088 | < | // add this cutoff group to the list of groups in this cell; |
1089 | < | cellListRow_[cellIndex].push_back(i); |
1090 | < | } |
1091 | < | |
1092 | < | for (int i = 0; i < nGroupsInCol_; i++) { |
1093 | < | rs = cgColData.position[i]; |
1094 | < | // scaled positions relative to the box vectors |
1095 | < | scaled = invHmat * rs; |
1096 | < | // wrap the vector back into the unit box by subtracting integer box |
1097 | < | // numbers |
1098 | < | for (int j = 0; j < 3; j++) |
1099 | < | scaled[j] -= roundMe(scaled[j]); |
1100 | < | |
1101 | < | // find xyz-indices of cell that cutoffGroup is in. |
1102 | < | whichCell.x() = nCells_.x() * scaled.x(); |
1103 | < | whichCell.y() = nCells_.y() * scaled.y(); |
1104 | < | whichCell.z() = nCells_.z() * scaled.z(); |
1105 | < | |
1106 | < | // find single index of this cell: |
1107 | < | cellIndex = Vlinear(whichCell, nCells_); |
1108 | < | // add this cutoff group to the list of groups in this cell; |
1109 | < | cellListCol_[cellIndex].push_back(i); |
1110 | < | } |
1086 | > | for (int i = 0; i < nGroupsInRow_; i++) { |
1087 | > | rs = cgRowData.position[i]; |
1088 | > | |
1089 | > | // scaled positions relative to the box vectors |
1090 | > | scaled = invHmat * rs; |
1091 | > | |
1092 | > | // wrap the vector back into the unit box by subtracting integer box |
1093 | > | // numbers |
1094 | > | for (int j = 0; j < 3; j++) { |
1095 | > | scaled[j] -= roundMe(scaled[j]); |
1096 | > | scaled[j] += 0.5; |
1097 | > | } |
1098 | > | |
1099 | > | // find xyz-indices of cell that cutoffGroup is in. |
1100 | > | whichCell.x() = nCells_.x() * scaled.x(); |
1101 | > | whichCell.y() = nCells_.y() * scaled.y(); |
1102 | > | whichCell.z() = nCells_.z() * scaled.z(); |
1103 | > | |
1104 | > | // find single index of this cell: |
1105 | > | cellIndex = Vlinear(whichCell, nCells_); |
1106 | > | |
1107 | > | // add this cutoff group to the list of groups in this cell; |
1108 | > | cellListRow_[cellIndex].push_back(i); |
1109 | > | } |
1110 | > | for (int i = 0; i < nGroupsInCol_; i++) { |
1111 | > | rs = cgColData.position[i]; |
1112 | > | |
1113 | > | // scaled positions relative to the box vectors |
1114 | > | scaled = invHmat * rs; |
1115 | > | |
1116 | > | // wrap the vector back into the unit box by subtracting integer box |
1117 | > | // numbers |
1118 | > | for (int j = 0; j < 3; j++) { |
1119 | > | scaled[j] -= roundMe(scaled[j]); |
1120 | > | scaled[j] += 0.5; |
1121 | > | } |
1122 | > | |
1123 | > | // find xyz-indices of cell that cutoffGroup is in. |
1124 | > | whichCell.x() = nCells_.x() * scaled.x(); |
1125 | > | whichCell.y() = nCells_.y() * scaled.y(); |
1126 | > | whichCell.z() = nCells_.z() * scaled.z(); |
1127 | > | |
1128 | > | // find single index of this cell: |
1129 | > | cellIndex = Vlinear(whichCell, nCells_); |
1130 | > | |
1131 | > | // add this cutoff group to the list of groups in this cell; |
1132 | > | cellListCol_[cellIndex].push_back(i); |
1133 | > | } |
1134 | #else | |
1135 | < | for (int i = 0; i < nGroups_; i++) { |
1136 | < | rs = snap_->cgData.position[i]; |
1137 | < | // scaled positions relative to the box vectors |
1138 | < | scaled = invHmat * rs; |
1139 | < | // wrap the vector back into the unit box by subtracting integer box |
1140 | < | // numbers |
1141 | < | for (int j = 0; j < 3; j++) |
1142 | < | scaled[j] -= roundMe(scaled[j]); |
1143 | < | |
1144 | < | // find xyz-indices of cell that cutoffGroup is in. |
1145 | < | whichCell.x() = nCells_.x() * scaled.x(); |
1146 | < | whichCell.y() = nCells_.y() * scaled.y(); |
1147 | < | whichCell.z() = nCells_.z() * scaled.z(); |
1148 | < | |
1149 | < | // find single index of this cell: |
1150 | < | cellIndex = Vlinear(whichCell, nCells_); |
1151 | < | // add this cutoff group to the list of groups in this cell; |
1152 | < | cellList_[cellIndex].push_back(i); |
1153 | < | } |
1135 | > | for (int i = 0; i < nGroups_; i++) { |
1136 | > | rs = snap_->cgData.position[i]; |
1137 | > | |
1138 | > | // scaled positions relative to the box vectors |
1139 | > | scaled = invHmat * rs; |
1140 | > | |
1141 | > | // wrap the vector back into the unit box by subtracting integer box |
1142 | > | // numbers |
1143 | > | for (int j = 0; j < 3; j++) { |
1144 | > | scaled[j] -= roundMe(scaled[j]); |
1145 | > | scaled[j] += 0.5; |
1146 | > | } |
1147 | > | |
1148 | > | // find xyz-indices of cell that cutoffGroup is in. |
1149 | > | whichCell.x() = nCells_.x() * scaled.x(); |
1150 | > | whichCell.y() = nCells_.y() * scaled.y(); |
1151 | > | whichCell.z() = nCells_.z() * scaled.z(); |
1152 | > | |
1153 | > | // find single index of this cell: |
1154 | > | cellIndex = Vlinear(whichCell, nCells_); |
1155 | > | |
1156 | > | // add this cutoff group to the list of groups in this cell; |
1157 | > | cellList_[cellIndex].push_back(i); |
1158 | > | } |
1159 | #endif | |
1160 | ||
1161 | < | for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
1162 | < | for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
1163 | < | for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
1164 | < | Vector3i m1v(m1x, m1y, m1z); |
1165 | < | int m1 = Vlinear(m1v, nCells_); |
1024 | < | |
1025 | < | for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
1026 | < | os != cellOffsets_.end(); ++os) { |
1161 | > | for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
1162 | > | for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
1163 | > | for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
1164 | > | Vector3i m1v(m1x, m1y, m1z); |
1165 | > | int m1 = Vlinear(m1v, nCells_); |
1166 | ||
1167 | < | Vector3i m2v = m1v + (*os); |
1168 | < | |
1169 | < | if (m2v.x() >= nCells_.x()) { |
1170 | < | m2v.x() = 0; |
1171 | < | } else if (m2v.x() < 0) { |
1172 | < | m2v.x() = nCells_.x() - 1; |
1173 | < | } |
1174 | < | |
1175 | < | if (m2v.y() >= nCells_.y()) { |
1176 | < | m2v.y() = 0; |
1177 | < | } else if (m2v.y() < 0) { |
1178 | < | m2v.y() = nCells_.y() - 1; |
1179 | < | } |
1180 | < | |
1181 | < | if (m2v.z() >= nCells_.z()) { |
1182 | < | m2v.z() = 0; |
1183 | < | } else if (m2v.z() < 0) { |
1184 | < | m2v.z() = nCells_.z() - 1; |
1185 | < | } |
1186 | < | |
1187 | < | int m2 = Vlinear (m2v, nCells_); |
1188 | < | |
1167 | > | for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
1168 | > | os != cellOffsets_.end(); ++os) { |
1169 | > | |
1170 | > | Vector3i m2v = m1v + (*os); |
1171 | > | |
1172 | > | if (m2v.x() >= nCells_.x()) { |
1173 | > | m2v.x() = 0; |
1174 | > | } else if (m2v.x() < 0) { |
1175 | > | m2v.x() = nCells_.x() - 1; |
1176 | > | } |
1177 | > | |
1178 | > | if (m2v.y() >= nCells_.y()) { |
1179 | > | m2v.y() = 0; |
1180 | > | } else if (m2v.y() < 0) { |
1181 | > | m2v.y() = nCells_.y() - 1; |
1182 | > | } |
1183 | > | |
1184 | > | if (m2v.z() >= nCells_.z()) { |
1185 | > | m2v.z() = 0; |
1186 | > | } else if (m2v.z() < 0) { |
1187 | > | m2v.z() = nCells_.z() - 1; |
1188 | > | } |
1189 | > | |
1190 | > | int m2 = Vlinear (m2v, nCells_); |
1191 | > | |
1192 | #ifdef IS_MPI | |
1193 | < | for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
1194 | < | j1 != cellListRow_[m1].end(); ++j1) { |
1195 | < | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
1196 | < | j2 != cellListCol_[m2].end(); ++j2) { |
1197 | < | |
1198 | < | // Always do this if we're in different cells or if |
1199 | < | // we're in the same cell and the global index of the |
1058 | < | // j2 cutoff group is less than the j1 cutoff group |
1059 | < | |
1060 | < | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
1193 | > | for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
1194 | > | j1 != cellListRow_[m1].end(); ++j1) { |
1195 | > | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
1196 | > | j2 != cellListCol_[m2].end(); ++j2) { |
1197 | > | |
1198 | > | // In parallel, we need to visit *all* pairs of row & |
1199 | > | // column indicies and will truncate later on. |
1200 | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; | |
1201 | snap_->wrapVector(dr); | |
1202 | cuts = getGroupCutoffs( (*j1), (*j2) ); | |
1203 | if (dr.lengthSquare() < cuts.third) { | |
1204 | neighborList.push_back(make_pair((*j1), (*j2))); | |
1205 | < | } |
1205 | > | } |
1206 | } | |
1207 | } | |
1069 | – | } |
1208 | #else | |
1209 | < | for (vector<int>::iterator j1 = cellList_[m1].begin(); |
1210 | < | j1 != cellList_[m1].end(); ++j1) { |
1211 | < | for (vector<int>::iterator j2 = cellList_[m2].begin(); |
1212 | < | j2 != cellList_[m2].end(); ++j2) { |
1213 | < | |
1214 | < | // Always do this if we're in different cells or if |
1215 | < | // we're in the same cell and the global index of the |
1216 | < | // j2 cutoff group is less than the j1 cutoff group |
1217 | < | |
1218 | < | if (m2 != m1 || (*j2) < (*j1)) { |
1219 | < | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
1220 | < | snap_->wrapVector(dr); |
1221 | < | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1222 | < | if (dr.lengthSquare() < cuts.third) { |
1223 | < | neighborList.push_back(make_pair((*j1), (*j2))); |
1209 | > | |
1210 | > | for (vector<int>::iterator j1 = cellList_[m1].begin(); |
1211 | > | j1 != cellList_[m1].end(); ++j1) { |
1212 | > | for (vector<int>::iterator j2 = cellList_[m2].begin(); |
1213 | > | j2 != cellList_[m2].end(); ++j2) { |
1214 | > | |
1215 | > | // Always do this if we're in different cells or if |
1216 | > | // we're in the same cell and the global index of the |
1217 | > | // j2 cutoff group is less than the j1 cutoff group |
1218 | > | |
1219 | > | if (m2 != m1 || (*j2) < (*j1)) { |
1220 | > | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
1221 | > | snap_->wrapVector(dr); |
1222 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); |
1223 | > | if (dr.lengthSquare() < cuts.third) { |
1224 | > | neighborList.push_back(make_pair((*j1), (*j2))); |
1225 | > | } |
1226 | } | |
1227 | } | |
1228 | } | |
1089 | – | } |
1229 | #endif | |
1230 | + | } |
1231 | } | |
1232 | } | |
1233 | } | |
1234 | + | } else { |
1235 | + | // branch to do all cutoff group pairs |
1236 | + | #ifdef IS_MPI |
1237 | + | for (int j1 = 0; j1 < nGroupsInRow_; j1++) { |
1238 | + | for (int j2 = 0; j2 < nGroupsInCol_; j2++) { |
1239 | + | dr = cgColData.position[j2] - cgRowData.position[j1]; |
1240 | + | snap_->wrapVector(dr); |
1241 | + | cuts = getGroupCutoffs( j1, j2 ); |
1242 | + | if (dr.lengthSquare() < cuts.third) { |
1243 | + | neighborList.push_back(make_pair(j1, j2)); |
1244 | + | } |
1245 | + | } |
1246 | + | } |
1247 | + | #else |
1248 | + | for (int j1 = 0; j1 < nGroups_ - 1; j1++) { |
1249 | + | for (int j2 = j1 + 1; j2 < nGroups_; j2++) { |
1250 | + | dr = snap_->cgData.position[j2] - snap_->cgData.position[j1]; |
1251 | + | snap_->wrapVector(dr); |
1252 | + | cuts = getGroupCutoffs( j1, j2 ); |
1253 | + | if (dr.lengthSquare() < cuts.third) { |
1254 | + | neighborList.push_back(make_pair(j1, j2)); |
1255 | + | } |
1256 | + | } |
1257 | + | } |
1258 | + | #endif |
1259 | } | |
1260 | < | |
1260 | > | |
1261 | // save the local cutoff group positions for the check that is | |
1262 | // done on each loop: | |
1263 | saved_CG_positions_.clear(); | |
1264 | for (int i = 0; i < nGroups_; i++) | |
1265 | saved_CG_positions_.push_back(snap_->cgData.position[i]); | |
1266 | < | |
1266 | > | |
1267 | return neighborList; | |
1268 | } | |
1269 | } //end namespace OpenMD |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |