ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/parallel/ForceMatrixDecomposition.cpp
Revision: 1583
Committed: Thu Jun 16 22:00:08 2011 UTC (13 years, 10 months ago) by gezelter
File size: 36830 byte(s)
Log Message:
Bug squashing

File Contents

# User Rev Content
1 gezelter 1539 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 chuckv 1538 *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31     *
32     * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33     * research, please cite the appropriate papers when you publish your
34     * work. Good starting points are:
35     *
36     * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37     * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38     * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39     * [4] Vardeman & Gezelter, in progress (2009).
40     */
41 gezelter 1549 #include "parallel/ForceMatrixDecomposition.hpp"
42 gezelter 1539 #include "math/SquareMatrix3.hpp"
43 gezelter 1544 #include "nonbonded/NonBondedInteraction.hpp"
44     #include "brains/SnapshotManager.hpp"
45 gezelter 1570 #include "brains/PairList.hpp"
46 chuckv 1538
47 gezelter 1541 using namespace std;
48 gezelter 1539 namespace OpenMD {
49 chuckv 1538
50 gezelter 1544 /**
51     * distributeInitialData is essentially a copy of the older fortran
52     * SimulationSetup
53     */
54    
55 gezelter 1549 void ForceMatrixDecomposition::distributeInitialData() {
56 gezelter 1551 snap_ = sman_->getCurrentSnapshot();
57     storageLayout_ = sman_->getStorageLayout();
58 gezelter 1571 ff_ = info_->getForceField();
59 gezelter 1567 nLocal_ = snap_->getNumberOfAtoms();
60 chuckv 1538
61 gezelter 1577 nGroups_ = info_->getNLocalCutoffGroups();
62 gezelter 1579 cerr << "in dId, nGroups = " << nGroups_ << "\n";
63 gezelter 1569 // gather the information for atomtype IDs (atids):
64 gezelter 1583 idents = info_->getIdentArray();
65 gezelter 1569 AtomLocalToGlobal = info_->getGlobalAtomIndices();
66     cgLocalToGlobal = info_->getGlobalGroupIndices();
67     vector<int> globalGroupMembership = info_->getGlobalGroupMembership();
68 gezelter 1581 massFactors = info_->getMassFactors();
69 gezelter 1570 PairList excludes = info_->getExcludedInteractions();
70     PairList oneTwo = info_->getOneTwoInteractions();
71     PairList oneThree = info_->getOneThreeInteractions();
72     PairList oneFour = info_->getOneFourInteractions();
73 gezelter 1569
74 gezelter 1567 #ifdef IS_MPI
75    
76     AtomCommIntRow = new Communicator<Row,int>(nLocal_);
77     AtomCommRealRow = new Communicator<Row,RealType>(nLocal_);
78     AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_);
79     AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_);
80 gezelter 1575 AtomCommPotRow = new Communicator<Row,potVec>(nLocal_);
81 chuckv 1538
82 gezelter 1567 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 gezelter 1575 AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_);
87 gezelter 1541
88 gezelter 1567 cgCommIntRow = new Communicator<Row,int>(nGroups_);
89     cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_);
90     cgCommIntColumn = new Communicator<Column,int>(nGroups_);
91     cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_);
92 gezelter 1551
93 gezelter 1567 nAtomsInRow_ = AtomCommIntRow->getSize();
94     nAtomsInCol_ = AtomCommIntColumn->getSize();
95     nGroupsInRow_ = cgCommIntRow->getSize();
96     nGroupsInCol_ = cgCommIntColumn->getSize();
97    
98 gezelter 1551 // Modify the data storage objects with the correct layouts and sizes:
99 gezelter 1567 atomRowData.resize(nAtomsInRow_);
100 gezelter 1551 atomRowData.setStorageLayout(storageLayout_);
101 gezelter 1567 atomColData.resize(nAtomsInCol_);
102 gezelter 1551 atomColData.setStorageLayout(storageLayout_);
103 gezelter 1567 cgRowData.resize(nGroupsInRow_);
104 gezelter 1551 cgRowData.setStorageLayout(DataStorage::dslPosition);
105 gezelter 1567 cgColData.resize(nGroupsInCol_);
106 gezelter 1551 cgColData.setStorageLayout(DataStorage::dslPosition);
107 gezelter 1575
108 gezelter 1577 identsRow.resize(nAtomsInRow_);
109     identsCol.resize(nAtomsInCol_);
110 gezelter 1549
111 gezelter 1583 AtomCommIntRow->gather(idents, identsRow);
112     AtomCommIntColumn->gather(idents, identsCol);
113 gezelter 1549
114     AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal);
115     AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal);
116    
117     cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
118     cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal);
119 gezelter 1541
120 gezelter 1581 AtomCommRealRow->gather(massFactors, massFactorsRow);
121     AtomCommRealColumn->gather(massFactors, massFactorsCol);
122 gezelter 1569
123     groupListRow_.clear();
124 gezelter 1577 groupListRow_.resize(nGroupsInRow_);
125 gezelter 1569 for (int i = 0; i < nGroupsInRow_; i++) {
126     int gid = cgRowToGlobal[i];
127     for (int j = 0; j < nAtomsInRow_; j++) {
128     int aid = AtomRowToGlobal[j];
129     if (globalGroupMembership[aid] == gid)
130     groupListRow_[i].push_back(j);
131     }
132     }
133    
134     groupListCol_.clear();
135 gezelter 1577 groupListCol_.resize(nGroupsInCol_);
136 gezelter 1569 for (int i = 0; i < nGroupsInCol_; i++) {
137     int gid = cgColToGlobal[i];
138     for (int j = 0; j < nAtomsInCol_; j++) {
139     int aid = AtomColToGlobal[j];
140     if (globalGroupMembership[aid] == gid)
141     groupListCol_[i].push_back(j);
142     }
143     }
144    
145 gezelter 1579 skipsForAtom.clear();
146     skipsForAtom.resize(nAtomsInRow_);
147     toposForAtom.clear();
148     toposForAtom.resize(nAtomsInRow_);
149     topoDist.clear();
150     topoDist.resize(nAtomsInRow_);
151 gezelter 1570 for (int i = 0; i < nAtomsInRow_; i++) {
152 gezelter 1571 int iglob = AtomRowToGlobal[i];
153 gezelter 1579
154 gezelter 1570 for (int j = 0; j < nAtomsInCol_; j++) {
155 gezelter 1579 int jglob = AtomColToGlobal[j];
156    
157 gezelter 1570 if (excludes.hasPair(iglob, jglob))
158 gezelter 1579 skipsForAtom[i].push_back(j);
159    
160 gezelter 1570 if (oneTwo.hasPair(iglob, jglob)) {
161 gezelter 1579 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 gezelter 1570 }
174     }
175     }
176    
177 gezelter 1569 #endif
178 gezelter 1579
179 gezelter 1569 groupList_.clear();
180 gezelter 1577 groupList_.resize(nGroups_);
181 gezelter 1569 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 gezelter 1577 if (globalGroupMembership[aid] == gid) {
186 gezelter 1569 groupList_[i].push_back(j);
187 gezelter 1577 }
188 gezelter 1569 }
189     }
190    
191 gezelter 1579 skipsForAtom.clear();
192     skipsForAtom.resize(nLocal_);
193     toposForAtom.clear();
194     toposForAtom.resize(nLocal_);
195     topoDist.clear();
196     topoDist.resize(nLocal_);
197 gezelter 1569
198 gezelter 1570 for (int i = 0; i < nLocal_; i++) {
199     int iglob = AtomLocalToGlobal[i];
200 gezelter 1579
201 gezelter 1570 for (int j = 0; j < nLocal_; j++) {
202 gezelter 1579 int jglob = AtomLocalToGlobal[j];
203    
204 gezelter 1570 if (excludes.hasPair(iglob, jglob))
205 gezelter 1579 skipsForAtom[i].push_back(j);
206    
207 gezelter 1570 if (oneTwo.hasPair(iglob, jglob)) {
208 gezelter 1579 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 gezelter 1570 }
221     }
222 gezelter 1579 }
223    
224     createGtypeCutoffMap();
225 gezelter 1576 }
226    
227     void ForceMatrixDecomposition::createGtypeCutoffMap() {
228    
229     RealType tol = 1e-6;
230     RealType rc;
231     int atid;
232     set<AtomType*> atypes = info_->getSimulatedAtomTypes();
233     vector<RealType> atypeCutoff;
234 gezelter 1577 atypeCutoff.resize( atypes.size() );
235 gezelter 1583
236 gezelter 1579 for (set<AtomType*>::iterator at = atypes.begin();
237     at != atypes.end(); ++at){
238 gezelter 1576 atid = (*at)->getIdent();
239 gezelter 1583
240     if (userChoseCutoff_)
241     atypeCutoff[atid] = userCutoff_;
242     else
243     atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at);
244 gezelter 1570 }
245 gezelter 1576
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 gezelter 1579 groupRowToGtype.resize(nGroupsInRow_);
253 gezelter 1576 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 gezelter 1579 groupColToGtype.resize(nGroupsInCol_);
279 gezelter 1576 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 gezelter 1579
303 gezelter 1576 vector<RealType> groupCutoff(nGroups_, 0.0);
304 gezelter 1579 groupToGtype.resize(nGroups_);
305    
306     cerr << "nGroups = " << nGroups_ << "\n";
307 gezelter 1576 for (int cg1 = 0; cg1 < nGroups_; cg1++) {
308 gezelter 1579
309 gezelter 1576 groupCutoff[cg1] = 0.0;
310     vector<int> atomList = getAtomsInGroupRow(cg1);
311 gezelter 1579
312 gezelter 1576 for (vector<int>::iterator ia = atomList.begin();
313     ia != atomList.end(); ++ia) {
314     int atom1 = (*ia);
315 gezelter 1583 atid = idents[atom1];
316 gezelter 1576 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 gezelter 1579 cerr << "gTypeCutoffs.size() = " << gTypeCutoffs.size() << "\n";
336 gezelter 1576 // Now we find the maximum group cutoff value present in the simulation
337    
338 gezelter 1579 RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end());
339 gezelter 1576
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 gezelter 1579 for (int j = 0; j < gTypeCutoffs.size(); j++) {
348 gezelter 1576 RealType thisRcut;
349     switch(cutoffPolicy_) {
350     case TRADITIONAL:
351     thisRcut = tradRcut;
352 gezelter 1579 break;
353 gezelter 1576 case MIX:
354     thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]);
355 gezelter 1579 break;
356 gezelter 1576 case MAX:
357     thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]);
358 gezelter 1579 break;
359 gezelter 1576 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 gezelter 1579 simError();
366     break;
367 gezelter 1576 }
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 gezelter 1583 "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_);
385 gezelter 1576 painCave.severity = OPENMD_ERROR;
386     painCave.isFatal = 1;
387     simError();
388     }
389     }
390     }
391     }
392 gezelter 1539 }
393 gezelter 1576
394    
395     groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) {
396 gezelter 1579 int i, j;
397 gezelter 1576 #ifdef IS_MPI
398     i = groupRowToGtype[cg1];
399     j = groupColToGtype[cg2];
400     #else
401     i = groupToGtype[cg1];
402     j = groupToGtype[cg2];
403 gezelter 1579 #endif
404 gezelter 1576 return gTypeCutoffMap[make_pair(i,j)];
405     }
406    
407 gezelter 1579 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 gezelter 1576
415 gezelter 1575 void ForceMatrixDecomposition::zeroWorkArrays() {
416 gezelter 1583 pairwisePot = 0.0;
417     embeddingPot = 0.0;
418 gezelter 1575
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 gezelter 1583 Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
435 gezelter 1575
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 gezelter 1549 void ForceMatrixDecomposition::distributeData() {
483 gezelter 1551 snap_ = sman_->getCurrentSnapshot();
484     storageLayout_ = sman_->getStorageLayout();
485 chuckv 1538 #ifdef IS_MPI
486 gezelter 1540
487 gezelter 1539 // gather up the atomic positions
488 gezelter 1551 AtomCommVectorRow->gather(snap_->atomData.position,
489     atomRowData.position);
490     AtomCommVectorColumn->gather(snap_->atomData.position,
491     atomColData.position);
492 gezelter 1539
493     // gather up the cutoff group positions
494 gezelter 1551 cgCommVectorRow->gather(snap_->cgData.position,
495     cgRowData.position);
496     cgCommVectorColumn->gather(snap_->cgData.position,
497     cgColData.position);
498 gezelter 1539
499     // if needed, gather the atomic rotation matrices
500 gezelter 1551 if (storageLayout_ & DataStorage::dslAmat) {
501     AtomCommMatrixRow->gather(snap_->atomData.aMat,
502     atomRowData.aMat);
503     AtomCommMatrixColumn->gather(snap_->atomData.aMat,
504     atomColData.aMat);
505 gezelter 1539 }
506    
507     // if needed, gather the atomic eletrostatic frames
508 gezelter 1551 if (storageLayout_ & DataStorage::dslElectroFrame) {
509     AtomCommMatrixRow->gather(snap_->atomData.electroFrame,
510     atomRowData.electroFrame);
511     AtomCommMatrixColumn->gather(snap_->atomData.electroFrame,
512     atomColData.electroFrame);
513 gezelter 1539 }
514     #endif
515     }
516    
517 gezelter 1575 /* collects information obtained during the pre-pair loop onto local
518     * data structures.
519     */
520 gezelter 1549 void ForceMatrixDecomposition::collectIntermediateData() {
521 gezelter 1551 snap_ = sman_->getCurrentSnapshot();
522     storageLayout_ = sman_->getStorageLayout();
523 gezelter 1539 #ifdef IS_MPI
524    
525 gezelter 1551 if (storageLayout_ & DataStorage::dslDensity) {
526    
527     AtomCommRealRow->scatter(atomRowData.density,
528     snap_->atomData.density);
529    
530     int n = snap_->atomData.density.size();
531 gezelter 1575 vector<RealType> rho_tmp(n, 0.0);
532 gezelter 1551 AtomCommRealColumn->scatter(atomColData.density, rho_tmp);
533 gezelter 1539 for (int i = 0; i < n; i++)
534 gezelter 1551 snap_->atomData.density[i] += rho_tmp[i];
535 gezelter 1539 }
536 chuckv 1538 #endif
537 gezelter 1539 }
538 gezelter 1575
539     /*
540     * redistributes information obtained during the pre-pair loop out to
541     * row and column-indexed data structures
542     */
543 gezelter 1549 void ForceMatrixDecomposition::distributeIntermediateData() {
544 gezelter 1551 snap_ = sman_->getCurrentSnapshot();
545     storageLayout_ = sman_->getStorageLayout();
546 chuckv 1538 #ifdef IS_MPI
547 gezelter 1551 if (storageLayout_ & DataStorage::dslFunctional) {
548     AtomCommRealRow->gather(snap_->atomData.functional,
549     atomRowData.functional);
550     AtomCommRealColumn->gather(snap_->atomData.functional,
551     atomColData.functional);
552 gezelter 1539 }
553    
554 gezelter 1551 if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
555     AtomCommRealRow->gather(snap_->atomData.functionalDerivative,
556     atomRowData.functionalDerivative);
557     AtomCommRealColumn->gather(snap_->atomData.functionalDerivative,
558     atomColData.functionalDerivative);
559 gezelter 1539 }
560 chuckv 1538 #endif
561     }
562 gezelter 1539
563    
564 gezelter 1549 void ForceMatrixDecomposition::collectData() {
565 gezelter 1551 snap_ = sman_->getCurrentSnapshot();
566     storageLayout_ = sman_->getStorageLayout();
567     #ifdef IS_MPI
568     int n = snap_->atomData.force.size();
569 gezelter 1544 vector<Vector3d> frc_tmp(n, V3Zero);
570 gezelter 1541
571 gezelter 1551 AtomCommVectorRow->scatter(atomRowData.force, frc_tmp);
572 gezelter 1541 for (int i = 0; i < n; i++) {
573 gezelter 1551 snap_->atomData.force[i] += frc_tmp[i];
574 gezelter 1541 frc_tmp[i] = 0.0;
575     }
576 gezelter 1540
577 gezelter 1551 AtomCommVectorColumn->scatter(atomColData.force, frc_tmp);
578 gezelter 1540 for (int i = 0; i < n; i++)
579 gezelter 1551 snap_->atomData.force[i] += frc_tmp[i];
580 gezelter 1540
581    
582 gezelter 1551 if (storageLayout_ & DataStorage::dslTorque) {
583 gezelter 1541
584 gezelter 1551 int nt = snap_->atomData.force.size();
585 gezelter 1544 vector<Vector3d> trq_tmp(nt, V3Zero);
586 gezelter 1541
587 gezelter 1551 AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp);
588 gezelter 1541 for (int i = 0; i < n; i++) {
589 gezelter 1551 snap_->atomData.torque[i] += trq_tmp[i];
590 gezelter 1541 trq_tmp[i] = 0.0;
591     }
592 gezelter 1540
593 gezelter 1551 AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp);
594 gezelter 1540 for (int i = 0; i < n; i++)
595 gezelter 1551 snap_->atomData.torque[i] += trq_tmp[i];
596 gezelter 1540 }
597    
598 gezelter 1567 nLocal_ = snap_->getNumberOfAtoms();
599 gezelter 1544
600 gezelter 1575 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 gezelter 1583 pairwisePot += pot_temp[ii];
609 gezelter 1540
610 gezelter 1575 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 gezelter 1583 pairwisePot += pot_temp[ii];
617 gezelter 1539 #endif
618 gezelter 1583
619 chuckv 1538 }
620 gezelter 1551
621 gezelter 1570 int ForceMatrixDecomposition::getNAtomsInRow() {
622     #ifdef IS_MPI
623     return nAtomsInRow_;
624     #else
625     return nLocal_;
626     #endif
627     }
628    
629 gezelter 1569 /**
630     * returns the list of atoms belonging to this group.
631     */
632     vector<int> ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){
633     #ifdef IS_MPI
634     return groupListRow_[cg1];
635     #else
636     return groupList_[cg1];
637     #endif
638     }
639    
640     vector<int> ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){
641     #ifdef IS_MPI
642     return groupListCol_[cg2];
643     #else
644     return groupList_[cg2];
645     #endif
646     }
647 chuckv 1538
648 gezelter 1551 Vector3d ForceMatrixDecomposition::getIntergroupVector(int cg1, int cg2){
649     Vector3d d;
650    
651     #ifdef IS_MPI
652     d = cgColData.position[cg2] - cgRowData.position[cg1];
653     #else
654     d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1];
655     #endif
656    
657     snap_->wrapVector(d);
658     return d;
659     }
660    
661    
662     Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){
663    
664     Vector3d d;
665    
666     #ifdef IS_MPI
667     d = cgRowData.position[cg1] - atomRowData.position[atom1];
668     #else
669     d = snap_->cgData.position[cg1] - snap_->atomData.position[atom1];
670     #endif
671    
672     snap_->wrapVector(d);
673     return d;
674     }
675    
676     Vector3d ForceMatrixDecomposition::getAtomToGroupVectorColumn(int atom2, int cg2){
677     Vector3d d;
678    
679     #ifdef IS_MPI
680     d = cgColData.position[cg2] - atomColData.position[atom2];
681     #else
682     d = snap_->cgData.position[cg2] - snap_->atomData.position[atom2];
683     #endif
684    
685     snap_->wrapVector(d);
686     return d;
687     }
688 gezelter 1569
689     RealType ForceMatrixDecomposition::getMassFactorRow(int atom1) {
690     #ifdef IS_MPI
691     return massFactorsRow[atom1];
692     #else
693 gezelter 1581 return massFactors[atom1];
694 gezelter 1569 #endif
695     }
696    
697     RealType ForceMatrixDecomposition::getMassFactorColumn(int atom2) {
698     #ifdef IS_MPI
699     return massFactorsCol[atom2];
700     #else
701 gezelter 1581 return massFactors[atom2];
702 gezelter 1569 #endif
703    
704     }
705 gezelter 1551
706     Vector3d ForceMatrixDecomposition::getInteratomicVector(int atom1, int atom2){
707     Vector3d d;
708    
709     #ifdef IS_MPI
710     d = atomColData.position[atom2] - atomRowData.position[atom1];
711     #else
712     d = snap_->atomData.position[atom2] - snap_->atomData.position[atom1];
713     #endif
714    
715     snap_->wrapVector(d);
716     return d;
717     }
718    
719 gezelter 1579 vector<int> ForceMatrixDecomposition::getSkipsForAtom(int atom1) {
720     return skipsForAtom[atom1];
721 gezelter 1570 }
722    
723     /**
724 gezelter 1575 * 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 gezelter 1570 */
730     bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) {
731     int unique_id_1, unique_id_2;
732    
733     #ifdef IS_MPI
734     // in MPI, we have to look up the unique IDs for each atom
735     unique_id_1 = AtomRowToGlobal[atom1];
736     unique_id_2 = AtomColToGlobal[atom2];
737    
738     // this situation should only arise in MPI simulations
739     if (unique_id_1 == unique_id_2) return true;
740    
741     // this prevents us from doing the pair on multiple processors
742     if (unique_id_1 < unique_id_2) {
743     if ((unique_id_1 + unique_id_2) % 2 == 0) return true;
744     } else {
745     if ((unique_id_1 + unique_id_2) % 2 == 1) return true;
746     }
747     #else
748     // in the normal loop, the atom numbers are unique
749     unique_id_1 = atom1;
750     unique_id_2 = atom2;
751     #endif
752    
753 gezelter 1579 for (vector<int>::iterator i = skipsForAtom[atom1].begin();
754     i != skipsForAtom[atom1].end(); ++i) {
755 gezelter 1570 if ( (*i) == unique_id_2 ) return true;
756 gezelter 1583 }
757 gezelter 1579
758 gezelter 1583 return false;
759 gezelter 1570 }
760    
761    
762 gezelter 1551 void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){
763     #ifdef IS_MPI
764     atomRowData.force[atom1] += fg;
765     #else
766     snap_->atomData.force[atom1] += fg;
767     #endif
768     }
769    
770     void ForceMatrixDecomposition::addForceToAtomColumn(int atom2, Vector3d fg){
771     #ifdef IS_MPI
772     atomColData.force[atom2] += fg;
773     #else
774     snap_->atomData.force[atom2] += fg;
775     #endif
776     }
777    
778     // filling interaction blocks with pointers
779 gezelter 1582 void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat,
780 gezelter 1581 int atom1, int atom2) {
781 gezelter 1551 #ifdef IS_MPI
782 gezelter 1571
783     idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
784     ff_->getAtomType(identsCol[atom2]) );
785 gezelter 1575
786 gezelter 1551 if (storageLayout_ & DataStorage::dslAmat) {
787 gezelter 1554 idat.A1 = &(atomRowData.aMat[atom1]);
788     idat.A2 = &(atomColData.aMat[atom2]);
789 gezelter 1551 }
790 gezelter 1567
791 gezelter 1551 if (storageLayout_ & DataStorage::dslElectroFrame) {
792 gezelter 1554 idat.eFrame1 = &(atomRowData.electroFrame[atom1]);
793     idat.eFrame2 = &(atomColData.electroFrame[atom2]);
794 gezelter 1551 }
795    
796     if (storageLayout_ & DataStorage::dslTorque) {
797 gezelter 1554 idat.t1 = &(atomRowData.torque[atom1]);
798     idat.t2 = &(atomColData.torque[atom2]);
799 gezelter 1551 }
800    
801     if (storageLayout_ & DataStorage::dslDensity) {
802 gezelter 1554 idat.rho1 = &(atomRowData.density[atom1]);
803     idat.rho2 = &(atomColData.density[atom2]);
804 gezelter 1551 }
805    
806 gezelter 1575 if (storageLayout_ & DataStorage::dslFunctional) {
807     idat.frho1 = &(atomRowData.functional[atom1]);
808     idat.frho2 = &(atomColData.functional[atom2]);
809     }
810    
811 gezelter 1551 if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
812 gezelter 1554 idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]);
813     idat.dfrho2 = &(atomColData.functionalDerivative[atom2]);
814 gezelter 1551 }
815 gezelter 1570
816 gezelter 1575 if (storageLayout_ & DataStorage::dslParticlePot) {
817     idat.particlePot1 = &(atomRowData.particlePot[atom1]);
818     idat.particlePot2 = &(atomColData.particlePot[atom2]);
819     }
820    
821 gezelter 1562 #else
822 gezelter 1571
823 gezelter 1583 idat.atypes = make_pair( ff_->getAtomType(idents[atom1]),
824     ff_->getAtomType(idents[atom2]) );
825 gezelter 1571
826 gezelter 1562 if (storageLayout_ & DataStorage::dslAmat) {
827     idat.A1 = &(snap_->atomData.aMat[atom1]);
828     idat.A2 = &(snap_->atomData.aMat[atom2]);
829     }
830    
831     if (storageLayout_ & DataStorage::dslElectroFrame) {
832     idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]);
833     idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]);
834     }
835    
836     if (storageLayout_ & DataStorage::dslTorque) {
837     idat.t1 = &(snap_->atomData.torque[atom1]);
838     idat.t2 = &(snap_->atomData.torque[atom2]);
839     }
840    
841 gezelter 1583 if (storageLayout_ & DataStorage::dslDensity) {
842 gezelter 1562 idat.rho1 = &(snap_->atomData.density[atom1]);
843     idat.rho2 = &(snap_->atomData.density[atom2]);
844     }
845    
846 gezelter 1575 if (storageLayout_ & DataStorage::dslFunctional) {
847     idat.frho1 = &(snap_->atomData.functional[atom1]);
848     idat.frho2 = &(snap_->atomData.functional[atom2]);
849     }
850    
851 gezelter 1562 if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
852     idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]);
853     idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]);
854     }
855 gezelter 1575
856     if (storageLayout_ & DataStorage::dslParticlePot) {
857     idat.particlePot1 = &(snap_->atomData.particlePot[atom1]);
858     idat.particlePot2 = &(snap_->atomData.particlePot[atom2]);
859     }
860    
861 gezelter 1551 #endif
862     }
863 gezelter 1567
864 gezelter 1575
865 gezelter 1582 void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) {
866 gezelter 1575 #ifdef IS_MPI
867     pot_row[atom1] += 0.5 * *(idat.pot);
868     pot_col[atom2] += 0.5 * *(idat.pot);
869    
870     atomRowData.force[atom1] += *(idat.f1);
871     atomColData.force[atom2] -= *(idat.f1);
872     #else
873 gezelter 1583 pairwisePot += *(idat.pot);
874    
875 gezelter 1575 snap_->atomData.force[atom1] += *(idat.f1);
876     snap_->atomData.force[atom2] -= *(idat.f1);
877     #endif
878    
879     }
880    
881    
882 gezelter 1582 void ForceMatrixDecomposition::fillSkipData(InteractionData &idat,
883 gezelter 1581 int atom1, int atom2) {
884 gezelter 1583 // Still Missing:: skippedCharge fill must be added to DataStorage
885 gezelter 1562 #ifdef IS_MPI
886 gezelter 1571 idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
887     ff_->getAtomType(identsCol[atom2]) );
888    
889 gezelter 1562 if (storageLayout_ & DataStorage::dslElectroFrame) {
890     idat.eFrame1 = &(atomRowData.electroFrame[atom1]);
891     idat.eFrame2 = &(atomColData.electroFrame[atom2]);
892     }
893     if (storageLayout_ & DataStorage::dslTorque) {
894     idat.t1 = &(atomRowData.torque[atom1]);
895     idat.t2 = &(atomColData.torque[atom2]);
896     }
897 gezelter 1567 #else
898 gezelter 1583 idat.atypes = make_pair( ff_->getAtomType(idents[atom1]),
899     ff_->getAtomType(idents[atom2]) );
900 gezelter 1571
901 gezelter 1567 if (storageLayout_ & DataStorage::dslElectroFrame) {
902     idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]);
903     idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]);
904     }
905     if (storageLayout_ & DataStorage::dslTorque) {
906     idat.t1 = &(snap_->atomData.torque[atom1]);
907     idat.t2 = &(snap_->atomData.torque[atom2]);
908     }
909 gezelter 1571 #endif
910 gezelter 1551 }
911 gezelter 1567
912 gezelter 1583
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 gezelter 1562 /*
925     * buildNeighborList
926     *
927     * first element of pair is row-indexed CutoffGroup
928     * second element of pair is column-indexed CutoffGroup
929     */
930 gezelter 1567 vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() {
931    
932     vector<pair<int, int> > neighborList;
933 gezelter 1576 groupCutoffs cuts;
934 gezelter 1567 #ifdef IS_MPI
935 gezelter 1568 cellListRow_.clear();
936     cellListCol_.clear();
937 gezelter 1567 #else
938 gezelter 1568 cellList_.clear();
939 gezelter 1567 #endif
940 gezelter 1562
941 gezelter 1576 RealType rList_ = (largestRcut_ + skinThickness_);
942 gezelter 1567 RealType rl2 = rList_ * rList_;
943     Snapshot* snap_ = sman_->getCurrentSnapshot();
944 gezelter 1562 Mat3x3d Hmat = snap_->getHmat();
945     Vector3d Hx = Hmat.getColumn(0);
946     Vector3d Hy = Hmat.getColumn(1);
947     Vector3d Hz = Hmat.getColumn(2);
948    
949 gezelter 1568 nCells_.x() = (int) ( Hx.length() )/ rList_;
950     nCells_.y() = (int) ( Hy.length() )/ rList_;
951     nCells_.z() = (int) ( Hz.length() )/ rList_;
952 gezelter 1562
953 gezelter 1567 Mat3x3d invHmat = snap_->getInvHmat();
954     Vector3d rs, scaled, dr;
955     Vector3i whichCell;
956     int cellIndex;
957 gezelter 1579 int nCtot = nCells_.x() * nCells_.y() * nCells_.z();
958 gezelter 1567
959     #ifdef IS_MPI
960 gezelter 1579 cellListRow_.resize(nCtot);
961     cellListCol_.resize(nCtot);
962     #else
963     cellList_.resize(nCtot);
964     #endif
965 gezelter 1582
966 gezelter 1579 #ifdef IS_MPI
967 gezelter 1567 for (int i = 0; i < nGroupsInRow_; i++) {
968 gezelter 1562 rs = cgRowData.position[i];
969 gezelter 1581
970 gezelter 1567 // scaled positions relative to the box vectors
971     scaled = invHmat * rs;
972 gezelter 1581
973 gezelter 1567 // wrap the vector back into the unit box by subtracting integer box
974     // numbers
975 gezelter 1581 for (int j = 0; j < 3; j++) {
976 gezelter 1567 scaled[j] -= roundMe(scaled[j]);
977 gezelter 1581 scaled[j] += 0.5;
978     }
979 gezelter 1567
980     // find xyz-indices of cell that cutoffGroup is in.
981 gezelter 1568 whichCell.x() = nCells_.x() * scaled.x();
982     whichCell.y() = nCells_.y() * scaled.y();
983     whichCell.z() = nCells_.z() * scaled.z();
984 gezelter 1567
985     // find single index of this cell:
986 gezelter 1568 cellIndex = Vlinear(whichCell, nCells_);
987 gezelter 1581
988 gezelter 1567 // add this cutoff group to the list of groups in this cell;
989 gezelter 1568 cellListRow_[cellIndex].push_back(i);
990 gezelter 1562 }
991    
992 gezelter 1567 for (int i = 0; i < nGroupsInCol_; i++) {
993     rs = cgColData.position[i];
994 gezelter 1581
995 gezelter 1567 // scaled positions relative to the box vectors
996     scaled = invHmat * rs;
997 gezelter 1581
998 gezelter 1567 // wrap the vector back into the unit box by subtracting integer box
999     // numbers
1000 gezelter 1581 for (int j = 0; j < 3; j++) {
1001 gezelter 1567 scaled[j] -= roundMe(scaled[j]);
1002 gezelter 1581 scaled[j] += 0.5;
1003     }
1004 gezelter 1567
1005     // find xyz-indices of cell that cutoffGroup is in.
1006 gezelter 1568 whichCell.x() = nCells_.x() * scaled.x();
1007     whichCell.y() = nCells_.y() * scaled.y();
1008     whichCell.z() = nCells_.z() * scaled.z();
1009 gezelter 1567
1010     // find single index of this cell:
1011 gezelter 1568 cellIndex = Vlinear(whichCell, nCells_);
1012 gezelter 1581
1013 gezelter 1567 // add this cutoff group to the list of groups in this cell;
1014 gezelter 1568 cellListCol_[cellIndex].push_back(i);
1015 gezelter 1562 }
1016 gezelter 1567 #else
1017     for (int i = 0; i < nGroups_; i++) {
1018     rs = snap_->cgData.position[i];
1019 gezelter 1581
1020 gezelter 1567 // scaled positions relative to the box vectors
1021     scaled = invHmat * rs;
1022 gezelter 1581
1023 gezelter 1567 // wrap the vector back into the unit box by subtracting integer box
1024     // numbers
1025 gezelter 1581 for (int j = 0; j < 3; j++) {
1026 gezelter 1567 scaled[j] -= roundMe(scaled[j]);
1027 gezelter 1581 scaled[j] += 0.5;
1028     }
1029 gezelter 1567
1030     // find xyz-indices of cell that cutoffGroup is in.
1031 gezelter 1568 whichCell.x() = nCells_.x() * scaled.x();
1032     whichCell.y() = nCells_.y() * scaled.y();
1033     whichCell.z() = nCells_.z() * scaled.z();
1034 gezelter 1567
1035     // find single index of this cell:
1036 gezelter 1581 cellIndex = Vlinear(whichCell, nCells_);
1037    
1038 gezelter 1567 // add this cutoff group to the list of groups in this cell;
1039 gezelter 1568 cellList_[cellIndex].push_back(i);
1040 gezelter 1567 }
1041     #endif
1042    
1043 gezelter 1568 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++) {
1046 gezelter 1562 Vector3i m1v(m1x, m1y, m1z);
1047 gezelter 1568 int m1 = Vlinear(m1v, nCells_);
1048 gezelter 1562
1049 gezelter 1568 for (vector<Vector3i>::iterator os = cellOffsets_.begin();
1050     os != cellOffsets_.end(); ++os) {
1051    
1052     Vector3i m2v = m1v + (*os);
1053    
1054     if (m2v.x() >= nCells_.x()) {
1055 gezelter 1562 m2v.x() = 0;
1056     } else if (m2v.x() < 0) {
1057 gezelter 1568 m2v.x() = nCells_.x() - 1;
1058 gezelter 1562 }
1059 gezelter 1568
1060     if (m2v.y() >= nCells_.y()) {
1061 gezelter 1562 m2v.y() = 0;
1062     } else if (m2v.y() < 0) {
1063 gezelter 1568 m2v.y() = nCells_.y() - 1;
1064 gezelter 1562 }
1065 gezelter 1568
1066     if (m2v.z() >= nCells_.z()) {
1067 gezelter 1567 m2v.z() = 0;
1068     } else if (m2v.z() < 0) {
1069 gezelter 1568 m2v.z() = nCells_.z() - 1;
1070 gezelter 1567 }
1071 gezelter 1568
1072     int m2 = Vlinear (m2v, nCells_);
1073 gezelter 1567
1074     #ifdef IS_MPI
1075 gezelter 1568 for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1076     j1 != cellListRow_[m1].end(); ++j1) {
1077     for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1078     j2 != cellListCol_[m2].end(); ++j2) {
1079 gezelter 1567
1080     // Always do this if we're in different cells or if
1081     // we're in the same cell and the global index of the
1082     // j2 cutoff group is less than the j1 cutoff group
1083    
1084     if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) {
1085     dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)];
1086     snap_->wrapVector(dr);
1087 gezelter 1576 cuts = getGroupCutoffs( (*j1), (*j2) );
1088     if (dr.lengthSquare() < cuts.third) {
1089 gezelter 1567 neighborList.push_back(make_pair((*j1), (*j2)));
1090 gezelter 1562 }
1091     }
1092     }
1093     }
1094 gezelter 1567 #else
1095 gezelter 1581
1096 gezelter 1568 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 gezelter 1581
1101 gezelter 1567 // 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
1104    
1105     if (m2 != m1 || (*j2) < (*j1)) {
1106     dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1107     snap_->wrapVector(dr);
1108 gezelter 1576 cuts = getGroupCutoffs( (*j1), (*j2) );
1109     if (dr.lengthSquare() < cuts.third) {
1110 gezelter 1567 neighborList.push_back(make_pair((*j1), (*j2)));
1111     }
1112     }
1113     }
1114     }
1115     #endif
1116 gezelter 1562 }
1117     }
1118     }
1119     }
1120 gezelter 1581
1121 gezelter 1568 // 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 gezelter 1583
1127 gezelter 1567 return neighborList;
1128 gezelter 1562 }
1129 gezelter 1539 } //end namespace OpenMD