1#ifndef DUNE_FEM_SPACE_MAPPER_GHOST_HH
2#define DUNE_FEM_SPACE_MAPPER_GHOST_HH
13#include <dune/grid/common/datahandleif.hh>
14#include <dune/grid/common/gridenums.hh>
29 template<
class Gr
idPart,
class Mapper >
32 template<
class AuxiliaryDofs >
37 namespace __GhostDofMapper
43 template<
class BaseMapper >
45 :
public CommDataHandleIF< BuildDataHandle< BaseMapper >, std::pair< int, std::size_t > >
47 typedef std::pair< int, std::size_t >
Data;
49 explicit BuildDataHandle (
int rank,
const BaseMapper &baseMapper, std::vector< std::tuple< int, std::size_t, std::size_t > > &masters )
56 template<
class Buffer,
class Entity >
57 void gather ( Buffer &buffer,
const Entity &entity )
const
59 baseMapper_.mapEachEntityDof( entity, [
this, &buffer ] (
int,
auto index ) {
65 template<
class Buffer,
class Entity >
66 void scatter ( Buffer &buffer,
const Entity &entity, std::size_t n )
68 assert( n ==
size( entity ) );
70 baseMapper_.mapEachEntityDof( entity, [
this, &buffer ] (
int,
auto index ) {
71 Data remote( -1, index );
72 buffer.read( remote );
73 assert( remote.first >= 0 );
76 if( (std::get< 0 >( local ) < 0) || (remote.first < std::get< 0 >( local )) )
77 std::tie( std::get< 0 >( local ), std::get< 1 >( local ) ) = remote;
81 template<
class Entity >
82 std::size_t
size (
const Entity &entity )
const
90 std::vector< std::tuple< int, std::size_t, std::size_t > > &
masters_;
98 template<
class Index >
100 :
public std::iterator< std::random_access_iterator_tag, Index, Index, Envelope< Index >, Index >
111 Index
operator[] ( Index n )
const noexcept {
return index_ + n; }
148 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey = std::
size_t >
174 template<
class Functor >
177 baseMapper().mapEach( element, [
this, &f ] (
auto local,
auto i ) { f( local, mapping_[ i ] ); } );
180 void map (
const ElementType &element, std::vector< GlobalKeyType > &indices )
const
182 indices.resize(
numDofs( element ) );
183 mapEach( element, [ &indices ] (
int local,
GlobalKeyType global ) { indices[ local ] = global; } );
188 baseMapper().onSubEntity( element, i, c, indices );
196 template<
class Entity,
class Functor >
199 baseMapper().mapEachEntityDof( entity, [
this, &f ] (
auto local,
auto i ) { f( local, mapping_[ i ] ); } );
202 template<
class Entity >
203 void mapEntityDofs (
const Entity &entity, std::vector< GlobalKeyType > &indices )
const
209 template<
class Entity >
230 int numBlocks ()
const { DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
231 SizeType offSet (
int blk )
const { DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
232 SizeType oldOffSet (
int blk )
const { DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
233 SizeType numberOfHoles (
int blk )
const { DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
234 SizeType oldIndex (
SizeType hole,
int blk )
const { DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
235 SizeType newIndex (
SizeType hole,
int blk )
const { DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
242 mapping_.resize( baseSize );
244 std::vector< std::tuple< int, std::size_t, std::size_t > > masters( baseSize );
245 for( std::size_t i = 0; i < baseSize; ++i )
246 masters[ i ] = std::make_tuple( -1, i, i );
248 const int rank =
gridPart().comm().rank();
250 gridPart().communicate( dataHandle, InteriorBorder_All_Interface, ForwardCommunication );
255 interiorSize_ = ghostSize_ = 0;
256 for(
const auto &m : masters )
258 if( (std::get< 0 >( m ) == -1) || (std::get< 0 >( m ) == rank ) )
259 mapping_[ std::get< 2 >( m ) ] = interiorSize_++;
261 masters[ ghostSize_++ ] = m;
263 masters.resize( ghostSize_ );
266 const auto less = [] (
auto a,
auto b ) {
return (std::get< 0 >( a ) < std::get< 0 >( b )) || ((std::get< 0 >( a ) == std::get< 0 >( b )) && (std::get< 1 >( a ) < std::get< 1 >( b ))); };
267 std::sort( masters.begin(), masters.end(), less );
271 std::tuple< int, std::size_t, std::size_t > current( -1, 0, 0 );
272 for(
const auto &m : masters )
274 if( less( current, m ) )
277 std::get< 2 >( current ) = interiorSize_ + ghostSize_++;
279 mapping_[ std::get< 2 >( m ) ] = std::get< 2 >( current );
286 const std::vector< GlobalKeyType > &
mapping ()
const {
return mapping_; }
291 std::vector< GlobalKeyType > mapping_;
300 namespace Capabilities
303 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
306 static const bool v =
false;
309 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
312 static const bool v =
true;
322 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
370 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
383 : mapper_( auxiliaryDofs.mapper() )
395 const MapperType &mapper_;
int operator[](const int index) const
return dof number of auxiliary for index
Definition: auxiliarydofs.hh:116
const GridPartType & gridPart() const
Definition: auxiliarydofs.hh:144
Mapper MapperType
type of used mapper
Definition: auxiliarydofs.hh:57
const MapperType & mapper_
Definition: auxiliarydofs.hh:63
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
In parallel computations the dofs of a discrete function are made up by all primary dofs....
Definition: auxiliarydofs.hh:47
Definition: space/mapper/capabilities.hh:22
static const bool v
Definition: space/mapper/capabilities.hh:23
bool fixedSize(int dim, int codim) const
Definition: ghost.hh:54
void gather(Buffer &buffer, const Entity &entity) const
Definition: ghost.hh:57
std::vector< std::tuple< int, std::size_t, std::size_t > > & masters_
Definition: ghost.hh:90
const BaseMapper & baseMapper_
Definition: ghost.hh:89
std::size_t size(const Entity &entity) const
Definition: ghost.hh:82
int rank_
Definition: ghost.hh:88
std::pair< int, std::size_t > Data
Definition: ghost.hh:47
BuildDataHandle(int rank, const BaseMapper &baseMapper, std::vector< std::tuple< int, std::size_t, std::size_t > > &masters)
Definition: ghost.hh:49
void scatter(Buffer &buffer, const Entity &entity, std::size_t n)
Definition: ghost.hh:66
bool contains(int dim, int codim) const
Definition: ghost.hh:53
ThisType & operator++() noexcept
Definition: ghost.hh:116
ConstIterator() noexcept=default
bool operator>=(const ThisType &other) const noexcept
Definition: ghost.hh:134
ThisType & operator--() noexcept
Definition: ghost.hh:119
ThisType & operator+=(Index n) noexcept
Definition: ghost.hh:122
ThisType operator-(Index n) const noexcept
Definition: ghost.hh:126
Index operator[](Index n) const noexcept
Definition: ghost.hh:111
bool operator<=(const ThisType &other) const noexcept
Definition: ghost.hh:133
bool operator>(const ThisType &other) const noexcept
Definition: ghost.hh:135
ThisType & operator-=(Index n) noexcept
Definition: ghost.hh:123
Index operator*() const noexcept
Definition: ghost.hh:108
bool operator==(const ThisType &other) const noexcept
Definition: ghost.hh:113
Envelope< Index > operator->() const noexcept
Definition: ghost.hh:109
bool operator<(const ThisType &other) const noexcept
Definition: ghost.hh:132
bool operator!=(const ThisType &other) const noexcept
Definition: ghost.hh:114
friend ThisType operator+(Index n, const ThisType &i) noexcept
Definition: ghost.hh:128
unsigned int numDofs(const ElementType &element) const
Definition: ghost.hh:192
bool fixedDataSize(int codim) const
Definition: ghost.hh:219
SizeType offSet(int blk) const
Definition: ghost.hh:231
SizeType numberOfHoles(int blk) const
Definition: ghost.hh:233
void onSubEntity(const ElementType &element, int i, int c, std::vector< bool > &indices) const
Definition: ghost.hh:186
SizeType size() const
Definition: ghost.hh:224
bool contains(int codim) const
Definition: ghost.hh:217
int numBlocks() const
Definition: ghost.hh:230
GhostDofMapper(const ThisType &)=delete
GhostDofMapper(ThisType &&)=delete
GhostDofMapper(const GridPartType &gridPart, BaseMapperType &baseMapper)
Definition: ghost.hh:162
void mapEntityDofs(const Entity &entity, std::vector< GlobalKeyType > &indices) const
Definition: ghost.hh:203
const GridPartType & gridPart() const
Definition: ghost.hh:283
ThisType & operator=(const ThisType &)=delete
GlobalKey GlobalKeyType
Definition: ghost.hh:158
void update()
Definition: ghost.hh:239
SizeType oldOffSet(int blk) const
Definition: ghost.hh:232
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition: ghost.hh:197
GridPart GridPartType
Definition: ghost.hh:154
unsigned int numEntityDofs(const Entity &entity) const
Definition: ghost.hh:210
const BaseMapperType & baseMapper() const
Definition: ghost.hh:284
void mapEach(const ElementType &element, Functor f) const
Definition: ghost.hh:175
const std::vector< GlobalKeyType > & mapping() const
Definition: ghost.hh:286
BaseMapperType::ElementType ElementType
Definition: ghost.hh:160
bool consecutive() const
Definition: ghost.hh:228
SizeType ghostSize() const
Definition: ghost.hh:222
unsigned int maxNumDofs() const
Definition: ghost.hh:191
SizeType interiorSize() const
Definition: ghost.hh:221
BaseMapper BaseMapperType
Definition: ghost.hh:155
std::size_t SizeType
Definition: ghost.hh:157
SizeType newIndex(SizeType hole, int blk) const
Definition: ghost.hh:235
void map(const ElementType &element, std::vector< GlobalKeyType > &indices) const
Definition: ghost.hh:180
SizeType oldIndex(SizeType hole, int blk) const
Definition: ghost.hh:234
const GridPartType & gridPart() const
Definition: ghost.hh:359
const MapperType & mapper() const
Definition: ghost.hh:358
ConstIteratorType end() const
Definition: ghost.hh:351
MapperType::SizeType SizeType
Definition: ghost.hh:332
void rebuild()
Definition: ghost.hh:356
GhostDofMapper< GridPart, BaseMapper, GlobalKey > MapperType
Definition: ghost.hh:329
MapperType::GlobalKeyType GlobalKeyType
Definition: ghost.hh:331
SizeType size() const
return number of auxiliary dofs
Definition: ghost.hh:348
__GhostDofMapper::ConstIterator< GlobalKeyType > ConstIteratorType
Definition: ghost.hh:334
ConstIteratorType begin() const
Definition: ghost.hh:350
GridPart GridPartType
Definition: ghost.hh:328
bool contains(GlobalKeyType index) const
return true if index is contained, meaning it is an auxiliary dof
Definition: ghost.hh:354
AuxiliaryDofs(const GridPartType &gridPart, const MapperType &mapper)
Definition: ghost.hh:340
AuxiliaryDofs(const MapperType &mapper)
Definition: ghost.hh:336
ConstIteratorType begin() const
Definition: ghost.hh:386
AuxiliaryDofsType::GridPartType GridPartType
Definition: ghost.hh:376
AuxiliaryDofsType::MapperType MapperType
Definition: ghost.hh:377
const MapperType & mapper() const
Definition: ghost.hh:391
__GhostDofMapper::ConstIterator< GlobalKeyType > ConstIteratorType
Definition: ghost.hh:380
MasterDofs(const AuxiliaryDofsType &auxiliaryDofs)
Definition: ghost.hh:382
SizeType size() const
Definition: ghost.hh:389
ConstIteratorType end() const
Definition: ghost.hh:387
AuxiliaryDofsType::SizeType SizeType
Definition: ghost.hh:378
AuxiliaryDofsType::GlobalKeyType GlobalKeyType
Definition: ghost.hh:375
const GridPartType & gridPart() const
Definition: ghost.hh:392
AuxiliaryDofs< GridPart, GhostDofMapper< GridPart, BaseMapper, GlobalKey > > AuxiliaryDofsType
Definition: ghost.hh:373
Definition: envelope.hh:11