source: src/grid/grid.hpp@ 1a92cf

Last change on this file since 1a92cf was 4571da, checked in by Julian Iseringhausen <isering@…>, 14 years ago

vmg: Implement fourth-order discretization of the Poisson equation.

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

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/**
2 * @file grid.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 12:53:45 2011
5 *
6 * @brief VMG::Grid
7 *
8 */
9
10#ifndef GRID_HPP_
11#define GRID_HPP_
12
13#include "base/object.hpp"
14#include "grid/grid_index_translations.hpp"
15#include "grid/grid_iterator.hpp"
16#include "grid/grid_iterator_suite.hpp"
17#include "grid/grid_properties.hpp"
18
19namespace VMG
20{
21
22class Comm;
23class Multigrid;
24class Stencil;
25
26class Grid : public Object
27{
28public:
29 typedef GridIterator iterator;
30
31 Grid(int level_ = 0, Multigrid* father_ = NULL) :
32 index_translations(this),
33 level(level_),
34 father(father_)
35 {
36 grid = NULL;
37 }
38
39 Grid(const GlobalIndices& global_,
40 const LocalIndices& local_,
41 const SpatialExtent& extent_,
42 int level_ = 0,
43 Multigrid* father_ = NULL) :
44 index_translations(this),
45 level(level_),
46 global(global_),
47 local(local_),
48 extent(extent_),
49 iterators(local_),
50 father(father_)
51 {
52 InitGrid();
53 }
54
55 Grid(const Grid& rhs) :
56 index_translations(rhs.Indexing()),
57 level(rhs.Level()),
58 global(rhs.Global()),
59 local(rhs.Local()),
60 extent(rhs.Extent()),
61 iterators(rhs.Iterators()),
62 father(rhs.Father())
63 {
64 InitGrid();
65 SetGrid(rhs);
66 }
67
68 virtual ~Grid();
69
70 Grid& operator=(const Grid& rhs);
71
72 GlobalIndices& Global() {return global;}
73 LocalIndices& Local() {return local;}
74 SpatialExtent& Extent() {return extent;}
75
76 const GlobalIndices& Global() const {return global;}
77 const LocalIndices& Local() const {return local;}
78 const SpatialExtent& Extent() const {return extent;}
79
80 GridIteratorSuite& Iterators() {return iterators;}
81 const GridIteratorSuite& Iterators() const {return iterators;}
82
83 void Clear(); ///< Overwrites all grid points on current level with zeros
84 void ClearInner();
85 void ClearHalo(); ///< Overwrites all halo points on current level with zeros
86 void ClearBoundary(); ///< Overwrites all boundary points on current level with zeros
87
88 vmg_float& operator()(int x, int y, int z); ///< Returns a reference to the requested gridpoint.
89 vmg_float& operator()(const Index& index);
90
91 const vmg_float& GetVal(int x, int y, int z) const; ///< Returns the value of a requested gridpoint.
92 const vmg_float& GetVal(const Index& index) const;
93
94 void ForceDiscreteCompatibilityCondition();
95 void SetAverageToZero();
96
97 void SetGrid(const Grid& rhs); ///< Overwrite current grid with values from another grid
98 void SetBoundary(const Grid& rhs); ///< Overwrite boundary with values from rhs
99
100 void AddGrid(const Grid& rhs); ///< Add values of another grid
101 void SubtractGrid(const Grid& rhs); ///< Subtract values of another grid
102 void MultiplyScalar(const vmg_float& scalar); ///< Multiply grid values with scalar
103 void ApplyStencil(const Stencil& stencil); ///< Apply stencil to grid
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 bool IsCompatible(const Grid& rhs) const; ///< Check if two grids share compatible settings
109 bool IsConsistent() const; ///< Check grid for nan and inf
110
111 Multigrid* Father() const {return father;}
112
113 virtual vmg_float DebugKnownSolution(Vector x) const {return 0.0;}
114 vmg_float DebugKnownSolution(Index i) const {return DebugKnownSolution(extent.Begin() + i * extent.MeshWidth());}
115
116 const GridIndexTranslations& Indexing() const {return index_translations;}
117
118 const int& Level() const {return level;}
119
120 bool IsActive() const {return Local().Size().Product() > 0;}
121
122private:
123 void InitGrid();
124
125 GridIndexTranslations index_translations;
126
127protected:
128 int level;
129
130 GlobalIndices global;
131 LocalIndices local;
132 SpatialExtent extent;
133
134 GridIteratorSuite iterators;
135
136 vmg_float *grid;
137
138 Multigrid* father;
139};
140
141inline vmg_float& Grid::operator()(int x, int y, int z)
142{
143 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
144}
145
146inline vmg_float& Grid::operator()(const Index& index)
147{
148 return this->operator()(index.X(), index.Y(), index.Z());
149}
150
151inline const vmg_float& Grid::GetVal(int x, int y, int z) const
152{
153 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
154}
155
156inline const vmg_float& Grid::GetVal(const Index& index) const
157{
158 return this->GetVal(index.X(), index.Y(), index.Z());
159}
160
161inline int Grid::GlobalLinearIndex(int x, int y, int z) const
162{
163 return z + global.GlobalSize().Z() * (y + global.GlobalSize().Y() * x);
164}
165
166inline int Grid::GlobalLinearIndex(const Index& index) const
167{
168 return GlobalLinearIndex(index.X(), index.Y(), index.Z());
169}
170
171}
172
173#endif /* GRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.