Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup FacetCoupling | ||
10 | * \brief Contains the grid manager class that creates the grids in the context | ||
11 | * of hybrid-dimensional coupled models, where the (n-1)-dimensional | ||
12 | * domains live on the element facets of the n-dimensional domains. | ||
13 | * Also, it allows to extract a grid data object containing parameters | ||
14 | * passed to elements and/or boundary segments. All grids are constructed | ||
15 | * from a single grid file. | ||
16 | */ | ||
17 | #ifndef DUMUX_FACETCOUPLING_GRID_MANAGER_HH | ||
18 | #define DUMUX_FACETCOUPLING_GRID_MANAGER_HH | ||
19 | |||
20 | #include <cassert> | ||
21 | #include <map> | ||
22 | #include <tuple> | ||
23 | #include <type_traits> | ||
24 | #include <vector> | ||
25 | |||
26 | #include <dune/common/exceptions.hh> | ||
27 | #include <dune/common/hybridutilities.hh> | ||
28 | #include <dune/grid/common/gridfactory.hh> | ||
29 | |||
30 | #include <dumux/io/grid/griddata.hh> | ||
31 | #include <dumux/common/parameters.hh> | ||
32 | #include <dumux/common/indextraits.hh> | ||
33 | #include <dumux/common/typetraits/utility.hh> | ||
34 | |||
35 | #include "gmshreader.hh" | ||
36 | |||
37 | namespace Dumux { | ||
38 | namespace FCGridManagerChecks { | ||
39 | |||
40 | // The grid creator and grid data classes provided below | ||
41 | // require that the grids passed as template arguments are | ||
42 | // ordered in descending grid dimension and they must have | ||
43 | // the same world dimension. The following helper structs | ||
44 | // verify these conditions and are reused below. | ||
45 | // evaluates if dim is descending or dimworld is equal for two grids | ||
46 | template<bool checkDimWorld, typename G1, typename G2> | ||
47 | static constexpr bool evalCondition() | ||
48 | { | ||
49 | return checkDimWorld ? int(G1::dimensionworld) == int(G2::dimensionworld) | ||
50 | : int(G1::dimension) > int(G2::dimension); | ||
51 | } | ||
52 | |||
53 | // helper structs to evaluate conditions on the grid | ||
54 | template<bool checkDimWorld, typename... Gs> struct FulfillConditions; | ||
55 | template<bool checkDimWorld, typename G1, typename... Gs> | ||
56 | struct FulfillConditions<checkDimWorld, G1, Gs...> | ||
57 | { | ||
58 | using G2 = typename std::tuple_element_t<0, std::tuple<Gs...>>; | ||
59 | static constexpr bool value = evalCondition<checkDimWorld, G1, G2>() && FulfillConditions<checkDimWorld, Gs...>::value; | ||
60 | }; | ||
61 | template<bool checkDimWorld, typename G1, typename G2> | ||
62 | struct FulfillConditions<checkDimWorld, G1, G2> { static constexpr bool value = evalCondition<checkDimWorld, G1, G2>(); }; | ||
63 | } | ||
64 | |||
65 | /*! | ||
66 | * \ingroup FacetCoupling | ||
67 | * \brief Grid data object to store element and boundary segment markers | ||
68 | * for all grids of the hierarchy. | ||
69 | * | ||
70 | * \tparam Grids the types of the grid hierarchy | ||
71 | * \note Grids must be ordered in descending grid dimension | ||
72 | */ | ||
73 | template<typename... Grids> | ||
74 | 74 | class FacetCouplingGridDataWrapper | |
75 | { | ||
76 | // make sure all grids have the same world dimension and are ordered in descending dimension | ||
77 | static_assert(FCGridManagerChecks::FulfillConditions<false, Grids...>::value, "All grids must have the same world dimension!"); | ||
78 | static_assert(FCGridManagerChecks::FulfillConditions<true, Grids...>::value, "Grids must be ordered w.r.t the dimension in descending order!"); | ||
79 | |||
80 | //! determine the number of involved grids | ||
81 | static constexpr std::size_t numGrids = sizeof...(Grids); | ||
82 | //! the i-th grid type | ||
83 | template<std::size_t id> using Grid = typename std::tuple_element_t<id, std::tuple<Grids...>>; | ||
84 | //! shared ptr to the i-th grid data type | ||
85 | template<std::size_t id> using GridDataPtr = std::shared_ptr< GridData<Grid<id>> >; | ||
86 | //! the intersection type of the i-th grid | ||
87 | template<std::size_t id> using Intersection = typename Grid<id>::LeafGridView::Intersection; | ||
88 | |||
89 | public: | ||
90 | //! export the i-th grid data type | ||
91 | template<std::size_t id> using GridData = GridData<Grid<id>>; | ||
92 | |||
93 | //! set the grid data object for the i-th grid | ||
94 | template<std::size_t id> | ||
95 | 48 | void setGridData(GridData<id>&& gridData) | |
96 | { | ||
97 |
3/6✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
|
48 | std::get<id>(gridDataPtrTuple_) = std::make_shared<GridData<id>>( std::move(gridData) ); |
98 | 48 | } | |
99 | |||
100 | //! return the grid data for a specific grid | ||
101 | template<std::size_t id> | ||
102 | std::shared_ptr<const GridData<id>> getSubDomainGridData() const | ||
103 | { return std::get<id>(gridDataPtrTuple_); } | ||
104 | |||
105 | //! Returns domain marker of an element | ||
106 | template<std::size_t id> | ||
107 | int getElementDomainMarker(const typename Grid<id>::template Codim<0>::Entity& element) const | ||
108 |
9/18✓ Branch 1 taken 982 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 982 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 982 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 64 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 64 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 64 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 4 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 4 times.
✗ Branch 26 not taken.
|
3150 | { return std::get<id>(gridDataPtrTuple_)->getElementDomainMarker(element); } |
109 | |||
110 | //! Returns the boundary marker of an intersection | ||
111 | template<std::size_t id> | ||
112 | int getBoundaryDomainMarker(const typename Grid<id>::LeafGridView::Intersection& is) const | ||
113 | { return std::get<id>(gridDataPtrTuple_)->getBoundaryDomainMarker(is); } | ||
114 | |||
115 | //! Returns the boundary marker for a given boundary segment index | ||
116 | template<std::size_t id> | ||
117 | int getBoundaryDomainMarker(int boundarySegmentIndex) const | ||
118 |
3/6✓ Branch 1 taken 480 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 480 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 480 times.
✗ Branch 8 not taken.
|
1440 | { return std::get<id>(gridDataPtrTuple_)->getBoundaryDomainMarker(boundarySegmentIndex); } |
119 | |||
120 | //! Returns true if an intersection was inserted during grid creation | ||
121 | template<std::size_t id> | ||
122 | bool wasInserted(const Intersection<id>& intersection) const | ||
123 |
4/8✓ Branch 1 taken 480 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 480 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 480 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 480 times.
✗ Branch 10 not taken.
|
1440 | { return std::get<id>(gridDataPtrTuple_)->wasInserted(intersection); } |
124 | |||
125 | private: | ||
126 | //! store a shared pointer to a grid data object for each grid | ||
127 | using GridDataPtrTuple = typename makeFromIndexedType<std::tuple, GridDataPtr, std::make_index_sequence<numGrids>>::type; | ||
128 | GridDataPtrTuple gridDataPtrTuple_; | ||
129 | }; | ||
130 | |||
131 | /*! | ||
132 | * \ingroup FacetCoupling | ||
133 | * \brief Contains the embeddings between grids with codimension one | ||
134 | * among the grid hierarchy. All these embedments are given in | ||
135 | * insertion indices as they are read directly from the grid. | ||
136 | * Therefore, this class furthermore allows access to the insertion | ||
137 | * indices of entities. Additionally, it gives access to the grid | ||
138 | * views of the different grids on the hierarchy. | ||
139 | * | ||
140 | * \tparam Grids the types of the grid hierarchy | ||
141 | * \note Grids must be ordered in descending grid dimension | ||
142 | */ | ||
143 | template<typename... Grids> | ||
144 | class FacetCouplingEmbeddings | ||
145 | { | ||
146 | // make sure all grids have the same world dimension and are ordered in descending dimension | ||
147 | static_assert(FCGridManagerChecks::FulfillConditions<false, Grids...>::value, "All grids must have the same world dimension!"); | ||
148 | static_assert(FCGridManagerChecks::FulfillConditions<true, Grids...>::value, "Grids must be ordered w.r.t the dimension in descending order!"); | ||
149 | |||
150 | //! the i-th grid type | ||
151 | template<std::size_t id> using Grid = typename std::tuple_element_t<id, std::tuple<Grids...>>; | ||
152 | //! the i-th grid factory type | ||
153 | template<std::size_t id> using GridFactory = typename Dune::GridFactory<Grid<id>>; | ||
154 | |||
155 | //! we use the bulk grid's index type here | ||
156 | using GIType = typename IndexTraits< typename Grid<0>::LeafGridView >::GridIndex; | ||
157 | //! the map type to store embedment data | ||
158 | using EmbedmentMap = std::unordered_map<GIType, std::vector<GIType>>; | ||
159 | |||
160 | public: | ||
161 | //! export the i-th grid view type | ||
162 | template<std::size_t id> using GridView = typename Grid<id>::LeafGridView; | ||
163 | |||
164 | //! export the number of created grids | ||
165 | static constexpr std::size_t numGrids = sizeof...(Grids); | ||
166 | //! export the grid id of the bulk grid (descending grid dim -> always zero!) | ||
167 | static constexpr int bulkGridId = 0; | ||
168 | //! state the dimension of the highest-dimensional grid | ||
169 | static constexpr int bulkDim = Grid<bulkGridId>::dimension; | ||
170 | |||
171 | //! export the bulk grid type | ||
172 | using BulkGridView = GridView<bulkGridId>; | ||
173 | //! export the type used for indices | ||
174 | using GridIndexType = GIType; | ||
175 | |||
176 | //! return reference to the i-th grid view | ||
177 | template<std::size_t id> | ||
178 | const GridView<id>& gridView() const | ||
179 |
11/22✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 76 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 66 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 66 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 68 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 2 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 2 times.
✗ Branch 32 not taken.
|
702 | { return *std::get<id>(gridViewPtrTuple_); } |
180 | |||
181 | //! return the insertion index of an entity of the i-th grid | ||
182 | template<std::size_t id, class Entity> | ||
183 | GridIndexType insertionIndex(const Entity& entity) const | ||
184 |
20/40✓ Branch 1 taken 148284 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 148606 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 152486 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10276 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 134944 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 131424 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 125350 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3990 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 3744 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 3744 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 344 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 240 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 240 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 10 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1052 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1052 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1052 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 114 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 114 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 114 times.
✗ Branch 59 not taken.
|
916230 | { return std::get<id>(gridFactoryPtrTuple_)->insertionIndex(entity); } |
185 | |||
186 | //! Returns the insertion indices of the entities embedded in given element | ||
187 | template<std::size_t id> | ||
188 | typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type | ||
189 | 5708 | embeddedEntityIndices(const typename Grid<id>::template Codim<0>::Entity& element) const | |
190 | { | ||
191 | 5708 | const auto& map = embeddedEntityMaps_[id]; | |
192 | 17124 | auto it = map.find( std::get<id>(gridFactoryPtrTuple_)->insertionIndex(element) ); | |
193 |
4/4✓ Branch 0 taken 144 times.
✓ Branch 1 taken 2710 times.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 2710 times.
|
11416 | if (it != map.end()) return it->second; |
194 | 5420 | else return typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type(); | |
195 | } | ||
196 | |||
197 | //! Returns the insertion indices of the entities in which the element is embedded | ||
198 | template<std::size_t id> | ||
199 | typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type | ||
200 | 10072 | adjoinedEntityIndices(const typename Grid<id>::template Codim<0>::Entity& element) const | |
201 | { | ||
202 | 10072 | const auto& map = adjoinedEntityMaps_[id]; | |
203 | 30216 | auto it = map.find( std::get<id>(gridFactoryPtrTuple_)->insertionIndex(element) ); | |
204 |
4/4✓ Branch 0 taken 6788 times.
✓ Branch 1 taken 982 times.
✓ Branch 2 taken 6788 times.
✓ Branch 3 taken 982 times.
|
20144 | if (it != map.end()) return it->second; |
205 | 1964 | else return typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type(); | |
206 | } | ||
207 | |||
208 | //! Returns const reference to maps of the embedded entities | ||
209 | const std::unordered_map< GridIndexType, std::vector<GridIndexType> >& embeddedEntityMap(std::size_t id) const | ||
210 |
6/12✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
|
12 | { assert(id < numGrids); return embeddedEntityMaps_[id]; } |
211 | |||
212 | //! Returns non-const reference to maps of the embedded entities | ||
213 | std::unordered_map< GridIndexType, std::vector<GridIndexType> >& embeddedEntityMap(std::size_t id) | ||
214 | { assert(id < numGrids); return embeddedEntityMaps_[id]; } | ||
215 | |||
216 | //! Returns const reference to the maps of the adjoined entities of dimension d+1 | ||
217 | const std::unordered_map< GridIndexType, std::vector<GridIndexType> >& adjoinedEntityMap(std::size_t id) const | ||
218 |
6/12✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
|
12 | { assert(id < numGrids); return adjoinedEntityMaps_[id]; } |
219 | |||
220 | //! Returns non-const reference to the maps of the adjoined entities of dimension d+1 | ||
221 | std::unordered_map< GridIndexType, std::vector<GridIndexType> >& adjoinedEntityMap(std::size_t id) | ||
222 | { assert(id < numGrids); return adjoinedEntityMaps_[id]; } | ||
223 | |||
224 | //! Returns the hierachy's insertion indices that make up the grid for the given id | ||
225 | const std::vector<GridIndexType>& gridHierarchyIndices(std::size_t id) const | ||
226 |
5/10✓ Branch 2 taken 2726 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2736 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 114 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 114 times.
✗ Branch 11 not taken.
|
30796 | { assert(id < numGrids); return gridVertexIndices_[id]; } |
227 | |||
228 | //! Returns the number of vertices contained in the entire grid hierarch | ||
229 | ✗ | std::size_t numVerticesInHierarchy() const | |
230 | ✗ | { return numVerticesInHierarchy_; } | |
231 | |||
232 | /*! | ||
233 | * \brief Sets the required data for a specific grid on the hierarchy. | ||
234 | * \param gridPtr shared pointer to this (id-th) grid | ||
235 | * \param gridFactoryPtr shared pointer to this (id-th) grid factory | ||
236 | * \param embeddedEntityMap map containing the lower-dimensional entities for this grid's elements | ||
237 | * \param adjoinedEntityMap map containing the (d+1)-dimensional elements in which this grid's elements are embedded in | ||
238 | * \param gridVertexIndices The hierachy's insertion indices that make up this grid | ||
239 | * \param numVerticesInHierarchy Total number of vertices in entire grid hierarchy | ||
240 | */ | ||
241 | template<std::size_t id> | ||
242 | 316 | void setData( std::shared_ptr<Grid<id>> gridPtr, | |
243 | std::shared_ptr<GridFactory<id>> gridFactoryPtr, | ||
244 | EmbedmentMap&& embeddedEntityMap, | ||
245 | EmbedmentMap&& adjoinedEntityMap, | ||
246 | std::vector<GridIndexType>&& gridVertexIndices, | ||
247 | std::size_t numVerticesInHierarchy ) | ||
248 | { | ||
249 |
2/4✗ Branch 3 not taken.
✓ Branch 4 taken 158 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 158 times.
|
948 | std::get<id>(gridViewPtrTuple_) = std::make_shared<GridView<id>>(gridPtr->leafGridView()); |
250 | 632 | std::get<id>(gridFactoryPtrTuple_) = gridFactoryPtr; | |
251 | 632 | embeddedEntityMaps_[id] = std::move(embeddedEntityMap); | |
252 | 632 | adjoinedEntityMaps_[id] = std::move(adjoinedEntityMap); | |
253 | 632 | gridVertexIndices_[id] = std::move(gridVertexIndices); | |
254 | 316 | numVerticesInHierarchy_ = numVerticesInHierarchy; | |
255 | 316 | } | |
256 | |||
257 | private: | ||
258 | //! data on connectivity between the grids | ||
259 | std::array<EmbedmentMap, numGrids> embeddedEntityMaps_; | ||
260 | std::array<EmbedmentMap, numGrids> adjoinedEntityMaps_; | ||
261 | |||
262 | //! Contains the hierarchy insertion indices that make up a lower-dimensional grid | ||
263 | std::size_t numVerticesInHierarchy_; | ||
264 | std::array<std::vector<GridIndexType>, numGrids> gridVertexIndices_; | ||
265 | |||
266 | //! tuple to store the grids | ||
267 | using Indices = std::make_index_sequence<numGrids>; | ||
268 | template<std::size_t id> using GridViewPtr = std::shared_ptr<GridView<id>>; | ||
269 | using GridPtrTuple = typename makeFromIndexedType<std::tuple, GridViewPtr, Indices>::type; | ||
270 | GridPtrTuple gridViewPtrTuple_; | ||
271 | |||
272 | //! tuple to store the grid grid factories | ||
273 | template<std::size_t id> using GridFactoryPtr = std::shared_ptr< Dune::GridFactory<Grid<id>> >; | ||
274 | using GridFactoryPtrTuple = typename makeFromIndexedType<std::tuple, GridFactoryPtr, Indices>::type; | ||
275 | GridFactoryPtrTuple gridFactoryPtrTuple_; | ||
276 | }; | ||
277 | |||
278 | /*! | ||
279 | * \ingroup FacetCoupling | ||
280 | * \brief Creates the grids in the context of hybrid-dimensional coupled models, | ||
281 | * where the (n-1)-dimensional domains live on the element facets of the | ||
282 | * n-dimensional domains. | ||
283 | * | ||
284 | * \tparam Grids the types of the grid hierarchy | ||
285 | * \note Grids must be ordered in descending grid dimension | ||
286 | */ | ||
287 | template<typename... Grids> | ||
288 |
4/8✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 74 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 74 times.
✗ Branch 11 not taken.
|
296 | class FacetCouplingGridManager |
289 | { | ||
290 | // make sure all grids have the same world dimension and are ordered in descending dimension | ||
291 | static_assert(FCGridManagerChecks::FulfillConditions<false, Grids...>::value, "All grids must have the same world dimension!"); | ||
292 | static_assert(FCGridManagerChecks::FulfillConditions<true, Grids...>::value, "Grids must be ordered w.r.t the dimension in descending order!"); | ||
293 | |||
294 | // we use a wrapper class for the grid data containing the data on all grids | ||
295 | using GridDataWrapper = FacetCouplingGridDataWrapper<Grids...>; | ||
296 | public: | ||
297 | //! export the i-th grid type | ||
298 | template<std::size_t id> using Grid = typename std::tuple_element_t<id, std::tuple<Grids...>>; | ||
299 | //! export the i-th grid pointer type | ||
300 | template<std::size_t id> using GridPtr = typename std::shared_ptr< Grid<id> >; | ||
301 | |||
302 | //! export the number of created grids | ||
303 | static constexpr std::size_t numGrids = sizeof...(Grids); | ||
304 | //! export the grid id of the bulk grid (descending grid dim -> always zero!) | ||
305 | static constexpr int bulkGridId = 0; | ||
306 | |||
307 | //! export the grid data (wrapper) type, i.e. parameters/markers | ||
308 | using GridData = GridDataWrapper; | ||
309 | //! export the type storing the embeddings | ||
310 | using Embeddings = FacetCouplingEmbeddings<Grids...>; | ||
311 | |||
312 | //! returns the i-th grid | ||
313 | template<std::size_t id> | ||
314 | const Grid<id>& grid() const | ||
315 |
9/18✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 65 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 59 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 59 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 59 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 9 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 9 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 9 times.
✗ Branch 26 not taken.
|
414 | { return *std::get<id>(gridPtrTuple_); } |
316 | |||
317 | //! return a pointer to the grid data object | ||
318 | 2010 | std::shared_ptr<const GridData> getGridData() const | |
319 | { | ||
320 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2010 times.
|
2010 | if (!enableEntityMarkers_) |
321 | ✗ | DUNE_THROW(Dune::IOError, "No grid data available"); | |
322 | 2010 | return gridDataPtr_; | |
323 | } | ||
324 | |||
325 | //! return a pointer to the object containing embeddings | ||
326 | std::shared_ptr<const Embeddings> getEmbeddings() const | ||
327 |
18/38✓ Branch 2 taken 552 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 29 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 982 times.
✗ Branch 25 not taken.
✓ Branch 28 taken 886 times.
✗ Branch 29 not taken.
✓ Branch 32 taken 870 times.
✗ Branch 33 not taken.
✓ Branch 36 taken 982 times.
✗ Branch 37 not taken.
✓ Branch 40 taken 64 times.
✗ Branch 41 not taken.
✓ Branch 44 taken 48 times.
✗ Branch 45 not taken.
✓ Branch 48 taken 64 times.
✗ Branch 49 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 56 taken 4 times.
✗ Branch 57 not taken.
✓ Branch 60 taken 4 times.
✗ Branch 61 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
|
4508 | { return embeddingsPtr_; } |
328 | |||
329 | //! creates the grids from a file given in parameter tree | ||
330 | 74 | void init(const std::string& paramGroup = "") | |
331 | { | ||
332 | // reset the grid & embedding data | ||
333 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 74 times.
|
74 | gridDataPtr_ = std::make_shared<GridData>(); |
334 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 74 times.
|
74 | embeddingsPtr_ = std::make_shared<Embeddings>(); |
335 | |||
336 | // get filename and determine grid file extension | ||
337 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
74 | const auto fileName = getParamFromGroup<std::string>(paramGroup, "Grid.File"); |
338 |
3/4✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 12 times.
|
148 | const auto ext = getFileExtension(fileName); |
339 | |||
340 | // get some parameters | ||
341 |
1/2✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
|
74 | const bool verbose = getParamFromGroup<bool>(paramGroup, "Grid.Verbosity", false); |
342 |
1/2✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
|
74 | const bool domainMarkers = getParamFromGroup<bool>(paramGroup, "Grid.DomainMarkers", false); |
343 |
1/2✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
|
74 | const bool boundarySegments = getParamFromGroup<bool>(paramGroup, "Grid.BoundarySegments", false); |
344 | |||
345 | // forward to the corresponding reader | ||
346 |
1/2✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
|
74 | if (ext == "msh") |
347 | { | ||
348 |
1/4✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
74 | const auto thresh = getParamFromGroup<std::size_t>(paramGroup, "Grid.GmshPhysicalEntityThreshold", 0); |
349 | 138 | FacetCouplingGmshReader<Grid<bulkGridId>, numGrids> gmshReader; | |
350 |
3/4✓ Branch 0 taken 66 times.
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 74 times.
✗ Branch 4 not taken.
|
140 | gmshReader.read(fileName, (boundarySegments ? thresh : 0), verbose); |
351 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
84 | passDataFromReader(gmshReader, domainMarkers, boundarySegments); |
352 | } | ||
353 | else | ||
354 | ✗ | DUNE_THROW(Dune::NotImplemented, "Reader for grid files of type ." + ext); | |
355 | |||
356 | // find out if entity markers are active | ||
357 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 74 times.
|
74 | enableEntityMarkers_ = domainMarkers || boundarySegments; |
358 | 74 | } | |
359 | |||
360 | //! Distributes the grid on all processes of a parallel computation | ||
361 | void loadBalance() | ||
362 | { | ||
363 | using namespace Dune::Hybrid; | ||
364 |
2/4✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
|
56 | forEach(integralRange(Dune::Hybrid::size(gridPtrTuple_)), [&](const auto id) |
365 | { | ||
366 |
12/36✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 25 taken 56 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 56 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 56 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 50 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 50 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 50 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 50 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 50 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 2 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 2 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 2 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 2 times.
✗ Branch 59 not taken.
|
168 | std::get<id>(this->gridPtrTuple_)->loadBalance(); |
367 | }); | ||
368 | } | ||
369 | |||
370 | protected: | ||
371 | //! return non-const reference to i-th grid | ||
372 | template<std::size_t id> | ||
373 | Grid<id>& grid_() | ||
374 | { return *std::get<id>(gridPtrTuple_); } | ||
375 | |||
376 | //! return non-const pointer to the object containing embeddings | ||
377 | std::shared_ptr<Embeddings> getEmbeddings_() | ||
378 | { return embeddingsPtr_; } | ||
379 | |||
380 | private: | ||
381 | //! Returns the filename extension of a given filename | ||
382 | 74 | static std::string getFileExtension(const std::string& fileName) | |
383 | { | ||
384 |
1/2✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
|
74 | const auto pos = fileName.rfind('.', fileName.length()); |
385 |
1/2✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
|
74 | if (pos != std::string::npos) |
386 | 74 | return(fileName.substr(pos+1, fileName.length() - pos)); | |
387 | else | ||
388 | ✗ | DUNE_THROW(Dune::IOError, "Please provide an extension for your grid file ('"<< fileName << "')!"); | |
389 | } | ||
390 | |||
391 | //! Creates the grids using the data in a mesh file reader | ||
392 | template<typename MeshFileReader> | ||
393 | 64 | void passDataFromReader(MeshFileReader& reader, bool domainMarkers, bool boundarySegments) | |
394 | { | ||
395 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
74 | const auto& vertices = reader.gridVertices(); |
396 | |||
397 | using namespace Dune::Hybrid; | ||
398 |
1/2✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
|
2286 | forEach(integralRange(Dune::Hybrid::size(gridPtrTuple_)), [&](const auto id) |
399 | { | ||
400 | using GridFactory = Dune::GridFactory<Grid<id>>; | ||
401 | 316 | auto factoryPtr = std::make_shared<GridFactory>(); | |
402 | |||
403 | // insert grid vertices | ||
404 |
12/12✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 2592 times.
✓ Branch 3 taken 74 times.
✓ Branch 4 taken 146020 times.
✓ Branch 5 taken 74 times.
✓ Branch 6 taken 146020 times.
✓ Branch 7 taken 74 times.
✓ Branch 8 taken 2276 times.
✓ Branch 9 taken 10 times.
✓ Branch 10 taken 2276 times.
✓ Branch 11 taken 10 times.
|
151520 | for (const auto idx : reader.vertexIndices(id)) |
405 |
9/18✓ Branch 1 taken 2592 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2592 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2592 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 146020 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 146020 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 146020 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2276 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 2276 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2276 times.
✗ Branch 26 not taken.
|
452664 | factoryPtr->insertVertex(vertices[idx]); |
406 | |||
407 | // insert elements | ||
408 |
12/12✓ Branch 0 taken 2612 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 2612 times.
✓ Branch 3 taken 74 times.
✓ Branch 4 taken 153643 times.
✓ Branch 5 taken 74 times.
✓ Branch 6 taken 153643 times.
✓ Branch 7 taken 74 times.
✓ Branch 8 taken 7782 times.
✓ Branch 9 taken 10 times.
✓ Branch 10 taken 7782 times.
✓ Branch 11 taken 10 times.
|
164669 | for (const auto& e : reader.elementData(id)) |
409 |
6/12✓ Branch 1 taken 2612 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2612 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 153643 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 153643 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 7782 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 7782 times.
✗ Branch 17 not taken.
|
328074 | factoryPtr->insertElement(e.gt, e.cornerIndices); |
410 | |||
411 | // insert boundary segments | ||
412 |
6/6✓ Branch 0 taken 8 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
|
158 | if (boundarySegments) |
413 |
8/12✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 1920 times.
✓ Branch 9 taken 8 times.
✓ Branch 10 taken 1920 times.
✓ Branch 11 taken 8 times.
|
2016 | for (const auto& segment : reader.boundarySegmentData(id)) |
414 |
2/12✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 13 taken 1920 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1920 times.
✗ Branch 17 not taken.
|
3840 | factoryPtr->insertBoundarySegment(segment); |
415 | |||
416 | // make grid | ||
417 |
15/36✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 74 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 74 times.
✓ Branch 11 taken 74 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 16 taken 74 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 74 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 74 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 74 times.
✓ Branch 26 taken 74 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 31 taken 10 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 10 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 10 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 10 times.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
474 | auto gridPtr = std::shared_ptr<Grid<id>>(factoryPtr->createGrid()); |
418 | |||
419 | // maybe create and set grid data object | ||
420 |
9/12✓ Branch 0 taken 66 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 66 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 66 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
|
158 | if (domainMarkers || boundarySegments) |
421 | { | ||
422 |
9/30✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 8 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 8 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 33 taken 8 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 8 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✓ Branch 38 taken 8 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
|
96 | typename GridDataWrapper::template GridData<id> gridData( gridPtr, |
423 | factoryPtr, | ||
424 | 24 | std::move(reader.elementMarkerMap(id)), | |
425 | 48 | std::move(reader.boundaryMarkerMap(id)) ); | |
426 |
6/12✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 8 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 8 times.
✗ Branch 17 not taken.
|
48 | gridDataPtr_->template setGridData<id>( std::move(gridData) ); |
427 | } | ||
428 | |||
429 | // copy the embeddings | ||
430 |
9/36✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 74 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 74 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 20 taken 74 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 74 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 74 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 36 taken 10 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 10 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
|
474 | embeddingsPtr_->template setData<id>( gridPtr, |
431 | factoryPtr, | ||
432 | 158 | std::move(reader.embeddedEntityMap(id)), | |
433 | 158 | std::move(reader.adjoinedEntityMap(id)), | |
434 | 316 | std::move(reader.vertexIndices(id)), | |
435 | vertices.size() ); | ||
436 | |||
437 | // set the grid pointer | ||
438 |
3/6✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 74 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
|
316 | std::get<id>(gridPtrTuple_) = gridPtr; |
439 | }); | ||
440 | 64 | } | |
441 | |||
442 | //! tuple to store the grids | ||
443 | using Indices = std::make_index_sequence<numGrids>; | ||
444 | using GridPtrTuple = typename makeFromIndexedType<std::tuple, GridPtr, Indices>::type; | ||
445 | GridPtrTuple gridPtrTuple_; | ||
446 | |||
447 | //! grid data, i.e. parameters and markers | ||
448 | bool enableEntityMarkers_; | ||
449 | std::shared_ptr<GridData> gridDataPtr_; | ||
450 | |||
451 | //! data on embeddings | ||
452 | std::shared_ptr<Embeddings> embeddingsPtr_; | ||
453 | }; | ||
454 | |||
455 | } // end namespace Dumux | ||
456 | |||
457 | #endif | ||
458 |