OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
CubicSpline Class Referencefinal

Natural cubic spline interpolator. More...

#include <CubicSpline.h>

Inheritance diagram for CubicSpline:
Inheritance graph
Collaboration diagram for CubicSpline:
Collaboration graph

Public Member Functions

 CubicSpline ()=default
 Default constructor.
 
 CubicSpline (const std::vector< double > &x, const std::vector< double > &y)
 Construct and initialize from tabulated data.
 
void init (const std::vector< double > &x, const std::vector< double > &y) override
 Initialize from tabulated data (natural spline).
 
double eval (double x, Accelerator &accel) const override
 Evaluate the spline at x using an accelerator.
 
double evalIntegral (double xa, double xb, Accelerator &accel) const override
 Evaluate the integral of the spline at x.
 

Protected Member Functions

size_t findInterval (double x, size_t &intervalCache) const
 Return the interval index for the given x-coordinate, using the supplied cached value if possible.
 

Protected Attributes

std::vector< double > x_ {}
 
std::vector< double > y_ {}
 

Private Member Functions

void computeCoefficients ()
 Compute natural spline coefficients.
 
void computeIntegrals ()
 Compute the integrals of the intervals.
 
double integral (size_t i, double dx) const
 Calculate the integral from x_[i] to x_[i]+dx.
 
double extrapolateLeft (double x) const
 Linear extrapolation to the left of the data range.
 
double extrapolateRight (double x) const
 Linear extrapolation to the right of the data range.
 

Private Attributes

std::vector< double > b_
 
std::vector< double > c_
 
std::vector< double > d_
 
std::vector< double > integrals_
 

Detailed Description

Natural cubic spline interpolator.

See also
https://www.gnu.org/software/gsl/doc/html/interp.html
https://www.gnu.org/software/gsl/

Definition at line 28 of file CubicSpline.h.

Constructor & Destructor Documentation

◆ CubicSpline() [1/2]

CubicSpline::CubicSpline ( )
default

Default constructor.

◆ CubicSpline() [2/2]

CubicSpline::CubicSpline ( const std::vector< double > &  x,
const std::vector< double > &  y 
)

Construct and initialize from tabulated data.

Parameters
xInput: strictly increasing x-coordinates.
yInput: y-values corresponding to x.

Definition at line 20 of file CubicSpline.cpp.

References init().

Here is the call graph for this function:

Member Function Documentation

◆ computeCoefficients()

void CubicSpline::computeCoefficients ( )
private

Compute natural spline coefficients.

Definition at line 88 of file CubicSpline.cpp.

References b_, c_, d_, AbstractSpline::x_, and AbstractSpline::y_.

Referenced by init().

◆ computeIntegrals()

void CubicSpline::computeIntegrals ( )
private

Compute the integrals of the intervals.

Definition at line 124 of file CubicSpline.cpp.

References integral(), integrals_, and AbstractSpline::x_.

Referenced by init().

Here is the call graph for this function:

◆ eval()

double CubicSpline::eval ( double  x,
Accelerator accel 
) const
overridevirtual

Evaluate the spline at x using an accelerator.

Parameters
xInput: x-coordinate.
accelInput/Output: cached interval index.
Returns
Output: interpolated value.

Implements AbstractSpline.

Definition at line 33 of file CubicSpline.cpp.

References b_, c_, d_, extrapolateLeft(), extrapolateRight(), AbstractSpline::findInterval(), AbstractSpline::Accelerator::last_index_, AbstractSpline::x_, and AbstractSpline::y_.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the call graph for this function:

◆ evalIntegral()

double CubicSpline::evalIntegral ( double  xa,
double  xb,
Accelerator accel 
) const
overridevirtual

Evaluate the integral of the spline at x.

Parameters
xaInput: x-coordinate lower bound.
xbInput: x-coordinate upper bound.
accelInput/output: accelerator for interval caching.
Returns
Output: interpolated integral value (with linear extrapolation).

Implements AbstractSpline.

Definition at line 50 of file CubicSpline.cpp.

References extrapolateLeft(), extrapolateRight(), AbstractSpline::findInterval(), integral(), integrals_, AbstractSpline::Accelerator::last_index_, AbstractSpline::Accelerator::last_upper_index_, AbstractSpline::x_, and AbstractSpline::y_.

Referenced by TEST_F().

Here is the call graph for this function:

◆ extrapolateLeft()

double CubicSpline::extrapolateLeft ( double  x) const
private

Linear extrapolation to the left of the data range.

Parameters
xInput: x-coordinate.
Returns
Output: extrapolated value.

Definition at line 136 of file CubicSpline.cpp.

References b_, AbstractSpline::x_, and AbstractSpline::y_.

Referenced by eval(), and evalIntegral().

◆ extrapolateRight()

double CubicSpline::extrapolateRight ( double  x) const
private

Linear extrapolation to the right of the data range.

Parameters
xInput: x-coordinate.
Returns
Output: extrapolated value.

Definition at line 141 of file CubicSpline.cpp.

References b_, AbstractSpline::x_, and AbstractSpline::y_.

Referenced by eval(), and evalIntegral().

◆ findInterval()

size_t AbstractSpline::findInterval ( double  x,
size_t &  intervalCache 
) const
protectedinherited

Return the interval index for the given x-coordinate, using the supplied cached value if possible.

Parameters
xInput: x-coordinate.
intervalCacheInput/output: The cached interval index.
Returns
Output: The index of the interval containing x.

Definition at line 39 of file AbstractSpline.cpp.

References AbstractSpline::x_.

Referenced by eval(), LinearSpline::eval(), evalIntegral(), and LinearSpline::evalIntegral().

◆ init()

void CubicSpline::init ( const std::vector< double > &  x,
const std::vector< double > &  y 
)
overridevirtual

Initialize from tabulated data (natural spline).

Parameters
xInput: strictly increasing x-coordinates.
yInput: y-values corresponding to x.

Reimplemented from AbstractSpline.

Definition at line 24 of file CubicSpline.cpp.

References computeCoefficients(), computeIntegrals(), and AbstractSpline::init().

Referenced by CubicSpline(), and TEST_F().

Here is the call graph for this function:

◆ integral()

double CubicSpline::integral ( size_t  i,
double  dx 
) const
private

Calculate the integral from x_[i] to x_[i]+dx.

Parameters
iInput: the interval index
dxInput: the distance in the interval over which to calculate
Returns
Output: The integral.

Definition at line 131 of file CubicSpline.cpp.

References b_, c_, d_, and AbstractSpline::y_.

Referenced by computeIntegrals(), and evalIntegral().

Member Data Documentation

◆ b_

std::vector<double> CubicSpline::b_
private

Definition at line 79 of file CubicSpline.h.

Referenced by computeCoefficients(), eval(), extrapolateLeft(), extrapolateRight(), and integral().

◆ c_

std::vector<double> CubicSpline::c_
private

Definition at line 80 of file CubicSpline.h.

Referenced by computeCoefficients(), eval(), and integral().

◆ d_

std::vector<double> CubicSpline::d_
private

Definition at line 81 of file CubicSpline.h.

Referenced by computeCoefficients(), eval(), and integral().

◆ integrals_

std::vector<double> CubicSpline::integrals_
private

Definition at line 82 of file CubicSpline.h.

Referenced by computeIntegrals(), and evalIntegral().

◆ x_

◆ y_

std::vector<double> AbstractSpline::y_ {}
protectedinherited

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