Skip to content
Snippets Groups Projects
Commit 8be98a9b authored by Henrik Stolzmann's avatar Henrik Stolzmann
Browse files

Added some helper functions to `GeometryType` to use i.e. in `dune-localfunctions`.

Prepared transition from `Topology` template parameter to
`GeometryType`.

The old Topology construction based on template recursion via the
structs `Point`, `Pyramid` and `Prism` is dated.
parent 3b461a88
No related branches found
No related tags found
1 merge request!161Feature/topology to geometry type
......@@ -16,6 +16,18 @@
These are optimal rules that include only one endpoint of the integration interval
(either left or right) and integrate polynomials of order 2n - 2 exactly.
- GeometryType has four new methods: `isPrismatic()`, `isPrismatic(int step)` and `isConical()`,`isConical(int step)`.
The versions with an argument return true if the corresponding construction was used in step 0 <= `step` <=dim-1.
The other two assume a default argument of `dim-1` (the latest construction step).
- GeometryTypes has two new methods: `prismaticExtension(GeometryType gt)` and `conicalExtension(GeometryType gt)`.
They return an extended GeometryType based on `gt` via the corresponding construction. For example:
```c++
GeometryType gt = GeometryTypes::line;
auto square = GeometryTypes::prismaticExtension(gt);
auto triangle = GeometryTypes::conicalExtension(gt);
```
## Deprecations and removals
- Remove code needed to use reference elements by reference.
......
......@@ -356,6 +356,11 @@ namespace Dune
return static_cast<Id>(id);
}
constexpr Id toId() const
{
return static_cast<Id>(*this);
}
/** \brief Reconstruct a Geometry type from a GeometryType::Id */
/**
* This constructor exists mostly to transparently support using a GeometryType as a
......@@ -469,6 +474,32 @@ namespace Dune
return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
}
/** \brief Return true if entity was constructed with a conical product in the last step */
constexpr bool isConical() const {
return ! none_ && (((topologyId_ & ~1) & (1u << (dim_-1))) == 0);
}
/** \brief Return true if entity was constructed with a conical product in the chosen step
*
* \param step 0 <= step <= dim-1
*/
constexpr bool isConical(const int& step) const {
return ! none_ && (((topologyId_ & ~1) & (1u << step)) == 0);
}
/** \brief Return true if entity was constructed with a prismatic product in the last step */
constexpr bool isPrismatic() const {
return ! none_ && (( (topologyId_ | 1) & (1u << (dim_-1))) != 0);
}
/** \brief Return true if entity was constructed with a prismatic product in the chosen step
*
* \param step 0 <= step <= dim-1
*/
constexpr bool isPrismatic(const int& step) const {
return ! none_ && (( (topologyId_ | 1) & (1u << step)) != 0);
}
/** \brief Return true if entity is a singular of any dimension */
constexpr bool isNone() const {
return none_;
......@@ -486,7 +517,6 @@ namespace Dune
/*@}*/
/** @name Comparison operators */
/** \brief Check for equality. This method knows that in dimension 0 and 1
......@@ -591,6 +621,18 @@ namespace Dune
return GeometryType(0,dim,true);
}
/** \brief Return GeometryType of a conical construction with gt as base */
inline constexpr GeometryType conicalExtension(const GeometryType& gt)
{
return GeometryType(gt.id(), gt.dim()+1, gt.isNone());
}
/** \brief Return GeometryType of a prismatic construction with gt as base */
inline constexpr GeometryType prismaticExtension(const GeometryType& gt)
{
return GeometryType(gt.id() | ((1 << gt.dim())), gt.dim()+1, gt.isNone());
}
#ifndef __cpp_inline_variables
namespace {
#endif
......@@ -649,7 +691,45 @@ namespace Dune
}
namespace Impl
{
/** \brief Removes the bit for the highest dimension and returns the lower-dimensional GeometryType */
inline constexpr GeometryType getBase(const GeometryType& gt) {
return GeometryType(gt.id() & ((1 << (gt.dim()-1))-1), gt.dim()-1, gt.isNone());
}
// IfGeometryType
// ----------
template< template< GeometryType::Id > class Operation, int dim, GeometryType::Id geometryId = GeometryTypes::vertex >
struct IfGeometryType
{
static constexpr GeometryType geometry = geometryId;
template< class... Args >
static auto apply ( GeometryType gt, Args &&... args )
{
GeometryType lowerGeometry(gt.id() >>1 , gt.dim()-1, gt.isNone());
if( gt.id() & 1 )
return IfGeometryType< Operation, dim-1, GeometryTypes::prismaticExtension(geometry).toId() >::apply( lowerGeometry, std::forward< Args >( args )... );
else
return IfGeometryType< Operation, dim-1, GeometryTypes::conicalExtension(geometry).toId() >::apply( lowerGeometry, std::forward< Args >( args )... );
}
};
template< template< GeometryType::Id > class Operation, GeometryType::Id geometryId >
struct IfGeometryType< Operation, 0, geometryId>
{
template< class... Args >
static auto apply ( GeometryType gt, Args &&... args )
{
DUNE_UNUSED_PARAMETER( gt );
return Operation< geometryId >::apply( std::forward< Args >( args )... );
}
};
} // namespace Impl
} // namespace Dune
#endif // DUNE_GEOMETRY_TYPE_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment