version 3.8
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 <memory>
18#include <dune/grid/common/mcmgmapper.hh>
19#include <dune/geometry/multilineargeometry.hh>
21
22namespace Dumux {
23
30template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>>
32{
34public:
35 using Entity = typename GridView::template Codim<codim>::Entity;
36
37 GridViewGeometricEntitySet(const GridView& gridView)
38 : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>())))
39 {}
40
41 GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper)
42 : gridView_(gridView)
43 , mapper_(mapper)
44 , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_))
45 {}
46
47 GridViewGeometricEntitySet(const GridView& gridView,
48 const Mapper& mapper,
49 std::shared_ptr<const EntityMap> entityMap)
50 : gridView_(gridView)
51 , mapper_(mapper)
52 , entityMap_(entityMap)
53 {}
54
58 enum { dimensionworld = GridView::dimensionworld };
59
63 using ctype = typename GridView::ctype;
64
68 decltype(auto) size() const
69 { return gridView_.size(codim); }
70
74 decltype(auto) begin() const
75 { return entities(gridView_, Dune::Codim<codim>()).begin(); }
76
80 decltype(auto) end() const
81 { return entities(gridView_, Dune::Codim<codim>()).end(); }
82
86 std::size_t index(const Entity& e) const
87 { return mapper_.index(e); }
88
92 Entity entity(std::size_t index) const
93 { assert(index < entityMap_->size()); return (*entityMap_)[index]; }
94
95private:
96 GridView gridView_;
97 Mapper mapper_;
98 std::shared_ptr<const EntityMap> entityMap_;
99};
100
107template<class GeoType>
109{
113 class EntityWrapper
114 {
115 public:
116 using Geometry = GeoType;
117
121 EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {}
122
126 EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {}
127
131 const Geometry& geometry() const
132 { return geo_; }
133
137 std::size_t index() const
138 { return index_; }
139
140 private:
141 Geometry geo_;
142 std::size_t index_;
143 };
144
145public:
146 using Entity = EntityWrapper;
147
151 GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
152 {
153 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 for (auto&& g : geometries)
158 entities_.emplace_back(g, index++);
159 }
160
164 GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
165 {
166 std::size_t index = 0;
167 for (auto&& g : geometries)
168 entities_.emplace_back(g, index++);
169 }
170
174 GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
175 {
176 std::size_t index = 0;
177 for (auto&& g : geometries)
178 entities_.emplace_back(std::move(g), index++);
179 }
180
184 enum { dimensionworld = Entity::Geometry::coorddimension };
185
189 using ctype = typename Entity::Geometry::ctype;
190
194 decltype(auto) size() const
195 { return entities_.size(); }
196
200 decltype(auto) begin() const
201 { return entities_.begin(); }
202
206 decltype(auto) end() const
207 { return entities_.end(); }
208
212 template<class Entity>
213 std::size_t index(const Entity& e) const
214 { return e.index(); }
215
219 const Entity& entity(std::size_t index) const
220 { assert(index < entities_.size()); return entities_[index]; }
221
222private:
223 std::vector<Entity> entities_;
224};
225
226} // end namespace Dumux
227
228#endif
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:27
An interface for a set of geometric entities.
Definition: geometricentityset.hh:109
@ dimensionworld
Definition: geometricentityset.hh:184
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:206
typename Entity::Geometry::ctype ctype
the coordinate type
Definition: geometricentityset.hh:189
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:200
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:194
const Entity & entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:219
EntityWrapper Entity
Definition: geometricentityset.hh:146
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:213
GeometriesEntitySet(std::initializer_list< typename Entity::Geometry > &&geometries)
Constructor for initializer_list.
Definition: geometricentityset.hh:151
GeometriesEntitySet(const std::vector< typename Entity::Geometry > &geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:164
GeometriesEntitySet(std::vector< typename Entity::Geometry > &&geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:174
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:32
typename GridView::ctype ctype
the coordinate type
Definition: geometricentityset.hh:63
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper)
Definition: geometricentityset.hh:41
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:86
typename GridView::template Codim< codim >::Entity Entity
Definition: geometricentityset.hh:35
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:68
GridViewGeometricEntitySet(const GridView &gridView)
Definition: geometricentityset.hh:37
Entity entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:92
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:80
@ dimensionworld
Definition: geometricentityset.hh:58
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper, std::shared_ptr< const EntityMap > entityMap)
Definition: geometricentityset.hh:47
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:74
A map from indices to entities using grid entity seeds.
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24