version 3.8
basicgridgeometry.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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_BASIC_GRID_GEOMETRY_HH
13#define DUMUX_DISCRETIZATION_BASIC_GRID_GEOMETRY_HH
14
15#include <memory>
16#include <utility>
17#include <type_traits>
18
19#include <dune/grid/common/mcmgmapper.hh>
20
25
26namespace Dumux {
27
35template<class GV, class EM, class VM>
37{
41
42 static constexpr int dim = GV::dimension;
43 static constexpr int dimWorld = GV::dimensionworld;
44
45 using GridIndexType = typename IndexTraits<GV>::GridIndex;
46 using Element = typename GV::template Codim<0>::Entity;
47
48public:
50 using Grid = typename GV::Grid;
52 using GridView = GV;
54 using GlobalCoordinate = typename Element::Geometry::GlobalCoordinate;
56 using ElementMapper = EM;
58 using VertexMapper = VM;
59
66 : gridView_(gridView)
67 , elementMapper_(makeElementMapper_(gridView))
68 , vertexMapper_(makeVertexMapper_(gridView))
69 , bBoxMin_(std::numeric_limits<double>::max())
70 , bBoxMax_(-std::numeric_limits<double>::max())
71 {
72 computeGlobalBoundingBox_();
73 update_();
74 }
75
80 {
81 gridView_ = gridView;
82 update_();
83 }
84
89 {
90 gridView_ = std::move(gridView);
91 update_();
92 }
93
97 const GridView& gridView() const
98 { return gridView_; }
99
104 { return vertexMapper_; }
105
110 { return elementMapper_; }
111
116 { return vertexMapper_; }
117
122 { return elementMapper_; }
123
128 { return *boundingBoxTree_; }
129
133 const ElementMap& elementMap() const
134 { return *elementMap_; }
135
139 Element element(GridIndexType eIdx) const
140 { return elementMap()[eIdx]; }
141
147 { return bBoxMin_; }
148
154 { return bBoxMax_; }
155
156private:
157
159 ElementMapper makeElementMapper_(const GridView& gridView) const
160 {
161 if constexpr (std::is_constructible<ElementMapper, GridView, Dune::MCMGLayout>())
162 return ElementMapper(gridView, Dune::mcmgElementLayout());
163 else
164 return ElementMapper(gridView);
165 }
166
168 VertexMapper makeVertexMapper_(const GridView& gridView) const
169 {
170 if constexpr (std::is_constructible<VertexMapper, GridView, Dune::MCMGLayout>())
171 return VertexMapper(gridView, Dune::mcmgVertexLayout());
172 else
173 return VertexMapper(gridView);
174 }
175
177 void computeGlobalBoundingBox_()
178 {
179 // calculate the bounding box of the local partition of the grid view
180 for (const auto& vertex : vertices(gridView_))
181 {
182 for (int i=0; i<dimWorld; i++)
183 {
184 using std::min;
185 using std::max;
186 bBoxMin_[i] = min(bBoxMin_[i], vertex.geometry().corner(0)[i]);
187 bBoxMax_[i] = max(bBoxMax_[i], vertex.geometry().corner(0)[i]);
188 }
189 }
190
191 // communicate to get the bounding box of the whole domain
192 if (gridView_.comm().size() > 1)
193 {
194 for (int i = 0; i < dimWorld; ++i)
195 {
196 bBoxMin_[i] = gridView_.comm().min(bBoxMin_[i]);
197 bBoxMax_[i] = gridView_.comm().max(bBoxMax_[i]);
198 }
199 }
200 }
201
202 void update_()
203 {
204 // Update the mappers
205 elementMapper_.update(gridView_);
206 vertexMapper_.update(gridView_);
207
208 // Compute the bounding box of the entire domain, for e.g. setting boundary conditions
209 computeGlobalBoundingBox_();
210
211 // update element map and bounding box tree
212 // always building these comes at a memory overhead but improved
213 // performance and thread-safe element level access (e.g. during assembly)
214 // for all simulation that use these features
215 elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_);
216 boundingBoxTree_ = std::make_unique<BoundingBoxTree>(
217 std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_)
218 );
219 }
220
222 GridView gridView_;
223
225 ElementMapper elementMapper_;
226 VertexMapper vertexMapper_;
227
229 std::unique_ptr<const BoundingBoxTree> boundingBoxTree_;
230
232 std::shared_ptr<const ElementMap> elementMap_;
233
235 GlobalCoordinate bBoxMin_;
236 GlobalCoordinate bBoxMax_;
237};
238
239} // end namespace Dumux
240
241#endif
An axis-aligned bounding box volume hierarchy for dune grids.
An implementation of a grid geometry with some basic features.
Definition: basicgridgeometry.hh:37
const BoundingBoxTree & boundingBoxTree() const
Returns the bounding box tree of the grid.
Definition: basicgridgeometry.hh:127
VM VertexMapper
export the vertex mapper type
Definition: basicgridgeometry.hh:58
void update(GridView &&gridView)
Update internal state after grid changed.
Definition: basicgridgeometry.hh:88
VertexMapper & vertexMapper()
Returns the mapper for vertices to indices for possibly adaptive grids.
Definition: basicgridgeometry.hh:115
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basicgridgeometry.hh:139
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition: basicgridgeometry.hh:103
ElementMapper & elementMapper()
Returns the mapper for elements to indices for possibly adaptive grids.
Definition: basicgridgeometry.hh:121
const ElementMap & elementMap() const
Returns the element index to element map.
Definition: basicgridgeometry.hh:133
typename GV::Grid Grid
export the grid type
Definition: basicgridgeometry.hh:50
void update(const GridView &gridView)
Update internal state after grid changed.
Definition: basicgridgeometry.hh:79
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition: basicgridgeometry.hh:153
GV GridView
export the grid view type
Definition: basicgridgeometry.hh:52
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition: basicgridgeometry.hh:146
typename Element::Geometry::GlobalCoordinate GlobalCoordinate
export the global coordinate type
Definition: basicgridgeometry.hh:54
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basicgridgeometry.hh:97
EM ElementMapper
export the element mapper type
Definition: basicgridgeometry.hh:56
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basicgridgeometry.hh:109
An axis-aligned bounding box volume tree implementation.
Definition: boundingboxtree.hh:56
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:27
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:32
A map from indices to entities using grid entity seeds.
An interface for a set of geometric entities.
BasicGridGeometry(const GridView &gridView)
Constructor computes the bounding box of the entire domain, for e.g. setting boundary conditions.
Definition: basicgridgeometry.hh:65
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26