version 3.11-dev
Loading...
Searching...
No Matches
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-FileCopyrightText: 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>
27
28namespace Dumux {
29
36template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>>
38{
39 using EntityMap = Dumux::EntityMap<GridView, codim>;
40public:
41 using Entity = typename GridView::template Codim<codim>::Entity;
42
43 explicit GridViewGeometricEntitySet(const GridView& gridView)
44 : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>())))
45 {}
46
47 GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper)
48 : gridView_(gridView)
49 , mapper_(mapper)
50 , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_))
51 {}
52
53 GridViewGeometricEntitySet(const GridView& gridView,
54 const Mapper& mapper,
55 std::shared_ptr<const EntityMap> entityMap)
56 : gridView_(gridView)
57 , mapper_(mapper)
58 , entityMap_(entityMap)
59 {}
60
64 static constexpr int dimensionworld = GridView::dimensionworld;
65
69 using ctype = typename GridView::ctype;
70
74 decltype(auto) size() const
75 { return gridView_.size(codim); }
76
81 decltype(auto) comm() const
82 { return gridView_.comm(); }
83
87 decltype(auto) begin() const
88 { return entities(gridView_, Dune::Codim<codim>()).begin(); }
89
93 decltype(auto) end() const
94 { return entities(gridView_, Dune::Codim<codim>()).end(); }
95
99 std::size_t index(const Entity& e) const
100 { return mapper_.index(e); }
101
105 Entity entity(std::size_t index) const
106 { assert(index < entityMap_->size()); return (*entityMap_)[index]; }
107
108private:
109 GridView gridView_;
110 Mapper mapper_;
111 std::shared_ptr<const EntityMap> entityMap_;
112};
113
114} // end namespace Dumux
115
116#ifndef DOXYGEN
117namespace Dumux::Detail::GeometricEntity {
118
122template<class GeoType>
123class EntityWrapper
124{
125public:
126 using Geometry = GeoType;
127
131 EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {}
132
136 EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {}
137
141 const Geometry& geometry() const
142 { return geo_; }
143
147 std::size_t index() const
148 { return index_; }
149
150private:
151 Geometry geo_;
152 std::size_t index_;
153};
154
158template<class ct, int dimworld>
159class ProcessEntity
160{
161public:
162 using Geometry = BoundingBoxGeometry<ct, dimworld>;
163
164 ProcessEntity(const Geometry& geo, std::size_t index, int rank)
165 : geo_(geo), index_(index), rank_(rank) {}
166
168 const Geometry& geometry() const
169 { return geo_; }
170
172 std::size_t index() const
173 { return index_; }
174
176 int rank() const
177 { return rank_; }
178
179private:
180 Geometry geo_;
181 std::size_t index_;
182 int rank_;
183};
184
185} // end namespace Dumux::Detail::GeometricEntity
186#endif // DOXYGEN
187
188namespace Dumux {
189
196template<class GeoType>
198{
199public:
200 using Entity = Detail::GeometricEntity::EntityWrapper<GeoType>;
201
205 GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
206 {
207 std::size_t index = 0;
208 // note: std::initializer_list::begin() returns const T*,
209 // thus no moving will be performed and only the copying ctor of
210 // EntityWrapper can be called
211 for (auto&& g : geometries)
212 entities_.emplace_back(g, index++);
213 }
214
218 explicit GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
219 {
220 std::size_t index = 0;
221 for (auto&& g : geometries)
222 entities_.emplace_back(g, index++);
223 }
224
228 explicit GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
229 {
230 std::size_t index = 0;
231 for (auto&& g : geometries)
232 entities_.emplace_back(std::move(g), index++);
233 }
234
238 static constexpr int dimensionworld = Entity::Geometry::coorddimension;
239
243 using ctype = typename Entity::Geometry::ctype;
244
248 decltype(auto) size() const
249 { return entities_.size(); }
250
254 decltype(auto) begin() const
255 { return entities_.begin(); }
256
260 decltype(auto) end() const
261 { return entities_.end(); }
262
266 template<class Entity>
267 std::size_t index(const Entity& e) const
268 { return e.index(); }
269
273 const Entity& entity(std::size_t index) const
274 { assert(index < entities_.size()); return entities_[index]; }
275
276private:
277 std::vector<Entity> entities_;
278};
279
286template<class GeoType, std::size_t N>
287class FixedSizeGeometriesEntitySet
288{
289 template<class GT, std::size_t... I>
290 FixedSizeGeometriesEntitySet(GT&& gt, std::index_sequence<I...>)
291 : entities_{{ Entity(std::get<I>(gt), I)... }}
292 { static_assert(sizeof...(I) == N, "Number of geometries must match the size of the entity set"); }
293
294public:
295 using Entity = Detail::GeometricEntity::EntityWrapper<GeoType>;
296
301 template<class... G>
303 : FixedSizeGeometriesEntitySet(std::forward_as_tuple(std::forward<G>(g)...), std::make_index_sequence<N>{})
304 {}
305
309 static constexpr int dimensionworld = Entity::Geometry::coorddimension;
310
314 using ctype = typename Entity::Geometry::ctype;
315
319 constexpr auto size() const
320 { return entities_.size(); }
321
325 decltype(auto) begin() const
326 { return entities_.begin(); }
327
331 decltype(auto) end() const
332 { return entities_.end(); }
333
337 template<class Entity>
338 std::size_t index(const Entity& e) const
339 { return e.index(); }
340
344 const Entity& entity(std::size_t index) const
345 { assert(index < entities_.size()); return entities_[index]; }
346
347private:
348 std::array<Entity, N> entities_;
349};
350
355template<class GeoType>
357: public FixedSizeGeometriesEntitySet<GeoType, 1>
358{
359 using ParentType = FixedSizeGeometriesEntitySet<GeoType, 1>;
360public:
361 using ParentType::ParentType;
362};
363
373template<class ct, int dimworld>
375{
376public:
377 using Entity = Detail::GeometricEntity::ProcessEntity<ct, dimworld>;
378
382 static constexpr int dimensionworld = dimworld;
383
387 using ctype = ct;
388
392 explicit ProcessGeometricEntitySet(std::vector<Entity>&& entities)
393 : entities_(std::move(entities)) {}
394
398 std::size_t size() const
399 { return entities_.size(); }
400
404 decltype(auto) begin() const
405 { return entities_.begin(); }
406
410 decltype(auto) end() const
411 { return entities_.end(); }
412
416 std::size_t index(const Entity& e) const
417 { return e.index(); }
418
422 const Entity& entity(std::size_t index) const
423 { assert(index < entities_.size()); return entities_[index]; }
424
428 int rank(std::size_t index) const
429 { assert(index < entities_.size()); return entities_[index].rank(); }
430
431private:
432 std::vector<Entity> entities_;
433};
434
435} // end namespace Dumux
436
437#endif
A thin axis-aligned box geometry.
A map from indices to entities using grid entity seeds.
Definition entitymap.hh:27
std::size_t index(const Entity &e) const
get an entities index
Definition geometricentityset.hh:338
FixedSizeGeometriesEntitySet(G &&... g)
Constructor with one or more geometries as arguments.
Definition geometricentityset.hh:302
constexpr auto size() const
the number of entities in this set
Definition geometricentityset.hh:319
const Entity & entity(std::size_t index) const
get an entity from an index
Definition geometricentityset.hh:344
static constexpr int dimensionworld
Definition geometricentityset.hh:309
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition geometricentityset.hh:325
Detail::GeometricEntity::EntityWrapper< GeoType > Entity
Definition geometricentityset.hh:295
typename Entity::Geometry::ctype ctype
the coordinate type
Definition geometricentityset.hh:314
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition geometricentityset.hh:331
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition geometricentityset.hh:260
typename Entity::Geometry::ctype ctype
Definition geometricentityset.hh:243
Detail::GeometricEntity::EntityWrapper< Geometry > Entity
Definition geometricentityset.hh:200
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition geometricentityset.hh:254
decltype(auto) size() const
the number of entities in this set
Definition geometricentityset.hh:248
const Entity & entity(std::size_t index) const
get an entity from an index
Definition geometricentityset.hh:273
std::size_t index(const Entity &e) const
Definition geometricentityset.hh:267
GeometriesEntitySet(std::initializer_list< typename Entity::Geometry > &&geometries)
Constructor for initializer_list.
Definition geometricentityset.hh:205
GeometriesEntitySet(const std::vector< typename Entity::Geometry > &geometries)
Constructor for a vector of geometries.
Definition geometricentityset.hh:218
GeometriesEntitySet(std::vector< typename Entity::Geometry > &&geometries)
Constructor for a vector of geometries.
Definition geometricentityset.hh:228
static constexpr int dimensionworld
Definition geometricentityset.hh:238
static constexpr int dimensionworld
Definition geometricentityset.hh:64
typename GV::ctype ctype
Definition geometricentityset.hh:69
decltype(auto) comm() const
the communicator of the underlying grid view
Definition geometricentityset.hh:81
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper)
Definition geometricentityset.hh:47
std::size_t index(const Entity &e) const
get an entities index
Definition geometricentityset.hh:99
typename GV::template Codim< codim >::Entity Entity
Definition geometricentityset.hh:41
decltype(auto) size() const
the number of entities in this set
Definition geometricentityset.hh:74
GridViewGeometricEntitySet(const GridView &gridView)
Definition geometricentityset.hh:43
Entity entity(std::size_t index) const
get an entity from an index
Definition geometricentityset.hh:105
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition geometricentityset.hh:93
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper, std::shared_ptr< const EntityMap > entityMap)
Definition geometricentityset.hh:53
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition geometricentityset.hh:87
Detail::GeometricEntity::ProcessEntity< ctype, dimworld > Entity
Definition geometricentityset.hh:377
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition geometricentityset.hh:404
static constexpr int dimensionworld
Definition geometricentityset.hh:382
ctype ctype
Definition geometricentityset.hh:387
const Entity & entity(std::size_t index) const
get an entity from an index
Definition geometricentityset.hh:422
ProcessGeometricEntitySet(std::vector< Entity > &&entities)
Constructor from a vector of process partition entities.
Definition geometricentityset.hh:392
std::size_t size() const
the number of entities in this set
Definition geometricentityset.hh:398
int rank(std::size_t index) const
get the rank owning the entity with the given index
Definition geometricentityset.hh:428
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition geometricentityset.hh:410
std::size_t index(const Entity &e) const
get an entities index
Definition geometricentityset.hh:416
An interface for a geometric entity set with a single geometry.
Definition geometricentityset.hh:358
A map from indices to entities using grid entity seeds.
Definition adapt.hh:17
Definition common/pdesolver.hh:24