dune-fem  2.8-git
dynamicnonblockmapper.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DYNAMICNONBLOCKMAPPER_HH
2 #define DUNE_FEM_DYNAMICNONBLOCKMAPPER_HH
3 
4 #include <vector>
5 
10 
11 namespace Dune
12 {
13 
14  namespace Fem
15  {
16 
17  // Internal Forward Declarations
18  // -----------------------------
19 
20  template< class BlockMapper >
21  class DynamicNonBlockMapper;
22 
23 
24  namespace __DynamicNonBlockMapper
25  {
26 
27  // Traits
28  // ------
29 
30  template< class BlockMapper >
31  struct Traits
32  {
34 
35  typedef BlockMapper BlockMapperType;
36  typedef typename BlockMapper::ElementType ElementType;
37  typedef typename BlockMapper::SizeType SizeType;
38  typedef typename BlockMapper::GlobalKeyType GlobalKeyType;
39  };
40 
41 
42  // DofMapper
43  // ---------
44 
45  template< class T, template< class > class Base = Dune::Fem::DofMapper >
46  class DofMapper
47  : public Base< T >
48  {
49  typedef Base< T > BaseType;
50 
51  template< class, template< class > class >
52  friend class DofMapper;
53 
54  public:
55  typedef typename BaseType::Traits Traits;
56 
58 
59  typedef typename Traits::ElementType ElementType;
60  typedef typename Traits::SizeType SizeType;
62 
63  private:
64  template< class Functor >
65  struct BlockFunctor
66  {
67  explicit BlockFunctor ( int blockSize, Functor functor )
68  : blockSize_( blockSize ), functor_( functor )
69  {}
70 
71  template< class GlobalKey >
72  void operator() ( int localBlock, const GlobalKey globalKey )
73  {
74  int localDof = blockSize_*localBlock;
75  SizeType globalDof = blockSize_*globalKey;
76  const int localEnd = localDof + blockSize_;
77  while( localDof != localEnd )
78  functor_( localDof++, globalDof++ );
79  }
80 
81  private:
82  int blockSize_;
83  Functor functor_;
84  };
85 
86  public:
88  : blockMapper_( blockMapper ), blockSize_( blockSize )
89  {}
90 
91  SizeType size () const { return blockSize() * blockMapper_.size(); }
92 
93  bool contains ( const int codim ) const { return blockMapper_.contains( codim ); }
94 
95  bool fixedDataSize ( int codim ) const { return blockMapper_.fixedDataSize( codim ); }
96 
97  template< class Functor >
98  void mapEach ( const ElementType &element, Functor f ) const
99  {
100  blockMapper_.mapEach( element, BlockFunctor< Functor >( blockSize(), f ) );
101  }
102 
103  void map ( const ElementType &element, std::vector< GlobalKeyType > &indices ) const
104  {
105  indices.resize( numDofs( element ) );
106  mapEach( element, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
107  }
108 
109  void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
110  {
111  const SizeType numDofs = blockMapper_.numDofs( element );
112  blockMapper_.onSubEntity( element, i, c, indices );
113  indices.resize( blockSize() * numDofs );
114  for( SizeType i = numDofs; i > 0; )
115  {
116  for( int j = 0; j < blockSize(); ++j )
117  indices[ i*blockSize() + j ] = indices[ i ];
118  }
119  }
120 
121  template< class Entity, class Functor >
122  void mapEachEntityDof ( const Entity &entity, Functor f ) const
123  {
124  blockMapper_.mapEachEntityDof( entity, BlockFunctor< Functor >( blockSize(), f ) );
125  }
126 
127  template< class Entity >
128  void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const
129  {
130  indices.resize( numEntityDofs( entity ) );
131  mapEachEntityDof( entity, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
132  }
133 
134  int maxNumDofs () const { return blockSize() * blockMapper_.maxNumDofs(); }
135 
136  SizeType numDofs ( const ElementType &element ) const { return blockSize() * blockMapper_.numDofs( element ); }
137 
138  template< class Entity >
139  SizeType numEntityDofs ( const Entity &entity ) const { return blockSize() * blockMapper_.numEntityDofs( entity ); }
140 
141  static constexpr bool consecutive () noexcept { return false; }
142 
144  {
145  DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
146  }
147 
148  SizeType numberOfHoles ( int ) const
149  {
150  DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
151  }
152 
153  GlobalKeyType oldIndex ( int hole, int ) const
154  {
155  DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
156  }
157 
158  GlobalKeyType newIndex ( int hole, int ) const
159  {
160  DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
161  }
162 
163  SizeType oldOffSet ( int ) const
164  {
165  DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
166  }
167 
168  SizeType offSet ( int ) const
169  {
170  DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
171  }
172 
173  const BlockMapperType &blockMapper () const { return blockMapper_; }
174  int blockSize () const { return blockSize_; }
175 
176  private:
177  BlockMapperType &blockMapper_;
178  int blockSize_;
179  };
180 
181 
182  // AdaptiveDofMapper
183  // -----------------
184 
185  template< class T >
187  : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
188  {
190 
191  template< class >
192  friend class AdaptiveDofMapper;
193 
194  public:
195  typedef typename BaseType::Traits Traits;
196 
198 
199  using BaseType::blockMapper;
200  using BaseType::blockSize;
201 
203  typedef typename Traits::SizeType SizeType;
205 
208  {}
209 
210  bool consecutive () const { return blockMapper().consecutive(); }
211 
212  SizeType numBlocks () const { return blockMapper().numBlocks(); }
213 
214  SizeType numberOfHoles ( int block ) const { return blockSize() * blockMapper().numberOfHoles( block ); }
215 
216  GlobalKeyType oldIndex ( int hole, int block ) const
217  {
218  const int i = hole % blockSize();
219  const int blockHole = hole / blockSize();
220  return blockMapper().oldIndex( blockHole, block ) * blockSize() + i;
221  }
222 
223  GlobalKeyType newIndex ( int hole, int block ) const
224  {
225  const int i = hole % blockSize;
226  const int blockHole = hole / blockSize();
227  return blockMapper().newIndex( blockHole, block ) * blockSize() + i;
228  }
229 
230  SizeType oldOffSet ( const int block ) const { return blockMapper().oldOffSet( block ) * blockSize(); }
231 
232  SizeType offSet ( const int block ) const { return blockMapper().offSet( block ) * blockSize(); }
233  };
234 
235 
236  // Implementation
237  // --------------
238 
239  template< class BlockMapper, bool adaptive = Capabilities::isAdaptiveDofMapper< BlockMapper >::v >
241  {
243 
244  public:
245  typedef typename std::conditional< adaptive, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type;
246  };
247 
248  } // namespace __DynamicNonBlockMapper
249 
250 
251 
252  // DynamicNonBlockMapper
253  // ---------------------
254 
256  template< class BlockMapper >
258  : public __DynamicNonBlockMapper::template Implementation< BlockMapper >::Type
259  {
260  typedef typename __DynamicNonBlockMapper::template Implementation< BlockMapper >::Type BaseType;
261 
262  public:
263  DynamicNonBlockMapper ( BlockMapper &blockMapper, int blockSize )
264  : BaseType( blockMapper, blockSize )
265  {}
266  };
267 
268 
269 
270  // DynamicNonBlockMapper for DynamicNonBlockMapper
271  // -----------------------------------------------
272 
273  template< class BlockMapper >
275  : public DynamicNonBlockMapper< BlockMapper >
276  {
278  typedef DynamicNonBlockMapper< BlockMapper > BaseType;
279 
280  public:
281  explicit DynamicNonBlockMapper ( const DynamicNonBlockMapper< BlockMapper > &blockMapper, int blockSize )
282  : BaseType( blockMapper.blockMapper(), blockMapper.blockSize() * blockSize )
283  {}
284  };
285 
286 
287 
288  // DynamicNonBlockMapper for NonBlockMapper
289  // ----------------------------------------
290 
291  template< class BlockMapper, int innerBlockSize >
292  class DynamicNonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize > >
293  : public DynamicNonBlockMapper< BlockMapper >
294  {
296  typedef DynamicNonBlockMapper< BlockMapper > BaseType;
297 
298  public:
299  explicit DynamicNonBlockMapper ( const NonBlockMapper< BlockMapper, innerBlockSize > &blockMapper, int blockSize )
300  : BaseType( blockMapper.blockMapper(), innerBlockSize * blockSize )
301  {}
302  };
303 
304 
305 
306  // NonBlockMapper for DynamicNonBlockMapper
307  // ----------------------------------------
308 
309  template< class BlockMapper, int outerBlockSize >
310  class NonBlockMapper< DynamicNonBlockMapper< BlockMapper >, outerBlockSize >
311  : public DynamicNonBlockMapper< BlockMapper >
312  {
314  typedef DynamicNonBlockMapper< BlockMapper > BaseType;
315 
316  public:
317  explicit NonBlockMapper ( const DynamicNonBlockMapper< BlockMapper > &blockMapper )
318  : BaseType( blockMapper.blockMapper(), outerBlockSize * blockMapper.blockSize() )
319  {}
320  };
321 
322 
323 
324  // Capabilities
325  // ------------
326 
327  namespace Capabilities
328  {
329  template< class BlockMapper >
331  {
333  };
334 
335  template< class BlockMapper >
336  struct isConsecutiveIndexSet< __DynamicNonBlockMapper::AdaptiveDofMapper< __DynamicNonBlockMapper::Traits< BlockMapper > > >
337  {
339  };
340 
341  } // namespace Capabilities
342 
343  } // namespace Fem
344 
345 } // namespace Dune
346 
347 #endif // #ifndef DUNE_FEM_DYNAMICNONBLOCKMAPPER_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: dynamicnonblockmapper.hh:259
DynamicNonBlockMapper(BlockMapper &blockMapper, int blockSize)
Definition: dynamicnonblockmapper.hh:263
Definition: dynamicnonblockmapper.hh:32
DynamicNonBlockMapper< BlockMapper > DofMapperType
Definition: dynamicnonblockmapper.hh:33
BlockMapper::GlobalKeyType GlobalKeyType
Definition: dynamicnonblockmapper.hh:38
BlockMapper::ElementType ElementType
Definition: dynamicnonblockmapper.hh:36
BlockMapper BlockMapperType
Definition: dynamicnonblockmapper.hh:35
BlockMapper::SizeType SizeType
Definition: dynamicnonblockmapper.hh:37
Definition: dynamicnonblockmapper.hh:48
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
Definition: dynamicnonblockmapper.hh:109
int maxNumDofs() const
Definition: dynamicnonblockmapper.hh:134
Traits::ElementType ElementType
Definition: dynamicnonblockmapper.hh:59
int blockSize() const
Definition: dynamicnonblockmapper.hh:174
GlobalKeyType newIndex(int hole, int) const
Definition: dynamicnonblockmapper.hh:158
SizeType numBlocks() const
Definition: dynamicnonblockmapper.hh:143
void mapEach(const ElementType &element, Functor f) const
Definition: dynamicnonblockmapper.hh:98
Traits::GlobalKeyType GlobalKeyType
Definition: dynamicnonblockmapper.hh:61
Traits::SizeType SizeType
Definition: dynamicnonblockmapper.hh:60
void mapEntityDofs(const Entity &entity, std::vector< GlobalKeyType > &indices) const
Definition: dynamicnonblockmapper.hh:128
SizeType oldOffSet(int) const
Definition: dynamicnonblockmapper.hh:163
SizeType numDofs(const ElementType &element) const
Definition: dynamicnonblockmapper.hh:136
Traits::BlockMapperType BlockMapperType
Definition: dynamicnonblockmapper.hh:57
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition: dynamicnonblockmapper.hh:122
SizeType numEntityDofs(const Entity &entity) const
Definition: dynamicnonblockmapper.hh:139
void map(const ElementType &element, std::vector< GlobalKeyType > &indices) const
Definition: dynamicnonblockmapper.hh:103
GlobalKeyType oldIndex(int hole, int) const
Definition: dynamicnonblockmapper.hh:153
bool contains(const int codim) const
Definition: dynamicnonblockmapper.hh:93
DofMapper(BlockMapperType &blockMapper, int blockSize)
Definition: dynamicnonblockmapper.hh:87
SizeType size() const
Definition: dynamicnonblockmapper.hh:91
static constexpr bool consecutive() noexcept
Definition: dynamicnonblockmapper.hh:141
SizeType offSet(int) const
Definition: dynamicnonblockmapper.hh:168
bool fixedDataSize(int codim) const
Definition: dynamicnonblockmapper.hh:95
const BlockMapperType & blockMapper() const
Definition: dynamicnonblockmapper.hh:173
BaseType::Traits Traits
Definition: dynamicnonblockmapper.hh:55
SizeType numberOfHoles(int) const
Definition: dynamicnonblockmapper.hh:148
Definition: dynamicnonblockmapper.hh:188
Traits::ElementType ElementType
Definition: dynamicnonblockmapper.hh:202
AdaptiveDofMapper(BlockMapperType &blockMapper, int blockSize)
Definition: dynamicnonblockmapper.hh:206
GlobalKeyType oldIndex(int hole, int block) const
Definition: dynamicnonblockmapper.hh:216
SizeType numberOfHoles(int block) const
Definition: dynamicnonblockmapper.hh:214
bool consecutive() const
Definition: dynamicnonblockmapper.hh:210
SizeType oldOffSet(const int block) const
Definition: dynamicnonblockmapper.hh:230
Traits::GlobalKeyType GlobalKeyType
Definition: dynamicnonblockmapper.hh:204
SizeType offSet(const int block) const
Definition: dynamicnonblockmapper.hh:232
SizeType numBlocks() const
Definition: dynamicnonblockmapper.hh:212
Traits::SizeType SizeType
Definition: dynamicnonblockmapper.hh:203
GlobalKeyType newIndex(int hole, int block) const
Definition: dynamicnonblockmapper.hh:223
Traits::BlockMapperType BlockMapperType
Definition: dynamicnonblockmapper.hh:197
BaseType::Traits Traits
Definition: dynamicnonblockmapper.hh:195
Definition: dynamicnonblockmapper.hh:241
std::conditional< adaptive, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type
Definition: dynamicnonblockmapper.hh:245
DynamicNonBlockMapper(const DynamicNonBlockMapper< BlockMapper > &blockMapper, int blockSize)
Definition: dynamicnonblockmapper.hh:281
DynamicNonBlockMapper(const NonBlockMapper< BlockMapper, innerBlockSize > &blockMapper, int blockSize)
Definition: dynamicnonblockmapper.hh:299
NonBlockMapper(const DynamicNonBlockMapper< BlockMapper > &blockMapper)
Definition: dynamicnonblockmapper.hh:317
Definition: nonblockmapper.hh:263