dune-fem 2.8.0
Loading...
Searching...
No Matches
nonblockmapper.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_NONBLOCKMAPPER_HH
2#define DUNE_FEM_NONBLOCKMAPPER_HH
3
4#include <vector>
5
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 {
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 >
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
59 static const int blockSize = Traits::blockSize;
60
62 typedef typename Traits::SizeType SizeType;
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:
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 void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
111 {
112 const SizeType numDofs = blockMapper_.numDofs( element );
113 blockMapper_.onSubEntity( element, i, c, indices );
114 indices.resize( blockSize * numDofs );
115 for( SizeType i = numDofs; i > 0; )
116 {
117 for( int j = 0; j < blockSize; ++j )
118 indices[ i*blockSize + j ] = indices[ i ];
119 }
120 }
121
122 template< class Entity, class Functor >
123 void mapEachEntityDof ( const Entity &entity, Functor f ) const
124 {
125 blockMapper_.mapEachEntityDof( entity, BlockFunctor< Functor >( std::forward< Functor >( f ) ) );
126 }
127
128 template< class Entity >
129 void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const
130 {
131 indices.resize( numEntityDofs( entity ) );
132 mapEachEntityDof( entity, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
133 }
134
135 int maxNumDofs () const { return blockSize * blockMapper_.maxNumDofs(); }
136
137 SizeType numDofs ( const ElementType &element ) const { return blockSize * blockMapper_.numDofs( element ); }
138
139 template< class Entity >
140 SizeType numEntityDofs ( const Entity &entity ) const { return blockSize * blockMapper_.numEntityDofs( entity ); }
141
142 static constexpr bool consecutive () noexcept { return false; }
143
145 {
146 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
147 }
148
150 {
151 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
152 }
153
154 GlobalKeyType oldIndex ( int hole, int ) const
155 {
156 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
157 }
158
159 GlobalKeyType newIndex ( int hole, int ) const
160 {
161 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
162 }
163
164 SizeType oldOffSet ( int ) const
165 {
166 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
167 }
168
169 SizeType offSet ( int ) const
170 {
171 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
172 }
173
174 const BlockMapperType &blockMapper () const { return blockMapper_; }
175
176 void update () { blockMapper_.update(); }
177
178 private:
179 BlockMapperType &blockMapper_;
180 };
181
182
183 // AdaptiveDofMapper
184 // -----------------
185
186 template< class T >
188 : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
189 {
191
192 template< class >
193 friend class AdaptiveDofMapper;
194
195 public:
196 typedef typename BaseType::Traits Traits;
197
199
200 static const int blockSize = Traits::blockSize;
201
202 using BaseType::blockMapper;
203
205 typedef typename Traits::SizeType SizeType;
207
209 : BaseType( blockMapper )
210 {}
211
212 bool consecutive () const { return blockMapper().consecutive(); }
213
214 SizeType numBlocks () const { return blockMapper().numBlocks(); }
215
216 SizeType numberOfHoles ( const int block ) const { return blockSize * blockMapper().numberOfHoles( block ); }
217
218 GlobalKeyType oldIndex ( const int hole, const int block ) const
219 {
220 const int i = hole % blockSize;
221 const int blockHole = hole / blockSize;
222 return blockMapper().oldIndex( blockHole, block ) * blockSize + i;
223 }
224
225 GlobalKeyType newIndex ( const int hole, const int block ) const
226 {
227 const int i = hole % blockSize;
228 const int blockHole = hole / blockSize;
229 return blockMapper().newIndex( blockHole, block ) * blockSize + i;
230 }
231
232 SizeType oldOffSet ( const int block ) const { return blockMapper().oldOffSet( block ) * blockSize; }
233
234 SizeType offSet ( const int block ) const { return blockMapper().offSet( block ) * blockSize; }
235 };
236
237
238
239 // Implementation
240 // --------------
241
242 template< class BlockMapper, int blockSize, bool adaptive = Capabilities::isAdaptiveDofMapper< BlockMapper >::v >
244 {
246
247 public:
248 typedef typename std::conditional< adaptive,
251 };
252
253 } // namespace __NonBlockMapper
254
255
256 // NonBlockMapper
257 // --------------
258
260 template< class BlockMapper, int blockSize >
262 : public __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type
263 {
264 typedef typename __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type BaseType;
265
266 public:
267
268 NonBlockMapper ( BlockMapper &blockMapper )
269 : BaseType( blockMapper )
270 {}
271 };
272
273
274 // NonBlockMapper for NonBlockMapper
275 // ---------------------------------
276
277 template< class BlockMapper, int innerBlockSize, int outerBlockSize >
278 class NonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize >, outerBlockSize >
279 : public NonBlockMapper< BlockMapper, innerBlockSize *outerBlockSize >
280 {
283
284 public:
286 : BaseType( blockMapper.blockMapper_ )
287 {}
288 };
289
290
291 // Capabilities
292 // ------------
293
294 namespace Capabilities
295 {
296 template< class BlockMapper, int blockSize >
297 struct isAdaptiveDofMapper< NonBlockMapper< BlockMapper, blockSize > >
298 {
300 };
301
302 template< class BlockMapper, int blockSize >
303 struct isConsecutiveIndexSet< __NonBlockMapper::AdaptiveDofMapper< __NonBlockMapper::Traits< BlockMapper, blockSize > > >
304 {
306 };
307
308 } // namespace Capabilities
309
310 } // namespace Fem
311
312} // namespace Dune
313
314#endif // #ifndef DUNE_FEM_NONBLOCKMAPPER_HH
Definition: bindguard.hh:11
specialize with true if index set implements the interface for consecutive index sets
Definition: common/indexset.hh:42
static const bool v
Definition: common/indexset.hh:49
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: nonblockmapper.hh:263
NonBlockMapper(BlockMapper &blockMapper)
Definition: nonblockmapper.hh:268
Definition: nonblockmapper.hh:31
BlockMapper::ElementType ElementType
Definition: nonblockmapper.hh:35
static const int blockSize
Definition: nonblockmapper.hh:39
NonBlockMapper< BlockMapper, bS > DofMapperType
Definition: nonblockmapper.hh:32
BlockMapper::GlobalKeyType GlobalKeyType
Definition: nonblockmapper.hh:37
BlockMapper BlockMapperType
Definition: nonblockmapper.hh:34
BlockMapper::SizeType SizeType
Definition: nonblockmapper.hh:36
Definition: nonblockmapper.hh:49
DofMapper(BlockMapperType &blockMapper)
Definition: nonblockmapper.hh:88
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
Definition: nonblockmapper.hh:110
Traits::GlobalKeyType GlobalKeyType
Definition: nonblockmapper.hh:63
SizeType size() const
Definition: nonblockmapper.hh:92
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition: nonblockmapper.hh:123
SizeType oldOffSet(int) const
Definition: nonblockmapper.hh:164
void mapEach(const ElementType &element, Functor f) const
Definition: nonblockmapper.hh:99
GlobalKeyType oldIndex(int hole, int) const
Definition: nonblockmapper.hh:154
Traits::BlockMapperType BlockMapperType
Definition: nonblockmapper.hh:58
SizeType offSet(int) const
Definition: nonblockmapper.hh:169
void update()
Definition: nonblockmapper.hh:176
BaseType::Traits Traits
Definition: nonblockmapper.hh:56
static constexpr bool consecutive() noexcept
Definition: nonblockmapper.hh:142
Traits::ElementType ElementType
Definition: nonblockmapper.hh:61
SizeType numDofs(const ElementType &element) const
Definition: nonblockmapper.hh:137
int maxNumDofs() const
Definition: nonblockmapper.hh:135
SizeType numberOfHoles(int) const
Definition: nonblockmapper.hh:149
bool contains(const int codim) const
Definition: nonblockmapper.hh:94
SizeType numBlocks() const
Definition: nonblockmapper.hh:144
void map(const ElementType &element, std::vector< GlobalKeyType > &indices) const
Definition: nonblockmapper.hh:104
bool fixedDataSize(int codim) const
Definition: nonblockmapper.hh:96
static const int blockSize
Definition: nonblockmapper.hh:59
const BlockMapperType & blockMapper() const
Definition: nonblockmapper.hh:174
GlobalKeyType newIndex(int hole, int) const
Definition: nonblockmapper.hh:159
void mapEntityDofs(const Entity &entity, std::vector< GlobalKeyType > &indices) const
Definition: nonblockmapper.hh:129
Traits::SizeType SizeType
Definition: nonblockmapper.hh:62
SizeType numEntityDofs(const Entity &entity) const
Definition: nonblockmapper.hh:140
Definition: nonblockmapper.hh:189
BaseType::Traits Traits
Definition: nonblockmapper.hh:196
SizeType numberOfHoles(const int block) const
Definition: nonblockmapper.hh:216
Traits::SizeType SizeType
Definition: nonblockmapper.hh:205
SizeType numBlocks() const
Definition: nonblockmapper.hh:214
SizeType offSet(const int block) const
Definition: nonblockmapper.hh:234
SizeType oldOffSet(const int block) const
Definition: nonblockmapper.hh:232
static const int blockSize
Definition: nonblockmapper.hh:200
GlobalKeyType oldIndex(const int hole, const int block) const
Definition: nonblockmapper.hh:218
Traits::BlockMapperType BlockMapperType
Definition: nonblockmapper.hh:198
AdaptiveDofMapper(BlockMapperType &blockMapper)
Definition: nonblockmapper.hh:208
Traits::GlobalKeyType GlobalKeyType
Definition: nonblockmapper.hh:206
GlobalKeyType newIndex(const int hole, const int block) const
Definition: nonblockmapper.hh:225
Traits::ElementType ElementType
Definition: nonblockmapper.hh:204
bool consecutive() const
Definition: nonblockmapper.hh:212
Definition: nonblockmapper.hh:244
std::conditional< adaptive, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type
Definition: nonblockmapper.hh:250
NonBlockMapper(const NonBlockMapper< BlockMapper, innerBlockSize > &blockMapper)
Definition: nonblockmapper.hh:285