GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/test/geometry/transformation.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 30 30 100.0%
Functions: 4 4 100.0%
Branches: 25 42 59.5%

Line Branch Exec Source
1 //
2 // SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 //
5 /*!
6 * \file
7 * \ingroup Common
8 * \brief Create a transformation function (translation + rotation)
9 */
10 #ifndef DUMUX_TEST_GEOMETRY_TRANSFORMATION_HH
11 #define DUMUX_TEST_GEOMETRY_TRANSFORMATION_HH
12
13 #include <iostream>
14
15 #include <dune/common/classname.hh>
16 #include <dune/common/fvector.hh>
17
18 #include <dumux/common/math.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup Common
24 * \brief Create a transformation function (translation) in 1D
25 */
26 template<class ctype>
27 auto make1DTransformation(const ctype scale,
28 const Dune::FieldVector<ctype, 1>& translate,
29 bool verbose = true)
30 {
31 if (verbose)
32 std::cout << "Created 1D transformation with"
33 << " ctype: " << Dune::className<ctype>()
34 << ", scaling: " << scale
35 << ", translation: " << translate << std::endl;
36
37 return [=](Dune::FieldVector<ctype, 1> p){
38 p *= scale;
39 p.axpy(scale, translate);
40 return p;
41 };
42 }
43
44 /*!
45 * \ingroup Common
46 * \brief Create a transformation function (translation + rotation) in 2D
47 * \note https://en.wikipedia.org/wiki/Rotation_matrix
48 */
49 template<class ctype>
50 40 auto make2DTransformation(const ctype scale,
51 const Dune::FieldVector<ctype, 2>& translate,
52 const ctype rotationAngle,
53 bool verbose = true)
54 {
55
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (verbose)
56 std::cout << "Created 2D transformation with"
57 << " ctype: " << Dune::className<ctype>()
58
3/6
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 40 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 40 times.
✗ Branch 10 not taken.
120 << ", scaling: " << scale
59
2/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
40 << ", translation: " << translate
60
2/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
40 << ", rotationAngle: " << rotationAngle << std::endl;
61
62 using std::sin; using std::cos;
63 40 const ctype sinAngle = sin(rotationAngle);
64 40 const ctype cosAngle = cos(rotationAngle);
65 920 return [=](Dune::FieldVector<ctype, 2> p){
66 920 auto tp = p;
67 920 tp[0] = p[0]*cosAngle-p[1]*sinAngle;
68 920 tp[1] = p[0]*sinAngle+p[1]*cosAngle;
69
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 920 times.
3680 tp *= scale;
70 920 return tp.axpy(scale, translate);
71 40 };
72 }
73
74 /*!
75 * \ingroup Common
76 * \brief Create a transformation function (translation + rotation) in 3D
77 * \note https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
78 */
79 template<class ctype>
80 845 auto make3DTransformation(const ctype scale,
81 const Dune::FieldVector<ctype, 3>& translate,
82 const Dune::FieldVector<ctype, 3>& rotationAxis,
83 const ctype rotationAngle,
84 bool verbose = true)
85 {
86
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 485 times.
845 if (verbose)
87 std::cout << "Created 3D transformation with"
88 << " ctype: " << Dune::className<ctype>()
89
3/6
✓ Branch 3 taken 360 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 360 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 360 times.
✗ Branch 10 not taken.
1080 << ", scaling: " << scale
90
2/4
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 360 times.
✗ Branch 5 not taken.
360 << ", translation: " << translate
91
2/4
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 360 times.
✗ Branch 5 not taken.
360 << ", rotationAxis: " << rotationAxis
92
2/4
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 360 times.
✗ Branch 5 not taken.
360 << ", rotationAngle: " << rotationAngle << std::endl;
93
94 using std::sin; using std::cos;
95 845 const ctype sinAngle = sin(rotationAngle);
96 845 const ctype cosAngle = cos(rotationAngle);
97 13073 return [=](Dune::FieldVector<ctype, 3> p){
98 13073 auto tp = p;
99 13073 tp *= cosAngle;
100 13073 tp.axpy(sinAngle, Dumux::crossProduct({rotationAxis}, p));
101
2/2
✓ Branch 0 taken 39219 times.
✓ Branch 1 taken 13073 times.
78438 tp.axpy((1.0-cosAngle)*(rotationAxis*p), rotationAxis);
102
2/2
✓ Branch 0 taken 39219 times.
✓ Branch 1 taken 13073 times.
52292 tp *= scale;
103 13073 return tp.axpy(scale, translate);
104 845 };
105 }
106
107 } // end namespace Dumux
108
109 #endif
110