1 #ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_BLOCKMAPPER_HH
2 #define DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_BLOCKMAPPER_HH
10 #include <type_traits>
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 >() );
230 static constexpr
bool contains (
const int codim ) {
return (codim == 0); }
236 template<
class Function >
239 mapEach( element,
function, Codim< ElementType::codimension >() );
243 template<
class Entity,
class Function >
246 mapEach( entity,
function, Codim< Entity::codimension >() );
252 assert( block == 0 );
253 return indices_.size();
259 assert( block == 0 );
262 return std::move( dof );
268 assert( block == 0 );
269 return indices_[ hole ].second;
291 template<
class Element >
292 typename std::enable_if< (std::is_same< Element, ElementType >::value || std::is_same< Element, GridElementType >::value),
const KeyType & >::type
293 key (
const Element &element )
const
301 assert( gridPart().indexSet().
contains( element ) );
308 assert( gridPart().indexSet().
contains( element ) );
313 template<
class Function >
321 const std::vector< std::size_t > &,
322 const std::vector< std::size_t > & )
324 return adapt(
function );
340 resize( keys_, std::make_pair( key_, key_ ) );
342 resize( dofs_[ gridElement ], localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
348 auto &
dofs = dofs_[ gridElement ];
351 Resize function( holes_ );
352 for(
auto dof :
dofs )
359 if( gridElement.isNew() )
361 resize( dofs_[ gridElement ], localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
362 assert( gridElement.hasFather() );
363 const GridElementType &father = gridElement.father();
369 auto &
dofs = dofs_[ gridElement ];
370 resize(
dofs, localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
371 for(
auto dof :
dofs )
373 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), dof );
374 if( iterator != holes_.end() && *iterator == dof )
375 holes_.erase( iterator );
383 resize( keys_, std::make_pair( key_, key_ ) );
385 auto first = gridPart().template begin< 0, All_Partition >();
386 auto last = gridPart().template end< 0, All_Partition >();
387 for( ; first != last; ++first )
394 resize(
dofs, localKeys().blocks( element.type(),
key( element ) ) );
402 template<
class Traits >
405 DUNE_THROW( NotImplemented,
"Method write() not implemented yet" );
409 template<
class Traits >
412 DUNE_THROW( NotImplemented,
"Method read() not implemented yet" );
418 DUNE_THROW( NotImplemented,
"Method backup() not implemented" );
424 DUNE_THROW( NotImplemented,
"Method restore() not implemented" );
428 bool compressed ()
const {
return holes_.empty(); }
430 template<
class Element,
class Function >
431 void mapEach (
const Element &element,
Function function, Codim< 0 > )
const
435 for( std::size_t i = 0; i <
size; ++i )
436 function( i,
dofs[ i ] );
439 template<
class Entity,
class Function,
int codim >
440 void mapEach (
const Entity &entity, Function
function, Codim< codim > )
const
443 template<
class Element >
449 template<
class Entity,
int codim >
457 size_ =
dofs.reserve( n, Reserve( size_ ) );
458 dofs.resize( Resize( holes_ ) );
462 static void resize ( PersistentContainer< GridType, T > &container,
const T &value = T() )
464 container.resize( value );
465 container.shrinkToFit();
468 const GridPartType &gridPart ()
const {
return gridPart_.get(); }
470 const LocalKeysType &localKeys ()
const {
return localKeys_.get(); }
472 std::reference_wrapper< const GridPartType > gridPart_;
473 std::reference_wrapper< const LocalKeysType > localKeys_;
476 PersistentContainer< GridType, std::pair< KeyType, KeyType > > keys_;
479 PersistentContainer< GridType, LocalDofStorageType > dofs_;
481 std::vector< GlobalKeyType > holes_;
482 std::vector< std::pair< GlobalKeyType, GlobalKeyType > > indices_;
484 std::reference_wrapper< DofManagerType > dofManager_;
492 template<
class Gr
idPart,
class LocalKeys >
510 template<
class Gr
idPart,
class LocalKeys >
513 explicit Resize ( std::vector< GlobalKeyType > &holes )
516 assert( std::is_sorted( holes_.begin(), holes_.end() ) );
521 assert( std::is_sorted( holes_.begin(), holes_.end() ) );
526 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), dof );
527 if( iterator == holes_.end() || *iterator != dof )
528 holes_.insert( iterator, dof );
532 std::vector< GlobalKeyType > &holes_;
540 template<
class Gr
idPart,
class LocalKeys >
541 template<
class Function >
545 gridPart().communicate( dataHandle, InteriorBorder_All_Interface, ForwardCommunication );
547 std::vector< std::size_t > origin, destination;
548 origin.reserve( maxNumDofs() );
549 destination.reserve( maxNumDofs() );
551 std::size_t count = 0;
553 auto first = gridPart().template begin< 0, All_Partition >();
554 auto last = gridPart().template end< 0, All_Partition >();
555 for( ; first != last; ++first )
558 const GridElementType &gridElement =
gridEntity( element );
559 auto &keys = keys_[ gridElement ];
560 if( keys.first == keys.second )
564 const KeyType prior = keys.first;
565 auto &
dofs = dofs_[ gridElement ];
566 origin.resize(
dofs.size() );
567 std::copy(
dofs.begin(),
dofs.end(), origin.begin() );
570 keys.first = keys.second;
571 resize(
dofs, localKeys().blocks( gridElement.type(), keys.first ) );
574 destination.resize(
dofs.size() );
575 std::copy(
dofs.begin(),
dofs.end(), destination.begin() );
576 function( element, prior, keys.first, origin, destination );
588 template<
class Gr
idPart,
class LocalKeys >
593 resize( keys_, std::make_pair( key_, key_ ) );
595 for(
auto &
dofs : dofs_ )
606 assert( size_ >= holes_.size() );
607 size_ -= holes_.size();
610 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), size_ );
611 holes_.erase( iterator, holes_.end() );
614 auto assign = [](
GlobalKeyType newIndex ) -> std::pair< GlobalKeyType, GlobalKeyType >
617 return std::make_pair( oldIndex, newIndex );
619 indices_.resize( holes_.size() );
620 std::transform( holes_.begin(), holes_.end(), indices_.begin(), assign );
623 std::size_t hole = 0u;
624 for(
auto &
dofs : dofs_ )
626 for(
auto &dof :
dofs )
630 auto &indices = indices_.at( hole++ );
632 dof = indices.second;
637 assert( hole == holes_.size() );
641 PersistentContainer< GridType, std::pair< KeyType, KeyType > > tmp( gridPart().grid(), 0, std::make_pair( key_, key_ ) );
642 auto first = gridPart().template begin< 0, All_Partition >();
643 auto last = gridPart().template end< 0, All_Partition >();
644 for( ; first != last; ++first )
647 const GridElementType &gridElement =
gridEntity( element );
648 tmp[ gridElement ] = keys_[ gridElement ];
657 namespace Capabilities
662 template<
class Gr
idPart,
class LocalKeys >
665 static const bool v =
true;
671 template<
class Gr
idPart,
class LocalKeys >
674 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
IteratorRange< typename DF::DofIteratorType > dofs(DF &df)
Iterates over all DOFs.
Definition: rangegenerators.hh:76
const GridEntityAccess< Entity >::GridEntityType & gridEntity(const Entity &entity)
Definition: gridpart.hh:412
static constexpr T max(T a)
Definition: utility.hh:77
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:825
An -adaptive Dune::Fem::DofMapper.
Definition: blockmapper.hh:102
void backup() const
this mapper has no I/O capabilities
Definition: blockmapper.hh:416
static constexpr SizeType oldOffSet(const int block)
return 0 (this mapper has no offset)
Definition: blockmapper.hh:276
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:266
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:273
GridPart GridPartType
grid part type
Definition: blockmapper.hh:113
void write(OutStreamInterface< Traits > &)
this mapper has no I/O capabilities
Definition: blockmapper.hh:403
void mapEachEntityDof(const Entity &entity, Function function) const
map local dof to global key
Definition: blockmapper.hh:244
DiscontinuousGalerkinBlockMapper(const ThisType &)=delete
copy constructor
void mapEach(const ElementType &element, Function function) const
map local dof to global key
Definition: blockmapper.hh:237
LocalKeys LocalKeysType
basis function sets type
Definition: blockmapper.hh:118
ThisType & operator=(const ThisType &)=delete
assignment operator
SizeType numEntityDofs(const Entity &entity) const
return number of dofs for given element
Definition: blockmapper.hh:224
typename BaseType::ElementType ElementType
element type
Definition: blockmapper.hh:115
void insertNewEntity(const GridElementType &gridElement)
add DOFs for new element
Definition: blockmapper.hh:357
bool adapt()
please doc me
Definition: blockmapper.hh:317
void insertEntity(const GridElementType &gridElement)
add DOFs for element
Definition: blockmapper.hh:337
static constexpr bool fixedDataSize(int codim)
return true if number of dofs is fixed for given codimension
Definition: blockmapper.hh:233
const DofManagerType & dofManager() const
return DOF manager
Definition: blockmapper.hh:334
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:306
bool compress()
compress DOF mapping
Definition: blockmapper.hh:589
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:410
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:250
static constexpr bool contains(const int codim)
return true if dofs are associated to codimension
Definition: blockmapper.hh:230
void removeEntity(const GridElementType &gridElement)
mark DOFs for removal
Definition: blockmapper.hh:346
std::enable_if<(std::is_same< Element, ElementType >::value||std::is_same< Element, GridElementType >::value), const KeyType & >::type key(const Element &element) const
get key currently assigned to an entity
Definition: blockmapper.hh:293
GlobalKeyType oldIndex(const int hole, const int block) const
return old index of given hole during compression
Definition: blockmapper.hh:257
static constexpr SizeType offSet(const int block)
return 0 (this mapper has no offset)
Definition: blockmapper.hh:279
void resize()
Definition: blockmapper.hh:380
void restore()
this mapper has no I/O capabilities
Definition: blockmapper.hh:422
void mark(const KeyType &key, const ElementType &element)
set key to be assigned to an entity after next call to adapt()
Definition: blockmapper.hh:299
static constexpr SizeType numBlocks()
return 1 (this mapper has one block)
Definition: blockmapper.hh:282
typename BaseType::SizeType SizeType
size type
Definition: blockmapper.hh:108
Definition: blockmapper.hh:494
Reserve(SizeType &size)
Definition: blockmapper.hh:495
Definition: blockmapper.hh:512
~Resize()
Definition: blockmapper.hh:519
Resize(std::vector< GlobalKeyType > &holes)
Definition: blockmapper.hh:513
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