GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/extrusion.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 23 23 100.0%
Functions: 5 5 100.0%
Branches: 59 103 57.3%

Line Branch Exec Source
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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup Discretization
10 * \brief Helper classes to compute the integration elements
11 *
12 * Provides area, volume, and integration elements for integration formulas.
13 * Modifying these quantities is useful to realize extrusions of the computational domain.
14 */
15 #ifndef DUMUX_DISCRETIZATION_EXTRUSION_HH
16 #define DUMUX_DISCRETIZATION_EXTRUSION_HH
17
18 #include <dune/common/std/type_traits.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup Discretization
24 * \brief Default implementation that performs no extrusion (extrusion with identity)
25 */
26 struct NoExtrusion
27 {
28 template<class FVGeo, class SCVF>
29
6/10
✓ Branch 0 taken 240429693 times.
✓ Branch 1 taken 21967688 times.
✓ Branch 2 taken 268908801 times.
✓ Branch 3 taken 75870 times.
✓ Branch 4 taken 137958 times.
✓ Branch 5 taken 58534 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
4349198826 static constexpr auto area(const FVGeo&, const SCVF& scvf)
30
10/15
✓ Branch 0 taken 240429693 times.
✓ Branch 1 taken 20935988 times.
✓ Branch 2 taken 268774039 times.
✓ Branch 3 taken 156756 times.
✓ Branch 4 taken 239774 times.
✓ Branch 5 taken 1105062 times.
✓ Branch 6 taken 26328 times.
✓ Branch 7 taken 67012 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 27972 times.
✓ Branch 10 taken 27972 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
5063861325 { return scvf.area(); }
31
32 template<class FVGeo, class SCV>
33
7/9
✓ Branch 3 taken 8246780 times.
✓ Branch 4 taken 665357 times.
✓ Branch 5 taken 9273 times.
✓ Branch 6 taken 1749207 times.
✓ Branch 1 taken 23928 times.
✓ Branch 2 taken 13173 times.
✓ Branch 7 taken 268800 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1110536952 static constexpr auto volume(const FVGeo&, const SCV& scv)
34
7/9
✓ Branch 3 taken 8246780 times.
✓ Branch 4 taken 598157 times.
✓ Branch 5 taken 76473 times.
✓ Branch 6 taken 1749207 times.
✓ Branch 1 taken 23928 times.
✓ Branch 2 taken 13173 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 268800 times.
✗ Branch 9 not taken.
1401111520 { return scv.volume(); }
35
36 template<class Geometry>
37
1/2
✓ Branch 1 taken 101517 times.
✗ Branch 2 not taken.
778623 static constexpr auto integrationElement(const Geometry& geo, const typename Geometry::LocalCoordinate& x)
38 778623 { return geo.integrationElement(x); }
39 };
40
41 /*!
42 * \ingroup Discretization
43 * \brief Rotation symmetric extrusion policy for rotating about an external axis
44 * \tparam radAx The radial axis perpendicular to the symmetry axis (0 = x, 1 = y)
45 */
46 template<int radAx = 0>
47 struct RotationalExtrusion
48 {
49 static constexpr int radialAxis = radAx;
50
51 /*!
52 * \brief Transformed sub-control-volume face area
53 * \note Mid-point rule integrals are only exact for constants
54 */
55 template<class FVGeo, class SCVF>
56
4/12
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 320 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 400 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 10 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
41711939 static constexpr auto area(const FVGeo&, const SCVF& scvf)
57 {
58 static_assert(int(SCVF::Traits::Geometry::mydimension) == int(SCVF::Traits::Geometry::coorddimension-1), "Area element to be called with a codim-1-entity!");
59 static_assert(SCVF::Traits::Geometry::coorddimension <= 2, "Axis rotation only makes sense for geometries up to 2D!");
60 static_assert(radialAxis < int(SCVF::Traits::Geometry::coorddimension), "Illegal radial axis!");
61
62 // Guldinus theorem
63
4/12
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 320 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 400 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 10 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
41711939 return scvf.area()*2.0*M_PI*scvf.center()[radialAxis];
64 }
65
66 /*!
67 * \brief Transformed sub-control-volume volume
68 * \note Mid-point rule integrals are only exact for constants
69 */
70 template<class FVGeo, class SCV>
71
9/13
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 312 times.
✓ Branch 3 taken 245514 times.
✓ Branch 4 taken 83884 times.
✓ Branch 5 taken 820 times.
✓ Branch 6 taken 335580 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 7 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 2 taken 2 times.
21294060 static constexpr auto volume(const FVGeo&, const SCV& scv)
72 {
73 static_assert(int(SCV::Traits::Geometry::mydimension) == int(SCV::Traits::Geometry::coorddimension), "Volume element to be called with a codim-0-entity!");
74 static_assert(SCV::Traits::Geometry::coorddimension <= 2, "Axis rotation only makes sense for geometries up to 2D!");
75 static_assert(radialAxis < int(SCV::Traits::Geometry::coorddimension), "Illegal radial axis!");
76
77 // Guldinus theorem
78
9/13
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 312 times.
✓ Branch 3 taken 245514 times.
✓ Branch 4 taken 83884 times.
✓ Branch 5 taken 820 times.
✓ Branch 6 taken 335580 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 7 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 2 taken 2 times.
22050060 return scv.volume()*2.0*M_PI*scv.center()[radialAxis];
79 }
80
81 /*!
82 * \brief Integration element for quadrature rules on the reference element
83 */
84 template<class Geometry>
85 9630 static constexpr auto integrationElement(const Geometry& geo, const typename Geometry::LocalCoordinate& x)
86 {
87 static_assert(Geometry::coorddimension <= 2, "Axis rotation only makes sense for geometries up to 2D!");
88 static_assert(radialAxis < int(Geometry::coorddimension), "Illegal radial axis!");
89
90 // Multiply with the polar extrusion factor (2*pi) and the determinant of the transformation Jacobian (radius)
91 9630 return geo.integrationElement(x)*2.0*M_PI*geo.global(x)[radialAxis];
92 }
93 };
94
95 /*!
96 * \ingroup Discretization
97 * \brief Rotation symmetric extrusion policy for spherical rotation
98 */
99 struct SphericalExtrusion
100 {
101 /*!
102 * \brief Transformed sub-control-volume face area
103 * \note Mid-point rule integrals are only exact for constants
104 */
105 template<class FVGeo, class SCVF>
106
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
12 static constexpr auto area(const FVGeo&, const SCVF& scvf)
107 {
108 static_assert(int(SCVF::Traits::Geometry::mydimension) == int(SCVF::Traits::Geometry::coorddimension-1), "Area element to be called with a codim-1-entity!");
109 static_assert(SCVF::Traits::Geometry::coorddimension == 1, "Spherical rotation only makes sense for 1D geometries!");
110
111 // sphere surface area
112 12 const auto radius = scvf.center()[0];
113
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
12 return 4.0*M_PI*radius*radius;
114 }
115
116 /*!
117 * \brief Transformed sub-control-volume volume
118 * \note Mid-point rule integrals are only exact for constants
119 */
120 template<class FVGeo, class SCV>
121 20 static constexpr auto volume(const FVGeo& fvGeometry, const SCV& scv)
122 {
123 static_assert(int(SCV::Traits::Geometry::mydimension) == int(SCV::Traits::Geometry::coorddimension), "Volume element to be called with a codim-0-entity!");
124 static_assert(SCV::Traits::Geometry::coorddimension == 1, "Spherical rotation only makes sense for 1D geometries!");
125
126 // subtract two balls
127 20 const auto geo = fvGeometry.geometry(scv);
128 20 const auto radius0 = geo.corner(0)[0];
129 20 const auto radius1 = geo.corner(1)[0];
130 using std::abs;
131 20 return 4.0/3.0*M_PI*abs(radius1*radius1*radius1 - radius0*radius0*radius0);
132 }
133
134 /*!
135 * \brief Integration element for quadrature rules on the reference element
136 */
137 template<class Geometry>
138 30 static constexpr auto integrationElement(const Geometry& geo, const typename Geometry::LocalCoordinate& x)
139 {
140 static_assert(Geometry::coorddimension == 1, "Spherical rotation only makes sense for 1D geometries!");
141
142 // Multiply with the constant spherical extrusion factor (int_0^2pi int_0^pi sin(phi) dphi dtheta = 4pi)
143 // and the remaining (radius-dependent) part of determinant of the transformation Jacobian (radius*radius)
144 30 const auto radius = geo.global(x)[0];
145 30 return geo.integrationElement(x)*4.0*M_PI*radius*radius;
146 }
147 };
148
149 /*!
150 * \brief Traits extracting the public Extrusion type from T
151 * Defaults to NoExtrusion if no such type is found
152 */
153 template<class T>
154 class Extrusion
155 {
156 template<class G>
157 using E = typename G::Extrusion;
158 public:
159 using type = typename Dune::Std::detected_or<NoExtrusion, E, T>::type;
160 };
161
162 /*!
163 * \brief Convenience alias for obtaining the extrusion type
164 */
165 template<class T>
166 using Extrusion_t = typename Extrusion<T>::type;
167
168 /*!
169 * \brief Convenience trait to check whether the extrusion is rotational
170 */
171 template<class T>
172 inline constexpr bool isRotationalExtrusion = false;
173
174 /*!
175 * \brief Convenience trait to check whether the extrusion is rotational
176 */
177 template<int radialAxis>
178 inline constexpr bool isRotationalExtrusion<RotationalExtrusion<radialAxis>> = true;
179
180 } // end namespace Dumux
181
182 #endif
183