Simpatico  v1.10
ddMd/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 DdMd
11 {
12 
13  using namespace Util;
14 
16  : begin_(0),
17  offsetsPtr_(0),
18  nextCellPtr_(0),
19  nAtom_(0),
20  atomCapacity_(0),
21  isGhostCell_(true)
22  {}
23 
25  { offsetsPtr_ = &offsets; }
26 
28  { isGhostCell_ = isGhostCell; }
29 
30  void Cell::setNextCell(Cell& nextCell)
31  { nextCellPtr_ = &nextCell; }
32 
34  { nextCellPtr_ = 0; }
35 
36  /*
37  * Fill an array with pointers to atoms in a cell and neighboring cells.
38  *
39  * Upon return, the NeighborArray neighbors contains pointers to all of
40  * the atoms this cell and neighboring cells. The first nAtom() elements
41  * are the atoms in this cell.
42  *
43  * \param neighbors array of pointers to neighbor Atoms
44  * \param force if true, use reverse communication
45  */
47  bool reverseUpdateFlag) const
48  {
49  // Preconditions
50  assert(offsetsPtr_);
51  assert(!isGhostCell_);
52 
53  const Cell* cellBegin;
54  const Cell* cellEnd;
55  CellAtom* atomBegin;
56  CellAtom* atomEnd;
57  int is, ns;
58  bool bg, eg;
59 
60  neighbors.clear();
61  ns = offsetsPtr_->size();
62 
63  if (reverseUpdateFlag) {
64  for (is = 0; is < ns; ++is) {
65  cellBegin = this + (*offsetsPtr_)[is].first;
66  cellEnd = this + (*offsetsPtr_)[is].second;
67  if (cellBegin->id() >= id_) {
68  atomBegin = cellBegin->begin_;
69  atomEnd = cellEnd->begin_ + cellEnd->nAtom_;
70  for ( ; atomBegin < atomEnd; ++atomBegin) {
71  neighbors.append(atomBegin);
72  }
73  }
74  }
75  } else {
76  for (is = 0; is < ns; ++is) {
77  cellBegin = this + (*offsetsPtr_)[is].first;
78  cellEnd = this + (*offsetsPtr_)[is].second;
79  if (cellBegin->id() >= id_) {
80  atomBegin = cellBegin->begin_;
81  atomEnd = cellEnd->begin_ + cellEnd->nAtom_;
82  for ( ; atomBegin < atomEnd; ++atomBegin) {
83  neighbors.append(atomBegin);
84  }
85  } else {
86  bg = cellBegin->isGhostCell();
87  eg = cellEnd->isGhostCell();
88  if (bg || eg) {
89  while (!bg){
90  ++cellBegin;
91  bg = cellBegin->isGhostCell();
92  }
93  while (!eg){
94  --cellEnd;
95  eg = cellEnd->isGhostCell();
96  }
97  assert(cellEnd >= cellBegin);
98  atomBegin = cellBegin->begin_;
99  atomEnd = cellEnd->begin_ + cellEnd->nAtom_;
100  for ( ; atomBegin < atomEnd; ++atomBegin) {
101  neighbors.append(atomBegin);
102  }
103  }
104  }
105  }
106  }
107  }
108 
109 }
void clear()
Set logical size to zero.
Definition: FSArray.h:271
Data for an atom in a CellList.
void append(const Data &data)
Append data to the end of the array.
Definition: FSArray.h:258
Parallel domain decomposition (DD) MD simulation.
int id() const
Get identifier for this Cell.
void setOffsetArray(OffsetArray &offsets)
Set the pointer to an array of integer offsets.
void setNextCell(Cell &nextCell)
Set the pointer to the next cell in the list.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setIsGhostCell(bool isGhostCell=true)
Mark as a ghost or local cell.
Cell()
Constructor.
void setLastCell()
Set this to be the last cell in the list.
void getNeighbors(NeighborArray &neighbors, bool reverseUpdateFlag=false) const
Fill an array with pointers to atoms in a cell and neighboring cells.
int size() const
Return logical size of this array (i.e., number of elements).
Definition: FSArray.h:207
bool isGhostCell() const
Is this a ghost cell?
A single Cell in a CellList.