Simpatico  v1.10
ddMd/neighbor/PairIterator.h
1 #ifndef DDMD_PAIR_ITERATOR_H
2 #define DDMD_PAIR_ITERATOR_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "PairList.h"
12 #include <util/global.h>
13 
14 namespace DdMd
15 {
16 
17  using namespace Util;
18 
19  class Atom;
20 
49  {
50 
51  public:
52 
59  PairIterator();
60 
69  PairIterator(const PairList &pairList);
70 
71  // Use default C++ destructor.
72 
76  PairIterator& operator++ ();
77 
84  bool isEnd() const;
85 
91  bool notEnd() const;
92 
99  void getPair(Atom* &atom1Ptr, Atom* &atom2Ptr) const;
100 
101  private:
102 
104  Atom* const* atom1Ptrs_;
105 
107  Atom* const* atom2Ptrs_;
108 
110  const int* first_;
111 
113  int nAtom1_;
114 
116  int nAtom2_;
117 
119  int atom1Id_;
120 
122  int atom2Id_;
123 
124  // friends:
125 
126  friend class PairList;
127 
128  };
129 
130  /*
131  * Default constructor.
132  */
134  : atom1Ptrs_(0),
135  atom2Ptrs_(0),
136  first_(0),
137  nAtom1_(0),
138  nAtom2_(0),
139  atom1Id_(0),
140  atom2Id_(0)
141  {}
142 
143  /*
144  * Constructor, initialized iterator.
145  */
146  inline PairIterator::PairIterator(const PairList &pairList)
147  : atom1Ptrs_(0),
148  atom2Ptrs_(0),
149  first_(0),
150  nAtom1_(0),
151  nAtom2_(0),
152  atom1Id_(0),
153  atom2Id_(0)
154  { pairList.begin(*this); }
155 
156  /*
157  * Get pointers to current pair of Atoms.
158  */
159  inline void PairIterator::getPair(Atom* &atom1Ptr, Atom* &atom2Ptr) const
160  {
161  assert(atom1Id_ >=0);
162  assert(atom1Id_ < nAtom1_);
163  assert(atom2Id_ >=0);
164  assert(atom2Id_ < nAtom2_);
165  atom1Ptr = atom1Ptrs_[atom1Id_];
166  atom2Ptr = atom2Ptrs_[atom2Id_];
167  }
168 
169  /*
170  * Increment current pair.
171  */
173  {
174  assert(atom1Id_ >=0);
175  assert(atom1Id_ < nAtom1_);
176  assert(atom2Id_ >=0);
177  assert(atom2Id_ < nAtom2_);
178  ++atom2Id_;
179  if (atom2Id_ == first_[atom1Id_+1]) {
180  ++atom1Id_;
181  }
182  return *this;
183  }
184 
185  /*
186  * Return true if past last pair in list.
187  */
188  inline bool PairIterator::isEnd() const
189  { return (atom2Id_ == nAtom2_); }
190 
191  /*
192  * Return false if one past last pair in list.
193  */
194  inline bool PairIterator::notEnd() const
195  { return (atom2Id_ != nAtom2_); }
196 
197 
198 
199 }
200 #endif
A Verlet nonbonded pair list.
PairIterator & operator++()
Increment to next pair.
void getPair(Atom *&atom1Ptr, Atom *&atom2Ptr) const
Get pointers for current pair of Atoms.
File containing preprocessor macros for error handling.
void begin(PairIterator &iterator) const
Initialize a PairIterator.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
bool notEnd() const
Return true if not at end of PairList.
Utility classes for scientific computation.
Definition: accumulators.mod:1
PairIterator()
Default constructor.
bool isEnd() const
Return true if at end of PairList.
Iterator for pairs in a PairList.