GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/geometry/transformation.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 4 4 100.0%
Branches: 16 34 47.1%

Line Branch Exec Source
1 //
2 // SPDX-FileCopyrightInfo: 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
2/6
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 40 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
200 << ", scaling: " << scale
59
1/2
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
80 << ", translation: " << translate
60
3/6
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 40 times.
80 << ", 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 2760 tp[0] = p[0]*cosAngle-p[1]*sinAngle;
68 2760 tp[1] = p[0]*sinAngle+p[1]*cosAngle;
69 920 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
2/6
✓ Branch 4 taken 360 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 360 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
1800 << ", scaling: " << scale
90
1/2
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
720 << ", translation: " << translate
91
1/2
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
720 << ", rotationAxis: " << rotationAxis
92
3/6
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 360 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 360 times.
720 << ", 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 26146 tp.axpy((1.0-cosAngle)*(rotationAxis*p), rotationAxis);
102 tp *= scale;
103 13073 return tp.axpy(scale, translate);
104 845 };
105 }
106
107 } // end namespace Dumux
108
109 #endif
110