1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH
19#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wattributes"
33 template<
class GridPart,
class ... Mapper >
39 namespace __TupleMapper
45 template<
class GridPart,
class ... Mapper >
48 static_assert( Std::are_all_same<
typename Mapper::ElementType ... >::value,
49 "TupleMapper needs common ElementType" );
52 typedef typename FirstMapperType::ElementType
ElementType;
53 typedef typename FirstMapperType::SizeType SizeType;
54 typedef typename FirstMapperType::GlobalKeyType GlobalKeyType;
56 typedef TupleMapper< GridPart, Mapper ... > DofMapperType;
62 template<
class Index,
class Int, Int i >
65 constexpr CombinedIndex ( Index
index, Index offset ) : index_(
index ), offset_( offset ) {}
67 static constexpr Int component () {
return i; }
69 constexpr operator Index ()
const {
return index_ + offset_; }
71 constexpr Index
index ()
const {
return index_; }
73 constexpr Index offset ()
const {
return offset_; }
76 Index index_, offset_;
86 template<
class GridPart,
class ... Mapper,
template<
class >
class Base >
87 class DofMapper< Traits< GridPart, Mapper ... >, Base >
88 :
public Base< Traits< GridPart, Mapper ... > >
90 typedef Base< Traits< GridPart, Mapper ... > > BaseType;
95 template<
class Functor,
int i >
98 FunctorWrapper ( Functor functor,
int localOffset,
int globalOffset )
99 : functor_( functor ),
100 localOffset_( localOffset ),
101 globalOffset_( globalOffset )
104 template<
class GlobalKey >
105 void operator() (
int localDof,
const GlobalKey &globalKey )
const
107 functor_( localDof + localOffset_, CombinedIndex< GlobalKey, int, i >( globalKey, globalOffset_ ) );
110 template<
class GlobalKey >
111 void operator() (
const GlobalKey &globalKey )
const
113 functor_( CombinedIndex< GlobalKey, int, i >( globalKey, globalOffset_ ) );
118 const int localOffset_;
119 const int globalOffset_;
124 static const int mapperTupleSize =
sizeof ... ( Mapper );
129 typedef typename BaseType::ElementType
ElementType;
130 typedef typename BaseType::SizeType SizeType;
131 typedef typename BaseType::Traits::GlobalKeyType GlobalKeyType;
133 typedef GridPart GridPartType;
135 DofMapper ( GridPartType &gridPart, Mapper & ... mapper )
136 : gridPart_( gridPart ),
137 mapperTuple_( mapper ... )
142 DofMapper ( GridPartType &gridPart, Mapper && ... mapper )
143 : gridPart_( gridPart ),
144 mapperTuple_(
std::
move( mapper ) ... )
155 template<
class Functor >
156 void mapEach (
const ElementType &element, Functor f )
const
158 OffsetType localOffset;
159 localOffset[ 0 ] = 0;
163 FunctorWrapper< Functor, i > wrappedFunctor( f, localOffset[ i ], globalOffset_[ i ] );
164 std::get< i >( mapperTuple_ ).mapEach( element, wrappedFunctor );
165 localOffset[ i + 1 ] = localOffset[ i ] +
std::get< i >( mapperTuple_ ).numDofs( element );
169 template<
class Entity,
class Functor >
170 void mapEachEntityDof (
const Entity &entity, Functor f )
const
172 OffsetType localOffset;
173 localOffset[ 0 ] = 0;
177 FunctorWrapper< Functor, i > wrappedFunctor( f, localOffset[ i ], globalOffset_[ i ] );
178 std::get< i >( mapperTuple_ ).mapEachEntityDof( entity, wrappedFunctor );
179 localOffset[ i + 1 ] = localOffset[ i ] +
std::get< i >( mapperTuple_ ).numEntityDofs( entity );
183 [[deprecated(
"Use onSubEntity method with char vector instead")]]
184 void onSubEntity (
const ElementType &element,
int i,
int c,
std::vector< bool > &indices )
const
187 onSubEntity(element, i, c, _idx);
190 _idx[i] = indices[i] > 0;
200 void onSubEntity (
const ElementType &element,
int i,
int c,
std::vector< char > &indices )
const
202 indices.
resize( numDofs( element ) );
203 OffsetType localOffset;
204 localOffset[ 0 ] = 0;
210 std::get< t >( mapperTuple_ ).onSubEntity( element, i,c, subIndices );
211 auto localSize =
std::get< t >( mapperTuple_ ).numDofs( element );
212 assert( subIndices.
size() == localSize );
213 assert( localOffset[ t ] + localSize <= indices.
size() );
216 indices[ localOffset[t] + d ] = subIndices[d]==0? 0 : subIndices[d] + rangeOffset;
233 localOffset[ t + 1 ] = localOffset[ t ] + localSize;
248 template<
class Entity >
253 indices.
resize( numDofs( element ) );
256 template<
class Entity >
259 indices.
resize( numEntityDofs( entity ) );
263 static constexpr bool consecutive () noexcept {
return false; }
265 SizeType numBlocks ()
const
267 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
270 SizeType numberOfHoles (
int )
const
272 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
275 GlobalKeyType oldIndex (
int hole,
int )
const
277 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
280 GlobalKeyType newIndex (
int hole,
int )
const
282 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
285 SizeType oldOffSet (
int )
const
287 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
290 SizeType offSet (
int )
const
292 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
306 SizeType offset (
int i )
const {
return globalOffset_[ i ]; }
309 SizeType subSize ()
const {
return std::get< i >( mapperTuple_ ).size(); }
321 return Std::And(
std::get< i >( mapperTuple_ ).fixedDataSize( codim ) ... );
333 return Std::sum(
std::get< i >( mapperTuple_ ).maxNumDofs() ... );
339 return Std::sum(
std::get< i >( mapperTuple_ ).numDofs( element ) ... );
345 return Std::sum(
std::get< i >( mapperTuple_ ).numEntityDofs( entity ) ... );
348 void computeOffset ()
350 globalOffset_[ 0 ] = 0;
353 [ & ](
auto i ){ globalOffset_[ i + 1 ] = globalOffset_[ i ] +
std::get< i >( mapperTuple_ ).size(); } );
356 GridPartType &gridPart_;
358 OffsetType globalOffset_;
367 class AdaptiveDofMapper;
369 template<
class GridPart,
class ... Mapper >
370 class AdaptiveDofMapper< Traits< GridPart, Mapper ... > >
371 :
public DofMapper< Traits< GridPart, Mapper ... >, Dune::Fem::AdaptiveDofMapper >
376 typedef typename GridPart :: GridType GridType;
377 typedef AdaptationMethod< GridType > AdaptationMethodType;
379 typedef typename BaseType::OffsetType OffsetType;
381 using BaseType::mapperTupleSize;
382 using BaseType::mapperTuple_;
383 using BaseType::gridPart_;
384 using BaseType::globalOffset_;
387 typedef typename BaseType::ElementType
ElementType;
388 typedef typename BaseType::SizeType SizeType;
389 typedef typename BaseType::GlobalKeyType GlobalKeyType;
390 typedef GridPart GridPartType;
392 AdaptiveDofMapper ( GridPartType &gridPart, Mapper & ... mapper )
393 : BaseType( gridPart, mapper ... ),
394 numBlocks_( computeNumBlocks() ),
395 isCallBackAdapt_( AdaptationMethodType( gridPart.
grid() ).isCallBackAdaptation() ),
396 needsFullUpdate_(true)
398 oldGlobalOffset_ = globalOffset_;
399 DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).addIndexSet( *
this );
402 AdaptiveDofMapper ( GridPartType &gridPart, Mapper && ... mapper )
403 : BaseType( gridPart,
std::
move( mapper ) ... ),
404 numBlocks_( computeNumBlocks() ),
405 isCallBackAdapt_( AdaptationMethodType( gridPart.
grid() ).isCallBackAdaptation() ),
406 needsFullUpdate_(true)
408 oldGlobalOffset_ = globalOffset_;
409 DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).addIndexSet( *
this );
412 ~AdaptiveDofMapper () { DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).removeIndexSet( *
this ); }
414 AdaptiveDofMapper (
const AdaptiveDofMapper & ) =
delete;
415 AdaptiveDofMapper ( AdaptiveDofMapper && ) =
delete;
417 static constexpr bool consecutive () noexcept {
return true; }
421 SizeType numberOfHoles (
const int block )
const
427 const int localBlock = computeBlock( i, block );
428 if( localBlock >= 0 )
430 nHoles =
std::get< i >( this->mapperTuple_ ).numberOfHoles( localBlock );
437 GlobalKeyType oldIndex (
const int hole,
const int block )
const
443 const int localBlock = computeBlock( i, block );
444 if( localBlock >= 0 )
446 oIndex =
std::get< i >( this->mapperTuple_ ).oldIndex( hole, localBlock ) + globalOffset_[ i ];
453 GlobalKeyType newIndex (
const int hole,
const int block )
const
459 const int localBlock = computeBlock( i, block );
460 if( localBlock >= 0 )
462 nIndex =
std::get< i >( this->mapperTuple_ ).newIndex( hole, localBlock ) + globalOffset_[ i ];
469 SizeType oldOffSet (
int block )
const
471 SizeType oOffset = 0;
475 const int localBlock = computeBlock( i, block );
476 if( localBlock >= 0 )
478 oOffset =
std::get< i >( this->mapperTuple_ ).oldOffSet( localBlock ) + oldGlobalOffset_[ i ];
485 SizeType offSet (
int block )
const
491 const int localBlock = computeBlock( i, block );
492 if( localBlock >= 0 )
494 offset =
std::get< i >( this->mapperTuple_ ).offSet( localBlock ) + globalOffset_[ i ];
501 void resize () {
update(); }
507 needsFullUpdate_ =
true;
511 void backup ()
const {}
513 void restore () { compress(); }
515 template<
class IOStream >
516 void read ( IOStream &in ) { compress(); }
518 template<
class IOStream >
519 void write ( IOStream &out )
const {}
521 template<
class Entity >
522 void insertEntity (
const Entity & )
524 if( needsFullUpdate_ )
537 template<
class Entity >
538 void removeEntity (
const Entity & ) {}
543 oldGlobalOffset_ = globalOffset_;
546 needsFullUpdate_ = isCallBackAdapt_ ;
553 int computeBlock(
const int i,
const unsigned int block )
const
555 if( block >= blocks_[ i ] && block < blocks_[ i + 1 ] )
556 return block - blocks_[ i ];
561 void printOffSet(
const OffsetType& offset,
const std::string&
name )
const
563 for(
const auto& off : offset )
572 return Std::sum(
std::get< i >( mapperTuple_ ).numBlocks() ... );
575 SizeType computeNumBlocks ()
581 [ & ](
auto i ){ blocks_[ i + 1 ] = blocks_[ i ] +
std::get< i >( mapperTuple_ ).numBlocks(); } );
584 return blocks_.back();
588 OffsetType oldGlobalOffset_;
591 const SizeType numBlocks_;
592 const bool isCallBackAdapt_;
593 bool needsFullUpdate_;
601 template<
class GridPart,
class ... Mapper >
602 struct Implementation
605 Std::And( Capabilities::isAdaptiveDofMapper< Mapper >::v ... ),
606 AdaptiveDofMapper< Traits< GridPart, Mapper ... > >,
607 DofMapper< Traits< GridPart, Mapper ... > > >::type Type;
629 template<
class GridPart,
class ... Mapper >
631 :
public __TupleMapper::template Implementation< GridPart, Mapper ... >::Type
633 typedef typename __TupleMapper::template Implementation< GridPart,
Mapper ... >::Type BaseType;
643 namespace Capabilities
645 template<
class GridPart,
class ...
Mapper >
651 template<
class GridPart,
class ...
Mapper >
654 static const bool v =
true;
665#pragma GCC diagnostic pop
Hierarchy< Domain, A >::Iterator update
static bool contains(const Type &attribute)
std::ptrdiff_t index() const
virtual void operator()()=0
#define DUNE_THROW(E,...)
static constexpr bool And()
Definition utility.hh:125
const Grid & grid() const
GridImp::template Codim< cd >::Entity Entity
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
mapper allocating one DoF per subentity of a given codimension
Definition tuplemapper.hh:632
TupleMapper(GridPart &gridPart, Mapper &... mapper)
Definition tuplemapper.hh:636
TupleMapper(GridPart &gridPart, Mapper &&... mapper)
Definition tuplemapper.hh:637
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