dune-grid-glue  2.9
intersectionlist.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-dune-grid-glue-exception
3 #ifndef DUNE_GRIDGLUE_MERGING_INTERSECTIONLIST_HH
4 #define DUNE_GRIDGLUE_MERGING_INTERSECTIONLIST_HH 1
5 
6 #include <array>
7 #include <type_traits>
8 #include <utility>
9 #include <vector>
10 
11 #include <dune/common/fvector.hh>
12 
13 namespace Dune {
14 namespace GridGlue {
15 
20 template<typename L0, typename L1>
22 {
23 public:
24 
28  using Local0 = L0;
29 
33  using Local1 = L1;
34 
38  using Index = unsigned int;
39 
43  virtual std::size_t size() const = 0;
44 
50  virtual std::size_t parents0(Index intersection) const = 0;
51 
57  virtual std::size_t parents1(Index intersection) const = 0;
58 
65  virtual Index parent0(Index intersection, unsigned index) const = 0;
66 
73  virtual Index parent1(Index intersection, unsigned index) const = 0;
74 
82  virtual Local0 corner0(Index intersection, unsigned corner, unsigned index) const = 0;
83 
91  virtual Local1 corner1(Index intersection, unsigned corner, unsigned index) const = 0;
92 };
93 
94 namespace Impl {
95 
96 template<typename P, int I>
97 struct IntersectionListLocal
98 {};
99 
100 template<typename P>
101 struct IntersectionListLocal<P, 0>
102 {
103  static std::size_t parents(const P& p, typename P::Index intersection)
104  { return p.parents0(intersection); }
105 
106  static typename P::Index parent(const P& p, typename P::Index intersection, unsigned index)
107  { return p.parent0(intersection, index); }
108 
109  static typename P::Local0 corner(const P& p, typename P::Index intersection, unsigned corner, unsigned index)
110  { return p.corner0(intersection, corner, index); }
111 };
112 
113 template<typename P>
114 struct IntersectionListLocal<P, 1>
115 {
116  static std::size_t parents(const P& p, typename P::Index intersection)
117  { return p.parents1(intersection); }
118 
119  static typename P::Index parent(const P& p, typename P::Index intersection, unsigned index)
120  { return p.parent1(intersection, index); }
121 
122  static typename P::Local1 corner(const P& p, typename P::Index intersection, unsigned corner, unsigned index)
123  { return p.corner1(intersection, corner, index); }
124 };
125 
126 } /* namespace Impl */
127 
132 template<typename Local0, typename Local1>
134 {
135 public:
137  using Index = typename Provider::Index;
138 
139  IntersectionList(const std::shared_ptr<Provider>& provider)
140  : impl_(provider)
141  {}
142 
146  std::size_t size() const
147  { return impl_->size(); }
148 
155  template<int I>
156  std::size_t parents(Index intersection) const
157  {
158  static_assert(I == 0 or I == 1, "I must be 0 or 1");
159  // TODO [C++17]: use `if constexpr` instead of indirection
160  return Impl::IntersectionListLocal<Provider, I>::parents(*impl_, intersection);
161  }
162 
170  template<int I>
171  Index parent(Index intersection, unsigned index = 0) const
172  {
173  static_assert(I == 0 or I == 1, "I must be 0 or 1");
174  // TODO [C++17]: use `if constexpr` instead of indirection
175  return Impl::IntersectionListLocal<Provider, I>::parent(*impl_, intersection, index);
176  }
177 
186  template<int I>
187  auto corner(Index intersection, unsigned corner, unsigned index = 0) const
188  {
189  static_assert(I == 0 or I == 1, "I must be 0 or 1");
190  // TODO [C++17]: use `if constexpr` instead of indirection
191  return Impl::IntersectionListLocal<Provider, I>::corner(*impl_, intersection, corner, index);
192  }
193 
194 private:
195  std::shared_ptr<Provider> impl_;
196 };
197 
204 template<int dim0, int dim1>
206  : public IntersectionListProvider< FieldVector<double, dim0>, FieldVector<double, dim1> >
207 {
208  using Base = IntersectionListProvider< FieldVector<double, dim0>, FieldVector<double, dim1> >;
209 
210 public:
211  using Index = typename Base::Index;
212  using Local0 = FieldVector<double, dim0>;
213  using Local1 = FieldVector<double, dim1>;
214 
215  template<int I>
216  using Local = std::conditional_t< I == 0, Local0, Local1 >;
217 
222  {
223  private:
224  static constexpr int intersectionDim = dim0 < dim1 ? dim0 : dim1;
225  static constexpr int nVertices = intersectionDim + 1;
226 
227  public:
230  : parents0{parent0}
231  , parents1{parent1}
232  {}
233 
237  template<int I>
238  using Corners = std::array<Local<I>, nVertices>;
239 
243  std::vector< Corners<0> > corners0 = std::vector< Corners<0> >(1);
244 
248  std::vector< Index > parents0 = std::vector< Index >(1);
249 
253  std::vector< Corners<1> > corners1 = std::vector< Corners<1> >(1);
254 
258  std::vector< Index > parents1 = std::vector< Index >(1);
259  };
260 
262  SimplicialIntersectionListProvider(std::vector<SimplicialIntersection>&& intersections)
263  : intersections_(std::move(intersections))
264  {}
265 
267  { return intersections_; }
268 
269  std::size_t size() const override
270  { return intersections_.size(); }
271 
272  std::size_t parents0(Index intersection) const override
273  { return intersections_[intersection].parents0.size(); }
274 
275  std::size_t parents1(Index intersection) const override
276  { return intersections_[intersection].parents1.size(); }
277 
278  Index parent0(Index intersection, unsigned index) const override
279  { return intersections_[intersection].parents0[index]; }
280 
281  Index parent1(Index intersection, unsigned index) const override
282  { return intersections_[intersection].parents1[index]; }
283 
284  Local0 corner0(Index intersection, unsigned corner, unsigned index) const override
285  { return intersections_[intersection].corners0[index][corner]; }
286 
287  Local1 corner1(Index intersection, unsigned corner, unsigned index) const override
288  { return intersections_[intersection].corners1[index][corner]; }
289 
290  void clear()
291  {
292  intersections_.clear();
293  }
294 
295 private:
296  std::vector<SimplicialIntersection> intersections_;
297 };
298 
299 } /* namespace GridGlue */
300 } /* namespace Dune */
301 
302 #endif
Definition: gridglue.hh:37
Coordinate corner(unsigned c)
Definition: projection_impl.hh:24
Definition: intersectionlist.hh:22
virtual std::size_t parents0(Index intersection) const =0
virtual Local1 corner1(Index intersection, unsigned corner, unsigned index) const =0
unsigned int Index
Definition: intersectionlist.hh:38
virtual std::size_t size() const =0
L0 Local0
Definition: intersectionlist.hh:28
virtual Local0 corner0(Index intersection, unsigned corner, unsigned index) const =0
L1 Local1
Definition: intersectionlist.hh:33
virtual Index parent1(Index intersection, unsigned index) const =0
virtual std::size_t parents1(Index intersection) const =0
virtual Index parent0(Index intersection, unsigned index) const =0
Definition: intersectionlist.hh:134
Index parent(Index intersection, unsigned index=0) const
Definition: intersectionlist.hh:171
auto corner(Index intersection, unsigned corner, unsigned index=0) const
Definition: intersectionlist.hh:187
typename Provider::Index Index
Definition: intersectionlist.hh:137
IntersectionList(const std::shared_ptr< Provider > &provider)
Definition: intersectionlist.hh:139
std::size_t parents(Index intersection) const
Definition: intersectionlist.hh:156
std::size_t size() const
Definition: intersectionlist.hh:146
Definition: intersectionlist.hh:207
FieldVector< double, dim0 > Local0
Definition: intersectionlist.hh:212
SimplicialIntersectionListProvider(std::vector< SimplicialIntersection > &&intersections)
Definition: intersectionlist.hh:262
Local1 corner1(Index intersection, unsigned corner, unsigned index) const override
Definition: intersectionlist.hh:287
Local0 corner0(Index intersection, unsigned corner, unsigned index) const override
Definition: intersectionlist.hh:284
Index parent1(Index intersection, unsigned index) const override
Definition: intersectionlist.hh:281
typename Base::Index Index
Definition: intersectionlist.hh:211
std::conditional_t< I==0, Local0, Local1 > Local
Definition: intersectionlist.hh:216
auto & intersections()
Definition: intersectionlist.hh:266
void clear()
Definition: intersectionlist.hh:290
std::size_t size() const override
Definition: intersectionlist.hh:269
FieldVector< double, dim1 > Local1
Definition: intersectionlist.hh:213
std::size_t parents1(Index intersection) const override
Definition: intersectionlist.hh:275
Index parent0(Index intersection, unsigned index) const override
Definition: intersectionlist.hh:278
std::size_t parents0(Index intersection) const override
Definition: intersectionlist.hh:272
SimplicialIntersection(Index parent0, Index parent1)
Definition: intersectionlist.hh:229
std::array< Local< I >, nVertices > Corners
Definition: intersectionlist.hh:238
std::vector< Index > parents1
Definition: intersectionlist.hh:258
std::vector< Index > parents0
Definition: intersectionlist.hh:248
std::vector< Corners< 1 > > corners1
Definition: intersectionlist.hh:253
std::vector< Corners< 0 > > corners0
Definition: intersectionlist.hh:243