dune-fem 2.8.0
Loading...
Searching...
No Matches
defaultcommhandler.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_DEFAULTDATAHANDLE_HH
2#define DUNE_FEM_DEFAULTDATAHANDLE_HH
3
4#include <cassert>
5
6//- Dune includes
7#include <dune/grid/common/datahandleif.hh>
8
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
24 template< class DiscreteFunction, class Operation = DFCommunicationOperation::Add >
26 : public CommDataHandleIF
27 < DefaultCommunicationHandler< DiscreteFunction, Operation >,
28 typename DiscreteFunction::DofType >
29 {
31 typedef CommDataHandleIF< ThisType, typename DiscreteFunction::DofType > BaseType;
32
33 public:
34 typedef typename BaseType::DataType DataType;
35
36 typedef DiscreteFunction DiscreteFunctionType;
37
38 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
39
40 protected:
41 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
42 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
43
44 public:
45 DefaultCommunicationHandler( DiscreteFunctionType &function, const Operation& operation = Operation() )
46 : function_( &function ),
47 blockMapper_( function.space().blockMapper() ),
48 operation_( operation )
49 {}
50
52 : function_( other.function_ ),
54 operation_( other.operation_ )
55 {}
56
59
60 private:
61 template < class Buffer >
62 struct GatherFunctor
63 {
64 Buffer& buffer_;
65 DiscreteFunctionType *const function_;
66
67 GatherFunctor( Buffer& buffer, DiscreteFunctionType* function )
68 : buffer_( buffer ), function_( function )
69 {}
70
71 template <class GlobalKey>
72 void operator () ( const size_t local, const GlobalKey& globalKey ) const
73 {
74 const auto &block = function_->dofVector()[ globalKey ];
75 Hybrid::forEach( LocalBlockIndices(), [ this, &block ] ( auto &&j ) { buffer_.write( block[ j ] ); } );
76 }
77 };
78
79 template < class Buffer >
80 struct ScatterFunctor
81 {
82 Buffer& buffer_;
83 DiscreteFunctionType *const function_;
84 const Operation& operation_;
85
86 ScatterFunctor( Buffer& buffer, DiscreteFunctionType* function, const Operation& operation )
87 : buffer_( buffer ), function_( function ), operation_( operation )
88 {}
89
90 template <class GlobalKey>
91 void operator () ( const size_t local, const GlobalKey& globalKey ) const
92 {
93 auto &&block = function_->dofVector()[ globalKey ];
94 Hybrid::forEach( LocalBlockIndices(), [ this, &block ] ( auto &&j ) {
95 DataType value;
96 buffer_.read( value );
97 operation_( value, block[ j ] );
98 } );
99 }
100 };
101
102 public:
103 bool contains ( int dim, int codim ) const
104 {
105 return blockMapper_.contains( codim );
106 }
107
108 bool fixedSize ( int dim, int codim) const
109 {
110 return blockMapper_.fixedDataSize( codim );
111 }
112
114 template< class MessageBuffer, class Entity >
115 void gather ( MessageBuffer &buffer, const Entity &entity ) const
116 {
117 GatherFunctor< MessageBuffer > gatherDofs ( buffer, function_ );
118 blockMapper_.mapEachEntityDof( entity, gatherDofs );
119 }
120
122 template< class MessageBuffer, class Entity >
123 void scatter ( MessageBuffer &buffer, const Entity &entity, size_t n )
124 {
125 assert( n == size( entity ) );
126 ScatterFunctor< MessageBuffer > scatterDofs ( buffer, function_, operation_ );
127
128 blockMapper_.mapEachEntityDof( entity, scatterDofs );
129 }
130
132 template< class Entity >
133 size_t size ( const Entity &entity ) const
134 {
135 return Hybrid::size( LocalBlockIndices() ) * blockMapper_.numEntityDofs( entity );
136 }
137
138 protected:
141 const Operation operation_;
142 };
143
144 } // namespace Fem
145
146} // namespace Dune
147
148#endif // #ifndef DUNE_FEM_DEFAULTDATAHANDLE_HH
Definition: bindguard.hh:11
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
Default communication handler for discrete functions.
Definition: defaultcommhandler.hh:29
const Operation operation_
Definition: defaultcommhandler.hh:141
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: defaultcommhandler.hh:38
DiscreteFunctionSpaceType::BlockMapperType BlockMapperType
Definition: defaultcommhandler.hh:41
DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices
Definition: defaultcommhandler.hh:42
void scatter(MessageBuffer &buffer, const Entity &entity, size_t n)
read buffer and apply operation
Definition: defaultcommhandler.hh:123
DiscreteFunctionType *const function_
Definition: defaultcommhandler.hh:139
DefaultCommunicationHandler(DiscreteFunctionType &function, const Operation &operation=Operation())
Definition: defaultcommhandler.hh:45
bool fixedSize(int dim, int codim) const
Definition: defaultcommhandler.hh:108
void gather(MessageBuffer &buffer, const Entity &entity) const
read buffer and apply operation
Definition: defaultcommhandler.hh:115
DefaultCommunicationHandler(const DefaultCommunicationHandler &other)
Definition: defaultcommhandler.hh:51
const BlockMapperType & blockMapper_
Definition: defaultcommhandler.hh:140
bool contains(int dim, int codim) const
Definition: defaultcommhandler.hh:103
size_t size(const Entity &entity) const
return local dof size to be communicated
Definition: defaultcommhandler.hh:133
DefaultCommunicationHandler & operator=(const DefaultCommunicationHandler &)=delete
cannot be implemented because of the reference
DiscreteFunction DiscreteFunctionType
Definition: defaultcommhandler.hh:36
BaseType::DataType DataType
Definition: defaultcommhandler.hh:34