5#ifndef DUNE_GEOMETRY_TYPE_HH
6#define DUNE_GEOMETRY_TYPE_HH
17#include <dune/common/exceptions.hh>
18#include <dune/common/keywords.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);
101# pragma GCC diagnostic push
102# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
106# pragma GCC diagnostic pop
149 unsigned int topologyId_;
157 enum class IdType : std::uint64_t
201 constexpr operator Id()
const
205 std::uint64_t
id = dim_ | (std::uint64_t(none_) << 8) | (std::uint64_t(topologyId_) << 32);
206 return static_cast<Id
>(
id);
223 return static_cast<Id
>(*this);
234 : dim_(static_cast<std::uint64_t>(
id) & 0xFF)
235 , none_(static_cast<std::uint64_t>(
id) & 0x100)
236 , topologyId_(static_cast<std::uint64_t>(
id) >> 32)
244 : dim_(0), none_(true), topologyId_(0)
254 : dim_(
dim), none_(
isNone), topologyId_(topologyId)
263 : dim_(
dim), none_(false), topologyId_(topologyId)
276 template<
class TopologyType,
277 class = std::void_t<
decltype(TopologyType::dimension),
decltype(TopologyType::id)>>
279 : dim_(TopologyType::dimension), none_(false), topologyId_(TopologyType::
id)
281 DUNE_UNUSED_PARAMETER(t);
301 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0001;
306 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0011;
311 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0001;
316 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0011;
321 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0101;
326 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0111;
331 return ! none_ && (topologyId_ | 1) == 1;
336 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
341 return ! none_ && (((topologyId_ & ~1) & (1u << (dim_-1))) == 0);
349 return ! none_ && (((topologyId_ & ~1) & (1u << step)) == 0);
354 return ! none_ && (( (topologyId_ | 1) & (1u << (dim_-1))) != 0);
362 return ! none_ && (( (topologyId_ | 1) & (1u << step)) != 0);
371 constexpr unsigned int dim()
const {
376 constexpr unsigned int id()
const {
388 return ( ( none_ == other.none_ )
389 && ( ( none_ ==
true )
390 || ( ( dim_ == other.dim_ )
391 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
399 return ! ((*this)==other);
404 return ( ( none_ < other.none_ )
405 || ( !( other.none_ < none_ )
406 && ( ( dim_ < other.dim_ )
407 || ( (other.dim_ == dim_)
408 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
424 s <<
"(simplex, " << a.
dim() <<
")";
429 s <<
"(cube, " << a.
dim() <<
")";
444 s <<
"(none, " << a.
dim() <<
")";
447 s <<
"(other [" << a.
id() <<
"], " << a.
dim() <<
")";
457 namespace GeometryTypes {
474 return GeometryType(((dim>1) ? ((1 << dim) - 1) : 0),dim,
false);
498#ifndef __cpp_inline_variables
550#ifndef __cpp_inline_variables
560 inline constexpr GeometryType getBase(
const GeometryType& gt) {
561 return GeometryType(gt.id() & ((1 << (gt.dim()-1))-1), gt.dim()-1, gt.isNone());
569 struct IfGeometryType
571 static constexpr GeometryType geometry = geometryId;
572 template<
class... Args >
573 static auto apply ( GeometryType gt, Args &&... args )
575 GeometryType lowerGeometry(gt.id() >>1 , gt.dim()-1, gt.isNone());
584 template<
template< GeometryType::Id >
class Operation,
GeometryType::Id geometryId >
585 struct IfGeometryType< Operation, 0, geometryId>
587 template<
class... Args >
588 static auto apply ([[maybe_unused]] GeometryType gt, Args &&... args )
590 return Operation< geometryId >::apply( std::forward< Args >( args )... );
constexpr GeometryType line
GeometryType representing a line.
Definition: type.hh:512
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
constexpr GeometryType prism
GeometryType representing a 3D prism.
Definition: type.hh:542
constexpr GeometryType triangle
GeometryType representing a triangle.
Definition: type.hh:518
constexpr GeometryType quadrilateral
GeometryType representing a quadrilateral (a square).
Definition: type.hh:524
constexpr GeometryType hexahedron
GeometryType representing a hexahedron.
Definition: type.hh:548
constexpr GeometryType pyramid
GeometryType representing a 3D pyramid.
Definition: type.hh:536
constexpr GeometryType tetrahedron
GeometryType representing a tetrahedron.
Definition: type.hh:530
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:481
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:463
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:506
Definition: affinegeometry.hh:21
std::ostream & operator<<(std::ostream &s, const GeometryType &a)
Prints the type to an output stream.
Definition: type.hh:420
constexpr GeometryType prismaticExtension(const GeometryType >)
Return GeometryType of a prismatic construction with gt as base
Definition: type.hh:493
constexpr GeometryType conicalExtension(const GeometryType >)
Return GeometryType of a conical construction with gt as base
Definition: type.hh:487
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr GeometryType(unsigned int topologyId, unsigned int dim)
Constructor, using the topologyId (integer) and the dimension.
Definition: type.hh:262
constexpr bool operator<(const GeometryType &other) const
less-than operation for use with maps
Definition: type.hh:403
constexpr bool operator!=(const GeometryType &other) const
Check for inequality.
Definition: type.hh:398
constexpr bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:315
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:310
constexpr bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:320
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:290
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:387
constexpr Id toId() const
Create an Id representation of this GeometryType.
Definition: type.hh:221
constexpr bool isConical(const int &step) const
Return true if entity was constructed with a conical product in the chosen step.
Definition: type.hh:348
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:371
constexpr bool isPrismatic(const int &step) const
Return true if entity was constructed with a prismatic product in the chosen step.
Definition: type.hh:361
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:300
GeometryType(TopologyType t)
Constructor from static TopologyType class.
Definition: type.hh:278
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:253
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:131
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:133
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:132
@ pyramid
Four sided pyramid in three dimensions.
Definition: type.hh:134
@ extended
Other, more general topology, representable as topologyId.
Definition: type.hh:136
@ none
Even more general topology, cannot be specified by a topologyId. Two GeometryTypes with 'none' type a...
Definition: type.hh:137
@ prism
Prism element in three dimensions.
Definition: type.hh:135
constexpr GeometryType(Id id)
Reconstruct a Geometry type from a GeometryType::Id.
Definition: type.hh:233
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:335
constexpr GeometryType()
Default constructor, not initializing anything.
Definition: type.hh:243
constexpr bool isConical() const
Return true if entity was constructed with a conical product in the last step.
Definition: type.hh:340
constexpr bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:295
constexpr bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:305
constexpr bool isPrismatic() const
Return true if entity was constructed with a prismatic product in the last step.
Definition: type.hh:353
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:376
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:366
constexpr bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:325
constexpr bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition: type.hh:330
IdType Id
An integral id representing a GeometryType.
Definition: type.hh:192