DUNE-FEM (unstable)

defaultcommhandler.hh
1#ifndef DUNE_FEM_DEFAULTDATAHANDLE_HH
2#define DUNE_FEM_DEFAULTDATAHANDLE_HH
3
4#include <cassert>
5
6//- Dune includes
8
9#include <dune/fem/common/hybrid.hh>
10#include <dune/fem/space/common/commoperations.hh>
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
18 // External Forward Declarations
19 // -----------------------------
20
21 class IsDiscreteFunction;
22
23 class IsBlockVector;
24
25
32 template< class DiscreteFunctionSpace,
33 class DiscreteFunction, class Operation > // e.g. DFCommunicationOperation::Add or Copy
35 : public CommDataHandleIF
36 < DefaultCommunicationHandlerImpl< DiscreteFunctionSpace, DiscreteFunction, Operation >,
37 typename DiscreteFunction::DofType >
38 {
41
42 public:
43 typedef typename BaseType::DataType DataType;
44
45 typedef DiscreteFunction DiscreteFunctionType;
46
48
49 protected:
50 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
51 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
52
53 static constexpr bool isDiscreteFunction = std::is_base_of< IsDiscreteFunction, DiscreteFunction > :: value;
54
55 public:
57 DiscreteFunctionType &function, const Operation& operation = Operation() )
58 : function_( &function ),
59 blockMapper_( space.blockMapper() ),
60 operation_( operation )
61 {}
62
63 DefaultCommunicationHandlerImpl( DiscreteFunctionType &function, const Operation& operation = Operation() )
64 : DefaultCommunicationHandlerImpl( function.space(), function, operation )
65 {}
66
68 : function_( other.function_ ),
69 blockMapper_( other.blockMapper_ ),
70 operation_( other.operation_ )
71 {}
72
75
76 private:
77 template < class Buffer >
78 struct GatherFunctor
79 {
80 Buffer& buffer_;
81 DiscreteFunctionType *const function_;
82
83 GatherFunctor( Buffer& buffer, DiscreteFunctionType* function )
84 : buffer_( buffer ), function_( function )
85 {}
86
87 template <class GlobalKey>
88 void operator () ( const size_t local, const GlobalKey& globalKey ) const
89 {
90 if constexpr ( isDiscreteFunction )
91 {
92 const auto &block = function_->dofVector()[ globalKey ];
93 Hybrid::forEach( LocalBlockIndices(), [ this, &block ] ( auto &&j ) { buffer_.write( block[ j ] ); } );
94 }
95 else
96 {
97 // use block size from block vector since it
98 // may differ from block size of the space
99 static const int blockSize = DiscreteFunctionType::blockSize;
100 const auto &block = (*function_)[ globalKey ];
101 for( int j=0; j<blockSize; ++j )
102 buffer_.write( block[ j ] );
103 }
104 }
105 };
106
107 template < class Buffer >
108 struct ScatterFunctor
109 {
110 Buffer& buffer_;
111 DiscreteFunctionType *const function_;
112 const Operation& operation_;
113
114 ScatterFunctor( Buffer& buffer, DiscreteFunctionType* function, const Operation& operation )
115 : buffer_( buffer ), function_( function ), operation_( operation )
116 {}
117
118 template <class GlobalKey>
119 void operator () ( const size_t local, const GlobalKey& globalKey ) const
120 {
121 if constexpr( isDiscreteFunction )
122 {
123 auto &&block = function_->dofVector()[ globalKey ];
124 Hybrid::forEach( LocalBlockIndices(), [ this, &block ] ( auto &&j ) {
125 DataType value;
126 buffer_.read( value );
127 operation_( value, block[ j ] );
128 } );
129 }
130 else
131 {
132 // use block size from block vector since it
133 // may differ from block size of the space
134 static const int blockSize = DiscreteFunctionType::blockSize;
135 auto&& block = (*function_)[ globalKey ];
136 for( int j=0; j<blockSize; ++j )
137 {
138 DataType value;
139 buffer_.read( value );
140 operation_( value, block[ j ] );
141 }
142 }
143 }
144 };
145
146 public:
147 bool contains ( int dim, int codim ) const
148 {
149 return blockMapper_.contains( codim );
150 }
151
152 bool fixedSize ( int dim, int codim) const
153 {
154 return blockMapper_.fixedDataSize( codim );
155 }
156
158 template< class MessageBuffer, class Entity >
159 void gather ( MessageBuffer &buffer, const Entity &entity ) const
160 {
161 GatherFunctor< MessageBuffer > gatherDofs ( buffer, function_ );
162 blockMapper_.mapEachEntityDof( entity, gatherDofs );
163 }
164
166 template< class MessageBuffer, class Entity >
167 void scatter ( MessageBuffer &buffer, const Entity &entity, size_t n )
168 {
169 assert( n == size( entity ) );
170 ScatterFunctor< MessageBuffer > scatterDofs ( buffer, function_, operation_ );
171
172 blockMapper_.mapEachEntityDof( entity, scatterDofs );
173 }
174
176 template< class Entity >
177 size_t size ( const Entity &entity ) const
178 {
179 return Hybrid::size( LocalBlockIndices() ) * blockMapper_.numEntityDofs( entity );
180 }
181
182 protected:
183 DiscreteFunctionType *const function_;
184 const BlockMapperType &blockMapper_;
185 const Operation operation_;
186 };
187
195 template< class DiscreteFunction,
196 class Operation = DFCommunicationOperation::Add >
197 using DefaultCommunicationHandler =
198 DefaultCommunicationHandlerImpl< typename DiscreteFunction::DiscreteFunctionSpaceType,
199 DiscreteFunction, Operation >;
200
201 } // namespace Fem
202
203} // namespace Dune
204
205#endif // #ifndef DUNE_FEM_DEFAULTDATAHANDLE_HH
discrete function space
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)