DUNE-FEM (unstable)

dynamicnonblockmapper.hh
1#warning LOOKS LIKE AN UNUSED HEADER THAT WILL BE REMOVE - IF YOU SEE THIS THE THAT STATEMENT IS APPARENTLY WRONG
2
3#ifndef DUNE_FEM_DYNAMICNONBLOCKMAPPER_HH
4#define DUNE_FEM_DYNAMICNONBLOCKMAPPER_HH
5
6#include <vector>
7
8#include <dune/fem/gridpart/common/indexset.hh>
9#include <dune/fem/misc/functor.hh>
10#include <dune/fem/space/mapper/dofmapper.hh>
11#include <dune/fem/space/mapper/nonblockmapper.hh>
12
13namespace Dune
14{
15
16 namespace Fem
17 {
18
19 // Internal Forward Declarations
20 // -----------------------------
21
22 template< class BlockMapper >
23 class DynamicNonBlockMapper;
24
25
26 namespace __DynamicNonBlockMapper
27 {
28
29 // Traits
30 // ------
31
32 template< class BlockMapper >
33 struct Traits
34 {
35 typedef DynamicNonBlockMapper< BlockMapper > DofMapperType;
36
37 typedef BlockMapper BlockMapperType;
38 typedef typename BlockMapper::ElementType ElementType;
39 typedef typename BlockMapper::SizeType SizeType;
40 typedef typename BlockMapper::GlobalKeyType GlobalKeyType;
41 };
42
43
44 // DofMapper
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 template< class, template< class > class >
54 friend class DofMapper;
55
56 public:
57 typedef typename BaseType::Traits Traits;
58
59 typedef typename Traits::BlockMapperType BlockMapperType;
60
61 typedef typename Traits::ElementType ElementType;
62 typedef typename Traits::SizeType SizeType;
63 typedef typename Traits::GlobalKeyType GlobalKeyType;
64
65 private:
66 template< class Functor >
67 struct BlockFunctor
68 {
69 explicit BlockFunctor ( int blockSize, Functor functor )
70 : blockSize_( blockSize ), functor_( functor )
71 {}
72
73 template< class GlobalKey >
74 void operator() ( int localBlock, const GlobalKey globalKey )
75 {
76 int localDof = blockSize_*localBlock;
77 SizeType globalDof = blockSize_*globalKey;
78 const int localEnd = localDof + blockSize_;
79 while( localDof != localEnd )
80 functor_( localDof++, globalDof++ );
81 }
82
83 private:
84 int blockSize_;
85 Functor functor_;
86 };
87
88 public:
89 DofMapper ( BlockMapperType &blockMapper, int blockSize )
90 : blockMapper_( blockMapper ), blockSize_( blockSize )
91 {}
92
93 SizeType size () const { return blockSize() * blockMapper_.size(); }
94
95 bool contains ( const int codim ) const { return blockMapper_.contains( codim ); }
96
97 bool fixedDataSize ( int codim ) const { return blockMapper_.fixedDataSize( codim ); }
98
99 template< class Functor >
100 void mapEach ( const ElementType &element, Functor f ) const
101 {
102 blockMapper_.mapEach( element, BlockFunctor< Functor >( blockSize(), f ) );
103 }
104
105 void map ( const ElementType &element, std::vector< GlobalKeyType > &indices ) const
106 {
107 indices.resize( numDofs( element ) );
108 mapEach( element, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
109 }
110
111 [[deprecated("Use onSubEntity method with char vector instead")]]
112 void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
113 {
114 std::vector< char > _idx;
115 onSubEntity(element, i, c, _idx);
116 indices.resize( _idx.size() );
117 for (std::size_t i=0; i<_idx.size();++i)
118 _idx[i] = indices[i] > 0;
119 }
120 // this method returns which local dofs are attached to the given subentity.
121 // indices[locDofNr] =
122 // 0 : not attached, not equal to 0 : attached
123 // (so this method can still be used in the way the deprecated method was).
124 // New: In case the dof can be associated to a component of the
125 // space, the value returned is that component+1. In other
126 // cases (normal velocity for RT for example) the value is always 1).
127 // So indices[i] is in [0,dimRange+1]
128 void onSubEntity ( const ElementType &element, int i, int c, std::vector< char > &indices ) const
129 {
130 const SizeType numDofs = blockMapper_.numDofs( element );
131 blockMapper_.onSubEntity( element, i, c, indices );
132 indices.resize( blockSize() * numDofs );
133 for( SizeType i = numDofs-1; i!=SizeType(-1) ; --i )
134 {
135 for( int j = 0; j < blockSize(); ++j )
136 indices[ i*blockSize() + j ] = ( indices[ i ]==0)? 0 : j+1;
137 }
138 }
139
140 template< class Entity, class Functor >
141 void mapEachEntityDof ( const Entity &entity, Functor f ) const
142 {
143 blockMapper_.mapEachEntityDof( entity, BlockFunctor< Functor >( blockSize(), f ) );
144 }
145
146 template< class Entity >
147 void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const
148 {
149 indices.resize( numEntityDofs( entity ) );
150 mapEachEntityDof( entity, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
151 }
152
153 int maxNumDofs () const { return blockSize() * blockMapper_.maxNumDofs(); }
154
155 SizeType numDofs ( const ElementType &element ) const { return blockSize() * blockMapper_.numDofs( element ); }
156
157 template< class Entity >
158 SizeType numEntityDofs ( const Entity &entity ) const { return blockSize() * blockMapper_.numEntityDofs( entity ); }
159
160 static constexpr bool consecutive () noexcept { return false; }
161
162 SizeType numBlocks () const
163 {
164 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
165 }
166
167 SizeType numberOfHoles ( int ) const
168 {
169 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
170 }
171
172 GlobalKeyType oldIndex ( int hole, int ) const
173 {
174 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
175 }
176
177 GlobalKeyType newIndex ( int hole, int ) const
178 {
179 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
180 }
181
182 SizeType oldOffSet ( int ) const
183 {
184 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
185 }
186
187 SizeType offSet ( int ) const
188 {
189 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
190 }
191
192 const BlockMapperType &blockMapper () const { return blockMapper_; }
193 int blockSize () const { return blockSize_; }
194
195 private:
196 BlockMapperType &blockMapper_;
197 int blockSize_;
198 };
199
200
201 // AdaptiveDofMapper
202 // -----------------
203
204 template< class T >
205 class AdaptiveDofMapper
206 : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
207 {
208 typedef DofMapper< T, Dune::Fem::AdaptiveDofMapper > BaseType;
209
210 template< class >
211 friend class AdaptiveDofMapper;
212
213 public:
214 typedef typename BaseType::Traits Traits;
215
216 typedef typename Traits::BlockMapperType BlockMapperType;
217
218 using BaseType::blockMapper;
219 using BaseType::blockSize;
220
221 typedef typename Traits::ElementType ElementType;
222 typedef typename Traits::SizeType SizeType;
223 typedef typename Traits::GlobalKeyType GlobalKeyType;
224
225 AdaptiveDofMapper ( BlockMapperType &blockMapper, int blockSize )
226 : BaseType( blockMapper, blockSize )
227 {}
228
229 bool consecutive () const { return blockMapper().consecutive(); }
230
231 SizeType numBlocks () const { return blockMapper().numBlocks(); }
232
233 SizeType numberOfHoles ( int block ) const { return blockSize() * blockMapper().numberOfHoles( block ); }
234
235 GlobalKeyType oldIndex ( int hole, int block ) const
236 {
237 const int i = hole % blockSize();
238 const int blockHole = hole / blockSize();
239 return blockMapper().oldIndex( blockHole, block ) * blockSize() + i;
240 }
241
242 GlobalKeyType newIndex ( int hole, int block ) const
243 {
244 const int i = hole % blockSize;
245 const int blockHole = hole / blockSize();
246 return blockMapper().newIndex( blockHole, block ) * blockSize() + i;
247 }
248
249 SizeType oldOffSet ( const int block ) const { return blockMapper().oldOffSet( block ) * blockSize(); }
250
251 SizeType offSet ( const int block ) const { return blockMapper().offSet( block ) * blockSize(); }
252 };
253
254
255 // Implementation
256 // --------------
257
258 template< class BlockMapper, bool adaptive = Capabilities::isAdaptiveDofMapper< BlockMapper >::v >
259 class Implementation
260 {
261 typedef __DynamicNonBlockMapper::Traits< BlockMapper > Traits;
262
263 public:
264 typedef typename std::conditional< adaptive, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type;
265 };
266
267 } // namespace __DynamicNonBlockMapper
268
269
270
271 // DynamicNonBlockMapper
272 // ---------------------
273
275 template< class BlockMapper >
277 : public __DynamicNonBlockMapper::template Implementation< BlockMapper >::Type
278 {
279 typedef typename __DynamicNonBlockMapper::template Implementation< BlockMapper >::Type BaseType;
280
281 public:
282 DynamicNonBlockMapper ( BlockMapper &blockMapper, int blockSize )
283 : BaseType( blockMapper, blockSize )
284 {}
285 };
286
287
288
289 // DynamicNonBlockMapper for DynamicNonBlockMapper
290 // -----------------------------------------------
291
292 template< class BlockMapper >
293 class DynamicNonBlockMapper< DynamicNonBlockMapper< BlockMapper > >
294 : public DynamicNonBlockMapper< BlockMapper >
295 {
298
299 public:
300 explicit DynamicNonBlockMapper ( const DynamicNonBlockMapper< BlockMapper > &blockMapper, int blockSize )
301 : BaseType( blockMapper.blockMapper(), blockMapper.blockSize() * blockSize )
302 {}
303 };
304
305
306
307 // DynamicNonBlockMapper for NonBlockMapper
308 // ----------------------------------------
309
310 template< class BlockMapper, int innerBlockSize >
311 class DynamicNonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize > >
312 : public DynamicNonBlockMapper< BlockMapper >
313 {
314 typedef DynamicNonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize > > ThisType;
315 typedef DynamicNonBlockMapper< BlockMapper > BaseType;
316
317 public:
318 explicit DynamicNonBlockMapper ( const NonBlockMapper< BlockMapper, innerBlockSize > &blockMapper, int blockSize )
319 : BaseType( blockMapper.blockMapper(), innerBlockSize * blockSize )
320 {}
321 };
322
323
324
325 // NonBlockMapper for DynamicNonBlockMapper
326 // ----------------------------------------
327
328 template< class BlockMapper, int outerBlockSize >
329 class NonBlockMapper< DynamicNonBlockMapper< BlockMapper >, outerBlockSize >
330 : public DynamicNonBlockMapper< BlockMapper >
331 {
332 typedef NonBlockMapper< DynamicNonBlockMapper< BlockMapper >, outerBlockSize > ThisType;
333 typedef DynamicNonBlockMapper< BlockMapper > BaseType;
334
335 public:
336 explicit NonBlockMapper ( const DynamicNonBlockMapper< BlockMapper > &blockMapper )
337 : BaseType( blockMapper.blockMapper(), outerBlockSize * blockMapper.blockSize() )
338 {}
339 };
340
341
342
343 // Capabilities
344 // ------------
345
346 namespace Capabilities
347 {
348 template< class BlockMapper >
349 struct isAdaptiveDofMapper< DynamicNonBlockMapper< BlockMapper > >
350 {
351 static const bool v = isAdaptiveDofMapper< BlockMapper >::v;
352 };
353
354 template< class BlockMapper >
355 struct isConsecutiveIndexSet< __DynamicNonBlockMapper::AdaptiveDofMapper< __DynamicNonBlockMapper::Traits< BlockMapper > > >
356 {
357 static const bool v = isConsecutiveIndexSet< BlockMapper >::v;
358 };
359
360 } // namespace Capabilities
361
362 } // namespace Fem
363
364} // namespace Dune
365
366#endif // #ifndef DUNE_FEM_DYNAMICNONBLOCKMAPPER_HH
Interface for calculating the size of a function space for a grid on a specified level....
Definition: dofmapper.hh:43
SizeType numDofs(const ElementType &element) const
obtain number of DoFs on an entity
Definition: dofmapper.hh:164
void mapEach(const ElementType &element, Functor f) const
map each local DoF number to a global key
Definition: dofmapper.hh:116
Definition: dynamicnonblockmapper.hh:278
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
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 (Nov 13, 23:29, 2024)