3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_GEOMETRY_GEOMETRIC_ENTITY_SET_HH
27#define DUMUX_GEOMETRY_GEOMETRIC_ENTITY_SET_HH
28
29#include <memory>
30#include <dune/grid/common/mcmgmapper.hh>
31#include <dune/geometry/multilineargeometry.hh>
33
34namespace Dumux {
35
42template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>>
44{
46public:
47 using Entity = typename GridView::template Codim<codim>::Entity;
48
49 GridViewGeometricEntitySet(const GridView& gridView)
50 : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>())))
51 {}
52
53 GridViewGeometricEntitySet(const GridView& gridView, const Mapper& mapper)
54 : gridView_(gridView)
55 , mapper_(mapper)
56 , entityMap_(std::make_shared<EntityMap>(gridView.grid(), mapper_))
57 {}
58
59 GridViewGeometricEntitySet(const GridView& gridView,
60 const Mapper& mapper,
61 std::shared_ptr<const EntityMap> entityMap)
62 : gridView_(gridView)
63 , mapper_(mapper)
64 , entityMap_(entityMap)
65 {}
66
70 enum { dimensionworld = GridView::dimensionworld };
71
75 using ctype = typename GridView::ctype;
76
80 decltype(auto) size() const
81 { return gridView_.size(codim); }
82
86 decltype(auto) begin() const
87 { return entities(gridView_, Dune::Codim<codim>()).begin(); }
88
92 decltype(auto) end() const
93 { return entities(gridView_, Dune::Codim<codim>()).end(); }
94
98 std::size_t index(const Entity& e) const
99 { return mapper_.index(e); }
100
104 Entity entity(std::size_t index) const
105 { assert(index < entityMap_->size()); return (*entityMap_)[index]; }
106
107private:
108 GridView gridView_;
109 Mapper mapper_;
110 std::shared_ptr<const EntityMap> entityMap_;
111};
112
119template<class GeoType>
121{
125 class EntityWrapper
126 {
127 public:
128 using Geometry = GeoType;
129
133 EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {}
134
138 EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {}
139
143 const Geometry& geometry() const
144 { return geo_; }
145
149 std::size_t index() const
150 { return index_; }
151
152 private:
153 Geometry geo_;
154 std::size_t index_;
155 };
156
157public:
158 using Entity = EntityWrapper;
159
163 GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
164 {
165 std::size_t index = 0;
166 // note: std::initializer_list::begin() returns const T*,
167 // thus no moving will be performed and only the copying ctor of
168 // EntityWrapper can be called
169 for (auto&& g : geometries)
170 entities_.emplace_back(g, index++);
171 }
172
176 GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
177 {
178 std::size_t index = 0;
179 for (auto&& g : geometries)
180 entities_.emplace_back(g, index++);
181 }
182
186 GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
187 {
188 std::size_t index = 0;
189 for (auto&& g : geometries)
190 entities_.emplace_back(std::move(g), index++);
191 }
192
196 enum { dimensionworld = Entity::Geometry::coorddimension };
197
201 using ctype = typename Entity::Geometry::ctype;
202
206 decltype(auto) size() const
207 { return entities_.size(); }
208
212 decltype(auto) begin() const
213 { return entities_.begin(); }
214
218 decltype(auto) end() const
219 { return entities_.end(); }
220
224 template<class Entity>
225 std::size_t index(const Entity& e) const
226 { return e.index(); }
227
231 const Entity& entity(std::size_t index) const
232 { assert(index < entities_.size()); return entities_[index]; }
233
234private:
235 std::vector<Entity> entities_;
236};
237
238} // end namespace Dumux
239
240#endif
A map from indices to entities using grid entity seeds.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Definition: deprecated.hh:149
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:44
typename GridView::ctype ctype
the coordinate type
Definition: geometricentityset.hh:75
@ dimensionworld
Definition: geometricentityset.hh:70
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper)
Definition: geometricentityset.hh:53
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:98
typename GridView::template Codim< codim >::Entity Entity
Definition: geometricentityset.hh:47
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:80
GridViewGeometricEntitySet(const GridView &gridView)
Definition: geometricentityset.hh:49
Entity entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:104
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:92
GridViewGeometricEntitySet(const GridView &gridView, const Mapper &mapper, std::shared_ptr< const EntityMap > entityMap)
Definition: geometricentityset.hh:59
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:86
An interface for a set of geometric entities.
Definition: geometricentityset.hh:121
decltype(auto) end() const
end iterator to enable range-based for iteration
Definition: geometricentityset.hh:218
typename Entity::Geometry::ctype ctype
the coordinate type
Definition: geometricentityset.hh:201
decltype(auto) begin() const
begin iterator to enable range-based for iteration
Definition: geometricentityset.hh:212
decltype(auto) size() const
the number of entities in this set
Definition: geometricentityset.hh:206
const Entity & entity(std::size_t index) const
get an entity from an index
Definition: geometricentityset.hh:231
@ dimensionworld
Definition: geometricentityset.hh:196
EntityWrapper Entity
Definition: geometricentityset.hh:158
std::size_t index(const Entity &e) const
get an entities index
Definition: geometricentityset.hh:225
GeometriesEntitySet(std::initializer_list< typename Entity::Geometry > &&geometries)
Constructor for initializer_list.
Definition: geometricentityset.hh:163
GeometriesEntitySet(const std::vector< typename Entity::Geometry > &geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:176
GeometriesEntitySet(std::vector< typename Entity::Geometry > &&geometries)
Constructor for a vector of geometries.
Definition: geometricentityset.hh:186