36 if (dimensions[i] <= 0) {
37 UTIL_THROW(
"Grid dimensions must be positive");
42 offsets_[Dimension -1] = 1;
43 for (i = Dimension - 1; i > 0; --i) {
44 offsets_[i-1] = offsets_[i]*dimensions_[i];
46 size_ = offsets_[0]*dimensions_[0];
54 assert(position[i] >= 0);
55 assert(position[i] < dimensions_[i]);
56 result += position[i]*offsets_[i];
58 assert(position[i] >= 0);
59 assert(position[i] < dimensions_[i]);
60 result += position[i];
71 position[i] = remainder/offsets_[i];
72 remainder -= position[i]*offsets_[i];
74 position[i] = remainder;
83 if (coordinate >= dimensions_[i])
94 if (position[i] >= dimensions_[i])
103 if (coordinate >= 0) {
104 shift = coordinate/dimensions_[i];
106 shift = -1 + ((coordinate+1)/dimensions_[i]);
108 coordinate -= shift*dimensions_[i];
116 shifts[i] =
shift(position[i], i);
const int Dimension
Dimensionality of space.
IntVector dimensions() const
Get an IntVector of the grid dimensions.
Grid()
Default constructor.
File containing preprocessor macros for error handling.
IntVector position(int rank) const
Get the position IntVector of a grid point with a specified rank.
bool isInGrid(int coordinate, int i) const
Is this coordinate in range?
int shift(int &coordinate, int i) const
Shift a periodic coordinate into range.
#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.
void setDimensions(const IntVector &dimensions)
Set the grid dimensions in all directions.