Simpatico  v1.10
ddMd/neighbor/Cell.h
1 #ifndef DDMD_CELL_H
2 #define DDMD_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 <ddMd/neighbor/CellAtom.h>
12 #include <ddMd/chemistry/Atom.h>
13 #include <util/containers/FSArray.h>
14 #include <util/global.h>
15 
16 #include <utility>
17 
18 namespace DdMd
19 {
20 
21  using namespace Util;
22 
71  class Cell
72  {
73 
74  public:
75 
76  // Static members
77 
81  static const int MaxNeighborAtom = 2000;
82 
86  static const int MaxNCellCut = 4;
87 
91  static const int OffSetArrayCapacity = (2*MaxNCellCut + 1)*(2*MaxNCellCut + 1) + 3;
92 
105  typedef FSArray< std::pair<int,int>, OffSetArrayCapacity> OffsetArray;
106 
111 
115  Cell();
116 
117  // Linked List Interface
118 
122  void setNextCell(Cell& nextCell);
123 
127  void setLastCell();
128 
132  const Cell* nextCellPtr() const;
133 
134  // Mutators
135 
141  void setId(int id);
142 
148  void setOffsetArray(OffsetArray& offsets);
149 
153  void setIsGhostCell(bool isGhostCell = true);
154 
160  void clear();
161 
169  void incrementCapacity();
170 
182  CellAtom* initialize(CellAtom* begin);
183 
187  void append(Atom* atomPtr);
188 
189  // Accessors
190 
194  int id() const;
195 
199  int nAtom() const;
200 
204  int atomCapacity() const;
205 
209  CellAtom* atomPtr(int i) const;
210 
214  bool isGhostCell() const;
215 
230  void getNeighbors(NeighborArray& neighbors,
231  bool reverseUpdateFlag = false) const;
232 
233  private:
234 
236  CellAtom* begin_;
237 
239  OffsetArray* offsetsPtr_;
240 
242  Cell* nextCellPtr_;
243 
245  int nAtom_;
246 
248  int atomCapacity_;
249 
251  int id_;
252 
254  bool isGhostCell_;
255 
256  };
257 
258  inline void Cell::setId(int id)
259  { id_ = id; }
260 
262  {
263  assert(begin_ == 0);
264  ++atomCapacity_;
265  }
266 
267  inline void Cell::clear()
268  {
269  begin_= 0;
270  nAtom_ = 0;
271  atomCapacity_ = 0;
272  }
273 
275  {
276  assert(begin_ == 0);
277  assert(nAtom_ == 0);
278  assert(atomCapacity_ >= 0);
279 
280  begin_ = begin;
281  return (begin_ + atomCapacity_);
282  }
283 
284  inline void Cell::append(Atom* atomPtr)
285  {
286  assert(begin_ != 0);
287  assert(nAtom_ < atomCapacity_);
288  begin_[nAtom_].setPtr(atomPtr);
289  ++nAtom_;
290  }
291 
292  /*
293  * Get identifier for this Cell.
294  */
295  inline int Cell::id() const
296  { return id_; }
297 
298  /*
299  * Return number of atoms in this cell.
300  */
301  inline int Cell::nAtom() const
302  { return nAtom_; }
303 
304  /*
305  * Return pointer to atom i.
306  */
307  inline CellAtom* Cell::atomPtr(int i) const
308  {
309  assert(i >= 0);
310  assert(i < nAtom_);
311  return &begin_[i];
312  }
313 
314  /*
315  * Pointer to next cell in list.
316  */
317  inline const Cell* Cell::nextCellPtr() const
318  { return nextCellPtr_; }
319 
320  /*
321  * Return current capacity of cell.
322  */
323  inline int Cell::atomCapacity() const
324  { return atomCapacity_; }
325 
326  /*
327  * Is this a ghost cell?
328  */
329  inline bool Cell::isGhostCell() const
330  { return isGhostCell_; }
331 
332 }
333 #endif
Data for an atom in a CellList.
CellAtom * atomPtr(int i) const
Return a pointer to atom i.
File containing preprocessor macros for error handling.
FSArray< std::pair< int, int >, OffSetArrayCapacity > OffsetArray
An array of strips of relative ids for columns of neighboring cells.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
void setId(int id)
Set id for this Cell.
int id() const
Get identifier for this Cell.
FSArray< CellAtom *, MaxNeighborAtom > NeighborArray
Static array for holding neighbors in a cell list.
void clear()
Reset to empty before incrementing capacity.
CellAtom * initialize(CellAtom *begin)
Associate the Cell with an array of CellAtom objects.
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:37
int nAtom() const
Number of atoms in cell.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void incrementCapacity()
Increment the capacity counter.
int atomCapacity() const
Capacity of array segment.
bool isGhostCell() const
Is this a ghost cell?
const Cell * nextCellPtr() const
Return a pointer to neighbor cell i.
A single Cell in a CellList.
void append(Atom *atomPtr)
Append an Atom to an initialized cell.