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 >
119 typedef typename GridPartType::template Codim< 0 >::EntityType
ElementType;
121 template<
class CodeFactory >
145 template<
class Functor >
148 void map (
const ElementType &element, std::vector< GlobalKeyType > &indices )
const;
164 template<
class Entity,
class Functor >
167 template<
class Entity >
168 void mapEntityDofs (
const Entity &entity, std::vector< GlobalKeyType > &indices )
const;
170 template<
class Entity >
204 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
209 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
214 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
219 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
224 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
229 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
232 template<
class Entity >
235 DUNE_THROW( NotImplemented,
"Method insertEntity(entity) called on non-adaptive block mapper" );
237 template<
class Entity >
240 DUNE_THROW( NotImplemented,
"Method removeEntity(entity) called on non-adaptive block mapper" );
247 template <
class StreamTraits>
249 template <
class StreamTraits>
264 template<
class Entity >
265 const SubEntityInfo &
subEntityInfo (
const Entity &entity )
const;
284 template<
class Gr
idPart,
class LocalDofMapping >
291 template<
class Iterator >
292 void operator() (
unsigned int gtIndex,
unsigned int subEntity, Iterator it, Iterator end )
295 const unsigned int numDofs = end - it;
296 if(
info.numDofs == 0 )
299 DUNE_THROW(
DofMapperError,
"Inconsistent number of DoFs on subEntity (codim = " <<
info.codim <<
")." );
312 template<
class Gr
idPart,
class LocalDofMapping >
315 template<
class Gr
idPart,
class LocalDofMapping >
316 template<
class CodeFactory >
322 : indexSet_( gridPart.indexSet() ),
323 localDofMapping_(
std::move( localDofMapping ) ),
324 code_( LocalGeometryTypeIndex::size( dimension ) ),
326 subEntityInfo_( GlobalGeometryTypeIndex::size( dimension ) )
328 std::vector< GeometryType > gt( GlobalGeometryTypeIndex::size(
dimension ) );
330 const typename RefElementsType::Iterator end = RefElementsType::end();
331 for(
typename RefElementsType::Iterator it = RefElementsType::begin(); it != end; ++it )
335 for(
int codim = 0; codim <=
dimension; ++codim )
337 for(
int i = 0; i < refElement.size( codim ); ++i )
339 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( refElement.type( i, codim ) );
340 gt[ gtIdx ] = refElement.type( i, codim );
346 code = codeFactory( refElement );
351 for(
int codim = 0; codim <=
dimension; ++codim )
358 if(
info.numDofs == 0 )
365 static const bool hasSingleGeometryType = Dune::Capabilities::hasSingleGeometryType< typename GridPartType::GridType > :: v ;
368 if (hasSingleGeometryType && geomTypes[0] != gt[i])
375 else if( codimDofs[
info.codim ] !=
info.numDofs )
378 codimDofs[
info.codim ] =
info.numDofs;
390 template<
class Gr
idPart,
class LocalDofMapping >
391 template<
class Functor >
395 const auto &idxSet = indexSet();
397 code( element )( [
this, &idxSet, &element, f ] (
unsigned int gtIndex,
unsigned int subEntity,
auto begin,
auto end ) {
399 const SizeType subIndex = idxSet.subIndex( element, subEntity,
info.codim );
401 localDofMapping_( element, subEntity,
info.codim )( index,
info.numDofs, begin, end, f );
406 template<
class Gr
idPart,
class LocalDofMapping >
410 indices.
resize( numDofs( element ) );
411 mapEach( element,
AssignFunctor< std::vector< SizeType > >( indices ) );
414 template<
class Gr
idPart,
class LocalDofMapping >
415 template<
class Entity,
class Functor >
420 const unsigned int numDofs =
info.numDofs;
422 for(
unsigned int i = 0; i <
info.numDofs; ++i )
427 template<
class Gr
idPart,
class LocalDofMapping >
428 template<
class Entity >
432 indices.
resize( numEntityDofs( entity ) );
433 mapEachEntityDof( entity,
AssignFunctor< std::vector< SizeType > >( indices ) );
436 template<
class Gr
idPart,
class LocalDofMapping >
440 const SubEntityFilter filter( RefElementsType::general( element.type() ), i, c );
441 indices.resize( numDofs( element ) );
442 code( element )( [
this, &indices, &filter ] (
unsigned int gtIndex,
unsigned int subEntity,
auto begin,
auto end ) {
443 const bool active = filter( subEntity, subEntityInfo_[ gtIndex ].codim );
444 while( begin != end )
445 indices[ *(begin++) ] = active;
449 template<
class Gr
idPart,
class LocalDofMapping >
450 template<
class Entity >
455 return subEntityInfo( entity ).
numDofs;
459 template<
class Gr
idPart,
class LocalDofMapping >
463 std::vector< int > codimensions;
464 codimensions.reserve( dimension+1 );
466 for(
typename BlockMapType::const_iterator it = blockMap_.begin(); it != blockMap_.end(); ++it )
469 codimensions.push_back(
info.codim );
473 indexSet().requestCodimensions( codimensions );
476 template<
class Gr
idPart,
class LocalDofMapping >
480 for(
const auto& geomType : blockMap_ )
482 SubEntityInfo &
info = subEntityInfo_[ GlobalGeometryTypeIndex::index( geomType ) ];
490 template<
class Gr
idPart,
class LocalDofMapping >
494 return code_[ LocalGeometryTypeIndex::index( gt ) ];
498 template<
class Gr
idPart,
class LocalDofMapping >
499 template<
class Entity >
503 return subEntityInfo_[ GlobalGeometryTypeIndex::index( entity.type() ) ];
511 template<
class Gr
idPart,
class LocalDofMapping >
528 template<
class CodeFactory >
530 :
BaseType( gridPart,
std::move( localDofMapping ), codeFactory ),
553 template<
class Gr
idPart,
class LocalDofMapping >
570 template<
class CodeFactory >
572 :
BaseType( gridPart,
std::move( localDofMapping ), codeFactory ),
606 template<
class Entity >
609 template<
class Entity >
616 template <
class StreamTraits>
619 template <
class StreamTraits>
642 template<
class Gr
idPart,
class LocalDofMapping >
646 assert( (blk >= 0) && (blk < numBlocks()) );
647 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
648 return subEntityInfo_[ gtIdx ].offset;
652 template<
class Gr
idPart,
class LocalDofMapping >
656 assert( (blk >= 0) && (blk < numBlocks()) );
657 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
658 return subEntityInfo_[ gtIdx ].oldOffset;
662 template<
class Gr
idPart,
class LocalDofMapping >
666 assert( (blk >= 0) && (blk < numBlocks()) );
667 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
673 template<
class Gr
idPart,
class LocalDofMapping >
677 assert( (hole >= 0) && (hole < numberOfHoles( blk )) );
678 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
680 const unsigned int numDofs =
info.numDofs;
681 const SizeType index = indexSet().oldIndex( hole / numDofs, blockMap_[ blk ] );
682 return info.offset + numDofs * index + (hole % numDofs);
686 template<
class Gr
idPart,
class LocalDofMapping >
690 assert( (hole >= 0) && (hole < numberOfHoles( blk )) );
691 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
693 const unsigned int numDofs =
info.numDofs;
694 const SizeType index = indexSet().newIndex( hole / numDofs, blockMap_[ blk ] );
695 return info.offset + numDofs * index + (hole % numDofs);
703 template< class GridPart, class LocalDofMapping, bool adaptive = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v >
716 template<
class Gr
idPart,
class LocalDofMapping = DefaultLocalDofMapping< Gr
idPart > >
718 :
public __IndexSetDofMapper::template Implementation< GridPart, LocalDofMapping >::Type
720 typedef typename __IndexSetDofMapper::template Implementation< GridPart, LocalDofMapping >::Type BaseType;
726 template<
class CodeFactory >
728 : BaseType( gridPart,
std::move( localDofMapping ), codeFactory )
731 template<
class CodeFactory >
741 namespace Capabilities
746 template<
class Gr
idPart,
class LocalDofMapping >
756 template<
class Gr
idPart,
class LocalDofMapping >
759 static const bool v =
true;
void removeIndexSet(const IndexSetType &iset)
removed index set from dof manager's list of index sets
Definition: dofmanager.hh:1291
void addIndexSet(const IndexSetType &iset)
add index set to dof manager's list of index sets
Definition: dofmanager.hh:1256
double max(const Dune::Fem::Double &v, const double p)
Definition: double.hh:965
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
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: dofmanager.hh:761
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
void map(const ElementType &element, std::vector< GlobalKeyType > &indices) const
Definition: indexsetdofmapper.hh:408
void removeEntity(const Entity &entity)
Definition: indexsetdofmapper.hh:238
static constexpr bool consecutive() noexcept
Definition: indexsetdofmapper.hh:200
void read(InStreamInterface< StreamTraits > &in)
Definition: indexsetdofmapper.hh:250
void mapEach(const ElementType &element, Functor f) const
map each local DoF number to a global one
Definition: indexsetdofmapper.hh:393
const DofMapperCode & code(const GeometryType >) const
Definition: indexsetdofmapper.hh:492
SizeType size_
Definition: indexsetdofmapper.hh:273
BlockMapType blockMap_
Definition: indexsetdofmapper.hh:275
unsigned int maxNumDofs_
Definition: indexsetdofmapper.hh:272
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition: indexsetdofmapper.hh:417
void requestCodimensions()
submit request for codimensions used to index set
Definition: indexsetdofmapper.hh:460
GridPart GridPartType
Definition: indexsetdofmapper.hh:115
SizeType GlobalKeyType
Definition: indexsetdofmapper.hh:113
bool contains(int codim) const
Definition: indexsetdofmapper.hh:175
GridPartType::template Codim< 0 >::EntityType ElementType
Definition: indexsetdofmapper.hh:119
const IndexSetType & indexSet() const
Definition: indexsetdofmapper.hh:267
std::vector< SubEntityInfo > subEntityInfo_
Definition: indexsetdofmapper.hh:274
void backup() const
Definition: indexsetdofmapper.hh:245
GridPartType::IndexSetType IndexSetType
Definition: indexsetdofmapper.hh:258
CodimType codimType_[dimension+1]
Definition: indexsetdofmapper.hh:276
GlobalKeyType oldIndex(int hole, int) const
Definition: indexsetdofmapper.hh:212
SizeType offSet(int) const
Definition: indexsetdofmapper.hh:227
std::vector< GeometryType > BlockMapType
Definition: indexsetdofmapper.hh:259
LocalDofMapping LocalDofMappingType
Definition: indexsetdofmapper.hh:116
void restore()
Definition: indexsetdofmapper.hh:246
std::vector< DofMapperCode > code_
Definition: indexsetdofmapper.hh:271
SizeType size() const
Definition: indexsetdofmapper.hh:179
unsigned int numDofs(const ElementType &element) const
Definition: indexsetdofmapper.hh:161
unsigned int maxNumDofs() const
Definition: indexsetdofmapper.hh:160
GridPart::GridType GridType
Definition: indexsetdofmapper.hh:117
CodimType
Definition: indexsetdofmapper.hh:78
@ CodimVariableSize
Definition: indexsetdofmapper.hh:78
@ CodimFixedSize
Definition: indexsetdofmapper.hh:78
@ CodimEmpty
Definition: indexsetdofmapper.hh:78
GlobalKeyType newIndex(int hole, int) const
Definition: indexsetdofmapper.hh:217
void resize()
Definition: indexsetdofmapper.hh:243
SizeType numBlocks() const
Definition: indexsetdofmapper.hh:202
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:438
SizeType oldOffSet(int) const
Definition: indexsetdofmapper.hh:222
bool fixedDataSize(int codim) const
Definition: indexsetdofmapper.hh:177
const DofMapperCode & code(const ElementType &element) const
Definition: indexsetdofmapper.hh:262
void mapEntityDofs(const Entity &entity, std::vector< GlobalKeyType > &indices) const
Definition: indexsetdofmapper.hh:430
SizeType numberOfHoles(int) const
Definition: indexsetdofmapper.hh:207
Dune::ReferenceElements< typename GridPart::ctype, dimension > RefElementsType
Definition: indexsetdofmapper.hh:80
void insertEntity(const Entity &entity)
Definition: indexsetdofmapper.hh:233
RefElementsType::ReferenceElement RefElementType
Definition: indexsetdofmapper.hh:81
LocalDofMapping localDofMapping_
Definition: indexsetdofmapper.hh:270
const IndexSetType & indexSet_
Definition: indexsetdofmapper.hh:269
unsigned int numEntityDofs(const Entity &entity) const
Definition: indexsetdofmapper.hh:453
void write(OutStreamInterface< StreamTraits > &out) const
Definition: indexsetdofmapper.hh:248
void update()
update mapper offsets
Definition: indexsetdofmapper.hh:477
static const int dimension
Definition: indexsetdofmapper.hh:79
bool compress()
Definition: indexsetdofmapper.hh:244
const SubEntityInfo & subEntityInfo(const Entity &entity) const
Definition: indexsetdofmapper.hh:501
std::size_t SizeType
Definition: indexsetdofmapper.hh:64
Definition: indexsetdofmapper.hh:68
SubEntityInfo()
Definition: indexsetdofmapper.hh:69
SizeType offset
Definition: indexsetdofmapper.hh:75
SizeType oldOffset
Definition: indexsetdofmapper.hh:75
unsigned int codim
Definition: indexsetdofmapper.hh:73
unsigned int numDofs
Definition: indexsetdofmapper.hh:74
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:286
BuildFunctor(std::vector< SubEntityInfo > &subEntityInfo)
Definition: indexsetdofmapper.hh:287
Definition: indexsetdofmapper.hh:514
BaseType::GridPartType::GridType GridType
Definition: indexsetdofmapper.hh:520
BaseType::SubEntityInfo SubEntityInfo
Definition: indexsetdofmapper.hh:519
BaseType::SizeType SizeType
Definition: indexsetdofmapper.hh:526
~DofMapper()
Definition: indexsetdofmapper.hh:538
DofManagerType & dofManager_
Definition: indexsetdofmapper.hh:546
DofMapper(const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:529
ThisType & operator=(const ThisType &)=delete
DofMapper(const ThisType &)=delete
BaseType::LocalDofMappingType LocalDofMappingType
Definition: indexsetdofmapper.hh:525
DofManager< GridType > DofManagerType
Definition: indexsetdofmapper.hh:521
BaseType::GridPartType GridPartType
Definition: indexsetdofmapper.hh:524
Definition: indexsetdofmapper.hh:556
bool compress()
Definition: indexsetdofmapper.hh:614
void update()
Definition: indexsetdofmapper.hh:589
int numBlocks() const
Definition: indexsetdofmapper.hh:593
void read(InStreamInterface< StreamTraits > &in)
Definition: indexsetdofmapper.hh:620
DofManager< GridType > DofManagerType
Definition: indexsetdofmapper.hh:563
BlockMapType blockMap_
Definition: indexsetdofmapper.hh:275
void write(OutStreamInterface< StreamTraits > &out) const
Definition: indexsetdofmapper.hh:617
BaseType::LocalDofMappingType LocalDofMappingType
Definition: indexsetdofmapper.hh:567
BaseType::SubEntityInfo SubEntityInfo
Definition: indexsetdofmapper.hh:561
bool consecutive() const
Definition: indexsetdofmapper.hh:604
SizeType newIndex(SizeType hole, int blk) const
Definition: indexsetdofmapper.hh:688
void insertEntity(const Entity &entity)
Definition: indexsetdofmapper.hh:607
void backup() const
Definition: indexsetdofmapper.hh:625
SizeType oldIndex(SizeType hole, int blk) const
Definition: indexsetdofmapper.hh:675
BaseType::GridPartType::GridType GridType
Definition: indexsetdofmapper.hh:562
void resize()
Definition: indexsetdofmapper.hh:612
AdaptiveDofMapper(const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:571
BaseType::GridPartType GridPartType
Definition: indexsetdofmapper.hh:566
BaseType::SizeType SizeType
Definition: indexsetdofmapper.hh:568
~AdaptiveDofMapper()
Definition: indexsetdofmapper.hh:580
AdaptiveDofMapper(const ThisType &)=delete
ThisType & operator=(const ThisType &)=delete
SizeType offSet(int blk) const
Definition: indexsetdofmapper.hh:644
SizeType numberOfHoles(int blk) const
Definition: indexsetdofmapper.hh:664
void restore()
Definition: indexsetdofmapper.hh:626
DofManagerType & dofManager_
Definition: indexsetdofmapper.hh:634
SizeType oldOffSet(int blk) const
Definition: indexsetdofmapper.hh:654
void removeEntity(const Entity &entity)
Definition: indexsetdofmapper.hh:610
Definition: indexsetdofmapper.hh:705
std::conditional< adaptive, AdaptiveDofMapper< GridPart, LocalDofMapping >, DofMapper< GridPart, LocalDofMapping > >::type Type
Definition: indexsetdofmapper.hh:706
Definition: indexsetdofmapper.hh:719
IndexSetDofMapper(const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:727
IndexSetDofMapper(const GridPartType &gridPart, const CodeFactory &codeFactory)
Definition: indexsetdofmapper.hh:732
BaseType::LocalDofMappingType LocalDofMappingType
Definition: indexsetdofmapper.hh:724
BaseType::GridPartType GridPartType
Definition: indexsetdofmapper.hh:723