Dune Core Modules (2.3.1)

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 std::size_t regular_size(std::size_t dim)
28 {
29 // The following expression is derived from the expression for
30 // GlobalGeometryTypeIndex::regular_base(). Substracting
31 // regular_base(dim+1)-regular_base(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 std::size_t size(std::size_t dim)
57 {
58 // one for "none"
59 return regular_size(dim) + 1;
60 }
61
68 inline static std::size_t index(const GeometryType &gt)
69 {
70 if(gt.isNone())
71 {
72 return regular_size(gt.dim());
73 }
74 else
75 {
76 return gt.id() >> 1;
77 }
78 }
79
81 inline static GeometryType type(std::size_t dim, std::size_t index) {
82 if(index == regular_size(dim)) {
84 gt.makeNone(dim);
85 return gt;
86 }
87 else {
88 // the cast to unsigned makes sure this is interpreted as the topology
89 // ID constructor
90 return GeometryType(unsigned(index << 1), dim);
91 }
92 }
93 };
94
97 {
105 inline static std::size_t regular_base(std::size_t dim)
106 {
107 // The number of regular geometry types in a given dimension is
108 // 2^(dim-1). For dim==0 this would yield 1/2 geometry types (which is
109 // obviously bogus, dim==0 has one regular geometry type, the point).
110 // The following expression relies on 1 >> 1 == 0 to treat dim==0
111 // specially.
112 return (1 << dim) >> 1;
113 }
114
119 inline static std::size_t base(std::size_t dim)
120 {
121 // dim times "none"
122 return regular_base(dim) + dim;
123 }
124
125 public:
132 inline static std::size_t size(std::size_t maxdim)
133 {
134 return base(maxdim+1);
135 }
136
145 inline static std::size_t index(const GeometryType &gt)
146 {
147 return base(gt.dim()) + LocalGeometryTypeIndex::index(gt);
148 }
149 };
150} // namespace Dune
151
152#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:97
static std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:132
static std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:145
Compute per-dimension indices for geometry types.
Definition: typeindex.hh:20
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:81
static std::size_t size(std::size_t dim)
Compute total number of geometry types for the given dimension.
Definition: typeindex.hh:56
static 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:132
Dune namespace.
Definition: alignment.hh:14
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 (Nov 12, 23:30, 2024)