5#ifndef DUNE_GEOMETRY_TYPE_HH
6#define DUNE_GEOMETRY_TYPE_HH
18#include <dune/common/exceptions.hh>
19#include <dune/common/typetraits.hh>
20#include <dune/common/unused.hh>
28 enum TopologyConstruction { pyramidConstruction = 0, prismConstruction = 1 };
41 inline static unsigned int numTopologies (
int dim )
noexcept
57 inline bool static isPyramid (
unsigned int topologyId,
int dim,
int codim = 0 ) noexcept
59 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
60 assert( (0 <= codim) && (codim < dim) );
61 return (((topologyId & ~1) & (1u << (dim-codim-1))) == 0);
75 inline static bool isPrism (
unsigned int topologyId,
int dim,
int codim = 0 ) noexcept
77 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
78 assert( (0 <= codim) && (codim < dim) );
79 return (( (topologyId | 1) & (1u << (dim-codim-1))) != 0);
89 inline static unsigned int baseTopologyId (
unsigned int topologyId,
int dim,
int codim = 1 ) noexcept
91 assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
92 assert( (0 <= codim) && (codim <= dim) );
93 return topologyId & ((1u << (dim-codim)) - 1);
138 unsigned int topologyId_;
146 enum class IdType : std::uint64_t
190 constexpr operator Id()
const
194 std::uint64_t
id = dim_ | (std::uint64_t(none_) << 8) | (std::uint64_t(topologyId_) << 32);
195 return static_cast<Id
>(
id);
212 return static_cast<Id
>(*this);
223 : dim_(static_cast<
std::uint64_t>(
id) & 0xFF)
224 , none_(static_cast<
std::uint64_t>(
id) & 0x100)
225 , topologyId_(static_cast<
std::uint64_t>(
id) >> 32)
233 : dim_(0), none_(true), topologyId_(0)
243 : dim_(
dim), none_(
isNone), topologyId_(topologyId)
252 : dim_(
dim), none_(false), topologyId_(topologyId)
265 template<
class TopologyType,
266 class = std::void_t<
decltype(TopologyType::dimension),
decltype(TopologyType::id)>>
268 : dim_(TopologyType::dimension), none_(false), topologyId_(TopologyType::
id)
270 DUNE_UNUSED_PARAMETER(t);
290 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0001;
295 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0011;
300 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0001;
305 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0011;
310 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0101;
315 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0111;
320 return ! none_ && (topologyId_ | 1) == 1;
325 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
330 return ! none_ && (((topologyId_ & ~1) & (1u << (dim_-1))) == 0);
338 return ! none_ && (((topologyId_ & ~1) & (1u << step)) == 0);
343 return ! none_ && (( (topologyId_ | 1) & (1u << (dim_-1))) != 0);
351 return ! none_ && (( (topologyId_ | 1) & (1u << step)) != 0);
360 constexpr unsigned int dim()
const {
365 constexpr unsigned int id()
const {
378 return ( ( none_ == other.none_ )
379 && ( ( none_ ==
true )
380 || ( ( dim_ == other.dim_ )
381 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
389 return ! ((*this)==other);
394 return ( ( none_ < other.none_ )
395 || ( !( other.none_ < none_ )
396 && ( ( dim_ < other.dim_ )
397 || ( (other.dim_ == dim_)
398 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
414 s <<
"(simplex, " << a.
dim() <<
")";
419 s <<
"(cube, " << a.
dim() <<
")";
434 s <<
"(none, " << a.
dim() <<
")";
437 s <<
"(other [" << a.
id() <<
"], " << a.
dim() <<
")";
447 namespace GeometryTypes {
464 return GeometryType(((dim>1) ? ((1 << dim) - 1) : 0),dim,
false);
550 template<
template< GeometryType::Id >
class Operation,
int dim,
GeometryType::Id geometryId = GeometryTypes::vertex >
551 struct IfGeometryType
553 static constexpr GeometryType geometry = geometryId;
554 template<
class... Args >
555 static auto apply ( GeometryType gt, Args &&... args )
557 GeometryType lowerGeometry(gt.id() >>1 , gt.dim()-1, gt.isNone());
560 return IfGeometryType< Operation, dim-1, GeometryTypes::prismaticExtension(geometry).toId() >::apply( lowerGeometry, std::forward< Args >( args )... );
562 return IfGeometryType< Operation, dim-1, GeometryTypes::conicalExtension(geometry).toId() >::apply( lowerGeometry, std::forward< Args >( args )... );
566 template<
template< GeometryType::Id >
class Operation,
GeometryType::Id geometryId >
567 struct IfGeometryType< Operation, 0, geometryId>
569 template<
class... Args >
570 static auto apply ([[maybe_unused]] GeometryType gt, Args &&... args )
572 return Operation< geometryId >::apply( std::forward< Args >( args )... );
Definition affinegeometry.hh:21
std::ostream & operator<<(std::ostream &s, const GeometryType &a)
Prints the type to an output stream.
Definition type.hh:410
Unique label for each type of entities that can occur in DUNE grids.
Definition type.hh:114
constexpr GeometryType(unsigned int topologyId, unsigned int dim)
Constructor, using the topologyId (integer) and the dimension.
Definition type.hh:251
constexpr bool operator<(const GeometryType &other) const
less-than operation for use with maps
Definition type.hh:393
constexpr bool operator!=(const GeometryType &other) const
Check for inequality.
Definition type.hh:388
constexpr bool isPyramid() const
Return true if entity is a pyramid.
Definition type.hh:304
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition type.hh:299
constexpr bool isPrism() const
Return true if entity is a prism.
Definition type.hh:309
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition type.hh:279
constexpr bool operator==(const GeometryType &other) const
Check for equality. This method knows that in dimension 0 and 1 all BasicTypes are equal.
Definition type.hh:377
constexpr Id toId() const
Create an Id representation of this GeometryType.
Definition type.hh:210
constexpr bool isConical(const int &step) const
Return true if entity was constructed with a conical product in the chosen step.
Definition type.hh:337
constexpr unsigned int dim() const
Return dimension of the type.
Definition type.hh:360
constexpr bool isPrismatic(const int &step) const
Return true if entity was constructed with a prismatic product in the chosen step.
Definition type.hh:350
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition type.hh:289
GeometryType(TopologyType t)
Constructor from static TopologyType class.
Definition type.hh:267
constexpr GeometryType(unsigned int topologyId, unsigned int dim, bool isNone)
Constructor, using the topologyId (integer), the dimension and a flag for type none.
Definition type.hh:242
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition type.hh:120
@ cube
Cube element in any nonnegative dimension.
Definition type.hh:122
@ simplex
Simplicial element in any nonnegative dimension.
Definition type.hh:121
@ pyramid
Four sided pyramid in three dimensions.
Definition type.hh:123
@ extended
Other, more general topology, representable as topologyId.
Definition type.hh:125
@ none
Even more general topology, cannot be specified by a topologyId. Two GeometryTypes with 'none' type a...
Definition type.hh:126
@ prism
Prism element in three dimensions.
Definition type.hh:124
constexpr GeometryType(Id id)
Reconstruct a Geometry type from a GeometryType::Id.
Definition type.hh:222
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition type.hh:324
constexpr GeometryType()
Default constructor, not initializing anything.
Definition type.hh:232
constexpr bool isConical() const
Return true if entity was constructed with a conical product in the last step.
Definition type.hh:329
constexpr bool isLine() const
Return true if entity is a line segment.
Definition type.hh:284
constexpr bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition type.hh:294
constexpr bool isPrismatic() const
Return true if entity was constructed with a prismatic product in the last step.
Definition type.hh:342
constexpr unsigned int id() const
Return the topology id of the type.
Definition type.hh:365
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition type.hh:355
constexpr bool isHexahedron() const
Return true if entity is a hexahedron.
Definition type.hh:314
constexpr bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition type.hh:319
IdType Id
An integral id representing a GeometryType.
Definition type.hh:181