1#ifndef DUNE_FEM_SPACE_MAPPER_PARALLEL_HH
2#define DUNE_FEM_SPACE_MAPPER_PARALLEL_HH
14#include <dune/fem/gridpart/common/indexset.hh>
15#include <dune/fem/space/common/auxiliarydofs.hh>
16#include <dune/fem/space/mapper/capabilities.hh>
24 namespace __ParallelDofMapper
30 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
31 struct BuildDataHandle
32 :
public CommDataHandleIF< BuildDataHandle< GridPart, BaseMapper, GlobalKey >, GlobalKey >
35 : baseMapper_( baseMapper ), auxiliaryDofs_( auxiliaryDofs ), mapping_( mapping )
38 bool contains (
int dim,
int codim )
const {
return baseMapper_.contains( codim ); }
39 bool fixedSize (
int dim,
int codim )
const {
return false; }
41 template<
class Buffer,
class Entity >
42 void gather ( Buffer &buffer,
const Entity &entity )
const
44 baseMapper_.mapEachEntityDof( entity, [
this, &buffer ] (
int,
auto index ) {
45 if( !auxiliaryDofs_.contains( index ) )
46 buffer.write( mapping_[ index ] );
50 template<
class Buffer,
class Entity >
51 void scatter ( Buffer &buffer,
const Entity &entity, std::size_t n )
56 assert( n ==
static_cast< std::size_t
>( baseMapper_.numEntityDofs( entity ) ) );
57 baseMapper_.mapEachEntityDof( entity, [
this, &buffer ] (
int,
auto index ) {
58 assert( auxiliaryDofs_.contains( index ) );
59 buffer.read( mapping_[ index ] );
63 template<
class Entity >
64 std::size_t
size (
const Entity &entity )
const
67 baseMapper_.mapEachEntityDof( entity, [
this, &
size ] (
int,
auto index )
68 {
size +=
static_cast< std::size_t
>( !auxiliaryDofs_.contains( index ) ); } );
73 const BaseMapper &baseMapper_;
75 std::vector< GlobalKey > &mapping_;
85 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey = std::
size_t >
86 class ParallelDofMapper
88 typedef ParallelDofMapper< GridPart, BaseMapper, GlobalKey > ThisType;
91 typedef GridPart GridPartType;
92 typedef BaseMapper BaseMapperType;
94 typedef std::size_t SizeType;
95 typedef GlobalKey GlobalKeyType;
97 typedef typename BaseMapperType::ElementType ElementType;
99 ParallelDofMapper (
const GridPartType &gridPart,
const BaseMapperType &baseMapper,
const InterfaceType commInterface )
100 : gridPart_( gridPart ), baseMapper_( baseMapper ), commInterface_( commInterface )
105 ParallelDofMapper (
const ThisType & ) =
delete;
106 ParallelDofMapper ( ThisType && ) =
delete;
108 ThisType &operator= (
const ThisType & ) =
delete;
109 ThisType &operator= ( ThisType && ) =
delete;
111 template<
class Functor >
112 void mapEach (
const ElementType &element, Functor f )
const
114 baseMapper().mapEach( element, [
this, f ] (
auto local,
auto i ) { f( local, mapping_[ i ] ); } );
117 void map (
const ElementType &element, std::vector< GlobalKeyType > &indices )
const
119 indices.resize( numDofs( element ) );
120 mapEach( element, [ &indices ] (
int local, GlobalKeyType global ) { indices[ local ] = global; } );
123 [[deprecated(
"Use onSubEntity method with char vector instead")]]
124 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< bool > &indices )
const
126 std::vector< char > _idx;
127 onSubEntity(element, i, c, _idx);
128 indices.resize( _idx.size() );
129 for (std::size_t i=0; i<_idx.size();++i)
130 _idx[i] = indices[i] > 0;
140 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< char > &indices )
const
142 baseMapper().onSubEntity( element, i, c, indices );
145 unsigned int maxNumDofs ()
const {
return baseMapper().maxNumDofs(); }
146 unsigned int numDofs (
const ElementType &element )
const {
return baseMapper().numDofs( element ); }
150 template<
class Entity,
class Functor >
151 void mapEachEntityDof (
const Entity &entity, Functor f )
const
153 baseMapper().mapEachEntityDof( entity, [
this, f ] (
auto local,
auto i ) { f( local, mapping_[ i ] ); } );
156 template<
class Entity >
157 void mapEntityDofs (
const Entity &entity, std::vector< GlobalKeyType > &indices )
const
159 indices.resize( numEntityDofs( entity ) );
160 mapEachEntityDof( entity, [ &indices ] (
int local, GlobalKeyType global ) { indices[ local ] = global; } );
163 template<
class Entity >
164 unsigned int numEntityDofs (
const Entity &entity )
const
166 return baseMapper().numEntityDofs( entity );
171 bool contains (
int codim )
const {
return baseMapper().contains( codim ); }
173 bool fixedDataSize (
int codim )
const {
return baseMapper().fixedDataSize( codim ); }
175 SizeType
size ()
const {
return size_; }
177 InterfaceType communicationInterface()
const {
return commInterface_; }
181 bool consecutive ()
const {
return false; }
183 int numBlocks ()
const {
DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
184 SizeType offSet (
int blk )
const {
DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
185 SizeType oldOffSet (
int blk )
const {
DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
186 SizeType numberOfHoles (
int blk )
const {
DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
187 SizeType oldIndex ( SizeType hole,
int blk )
const {
DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
188 SizeType newIndex ( SizeType hole,
int blk )
const {
DUNE_THROW( NotImplemented,
"Adaptive dof mapper interface not implemented." ); }
194 AuxiliaryDofs< GridPartType, BaseMapperType > auxiliaryDofs( gridPart(), baseMapper() );
195 auxiliaryDofs.rebuild();
198 const auto primarySize = auxiliaryDofs.primarySize();
200 offset_ = exScan( gridPart().comm(), size_ );
201 size_ = gridPart().comm().sum( size_ );
203 std::size_t baseSize = baseMapper().size();
204 mapping_.resize( baseSize );
205 GlobalKeyType next =
static_cast< GlobalKeyType
>( offset_ );
206 std::vector< GlobalKeyType >& mapping = mapping_;
207 auto mapNext = [&mapping, &next] (
const auto i) { mapping[ i ] = next++; };
210 assert( next ==
static_cast< GlobalKeyType
>( offset_ + primarySize ) );
212 __ParallelDofMapper::BuildDataHandle< GridPartType, BaseMapperType, GlobalKeyType > dataHandle( baseMapper(), auxiliaryDofs, mapping_ );
216 const GridPartType &gridPart ()
const {
return gridPart_; }
217 const BaseMapperType &baseMapper ()
const {
return baseMapper_; }
219 const std::vector< GlobalKeyType > &mapping ()
const {
return mapping_; }
222 template<
class Comm,
class T >
223 static T exScan (
const Communication< Comm > &comm, T in )
230 static T exScan (
const Communication< MPI_Comm > &comm, T in )
233 MPI_Exscan( &in, &out, 1, MPITraits< T >::getType(), MPI_SUM,
static_cast< MPI_Comm
>( comm ) );
238 const GridPartType &gridPart_;
239 const BaseMapperType &baseMapper_;
241 std::vector< GlobalKeyType > mapping_;
242 SizeType offset_, size_;
250 namespace Capabilities
253 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
254 struct isAdaptiveDofMapper< ParallelDofMapper< GridPart, BaseMapper, GlobalKey > >
256 static const bool v =
false;
259 template<
class Gr
idPart,
class BaseMapper,
class GlobalKey >
260 struct isConsecutiveIndexSet< ParallelDofMapper< GridPart, BaseMapper, GlobalKey > >
262 static const bool v =
true;
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
Describes the parallel communication interface class for MessageBuffers and DataHandles.
static void forEachPrimaryDof(const AuxiliaryDofs &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all primary dofs.
Definition: auxiliarydofs.hh:303
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
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