www.mooseframework.org
Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
SplineInterpolationBase Class Reference

#include <SplineInterpolationBase.h>

Inheritance diagram for SplineInterpolationBase:
[legend]

Public Member Functions

 SplineInterpolationBase ()
 
virtual ~SplineInterpolationBase ()=default
 
Real sample (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
 
Real sampleDerivative (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
 
Real sample2ndDerivative (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
 

Protected Member Functions

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. More...
 
void findInterval (const std::vector< Real > &x, Real x_int, unsigned int &klo, unsigned int &khi) const
 
void computeCoeffs (const std::vector< Real > &x, unsigned int klo, unsigned int khi, Real x_int, Real &h, Real &a, Real &b) const
 

Static Protected Attributes

static const Real _deriv_bound = std::numeric_limits<Real>::max()
 

Detailed Description

Definition at line 22 of file SplineInterpolationBase.h.

Constructor & Destructor Documentation

SplineInterpolationBase::SplineInterpolationBase ( )

Definition at line 21 of file SplineInterpolationBase.C.

21 {}
virtual SplineInterpolationBase::~SplineInterpolationBase ( )
virtualdefault

Member Function Documentation

void SplineInterpolationBase::computeCoeffs ( const std::vector< Real > &  x,
unsigned int  klo,
unsigned int  khi,
Real  x_int,
Real &  h,
Real &  a,
Real &  b 
) const
protected

Definition at line 89 of file SplineInterpolationBase.C.

Referenced by sample(), sample2ndDerivative(), and sampleDerivative().

96 {
97  h = x[khi] - x[klo];
98  if (h == 0)
99  mooseError("The values of x must be distinct");
100  a = (x[khi] - x_int) / h;
101  b = (x_int - x[klo]) / h;
102 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
static PetscErrorCode Vec x
void SplineInterpolationBase::findInterval ( const std::vector< Real > &  x,
Real  x_int,
unsigned int &  klo,
unsigned int &  khi 
) const
protected

Definition at line 70 of file SplineInterpolationBase.C.

Referenced by sample(), sample2ndDerivative(), and sampleDerivative().

74 {
75  klo = 0;
76  mooseAssert(x.size() >= 2, "You must have at least two knots to create a spline.");
77  khi = x.size() - 1;
78  while (khi - klo > 1)
79  {
80  unsigned int k = (khi + klo) >> 1;
81  if (x[k] > x_int)
82  khi = k;
83  else
84  klo = k;
85  }
86 }
static PetscErrorCode Vec x
Real SplineInterpolationBase::sample ( const std::vector< Real > &  x,
const std::vector< Real > &  y,
const std::vector< Real > &  y2,
Real  x_int 
) const

Definition at line 105 of file SplineInterpolationBase.C.

Referenced by BicubicSplineInterpolation::sample(), SplineInterpolation::sample(), BicubicSplineInterpolation::sample2ndDerivative(), and BicubicSplineInterpolation::sampleDerivative().

109 {
110  unsigned int klo, khi;
111  findInterval(x, x_int, klo, khi);
112 
113  Real h, a, b;
114  computeCoeffs(x, klo, khi, x_int, h, a, b);
115 
116  return a * y[klo] + b * y[khi] +
117  ((a * a * a - a) * y2[klo] + (b * b * b - b) * y2[khi]) * (h * h) / 6.0;
118 }
void findInterval(const std::vector< Real > &x, Real x_int, unsigned int &klo, unsigned int &khi) const
static PetscErrorCode Vec x
void computeCoeffs(const std::vector< Real > &x, unsigned int klo, unsigned int khi, Real x_int, Real &h, Real &a, Real &b) const
Real SplineInterpolationBase::sample2ndDerivative ( const std::vector< Real > &  x,
const std::vector< Real > &  y,
const std::vector< Real > &  y2,
Real  x_int 
) const

Definition at line 137 of file SplineInterpolationBase.C.

Referenced by BicubicSplineInterpolation::sample2ndDerivative(), and SplineInterpolation::sample2ndDerivative().

141 {
142  unsigned int klo, khi;
143  findInterval(x, x_int, klo, khi);
144 
145  Real h, a, b;
146  computeCoeffs(x, klo, khi, x_int, h, a, b);
147 
148  return a * y2[klo] + b * y2[khi];
149 }
void findInterval(const std::vector< Real > &x, Real x_int, unsigned int &klo, unsigned int &khi) const
static PetscErrorCode Vec x
void computeCoeffs(const std::vector< Real > &x, unsigned int klo, unsigned int khi, Real x_int, Real &h, Real &a, Real &b) const
Real SplineInterpolationBase::sampleDerivative ( const std::vector< Real > &  x,
const std::vector< Real > &  y,
const std::vector< Real > &  y2,
Real  x_int 
) const

Definition at line 121 of file SplineInterpolationBase.C.

Referenced by BicubicSplineInterpolation::sampleDerivative(), and SplineInterpolation::sampleDerivative().

125 {
126  unsigned int klo, khi;
127  findInterval(x, x_int, klo, khi);
128 
129  Real h, a, b;
130  computeCoeffs(x, klo, khi, x_int, h, a, b);
131 
132  return (y[khi] - y[klo]) / h -
133  (((3.0 * a * a - 1.0) * y2[klo] + (3.0 * b * b - 1.0) * -y2[khi]) * h / 6.0);
134 }
void findInterval(const std::vector< Real > &x, Real x_int, unsigned int &klo, unsigned int &khi) const
static PetscErrorCode Vec x
void computeCoeffs(const std::vector< Real > &x, unsigned int klo, unsigned int khi, Real x_int, Real &h, Real &a, Real &b) const
void SplineInterpolationBase::spline ( const std::vector< Real > &  x,
const std::vector< Real > &  y,
std::vector< Real > &  y2,
Real  yp1 = _deriv_bound,
Real  ypn = _deriv_bound 
)
protected

This function calculates the second derivatives based on supplied x and y-vectors.

Definition at line 24 of file SplineInterpolationBase.C.

Referenced by BicubicSplineInterpolation::constructColumnSplineSecondDerivativeTable(), BicubicSplineInterpolation::constructRowSplineSecondDerivativeTable(), BicubicSplineInterpolation::sample(), BicubicSplineInterpolation::sample2ndDerivative(), BicubicSplineInterpolation::sampleDerivative(), and SplineInterpolation::solve().

29 {
30  auto n = x.size();
31  if (n < 2)
32  mooseError("You must have at least two knots to create a spline.");
33 
34  std::vector<Real> u(n, 0.);
35  y2.assign(n, 0.);
36 
37  if (yp1 >= 1e30)
38  y2[0] = u[0] = 0.;
39  else
40  {
41  y2[0] = -0.5;
42  u[0] = (3.0 / (x[1] - x[0])) * ((y[1] - y[0]) / (x[1] - x[0]) - yp1);
43  }
44  // decomposition of tri-diagonal algorithm (y2 and u are used for temporary storage)
45  for (decltype(n) i = 1; i < n - 1; i++)
46  {
47  Real sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
48  Real p = sig * y2[i - 1] + 2.0;
49  y2[i] = (sig - 1.0) / p;
50  u[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]);
51  u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
52  }
53 
54  Real qn, un;
55  if (ypn >= 1e30)
56  qn = un = 0.;
57  else
58  {
59  qn = 0.5;
60  un = (3.0 / (x[n - 1] - x[n - 2])) * (ypn - (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]));
61  }
62 
63  y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.);
64  // back substitution
65  for (auto k = n - 1; k >= 1; k--)
66  y2[k - 1] = y2[k - 1] * y2[k] + u[k - 1];
67 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
static PetscErrorCode Vec x
PetscInt n

Member Data Documentation

const Real SplineInterpolationBase::_deriv_bound = std::numeric_limits<Real>::max()
staticprotected

Definition at line 64 of file SplineInterpolationBase.h.

Referenced by BicubicSplineInterpolation::errorCheck().


The documentation for this class was generated from the following files: