dune-grid-glue  2.3.0
merger.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 #ifndef DUNE_GRIDGLUE_MERGING_MERGER_HH
4 #define DUNE_GRIDGLUE_MERGING_MERGER_HH
5 
6 #include <vector>
7 
8 #include <dune/common/fvector.hh>
9 #include <dune/geometry/type.hh>
10 
11 // forward declaration
12 template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
13 class Merger;
14 
15 namespace {
16 
17  // forward calls to the (grid2/grid1)-calls depending on the grid number (0/1)
18  template <class ctype, int grid1Dim, int grid2Dim, int dimworld, int n>
19  struct MergerGridPolicy;
20 
21  template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
22  struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 0>
23  {
25 
27  typedef Dune::FieldVector<ctype, grid1Dim> GridCoords;
28 
29  static
30  unsigned int parents(const Parent & m, unsigned int idx)
31  {
32  return m.grid1Parents(idx);
33  }
34 
35  static
36  unsigned int parent(const Parent & m, unsigned int idx, unsigned int parId = 0)
37  {
38  return m.grid1Parent(idx, parId);
39  }
40 
41  static
42  GridCoords parentLocal(const Parent & m, unsigned int idx, unsigned int corner, unsigned int parId = 0)
43  {
44  return m.grid1ParentLocal(idx, corner, parId);
45  }
46 
47  };
48 
49  template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
50  struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 1>
51  {
53 
55  typedef Dune::FieldVector<ctype, grid2Dim> GridCoords;
56 
57  static
58  unsigned int parents(const Parent & m, unsigned int idx)
59  {
60  return m.grid2Parents(idx);
61  }
62 
63  static
64  unsigned int parent(const Parent & m, unsigned int idx, unsigned int parId = 0)
65  {
66  return m.grid2Parent(idx, parId);
67  }
68 
69  static
70  GridCoords parentLocal(const Parent & m, unsigned int idx, unsigned int corner, unsigned int parId = 0)
71  {
72  return m.grid2ParentLocal(idx, corner, parId);
73  }
74 
75  };
76 
77 } // end empty namespace
78 
86 template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
87 class Merger
88 {
89 
90  // the policy class get's access to the Merger
91  friend struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 0>;
92  friend struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 1>;
93 
94 public:
95 
97  typedef Dune::FieldVector<ctype, grid1Dim> Grid1Coords;
98 
100  typedef Dune::FieldVector<ctype, grid2Dim> Grid2Coords;
101 
103  typedef Dune::FieldVector<ctype, dimworld> WorldCoords;
104 
105  template<int n>
106  struct GridTraits
107  {
109  typedef MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, n> Policy;
111  typedef typename MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, n>::GridCoords Coords;
112  };
113 
127  virtual void build(const std::vector<Dune::FieldVector<ctype,dimworld> >& grid1_coords,
128  const std::vector<unsigned int>& grid1_elements,
129  const std::vector<Dune::GeometryType>& grid1_element_types,
130  const std::vector<Dune::FieldVector<ctype,dimworld> >& grid2_coords,
131  const std::vector<unsigned int>& grid2_elements,
132  const std::vector<Dune::GeometryType>& grid2_element_types) = 0;
133 
137  virtual unsigned int nSimplices() const = 0;
138 
139  virtual void clear() = 0;
140 
144  template<int n>
145  unsigned int parents(unsigned int idx) const {
146  return GridTraits<n>::Policy::parents(*this, idx);
147  }
148 
155  template<int n>
156  unsigned int parent(unsigned int idx, unsigned int parId = 0) const
157  {
158  return GridTraits<n>::Policy::parent(*this, idx, parId);
159  }
160 
168  template<int n>
169  bool simplexRefined(unsigned int idx, std::vector<unsigned int>& indices) const
170  {
171  return GridTraits<n>::Policy::simplexRefined(*this, idx, indices);
172  }
173 
182  template<int n>
183  typename GridTraits<n>::Coords parentLocal(unsigned int idx, unsigned int corner, unsigned int parId = 0) const
184  {
185  return GridTraits<n>::Policy::parentLocal(*this, idx, corner, parId);
186  }
187 
192  unsigned int counter;
193 
194 
195 private:
196 
197  virtual unsigned int grid1Parents(unsigned int idx) const = 0;
198 
199  virtual unsigned int grid2Parents(unsigned int idx) const = 0;
200 
206  virtual unsigned int grid1Parent(unsigned int idx, unsigned int parId = 0) const = 0;
207 
213  virtual unsigned int grid2Parent(unsigned int idx, unsigned int parId = 0) const = 0;
214 
222  virtual Grid1Coords grid1ParentLocal(unsigned int idx, unsigned int corner, unsigned int parId = 0) const = 0;
223 
231  virtual Grid2Coords grid2ParentLocal(unsigned int idx, unsigned int corner, unsigned int parId = 0) const = 0;
232 
233 };
234 
235 #endif
Definition: merger.hh:106
Dune::FieldVector< ctype, grid2Dim > Grid2Coords
the local coordinate type for the grid2 coordinates
Definition: merger.hh:100
unsigned int parent(unsigned int idx, unsigned int parId=0) const
get index of grid-n's parent simplex for given merged grid simplex
Definition: merger.hh:156
GridTraits< n >::Coords parentLocal(unsigned int idx, unsigned int corner, unsigned int parId=0) const
get the grid-n parent's simplex local coordinates for a particular merged grid simplex corner (parent...
Definition: merger.hh:183
bool simplexRefined(unsigned int idx, std::vector< unsigned int > &indices) const
get the merged grid simplices refining a given grid-n simplex
Definition: merger.hh:169
virtual void build(const std::vector< Dune::FieldVector< ctype, dimworld > > &grid1_coords, const std::vector< unsigned int > &grid1_elements, const std::vector< Dune::GeometryType > &grid1_element_types, const std::vector< Dune::FieldVector< ctype, dimworld > > &grid2_coords, const std::vector< unsigned int > &grid2_elements, const std::vector< Dune::GeometryType > &grid2_element_types)=0
builds the merged grid
unsigned int parents(unsigned int idx) const
Definition: merger.hh:145
MergerGridPolicy< ctype, grid1Dim, grid2Dim, dimworld, n > Policy
the policy class for this grid number
Definition: merger.hh:109
Abstract base for all classes that take extracted grids and build sets of intersections.
Definition: merger.hh:13
unsigned int counter
Counts the number of times the computeIntersection method has been called.
Definition: merger.hh:192
MergerGridPolicy< ctype, grid1Dim, grid2Dim, dimworld, n >::GridCoords Coords
the local coordinate type for the grid-n coordinates
Definition: merger.hh:111
Dune::FieldVector< ctype, dimworld > WorldCoords
the coordinate type used in this interface
Definition: merger.hh:103
virtual void clear()=0
Dune::FieldVector< ctype, grid1Dim > Grid1Coords
the local coordinate type for the grid1 coordinates
Definition: merger.hh:97
virtual unsigned int nSimplices() const =0
get the number of simplices in the merged grid The indices are then in 0..nSimplices()-1 ...