| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // This file is part of Bembel, the higher order C++ boundary element library. | ||
| 2 | // | ||
| 3 | // Copyright (C) 2022 see <http://www.bembel.eu> | ||
| 4 | // | ||
| 5 | // It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz, | ||
| 6 | // M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt, | ||
| 7 | // Universitaet Basel, and Universita della Svizzera italiana, Lugano. This | ||
| 8 | // source code is subject to the GNU General Public License version 3 and | ||
| 9 | // provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further | ||
| 10 | // information. | ||
| 11 | #ifndef BEMBEL_SRC_SPLINE_KNOTS_HPP_ | ||
| 12 | #define BEMBEL_SRC_SPLINE_KNOTS_HPP_ | ||
| 13 | |||
| 14 | namespace Bembel { | ||
| 15 | namespace Spl { | ||
| 16 | /** | ||
| 17 | * \ingroup Spline | ||
| 18 | * \brief Here, routines for the creation and processing of knot vectors are | ||
| 19 | * defined. | ||
| 20 | */ | ||
| 21 | 64188 | inline std::vector<double> MakeBezierKnotVector( | |
| 22 | int polynomial_degree) noexcept { | ||
| 23 | 64188 | std::vector<double> out; | |
| 24 | 64188 | out.reserve(polynomial_degree * 2); | |
| 25 |
2/2✓ Branch 1 taken 918888 times.
✓ Branch 2 taken 64188 times.
|
983076 | for (int i = 0; i < polynomial_degree; i++) out.push_back(0); |
| 26 |
2/2✓ Branch 1 taken 918888 times.
✓ Branch 2 taken 64188 times.
|
983076 | for (int i = 0; i < polynomial_degree; i++) out.push_back(1); |
| 27 | 64188 | return out; | |
| 28 | } | ||
| 29 | |||
| 30 | inline int GetPolynomialDegreeFromKnotVector( | ||
| 31 | const std::vector<double> &knot_vector) { | ||
| 32 | constexpr double tol = .0000001; | ||
| 33 | int i = 0; | ||
| 34 | const int sz = knot_vector.size(); | ||
| 35 | while (++i < sz) { | ||
| 36 | if (knot_vector[i] > tol) { | ||
| 37 | return i; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | 542 | inline std::vector<double> MakeUniformKnotVector(int polynomial_degree, | |
| 44 | int interior, | ||
| 45 | int knotrepetition) noexcept { | ||
| 46 | 542 | std::vector<double> out; | |
| 47 | 542 | const double h = 1. / (interior + 1); | |
| 48 | 542 | out.reserve(polynomial_degree * 2); | |
| 49 |
2/2✓ Branch 1 taken 1662 times.
✓ Branch 2 taken 542 times.
|
2204 | for (int i = 0; i < polynomial_degree; i++) out.push_back(0); |
| 50 |
2/2✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 542 times.
|
1956 | for (int i = 1; i < interior + 1; i++) |
| 51 |
2/2✓ Branch 1 taken 1534 times.
✓ Branch 2 taken 1414 times.
|
2948 | for (int k = 0; k < knotrepetition; k++) out.push_back(i * h); |
| 52 |
2/2✓ Branch 1 taken 1662 times.
✓ Branch 2 taken 542 times.
|
2204 | for (int i = 0; i < polynomial_degree; i++) out.push_back(1); |
| 53 | 542 | return out; | |
| 54 | } | ||
| 55 | |||
| 56 | inline std::vector<double> MakeUniformKnotVector(int p, int lvl) { | ||
| 57 | return MakeUniformKnotVector(p, lvl, 1); | ||
| 58 | } | ||
| 59 | |||
| 60 | // Chunk knots eats knotvectors and returns knotvectors in which each knot is | ||
| 61 | // unique, up to tolerance tol. | ||
| 62 | 188 | inline std::vector<double> ExtractUniqueKnotVector( | |
| 63 | const std::vector<double> &in) { | ||
| 64 | 188 | constexpr double tol = Bembel::Constants::generic_tolerance; | |
| 65 | 188 | std::vector<double> out; | |
| 66 | 188 | const int size = in.size(); | |
| 67 | // std::cout<< "chunk " << in[0] <<"\n"; | ||
| 68 |
1/2✓ Branch 2 taken 188 times.
✗ Branch 3 not taken.
|
188 | out.push_back(in[0]); |
| 69 |
2/2✓ Branch 0 taken 1146 times.
✓ Branch 1 taken 188 times.
|
1334 | for (int i = 1; i < size; i++) { |
| 70 |
3/4✓ Branch 2 taken 190 times.
✓ Branch 3 taken 956 times.
✓ Branch 6 taken 190 times.
✗ Branch 7 not taken.
|
1146 | if (in[i] > (in[i - 1] + tol)) out.push_back(in[i]); |
| 71 | } | ||
| 72 | 188 | return out; | |
| 73 | ✗ | } | |
| 74 | |||
| 75 | // Up tp tol, fins knot element index for a given x. | ||
| 76 | 199812112 | inline int FindLocationInKnotVector(const double &x, | |
| 77 | const std::vector<double> &v) { | ||
| 78 | 199812112 | constexpr double tol = Bembel::Constants::generic_tolerance; | |
| 79 | 199812112 | int size = v.size(); | |
| 80 |
3/4✓ Branch 0 taken 17316 times.
✓ Branch 1 taken 199794796 times.
✓ Branch 2 taken 17316 times.
✗ Branch 3 not taken.
|
199812112 | if (((x - tol) < 0.) && ((x + tol) > 0.)) return 0; |
| 81 |
2/2✓ Branch 0 taken 199794796 times.
✓ Branch 1 taken 17720 times.
|
199812516 | for (int i = 0; i < size - 1; i++) { |
| 82 |
5/6✓ Branch 1 taken 199794796 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 199777076 times.
✓ Branch 5 taken 17720 times.
✓ Branch 6 taken 199777076 times.
✓ Branch 7 taken 17720 times.
|
199794796 | if (v[i] <= x && v[i + 1] > x) return i; |
| 83 | } | ||
| 84 | 17720 | return size - 2; | |
| 85 | } | ||
| 86 | } // namespace Spl | ||
| 87 | } // namespace Bembel | ||
| 88 | #endif // BEMBEL_SRC_SPLINE_KNOTS_HPP_ | ||
| 89 |