Bembel
 
Loading...
Searching...
No Matches
Bernstein.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
12#ifndef BEMBEL_SRC_SPLINE_BERNSTEIN_HPP_
13#define BEMBEL_SRC_SPLINE_BERNSTEIN_HPP_
14
15namespace Bembel {
16namespace Basis {
22template <int N>
23inline constexpr double BernsteinX(double evaluation_point) noexcept {
24#ifdef _spline_debug_flag_
25 assert((evaluation_point > -.0000001) && (evaluation_point < 1.0000001) &&
26 ("Function only valid for 0 <= x <= 1!"));
27#endif
29}
30
31template <>
32inline constexpr double BernsteinX<1>(double evaluation_point) noexcept {
33 return evaluation_point;
34}
35template <>
36inline constexpr double BernsteinX<0>(double evaluation_point) noexcept {
37 return 1.;
38}
39template <>
40inline constexpr double BernsteinX<-1>(double evaluation_point) noexcept {
41 return 0.;
42}
43
44template <int N, int P>
45inline constexpr double Bernstein(double evaluation_point) noexcept {
46 return Binomial<N, P>::value * BernsteinX<N>(evaluation_point) *
48}
52template <typename T, int N, int P>
54 public:
55 static inline T EvalCoefs(T *in, double evaluation_point) noexcept {
58 }
59 static inline T EvalDerCoefs(T *in, double evaluation_point) noexcept {
60 return (
63 }
64 static inline void EvalBasisPEQ(T *in, double evaluation_point) noexcept {
67 return;
68 }
69 static inline void EvalDerBasisPEQ(T *in, double evaluation_point) noexcept {
73 return;
74 }
75 static inline void EvalBasis(T *in, double evaluation_point) noexcept {
78 return;
79 }
80 static inline void EvalDerBasis(T *in, double evaluation_point) noexcept {
84 return;
85 }
86};
87
88template <typename T, int P>
90 public:
91 static inline T EvalCoefs(T *in, double evaluation_point) noexcept {
93 }
94 static inline T EvalDerCoefs(T *in, double evaluation_point) noexcept {
95 // P needs to be passed lower to avoid infinite recursion
96 return (in[1] - in[0]) * Bernstein<0, P>(evaluation_point);
97 }
98 static inline void EvalBasisPEQ(T *in, double evaluation_point) noexcept {
100 return;
101 }
102 static inline void EvalDerBasisPEQ(T *in, double evaluation_point) noexcept {
103 // P needs to be passed lower to avoid infinite recursion
104 in[0] += (-P - 1) * Bernstein<0, P>(evaluation_point);
105 return;
106 }
107
108 static inline void EvalBasis(T *in, double evaluation_point) noexcept {
110 return;
111 }
112 static inline void EvalDerBasis(T *in, double evaluation_point) noexcept {
113 // P needs to be passed lower to avoid infinite recursion
114 in[0] = (-P - 1) * Bernstein<0, P>(evaluation_point);
115 return;
116 }
117};
118
119// This specialization is needed to get a specialized recursion anchor for the
120// case P = 0.
121template <typename T, int P>
123 public:
124 static inline T EvalCoefs(T *in, double evaluation_point) noexcept {
125 (void)in;
127 assert(
128 false &&
129 "Pos.A This should not happen. Something is wrong with the recursion");
130 };
131 static inline T EvalDerCoefs(T *in, double evaluation_point) noexcept {
132 // P needs to be passed lower to avoid infinite recursion
133 (void)in;
135 return 0;
136 };
137 static inline void EvalBasis(T *in, double evaluation_point) noexcept {
138 (void)in;
140 assert(
141 false &&
142 "Pos.C This should not happen. Something is wrong with the recursion");
143 };
144 static inline void EvalDerBasis(T *in, double evaluation_point) noexcept {
145 (void)in;
147 // P needs to be passed lower to avoid infinite recursion
148 return;
149 };
150 static inline void EvalBasisPEQ(T *in, double evaluation_point) noexcept {
151 (void)in;
153 assert(
154 false &&
155 "Pos.C This should not happen. Something is wrong with the recursion");
156 };
157 static inline void EvalDerBasisPEQ(T *in, double evaluation_point) noexcept {
158 (void)in;
160 // P needs to be passed lower to avoid infinite recursion
161 return;
162 };
163};
167template <typename T, int P>
171
172template <typename T, int P>
173void EvalBernstein(T *in, const std::vector<double> &evaluation_points,
174 T *out) noexcept {
175 const int N = evaluation_points.size();
176 for (int i = 0; i < N; i++)
177 out[i] = HiddenBernsteinClass<T, P, P>::EvalCoefs(in, evaluation_points[i]);
178 return;
179}
180
181template <typename T, int P>
182std::vector<T> EvalBernstein(
183 T *in, const std::vector<double> &evaluation_points) noexcept {
184 const int N = evaluation_points.size();
185 std::vector<double> out(N);
186 for (int i = 0; i < N; i++)
187 out[i] = HiddenBernsteinClass<T, P, P>::EvalCoefs(in, evaluation_points[i]);
188 return out;
189}
190
191template <typename T, int P>
192void EvalBernsteinBasisPEQ(T *in, double evaluation_point) noexcept {
193 HiddenBernsteinClass<T, P, P>::EvalBasisPEQ(in, evaluation_point);
194 return;
195}
196
197template <typename T, int P>
198void EvalBernsteinBasis(T *in, double evaluation_point) noexcept {
199 HiddenBernsteinClass<T, P, P>::EvalBasis(in, evaluation_point);
200 return;
201}
205template <typename T, int P>
210
211template <typename T, int P>
212void EvalBernsteinDer(T *in, const std::vector<double> &evaluation_points,
213 T *out) noexcept {
214 const int N = evaluation_points.size();
215 for (int i = 0; i < N; i++)
216 out[i] = P * HiddenBernsteinClass<T, P - 1, P - 1>::EvalDerCoefs(
218 return;
219}
220
221template <typename T, int P>
222std::vector<T> EvalBernsteinDer(
223 T *in, const std::vector<double> &evaluation_points) noexcept {
224 const int N = evaluation_points.size();
225 std::vector<double> out(N);
226 for (int i = 0; i < N; i++)
227 out[i] = P * HiddenBernsteinClass<T, P - 1, P - 1>::EvalDerCoefs(
229 return out;
230}
231
232template <typename T, int P>
233void EvalBernsteinDerBasisPEQ(T *in, double evaluation_point) noexcept {
234 in[P] += P * Bernstein<P - 1, P - 1>(evaluation_point);
235 HiddenBernsteinClass<T, P - 1, P - 1>::EvalDerBasisPEQ(in, evaluation_point);
236 return;
237}
238
239template <typename T, int P>
240void EvalBernsteinDerBasis(T *in, double evaluation_point) noexcept {
241 in[P] = P * Bernstein<P - 1, P - 1>(evaluation_point);
242 HiddenBernsteinClass<T, P - 1, P - 1>::EvalDerBasis(in, evaluation_point);
243 return;
244}
245
246} // namespace Basis
247} // namespace Bembel
248#endif // BEMBEL_SRC_SPLINE_BERNSTEIN_HPP_
constexpr double BernsteinX(double evaluation_point) noexcept
Template recursion to produce Bernstein polynomials. This is only limited by the binomial coefficient...
Definition Bernstein.hpp:23
T EvalBernstein(T *in, double evaluation_point) noexcept
Evaluation Routines.
T EvalBernsteinDer(T *in, double evaluation_point) noexcept
Evaluation of the Derivatives.
Routines for the evalutation of pointwise errors.
constexpr int getFunctionSpaceOutputDimension()