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 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 <memory> | ||
18 | #include <dune/grid/common/mcmgmapper.hh> | ||
19 | #include <dune/geometry/multilineargeometry.hh> | ||
20 | #include <dumux/common/entitymap.hh> | ||
21 | |||
22 | namespace Dumux { | ||
23 | |||
24 | /*! | ||
25 | * \ingroup Geometry | ||
26 | * \brief An interface for a set of geometric entities based on a GridView | ||
27 | * \note This can be used e.g. to construct a bounding box volume hierarchy of a grid | ||
28 | * It defines the minimum requirement for such a set | ||
29 | */ | ||
30 | template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>> | ||
31 | class GridViewGeometricEntitySet | ||
32 | { | ||
33 | using EntityMap = Dumux::EntityMap<GridView, codim>; | ||
34 | public: | ||
35 | using Entity = typename GridView::template Codim<codim>::Entity; | ||
36 | |||
37 | 84 | GridViewGeometricEntitySet(const GridView& gridView) | |
38 |
4/10✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
168 | : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>()))) |
39 | 84 | {} | |
40 | |||
41 | 84 | GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper) | |
42 | : gridView_(gridView) | ||
43 | , mapper_(mapper) | ||
44 |
2/4✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
✓ Branch 5 taken 48 times.
✗ Branch 6 not taken.
|
168 | , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_)) |
45 | 84 | {} | |
46 | |||
47 | 16 | GridViewGeometricEntitySet(const GridView& gridView, | |
48 | const Mapper& mapper, | ||
49 | std::shared_ptr<const EntityMap> entityMap) | ||
50 | : gridView_(gridView) | ||
51 | , mapper_(mapper) | ||
52 |
1/20✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
23 | , entityMap_(entityMap) |
53 | 16 | {} | |
54 | |||
55 | /*! | ||
56 | * \brief The world dimension of the entity set | ||
57 | */ | ||
58 | enum { dimensionworld = GridView::dimensionworld }; | ||
59 | |||
60 | /*! | ||
61 | * \brief the coordinate type | ||
62 | */ | ||
63 | using ctype = typename GridView::ctype; | ||
64 | |||
65 | /*! | ||
66 | * \brief the number of entities in this set | ||
67 | */ | ||
68 | decltype(auto) size() const | ||
69 |
2/4✓ Branch 6 taken 27 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
923 | { return gridView_.size(codim); } |
70 | |||
71 | /*! | ||
72 | * \brief begin iterator to enable range-based for iteration | ||
73 | */ | ||
74 | 246 | decltype(auto) begin() const | |
75 |
10/17✓ Branch 1 taken 397 times.
✓ Branch 2 taken 119 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 428 times.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 433 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 87 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 56 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 51 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
|
1018 | { return entities(gridView_, Dune::Codim<codim>()).begin(); } |
76 | |||
77 | /*! | ||
78 | * \brief end iterator to enable range-based for iteration | ||
79 | */ | ||
80 | 246 | decltype(auto) end() const | |
81 |
6/8✓ Branch 1 taken 397 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 52 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
|
1018 | { return entities(gridView_, Dune::Codim<codim>()).end(); } |
82 | |||
83 | /*! | ||
84 | * \brief get an entities index | ||
85 | */ | ||
86 | std::size_t index(const Entity& e) const | ||
87 |
13/16✓ Branch 1 taken 607444 times.
✓ Branch 2 taken 65116 times.
✓ Branch 3 taken 200 times.
✓ Branch 4 taken 596532 times.
✓ Branch 5 taken 53999 times.
✓ Branch 6 taken 88 times.
✓ Branch 7 taken 318 times.
✓ Branch 8 taken 66697 times.
✓ Branch 9 taken 1927 times.
✓ Branch 10 taken 318 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2123 times.
✓ Branch 13 taken 318 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 318 times.
✗ Branch 17 not taken.
|
3282348 | { return mapper_.index(e); } |
88 | |||
89 | /*! | ||
90 | * \brief get an entity from an index | ||
91 | */ | ||
92 | 3426238 | Entity entity(std::size_t index) const | |
93 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 2786741 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2786741 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2786741 times.
|
10278714 | { assert(index < entityMap_->size()); return (*entityMap_)[index]; } |
94 | |||
95 | private: | ||
96 | GridView gridView_; | ||
97 | Mapper mapper_; | ||
98 | std::shared_ptr<const EntityMap> entityMap_; | ||
99 | }; | ||
100 | |||
101 | /*! | ||
102 | * \ingroup Geometry | ||
103 | * \brief An interface for a set of geometric entities | ||
104 | * \note This can be used e.g. to construct a bounding box volume hierarchy of a grid | ||
105 | * It defines the minimum requirement for such a set | ||
106 | */ | ||
107 | template<class GeoType> | ||
108 |
28/72✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 29 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 37 times.
✓ Branch 11 taken 25 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 25 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 8 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 8 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 8 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 8 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 8 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 8 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 120 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 120 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 120 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 122 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 122 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 122 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 2 times.
✓ Branch 55 taken 120 times.
✓ Branch 56 taken 6 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 126 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 6 times.
✓ Branch 61 taken 120 times.
✓ Branch 62 taken 6 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 2 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 2 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 2 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 2 times.
✗ Branch 71 not taken.
|
1791 | class GeometriesEntitySet |
109 | { | ||
110 | /*! | ||
111 | * \brief Wrapper to turn a geometry into a geometric entity | ||
112 | */ | ||
113 |
14/36✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 450 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 871 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 396 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 318 times.
✓ Branch 19 taken 360 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 318 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 8 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 360 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 16 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 512 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 480 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 480 times.
✗ Branch 35 not taken.
|
11529 | class EntityWrapper |
114 | { | ||
115 | public: | ||
116 | using Geometry = GeoType; | ||
117 | |||
118 | /*! | ||
119 | * \brief Constructor | ||
120 | */ | ||
121 |
4/12✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 360 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 360 times.
✗ Branch 16 not taken.
✓ Branch 20 taken 360 times.
✗ Branch 21 not taken.
|
27667 | EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {} |
122 | |||
123 | /*! | ||
124 | * \brief Constructor | ||
125 | */ | ||
126 | 29102 | EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {} | |
127 | |||
128 | /*! | ||
129 | * \brief Returns the geometry | ||
130 | */ | ||
131 | const Geometry& geometry() const | ||
132 |
2/5✓ Branch 4 taken 410 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6898 times.
✗ Branch 8 not taken.
|
3264776 | { return geo_; } |
133 | |||
134 | /*! | ||
135 | * \brief Returns the index of the geometry | ||
136 | */ | ||
137 | ✗ | std::size_t index() const | |
138 | ✗ | { return index_; } | |
139 | |||
140 | private: | ||
141 | Geometry geo_; | ||
142 | std::size_t index_; | ||
143 | }; | ||
144 | |||
145 | public: | ||
146 | using Entity = EntityWrapper; | ||
147 | |||
148 | /*! | ||
149 | * \brief Constructor for initializer_list | ||
150 | */ | ||
151 | 33 | GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries) | |
152 | 33 | { | |
153 | 33 | std::size_t index = 0; | |
154 | // note: std::initializer_list::begin() returns const T*, | ||
155 | // thus no moving will be performed and only the copying ctor of | ||
156 | // EntityWrapper can be called | ||
157 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 33 times.
|
99 | for (auto&& g : geometries) |
158 |
1/4✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
33 | entities_.emplace_back(g, index++); |
159 | 33 | } | |
160 | |||
161 | /*! | ||
162 | * \brief Constructor for a vector of geometries | ||
163 | */ | ||
164 | 1509 | GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries) | |
165 | 1509 | { | |
166 | 1509 | std::size_t index = 0; | |
167 |
4/4✓ Branch 0 taken 27634 times.
✓ Branch 1 taken 769 times.
✓ Branch 2 taken 27634 times.
✓ Branch 3 taken 769 times.
|
114003 | for (auto&& g : geometries) |
168 |
1/4✓ Branch 1 taken 27634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
54738 | entities_.emplace_back(g, index++); |
169 | 1509 | } | |
170 | |||
171 | /*! | ||
172 | * \brief Constructor for a vector of geometries | ||
173 | */ | ||
174 | 1687 | GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries) | |
175 | 1687 | { | |
176 | 1687 | std::size_t index = 0; | |
177 |
4/4✓ Branch 0 taken 28372 times.
✓ Branch 1 taken 858 times.
✓ Branch 2 taken 28372 times.
✓ Branch 3 taken 858 times.
|
117489 | for (auto&& g : geometries) |
178 |
1/4✓ Branch 1 taken 28372 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
56214 | entities_.emplace_back(std::move(g), index++); |
179 | 1687 | } | |
180 | |||
181 | /*! | ||
182 | * \brief The world dimension of the entity set | ||
183 | */ | ||
184 | enum { dimensionworld = Entity::Geometry::coorddimension }; | ||
185 | |||
186 | /*! | ||
187 | * \brief the coordinate type | ||
188 | */ | ||
189 | using ctype = typename Entity::Geometry::ctype; | ||
190 | |||
191 | /*! | ||
192 | * \brief the number of entities in this set | ||
193 | */ | ||
194 | decltype(auto) size() const | ||
195 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1661 | { return entities_.size(); } |
196 | |||
197 | /*! | ||
198 | * \brief begin iterator to enable range-based for iteration | ||
199 | */ | ||
200 | decltype(auto) begin() const | ||
201 | 1660 | { return entities_.begin(); } | |
202 | |||
203 | /*! | ||
204 | * \brief end iterator to enable range-based for iteration | ||
205 | */ | ||
206 | decltype(auto) end() const | ||
207 | 1660 | { return entities_.end(); } | |
208 | |||
209 | /*! | ||
210 | * \brief get an entities index | ||
211 | */ | ||
212 | template<class Entity> | ||
213 | ✗ | std::size_t index(const Entity& e) const | |
214 |
5/8✓ Branch 1 taken 876 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 798 times.
✓ Branch 5 taken 16 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 798 times.
✗ Branch 8 not taken.
|
56357 | { return e.index(); } |
215 | |||
216 | /*! | ||
217 | * \brief get an entity from an index | ||
218 | */ | ||
219 | 7598138 | const Entity& entity(std::size_t index) const | |
220 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 3799662 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3799662 times.
|
15196276 | { assert(index < entities_.size()); return entities_[index]; } |
221 | |||
222 | private: | ||
223 | std::vector<Entity> entities_; | ||
224 | }; | ||
225 | |||
226 | } // end namespace Dumux | ||
227 | |||
228 | #endif | ||
229 |