Dune Core Modules (2.4.2)

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
15
16#include "type.hh"
17
18namespace Dune
19{
22 {
29 DUNE_CONSTEXPR inline static std::size_t regular_size(std::size_t dim)
30 {
31 // The following expression is derived from the expression for
32 // GlobalGeometryTypeIndex::regular_offset(). Subtracting
33 // regular_offset(dim+1)-regular_offset(dim) we get:
34 //
35 // ((1 << dim+1) >> 1) - ((1 << dim) >> 1)
36 //
37 // We always have
38 //
39 // dim >= 0,
40 //
41 // so
42 //
43 // (1 << dim+1) >= 2 and (1 << dim+2) % 2 == 0.
44 //
45 // So if we apply a single right-shift to that, we will never lose any
46 // set bits, thus
47 //
48 // ((1 << dim+1) >> 1) == (1 << dim)
49 return (1 << dim) - ((1 << dim) >> 1);
50 }
51
52 public:
58 DUNE_CONSTEXPR inline static std::size_t size(std::size_t dim)
59 {
60 // one for "none"
61 return regular_size(dim) + 1;
62 }
63
70 inline static std::size_t index(const GeometryType &gt)
71 {
72 if(gt.isNone())
73 {
74 return regular_size(gt.dim());
75 }
76 else
77 {
78 return gt.id() >> 1;
79 }
80 }
81
83 inline static GeometryType type(std::size_t dim, std::size_t index) {
84 if(index == regular_size(dim)) {
86 gt.makeNone(dim);
87 return gt;
88 }
89 else {
90 // the cast to unsigned makes sure this is interpreted as the topology
91 // ID constructor
92 return GeometryType(unsigned(index << 1), dim);
93 }
94 }
95 };
96
99 {
107 DUNE_CONSTEXPR inline static std::size_t regular_offset(std::size_t dim)
108 {
109 // The number of regular geometry types in a given dimension is
110 // 2^(dim-1). For dim==0 this would yield 1/2 geometry types (which is
111 // obviously bogus, dim==0 has one regular geometry type, the point).
112 // The following expression relies on 1 >> 1 == 0 to treat dim==0
113 // specially.
114 return (1 << dim) >> 1;
115 }
116
117 public:
122 DUNE_CONSTEXPR inline static std::size_t offset(std::size_t dim)
123 {
124 // dim times "none"
125 return regular_offset(dim) + dim;
126 }
127
134 DUNE_CONSTEXPR inline static std::size_t size(std::size_t maxdim)
135 {
136 return offset(maxdim+1);
137 }
138
147 inline static std::size_t index(const GeometryType &gt)
148 {
149 return offset(gt.dim()) + LocalGeometryTypeIndex::index(gt);
150 }
151 };
152} // namespace Dune
153
154#endif // DUNE_GEOMETRY_TYPEINDEX_HH
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Compute indices for geometry types, taking the dimension into account.
Definition: typeindex.hh:99
static DUNE_CONSTEXPR std::size_t offset(std::size_t dim)
Compute the starting index for a given dimension including irregular geometry types.
Definition: typeindex.hh:122
static DUNE_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:134
static std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:147
Compute per-dimension indices for geometry types.
Definition: typeindex.hh:22
static GeometryType type(std::size_t dim, std::size_t index)
compute the geometry type for the given local index and dimension
Definition: typeindex.hh:83
static DUNE_CONSTEXPR std::size_t size(std::size_t dim)
Compute total number of geometry types for the given dimension.
Definition: typeindex.hh:58
static std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type within its dimension.
Definition: typeindex.hh:70
Definition of the DUNE_CONSTEXPR macro.
#define DUNE_CONSTEXPR
Set method or expression constexpr if supported by the compiler.
Definition: constexpr.hh:21
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
Dune namespace.
Definition: alignment.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 11, 23:30, 2024)