Simpatico  v1.10
tools/neighbor/Cell.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "Cell.h"
9 
10 namespace Tools
11 {
12 
13  using namespace Util;
14 
16  : begin_(0),
17  offsetsPtr_(0),
18  nextCellPtr_(0),
19  nAtom_(0),
20  atomCapacity_(0)
21  {}
22 
24  {
25  delete offsetsPtr_;
26  }
27 
29  { offsetsPtr_ = &offsets; }
30 
31  void Cell::setNextCell(Cell& nextCell)
32  { nextCellPtr_ = &nextCell; }
33 
35  { nextCellPtr_ = 0; }
36 
37  /*
38  * Fill an array with pointers to CellAtom objects in this cell and neighbors.
39  *
40  * Upon return, the NeighborArray neighbors contains pointers to all of the atoms
41  * in this cell and neighboring cells. The first nAtom() elements are the the
42  * atoms in this cell.
43  */
44  void Cell::getNeighbors(NeighborArray &neighbors) const
45  {
46  // Preconditions
47  assert(offsetsPtr_);
48 
49  CellAtom* atom;
50  int offset;
51 
52  neighbors.clear();
53 
54  // add neighbors from this cell
55  atom = begin_;
56  while (atom < begin_ + nAtom_) {
57  neighbors.append(atom);
58  atom++;
59  }
60 
61  for (int i = -1; i <= 1; i++)
62  for (int j = -1; j <= 1; j++)
63  for (int k = -1; k <= 1; k++) {
64  offset = 0;
65  // we already counted this cell
66  if (!(i == 0 && j == 0 && k == 0)) {
67  offset += ((i == 0) ? 0 : ((i > 0) ? (*offsetsPtr_)[0].first : (*offsetsPtr_)[0].second));
68  offset += ((j == 0) ? 0 : ((j > 0) ? (*offsetsPtr_)[1].first : (*offsetsPtr_)[1].second));
69  offset += ((k == 0) ? 0 : ((k > 0) ? (*offsetsPtr_)[2].first : (*offsetsPtr_)[2].second));
70 
71  if ((this +offset)->id_ >= id_) {
72  atom = (this + offset)->begin_;
73  while (atom < (this + offset)->begin_ + (this + offset)->nAtom_) {
74  neighbors.append(atom);
75  atom++;
76  }
77  }
78  }
79  }
80 
81  }
82 
83 }
void clear()
Set logical size to zero.
Definition: FSArray.h:271
Cell()
Constructor.
~Cell()
Destructor.
void append(const Data &data)
Append data to the end of the array.
Definition: FSArray.h:258
void setOffsetArray(OffsetArray &offsets)
Set the pointer to an array of integer offsets.
void getNeighbors(NeighborArray &neighbors) const
Fill an array with pointers to atoms in a cell and neighboring cells.
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:37
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setLastCell()
Set this to be the last cell in the list.
Single-processor classes for pre- and post-processing MD trajectories.
void setNextCell(Cell &nextCell)
Set the pointer to the next cell in the list.
Data for an atom in a CellList.
A single cell in a CellList.