3#ifndef DUNE_GEOMETRY_TYPE_HH
4#define DUNE_GEOMETRY_TYPE_HH
24 enum TopologyConstruction { pyramidConstruction = 0, prismConstruction = 1 };
33 static const unsigned int dimension = 0;
34 static const unsigned int numCorners = 1;
36 static const unsigned int id = 0;
38 static std::string name () {
return "p"; }
42 template<
class BaseTopology >
45 static const unsigned int dimension = BaseTopology::dimension + 1;
46 static const unsigned int numCorners = 2 * BaseTopology::numCorners;
48 static const unsigned int id = BaseTopology::id | ((
unsigned int)prismConstruction << (dimension-1));
50 static std::string name () {
return BaseTopology::name() +
"l"; }
54 template<
class BaseTopology >
57 static const unsigned int dimension = BaseTopology::dimension + 1;
58 static const unsigned int numCorners = BaseTopology::numCorners + 1;
60 static const unsigned int id = BaseTopology::id | ((
unsigned int)pyramidConstruction << (dimension-1));
62 static std::string name () {
return BaseTopology::name() +
"o"; }
70 template<
class Topology >
72 :
public std::integral_constant< bool, (Topology::id >> 1) == 0 >
75 template<
class Topology >
77 :
public std::integral_constant< bool, (Topology::id | 1) == (1 << Topology::dimension) - 1 >
93 inline static unsigned int numTopologies ( int dim ) noexcept
109 inline bool static isPyramid ( unsigned int topologyId, int dim, int codim = 0 ) noexcept
111 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
112 assert( (0 <= codim) && (codim < dim) );
113 return (((topologyId & ~1) & (1u << (dim-codim-1))) == 0);
127 inline static bool isPrism ( unsigned int topologyId, int dim, int codim = 0 ) noexcept
129 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
130 assert( (0 <= codim) && (codim < dim) );
131 return (( (topologyId | 1) & (1u << (dim-codim-1))) != 0);
146 inline static bool isTopology ( TopologyConstruction construction, unsigned int topologyId, int dim, int codim = 0 ) noexcept
148 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
149 assert( (0 <= codim) && (codim <= dim) );
150 return (codim >= (dim-1)) || (((topologyId >> (dim-codim-1)) & 1) == (unsigned int)construction);
160 inline static unsigned int baseTopologyId ( unsigned int topologyId, int dim, int codim = 1 ) noexcept
162 assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
163 assert( (0 <= codim) && (codim <= dim) );
164 return topologyId & ((1u << (dim-codim)) - 1);
172 template< unsigned int dim >
173 struct SimplexTopology
175 typedef Pyramid< typename SimplexTopology< dim-1 >::type > type;
179 struct SimplexTopology< 0 >
189 template< unsigned int dim >
192 typedef Prism< typename CubeTopology< dim-1 >::type > type;
196 struct CubeTopology< 0 >
206 template< unsigned int dim >
207 struct PyramidTopology
209 typedef Pyramid< typename CubeTopology< dim-1 >::type > type;
217 template< unsigned int dim >
220 typedef Prism< typename SimplexTopology< dim-1 >::type > type;
229 template< template< class > class Operation, int dim, class Topology = Point >
232 template< class... Args >
233 static auto apply ( unsigned int topologyId, Args &&... args )
236 return IfTopology< Operation, dim-1, Prism< Topology > >::apply( topologyId >> 1, std::forward< Args >( args )... );
238 return IfTopology< Operation, dim-1, Pyramid< Topology > >::apply( topologyId >> 1, std::forward< Args >( args )... );
242 template< template< class > class Operation, class Topology >
243 struct IfTopology< Operation, 0, Topology >
245 template< class... Args >
246 static auto apply ( unsigned int topologyId, Args &&... args )
248 DUNE_UNUSED_PARAMETER( topologyId );
249 return Operation< Topology >::apply( std::forward< Args >( args )... );
291 unsigned int topologyId_;
294 unsigned char dim_ : 7;
302 : topologyId_(0), dim_(0), none_(true)
306 GeometryType(BasicType basicType, unsigned int dim)
307 : topologyId_(0), dim_(dim), none_((basicType == GeometryType::none) ? true : false)
313 case GeometryType::simplex :
316 case GeometryType::cube :
319 case GeometryType::pyramid :
323 DUNE_THROW( RangeError,
324 "Invalid basic geometry type: no pyramids for dimension " << dim << "." );
326 case GeometryType::prism :
330 DUNE_THROW( RangeError,
331 "Invalid basic geometry type: no prisms for dimension " << dim << "." );
333 case GeometryType::none :
336 DUNE_THROW( RangeError,
337 "Invalid basic geometry type: " << basicType << " for dimension " << dim << "." );
346 GeometryType(unsigned int topologyId, unsigned int dim)
347 : topologyId_(topologyId), dim_(dim), none_(false)
360 template<class TopologyType,
361 class = Dune::void_t<decltype(TopologyType::dimension), decltype(TopologyType::id)>>
362 explicit GeometryType(TopologyType t)
363 : topologyId_(TopologyType::id), dim_(TopologyType::dimension), none_(false)
365 DUNE_UNUSED_PARAMETER(t);
369 explicit GeometryType(unsigned int dim)
370 : topologyId_(0), dim_(dim), none_(false)
379 explicit GeometryType(int dim)
380 : topologyId_(0), dim_(dim), none_(false)
403 void makeTriangle() {
408 void makeQuadrilateral() {
413 void makeTetrahedron() {
432 void makeHexahedron() {
437 void makeSimplex(unsigned int dim) {
444 void makeCube(unsigned int dim) {
447 topologyId_ = ((dim>1) ? ((1 << dim) - 1) : 0);
451 void makeNone(unsigned int dim) {
461 void makeFromVertices(unsigned int dim, unsigned int vertices)
480 DUNE_THROW(NotImplemented, "2d elements with " << vertices << " corners are not supported!");
497 DUNE_THROW(NotImplemented, "3d elements with " << vertices << " corners are not supported!");
500 DUNE_THROW(NotImplemented, "makeFromVertices only implemented up to 3d");
510 bool isVertex() const {
515 bool isLine() const {
520 bool isTriangle() const {
521 return ! none_ && dim_==2 && (topologyId_ | 1) == b0001;
525 bool isQuadrilateral() const {
526 return ! none_ && dim_==2 && (topologyId_ | 1) == b0011;
530 bool isTetrahedron() const {
531 return ! none_ && dim_==3 && (topologyId_ | 1) == b0001;
535 bool isPyramid() const {
536 return ! none_ && dim_==3 && (topologyId_ | 1) == b0011;
540 bool isPrism() const {
541 return ! none_ && dim_==3 && (topologyId_ | 1) == b0101;
545 bool isHexahedron() const {
546 return ! none_ && dim_==3 && (topologyId_ | 1) == b0111;
550 bool isSimplex() const {
551 return ! none_ && (topologyId_ | 1) == 1;
555 bool isCube() const {
556 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
560 bool isNone() const {
565 unsigned int dim() const {
570 unsigned int id() const {
579 bool operator==(const GeometryType& other) const {
580 return ( ( none_ == other.none_ )
581 && ( ( none_ == true )
582 || ( ( dim_ == other.dim_ )
583 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
590 bool operator!=(const GeometryType& other) const {
591 return ! ((*this)==other);
595 bool operator < (const GeometryType& other) const {
596 return ( ( none_ < other.none_ )
597 || ( !( other.none_ < none_ )
598 && ( ( dim_ < other.dim_ )
599 || ( (other.dim_ == dim_)
600 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
609 inline std::ostream& operator<< (std::ostream& s, const GeometryType& a)
613 s << "(simplex, " << a.dim() << ")";
618 s << "(cube, " << a.dim() << ")";
633 s << "(none, " << a.dim() << ")";
636 s << "(other [" << a.id() << "], " << a.dim() << ")";
641 inline std::ostream& operator<< (std::ostream& s, GeometryType::BasicType type)
644 case GeometryType::simplex :
647 case GeometryType::cube :
650 case GeometryType::pyramid :
653 case GeometryType::prism :
656 case GeometryType::extended :
658 case GeometryType::none :
662 DUNE_THROW(Exception, "invalid GeometryType::BasicType");
A few common exception classes.
Dune namespace.
Definition: alignment.hh:11
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.