3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
geometricentityset.hh
Go to the documentation of this file.
1/*****************************************************************************
2 * See the file COPYING for full copying permissions. *
3 * *
4 * This program is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 *****************************************************************************/
24#ifndef DUMUX_GEOMETRIC_ENTITY_SET_HH
25#define DUMUX_GEOMETRIC_ENTITY_SET_HH
26
27#include <memory>
28#include <dune/grid/common/mcmgmapper.hh>
29#include <dune/geometry/multilineargeometry.hh>
31
32namespace Dumux {
33
40template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>>
42{
44public:
45 using Entity = typename GridView::template Codim<codim>::Entity;
46
47 GridViewGeometricEntitySet(const GridView& gridView)
48 : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>())))
49 {}
50
51 GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper)
52 : gridView_(gridView)
53 , mapper_(mapper)
54 , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_))
55 {}
56
57 GridViewGeometricEntitySet(const GridView& gridView,
58 const Mapper& mapper,
59 std::shared_ptr<const EntityMap> entityMap)
60 : gridView_(gridView)
61 , mapper_(mapper)
62 , entityMap_(entityMap)
63 {}
64
68 enum { dimensionworld = GridView::dimensionworld };
69
73 using ctype = typename GridView::ctype;
74
78 decltype(auto) size() const
79 { return gridView_.size(codim); }
80
84 decltype(auto) begin() const
85 { return entities(gridView_, Dune::Codim<codim>()).begin(); }
86
90 decltype(auto) end() const
91 { return entities(gridView_, Dune::Codim<codim>()).end(); }
92
96 std::size_t index(const Entity& e) const
97 { return mapper_.index(e); }
98
102 Entity entity(std::size_t index) const
103 { return (*entityMap_)[index]; }
104
105private:
106 GridView gridView_;
107 Mapper mapper_;
108 std::shared_ptr<const EntityMap> entityMap_;
109
110};
111
118template<class GeoType>
120{
124 class EntityWrapper
125 {
126 public:
127 using Geometry = GeoType;
128
132 EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {}
133
137 EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {}
138
142 const Geometry& geometry() const
143 { return geo_; }
144
148 std::size_t index() const
149 { return index_; }
150
151 private:
152 Geometry geo_;
153 std::size_t index_;
154 };
155
156public:
157 using Entity = EntityWrapper;
158
162 GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
163 {
164 std::size_t index = 0;
165 // note: std::initializer_list::begin() returns const T*,
166 // thus no moving will be performed and only the copying ctor of
167 // EntityWrapper can be called
168 for (auto&& g : geometries)
169 entities_.emplace_back(g, index++);
170 }
171
175 GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
176 {
177 std::size_t index = 0;
178 for (auto&& g : geometries)
179 entities_.emplace_back(g, index++);
180 }
181
185 GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
186 {
187 std::size_t index = 0;
188 for (auto&& g : geometries)
189 entities_.emplace_back(std::move(g), index++);
190 }
191
195 enum { dimensionworld = Entity::Geometry::coorddimension };
196
200 using ctype = typename Entity::Geometry::ctype;
201
205 decltype(auto) size() const
206 { return entities_.size(); }
207
211 decltype(auto) begin() const
212 { return entities_.begin(); }
213
217 decltype(auto) end() const
218 { return entities_.end(); }
219
223 template<class Entity>
224 std::size_t index(const Entity& e) const
225 { return e.index(); }
226
230 Entity entity(std::size_t index) const
231 { return entities_[index]; }
232
233private:
234 std::vector<Entity> entities_;
235};
236
237} // end namespace Dumux
238
239#endif
A map from indices to entities using grid entity seeds.
Definition: adapt.hh:29
Definition: common/pdesolver.hh:35
A map from indices to entities using grid entity seeds.
Definition: entitymap.hh:39
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:42
typename GridView::ctype ctype
the coordinate type
Definition: geometricentityset.hh:73
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper)
Definition: geometricentityset.hh:51
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:96
typename GridView::template Codim< codim >::Entity Entity
Definition: geometricentityset.hh:45
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:78
GridViewGeometricEntitySet(const GridView &gridView)
Definition: geometricentityset.hh:47
Entity entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:102
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:90
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper, std::shared_ptr< const EntityMap > entityMap)
Definition: geometricentityset.hh:57
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:84
@ dimensionworld
Definition: geometricentityset.hh:68
An interface for a set of geometric entities.
Definition: geometricentityset.hh:120
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:217
typename Entity::Geometry::ctype ctype
the coordinate type
Definition: geometricentityset.hh:200
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:211
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:205
@ dimensionworld
Definition: geometricentityset.hh:195
EntityWrapper Entity
Definition: geometricentityset.hh:157
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:224
GeometriesEntitySet(std::initializer_list< typename Entity::Geometry > &&geometries)
Constructor for initializer_list.
Definition: geometricentityset.hh:162
Entity entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:230
GeometriesEntitySet(const std::vector< typename Entity::Geometry > &geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:175
GeometriesEntitySet(std::vector< typename Entity::Geometry > &&geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:185