20 const std::vector<Real> & y,
21 std::vector<Real> & y2,
27 mooseError(
"You must have at least two knots to create a spline.");
29 std::vector<Real> u(n, 0.);
37 u[0] = (3.0 / (x[1] - x[0])) * ((y[1] - y[0]) / (x[1] - x[0]) - yp1);
40 for (decltype(n) i = 1; i < n - 1; i++)
42 Real sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
43 Real p = sig * y2[i - 1] + 2.0;
44 y2[i] = (sig - 1.0) / p;
45 u[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]);
46 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
55 un = (3.0 / (x[n - 1] - x[n - 2])) * (ypn - (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]));
58 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.);
60 for (
auto k = n - 1; k >= 1; k--)
61 y2[k - 1] = y2[k - 1] * y2[k] + u[k - 1];
68 unsigned int & khi)
const 71 mooseAssert(x.size() >= 2,
"You must have at least two knots to create a spline.");
75 unsigned int k = (khi + klo) >> 1;
95 mooseError(
"The values of x must be distinct");
96 a = (x[khi] - x_int) / h;
97 b = (x_int - x[klo]) / h;
102 const std::vector<Real> & y,
103 const std::vector<Real> & y2,
106 unsigned int klo, khi;
109 return sample(x, y, y2, x_int, klo, khi);
114 const std::vector<Real> & y,
115 const std::vector<Real> & y2,
116 const ADReal & x_int)
const 118 unsigned int klo, khi;
121 return sample(x, y, y2, x_int, klo, khi);
126 const std::vector<Real> & y,
127 const std::vector<Real> & y2,
130 unsigned int klo, khi;
136 return (y[khi] - y[klo]) / h -
137 (((3.0 * a * a - 1.0) * y2[klo] + (3.0 * b * b - 1.0) * -y2[khi]) * h / 6.0);
142 const std::vector<Real> & ,
143 const std::vector<Real> & y2,
146 unsigned int klo, khi;
152 return a * y2[klo] + b * y2[khi];
155 template <
typename T>
158 const std::vector<Real> & y,
159 const std::vector<Real> & y2,
162 unsigned int khi)
const 168 return a * y[klo] + b * y[khi] +
169 ((a * a * a - a) * y2[klo] + (b * b * b - b) * y2[khi]) * (h * h) / 6.0;
172 template Real SplineInterpolationBase::sample<Real>(
const std::vector<Real> & x,
173 const std::vector<Real> & y,
174 const std::vector<Real> & y2,
177 unsigned int khi)
const;
178 template ADReal SplineInterpolationBase::sample<ADReal>(
const std::vector<Real> & x,
179 const std::vector<Real> & y,
180 const std::vector<Real> & y2,
183 unsigned int khi)
const;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Real sample2ndDerivative(const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
Real sample(const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
void computeCoeffs(const std::vector< Real > &x, unsigned int klo, unsigned int khi, const T &x_int, Real &h, T &a, T &b) const
Real sampleDerivative(const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
auto max(const L &left, const R &right)
void findInterval(const std::vector< Real > &x, Real x_int, unsigned int &klo, unsigned int &khi) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void spline(const std::vector< Real > &x, const std::vector< Real > &y, std::vector< Real > &y2, Real yp1=_deriv_bound, Real ypn=_deriv_bound)
This function calculates the second derivatives based on supplied x and y-vectors.
SplineInterpolationBase()
static const Real _deriv_bound