version 3.10-dev
geometricentityset.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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
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>
26
27namespace Dumux {
28
35template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>>
37{
39public:
40 using Entity = typename GridView::template Codim<codim>::Entity;
41
42 GridViewGeometricEntitySet(const GridView& gridView)
43 : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>())))
44 {}
45
46 GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper)
47 : gridView_(gridView)
48 , mapper_(mapper)
49 , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_))
50 {}
51
52 GridViewGeometricEntitySet(const GridView& gridView,
53 const Mapper& mapper,
54 std::shared_ptr<const EntityMap> entityMap)
55 : gridView_(gridView)
56 , mapper_(mapper)
57 , entityMap_(entityMap)
58 {}
59
63 enum { dimensionworld = GridView::dimensionworld };
64
68 using ctype = typename GridView::ctype;
69
73 decltype(auto) size() const
74 { return gridView_.size(codim); }
75
79 decltype(auto) begin() const
80 { return entities(gridView_, Dune::Codim<codim>()).begin(); }
81
85 decltype(auto) end() const
86 { return entities(gridView_, Dune::Codim<codim>()).end(); }
87
91 std::size_t index(const Entity& e) const
92 { return mapper_.index(e); }
93
97 Entity entity(std::size_t index) const
98 { assert(index < entityMap_->size()); return (*entityMap_)[index]; }
99
100private:
101 GridView gridView_;
102 Mapper mapper_;
103 std::shared_ptr<const EntityMap> entityMap_;
104};
105
106} // end namespace Dumux
107
108#ifndef DOXYGEN
109namespace Dumux::Detail::GeometricEntity {
110
114template<class GeoType>
115class EntityWrapper
116{
117public:
118 using Geometry = GeoType;
119
123 EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {}
124
128 EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {}
129
133 const Geometry& geometry() const
134 { return geo_; }
135
139 std::size_t index() const
140 { return index_; }
141
142private:
143 Geometry geo_;
144 std::size_t index_;
145};
146
147} // end namespace Dumux::Detail::GeometricEntity
148#endif // DOXYGEN
149
150namespace Dumux {
151
158template<class GeoType>
160{
161public:
162 using Entity = Detail::GeometricEntity::EntityWrapper<GeoType>;
163
167 GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
168 {
169 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 for (auto&& g : geometries)
174 entities_.emplace_back(g, index++);
175 }
176
180 GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
181 {
182 std::size_t index = 0;
183 for (auto&& g : geometries)
184 entities_.emplace_back(g, index++);
185 }
186
190 GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
191 {
192 std::size_t index = 0;
193 for (auto&& g : geometries)
194 entities_.emplace_back(std::move(g), index++);
195 }
196
200 enum { dimensionworld = Entity::Geometry::coorddimension };
201
205 using ctype = typename Entity::Geometry::ctype;
206
210 decltype(auto) size() const
211 { return entities_.size(); }
212
216 decltype(auto) begin() const
217 { return entities_.begin(); }
218
222 decltype(auto) end() const
223 { return entities_.end(); }
224
228 template<class Entity>
229 std::size_t index(const Entity& e) const
230 { return e.index(); }
231
235 const Entity& entity(std::size_t index) const
236 { assert(index < entities_.size()); return entities_[index]; }
237
238private:
239 std::vector<Entity> entities_;
240};
241
248template<class GeoType, std::size_t N>
250{
251 template<class GT, std::size_t... I>
252 FixedSizeGeometriesEntitySet(GT&& gt, std::index_sequence<I...>)
253 : 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
256public:
257 using Entity = Detail::GeometricEntity::EntityWrapper<GeoType>;
258
263 template<class... G>
265 : FixedSizeGeometriesEntitySet(std::forward_as_tuple(std::forward<G>(g)...), std::make_index_sequence<N>{})
266 {}
267
271 static constexpr int dimensionworld = Entity::Geometry::coorddimension;
272
276 using ctype = typename Entity::Geometry::ctype;
277
281 constexpr auto size() const
282 { return entities_.size(); }
283
287 decltype(auto) begin() const
288 { return entities_.begin(); }
289
293 decltype(auto) end() const
294 { return entities_.end(); }
295
299 template<class Entity>
300 std::size_t index(const Entity& e) const
301 { return e.index(); }
302
306 const Entity& entity(std::size_t index) const
307 { assert(index < entities_.size()); return entities_[index]; }
308
309private:
310 std::array<Entity, N> entities_;
311};
312
317template<class GeoType>
319: public FixedSizeGeometriesEntitySet<GeoType, 1>
320{
322public:
323 using ParentType::ParentType;
324};
325
326} // end namespace Dumux
327
328#endif
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:27
An interface for a fixed-size set of geometric entities.
Definition: geometricentityset.hh:250
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:300
FixedSizeGeometriesEntitySet(G &&... g)
Constructor with one or more geometries as arguments.
Definition: geometricentityset.hh:264
constexpr auto size() const
the number of entities in this set
Definition: geometricentityset.hh:281
const Entity & entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:306
static constexpr int dimensionworld
The world dimension of the entity set.
Definition: geometricentityset.hh:271
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:287
Detail::GeometricEntity::EntityWrapper< GeoType > Entity
Definition: geometricentityset.hh:257
typename Entity::Geometry::ctype ctype
the coordinate type
Definition: geometricentityset.hh:276
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:293
An interface for a set of geometric entities.
Definition: geometricentityset.hh:160
@ dimensionworld
Definition: geometricentityset.hh:200
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:222
typename Entity::Geometry::ctype ctype
the coordinate type
Definition: geometricentityset.hh:205
Detail::GeometricEntity::EntityWrapper< GeoType > Entity
Definition: geometricentityset.hh:162
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:216
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:210
const Entity & entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:235
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:229
GeometriesEntitySet(std::initializer_list< typename Entity::Geometry > &&geometries)
Constructor for initializer_list.
Definition: geometricentityset.hh:167
GeometriesEntitySet(const std::vector< typename Entity::Geometry > &geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:180
GeometriesEntitySet(std::vector< typename Entity::Geometry > &&geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:190
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:37
typename GridView::ctype ctype
the coordinate type
Definition: geometricentityset.hh:68
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper)
Definition: geometricentityset.hh:46
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:91
typename GridView::template Codim< codim >::Entity Entity
Definition: geometricentityset.hh:40
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:73
GridViewGeometricEntitySet(const GridView &gridView)
Definition: geometricentityset.hh:42
Entity entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:97
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:85
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper, std::shared_ptr< const EntityMap > entityMap)
Definition: geometricentityset.hh:52
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:79
@ dimensionworld
Definition: geometricentityset.hh:63
An interface for a geometric entity set with a single geometry.
Definition: geometricentityset.hh:320
A map from indices to entities using grid entity seeds.
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24