3.4
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
36
37// make the local view function available whenever we use the grid geometry
39
40namespace Dumux {
41
48template<class GV, class Traits>
50{
54
55 static constexpr int dim = GV::dimension;
56 static constexpr int dimWorld = GV::dimensionworld;
57
58 using GridIndexType = typename IndexTraits<GV>::GridIndex;
59 using Element = typename GV::template Codim<0>::Entity;
60
61public:
63 using Grid = typename GV::Grid;
65 using GridView = GV;
67 using GlobalCoordinate = typename Element::Geometry::GlobalCoordinate;
69 using ElementMapper = typename Traits::ElementMapper;
71 using VertexMapper = typename Traits::VertexMapper;
72
79 : gridView_(gridView)
80 , elementMapper_(makeElementMapper_(gridView))
81 , vertexMapper_(makeVertexMapper_(gridView))
82 , bBoxMin_(std::numeric_limits<double>::max())
83 , bBoxMax_(-std::numeric_limits<double>::max())
84 {
85 computeGlobalBoundingBox_();
86 }
87
91 void update()
92 {
94 if constexpr (Deprecated::hasUpdateGridView<ElementMapper, GridView>())
95 elementMapper_.update(gridView_);
96 else
97 Deprecated::update(elementMapper_);
98
99 if constexpr (Deprecated::hasUpdateGridView<VertexMapper, GridView>())
100 vertexMapper_.update(gridView_);
101 else
102 Deprecated::update(vertexMapper_);
103
105 computeGlobalBoundingBox_();
106
108 boundingBoxTree_.release();
109 elementMap_.reset();
110 }
111
115 const GridView& gridView() const
116 { return gridView_; }
117
122 { return vertexMapper_; }
123
128 { return elementMapper_; }
129
134 { return vertexMapper_; }
135
140 { return elementMapper_; }
141
146 {
147 if(!boundingBoxTree_)
148 {
149 elementMap(); // make sure the element map is built
150 boundingBoxTree_ = std::make_unique<BoundingBoxTree>
151 ( std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_) );
152 }
153
154 return *boundingBoxTree_;
155 }
156
160 const ElementMap& elementMap() const
161 {
162 if(!elementMap_)
163 elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_);
164
165 return *elementMap_;
166 }
167
171 Element element(GridIndexType eIdx) const
172 { return elementMap()[eIdx]; }
173
179 { return bBoxMin_; }
180
186 { return bBoxMax_; }
187
191 bool isPeriodic() const
192 { return periodic_; }
193
197 void setPeriodic(bool value = true)
198 { periodic_ = value; }
199
200private:
201
203 ElementMapper makeElementMapper_(const GridView& gridView) const
204 {
205 if constexpr (std::is_constructible<ElementMapper, GridView, Dune::MCMGLayout>())
206 return ElementMapper(gridView, Dune::mcmgElementLayout());
207 else
208 return ElementMapper(gridView);
209 }
210
212 VertexMapper makeVertexMapper_(const GridView& gridView) const
213 {
214 if constexpr (std::is_constructible<VertexMapper, GridView, Dune::MCMGLayout>())
215 return VertexMapper(gridView, Dune::mcmgVertexLayout());
216 else
217 return VertexMapper(gridView);
218 }
219
221 void computeGlobalBoundingBox_()
222 {
223 // calculate the bounding box of the local partition of the grid view
224 for (const auto& vertex : vertices(gridView_))
225 {
226 for (int i=0; i<dimWorld; i++)
227 {
228 using std::min;
229 using std::max;
230 bBoxMin_[i] = min(bBoxMin_[i], vertex.geometry().corner(0)[i]);
231 bBoxMax_[i] = max(bBoxMax_[i], vertex.geometry().corner(0)[i]);
232 }
233 }
234
235 // communicate to get the bounding box of the whole domain
236 if (gridView_.comm().size() > 1)
237 {
238 for (int i = 0; i < dimWorld; ++i)
239 {
240 bBoxMin_[i] = gridView_.comm().min(bBoxMin_[i]);
241 bBoxMax_[i] = gridView_.comm().max(bBoxMax_[i]);
242 }
243 }
244 }
245
247 const GridView gridView_;
248
250 ElementMapper elementMapper_;
251 VertexMapper vertexMapper_;
252
254 mutable std::unique_ptr<BoundingBoxTree> boundingBoxTree_;
255
257 mutable std::shared_ptr<ElementMap> elementMap_;
258
260 GlobalCoordinate bBoxMin_;
261 GlobalCoordinate bBoxMax_;
262
264 bool periodic_ = false;
265};
266
267} // end namespace Dumux
268
269#endif
A map from indices to entities using grid entity seeds.
Defines the index types used for grid and local indices.
Helpers for deprecation.
Free function to get the local view of a grid cache object.
An axis-aligned bounding box volume hierarchy for dune grids.
An interface for a set of geometric entities.
BaseGridGeometry(const GridView &gridView)
Constructor computes the bouding box of the entire domain, for e.g. setting boundary conditions.
Definition: basegridgeometry.hh:78
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:50
GV GridView
export the grid view type
Definition: basegridgeometry.hh:65
typename GV::Grid Grid
export the grid type
Definition: basegridgeometry.hh:63
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basegridgeometry.hh:127
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition: basegridgeometry.hh:197
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition: basegridgeometry.hh:185
const BoundingBoxTree & boundingBoxTree() const
Returns the bounding box tree of the grid.
Definition: basegridgeometry.hh:145
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basegridgeometry.hh:171
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition: basegridgeometry.hh:121
VertexMapper & vertexMapper()
Returns the mapper for vertices to indices for possibly adaptive grids.
Definition: basegridgeometry.hh:133
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basegridgeometry.hh:115
void update()
Update all fvElementGeometries (do this again after grid adaption)
Definition: basegridgeometry.hh:91
ElementMapper & elementMapper()
Returns the mapper for elements to indices for possibly adaptive grids.
Definition: basegridgeometry.hh:139
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition: basegridgeometry.hh:178
bool isPeriodic() const
Returns if the grid geometry is periodic (at all)
Definition: basegridgeometry.hh:191
typename Traits::VertexMapper VertexMapper
export the vertex mapper type
Definition: basegridgeometry.hh:71
typename Traits::ElementMapper ElementMapper
export the element mapper type
Definition: basegridgeometry.hh:69
typename Element::Geometry::GlobalCoordinate GlobalCoordinate
export the global coordinate type
Definition: basegridgeometry.hh:67
const ElementMap & elementMap() const
Returns the element index to element map.
Definition: basegridgeometry.hh:160
An axis-aligned bounding box volume tree implementation.
Definition: boundingboxtree.hh:66
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:42