| 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 |
|
|---|
| 19 | namespace VMG
|
|---|
| 20 | {
|
|---|
| 21 |
|
|---|
| 22 | class Comm;
|
|---|
| 23 | class Multigrid;
|
|---|
| 24 | class Stencil;
|
|---|
| 25 |
|
|---|
| 26 | class Grid : public Object
|
|---|
| 27 | {
|
|---|
| 28 | public:
|
|---|
| 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_, const LocalIndices& local_, const SpatialExtent& extent_,
|
|---|
| 40 | int level_ = 0, Multigrid* father_ = NULL) :
|
|---|
| 41 | index_translations(this),
|
|---|
| 42 | level(level_),
|
|---|
| 43 | global(global_),
|
|---|
| 44 | local(local_),
|
|---|
| 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 | }
|
|---|
| 64 |
|
|---|
| 65 | virtual ~Grid();
|
|---|
| 66 |
|
|---|
| 67 | Grid& operator=(const Grid& rhs);
|
|---|
| 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 |
|
|---|
| 77 | GridIteratorSuite& Iterators() {return iterators;}
|
|---|
| 78 | const GridIteratorSuite& Iterators() const {return iterators;}
|
|---|
| 79 |
|
|---|
| 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 |
|
|---|
| 115 | Multigrid* Father() const {return father;}
|
|---|
| 116 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 126 | private:
|
|---|
| 127 | void InitGrid();
|
|---|
| 128 |
|
|---|
| 129 | GridIndexTranslations index_translations;
|
|---|
| 130 |
|
|---|
| 131 | protected:
|
|---|
| 132 | int level;
|
|---|
| 133 |
|
|---|
| 134 | GlobalIndices global;
|
|---|
| 135 | LocalIndices local;
|
|---|
| 136 | SpatialExtent extent;
|
|---|
| 137 |
|
|---|
| 138 | GridIteratorSuite iterators;
|
|---|
| 139 |
|
|---|
| 140 | vmg_float *grid;
|
|---|
| 141 |
|
|---|
| 142 | Multigrid* father;
|
|---|
| 143 |
|
|---|
| 144 | static vmg_float correction;
|
|---|
| 145 | };
|
|---|
| 146 |
|
|---|
| 147 | inline 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 |
|
|---|
| 152 | inline vmg_float& Grid::operator()(const Index& index)
|
|---|
| 153 | {
|
|---|
| 154 | return this->operator()(index.X(), index.Y(), index.Z());
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | inline 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 |
|
|---|
| 162 | inline const vmg_float& Grid::GetVal(const Index& index) const
|
|---|
| 163 | {
|
|---|
| 164 | return this->GetVal(index.X(), index.Y(), index.Z());
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | inline int Grid::GlobalLinearIndex(int x, int y, int z) const
|
|---|
| 168 | {
|
|---|
| 169 | return z + global.SizeGlobal().Z() * (y + global.SizeGlobal().Y() * x);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | inline 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_ */
|
|---|