1#ifndef TATOOINE_INTERPOLATION_H
2#define TATOOINE_INTERPOLATION_H
15template <
typename Real>
18template <
floating_po
int Real>
24 static constexpr std::size_t num_derivatives = 0;
44 constexpr linear(Real
const ft0, Real
const ft1)
45 : m_interpolant{ft0, ft1 - ft0} {}
47 constexpr linear(Real
const t0, Real
const t1, Real
const ft0, Real
const ft1)
48 : m_interpolant{(ft0 * t1 - ft1 * t0) / (t1 - t0),
49 (ft1 - ft0) / (t1 - t0)} {}
54 return m_interpolant(t);
60 constexpr auto polynomial() const -> auto const& {
return m_interpolant; }
61 constexpr auto polynomial() ->
auto& {
return m_interpolant; }
67template <
typename Real, std::size_t... Dims>
72template <
typename Real, std::
size_t N>
77template <
typename Real, std::
size_t N>
81template <
typename Real, std::
size_t M, std::
size_t N>
86template <
typename Real, std::
size_t M, std::
size_t N>
94template <
typename Real>
97template <
typename Real, std::size_t... Dims>
102template <
typename Real, std::
size_t N>
107template <
typename Real, std::
size_t N>
112template <
typename Real, std::
size_t M, std::
size_t N>
121template <
floating_po
int Float>
123template <
floating_po
int Float>
132 static constexpr std::size_t num_derivatives = 0;
153 constexpr linear(Real
const t0, Real
const t1,
155 auto it = [&](
auto const... is) {
156 m_interpolants(is...) =
158 (ft1(is...) - ft0(is...)) / (t1 - t0)};
164 auto it = [&](
auto const... is) {
165 m_interpolants(is...) =
176 auto it = [&](
auto const... is) {
177 interpolation(is...) = m_interpolants(is...)(t);
180 return interpolation;
186 auto polynomial() const -> auto const& {
return m_interpolants; }
190template <
typename Real, std::
size_t N>
195template <
typename Real, std::
size_t M, std::
size_t N>
205template <
floating_po
int Float, std::
size_t N>
207template <
floating_po
int Float, std::
size_t N>
209template <
floating_po
int Float, std::
size_t M, std::
size_t N>
212template <
floating_po
int Float, std::
size_t M, std::
size_t N>
215template <
typename Real>
218template <
floating_po
int Real>
220 static constexpr std::size_t num_derivatives = 1;
235 constexpr cubic(Real
const t0, Real
const t1, Real
const ft0, Real
const ft1,
236 Real
const dft0_dt, Real
const dft1_dt)
238 constexpr Real zero = 0;
239 constexpr Real one = 1;
241 {one, t1, t1 * t1, t1 * t1 * t1},
242 {zero, one, 2 * t0, 3 * t0 * t0},
243 {zero, one, 2 * t1, 3 * t1 * t1}};
244 auto const b =
vec<Real, 4>{ft0, ft1, dft0_dt, dft1_dt};
245 this->set_coefficients(
solve(A, b)->data());
248 constexpr cubic(Real
const ft0, Real
const ft1, Real
const dft0_dt,
250 :
parent_type{ft0, dft0_dt, 3 * ft1 - 3 * ft0 - dft1_dt - 2 * dft0_dt,
251 -2 * ft1 + 2 * ft0 + dft1_dt + dft0_dt} {}
254template <
floating_po
int Float>
257template <
floating_po
int Float>
260template <arithmetic Real, std::
size_t N>
266 static constexpr std::size_t num_derivatives = 1;
287 template <std::size_t... Is>
290 std::index_sequence<Is...> )
292 ft0(Is), dft0_dt(Is),
293 3 * ft1(Is) - 3 * ft0(Is) - dft1_dt(Is) - 2 * dft0_dt(Is),
294 -2 * ft1(Is) + 2 * ft0(Is) + dft1_dt(Is) + dft0_dt(Is)}...} {}
299 :
cubic{ft0, ft1, dft0_dt, dft1_dt, std::make_index_sequence<N>{}} {}
309 auto const A =
Mat4<Real>{{1.0, t0, t0 * t0, t0 * t0 * t0},
310 {1.0, t1, t1 * t1, t1 * t1 * t1},
311 {0.0, 1.0, 2 * t0, 3 * t0 * t0},
312 {0.0, 1.0, 2 * t1, 3 * t1 * t1}};
313 auto const C = *
solve(A, B);
314 for (std::size_t i = 0; i < N; ++i) {
315 m_interpolants[i].set_coefficients(C(0, i), C(1, i), C(2, i), C(3, i));
321 template <std::size_t... Is>
323 std::index_sequence<Is...> )
const {
324 return vec{m_interpolants[Is](t)...};
327 return evaluate(t, std::make_index_sequence<N>{});
330 return evaluate(t, std::make_index_sequence<N>{});
333 auto polynomial() const -> auto const& {
return m_interpolants; }
337template <
typename Real, std::
size_t N>
341template <
floating_po
int Float, std::
size_t N>
345template <
floating_po
int Float, std::
size_t N>
349template <
floating_po
int Float, std::
size_t N>
353template <
floating_po
int Float, std::
size_t N>
357template <
typename Real>
360template <
floating_po
int Real>
362 static constexpr std::size_t num_derivatives = 2;
366 static_assert(std::is_arithmetic<Real>::value);
384 constexpr quintic(Real
const t0, Real
const t1, Real
const ft0,
385 Real
const ft1, Real
const dft0_dt, Real
const dft1_dt,
386 Real
const ddft0_dtt, Real
const ddft1_dtt)
387 : m_interpolant{0, 0, 0, 0, 0, 0} {
389 Mat4<Real>{{1.0, t0, t0 * t0, t0 * t0 * t0, t0 * t0 * t0 * t0,
390 t0 * t0 * t0 * t0 * t0},
391 {1.0, t1, t1 * t1, t1 * t1 * t1, t1 * t1 * t1 * t1,
392 t1 * t1 * t1 * t1 * t1},
393 {0.0, 1.0, 2 * t0, 3 * t0 * t0, 4 * t0 * t0 * t0,
394 5 * t0 * t0 * t0 * t0},
395 {0.0, 1.0, 2 * t1, 3 * t1 * t1, 4 * t1 * t1 * t1,
396 5 * t1 * t1 * t1 * t1},
397 {0.0, 0.0, 2.0, 6 * t0, 12 * t0 * t0, 20 * t0 * t0 * t0},
398 {0.0, 0.0, 2.0, 6 * t1, 12 * t1 * t1, 20 * t1 * t1 * t1}};
399 vec<Real, 6> b{ft0, ft1, dft0_dt, dft1_dt, ddft0_dtt, ddft1_dtt};
403 constexpr quintic(Real
const ft0, Real
const ft1, Real
const dft0_dt,
404 Real
const dft1_dt, Real
const ddft0_dtt,
405 Real
const ddft1_dtt)
409 (20 * ft1 - 20 * ft0 - 8 * dft1_dt - 12 * dft0_dt +
410 ddft1_dtt - 3 * ddft0_dtt) /
412 -(30 * ft1 - 30 * ft0 - 14 * dft1_dt - 16 * dft0_dt +
413 2 * ddft1_dtt - 3 * ddft0_dtt) /
415 (12 * ft1 - 12 * ft0 - 6 * dft1_dt - 6 * dft0_dt +
416 ddft1_dtt - ddft0_dtt) /
423 return m_interpolant(t);
430 constexpr auto polynomial() const -> auto const& {
return m_interpolant; }
431 constexpr auto polynomial() ->
auto& {
return m_interpolant; }
434template <
floating_po
int Float>
Definition: concepts.h:33
Definition: concepts.h:30
Definition: interpolation.h:13
typename interpolation_value_type_impl< T >::type interpolation_value_type
Definition: interpolation.h:92
typename interpolation_tensor_type_impl< T >::type interpolation_tensor_type
Definition: interpolation.h:119
auto solve(polynomial< Real, 1 > const &p) -> std::vector< Real >
solve a + b*x
Definition: polynomial.h:187
constexpr auto for_loop(Iteration &&iteration, execution_policy::sequential_t, Ranges(&&... ranges)[2]) -> void
Use this function for creating a sequential nested loop.
Definition: for_loop.h:336
T type
Definition: common_type.h:13
constexpr cubic & operator=(cubic const &)=default
static constexpr std::size_t num_dimensions()
Definition: interpolation.h:223
Real real_type
Definition: interpolation.h:221
constexpr cubic & operator=(cubic &&)=default
constexpr cubic(Real const t0, Real const t1, Real const ft0, Real const ft1, Real const dft0_dt, Real const dft1_dt)
Definition: interpolation.h:235
constexpr cubic()=default
constexpr cubic(Real const ft0, Real const ft1, Real const dft0_dt, Real const dft1_dt)
Definition: interpolation.h:248
constexpr cubic(cubic &&)=default
constexpr cubic(cubic const &)=default
constexpr cubic(real_type const t0, real_type const t1, vec_type const &ft0, vec_type const &ft1, vec_type const &dft0_dt, vec_type const &dft1_dt)
Definition: interpolation.h:301
constexpr cubic(vec_type const &ft0, vec_type const &ft1, vec_type const &dft0_dt, vec_type const &dft1_dt)
Definition: interpolation.h:297
static constexpr std::size_t num_dimensions()
Definition: interpolation.h:271
Real real_type
Definition: interpolation.h:267
constexpr cubic(vec_type const &ft0, vec_type const &ft1, vec_type const &dft0_dt, vec_type const &dft1_dt, std::index_sequence< Is... >)
Definition: interpolation.h:288
constexpr cubic()=default
constexpr auto operator()(arithmetic auto const t) const
Definition: interpolation.h:329
constexpr cubic & operator=(cubic const &)=default
std::array< interpolant_type, N > polynomial_array_type
Definition: interpolation.h:270
constexpr auto evaluate(arithmetic auto const t, std::index_sequence< Is... >) const
Definition: interpolation.h:322
auto polynomial() -> auto &
Definition: interpolation.h:334
auto polynomial() const -> auto const &
Definition: interpolation.h:333
constexpr auto evaluate(arithmetic auto const t) const
Definition: interpolation.h:326
polynomial_array_type m_interpolants
Definition: interpolation.h:276
constexpr cubic(cubic &&)=default
constexpr cubic & operator=(cubic &&)=default
constexpr cubic(cubic const &)=default
Definition: interpolation.h:216
Definition: interpolation.h:95
Definition: interpolation.h:65
constexpr linear(Real const t0, Real const t1, Real const ft0, Real const ft1)
Definition: interpolation.h:47
constexpr linear()=default
constexpr linear & operator=(linear &&)=default
constexpr linear(Real const ft0, Real const ft1)
Definition: interpolation.h:44
interpolant_type m_interpolant
Definition: interpolation.h:33
constexpr auto polynomial() const -> auto const &
Definition: interpolation.h:60
constexpr linear & operator=(linear const &)=default
constexpr linear(linear const &)=default
constexpr auto polynomial() -> auto &
Definition: interpolation.h:61
constexpr auto operator()(arithmetic auto const t) const
Definition: interpolation.h:56
Real real_type
Definition: interpolation.h:25
constexpr linear(linear &&)=default
static constexpr std::size_t num_dimensions()
Definition: interpolation.h:27
constexpr auto evaluate(arithmetic auto const t) const
Definition: interpolation.h:53
constexpr linear()=default
constexpr linear(linear &&)=default
constexpr linear(Real const t0, Real const t1, tensor_type const &ft0, tensor_type const &ft1)
Definition: interpolation.h:153
interpolation_value_type< tensor< Real, Dims... > > value_type
Definition: interpolation.h:134
constexpr auto operator()(arithmetic auto const t) const
Definition: interpolation.h:182
auto polynomial() -> auto &
Definition: interpolation.h:187
auto polynomial() const -> auto const &
Definition: interpolation.h:186
constexpr linear(tensor_type const &ft0, tensor_type const &ft1)
Definition: interpolation.h:163
Real real_type
Definition: interpolation.h:133
constexpr linear & operator=(linear const &)=default
interpolation_tensor_type< tensor< Real, Dims... > > tensor_type
Definition: interpolation.h:135
constexpr linear(linear const &)=default
constexpr auto evaluate(arithmetic auto const t) const
Definition: interpolation.h:174
constexpr linear & operator=(linear &&)=default
Definition: interpolation.h:16
constexpr quintic(Real const ft0, Real const ft1, Real const dft0_dt, Real const dft1_dt, Real const ddft0_dtt, Real const ddft1_dtt)
Definition: interpolation.h:403
static constexpr std::size_t num_dimensions()
Definition: interpolation.h:365
Real real_type
Definition: interpolation.h:363
constexpr auto polynomial() const -> auto const &
Definition: interpolation.h:430
constexpr quintic(quintic &&)=default
constexpr auto polynomial() -> auto &
Definition: interpolation.h:431
constexpr quintic & operator=(quintic const &)=default
constexpr auto evaluate(arithmetic auto const t) const
Definition: interpolation.h:422
constexpr quintic(quintic const &)=default
constexpr auto operator()(arithmetic auto const t) const
Definition: interpolation.h:426
interpolant_type m_interpolant
Definition: interpolation.h:372
constexpr quintic & operator=(quintic &&)=default
constexpr quintic(Real const t0, Real const t1, Real const ft0, Real const ft1, Real const dft0_dt, Real const dft1_dt, Real const ddft0_dtt, Real const ddft1_dtt)
Definition: interpolation.h:384
constexpr quintic()=default
Definition: interpolation.h:358
auto constexpr row(std::size_t i)
Definition: mat.h:172
constexpr auto set_coefficients(std::array< Real, Degree+1 > const &coeffs) -> void
Definition: polynomial.h:104
Definition: index_order.h:17