dune-grid-glue 2.5-git
gridglue.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
10#ifndef DUNE_GRIDGLUE_GRIDGLUE_HH
11#define DUNE_GRIDGLUE_GRIDGLUE_HH
12
13#include <dune/common/deprecated.hh>
14#include <dune/common/exceptions.hh>
15#include <dune/common/iteratorfacades.hh>
16#include <dune/common/promotiontraits.hh>
17#include <dune/common/shared_ptr.hh>
18
21
22#include <dune/common/parallel/mpitraits.hh>
23#include <dune/common/parallel/mpicollectivecommunication.hh>
24#include <dune/common/parallel/indexset.hh>
25#include <dune/common/parallel/plocalindex.hh>
26#include <dune/common/parallel/remoteindices.hh>
27#include <dune/common/parallel/communicator.hh>
28#include <dune/common/parallel/interface.hh>
29
30namespace Dune {
31namespace GridGlue {
32
35 Domain = 0,
36 Target = 1
37};
38
39// forward declarations
40template<typename P0, typename P1>
41class GridGlue;
42
43template<typename P0, typename P1>
44class IntersectionData;
45
46template<typename P0, typename P1, int inside, int outside>
47class Intersection;
48
49template<typename P0, typename P1, int inside, int outside>
50class IntersectionIterator;
51
52template<typename P0, typename P1>
53class IntersectionIndexSet;
54
55template<typename P0, typename P1, int P>
57
58template<typename P0, typename P1>
59struct GridGlueView<P0,P1,0>
60{
61 typedef P0 Patch;
63 typedef typename Patch::GridView::template Codim<0>::Entity GridElement;
64 static const P0& patch(const GridGlue<P0,P1>& g)
65 {
66 return *g.patch0_;
67 }
68};
69
70template<typename P0, typename P1>
71struct GridGlueView<P0,P1,1>
72{
73 typedef P1 Patch;
75 typedef typename Patch::GridView::template Codim<0>::Entity GridElement;
76 static const P1& patch(const GridGlue<P0,P1>& g)
77 {
78 return *g.patch1_;
79 }
80};
81
91template<typename P0, typename P1>
93{
94private:
95
96 /* F R I E N D S */
97
98 friend class IntersectionData<P0,P1>;
99 friend class Intersection<P0,P1,0,1>;
100 friend class Intersection<P0,P1,1,0>;
101 friend class IntersectionIterator<P0,P1,0,1>;
102 friend class IntersectionIterator<P0,P1,1,0>;
103 friend class IntersectionIndexSet<P0,P1>;
104 friend struct GridGlueView<P0,P1,0>;
105 friend struct GridGlueView<P0,P1,1>;
106
107 /* P R I V A T E T Y P E S */
108
111
113 typedef Dune::ParallelLocalIndex <Dune::PartitionType> LocalIndex;
114
116 typedef Dune::ParallelIndexSet <GlobalId, LocalIndex> PIndexSet;
117
118public:
119
120 /* P U B L I C T Y P E S A N D C O N S T A N T S */
121
123 typedef typename P0::GridView Grid0View;
124
126 typedef typename Grid0View::Grid Grid0;
127
129 typedef P0 Grid0Patch;
130
132 enum {
134 grid0dim = Grid0Patch::dim,
135 domdim = Grid0Patch::dim,
137 grid0dimworld = Grid0Patch::dimworld,
138 domdimworld = Grid0Patch::dimworld
139 };
140
142 typedef typename P1::GridView Grid1View;
143
145 typedef typename Grid1View::Grid Grid1;
146
148 typedef P1 Grid1Patch;
149
151 typedef unsigned int IndexType;
152
154 enum {
156 tardim = Grid1Patch::dim,
157 grid1dim = Grid1Patch::dim,
159 tardimworld = Grid1Patch::dimworld,
160 grid1dimworld = Grid1Patch::dimworld
161 };
162
163
165 enum {
168 dimworld = ((int)Grid0Patch::dimworld > (int)Grid1Patch::dimworld) ? (int)Grid0Patch::dimworld : (int)Grid1Patch::dimworld
169
170 };
171
174 typedef typename PromotionTraits<typename Grid0View::ctype,
175 typename Grid1View::ctype>::PromotedType ctype;
176
178 typedef Dune::FieldVector<ctype, dimworld> Coords;
179
181 typedef typename Grid0View::Traits::template Codim<0>::Entity Grid0Element;
182
184 typedef typename Grid0View::Traits::template Codim<Grid0::dimension>::Entity Grid0Vertex;
185
187 typedef typename Grid1View::Traits::template Codim<0>::Entity Grid1Element;
188
190 typedef typename Grid1View::Traits::template Codim<Grid1::dimension>::Entity Grid1Vertex;
191
194 Grid0::dimension - Grid0Patch::codim,
195 Grid1::dimension - Grid1Patch::codim,
197
200
203
210
211private:
212
213 /* M E M B E R V A R I A B L E S */
214
216 const std::shared_ptr<const Grid0Patch> patch0_;
217
219 const std::shared_ptr<const Grid1Patch> patch1_;
220
222 const std::shared_ptr<Merger> merger_;
223
225 IndexType index__sz;
226
227#if HAVE_MPI
229 MPI_Comm mpicomm_;
230
232 PIndexSet patch0_is_;
233
235 PIndexSet patch1_is_;
236
238 Dune::RemoteIndices<PIndexSet> remoteIndices_;
239#endif // HAVE_MPI
240
243
245 mutable std::vector<IntersectionData> intersections_;
246
247protected:
248
265 void mergePatches(const std::vector<Dune::FieldVector<ctype,dimworld> >& patch0coords,
266 const std::vector<unsigned int>& patch0entities,
267 const std::vector<Dune::GeometryType>& patch0types,
268 const int patch0rank,
269 const std::vector<Dune::FieldVector<ctype,dimworld> >& patch1coords,
270 const std::vector<unsigned int>& patch1entities,
271 const std::vector<Dune::GeometryType>& patch1types,
272 const int patch1rank);
273
274
275 template<typename Extractor>
276 void extractGrid (const Extractor & extractor,
277 std::vector<Dune::FieldVector<ctype, dimworld> > & coords,
278 std::vector<unsigned int> & faces,
279 std::vector<Dune::GeometryType>& geometryTypes) const;
280
281public:
282
283 /* C O N S T R U C T O R S A N D D E S T R U C T O R S */
284
295 DUNE_DEPRECATED_MSG("Please use a std::shared_ptr for patches and merger")
296 GridGlue(const Grid0Patch& gp0, const Grid1Patch& gp1, Merger* merger);
297
308 GridGlue(const std::shared_ptr<const Grid0Patch> gp0, const std::shared_ptr<const Grid1Patch> gp1, const std::shared_ptr<Merger> merger);
309
310 /* G E T T E R S */
311
313 template<int P>
314 const typename GridGlueView<P0,P1,P>::Patch & patch() const
315 {
316 return GridGlueView<P0,P1,P>::patch(*this);
317 }
318
323 template<int P>
325 {
326 return GridGlueView<P0,P1,P>::patch(*this).gridView();
327 }
328
329
330 /* F U N C T I O N A L I T Y */
331
332 void build();
333
334 /* I N T E R S E C T I O N S A N D I N T E R S E C T I O N I T E R A T O R S */
335
342 template<int I>
347
348
355 template<int I>
357 {
358 return typename GridGlueView<P0,P1,I>::IntersectionIterator(this, index__sz);
359 }
360
361
373 template<class DataHandleImp, class DataTypeImp>
375 Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const
376 {
378 typedef typename DataHandle::DataType DataType;
379
380#if HAVE_MPI
381
382 if (mpicomm_ != MPI_COMM_SELF)
383 {
384 /*
385 * P A R A L L E L V E R S I O N
386 */
387 // setup communication interfaces
388 Dune::dinfo << "GridGlue: parallel communication" << std::endl;
389 typedef Dune::EnumItem <Dune::PartitionType, Dune::InteriorEntity> InteriorFlags;
390 typedef Dune::EnumItem <Dune::PartitionType, Dune::OverlapEntity> OverlapFlags;
391 typedef Dune::EnumRange <Dune::PartitionType, Dune::InteriorEntity, Dune::GhostEntity> AllFlags;
392 Dune::Interface interface;
393 assert(remoteIndices_.isSynced());
394 switch (iftype)
395 {
396 case Dune::InteriorBorder_InteriorBorder_Interface :
397 interface.build (remoteIndices_, InteriorFlags(), InteriorFlags() );
398 break;
399 case Dune::InteriorBorder_All_Interface :
400 if (dir == Dune::ForwardCommunication)
401 interface.build (remoteIndices_, InteriorFlags(), AllFlags() );
402 else
403 interface.build (remoteIndices_, AllFlags(), InteriorFlags() );
404 break;
405 case Dune::Overlap_OverlapFront_Interface :
406 interface.build (remoteIndices_, OverlapFlags(), OverlapFlags() );
407 break;
408 case Dune::Overlap_All_Interface :
409 if (dir == Dune::ForwardCommunication)
410 interface.build (remoteIndices_, OverlapFlags(), AllFlags() );
411 else
412 interface.build (remoteIndices_, AllFlags(), OverlapFlags() );
413 break;
414 case Dune::All_All_Interface :
415 interface.build (remoteIndices_, AllFlags(), AllFlags() );
416 break;
417 default :
418 DUNE_THROW(Dune::NotImplemented, "GridGlue::communicate for interface " << iftype << " not implemented");
419 }
420
421 // setup communication info (class needed to tunnel all info to the operator)
423 CommInfo commInfo;
424 commInfo.dir = dir;
425 commInfo.gridglue = this;
426 commInfo.data = &data;
427
428 // create communicator
429 Dune::BufferedCommunicator bComm ;
430 bComm.template build< CommInfo >(commInfo, commInfo, interface);
431
432 // do communication
433 // choose communication direction.
434 if (dir == Dune::ForwardCommunication)
435 bComm.forward< Dune::GridGlue::ForwardOperator >(commInfo, commInfo);
436 else
437 bComm.backward< Dune::GridGlue::BackwardOperator >(commInfo, commInfo);
438 }
439 else
440#endif // HAVE_MPI
441 {
442 /*
443 * S E Q U E N T I A L V E R S I O N
444 */
445 Dune::dinfo << "GridGlue: sequential fallback communication" << std::endl;
446
447 // get comm buffer size
448 int ssz = size() * 10; // times data per intersection
449 int rsz = size() * 10;
450
451 // allocate send/receive buffer
452 DataType* sendbuffer = new DataType[ssz];
453 DataType* receivebuffer = new DataType[rsz];
454
455 // iterators
456 Grid0IntersectionIterator rit = ibegin<0>();
457 Grid0IntersectionIterator ritend = iend<0>();
458
459 // gather
461 for (; rit != ritend; ++rit)
462 {
463 /*
464 we need to have to variants depending on the communication direction.
465 */
466 if (dir == Dune::ForwardCommunication)
467 {
468 /*
469 dir : Forward (grid0 -> grid1)
470 */
471 if (rit->self())
472 {
473 data.gather(gatherbuffer, rit->inside(), *rit);
474 }
475 }
476 else // (dir == Dune::BackwardCommunication)
477 {
478 /*
479 dir : Backward (grid1 -> grid0)
480 */
481 if (rit->neighbor())
482 {
483 data.gather(gatherbuffer, rit->outside(), rit->flip());
484 }
485 }
486 }
487
488 assert(ssz == rsz);
489 for (int i=0; i<ssz; i++)
490 receivebuffer[i] = sendbuffer[i];
491
492 // scatter
493 Dune::GridGlue::StreamingMessageBuffer<DataType> scatterbuffer(receivebuffer);
494 for (rit = ibegin<0>(); rit != ritend; ++rit)
495 {
496 /*
497 we need to have to variants depending on the communication direction.
498 */
499 if (dir == Dune::ForwardCommunication)
500 {
501 /*
502 dir : Forward (grid0 -> grid1)
503 */
504 if (rit->neighbor())
505 data.scatter(scatterbuffer, rit->outside(), rit->flip(),
506 data.size(*rit));
507 }
508 else // (dir == Dune::BackwardCommunication)
509 {
510 /*
511 dir : Backward (grid1 -> grid0)
512 */
513 if (rit->self())
514 data.scatter(scatterbuffer, rit->inside(), *rit,
515 data.size(*rit));
516 }
517 }
518
519 // cleanup pointers
520 delete[] sendbuffer;
521 delete[] receivebuffer;
522 }
523 }
524
525 /*
526 * @brief return an IndexSet mapping from Intersection to IndexType
527 */
529 {
530 return IndexSet(this);
531 }
532
533#if QUICKHACK_INDEX
534 // indexset size
535 size_t indexSet_size() const
536 {
537 return index__sz;
538 }
539
540#endif
541
543 {
544 return Intersection(this, & intersections_[i]);
545 }
546
547 size_t size() const
548 {
549 return index__sz;
550 }
551
552};
553
554} // end namespace GridGlue
555} // end namespace Dune
556
557#include "adapter/gridglue.cc"
558
562
564
565#endif // DUNE_GRIDGLUE_GRIDGLUE_HH
Describes the parallel communication interface class for Dune::GridGlue.
Model of the Intersection concept provided by GridGlue.
Implement iterators over GridGlue intersections.
Definition gridglue.hh:30
GridOrdering
Definition gridglue.hh:34
@ Target
Definition gridglue.hh:36
@ Domain
Definition gridglue.hh:35
sequential adapter to couple two grids at specified close together boundaries
Definition gridglue.hh:93
Grid0View::Traits::template Codim< 0 >::Entity Grid0Element
The type of the Grid0 elements.
Definition gridglue.hh:181
PromotionTraits< typenameGrid0View::ctype, typenameGrid1View::ctype >::PromotedType ctype
The type used for coordinates.
Definition gridglue.hh:175
Grid1View::Grid Grid1
Grid 1 type.
Definition gridglue.hh:145
Dune::FieldVector< ctype, dimworld > Coords
The type used for coordinate vectors.
Definition gridglue.hh:178
Intersection getIntersection(int i) const
Definition gridglue.hh:542
Dune::GridGlue::IntersectionIndexSet< P0, P1 > IndexSet
Type of remote intersection indexSet.
Definition gridglue.hh:202
unsigned int IndexType
Definition gridglue.hh:151
void mergePatches(const std::vector< Dune::FieldVector< ctype, dimworld > > &patch0coords, const std::vector< unsigned int > &patch0entities, const std::vector< Dune::GeometryType > &patch0types, const int patch0rank, const std::vector< Dune::FieldVector< ctype, dimworld > > &patch1coords, const std::vector< unsigned int > &patch1entities, const std::vector< Dune::GeometryType > &patch1types, const int patch1rank)
after building the merged grid the intersection can be updated through this method (for internal use)
Definition gridglue.cc:449
Dune::GridGlue::Intersection< P0, P1, 0, 1 > Intersection
Type of remote intersection objects.
Definition gridglue.hh:199
void communicate(Dune::GridGlue::CommDataHandle< DataHandleImp, DataTypeImp > &data, Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const
Communicate information on the MergedGrid of a GridGlue.
Definition gridglue.hh:374
@ domdim
Definition gridglue.hh:135
@ grid0dimworld
World dimension of the grid 0 extractor.
Definition gridglue.hh:137
@ grid0dim
Dimension of the grid 0 extractor.
Definition gridglue.hh:134
@ domdimworld
Definition gridglue.hh:138
Dune::GridGlue::IntersectionIterator< P0, P1, 1, 0 > Grid1IntersectionIterator
Definition gridglue.hh:209
P1::GridView Grid1View
GridView of grid 1 (aka target grid)
Definition gridglue.hh:142
P1 Grid1Patch
Coupling patch of grid 1.
Definition gridglue.hh:148
Grid0View::Grid Grid0
Grid 0 type.
Definition gridglue.hh:126
void build()
Definition gridglue.cc:183
@ tardimworld
World dimension of the grid 1 extractor.
Definition gridglue.hh:159
@ grid1dim
Definition gridglue.hh:157
@ tardim
Dimension of the grid 1 extractor.
Definition gridglue.hh:156
@ grid1dimworld
Definition gridglue.hh:160
void extractGrid(const Extractor &extractor, std::vector< Dune::FieldVector< ctype, dimworld > > &coords, std::vector< unsigned int > &faces, std::vector< Dune::GeometryType > &geometryTypes) const
Definition gridglue.cc:536
const GridGlueView< P0, P1, P >::Patch & patch() const
Definition gridglue.hh:314
GridGlueView< P0, P1, I >::IntersectionIterator iend() const
gets the (general) end-iterator for grid glue iterations
Definition gridglue.hh:356
Grid1View::Traits::template Codim< Grid1::dimension >::Entity Grid1Vertex
The type of the Grid1 vertices.
Definition gridglue.hh:190
const GridGlueView< P0, P1, P >::Patch::GridView & gridView() const
getter for the GridView of patch P
Definition gridglue.hh:324
P0 Grid0Patch
Coupling patch of grid 0.
Definition gridglue.hh:129
Grid1View::Traits::template Codim< 0 >::Entity Grid1Element
The type of the Grid1 elements.
Definition gridglue.hh:187
@ dimworld
export the world dimension : maximum of the two extractor world dimensions
Definition gridglue.hh:168
Dune::GridGlue::IntersectionIterator< P0, P1, 0, 1 > Grid0IntersectionIterator
Type of the iterator that iterates over remove intersections.
Definition gridglue.hh:207
GridGlueView< P0, P1, I >::IntersectionIterator ibegin() const
gets an iterator over all remote intersections in the merged grid between grid0 and grid1
Definition gridglue.hh:343
Dune::GridGlue::Merger< ctype, Grid0::dimension - Grid0Patch::codim, Grid1::dimension - Grid1Patch::codim, dimworld > Merger
Instance of a Merger.
Definition gridglue.hh:196
Grid0View::Traits::template Codim< Grid0::dimension >::Entity Grid0Vertex
The type of the Grid0 vertices.
Definition gridglue.hh:184
IndexSet indexSet() const
Definition gridglue.hh:528
size_t size() const
Definition gridglue.hh:547
P0::GridView Grid0View
GridView of grid 0 (aka domain grid)
Definition gridglue.hh:123
storage class for Dune::GridGlue::Intersection related data
Definition intersection.hh:31
The intersection of two entities of the two patches of a GridGlue.
Definition intersection.hh:371
Definition intersectioniterator.hh:23
Definition intersectionindexset.hh:18
Definition gridglue.hh:56
static const P0 & patch(const GridGlue< P0, P1 > &g)
Definition gridglue.hh:64
Dune::GridGlue::IntersectionIterator< P0, P1, 0, 1 > IntersectionIterator
Definition gridglue.hh:62
P0 Patch
Definition gridglue.hh:61
Patch::GridView::template Codim< 0 >::Entity GridElement
Definition gridglue.hh:63
Patch::GridView::template Codim< 0 >::Entity GridElement
Definition gridglue.hh:75
Dune::GridGlue::IntersectionIterator< P0, P1, 1, 0 > IntersectionIterator
Definition gridglue.hh:74
P1 Patch
Definition gridglue.hh:73
Definition gridgluecommunicate.hh:24
describes the features of a data handle for communication in parallel runs using the GridGlue::commun...
Definition gridgluecommunicate.hh:75
size_t size(RISType &i) const
Definition gridgluecommunicate.hh:90
void scatter(MessageBufferImp &buff, const EntityType &e, const RISType &i, size_t n)
Definition gridgluecommunicate.hh:116
void gather(MessageBufferImp &buff, const EntityType &e, const RISType &i) const
pack data from user to message buffer
Definition gridgluecommunicate.hh:102
Definition gridgluecommunicate.hh:139
forward gather scatter to user defined CommInfo class
Definition gridgluecommunicate.hh:192
collects all GridGlue data requried for communication
Definition gridgluecommunicate.hh:270
Dune::CommunicationDirection dir
Definition gridgluecommunicate.hh:286
::Dune::GridGlue::CommDataHandle< DataHandleImp, DataTypeImp > * data
Definition gridgluecommunicate.hh:280
const GridGlue * gridglue
Definition gridgluecommunicate.hh:279
Provides codimension-independent methods for grid extraction.
Definition extractor.hh:43
Abstract base for all classes that take extracted grids and build sets of intersections.
Definition merger.hh:91