Simpatico  v1.10
ddMd/neighbor/PairList.h
1 #ifndef DDMD_PAIR_LIST_H
2 #define DDMD_PAIR_LIST_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 "CellList.h"
12 #include <util/containers/GArray.h>
13 #include <util/misc/Setable.h>
14 #include <util/global.h>
15 
16 namespace DdMd
17 {
18 
19  using namespace Util;
20 
21  class Atom;
22  class PairIterator;
23 
41  class PairList
42  {
43 
44  // Null value for any non-negative index
45  static const int NullIndex = -1;
46 
47  public:
48 
52  PairList();
53 
57  virtual ~PairList();
58 
60 
61 
69  void allocate(int atomCapacity, int pairCapacity, double cutoff);
70 
74  void clear();
75 
82  void build(CellList& cellList, bool reverseUpdateFlag = false);
83 
85 
87 
93  void begin(PairIterator &iterator) const;
94 
98  int nAtom() const;
99 
103  int nPair() const;
104 
108  int pairCapacity() const;
109 
113  int atomCapacity() const;
114 
118  bool isAllocated() const;
119 
121 
123 
129  #ifdef UTIL_MPI
130  virtual void computeStatistics(MPI::Intracomm& communicator);
131  #else
132  virtual void computeStatistics();
133  #endif
134 
138  void clearStatistics();
139 
147  void outputStatistics(std::ostream& out);
148 
154  int maxNAtom() const;
155 
161  int maxNPair() const;
162 
166  int buildCounter() const;
167 
169 
170  private:
171 
173  GArray<Atom*> atom1Ptrs_;
174 
176  GArray<Atom*> atom2Ptrs_;
177 
179  GArray<int> first_;
180 
182  double cutoff_;
183 
185  int atomCapacity_;
186 
188  int pairCapacity_;
189 
191  int maxNAtomLocal_;
192 
194  int maxNPairLocal_;
195 
197  int buildCounter_;
198 
200  Setable<int> maxNAtom_;
201 
203  Setable<int> maxNPair_;
204 
206  bool isAllocated_;
207 
208  /*
209  * Implementation Notes:
210  *
211  * The pair list is stored in Atom* pointer arrays atom1Ptrs_, atom2Ptrs_,
212  * and in an integer array first_. Each element of atom1Ptrs_ contains a
213  * pointer to the first atom in a pair (the primary Atom). Each element
214  * of atom2Ptrs_ contains a pointer to the second atom in a pair (the
215  * secondary Atom). Secondary atoms that are neighbors of the same
216  * primary atom are listed consecutively. Element first_[i] contains the
217  * array index of the first element in atom2Ptrs_ that contains a neighbor
218  * of primary atom atom1Ptrs_[i]. Pointers to neighbors of primary atom
219  * *atom1Ptrs_[i] are thus stored in elements first_[i] <= j < first_[i+1]
220  * of atom2Ptrs_. Each pair is included only once.
221  *
222  * The only way legal way to loop over all atom pairs, using the public
223  * interface of a PairList, is to use a PairListIterator. See the
224  * documentation of PairListIterator for a discussion of its usage. The
225  * resulting loop over pairs is equivalent to the following double loop
226  * over private member variables of PairList:
227  *
228  * int i, j;
229  * Atom* atom1Ptr;
230  * Atom* atom2Ptr;
231  *
232  * \\ Loop over primary Atoms
233  * for (i = 0; i < atom1Ptrs_.size(); ++i) {
234  * atom1Ptr = atom1Ptrs_[i];
235  *
236  * // Loop over secondary atoms
237  * for (j = first_[i]; j < first_[i+1]; ++j) {
238  * atom2Ptr = atom2Ptrs_[j];
239  *
240  * // ... Do something with Atoms *atom1Ptr and *atom2Ptr.
241  *
242  * }
243  * }
244  *
245  * Note that GArray<int> first_ contains one more elements than
246  * atom1Ptrs_. The element first_[0] is equal to 0, and the last
247  * element is always equal to the total number of pairs.
248  */
249 
250  };
251 
252  /*
253  * Get the current number of primary atoms in the pairlist.
254  */
255  inline int PairList::nAtom() const
256  { return atom1Ptrs_.size(); }
257 
258  /*
259  * Get the current number of pairs.
260  */
261  inline int PairList::nPair() const
262  { return atom2Ptrs_.size(); }
263 
267  inline int PairList::pairCapacity() const
268  { return pairCapacity_; }
269 
273  inline int PairList::atomCapacity() const
274  { return atomCapacity_; }
275 
276  /*
277  * Get the maximum value of aAtom() since instantiation.
278  */
279  inline int PairList::maxNAtom() const
280  { return maxNAtom_.value(); }
281 
282  /*
283  * Get the maximum value of nPair() since instantiation.
284  */
285  inline int PairList::maxNPair() const
286  { return maxNPair_.value(); }
287 
288  /*
289  * Get the number of times this PairList has been built.
290  */
291  inline int PairList::buildCounter() const
292  { return buildCounter_; }
293 
294  /*
295  * Has memory been allocated for this PairList?
296  */
297  inline bool PairList::isAllocated() const
298  { return isAllocated_; }
299 
300 }
301 #endif
A cell list used only to identify nearby atom pairs.
An automatically growable array, analogous to a std::vector.
Definition: GArray.h:33
int atomCapacity() const
Get the maximum number of primary atoms.
int maxNAtom() const
Get the maximum number of primary atoms encountered thus far.
A Verlet nonbonded pair list.
int nPair() const
Get the number of pairs in the PairList.
int maxNPair() const
Get the maximum number of pairs encountered thus far.
File containing preprocessor macros for error handling.
Parallel domain decomposition (DD) MD simulation.
Utility classes for scientific computation.
Definition: accumulators.mod:1
int buildCounter() const
Return number of times the PairList has been built thus far.
Iterator for pairs in a PairList.
bool isAllocated() const
Has memory been allocated for this PairList?
int pairCapacity() const
Get the maximum number of pairs.
int nAtom() const
Get the number of primary atoms in the PairList.