Newer
Older
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CURVED_SURFACE_GRID_ENTITY_HH
#define DUNE_CURVED_SURFACE_GRID_ENTITY_HH
#include <dune/common/std/optional.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/common/grid.hh>
namespace Dune
{
{
// Internal Forward Declarations
// -----------------------------
/** \class EntityBase
* \brief actual implementation of the entity
*
* \tparam codim codimension of the entity
* \tparam Grid CurvedSurfaceGrid, this entity belongs to
*/
class EntityBase;
/** \class Entity
* \brief DUNE-conform implementation of the entity
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
*
* This class merely changes the template parameters of the entity to make
* DUNE happy. The actual implementation of the entity can be found in
* EntityBase.
*
* \tparam codim codimension of the entity
* \tparam dim dimension of the Grid (redundant information)
* \tparam Grid CurvedSurfaceGrid, this entity belongs to
*/
template< int codim, int dim, class Grid >
class Entity;
// External Forward Declarations
// -----------------------------
template< class Grid >
class HierarchicIterator;
template< class Grid, class HostIntersectionIterator >
class IntersectionIterator;
// EntityBase (real)
// -----------------
/** \copydoc EntityBase
*
* This specialization implements the case, where the host grid provides
* the entity for this codimension, i.e., \em fake = \b false.
*
* \nosubgrouping
*/
template< int codim, class Grid >
using Traits = typename std::remove_const_t<Grid>::Traits;
public:
/** \name Attributes
* \{ */
//! codimensioon of the entity
static const int codimension = codim;
//! dimension of the grid
static const int dimension = Traits::dimension;
//! dimension of the entity
static const int mydimension = dimension - codimension;
//! dimension of the world
static const int dimensionworld = Traits::dimensionworld;
/** \} */
/** \name Types Required by DUNE
* \{ */
//! coordinate type of the grid
using Geometry = typename Traits::template Codim<codimension>::Geometry;
using HostGrid = typename Traits::HostGrid;
public:
/** \name Host Types
* \{ */
//! type of corresponding host entity
using HostEntity = typename HostGrid::template Codim<codimension>::Entity;
using EntitySeed = typename Traits::template Codim<codimension>::EntitySeed;
//! type of host elements, i.e., of host entities of codimension 0
using HostElement = typename HostGrid::template Codim<0>::Entity;
using GeometryImpl = typename Traits::template Codim<codimension>::GeometryImpl;
using HostGeometry = typename HostGrid::template Codim<codimension>::Geometry;
public:
/** \name Construction, Initialization and Destruction
* \{ */
// Construct the entity from an entity seed
EntityBase (const Grid& grid, const EntitySeed& seed)
: hostEntity_(grid.hostGrid().entity(seed.impl().hostEntitySeed()))
, grid_(&grid)
// construct the entity from a subentity of a host-entity
EntityBase (const Grid& grid, const HostElement& hostElement, int i)
: hostEntity_(hostElement.template subEntity<codim>(i))
, grid_(&grid)
// construct the entity from a host-entity
EntityBase (const Grid& grid, const HostEntity& hostEntity)
: hostEntity_(hostEntity)
, grid_(&grid)
// construct the entity from a host-entity
EntityBase (const Grid& grid, HostEntity&& hostEntity)
: hostEntity_(std::move(hostEntity))
, grid_(&grid)
//! compare two entities
bool equals (const EntityBase& other) const
{
return hostEntity_ == other.hostEntity_;
}
public:
/** \name Methods Shared by Entities of All Codimensions
* \{ */
//! obtain the name of the corresponding reference element
/**
* This type can be used to access the DUNE reference element.
*/
GeometryType type () const
{
return hostEntity().type();
}
int level () const
{
return hostEntity().level();
}
//! obtain the partition type of this entity
PartitionType partitionType () const
{
return hostEntity().partitionType();
}
//! obtain the geometry of this entity
/**
* Each DUNE entity encapsulates a geometry object, representing the map
* from the reference element to world coordinates. Wrapping the geometry
* is the main objective of the CurvedSurfaceGrid.
*
* The CurvedSurfaceGrid provides geometries by parametrization with local basis
* functions, using the CurvedGeometry.
// mapping from local to curved global coordinates
auto ff = [f=grid().coordFunction(),geo=hostEntity().geometry()](const auto& local) {
return f(geo.global(local));
};
if (grid_->useGeometryCaching()) {
auto const& idSet = grid_->hostGrid().localIdSet();
auto id = idSet.id(hostEntity());
auto& cache = std::get<codim>(grid_->geometryCache_);
auto [it,inserted] = cache.try_emplace(id, type(), ff);
geo_ = it->second;
else {
geo_ = GeometryImpl(type(), ff);
//! obtain number of sub-entities of the current entity
unsigned int subEntities (unsigned int cc) const
//! return EntitySeed of host grid entity
EntitySeed seed () const
return typename EntitySeed::Implementation(hostEntity().seed());
/** \name Methods Supporting the Grid Implementation
//! return the wrapped host-entity
const HostEntity& hostEntity () const
HostEntity hostEntity_ = {};
const Grid* grid_ = nullptr;
mutable Std::optional<GeometryImpl> geo_;
};
// Entity
// ------
template< int codim, int dim, class Grid >
class Entity
// import constructors from base class
using Super::Super;
};
// Entity for codimension 0
// ------------------------
template< int dim, class Grid >
class Entity<0, dim, Grid>
: public EntityBase<0, Grid>
using Traits = typename std::remove_const_t<Grid>::Traits;
using HostGrid = typename Traits::HostGrid;
public:
/** \name Types Required by DUNE
* \{ */
//! type of corresponding local geometry
using LocalGeometry = typename Traits::template Codim<0>::LocalGeometry;
//! facade type for entities
using EntityFacade = Dune::Entity<0, dim, Grid, Dune::CGeo::Entity>;
using HierarchicIterator = typename Traits::HierarchicIterator;
using LeafIntersectionIterator = typename Traits::LeafIntersectionIterator;
using LevelIntersectionIterator = typename Traits::LevelIntersectionIterator;
// import constructors from base class
using Super::Super;
typename Grid::template Codim<codim>::Entity subEntity (int i) const
using EntityImpl = typename Traits::template Codim<codim>::EntityImpl;
return EntityImpl(Super::grid(), Super::hostEntity(), i);
}
LevelIntersectionIterator ilevelbegin () const
{
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ilevelbegin());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ilevelend());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ileafbegin());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ileafend());
return Super::hostEntity().hasBoundaryIntersections();
return Entity(Super::grid(), Super::hostEntity().father());
return Super::hostEntity().geometryInFather();
HierarchicIterator hbegin (int maxLevel) const
using IteratorImpl = CGeo::HierarchicIterator<Grid>;
return IteratorImpl(Super::grid(), Super::hostEntity().hbegin(maxLevel));
HierarchicIterator hend (int maxLevel) const
using IteratorImpl = CGeo::HierarchicIterator<Grid>;
return IteratorImpl(Super::grid(), Super::hostEntity().hend(maxLevel));
#endif // DUNE_CURVED_SURFACE_GRID_ENTITY_HH