3.5-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_GEOMETRY_GEOMETRIC_ENTITY_SET_HH
25#define DUMUX_GEOMETRY_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 { assert(index < entityMap_->size()); return (*entityMap_)[index]; }
104
105private:
106 GridView gridView_;
107 Mapper mapper_;
108 std::shared_ptr<const EntityMap> entityMap_;
109};
110
117template<class GeoType>
119{
123 class EntityWrapper
124 {
125 public:
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
150 private:
151 Geometry geo_;
152 std::size_t index_;
153 };
154
155public:
156 using Entity = EntityWrapper;
157
161 GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
162 {
163 std::size_t index = 0;
164 // note: std::initializer_list::begin() returns const T*,
165 // thus no moving will be performed and only the copying ctor of
166 // EntityWrapper can be called
167 for (auto&& g : geometries)
168 entities_.emplace_back(g, index++);
169 }
170
174 GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
175 {
176 std::size_t index = 0;
177 for (auto&& g : geometries)
178 entities_.emplace_back(g, index++);
179 }
180
184 GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
185 {
186 std::size_t index = 0;
187 for (auto&& g : geometries)
188 entities_.emplace_back(std::move(g), index++);
189 }
190
194 enum { dimensionworld = Entity::Geometry::coorddimension };
195
199 using ctype = typename Entity::Geometry::ctype;
200
204 decltype(auto) size() const
205 { return entities_.size(); }
206
210 decltype(auto) begin() const
211 { return entities_.begin(); }
212
216 decltype(auto) end() const
217 { return entities_.end(); }
218
222 template<class Entity>
223 std::size_t index(const Entity& e) const
224 { return e.index(); }
225
229 const Entity& entity(std::size_t index) const
230 { assert(index < entities_.size()); return entities_[index]; }
231
232private:
233 std::vector<Entity> entities_;
234};
235
236} // end namespace Dumux
237
238#endif
A map from indices to entities using grid entity seeds.
Definition: adapt.hh:29
Definition: common/pdesolver.hh:36
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
@ dimensionworld
Definition: geometricentityset.hh:68
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
An interface for a set of geometric entities.
Definition: geometricentityset.hh:119
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:216
typename Entity::Geometry::ctype ctype
the coordinate type
Definition: geometricentityset.hh:199
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:210
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:204
const Entity & entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:229
EntityWrapper Entity
Definition: geometricentityset.hh:156
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:223
GeometriesEntitySet(std::initializer_list< typename Entity::Geometry > &&geometries)
Constructor for initializer_list.
Definition: geometricentityset.hh:161
GeometriesEntitySet(const std::vector< typename Entity::Geometry > &geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:174
GeometriesEntitySet(std::vector< typename Entity::Geometry > &&geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:184
@ dimensionworld
Definition: geometricentityset.hh:194