dune-alugrid 3.0.0
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/stdstreams.hh>
9
10#include <dune/grid/common/datahandleif.hh>
11#include <dune/grid/common/gridenums.hh>
12
15
16namespace Dune
17{
18
19 // Internal Forward Declaration
20 // ----------------------------
21
22 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
24
25 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
27
28 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
30
31
32
33 // External Forward Declarations
34 // -----------------------------
35
36 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
37 class ALU3dGrid;
38
39
40
41 // ALUCommunication for ALUGridNoComm
42 // ----------------------------------
43
44 template< int dim, int dimworld, ALU3dGridElementType elType >
45 struct ALUCommunication< dim, dimworld, elType, ALUGridNoComm >
46 {
48
49 bool pending () const { return false; }
50
51 void wait () {}
52 };
53
54
55
56 // ALULeafCommunication for ALUGridNoComm
57 // --------------------------------------
58
59 template< int dim, int dimworld, ALU3dGridElementType elType >
60 class ALULeafCommunication< dim, dimworld, elType, ALUGridNoComm >
61 : public ALUCommunication< dim, dimworld, elType, ALUGridNoComm >
62 {
64
65 public:
66 typedef typename Base::Grid Grid;
67
68 template< class DataHandle, class Data >
69 ALULeafCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
70 InterfaceType iftype, CommunicationDirection dir )
71 {}
72 };
73
74
75
76 // ALULevelCommunication for ALUGridNoComm
77 // ---------------------------------------
78
79 template< int dim, int dimworld, ALU3dGridElementType elType >
80 class ALULevelCommunication< dim, dimworld, elType, ALUGridNoComm >
81 : public ALUCommunication< dim, dimworld, elType, ALUGridNoComm >
82 {
84
85 public:
86 typedef typename Base::Grid Grid;
87
88 template< class DataHandle, class Data >
89 ALULevelCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
90 InterfaceType iftype, CommunicationDirection dir, int level )
91 {}
92 };
93
94
95
96 // ALUCommunication for ALUGridMPIComm
97 // -----------------------------------
98
99 template< int dim, int dimworld, ALU3dGridElementType elType >
100 struct ALUCommunication< dim, dimworld, elType, ALUGridMPIComm >
101 {
104
105 protected:
106 typedef typename Grid::Traits::template Codim< dim >::Entity VertexObject;
107 typedef typename Grid::Traits::template Codim< 2 >::Entity EdgeObject;
108 typedef typename Grid::Traits::template Codim< 1 >::Entity FaceObject;
109 typedef typename Grid::Traits::template Codim< 0 >::Entity ElementObject;
110
111 typedef typename Grid::Traits::template Codim< dim >::EntityImp VertexImpl;
112 typedef typename Grid::Traits::template Codim< 2 >::EntityImp EdgeImpl;
113 typedef typename Grid::Traits::template Codim< 1 >::EntityImp FaceImpl;
114 typedef typename Grid::Traits::template Codim< 0 >::EntityImp ElementImpl;
115
116 struct Storage
117 {
118 Storage ( const Grid &grid, int level )
119 : vertex( VertexImpl() ),
120 edge( EdgeImpl() ),
121 face( FaceImpl() ),
122 element( ElementImpl() )
123 {}
124
125 virtual ~Storage () {}
126
131
132 protected:
137 };
138
139 public:
140 ALUCommunication ( const Grid &grid, Storage *storage, InterfaceType iftype, CommunicationDirection dir )
141 : storage_( storage )
142 {
143 // check interface types
144 if( (iftype == Overlap_OverlapFront_Interface) || (iftype == Overlap_All_Interface) )
145 {
146 dverb << "ALUGrid contains no overlap, therefore no communication for" << std::endl;
147 dverb << "Overlap_OverlapFront_Interface or Overlap_All_Interface interfaces!" << std::endl;
148 }
149 // communication from border to border
150 else if( iftype == InteriorBorder_InteriorBorder_Interface )
151 grid.myGrid().borderBorderCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
152 // communication from interior to ghost including border
153 else if( iftype == InteriorBorder_All_Interface )
154 {
155 if( dir == ForwardCommunication )
156 communication_ = grid.myGrid().interiorGhostCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
157 // reverse communiction interface (here All_InteriorBorder)
158 else if( dir == BackwardCommunication )
159 communication_ = grid.myGrid().ghostInteriorCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
160 }
161 // communication from interior to ghost including border
162 else if( iftype == All_All_Interface )
163 communication_ = grid.myGrid().allAllCommunication( storage_->vertexGatherScatter(), storage_->edgeGatherScatter(), storage_->faceGatherScatter(), storage_->elementGatherScatter() );
164 else
165 DUNE_THROW( GridError, "Wrong parameters in ALUCommunication." );
166 }
167
169 : storage_( std::move( other.storage_ ) ),
170 communication_( std::move( other.communication_ ) )
171 {}
172
173 ALUCommunication &operator= ( ALUCommunication &&other )
174 {
175 storage_ = std::move( other.storage_ );
176 communication_ = std::move( other.communication_ );
177 return *this;
178 }
179
180 bool pending () const { return communication_.pending(); }
181
182 void wait () { communication_.wait(); }
183
184 private:
185 std::unique_ptr< Storage > storage_;
186 ALU3DSPACE GitterDunePll::Communication communication_;
187 };
188
189
190
191 // ALULeafCommunication for ALUGridMPIComm
192 // ---------------------------------------
193
194 template< int dim, int dimworld, ALU3dGridElementType elType >
195 class ALULeafCommunication< dim, dimworld, elType, ALUGridMPIComm >
196 : public ALUCommunication< dim, dimworld, elType, ALUGridMPIComm >
197 {
199
200 public:
201 typedef typename Base::Grid Grid;
203
204 protected:
205 template< class DataHandle, class Data >
206 struct Storage
207 : Base::Storage
208 {
209 typedef Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF;
210 typedef typename std::conditional<dim == 2,
211 ALU3DSPACE GatherScatterNoData< Grid, CommDataHandleIF, 2 >,
212 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 2 >
214
215 Storage ( const Grid &grid, CommDataHandleIF &dataHandle )
216 : Base::Storage( grid, grid.maxLevel() ),
217 vertexGatherScatter_( grid, vertex, Grid::getRealImplementation( vertex ), dataHandle ),
218 edgeGatherScatter_( grid, edge, Grid::getRealImplementation( edge ), dataHandle ),
219 faceGatherScatter_( grid, face, Grid::getRealImplementation( face ), dataHandle ),
220 elementGatherScatter_( grid, element, Grid::getRealImplementation( element ), dataHandle )
221 {}
222
223 GatherScatter &vertexGatherScatter () { return vertexGatherScatter_; }
224 GatherScatter &edgeGatherScatter () { return edgeGatherScatter_; }
225 GatherScatter &faceGatherScatter () { return faceGatherScatter_; }
226 GatherScatter &elementGatherScatter () { return elementGatherScatter_; }
227
228 protected:
229 using Base::Storage::vertex;
230 using Base::Storage::edge;
231 using Base::Storage::face;
232 using Base::Storage::element;
233
234 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, dim > vertexGatherScatter_;
236 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 1 > faceGatherScatter_;
237 ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 0 > elementGatherScatter_;
238 };
239
240 public:
241 template< class DataHandle, class Data >
242 ALULeafCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
243 InterfaceType iftype, CommunicationDirection dir )
244 : Base( grid, new Storage< DataHandle, Data >( grid, data ), iftype, dir )
245 {}
246
248 : Base( static_cast< Base && >( other ) )
249 {}
250
252 {
253 static_cast< Base & >( *this ) = static_cast< Base && >( other );
254 return *this;
255 }
256 };
257
258
259
260 // ALULevelCommunication for ALUGridMPIComm
261 // ----------------------------------------
262
263 template< int dim, int dimworld, ALU3dGridElementType elType >
264 class ALULevelCommunication< dim, dimworld, elType, ALUGridMPIComm >
265 : public ALUCommunication< dim, dimworld, elType, ALUGridMPIComm >
266 {
268
269 public:
270 typedef typename Base::Grid Grid;
272
273 protected:
274 template< class DataHandle, class Data >
275 struct Storage
276 : Base::Storage
277 {
278 typedef Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF;
279 typedef typename std::conditional<dim == 2,
280 ALU3DSPACE GatherScatterNoData< Grid, CommDataHandleIF, 2 >,
281 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 2 >
283
284 Storage ( const Grid &grid, int level, CommDataHandleIF &dataHandle )
285 : Base::Storage( grid, level ),
286 indexSet_( grid.accessLevelIndexSet( level ) ),
287 vertexGatherScatter_( grid, vertex, Grid::getRealImplementation( vertex ), dataHandle, *indexSet_, level ),
288 edgeGatherScatter_( grid, edge, Grid::getRealImplementation( edge ), dataHandle, *indexSet_, level ),
289 faceGatherScatter_( grid, face, Grid::getRealImplementation( face ), dataHandle, *indexSet_, level ),
290 elementGatherScatter_( grid, element, Grid::getRealImplementation( element ), dataHandle, *indexSet_, level )
291 {}
292
293 GatherScatter &vertexGatherScatter () { return vertexGatherScatter_; }
294 GatherScatter &edgeGatherScatter () { return edgeGatherScatter_; }
295 GatherScatter &faceGatherScatter () { return faceGatherScatter_; }
296 GatherScatter &elementGatherScatter () { return elementGatherScatter_; }
297
298 protected:
299 using Base::Storage::vertex;
300 using Base::Storage::edge;
301 using Base::Storage::face;
302 using Base::Storage::element;
303
304 std::shared_ptr< typename Grid::LevelIndexSetImp > indexSet_;
305 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, dim > vertexGatherScatter_;
307 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 1 > faceGatherScatter_;
308 ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 0 > elementGatherScatter_;
309 };
310
311 public:
312 template< class DataHandle, class Data >
313 ALULevelCommunication ( const Grid &grid, CommDataHandleIF< DataHandle, Data > &data,
314 InterfaceType iftype, CommunicationDirection dir, int level )
315 : Base( grid, new Storage< DataHandle, Data >( grid, level, data ), iftype, dir )
316 {}
317
319 : Base( static_cast< Base && >( other ) )
320 {}
321
323 {
324 static_cast< Base & >( *this ) = static_cast< Base && >( other );
325 return *this;
326 }
327 };
328
329} // namespace Dune
330
331#endif // #ifndef DUNE_ALUGRID_3D_COMMUNICATION_HH
#define ALU3DSPACE
Definition alu3dinclude.hh:24
Definition alu3dinclude.hh:80
Definition communication.hh:23
Definition communication.hh:26
Definition communication.hh:29
[ provides Dune::Grid ]
Definition 3d/grid.hh:468
bool pending() const
Definition communication.hh:49
ALU3dGrid< dim, dimworld, elType, ALUGridNoComm > Grid
Definition communication.hh:47
ALULeafCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir)
Definition communication.hh:69
ALULevelCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir, int level)
Definition communication.hh:89
Grid::Traits::template Codim< 0 >::EntityImp ElementImpl
Definition communication.hh:114
Grid::Traits::template Codim< 1 >::EntityImp FaceImpl
Definition communication.hh:113
ALU3DSPACE GatherScatter GatherScatter
Definition communication.hh:103
ALU3dGrid< dim, dimworld, elType, ALUGridMPIComm > Grid
Definition communication.hh:102
bool pending() const
Definition communication.hh:180
Grid::Traits::template Codim< 2 >::Entity EdgeObject
Definition communication.hh:107
Grid::Traits::template Codim< 2 >::EntityImp EdgeImpl
Definition communication.hh:112
Grid::Traits::template Codim< 1 >::Entity FaceObject
Definition communication.hh:108
Grid::Traits::template Codim< dim >::Entity VertexObject
Definition communication.hh:106
Grid::Traits::template Codim< dim >::EntityImp VertexImpl
Definition communication.hh:111
ALUCommunication(ALUCommunication &&other)
Definition communication.hh:168
Grid::Traits::template Codim< 0 >::Entity ElementObject
Definition communication.hh:109
ALUCommunication(const Grid &grid, Storage *storage, InterfaceType iftype, CommunicationDirection dir)
Definition communication.hh:140
Storage(const Grid &grid, int level)
Definition communication.hh:118
Base::GatherScatter GatherScatter
Definition communication.hh:202
ALULeafCommunication(ALULeafCommunication &&other)
Definition communication.hh:247
ALULeafCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir)
Definition communication.hh:242
GatherScatter & edgeGatherScatter()
Definition communication.hh:224
Storage(const Grid &grid, CommDataHandleIF &dataHandle)
Definition communication.hh:215
ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, dim > vertexGatherScatter_
Definition communication.hh:234
ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 0 > elementGatherScatter_
Definition communication.hh:237
EdgeGatherScatterType edgeGatherScatter_
Definition communication.hh:235
GatherScatter & faceGatherScatter()
Definition communication.hh:225
Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF
Definition communication.hh:209
GatherScatter & vertexGatherScatter()
Definition communication.hh:223
GatherScatter & elementGatherScatter()
Definition communication.hh:226
std::conditional< dim==2, ALU3DSPACEGatherScatterNoData< Grid, CommDataHandleIF, 2 >, ALU3DSPACEGatherScatterLeafData< Grid, CommDataHandleIF, 2 > >::type EdgeGatherScatterType
Definition communication.hh:213
ALU3DSPACE GatherScatterLeafData< Grid, CommDataHandleIF, 1 > faceGatherScatter_
Definition communication.hh:236
ALULevelCommunication(ALULevelCommunication &&other)
Definition communication.hh:318
ALULevelCommunication(const Grid &grid, CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir, int level)
Definition communication.hh:313
Base::GatherScatter GatherScatter
Definition communication.hh:271
GatherScatter & faceGatherScatter()
Definition communication.hh:295
std::conditional< dim==2, ALU3DSPACEGatherScatterNoData< Grid, CommDataHandleIF, 2 >, ALU3DSPACEGatherScatterLevelData< Grid, CommDataHandleIF, 2 > >::type EdgeGatherScatterType
Definition communication.hh:282
GatherScatter & edgeGatherScatter()
Definition communication.hh:294
ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, dim > vertexGatherScatter_
Definition communication.hh:305
ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 0 > elementGatherScatter_
Definition communication.hh:308
EdgeGatherScatterType edgeGatherScatter_
Definition communication.hh:306
ALU3DSPACE GatherScatterLevelData< Grid, CommDataHandleIF, 1 > faceGatherScatter_
Definition communication.hh:307
GatherScatter & vertexGatherScatter()
Definition communication.hh:293
Dune::CommDataHandleIF< DataHandle, Data > CommDataHandleIF
Definition communication.hh:278
std::shared_ptr< typename Grid::LevelIndexSetImp > indexSet_
Definition communication.hh:304
Storage(const Grid &grid, int level, CommDataHandleIF &dataHandle)
Definition communication.hh:284
GatherScatter & elementGatherScatter()
Definition communication.hh:296
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:39