DUNE-FEM (unstable)

typeindexset.hh
1#ifndef DUNE_GEOMETRY_TYPEINDEXSET_HH
2#define DUNE_GEOMETRY_TYPEINDEXSET_HH
3
4#include <cstddef>
5
7
8namespace Dune
9{
10
11 namespace Fem
12 {
13 namespace hpDG {
14 // LocalGeometryTypeIndexSet
15 // -------------------------
16
24 template< int dim, bool regular = false >
26
27 template< int dim >
28 class LocalGeometryTypeIndexSet< dim, true >
29 {
31
32 public:
33 inline static constexpr std::size_t size () noexcept
34 {
35 return (1 << dim) - ((1 << dim) >> 1);
36 }
37
38 inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
39 {
40 return (type.id() >> 1);
41 }
42
43 inline static constexpr bool contains ( const GeometryType &type ) noexcept
44 {
45 return ((type.dim() == dim) && !type.isNone());
46 }
47
48 inline static GeometryType type ( std::size_t index ) noexcept
49 {
50 return GeometryType( static_cast< unsigned int >( index ) << 1, dim );
51 }
52 };
53
54 template< int dim >
55 class LocalGeometryTypeIndexSet< dim, false >
56 {
58 typedef LocalGeometryTypeIndexSet< dim, true > RegularTypeIndexSet;
59
60 public:
61 inline static constexpr std::size_t size () noexcept
62 {
63 return (RegularTypeIndexSet::size() + 1);
64 }
65
66 inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
67 {
68 return (type.isNone() ? RegularTypeIndexSet::size() : type.id() >> 1);
69 }
70
71 inline static constexpr bool contains ( const GeometryType &type ) noexcept
72 {
73 return (type.dim() == dim);
74 }
75
76 inline static GeometryType type ( std::size_t index ) noexcept
77 {
78 return (index < RegularTypeIndexSet::size() ? RegularTypeIndexSet::type( index ) : GeometryType( 0, dim, true ));
79 }
80 };
81
82
83
84 // GlobalGeometryTypeIndexSet
85 // --------------------------
86
94 template< int maxdim, bool regular = false >
96
97 template< int maxdim >
98 class GlobalGeometryTypeIndexSet< maxdim, true >
99 {
101
102 public:
103 inline static constexpr std::size_t size () noexcept
104 {
105 return (1 << maxdim);
106 }
107
108 inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
109 {
110 return ((1 << type.dim()) + type.id()) >> 1;
111 }
112
113 inline static constexpr bool contains ( const GeometryType &type ) noexcept
114 {
115 return ((type.dim() <= maxdim) && !type.isNone());
116 }
117
118 inline static GeometryType type ( std::size_t index ) noexcept
119 {
120 return GeometryType( (index << 1) & ~(1 << dim( index )), dim( index ) );
121 }
122
123 private:
124 inline static constexpr int dim ( std::size_t index, int d = maxdim )
125 {
126 return ((d <= 0) || ((index & (1 << (d-1))) != 0) ? d : dim( index, d-1 ));
127 }
128 };
129
130 template< int maxdim >
131 class GlobalGeometryTypeIndexSet< maxdim, false >
132 {
134 typedef GlobalGeometryTypeIndexSet< maxdim, true > RegularTypeIndexSet;
135
136 public:
137 inline static constexpr std::size_t size () noexcept
138 {
139 return RegularTypeIndexSet::size() + (maxdim + 1);
140 }
141
142 inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
143 {
144 return (type.isNone() ? RegularTypeIndexSet::size() + type.dim() : RegularTypeIndexSet::index( type ));
145 }
146
147 inline static constexpr bool contains ( const GeometryType &type ) noexcept
148 {
149 return (type.dim() <= maxdim);
150 }
151
152 inline static GeometryType type ( std::size_t index ) noexcept
153 {
154 return (index < RegularTypeIndexSet::size() ? RegularTypeIndexSet::type( index ) : GeometryType( 0, static_cast< int >( index - RegularTypeIndexSet::size() ), true ));
155 }
156 };
157
158
159
160 // SingleGeometryTypeIndexSet
161 // --------------------------
162
170 template< unsigned int topologyId, int dim >
172 {
174
175 public:
176 inline static constexpr std::size_t size () noexcept
177 {
178 return 1;
179 }
180
181 inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
182 {
183 return 0;
184 }
185
186 inline static constexpr bool contains ( const GeometryType &type ) noexcept
187 {
188 return (type == GeometryType( topologyId, dim ));
189 }
190
191 inline static GeometryType type ( std::size_t index ) noexcept
192 {
193 return GeometryType( topologyId, dim );
194 }
195 };
196
197
198
199 // GeometryTypes
200 // -------------
201
202 template< class TypeIndexSet >
203 struct GeometryTypes
204 {
205 struct Iterator
206 {
207 bool operator== ( const Iterator &other ) const { return (index == other.index); }
208 bool operator!= ( const Iterator &other ) const { return (index != other.index); }
209
210 GeometryType operator* () const { return TypeIndexSet::type( index ); }
211
212 Iterator &operator++ () { ++index; return *this; }
213
214 std::size_t index;
215 };
216
217 Iterator begin () const { return Iterator{ 0 }; }
218 Iterator end () const { return Iterator{ TypeIndexSet::size() }; }
219 };
220
221} // namespace hpDG
222} // namespace Fem
223} // namespace Dune
224
225#endif // #ifndef DUNE_GEOMETRY_TYPEINDEXSET_HH
Please doc me.
Definition: typeindexset.hh:95
Please doc me.
Definition: typeindexset.hh:25
Please doc me.
Definition: typeindexset.hh:172
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:260
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
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 (Jul 27, 22:29, 2024)