dune-grid-glue  2.8.0
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 <memory>
14 #include <tuple>
15 #include <type_traits>
16 
17 #include <dune/common/deprecated.hh>
18 #include <dune/common/exceptions.hh>
19 #include <dune/common/iteratorfacades.hh>
20 #include <dune/common/promotiontraits.hh>
21 #include <dune/common/shared_ptr.hh>
22 #include <dune/common/stdstreams.hh>
23 
26 
27 #include <dune/common/parallel/mpitraits.hh>
28 #include <dune/common/parallel/mpicommunication.hh>
29 #include <dune/common/parallel/indexset.hh>
30 #include <dune/common/parallel/plocalindex.hh>
31 #include <dune/common/parallel/remoteindices.hh>
32 #include <dune/common/parallel/communicator.hh>
33 #include <dune/common/parallel/interface.hh>
34 
35 namespace Dune {
36 namespace GridGlue {
37 
38 // forward declarations
39 template<typename P0, typename P1>
40 class GridGlue;
41 
42 template<typename P0, typename P1>
43 class IntersectionData;
44 
45 template<typename P0, typename P1, int inside, int outside>
46 class Intersection;
47 
48 template<typename P0, typename P1, int inside, int outside>
50 
51 template<typename P0, typename P1>
53 
63 template<typename P0, typename P1>
64 class GridGlue
65 {
66 private:
67 
68  /* F R I E N D S */
69 
70  friend class IntersectionData<P0,P1>;
71  friend class Intersection<P0,P1,0,1>;
72  friend class Intersection<P0,P1,1,0>;
73  friend class IntersectionIterator<P0,P1,0,1>;
74  friend class IntersectionIterator<P0,P1,1,0>;
75  friend class IntersectionIndexSet<P0,P1>;
76 
77  /* P R I V A T E T Y P E S */
78 
80  typedef ::Dune::GridGlue::GlobalId GlobalId;
81 
83  typedef Dune::ParallelLocalIndex <Dune::PartitionType> LocalIndex;
84 
86  typedef Dune::ParallelIndexSet <GlobalId, LocalIndex> PIndexSet;
87 
88 public:
89 
90  /* P U B L I C T Y P E S A N D C O N S T A N T S */
91 
93  template<int side>
94  using GridPatch = std::conditional_t<side == 0, P0, std::conditional_t<side == 1, P1, void>>;
95 
97  template<int side>
99 
101  template<int side>
102  using Grid = typename GridView<side>::Grid;
103 
105  using Grid0View [[deprecated("please use GridView<0> instead")]] = GridView<0>;
106 
108  using Grid0 [[deprecated("please use Grid<0> instead")]] = Grid<0>;
109 
111  using Grid0Patch [[deprecated("please use GridPatch<0> instead")]] = GridPatch<0>;
112 
113  template<int side>
114  static constexpr auto griddim()
115  { return GridPatch<side>::dim; }
116 
117  template<int side>
118  static constexpr auto griddimworld()
119  { return GridPatch<side>::dimworld; }
120 
122  [[deprecated("please use griddim<0>() instead")]]
123  static constexpr auto grid0dim = griddim<0>();
124 
125  [[deprecated("please use griddim<0>() instead")]]
126  static constexpr auto domdim = griddim<0>();
127 
129  [[deprecated("please use griddimworld<0>() instead")]]
130  static constexpr auto grid0dimworld = griddimworld<0>();
131 
132  [[deprecated("please use griddimworld<0>() instead")]]
133  static constexpr auto domdimworld = griddimworld<0>();
134 
136  using Grid1View [[deprecated("please use GridView<0> instead")]] = GridView<1>;
137 
139  using Grid1 [[deprecated("please use Grid<1> instead")]] = Grid<1>;
140 
142  using Grid1Patch [[deprecated("please use GridPatch<1> instead")]] = GridPatch<1>;
143 
145  typedef unsigned int IndexType;
146 
148  [[deprecated("please use griddim<1>() instead")]]
149  static constexpr auto grid1dim = griddim<1>();
150 
151  [[deprecated("please use griddim<1>() instead")]]
152  static constexpr auto tardim = griddim<1>();
153 
155  [[deprecated("please use griddimworld<1>() instead")]]
156  static constexpr auto grid1dimworld = griddimworld<1>();
157 
158  [[deprecated("please use griddimworld<1>() instead")]]
159  static constexpr auto tardimworld = griddimworld<1>();
160 
164  static constexpr int dimworld = (int)griddimworld<0>() > (int)griddimworld<1>() ? (int)griddimworld<0>() : (int)griddimworld<1>();
165 
168  typedef typename PromotionTraits<typename GridView<0>::ctype,
169  typename GridView<1>::ctype>::PromotedType ctype;
170 
172  typedef Dune::FieldVector<ctype, dimworld> Coords;
173 
175  template<int side>
176  using GridElement = typename GridView<side>::Traits::template Codim<0>::Entity;
177 
179  template<int side>
180  using GridVertex = typename GridView<side>::Traits::template Codim<Grid<side>::dimension>::Entity;
181 
183  using Grid0Element [[deprecated("please use GridElement<0> instead")]] = GridElement<0>;
184 
186  using Grid0Vertex [[deprecated("please use GridVertex<0> instead")]] = GridVertex<0>;
187 
189  using Grid1Element [[deprecated("please use GridElement<1> instead")]] = GridElement<1>;
190 
192  using Grid1Vertex [[deprecated("please use GridVertex<1> instead")]] = GridVertex<1>;
193 
199 
202 
205 
207  template<int side>
208  using IntersectionIterator = Dune::GridGlue::IntersectionIterator<P0, P1, side, (side+1) % 2>;
209 
211  using Grid0IntersectionIterator [[deprecated("please use IntersectionIterator<0> instead")]] = IntersectionIterator<0>;
212 
214  using Grid1IntersectionIterator [[deprecated("please use IntersectionIterator<1> instead")]] = IntersectionIterator<1>;
215 
216 private:
217 
218  /* M E M B E R V A R I A B L E S */
219 
220  using GridPatches = std::tuple<
221  const std::shared_ptr< const GridPatch<0> >,
222  const std::shared_ptr< const GridPatch<1> >
223  >;
224 
225  const GridPatches patches_;
226 
228  const std::shared_ptr<Merger> merger_;
229 
231  IndexType index__sz = 0;
232 
233 #if HAVE_MPI
235  MPI_Comm mpicomm_;
236 
238  PIndexSet patch0_is_;
239 
241  PIndexSet patch1_is_;
242 
244  Dune::RemoteIndices<PIndexSet> remoteIndices_;
245 #endif // HAVE_MPI
246 
249 
251  mutable std::vector<IntersectionData> intersections_;
252 
253 protected:
254 
270  void mergePatches(const std::vector<Dune::FieldVector<ctype,dimworld> >& patch0coords,
271  const std::vector<unsigned int>& patch0entities,
272  const std::vector<Dune::GeometryType>& patch0types,
273  const int patch0rank,
274  const std::vector<Dune::FieldVector<ctype,dimworld> >& patch1coords,
275  const std::vector<unsigned int>& patch1entities,
276  const std::vector<Dune::GeometryType>& patch1types,
277  const int patch1rank);
278 
279 
280  template<typename Extractor>
281  void extractGrid (const Extractor & extractor,
282  std::vector<Dune::FieldVector<ctype, dimworld> > & coords,
283  std::vector<unsigned int> & faces,
284  std::vector<Dune::GeometryType>& geometryTypes) const;
285 
286 public:
287 
288  /* 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 */
289 
300  GridGlue(const std::shared_ptr< const GridPatch<0> >& gp0, const std::shared_ptr< const GridPatch<1> >& gp1, const std::shared_ptr<Merger>& merger);
301 
302  /* G E T T E R S */
303 
305  template<int P>
306  const GridPatch<P>& patch() const
307  {
308  return *std::get<P>(patches_);
309  }
310 
315  template<int P>
316  const GridView<P>& gridView() const
317  {
318  return std::get<P>(patches_)->gridView();
319  }
320 
321 
322  /* F U N C T I O N A L I T Y */
323 
324  void build();
325 
326  /* 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 */
327 
334  template<int I = 0>
336  {
337  return {this, 0};
338  }
339 
340 
347  template<int I = 0>
349  {
350  return {this, index__sz};
351  }
352 
353 
365  template<class DataHandleImp, class DataTypeImp>
367  Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const;
368 
369  /*
370  * @brief return an IndexSet mapping from Intersection to IndexType
371  */
373  {
374  return IndexSet(this);
375  }
376 
377 #if QUICKHACK_INDEX
378  // indexset size
379  size_t indexSet_size() const
380  {
381  return index__sz;
382  }
383 
384 #endif
385 
387  {
388  return Intersection(this, & intersections_[i]);
389  }
390 
391  size_t size() const
392  {
393  return index__sz;
394  }
395 
396 };
397 
398 } // end namespace GridGlue
399 } // end namespace Dune
400 
402 
403 #include "adapter/gridglue.cc"
404 
405 #include "adapter/intersection.hh"
408 
409 #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:35
sequential adapter to couple two grids at specified close together boundaries
Definition: gridglue.hh:52
IntersectionIterator< I > ibegin() const
gets an iterator over all remote intersections in the merged grid between grid0 and grid1
Definition: gridglue.hh:335
Dune::FieldVector< ctype, dimworld > Coords
The type used for coordinate vectors.
Definition: gridglue.hh:172
Intersection getIntersection(int i) const
Definition: gridglue.hh:386
GridVertex< 1 > Grid1Vertex
The type of the Grid1 vertices.
Definition: gridglue.hh:192
Dune::GridGlue::IntersectionIndexSet< P0, P1 > IndexSet
Type of remote intersection indexSet.
Definition: gridglue.hh:204
unsigned int IndexType
Definition: gridglue.hh:145
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:177
Dune::GridGlue::Intersection< P0, P1, 0, 1 > Intersection
Type of remote intersection objects.
Definition: gridglue.hh:201
GridElement< 0 > Grid0Element
The type of the Grid0 elements.
Definition: gridglue.hh:183
static constexpr auto griddimworld()
Definition: gridglue.hh:118
Grid< 1 > Grid1
Grid 1 type.
Definition: gridglue.hh:139
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.cc:298
GridView< 0 > Grid0View
GridView of grid 0 (aka domain grid)
Definition: gridglue.hh:105
static constexpr int dimworld
export the world dimension This is the maximum of the extractors' world dimensions.
Definition: gridglue.hh:164
IntersectionIterator< I > iend() const
gets the (general) end-iterator for grid glue iterations
Definition: gridglue.hh:348
const GridPatch< P > & patch() const
Definition: gridglue.hh:306
GridGlue(const std::shared_ptr< const GridPatch< 0 > > &gp0, const std::shared_ptr< const GridPatch< 1 > > &gp1, const std::shared_ptr< Merger > &merger)
constructor
Definition: gridglue.cc:19
Dune::GridGlue::Merger< ctype, Grid< 0 >::dimension - GridPatch< 0 >::codim, Grid< 1 >::dimension - GridPatch< 1 >::codim, dimworld > Merger
Instance of a Merger.
Definition: gridglue.hh:198
GridView< 1 > Grid1View
GridView of grid 1 (aka target grid)
Definition: gridglue.hh:136
static constexpr auto domdimworld
Definition: gridglue.hh:133
PromotionTraits< typename GridView< 0 >::ctype, typename GridView< 1 >::ctype >::PromotedType ctype
The type used for coordinates.
Definition: gridglue.hh:169
void build()
Definition: gridglue.cc:34
GridPatch< 1 > Grid1Patch
Coupling patch of grid 1.
Definition: gridglue.hh:142
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:263
static constexpr auto grid0dim
dimension of the grid 0 extractor
Definition: gridglue.hh:123
static constexpr auto grid1dim
dimension of the grid 1 extractor
Definition: gridglue.hh:149
static constexpr auto griddim()
Definition: gridglue.hh:114
GridPatch< 0 > Grid0Patch
Coupling patch of grid 0.
Definition: gridglue.hh:111
Grid< 0 > Grid0
Grid 0 type.
Definition: gridglue.hh:108
static constexpr auto grid1dimworld
world dimension of the grid 1 extractor
Definition: gridglue.hh:156
const GridView< P > & gridView() const
getter for the GridView of patch P
Definition: gridglue.hh:316
static constexpr auto domdim
Definition: gridglue.hh:126
static constexpr auto grid0dimworld
world dimension of the grid 0 extractor
Definition: gridglue.hh:130
GridVertex< 0 > Grid0Vertex
The type of the Grid0 vertices.
Definition: gridglue.hh:186
typename GridPatch< side >::GridView GridView
Definition: gridglue.hh:98
static constexpr auto tardim
Definition: gridglue.hh:152
std::conditional_t< side==0, P0, std::conditional_t< side==1, P1, void > > GridPatch
Definition: gridglue.hh:94
typename GridView< side >::Traits::template Codim< Grid< side >::dimension >::Entity GridVertex
type of grid vertices on side side
Definition: gridglue.hh:180
typename GridView< side >::Traits::template Codim< 0 >::Entity GridElement
type of grid elements on side side
Definition: gridglue.hh:176
IndexSet indexSet() const
Definition: gridglue.hh:372
size_t size() const
Definition: gridglue.hh:391
static constexpr auto tardimworld
Definition: gridglue.hh:159
GridElement< 1 > Grid1Element
The type of the Grid1 elements.
Definition: gridglue.hh:189
typename GridView< side >::Grid Grid
Definition: gridglue.hh:102
storage class for Dune::GridGlue::Intersection related data
Definition: intersection.hh:36
The intersection of two entities of the two patches of a GridGlue.
Definition: intersection.hh:259
Definition: intersectioniterator.hh:23
Definition: intersectionindexset.hh:18
Definition: gridgluecommunicate.hh:24
describes the features of a data handle for communication in parallel runs using the GridGlue::commun...
Definition: gridgluecommunicate.hh:75
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:44
Abstract base for all classes that take extracted grids and build sets of intersections.
Definition: merger.hh:25