1#ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_BLOCKMAPPER_HH
2#define DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_BLOCKMAPPER_HH
16#include <dune/geometry/dimension.hh>
18#include <dune/grid/common/gridenums.hh>
19#include <dune/grid/utility/persistentcontainer.hh>
21#include <dune/fem/gridpart/common/gridpart.hh>
22#include <dune/fem/io/streams/streams.hh>
23#include <dune/fem/space/common/dofmanager.hh>
24#include <dune/fem/space/mapper/dofmapper.hh>
26#include <dune/fem/space/common/capabilities.hh>
28#include "datahandle.hh"
29#include "localdofstorage.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;
123 using DataHandleType = DataHandle< ThisType >;
129 using LocalDofStorageType = LocalDofStorage< GlobalKeyType >;
131 using GridType =
typename GridPartType::GridType;
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 ];
165 resize( dofs, localKeys.blocks( gridElement.type(),
key ) );
168 dofManager_.get().addIndexSet( *
this );
201 dofManager_.get().removeIndexSet( *
this );
223 template<
class Entity >
229 [[deprecated(
"Use onSubEntity method with char vector instead")]]
230 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< bool > &indices )
const
232 std::vector< char > _idx;
233 onSubEntity(element, i, c, _idx);
234 indices.resize( _idx.size() );
235 for (std::size_t i=0; i<_idx.size();++i)
236 _idx[i] = indices[i] > 0;
246 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< char > &indices )
const
248 indices.resize(
numDofs(element) );
250 std::fill(indices.begin(),indices.end(),1);
252 std::fill(indices.begin(),indices.end(),0);
256 static constexpr bool contains (
const int codim ) {
return (codim == 0); }
262 template<
class Function >
269 template<
class Entity,
class Function >
278 assert( block == 0 );
279 return indices_.size();
285 assert( block == 0 );
288 return std::move( dof );
294 assert( block == 0 );
295 return indices_[ hole ].second;
317 template<
class Element >
318 typename std::enable_if< (std::is_same< Element, ElementType >::value || std::is_same< Element, GridElementType >::value),
const KeyType & >::type
319 key (
const Element &element )
const
321 return keys_[ gridEntity( element ) ].first;
327 assert( gridPart().indexSet().
contains( element ) );
328 keys_[ gridEntity( element ) ].second =
key;
334 assert( gridPart().indexSet().
contains( element ) );
335 return keys_[ gridEntity( element ) ].second;
339 template<
class Function >
347 const std::vector< std::size_t > &,
348 const std::vector< std::size_t > & )
350 return adapt( function );
366 resize( keys_, std::make_pair( key_, key_ ) );
368 resize( dofs_[ gridElement ], localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
374 auto &dofs = dofs_[ gridElement ];
376 size_ = dofs.reserve( 0u, Reserve( size_ ) );
377 Resize function( holes_ );
378 for(
auto dof : dofs )
385 if( gridElement.isNew() )
387 resize( dofs_[ gridElement ], localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
388 assert( gridElement.hasFather() );
389 const GridElementType &father = gridElement.father();
395 auto &dofs = dofs_[ gridElement ];
396 resize( dofs, localKeys().blocks( gridElement.type(),
key( gridElement ) ) );
397 for(
auto dof : dofs )
399 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), dof );
400 if( iterator != holes_.end() && *iterator == dof )
401 holes_.erase( iterator );
409 resize( keys_, std::make_pair( key_, key_ ) );
411 auto first = gridPart().template begin< 0, All_Partition >();
412 auto last = gridPart().template end< 0, All_Partition >();
413 for( ; first != last; ++first )
419 auto &dofs = dofs_[ gridEntity( element ) ];
420 resize( dofs, localKeys().blocks( element.type(),
key( element ) ) );
428 template<
class Traits >
435 template<
class Traits >
454 bool compressed ()
const {
return holes_.empty(); }
456 template<
class Element,
class Function >
459 const auto &dofs = dofs_[ gridEntity( element ) ];
460 std::size_t
size = dofs.size();
461 for( std::size_t i = 0; i <
size; ++i )
462 function( i, dofs[ i ] );
465 template<
class Entity,
class Function,
int codim >
469 template<
class Element >
472 return dofs_[ gridEntity( element ) ].size();
475 template<
class Entity,
int codim >
481 void resize ( LocalDofStorageType &dofs,
SizeType n )
483 size_ = dofs.reserve( n, Reserve( size_ ) );
484 dofs.resize( Resize( holes_ ) );
488 static void resize ( PersistentContainer< GridType, T > &container,
const T &value = T() )
490 container.resize( value );
491 container.shrinkToFit();
494 const GridPartType &gridPart ()
const {
return gridPart_.get(); }
496 const LocalKeysType &localKeys ()
const {
return localKeys_.get(); }
498 std::reference_wrapper< const GridPartType > gridPart_;
499 std::reference_wrapper< const LocalKeysType > localKeys_;
502 PersistentContainer< GridType, std::pair< KeyType, KeyType > > keys_;
507 std::vector< GlobalKeyType > holes_;
508 std::vector< std::pair< GlobalKeyType, GlobalKeyType > > indices_;
510 std::reference_wrapper< DofManagerType > dofManager_;
518 template<
class Gr
idPart,
class LocalKeys >
519 struct DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys >::Reserve
525 operator SizeType ()
const {
return size_; }
536 template<
class Gr
idPart,
class LocalKeys >
537 struct DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys >::Resize
539 explicit Resize ( std::vector< GlobalKeyType > &holes )
542 assert( std::is_sorted( holes_.begin(), holes_.end() ) );
547 assert( std::is_sorted( holes_.begin(), holes_.end() ) );
552 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), dof );
553 if( iterator == holes_.end() || *iterator != dof )
554 holes_.insert( iterator, dof );
558 std::vector< GlobalKeyType > &holes_;
566 template<
class Gr
idPart,
class LocalKeys >
567 template<
class Function >
570 DataHandleType dataHandle( *
this );
573 std::vector< std::size_t > origin, destination;
574 origin.reserve( maxNumDofs() );
575 destination.reserve( maxNumDofs() );
577 std::size_t count = 0;
579 auto first = gridPart().template begin< 0, All_Partition >();
580 auto last = gridPart().template end< 0, All_Partition >();
581 for( ; first != last; ++first )
584 const GridElementType &gridElement = gridEntity( element );
585 auto &keys = keys_[ gridElement ];
586 if( keys.first == keys.second )
590 const KeyType prior = keys.first;
591 auto &dofs = dofs_[ gridElement ];
592 origin.resize( dofs.size() );
593 std::copy( dofs.begin(), dofs.end(), origin.begin() );
596 keys.first = keys.second;
597 resize( dofs, localKeys().blocks( gridElement.type(), keys.first ) );
600 destination.resize( dofs.size() );
601 std::copy( dofs.begin(), dofs.end(), destination.begin() );
602 function( element, prior, keys.first, origin, destination );
614 template<
class Gr
idPart,
class LocalKeys >
619 resize( keys_, std::make_pair( key_, key_ ) );
621 for(
auto &dofs : dofs_ )
622 dofs.resize( Resize( holes_ ) );
632 assert( size_ >= holes_.size() );
633 size_ -= holes_.size();
636 auto iterator = std::lower_bound( holes_.begin(), holes_.end(), size_ );
637 holes_.erase( iterator, holes_.end() );
643 return std::make_pair( oldIndex, newIndex );
645 indices_.resize( holes_.size() );
646 std::transform( holes_.begin(), holes_.end(), indices_.begin(),
assign );
649 std::size_t hole = 0u;
650 for(
auto &dofs : dofs_ )
652 for(
auto &dof : dofs )
656 auto &indices = indices_.at( hole++ );
658 dof = indices.second;
663 assert( hole == holes_.size() );
668 auto first = gridPart().template begin< 0, All_Partition >();
669 auto last = gridPart().template end< 0, All_Partition >();
670 for( ; first != last; ++first )
673 const GridElementType &gridElement = gridEntity( element );
674 tmp[ gridElement ] = keys_[ gridElement ];
683 namespace Capabilities
688 template<
class Gr
idPart,
class LocalKeys >
689 struct isConsecutiveIndexSet< hpDG::DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys > >
691 static const bool v =
true;
697 template<
class Gr
idPart,
class LocalKeys >
698 struct isAdaptiveDofMapper< hpDG::DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys > >
700 static const bool v =
true;
Wrapper class for entities.
Definition: entity.hh:66
Extended interface for adaptive DoF mappers.
Definition: dofmapper.hh:219
SizeType GlobalKeyType
at the moment this should be similar to SizeType
Definition: dofmapper.hh:230
BaseType::SizeType SizeType
type of size integer
Definition: dofmapper.hh:227
Definition: dofmanager.hh:786
Traits::ElementType ElementType
type of codimension 0 entities
Definition: dofmapper.hh:54
Abstract class representing a function.
Definition: function.hh:50
abstract interface for an input stream
Definition: streams.hh:190
abstract interface for an output stream
Definition: streams.hh:48
Default exception for dummy implementations.
Definition: exceptions.hh:263
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13
void assign(T &dst, const T &src, bool mask)
masked Simd assignment (scalar version)
Definition: simd.hh:447
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
Static tag representing a codimension.
Definition: dimension.hh:24
An -adaptive Dune::Fem::DofMapper.
Definition: blockmapper.hh:102
void backup() const
this mapper has no I/O capabilities
Definition: blockmapper.hh:442
static constexpr SizeType oldOffSet(const int block)
return 0 (this mapper has no offset)
Definition: blockmapper.hh:302
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:292
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:319
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:299
GridPart GridPartType
grid part type
Definition: blockmapper.hh:113
void write(OutStreamInterface< Traits > &)
this mapper has no I/O capabilities
Definition: blockmapper.hh:429
void mapEachEntityDof(const Entity &entity, Function function) const
map local dof to global key
Definition: blockmapper.hh:270
DiscontinuousGalerkinBlockMapper(const ThisType &)=delete
copy constructor
void mapEach(const ElementType &element, Function function) const
map local dof to global key
Definition: blockmapper.hh:263
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:383
bool adapt()
please doc me
Definition: blockmapper.hh:343
void insertEntity(const GridElementType &gridElement)
add DOFs for element
Definition: blockmapper.hh:363
static constexpr bool fixedDataSize(int codim)
return true if number of dofs is fixed for given codimension
Definition: blockmapper.hh:259
const DofManagerType & dofManager() const
return DOF manager
Definition: blockmapper.hh:360
KeyType getMark(const ElementType &element) const
get key to be assigned to an entity after next call to adapt()
Definition: blockmapper.hh:332
bool compress()
compress DOF mapping
Definition: blockmapper.hh:615
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:436
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:276
static constexpr bool contains(const int codim)
return true if dofs are associated to codimension
Definition: blockmapper.hh:256
void removeEntity(const GridElementType &gridElement)
mark DOFs for removal
Definition: blockmapper.hh:372
GlobalKeyType oldIndex(const int hole, const int block) const
return old index of given hole during compression
Definition: blockmapper.hh:283
static constexpr SizeType offSet(const int block)
return 0 (this mapper has no offset)
Definition: blockmapper.hh:305
void restore()
this mapper has no I/O capabilities
Definition: blockmapper.hh:448
void mark(const KeyType &key, const ElementType &element)
set key to be assigned to an entity after next call to adapt()
Definition: blockmapper.hh:325
static constexpr SizeType numBlocks()
return 1 (this mapper has one block)
Definition: blockmapper.hh:308
typename BaseType::SizeType SizeType
size type
Definition: blockmapper.hh:108