3 #ifndef DUNE_GEOMETRY_TYPE_HH 4 #define DUNE_GEOMETRY_TYPE_HH 14 #include <dune/common/deprecated.hh> 15 #include <dune/common/exceptions.hh> 16 #include <dune/common/keywords.hh> 17 #include <dune/common/typetraits.hh> 18 #include <dune/common/unused.hh> 30 enum TopologyConstruction { pyramidConstruction = 0, prismConstruction = 1 };
39 static const unsigned int dimension = 0;
40 static const unsigned int numCorners = 1;
42 static const unsigned int id = 0;
44 static std::string name () {
return "p"; }
48 template<
class BaseTopology >
51 static const unsigned int dimension = BaseTopology::dimension + 1;
52 static const unsigned int numCorners = 2 * BaseTopology::numCorners;
54 static const unsigned int id = BaseTopology::id | ((
unsigned int)prismConstruction << (dimension-1));
56 static std::string name () {
return BaseTopology::name() +
"l"; }
60 template<
class BaseTopology >
63 static const unsigned int dimension = BaseTopology::dimension + 1;
64 static const unsigned int numCorners = BaseTopology::numCorners + 1;
66 static const unsigned int id = BaseTopology::id | ((
unsigned int)pyramidConstruction << (dimension-1));
68 static std::string name () {
return BaseTopology::name() +
"o"; }
76 template<
class Topology >
78 :
public std::integral_constant< bool, (Topology::id >> 1) == 0 >
81 template<
class Topology >
83 :
public std::integral_constant< bool, (Topology::id | 1) == (1 << Topology::dimension) - 1 >
99 inline static unsigned int numTopologies ( int dim ) noexcept
115 inline bool static isPyramid ( unsigned int topologyId, int dim, int codim = 0 ) noexcept
117 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
118 assert( (0 <= codim) && (codim < dim) );
119 return (((topologyId & ~1) & (1u << (dim-codim-1))) == 0);
133 inline static bool isPrism ( unsigned int topologyId, int dim, int codim = 0 ) noexcept
135 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
136 assert( (0 <= codim) && (codim < dim) );
137 return (( (topologyId | 1) & (1u << (dim-codim-1))) != 0);
152 inline static bool isTopology ( TopologyConstruction construction, unsigned int topologyId, int dim, int codim = 0 ) noexcept
154 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
155 assert( (0 <= codim) && (codim <= dim) );
156 return (codim >= (dim-1)) || (((topologyId >> (dim-codim-1)) & 1) == (unsigned int)construction);
166 inline static unsigned int baseTopologyId ( unsigned int topologyId, int dim, int codim = 1 ) noexcept
168 assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
169 assert( (0 <= codim) && (codim <= dim) );
170 return topologyId & ((1u << (dim-codim)) - 1);
178 template< unsigned int dim >
179 struct SimplexTopology
181 typedef Pyramid< typename SimplexTopology< dim-1 >::type > type;
185 struct SimplexTopology< 0 >
195 template< unsigned int dim >
198 typedef Prism< typename CubeTopology< dim-1 >::type > type;
202 struct CubeTopology< 0 >
212 template< unsigned int dim >
213 struct PyramidTopology
215 typedef Pyramid< typename CubeTopology< dim-1 >::type > type;
223 template< unsigned int dim >
226 typedef Prism< typename SimplexTopology< dim-1 >::type > type;
235 template< template< class > class Operation, int dim, class Topology = Point >
238 template< class... Args >
239 static auto apply ( unsigned int topologyId, Args &&... args )
242 return IfTopology< Operation, dim-1, Prism< Topology > >::apply( topologyId >> 1, std::forward< Args >( args )... );
244 return IfTopology< Operation, dim-1, Pyramid< Topology > >::apply( topologyId >> 1, std::forward< Args >( args )... );
248 template< template< class > class Operation, class Topology >
249 struct IfTopology< Operation, 0, Topology >
251 template< class... Args >
252 static auto apply ( unsigned int topologyId, Args &&... args )
254 DUNE_UNUSED_PARAMETER( topologyId );
255 return Operation< Topology >::apply( std::forward< Args >( args )... );
295 unsigned int topologyId_;
298 unsigned char dim_ : 7;
309 constexpr GeometryType ()
310 : topologyId_(0), dim_(0), none_(true)
313 #pragma GCC diagnostic push
314 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
316 GeometryType(BasicType basicType, unsigned int dim)
317 DUNE_DEPRECATED_MSG("The GeometryType constructor taking BasicType is deprecated and will be removed after DUNE 2.6")
318 : topologyId_(0), dim_(dim), none_((basicType == GeometryType::none) ? true : false)
324 case GeometryType::simplex :
327 case GeometryType::cube :
328 topologyId_ = ((1 << dim) - 1);
330 case GeometryType::pyramid :
332 topologyId_ = 0b0011;
334 DUNE_THROW( RangeError,
335 "Invalid basic geometry type: no pyramids for dimension " << dim << "." );
337 case GeometryType::prism :
339 topologyId_ = 0b0101;
341 DUNE_THROW( RangeError,
342 "Invalid basic geometry type: no prisms for dimension " << dim << "." );
344 case GeometryType::none :
347 DUNE_THROW( RangeError,
348 "Invalid basic geometry type: " << basicType << " for dimension " << dim << "." );
351 #pragma GCC diagnostic pop
359 constexpr GeometryType(unsigned int topologyId, unsigned int dim, bool none)
360 : topologyId_(topologyId), dim_(dim), none_(none)
368 constexpr GeometryType(unsigned int topologyId, unsigned int dim)
369 : topologyId_(topologyId), dim_(dim), none_(false)
382 template<class TopologyType,
383 class = Dune::void_t<decltype(TopologyType::dimension), decltype(TopologyType::id)>>
384 explicit GeometryType(TopologyType t)
385 : topologyId_(TopologyType::id), dim_(TopologyType::dimension), none_(false)
387 DUNE_UNUSED_PARAMETER(t);
391 explicit GeometryType(unsigned int dim)
392 : topologyId_(0), dim_(dim), none_(false)
401 explicit GeometryType(int dim)
402 : topologyId_(0), dim_(dim), none_(false)
414 DUNE_DEPRECATED_MSG("makeVertex() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::vertex instead")
422 DUNE_DEPRECATED_MSG("makeLine() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::line instead")
430 DUNE_DEPRECATED_MSG("makeTriangle() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::triangle instead")
431 void makeTriangle() {
438 DUNE_DEPRECATED_MSG("makeQuadrilateral() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::quadrilateral instead")
439 void makeQuadrilateral() {
442 topologyId_ = 0b0011;
446 DUNE_DEPRECATED_MSG("makeTetrahedron() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::tetrahedron instead")
447 void makeTetrahedron() {
454 DUNE_DEPRECATED_MSG("makePyramid() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::pyramid instead")
458 topologyId_ = 0b0011;
462 DUNE_DEPRECATED_MSG("makePrism() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::prism instead")
466 topologyId_ = 0b0101;
470 DUNE_DEPRECATED_MSG("makeHexahedron() is deprecated in DUNE 2.6, please use Dune::GeometryTypes::hexahedron instead")
471 void makeHexahedron() {
474 topologyId_ = 0b0111;
478 DUNE_DEPRECATED_MSG("makeSimplex(dim) is deprecated in DUNE 2.6, please use Dune::GeometryTypes::simplex(dim) instead")
479 void makeSimplex(unsigned int dim) {
486 DUNE_DEPRECATED_MSG("makeCube(dim) is deprecated in DUNE 2.6, please use Dune::GeometryTypes::cube(dim) instead")
487 void makeCube(unsigned int dim) {
490 topologyId_ = ((dim>1) ? ((1 << dim) - 1) : 0);
494 DUNE_DEPRECATED_MSG("makeNone(dim) is deprecated in DUNE 2.6, please use Dune::GeometryTypes::none(dim) instead")
495 void makeNone(unsigned int dim) {
505 void makeFromVertices(unsigned int dim, unsigned int vertices) DUNE_DEPRECATED_MSG("Use the utility function geometryTypeFromVertexCount(...) instead.")
507 *this = geometryTypeFromVertexCount(dim, vertices);
517 constexpr bool isVertex() const {
522 constexpr bool isLine() const {
527 constexpr bool isTriangle() const {
528 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0001;
532 constexpr bool isQuadrilateral() const {
533 return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0011;
537 constexpr bool isTetrahedron() const {
538 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0001;
542 constexpr bool isPyramid() const {
543 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0011;
547 constexpr bool isPrism() const {
548 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0101;
552 constexpr bool isHexahedron() const {
553 return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0111;
557 constexpr bool isSimplex() const {
558 return ! none_ && (topologyId_ | 1) == 1;
562 constexpr bool isCube() const {
563 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
567 constexpr bool isNone() const {
572 constexpr unsigned int dim() const {
577 constexpr unsigned int id() const {
589 constexpr bool operator==(const GeometryType& other) const {
590 return ( ( none_ == other.none_ )
591 && ( ( none_ == true )
592 || ( ( dim_ == other.dim_ )
593 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
600 constexpr bool operator!=(const GeometryType& other) const {
601 return ! ((*this)==other);
605 constexpr bool operator < (const GeometryType& other) const {
606 return ( ( none_ < other.none_ )
607 || ( !( other.none_ < none_ )
608 && ( ( dim_ < other.dim_ )
609 || ( (other.dim_ == dim_)
610 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
622 inline std::ostream& operator<< (std::ostream& s, const GeometryType& a)
626 s << "(simplex, " << a.dim() << ")";
631 s << "(cube, " << a.dim() << ")";
646 s << "(none, " << a.dim() << ")";
649 s << "(other [" << a.id() << "], " << a.dim() << ")";
653 #pragma GCC diagnostic push
654 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
656 inline std::ostream& operator<< (std::ostream& s, GeometryType::BasicType type)
659 case GeometryType::simplex :
662 case GeometryType::cube :
665 case GeometryType::pyramid :
668 case GeometryType::prism :
671 case GeometryType::extended :
673 case GeometryType::none :
677 DUNE_THROW(Exception, "invalid GeometryType::BasicType");
681 #pragma GCC diagnostic pop
690 namespace GeometryTypes {
696 inline constexpr GeometryType simplex(unsigned int dim)
698 return GeometryType(0,dim,false);
705 inline constexpr GeometryType cube(unsigned int dim)
707 return GeometryType(((dim>1) ? ((1 << dim) - 1) : 0),dim,false);
714 inline constexpr GeometryType none(unsigned int dim)
716 return GeometryType(0,dim,true);
719 #ifndef __cpp_inline_variables
727 DUNE_INLINE_VARIABLE constexpr GeometryType vertex = GeometryType(0,0,false);
733 DUNE_INLINE_VARIABLE constexpr GeometryType line = GeometryType(0,1,false);
739 DUNE_INLINE_VARIABLE constexpr GeometryType triangle = simplex(2);
745 DUNE_INLINE_VARIABLE constexpr GeometryType quadrilateral = cube(2);
751 DUNE_INLINE_VARIABLE constexpr GeometryType tetrahedron = simplex(3);
757 DUNE_INLINE_VARIABLE constexpr GeometryType pyramid = GeometryType(0b0011,3,false);
763 DUNE_INLINE_VARIABLE constexpr GeometryType prism = GeometryType(0b0101,3,false);
769 DUNE_INLINE_VARIABLE constexpr GeometryType hexahedron = cube(3);
771 #ifndef __cpp_inline_variables
781 #include "utility/typefromvertexcount.hh"
GeometryType geometryTypeFromVertexCount(unsigned int dim, unsigned int vertices)
Utitlity function to construct the correct geometry type given the dimension and the number of vertic...
Definition: typefromvertexcount.hh:15
Definition: affinegeometry.hh:18