9 #include <util/space/Vector.h> 10 #include <util/space/IntVector.h> 31 cellLengths_[i] = 0.0;
49 atoms_.allocate(atomCapacity);
52 setGridDimensions(lower, upper, cutoffs);
58 void CellList::setGridDimensions(
const Vector& lower,
const Vector& upper,
65 if (grid_.
size() < 27) {
76 lengths[i] = upper_[i] - lower_[i];
80 if (lengths[i] < cutoffs[i]) {
83 gridDimensions[i] = int(lengths[i]/cutoffs[i]);
84 cellLengths_[i] = lengths[i]/double(gridDimensions[i]);
86 if (gridDimensions[i] != grid_.
dimension(i)) {
95 gridOffsets_[Dimension - 1] = 1;
96 for (
int i = Dimension - 1; i > 0; --i) {
97 gridOffsets_[i-1] = gridOffsets_[i]*gridDimensions[i];
102 int oldSize = cells_.size();
103 int newSize = grid_.
size();
104 if (newSize != oldSize) {
105 cells_.resize(newSize);
106 if (newSize > oldSize) {
107 for (
int i = 0; i < newSize; ++i) {
114 assert(newSize >= 27);
115 assert(newSize == cells_.size());
124 for (p[0] = 0; p[0] < grid_.
dimension(0); ++p[0]) {
125 for (p[1] = 0; p[1] < grid_.
dimension(1); ++p[1]) {
126 for (p[2] = 0; p[2] < grid_.
dimension(2); ++p[2]) {
128 cellPtr = &cells_[ic];
150 setGridDimensions(lower, upper, cutoffs);
153 for (
int cellId = 0; cellId < grid_.
size(); cellId++) {
157 std::pair<int, int> axisOffset;
158 axisOffset.first = calculateAxisOffset(cellId, i, 1);
159 axisOffset.second = calculateAxisOffset(cellId, i, -1);
161 offsets->
append(axisOffset);
164 cells_[cellId].setOffsetArray(*offsets);
174 if (grid_.
size() > 0) {
175 for (
int i = 0; i < grid_.
size(); ++i) {
198 for (
int i = 0; i < grid_.
size(); ++i) {
199 cellAtomPtr = cells_[i].initialize(cellAtomPtr);
203 for (
int i = 0; i < nAtom_; ++i) {
204 cells_[tags_[i].cellRank].append(tags_[i].ptr);
211 for (
int i = 0; i < grid_.
size(); ++i) {
212 nAtomCell = cells_[i].nAtom();
213 if (nAtomCell > maxNAtomCell_) {
214 maxNAtomCell_ = nAtomCell;
227 for (
int i = 0; i < nAtom_; ++i) {
248 int CellList::maxNAtomCell()
const 249 {
return maxNAtomCell_; }
262 {
return cells_.capacity(); }
278 UTIL_THROW(
"CellList is allocated but tags_.capacity() <= 0");
280 if (atoms_.capacity() <= 0) {
281 UTIL_THROW(
"CellList is allocated but atoms_.capacity() <= 0");
288 UTIL_THROW(
"CellList is built but not allocated");
296 for (
int icell = 0; icell < grid_.
size(); ++icell) {
297 cellPtr = &cells_[icell];
298 nAtomCell = cellPtr->
nAtom();
304 for (
int i = 0; i < nAtomCell; ++i) {
312 nAtomSum += nAtomCell;
318 if (nAtomSum != nAtom_) {
319 UTIL_THROW(
"Number of atoms in all cells != nAtom");
326 UTIL_THROW(
"CellList is not built, but nAtom_ != 0");
const int Dimension
Dimensionality of space.
A Vector is a Cartesian vector.
void append(const Data &data)
Append data to the end of the array.
int dimension(int i) const
Get grid dimension along Cartesian direction i.
int size() const
Get total number of grid points.
A fixed capacity (static) contiguous array with a variable logical size.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.
int rank(const IntVector &position) const
Get the rank of a grid point with specified position.
An IntVector is an integer Cartesian vector.
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.