Simpatico  v1.10
tools/neighbor/Cell.h
1 #ifndef TOOLS_CELL_H
2 #define TOOLS_CELL_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 <tools/neighbor/CellAtom.h>
12 #include <tools/chemistry/Atom.h>
13 #include <util/containers/FSArray.h>
14 #include <util/containers/FArray.h>
15 #include <util/global.h>
16 
17 #include <utility>
18 
19 namespace Tools
20 {
21 
22  using namespace Util;
23 
70  class Cell
71  {
72 
73  public:
74 
75  // Static members
76 
80  static const int MaxNeighborAtom = 2000;
81 
94 
99 
103  Cell();
104 
108  ~Cell();
109 
110  // Linked List Interface
111 
115  void setNextCell(Cell& nextCell);
116 
120  void setLastCell();
121 
125  const Cell* nextCellPtr() const;
126 
127  // Mutators
128 
134  void setId(int id);
135 
139  void setOffsetArray(OffsetArray& offsets);
140 
144  void clear();
145 
153  void incrementCapacity();
154 
166  CellAtom* initialize(CellAtom* begin);
167 
171  void append(Atom* atomPtr);
172 
173  // Accessors
174 
178  int id() const;
179 
183  int nAtom() const;
184 
188  int atomCapacity() const;
189 
193  CellAtom* atomPtr(int i) const;
194 
207  void getNeighbors(NeighborArray& neighbors) const;
208 
209  private:
210 
212  CellAtom* begin_;
213 
215  OffsetArray* offsetsPtr_;
216 
218  Cell* nextCellPtr_;
219 
221  int nAtom_;
222 
224  int atomCapacity_;
225 
227  int id_;
228 
229  };
230 
231  inline void Cell::setId(int id)
232  { id_ = id; }
233 
235  {
236  assert(begin_ == 0);
237  ++atomCapacity_;
238  }
239 
240  inline void Cell::clear()
241  {
242  begin_= 0;
243  nAtom_ = 0;
244  atomCapacity_ = 0;
245  }
246 
248  {
249  assert(begin_ == 0);
250  assert(nAtom_ == 0);
251  assert(atomCapacity_ >= 0);
252 
253  begin_ = begin;
254  return (begin_ + atomCapacity_);
255  }
256 
257  inline void Cell::append(Atom* atomPtr)
258  {
259  assert(begin_ != 0);
260  assert(nAtom_ < atomCapacity_);
261  begin_[nAtom_].setPtr(atomPtr);
262  ++nAtom_;
263  }
264 
265  /*
266  * Get identifier for this Cell.
267  */
268  inline int Cell::id() const
269  { return id_; }
270 
271  /*
272  * Return number of atoms in this cell.
273  */
274  inline int Cell::nAtom() const
275  { return nAtom_; }
276 
277  /*
278  * Return pointer to atom i.
279  */
280  inline CellAtom* Cell::atomPtr(int i) const
281  {
282  assert(i >= 0);
283  assert(i < nAtom_);
284  return &begin_[i];
285  }
286 
287  /*
288  * Pointer to next cell in list.
289  */
290  inline const Cell* Cell::nextCellPtr() const
291  { return nextCellPtr_; }
292 
293  /*
294  * Return current capacity of cell.
295  */
296  inline int Cell::atomCapacity() const
297  { return atomCapacity_; }
298 
299 }
300 #endif
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
int atomCapacity() const
Capacity of array segment.
void clear()
Reset to empty before incrementing capacity.
void setId(int id)
Set id for this Cell.
void append(Atom *atomPtr)
Append an Atom to an initialized cell.
int nAtom() const
Number of atoms in cell.
File containing preprocessor macros for error handling.
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:37
FSArray< CellAtom *, MaxNeighborAtom > NeighborArray
Static array for holding neighbors in a cell list.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void incrementCapacity()
Increment the capacity counter.
int id() const
Get identifier for this Cell.
Single-processor classes for pre- and post-processing MD trajectories.
A point particle in an MD simulation.
CellAtom * atomPtr(int i) const
Return a pointer to atom i.
FSArray< std::pair< int, int >, Dimension > OffsetArray
An array of offsets to the neighboring cells surrounding this cell.
CellAtom * initialize(CellAtom *begin)
Associate the Cell with an array of CellAtom objects.
const Cell * nextCellPtr() const
Return a pointer to neighbor cell i.
Data for an atom in a CellList.
A single cell in a CellList.