GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/extrusion.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 16 22 72.7%
Functions: 5 264 1.9%
Branches: 53 102 52.0%

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-FileCopyrightInfo: 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 static constexpr auto area(const FVGeo&, const SCVF& scvf)
30
11/17
✓ Branch 0 taken 232533750 times.
✓ Branch 1 taken 20982166 times.
✓ Branch 2 taken 145602573 times.
✓ Branch 3 taken 296406 times.
✓ Branch 4 taken 43248 times.
✓ Branch 5 taken 26328 times.
✓ Branch 6 taken 11068 times.
✓ Branch 7 taken 27972 times.
✓ Branch 8 taken 69680 times.
✓ Branch 9 taken 131556 times.
✓ Branch 10 taken 1028792 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
4819738888 { return scvf.area(); }
31
32 template<class FVGeo, class SCV>
33 static constexpr auto volume(const FVGeo&, const SCV& scv)
34
7/9
✓ Branch 1 taken 16440 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 8244637 times.
✓ Branch 4 taken 37759 times.
✓ Branch 5 taken 437531 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 189 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1198295284 { return scv.volume(); }
35
36 template<class Geometry>
37 static constexpr auto integrationElement(const Geometry& geo, const typename Geometry::LocalCoordinate& x)
38
1/2
✓ Branch 1 taken 101517 times.
✗ Branch 2 not taken.
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 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
11/32
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 320 times.
✓ Branch 4 taken 80 times.
✓ Branch 5 taken 320 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 400 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 400 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 400 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 10 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 10 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
124596874 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 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
21/34
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 312 times.
✓ Branch 2 taken 88 times.
✓ Branch 3 taken 312 times.
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 245710 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 245398 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 116 times.
✓ Branch 13 taken 83884 times.
✓ Branch 14 taken 116 times.
✓ Branch 15 taken 83948 times.
✓ Branch 16 taken 452 times.
✓ Branch 17 taken 83948 times.
✓ Branch 18 taken 336 times.
✓ Branch 19 taken 64 times.
✓ Branch 20 taken 336 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 3 times.
✓ Branch 31 taken 7 times.
✓ Branch 32 taken 3 times.
✓ Branch 33 taken 7 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
67996960 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 9600 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 19290 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 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
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
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 40 const auto radius0 = geo.corner(0)[0];
129 40 const auto radius1 = geo.corner(1)[0];
130 using std::abs;
131 40 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 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 60 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