3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * 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_BASIC_GRID_GEOMETRY_HH
25#define DUMUX_DISCRETIZATION_BASIC_GRID_GEOMETRY_HH
26
27#include <memory>
28#include <utility>
29#include <type_traits>
30
31#include <dune/grid/common/mcmgmapper.hh>
32
37
38namespace Dumux {
39
47template<class GV, class EM, class VM>
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 = EM;
70 using VertexMapper = VM;
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 update_();
86 }
87
92 {
93 gridView_ = gridView;
94 update_();
95 }
96
101 {
102 gridView_ = std::move(gridView);
103 update_();
104 }
105
109 const GridView& gridView() const
110 { return gridView_; }
111
116 { return vertexMapper_; }
117
122 { return elementMapper_; }
123
128 { return vertexMapper_; }
129
134 { return elementMapper_; }
135
140 { return *boundingBoxTree_; }
141
145 const ElementMap& elementMap() const
146 { return *elementMap_; }
147
151 Element element(GridIndexType eIdx) const
152 { return elementMap()[eIdx]; }
153
159 { return bBoxMin_; }
160
166 { return bBoxMax_; }
167
168private:
169
171 ElementMapper makeElementMapper_(const GridView& gridView) const
172 {
173 if constexpr (std::is_constructible<ElementMapper, GridView, Dune::MCMGLayout>())
174 return ElementMapper(gridView, Dune::mcmgElementLayout());
175 else
176 return ElementMapper(gridView);
177 }
178
180 VertexMapper makeVertexMapper_(const GridView& gridView) const
181 {
182 if constexpr (std::is_constructible<VertexMapper, GridView, Dune::MCMGLayout>())
183 return VertexMapper(gridView, Dune::mcmgVertexLayout());
184 else
185 return VertexMapper(gridView);
186 }
187
189 void computeGlobalBoundingBox_()
190 {
191 // calculate the bounding box of the local partition of the grid view
192 for (const auto& vertex : vertices(gridView_))
193 {
194 for (int i=0; i<dimWorld; i++)
195 {
196 using std::min;
197 using std::max;
198 bBoxMin_[i] = min(bBoxMin_[i], vertex.geometry().corner(0)[i]);
199 bBoxMax_[i] = max(bBoxMax_[i], vertex.geometry().corner(0)[i]);
200 }
201 }
202
203 // communicate to get the bounding box of the whole domain
204 if (gridView_.comm().size() > 1)
205 {
206 for (int i = 0; i < dimWorld; ++i)
207 {
208 bBoxMin_[i] = gridView_.comm().min(bBoxMin_[i]);
209 bBoxMax_[i] = gridView_.comm().max(bBoxMax_[i]);
210 }
211 }
212 }
213
214 void update_()
215 {
216 // Update the mappers
217 elementMapper_.update(gridView_);
218 vertexMapper_.update(gridView_);
219
220 // Compute the bounding box of the entire domain, for e.g. setting boundary conditions
221 computeGlobalBoundingBox_();
222
223 // update element map and bounding box tree
224 // always building these comes at a memory overhead but improved
225 // performance and thread-safe element level access (e.g. during assembly)
226 // for all simulation that use these features
227 elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_);
228 boundingBoxTree_ = std::make_unique<BoundingBoxTree>(
229 std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_)
230 );
231 }
232
234 GridView gridView_;
235
237 ElementMapper elementMapper_;
238 VertexMapper vertexMapper_;
239
241 std::unique_ptr<const BoundingBoxTree> boundingBoxTree_;
242
244 std::shared_ptr<const ElementMap> elementMap_;
245
247 GlobalCoordinate bBoxMin_;
248 GlobalCoordinate bBoxMax_;
249};
250
251} // end namespace Dumux
252
253#endif
Defines the index types used for grid and local indices.
A map from indices to entities using grid entity seeds.
An axis-aligned bounding box volume hierarchy for dune grids.
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:77
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:39
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:38
An implementation of a grid geometry with some basic features.
Definition: basicgridgeometry.hh:49
const BoundingBoxTree & boundingBoxTree() const
Returns the bounding box tree of the grid.
Definition: basicgridgeometry.hh:139
VM VertexMapper
export the vertex mapper type
Definition: basicgridgeometry.hh:70
void update(GridView &&gridView)
Update internal state after grid changed.
Definition: basicgridgeometry.hh:100
VertexMapper & vertexMapper()
Returns the mapper for vertices to indices for possibly adaptive grids.
Definition: basicgridgeometry.hh:127
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basicgridgeometry.hh:151
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition: basicgridgeometry.hh:115
ElementMapper & elementMapper()
Returns the mapper for elements to indices for possibly adaptive grids.
Definition: basicgridgeometry.hh:133
const ElementMap & elementMap() const
Returns the element index to element map.
Definition: basicgridgeometry.hh:145
typename GV::Grid Grid
export the grid type
Definition: basicgridgeometry.hh:62
void update(const GridView &gridView)
Update internal state after grid changed.
Definition: basicgridgeometry.hh:91
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition: basicgridgeometry.hh:165
GV GridView
export the grid view type
Definition: basicgridgeometry.hh:64
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition: basicgridgeometry.hh:158
typename Element::Geometry::GlobalCoordinate GlobalCoordinate
export the global coordinate type
Definition: basicgridgeometry.hh:66
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basicgridgeometry.hh:109
EM ElementMapper
export the element mapper type
Definition: basicgridgeometry.hh:68
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basicgridgeometry.hh:121
An axis-aligned bounding box volume tree implementation.
Definition: boundingboxtree.hh:68
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:44