13#ifndef DUMUX_MULTIDOMAIN_EMBEDDED_LOCAL_REFINEMENT_QUADRATURE_HH
14#define DUMUX_MULTIDOMAIN_EMBEDDED_LOCAL_REFINEMENT_QUADRATURE_HH
21#include <dune/common/exceptions.hh>
39template<
class Geometry,
class IndicatorFunction>
42 using IndicatorTriple = std::array<std::size_t, 3>;
43 using GlobalPosition =
typename Geometry::GlobalCoordinate;
44 using LocalPosition =
typename Geometry::LocalCoordinate;
45 using Corners = std::array<GlobalPosition, 3>;
49 LocalPosition localPos_;
51 std::size_t indicator_;
54 QuadPoint(LocalPosition&& localPos,
double weight, std::size_t i)
55 : localPos_(weight*std::move(localPos))
60 void add(LocalPosition&& localPos,
double weight)
62 localPos_ += weight*localPos;
71 const LocalPosition& position()
const {
return localPos_; }
72 double weight()
const {
return weight_; }
73 std::size_t indicator()
const {
return indicator_; }
80 Triangle(
const Corners& c) : corners_(c) {}
81 Triangle(Corners&& c) : corners_(std::move(c)) {}
82 const GlobalPosition& operator[](std::size_t i)
const {
return corners_[i]; }
84 GlobalPosition
center()
const
86 GlobalPosition
center(0.0);
87 for (
const auto& c : corners_)
95 const auto ab = corners_[1] - corners_[0];
96 const auto ac = corners_[2] - corners_[0];
104 , maxLevel_(maxLevel)
107 static constexpr int dim = Geometry::mydimension;
108 static_assert(dim == 2,
"Only triangles are supported so far");
110 if (geo.corners() != (dim+1))
111 DUNE_THROW(Dune::InvalidStateException,
"Only simplex geometries are allowed");
114 const auto tri = Triangle{{ geo.corner(0), geo.corner(1), geo.corner(2) }};
115 const auto triple = IndicatorTriple{{ ind_(tri[0]), ind_(tri[1]), ind_(tri[2]) }};
116 volume_ = tri.volume();
119 addSimplex_(tri, 0, triple, triple);
121 for (
auto& qp : qps_)
125 auto begin()
const {
return qps_.begin(); }
126 auto end()
const {
return qps_.end(); }
127 auto size()
const {
return qps_.size(); }
130 void addSimplex_(
const Triangle& tri, std::size_t level,
const IndicatorTriple& triple,
const IndicatorTriple& childTriple)
133 if (std::all_of(childTriple.begin(), childTriple.end(), [a0=childTriple[0]](
auto a){ return (a == a0); }))
136 auto it = std::find_if(qps_.begin(), qps_.end(), [&](
const auto& qp){ return (qp.indicator() == childTriple[0]); });
137 if (it != qps_.end())
138 it->add(geometry_.local(tri.center()), 0.5*tri.volume()/volume_);
140 qps_.emplace_back(geometry_.local(tri.center()), 0.5*tri.volume()/volume_, childTriple[0]);
144 else if (level == maxLevel_)
146 for (
int i = 0; i < 3; ++i)
149 auto it = std::find_if(qps_.begin(), qps_.end(), [&](
const auto& qp){ return (qp.indicator() == childTriple[i]); });
150 if (it != qps_.end())
151 it->add(geometry_.local(tri[i]), 0.5*tri.volume()/volume_/3.0);
153 qps_.emplace_back(geometry_.local(tri[i]), 0.5*tri.volume()/volume_/3.0, childTriple[i]);
160 const auto children = refine(tri);
161 for (
const auto& c : children)
164 const auto grandChildTriple = IndicatorTriple{{ ind_(c[0]), ind_(c[1]), ind_(c[2]) }};
165 addSimplex_(c, level+1, triple, grandChildTriple);
170 std::array<Triangle, 4> refine(
const Triangle& tri)
const
172 const auto p01 = 0.5*(tri[0] + tri[1]);
173 const auto p12 = 0.5*(tri[1] + tri[2]);
174 const auto p20 = 0.5*(tri[2] + tri[0]);
177 {{ tri[0], p01, p20 }},
178 {{ tri[1], p01, p12 }},
179 {{ tri[2], p12, p20 }},
184 const IndicatorFunction &ind_;
185 std::size_t maxLevel_;
186 const Geometry& geometry_;
189 std::vector<QuadPoint> qps_;
A quadrature rule using local refinement to approximate partitioned elements.
Definition: localrefinementquadrature.hh:41
auto end() const
Definition: localrefinementquadrature.hh:126
auto size() const
Definition: localrefinementquadrature.hh:127
LocalRefinementSimplexQuadrature(const Geometry &geo, std::size_t maxLevel, const IndicatorFunction &i)
Definition: localrefinementquadrature.hh:102
auto begin() const
Definition: localrefinementquadrature.hh:125
Dune::FieldVector< Scalar, 3 > crossProduct(const Dune::FieldVector< Scalar, 3 > &vec1, const Dune::FieldVector< Scalar, 3 > &vec2)
Cross product of two vectors in three-dimensional Euclidean space.
Definition: math.hh:671
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition: center.hh:24