1#ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_BLOCKMAPPER_HH
2#define DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_BLOCKMAPPER_HH
14#include <dune/common/exceptions.hh>
16#include <dune/geometry/dimension.hh>
18#include <dune/grid/common/gridenums.hh>
19#include <dune/grid/utility/persistentcontainer.hh>
43 template<
class Gr
idPart,
class LocalKeys >
44 struct DiscontinuousGalerkinBlockMapper;
53 template<
class Gr
idPart,
class LocalKeys >
54 struct DiscontinuousGalerkinBlockMapperTraits
56 using DofMapperType = DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys >;
57 using ElementType =
typename GridPart::template Codim< 0 >::EntityType;
58 using SizeType = std::size_t;
99 template<
class Gr
idPart,
class LocalKeys >
101 :
public AdaptiveDofMapper< DiscontinuousGalerkinBlockMapperTraits< GridPart, LocalKeys > >
120 using KeyType =
typename LocalKeysType::KeyType;
131 using GridType =
typename GridPartType::GridType;
132 using GridElementType =
typename GridType::template Codim< 0 >::Entity;
142 template<
class Function >
146 : gridPart_( gridPart ),
147 localKeys_( localKeys ),
149 keys_( gridPart_.
get().grid(), 0,
std::make_pair( key_, key_ ) ),
151 dofs_( gridPart_.
get().grid(), 0 ),
154 auto first = gridPart.template begin< 0, All_Partition >();
155 auto last = gridPart.template end< 0, All_Partition >();
156 for( ; first != last; ++first )
161 const GridElementType &gridElement =
gridEntity( element );
162 keys_[ gridElement ] = std::make_pair(
key,
key );
164 auto &
dofs = dofs_[ gridElement ];
168 dofManager_.get().addIndexSet( *
this );
201 dofManager_.get().removeIndexSet( *
this );
219 return numDofs( element, Codim< ElementType::codimension >() );
223 template<
class Entity >
226 return numDofs( entity, Codim< Entity::codimension >() );
231 indices.resize(
numDofs(element) );
233 std::fill(indices.begin(),indices.end(),
true);
235 std::fill(indices.begin(),indices.end(),
false);
239 static constexpr bool contains (
const int codim ) {
return (codim == 0); }
245 template<
class Function >
248 mapEach( element, function, Codim< ElementType::codimension >() );
252 template<
class Entity,
class Function >
255 mapEach( entity, function, Codim< Entity::codimension >() );
261 assert( block == 0 );
262 return indices_.size();
268 assert( block == 0 );
270 assert( dof != std::numeric_limits< GlobalKeyType >::max() );
271 return std::move( dof );
277 assert( block == 0 );
278 return indices_[ hole ].second;
300 template<
class Element >
301 typename std::enable_if< (std::is_same< Element, ElementType >::value || std::is_same< Element, GridElementType >::value),
const KeyType & >::type
302 key (
const Element &element )
const
310 assert( gridPart().indexSet().
contains( element ) );
317 assert( gridPart().indexSet().
contains( element ) );
322 template<
class Function >
330 const std::vector< std::size_t > &,
331 const std::vector< std::size_t > & )
333 return adapt( function );
349 resize( keys_, std::make_pair( key_, key_ ) );
351 resize( dofs_[ gridElement ], localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
357 auto &
dofs = dofs_[ gridElement ];
360 Resize function( holes_ );
361 for(
auto dof :
dofs )
368 if( gridElement.isNew() )
370 resize( dofs_[ gridElement ], localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
371 assert( gridElement.hasFather() );
372 const GridElementType &father = gridElement.father();
378 auto &
dofs = dofs_[ gridElement ];
379 resize(
dofs, localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
380 for(
auto dof :
dofs )
382 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), dof );
383 if( iterator != holes_.end() && *iterator == dof )
384 holes_.erase( iterator );
392 resize( keys_, std::make_pair( key_, key_ ) );
394 auto first = gridPart().template begin< 0, All_Partition >();
395 auto last = gridPart().template end< 0, All_Partition >();
396 for( ; first != last; ++first )
403 resize(
dofs, localKeys().blocks( element.type(),
key( element ) ) );
411 template<
class Traits >
414 DUNE_THROW( NotImplemented,
"Method write() not implemented yet" );
418 template<
class Traits >
421 DUNE_THROW( NotImplemented,
"Method read() not implemented yet" );
427 DUNE_THROW( NotImplemented,
"Method backup() not implemented" );
433 DUNE_THROW( NotImplemented,
"Method restore() not implemented" );
437 bool compressed ()
const {
return holes_.empty(); }
439 template<
class Element,
class Function >
440 void mapEach (
const Element &element,
Function function, Codim< 0 > )
const
444 for( std::size_t i = 0; i <
size; ++i )
445 function( i,
dofs[ i ] );
448 template<
class Entity,
class Function,
int codim >
449 void mapEach (
const Entity &entity, Function function, Codim< codim > )
const
452 template<
class Element >
458 template<
class Entity,
int codim >
466 size_ =
dofs.reserve( n, Reserve( size_ ) );
467 dofs.resize( Resize( holes_ ) );
471 static void resize ( PersistentContainer< GridType, T > &container,
const T &value = T() )
473 container.resize( value );
474 container.shrinkToFit();
477 const GridPartType &gridPart ()
const {
return gridPart_.get(); }
479 const LocalKeysType &localKeys ()
const {
return localKeys_.get(); }
481 std::reference_wrapper< const GridPartType > gridPart_;
482 std::reference_wrapper< const LocalKeysType > localKeys_;
485 PersistentContainer< GridType, std::pair< KeyType, KeyType > > keys_;
488 PersistentContainer< GridType, LocalDofStorageType > dofs_;
490 std::vector< GlobalKeyType > holes_;
491 std::vector< std::pair< GlobalKeyType, GlobalKeyType > > indices_;
493 std::reference_wrapper< DofManagerType > dofManager_;
501 template<
class Gr
idPart,
class LocalKeys >
519 template<
class Gr
idPart,
class LocalKeys >
522 explicit Resize ( std::vector< GlobalKeyType > &holes )
525 assert( std::is_sorted( holes_.begin(), holes_.end() ) );
530 assert( std::is_sorted( holes_.begin(), holes_.end() ) );
535 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), dof );
536 if( iterator == holes_.end() || *iterator != dof )
537 holes_.insert( iterator, dof );
541 std::vector< GlobalKeyType > &holes_;
549 template<
class Gr
idPart,
class LocalKeys >
550 template<
class Function >
554 gridPart().communicate( dataHandle, InteriorBorder_All_Interface, ForwardCommunication );
556 std::vector< std::size_t > origin, destination;
557 origin.reserve( maxNumDofs() );
558 destination.reserve( maxNumDofs() );
560 std::size_t count = 0;
562 auto first = gridPart().template begin< 0, All_Partition >();
563 auto last = gridPart().template end< 0, All_Partition >();
564 for( ; first != last; ++first )
567 const GridElementType &gridElement =
gridEntity( element );
568 auto &keys = keys_[ gridElement ];
569 if( keys.first == keys.second )
573 const KeyType prior = keys.first;
574 auto &
dofs = dofs_[ gridElement ];
575 origin.resize(
dofs.size() );
576 std::copy(
dofs.begin(),
dofs.end(), origin.begin() );
579 keys.first = keys.second;
580 resize(
dofs, localKeys().blocks( gridElement.type(), keys.first ) );
583 destination.resize(
dofs.size() );
584 std::copy(
dofs.begin(),
dofs.end(), destination.begin() );
585 function( element, prior, keys.first, origin, destination );
597 template<
class Gr
idPart,
class LocalKeys >
602 resize( keys_, std::make_pair( key_, key_ ) );
604 for(
auto &
dofs : dofs_ )
615 assert( size_ >= holes_.size() );
616 size_ -= holes_.size();
619 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), size_ );
620 holes_.erase( iterator, holes_.end() );
623 auto assign = [](
GlobalKeyType newIndex ) -> std::pair< GlobalKeyType, GlobalKeyType >
625 GlobalKeyType oldIndex = std::numeric_limits< GlobalKeyType >::max();
626 return std::make_pair( oldIndex, newIndex );
628 indices_.resize( holes_.size() );
629 std::transform( holes_.begin(), holes_.end(), indices_.begin(), assign );
632 std::size_t hole = 0u;
633 for(
auto &
dofs : dofs_ )
635 for(
auto &dof :
dofs )
639 auto &indices = indices_.at( hole++ );
641 dof = indices.second;
646 assert( hole == holes_.size() );
650 PersistentContainer< GridType, std::pair< KeyType, KeyType > > tmp( gridPart().grid(), 0, std::make_pair( key_, key_ ) );
651 auto first = gridPart().template begin< 0, All_Partition >();
652 auto last = gridPart().template end< 0, All_Partition >();
653 for( ; first != last; ++first )
656 const GridElementType &gridElement =
gridEntity( element );
657 tmp[ gridElement ] = keys_[ gridElement ];
666 namespace Capabilities
671 template<
class Gr
idPart,
class LocalKeys >
674 static const bool v =
true;
680 template<
class Gr
idPart,
class LocalKeys >
683 static const bool v =
true;
Definition: bindguard.hh:11
std::tuple_element< i, Tuple >::type & get(Dune::TypeIndexedTuple< Tuple, Types > &tuple)
Definition: typeindexedtuple.hh:122
const GridEntityAccess< Entity >::GridEntityType & gridEntity(const Entity &entity)
Definition: gridpart.hh:412
IteratorRange< typename DF::DofIteratorType > dofs(DF &df)
Iterates over all DOFs.
Definition: rangegenerators.hh:76
Abstract class representing a function.
Definition: common/function.hh:50
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
abstract interface for an output stream
Definition: streams.hh:46
abstract interface for an input stream
Definition: streams.hh:179
Definition: dofmanager.hh:761
An -adaptive Dune::Fem::DofMapper.
Definition: blockmapper.hh:102
void backup() const
this mapper has no I/O capabilities
Definition: blockmapper.hh:425
static constexpr SizeType oldOffSet(const int block)
return 0 (this mapper has no offset)
Definition: blockmapper.hh:285
DiscontinuousGalerkinBlockMapper(const GridPartType &gridPart, const LocalKeysType &localKeys, const KeyType &value)
Definition: blockmapper.hh:171
SizeType size() const
return number of dofs
Definition: blockmapper.hh:211
GlobalKeyType newIndex(const int hole, const int block) const
return new index of given hole during compression
Definition: blockmapper.hh:275
std::enable_if<(std::is_same< Element, ElementType >::value||std::is_same< Element, GridElementType >::value), constKeyType & >::type key(const Element &element) const
get key currently assigned to an entity
Definition: blockmapper.hh:302
typename LocalKeysType::KeyType KeyType
key type
Definition: blockmapper.hh:120
static constexpr bool consecutive()
return true (this mapper yields a consecutive DOF numbering)
Definition: blockmapper.hh:282
GridPart GridPartType
grid part type
Definition: blockmapper.hh:113
void write(OutStreamInterface< Traits > &)
this mapper has no I/O capabilities
Definition: blockmapper.hh:412
void mapEachEntityDof(const Entity &entity, Function function) const
map local dof to global key
Definition: blockmapper.hh:253
DiscontinuousGalerkinBlockMapper(const ThisType &)=delete
copy constructor
void mapEach(const ElementType &element, Function function) const
map local dof to global key
Definition: blockmapper.hh:246
LocalKeys LocalKeysType
basis function sets type
Definition: blockmapper.hh:118
SizeType numEntityDofs(const Entity &entity) const
return number of dofs for given element
Definition: blockmapper.hh:224
ThisType & operator=(const ThisType &)=delete
assignment operator
typename BaseType::ElementType ElementType
element type
Definition: blockmapper.hh:115
void insertNewEntity(const GridElementType &gridElement)
add DOFs for new element
Definition: blockmapper.hh:366
bool adapt()
please doc me
Definition: blockmapper.hh:326
void insertEntity(const GridElementType &gridElement)
add DOFs for element
Definition: blockmapper.hh:346
static constexpr bool fixedDataSize(int codim)
return true if number of dofs is fixed for given codimension
Definition: blockmapper.hh:242
const DofManagerType & dofManager() const
return DOF manager
Definition: blockmapper.hh:343
DiscontinuousGalerkinBlockMapper(const GridPartType &gridPart, const LocalKeysType &localKeys, const KeyType &value, Function function)
Definition: blockmapper.hh:143
KeyType getMark(const ElementType &element) const
get key to be assigned to an entity after next call to adapt()
Definition: blockmapper.hh:315
bool compress()
compress DOF mapping
Definition: blockmapper.hh:598
DiscontinuousGalerkinBlockMapper(ThisType &&)=default
move constructor
typename BaseType::GlobalKeyType GlobalKeyType
global key type
Definition: blockmapper.hh:110
void read(InStreamInterface< Traits > &)
this mapper has no I/O capabilities
Definition: blockmapper.hh:419
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
Definition: blockmapper.hh:229
SizeType numDofs(const ElementType &element) const
return number of dofs for given element
Definition: blockmapper.hh:217
int maxNumDofs() const
return upper bound for number of dofs
Definition: blockmapper.hh:214
SizeType numberOfHoles(const int block) const
return number of holes during compression
Definition: blockmapper.hh:259
static constexpr bool contains(const int codim)
return true if dofs are associated to codimension
Definition: blockmapper.hh:239
void removeEntity(const GridElementType &gridElement)
mark DOFs for removal
Definition: blockmapper.hh:355
GlobalKeyType oldIndex(const int hole, const int block) const
return old index of given hole during compression
Definition: blockmapper.hh:266
static constexpr SizeType offSet(const int block)
return 0 (this mapper has no offset)
Definition: blockmapper.hh:288
void resize()
Definition: blockmapper.hh:389
void restore()
this mapper has no I/O capabilities
Definition: blockmapper.hh:431
void mark(const KeyType &key, const ElementType &element)
set key to be assigned to an entity after next call to adapt()
Definition: blockmapper.hh:308
static constexpr SizeType numBlocks()
return 1 (this mapper has one block)
Definition: blockmapper.hh:291
typename BaseType::SizeType SizeType
size type
Definition: blockmapper.hh:108
Definition: blockmapper.hh:503
Reserve(SizeType &size)
Definition: blockmapper.hh:504
Definition: blockmapper.hh:521
~Resize()
Definition: blockmapper.hh:528
Resize(std::vector< GlobalKeyType > &holes)
Definition: blockmapper.hh:522
Definition: space/hpdg/datahandle.hh:32
Definition: localdofstorage.hh:25
Definition: space/mapper/capabilities.hh:22
static const bool v
Definition: space/mapper/capabilities.hh:23
Traits::ElementType ElementType
type of codimension 0 entities
Definition: mapper/dofmapper.hh:54
Extended interface for adaptive DoF mappers.
Definition: mapper/dofmapper.hh:219
SizeType GlobalKeyType
at the moment this should be similar to SizeType
Definition: mapper/dofmapper.hh:230
BaseType::SizeType SizeType
type of size integer
Definition: mapper/dofmapper.hh:227