5#ifndef DUNE_GEOMETRY_TYPE_HH
6#define DUNE_GEOMETRY_TYPE_HH
18#include <dune/common/exceptions.hh>
19#include <dune/common/keywords.hh>
20#include <dune/common/typetraits.hh>
21#include <dune/common/unused.hh>
29 enum TopologyConstruction { pyramidConstruction = 0, prismConstruction = 1 };
42 inline static unsigned int numTopologies (
int dim )
noexcept
58 inline bool static isPyramid (
unsigned int topologyId,
int dim,
int codim = 0 ) noexcept
60 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
61 assert( (0 <= codim) && (codim < dim) );
62 return (((topologyId & ~1) & (1u << (dim-codim-1))) == 0);
76 inline static bool isPrism (
unsigned int topologyId,
int dim,
int codim = 0 ) noexcept
78 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
79 assert( (0 <= codim) && (codim < dim) );
80 return (( (topologyId | 1) & (1u << (dim-codim-1))) != 0);
90 inline static unsigned int baseTopologyId (
unsigned int topologyId,
int dim,
int codim = 1 ) noexcept
92 assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
93 assert( (0 <= codim) && (codim <= dim) );
94 return topologyId & ((1u << (dim-codim)) - 1);
102# pragma GCC diagnostic push
103# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
107# pragma GCC diagnostic pop
150 unsigned int topologyId_;
158 enum class IdType : std::uint64_t
202 constexpr operator Id()
const
206 std::uint64_t
id = dim_ | (std::uint64_t(none_) << 8) | (std::uint64_t(topologyId_) << 32);
207 return static_cast<Id
>(
id);
224 return static_cast<Id
>(*this);
235 : dim_(static_cast<std::uint64_t>(
id) & 0xFF)
236 , none_(static_cast<std::uint64_t>(
id) & 0x100)
237 , topologyId_(static_cast<std::uint64_t>(
id) >> 32)
245 : dim_(0), none_(true), topologyId_(0)
255 : dim_(
dim), none_(
isNone), topologyId_(topologyId)
264 : dim_(
dim), none_(false), topologyId_(topologyId)
277 template<
class TopologyType,
278 class = std::void_t<
decltype(TopologyType::dimension),
decltype(TopologyType::id)>>
280 : dim_(TopologyType::dimension), none_(false), topologyId_(TopologyType::
id)
282 DUNE_UNUSED_PARAMETER(t);
302 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0001;
307 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0011;
312 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0001;
317 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0011;
322 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0101;
327 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0111;
332 return ! none_ && (topologyId_ | 1) == 1;
337 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
342 return ! none_ && (((topologyId_ & ~1) & (1u << (dim_-1))) == 0);
350 return ! none_ && (((topologyId_ & ~1) & (1u << step)) == 0);
355 return ! none_ && (( (topologyId_ | 1) & (1u << (dim_-1))) != 0);
363 return ! none_ && (( (topologyId_ | 1) & (1u << step)) != 0);
372 constexpr unsigned int dim()
const {
377 constexpr unsigned int id()
const {
389 return ( ( none_ == other.none_ )
390 && ( ( none_ ==
true )
391 || ( ( dim_ == other.dim_ )
392 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
400 return ! ((*this)==other);
405 return ( ( none_ < other.none_ )
406 || ( !( other.none_ < none_ )
407 && ( ( dim_ < other.dim_ )
408 || ( (other.dim_ == dim_)
409 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
425 s <<
"(simplex, " << a.
dim() <<
")";
430 s <<
"(cube, " << a.
dim() <<
")";
445 s <<
"(none, " << a.
dim() <<
")";
448 s <<
"(other [" << a.
id() <<
"], " << a.
dim() <<
")";
458 namespace GeometryTypes {
475 return GeometryType(((dim>1) ? ((1 << dim) - 1) : 0),dim,
false);
499#ifndef __cpp_inline_variables
551#ifndef __cpp_inline_variables
561 inline constexpr GeometryType getBase(
const GeometryType& gt) {
562 return GeometryType(gt.id() & ((1 << (gt.dim()-1))-1), gt.dim()-1, gt.isNone());
570 struct IfGeometryType
572 static constexpr GeometryType geometry = geometryId;
573 template<
class... Args >
574 static auto apply ( GeometryType gt, Args &&... args )
576 GeometryType lowerGeometry(gt.id() >>1 , gt.dim()-1, gt.isNone());
585 template<
template< GeometryType::Id >
class Operation,
GeometryType::Id geometryId >
586 struct IfGeometryType< Operation, 0, geometryId>
588 template<
class... Args >
589 static auto apply ([[maybe_unused]] GeometryType gt, Args &&... args )
591 return Operation< geometryId >::apply( std::forward< Args >( args )... );
constexpr GeometryType line
GeometryType representing a line.
Definition type.hh:513
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition type.hh:473
constexpr GeometryType prism
GeometryType representing a 3D prism.
Definition type.hh:543
constexpr GeometryType triangle
GeometryType representing a triangle.
Definition type.hh:519
constexpr GeometryType quadrilateral
GeometryType representing a quadrilateral (a square).
Definition type.hh:525
constexpr GeometryType hexahedron
GeometryType representing a hexahedron.
Definition type.hh:549
constexpr GeometryType pyramid
GeometryType representing a 3D pyramid.
Definition type.hh:537
constexpr GeometryType tetrahedron
GeometryType representing a tetrahedron.
Definition type.hh:531
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition type.hh:482
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition type.hh:464
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition type.hh:507
Definition affinegeometry.hh:21
std::ostream & operator<<(std::ostream &s, const GeometryType &a)
Prints the type to an output stream.
Definition type.hh:421
constexpr GeometryType prismaticExtension(const GeometryType >)
Return GeometryType of a prismatic construction with gt as base
Definition type.hh:494
constexpr GeometryType conicalExtension(const GeometryType >)
Return GeometryType of a conical construction with gt as base
Definition type.hh:488
Unique label for each type of entities that can occur in DUNE grids.
Definition type.hh:126
constexpr GeometryType(unsigned int topologyId, unsigned int dim)
Constructor, using the topologyId (integer) and the dimension.
Definition type.hh:263
constexpr bool operator<(const GeometryType &other) const
less-than operation for use with maps
Definition type.hh:404
constexpr bool operator!=(const GeometryType &other) const
Check for inequality.
Definition type.hh:399
constexpr bool isPyramid() const
Return true if entity is a pyramid.
Definition type.hh:316
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition type.hh:311
constexpr bool isPrism() const
Return true if entity is a prism.
Definition type.hh:321
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition type.hh:291
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:388
constexpr Id toId() const
Create an Id representation of this GeometryType.
Definition type.hh:222
constexpr bool isConical(const int &step) const
Return true if entity was constructed with a conical product in the chosen step.
Definition type.hh:349
constexpr unsigned int dim() const
Return dimension of the type.
Definition type.hh:372
constexpr bool isPrismatic(const int &step) const
Return true if entity was constructed with a prismatic product in the chosen step.
Definition type.hh:362
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition type.hh:301
GeometryType(TopologyType t)
Constructor from static TopologyType class.
Definition type.hh:279
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:254
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition type.hh:132
@ cube
Cube element in any nonnegative dimension.
Definition type.hh:134
@ simplex
Simplicial element in any nonnegative dimension.
Definition type.hh:133
@ pyramid
Four sided pyramid in three dimensions.
Definition type.hh:135
@ extended
Other, more general topology, representable as topologyId.
Definition type.hh:137
@ none
Even more general topology, cannot be specified by a topologyId. Two GeometryTypes with 'none' type a...
Definition type.hh:138
@ prism
Prism element in three dimensions.
Definition type.hh:136
constexpr GeometryType(Id id)
Reconstruct a Geometry type from a GeometryType::Id.
Definition type.hh:234
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition type.hh:336
constexpr GeometryType()
Default constructor, not initializing anything.
Definition type.hh:244
constexpr bool isConical() const
Return true if entity was constructed with a conical product in the last step.
Definition type.hh:341
constexpr bool isLine() const
Return true if entity is a line segment.
Definition type.hh:296
constexpr bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition type.hh:306
constexpr bool isPrismatic() const
Return true if entity was constructed with a prismatic product in the last step.
Definition type.hh:354
constexpr unsigned int id() const
Return the topology id of the type.
Definition type.hh:377
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition type.hh:367
constexpr bool isHexahedron() const
Return true if entity is a hexahedron.
Definition type.hh:326
constexpr bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition type.hh:331
IdType Id
An integral id representing a GeometryType.
Definition type.hh:193