dune-alugrid 2.8.0
Loading...
Searching...
No Matches
communication.hh
Go to the documentation of this file.
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
8#include <dune/common/visibility.hh>
9#include <dune/common/stdstreams.hh>
10
11#include <dune/grid/common/datahandleif.hh>
12#include <dune/grid/common/gridenums.hh>
13
16
17namespace Dune
18{
19
20 // Internal Forward Declaration
21 // ----------------------------
22
23 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
25
26 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
28
29 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
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 {
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 {
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,
74 InterfaceType iftype, CommunicationDirection dir )
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 {
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 {
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
135
136 protected:
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
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 {
205
206 public:
207 typedef typename Base::Grid Grid;
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 >
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:
235 using Base::Storage::vertex;
236 using Base::Storage::edge;
237 using Base::Storage::face;
238 using Base::Storage::element;
239
240 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, dim > vertexGatherScatter_;
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,
249 InterfaceType iftype, CommunicationDirection dir )
250 : Base( grid, new Storage< DataHandle, Data >( grid, data ), iftype, dir )
251 {}
252
254 : Base( static_cast< Base && >( other ) )
255 {}
256
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 {
274
275 public:
276 typedef typename Base::Grid Grid;
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 >
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:
305 using Base::Storage::vertex;
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_;
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
325 : Base( static_cast< Base && >( other ) )
326 {}
327
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
#define ALU3DSPACE
Definition: alu3dinclude.hh:7
Definition: alu3dinclude.hh:63
Definition: communication.hh:24
Definition: communication.hh:27
Definition: communication.hh:30
[ provides Dune::Grid ]
Definition: 3d/grid.hh:429
GitterImplType & myGrid() const
Definition: grid_inline.hh:89
bool ready() const
Definition: communication.hh:50
bool pending() const
Definition: communication.hh:55
ALU3dGrid< dim, dimworld, elType, ALUGridNoComm > Grid
Definition: communication.hh:48
ALULeafCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir)
Definition: communication.hh:73
ALULevelCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir, int level)
Definition: communication.hh:93
Grid::Traits::template Codim< 0 >::EntityImp ElementImpl
Definition: communication.hh:118
Grid::Traits::template Codim< 1 >::EntityImp FaceImpl
Definition: communication.hh:117
ALU3DSPACE GatherScatter GatherScatter
Definition: communication.hh:107
ALU3dGrid< dim, dimworld, elType, ALUGridMPIComm > Grid
Definition: communication.hh:106
bool pending() const
Definition: communication.hh:189
bool ready() const
Definition: communication.hh:184
Grid::Traits::template Codim< 2 >::Entity EdgeObject
Definition: communication.hh:111
Grid::Traits::template Codim< 2 >::EntityImp EdgeImpl
Definition: communication.hh:116
Grid::Traits::template Codim< 1 >::Entity FaceObject
Definition: communication.hh:112
Grid::Traits::template Codim< dim >::Entity VertexObject
Definition: communication.hh:110
Grid::Traits::template Codim< dim >::EntityImp VertexImpl
Definition: communication.hh:115
ALUCommunication(ALUCommunication &&other)
Definition: communication.hh:172
Grid::Traits::template Codim< 0 >::Entity ElementObject
Definition: communication.hh:113
ALUCommunication(const Grid &grid, Storage *storage, InterfaceType iftype, CommunicationDirection dir)
Definition: communication.hh:144
Storage(const Grid &grid, int level)
Definition: communication.hh:122
Base::GatherScatter GatherScatter
Definition: communication.hh:208
ALULeafCommunication(ALULeafCommunication &&other)
Definition: communication.hh:253
ALULeafCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir)
Definition: communication.hh:248
GatherScatter & edgeGatherScatter()
Definition: communication.hh:230
Storage(const Grid &grid, CommDataHandleIF &dataHandle)
Definition: communication.hh:221
ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, dim > vertexGatherScatter_
Definition: communication.hh:240
ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 0 > elementGatherScatter_
Definition: communication.hh:243
EdgeGatherScatterType edgeGatherScatter_
Definition: communication.hh:241
GatherScatter & faceGatherScatter()
Definition: communication.hh:231
Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF
Definition: communication.hh:215
GatherScatter & vertexGatherScatter()
Definition: communication.hh:229
GatherScatter & elementGatherScatter()
Definition: communication.hh:232
std::conditional< dim==2, ALU3DSPACEGatherScatterNoData< Grid, CommDataHandleIF, 2 >, ALU3DSPACEGatherScatterLeafData< Grid, CommDataHandleIF, 2 > >::type EdgeGatherScatterType
Definition: communication.hh:219
ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 1 > faceGatherScatter_
Definition: communication.hh:242
ALULevelCommunication(ALULevelCommunication &&other)
Definition: communication.hh:324
ALULevelCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir, int level)
Definition: communication.hh:319
Base::GatherScatter GatherScatter
Definition: communication.hh:277
GatherScatter & faceGatherScatter()
Definition: communication.hh:301
std::conditional< dim==2, ALU3DSPACEGatherScatterNoData< Grid, CommDataHandleIF, 2 >, ALU3DSPACEGatherScatterLevelData< Grid, CommDataHandleIF, 2 > >::type EdgeGatherScatterType
Definition: communication.hh:288
GatherScatter & edgeGatherScatter()
Definition: communication.hh:300
ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, dim > vertexGatherScatter_
Definition: communication.hh:311
ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 0 > elementGatherScatter_
Definition: communication.hh:314
EdgeGatherScatterType edgeGatherScatter_
Definition: communication.hh:312
ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 1 > faceGatherScatter_
Definition: communication.hh:313
GatherScatter & vertexGatherScatter()
Definition: communication.hh:299
Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF
Definition: communication.hh:284
std::shared_ptr< typename Grid::LevelIndexSetImp > indexSet_
Definition: communication.hh:310
Storage(const Grid &grid, int level, CommDataHandleIF &dataHandle)
Definition: communication.hh:290
GatherScatter & elementGatherScatter()
Definition: communication.hh:302
type of class for specialization of serial ALUGrid (No_Comm as communicator)
Definition: declaration.hh:31
type of class for specialization of parallel ALUGrid (MPI_Comm as communicator)
Definition: declaration.hh:43