Bembel
 
Loading...
Searching...
No Matches
Knots.hpp
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
14namespace Bembel {
15namespace Spl {
21inline std::vector<double> MakeBezierKnotVector(
22 int polynomial_degree) noexcept {
23 std::vector<double> out;
24 out.reserve(polynomial_degree * 2);
25 for (int i = 0; i < polynomial_degree; i++) out.push_back(0);
26 for (int i = 0; i < polynomial_degree; i++) out.push_back(1);
27 return out;
28}
29
30inline 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
43inline std::vector<double> MakeUniformKnotVector(int polynomial_degree,
44 int interior,
45 int knotrepetition) noexcept {
46 std::vector<double> out;
47 const double h = 1. / (interior + 1);
48 out.reserve(polynomial_degree * 2);
49 for (int i = 0; i < polynomial_degree; i++) out.push_back(0);
50 for (int i = 1; i < interior + 1; i++)
51 for (int k = 0; k < knotrepetition; k++) out.push_back(i * h);
52 for (int i = 0; i < polynomial_degree; i++) out.push_back(1);
53 return out;
54}
55
56inline 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.
62inline std::vector<double> ExtractUniqueKnotVector(
63 const std::vector<double> &in) {
64 constexpr double tol = Bembel::Constants::generic_tolerance;
65 std::vector<double> out;
66 const int size = in.size();
67 // std::cout<< "chunk " << in[0] <<"\n";
68 out.push_back(in[0]);
69 for (int i = 1; i < size; i++) {
70 if (in[i] > (in[i - 1] + tol)) out.push_back(in[i]);
71 }
72 return out;
73}
74
75// Up tp tol, fins knot element index for a given x.
76inline int FindLocationInKnotVector(const double &x,
77 const std::vector<double> &v) {
78 constexpr double tol = Bembel::Constants::generic_tolerance;
79 int size = v.size();
80 if (((x - tol) < 0.) && ((x + tol) > 0.)) return 0;
81 for (int i = 0; i < size - 1; i++) {
82 if (v[i] <= x && v[i + 1] > x) return i;
83 }
84 return size - 2;
85}
86} // namespace Spl
87} // namespace Bembel
88#endif // BEMBEL_SRC_SPLINE_KNOTS_HPP_
std::vector< double > MakeBezierKnotVector(int polynomial_degree) noexcept
Here, routines for the creation and processing of knot vectors are defined.
Definition Knots.hpp:21
Routines for the evalutation of pointwise errors.
constexpr int getFunctionSpaceOutputDimension()