dune-fem 2.12-git
Loading...
Searching...
No Matches
dynamicnonblockmapper.hh
Go to the documentation of this file.
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
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 {
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 >
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
60
62 typedef typename Traits::SizeType SizeType;
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:
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 {
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
163 {
164 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
165 }
166
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 >
206 : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
207 {
209
210 template< class >
211 friend class AdaptiveDofMapper;
212
213 public:
214 typedef typename BaseType::Traits Traits;
215
217
220
222 typedef typename Traits::SizeType SizeType;
224
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 >
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 >
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 {
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 {
334
335 public:
337 : BaseType( blockMapper.blockMapper(), outerBlockSize * blockMapper.blockSize() )
338 {}
339 };
340
341
342
343 // Capabilities
344 // ------------
345
346 namespace Capabilities
347 {
348 template< class BlockMapper >
350 {
352 };
353
354 template< class BlockMapper >
355 struct isConsecutiveIndexSet< __DynamicNonBlockMapper::AdaptiveDofMapper< __DynamicNonBlockMapper::Traits< BlockMapper > > >
356 {
358 };
359
360 } // namespace Capabilities
361
362 } // namespace Fem
363
364} // namespace Dune
365
366#endif // #ifndef DUNE_FEM_DYNAMICNONBLOCKMAPPER_HH
virtual void operator()()=0
#define DUNE_THROW(E,...)
const GlobalIndex & global() const
LocalIndex & local()
specialize with true if index set implements the interface for consecutive index sets
Definition common/indexset.hh:61
static const bool v
Definition common/indexset.hh:68
Definition space/mapper/capabilities.hh:22
static const bool v
Definition space/mapper/capabilities.hh:23
Interface for calculating the size of a function space for a grid on a specified level....
Definition mapper/dofmapper.hh:43
Extended interface for adaptive DoF mappers.
Definition mapper/dofmapper.hh:219
Definition dynamicnonblockmapper.hh:278
DynamicNonBlockMapper(BlockMapper &blockMapper, int blockSize)
Definition dynamicnonblockmapper.hh:282
Definition dynamicnonblockmapper.hh:34
DynamicNonBlockMapper< BlockMapper > DofMapperType
Definition dynamicnonblockmapper.hh:35
BlockMapper::GlobalKeyType GlobalKeyType
Definition dynamicnonblockmapper.hh:40
BlockMapper::ElementType ElementType
Definition dynamicnonblockmapper.hh:38
BlockMapper BlockMapperType
Definition dynamicnonblockmapper.hh:37
BlockMapper::SizeType SizeType
Definition dynamicnonblockmapper.hh:39
Definition dynamicnonblockmapper.hh:50
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
Definition dynamicnonblockmapper.hh:112
int maxNumDofs() const
Definition dynamicnonblockmapper.hh:153
Traits::ElementType ElementType
Definition dynamicnonblockmapper.hh:61
int blockSize() const
Definition dynamicnonblockmapper.hh:193
GlobalKeyType newIndex(int hole, int) const
Definition dynamicnonblockmapper.hh:177
SizeType numBlocks() const
Definition dynamicnonblockmapper.hh:162
void mapEach(const ElementType &element, Functor f) const
Definition dynamicnonblockmapper.hh:100
Traits::GlobalKeyType GlobalKeyType
Definition dynamicnonblockmapper.hh:63
Traits::SizeType SizeType
Definition dynamicnonblockmapper.hh:62
void mapEntityDofs(const Entity &entity, std::vector< GlobalKeyType > &indices) const
Definition dynamicnonblockmapper.hh:147
SizeType oldOffSet(int) const
Definition dynamicnonblockmapper.hh:182
SizeType numDofs(const ElementType &element) const
Definition dynamicnonblockmapper.hh:155
Traits::BlockMapperType BlockMapperType
Definition dynamicnonblockmapper.hh:59
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition dynamicnonblockmapper.hh:141
SizeType numEntityDofs(const Entity &entity) const
Definition dynamicnonblockmapper.hh:158
void map(const ElementType &element, std::vector< GlobalKeyType > &indices) const
Definition dynamicnonblockmapper.hh:105
GlobalKeyType oldIndex(int hole, int) const
Definition dynamicnonblockmapper.hh:172
bool contains(const int codim) const
Definition dynamicnonblockmapper.hh:95
DofMapper(BlockMapperType &blockMapper, int blockSize)
Definition dynamicnonblockmapper.hh:89
void onSubEntity(const ElementType &element, int i, int c, std::vector< char > &indices) const
Definition dynamicnonblockmapper.hh:128
SizeType size() const
Definition dynamicnonblockmapper.hh:93
static constexpr bool consecutive() noexcept
Definition dynamicnonblockmapper.hh:160
SizeType offSet(int) const
Definition dynamicnonblockmapper.hh:187
bool fixedDataSize(int codim) const
Definition dynamicnonblockmapper.hh:97
const BlockMapperType & blockMapper() const
Definition dynamicnonblockmapper.hh:192
BaseType::Traits Traits
Definition dynamicnonblockmapper.hh:57
SizeType numberOfHoles(int) const
Definition dynamicnonblockmapper.hh:167
Definition dynamicnonblockmapper.hh:207
Traits::ElementType ElementType
Definition dynamicnonblockmapper.hh:221
AdaptiveDofMapper(BlockMapperType &blockMapper, int blockSize)
Definition dynamicnonblockmapper.hh:225
GlobalKeyType oldIndex(int hole, int block) const
Definition dynamicnonblockmapper.hh:235
SizeType numberOfHoles(int block) const
Definition dynamicnonblockmapper.hh:233
bool consecutive() const
Definition dynamicnonblockmapper.hh:229
SizeType oldOffSet(const int block) const
Definition dynamicnonblockmapper.hh:249
Traits::GlobalKeyType GlobalKeyType
Definition dynamicnonblockmapper.hh:223
SizeType offSet(const int block) const
Definition dynamicnonblockmapper.hh:251
SizeType numBlocks() const
Definition dynamicnonblockmapper.hh:231
Traits::SizeType SizeType
Definition dynamicnonblockmapper.hh:222
GlobalKeyType newIndex(int hole, int block) const
Definition dynamicnonblockmapper.hh:242
Traits::BlockMapperType BlockMapperType
Definition dynamicnonblockmapper.hh:216
BaseType::Traits Traits
Definition dynamicnonblockmapper.hh:214
Definition dynamicnonblockmapper.hh:260
std::conditional< adaptive, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type
Definition dynamicnonblockmapper.hh:264
DynamicNonBlockMapper(const DynamicNonBlockMapper< BlockMapper > &blockMapper, int blockSize)
Definition dynamicnonblockmapper.hh:300
DynamicNonBlockMapper(const NonBlockMapper< BlockMapper, innerBlockSize > &blockMapper, int blockSize)
Definition dynamicnonblockmapper.hh:318
NonBlockMapper(const DynamicNonBlockMapper< BlockMapper > &blockMapper)
Definition dynamicnonblockmapper.hh:336
Definition nonblockmapper.hh:284
T resize(T... args)
T size(T... args)