3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
basegridgeometry.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_BASE_GRID_GEOMETRY_HH
25#define DUMUX_DISCRETIZATION_BASE_GRID_GEOMETRY_HH
26
27#include <type_traits>
28
29#include <dune/grid/common/mcmgmapper.hh>
30
35
36// make the local view function available whenever we use the grid geometry
38
39namespace Dumux {
40
47template<class GV, class Traits>
49{
53
54 static constexpr int dim = GV::dimension;
55 static constexpr int dimWorld = GV::dimensionworld;
56
57 using GridIndexType = typename IndexTraits<GV>::GridIndex;
58 using Element = typename GV::template Codim<0>::Entity;
59
60public:
62 using Grid = typename GV::Grid;
64 using GridView = GV;
66 using GlobalCoordinate = typename Element::Geometry::GlobalCoordinate;
68 using ElementMapper = typename Traits::ElementMapper;
70 using VertexMapper = typename Traits::VertexMapper;
71
78 : gridView_(gridView)
79 , elementMapper_(makeElementMapper_(gridView))
80 , vertexMapper_(makeVertexMapper_(gridView))
81 , bBoxMin_(std::numeric_limits<double>::max())
82 , bBoxMax_(-std::numeric_limits<double>::max())
83 {
84 computeGlobalBoundingBox_();
85 }
86
90 void update()
91 {
93 vertexMapper_.update();
94 elementMapper_.update();
95
97 computeGlobalBoundingBox_();
98
100 boundingBoxTree_.release();
101 elementMap_.reset();
102 }
103
107 const GridView& gridView() const
108 { return gridView_; }
109
114 { return vertexMapper_; }
115
120 { return elementMapper_; }
121
126 { return vertexMapper_; }
127
132 { return elementMapper_; }
133
138 {
139 if(!boundingBoxTree_)
140 {
141 elementMap(); // make sure the element map is built
142 boundingBoxTree_ = std::make_unique<BoundingBoxTree>
143 ( std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_) );
144 }
145
146 return *boundingBoxTree_;
147 }
148
152 const ElementMap& elementMap() const
153 {
154 if(!elementMap_)
155 elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_);
156
157 return *elementMap_;
158 }
159
163 Element element(GridIndexType eIdx) const
164 { return elementMap()[eIdx]; }
165
171 { return bBoxMin_; }
172
178 { return bBoxMax_; }
179
183 bool isPeriodic() const
184 { return periodic_; }
185
189 void setPeriodic(bool value = true)
190 { periodic_ = value; }
191
192private:
193
195 ElementMapper makeElementMapper_(const GridView& gridView) const
196 {
197 if constexpr (std::is_constructible<ElementMapper, GridView, Dune::MCMGLayout>())
198 return ElementMapper(gridView, Dune::mcmgElementLayout());
199 else
200 return ElementMapper(gridView);
201 }
202
204 VertexMapper makeVertexMapper_(const GridView& gridView) const
205 {
206 if constexpr (std::is_constructible<VertexMapper, GridView, Dune::MCMGLayout>())
207 return VertexMapper(gridView, Dune::mcmgVertexLayout());
208 else
209 return VertexMapper(gridView);
210 }
211
213 void computeGlobalBoundingBox_()
214 {
215 // calculate the bounding box of the local partition of the grid view
216 for (const auto& vertex : vertices(gridView_))
217 {
218 for (int i=0; i<dimWorld; i++)
219 {
220 using std::min;
221 using std::max;
222 bBoxMin_[i] = min(bBoxMin_[i], vertex.geometry().corner(0)[i]);
223 bBoxMax_[i] = max(bBoxMax_[i], vertex.geometry().corner(0)[i]);
224 }
225 }
226
227 // communicate to get the bounding box of the whole domain
228 if (gridView_.comm().size() > 1)
229 {
230 for (int i = 0; i < dimWorld; ++i)
231 {
232 bBoxMin_[i] = gridView_.comm().min(bBoxMin_[i]);
233 bBoxMax_[i] = gridView_.comm().max(bBoxMax_[i]);
234 }
235 }
236 }
237
239 const GridView gridView_;
240
242 ElementMapper elementMapper_;
243 VertexMapper vertexMapper_;
244
246 mutable std::unique_ptr<BoundingBoxTree> boundingBoxTree_;
247
249 mutable std::shared_ptr<ElementMap> elementMap_;
250
252 GlobalCoordinate bBoxMin_;
253 GlobalCoordinate bBoxMax_;
254
256 bool periodic_ = false;
257};
258
259} // end namespace Dumux
260
261#endif
A map from indices to entities using grid entity seeds.
Defines the index types used for grid and local indices.
Free function to get the local view of a grid cache object.
BaseGridGeometry(const GridView &gridView)
Constructor computes the bouding box of the entire domain, for e.g. setting boundary conditions.
Definition: basegridgeometry.hh:77
Definition: adapt.hh:29
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:39
Struture to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Base class for all finite volume grid geometries.
Definition: basegridgeometry.hh:49
GV GridView
export the grid view type
Definition: basegridgeometry.hh:64
typename GV::Grid Grid
export the grid type
Definition: basegridgeometry.hh:62
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basegridgeometry.hh:119
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition: basegridgeometry.hh:189
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition: basegridgeometry.hh:177
const BoundingBoxTree & boundingBoxTree() const
Returns the bounding box tree of the grid.
Definition: basegridgeometry.hh:137
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basegridgeometry.hh:163
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition: basegridgeometry.hh:113
VertexMapper & vertexMapper()
Returns the mapper for vertices to indices for possibly adaptive grids.
Definition: basegridgeometry.hh:125
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basegridgeometry.hh:107
void update()
Update all fvElementGeometries (do this again after grid adaption)
Definition: basegridgeometry.hh:90
ElementMapper & elementMapper()
Returns the mapper for elements to indices for possibly adaptive grids.
Definition: basegridgeometry.hh:131
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition: basegridgeometry.hh:170
bool isPeriodic() const
Returns if the grid geometry is periodic (at all)
Definition: basegridgeometry.hh:183
typename Traits::VertexMapper VertexMapper
export the vertex mapper type
Definition: basegridgeometry.hh:70
typename Traits::ElementMapper ElementMapper
export the element mapper type
Definition: basegridgeometry.hh:68
typename Element::Geometry::GlobalCoordinate GlobalCoordinate
export the global coordinate type
Definition: basegridgeometry.hh:66
const ElementMap & elementMap() const
Returns the element index to element map.
Definition: basegridgeometry.hh:152
An axis-aligned bounding box volume tree implementation.
Definition: geometry/boundingboxtree.hh:66
An interface for a set of geometric entities based on a GridView.
Definition: geometry/geometricentityset.hh:42
An axis-aligned bounding box volume hierarchy for dune grids.
An interface for a set of geometric entities.