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 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 | 8060049 | 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 | 2000240 | return Vector({-v[1], v[0]}); | |
32 | |||
33 |
25/42✓ Branch 0 taken 718728 times.
✓ Branch 1 taken 2070060 times.
✓ Branch 2 taken 413480 times.
✓ Branch 3 taken 1656580 times.
✓ Branch 4 taken 375796 times.
✓ Branch 5 taken 1280784 times.
✓ Branch 6 taken 335926 times.
✓ Branch 7 taken 944858 times.
✓ Branch 8 taken 38794 times.
✓ Branch 9 taken 21015 times.
✓ Branch 10 taken 113710 times.
✓ Branch 11 taken 63375 times.
✓ Branch 12 taken 63375 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 778434 times.
✓ Branch 15 taken 1221566 times.
✓ Branch 16 taken 681041 times.
✓ Branch 17 taken 600094 times.
✓ Branch 18 taken 444084 times.
✓ Branch 19 taken 156010 times.
✓ Branch 20 taken 156010 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 949012 times.
✓ Branch 37 taken 1050988 times.
✓ Branch 38 taken 800896 times.
✓ Branch 39 taken 250092 times.
✓ Branch 40 taken 250092 times.
✗ Branch 41 not taken.
|
14449946 | const auto it = std::find_if(v.begin(), v.end(), [](const auto& x) { return Dune::FloatCmp::ne(x, 0.0); }); |
34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59569 times.
|
6059809 | const auto index = std::distance(v.begin(), it); |
35 |
2/2✓ Branch 0 taken 42916 times.
✓ Branch 1 taken 16653 times.
|
6059809 | if (index != Vector::size()-1) |
36 | { | ||
37 | 5590332 | Vector normal(0.0); | |
38 | 5590332 | normal[index] = -v[index+1]; | |
39 | 5590332 | normal[index+1] = v[index]; | |
40 | 5590332 | return normal; | |
41 | } | ||
42 | else | ||
43 | { | ||
44 | 469477 | Vector normal(0.0); | |
45 | 469477 | normal[index-1] = -v[index]; | |
46 | 469477 | normal[index] = v[index-1]; | |
47 | 469477 | 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 | 59569 | inline Vector unitNormal(const Vector& v) | |
59 | { | ||
60 | 59569 | auto normal = Dumux::normal(v); | |
61 | 59569 | normal /= normal.two_norm(); | |
62 | 59569 | return normal; | |
63 | } | ||
64 | |||
65 | } // end namespace Dumux | ||
66 | |||
67 | #endif | ||
68 |