source: src/grid/grid.hpp@ 66f24d

Last change on this file since 66f24d was 48b662, checked in by Olaf Lenz <olenz@…>, 14 years ago

Moved files in scafacos_fcs one level up.

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

  • Property mode set to 100644
File size: 4.0 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_indexing.hpp"
15
16namespace VMG
17{
18
19class Comm;
20
21class Grid : public Object
22{
23public:
24 Grid()
25 {
26 grid = NULL;
27 }
28
29 Grid(const GlobalIndices& global_, const LocalIndices& local_, const SpatialExtent& extent_) :
30 global(global_),
31 local(local_),
32 extent(extent_)
33 {InitGrid();}
34
35 virtual ~Grid();
36
37 Grid(const Comm* comm, const Index& size, const vmg_float& width);
38
39 const GlobalIndices& Global() const {return global;}
40 const LocalIndices& Local() const {return local;}
41 const SpatialExtent& Extent() const {return extent;}
42
43 GlobalIndices& Global() {return global;}
44 LocalIndices& Local() {return local;}
45 SpatialExtent& Extent() {return extent;}
46
47 const vmg_float& MeshWidth() const {return Extent().MeshWidth().X();} ///< Mesh width of current level
48
49 static vmg_float& Correction() {return Grid::correction;}
50
51 void Clear(); ///< Overwrites all grid points on current level with zeros
52 void ClearInner();
53 void ClearHalo(); ///< Overwrites all halo points on current level with zeros
54 void ClearBoundary(); ///< Overwrites all boundary points on current level with zeros
55
56 vmg_float& operator()(int x, int y, int z); ///< Returns a reference to the requested gridpoint.
57 vmg_float& operator()(const Index& index);
58
59 const vmg_float& GetVal(int x, int y, int z) const; ///< Returns the value of a requested gridpoint.
60 const vmg_float& GetVal(const Index& index) const;
61
62 vmg_float GetCorrectedVal(int x, int y, int z) const {return this->GetVal(x, y, z) - correction;} ///< Return grid
63 vmg_float GetCorrectedVal(const Index& index) const {return this->GetVal(index) - correction;}
64
65 void ForceDiscreteCompatibilityCondition();
66 void SetAverageToZero();
67
68 void SetGrid(const Grid& rhs); ///< Overwrite current grid with values from another grid
69 void SetBoundary(const Grid& rhs); ///< Overwrite boundary with values from rhs
70
71 void AddGrid(const Grid& rhs); ///< Add values of another grid
72 void SubtractGrid(const Grid& rhs); ///< Subtract values of another grid
73 void MultiplyScalar(const vmg_float& scalar); ///< Multiply grid values with scalar
74 void ApplyStencil(const Stencil& stencil); ///< Apply stencil to grid
75
76 int GlobalLinearIndex(int x, int y, int z) const; ///< Compute a unique 1-dimensional global index
77 int GlobalLinearIndex(const Index& index) const;
78
79 Index GlobalToLocalIndex(const Index& index) const;
80
81 bool IsCompatible(const Grid& rhs) const; ///< Check if two grids share compatible settings
82 bool IsConsistent() const; ///< Check grid for nan and inf
83
84 virtual vmg_float DebugKnownSolution(Vector x) const {return 0.0;}
85 vmg_float DebugKnownSolution(Index i) const {return DebugKnownSolution(extent.Begin() + i * extent.MeshWidth());}
86
87private:
88 void InitGrid();
89
90protected:
91 GlobalIndices global;
92 LocalIndices local;
93 SpatialExtent extent;
94
95 vmg_float *grid;
96
97 static vmg_float correction;
98};
99
100inline vmg_float& Grid::operator()(int x, int y, int z)
101{
102 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
103}
104
105inline vmg_float& Grid::operator()(const Index& index)
106{
107 return this->operator()(index.X(), index.Y(), index.Z());
108}
109
110inline const vmg_float& Grid::GetVal(int x, int y, int z) const
111{
112 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
113}
114
115inline const vmg_float& Grid::GetVal(const Index& index) const
116{
117 return this->GetVal(index.X(), index.Y(), index.Z());
118}
119
120inline int Grid::GlobalLinearIndex(int x, int y, int z) const
121{
122 return z + global.Size().Z() * (y + global.Size().Y() * x);
123}
124
125inline int Grid::GlobalLinearIndex(const Index& index) const
126{
127 return GlobalLinearIndex(index.X(), index.Y(), index.Z());
128}
129
130inline Index Grid::GlobalToLocalIndex(const Index& index) const
131{
132 return index - Global().Begin() + Local().Begin();
133}
134
135}
136
137#endif /* GRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.