Commit e81a6bd8 authored by Kilian Weishaupt's avatar Kilian Weishaupt Committed by Timo Koch
Browse files

[common][geometricentityset] Add entity set for Dune geometries

parent 9550ab25
......@@ -21,18 +21,19 @@
* \note This can be used e.g. to contruct a bounding box volume hierarchy of a grid
* It defines the minimum requirement for such a set
*/
#ifndef DUMUX_GRIDVIEW_GEOMETRIC_ENTITY_SET_HH
#define DUMUX_GRIDVIEW_GEOMETRIC_ENTITY_SET_HH
#ifndef DUMUX_GEOMETRIC_ENTITY_SET_HH
#define DUMUX_GEOMETRIC_ENTITY_SET_HH
#include <memory>
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/geometry/multilineargeometry.hh>
#include <dumux/common/entitymap.hh>
namespace Dumux {
/*!
* \ingroup Geometry
* \brief An interface for a set of geometric entities
* \brief An interface for a set of geometric entities based on a GridView
* \note This can be used e.g. to contruct a bounding box volume hierarchy of a grid
* It defines the minimum requirement for such a set
*/
......@@ -108,6 +109,131 @@ private:
};
/*!
* \ingroup Geometry
* \brief An interface for a set of geometric entities
* \note This can be used e.g. to contruct a bounding box volume hierarchy of a grid
* It defines the minimum requirement for such a set
*/
template<class GeoType>
class GeometriesEntitySet
{
/*!
* \brief Wrapper to turn a geometry into a geometric entity
*/
class EntityWrapper
{
public:
using Geometry = GeoType;
/*!
* \brief Constructor
*/
EntityWrapper(const Geometry& geo, const std::size_t index) : geo_(geo), index_(index) {}
/*!
* \brief Constructor
*/
EntityWrapper(Geometry&& geo, const std::size_t index) : geo_(std::move(geo)), index_(index) {}
/*!
* \brief Returns the geometry
*/
const Geometry& geometry() const
{ return geo_; }
/*!
* \brief Returns the index of the geometry
*/
std::size_t index() const
{ return index_; }
private:
Geometry geo_;
std::size_t index_;
};
public:
using Entity = EntityWrapper;
/*!
* \brief Constructor for initializer_list
*/
GeometriesEntitySet(std::initializer_list<typename Entity::Geometry>&& geometries)
{
std::size_t index = 0;
// note: std::initializer_list::begin() returns const T*,
// thus no moving will be performed and only the copying ctor of
// EntityWrapper can be called
for (auto&& g : geometries)
entities_.emplace_back(g, index++);
}
/*!
* \brief Constructor for a vector of geometries
*/
GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries)
{
std::size_t index = 0;
for (auto&& g : geometries)
entities_.emplace_back(g, index++);
}
/*!
* \brief Constructor for a vector of geometries
*/
GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries)
{
std::size_t index = 0;
for (auto&& g : geometries)
entities_.emplace_back(std::move(g), index++);
}
/*!
* \brief The world dimension of the entity set
*/
enum { dimensionworld = Entity::Geometry::coorddimension };
/*!
* \brief the coordinate type
*/
using ctype = typename Entity::Geometry::ctype;
/*!
* \brief the number of entities in this set
*/
decltype(auto) size() const
{ return entities_.size(); }
/*!
* \brief begin iterator to enable range-based for iteration
*/
decltype(auto) begin() const
{ return entities_.begin(); }
/*!
* \brief end iterator to enable range-based for iteration
*/
decltype(auto) end() const
{ return entities_.end(); }
/*!
* \brief get an entities index
*/
template<class Entity>
std::size_t index(const Entity& e) const
{ return e.index(); }
/*!
* \brief get an entity from an index
*/
Entity entity(std::size_t index) const
{ return entities_[index]; }
private:
std::vector<Entity> entities_;
};
} // end namespace Dumux
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment