DUNE-FEM (unstable)

powermapper.hh
1#ifndef DUNE_FEM_COMBINEDSPACE_POWERMAPPER_HH
2#define DUNE_FEM_COMBINEDSPACE_POWERMAPPER_HH
3
4#include <dune/common/math.hh>
5
6#include <dune/fem/gridpart/common/indexset.hh>
7#include <dune/fem/space/common/dofmanager.hh>
8#include <dune/fem/space/mapper/dofmapper.hh>
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15 // Internal Forward Declration
16 // ---------------------------
17
18 template< class GridPart, class Mapper, int N >
19 class PowerMapper;
20
21#ifndef DOXYGEN
22
23 namespace __PowerMapper
24 {
25
26 // Traits
27 // ------
28
29 template< class GridPart, class Mapper, int N >
30 struct Traits
31 {
32 typedef Mapper MapperType;
33
34 typedef GridPart GridPartType;
35
36 typedef typename MapperType::ElementType ElementType;
37 typedef typename MapperType::SizeType SizeType;
38 typedef typename MapperType::GlobalKeyType GlobalKeyType;
39
40 typedef PowerMapper< GridPartType, MapperType, N > DofMapperType;
41
42 static const int numComponents = N;
43 };
44
45
46
47 template< class T, template< class > class Base = Dune::Fem::DofMapper >
48 class DofMapper
49 : public Base< T >
50 {
51 typedef Base< T > BaseType;
52
53 public:
54 typedef typename BaseType::Traits Traits;
55 typedef typename BaseType::ElementType ElementType;
56 typedef typename BaseType::SizeType SizeType;
57
58 typedef typename Traits::GridPartType GridPartType;
59 typedef typename Traits::GlobalKeyType GlobalKeyType;
60
61 typedef typename Traits::MapperType MapperType;
62
63 static const int numComponents = Traits::numComponents;
64
65 protected:
66 // funtor wrapper
67 template< class Functor >
68 struct FunctorWrapper
69 {
70 FunctorWrapper ( SizeType offset, Functor functor )
71 : offset_( offset ),
72 functor_( functor )
73 {}
74
75 template< class GlobalKey >
76 void operator() ( int localBlock, const GlobalKey &globalKey )
77 {
78 int localDof = localBlock*numComponents;
79 for( int component = 0; component < numComponents; ++component, ++localDof )
80 functor_( localDof, globalKey + component * offset_ );
81 }
82
83 template< class GlobalKey >
84 void operator() ( const GlobalKey &globalKey )
85 {
86 for( int component = 0; component < numComponents; ++component )
87 functor_( globalKey + component * offset_ );
88 }
89
90 private:
91 SizeType offset_;
92 Functor functor_;
93 };
94
95 public:
96
97 DofMapper ( GridPartType &gridPart, MapperType &mapper )
98 : gridPart_( gridPart ),
99 mapper_( mapper ),
100 offset_( mapper_.size() )
101 {}
102
103 SizeType size () const { return mapper().size() * numComponents; }
104
105 bool contains ( const int codim ) const { return mapper().contains( codim ); }
106
107 bool fixedDataSize ( const int codim ) const { return mapper().fixedDataSize( codim ); }
108
109 template< class Functor >
110 void mapEach ( const ElementType &element, Functor f ) const
111 {
112 FunctorWrapper< Functor > wrapper( offset_, f );
113 mapper().mapEach( element, wrapper );
114 }
115
116 template< class Entity, class Functor >
117 void mapEachEntityDof ( const Entity &entity, Functor f ) const
118 {
119 FunctorWrapper< Functor > wrapper( offset_, f );
120 mapper().mapEachEntityDof( entity, wrapper );
121 }
122
123 int maxNumDofs () const { return mapper().maxNumDofs() * numComponents; }
124
125 SizeType numDofs ( const ElementType &element ) const { return mapper().numDofs( element ) * numComponents; }
126
127 template< class Entity >
128 SizeType numEntityDofs ( const Entity &entity ) const { return mapper().numEntityDofs( entity ) * numComponents; }
129
130
131 static constexpr bool consecutive () noexcept { return false; }
132
133 SizeType numBlocks () const
134 {
135 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
136 }
137
138 SizeType numberOfHoles ( int ) const
139 {
140 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
141 }
142
143 GlobalKeyType oldIndex ( int hole, int ) const
144 {
145 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
146 }
147
148 GlobalKeyType newIndex ( int hole, int ) const
149 {
150 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
151 }
152
153 SizeType oldOffSet ( int ) const
154 {
155 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
156 }
157
158 SizeType offSet ( int ) const
159 {
160 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
161 }
162
163 protected:
164 MapperType &mapper () { return mapper_; }
165 const MapperType &mapper () const { return mapper_; }
166
167 GridPartType &gridPart_;
168 MapperType &mapper_;
169 SizeType offset_;
170 };
171
172
173
174 // AdaptiveDofMapper
175 // -----------------
176
177 template< class T >
178 class AdaptiveDofMapper
179 : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
180 {
181 typedef DofMapper< T, Dune::Fem::AdaptiveDofMapper > BaseType;
182
183 public:
184 typedef typename BaseType::Traits Traits;
185 typedef typename BaseType::ElementType ElementType;
186 typedef typename BaseType::SizeType SizeType;
187
188 typedef typename Traits::GridPartType GridPartType;
189 typedef typename Traits::GlobalKeyType GlobalKeyType;
190
191 typedef typename Traits::MapperType MapperType;
192
193 static const int numComponents = Traits::numComponents;
194
195 protected:
196 using BaseType::mapper;
197 using BaseType::gridPart_;
198 using BaseType::offset_;
199
200 public:
201
202 AdaptiveDofMapper ( GridPartType &gridPart, MapperType &mapper )
203 : BaseType( gridPart, mapper ),
204 oldOffset_( -1 )
205 {
207 }
208
209 ~AdaptiveDofMapper ()
210 {
212 }
213
214 bool consecutive () const { return true; }
215
216 SizeType numBlocks () const { return mapper().numBlocks() * numComponents; }
217
218 SizeType numberOfHoles ( const int block ) const { return mapper().numberOfHoles( block % mapper().numBlocks() ); }
219
220 GlobalKeyType oldIndex ( const int hole, const int block ) const
221 {
222 const int numContainedBlocks = mapper().numBlocks();
223 const int containedBlock = block % numContainedBlocks;
224 const int component = block / numContainedBlocks;
225
226 const int containedOffset = mapper().oldIndex( hole, containedBlock );
227 return containedOffset + component * oldOffset_;
228 }
229
230 GlobalKeyType newIndex ( const int hole, const int block ) const
231 {
232 const int numContainedBlocks = mapper().numBlocks();
233 const int containedBlock = block % numContainedBlocks;
234 const int component = block / numContainedBlocks;
235
236 const int containedOffset = mapper().newIndex( hole, containedBlock );
237 return containedOffset + component * offset_;
238 }
239
240 SizeType oldOffSet ( const int block ) const
241 {
242 const int numContainedBlocks = mapper().numBlocks();
243 const int containedBlock = block % numContainedBlocks;
244 const int component = block / numContainedBlocks;
245
246 const int containedOffset = mapper().oldOffSet( containedBlock );
247 return containedOffset + component * oldOffset_;
248 }
249
250 SizeType offSet ( const int block ) const
251 {
252 const int numContainedBlocks = mapper().numBlocks();
253 const int containedBlock = block % numContainedBlocks;
254 const int component = block / numContainedBlocks;
255
256 const int containedOffset = mapper().offSet( containedBlock );
257 return containedOffset + component * offset_;
258 }
259
260 template< class Entity >
261 void insertEntity ( const Entity &entity ) { update(); }
262
263 template< class Entity >
264 void removeEntity ( const Entity &entity ) { }
265
266 void resize () { update(); }
267
268 bool compress () { update(); return true; }
269
270 template< class StreamTraits >
271 void write ( OutStreamInterface< StreamTraits > &out ) const {}
272
273 template< class StreamTraits >
274 void read ( InStreamInterface< StreamTraits > &in )
275 {
276 update();
277 }
278
279 void backup () const {}
280 void restore () {}
281
282 protected:
283 void update ()
284 {
285 oldOffset_ = offset_;
286 offset_ = mapper().size();
287 }
288
289 private:
290 SizeType oldOffset_;
291 };
292
293
294 // Implementation
295 // --------------
296
297 template< class GridPart, class Mapper, int N, bool adapative = Capabilities::isAdaptiveDofMapper< Mapper >::v >
298 class Implementation
299 {
300 typedef __PowerMapper::Traits< GridPart, Mapper, N > Traits;
301
302 public:
303 typedef typename std::conditional< adapative, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type;
304 };
305
306
307
308 } // namespace __PowerMapper
309
310#endif // #ifndef DOXYGEN
311
312
313 // PowerMapper
314 // ----------
315
327 template< class GridPart, class Mapper, int N >
329 : public __PowerMapper::template Implementation< GridPart, Mapper, N >::Type
330 {
331 typedef typename __PowerMapper::template Implementation< GridPart, Mapper, N >::Type BaseType;
332
333 public:
334 PowerMapper ( GridPart &gridPart, Mapper &mapper )
335 : BaseType( gridPart, mapper )
336 {}
337 };
338
339
340 // Capabilities
341 // ------------
342
343 namespace Capabilities
344 {
345 template< class GridPart, class Mapper, int N >
346 struct isAdaptiveDofMapper< PowerMapper< GridPart, Mapper, N > >
347 {
348 static const bool v = isAdaptiveDofMapper< Mapper >::v;
349 };
350
351 template< class GridPart, class Mapper, int N >
352 struct isConsecutiveIndexSet< __PowerMapper::AdaptiveDofMapper< __PowerMapper::Traits< GridPart, Mapper, N > > >
353 {
354 static const bool v = true;
355 };
356
357 } // namespace Capabilities
360 } // namespace Fem
361
362} // namespace Dune
363
364#endif //#ifndef DUNE_FEM_COMBINEDSPACE_POWERMAPPER_HH
Interface for calculating the size of a function space for a grid on a specified level....
Definition: dofmapper.hh:43
mapper allocating one DoF per subentity of a given codimension
Definition: powermapper.hh:330
Mapper interface.
Definition: mapper.hh:110
void removeIndexSet(const IndexSetType &iset)
removed index set from dof manager's list of index sets
Definition: dofmanager.hh:1331
static ThisType & instance(const GridType &grid)
obtain a reference to the DofManager for a given grid
Definition: dofmanager.hh:1251
void addIndexSet(const IndexSetType &iset)
add index set to dof manager's list of index sets
Definition: dofmanager.hh:1296
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Some useful basic math stuff.
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)