dune-fem 2.8.0
Loading...
Searching...
No Matches
common/indexset.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_GRIDPART_COMMON_INDEXSET_HH
2#define DUNE_FEM_GRIDPART_COMMON_INDEXSET_HH
3
4#include <type_traits>
5#include <utility>
6#include <vector>
7
8#include <dune/geometry/type.hh>
9
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
18 // Internal forward declaration
19 // ----------------------------
20 template< class Traits >
21 class IndexSet;
22 template< class Traits >
23 class ConsecutiveIndexSet;
24 template< class Traits >
25 class AdaptiveIndexSet;
26
27
28 namespace Capabilities
29 {
30
31 // isConsecutiveIndexSet
32 // ---------------------
33
40 template< class IndexSet >
42 {
43 template< class Traits >
44 static std::true_type __isConsecutive ( const ConsecutiveIndexSet< Traits > & );
45
46 static std::false_type __isConsecutive ( ... );
47
48 public:
49 static const bool v = decltype( __isConsecutive( std::declval< IndexSet >() ) )::value;
50 };
51
52
53 // isAdaptiveIndexSet
54 // ------------------
55
62 template< class IndexSet >
64 {
65 template< class Traits >
66 static std::true_type __isAdaptive ( const AdaptiveIndexSet< Traits > & );
67
68 static std::false_type __isAdaptive ( ... );
69
70 public:
71 static const bool v = decltype( __isAdaptive( std::declval< IndexSet >() ) )::value;
72 };
73
74
75
76#ifndef DOXYGEN
77
78 template< class IndexSet >
79 struct isConsecutiveIndexSet< const IndexSet >
80 : public isConsecutiveIndexSet< IndexSet >
81 {};
82
83 template< class IndexSet >
84 struct isAdaptiveIndexSet< const IndexSet >
85 : public isAdaptiveIndexSet< IndexSet >
86 {};
87
88#endif // #ifndef DOXYGEN
89
90 } // namespace Capabilites
91
92
93
94 // IndexSet
95 // --------
96
102 template< class Traits >
104 {
105 public:
107 static const int dimension = Traits::dimension;
108
109 template< int codim >
110 struct Codim
111 {
113 typedef typename Traits::template Codim< codim >::Entity Entity;
114 };
115
117 typedef typename Traits::IndexType IndexType;
118
120 typedef typename Traits::Types Types;
121
122 protected:
123 IndexSet () = default;
124
125 public:
127 Types types ( int codim ) const
128 {
129 return impl().types( codim );
130 }
131
133 template< class Entity >
134 bool contains ( const Entity &entity ) const
135 {
136 return impl().contains( entity );
137 }
138
140 IndexType size ( GeometryType type ) const
141 {
142 return impl().size( type );
143 }
144
146 IndexType size ( int codim ) const
147 {
148 return impl().size( codim );
149 }
150
152 template< class Entity >
153 IndexType index ( const Entity &entity ) const
154 {
155 return index< Entity::codimension >( entity );
156 }
157
159 template< int codim >
160 IndexType index ( const typename Codim< codim >::Entity &entity ) const
161 {
162 return impl().template index< codim >( entity );
163 }
164
166 template< class Entity >
167 IndexType subIndex ( const Entity &entity, int i, unsigned int cd ) const
168 {
169 return subIndex< Entity::codimension >( entity, i, cd );
170 }
171
173 template< int codim >
174 IndexType subIndex ( const typename Codim< codim >::Entity &entity, int i, unsigned int cd ) const
175 {
176 return impl().template subIndex< codim >( entity, i, cd );
177 }
178
180 void requestCodimensions ( const std::vector< int >& codimensions ) const
181 {
182 }
183
184 protected:
185 const typename Traits::IndexSetType &impl () const
186 {
187 return static_cast< const typename Traits::IndexSetType & >( *this );
188 }
189 };
190
191
192
193 // ConsecutiveIndexSet
194 // -------------------
195
201 template< class Traits >
203 : public IndexSet< Traits >
204 {
206
207 protected:
209
211
212 public:
218 void resize () { impl().resize(); }
219
221 bool compress () { return impl().compress(); }
222
224 void insertEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
225 {
226 impl().insertEntity( entity );
227 }
228
230 void removeEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
231 {
232 impl().removeEntity( entity );
233 }
234
236 void backup () const { impl().backup(); }
237
239 void restore () { impl().restore(); }
240
242 template< class T >
243 void write ( OutStreamInterface< T > &stream ) const
244 {
245 impl().write( stream );
246 }
247
249 template< class T >
251 {
252 impl().read( stream );
253 }
254
257 protected:
258 typename Traits::IndexSetType &impl ()
259 {
260 const typename Traits::IndexSetType &impl = BaseType::impl();
261 return const_cast< typename Traits::IndexSetType & >( impl );
262 }
263 };
264
265
266
267 // AdaptiveIndexSet
268 // ----------------
269
275 template< class Traits >
277 : public ConsecutiveIndexSet< Traits >
278 {
280
281 protected:
283
284 AdaptiveIndexSet () = default;
285
286 public:
292 int numberOfHoles ( GeometryType type ) const
293 {
294 return impl().numberOfHoles( type );
295 }
296
298 int oldIndex ( int hole, GeometryType type ) const
299 {
300 return impl().oldIndex( hole, type );
301 }
302
304 int newIndex ( int hole, GeometryType type ) const
305 {
306 return impl().newIndex( hole, type );
307 }
308
311 };
312
313 } // namespace Fem
314
315} // namespace Dune
316
317#endif // #ifndef DUNE_FEM_GRIDPART_COMMON_INDEXSET_HH
Definition: bindguard.hh:11
interface documentation for (grid part) index sets
Definition: common/indexset.hh:104
IndexType subIndex(const typename Codim< codim >::Entity &entity, int i, unsigned int cd) const
return index for given subentity
Definition: common/indexset.hh:174
IndexType index(const typename Codim< codim >::Entity &entity) const
return index for given entity
Definition: common/indexset.hh:160
Traits::Types Types
geometry type range type
Definition: common/indexset.hh:120
bool contains(const Entity &entity) const
return true if entity has index
Definition: common/indexset.hh:134
void requestCodimensions(const std::vector< int > &codimensions) const
receive request for codimension support in case index set is adaptive
Definition: common/indexset.hh:180
IndexType size(GeometryType type) const
return number of entities of given type
Definition: common/indexset.hh:140
IndexType subIndex(const Entity &entity, int i, unsigned int cd) const
return index for given subentity
Definition: common/indexset.hh:167
const Traits::IndexSetType & impl() const
Definition: common/indexset.hh:185
Types types(int codim) const
return range of geometry types
Definition: common/indexset.hh:127
IndexType size(int codim) const
return number of entities of given codimension
Definition: common/indexset.hh:146
IndexType index(const Entity &entity) const
return index for given entity
Definition: common/indexset.hh:153
static const int dimension
grid dimension
Definition: common/indexset.hh:107
Traits::IndexType IndexType
index type
Definition: common/indexset.hh:117
extended interface for consecutive index sets
Definition: common/indexset.hh:204
Traits::IndexSetType & impl()
Definition: common/indexset.hh:258
void write(OutStreamInterface< T > &stream) const
please doc me
Definition: common/indexset.hh:243
bool compress()
please doc me
Definition: common/indexset.hh:221
void backup() const
please doc me
Definition: common/indexset.hh:236
void resize()
please doc me
Definition: common/indexset.hh:218
void insertEntity(const typename BaseType::template Codim< 0 >::Entity &entity)
please doc me
Definition: common/indexset.hh:224
void removeEntity(const typename BaseType::template Codim< 0 >::Entity &entity)
please doc me
Definition: common/indexset.hh:230
void restore()
please doc me
Definition: common/indexset.hh:239
void read(InStreamInterface< T > &stream)
please doc me
Definition: common/indexset.hh:250
extended interface for adaptive, consecutive index sets
Definition: common/indexset.hh:278
Traits::IndexSetType & impl()
Definition: common/indexset.hh:258
int numberOfHoles(GeometryType type) const
return number of holes for given type
Definition: common/indexset.hh:292
int oldIndex(int hole, GeometryType type) const
return old index for given hole and type
Definition: common/indexset.hh:298
int newIndex(int hole, GeometryType type) const
return new index for given hole and type
Definition: common/indexset.hh:304
specialize with true if index set implements the interface for consecutive index sets
Definition: common/indexset.hh:42
static std::false_type __isConsecutive(...)
static std::true_type __isConsecutive(const ConsecutiveIndexSet< Traits > &)
static const bool v
Definition: common/indexset.hh:49
specialize with true if index set implements the interface for adaptive index sets
Definition: common/indexset.hh:64
static const bool v
Definition: common/indexset.hh:71
Definition: common/indexset.hh:111
Traits::template Codim< codim >::Entity Entity
entity type
Definition: common/indexset.hh:113
abstract interface for an output stream
Definition: streams.hh:46
abstract interface for an input stream
Definition: streams.hh:179