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-FileCopyrightText: 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 Geometry | ||
10 | * \brief An interface for a set of geometric entities | ||
11 | * \note This can be used e.g. to construct a bounding box volume hierarchy of a grid | ||
12 | * It defines the minimum requirement for such a set | ||
13 | */ | ||
14 | #ifndef DUMUX_GEOMETRY_GEOMETRIC_ENTITY_SET_HH | ||
15 | #define DUMUX_GEOMETRY_GEOMETRIC_ENTITY_SET_HH | ||
16 | |||
17 | #include <array> | ||
18 | #include <vector> | ||
19 | #include <memory> | ||
20 | #include <utility> | ||
21 | #include <initializer_list> | ||
22 | |||
23 | #include <dune/grid/common/mcmgmapper.hh> | ||
24 | #include <dune/geometry/multilineargeometry.hh> | ||
25 | #include <dumux/common/entitymap.hh> | ||
26 | |||
27 | namespace Dumux { | ||
28 | |||
29 | /*! | ||
30 | * \ingroup Geometry | ||
31 | * \brief An interface for a set of geometric entities based on a GridView | ||
32 | * \note This can be used e.g. to construct a bounding box volume hierarchy of a grid | ||
33 | * It defines the minimum requirement for such a set | ||
34 | */ | ||
35 | template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>> | ||
36 | class GridViewGeometricEntitySet | ||
37 | { | ||
38 | using EntityMap = Dumux::EntityMap<GridView, codim>; | ||
39 | public: | ||
40 | using Entity = typename GridView::template Codim<codim>::Entity; | ||
41 | |||
42 |
1/2✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
|
87 | explicit GridViewGeometricEntitySet(const GridView& gridView) |
43 |
3/6✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 51 times.
✗ Branch 8 not taken.
|
87 | : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>()))) |
44 | 87 | {} | |
45 | |||
46 | 87 | GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper) | |
47 | 87 | : gridView_(gridView) | |
48 | 87 | , mapper_(mapper) | |
49 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
✓ Branch 3 taken 51 times.
✗ Branch 4 not taken.
|
87 | , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_)) |
50 | 87 | {} | |
51 | |||
52 | 909 | GridViewGeometricEntitySet(const GridView& gridView, | |
53 | const Mapper& mapper, | ||
54 | std::shared_ptr<const EntityMap> entityMap) | ||
55 |
4/7✓ Branch 1 taken 715 times.
✓ Branch 2 taken 5 times.
✓ Branch 4 taken 163 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✗ Branch 3 not taken.
|
910 | : gridView_(gridView) |
56 |
4/7✓ Branch 1 taken 725 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 166 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✗ Branch 3 not taken.
|
909 | , mapper_(mapper) |
57 |
4/7✓ Branch 1 taken 715 times.
✓ Branch 2 taken 5 times.
✓ Branch 4 taken 162 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✗ Branch 3 not taken.
|
909 | , entityMap_(entityMap) |
58 | 17 | {} | |
59 | |||
60 | /*! | ||
61 | * \brief The world dimension of the entity set | ||
62 | */ | ||
63 | enum { dimensionworld = GridView::dimensionworld }; | ||
64 | |||
65 | /*! | ||
66 | * \brief the coordinate type | ||
67 | */ | ||
68 | using ctype = typename GridView::ctype; | ||
69 | |||
70 | /*! | ||
71 | * \brief the number of entities in this set | ||
72 | */ | ||
73 | 1025 | decltype(auto) size() const | |
74 |
3/6✓ Branch 6 taken 28 times.
✗ Branch 7 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1025 | { return gridView_.size(codim); } |
75 | |||
76 | /*! | ||
77 | * \brief begin iterator to enable range-based for iteration | ||
78 | */ | ||
79 | 1095 | decltype(auto) begin() const | |
80 | 1383 | { return entities(gridView_, Dune::Codim<codim>()).begin(); } | |
81 | |||
82 | /*! | ||
83 | * \brief end iterator to enable range-based for iteration | ||
84 | */ | ||
85 | 1095 | decltype(auto) end() const | |
86 | 1383 | { return entities(gridView_, Dune::Codim<codim>()).end(); } | |
87 | |||
88 | /*! | ||
89 | * \brief get an entities index | ||
90 | */ | ||
91 | 3731717 | std::size_t index(const Entity& e) const | |
92 |
12/16✓ Branch 1 taken 716199 times.
✓ Branch 2 taken 85212 times.
✓ Branch 4 taken 712696 times.
✓ Branch 5 taken 53999 times.
✓ Branch 7 taken 318 times.
✓ Branch 8 taken 66697 times.
✓ Branch 10 taken 318 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 318 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 318 times.
✗ Branch 17 not taken.
✗ Branch 3 not taken.
✓ Branch 6 taken 88 times.
✓ Branch 9 taken 1927 times.
✓ Branch 12 taken 2123 times.
|
3731717 | { return mapper_.index(e); } |
93 | |||
94 | /*! | ||
95 | * \brief get an entity from an index | ||
96 | */ | ||
97 | 3490202 | Entity entity(std::size_t index) const | |
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2842657 times.
|
3490202 | { assert(index < entityMap_->size()); return (*entityMap_)[index]; } |
99 | |||
100 | private: | ||
101 | GridView gridView_; | ||
102 | Mapper mapper_; | ||
103 | std::shared_ptr<const EntityMap> entityMap_; | ||
104 | }; | ||
105 | |||
106 | } // end namespace Dumux | ||
107 | |||
108 | #ifndef DOXYGEN | ||
109 | namespace Dumux::Detail::GeometricEntity { | ||
110 | |||
111 | /*! | ||
112 | * \brief Wrapper to turn a geometry into a geometric entity | ||
113 | */ | ||
114 | template<class GeoType> | ||
115 |
9/18✗ Branch 0 not taken.
✓ Branch 1 taken 818 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 871 times.
✓ Branch 4 taken 412 times.
✓ Branch 5 taken 360 times.
✓ Branch 6 taken 798 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 326 times.
✓ Branch 10 taken 496 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 32 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
7431 | class EntityWrapper |
116 | { | ||
117 | public: | ||
118 | using Geometry = GeoType; | ||
119 | |||
120 | /*! | ||
121 | * \brief Constructor | ||
122 | */ | ||
123 |
3/6✓ Branch 1 taken 368 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 360 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 360 times.
✗ Branch 8 not taken.
|
27821 | EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {} |
124 | |||
125 | /*! | ||
126 | * \brief Constructor | ||
127 | */ | ||
128 | 28482 | EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {} | |
129 | |||
130 | /*! | ||
131 | * \brief Returns the geometry | ||
132 | */ | ||
133 | 358 | const Geometry& geometry() const | |
134 |
2/5✓ Branch 4 taken 410 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 6898 times.
✗ Branch 9 not taken.
✗ Branch 6 not taken.
|
3267692 | { return geo_; } |
135 | |||
136 | /*! | ||
137 | * \brief Returns the index of the geometry | ||
138 | */ | ||
139 | 56583 | std::size_t index() const | |
140 | 56583 | { return index_; } | |
141 | |||
142 | private: | ||
143 | Geometry geo_; | ||
144 | std::size_t index_; | ||
145 | }; | ||
146 | |||
147 | } // end namespace Dumux::Detail::GeometricEntity | ||
148 | #endif // DOXYGEN | ||
149 | |||
150 | namespace Dumux { | ||
151 | |||
152 | /*! | ||
153 | * \ingroup Geometry | ||
154 | * \brief An interface for a set of geometric entities | ||
155 | * \note This can be used e.g. to construct a bounding box volume hierarchy of a grid | ||
156 | * It defines the minimum requirement for such a set | ||
157 | */ | ||
158 | template<class GeoType> | ||
159 |
5/15✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 29 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1849 | class GeometriesEntitySet |
160 | { | ||
161 | public: | ||
162 | using Entity = Detail::GeometricEntity::EntityWrapper<GeoType>; | ||
163 | |||
164 | /*! | ||
165 | * \brief Constructor for initializer_list | ||
166 | */ | ||
167 | 37 | GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries) | |
168 | 37 | { | |
169 | 37 | std::size_t index = 0; | |
170 | // note: std::initializer_list::begin() returns const T*, | ||
171 | // thus no moving will be performed and only the copying ctor of | ||
172 | // EntityWrapper can be called | ||
173 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 37 times.
|
74 | for (auto&& g : geometries) |
174 |
1/2✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
|
37 | entities_.emplace_back(g, index++); |
175 | 37 | } | |
176 | |||
177 | /*! | ||
178 | * \brief Constructor for a vector of geometries | ||
179 | */ | ||
180 | 1530 | explicit GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries) | |
181 | 1530 | { | |
182 | 1530 | std::size_t index = 0; | |
183 |
2/2✓ Branch 0 taken 27744 times.
✓ Branch 1 taken 790 times.
|
56378 | for (auto&& g : geometries) |
184 |
1/2✓ Branch 1 taken 27744 times.
✗ Branch 2 not taken.
|
54848 | entities_.emplace_back(g, index++); |
185 | 1530 | } | |
186 | |||
187 | /*! | ||
188 | * \brief Constructor for a vector of geometries | ||
189 | */ | ||
190 | 1708 | explicit GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries) | |
191 | 1708 | { | |
192 | 1708 | std::size_t index = 0; | |
193 |
2/2✓ Branch 0 taken 28482 times.
✓ Branch 1 taken 879 times.
|
58032 | for (auto&& g : geometries) |
194 |
1/2✓ Branch 1 taken 28482 times.
✗ Branch 2 not taken.
|
56324 | entities_.emplace_back(std::move(g), index++); |
195 | 1708 | } | |
196 | |||
197 | /*! | ||
198 | * \brief The world dimension of the entity set | ||
199 | */ | ||
200 | enum { dimensionworld = Entity::Geometry::coorddimension }; | ||
201 | |||
202 | /*! | ||
203 | * \brief the coordinate type | ||
204 | */ | ||
205 | using ctype = typename Entity::Geometry::ctype; | ||
206 | |||
207 | /*! | ||
208 | * \brief the number of entities in this set | ||
209 | */ | ||
210 | 1780 | decltype(auto) size() const | |
211 |
4/8✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 36 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
|
1744 | { return entities_.size(); } |
212 | |||
213 | /*! | ||
214 | * \brief begin iterator to enable range-based for iteration | ||
215 | */ | ||
216 | 1706 | decltype(auto) begin() const | |
217 | 1706 | { return entities_.begin(); } | |
218 | |||
219 | /*! | ||
220 | * \brief end iterator to enable range-based for iteration | ||
221 | */ | ||
222 | 1706 | decltype(auto) end() const | |
223 | 1706 | { return entities_.end(); } | |
224 | |||
225 | /*! | ||
226 | * \brief get an entities index | ||
227 | */ | ||
228 | template<class Entity> | ||
229 | 56581 | std::size_t index(const Entity& e) const | |
230 |
7/9✓ Branch 2 taken 488 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 318 times.
✓ Branch 9 taken 480 times.
✗ Branch 10 not taken.
✓ Branch 1 taken 396 times.
✓ Branch 4 taken 318 times.
✓ Branch 5 taken 16 times.
|
56581 | { return e.index(); } |
231 | |||
232 | /*! | ||
233 | * \brief get an entity from an index | ||
234 | */ | ||
235 | 7605784 | const Entity& entity(std::size_t index) const | |
236 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 3803725 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
7605784 | { assert(index < entities_.size()); return entities_[index]; } |
237 | |||
238 | private: | ||
239 | std::vector<Entity> entities_; | ||
240 | }; | ||
241 | |||
242 | /*! | ||
243 | * \ingroup Geometry | ||
244 | * \brief An interface for a fixed-size set of geometric entities | ||
245 | * \note This can be used e.g. to construct a bounding box volume hierarchy of a grid | ||
246 | * It defines the minimum requirement for such a set | ||
247 | */ | ||
248 | template<class GeoType, std::size_t N> | ||
249 | 2 | class FixedSizeGeometriesEntitySet | |
250 | { | ||
251 | template<class GT, std::size_t... I> | ||
252 | 40 | FixedSizeGeometriesEntitySet(GT&& gt, std::index_sequence<I...>) | |
253 | 42 | : entities_{{ Entity(std::get<I>(gt), I)... }} | |
254 | { static_assert(sizeof...(I) == N, "Number of geometries must match the size of the entity set"); } | ||
255 | |||
256 | public: | ||
257 | using Entity = Detail::GeometricEntity::EntityWrapper<GeoType>; | ||
258 | |||
259 | /*! | ||
260 | * \brief Constructor with one or more geometries as arguments | ||
261 | * \note The number of geometries must match the size of the entity set | ||
262 | */ | ||
263 | template<class... G> | ||
264 | 40 | FixedSizeGeometriesEntitySet(G&&... g) | |
265 | 40 | : FixedSizeGeometriesEntitySet(std::forward_as_tuple(std::forward<G>(g)...), std::make_index_sequence<N>{}) | |
266 | {} | ||
267 | |||
268 | /*! | ||
269 | * \brief The world dimension of the entity set | ||
270 | */ | ||
271 | static constexpr int dimensionworld = Entity::Geometry::coorddimension; | ||
272 | |||
273 | /*! | ||
274 | * \brief the coordinate type | ||
275 | */ | ||
276 | using ctype = typename Entity::Geometry::ctype; | ||
277 | |||
278 | /*! | ||
279 | * \brief the number of entities in this set | ||
280 | */ | ||
281 | constexpr auto size() const | ||
282 | 40 | { return entities_.size(); } | |
283 | |||
284 | /*! | ||
285 | * \brief begin iterator to enable range-based for iteration | ||
286 | */ | ||
287 | 1 | decltype(auto) begin() const | |
288 | 1 | { return entities_.begin(); } | |
289 | |||
290 | /*! | ||
291 | * \brief end iterator to enable range-based for iteration | ||
292 | */ | ||
293 | 1 | decltype(auto) end() const | |
294 | 1 | { return entities_.end(); } | |
295 | |||
296 | /*! | ||
297 | * \brief get an entities index | ||
298 | */ | ||
299 | template<class Entity> | ||
300 | 2 | std::size_t index(const Entity& e) const | |
301 | 2 | { return e.index(); } | |
302 | |||
303 | /*! | ||
304 | * \brief get an entity from an index | ||
305 | */ | ||
306 | 2 | const Entity& entity(std::size_t index) const | |
307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
41 | { assert(index < entities_.size()); return entities_[index]; } |
308 | |||
309 | private: | ||
310 | std::array<Entity, N> entities_; | ||
311 | }; | ||
312 | |||
313 | /*! | ||
314 | * \ingroup Geometry | ||
315 | * \brief An interface for a geometric entity set with a single geometry | ||
316 | */ | ||
317 | template<class GeoType> | ||
318 | 2 | class SingleGeometryEntitySet | |
319 | : public FixedSizeGeometriesEntitySet<GeoType, 1> | ||
320 | { | ||
321 | using ParentType = FixedSizeGeometriesEntitySet<GeoType, 1>; | ||
322 | public: | ||
323 | 39 | using ParentType::ParentType; | |
324 | }; | ||
325 | |||
326 | } // end namespace Dumux | ||
327 | |||
328 | #endif | ||
329 |