1#ifndef DUNE_FEM_GENERICPADAPTIVEDOFMAPPER_HH
2#define DUNE_FEM_GENERICPADAPTIVEDOFMAPPER_HH
4#include <dune/common/exceptions.hh>
6#include <dune/geometry/type.hh>
8#include <dune/grid/utility/persistentcontainer.hh>
12#include <dune/fem/misc/metaprogramming.hh>
29 template<
class TraitsImp >
54 typedef typename GridPartType::GridType
GridType;
90 std::vector< DofVectorType >
dofs_;
115 const int dofSize = otherDofs.size();
116 dofs.resize( dofSize );
117 for(
int d = 0; d<dofSize; ++d )
118 dofs[ d ] = otherDofs[ d ];
134 bool exists(
const int codim,
const int polOrd )
const
137 return dofs_[ entry ].size() > 0 ;
141 bool use(
const int codim,
const int polOrd )
145 return (
used_[ entry ] == 1 );
151 const int numDofs,
const int startDof )
153 use( codim, polOrd );
154 assert( !
exists ( codim, polOrd ) );
167 assert( codim >= 0 );
177 void remove(
const int codim,
const int polOrd )
180 if(
used_[ entry ] > 0 )
190 int dof (
const int codim,
const int polOrd,
const size_t dofNumber )
const
193 assert( entry <
dofs_.size() );
194 assert(
type_ != GeometryType() );
195 assert( dofNumber <
dofs_[ entry ].
size() );
196 return dofs_[ entry ][ dofNumber ];
203 const int dofSize =
dofs_[ k ].size();
204 if( dofNumber < dofSize )
205 return dofs_[ k ][ dofNumber ];
207 dofNumber -= dofSize;
220 dofSize +=
dofs_[ k ].size();
225 template <
class VectorType>
232 const int dofSize =
dofs.size();
238 for(
int d = 0; d<dofSize; ++d )
243 assert(
dof < (
int)isHole.size() );
244 isHole[
dof ] = false ;
261 const int dofSize =
dofs.size();
262 for(
int d = 0; d<dofSize; ++d )
263 std::cout <<
dofs[ d ] <<
" dofs " << std::endl;
267 template <
class VectorType>
269 VectorType& holesVec,
int& currentHole,
270 const int usedSize,
int& holes )
272 bool haveToCopy = false ;
276 const int dofSize =
dofs.size();
279 assert(
used_[ k ] );
284 if( currDof >= usedSize )
291 assert(currentHole >= 0);
292 assert( holesVec[currentHole] < usedSize );
295 oldIdx[ holes ] = currDof;
296 currDof = holesVec[ currentHole ];
297 newIdx[ holes ] = currDof ;
317 signed char active_ ;
332 bool active ()
const {
return active_ > 0; }
354 template <
int codim,
bool dg>
359 const int subEntity )
361 return clk.numDofs( codim, subEntity );
370 const int subEntity )
379 template <
int codim >
386 unsigned int& globalSize,
387 unsigned int& notAlreadyCounted,
395 bool notCountedYet = false ;
396 if( ! entityDofs.
exists( codim, polOrd ) )
398 entityDofs.
insert( entity.type(), codim, polOrd,
numDofs, globalSize );
400 notCountedYet = true ;
405 notCountedYet = entityDofs.
use( codim, polOrd );
419 unsigned int& globalSize,
420 unsigned int& notAlreadyCounted,
421 std::vector< DofContainerType* > dofContainers )
426 insertDofs( entity, clk, polOrd, 0, globalSize,
431 const int count = entity.subEntities( codim );
432 for(
int i=0; i<count; ++i )
434 insertDofs( entity, clk, polOrd, i, globalSize,
441 template <
int codim >
446 std::vector< DofContainerType* > dofContainers )
449 const int count = entity.subEntities( codim );
450 for(
int i=0; i<count; ++i )
453 entityDofs.
remove( codim, polOrd );
463 : gridPart_( gridPart ),
465 compiledLocalKeys_( compiledLocalKeyVector ),
474 sequence_( dm_.sequence() )
479 for(
size_t i=0; i<compiledLocalKeys_.size(); ++i )
481 maxNumDofs_ = std :: max( maxNumDofs_, compiledLocalKeys_[ i ].maxSize() );
493 : gridPart_( other.gridPart_ ),
495 compiledLocalKeys_( compiledLocalKeyVector ),
497 entityPolynomOrder_( other.entityPolynomOrder_ ),
499 numberOfHoles_( other.numberOfHoles_ ),
500 oldIndex_( other.oldIndex_ ),
501 newIndex_( other.newIndex_ ),
502 size_( other.size_ ),
503 maxNumDofs_( other.maxNumDofs_ ),
504 sequence_( other.sequence_ )
507 dofContainer_[ codim ] =
new DofContainerType( *(other.dofContainer_[ codim ]) );
514 return entityPolynomOrder_[ entity ].order();
519 return entityPolynomOrder_[ entity ].suggestedOrder();
525 if( polOrd < minOrder || polOrd > order_ )
528 entityPolynomOrder_[ entity ].suggest( polOrd );
533 assert( codim < dofContainer_.size() );
534 assert( dofContainer_[ codim ] );
535 return *(dofContainer_[ codim ]);
542 return compiledLocalKeys_[ polOrd ][ type ];
557 template<
class Functor >
560 const int n =
numDofs( element );
561 for(
int i = 0; i < n; ++i )
574 return dofContainer( 0 )[ entity ].dof( 0, polOrd, localDof );
583 const Fem::LocalKey &dofInfo = compLocalKey.localKey( localDof );
585 const unsigned int codim = dofInfo.
codim();
586 const unsigned int subEntity = dofInfo.
subEntity();
588 unsigned int index = dofInfo.
index() ;
593 auto refElem = referenceElement< FieldType, dimension >( entity.type() );
596 const int vxSize = refElem.size( subEntity, codim,
dimension );
598 assert( vxSize == 2 );
600 const int vx[ 2 ] = { refElem.subEntity ( subEntity, codim, 0,
dimension ),
601 refElem.subEntity ( subEntity, codim, 1,
dimension ) };
604 if( gridPart_.grid().localIdSet().subId( entity, vx[ 0 ],
dimension ) >
605 gridPart_.grid().localIdSet().subId( entity, vx[ 1 ],
dimension ) )
607 const unsigned int numDofsSubEntity = compLocalKey.numDofs( codim, subEntity );
608 index = numDofsSubEntity - index - 1;
612 assert( index < compLocalKey.numDofs( codim, subEntity ) );
613 return dofContainer( codim )( entity, subEntity ).dof( codim, polOrd, index );
618 template<
class Entity,
class Functor >
622 for(
int i = 0; i < n; ++i )
623 f( i,
dofContainer( Entity::codimension )[ entity ].entityDof( i ) );
628 indices.resize(
numDofs(element) );
632 std::fill(indices.begin(),indices.end(),
true);
634 std::fill(indices.begin(),indices.end(),
false);
638 DUNE_THROW( NotImplemented,
"Method onSubEntity(...) not yet implemented for TupleMapper" );
644 indices.resize(
numDofs( element ) );
648 template<
class Entity >
649 void mapEntityDofs (
const Entity &entity, std::vector< SizeType > &indices )
const
669 template<
class Entity >
674 if( Entity :: codimension == 0 )
683 return dofContainer( Entity :: codimension )[ entity ].entityDofs();
700 int oldIndex (
const int hole,
const int block )
const
702 assert( oldIndex_[ hole ] >= 0 );
703 return oldIndex_[ hole ];
707 int newIndex (
const int hole,
const int block )
const
709 assert( newIndex_[ hole ] >= 0 );
710 return newIndex_[ hole ];
716 return numberOfHoles_;
750 entityPolynomOrder_.shrinkToFit();
768 if( ! polyStorage.
active() )
770 unsigned int notAlreadyCounted = 0;
772 const int polOrd = polyStorage.
order();
783 apply( entity, clk, polOrd, size_, notAlreadyCounted, dofContainer_ );
786 return notAlreadyCounted ;
796 if( entityPolynomOrder_[ entity ].deactivate( polOrd ) )
799 apply( entity, polOrd, dofContainer_ );
813 for(
auto& pol : entityPolynomOrder_ )
824 if( entity.hasFather() )
842 return DGFGridInfo< GridType > :: refineStepsForHalf() > 1 ||
843 ! Dune::Capabilities::hasSingleGeometryType<GridType> :: v ;
857 typedef typename GridPartType :: template Codim< 0 > :: IteratorType IteratorType;
858 const IteratorType end = gridPart_.template end<0>();
859 for( IteratorType it = gridPart_.template begin<0>();
863 if( considerHierarchyOfElements )
882 typedef typename GridPartType :: template Codim< 0 > :: IteratorType IteratorType;
883 const IteratorType end = gridPart_.template end<0>();
884 for( IteratorType it = gridPart_.template begin<0>();
893 std::cout <<
"Print entity " << gridPart_.grid().localIdSet().id( entity ) <<
" with " << std::endl;
894 for(
int i = 0; i<
numDofs( entity ); ++i )
896 std::cout <<
"en[ " << i <<
" ] = " <<
mapToGlobal( entity, i ) << std::endl;
905 typedef typename PolyOrderContainerType :: Iterator Iterator;
906 const Iterator endit = entityPolynomOrder_.end();
907 for( Iterator it = entityPolynomOrder_.begin(); it != endit; ++it )
918 typedef typename DofContainerType :: Iterator Iterator;
919 const Iterator endit = codimContainer.end();
920 for( Iterator it = codimContainer.begin(); it != endit; ++it )
950 bool haveToCopy =
false;
952 std::vector<int> validHoles;
956 std::vector< bool > holeMarker( size_,
true );
962 typedef typename DofContainerType :: Iterator Iterator;
963 const Iterator endit = codimContainer.end();
964 for( Iterator it = codimContainer.begin(); it != endit; ++it )
973 validHoles.reserve( usedSize );
974 validHoles.resize( 0 );
977 for(
size_t i=0; i<usedSize; ++i )
980 if( holeMarker[ i ] )
983 validHoles.push_back( i );
988 if( validHoles.size() > 0 )
991 int currentHole = validHoles.size();
994 oldIndex_.resize( currentHole, -1) ;
995 newIndex_.resize( currentHole, -1) ;
1000 typedef typename DofContainerType :: Iterator Iterator;
1001 const Iterator endit = codimContainer.end();
1002 for( Iterator it = codimContainer.begin(); it != endit; ++it )
1009 haveToCopy |= dof.
removeHoles( oldIndex_, newIndex_,
1010 validHoles, currentHole,
1011 usedSize, numberOfHoles_ );
1033 template<
class InStream >
1037 template<
class OutStream >
1057 mutable std::vector< DofContainerType* > dofContainer_;
1059 int numberOfHoles_ ;
1060 std::vector< int > oldIndex_ ;
1061 std::vector< int > newIndex_ ;
1063 mutable unsigned int size_;
1064 unsigned int maxNumDofs_;
1069 namespace Capabilities
1074 template<
class Traits >
1077 static const bool v =
true;
1080 template<
class Traits >
1083 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
int sequence() const
return number of sequence, if dofmanagers memory was changed by calling some method like resize,...
Definition: dofmanager.hh:978
Dune::Fem::Double abs(const Dune::Fem::Double &a)
Definition: double.hh:942
Definition: bindguard.hh:11
Double abs(const Double &a)
Definition: double.hh:871
IteratorRange< typename DF::DofIteratorType > dofs(DF &df)
Iterates over all DOFs.
Definition: rangegenerators.hh:76
static DUNE_PRIVATE void apply(Args &&... args)
Definition: forloop.hh:23
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
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
Extended interface for adaptive DoF mappers.
Definition: mapper/dofmapper.hh:219
const Implementation & asImp() const
Definition: bartonnackmaninterface.hh:37
Definition: genericadaptivedofmapper.hh:32
int offSet(const int block) const
Definition: genericadaptivedofmapper.hh:735
GenericAdaptiveDofMapper(const ThisType &)=delete
@ minOrder
Definition: genericadaptivedofmapper.hh:83
void printEntityDofs(const ElementType &entity) const
Definition: genericadaptivedofmapper.hh:891
EntityDofStorage EntityDofStorageType
Definition: genericadaptivedofmapper.hh:310
unsigned int insertEntityDofs(const ElementType &entity)
Definition: genericadaptivedofmapper.hh:765
static const bool discontinuousMapper
Definition: genericadaptivedofmapper.hh:41
bool consecutive() const
Definition: genericadaptivedofmapper.hh:741
int numberOfHoles(const int block) const
Definition: genericadaptivedofmapper.hh:714
int newIndex(const int hole, const int block) const
Definition: genericadaptivedofmapper.hh:707
PolynomialOrderStorage PolynomialOrderStorageType
Definition: genericadaptivedofmapper.hh:348
void setUnused()
reset all used flags of all DoF entries
Definition: genericadaptivedofmapper.hh:901
void insertEntity(const ElementType &entity)
Definition: genericadaptivedofmapper.hh:758
void mapEntityDofs(const Entity &entity, std::vector< SizeType > &indices) const
Definition: genericadaptivedofmapper.hh:649
std::size_t SizeType
Definition: genericadaptivedofmapper.hh:38
DofManager< GridType > DofManagerType
type of the DoF manager
Definition: genericadaptivedofmapper.hh:81
@ maxOrder
Definition: genericadaptivedofmapper.hh:84
Traits::ElementType ElementType
type of entities (codim 0)
Definition: genericadaptivedofmapper.hh:51
GenericAdaptiveDofMapper(const GenericAdaptiveDofMapper &other, const int order, CompiledLocalKeyVectorType &compiledLocalKeyVector)
sort of copy constructor
Definition: genericadaptivedofmapper.hh:490
Traits::GridPartType GridPartType
type of the grid part
Definition: genericadaptivedofmapper.hh:48
GridPartType::GridType GridType
type of the underlying grid
Definition: genericadaptivedofmapper.hh:54
PersistentContainer< GridType, PolynomialOrderStorageType > PolyOrderContainerType
Definition: genericadaptivedofmapper.hh:352
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
Definition: genericadaptivedofmapper.hh:626
@ numOrders
Definition: genericadaptivedofmapper.hh:85
GridPartType::IndexSetType IndexSetType
type of the index set
Definition: genericadaptivedofmapper.hh:57
Traits::CompiledLocalKeyVectorType CompiledLocalKeyVectorType
type of vector containing compiled local keys
Definition: genericadaptivedofmapper.hh:75
int suggestedOrder(const ElementType &entity) const
Definition: genericadaptivedofmapper.hh:517
void mapEachEntityDof(const Entity &entity, Functor f) const
map each local DoF number to a global key
Definition: genericadaptivedofmapper.hh:619
ThisType & operator=(const ThisType &)=delete
void restore()
Definition: genericadaptivedofmapper.hh:1030
TraitsImp Traits
Definition: genericadaptivedofmapper.hh:37
int numDofs(const ElementType &entity) const
obtain number of DoFs on an entity
Definition: genericadaptivedofmapper.hh:662
void write(OutStream &out)
Definition: genericadaptivedofmapper.hh:1038
void read(InStream &in)
Definition: genericadaptivedofmapper.hh:1034
GenericAdaptiveDofMapper(const GridPartType &gridPart, const int order, CompiledLocalKeyVectorType &compiledLocalKeyVector)
constructor
Definition: genericadaptivedofmapper.hh:460
int numEntityDofs(const Entity &entity) const
obtain number of DoFs actually belonging to an entity
Definition: genericadaptivedofmapper.hh:670
static const int polynomialOrder
order of the Lagrange polynoms
Definition: genericadaptivedofmapper.hh:72
int mapToGlobal(const ElementType &entity, const int localDof) const
Definition: genericadaptivedofmapper.hh:566
Traits::GlobalKeyType GlobalKeyType
type of global key
Definition: genericadaptivedofmapper.hh:60
void suggestPolynomOrder(const ElementType &entity, const int polOrd)
Definition: genericadaptivedofmapper.hh:522
PersistentContainer< GridType, EntityDofStorageType > DofContainerType
Definition: genericadaptivedofmapper.hh:350
size_t insertAllUsed()
return number of DoFs currently used for space
Definition: genericadaptivedofmapper.hh:847
bool fixedDataSize(int codim) const
Check, whether the data in a codimension has fixed size.
Definition: genericadaptivedofmapper.hh:694
DofContainerType & dofContainer(const std::size_t codim) const
Definition: genericadaptivedofmapper.hh:531
int oldOffSet(const int block) const
Definition: genericadaptivedofmapper.hh:728
int size() const
return overall number of degrees of freedom
Definition: genericadaptivedofmapper.hh:552
void adapt()
adjust mapper to newly set polynomial orders
Definition: genericadaptivedofmapper.hh:810
static const int dimension
dimension of the grid
Definition: genericadaptivedofmapper.hh:66
void removeEntity(const ElementType &entity)
Definition: genericadaptivedofmapper.hh:792
unsigned int insertFather(const ElementType &entity)
Definition: genericadaptivedofmapper.hh:822
CompiledLocalKeyVectorType::value_type::value_type CompiledLocalKeyType
compiled local key type
Definition: genericadaptivedofmapper.hh:78
void mapEach(const ElementType &element, Functor f) const
Definition: genericadaptivedofmapper.hh:558
int numBlocks() const
Definition: genericadaptivedofmapper.hh:721
int polynomOrder(const ElementType &entity) const
Definition: genericadaptivedofmapper.hh:512
virtual ~GenericAdaptiveDofMapper()
destructor
Definition: genericadaptivedofmapper.hh:546
void backup() const
Definition: genericadaptivedofmapper.hh:1027
GridType::ctype FieldType
type of coordinates within the grid
Definition: genericadaptivedofmapper.hh:63
bool contains(int codim) const
Check, whether any DoFs are associated with a codimension.
Definition: genericadaptivedofmapper.hh:688
bool compress()
Definition: genericadaptivedofmapper.hh:928
static const int highestDimension
highest codimension used to attach dofs
Definition: genericadaptivedofmapper.hh:69
const CompiledLocalKeyType & compiledLocalKey(const int polOrd, const GeometryType type) const
Definition: genericadaptivedofmapper.hh:539
void map(const ElementType &element, std::vector< SizeType > &indices) const
Definition: genericadaptivedofmapper.hh:642
int maxNumDofs() const
obtain maximal number of DoFs on one entity
Definition: genericadaptivedofmapper.hh:656
void resize()
Definition: genericadaptivedofmapper.hh:803
void printDofs() const
Definition: genericadaptivedofmapper.hh:879
int oldIndex(const int hole, const int block) const
Definition: genericadaptivedofmapper.hh:700
void resizeContainers()
Definition: genericadaptivedofmapper.hh:747
bool considerHierarchy() const
return true if elements can be refined more than once during adaptation
Definition: genericadaptivedofmapper.hh:840
Definition: genericadaptivedofmapper.hh:88
bool use(const int codim, const int polOrd)
returns true if entry has a reference count of 1
Definition: genericadaptivedofmapper.hh:141
int entityDofs() const
Definition: genericadaptivedofmapper.hh:215
int dof(const int codim, const int polOrd, const size_t dofNumber) const
Definition: genericadaptivedofmapper.hh:190
bool removeHoles(VectorType &oldIdx, VectorType &newIdx, VectorType &holesVec, int ¤tHole, const int usedSize, int &holes)
Definition: genericadaptivedofmapper.hh:268
std::vector< DofVectorType > dofs_
Definition: genericadaptivedofmapper.hh:90
void insert(const GeometryType type, const int codim, const int polOrd, const int numDofs, const int startDof)
Definition: genericadaptivedofmapper.hh:148
int entityDof(int dofNumber) const
Definition: genericadaptivedofmapper.hh:199
EntityDofStorage(const EntityDofStorage &other)
Definition: genericadaptivedofmapper.hh:122
char used_[numOrders]
Definition: genericadaptivedofmapper.hh:93
int determineVectorEntry(const int codim, const int polOrd) const
Definition: genericadaptivedofmapper.hh:165
void printDofs() const
Definition: genericadaptivedofmapper.hh:256
void detectUnusedDofs(VectorType &isHole, const int actSize)
Definition: genericadaptivedofmapper.hh:226
GeometryType type_
Definition: genericadaptivedofmapper.hh:92
void assign(const EntityDofStorage &other)
Definition: genericadaptivedofmapper.hh:104
EntityDofStorage & operator=(const EntityDofStorage &other)
Definition: genericadaptivedofmapper.hh:128
EntityDofStorage()
Definition: genericadaptivedofmapper.hh:95
const GeometryType & type() const
Definition: genericadaptivedofmapper.hh:175
void reset()
Definition: genericadaptivedofmapper.hh:184
void remove(const int codim, const int polOrd)
Definition: genericadaptivedofmapper.hh:177
bool exists(const int codim, const int polOrd) const
Definition: genericadaptivedofmapper.hh:134
std::vector< int > DofVectorType
Definition: genericadaptivedofmapper.hh:89
Definition: genericadaptivedofmapper.hh:313
void set(const int k)
Definition: genericadaptivedofmapper.hh:330
int order() const
Definition: genericadaptivedofmapper.hh:322
void suggest(const int k)
Definition: genericadaptivedofmapper.hh:323
void update()
Definition: genericadaptivedofmapper.hh:345
int suggested() const
Definition: genericadaptivedofmapper.hh:344
bool deactivate(int &k)
Definition: genericadaptivedofmapper.hh:333
void activate()
Definition: genericadaptivedofmapper.hh:331
PolynomialOrderStorage(const int k)
Definition: genericadaptivedofmapper.hh:321
bool active() const
Definition: genericadaptivedofmapper.hh:332
Definition: genericadaptivedofmapper.hh:356
static int numDofs(const ElementType &entity, const CompiledLocalKeyType &clk, const int subEntity)
Definition: genericadaptivedofmapper.hh:357
static int numDofs(const ElementType &entity, const CompiledLocalKeyType &clk, const int subEntity)
Definition: genericadaptivedofmapper.hh:368
Definition: genericadaptivedofmapper.hh:381
static void insertDofs(const ElementType &entity, const CompiledLocalKeyType &clk, const int polOrd, const int subEntity, unsigned int &globalSize, unsigned int ¬AlreadyCounted, EntityDofStorage &entityDofs)
Definition: genericadaptivedofmapper.hh:382
static void apply(const ElementType &entity, const CompiledLocalKeyType &clk, const int polOrd, unsigned int &globalSize, unsigned int ¬AlreadyCounted, std::vector< DofContainerType * > dofContainers)
Definition: genericadaptivedofmapper.hh:416
Definition: genericadaptivedofmapper.hh:443
static void apply(const ElementType &entity, const int polOrd, std::vector< DofContainerType * > dofContainers)
Definition: genericadaptivedofmapper.hh:444
Definition: localkey.hh:21
unsigned int subEntity() const
Definition: localkey.hh:26
unsigned int index() const
Definition: localkey.hh:28
unsigned int codim() const
Definition: localkey.hh:27