1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH
8#include <dune/common/hybridutilities.hh>
24 template<
class GridPart,
class ... Mapper >
30 namespace __TupleMapper
36 template<
class GridPart,
class ... Mapper >
39 static_assert( Std::are_all_same<
typename Mapper::ElementType ... >::value,
40 "TupleMapper needs common ElementType" );
42 typedef typename std::tuple_element< 0, std::tuple< Mapper ... > >::type FirstMapperType;
43 typedef typename FirstMapperType::ElementType ElementType;
44 typedef typename FirstMapperType::SizeType SizeType;
45 typedef typename FirstMapperType::GlobalKeyType GlobalKeyType;
47 typedef TupleMapper< GridPart, Mapper ... > DofMapperType;
53 template<
class Index,
class Int, Int i >
56 constexpr CombinedIndex ( Index index, Index offset ) : index_( index ), offset_( offset ) {}
58 static constexpr Int component () {
return i; }
60 constexpr operator Index ()
const {
return index_ + offset_; }
62 constexpr Index index ()
const {
return index_; }
64 constexpr Index offset ()
const {
return offset_; }
67 Index index_, offset_;
77 template<
class GridPart,
class ... Mapper,
template<
class >
class Base >
78 class DofMapper< Traits< GridPart, Mapper ... >, Base >
79 :
public Base< Traits< GridPart, Mapper ... > >
81 typedef Base< Traits< GridPart, Mapper ... > > BaseType;
86 template<
class Functor,
int i >
89 FunctorWrapper ( Functor functor,
int localOffset,
int globalOffset )
90 : functor_( functor ),
91 localOffset_( localOffset ),
92 globalOffset_( globalOffset )
95 template<
class GlobalKey >
96 void operator() (
int localDof,
const GlobalKey &globalKey )
const
98 functor_( localDof + localOffset_, CombinedIndex< GlobalKey, int, i >( globalKey, globalOffset_ ) );
101 template<
class GlobalKey >
102 void operator() (
const GlobalKey &globalKey )
const
104 functor_( CombinedIndex< GlobalKey, int, i >( globalKey, globalOffset_ ) );
109 const int localOffset_;
110 const int globalOffset_;
114 static const int mapperTupleSize =
sizeof ... ( Mapper );
116 typedef std::array< typename BaseType::SizeType, mapperTupleSize + 1 > OffsetType;
119 typedef typename BaseType::ElementType ElementType;
120 typedef typename BaseType::SizeType SizeType;
121 typedef typename BaseType::Traits::GlobalKeyType GlobalKeyType;
123 typedef GridPart GridPartType;
125 DofMapper ( GridPartType &gridPart, Mapper & ... mapper )
126 : gridPart_( gridPart ),
127 mapperTuple_( mapper ... )
132 DofMapper ( GridPartType &gridPart, Mapper && ... mapper )
133 : gridPart_( gridPart ),
134 mapperTuple_(
std::move( mapper ) ... )
139 SizeType size ()
const {
return size( std::index_sequence_for< Mapper ... >() ); }
141 bool contains (
const int codim )
const {
return contains( codim, std::index_sequence_for< Mapper ... >() ); }
143 bool fixedDataSize (
int codim )
const {
return fixedDataSize( codim, std::index_sequence_for< Mapper ... >() ); }
145 template<
class Functor >
146 void mapEach (
const ElementType &element, Functor f )
const
148 OffsetType localOffset;
149 localOffset[ 0 ] = 0;
150 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
153 FunctorWrapper< Functor, i > wrappedFunctor( f, localOffset[ i ], globalOffset_[ i ] );
154 std::get< i >( mapperTuple_ ).mapEach( element, wrappedFunctor );
155 localOffset[ i + 1 ] = localOffset[ i ] + std::get< i >( mapperTuple_ ).numDofs( element );
159 template<
class Entity,
class Functor >
160 void mapEachEntityDof (
const Entity &entity, Functor f )
const
162 OffsetType localOffset;
163 localOffset[ 0 ] = 0;
164 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
167 FunctorWrapper< Functor, i > wrappedFunctor( f, localOffset[ i ], globalOffset_[ i ] );
168 std::get< i >( mapperTuple_ ).mapEachEntityDof( entity, wrappedFunctor );
169 localOffset[ i + 1 ] = localOffset[ i ] + std::get< i >( mapperTuple_ ).numEntityDofs( entity );
173 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< bool > &indices )
const
175 DUNE_THROW( NotImplemented,
"Method onSubEntity(...) not yet implemented for TupleMapper" );
178 int maxNumDofs ()
const {
return maxNumDofs( std::index_sequence_for< Mapper ... >() ); }
180 SizeType numDofs (
const ElementType &element )
const {
return numDofs( element, std::index_sequence_for< Mapper ... >() ); }
182 template<
class Entity >
183 SizeType numEntityDofs (
const Entity &entity )
const {
return numEntityDofs( entity, std::index_sequence_for< Mapper ... >() ); }
186 static constexpr bool consecutive () noexcept {
return false; }
188 SizeType numBlocks ()
const
190 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
193 SizeType numberOfHoles (
int )
const
195 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
198 GlobalKeyType oldIndex (
int hole,
int )
const
200 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
203 GlobalKeyType newIndex (
int hole,
int )
const
205 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
208 SizeType oldOffSet (
int )
const
210 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
213 SizeType offSet (
int )
const
215 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
221 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
222 [ & ](
auto i){ std::get< i >( mapperTuple_ ).update(); } );
227 SizeType offset (
int i )
const {
return globalOffset_[ i ]; }
230 SizeType subSize ()
const {
return std::get< i >( mapperTuple_ ).size(); }
233 template< std::size_t ... i >
234 SizeType size ( std::index_sequence< i ... > )
const
236 return Std::sum( std::get< i >( mapperTuple_ ).size() ... );
239 template< std::size_t ... i >
240 bool fixedDataSize (
const int codim, std::index_sequence< i ... > )
const
242 return Std::And( std::get< i >( mapperTuple_ ).fixedDataSize( codim ) ... );
245 template< std::size_t ... i >
246 bool contains (
const int codim, std::index_sequence< i ... > )
const
248 return Std::Or( std::get< i >( mapperTuple_ ).contains( codim ) ... );
251 template< std::size_t ... i >
252 int maxNumDofs ( std::index_sequence< i ... > )
const
254 return Std::sum( std::get< i >( mapperTuple_ ).maxNumDofs() ... );
257 template< std::size_t ... i >
258 SizeType numDofs (
const ElementType &element, std::index_sequence< i ... > )
const
260 return Std::sum( std::get< i >( mapperTuple_ ).numDofs( element ) ... );
263 template<
class Entity, std::size_t ... i >
264 SizeType numEntityDofs (
const Entity &entity, std::index_sequence< i ... > )
const
266 return Std::sum( std::get< i >( mapperTuple_ ).numEntityDofs( entity ) ... );
271 globalOffset_[ 0 ] = 0;
273 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
274 [ & ](
auto i ){ globalOffset_[ i + 1 ] = globalOffset_[ i ] + std::get< i >( mapperTuple_ ).size(); } );
277 GridPartType &gridPart_;
278 std::tuple< Mapper ... > mapperTuple_;
279 OffsetType globalOffset_;
288 class AdaptiveDofMapper;
290 template<
class GridPart,
class ... Mapper >
291 class AdaptiveDofMapper< Traits< GridPart, Mapper ... > >
292 :
public DofMapper< Traits< GridPart, Mapper ... >, Dune::Fem::AdaptiveDofMapper >
299 static const int mapperTupleSize =
sizeof ... ( Mapper );
301 typedef std::array< typename BaseType::Traits::SizeType, mapperTupleSize + 1 > OffsetType;
303 using BaseType::mapperTuple_;
304 using BaseType::gridPart_;
305 using BaseType::globalOffset_;
308 typedef typename BaseType::ElementType ElementType;
309 typedef typename BaseType::SizeType SizeType;
310 typedef typename BaseType::GlobalKeyType GlobalKeyType;
311 typedef GridPart GridPartType;
313 AdaptiveDofMapper ( GridPartType &gridPart, Mapper & ... mapper )
314 : BaseType( gridPart, mapper ... )
316 DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).addIndexSet( *
this );
319 AdaptiveDofMapper ( GridPartType &gridPart, Mapper && ... mapper )
320 : BaseType( gridPart,
std::move( mapper ) ... )
322 DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).addIndexSet( *
this );
325 ~AdaptiveDofMapper () { DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).removeIndexSet( *
this ); }
327 AdaptiveDofMapper (
const AdaptiveDofMapper & ) =
delete;
328 AdaptiveDofMapper ( AdaptiveDofMapper && ) =
delete;
330 static constexpr bool consecutive () noexcept {
return true; }
332 SizeType numBlocks ()
const {
return numBlocks( std::index_sequence_for< Mapper ... >() ); }
334 SizeType numberOfHoles (
int block )
const
338 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
343 const int localBlock = block - std::get< i >( this->mapperTuple_ ).numBlocks();
344 if( localBlock >= 0 )
347 nHoles = std::get< i >( this->mapperTuple_ ).numberOfHoles( localBlock );
353 GlobalKeyType oldIndex (
int hole,
int block )
const
357 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
362 const int localBlock = block - std::get< i >( this->mapperTuple_ ).numBlocks();
363 if( localBlock >= 0 )
366 oIndex = std::get< i >( this->mapperTuple_ ).oldIndex( hole, localBlock );
370 return oIndex + globalOffset_[ comp ];
373 GlobalKeyType newIndex (
int hole,
int block )
const
377 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
382 const int localBlock = block - std::get< i >( this->mapperTuple_ ).numBlocks();
383 if( localBlock >= 0 )
386 nIndex = std::get< i >( this->mapperTuple_ ).newIndex( hole, localBlock );
390 return nIndex + globalOffset_[ comp ];
393 SizeType oldOffSet (
int block )
const
396 SizeType oOffset = 0;
397 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
402 const int localBlock = block - std::get< i >( this->mapperTuple_ ).numBlocks();
403 if( localBlock >= 0 )
406 oOffset = std::get< i >( this->mapperTuple_ ).oldOffSet( localBlock );
410 return oOffset + oldGlobalOffset_[ comp ];
413 SizeType offSet (
int block )
const
417 Hybrid::forEach( std::make_index_sequence< mapperTupleSize >{},
422 const int localBlock = block - std::get< i >( this->mapperTuple_ ).numBlocks();
423 if( localBlock >= 0 )
426 offset = std::get< i >( this->mapperTuple_ ).offSet( localBlock );
430 return offset + globalOffset_[ comp ];
433 void resize () { update(); }
441 void backup ()
const {}
443 void restore () { update(); }
445 template<
class IOStream >
446 void read ( IOStream &in ) { update(); }
448 template<
class IOStream >
449 void write ( IOStream &out )
const {}
451 template<
class Entity >
452 void insertEntity (
const Entity & ) { update(); }
454 template<
class Entity >
455 void removeEntity (
const Entity & ) { update(); }
459 oldGlobalOffset_ = globalOffset_;
464 template< std::size_t ... i >
465 SizeType numBlocks ( std::index_sequence< i ... > )
const
467 return Std::sum( std::get< i >( mapperTuple_ ).numBlocks() ... );
471 OffsetType oldGlobalOffset_;
479 template<
class GridPart,
class ... Mapper >
480 struct Implementation
482 typedef typename std::conditional<
483 Std::And( Capabilities::isAdaptiveDofMapper< Mapper >::v ... ),
484 AdaptiveDofMapper< Traits< GridPart, Mapper ... > >,
485 DofMapper< Traits< GridPart, Mapper ... > > >::type Type;
507 template<
class GridPart,
class ... Mapper >
509 :
public __TupleMapper::template Implementation< GridPart, Mapper ... >::Type
511 typedef typename __TupleMapper::template Implementation< GridPart, Mapper ... >::Type BaseType;
514 TupleMapper ( GridPart &gridPart, Mapper & ... mapper ) : BaseType( gridPart, mapper ... ) {}
515 TupleMapper ( GridPart &gridPart, Mapper && ... mapper ) : BaseType( gridPart,
std::move( mapper ) ... ) {}
521 namespace Capabilities
523 template<
class GridPart,
class ... Mapper >
529 template<
class GridPart,
class ... Mapper >
532 static const bool v =
true;
Definition: bindguard.hh:11
static constexpr bool And()
Definition: utility.hh:125
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
mapper allocating one DoF per subentity of a given codimension
Definition: tuplemapper.hh:510
TupleMapper(GridPart &gridPart, Mapper &... mapper)
Definition: tuplemapper.hh:514
TupleMapper(GridPart &gridPart, Mapper &&... mapper)
Definition: tuplemapper.hh:515
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