lbm_reference
Grid.h
Go to the documentation of this file.
1 //! \file Grid.h
2 //! \date Jan 2, 2009
3 //! \author Florian Rathgeber
4 
5 #ifndef GRID_H_
6 #define GRID_H_
7 
8 #include <assert.h>
9 #include <vector>
10 
11 //! 3-dimensional grid of Cells with template specifyable number of cell
12 //! variables and type
13 
14 //! \tparam T Type of cell variables
15 //! \tparam Cellsize Number of cell variables
16 
17 template<typename T, int Cellsize>
18 class Grid {
19 
20 public:
21 
22  // ============================ //
23  // Constructors and destructors //
24  // ============================ //
25 
26  //! Default constructor
27 
28  //! Creates a grid with zero cells in each dimension
29 
30  Grid();
31 
32  //! Constructor to specify grid dimensions
33 
34  //! \param[in] sizeX Grid size in x-dimension
35  //! \param[in] sizeY Grid size in y-dimension
36  //! \param[in] sizeZ Grid size in z-dimension
37 
38  Grid(int sizeX, int sizeY, int sizeZ);
39 
40  //! Constructor to specify grid dimensions and initialization value
41 
42  //! \param[in] sizeX Grid size in x-dimension
43  //! \param[in] sizeY Grid size in y-dimension
44  //! \param[in] sizeZ Grid size in z-dimension
45  //! \param[in] val Initial value for all cell variables
46 
47  Grid(int sizeX, int sizeY, int sizeZ, T val);
48 
49  //! Destructor
50 
51  //! Clears the vector of cell variables
52 
53  virtual ~Grid();
54 
55  // ============= //
56  // Set operators //
57  // ============= //
58 
59  //! Initialize the grid with given dimensions and initial value
60 
61  //! \param[in] sizeX Grid size in x-dimension
62  //! \param[in] sizeY Grid size in y-dimension
63  //! \param[in] sizeZ Grid size in z-dimension
64  //! \param[in] val Initial value for all cell variables
65 
66  void init( int sizeX, int sizeY, int sizeZ, T val );
67 
68  //! Initialize the grid with given initial value
69 
70  //! \param[in] val Initial value for all cell variables
71 
72  void init( T val );
73 
74  // ================ //
75  // Access operators //
76  // ================ //
77 
78  //! Get size in x-dimension
79 
80  //! \returns Grid size in x-dimension
81 
82  inline int getSizeX() {
83  return sizeX_;
84  }
85 
86  //! Get size in y-dimension
87 
88  //! \returns Grid size in y-dimension
89 
90  inline int getSizeY() {
91  return sizeY_;
92  }
93 
94  //! Get size in z-dimension
95 
96  //! \returns Grid size in z-dimension
97 
98  inline int getSizeZ() {
99  return sizeZ_;
100  }
101 
102  //! Get specified cell variable of specified cell
103 
104  //! \param[in] x Cell coordinate in x-dimension
105  //! \param[in] y Cell coordinate in y-dimension
106  //! \param[in] z Cell coordinate in z-dimension
107  //! \param[in] f Cell variable index
108  //! \return Reference to specified cell variable of specified cell
109 
110  inline T& operator()(int x, int y, int z, int f);
111 
112  //! Get specified const cell variable of specified cell
113 
114  //! \param[in] x Cell coordinate in x-dimension
115  //! \param[in] y Cell coordinate in y-dimension
116  //! \param[in] z Cell coordinate in z-dimension
117  //! \param[in] f Cell variable index
118  //! \return Const reference to specified cell variable of specified cell
119 
120  inline const T& operator()(int x, int y, int z, int f) const;
121 
122 protected:
123 
124  // ============ //
125  // Data members //
126  // ============ //
127 
128  //! Number of cells in x-dimension
129 
130  int sizeX_;
131 
132  //! Number of cells in y-dimension
133 
134  int sizeY_;
135 
136  //! Number of cells in z-dimension
137 
138  int sizeZ_;
139 
140  //! Linearized, 1-dimensional representation of the 3D data grid
141 
142  std::vector<T> data_;
143 
144 };
145 
146 
147 //! 3-dimensional grid of cells with template type, specialization to a single
148 //! cell variable
149 
150 //! \tparam T Type of cell variables
151 
152 template<typename T>
153 class Grid<T,1> {
154 
155 public:
156 
157  // ============================ //
158  // Constructors and destructors //
159  // ============================ //
160 
161  //! Default constructor
162 
163  //! Creates a grid with zero cells in each dimension
164 
165  Grid();
166 
167  //! Constructor to specify grid dimensions
168 
169  //! \param[in] sizeX Grid size in x-dimension
170  //! \param[in] sizeY Grid size in y-dimension
171  //! \param[in] sizeZ Grid size in z-dimension
172 
173  Grid(int sizeX, int sizeY, int sizeZ);
174 
175  //! Constructor to specify grid dimensions and initialization value
176 
177  //! \param[in] sizeX Grid size in x-dimension
178  //! \param[in] sizeY Grid size in y-dimension
179  //! \param[in] sizeZ Grid size in z-dimension
180  //! \param[in] val Initial value for cells
181 
182  Grid(int sizeX, int sizeY, int sizeZ, T val);
183 
184  //! Destructor
185 
186  //! Clears the vector of cell variables
187 
188  virtual ~Grid();
189 
190  // ============= //
191  // Set operators //
192  // ============= //
193 
194  //! Initialize the grid with given dimensions and initial value
195 
196  //! \param[in] sizeX Grid size in x-dimension
197  //! \param[in] sizeY Grid size in y-dimension
198  //! \param[in] sizeZ Grid size in z-dimension
199  //! \param[in] val Initial value for cells
200 
201  void init( int sizeX, int sizeY, int sizeZ, T val );
202 
203  //! Initialize the grid with given initial value
204 
205  //! \param[in] val Initial value for cells
206 
207  void init( T val );
208 
209  // ================ //
210  // Access operators //
211  // ================ //
212 
213  //! Get size in x-dimension
214 
215  //! \returns Grid size in x-dimension
216 
217  inline int getSizeX() {
218  return sizeX_;
219  }
220 
221  //! Get size in y-dimension
222 
223  //! \returns Grid size in y-dimension
224 
225  inline int getSizeY() {
226  return sizeY_;
227  }
228 
229  //! Get size in z-dimension
230 
231  //! \returns Grid size in z-dimension
232 
233  inline int getSizeZ() {
234  return sizeZ_;
235  }
236 
237  //! Get cell variable of specified cell
238 
239  //! \param[in] x Cell coordinate in x-dimension
240  //! \param[in] y Cell coordinate in y-dimension
241  //! \param[in] z Cell coordinate in z-dimension
242  //! \return Reference to specified cell variable of specified cell
243 
244  inline T& operator()(int x, int y, int z);
245 
246  //! Get specified constant cell variable of specified cell
247 
248  //! \param[in] x Cell coordinate in x-dimension
249  //! \param[in] y Cell coordinate in y-dimension
250  //! \param[in] z Cell coordinate in z-dimension
251  //! \return Constant reference to specified cell variable of specified cell
252 
253  inline const T& operator()(int x, int y, int z) const;
254 
255 protected:
256 
257  //! Number of cells in x-dimension
258 
259  int sizeX_;
260 
261  //! Number of cells in y-dimension
262 
263  int sizeY_;
264 
265  //! Number of cells in z-dimension
266 
267  int sizeZ_;
268 
269  //! Linearized, 1-dimensional representation of the 3D data grid
270 
271  std::vector<T> data_;
272 
273 };
274 
275 // include the definitions
276 #include "Grid_def.h"
277 
278 #endif /* GRID_H_ */