1 #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH 2 #define DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH 8 #include <dune/common/forloop.hh> 9 #include <dune/common/tuples.hh> 11 #include <dune/common/std/utility.hh> 27 template<
class GridPart,
class ... Mapper >
33 namespace __TupleMapper
39 template<
class GridPart,
class ... Mapper >
43 "TupleMapper needs common ElementType" );
45 typedef typename std::tuple_element< 0, std::tuple< Mapper ... > >::type FirstMapperType;
46 typedef typename FirstMapperType::ElementType ElementType;
47 typedef typename FirstMapperType::SizeType SizeType;
48 typedef typename FirstMapperType::GlobalKeyType GlobalKeyType;
50 typedef TupleMapper< GridPart, Mapper ... > DofMapperType;
60 template<
class GridPart,
class ... Mapper,
template<
class >
class Base >
61 class DofMapper< Traits< GridPart, Mapper ... >, Base >
62 :
public Base< Traits< GridPart, Mapper ... > >
64 typedef Base< Traits< GridPart, Mapper ... > > BaseType;
72 struct MapEachEntityDof;
77 template<
class Functor >
80 FunctorWrapper ( Functor functor,
int localOffset,
int globalOffset )
81 : functor_( functor ),
82 localOffset_( localOffset ),
83 globalOffset_( globalOffset )
86 template<
class GlobalKey >
87 void operator() (
int localDof,
const GlobalKey &globalKey )
89 functor_( localDof + localOffset_, globalKey + globalOffset_ );
92 template<
class GlobalKey >
93 void operator() (
const GlobalKey &globalKey )
95 functor_( globalKey + globalOffset_ );
100 const int localOffset_;
101 const int globalOffset_;
105 static const int mapperTupleSize =
sizeof ... ( Mapper );
107 typedef std::array< typename BaseType::SizeType, mapperTupleSize + 1 > OffsetType;
110 typedef typename BaseType::ElementType ElementType;
111 typedef typename BaseType::SizeType SizeType;
112 typedef typename BaseType::Traits::GlobalKeyType GlobalKeyType;
114 typedef GridPart GridPartType;
116 DofMapper ( GridPartType &gridPart, Mapper & ... mapper )
117 : gridPart_( gridPart ),
118 mapperTuple_( mapper ... )
123 DofMapper ( GridPartType &gridPart, Mapper && ... mapper )
124 : gridPart_( gridPart ),
125 mapperTuple_(
std::
move( mapper ) ... )
130 SizeType size ()
const {
return size( Std::index_sequence_for< Mapper ... >() ); }
132 bool contains (
const int codim )
const {
return contains( codim, Std::index_sequence_for< Mapper ... >() ); }
134 bool fixedDataSize (
int codim )
const {
return fixedDataSize( codim, Std::index_sequence_for< Mapper ... >() ); }
136 template<
class Functor >
137 void mapEach (
const ElementType &element, Functor f )
const 139 OffsetType localOffset;
140 localOffset[ 0 ] = 0;
141 ForLoop< MapEach, 0, mapperTupleSize - 1 >::apply( localOffset, globalOffset_, element, f, mapperTuple_ );
144 template<
class Entity,
class Functor >
145 void mapEachEntityDof (
const Entity &entity, Functor f )
const 147 OffsetType localOffset;
148 localOffset[ 0 ] = 0;
149 ForLoop< MapEachEntityDof, 0, mapperTupleSize - 1 >::apply( localOffset, globalOffset_, entity, f, mapperTuple_ );
152 int maxNumDofs ()
const {
return maxNumDofs( Std::index_sequence_for< Mapper ... >() ); }
154 SizeType numDofs (
const ElementType &element )
const {
return numDofs( element, Std::index_sequence_for< Mapper ... >() ); }
156 template<
class Entity >
157 SizeType numEntityDofs (
const Entity &entity )
const {
return numEntityDofs( entity, Std::index_sequence_for< Mapper ... >() ); }
160 static constexpr
bool consecutive () noexcept {
return false; }
162 SizeType numBlocks ()
const 164 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
167 SizeType numberOfHoles (
int )
const 169 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
172 GlobalKeyType oldIndex (
int hole,
int )
const 174 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
177 GlobalKeyType newIndex (
int hole,
int )
const 179 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
182 SizeType oldOffSet (
int )
const 184 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
187 SizeType offSet (
int )
const 189 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
194 SizeType offset (
int i )
const {
return globalOffset_[ i ]; }
197 SizeType subSize ()
const {
return std::get< i >( mapperTuple_ ).size(); }
200 template< std::size_t ... i >
201 SizeType size ( Std::index_sequence< i ... > )
const 203 return Std::sum( std::get< i >( mapperTuple_ ).size() ... );
206 template< std::size_t ... i >
207 bool fixedDataSize (
const int codim, Std::index_sequence< i ... > )
const 209 return Std::And( std::get< i >( mapperTuple_ ).fixedDataSize( codim ) ... );
212 template< std::size_t ... i >
213 bool contains (
const int codim, Std::index_sequence< i ... > )
const 215 return Std::Or( std::get< i >( mapperTuple_ ).contains( codim ) ... );
218 template< std::size_t ... i >
219 int maxNumDofs ( Std::index_sequence< i ... > )
const 221 return Std::sum( std::get< i >( mapperTuple_ ).maxNumDofs() ... );
224 template< std::size_t ... i >
225 SizeType numDofs (
const ElementType &element, Std::index_sequence< i ... > )
const 227 return Std::sum( std::get< i >( mapperTuple_ ).numDofs( element ) ... );
230 template<
class Entity, std::size_t ... i >
231 SizeType numEntityDofs (
const Entity &entity, Std::index_sequence< i ... > )
const 233 return Std::sum( std::get< i >( mapperTuple_ ).numEntityDofs( entity ) ... );
238 globalOffset_[ 0 ] = 0;
240 ForLoop< ComputeOffSet, 0, mapperTupleSize - 1 >::apply( globalOffset_, mapperTuple_ );
243 GridPartType &gridPart_;
244 std::tuple< Mapper ... > mapperTuple_;
245 OffsetType globalOffset_;
252 template<
class GridPart,
class ... Mapper,
template<
class >
class Base >
254 struct DofMapper< Traits< GridPart, Mapper ... >, Base >::
257 template<
class Tuple >
258 static void apply ( OffsetType &offset,
const Tuple &tuple )
260 offset[ i + 1 ] = offset[ i ] + std::get< i >( tuple ).size();
268 template<
class GridPart,
class ... Mapper,
template<
class >
class Base >
270 struct DofMapper< Traits< GridPart, Mapper ... >, Base >::
273 template<
class Entity,
class Functor,
class Tuple >
274 static void apply ( OffsetType &localOffset,
const OffsetType &globalOffset,
const Entity &entity, Functor f,
const Tuple &tuple )
276 FunctorWrapper< Functor > wrappedFunctor( f, localOffset[ i ], globalOffset[ i ] );
277 std::get< i >( tuple ).mapEachEntityDof( entity, wrappedFunctor );
278 localOffset[ i + 1 ] = localOffset[ i ] + std::get< i >( tuple ).numEntityDofs( entity );
286 template<
class GridPart,
class ... Mapper,
template<
class >
class Base >
288 struct DofMapper< Traits< GridPart, Mapper ... >, Base >::
291 template<
class Functor,
class Tuple >
292 static void apply ( OffsetType &localOffset,
const OffsetType &globalOffset,
const ElementType &element, Functor f,
const Tuple &tuple )
294 FunctorWrapper< Functor > wrappedFunctor( f, localOffset[ i ], globalOffset[ i ] );
295 std::get< i >( tuple ).mapEach( element, wrappedFunctor );
296 localOffset[ i + 1 ] = localOffset[ i ] + std::get< i >( tuple ).numDofs( element );
307 template<
class GridPart,
class ... Mapper >
309 :
public DofMapper< Traits< GridPart, Mapper ... >, Dune::Fem::AdaptiveDofMapper >
325 struct NumberOfHoles;
328 static const int mapperTupleSize =
sizeof ... ( Mapper );
330 typedef std::array< typename BaseType::Traits::SizeType, mapperTupleSize + 1 > OffsetType;
332 using BaseType::mapperTuple_;
333 using BaseType::gridPart_;
334 using BaseType::globalOffset_;
337 typedef typename BaseType::ElementType ElementType;
338 typedef typename BaseType::SizeType SizeType;
339 typedef typename BaseType::GlobalKeyType GlobalKeyType;
340 typedef GridPart GridPartType;
343 : BaseType( gridPart, mapper ... )
349 : BaseType( gridPart,
std::
move( mapper ) ... )
359 static constexpr
bool consecutive () noexcept {
return true; }
361 SizeType numBlocks ()
const {
return numBlocks( Std::index_sequence_for< Mapper ... >() ); }
363 SizeType numberOfHoles (
int block )
const 367 ForLoop< NumberOfHoles, 0, mapperTupleSize - 1 >::apply( nHoles, comp, block, mapperTuple_ );
371 GlobalKeyType oldIndex (
int hole,
int block )
const 375 ForLoop< OldIndex, 0, mapperTupleSize - 1 >::apply( oIndex, comp, hole, block, mapperTuple_ );
377 return oIndex + globalOffset_[ comp ];
380 GlobalKeyType newIndex (
int hole,
int block )
const 384 ForLoop< NewIndex, 0, mapperTupleSize - 1 >::apply( nIndex, comp, hole, block, mapperTuple_ );
386 return nIndex + globalOffset_[ comp ];
389 SizeType oldOffSet (
int block )
const 392 SizeType oOffset = 0;
393 ForLoop< OldOffset, 0, mapperTupleSize - 1 >::apply( oOffset, comp, block, mapperTuple_ );
395 return oOffset + oldGlobalOffset_[ comp ];
398 SizeType offSet (
int block )
const 402 ForLoop< Offset, 0, mapperTupleSize - 1 >::apply( offset, comp, block, mapperTuple_ );
404 return offset + globalOffset_[ comp ];
408 void resize () { update(); }
416 void backup ()
const {}
418 void restore () { update(); }
420 template<
class IOStream >
421 void read ( IOStream &in ) { update(); }
423 template<
class IOStream >
424 void write ( IOStream &out )
const {}
426 template<
class Entity >
427 void insertEntity (
const Entity & ) { update(); }
429 template<
class Entity >
430 void removeEntity (
const Entity & ) { update(); }
436 oldGlobalOffset_ = globalOffset_;
440 template< std::size_t ... i >
441 SizeType numBlocks ( Std::index_sequence< i ... > )
const 443 return Std::sum( std::get< i >( mapperTuple_ ).numBlocks() ... );
447 OffsetType oldGlobalOffset_;
455 template<
class GridPart,
class ... Mapper >
460 template<
class Tuple >
461 static void apply ( SizeType &nHoles,
int &comp,
const int block,
const Tuple &tuple )
465 const int localBlock = block - std::get< i >( tuple ).numBlocks();
466 if( localBlock >= 0 )
469 nHoles = std::get< i >( tuple ).numberOfHoles( localBlock );
479 template<
class GridPart,
class ... Mapper >
484 template<
class Tuple >
485 static void apply ( SizeType &oldIndex,
int &comp,
const int hole,
const int block,
const Tuple &tuple )
489 const int localBlock = block - std::get< i >( tuple ).numBlocks();
490 if( localBlock >= 0 )
493 oldIndex = std::get< i >( tuple ).oldIndex( hole, localBlock );
502 template<
class GridPart,
class ... Mapper >
507 template<
class Tuple >
508 static void apply ( SizeType &nIndex,
int &comp,
const int hole,
const int block,
const Tuple &tuple )
512 const int localBlock = block - std::get< i >( tuple ).numBlocks();
513 if( localBlock >= 0 )
516 nIndex = std::get< i >( tuple ).newIndex( hole, localBlock );
525 template<
class GridPart,
class ... Mapper >
530 template<
class Tuple >
531 static void apply ( SizeType &offset,
int &comp,
const int block,
const Tuple &tuple )
535 const int localBlock = block - std::get< i >( tuple ).numBlocks();
536 if( localBlock >= 0 )
539 offset = std::get< i >( tuple ).oldOffSet( localBlock );
548 template<
class GridPart,
class ... Mapper >
553 template<
class Tuple >
554 static void apply ( SizeType &offset,
int &comp,
const int block,
const Tuple &tuple )
558 const int localBlock = block - std::get< i >( tuple ).numBlocks();
559 if( localBlock >= 0 )
562 offset = std::get< i >( tuple ).offSet( localBlock );
571 template<
class GridPart,
class ... Mapper >
572 struct Implementation
574 typedef typename std::conditional<
577 DofMapper< Traits< GridPart, Mapper ... > > >::type Type;
583 #endif // #ifndef DOXYGEN 599 template<
class GridPart,
class ... Mapper >
601 :
public __TupleMapper::template Implementation< GridPart, Mapper ... >::Type
603 typedef typename __TupleMapper::template Implementation< GridPart, Mapper ... >::Type BaseType;
606 TupleMapper ( GridPart &gridPart, Mapper & ... mapper ) : BaseType( gridPart, mapper ... ) {}
607 TupleMapper ( GridPart &gridPart, Mapper && ... mapper ) : BaseType( gridPart,
std::
move( mapper ) ... ) {}
613 namespace Capabilities
615 template<
class GridPart,
class ... Mapper >
627 #endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLEMAPPER_HH TupleMapper(GridPart &gridPart, Mapper &...mapper)
Definition: tuplemapper.hh:606
Extended interface for adaptive DoF mappers.
Definition: mapper/dofmapper.hh:204
Definition: utility.hh:135
static constexpr T sum(T a)
Definition: utility.hh:33
mapper allocating one DoF per subentity of a given codimension
Definition: tuplemapper.hh:28
Interface for calculating the size of a function space for a grid on a specified level. Furthermore the local to global mapping of dof number is done. Also during grid adaptation this mapper knows about old and new indices of entities.
Definition: mapper/dofmapper.hh:40
Definition: coordinate.hh:4
static constexpr bool Or(bool a)
Definition: utility.hh:98
void move(ArrayInterface< T > &array, const unsigned int oldOffset, const unsigned int newOffset, const unsigned int length)
Definition: array_inline.hh:38
Definition: space/mapper/capabilities.hh:21
static constexpr bool And(bool a)
Definition: utility.hh:113
static ThisType & instance(const GridType &grid)
obtain a reference to the DofManager for a given grid
Definition: dofmanager.hh:1319
TupleMapper(GridPart &gridPart, Mapper &&...mapper)
Definition: tuplemapper.hh:607