1 #ifndef DUNE_FEM_DOFMAPPER_INDEXSETDOFMAPPER_HH
2 #define DUNE_FEM_DOFMAPPER_INDEXSETDOFMAPPER_HH
9 #include <dune/geometry/referenceelements.hh>
10 #include <dune/geometry/type.hh>
11 #include <dune/geometry/typeindex.hh>
30 template<
class Gr
idPart >
35 template<
class Iterator,
class Functor >
36 void operator() ( std::size_t index,
unsigned int numDofs, Iterator begin, Iterator end, Functor functor )
const
39 functor( *(begin++), index++ );
47 Mapping
operator() (
const typename GridPart::template Codim< 0 >::EntityType &element,
unsigned int subEntity,
unsigned int codim )
const {
return {}; }
52 namespace __IndexSetDofMapper
58 template<
class Gr
idPart,
class LocalDofMapping >
80 typedef Dune::ReferenceElements< typename GridPart::ctype, dimension >
RefElementsType;
92 std::vector<bool> &a = active_[c];
93 a.resize( refElement.size( c ),
false );
94 if (c<codim)
continue;
95 if (c==codim) { a[subEntity]=
true; ++size_;
continue; }
96 for (
int i=0;i<refElement.size(subEntity, codim, c);++i)
98 a[refElement.subEntity(subEntity, codim, i, c)] =
true;
105 std::vector< std::vector< bool > > active_;
109 template<
class Functor >
118 typedef typename GridPartType::template Codim< 0 >::EntityType
ElementType;
120 template<
class CodeFactory >
144 template<
class Functor >
147 void map (
const ElementType &element, std::vector< GlobalKeyType > &indices )
const;
163 template<
class Entity,
class Functor >
166 template<
class Entity >
167 void mapEntityDofs (
const Entity &entity, std::vector< GlobalKeyType > &indices )
const;
169 template<
class Entity >
203 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
208 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
213 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
218 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
223 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
228 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
243 template<
class Entity >
244 const SubEntityInfo &
subEntityInfo (
const Entity &entity )
const;
263 template<
class Gr
idPart,
class LocalDofMapping >
270 template<
class Iterator >
271 void operator() (
unsigned int gtIndex,
unsigned int subEntity, Iterator it, Iterator end )
274 const unsigned int numDofs = end - it;
275 if(
info.numDofs == 0 )
278 DUNE_THROW(
DofMapperError,
"Inconsistent number of DoFs on subEntity (codim = " <<
info.codim <<
")." );
291 template<
class Gr
idPart,
class LocalDofMapping >
294 template<
class Gr
idPart,
class LocalDofMapping >
295 template<
class CodeFactory >
301 : indexSet_( gridPart.indexSet() ),
302 localDofMapping_( std::move( localDofMapping ) ),
303 code_( LocalGeometryTypeIndex::size( dimension ) ),
305 subEntityInfo_( GlobalGeometryTypeIndex::size( dimension ) )
307 std::vector< GeometryType > gt( GlobalGeometryTypeIndex::size( dimension ) );
309 const typename RefElementsType::Iterator end = RefElementsType::end();
310 for(
typename RefElementsType::Iterator it = RefElementsType::begin(); it != end; ++it )
314 for(
int codim = 0; codim <= dimension; ++codim )
316 for(
int i = 0; i < refElement.size( codim ); ++i )
318 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( refElement.type( i, codim ) );
319 gt[ gtIdx ] = refElement.type( i, codim );
320 subEntityInfo_[ gtIdx ].codim = codim;
324 DofMapperCode &code = code_[ LocalGeometryTypeIndex::index( refElement.type() ) ];
325 code = codeFactory( refElement );
330 for(
int codim = 0; codim <= dimension; ++codim )
331 codimType_[ codim ] = CodimEmpty;
333 unsigned int codimDofs[ dimension+1 ];
334 for(
unsigned int i = 0; i < subEntityInfo_.size(); ++i )
337 if(
info.numDofs == 0 )
344 static const bool hasSingleGeometryType = Dune::Capabilities::hasSingleGeometryType< typename GridPartType::GridType > :: v ;
345 const auto & geomTypes = indexSet().types(
info.codim);
347 if (hasSingleGeometryType && geomTypes[0] != gt[i])
352 if( codimType_[
info.codim ] == CodimEmpty )
353 codimType_[
info.codim ] = CodimFixedSize;
354 else if( codimDofs[
info.codim ] !=
info.numDofs )
355 codimType_[
info.codim ] = CodimVariableSize;
357 codimDofs[
info.codim ] =
info.numDofs;
358 blockMap_.push_back( gt[ i ] );
362 requestCodimensions ();
369 template<
class Gr
idPart,
class LocalDofMapping >
370 template<
class Functor >
374 const auto &idxSet = indexSet();
376 code( element )( [
this, &idxSet, &element, f ] (
unsigned int gtIndex,
unsigned int subEntity,
auto begin,
auto end ) {
378 const SizeType subIndex = idxSet.subIndex( element, subEntity,
info.codim );
380 localDofMapping_( element, subEntity,
info.codim )( index,
info.numDofs, begin, end, f );
385 template<
class Gr
idPart,
class LocalDofMapping >
389 indices.resize( numDofs( element ) );
390 mapEach( element,
AssignFunctor< std::vector< SizeType > >( indices ) );
393 template<
class Gr
idPart,
class LocalDofMapping >
394 template<
class Entity,
class Functor >
399 const unsigned int numDofs =
info.numDofs;
401 for(
unsigned int i = 0; i <
info.numDofs; ++i )
406 template<
class Gr
idPart,
class LocalDofMapping >
407 template<
class Entity >
411 indices.resize( numEntityDofs( entity ) );
412 mapEachEntityDof( entity,
AssignFunctor< std::vector< SizeType > >( indices ) );
415 template<
class Gr
idPart,
class LocalDofMapping >
419 const SubEntityFilter filter( RefElementsType::general( element.type() ), i, c );
420 indices.resize( numDofs( element ) );
421 code( element )( [
this, &indices, &filter ] (
unsigned int gtIndex,
unsigned int subEntity,
auto begin,
auto end ) {
422 const bool active = filter( subEntity, subEntityInfo_[ gtIndex ].codim );
423 while( begin != end )
424 indices[ *(begin++) ] = active;
428 template<
class Gr
idPart,
class LocalDofMapping >
429 template<
class Entity >
434 return subEntityInfo( entity ).numDofs;
438 template<
class Gr
idPart,
class LocalDofMapping >
442 std::vector< int > codimensions;
443 codimensions.reserve( dimension+1 );
445 for(
typename BlockMapType::const_iterator it = blockMap_.begin(); it != blockMap_.end(); ++it )
448 codimensions.push_back(
info.codim );
452 indexSet().requestCodimensions( codimensions );
455 template<
class Gr
idPart,
class LocalDofMapping >
459 for(
const auto& geomType : blockMap_ )
461 SubEntityInfo &
info = subEntityInfo_[ GlobalGeometryTypeIndex::index( geomType ) ];
469 template<
class Gr
idPart,
class LocalDofMapping >
473 return code_[ LocalGeometryTypeIndex::index( gt ) ];
477 template<
class Gr
idPart,
class LocalDofMapping >
478 template<
class Entity >
482 return subEntityInfo_[ GlobalGeometryTypeIndex::index( entity.type() ) ];
490 template<
class Gr
idPart,
class LocalDofMapping >
492 :
public DofMapper< GridPart, LocalDofMapping >
499 typedef typename BaseType::GridPartType::GridType
GridType;
506 template<
class CodeFactory >
508 :
BaseType( gridPart, std::move( localDofMapping ), codeFactory ),
510 grid_( gridPart.grid() )
542 template<
class Entity >
545 template<
class Entity >
552 template <
class StreamTraits>
555 template <
class StreamTraits>
578 template<
class Gr
idPart,
class LocalDofMapping >
582 assert( (blk >= 0) && (blk < numBlocks()) );
583 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
584 return subEntityInfo_[ gtIdx ].offset;
588 template<
class Gr
idPart,
class LocalDofMapping >
592 assert( (blk >= 0) && (blk < numBlocks()) );
593 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
594 return subEntityInfo_[ gtIdx ].oldOffset;
598 template<
class Gr
idPart,
class LocalDofMapping >
602 assert( (blk >= 0) && (blk < numBlocks()) );
603 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
609 template<
class Gr
idPart,
class LocalDofMapping >
613 assert( (hole >= 0) && (hole < numberOfHoles( blk )) );
614 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
616 const unsigned int numDofs =
info.numDofs;
617 const SizeType index = indexSet().oldIndex( hole / numDofs, blockMap_[ blk ] );
618 return info.offset + numDofs * index + (hole % numDofs);
622 template<
class Gr
idPart,
class LocalDofMapping >
626 assert( (hole >= 0) && (hole < numberOfHoles( blk )) );
627 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
629 const unsigned int numDofs =
info.numDofs;
630 const SizeType index = indexSet().newIndex( hole / numDofs, blockMap_[ blk ] );
631 return info.offset + numDofs * index + (hole % numDofs);
639 template< class GridPart, class LocalDofMapping, bool adaptive = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v >
652 template<
class Gr
idPart,
class LocalDofMapping = DefaultLocalDofMapping< Gr
idPart > >
654 :
public __IndexSetDofMapper::template Implementation< GridPart, LocalDofMapping >::Type
656 typedef typename __IndexSetDofMapper::template Implementation< GridPart, LocalDofMapping >::Type BaseType;
662 template<
class CodeFactory >
664 : BaseType( gridPart, std::move( localDofMapping ), codeFactory )
667 template<
class CodeFactory >
677 namespace Capabilities
682 template<
class Gr
idPart,
class LocalDofMapping >
692 template<
class Gr
idPart,
class LocalDofMapping >
695 static const bool v =
true;
static ThisType & instance(const GridType &grid)
obtain a reference to the DofManager for a given grid
Definition: dofmanager.hh:1216
Definition: bindguard.hh:11
static constexpr T max(T a)
Definition: utility.hh:77
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
specialize with true if index set implements the interface for adaptive index sets
Definition: common/indexset.hh:64
abstract interface for an output stream
Definition: streams.hh:46
abstract interface for an input stream
Definition: streams.hh:179
Definition: grcommon.hh:31
Definition: misc/functor.hh:31
Definition: space/mapper/capabilities.hh:22
static const bool v
Definition: space/mapper/capabilities.hh:23
unsigned int numDofs() const
Definition: code.hh:92
Extended interface for adaptive DoF mappers.
Definition: mapper/dofmapper.hh:219
Definition: space/mapper/exceptions.hh:14
Definition: indexsetdofmapper.hh:32
DefaultLocalDofMapping()
Definition: indexsetdofmapper.hh:44
Mapping operator()(const typename GridPart::template Codim< 0 >::EntityType &element, unsigned int subEntity, unsigned int codim) const
Definition: indexsetdofmapper.hh:47
DefaultLocalDofMapping(const GridPart &)
Definition: indexsetdofmapper.hh:45
Definition: indexsetdofmapper.hh:60
const IndexSetType & indexSet() const
Definition: indexsetdofmapper.hh:246
bool fixedDataSize(int codim) const
Definition: indexsetdofmapper.hh:176
LocalDofMapping LocalDofMappingType
Definition: indexsetdofmapper.hh:116
unsigned int numDofs(const ElementType &element) const
Definition: indexsetdofmapper.hh:160
RefElementsType::ReferenceElement RefElementType
Definition: indexsetdofmapper.hh:81
std::size_t SizeType
Definition: indexsetdofmapper.hh:64
void mapEach(const ElementType &element, Functor f) const
map each local DoF number to a global one
Definition: indexsetdofmapper.hh:372
SizeType numberOfHoles(int) const
Definition: indexsetdofmapper.hh:206
unsigned int maxNumDofs_
Definition: indexsetdofmapper.hh:251
SizeType size() const
Definition: indexsetdofmapper.hh:178
void requestCodimensions()
submit request for codimensions used to index set
Definition: indexsetdofmapper.hh:439
void map(const ElementType &element, std::vector< GlobalKeyType > &indices) const
Definition: indexsetdofmapper.hh:387
GridPart GridPartType
Definition: indexsetdofmapper.hh:115
LocalDofMapping localDofMapping_
Definition: indexsetdofmapper.hh:249
Dune::ReferenceElements< typename GridPart::ctype, dimension > RefElementsType
Definition: indexsetdofmapper.hh:80
static const int dimension
Definition: indexsetdofmapper.hh:79
GlobalKeyType oldIndex(int hole, int) const
Definition: indexsetdofmapper.hh:211
void mapEntityDofs(const Entity &entity, std::vector< GlobalKeyType > &indices) const
Definition: indexsetdofmapper.hh:409
CodimType
Definition: indexsetdofmapper.hh:78
@ CodimVariableSize
Definition: indexsetdofmapper.hh:78
@ CodimEmpty
Definition: indexsetdofmapper.hh:78
@ CodimFixedSize
Definition: indexsetdofmapper.hh:78
SizeType offSet(int) const
Definition: indexsetdofmapper.hh:226
SizeType GlobalKeyType
Definition: indexsetdofmapper.hh:110
const DofMapperCode & code(const GeometryType >) const
Definition: indexsetdofmapper.hh:471
void update()
update mapper offsets
Definition: indexsetdofmapper.hh:456
const IndexSetType & indexSet_
Definition: indexsetdofmapper.hh:248
bool contains(int codim) const
Definition: indexsetdofmapper.hh:174
DofMapper(const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:297
unsigned int maxNumDofs() const
Definition: indexsetdofmapper.hh:159
SizeType oldOffSet(int) const
Definition: indexsetdofmapper.hh:221
std::vector< GeometryType > BlockMapType
Definition: indexsetdofmapper.hh:238
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
fills a vector of bools with true indicating that the corresponding local degree of freedom is attach...
Definition: indexsetdofmapper.hh:417
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition: indexsetdofmapper.hh:396
GlobalKeyType newIndex(int hole, int) const
Definition: indexsetdofmapper.hh:216
const SubEntityInfo & subEntityInfo(const Entity &entity) const
Definition: indexsetdofmapper.hh:480
GridPartType::template Codim< 0 >::EntityType ElementType
Definition: indexsetdofmapper.hh:118
static constexpr bool consecutive() noexcept
Definition: indexsetdofmapper.hh:199
GridPartType::IndexSetType IndexSetType
Definition: indexsetdofmapper.hh:237
CodimType codimType_[dimension+1]
Definition: indexsetdofmapper.hh:255
const DofMapperCode & code(const ElementType &element) const
Definition: indexsetdofmapper.hh:241
std::vector< DofMapperCode > code_
Definition: indexsetdofmapper.hh:250
SizeType size_
Definition: indexsetdofmapper.hh:252
unsigned int numEntityDofs(const Entity &entity) const
Definition: indexsetdofmapper.hh:432
BlockMapType blockMap_
Definition: indexsetdofmapper.hh:254
SizeType numBlocks() const
Definition: indexsetdofmapper.hh:201
std::vector< SubEntityInfo > subEntityInfo_
Definition: indexsetdofmapper.hh:253
Definition: indexsetdofmapper.hh:68
SizeType oldOffset
Definition: indexsetdofmapper.hh:75
SubEntityInfo()
Definition: indexsetdofmapper.hh:69
SizeType offset
Definition: indexsetdofmapper.hh:75
unsigned int numDofs
Definition: indexsetdofmapper.hh:74
unsigned int codim
Definition: indexsetdofmapper.hh:73
Definition: indexsetdofmapper.hh:86
SubEntityFilter(const RefElementType &refElement, int subEntity, int codim)
Definition: indexsetdofmapper.hh:87
bool operator()(int i, int c) const
Definition: indexsetdofmapper.hh:103
Definition: indexsetdofmapper.hh:110
Definition: indexsetdofmapper.hh:265
BuildFunctor(std::vector< SubEntityInfo > &subEntityInfo)
Definition: indexsetdofmapper.hh:266
Definition: indexsetdofmapper.hh:493
bool compress()
Definition: indexsetdofmapper.hh:550
void update()
Definition: indexsetdofmapper.hh:525
int numBlocks() const
Definition: indexsetdofmapper.hh:529
void read(InStreamInterface< StreamTraits > &in)
Definition: indexsetdofmapper.hh:556
void write(OutStreamInterface< StreamTraits > &out) const
Definition: indexsetdofmapper.hh:553
BaseType::LocalDofMappingType LocalDofMappingType
Definition: indexsetdofmapper.hh:503
BaseType::SubEntityInfo SubEntityInfo
Definition: indexsetdofmapper.hh:498
bool consecutive() const
Definition: indexsetdofmapper.hh:540
SizeType newIndex(SizeType hole, int blk) const
Definition: indexsetdofmapper.hh:624
void insertEntity(const Entity &entity)
Definition: indexsetdofmapper.hh:543
ThisType & operator=(const ThisType &)=delete
void backup() const
Definition: indexsetdofmapper.hh:561
SizeType oldIndex(SizeType hole, int blk) const
Definition: indexsetdofmapper.hh:611
BaseType::GridPartType::GridType GridType
Definition: indexsetdofmapper.hh:499
void resize()
Definition: indexsetdofmapper.hh:548
AdaptiveDofMapper(const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:507
BaseType::GridPartType GridPartType
Definition: indexsetdofmapper.hh:502
BaseType::SizeType SizeType
Definition: indexsetdofmapper.hh:504
const GridType & grid_
Definition: indexsetdofmapper.hh:570
~AdaptiveDofMapper()
Definition: indexsetdofmapper.hh:517
AdaptiveDofMapper(const ThisType &)=delete
SizeType offSet(int blk) const
Definition: indexsetdofmapper.hh:580
SizeType numberOfHoles(int blk) const
Definition: indexsetdofmapper.hh:600
BlockMapType blockMap_
Definition: indexsetdofmapper.hh:254
void restore()
Definition: indexsetdofmapper.hh:562
SizeType oldOffSet(int blk) const
Definition: indexsetdofmapper.hh:590
void removeEntity(const Entity &entity)
Definition: indexsetdofmapper.hh:546
Definition: indexsetdofmapper.hh:641
std::conditional< adaptive, AdaptiveDofMapper< GridPart, LocalDofMapping >, DofMapper< GridPart, LocalDofMapping > >::type Type
Definition: indexsetdofmapper.hh:642
Definition: indexsetdofmapper.hh:655
IndexSetDofMapper(const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:663
IndexSetDofMapper(const GridPartType &gridPart, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:668
BaseType::LocalDofMappingType LocalDofMappingType
Definition: indexsetdofmapper.hh:660
BaseType::GridPartType GridPartType
Definition: indexsetdofmapper.hh:659