1#ifndef DUNE_FEM_DEFAULTDATAHANDLE_HH
2#define DUNE_FEM_DEFAULTDATAHANDLE_HH
9#include <dune/fem/common/hybrid.hh>
10#include <dune/fem/space/common/commoperations.hh>
21 class IsDiscreteFunction;
33 class DiscreteFunction,
class Operation >
36 < DefaultCommunicationHandlerImpl< DiscreteFunctionSpace, DiscreteFunction, Operation >,
37 typename DiscreteFunction::DofType >
45 typedef DiscreteFunction DiscreteFunctionType;
51 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
53 static constexpr bool isDiscreteFunction = std::is_base_of< IsDiscreteFunction, DiscreteFunction > :: value;
57 DiscreteFunctionType &function,
const Operation& operation = Operation() )
58 : function_( &function ),
59 blockMapper_( space.blockMapper() ),
60 operation_( operation )
68 : function_( other.function_ ),
69 blockMapper_( other.blockMapper_ ),
70 operation_( other.operation_ )
77 template <
class Buffer >
81 DiscreteFunctionType *
const function_;
83 GatherFunctor( Buffer& buffer, DiscreteFunctionType* function )
84 : buffer_( buffer ), function_( function )
87 template <
class GlobalKey>
88 void operator () (
const size_t local,
const GlobalKey& globalKey )
const
90 if constexpr ( isDiscreteFunction )
92 const auto &block = function_->dofVector()[ globalKey ];
93 Hybrid::forEach( LocalBlockIndices(), [
this, &block ] (
auto &&j ) { buffer_.write( block[ j ] ); } );
100 const auto &block = (*function_)[ globalKey ];
101 for(
int j=0; j<blockSize; ++j )
102 buffer_.write( block[ j ] );
107 template <
class Buffer >
108 struct ScatterFunctor
112 const Operation& operation_;
115 : buffer_( buffer ), function_( function ), operation_( operation )
118 template <
class GlobalKey>
119 void operator () (
const size_t local,
const GlobalKey& globalKey )
const
121 if constexpr( isDiscreteFunction )
123 auto &&block = function_->dofVector()[ globalKey ];
126 buffer_.read( value );
127 operation_( value, block[ j ] );
135 auto&& block = (*function_)[ globalKey ];
136 for(
int j=0; j<blockSize; ++j )
139 buffer_.read( value );
140 operation_( value, block[ j ] );
147 bool contains (
int dim,
int codim )
const
149 return blockMapper_.contains( codim );
152 bool fixedSize (
int dim,
int codim)
const
154 return blockMapper_.fixedDataSize( codim );
158 template<
class MessageBuffer,
class Entity >
161 GatherFunctor< MessageBuffer > gatherDofs ( buffer, function_ );
162 blockMapper_.mapEachEntityDof( entity, gatherDofs );
166 template<
class MessageBuffer,
class Entity >
169 assert( n ==
size( entity ) );
170 ScatterFunctor< MessageBuffer > scatterDofs ( buffer, function_, operation_ );
172 blockMapper_.mapEachEntityDof( entity, scatterDofs );
176 template<
class Entity >
179 return Hybrid::size( LocalBlockIndices() ) * blockMapper_.numEntityDofs( entity );
184 const BlockMapperType &blockMapper_;
185 const Operation operation_;
195 template<
class DiscreteFunction,
196 class Operation = DFCommunicationOperation::Add >
197 using DefaultCommunicationHandler =
198 DefaultCommunicationHandlerImpl<
typename DiscreteFunction::DiscreteFunctionSpaceType,
199 DiscreteFunction, Operation >;
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
DataTypeImp DataType
data type of data to communicate
Definition: datahandleif.hh:82
Wrapper class for entities.
Definition: entity.hh:66
mapper allocating one DoF per subentity of a given codimension
Definition: codimensionmapper.hh:357
Default communication handler for discrete functions.
Definition: defaultcommhandler.hh:38
DefaultCommunicationHandlerImpl & operator=(const DefaultCommunicationHandlerImpl &)=delete
cannot be implemented because of the reference
void scatter(MessageBuffer &buffer, const Entity &entity, size_t n)
read buffer and apply operation
Definition: defaultcommhandler.hh:167
size_t size(const Entity &entity) const
return local dof size to be communicated
Definition: defaultcommhandler.hh:177
void gather(MessageBuffer &buffer, const Entity &entity) const
read buffer and apply operation
Definition: defaultcommhandler.hh:159
static constexpr std::size_t blockSize
size of the dof blocks
Definition: discretefunction.hh:148
forward declaration
Definition: discretefunction.hh:51
Describes the parallel communication interface class for MessageBuffers and DataHandles.
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13