version 3.8
refinementquadraturerule.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_GEOMETRY_REFINEMENT_QUADRATURERULE_HH
15#define DUMUX_GEOMETRY_REFINEMENT_QUADRATURERULE_HH
16
17#include <dune/geometry/quadraturerules.hh>
18#include <dune/geometry/virtualrefinement.hh>
19#include <dumux/common/math.hh>
20
21namespace Dumux {
22
27template<typename ct, int mydim>
28class RefinementQuadratureRule final : public Dune::QuadratureRule<ct, mydim>
29{
30public:
32 static constexpr int dim = mydim;
33
35 static constexpr int highest_order = 1;
36
38
39 RefinementQuadratureRule(Dune::GeometryType type, int levels)
40 : Dune::QuadratureRule<ct, dim>(type, highest_order)
41 {
42 auto& refinement = Dune::buildRefinement<dim, ct>(type, type);
43 const auto tag = Dune::refinementLevels(levels);
44
45 // get the vertices
46 const auto numVertices = refinement.nVertices(tag);
47 std::vector<Dune::FieldVector<ct, dim>> points; points.reserve(numVertices);
48 auto vIt = refinement.vBegin(tag);
49 const auto vItEnd = refinement.vEnd(tag);
50 for (; vIt != vItEnd; ++vIt)
51 points.emplace_back(vIt.coords());
52
53 // go over all elements and get center and volume
54 const auto numElements = refinement.nElements(tag);
55 this->reserve(numElements);
56 auto eIt = refinement.eBegin(tag);
57 const auto eItEnd = refinement.eEnd(tag);
58 for (; eIt != eItEnd; ++eIt)
59 {
60 // quadrature point in the centroid of the sub-element and weight is its volume
61 const auto weight = computeVolume_(type, points, eIt.vertexIndices());
62 this->emplace_back(eIt.coords(), weight);
63 }
64 }
65
66private:
67 template<class VertexIndices>
68 ct computeVolume_(Dune::GeometryType t, const std::vector<Dune::FieldVector<ct, dim>>& points, const VertexIndices& indices) const
69 {
70 if (t != Dune::GeometryTypes::simplex(2))
71 DUNE_THROW(Dune::NotImplemented, "Only implemented for 2d simplices");
72
73 const auto ab = points[indices[1]] - points[indices[0]];
74 const auto ac = points[indices[2]] - points[indices[0]];
75 using std::abs;
76 return abs(crossProduct(ab, ac))*0.5;
77 }
78};
79
80} // end namespace Dumux
81
82#endif
A "quadrature" based on virtual refinement.
Definition: refinementquadraturerule.hh:29
~RefinementQuadratureRule() final
Definition: refinementquadraturerule.hh:37
RefinementQuadratureRule(Dune::GeometryType type, int levels)
Definition: refinementquadraturerule.hh:39
static constexpr int dim
The space dimension.
Definition: refinementquadraturerule.hh:32
static constexpr int highest_order
The highest quadrature order available.
Definition: refinementquadraturerule.hh:35
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:642
Define some often used mathematical functions.
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24