DUNE-FEM (unstable)

nonblockmapper.hh
1#ifndef DUNE_FEM_NONBLOCKMAPPER_HH
2#define DUNE_FEM_NONBLOCKMAPPER_HH
3
4#include <vector>
5
6#include <dune/fem/gridpart/common/indexset.hh>
7#include <dune/fem/misc/functor.hh>
8#include <dune/fem/space/mapper/dofmapper.hh>
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15
16 // Internal Forward Declarations
17 // -----------------------------
18
19 template< class BlockMapper, int blockSize >
20 class NonBlockMapper;
21
22
23 namespace __NonBlockMapper
24 {
25
26 // Traits
27 // ------
28
29 template< class BlockMapper, int bS >
30 struct Traits
31 {
32 typedef NonBlockMapper< BlockMapper, bS > DofMapperType;
33
34 typedef BlockMapper BlockMapperType;
35 typedef typename BlockMapper::ElementType ElementType;
36 typedef typename BlockMapper::SizeType SizeType;
37 typedef typename BlockMapper::GlobalKeyType GlobalKeyType;
38
39 static const int blockSize = bS;
40 };
41
42
43 // DofMapper
44 // ---------
45
46 template< class T, template< class > class Base = Dune::Fem::DofMapper >
47 class DofMapper
48 : public Base< T >
49 {
50 typedef Base< T > BaseType;
51
52 template< class, template< class > class >
53 friend class DofMapper;
54
55 public:
56 typedef typename BaseType::Traits Traits;
57
58 typedef typename Traits::BlockMapperType BlockMapperType;
59 static const int blockSize = Traits::blockSize;
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 ( Functor functor )
70 : functor_( functor )
71 {}
72
73 template< class GlobalKey >
74 void operator() ( int localBlock, const GlobalKey globalKey ) const
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 Functor functor_;
85 };
86
87 public:
88 DofMapper ( BlockMapperType &blockMapper )
89 : blockMapper_( blockMapper )
90 {}
91
92 SizeType size () const { return blockSize * blockMapper_.size(); }
93
94 bool contains ( const int codim ) const { return blockMapper_.contains( codim ); }
95
96 bool fixedDataSize ( int codim ) const { return blockMapper_.fixedDataSize( codim ); }
97
98 template< class Functor >
99 void mapEach ( const ElementType &element, Functor f ) const
100 {
101 blockMapper_.mapEach( element, BlockFunctor< Functor >( std::forward< Functor >( f ) ) );
102 }
103
104 void map ( const ElementType &element, std::vector< GlobalKeyType > &indices ) const
105 {
106 indices.resize( numDofs( element ) );
107 mapEach( element, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
108 }
109
110 [[deprecated("Use onSubEntity method with char vector instead")]]
111 void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
112 {
113 std::vector< char > _idx;
114 onSubEntity(element, i, c, _idx);
115 indices.resize( _idx.size() );
116 for (std::size_t i=0; i<_idx.size();++i)
117 _idx[i] = indices[i] > 0;
118 }
119 // this method returns which local dofs are attached to the given subentity.
120 // indices[locDofNr] =
121 // 0 : not attached, not equal to 0 : attached
122 // (so this method can still be used in the way the deprecated method was).
123 // New: In case the dof can be associated to a component of the
124 // space, the value returned is that component+1. In other
125 // cases (normal velocity for RT for example) the value is 1).
126 // So indices[i] is in [0,dimRange+1]
127 void onSubEntity ( const ElementType &element, int i, int c, std::vector< char > &indices ) const
128 {
129 const SizeType numDofs = blockMapper_.numDofs( element );
130 blockMapper_.onSubEntity( element, i, c, indices );
131 indices.resize( blockSize * numDofs );
132 for( SizeType i = numDofs-1; i!=SizeType(-1) ; --i )
133 {
134 for( int j = 0; j < blockSize; ++j )
135 {
136 assert( i < indices.size() );
137 assert( i*blockSize+j < indices.size() );
138 indices[ i*blockSize + j ] = (indices[ i ]==0)? 0 : j+1;
139 }
140 }
141 }
142
143 template< class Entity, class Functor >
144 void mapEachEntityDof ( const Entity &entity, Functor f ) const
145 {
146 blockMapper_.mapEachEntityDof( entity, BlockFunctor< Functor >( std::forward< Functor >( f ) ) );
147 }
148
149 template< class Entity >
150 void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const
151 {
152 indices.resize( numEntityDofs( entity ) );
153 mapEachEntityDof( entity, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
154 }
155
156 int maxNumDofs () const { return blockSize * blockMapper_.maxNumDofs(); }
157
158 SizeType numDofs ( const ElementType &element ) const { return blockSize * blockMapper_.numDofs( element ); }
159
160 template< class Entity >
161 SizeType numEntityDofs ( const Entity &entity ) const { return blockSize * blockMapper_.numEntityDofs( entity ); }
162
163 static constexpr bool consecutive () noexcept { return false; }
164
165 SizeType numBlocks () const
166 {
167 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
168 }
169
170 SizeType numberOfHoles ( int ) const
171 {
172 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
173 }
174
175 GlobalKeyType oldIndex ( int hole, int ) const
176 {
177 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
178 }
179
180 GlobalKeyType newIndex ( int hole, int ) const
181 {
182 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
183 }
184
185 SizeType oldOffSet ( int ) const
186 {
187 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
188 }
189
190 SizeType offSet ( int ) const
191 {
192 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
193 }
194
195 const BlockMapperType &blockMapper () const { return blockMapper_; }
196
197 void update () { blockMapper_.update(); }
198
199 private:
200 BlockMapperType &blockMapper_;
201 };
202
203
204 // AdaptiveDofMapper
205 // -----------------
206
207 template< class T >
208 class AdaptiveDofMapper
209 : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
210 {
211 typedef DofMapper< T, Dune::Fem::AdaptiveDofMapper > BaseType;
212
213 template< class >
214 friend class AdaptiveDofMapper;
215
216 public:
217 typedef typename BaseType::Traits Traits;
218
219 typedef typename Traits::BlockMapperType BlockMapperType;
220
221 static const int blockSize = Traits::blockSize;
222
223 using BaseType::blockMapper;
224
225 typedef typename Traits::ElementType ElementType;
226 typedef typename Traits::SizeType SizeType;
227 typedef typename Traits::GlobalKeyType GlobalKeyType;
228
229 AdaptiveDofMapper ( BlockMapperType &blockMapper )
230 : BaseType( blockMapper )
231 {}
232
233 bool consecutive () const { return blockMapper().consecutive(); }
234
235 SizeType numBlocks () const { return blockMapper().numBlocks(); }
236
237 SizeType numberOfHoles ( const int block ) const { return blockSize * blockMapper().numberOfHoles( block ); }
238
239 GlobalKeyType oldIndex ( const int hole, const int block ) const
240 {
241 const int i = hole % blockSize;
242 const int blockHole = hole / blockSize;
243 return blockMapper().oldIndex( blockHole, block ) * blockSize + i;
244 }
245
246 GlobalKeyType newIndex ( const int hole, const int block ) const
247 {
248 const int i = hole % blockSize;
249 const int blockHole = hole / blockSize;
250 return blockMapper().newIndex( blockHole, block ) * blockSize + i;
251 }
252
253 SizeType oldOffSet ( const int block ) const { return blockMapper().oldOffSet( block ) * blockSize; }
254
255 SizeType offSet ( const int block ) const { return blockMapper().offSet( block ) * blockSize; }
256 };
257
258
259
260 // Implementation
261 // --------------
262
263 template< class BlockMapper, int blockSize, bool adaptive = Capabilities::isAdaptiveDofMapper< BlockMapper >::v >
264 class Implementation
265 {
266 typedef __NonBlockMapper::Traits< BlockMapper, blockSize > Traits;
267
268 public:
269 typedef typename std::conditional< adaptive,
270 AdaptiveDofMapper< Traits >,
271 DofMapper< Traits > >::type Type;
272 };
273
274 } // namespace __NonBlockMapper
275
276
277 // NonBlockMapper
278 // --------------
279
281 template< class BlockMapper, int blockSize >
283 : public __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type
284 {
285 typedef typename __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type BaseType;
286
287 public:
288
289 NonBlockMapper ( BlockMapper &blockMapper )
290 : BaseType( blockMapper )
291 {}
292 };
293
294
295 // NonBlockMapper for NonBlockMapper
296 // ---------------------------------
297
298 template< class BlockMapper, int innerBlockSize, int outerBlockSize >
299 class NonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize >, outerBlockSize >
300 : public NonBlockMapper< BlockMapper, innerBlockSize *outerBlockSize >
301 {
302 typedef NonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize >, outerBlockSize > ThisType;
304
305 public:
307 : BaseType( blockMapper.blockMapper_ )
308 {}
309 };
310
311
312 // Capabilities
313 // ------------
314
315 namespace Capabilities
316 {
317 template< class BlockMapper, int blockSize >
318 struct isAdaptiveDofMapper< NonBlockMapper< BlockMapper, blockSize > >
319 {
320 static const bool v = isAdaptiveDofMapper< BlockMapper >::v;
321 };
322
323 template< class BlockMapper, int blockSize >
324 struct isConsecutiveIndexSet< __NonBlockMapper::AdaptiveDofMapper< __NonBlockMapper::Traits< BlockMapper, blockSize > > >
325 {
326 static const bool v = isConsecutiveIndexSet< BlockMapper >::v;
327 };
328
329 } // namespace Capabilities
330
331 } // namespace Fem
332
333} // namespace Dune
334
335#endif // #ifndef DUNE_FEM_NONBLOCKMAPPER_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: nonblockmapper.hh:284
#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 21, 23:30, 2024)