3.5-git
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 <utility>
28#include <type_traits>
29
30#include <dune/grid/common/mcmgmapper.hh>
31
37
38// make the local view function available whenever we use the grid geometry
40
41namespace Dumux {
42
49template<class GV, class Traits>
51{
55
56 static constexpr int dim = GV::dimension;
57 static constexpr int dimWorld = GV::dimensionworld;
58
59 using GridIndexType = typename IndexTraits<GV>::GridIndex;
60 using Element = typename GV::template Codim<0>::Entity;
61
62public:
64 using Grid = typename GV::Grid;
66 using GridView = GV;
68 using GlobalCoordinate = typename Element::Geometry::GlobalCoordinate;
70 using ElementMapper = typename Traits::ElementMapper;
72 using VertexMapper = typename Traits::VertexMapper;
73
80 : gridView_(gridView)
81 , elementMapper_(makeElementMapper_(gridView))
82 , vertexMapper_(makeVertexMapper_(gridView))
83 , bBoxMin_(std::numeric_limits<double>::max())
84 , bBoxMax_(-std::numeric_limits<double>::max())
85 {
86 computeGlobalBoundingBox_();
87 update_();
88 }
89
93 [[deprecated("Use update(gridView) instead! Will be removed after release 3.5.")]]
94 void update()
95 {
96 update_();
97 }
98
103 {
104 gridView_ = gridView;
105 update_();
106 }
107
112 {
113 gridView_ = std::move(gridView);
114 update_();
115 }
116
120 const GridView& gridView() const
121 { return gridView_; }
122
127 { return vertexMapper_; }
128
133 { return elementMapper_; }
134
139 { return vertexMapper_; }
140
145 { return elementMapper_; }
146
151 { return *boundingBoxTree_; }
152
156 const ElementMap& elementMap() const
157 { return *elementMap_; }
158
162 Element element(GridIndexType eIdx) const
163 { return elementMap()[eIdx]; }
164
170 { return bBoxMin_; }
171
177 { return bBoxMax_; }
178
182 bool isPeriodic() const
183 { return periodic_; }
184
188 void setPeriodic(bool value = true)
189 { periodic_ = value; }
190
191private:
192
194 ElementMapper makeElementMapper_(const GridView& gridView) const
195 {
196 if constexpr (std::is_constructible<ElementMapper, GridView, Dune::MCMGLayout>())
197 return ElementMapper(gridView, Dune::mcmgElementLayout());
198 else
199 return ElementMapper(gridView);
200 }
201
203 VertexMapper makeVertexMapper_(const GridView& gridView) const
204 {
205 if constexpr (std::is_constructible<VertexMapper, GridView, Dune::MCMGLayout>())
206 return VertexMapper(gridView, Dune::mcmgVertexLayout());
207 else
208 return VertexMapper(gridView);
209 }
210
212 void computeGlobalBoundingBox_()
213 {
214 // calculate the bounding box of the local partition of the grid view
215 for (const auto& vertex : vertices(gridView_))
216 {
217 for (int i=0; i<dimWorld; i++)
218 {
219 using std::min;
220 using std::max;
221 bBoxMin_[i] = min(bBoxMin_[i], vertex.geometry().corner(0)[i]);
222 bBoxMax_[i] = max(bBoxMax_[i], vertex.geometry().corner(0)[i]);
223 }
224 }
225
226 // communicate to get the bounding box of the whole domain
227 if (gridView_.comm().size() > 1)
228 {
229 for (int i = 0; i < dimWorld; ++i)
230 {
231 bBoxMin_[i] = gridView_.comm().min(bBoxMin_[i]);
232 bBoxMax_[i] = gridView_.comm().max(bBoxMax_[i]);
233 }
234 }
235 }
236
237 void update_()
238 {
239 // Update the mappers
240 if constexpr (Deprecated::hasUpdateGridView<ElementMapper, GridView>())
241 elementMapper_.update(gridView_);
242 else
243 Deprecated::update(elementMapper_);
244
245 if constexpr (Deprecated::hasUpdateGridView<VertexMapper, GridView>())
246 vertexMapper_.update(gridView_);
247 else
248 Deprecated::update(vertexMapper_);
249
250 // Compute the bounding box of the entire domain, for e.g. setting boundary conditions
251 computeGlobalBoundingBox_();
252
253 // update element map and bounding box tree
254 // always building these comes at a memory overhead but improved
255 // performance and thread-safe element level access (e.g. during assembly)
256 // for all simulation that use these features
257 elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_);
258 boundingBoxTree_ = std::make_unique<BoundingBoxTree>(
259 std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_)
260 );
261 }
262
264 GridView gridView_;
265
267 ElementMapper elementMapper_;
268 VertexMapper vertexMapper_;
269
271 std::unique_ptr<const BoundingBoxTree> boundingBoxTree_;
272
274 std::shared_ptr<const ElementMap> elementMap_;
275
277 GlobalCoordinate bBoxMin_;
278 GlobalCoordinate bBoxMax_;
279
281 bool periodic_ = false;
282};
283
284} // end namespace Dumux
285
286#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 bounding box of the entire domain, for e.g. setting boundary conditions.
Definition: basegridgeometry.hh:79
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:51
GV GridView
export the grid view type
Definition: basegridgeometry.hh:66
typename GV::Grid Grid
export the grid type
Definition: basegridgeometry.hh:64
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basegridgeometry.hh:132
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition: basegridgeometry.hh:188
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition: basegridgeometry.hh:176
void update(GridView &&gridView)
Update all fvElementGeometries (call this after grid adaption)
Definition: basegridgeometry.hh:111
const BoundingBoxTree & boundingBoxTree() const
Returns the bounding box tree of the grid.
Definition: basegridgeometry.hh:150
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basegridgeometry.hh:162
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition: basegridgeometry.hh:126
VertexMapper & vertexMapper()
Returns the mapper for vertices to indices for possibly adaptive grids.
Definition: basegridgeometry.hh:138
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basegridgeometry.hh:120
void update()
Update all fvElementGeometries (do this again after grid adaption)
Definition: basegridgeometry.hh:94
ElementMapper & elementMapper()
Returns the mapper for elements to indices for possibly adaptive grids.
Definition: basegridgeometry.hh:144
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption)
Definition: basegridgeometry.hh:102
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition: basegridgeometry.hh:169
bool isPeriodic() const
Returns if the grid geometry is periodic (at all)
Definition: basegridgeometry.hh:182
typename Traits::VertexMapper VertexMapper
export the vertex mapper type
Definition: basegridgeometry.hh:72
typename Traits::ElementMapper ElementMapper
export the element mapper type
Definition: basegridgeometry.hh:70
typename Element::Geometry::GlobalCoordinate GlobalCoordinate
export the global coordinate type
Definition: basegridgeometry.hh:68
const ElementMap & elementMap() const
Returns the element index to element map.
Definition: basegridgeometry.hh:156
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