1#ifndef DUNE_FEM_SPACE_MAPPER_GHOST_HH 
    2#define DUNE_FEM_SPACE_MAPPER_GHOST_HH 
   13#include <dune/grid/common/gridenums.hh> 
   15#include <dune/fem/gridpart/common/indexset.hh> 
   16#include <dune/fem/space/mapper/capabilities.hh> 
   17#include <dune/fem/storage/envelope.hh> 
   28    template< 
class Gr
idPart, 
class Mapper >
 
   31    template< 
class AuxiliaryDofs >
 
   36    namespace __GhostDofMapper
 
   42      template< 
class BaseMapper >
 
   43      struct BuildDataHandle
 
   44        : 
public CommDataHandleIF< BuildDataHandle< BaseMapper >, std::pair< int, std::size_t > >
 
   46        typedef std::pair< int, std::size_t > Data;
 
   48        explicit BuildDataHandle ( 
int rank, 
const BaseMapper &baseMapper, std::vector< std::tuple< int, std::size_t, std::size_t > > &masters )
 
   49          : rank_( rank ), baseMapper_( baseMapper ), masters_( masters )
 
   52        bool contains ( 
int dim, 
int codim )
 const { 
return baseMapper_.contains( codim ); }
 
   53        bool fixedSize ( 
int dim, 
int codim )
 const { 
return baseMapper_.fixedDataSize( codim ); }
 
   55        template< 
class Buffer, 
class Entity >
 
   56        void gather ( Buffer &buffer, 
const Entity &entity )
 const 
   58          baseMapper_.mapEachEntityDof( entity, [ 
this, &buffer ] ( 
int, 
auto index ) {
 
   59              std::get< 0 >( masters_[ index ] ) = rank_;
 
   60              buffer.write( Data( std::get< 0 >( masters_[ index ] ), std::get< 1 >( masters_[ index ] ) ) );
 
   64        template< 
class Buffer, 
class Entity >
 
   65        void scatter ( Buffer &buffer, 
const Entity &entity, std::size_t n )
 
   67          assert( n == 
size( entity ) );
 
   69          baseMapper_.mapEachEntityDof( entity, [ 
this, &buffer ] ( 
int, 
auto index ) {
 
   70              Data remote( -1, index );
 
   71              buffer.read( remote );
 
   72              assert( remote.first >= 0 );
 
   74              auto &local = masters_[ index ];
 
   75              if( (std::get< 0 >( local ) < 0) || (remote.first < std::get< 0 >( local )) )
 
   76                std::tie( std::get< 0 >( local ), std::get< 1 >( local ) ) = remote;
 
   80        template< 
class Entity >
 
   81        std::size_t 
size ( 
const Entity &entity )
 const 
   83          return baseMapper_.numEntityDofs( entity );
 
   88        const BaseMapper &baseMapper_;
 
   89        std::vector< std::tuple< int, std::size_t, std::size_t > > &masters_;
 
   97      template< 
class Index >
 
  100        typedef ConstIterator< Index > ThisType;
 
  103        typedef std::random_access_iterator_tag iterator_category;
 
  104        typedef Index value_type;
 
  105        typedef Index difference_type;
 
  106        typedef Envelope< Index > pointer;
 
  107        typedef Index reference;
 
  109        ConstIterator () noexcept = default;
 
  110        explicit ConstIterator ( Index index ) noexcept : index_( index ) {}
 
  112        Index operator* () const noexcept { 
return index_; }
 
  113        Envelope< Index > operator-> () const noexcept { 
return Envelope< Index >( index_ ); }
 
  115        Index operator[] ( Index n ) 
const noexcept { 
return index_ + n; }
 
  117        bool operator== ( 
const ThisType &other ) 
const noexcept { 
return (index_ == other.index_); }
 
  118        bool operator!= ( 
const ThisType &other ) 
const noexcept { 
return (index_ != other.index_); }
 
  120        ThisType &operator++ () noexcept { ++index_; 
return *
this; }
 
  121        ThisType operator++ ( 
int ) 
noexcept { ThisType copy( *
this ); ++(*this); 
return copy; }
 
  123        ThisType &operator-- () noexcept { --index_; 
return *
this; }
 
  124        ThisType operator-- ( 
int ) 
noexcept { ThisType copy( *
this ); --(*this); 
return copy; }
 
  126        ThisType &operator+= ( Index n ) 
noexcept { index_ += n; 
return *
this; }
 
  127        ThisType &operator-= ( Index n ) 
noexcept { index_ -= n; 
return *
this; }
 
  129        ThisType operator+ ( Index n ) 
const noexcept { 
return ThisType( index_ + n ); }
 
  130        ThisType operator- ( Index n ) 
const noexcept { 
return ThisType( index_ - n ); }
 
  132        friend ThisType operator+ ( Index n, 
const ThisType &i ) 
noexcept { 
return i + n; }
 
  134        Index operator- ( 
const ThisType &other ) 
const noexcept { 
return (index_ - other.index_); }
 
  136        bool operator< ( 
const ThisType &other ) 
const noexcept { 
return (index_ < other.index_); }
 
  137        bool operator<= ( 
const ThisType &other ) 
const noexcept { 
return (index_ <= other.index_); }
 
  138        bool operator>= ( 
const ThisType &other ) 
const noexcept { 
return (index_ >= other.index_); }
 
  139        bool operator> ( 
const ThisType &other ) 
const noexcept { 
return (index_ > other.index_); }
 
  152    template< 
class Gr
idPart, 
class BaseMapper, 
class GlobalKey = std::
size_t >
 
  155      typedef GhostDofMapper< GridPart, BaseMapper, GlobalKey > ThisType;
 
  158      typedef GridPart GridPartType;
 
  159      typedef BaseMapper BaseMapperType;
 
  161      typedef std::size_t SizeType;
 
  162      typedef GlobalKey GlobalKeyType;
 
  164      typedef typename BaseMapperType::ElementType ElementType;
 
  166      GhostDofMapper ( 
const GridPartType &gridPart, BaseMapperType &baseMapper, 
const InterfaceType commInterface )
 
  167        : gridPart_( gridPart ), baseMapper_( baseMapper ), commInterface_(commInterface)
 
  172      GhostDofMapper ( 
const ThisType & ) = 
delete;
 
  173      GhostDofMapper ( ThisType && ) = 
delete;
 
  175      ThisType &operator= ( 
const ThisType & ) = 
delete;
 
  176      ThisType &operator= ( ThisType && ) = 
delete;
 
  178      template< 
class Functor >
 
  179      void mapEach ( 
const ElementType &element, Functor f )
 const 
  181        baseMapper().mapEach( element, [ 
this, &f ] ( 
auto local, 
auto i ) { f( local, mapping_[ i ] ); } );
 
  184      void map ( 
const ElementType &element, std::vector< GlobalKeyType > &indices )
 const 
  186        indices.resize( numDofs( element ) );
 
  187        mapEach( element, [ &indices ] ( 
int local, GlobalKeyType global ) { indices[ local ] = global; } );
 
  190      [[deprecated(
"Use onSubEntity method with char vector instead")]]
 
  191      void onSubEntity ( 
const ElementType &element, 
int i, 
int c, std::vector< bool > &indices )
 const 
  193        std::vector< char > _idx;
 
  194        onSubEntity(element, i, c, _idx);
 
  195        indices.resize( _idx.size() );
 
  196        for (std::size_t i=0; i<_idx.size();++i)
 
  197          _idx[i] = indices[i] > 0;
 
  207      void onSubEntity ( 
const ElementType &element, 
int i, 
int c, std::vector< char > &indices )
 const 
  209        baseMapper().onSubEntity( element, i, c, indices );
 
  212      unsigned int maxNumDofs ()
 const { 
return baseMapper().maxNumDofs(); }
 
  213      unsigned int numDofs ( 
const ElementType &element )
 const { 
return baseMapper().numDofs( element ); }
 
  217      template< 
class Entity, 
class Functor >
 
  218      void mapEachEntityDof ( 
const Entity &entity, Functor f )
 const 
  220        baseMapper().mapEachEntityDof( entity, [ 
this, &f ] ( 
auto local, 
auto i ) { f( local, mapping_[ i ] ); } );
 
  223      template< 
class Entity >
 
  224      void mapEntityDofs ( 
const Entity &entity, std::vector< GlobalKeyType > &indices )
 const 
  226        indices.resize( numEntityDofs( entity ) );
 
  227        mapEachEntityDof( entity, [ &indices ] ( 
int local, GlobalKeyType global ) { indices[ local ] = global; } );
 
  230      template< 
class Entity >
 
  231      unsigned int numEntityDofs ( 
const Entity &entity )
 const 
  233        return baseMapper().numEntityDofs( entity );
 
  238      bool contains ( 
int codim )
 const { 
return baseMapper().contains( codim ); }
 
  240      bool fixedDataSize ( 
int codim )
 const { 
return baseMapper().fixedDataSize( codim ); }
 
  242      SizeType interiorSize ()
 const { 
return interiorSize_; }
 
  243      SizeType ghostSize ()
 const { 
return ghostSize_; }
 
  245      SizeType 
size ()
 const { 
return interiorSize() + ghostSize(); }
 
  247      InterfaceType communicationInterface()
 const { 
return commInterface_; }
 
  251      bool consecutive ()
 const { 
return false; }
 
  253      int numBlocks ()
 const { 
DUNE_THROW( NotImplemented, 
"Adaptive dof mapper interface not implemented." ); }
 
  254      SizeType offSet ( 
int blk )
 const { 
DUNE_THROW( NotImplemented, 
"Adaptive dof mapper interface not implemented." ); }
 
  255      SizeType oldOffSet ( 
int blk )
 const { 
DUNE_THROW( NotImplemented, 
"Adaptive dof mapper interface not implemented." ); }
 
  256      SizeType numberOfHoles ( 
int blk )
 const { 
DUNE_THROW( NotImplemented, 
"Adaptive dof mapper interface not implemented." ); }
 
  257      SizeType oldIndex ( SizeType hole, 
int blk )
 const { 
DUNE_THROW( NotImplemented, 
"Adaptive dof mapper interface not implemented." ); }
 
  258      SizeType newIndex ( SizeType hole, 
int blk )
 const { 
DUNE_THROW( NotImplemented, 
"Adaptive dof mapper interface not implemented." ); }
 
  264        std::size_t baseSize = baseMapper().size();
 
  265        mapping_.resize( baseSize );
 
  267        std::vector< std::tuple< int, std::size_t, std::size_t > > masters( baseSize );
 
  268        for( std::size_t i = 0; i < baseSize; ++i )
 
  269          masters[ i ] = std::make_tuple( -1, i, i );
 
  271        const int rank = gridPart().comm().rank();
 
  272        __GhostDofMapper::BuildDataHandle< BaseMapper > dataHandle( rank, baseMapper_, masters );
 
  279        interiorSize_ = ghostSize_ = 0;
 
  280        for( 
const auto &m : masters )
 
  282          if( (std::get< 0 >( m ) == -1) || (std::get< 0 >( m ) == rank ) )
 
  283            mapping_[ std::get< 2 >( m ) ] = interiorSize_++;
 
  285            masters[ ghostSize_++ ] = m;
 
  287        masters.resize( ghostSize_ );
 
  290        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 ))); };
 
  291        std::sort( masters.begin(), masters.end(), less );
 
  295        std::tuple< int, std::size_t, std::size_t > current( -1, 0, 0 );
 
  296        for( 
const auto &m : masters )
 
  298          if( less( current, m ) )
 
  301            std::get< 2 >( current ) = interiorSize_ + ghostSize_++;
 
  303          mapping_[ std::get< 2 >( m ) ] = std::get< 2 >( current );
 
  307      const GridPartType &gridPart ()
 const { 
return gridPart_; }
 
  308      const BaseMapperType &baseMapper ()
 const { 
return baseMapper_; }
 
  310      const std::vector< GlobalKeyType > &mapping ()
 const { 
return mapping_; }
 
  313      const GridPartType &gridPart_;
 
  314      BaseMapperType &baseMapper_;
 
  316      std::vector< GlobalKeyType > mapping_;
 
  317      SizeType interiorSize_, ghostSize_;
 
  325    namespace Capabilities
 
  328      template< 
class Gr
idPart, 
class BaseMapper, 
class GlobalKey >
 
  329      struct isAdaptiveDofMapper< GhostDofMapper< GridPart, BaseMapper, GlobalKey > >
 
  331        static const bool v = 
false;
 
  334      template< 
class Gr
idPart, 
class BaseMapper, 
class GlobalKey >
 
  335      struct isConsecutiveIndexSet< GhostDofMapper< GridPart, BaseMapper, GlobalKey > >
 
  337        static const bool v = 
true;
 
  347    template< 
class Gr
idPart, 
class BaseMapper, 
class GlobalKey >
 
  348    class AuxiliaryDofs< GridPart, GhostDofMapper< GridPart, BaseMapper, GlobalKey > >
 
  350      typedef AuxiliaryDofs< GridPart, GhostDofMapper< GridPart, BaseMapper, GlobalKey > > ThisType;
 
  354      typedef GhostDofMapper< GridPart, BaseMapper, GlobalKey > 
MapperType;
 
  356      typedef typename MapperType::GlobalKeyType GlobalKeyType;
 
  357      typedef typename MapperType::SizeType SizeType;
 
  359      typedef __GhostDofMapper::ConstIterator< GlobalKeyType > ConstIteratorType;
 
  361      explicit AuxiliaryDofs ( 
const MapperType &mapper )
 
  365      AuxiliaryDofs ( 
const GridPartType &gridPart, 
const MapperType &mapper )
 
  366        : AuxiliaryDofs( mapper )
 
  370      GlobalKeyType 
operator [] ( 
int index )
 const { 
return mapper().interiorSize() + index; }
 
  373      SizeType 
size ()
 const { 
return mapper().ghostSize()+1; }
 
  376      SizeType 
primarySize ()
 const { 
return mapper().interiorSize(); }
 
  378      ConstIteratorType begin ()
 const { 
return ConstIteratorType( mapper().interiorSize() ); }
 
  379      ConstIteratorType end ()
 const { 
return ConstIteratorType( mapper().interiorSize() + mapper().ghostSize() ); }
 
  382      bool contains ( GlobalKeyType index )
 const { 
return (
static_cast< SizeType 
>( index ) >= mapper().interiorSize()); }
 
  386      const MapperType &mapper ()
 const { 
return mapper_; }
 
  387      const GridPartType &gridPart ()
 const { 
return mapper().gridPart(); }
 
  402    template <
class Gr
idPart, 
class BaseMapper, 
class GlobalKey, 
class F>
 
  405      const size_t size = auxiliaryDofs.mapper().interiorSize();
 
  406      for( 
size_t dof = 0 ; dof<
size; ++dof )
 
  419    template< 
class Gr
idPart, 
class BaseMapper, 
class GlobalKey >
 
  420    struct PrimaryDofs< AuxiliaryDofs< GridPart, GhostDofMapper< GridPart, BaseMapper, GlobalKey > > >
 
  422      typedef AuxiliaryDofs< GridPart, GhostDofMapper< GridPart, BaseMapper, GlobalKey > > AuxiliaryDofsType;
 
  424      typedef typename AuxiliaryDofsType::GlobalKeyType GlobalKeyType;
 
  425      typedef typename AuxiliaryDofsType::GridPartType GridPartType;
 
  426      typedef typename AuxiliaryDofsType::MapperType MapperType;
 
  427      typedef typename AuxiliaryDofsType::SizeType SizeType;
 
  429      typedef __GhostDofMapper::ConstIterator< GlobalKeyType > ConstIteratorType;
 
  431      [[deprecated(
"Use forEachPrimaryDof instead!")]]
 
  432      explicit PrimaryDofs ( 
const AuxiliaryDofsType &auxiliaryDofs )
 
  433        : mapper_( auxiliaryDofs.mapper() )
 
  436      ConstIteratorType begin ()
 const { 
return ConstIteratorType( 0 ); }
 
  437      ConstIteratorType end ()
 const { 
return ConstIteratorType( 
size() ); }
 
  439      SizeType 
size ()
 const { 
return mapper().interiorSize(); }
 
  441      const MapperType &mapper ()
 const { 
return mapper_; }
 
  442      const GridPartType &gridPart ()
 const { 
return mapper().gridPart(); }
 
  445      const MapperType &mapper_;
 
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:143
 
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:129
 
In parallel computations the dofs of a discrete function are made up by all primary dofs....
Definition: auxiliarydofs.hh:46
 
Describes the parallel communication interface class for MessageBuffers and DataHandles.
 
GridPart GridPartType
type of grid part
Definition: auxiliarydofs.hh:53
 
bool contains(IndexType index) const
return true if index is contained, meaning it is a auxiliary dof
Definition: auxiliarydofs.hh:146
 
IndexType operator[](const IndexType index) const
return dof number of auxiliary for index
Definition: auxiliarydofs.hh:122
 
IndexType size() const
return number of auxiliary dofs
Definition: auxiliarydofs.hh:128
 
Mapper MapperType
type of used mapper
Definition: auxiliarydofs.hh:56
 
IndexType primarySize() const
return number of primaryDofs
Definition: auxiliarydofs.hh:134
 
static void forEachPrimaryDof(const AuxiliaryDofs< GridPart, GhostDofMapper< GridPart, BaseMapper, GlobalKey > > &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all primary dofs.
Definition: ghost.hh:403
 
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
 
constexpr EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:684
 
constexpr EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:638
 
constexpr EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
 
constexpr EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:661
 
constexpr EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:260
 
constexpr EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:706
 
Dune namespace.
Definition: alignedallocator.hh:13
 
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
 
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
 
std::size_t fixedSize
The number of data items per index if it is fixed, 0 otherwise.
Definition: variablesizecommunicator.hh:264