Loading [MathJax]/extensions/tex2jax.js

DUNE-GRID-GLUE (2.10)

intersectionlist.hh
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
13namespace Dune {
14namespace GridGlue {
15
20template<typename L0, typename L1>
22{
23public:
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
94namespace Impl {
95
96template<typename P, int I>
97struct IntersectionListLocal
98{};
99
100template<typename P>
101struct 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
113template<typename P>
114struct 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
132template<typename Local0, typename Local1>
134{
135public:
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
194private:
195 std::shared_ptr<Provider> impl_;
196};
197
204template<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
210public:
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:
228 SimplicialIntersection() = default;
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
266 auto& intersections()
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
295private:
296 std::vector<SimplicialIntersection> intersections_;
297};
298
299} /* namespace GridGlue */
300} /* namespace Dune */
301
302#endif
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
std::size_t parents(Index intersection) const
Definition: intersectionlist.hh:156
std::size_t size() const
Definition: intersectionlist.hh:146
Definition: intersectionlist.hh:207
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
std::size_t size() const override
Definition: intersectionlist.hh:269
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
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 3, 22:46, 2025)