1#ifndef INTERPOLATION_DEFINED
2#define INTERPOLATION_DEFINED
11template <
typename F =
double>
38 const std::string boundaryCondition =
"M") {
40 double qn(0.), un(0.), sig(0.), p(0.);
41 if (boundaryCondition ==
"N") {
42 LOG(1,
"Interpolation::cubicSpline") <<
"Natural" << std::endl;
45 }
else if (boundaryCondition ==
"M") {
46 LOG(1,
"Interpolation::cubicSpline") <<
"Manual " << y1d0 << std::endl;
49 (3. / (
xv[1] -
xv[0])) * (((
yv[1] -
yv[0])) / (
xv[1] -
xv[0]) - y1d0);
51 un = (3. / (
xv[
N - 1] -
xv[
N - 2]))
52 * ((
yv[
N - 1] -
yv[
N - 2]) / (
xv[
N - 1] -
xv[
N - 2]) - y1dn);
54 for (
int i(1); i <
N - 1; i++) {
55 sig = (
xv[i] -
xv[i - 1]) / (
xv[i + 1] -
xv[i - 1]);
56 p = sig *
y2d[i - 1] + 2.;
57 y2d[i] = (sig - 1.) / p;
59 * ((
yv[i + 1] -
yv[i]) / (
xv[i + 1] -
xv[i])
60 - (
yv[i] -
yv[i - 1]) / (
xv[i] -
xv[i - 1]))
61 / (
xv[i + 1] -
xv[i - 1])
65 y2d[
N - 1] = (un - qn * u[
N - 2]) / (qn *
y2d[
N - 2] + 1.);
66 for (
int t =
N - 2; t >= 0; t--)
y2d[t] =
y2d[t] *
y2d[t + 1] + u[t];
79 while ((khigh - klow) > 1) {
80 k = (khigh + klow) / 2;
81 if (
xv[k - 1] > xinterp) khigh = k;
84 h =
xv[khigh - 1] -
xv[klow - 1];
86 LOG(1,
"CubicSpline_getValue") <<
"Same x points in x data!"
87 <<
"STOP!" << std::endl;
90 a = (
xv[khigh - 1] - xinterp) / h;
91 b = (xinterp -
xv[klow - 1]) / h;
93 a *
yv[klow - 1] + b *
yv[khigh - 1]
94 + ((a * a * a - a) *
y2d[klow - 1] + (b * b * b - b) *
y2d[khigh - 1])
#define LOG(...)
Definition Log.hpp:119
Definition Interpolation.hpp:12
F getValue(F xinterp)
Definition Interpolation.hpp:69
F * yv
Definition Interpolation.hpp:100
int N
Definition Interpolation.hpp:99
Inter1D(const int size, F *x, F *y)
Definition Interpolation.hpp:17
F * xv
Definition Interpolation.hpp:100
F * y2d
Definition Interpolation.hpp:100
void cubicSpline(F y1d0=0., F y1dn=0., const std::string boundaryCondition="M")
Definition Interpolation.hpp:36
Definition Algorithm.hpp:10
F abs(F const x)
Definition MathFunctions.hpp:29