Simpatico  v1.10
mcMd/neighbor/PairList.h
1 #ifndef MCMD_PAIR_LIST_H
2 #define MCMD_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 <simp/boundary/Boundary.h>
13 #include <util/param/ParamComposite.h>
14 #include <util/containers/DArray.h>
15 #include <util/space/Vector.h>
16 
17 class PairListTest;
18 
19 namespace McMd
20 {
21 
22  using namespace Util;
23  using namespace Simp;
24 
25  class Atom;
26  class PairIterator;
27 
61  class PairList : public ParamComposite
62  {
63 
64  // Null value for any non-negative index
65  static const int NullIndex = -1;
66 
67  public:
68 
72  PairList();
73 
79  virtual ~PairList();
80 
86  void readParameters(std::istream &in);
87 
93  virtual void loadParameters(Serializable::IArchive &ar);
94 
100  virtual void save(Serializable::OArchive &ar);
101 
103 
104 
117  void initialize(int atomIdEnd, double potentialCutoff);
118 
122  void setup(const Boundary &boundary);
123 
129  void clear();
130 
140  void addAtom(Atom& atom);
141 
152  void build(const Boundary& boundary);
153 
159  void begin(PairIterator &iterator) const;
160 
162 
164 
168  int nAtom() const;
169 
173  int nPair() const;
174 
178  bool isInitialized() const;
179 
193  bool isCurrent(const Boundary &boundary) const;
194 
196  bool isValid() const;
197 
199 
201 
205  int maxNAtom() const;
206 
210  int maxNPair() const;
211 
215  int buildCounter() const;
216 
220  void clearStatistics();
221 
223 
224  private:
225 
227  CellList cellList_;
228 
230  DArray<Atom*> atom1Ptrs_;
231 
233  DArray<Atom*> atom2Ptrs_;
234 
236  DArray<int> first_;
237 
239  DArray<Vector> oldPositions_;
240 
242  double skin_;
243 
245  double cutoff_;
246 
248  int atomCapacity_;
249 
251  int pairCapacity_;
252 
254  int nAtom1_;
255 
257  int nAtom2_;
258 
260  int nAtom_;
261 
264  int tList1_;
265 
267  int maxNAtom_;
268 
270  int maxNAtom2_;
271 
273  int buildCounter_;
274 
276  bool isInitialized_;
277 
281  void allocate();
282 
283  /*
284  * Implementation Notes:
285  *
286  * The pair list is stored in Atom* pointer arrays atom1Ptrs_, atom2Ptrs_,
287  * and in an integer array first_. Each element of atom1Ptrs_ contains a
288  * pointer to the first atom in a pair (the primary Atom). Each element
289  * of atom2Ptrs_ contains a pointer to the second atom in a pair (the
290  * secondary Atom). Secondary atoms that are neighbors of the same
291  * primary atom are listed consecutively. Element first_[i] contains the
292  * array index of the first element in atom2Ptrs_ that contains a neighbor
293  * of primary atom atom1Ptrs_[i]. Pointers to neighbors of primary atom
294  * *atom1Ptrs_[i] are thus stored in elements first_[i] <= j < first_[i+1]
295  * of atom2Ptrs_. Each pair is included only once, by including only
296  * pairs in which atom2Ptrs_[j]->id() > atom1Ptrs_[i]->id(), so
297  * the Id of the secondary atom in a pair is always greater than that of
298  * the primary atom. The total number of primary atoms in atom1Ptrs_ is
299  * nAtom1_. The total number of secondary atoms in Array atom2Ptrs_ (or
300  * the total number of distinct pairs) is nAtom2_. The total number of
301  * Atoms in the System in nAtom_.
302  *
303  * The only way legal way to loop over all atom pairs, using the public
304  * interface of a PairList, is to use a PairListIterator. See the
305  * documentation of PairListIterator for a discussion of its usage. The
306  * resulting loop over pairs is equivalent to the following double loop
307  * over private member variables of PairList:
308  *
309  * int i, j;
310  * Atom* atom1Ptr;
311  * Atom* atom2Ptr;
312  *
313  * \\ Loop over primary Atoms
314  * for (i = 0; i < nAtom1_; ++i) {
315  * atom1Ptr = atom1Ptrs_[i];
316  *
317  * // Loop over secondary atoms
318  * for (j = first_[i]; j < first_[i+1]; ++j) {
319  * atom2Ptr = atom2Ptrs_[j];
320  *
321  * // ... Do something with Atoms *atom1Ptr and *atom2Ptr.
322  *
323  * }
324  * }
325  *
326  * Note that DArray<int> first_ contains nAtom1_ + 1 elements. The first
327  * element, element first_[0] is equal to 0, and the last element,
328  * first_[nAtom1_], is always equal to nAtom2_, the total number of
329  * pairs.
330  *
331  * The number of primary Atoms nAtom1_ is generally less than nAtom_, the
332  * total number of atoms, because some Atoms have no neighbors with integer
333  * Ids higher than their own. This is always true, for example, for the
334  * Atom with the highest Id. Pointers to such atoms, which do not appear
335  * in the first nAtom1_ elements of atom1Ptrs_, are instead stored in the
336  * last elements of the atom1Ptrs_ array , in elements tList1 + 1, .... ,
337  * atomCapacity_ - 1. The previous position Vectors for these Atoms are
338  * stored in the corresponding elements of the oldPositions_ array.
339  * These pointers and previous positions retained because they are used
340  * in the isCurrent() method to calculate how far these Atoms have moved
341  * since the last time the PairList was built.
342  */
343 
344  // friends:
345 
346  // Unit test classes
347  friend class ::PairListTest;
348 
349  }; // end class PairList
350 
351 
352  /*
353  * Add an Atom to the CellList.
354  */
355  inline void PairList::addAtom(Atom &atom)
356  { cellList_.addAtom(atom); }
357 
358  /*
359  * Get the current number of atoms in the pairlist.
360  */
361  inline int PairList::nAtom() const
362  { return nAtom_; }
363 
364  /*
365  * Get the current number of pairs.
366  */
367  inline int PairList::nPair() const
368  { return nAtom2_; }
369 
370  /*
371  * Get the maximum value of aAtom() since instantiation.
372  */
373  inline int PairList::maxNAtom() const
374  { return maxNAtom_; }
375 
376  /*
377  * Get the maximum value of nPair() since instantiation.
378  */
379  inline int PairList::maxNPair() const
380  { return maxNAtom2_; }
381 
382  /*
383  * Get the number of times this PairList has been built.
384  */
385  inline int PairList::buildCounter() const
386  { return buildCounter_; }
387 
388  /*
389  * Has the initialize function been called?
390  */
391  inline bool PairList::isInitialized() const
392  { return isInitialized_; }
393 
394 }
395 #endif
void addAtom(Atom &atom)
Add an Atom to the CellList.
int buildCounter() const
Return number of times the PairList has been built thus far.
An orthorhombic periodic unit cell.
A Verlet neighbor list.
Classes used by all simpatico molecular simulations.
bool isInitialized() const
Has the initialize function been called?
Saving / output archive for binary ostream.
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
int nAtom() const
Get the number of pairs currently in the PairList.
int nPair() const
Get the number of pairs currently in the PairList.
Iterator for pairs in a PairList.
A cell list for Atom objects in a periodic system boundary.
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int maxNPair() const
Get the maximum number of pairs encountered thus far.
int maxNAtom() const
Get the maximum number of atoms encountered thus far.
An object that can read multiple parameters from file.