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 Geometry | ||
10 | * \brief Helper functions for normals | ||
11 | */ | ||
12 | #ifndef DUMUX_GEOMETRY_NORMAL_HH | ||
13 | #define DUMUX_GEOMETRY_NORMAL_HH | ||
14 | |||
15 | #include <algorithm> | ||
16 | #include <dune/common/float_cmp.hh> | ||
17 | |||
18 | namespace Dumux { | ||
19 | |||
20 | /*! | ||
21 | * \ingroup Geometry | ||
22 | * \brief Create a vector normal to the given one (v is expected to be non-zero) | ||
23 | * \note This returns some orthogonal vector with arbitrary length | ||
24 | */ | ||
25 | template<class Vector> | ||
26 | 6046519 | inline Vector normal(const Vector& v) | |
27 | { | ||
28 | static_assert(Vector::size() > 1, "normal expects a coordinate dimension > 1"); | ||
29 | |||
30 | if constexpr (Vector::size() == 2) | ||
31 |
20/40✓ Branch 1 taken 400000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400000 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400000 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 400000 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 400000 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 400000 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 400000 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 400000 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 400000 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 400000 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 400000 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 400000 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 400000 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 400000 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 400000 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 400000 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 400000 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 400000 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 400000 times.
✗ Branch 59 not taken.
|
8000960 | return Vector({-v[1], v[0]}); |
32 | |||
33 |
50/84✓ Branch 0 taken 717272 times.
✓ Branch 1 taken 2070186 times.
✓ Branch 2 taken 717272 times.
✓ Branch 3 taken 2070186 times.
✓ Branch 4 taken 416100 times.
✓ Branch 5 taken 1654086 times.
✓ Branch 6 taken 416100 times.
✓ Branch 7 taken 1654086 times.
✓ Branch 8 taken 375222 times.
✓ Branch 9 taken 1278864 times.
✓ Branch 10 taken 375222 times.
✓ Branch 11 taken 1278864 times.
✓ Branch 12 taken 336150 times.
✓ Branch 13 taken 942714 times.
✓ Branch 14 taken 336150 times.
✓ Branch 15 taken 942714 times.
✓ Branch 16 taken 25504 times.
✓ Branch 17 taken 21015 times.
✓ Branch 18 taken 25504 times.
✓ Branch 19 taken 21015 times.
✓ Branch 20 taken 112428 times.
✓ Branch 21 taken 63843 times.
✓ Branch 22 taken 112428 times.
✓ Branch 23 taken 63843 times.
✓ Branch 24 taken 63843 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 63843 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 777692 times.
✓ Branch 29 taken 1222308 times.
✓ Branch 30 taken 777692 times.
✓ Branch 31 taken 1222308 times.
✓ Branch 32 taken 620264 times.
✓ Branch 33 taken 602044 times.
✓ Branch 34 taken 620264 times.
✓ Branch 35 taken 602044 times.
✓ Branch 36 taken 446044 times.
✓ Branch 37 taken 156000 times.
✓ Branch 38 taken 446044 times.
✓ Branch 39 taken 156000 times.
✓ Branch 40 taken 156000 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 156000 times.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 950014 times.
✓ Branch 73 taken 1049986 times.
✓ Branch 74 taken 950014 times.
✓ Branch 75 taken 1049986 times.
✓ Branch 76 taken 799804 times.
✓ Branch 77 taken 250182 times.
✓ Branch 78 taken 799804 times.
✓ Branch 79 taken 250182 times.
✓ Branch 80 taken 250182 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 250182 times.
✗ Branch 83 not taken.
|
34888075 | const auto it = std::find_if(v.begin(), v.end(), [](const auto& x) { return Dune::FloatCmp::ne(x, 0.0); }); |
34 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 46519 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 46519 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 46519 times.
|
18139557 | const auto index = std::distance(v.begin(), it); |
35 |
2/2✓ Branch 0 taken 29866 times.
✓ Branch 1 taken 16653 times.
|
6046519 | if (index != Vector::size()-1) |
36 | { | ||
37 | 5576494 | Vector normal(0.0); | |
38 | 11152988 | normal[index] = -v[index+1]; | |
39 | 11152988 | normal[index+1] = v[index]; | |
40 | 5576494 | return normal; | |
41 | } | ||
42 | else | ||
43 | { | ||
44 | 470025 | Vector normal(0.0); | |
45 | 940050 | normal[index-1] = -v[index]; | |
46 | 940050 | normal[index] = v[index-1]; | |
47 | 470025 | return normal; | |
48 | |||
49 | } | ||
50 | } | ||
51 | |||
52 | /*! | ||
53 | * \ingroup Geometry | ||
54 | * \brief Create a vector normal to the given one (v is expected to be non-zero) | ||
55 | * \note This returns some orthogonal vector with unit length | ||
56 | */ | ||
57 | template<class Vector> | ||
58 | 46279 | inline Vector unitNormal(const Vector& v) | |
59 | { | ||
60 | 46279 | auto normal = Dumux::normal(v); | |
61 | 92558 | normal /= normal.two_norm(); | |
62 | 46279 | return normal; | |
63 | } | ||
64 | |||
65 | } // end namespace Dumux | ||
66 | |||
67 | #endif | ||
68 |