version 3.11-dev
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-FileCopyrightText: 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 const auto pos = vertex.geometry().corner(0);
183 for (int i = 0; i < dimWorld; ++i)
184 {
185 using std::min;
186 using std::max;
187 bBoxMin_[i] = min(bBoxMin_[i], pos[i]);
188 bBoxMax_[i] = max(bBoxMax_[i], pos[i]);
189 }
190 }
191
192 // communicate to get the bounding box of the whole domain
193 if (gridView_.comm().size() > 1)
194 {
195 for (int i = 0; i < dimWorld; ++i)
196 {
197 bBoxMin_[i] = gridView_.comm().min(bBoxMin_[i]);
198 bBoxMax_[i] = gridView_.comm().max(bBoxMax_[i]);
199 }
200 }
201 }
202
203 void update_()
204 {
205 // Update the mappers
206 elementMapper_.update(gridView_);
207 vertexMapper_.update(gridView_);
208
209 // Compute the bounding box of the entire domain, for e.g. setting boundary conditions
210 computeGlobalBoundingBox_();
211
212 // update element map and bounding box tree
213 // always building these comes at a memory overhead but improved
214 // performance and thread-safe element level access (e.g. during assembly)
215 // for all simulation that use these features
216 elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_);
217 boundingBoxTree_ = std::make_unique<BoundingBoxTree>(
218 std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_)
219 );
220 }
221
223 GridView gridView_;
224
226 ElementMapper elementMapper_;
227 VertexMapper vertexMapper_;
228
230 std::unique_ptr<const BoundingBoxTree> boundingBoxTree_;
231
233 std::shared_ptr<const ElementMap> elementMap_;
234
236 GlobalCoordinate bBoxMin_;
237 GlobalCoordinate bBoxMax_;
238};
239
240} // end namespace Dumux
241
242#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:67
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:37
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