dune-grid-glue  2.8.0
intersectionlist.hh
Go to the documentation of this file.
1 #ifndef DUNE_GRIDGLUE_MERGING_INTERSECTIONLIST_HH
2 #define DUNE_GRIDGLUE_MERGING_INTERSECTIONLIST_HH 1
3 
4 #include <array>
5 #include <type_traits>
6 #include <utility>
7 #include <vector>
8 
9 #include <dune/common/fvector.hh>
10 
11 namespace Dune {
12 namespace GridGlue {
13 
18 template<typename L0, typename L1>
20 {
21 public:
22 
26  using Local0 = L0;
27 
31  using Local1 = L1;
32 
36  using Index = unsigned int;
37 
41  virtual std::size_t size() const = 0;
42 
48  virtual std::size_t parents0(Index intersection) const = 0;
49 
55  virtual std::size_t parents1(Index intersection) const = 0;
56 
63  virtual Index parent0(Index intersection, unsigned index) const = 0;
64 
71  virtual Index parent1(Index intersection, unsigned index) const = 0;
72 
80  virtual Local0 corner0(Index intersection, unsigned corner, unsigned index) const = 0;
81 
89  virtual Local1 corner1(Index intersection, unsigned corner, unsigned index) const = 0;
90 };
91 
92 namespace Impl {
93 
94 template<typename P, int I>
95 struct IntersectionListLocal
96 {};
97 
98 template<typename P>
99 struct IntersectionListLocal<P, 0>
100 {
101  static std::size_t parents(const P& p, typename P::Index intersection)
102  { return p.parents0(intersection); }
103 
104  static typename P::Index parent(const P& p, typename P::Index intersection, unsigned index)
105  { return p.parent0(intersection, index); }
106 
107  static typename P::Local0 corner(const P& p, typename P::Index intersection, unsigned corner, unsigned index)
108  { return p.corner0(intersection, corner, index); }
109 };
110 
111 template<typename P>
112 struct IntersectionListLocal<P, 1>
113 {
114  static std::size_t parents(const P& p, typename P::Index intersection)
115  { return p.parents1(intersection); }
116 
117  static typename P::Index parent(const P& p, typename P::Index intersection, unsigned index)
118  { return p.parent1(intersection, index); }
119 
120  static typename P::Local1 corner(const P& p, typename P::Index intersection, unsigned corner, unsigned index)
121  { return p.corner1(intersection, corner, index); }
122 };
123 
124 } /* namespace Impl */
125 
130 template<typename Local0, typename Local1>
132 {
133 public:
135  using Index = typename Provider::Index;
136 
137  IntersectionList(const std::shared_ptr<Provider>& provider)
138  : impl_(provider)
139  {}
140 
144  std::size_t size() const
145  { return impl_->size(); }
146 
153  template<int I>
154  std::size_t parents(Index intersection) const
155  {
156  static_assert(I == 0 or I == 1, "I must be 0 or 1");
157  // TODO [C++17]: use `if constexpr` instead of indirection
158  return Impl::IntersectionListLocal<Provider, I>::parents(*impl_, intersection);
159  }
160 
168  template<int I>
169  Index parent(Index intersection, unsigned index = 0) const
170  {
171  static_assert(I == 0 or I == 1, "I must be 0 or 1");
172  // TODO [C++17]: use `if constexpr` instead of indirection
173  return Impl::IntersectionListLocal<Provider, I>::parent(*impl_, intersection, index);
174  }
175 
184  template<int I>
185  auto corner(Index intersection, unsigned corner, unsigned index = 0) const
186  {
187  static_assert(I == 0 or I == 1, "I must be 0 or 1");
188  // TODO [C++17]: use `if constexpr` instead of indirection
189  return Impl::IntersectionListLocal<Provider, I>::corner(*impl_, intersection, corner, index);
190  }
191 
192 private:
193  std::shared_ptr<Provider> impl_;
194 };
195 
202 template<int dim0, int dim1>
204  : public IntersectionListProvider< FieldVector<double, dim0>, FieldVector<double, dim1> >
205 {
206  using Base = IntersectionListProvider< FieldVector<double, dim0>, FieldVector<double, dim1> >;
207 
208 public:
209  using Index = typename Base::Index;
210  using Local0 = FieldVector<double, dim0>;
211  using Local1 = FieldVector<double, dim1>;
212 
213  template<int I>
214  using Local = std::conditional_t< I == 0, Local0, Local1 >;
215 
220  {
221  private:
222  static constexpr int intersectionDim = dim0 < dim1 ? dim0 : dim1;
223  static constexpr int nVertices = intersectionDim + 1;
224 
225  public:
228  : parents0{parent0}
229  , parents1{parent1}
230  {}
231 
235  template<int I>
236  using Corners = std::array<Local<I>, nVertices>;
237 
241  std::vector< Corners<0> > corners0 = std::vector< Corners<0> >(1);
242 
246  std::vector< Index > parents0 = std::vector< Index >(1);
247 
251  std::vector< Corners<1> > corners1 = std::vector< Corners<1> >(1);
252 
256  std::vector< Index > parents1 = std::vector< Index >(1);
257  };
258 
260  SimplicialIntersectionListProvider(std::vector<SimplicialIntersection>&& intersections)
261  : intersections_(std::move(intersections))
262  {}
263 
265  { return intersections_; }
266 
267  std::size_t size() const override
268  { return intersections_.size(); }
269 
270  std::size_t parents0(Index intersection) const override
271  { return intersections_[intersection].parents0.size(); }
272 
273  std::size_t parents1(Index intersection) const override
274  { return intersections_[intersection].parents1.size(); }
275 
276  Index parent0(Index intersection, unsigned index) const override
277  { return intersections_[intersection].parents0[index]; }
278 
279  Index parent1(Index intersection, unsigned index) const override
280  { return intersections_[intersection].parents1[index]; }
281 
282  Local0 corner0(Index intersection, unsigned corner, unsigned index) const override
283  { return intersections_[intersection].corners0[index][corner]; }
284 
285  Local1 corner1(Index intersection, unsigned corner, unsigned index) const override
286  { return intersections_[intersection].corners1[index][corner]; }
287 
288  void clear()
289  {
290  intersections_.clear();
291  }
292 
293 private:
294  std::vector<SimplicialIntersection> intersections_;
295 };
296 
297 } /* namespace GridGlue */
298 } /* namespace Dune */
299 
300 #endif
Definition: gridglue.hh:35
Coordinate corner(unsigned c)
Definition: projection_impl.hh:22
Definition: intersectionlist.hh:20
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:36
virtual std::size_t size() const =0
L0 Local0
Definition: intersectionlist.hh:26
virtual Local0 corner0(Index intersection, unsigned corner, unsigned index) const =0
L1 Local1
Definition: intersectionlist.hh:31
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:132
Index parent(Index intersection, unsigned index=0) const
Definition: intersectionlist.hh:169
auto corner(Index intersection, unsigned corner, unsigned index=0) const
Definition: intersectionlist.hh:185
typename Provider::Index Index
Definition: intersectionlist.hh:135
IntersectionList(const std::shared_ptr< Provider > &provider)
Definition: intersectionlist.hh:137
std::size_t parents(Index intersection) const
Definition: intersectionlist.hh:154
std::size_t size() const
Definition: intersectionlist.hh:144
Definition: intersectionlist.hh:205
FieldVector< double, dim0 > Local0
Definition: intersectionlist.hh:210
SimplicialIntersectionListProvider(std::vector< SimplicialIntersection > &&intersections)
Definition: intersectionlist.hh:260
Local1 corner1(Index intersection, unsigned corner, unsigned index) const override
Definition: intersectionlist.hh:285
Local0 corner0(Index intersection, unsigned corner, unsigned index) const override
Definition: intersectionlist.hh:282
Index parent1(Index intersection, unsigned index) const override
Definition: intersectionlist.hh:279
typename Base::Index Index
Definition: intersectionlist.hh:209
std::conditional_t< I==0, Local0, Local1 > Local
Definition: intersectionlist.hh:214
auto & intersections()
Definition: intersectionlist.hh:264
void clear()
Definition: intersectionlist.hh:288
std::size_t size() const override
Definition: intersectionlist.hh:267
FieldVector< double, dim1 > Local1
Definition: intersectionlist.hh:211
std::size_t parents1(Index intersection) const override
Definition: intersectionlist.hh:273
Index parent0(Index intersection, unsigned index) const override
Definition: intersectionlist.hh:276
std::size_t parents0(Index intersection) const override
Definition: intersectionlist.hh:270
SimplicialIntersection(Index parent0, Index parent1)
Definition: intersectionlist.hh:227
std::array< Local< I >, nVertices > Corners
Definition: intersectionlist.hh:236
std::vector< Index > parents1
Definition: intersectionlist.hh:256
std::vector< Index > parents0
Definition: intersectionlist.hh:246
std::vector< Corners< 1 > > corners1
Definition: intersectionlist.hh:251
std::vector< Corners< 0 > > corners0
Definition: intersectionlist.hh:241