Dune Core Modules (2.9.0)

communication.hh
1#ifndef DUNE_ALUGRID_3D_COMMUNICATION_HH
2#define DUNE_ALUGRID_3D_COMMUNICATION_HH
3
4#include <memory>
5#include <utility>
6#include <type_traits>
7
10
12#include <dune/grid/common/gridenums.hh>
13
14#include <dune/alugrid/3d/alu3dinclude.hh>
15#include <dune/alugrid/3d/datahandle.hh>
16
17namespace Dune
18{
19
20 // Internal Forward Declaration
21 // ----------------------------
22
23 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
24 struct ALUCommunication;
25
26 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
27 class ALULeafCommunication;
28
29 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
30 class ALULevelCommunication;
31
32
33
34 // External Forward Declarations
35 // -----------------------------
36
37 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
38 class ALU3dGrid;
39
40
41
42 // ALUCommunication for ALUGridNoComm
43 // ----------------------------------
44
45 template< int dim, int dimworld, ALU3dGridElementType elType >
46 struct ALUCommunication< dim, dimworld, elType, ALUGridNoComm >
47 {
48 typedef ALU3dGrid< dim, dimworld, elType, ALUGridNoComm > Grid;
49
50 bool ready() const { return true; }
51
52 void wait () {}
53
54 [[deprecated]]
55 bool pending () const { return ! ready(); }
56 };
57
58
59
60 // ALULeafCommunication for ALUGridNoComm
61 // --------------------------------------
62
63 template< int dim, int dimworld, ALU3dGridElementType elType >
64 class ALULeafCommunication< dim, dimworld, elType, ALUGridNoComm >
65 : public ALUCommunication< dim, dimworld, elType, ALUGridNoComm >
66 {
67 typedef ALUCommunication< dim, dimworld, elType, ALUGridNoComm > Base;
68
69 public:
70 typedef typename Base::Grid Grid;
71
72 template< class DataHandle, class Data >
73 ALULeafCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
75 {}
76 };
77
78
79
80 // ALULevelCommunication for ALUGridNoComm
81 // ---------------------------------------
82
83 template< int dim, int dimworld, ALU3dGridElementType elType >
84 class ALULevelCommunication< dim, dimworld, elType, ALUGridNoComm >
85 : public ALUCommunication< dim, dimworld, elType, ALUGridNoComm >
86 {
87 typedef ALUCommunication< dim, dimworld, elType, ALUGridNoComm > Base;
88
89 public:
90 typedef typename Base::Grid Grid;
91
92 template< class DataHandle, class Data >
93 ALULevelCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
94 InterfaceType iftype, CommunicationDirection dir, int level )
95 {}
96 };
97
98
99
100 // ALUCommunication for ALUGridMPIComm
101 // -----------------------------------
102
103 template< int dim, int dimworld, ALU3dGridElementType elType >
104 struct ALUCommunication< dim, dimworld, elType, ALUGridMPIComm >
105 {
106 typedef ALU3dGrid< dim, dimworld, elType, ALUGridMPIComm > Grid;
107 typedef ALU3DSPACE GatherScatter GatherScatter;
108
109 protected:
110 typedef typename Grid::Traits::template Codim< dim >::Entity VertexObject;
111 typedef typename Grid::Traits::template Codim< 2 >::Entity EdgeObject;
112 typedef typename Grid::Traits::template Codim< 1 >::Entity FaceObject;
113 typedef typename Grid::Traits::template Codim< 0 >::Entity ElementObject;
114
115 typedef typename Grid::Traits::template Codim< dim >::EntityImp VertexImpl;
116 typedef typename Grid::Traits::template Codim< 2 >::EntityImp EdgeImpl;
117 typedef typename Grid::Traits::template Codim< 1 >::EntityImp FaceImpl;
118 typedef typename Grid::Traits::template Codim< 0 >::EntityImp ElementImpl;
119
120 struct Storage
121 {
122 Storage ( const Grid &grid, int level )
123 : vertex( VertexImpl() ),
124 edge( EdgeImpl() ),
125 face( FaceImpl() ),
126 element( ElementImpl() )
127 {}
128
129 virtual ~Storage () {}
130
131 virtual GatherScatter &vertexGatherScatter () = 0;
132 virtual GatherScatter &edgeGatherScatter () = 0;
133 virtual GatherScatter &faceGatherScatter () = 0;
134 virtual GatherScatter &elementGatherScatter () = 0;
135
136 protected:
137 VertexObject vertex;
138 EdgeObject edge;
139 FaceObject face;
140 ElementObject element;
141 };
142
143 public:
144 ALUCommunication ( const Grid &grid, Storage *storage, InterfaceType iftype, CommunicationDirection dir )
145 : storage_( storage )
146 {
147 // check interface types
148 if( (iftype == Overlap_OverlapFront_Interface) || (iftype == Overlap_All_Interface) )
149 {
150 dverb << "ALUGrid contains no overlap, therefore no communication for" << std::endl;
151 dverb << "Overlap_OverlapFront_Interface or Overlap_All_Interface interfaces!" << std::endl;
152 }
153 // communication from border to border
154 else if( iftype == InteriorBorder_InteriorBorder_Interface )
155 grid.myGrid().borderBorderCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
156 // communication from interior to ghost including border
157 else if( iftype == InteriorBorder_All_Interface )
158 {
159 if( dir == ForwardCommunication )
160 communication_ = grid.myGrid().interiorGhostCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
161 // reverse communiction interface (here All_InteriorBorder)
162 else if( dir == BackwardCommunication )
163 communication_ = grid.myGrid().ghostInteriorCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
164 }
165 // communication from interior to ghost including border
166 else if( iftype == All_All_Interface )
167 communication_ = grid.myGrid().allAllCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
168 else
169 DUNE_THROW( GridError, "Wrong parameters in ALUCommunication." );
170 }
171
172 ALUCommunication ( ALUCommunication &&other )
173 : storage_( std::move( other.storage_ ) ),
174 communication_( std::move( other.communication_ ) )
175 {}
176
177 ALUCommunication &operator= ( ALUCommunication &&other )
178 {
179 storage_ = std::move( other.storage_ );
180 communication_ = std::move( other.communication_ );
181 return *this;
182 }
183
184 bool ready () const { return communication_.ready(); }
185
186 void wait () { communication_.wait(); }
187
188 [[ deprecated ]]
189 bool pending () const { return ! ready(); }
190 private:
191 std::unique_ptr< Storage > storage_;
192 ALU3DSPACE GitterDunePll::Communication communication_;
193 };
194
195
196
197 // ALULeafCommunication for ALUGridMPIComm
198 // ---------------------------------------
199
200 template< int dim, int dimworld, ALU3dGridElementType elType >
201 class ALULeafCommunication< dim, dimworld, elType, ALUGridMPIComm >
202 : public ALUCommunication< dim, dimworld, elType, ALUGridMPIComm >
203 {
204 typedef ALUCommunication< dim, dimworld, elType, ALUGridMPIComm > Base;
205
206 public:
207 typedef typename Base::Grid Grid;
208 typedef typename Base::GatherScatter GatherScatter;
209
210 protected:
211 template< class DataHandle, class Data >
212 struct DUNE_PRIVATE Storage
213 : Base::Storage
214 {
215 typedef Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF;
216 typedef typename std::conditional<dim == 2,
217 ALU3DSPACE GatherScatterNoData< Grid, CommDataHandleIF, 2 >,
218 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 2 >
219 >::type EdgeGatherScatterType;
220
221 Storage ( const Grid &grid, CommDataHandleIF &dataHandle )
222 : Base::Storage( grid, grid.maxLevel() ),
223 vertexGatherScatter_( grid, vertex, vertex.impl(), dataHandle ),
224 edgeGatherScatter_( grid, edge, edge.impl(), dataHandle ),
225 faceGatherScatter_( grid, face, face.impl(), dataHandle ),
226 elementGatherScatter_( grid, element, element.impl(), dataHandle )
227 {}
228
229 GatherScatter &vertexGatherScatter () { return vertexGatherScatter_; }
230 GatherScatter &edgeGatherScatter () { return edgeGatherScatter_; }
231 GatherScatter &faceGatherScatter () { return faceGatherScatter_; }
232 GatherScatter &elementGatherScatter () { return elementGatherScatter_; }
233
234 protected:
236 using Base::Storage::edge;
237 using Base::Storage::face;
238 using Base::Storage::element;
239
240 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, dim > vertexGatherScatter_;
241 EdgeGatherScatterType edgeGatherScatter_;
242 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 1 > faceGatherScatter_;
243 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 0 > elementGatherScatter_;
244 };
245
246 public:
247 template< class DataHandle, class Data >
248 ALULeafCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
250 : Base( grid, new Storage< DataHandle, Data >( grid, data ), iftype, dir )
251 {}
252
253 ALULeafCommunication ( ALULeafCommunication &&other )
254 : Base( static_cast< Base && >( other ) )
255 {}
256
257 ALULeafCommunication &operator= ( ALULeafCommunication &&other )
258 {
259 static_cast< Base & >( *this ) = static_cast< Base && >( other );
260 return *this;
261 }
262 };
263
264
265
266 // ALULevelCommunication for ALUGridMPIComm
267 // ----------------------------------------
268
269 template< int dim, int dimworld, ALU3dGridElementType elType >
270 class ALULevelCommunication< dim, dimworld, elType, ALUGridMPIComm >
271 : public ALUCommunication< dim, dimworld, elType, ALUGridMPIComm >
272 {
273 typedef ALUCommunication< dim, dimworld, elType, ALUGridMPIComm > Base;
274
275 public:
276 typedef typename Base::Grid Grid;
277 typedef typename Base::GatherScatter GatherScatter;
278
279 protected:
280 template< class DataHandle, class Data >
281 struct DUNE_PRIVATE Storage
282 : Base::Storage
283 {
284 typedef Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF;
285 typedef typename std::conditional<dim == 2,
286 ALU3DSPACE GatherScatterNoData< Grid, CommDataHandleIF, 2 >,
287 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 2 >
288 >::type EdgeGatherScatterType;
289
290 Storage ( const Grid &grid, int level, CommDataHandleIF &dataHandle )
291 : Base::Storage( grid, level ),
292 indexSet_( grid.accessLevelIndexSet( level ) ),
293 vertexGatherScatter_( grid, vertex, vertex.impl(), dataHandle, *indexSet_, level ),
294 edgeGatherScatter_( grid, edge, edge.impl(), dataHandle, *indexSet_, level ),
295 faceGatherScatter_( grid, face, face.impl(), dataHandle, *indexSet_, level ),
296 elementGatherScatter_( grid, element, element.impl(), dataHandle, *indexSet_, level )
297 {}
298
299 GatherScatter &vertexGatherScatter () { return vertexGatherScatter_; }
300 GatherScatter &edgeGatherScatter () { return edgeGatherScatter_; }
301 GatherScatter &faceGatherScatter () { return faceGatherScatter_; }
302 GatherScatter &elementGatherScatter () { return elementGatherScatter_; }
303
304 protected:
306 using Base::Storage::edge;
307 using Base::Storage::face;
308 using Base::Storage::element;
309
310 std::shared_ptr< typename Grid::LevelIndexSetImp > indexSet_;
311 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, dim > vertexGatherScatter_;
312 EdgeGatherScatterType edgeGatherScatter_;
313 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 1 > faceGatherScatter_;
314 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 0 > elementGatherScatter_;
315 };
316
317 public:
318 template< class DataHandle, class Data >
319 ALULevelCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
320 InterfaceType iftype, CommunicationDirection dir, int level )
321 : Base( grid, new Storage< DataHandle, Data >( grid, level, data ), iftype, dir )
322 {}
323
324 ALULevelCommunication ( ALULevelCommunication &&other )
325 : Base( static_cast< Base && >( other ) )
326 {}
327
328 ALULevelCommunication &operator= ( ALULevelCommunication &&other )
329 {
330 static_cast< Base & >( *this ) = static_cast< Base && >( other );
331 return *this;
332 }
333 };
334
335} // namespace Dune
336
337#endif // #ifndef DUNE_ALUGRID_3D_COMMUNICATION_HH
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
Describes the parallel communication interface class for MessageBuffers and DataHandles.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
@ BackwardCommunication
reverse communication direction
Definition: gridenums.hh:172
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:171
@ InteriorBorder_All_Interface
send interior and border, receive all entities
Definition: gridenums.hh:88
@ All_All_Interface
send all and receive all entities
Definition: gridenums.hh:91
@ Overlap_All_Interface
send overlap, receive all entities
Definition: gridenums.hh:90
@ Overlap_OverlapFront_Interface
send overlap, receive overlap and front entities
Definition: gridenums.hh:89
@ InteriorBorder_InteriorBorder_Interface
send/receive interior and border entities
Definition: gridenums.hh:87
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:506
DVerbType dverb(std::cout)
Singleton of verbose debug stream.
Definition: stdstreams.hh:116
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Standard Dune debug streams.
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_PRIVATE
Mark a symbol as being for internal use within the current DSO only.
Definition: visibility.hh:28
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)