source: src/grid/grid.hpp@ ac6d04

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

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

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

  • Property mode set to 100644
File size: 4.9 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 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
116 Multigrid* Father() const {return father;}
117
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
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
127private:
128 void InitGrid();
129
130 GridIndexTranslations index_translations;
131
132protected:
133 int level;
134
135 GlobalIndices global;
136 LocalIndices local;
137 SpatialExtent extent;
138
139 GridIteratorSuite iterators;
140
141 vmg_float *grid;
142
143 Multigrid* father;
144
145 static vmg_float correction;
146};
147
148inline 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
153inline vmg_float& Grid::operator()(const Index& index)
154{
155 return this->operator()(index.X(), index.Y(), index.Z());
156}
157
158inline 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
163inline const vmg_float& Grid::GetVal(const Index& index) const
164{
165 return this->GetVal(index.X(), index.Y(), index.Z());
166}
167
168inline int Grid::GlobalLinearIndex(int x, int y, int z) const
169{
170 return z + global.GlobalSize().Z() * (y + global.GlobalSize().Y() * x);
171}
172
173inline 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_ */
Note: See TracBrowser for help on using the repository browser.