DUNE-FEM (unstable)

indexset.hh
1#ifndef DUNE_FEM_GRIDPART_IDGRIDPART_INDEXSET_HH
2#define DUNE_FEM_GRIDPART_IDGRIDPART_INDEXSET_HH
3
4#include <type_traits>
5#include <vector>
6
8
9#include <dune/fem/gridpart/common/indexset.hh>
10#include <dune/fem/gridpart/common/persistentindexset.hh>
11
12#include <dune/fem/io/streams/streams.hh>
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19
20 // Internal forward declaration
21 // ----------------------------
22
23 template< class GridFamily >
24 class IdIndexSet;
25
26
27
28 namespace __IdIndexSet
29 {
30
31 // IndexSet
32 // --------
33
34 template< class GridFamily >
35 class IndexSet
36 {
37 protected:
38 typedef typename std::remove_const< GridFamily >::type::Traits Traits;
39
40 public:
41 typedef typename Traits::HostGridPartType::IndexSetType HostIndexSetType;
42
43 static const int dimension = HostIndexSetType::dimension;
44
45 template< int codim >
46 struct Codim
47 {
48 typedef typename Traits::template Codim< codim >::Entity Entity;
49 };
50
51 typedef typename HostIndexSetType::IndexType IndexType;
52
53 typedef typename HostIndexSetType::Types Types;
54
55 explicit IndexSet ( const HostIndexSetType &hostIndexSet )
56 : hostIndexSet_( &hostIndexSet )
57 {}
58
59 Types types ( int codim ) const
60 {
61 return hostIndexSet().types( codim );
62 }
63
64 const std::vector< GeometryType > &geomTypes ( int codim ) const
65 {
66 return hostIndexSet().geomTypes( codim );
67 }
68
69 template< class Entity >
70 bool contains ( const Entity &entity ) const
71 {
72 return hostIndexSet().contains( entity.impl().hostEntity() );
73 }
74
75 IndexType size ( GeometryType type ) const
76 {
77 return hostIndexSet().size( type );
78 }
79
80 IndexType size ( int codim ) const
81 {
82 return hostIndexSet().size( codim );
83 }
84
85 template< class Entity >
86 IndexType index ( const Entity &entity ) const
87 {
88 return index< Entity::codimension >( entity );
89 }
90
91 template< int codim >
92 IndexType index ( const typename Codim< codim >::Entity &entity ) const
93 {
94 return hostIndexSet().template index< codim >( entity.impl().hostEntity() );
95 }
96
97 template< class Entity >
98 IndexType subIndex ( const Entity &entity, int i, unsigned int cd ) const
99 {
100 return subIndex< Entity::codimension >( entity, i, cd );
101 }
102
103 template< int codim >
104 IndexType subIndex ( const typename Codim< codim >::Entity &entity, int i, unsigned int cd ) const
105 {
106 return hostIndexSet().template subIndex< codim >( entity.impl().hostEntity(), i, cd );
107 }
108
109 const HostIndexSetType &hostIndexSet () const
110 {
111 assert( hostIndexSet_ );
112 return *hostIndexSet_;
113 }
114
115 void requestCodimensions( const std::vector< int >& codimensions ) const
116 {
117 hostIndexSet().requestCodimensions( codimensions );
118 }
119
120 protected:
121 HostIndexSetType &hostIndexSet ()
122 {
123 assert( hostIndexSet_ );
124 return const_cast< HostIndexSetType & >(*hostIndexSet_);
125 }
126
127 const HostIndexSetType *hostIndexSet_;
128 };
129
130
131
132 // ConsecutiveIndexSet
133 // -------------------
134
135 template< class GridFamily >
136 class ConsecutiveIndexSet
137 : public IndexSet< GridFamily >
138 {
139 typedef IndexSet< GridFamily > BaseType;
140
141 public:
142 typedef typename BaseType::HostIndexSetType HostIndexSetType;
143
144 using BaseType::hostIndexSet;
145
146 explicit ConsecutiveIndexSet ( const HostIndexSetType &hostIndexSet )
147 : BaseType ( hostIndexSet )
148 {}
149
150 void resize () { hostIndexSet().resize(); }
151
152 bool compress () { return hostIndexSet().compress(); }
153
154 void insertEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
155 {
156 hostIndexSet().insertEntity( entity.impl().hostEntity() );
157 }
158
159 void removeEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
160 {
161 hostIndexSet().removeEntity( entity.impl().hostEntity() );
162 }
163
164 void backup () const { hostIndexSet().backup(); }
165
166 void restore () { hostIndexSet().restore(); }
167
168 template< class T >
169 void write ( OutStreamInterface< T > &stream )
170 {
171 hostIndexSet().write( stream );
172 }
173
174 template< class T >
175 void read ( InStreamInterface< T > &stream )
176 {
177 hostIndexSet().read( stream );
178 }
179
180 protected:
181 HostIndexSetType &hostIndexSet ()
182 {
183 return const_cast< HostIndexSetType& >( BaseType::hostIndexSet() );
184 }
185 };
186
187
188
189 // AdaptiveIndexSet
190 // ----------------
191
192 template< class GridFamily >
193 class AdaptiveIndexSet
194 : public ConsecutiveIndexSet< GridFamily >
195 {
196 typedef ConsecutiveIndexSet< GridFamily > BaseType;
197
198 public:
199 explicit AdaptiveIndexSet ( const typename BaseType::HostIndexSetType &hostIndexSet )
200 : BaseType ( hostIndexSet )
201 {}
202
203 int numberOfHoles ( GeometryType type ) const
204 {
205 return this->hostIndexSet().numberOfHoles( type );
206 }
207
208 int numberOfHoles ( int codim ) const
209 {
210 return this->hostIndexSet().numberOfHoles( codim );
211 }
212
213 int oldIndex ( int hole, GeometryType type ) const
214 {
215 return this->hostIndexSet().oldIndex( hole, type );
216 }
217
218 int oldIndex ( int hole, int codim ) const
219 {
220 return this->hostIndexSet().oldIndex( hole, codim );
221 }
222
223 int newIndex ( int hole, GeometryType type ) const
224 {
225 return this->hostIndexSet().newIndex( hole, type );
226 }
227
228 int newIndex ( int hole, int codim ) const
229 {
230 return this->hostIndexSet().newIndex( hole, codim );
231 }
232 };
233
234
235
236 // Implementation
237 // --------------
238
239 template< class GridFamily,
240 class HostIndexSet = typename std::remove_const< GridFamily >::type::Traits::HostGridPartType::IndexSetType,
241 bool consecutive = Capabilities::isConsecutiveIndexSet< HostIndexSet >::v,
242 bool adaptive = Capabilities::isAdaptiveIndexSet< HostIndexSet >::v >
243 struct Implementation
244 {
245 typedef typename std::conditional< adaptive,
246 AdaptiveIndexSet< GridFamily >,
247 typename std::conditional< consecutive,
248 ConsecutiveIndexSet< GridFamily >,
249 IndexSet< GridFamily >
250 >::type
251 >::type Type;
252 };
253
254 } // namespace __IdIndexSet
255
256
257
258 // IdIndexSet
259 // ----------
260
261 template< class GridFamily >
262 class IdIndexSet
263 : public __IdIndexSet::Implementation< GridFamily >::Type
264 {
265 typedef typename __IdIndexSet::Implementation< GridFamily >::Type BaseType;
266
267 friend struct Capabilities::isPersistentIndexSet< IdIndexSet< GridFamily > >;
268
269 public:
270 explicit IdIndexSet ( const typename BaseType::HostIndexSetType &hostIndexSet )
271 : BaseType ( hostIndexSet )
272 {}
273 };
274
275
276
277 namespace Capabilities
278 {
279
280 template< class GridFamily >
281 struct isConsecutiveIndexSet< IdIndexSet< GridFamily > >
282 : public isConsecutiveIndexSet< typename IdIndexSet< GridFamily >::HostIndexSetType >
283 {};
284
285 template< class GridFamily >
286 struct isAdaptiveIndexSet< IdIndexSet< GridFamily > >
287 : public isAdaptiveIndexSet< typename IdIndexSet< GridFamily >::HostIndexSetType >
288 {};
289
290 template< class GridFamily >
291 struct isPersistentIndexSet< IdIndexSet< GridFamily > >
292 {
293 private:
294 typedef IdIndexSet< GridFamily > IndexSetType;
295 typedef typename IndexSetType::HostIndexSetType HostIndexSetType;
296
297 public:
299
300 static constexpr PersistentIndexSetInterface *map ( IndexSetType &indexSet ) noexcept
301 {
302 return isPersistentIndexSet< HostIndexSetType >::map( indexSet.hostIndexSet() );
303 }
304 };
305
306 } // namespace Capabilities
307
308 } // namespace Fem
309
310} // namespace Dune
311
312#endif // #ifndef DUNE_FEM_GRIDPART_IDGRIDPART_INDEXSET_HH
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
static constexpr PersistentIndexSetInterface * map(IndexSet &indexSet) noexcept
please doc me
Definition: persistentindexset.hh:101
static const bool v
please doc me
Definition: persistentindexset.hh:98
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 24, 23:30, 2024)