source: src/grid/grid.hpp@ d24c2f

Last change on this file since d24c2f was dfed1c, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Major vmg update.

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

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