source: src/grid/is_grid.hpp@ 6f05224

Last change on this file since 6f05224 was 65f11de, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Minor vmg fix to comply with the standard.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1670 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[dfed1c]1/**
2 * @file is_grid.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 12:53:45 2011
5 *
6 * @brief Grid-like class that holds arbitrary data.
7 *
8 */
9
10#ifndef IS_GRID_HPP_
11#define IS_GRID_HPP_
12
13#include "base/object.hpp"
14#include "grid/grid.hpp"
15#include "grid/grid_index_translations.hpp"
16#include "grid/grid_iterator.hpp"
17#include "grid/grid_iterator_suite.hpp"
18#include "grid/grid_properties.hpp"
19
20namespace VMG
21{
22
23class Comm;
24class Grid;
25class Multigrid;
26class Stencil;
27
28template <class T>
29class IsGrid
30{
31public:
32 typedef GridIterator iterator;
33
34 IsGrid(int level = 0) :
35 level(level)
36 {
37 grid = NULL;
38 }
39
40 IsGrid(const GlobalIndices& global,
41 const LocalIndices& local,
42 const SpatialExtent& extent,
43 int level = 0) :
44 level(level),
45 global(global),
46 local(local),
47 extent(extent),
48 iterators(local)
49 {
50 InitIsGrid();
51 }
52
53 IsGrid(const IsGrid& rhs) :
54 level(rhs.Level()),
55 global(rhs.Global()),
56 local(rhs.Local()),
57 extent(rhs.Extent()),
58 iterators(rhs.Iterators())
59 {
60 InitIsGrid();
61 SetGrid(rhs);
62 }
63
64 IsGrid(const Grid& rhs) :
65 level(rhs.Level()),
66 global(rhs.Global()),
67 local(rhs.Local()),
68 extent(rhs.Extent()),
69 iterators(rhs.Iterators())
70 {
71 InitIsGrid();
72 }
73
74 virtual ~IsGrid();
75
76 void SetGridSize(const Grid& grid);
77 void SetGridSize(const GlobalIndices& global,
78 const LocalIndices& local,
79 const SpatialExtent& extent);
80
81 IsGrid& operator=(const IsGrid& rhs);
82
83 const GlobalIndices& Global() const {return global;}
84 const LocalIndices& Local() const {return local;}
85 const SpatialExtent& Extent() const {return extent;}
86
87 GlobalIndices& Global() {return global;}
88 LocalIndices& Local() {return local;}
89 SpatialExtent& Extent() {return extent;}
90
91 GridIteratorSuite& Iterators() {return iterators;}
92 const GridIteratorSuite& Iterators() const {return iterators;}
93
94 const vmg_float& MeshWidth() const {return Extent().MeshWidth().X();} ///< Mesh width of current level
95
96 T& operator()(int x, int y, int z); ///< Returns a reference to the requested gridpoint.
97 T& operator()(const Index& index);
98
99 const T& GetVal(int x, int y, int z) const; ///< Returns the value of a requested gridpoint.
100 const T& GetVal(const Index& index) const;
101
102 void SetGrid(const IsGrid& rhs); ///< Overwrite current grid with values from another grid
103 void SetBoundary(const IsGrid& rhs); ///< Overwrite boundary with values from rhs
104
105 int GlobalLinearIndex(int x, int y, int z) const; ///< Compute a unique 1-dimensional global index
106 int GlobalLinearIndex(const Index& index) const;
107
108 const int& Level() const {return level;}
109
110 bool IsActive() const {return Local().Size().Product() > 0;}
111
112private:
113 void InitIsGrid();
114
115protected:
116 int level;
117
118 GlobalIndices global;
119 LocalIndices local;
120 SpatialExtent extent;
121
122 GridIteratorSuite iterators;
123
124 T* grid;
125
126 static vmg_float correction;
127};
128
129template <class T>
130inline T& IsGrid<T>::operator()(int x, int y, int z)
131{
132 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
133}
134
135template <class T>
136inline T& IsGrid<T>::operator()(const Index& index)
137{
138 return this->operator()(index.X(), index.Y(), index.Z());
139}
140
141template <class T>
142inline const T& IsGrid<T>::GetVal(int x, int y, int z) const
143{
144 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
145}
146
147template <class T>
148inline const T& IsGrid<T>::GetVal(const Index& index) const
149{
150 return this->GetVal(index.X(), index.Y(), index.Z());
151}
152
153template <class T>
154inline int IsGrid<T>::GlobalLinearIndex(int x, int y, int z) const
155{
[ac6d04]156 return z + global.GlobalSize().Z() * (y + global.GlobalSize().Y() * x);
[dfed1c]157}
158
159template <class T>
160inline int IsGrid<T>::GlobalLinearIndex(const Index& index) const
161{
[ac6d04]162 return index.Z() + global.GlobalSize().Z() * (index.Y() + global.GlobalSize().Y() * index.X());
[dfed1c]163}
164
165template <class T>
166void IsGrid<T>::InitIsGrid()
167{
168 grid = new T[local.SizeTotal().Product()];
169}
170
171template <class T>
172IsGrid<T>::~IsGrid()
173{
174 delete [] grid;
175}
176
177template <class T>
[facba0]178void IsGrid<T>::SetGridSize(const Grid& rhs)
[dfed1c]179{
[facba0]180 global = rhs.Global();
181 local = rhs.Local();
182 extent = rhs.Extent();
183 iterators = rhs.Iterators();
184 level = rhs.Level();
[dfed1c]185
186 delete [] grid;
187 grid = new T[local.SizeTotal().Product()];
188}
189
190template <class T>
191void IsGrid<T>::SetGridSize(const GlobalIndices& global_,
192 const LocalIndices& local_,
193 const SpatialExtent& extent_)
194{
195 global = global_;
196 local = local_;
197 extent = extent_;
198 iterators.SetSubgrids(local);
199 level = 0;
200 delete [] grid;
201 grid = new T[local.SizeTotal().Product()];
202}
203
204template <class T>
205IsGrid<T>& IsGrid<T>::operator=(const IsGrid<T>& rhs)
206{
207 if (this != &rhs) {
208
209 global = rhs.Global();
210 local = rhs.Local();
211 extent = rhs.Extent();
212 iterators = rhs.Iterators();
213 level = rhs.Level();
214
215 delete [] grid;
216 grid = new T[local.SizeTotal().Product()];
217
218 SetGrid(rhs);
219
220 }
221
222 return *this;
223}
224
225template <class T>
226void IsGrid<T>::SetGrid(const IsGrid<T>& rhs)
227{
[65f11de]228 for (typename IsGrid<T>::iterator iter = Iterators().CompleteGrid().Begin(); iter != Iterators().CompleteGrid().End(); ++iter)
[dfed1c]229 (*this)(*iter) = rhs.GetVal(*iter);
230}
231
232template <class T>
233void IsGrid<T>::SetBoundary(const IsGrid<T>& rhs)
234{
[65f11de]235 typename IsGrid<T>::iterator iter;
[dfed1c]236
237 for (int i=0; i<3; ++i) {
238
239 for (iter = Iterators().Boundary1()[i].Begin(); iter != Iterators().Boundary1()[i].End(); ++iter)
240 (*this)(*iter) = rhs.GetVal(*iter);
241
242 for (iter = Iterators().Boundary2()[i].Begin(); iter != Iterators().Boundary2()[i].End(); ++iter)
243 (*this)(*iter) = rhs.GetVal(*iter);
244
245 }
246}
247
248
249}
250
251#endif /* GRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.