Dune Core Modules (2.6.0)

typeindex.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_GEOMETRY_TYPEINDEX_HH
4#define DUNE_GEOMETRY_TYPEINDEX_HH
5
12#include <cstddef>
13
14#include "type.hh"
15
16namespace Dune
17{
20 {
27 inline static constexpr std::size_t regular_size(std::size_t dim)
28 {
29 // The following expression is derived from the expression for
30 // GlobalGeometryTypeIndex::regular_offset(). Subtracting
31 // regular_offset(dim+1)-regular_offset(dim) we get:
32 //
33 // ((1 << dim+1) >> 1) - ((1 << dim) >> 1)
34 //
35 // We always have
36 //
37 // dim >= 0,
38 //
39 // so
40 //
41 // (1 << dim+1) >= 2 and (1 << dim+2) % 2 == 0.
42 //
43 // So if we apply a single right-shift to that, we will never lose any
44 // set bits, thus
45 //
46 // ((1 << dim+1) >> 1) == (1 << dim)
47 return (1 << dim) - ((1 << dim) >> 1);
48 }
49
50 public:
56 inline static constexpr std::size_t size(std::size_t dim)
57 {
58 // one for "none"
59 return regular_size(dim) + 1;
60 }
61
68 inline static constexpr std::size_t index(const GeometryType &gt)
69 {
70 return gt.isNone() ? regular_size(gt.dim()) : (gt.id() >> 1);
71 }
72
74 inline static constexpr GeometryType type(std::size_t dim, std::size_t index) {
75 return (index == regular_size(dim)) ?
77 // the cast to unsigned makes sure this is interpreted as the topology
78 // ID constructor
79 GeometryType(static_cast< unsigned int >(index << 1), dim);
80 }
81 };
82
85 {
93 inline static constexpr std::size_t regular_offset(std::size_t dim)
94 {
95 // The number of regular geometry types in a given dimension is
96 // 2^(dim-1). For dim==0 this would yield 1/2 geometry types (which is
97 // obviously bogus, dim==0 has one regular geometry type, the point).
98 // The following expression relies on 1 >> 1 == 0 to treat dim==0
99 // specially.
100 return (1 << dim) >> 1;
101 }
102
103 public:
108 inline static constexpr std::size_t offset(std::size_t dim)
109 {
110 // dim times "none"
111 return regular_offset(dim) + dim;
112 }
113
120 inline static constexpr std::size_t size(std::size_t maxdim)
121 {
122 return offset(maxdim+1);
123 }
124
133 inline static constexpr std::size_t index(const GeometryType &gt)
134 {
135 return offset(gt.dim()) + LocalGeometryTypeIndex::index(gt);
136 }
137 };
138} // namespace Dune
139
140#endif // DUNE_GEOMETRY_TYPEINDEX_HH
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
Compute indices for geometry types, taking the dimension into account.
Definition: typeindex.hh:85
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:133
static constexpr std::size_t offset(std::size_t dim)
Compute the starting index for a given dimension including irregular geometry types.
Definition: typeindex.hh:108
static constexpr std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:120
Compute per-dimension indices for geometry types.
Definition: typeindex.hh:20
static constexpr std::size_t size(std::size_t dim)
Compute total number of geometry types for the given dimension.
Definition: typeindex.hh:56
static constexpr GeometryType type(std::size_t dim, std::size_t index)
compute the geometry type for the given local index and dimension
Definition: typeindex.hh:74
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type within its dimension.
Definition: typeindex.hh:68
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:147
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:714
Dune namespace.
Definition: alignedallocator.hh:10
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 26, 23:30, 2024)