Simpatico  v1.10
Grid.h
1 #ifndef UTIL_GRID_H
2 #define UTIL_GRID_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 #include <util/space/IntVector.h>
13 
14 namespace Util
15 {
16 
33  class Grid
34  {
35 
36  public:
37 
41  Grid();
42 
48  Grid(const IntVector& dimensions);
49 
50  // Compiler default destructor.
51 
52  // Compiler copy constructor.
53 
59  void setDimensions(const IntVector& dimensions);
60 
64  IntVector dimensions() const;
65 
71  int dimension(int i) const;
72 
76  int size() const;
77 
84  IntVector position(int rank) const;
85 
92  int rank(const IntVector& position) const;
93 
102  bool isInGrid(int coordinate, int i) const;
103 
112  bool isInGrid(IntVector& position) const;
113 
126  int shift(int& coordinate, int i) const;
127 
139  IntVector shift(IntVector& position) const;
140 
141  private:
142 
144  IntVector dimensions_;
145 
147  IntVector offsets_;
148 
150  int size_;
151 
152  };
153 
154  // Inline member functions
155 
157  { return dimensions_; }
158 
159  inline int Grid::dimension(int i) const
160  {
161  assert(i >=0);
162  assert(i < Dimension);
163  return dimensions_[i];
164  }
165 
166  inline int Grid::size() const
167  { return size_; }
168 
169 }
170 #endif
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
IntVector dimensions() const
Get an IntVector of the grid dimensions.
Definition: Grid.h:156
Grid()
Default constructor.
Definition: Grid.cpp:15
File containing preprocessor macros for error handling.
IntVector position(int rank) const
Get the position IntVector of a grid point with a specified rank.
Definition: Grid.cpp:64
int dimension(int i) const
Get grid dimension along Cartesian direction i.
Definition: Grid.h:159
bool isInGrid(int coordinate, int i) const
Is this coordinate in range?
Definition: Grid.cpp:78
int shift(int &coordinate, int i) const
Shift a periodic coordinate into range.
Definition: Grid.cpp:100
int size() const
Get total number of grid points.
Definition: Grid.h:166
Utility classes for scientific computation.
Definition: accumulators.mod:1
int rank(const IntVector &position) const
Get the rank of a grid point with specified position.
Definition: Grid.cpp:49
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:73
A grid of points indexed by integer coordinates.
Definition: Grid.h:33
void setDimensions(const IntVector &dimensions)
Set the grid dimensions in all directions.
Definition: Grid.cpp:32