ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/parallel/ForceMatrixDecomposition.cpp
(Generate patch)

Comparing branches/development/src/parallel/ForceMatrixDecomposition.cpp (file contents):
Revision 1577 by gezelter, Wed Jun 8 20:26:56 2011 UTC vs.
Revision 1601 by gezelter, Thu Aug 4 20:04:35 2011 UTC

# 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();
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();
67    vector<RealType> massFactorsLocal = info_->getMassFactors();
68    PairList excludes = info_->getExcludedInteractions();
69    PairList oneTwo = info_->getOneTwoInteractions();
70    PairList oneThree = info_->getOneThreeInteractions();
71    PairList oneFour = info_->getOneFourInteractions();
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_);
77 <    AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_);
78 <    AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_);
79 <    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 107 | 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 <    
116 <    cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
117 <    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 +    cgRowToGlobal.resize(nGroupsInRow_);
158 +    cgColToGlobal.resize(nGroupsInCol_);
159 +    cgPlanIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
160 +    cgPlanIntColumn->gather(cgLocalToGlobal, cgColToGlobal);
161 +
162 +    massFactorsRow.resize(nAtomsInRow_);
163 +    massFactorsCol.resize(nAtomsInCol_);
164 +    AtomPlanRealRow->gather(massFactors, massFactorsRow);
165 +    AtomPlanRealColumn->gather(massFactors, massFactorsCol);
166 +
167      groupListRow_.clear();
168      groupListRow_.resize(nGroupsInRow_);
169      for (int i = 0; i < nGroupsInRow_; i++) {
# Line 141 | Line 186 | namespace OpenMD {
186        }      
187      }
188  
189 <    skipsForRowAtom.clear();
190 <    skipsForRowAtom.resize(nAtomsInRow_);
189 >    excludesForAtom.clear();
190 >    excludesForAtom.resize(nAtomsInRow_);
191 >    toposForAtom.clear();
192 >    toposForAtom.resize(nAtomsInRow_);
193 >    topoDist.clear();
194 >    topoDist.resize(nAtomsInRow_);
195      for (int i = 0; i < nAtomsInRow_; i++) {
196        int iglob = AtomRowToGlobal[i];
148      for (int j = 0; j < nAtomsInCol_; j++) {
149        int jglob = AtomColToGlobal[j];        
150        if (excludes.hasPair(iglob, jglob))
151          skipsForRowAtom[i].push_back(j);      
152      }      
153    }
197  
155    toposForRowAtom.clear();
156    toposForRowAtom.resize(nAtomsInRow_);
157    for (int i = 0; i < nAtomsInRow_; i++) {
158      int iglob = AtomRowToGlobal[i];
159      int nTopos = 0;
198        for (int j = 0; j < nAtomsInCol_; j++) {
199 <        int jglob = AtomColToGlobal[j];        
200 <        if (oneTwo.hasPair(iglob, jglob)) {
201 <          toposForRowAtom[i].push_back(j);
202 <          topoDistRow[i][nTopos] = 1;
203 <          nTopos++;
199 >        int jglob = AtomColToGlobal[j];
200 >
201 >        if (excludes->hasPair(iglob, jglob))
202 >          excludesForAtom[i].push_back(j);      
203 >        
204 >        if (oneTwo->hasPair(iglob, jglob)) {
205 >          toposForAtom[i].push_back(j);
206 >          topoDist[i].push_back(1);
207 >        } else {
208 >          if (oneThree->hasPair(iglob, jglob)) {
209 >            toposForAtom[i].push_back(j);
210 >            topoDist[i].push_back(2);
211 >          } else {
212 >            if (oneFour->hasPair(iglob, jglob)) {
213 >              toposForAtom[i].push_back(j);
214 >              topoDist[i].push_back(3);
215 >            }
216 >          }
217          }
167        if (oneThree.hasPair(iglob, jglob)) {
168          toposForRowAtom[i].push_back(j);
169          topoDistRow[i][nTopos] = 2;
170          nTopos++;
171        }
172        if (oneFour.hasPair(iglob, jglob)) {
173          toposForRowAtom[i].push_back(j);
174          topoDistRow[i][nTopos] = 3;
175          nTopos++;
176        }
218        }      
219      }
220  
221   #endif
222 +
223 +    // allocate memory for the parallel objects
224 +    atypesLocal.resize(nLocal_);
225 +
226 +    for (int i = 0; i < nLocal_; i++)
227 +      atypesLocal[i] = ff_->getAtomType(idents[i]);
228 +
229      groupList_.clear();
230      groupList_.resize(nGroups_);
231      for (int i = 0; i < nGroups_; i++) {
# Line 186 | Line 234 | namespace OpenMD {
234          int aid = AtomLocalToGlobal[j];
235          if (globalGroupMembership[aid] == gid) {
236            groupList_[i].push_back(j);
189
237          }
238        }      
239      }
240  
241 <    skipsForLocalAtom.clear();
242 <    skipsForLocalAtom.resize(nLocal_);
241 >    excludesForAtom.clear();
242 >    excludesForAtom.resize(nLocal_);
243 >    toposForAtom.clear();
244 >    toposForAtom.resize(nLocal_);
245 >    topoDist.clear();
246 >    topoDist.resize(nLocal_);
247  
248      for (int i = 0; i < nLocal_; i++) {
249        int iglob = AtomLocalToGlobal[i];
250 +
251        for (int j = 0; j < nLocal_; j++) {
252 <        int jglob = AtomLocalToGlobal[j];        
253 <        if (excludes.hasPair(iglob, jglob))
254 <          skipsForLocalAtom[i].push_back(j);      
255 <      }      
256 <    }
257 <    toposForLocalAtom.clear();
258 <    toposForLocalAtom.resize(nLocal_);
259 <    for (int i = 0; i < nLocal_; i++) {
260 <      int iglob = AtomLocalToGlobal[i];
261 <      int nTopos = 0;
262 <      for (int j = 0; j < nLocal_; j++) {
263 <        int jglob = AtomLocalToGlobal[j];        
264 <        if (oneTwo.hasPair(iglob, jglob)) {
265 <          toposForLocalAtom[i].push_back(j);
266 <          topoDistLocal[i][nTopos] = 1;
267 <          nTopos++;
252 >        int jglob = AtomLocalToGlobal[j];
253 >
254 >        if (excludes->hasPair(iglob, jglob))
255 >          excludesForAtom[i].push_back(j);              
256 >        
257 >        if (oneTwo->hasPair(iglob, jglob)) {
258 >          toposForAtom[i].push_back(j);
259 >          topoDist[i].push_back(1);
260 >        } else {
261 >          if (oneThree->hasPair(iglob, jglob)) {
262 >            toposForAtom[i].push_back(j);
263 >            topoDist[i].push_back(2);
264 >          } else {
265 >            if (oneFour->hasPair(iglob, jglob)) {
266 >              toposForAtom[i].push_back(j);
267 >              topoDist[i].push_back(3);
268 >            }
269 >          }
270          }
217        if (oneThree.hasPair(iglob, jglob)) {
218          toposForLocalAtom[i].push_back(j);
219          topoDistLocal[i][nTopos] = 2;
220          nTopos++;
221        }
222        if (oneFour.hasPair(iglob, jglob)) {
223          toposForLocalAtom[i].push_back(j);
224          topoDistLocal[i][nTopos] = 3;
225          nTopos++;
226        }
271        }      
272 <    }    
272 >    }
273 >    
274 >    createGtypeCutoffMap();
275  
276    }
277    
278    void ForceMatrixDecomposition::createGtypeCutoffMap() {
279 <
279 >    
280      RealType tol = 1e-6;
281 +    largestRcut_ = 0.0;
282      RealType rc;
283      int atid;
284      set<AtomType*> atypes = info_->getSimulatedAtomTypes();
285 <    vector<RealType> atypeCutoff;
286 <    atypeCutoff.resize( atypes.size() );
287 <
288 <    for (set<AtomType*>::iterator at = atypes.begin(); at != atypes.end(); ++at){
289 <      rc = interactionMan_->getSuggestedCutoffRadius(*at);
285 >    
286 >    map<int, RealType> atypeCutoff;
287 >      
288 >    for (set<AtomType*>::iterator at = atypes.begin();
289 >         at != atypes.end(); ++at){
290        atid = (*at)->getIdent();
291 <      atypeCutoff[atid] = rc;
291 >      if (userChoseCutoff_)
292 >        atypeCutoff[atid] = userCutoff_;
293 >      else
294 >        atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at);
295      }
296 <
296 >    
297      vector<RealType> gTypeCutoffs;
248
298      // first we do a single loop over the cutoff groups to find the
299      // largest cutoff for any atypes present in this group.
300   #ifdef IS_MPI
301      vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0);
302 +    groupRowToGtype.resize(nGroupsInRow_);
303      for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) {
304        vector<int> atomListRow = getAtomsInGroupRow(cg1);
305        for (vector<int>::iterator ia = atomListRow.begin();
# Line 275 | Line 325 | namespace OpenMD {
325        
326      }
327      vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0);
328 +    groupColToGtype.resize(nGroupsInCol_);
329      for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) {
330        vector<int> atomListCol = getAtomsInGroupColumn(cg2);
331        for (vector<int>::iterator jb = atomListCol.begin();
# Line 298 | Line 349 | namespace OpenMD {
349        }
350      }
351   #else
352 +
353      vector<RealType> groupCutoff(nGroups_, 0.0);
354 +    groupToGtype.resize(nGroups_);
355      for (int cg1 = 0; cg1 < nGroups_; cg1++) {
356        groupCutoff[cg1] = 0.0;
357        vector<int> atomList = getAtomsInGroupRow(cg1);
358        for (vector<int>::iterator ia = atomList.begin();
359             ia != atomList.end(); ++ia) {            
360          int atom1 = (*ia);
361 <        atid = identsLocal[atom1];
362 <        if (atypeCutoff[atid] > groupCutoff[cg1]) {
361 >        atid = idents[atom1];
362 >        if (atypeCutoff[atid] > groupCutoff[cg1])
363            groupCutoff[cg1] = atypeCutoff[atid];
311        }
364        }
365 <
365 >      
366        bool gTypeFound = false;
367        for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
368          if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) {
# Line 318 | Line 370 | namespace OpenMD {
370            gTypeFound = true;
371          }
372        }
373 <      if (!gTypeFound) {
373 >      if (!gTypeFound) {      
374          gTypeCutoffs.push_back( groupCutoff[cg1] );
375          groupToGtype[cg1] = gTypeCutoffs.size() - 1;
376        }      
# Line 327 | Line 379 | namespace OpenMD {
379  
380      // Now we find the maximum group cutoff value present in the simulation
381  
382 <    vector<RealType>::iterator groupMaxLoc = max_element(gTypeCutoffs.begin(), gTypeCutoffs.end());
383 <    RealType groupMax = *groupMaxLoc;
382 >    RealType groupMax = *max_element(gTypeCutoffs.begin(),
383 >                                     gTypeCutoffs.end());
384  
385   #ifdef IS_MPI
386 <    MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX);
386 >    MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE,
387 >                              MPI::MAX);
388   #endif
389      
390      RealType tradRcut = groupMax;
391  
392      for (int i = 0; i < gTypeCutoffs.size();  i++) {
393 <      for (int j = 0; j < gTypeCutoffs.size();  j++) {
341 <        
393 >      for (int j = 0; j < gTypeCutoffs.size();  j++) {      
394          RealType thisRcut;
395          switch(cutoffPolicy_) {
396          case TRADITIONAL:
397            thisRcut = tradRcut;
398 +          break;
399          case MIX:
400            thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]);
401 +          break;
402          case MAX:
403            thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]);
404 +          break;
405          default:
406            sprintf(painCave.errMsg,
407                    "ForceMatrixDecomposition::createGtypeCutoffMap "
408                    "hit an unknown cutoff policy!\n");
409            painCave.severity = OPENMD_ERROR;
410            painCave.isFatal = 1;
411 <          simError();              
411 >          simError();
412 >          break;
413          }
414  
415          pair<int,int> key = make_pair(i,j);
416          gTypeCutoffMap[key].first = thisRcut;
361
417          if (thisRcut > largestRcut_) largestRcut_ = thisRcut;
363
418          gTypeCutoffMap[key].second = thisRcut*thisRcut;
365        
419          gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
367
420          // sanity check
421          
422          if (userChoseCutoff_) {
423            if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) {
424              sprintf(painCave.errMsg,
425                      "ForceMatrixDecomposition::createGtypeCutoffMap "
426 <                    "user-specified rCut does not match computed group Cutoff\n");
426 >                    "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_);
427              painCave.severity = OPENMD_ERROR;
428              painCave.isFatal = 1;
429              simError();            
# Line 383 | Line 435 | namespace OpenMD {
435  
436  
437    groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) {
438 <    int i, j;
387 <
438 >    int i, j;  
439   #ifdef IS_MPI
440      i = groupRowToGtype[cg1];
441      j = groupColToGtype[cg2];
442   #else
443      i = groupToGtype[cg1];
444      j = groupToGtype[cg2];
445 < #endif
395 <    
445 > #endif    
446      return gTypeCutoffMap[make_pair(i,j)];
447    }
448  
449 +  int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) {
450 +    for (int j = 0; j < toposForAtom[atom1].size(); j++) {
451 +      if (toposForAtom[atom1][j] == atom2)
452 +        return topoDist[atom1][j];
453 +    }
454 +    return 0;
455 +  }
456  
457    void ForceMatrixDecomposition::zeroWorkArrays() {
458 +    pairwisePot = 0.0;
459 +    embeddingPot = 0.0;
460  
402    for (int j = 0; j < N_INTERACTION_FAMILIES; j++) {
403      longRangePot_[j] = 0.0;
404    }
405
461   #ifdef IS_MPI
462      if (storageLayout_ & DataStorage::dslForce) {
463        fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero);
# Line 418 | Line 473 | namespace OpenMD {
473           Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
474  
475      fill(pot_col.begin(), pot_col.end(),
476 <         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
422 <    
423 <    pot_local = Vector<RealType, N_INTERACTION_FAMILIES>(0.0);
476 >         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));  
477  
478      if (storageLayout_ & DataStorage::dslParticlePot) {    
479 <      fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0);
480 <      fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0);
479 >      fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(),
480 >           0.0);
481 >      fill(atomColData.particlePot.begin(), atomColData.particlePot.end(),
482 >           0.0);
483      }
484  
485      if (storageLayout_ & DataStorage::dslDensity) {      
# Line 433 | Line 488 | namespace OpenMD {
488      }
489  
490      if (storageLayout_ & DataStorage::dslFunctional) {  
491 <      fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0);
492 <      fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0);
491 >      fill(atomRowData.functional.begin(), atomRowData.functional.end(),
492 >           0.0);
493 >      fill(atomColData.functional.begin(), atomColData.functional.end(),
494 >           0.0);
495      }
496  
497      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {      
# Line 444 | Line 501 | namespace OpenMD {
501             atomColData.functionalDerivative.end(), 0.0);
502      }
503  
504 < #else
505 <    
504 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {      
505 >      fill(atomRowData.skippedCharge.begin(),
506 >           atomRowData.skippedCharge.end(), 0.0);
507 >      fill(atomColData.skippedCharge.begin(),
508 >           atomColData.skippedCharge.end(), 0.0);
509 >    }
510 >
511 > #endif
512 >    // even in parallel, we need to zero out the local arrays:
513 >
514      if (storageLayout_ & DataStorage::dslParticlePot) {      
515        fill(snap_->atomData.particlePot.begin(),
516             snap_->atomData.particlePot.end(), 0.0);
# Line 463 | Line 528 | namespace OpenMD {
528        fill(snap_->atomData.functionalDerivative.begin(),
529             snap_->atomData.functionalDerivative.end(), 0.0);
530      }
531 < #endif
531 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {      
532 >      fill(snap_->atomData.skippedCharge.begin(),
533 >           snap_->atomData.skippedCharge.end(), 0.0);
534 >    }
535      
536    }
537  
# Line 474 | Line 542 | namespace OpenMD {
542   #ifdef IS_MPI
543      
544      // gather up the atomic positions
545 <    AtomCommVectorRow->gather(snap_->atomData.position,
545 >    AtomPlanVectorRow->gather(snap_->atomData.position,
546                                atomRowData.position);
547 <    AtomCommVectorColumn->gather(snap_->atomData.position,
547 >    AtomPlanVectorColumn->gather(snap_->atomData.position,
548                                   atomColData.position);
549      
550      // gather up the cutoff group positions
551 <    cgCommVectorRow->gather(snap_->cgData.position,
551 >
552 >    cgPlanVectorRow->gather(snap_->cgData.position,
553                              cgRowData.position);
554 <    cgCommVectorColumn->gather(snap_->cgData.position,
554 >
555 >    cgPlanVectorColumn->gather(snap_->cgData.position,
556                                 cgColData.position);
557 +
558      
559      // if needed, gather the atomic rotation matrices
560      if (storageLayout_ & DataStorage::dslAmat) {
561 <      AtomCommMatrixRow->gather(snap_->atomData.aMat,
561 >      AtomPlanMatrixRow->gather(snap_->atomData.aMat,
562                                  atomRowData.aMat);
563 <      AtomCommMatrixColumn->gather(snap_->atomData.aMat,
563 >      AtomPlanMatrixColumn->gather(snap_->atomData.aMat,
564                                     atomColData.aMat);
565      }
566      
567      // if needed, gather the atomic eletrostatic frames
568      if (storageLayout_ & DataStorage::dslElectroFrame) {
569 <      AtomCommMatrixRow->gather(snap_->atomData.electroFrame,
569 >      AtomPlanMatrixRow->gather(snap_->atomData.electroFrame,
570                                  atomRowData.electroFrame);
571 <      AtomCommMatrixColumn->gather(snap_->atomData.electroFrame,
571 >      AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame,
572                                     atomColData.electroFrame);
573      }
574 +
575   #endif      
576    }
577    
# Line 513 | Line 585 | namespace OpenMD {
585      
586      if (storageLayout_ & DataStorage::dslDensity) {
587        
588 <      AtomCommRealRow->scatter(atomRowData.density,
588 >      AtomPlanRealRow->scatter(atomRowData.density,
589                                 snap_->atomData.density);
590        
591        int n = snap_->atomData.density.size();
592        vector<RealType> rho_tmp(n, 0.0);
593 <      AtomCommRealColumn->scatter(atomColData.density, rho_tmp);
593 >      AtomPlanRealColumn->scatter(atomColData.density, rho_tmp);
594        for (int i = 0; i < n; i++)
595          snap_->atomData.density[i] += rho_tmp[i];
596      }
# Line 534 | Line 606 | namespace OpenMD {
606      storageLayout_ = sman_->getStorageLayout();
607   #ifdef IS_MPI
608      if (storageLayout_ & DataStorage::dslFunctional) {
609 <      AtomCommRealRow->gather(snap_->atomData.functional,
609 >      AtomPlanRealRow->gather(snap_->atomData.functional,
610                                atomRowData.functional);
611 <      AtomCommRealColumn->gather(snap_->atomData.functional,
611 >      AtomPlanRealColumn->gather(snap_->atomData.functional,
612                                   atomColData.functional);
613      }
614      
615      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
616 <      AtomCommRealRow->gather(snap_->atomData.functionalDerivative,
616 >      AtomPlanRealRow->gather(snap_->atomData.functionalDerivative,
617                                atomRowData.functionalDerivative);
618 <      AtomCommRealColumn->gather(snap_->atomData.functionalDerivative,
618 >      AtomPlanRealColumn->gather(snap_->atomData.functionalDerivative,
619                                   atomColData.functionalDerivative);
620      }
621   #endif
# Line 557 | Line 629 | namespace OpenMD {
629      int n = snap_->atomData.force.size();
630      vector<Vector3d> frc_tmp(n, V3Zero);
631      
632 <    AtomCommVectorRow->scatter(atomRowData.force, frc_tmp);
632 >    AtomPlanVectorRow->scatter(atomRowData.force, frc_tmp);
633      for (int i = 0; i < n; i++) {
634        snap_->atomData.force[i] += frc_tmp[i];
635        frc_tmp[i] = 0.0;
636      }
637      
638 <    AtomCommVectorColumn->scatter(atomColData.force, frc_tmp);
639 <    for (int i = 0; i < n; i++)
638 >    AtomPlanVectorColumn->scatter(atomColData.force, frc_tmp);
639 >    for (int i = 0; i < n; i++) {
640        snap_->atomData.force[i] += frc_tmp[i];
641 <    
642 <    
641 >    }
642 >        
643      if (storageLayout_ & DataStorage::dslTorque) {
644  
645 <      int nt = snap_->atomData.force.size();
645 >      int nt = snap_->atomData.torque.size();
646        vector<Vector3d> trq_tmp(nt, V3Zero);
647  
648 <      AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp);
649 <      for (int i = 0; i < n; i++) {
648 >      AtomPlanVectorRow->scatter(atomRowData.torque, trq_tmp);
649 >      for (int i = 0; i < nt; i++) {
650          snap_->atomData.torque[i] += trq_tmp[i];
651          trq_tmp[i] = 0.0;
652        }
653        
654 <      AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp);
655 <      for (int i = 0; i < n; i++)
654 >      AtomPlanVectorColumn->scatter(atomColData.torque, trq_tmp);
655 >      for (int i = 0; i < nt; i++)
656          snap_->atomData.torque[i] += trq_tmp[i];
657      }
658 +
659 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {
660 +
661 +      int ns = snap_->atomData.skippedCharge.size();
662 +      vector<RealType> skch_tmp(ns, 0.0);
663 +
664 +      AtomPlanRealRow->scatter(atomRowData.skippedCharge, skch_tmp);
665 +      for (int i = 0; i < ns; i++) {
666 +        snap_->atomData.skippedCharge[i] += skch_tmp[i];
667 +        skch_tmp[i] = 0.0;
668 +      }
669 +      
670 +      AtomPlanRealColumn->scatter(atomColData.skippedCharge, skch_tmp);
671 +      for (int i = 0; i < ns; i++)
672 +        snap_->atomData.skippedCharge[i] += skch_tmp[i];
673 +    }
674      
675      nLocal_ = snap_->getNumberOfAtoms();
676  
# Line 591 | Line 679 | namespace OpenMD {
679  
680      // scatter/gather pot_row into the members of my column
681            
682 <    AtomCommPotRow->scatter(pot_row, pot_temp);
682 >    AtomPlanPotRow->scatter(pot_row, pot_temp);
683  
684      for (int ii = 0;  ii < pot_temp.size(); ii++ )
685 <      pot_local += pot_temp[ii];
685 >      pairwisePot += pot_temp[ii];
686      
687      fill(pot_temp.begin(), pot_temp.end(),
688           Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
689        
690 <    AtomCommPotColumn->scatter(pot_col, pot_temp);    
690 >    AtomPlanPotColumn->scatter(pot_col, pot_temp);    
691      
692      for (int ii = 0;  ii < pot_temp.size(); ii++ )
693 <      pot_local += pot_temp[ii];
693 >      pairwisePot += pot_temp[ii];    
694      
695 +    for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
696 +      RealType ploc1 = pairwisePot[ii];
697 +      RealType ploc2 = 0.0;
698 +      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
699 +      pairwisePot[ii] = ploc2;
700 +    }
701 +
702   #endif
703 +
704    }
705  
706    int ForceMatrixDecomposition::getNAtomsInRow() {  
# Line 679 | Line 775 | namespace OpenMD {
775   #ifdef IS_MPI
776      return massFactorsRow[atom1];
777   #else
778 <    return massFactorsLocal[atom1];
778 >    return massFactors[atom1];
779   #endif
780    }
781  
# Line 687 | Line 783 | namespace OpenMD {
783   #ifdef IS_MPI
784      return massFactorsCol[atom2];
785   #else
786 <    return massFactorsLocal[atom2];
786 >    return massFactors[atom2];
787   #endif
788  
789    }
# Line 705 | Line 801 | namespace OpenMD {
801      return d;    
802    }
803  
804 <  vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) {
805 < #ifdef IS_MPI
710 <    return skipsForRowAtom[atom1];
711 < #else
712 <    return skipsForLocalAtom[atom1];
713 < #endif
804 >  vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
805 >    return excludesForAtom[atom1];
806    }
807  
808    /**
809 <   * There are a number of reasons to skip a pair or a
718 <   * particle. Mostly we do this to exclude atoms who are involved in
719 <   * short range interactions (bonds, bends, torsions), but we also
720 <   * need to exclude some overcounted interactions that result from
809 >   * We need to exclude some overcounted interactions that result from
810     * the parallel decomposition.
811     */
812    bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) {
813      int unique_id_1, unique_id_2;
814 <
814 >    
815   #ifdef IS_MPI
816      // in MPI, we have to look up the unique IDs for each atom
817      unique_id_1 = AtomRowToGlobal[atom1];
# Line 737 | Line 826 | namespace OpenMD {
826      } else {
827        if ((unique_id_1 + unique_id_2) % 2 == 1) return true;
828      }
829 + #endif
830 +    return false;
831 +  }
832 +
833 +  /**
834 +   * We need to handle the interactions for atoms who are involved in
835 +   * the same rigid body as well as some short range interactions
836 +   * (bonds, bends, torsions) differently from other interactions.
837 +   * We'll still visit the pairwise routines, but with a flag that
838 +   * tells those routines to exclude the pair from direct long range
839 +   * interactions.  Some indirect interactions (notably reaction
840 +   * field) must still be handled for these pairs.
841 +   */
842 +  bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) {
843 +    int unique_id_2;
844 + #ifdef IS_MPI
845 +    // in MPI, we have to look up the unique IDs for the row atom.
846 +    unique_id_2 = AtomColToGlobal[atom2];
847   #else
848      // in the normal loop, the atom numbers are unique
742    unique_id_1 = atom1;
849      unique_id_2 = atom2;
850   #endif
851      
852 < #ifdef IS_MPI
853 <    for (vector<int>::iterator i = skipsForRowAtom[atom1].begin();
748 <         i != skipsForRowAtom[atom1].end(); ++i) {
852 >    for (vector<int>::iterator i = excludesForAtom[atom1].begin();
853 >         i != excludesForAtom[atom1].end(); ++i) {
854        if ( (*i) == unique_id_2 ) return true;
750    }    
751 #else
752    for (vector<int>::iterator i = skipsForLocalAtom[atom1].begin();
753         i != skipsForLocalAtom[atom1].end(); ++i) {
754      if ( (*i) == unique_id_2 ) return true;
755    }    
756 #endif
757  }
758
759  int ForceMatrixDecomposition::getTopoDistance(int atom1, int atom2) {
760    
761 #ifdef IS_MPI
762    for (int i = 0; i < toposForRowAtom[atom1].size(); i++) {
763      if ( toposForRowAtom[atom1][i] == atom2 ) return topoDistRow[atom1][i];
855      }
765 #else
766    for (int i = 0; i < toposForLocalAtom[atom1].size(); i++) {
767      if ( toposForLocalAtom[atom1][i] == atom2 ) return topoDistLocal[atom1][i];
768    }
769 #endif
856  
857 <    // zero is default for unconnected (i.e. normal) pair interactions
772 <    return 0;
857 >    return false;
858    }
859  
860 +
861    void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){
862   #ifdef IS_MPI
863      atomRowData.force[atom1] += fg;
# Line 789 | Line 875 | namespace OpenMD {
875    }
876  
877      // filling interaction blocks with pointers
878 <  InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) {    
879 <    InteractionData idat;
878 >  void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat,
879 >                                                     int atom1, int atom2) {
880  
881 +    idat.excluded = excludeAtomPair(atom1, atom2);
882 +  
883   #ifdef IS_MPI
884 +    idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]);
885 +    //idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
886 +    //                         ff_->getAtomType(identsCol[atom2]) );
887      
797    idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
798                             ff_->getAtomType(identsCol[atom2]) );
799
800    
888      if (storageLayout_ & DataStorage::dslAmat) {
889        idat.A1 = &(atomRowData.aMat[atom1]);
890        idat.A2 = &(atomColData.aMat[atom2]);
# Line 833 | Line 920 | namespace OpenMD {
920        idat.particlePot2 = &(atomColData.particlePot[atom2]);
921      }
922  
923 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {              
924 +      idat.skippedCharge1 = &(atomRowData.skippedCharge[atom1]);
925 +      idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]);
926 +    }
927 +
928   #else
929  
930 <    idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]),
931 <                             ff_->getAtomType(identsLocal[atom2]) );
930 >    idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]);
931 >    //idat.atypes = make_pair( ff_->getAtomType(idents[atom1]),
932 >    //                         ff_->getAtomType(idents[atom2]) );
933  
934      if (storageLayout_ & DataStorage::dslAmat) {
935        idat.A1 = &(snap_->atomData.aMat[atom1]);
# Line 853 | Line 946 | namespace OpenMD {
946        idat.t2 = &(snap_->atomData.torque[atom2]);
947      }
948  
949 <    if (storageLayout_ & DataStorage::dslDensity) {
949 >    if (storageLayout_ & DataStorage::dslDensity) {    
950        idat.rho1 = &(snap_->atomData.density[atom1]);
951        idat.rho2 = &(snap_->atomData.density[atom2]);
952      }
# Line 873 | Line 966 | namespace OpenMD {
966        idat.particlePot2 = &(snap_->atomData.particlePot[atom2]);
967      }
968  
969 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {
970 +      idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]);
971 +      idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]);
972 +    }
973   #endif
877    return idat;
974    }
975  
976    
977 <  void ForceMatrixDecomposition::unpackInteractionData(InteractionData idat, int atom1, int atom2) {    
977 >  void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) {    
978   #ifdef IS_MPI
979      pot_row[atom1] += 0.5 *  *(idat.pot);
980      pot_col[atom2] += 0.5 *  *(idat.pot);
# Line 886 | Line 982 | namespace OpenMD {
982      atomRowData.force[atom1] += *(idat.f1);
983      atomColData.force[atom2] -= *(idat.f1);
984   #else
985 <    longRangePot_ += *(idat.pot);
986 <    
985 >    pairwisePot += *(idat.pot);
986 >
987      snap_->atomData.force[atom1] += *(idat.f1);
988      snap_->atomData.force[atom2] -= *(idat.f1);
989   #endif
990 <
895 <  }
896 <
897 <
898 <  InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){
899 <
900 <    InteractionData idat;
901 < #ifdef IS_MPI
902 <    idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
903 <                             ff_->getAtomType(identsCol[atom2]) );
904 <
905 <    if (storageLayout_ & DataStorage::dslElectroFrame) {
906 <      idat.eFrame1 = &(atomRowData.electroFrame[atom1]);
907 <      idat.eFrame2 = &(atomColData.electroFrame[atom2]);
908 <    }
909 <    if (storageLayout_ & DataStorage::dslTorque) {
910 <      idat.t1 = &(atomRowData.torque[atom1]);
911 <      idat.t2 = &(atomColData.torque[atom2]);
912 <    }
913 < #else
914 <    idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]),
915 <                             ff_->getAtomType(identsLocal[atom2]) );
916 <
917 <    if (storageLayout_ & DataStorage::dslElectroFrame) {
918 <      idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]);
919 <      idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]);
920 <    }
921 <    if (storageLayout_ & DataStorage::dslTorque) {
922 <      idat.t1 = &(snap_->atomData.torque[atom1]);
923 <      idat.t2 = &(snap_->atomData.torque[atom2]);
924 <    }
925 < #endif    
990 >    
991    }
992  
993    /*
# Line 935 | Line 1000 | namespace OpenMD {
1000        
1001      vector<pair<int, int> > neighborList;
1002      groupCutoffs cuts;
1003 +    bool doAllPairs = false;
1004 +
1005   #ifdef IS_MPI
1006      cellListRow_.clear();
1007      cellListCol_.clear();
# Line 954 | Line 1021 | namespace OpenMD {
1021      nCells_.y() = (int) ( Hy.length() )/ rList_;
1022      nCells_.z() = (int) ( Hz.length() )/ rList_;
1023  
1024 +    // handle small boxes where the cell offsets can end up repeating cells
1025 +    
1026 +    if (nCells_.x() < 3) doAllPairs = true;
1027 +    if (nCells_.y() < 3) doAllPairs = true;
1028 +    if (nCells_.z() < 3) doAllPairs = true;
1029 +
1030      Mat3x3d invHmat = snap_->getInvHmat();
1031      Vector3d rs, scaled, dr;
1032      Vector3i whichCell;
1033      int cellIndex;
1034 +    int nCtot = nCells_.x() * nCells_.y() * nCells_.z();
1035  
1036   #ifdef IS_MPI
1037 <    for (int i = 0; i < nGroupsInRow_; i++) {
1038 <      rs = cgRowData.position[i];
965 <      // scaled positions relative to the box vectors
966 <      scaled = invHmat * rs;
967 <      // wrap the vector back into the unit box by subtracting integer box
968 <      // numbers
969 <      for (int j = 0; j < 3; j++)
970 <        scaled[j] -= roundMe(scaled[j]);
971 <    
972 <      // find xyz-indices of cell that cutoffGroup is in.
973 <      whichCell.x() = nCells_.x() * scaled.x();
974 <      whichCell.y() = nCells_.y() * scaled.y();
975 <      whichCell.z() = nCells_.z() * scaled.z();
976 <
977 <      // find single index of this cell:
978 <      cellIndex = Vlinear(whichCell, nCells_);
979 <      // add this cutoff group to the list of groups in this cell;
980 <      cellListRow_[cellIndex].push_back(i);
981 <    }
982 <
983 <    for (int i = 0; i < nGroupsInCol_; i++) {
984 <      rs = cgColData.position[i];
985 <      // scaled positions relative to the box vectors
986 <      scaled = invHmat * rs;
987 <      // wrap the vector back into the unit box by subtracting integer box
988 <      // numbers
989 <      for (int j = 0; j < 3; j++)
990 <        scaled[j] -= roundMe(scaled[j]);
991 <
992 <      // find xyz-indices of cell that cutoffGroup is in.
993 <      whichCell.x() = nCells_.x() * scaled.x();
994 <      whichCell.y() = nCells_.y() * scaled.y();
995 <      whichCell.z() = nCells_.z() * scaled.z();
996 <
997 <      // find single index of this cell:
998 <      cellIndex = Vlinear(whichCell, nCells_);
999 <      // add this cutoff group to the list of groups in this cell;
1000 <      cellListCol_[cellIndex].push_back(i);
1001 <    }
1037 >    cellListRow_.resize(nCtot);
1038 >    cellListCol_.resize(nCtot);
1039   #else
1040 <    for (int i = 0; i < nGroups_; i++) {
1004 <      rs = snap_->cgData.position[i];
1005 <      // scaled positions relative to the box vectors
1006 <      scaled = invHmat * rs;
1007 <      // wrap the vector back into the unit box by subtracting integer box
1008 <      // numbers
1009 <      for (int j = 0; j < 3; j++)
1010 <        scaled[j] -= roundMe(scaled[j]);
1011 <
1012 <      // find xyz-indices of cell that cutoffGroup is in.
1013 <      whichCell.x() = nCells_.x() * scaled.x();
1014 <      whichCell.y() = nCells_.y() * scaled.y();
1015 <      whichCell.z() = nCells_.z() * scaled.z();
1016 <
1017 <      // find single index of this cell:
1018 <      cellIndex = Vlinear(whichCell, nCells_);
1019 <      // add this cutoff group to the list of groups in this cell;
1020 <      cellList_[cellIndex].push_back(i);
1021 <    }
1040 >    cellList_.resize(nCtot);
1041   #endif
1042  
1043 <    for (int m1z = 0; m1z < nCells_.z(); m1z++) {
1044 <      for (int m1y = 0; m1y < nCells_.y(); m1y++) {
1026 <        for (int m1x = 0; m1x < nCells_.x(); m1x++) {
1027 <          Vector3i m1v(m1x, m1y, m1z);
1028 <          int m1 = Vlinear(m1v, nCells_);
1043 >    if (!doAllPairs) {
1044 > #ifdef IS_MPI
1045  
1046 <          for (vector<Vector3i>::iterator os = cellOffsets_.begin();
1047 <               os != cellOffsets_.end(); ++os) {
1048 <            
1049 <            Vector3i m2v = m1v + (*os);
1050 <            
1051 <            if (m2v.x() >= nCells_.x()) {
1052 <              m2v.x() = 0;          
1053 <            } else if (m2v.x() < 0) {
1054 <              m2v.x() = nCells_.x() - 1;
1055 <            }
1056 <            
1057 <            if (m2v.y() >= nCells_.y()) {
1058 <              m2v.y() = 0;          
1059 <            } else if (m2v.y() < 0) {
1060 <              m2v.y() = nCells_.y() - 1;
1061 <            }
1062 <            
1063 <            if (m2v.z() >= nCells_.z()) {
1064 <              m2v.z() = 0;          
1065 <            } else if (m2v.z() < 0) {
1066 <              m2v.z() = nCells_.z() - 1;
1067 <            }
1068 <            
1069 <            int m2 = Vlinear (m2v, nCells_);
1046 >      for (int i = 0; i < nGroupsInRow_; i++) {
1047 >        rs = cgRowData.position[i];
1048 >        
1049 >        // scaled positions relative to the box vectors
1050 >        scaled = invHmat * rs;
1051 >        
1052 >        // wrap the vector back into the unit box by subtracting integer box
1053 >        // numbers
1054 >        for (int j = 0; j < 3; j++) {
1055 >          scaled[j] -= roundMe(scaled[j]);
1056 >          scaled[j] += 0.5;
1057 >        }
1058 >        
1059 >        // find xyz-indices of cell that cutoffGroup is in.
1060 >        whichCell.x() = nCells_.x() * scaled.x();
1061 >        whichCell.y() = nCells_.y() * scaled.y();
1062 >        whichCell.z() = nCells_.z() * scaled.z();
1063 >        
1064 >        // find single index of this cell:
1065 >        cellIndex = Vlinear(whichCell, nCells_);
1066 >        
1067 >        // add this cutoff group to the list of groups in this cell;
1068 >        cellListRow_[cellIndex].push_back(i);
1069 >      }
1070 >      for (int i = 0; i < nGroupsInCol_; i++) {
1071 >        rs = cgColData.position[i];
1072 >        
1073 >        // scaled positions relative to the box vectors
1074 >        scaled = invHmat * rs;
1075 >        
1076 >        // wrap the vector back into the unit box by subtracting integer box
1077 >        // numbers
1078 >        for (int j = 0; j < 3; j++) {
1079 >          scaled[j] -= roundMe(scaled[j]);
1080 >          scaled[j] += 0.5;
1081 >        }
1082 >        
1083 >        // find xyz-indices of cell that cutoffGroup is in.
1084 >        whichCell.x() = nCells_.x() * scaled.x();
1085 >        whichCell.y() = nCells_.y() * scaled.y();
1086 >        whichCell.z() = nCells_.z() * scaled.z();
1087 >        
1088 >        // find single index of this cell:
1089 >        cellIndex = Vlinear(whichCell, nCells_);
1090 >        
1091 >        // add this cutoff group to the list of groups in this cell;
1092 >        cellListCol_[cellIndex].push_back(i);
1093 >      }
1094 > #else
1095 >      for (int i = 0; i < nGroups_; i++) {
1096 >        rs = snap_->cgData.position[i];
1097 >        
1098 >        // scaled positions relative to the box vectors
1099 >        scaled = invHmat * rs;
1100 >        
1101 >        // wrap the vector back into the unit box by subtracting integer box
1102 >        // numbers
1103 >        for (int j = 0; j < 3; j++) {
1104 >          scaled[j] -= roundMe(scaled[j]);
1105 >          scaled[j] += 0.5;
1106 >        }
1107 >        
1108 >        // find xyz-indices of cell that cutoffGroup is in.
1109 >        whichCell.x() = nCells_.x() * scaled.x();
1110 >        whichCell.y() = nCells_.y() * scaled.y();
1111 >        whichCell.z() = nCells_.z() * scaled.z();
1112 >        
1113 >        // find single index of this cell:
1114 >        cellIndex = Vlinear(whichCell, nCells_);
1115 >        
1116 >        // add this cutoff group to the list of groups in this cell;
1117 >        cellList_[cellIndex].push_back(i);
1118 >      }
1119 > #endif
1120  
1121 +      for (int m1z = 0; m1z < nCells_.z(); m1z++) {
1122 +        for (int m1y = 0; m1y < nCells_.y(); m1y++) {
1123 +          for (int m1x = 0; m1x < nCells_.x(); m1x++) {
1124 +            Vector3i m1v(m1x, m1y, m1z);
1125 +            int m1 = Vlinear(m1v, nCells_);
1126 +            
1127 +            for (vector<Vector3i>::iterator os = cellOffsets_.begin();
1128 +                 os != cellOffsets_.end(); ++os) {
1129 +              
1130 +              Vector3i m2v = m1v + (*os);
1131 +              
1132 +              if (m2v.x() >= nCells_.x()) {
1133 +                m2v.x() = 0;          
1134 +              } else if (m2v.x() < 0) {
1135 +                m2v.x() = nCells_.x() - 1;
1136 +              }
1137 +              
1138 +              if (m2v.y() >= nCells_.y()) {
1139 +                m2v.y() = 0;          
1140 +              } else if (m2v.y() < 0) {
1141 +                m2v.y() = nCells_.y() - 1;
1142 +              }
1143 +              
1144 +              if (m2v.z() >= nCells_.z()) {
1145 +                m2v.z() = 0;          
1146 +              } else if (m2v.z() < 0) {
1147 +                m2v.z() = nCells_.z() - 1;
1148 +              }
1149 +              
1150 +              int m2 = Vlinear (m2v, nCells_);
1151 +              
1152   #ifdef IS_MPI
1153 <            for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1154 <                 j1 != cellListRow_[m1].end(); ++j1) {
1155 <              for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1156 <                   j2 != cellListCol_[m2].end(); ++j2) {
1157 <                              
1158 <                // Always do this if we're in different cells or if
1159 <                // we're in the same cell and the global index of the
1063 <                // j2 cutoff group is less than the j1 cutoff group
1064 <
1065 <                if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) {
1153 >              for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1154 >                   j1 != cellListRow_[m1].end(); ++j1) {
1155 >                for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1156 >                     j2 != cellListCol_[m2].end(); ++j2) {
1157 >                  
1158 >                  // In parallel, we need to visit *all* pairs of row &
1159 >                  // column indicies and will truncate later on.
1160                    dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)];
1161                    snap_->wrapVector(dr);
1162                    cuts = getGroupCutoffs( (*j1), (*j2) );
1163                    if (dr.lengthSquare() < cuts.third) {
1164                      neighborList.push_back(make_pair((*j1), (*j2)));
1165 <                  }
1165 >                  }                  
1166                  }
1167                }
1074            }
1168   #else
1169 <            for (vector<int>::iterator j1 = cellList_[m1].begin();
1170 <                 j1 != cellList_[m1].end(); ++j1) {
1171 <              for (vector<int>::iterator j2 = cellList_[m2].begin();
1172 <                   j2 != cellList_[m2].end(); ++j2) {
1173 <                              
1174 <                // Always do this if we're in different cells or if
1175 <                // we're in the same cell and the global index of the
1176 <                // j2 cutoff group is less than the j1 cutoff group
1177 <
1178 <                if (m2 != m1 || (*j2) < (*j1)) {
1179 <                  dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1180 <                  snap_->wrapVector(dr);
1181 <                  cuts = getGroupCutoffs( (*j1), (*j2) );
1182 <                  if (dr.lengthSquare() < cuts.third) {
1183 <                    neighborList.push_back(make_pair((*j1), (*j2)));
1169 >              
1170 >              for (vector<int>::iterator j1 = cellList_[m1].begin();
1171 >                   j1 != cellList_[m1].end(); ++j1) {
1172 >                for (vector<int>::iterator j2 = cellList_[m2].begin();
1173 >                     j2 != cellList_[m2].end(); ++j2) {
1174 >                  
1175 >                  // Always do this if we're in different cells or if
1176 >                  // we're in the same cell and the global index of the
1177 >                  // j2 cutoff group is less than the j1 cutoff group
1178 >                  
1179 >                  if (m2 != m1 || (*j2) < (*j1)) {
1180 >                    dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1181 >                    snap_->wrapVector(dr);
1182 >                    cuts = getGroupCutoffs( (*j1), (*j2) );
1183 >                    if (dr.lengthSquare() < cuts.third) {
1184 >                      neighborList.push_back(make_pair((*j1), (*j2)));
1185 >                    }
1186                    }
1187                  }
1188                }
1094            }
1189   #endif
1190 +            }
1191            }
1192          }
1193        }
1194 +    } else {
1195 +      // branch to do all cutoff group pairs
1196 + #ifdef IS_MPI
1197 +      for (int j1 = 0; j1 < nGroupsInRow_; j1++) {
1198 +        for (int j2 = 0; j2 < nGroupsInCol_; j2++) {      
1199 +          dr = cgColData.position[j2] - cgRowData.position[j1];
1200 +          snap_->wrapVector(dr);
1201 +          cuts = getGroupCutoffs( j1, j2 );
1202 +          if (dr.lengthSquare() < cuts.third) {
1203 +            neighborList.push_back(make_pair(j1, j2));
1204 +          }
1205 +        }
1206 +      }
1207 + #else
1208 +      for (int j1 = 0; j1 < nGroups_ - 1; j1++) {
1209 +        for (int j2 = j1 + 1; j2 < nGroups_; j2++) {
1210 +          dr = snap_->cgData.position[j2] - snap_->cgData.position[j1];
1211 +          snap_->wrapVector(dr);
1212 +          cuts = getGroupCutoffs( j1, j2 );
1213 +          if (dr.lengthSquare() < cuts.third) {
1214 +            neighborList.push_back(make_pair(j1, j2));
1215 +          }
1216 +        }
1217 +      }        
1218 + #endif
1219      }
1220 <
1220 >      
1221      // save the local cutoff group positions for the check that is
1222      // done on each loop:
1223      saved_CG_positions_.clear();
1224      for (int i = 0; i < nGroups_; i++)
1225        saved_CG_positions_.push_back(snap_->cgData.position[i]);
1226 <
1226 >    
1227      return neighborList;
1228    }
1229   } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines