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