3 #ifndef DUNE_GEOMETRY_TYPE_HH
4 #define DUNE_GEOMETRY_TYPE_HH
13 #include <type_traits>
15 #include <dune/common/exceptions.hh>
16 #include <dune/common/keywords.hh>
17 #include <dune/common/typetraits.hh>
18 #include <dune/common/unused.hh>
26 enum TopologyConstruction { pyramidConstruction = 0, prismConstruction = 1 };
39 inline static unsigned int numTopologies (
int dim ) noexcept
55 inline bool static isPyramid (
unsigned int topologyId,
int dim,
int codim = 0 ) noexcept
57 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
58 assert( (0 <= codim) && (codim < dim) );
59 return (((topologyId & ~1) & (1u << (dim-codim-1))) == 0);
73 inline static bool isPrism (
unsigned int topologyId,
int dim,
int codim = 0 ) noexcept
75 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
76 assert( (0 <= codim) && (codim < dim) );
77 return (( (topologyId | 1) & (1u << (dim-codim-1))) != 0);
87 inline static unsigned int baseTopologyId (
unsigned int topologyId,
int dim,
int codim = 1 ) noexcept
89 assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
90 assert( (0 <= codim) && (codim <= dim) );
91 return topologyId & ((1u << (dim-codim)) - 1);
99 # pragma GCC diagnostic push
100 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
104 # pragma GCC diagnostic pop
147 unsigned int topologyId_;
155 enum class IdType : std::uint64_t
199 constexpr
operator Id()
const
203 std::uint64_t
id = dim_ | (std::uint64_t(none_) << 8) | (std::uint64_t(topologyId_) << 32);
204 return static_cast<Id
>(
id);
221 return static_cast<Id
>(*this);
232 : dim_(static_cast<std::uint64_t>(
id) & 0xFF)
233 , none_(static_cast<std::uint64_t>(
id) & 0x100)
234 , topologyId_(static_cast<std::uint64_t>(
id) >> 32)
242 : dim_(0), none_(true), topologyId_(0)
252 : dim_(
dim), none_(
isNone), topologyId_(topologyId)
261 : dim_(
dim), none_(false), topologyId_(topologyId)
274 template<
class TopologyType,
275 class = std::void_t<decltype(TopologyType::dimension), decltype(TopologyType::id)>>
277 : dim_(TopologyType::dimension), none_(false), topologyId_(TopologyType::
id)
279 DUNE_UNUSED_PARAMETER(t);
299 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0001;
304 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0011;
309 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0001;
314 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0011;
319 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0101;
324 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0111;
329 return ! none_ && (topologyId_ | 1) == 1;
334 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
339 return ! none_ && (((topologyId_ & ~1) & (1u << (dim_-1))) == 0);
347 return ! none_ && (((topologyId_ & ~1) & (1u << step)) == 0);
352 return ! none_ && (( (topologyId_ | 1) & (1u << (dim_-1))) != 0);
360 return ! none_ && (( (topologyId_ | 1) & (1u << step)) != 0);
369 constexpr
unsigned int dim()
const {
374 constexpr
unsigned int id()
const {
386 return ( ( none_ == other.none_ )
387 && ( ( none_ ==
true )
388 || ( ( dim_ == other.dim_ )
389 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
397 return ! ((*this)==other);
402 return ( ( none_ < other.none_ )
403 || ( !( other.none_ < none_ )
404 && ( ( dim_ < other.dim_ )
405 || ( (other.dim_ == dim_)
406 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
422 s <<
"(simplex, " << a.
dim() <<
")";
427 s <<
"(cube, " << a.
dim() <<
")";
442 s <<
"(none, " << a.
dim() <<
")";
445 s <<
"(other [" << a.
id() <<
"], " << a.
dim() <<
")";
455 namespace GeometryTypes {
472 return GeometryType(((dim>1) ? ((1 << dim) - 1) : 0),dim,
false);
496 #ifndef __cpp_inline_variables
548 #ifndef __cpp_inline_variables
558 inline constexpr GeometryType getBase(
const GeometryType& gt) {
559 return GeometryType(gt.id() & ((1 << (gt.dim()-1))-1), gt.dim()-1, gt.isNone());
567 struct IfGeometryType
569 static constexpr GeometryType geometry = geometryId;
570 template<
class... Args >
571 static auto apply ( GeometryType gt, Args &&... args )
573 GeometryType lowerGeometry(gt.id() >>1 , gt.dim()-1, gt.isNone());
582 template<
template< GeometryType::Id >
class Operation,
GeometryType::Id geometryId >
583 struct IfGeometryType< Operation, 0, geometryId>
585 template<
class... Args >
586 static auto apply ([[maybe_unused]] GeometryType gt, Args &&... args )
588 return Operation< geometryId >::apply( std::forward< Args >( args )... );
constexpr GeometryType line
GeometryType representing a line.
Definition: type.hh:510
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:470
constexpr GeometryType prism
GeometryType representing a 3D prism.
Definition: type.hh:540
constexpr GeometryType triangle
GeometryType representing a triangle.
Definition: type.hh:516
constexpr GeometryType quadrilateral
GeometryType representing a quadrilateral (a square).
Definition: type.hh:522
constexpr GeometryType hexahedron
GeometryType representing a hexahedron.
Definition: type.hh:546
constexpr GeometryType pyramid
GeometryType representing a 3D pyramid.
Definition: type.hh:534
constexpr GeometryType tetrahedron
GeometryType representing a tetrahedron.
Definition: type.hh:528
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:479
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:461
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:504
Definition: affinegeometry.hh:19
std::ostream & operator<<(std::ostream &s, const GeometryType &a)
Prints the type to an output stream.
Definition: type.hh:418
constexpr GeometryType prismaticExtension(const GeometryType >)
Return GeometryType of a prismatic construction with gt as base
Definition: type.hh:491
constexpr GeometryType conicalExtension(const GeometryType >)
Return GeometryType of a conical construction with gt as base
Definition: type.hh:485
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
constexpr GeometryType(unsigned int topologyId, unsigned int dim)
Constructor, using the topologyId (integer) and the dimension.
Definition: type.hh:260
constexpr bool operator<(const GeometryType &other) const
less-than operation for use with maps
Definition: type.hh:401
constexpr bool operator!=(const GeometryType &other) const
Check for inequality.
Definition: type.hh:396
constexpr bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:313
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:308
constexpr bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:318
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:288
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:385
constexpr Id toId() const
Create an Id representation of this GeometryType.
Definition: type.hh:219
constexpr bool isConical(const int &step) const
Return true if entity was constructed with a conical product in the chosen step.
Definition: type.hh:346
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:369
constexpr bool isPrismatic(const int &step) const
Return true if entity was constructed with a prismatic product in the chosen step.
Definition: type.hh:359
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:298
GeometryType(TopologyType t)
Constructor from static TopologyType class.
Definition: type.hh:276
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:251
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:129
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:131
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:130
@ pyramid
Four sided pyramid in three dimensions.
Definition: type.hh:132
@ extended
Other, more general topology, representable as topologyId.
Definition: type.hh:134
@ none
Even more general topology, cannot be specified by a topologyId. Two GeometryTypes with 'none' type a...
Definition: type.hh:135
@ prism
Prism element in three dimensions.
Definition: type.hh:133
constexpr GeometryType(Id id)
Reconstruct a Geometry type from a GeometryType::Id.
Definition: type.hh:231
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:333
constexpr GeometryType()
Default constructor, not initializing anything.
Definition: type.hh:241
constexpr bool isConical() const
Return true if entity was constructed with a conical product in the last step.
Definition: type.hh:338
constexpr bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:293
constexpr bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:303
constexpr bool isPrismatic() const
Return true if entity was constructed with a prismatic product in the last step.
Definition: type.hh:351
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:374
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:364
constexpr bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:323
constexpr bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition: type.hh:328
IdType Id
An integral id representing a GeometryType.
Definition: type.hh:190