dune-grid-glue 2.5-git
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
11namespace Dune {
12namespace GridGlue {
13
14// forward declaration
15template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
16class Merger;
17
18namespace {
19
20 // forward calls to the (grid2/grid1)-calls depending on the grid number (0/1)
21 template <class ctype, int grid1Dim, int grid2Dim, int dimworld, int n>
22 struct MergerGridPolicy;
23
24 template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
25 struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 0>
26 {
27 typedef Merger<ctype, grid1Dim, grid2Dim, dimworld> Parent;
28
30 typedef Dune::FieldVector<ctype, grid1Dim> GridCoords;
31
32 static
33 unsigned int parents(const Parent & m, unsigned int idx)
34 {
35 return m.grid1Parents(idx);
36 }
37
38 static
39 unsigned int parent(const Parent & m, unsigned int idx, unsigned int parId = 0)
40 {
41 return m.grid1Parent(idx, parId);
42 }
43
44 static
45 GridCoords parentLocal(const Parent & m, unsigned int idx, unsigned int corner, unsigned int parId = 0)
46 {
47 return m.grid1ParentLocal(idx, corner, parId);
48 }
49
50 };
51
52 template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
53 struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 1>
54 {
55 typedef Merger<ctype, grid1Dim, grid2Dim, dimworld> Parent;
56
58 typedef Dune::FieldVector<ctype, grid2Dim> GridCoords;
59
60 static
61 unsigned int parents(const Parent & m, unsigned int idx)
62 {
63 return m.grid2Parents(idx);
64 }
65
66 static
67 unsigned int parent(const Parent & m, unsigned int idx, unsigned int parId = 0)
68 {
69 return m.grid2Parent(idx, parId);
70 }
71
72 static
73 GridCoords parentLocal(const Parent & m, unsigned int idx, unsigned int corner, unsigned int parId = 0)
74 {
75 return m.grid2ParentLocal(idx, corner, parId);
76 }
77
78 };
79
80} // end empty namespace
81
89template <class ctype, int grid1Dim, int grid2Dim, int dimworld>
90class Merger
91{
92
93 // the policy class get's access to the Merger
94 friend struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 0>;
95 friend struct MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, 1>;
96
97public:
98
100 typedef Dune::FieldVector<ctype, grid1Dim> Grid1Coords;
101
103 typedef Dune::FieldVector<ctype, grid2Dim> Grid2Coords;
104
106 typedef Dune::FieldVector<ctype, dimworld> WorldCoords;
107
108 template<int n>
110 {
112 typedef MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, n> Policy;
114 typedef typename MergerGridPolicy<ctype, grid1Dim, grid2Dim, dimworld, n>::GridCoords Coords;
115 };
116
130 virtual void build(const std::vector<Dune::FieldVector<ctype,dimworld> >& grid1_coords,
131 const std::vector<unsigned int>& grid1_elements,
132 const std::vector<Dune::GeometryType>& grid1_element_types,
133 const std::vector<Dune::FieldVector<ctype,dimworld> >& grid2_coords,
134 const std::vector<unsigned int>& grid2_elements,
135 const std::vector<Dune::GeometryType>& grid2_element_types) = 0;
136
140 virtual unsigned int nSimplices() const = 0;
141
142 virtual void clear() = 0;
143
147 template<int n>
148 unsigned int parents(unsigned int idx) const {
149 return GridTraits<n>::Policy::parents(*this, idx);
150 }
151
158 template<int n>
159 unsigned int parent(unsigned int idx, unsigned int parId = 0) const
160 {
161 return GridTraits<n>::Policy::parent(*this, idx, parId);
162 }
163
171 template<int n>
172 bool simplexRefined(unsigned int idx, std::vector<unsigned int>& indices) const
173 {
174 return GridTraits<n>::Policy::simplexRefined(*this, idx, indices);
175 }
176
185 template<int n>
186 typename GridTraits<n>::Coords parentLocal(unsigned int idx, unsigned int corner, unsigned int parId = 0) const
187 {
188 return GridTraits<n>::Policy::parentLocal(*this, idx, corner, parId);
189 }
190
195 unsigned int counter;
196
197
198private:
199
200 virtual unsigned int grid1Parents(unsigned int idx) const = 0;
201
202 virtual unsigned int grid2Parents(unsigned int idx) const = 0;
203
209 virtual unsigned int grid1Parent(unsigned int idx, unsigned int parId = 0) const = 0;
210
216 virtual unsigned int grid2Parent(unsigned int idx, unsigned int parId = 0) const = 0;
217
225 virtual Grid1Coords grid1ParentLocal(unsigned int idx, unsigned int corner, unsigned int parId = 0) const = 0;
226
234 virtual Grid2Coords grid2ParentLocal(unsigned int idx, unsigned int corner, unsigned int parId = 0) const = 0;
235
236};
237
238} /* namespace GridGlue */
239} /* namespace Dune */
240
241#endif
Definition gridglue.hh:30
Abstract base for all classes that take extracted grids and build sets of intersections.
Definition merger.hh:91
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:159
virtual void clear()=0
Dune::FieldVector< ctype, dimworld > WorldCoords
the coordinate type used in this interface
Definition merger.hh:106
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:186
Dune::FieldVector< ctype, grid1Dim > Grid1Coords
the local coordinate type for the grid1 coordinates
Definition merger.hh:100
unsigned int counter
Counts the number of times the computeIntersection method has been called.
Definition merger.hh:195
virtual unsigned int nSimplices() const =0
get the number of simplices in the merged grid The indices are then in 0..nSimplices()-1
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
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:172
unsigned int parents(unsigned int idx) const
Definition merger.hh:148
Dune::FieldVector< ctype, grid2Dim > Grid2Coords
the local coordinate type for the grid2 coordinates
Definition merger.hh:103
Definition merger.hh:110
MergerGridPolicy< ctype, grid1Dim, grid2Dim, dimworld, n > Policy
the policy class for this grid number
Definition merger.hh:112
MergerGridPolicy< ctype, grid1Dim, grid2Dim, dimworld, n >::GridCoords Coords
the local coordinate type for the grid-n coordinates
Definition merger.hh:114