9 #include <util/space/Vector.h> 10 #include <util/space/IntVector.h> 11 #include <util/containers/FArray.h> 31 cellLengths_[i] = 0.0;
45 const Vector& upper,
const Vector& cutoffs,
int nCellCut)
50 atoms_.allocate(atomCapacity);
53 setGridDimensions(lower, upper, cutoffs, nCellCut);
59 void CellList::setGridDimensions(
const Vector& lower,
const Vector& upper,
60 const Vector& cutoffs,
int nCellCut)
66 UTIL_THROW(
"Error: nCellCut > Cell::MaxNCellCut");
72 if (grid_.
size() < 27) {
82 lengths[i] = upper_[i] - lower_[i];
86 if (lengths[i] < cutoffs[i]) {
89 gridDimensions[i] = int(lengths[i]*nCellCut/cutoffs[i]);
90 cellLengths_[i] = lengths[i]/double(gridDimensions[i]);
91 lowerOuter_[i] = lower_[i] - nCellCut*cellLengths_[i];
92 upperOuter_[i] = upper_[i] + nCellCut*cellLengths_[i];
95 gridDimensions[i] += 2*nCellCut;
97 if (gridDimensions[i] != grid_.
dimension(i)) {
108 int oldSize = cells_.size();
109 int newSize = grid_.
size();
110 if (newSize != oldSize) {
111 cells_.resize(newSize);
112 if (newSize > oldSize) {
113 for (
int i = 0; i < newSize; ++i) {
114 cells_[i].setOffsetArray(offsets_);
121 assert(newSize >= 27);
122 assert(newSize == cells_.size());
128 for (ic = 0; ic < newSize; ++ic) {
129 cells_[ic].setIsGhostCell(
true);
135 for (p[0] = nCellCut; p[0] < grid_.
dimension(0) - nCellCut; ++p[0]) {
136 for (p[1] = nCellCut; p[1] < grid_.
dimension(1) - nCellCut; ++p[1]) {
137 for (p[2] = nCellCut; p[2] < grid_.
dimension(2) - nCellCut; ++p[2]) {
139 cellPtr = &cells_[ic];
159 const Vector& cutoffs,
int nCellCut)
163 setGridDimensions(lower, upper, cutoffs, nCellCut);
174 q = cellLengths_[j]/cutoffs[j];
175 for (i = 1; i <= nCellCut; ++i) {
178 e[nCellCut + i][j] = r;
179 e[nCellCut - i][j] = r;
181 e[nCellCut][j] = 0.0;
191 std::pair<int, int> strip;
202 int offset0, offset1, offset;
206 bool isActive =
false;
207 for (i = -nCellCut; i <= nCellCut; ++i) {
208 e0 = e[i+nCellCut][0];
210 for (j = -nCellCut; j <= nCellCut; ++j) {
211 e1 = e0 + e[j + nCellCut][1];
212 offset1 = offset0 + j*span1;
213 for (k = -nCellCut; k <= nCellCut; ++k) {
214 offset = offset1 + k;
215 e2 = e1 + e[k + nCellCut][2];
219 if (offset == strip.second + 1) {
220 strip.second = offset;
223 strip.first = offset;
224 strip.second = offset;
227 strip.first = offset;
228 strip.second = offset;
259 if (grid_.
size() > 0) {
260 for (
int i = 0; i < grid_.
size(); ++i) {
283 for (
int i = 0; i < grid_.
size(); ++i) {
284 cellAtomPtr = cells_[i].initialize(cellAtomPtr);
288 for (
int i = 0; i < nAtom_; ++i) {
289 cells_[tags_[i].cellRank].append(tags_[i].ptr);
296 for (
int i = 0; i < grid_.
size(); ++i) {
297 nAtomCell = cells_[i].nAtom();
298 if (nAtomCell > maxNAtomCell_) {
299 maxNAtomCell_ = nAtomCell;
312 for (
int i = 0; i < nAtom_; ++i) {
333 int CellList::maxNAtomCell()
const 334 {
return maxNAtomCell_; }
347 {
return cells_.capacity(); }
363 UTIL_THROW(
"CellList is allocated but tags_.capacity() <= 0");
365 if (atoms_.capacity() <= 0) {
366 UTIL_THROW(
"CellList is allocated but atoms_.capacity() <= 0");
373 UTIL_THROW(
"CellList is built but not allocated");
381 for (
int icell = 0; icell < grid_.
size(); ++icell) {
382 cellPtr = &cells_[icell];
383 nAtomCell = cellPtr->
nAtom();
389 for (
int i = 0; i < nAtomCell; ++i) {
397 nAtomSum += nAtomCell;
403 if (nAtomSum != nAtom_) {
404 UTIL_THROW(
"Number of atoms in all cells != nAtom");
411 UTIL_THROW(
"CellList is not built, but nAtom_ != 0");
void makeGrid(const Vector &lower, const Vector &upper, const Vector &cutoffs, int nCellCut=1)
Make the cell grid (using generalized coordinates).
const int Dimension
Dimensionality of space.
A Vector is a Cartesian vector.
void clear()
Set logical size to zero.
Data for an atom in a CellList.
CellAtom * atomPtr(int i) const
Return a pointer to atom i.
virtual ~CellList()
Destructor.
static const int MaxNCellCut
Maximum number of cell per cutoff length.
void append(const Data &data)
Append data to the end of the array.
int nAtom() const
Get total number of atoms (local and ghost) in this CellList.
Parallel domain decomposition (DD) MD simulation.
bool isValid() const
Return true if valid, or throw Exception.
bool isBuilt() const
Has this CellList been built?
int dimension(int i) const
Get grid dimension along Cartesian direction i.
int atomCapacity() const
Maximum number of atoms for which space is allocated.
int size() const
Get total number of grid points.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void setNextCell(Cell &nextCell)
Set the pointer to the next cell in the list.
void update()
Update the cell list.
int nAtom() const
Number of atoms in cell.
Utility classes for scientific computation.
bool isAllocated() const
Has memory been allocated for this CellList?
void clear()
Reset the cell list to its empty state (no Atoms).
void setIsGhostCell(bool isGhostCell=true)
Mark as a ghost or local cell.
A fixed size (static) contiguous array template.
int rank(const IntVector &position) const
Get the rank of a grid point with specified position.
void setLastCell()
Set this to be the last cell in the list.
int nReject() const
Get number of atoms that were rejected (not placed in cells)
An IntVector is an integer Cartesian vector.
void allocate(int atomCapacity, const Vector &lower, const Vector &upper, const Vector &cutoffs, int nCellCut=1)
Allocate memory for this CellList (generalized coordinates).
int cellCapacity() const
Number of cells for which space has been allocated.
int capacity() const
Return allocated size.
void allocate(int capacity)
Allocate the underlying C array.
void setDimensions(const IntVector &dimensions)
Set the grid dimensions in all directions.
int atomCapacity() const
Capacity of array segment.
int cellIndexFromPosition(const Vector &position) const
Return the index of the cell that contains a position Vector.
void build()
Build the cell list.
A single Cell in a CellList.