source: src/grid/grid.hpp@ e3da7f

Last change on this file since e3da7f was a72216, checked in by Olaf Lenz <olenz@…>, 13 years ago

Fixed permissions.

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

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[fcf7f6]1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
[48b662]19/**
20 * @file grid.hpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 12:53:45 2011
23 *
24 * @brief VMG::Grid
25 *
26 */
27
28#ifndef GRID_HPP_
29#define GRID_HPP_
30
31#include "base/object.hpp"
[dfed1c]32#include "grid/grid_index_translations.hpp"
33#include "grid/grid_iterator.hpp"
34#include "grid/grid_iterator_suite.hpp"
35#include "grid/grid_properties.hpp"
[48b662]36
37namespace VMG
38{
39
40class Comm;
[dfed1c]41class Multigrid;
42class Stencil;
[48b662]43
44class Grid : public Object
45{
46public:
[dfed1c]47 typedef GridIterator iterator;
48
49 Grid(int level_ = 0, Multigrid* father_ = NULL) :
50 index_translations(this),
51 level(level_),
52 father(father_)
[48b662]53 {
54 grid = NULL;
55 }
56
[ac6d04]57 Grid(const GlobalIndices& global_,
58 const LocalIndices& local_,
59 const SpatialExtent& extent_,
60 int level_ = 0,
61 Multigrid* father_ = NULL) :
[dfed1c]62 index_translations(this),
63 level(level_),
[48b662]64 global(global_),
65 local(local_),
[dfed1c]66 extent(extent_),
67 iterators(local_),
68 father(father_)
69 {
70 InitGrid();
71 }
72
73 Grid(const Grid& rhs) :
74 index_translations(rhs.Indexing()),
75 level(rhs.Level()),
76 global(rhs.Global()),
77 local(rhs.Local()),
78 extent(rhs.Extent()),
79 iterators(rhs.Iterators()),
80 father(rhs.Father())
81 {
82 InitGrid();
83 SetGrid(rhs);
84 }
[48b662]85
86 virtual ~Grid();
87
[dfed1c]88 Grid& operator=(const Grid& rhs);
[48b662]89
90 GlobalIndices& Global() {return global;}
91 LocalIndices& Local() {return local;}
92 SpatialExtent& Extent() {return extent;}
93
[ac6d04]94 const GlobalIndices& Global() const {return global;}
95 const LocalIndices& Local() const {return local;}
96 const SpatialExtent& Extent() const {return extent;}
97
[dfed1c]98 GridIteratorSuite& Iterators() {return iterators;}
99 const GridIteratorSuite& Iterators() const {return iterators;}
100
[48b662]101 void Clear(); ///< Overwrites all grid points on current level with zeros
102 void ClearInner();
103 void ClearHalo(); ///< Overwrites all halo points on current level with zeros
104 void ClearBoundary(); ///< Overwrites all boundary points on current level with zeros
105
106 vmg_float& operator()(int x, int y, int z); ///< Returns a reference to the requested gridpoint.
107 vmg_float& operator()(const Index& index);
108
109 const vmg_float& GetVal(int x, int y, int z) const; ///< Returns the value of a requested gridpoint.
110 const vmg_float& GetVal(const Index& index) const;
111
112 void ForceDiscreteCompatibilityCondition();
113 void SetAverageToZero();
114
115 void SetGrid(const Grid& rhs); ///< Overwrite current grid with values from another grid
116 void SetBoundary(const Grid& rhs); ///< Overwrite boundary with values from rhs
117
118 void AddGrid(const Grid& rhs); ///< Add values of another grid
119 void SubtractGrid(const Grid& rhs); ///< Subtract values of another grid
120 void MultiplyScalar(const vmg_float& scalar); ///< Multiply grid values with scalar
121 void ApplyStencil(const Stencil& stencil); ///< Apply stencil to grid
122
123 int GlobalLinearIndex(int x, int y, int z) const; ///< Compute a unique 1-dimensional global index
124 int GlobalLinearIndex(const Index& index) const;
125
126 bool IsCompatible(const Grid& rhs) const; ///< Check if two grids share compatible settings
127 bool IsConsistent() const; ///< Check grid for nan and inf
128
[dfed1c]129 Multigrid* Father() const {return father;}
130
[48b662]131 virtual vmg_float DebugKnownSolution(Vector x) const {return 0.0;}
132 vmg_float DebugKnownSolution(Index i) const {return DebugKnownSolution(extent.Begin() + i * extent.MeshWidth());}
133
[dfed1c]134 const GridIndexTranslations& Indexing() const {return index_translations;}
135
136 const int& Level() const {return level;}
137
138 bool IsActive() const {return Local().Size().Product() > 0;}
139
[48b662]140private:
141 void InitGrid();
142
[dfed1c]143 GridIndexTranslations index_translations;
144
[48b662]145protected:
[dfed1c]146 int level;
147
[48b662]148 GlobalIndices global;
149 LocalIndices local;
150 SpatialExtent extent;
151
[dfed1c]152 GridIteratorSuite iterators;
153
[48b662]154 vmg_float *grid;
155
[dfed1c]156 Multigrid* father;
[48b662]157};
158
159inline vmg_float& Grid::operator()(int x, int y, int z)
160{
161 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
162}
163
164inline vmg_float& Grid::operator()(const Index& index)
165{
166 return this->operator()(index.X(), index.Y(), index.Z());
167}
168
169inline const vmg_float& Grid::GetVal(int x, int y, int z) const
170{
171 return grid[z + local.SizeTotal().Z() * (y + local.SizeTotal().Y() * x)];
172}
173
174inline const vmg_float& Grid::GetVal(const Index& index) const
175{
176 return this->GetVal(index.X(), index.Y(), index.Z());
177}
178
179inline int Grid::GlobalLinearIndex(int x, int y, int z) const
180{
[ac6d04]181 return z + global.GlobalSize().Z() * (y + global.GlobalSize().Y() * x);
[48b662]182}
183
184inline int Grid::GlobalLinearIndex(const Index& index) const
185{
186 return GlobalLinearIndex(index.X(), index.Y(), index.Z());
187}
188
189}
190
191#endif /* GRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.