dune-grid-glue  2.9
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:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-dune-grid-glue-exception
12 #ifndef DUNE_GRIDGLUE_GRIDGLUE_HH
13 #define DUNE_GRIDGLUE_GRIDGLUE_HH
14 
15 #include <memory>
16 #include <tuple>
17 #include <type_traits>
18 
19 #include <dune/common/deprecated.hh>
20 #include <dune/common/exceptions.hh>
21 #include <dune/common/iteratorfacades.hh>
22 #include <dune/common/promotiontraits.hh>
23 #include <dune/common/shared_ptr.hh>
24 #include <dune/common/stdstreams.hh>
25 
28 
29 #include <dune/common/parallel/mpitraits.hh>
30 #include <dune/common/parallel/mpicommunication.hh>
31 #include <dune/common/parallel/indexset.hh>
32 #include <dune/common/parallel/plocalindex.hh>
33 #include <dune/common/parallel/remoteindices.hh>
34 #include <dune/common/parallel/communicator.hh>
35 #include <dune/common/parallel/interface.hh>
36 
37 namespace Dune {
38 namespace GridGlue {
39 
40 // forward declarations
41 template<typename P0, typename P1>
42 class GridGlue;
43 
44 template<typename P0, typename P1>
45 class IntersectionData;
46 
47 template<typename P0, typename P1, int inside, int outside>
48 class Intersection;
49 
50 template<typename P0, typename P1, int inside, int outside>
52 
53 template<typename P0, typename P1>
55 
65 template<typename P0, typename P1>
66 class GridGlue
67 {
68 private:
69 
70  /* F R I E N D S */
71 
72  friend class IntersectionData<P0,P1>;
73  friend class Intersection<P0,P1,0,1>;
74  friend class Intersection<P0,P1,1,0>;
75  friend class IntersectionIterator<P0,P1,0,1>;
76  friend class IntersectionIterator<P0,P1,1,0>;
77  friend class IntersectionIndexSet<P0,P1>;
78 
79  /* P R I V A T E T Y P E S */
80 
82  typedef ::Dune::GridGlue::GlobalId GlobalId;
83 
85  typedef Dune::ParallelLocalIndex <Dune::PartitionType> LocalIndex;
86 
88  typedef Dune::ParallelIndexSet <GlobalId, LocalIndex> PIndexSet;
89 
90 public:
91 
92  /* P U B L I C T Y P E S A N D C O N S T A N T S */
93 
95  template<int side>
96  using GridPatch = std::conditional_t<side == 0, P0, std::conditional_t<side == 1, P1, void>>;
97 
99  template<int side>
101 
103  template<int side>
104  using Grid = typename GridView<side>::Grid;
105 
107  using Grid0View [[deprecated("please use GridView<0> instead")]] = GridView<0>;
108 
110  using Grid0 [[deprecated("please use Grid<0> instead")]] = Grid<0>;
111 
113  using Grid0Patch [[deprecated("please use GridPatch<0> instead")]] = GridPatch<0>;
114 
115  template<int side>
116  static constexpr auto griddim()
117  { return GridPatch<side>::dim; }
118 
119  template<int side>
120  static constexpr auto griddimworld()
121  { return GridPatch<side>::dimworld; }
122 
124  [[deprecated("please use griddim<0>() instead")]]
125  static constexpr auto grid0dim = griddim<0>();
126 
127  [[deprecated("please use griddim<0>() instead")]]
128  static constexpr auto domdim = griddim<0>();
129 
131  [[deprecated("please use griddimworld<0>() instead")]]
132  static constexpr auto grid0dimworld = griddimworld<0>();
133 
134  [[deprecated("please use griddimworld<0>() instead")]]
135  static constexpr auto domdimworld = griddimworld<0>();
136 
138  using Grid1View [[deprecated("please use GridView<0> instead")]] = GridView<1>;
139 
141  using Grid1 [[deprecated("please use Grid<1> instead")]] = Grid<1>;
142 
144  using Grid1Patch [[deprecated("please use GridPatch<1> instead")]] = GridPatch<1>;
145 
147  typedef unsigned int IndexType;
148 
150  [[deprecated("please use griddim<1>() instead")]]
151  static constexpr auto grid1dim = griddim<1>();
152 
153  [[deprecated("please use griddim<1>() instead")]]
154  static constexpr auto tardim = griddim<1>();
155 
157  [[deprecated("please use griddimworld<1>() instead")]]
158  static constexpr auto grid1dimworld = griddimworld<1>();
159 
160  [[deprecated("please use griddimworld<1>() instead")]]
161  static constexpr auto tardimworld = griddimworld<1>();
162 
166  static constexpr int dimworld = (int)griddimworld<0>() > (int)griddimworld<1>() ? (int)griddimworld<0>() : (int)griddimworld<1>();
167 
170  typedef typename PromotionTraits<typename GridView<0>::ctype,
171  typename GridView<1>::ctype>::PromotedType ctype;
172 
174  typedef Dune::FieldVector<ctype, dimworld> Coords;
175 
177  template<int side>
178  using GridElement = typename GridView<side>::Traits::template Codim<0>::Entity;
179 
181  template<int side>
182  using GridVertex = typename GridView<side>::Traits::template Codim<Grid<side>::dimension>::Entity;
183 
185  using Grid0Element [[deprecated("please use GridElement<0> instead")]] = GridElement<0>;
186 
188  using Grid0Vertex [[deprecated("please use GridVertex<0> instead")]] = GridVertex<0>;
189 
191  using Grid1Element [[deprecated("please use GridElement<1> instead")]] = GridElement<1>;
192 
194  using Grid1Vertex [[deprecated("please use GridVertex<1> instead")]] = GridVertex<1>;
195 
201 
204 
207 
209  template<int side>
210  using IntersectionIterator = Dune::GridGlue::IntersectionIterator<P0, P1, side, (side+1) % 2>;
211 
213  using Grid0IntersectionIterator [[deprecated("please use IntersectionIterator<0> instead")]] = IntersectionIterator<0>;
214 
216  using Grid1IntersectionIterator [[deprecated("please use IntersectionIterator<1> instead")]] = IntersectionIterator<1>;
217 
218 private:
219 
220  /* M E M B E R V A R I A B L E S */
221 
222  using GridPatches = std::tuple<
223  const std::shared_ptr< const GridPatch<0> >,
224  const std::shared_ptr< const GridPatch<1> >
225  >;
226 
227  const GridPatches patches_;
228 
230  const std::shared_ptr<Merger> merger_;
231 
233  IndexType index__sz = 0;
234 
235 #if HAVE_MPI
237  MPI_Comm mpicomm_;
238 
240  PIndexSet patch0_is_;
241 
243  PIndexSet patch1_is_;
244 
246  Dune::RemoteIndices<PIndexSet> remoteIndices_;
247 #endif // HAVE_MPI
248 
251 
253  mutable std::vector<IntersectionData> intersections_;
254 
255 protected:
256 
272  void mergePatches(const std::vector<Dune::FieldVector<ctype,dimworld> >& patch0coords,
273  const std::vector<unsigned int>& patch0entities,
274  const std::vector<Dune::GeometryType>& patch0types,
275  const int patch0rank,
276  const std::vector<Dune::FieldVector<ctype,dimworld> >& patch1coords,
277  const std::vector<unsigned int>& patch1entities,
278  const std::vector<Dune::GeometryType>& patch1types,
279  const int patch1rank);
280 
281 
282  template<typename Extractor>
283  void extractGrid (const Extractor & extractor,
284  std::vector<Dune::FieldVector<ctype, dimworld> > & coords,
285  std::vector<unsigned int> & faces,
286  std::vector<Dune::GeometryType>& geometryTypes) const;
287 
288 public:
289 
290  /* 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 */
291 
302  GridGlue(const std::shared_ptr< const GridPatch<0> >& gp0, const std::shared_ptr< const GridPatch<1> >& gp1, const std::shared_ptr<Merger>& merger);
303 
304  /* G E T T E R S */
305 
307  template<int P>
308  const GridPatch<P>& patch() const
309  {
310  return *std::get<P>(patches_);
311  }
312 
317  template<int P>
318  const GridView<P>& gridView() const
319  {
320  return std::get<P>(patches_)->gridView();
321  }
322 
323 
324  /* F U N C T I O N A L I T Y */
325 
326  void build();
327 
328  /* 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 */
329 
336  template<int I = 0>
338  {
339  return {this, 0};
340  }
341 
342 
349  template<int I = 0>
351  {
352  return {this, index__sz};
353  }
354 
355 
367  template<class DataHandleImp, class DataTypeImp>
369  Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const;
370 
371  /*
372  * @brief return an IndexSet mapping from Intersection to IndexType
373  */
375  {
376  return IndexSet(this);
377  }
378 
379 #if QUICKHACK_INDEX
380  // indexset size
381  size_t indexSet_size() const
382  {
383  return index__sz;
384  }
385 
386 #endif
387 
389  {
390  return Intersection(this, & intersections_[i]);
391  }
392 
393  size_t size() const
394  {
395  return index__sz;
396  }
397 
398 };
399 
400 } // end namespace GridGlue
401 } // end namespace Dune
402 
404 
405 #include "adapter/gridglue.cc"
406 
407 #include "adapter/intersection.hh"
410 
411 #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:37
sequential adapter to couple two grids at specified close together boundaries
Definition: gridglue.hh:54
IntersectionIterator< I > ibegin() const
gets an iterator over all remote intersections in the merged grid between grid0 and grid1
Definition: gridglue.hh:337
Dune::FieldVector< ctype, dimworld > Coords
The type used for coordinate vectors.
Definition: gridglue.hh:174
Intersection getIntersection(int i) const
Definition: gridglue.hh:388
GridVertex< 1 > Grid1Vertex
The type of the Grid1 vertices.
Definition: gridglue.hh:194
Dune::GridGlue::IntersectionIndexSet< P0, P1 > IndexSet
Type of remote intersection indexSet.
Definition: gridglue.hh:206
unsigned int IndexType
Definition: gridglue.hh:147
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:179
Dune::GridGlue::Intersection< P0, P1, 0, 1 > Intersection
Type of remote intersection objects.
Definition: gridglue.hh:203
GridElement< 0 > Grid0Element
The type of the Grid0 elements.
Definition: gridglue.hh:185
static constexpr auto griddimworld()
Definition: gridglue.hh:120
Grid< 1 > Grid1
Grid 1 type.
Definition: gridglue.hh:141
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:300
GridView< 0 > Grid0View
GridView of grid 0 (aka domain grid)
Definition: gridglue.hh:107
static constexpr int dimworld
export the world dimension This is the maximum of the extractors' world dimensions.
Definition: gridglue.hh:166
IntersectionIterator< I > iend() const
gets the (general) end-iterator for grid glue iterations
Definition: gridglue.hh:350
const GridPatch< P > & patch() const
Definition: gridglue.hh:308
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:21
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:200
GridView< 1 > Grid1View
GridView of grid 1 (aka target grid)
Definition: gridglue.hh:138
static constexpr auto domdimworld
Definition: gridglue.hh:135
PromotionTraits< typename GridView< 0 >::ctype, typename GridView< 1 >::ctype >::PromotedType ctype
The type used for coordinates.
Definition: gridglue.hh:171
void build()
Definition: gridglue.cc:36
GridPatch< 1 > Grid1Patch
Coupling patch of grid 1.
Definition: gridglue.hh:144
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:265
static constexpr auto grid0dim
dimension of the grid 0 extractor
Definition: gridglue.hh:125
static constexpr auto grid1dim
dimension of the grid 1 extractor
Definition: gridglue.hh:151
static constexpr auto griddim()
Definition: gridglue.hh:116
GridPatch< 0 > Grid0Patch
Coupling patch of grid 0.
Definition: gridglue.hh:113
Grid< 0 > Grid0
Grid 0 type.
Definition: gridglue.hh:110
static constexpr auto grid1dimworld
world dimension of the grid 1 extractor
Definition: gridglue.hh:158
const GridView< P > & gridView() const
getter for the GridView of patch P
Definition: gridglue.hh:318
static constexpr auto domdim
Definition: gridglue.hh:128
static constexpr auto grid0dimworld
world dimension of the grid 0 extractor
Definition: gridglue.hh:132
GridVertex< 0 > Grid0Vertex
The type of the Grid0 vertices.
Definition: gridglue.hh:188
typename GridPatch< side >::GridView GridView
Definition: gridglue.hh:100
static constexpr auto tardim
Definition: gridglue.hh:154
std::conditional_t< side==0, P0, std::conditional_t< side==1, P1, void > > GridPatch
Definition: gridglue.hh:96
typename GridView< side >::Traits::template Codim< Grid< side >::dimension >::Entity GridVertex
type of grid vertices on side side
Definition: gridglue.hh:182
typename GridView< side >::Traits::template Codim< 0 >::Entity GridElement
type of grid elements on side side
Definition: gridglue.hh:178
IndexSet indexSet() const
Definition: gridglue.hh:374
size_t size() const
Definition: gridglue.hh:393
static constexpr auto tardimworld
Definition: gridglue.hh:161
GridElement< 1 > Grid1Element
The type of the Grid1 elements.
Definition: gridglue.hh:191
typename GridView< side >::Grid Grid
Definition: gridglue.hh:104
storage class for Dune::GridGlue::Intersection related data
Definition: intersection.hh:38
The intersection of two entities of the two patches of a GridGlue.
Definition: intersection.hh:261
Definition: intersectioniterator.hh:25
Definition: intersectionindexset.hh:20
Definition: gridgluecommunicate.hh:26
describes the features of a data handle for communication in parallel runs using the GridGlue::commun...
Definition: gridgluecommunicate.hh:77
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:46
Abstract base for all classes that take extracted grids and build sets of intersections.
Definition: merger.hh:27