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

#include <LinearSpline.h>

Inheritance diagram for LinearSpline:
Inheritance graph
Collaboration diagram for LinearSpline:
Collaboration graph

Public Member Functions

 LinearSpline ()=default
 Default constructor.
 
 LinearSpline (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 linear 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 > m_ {}
 
std::vector< double > c_ {}
 
std::vector< double > integrals_ {}
 

Detailed Description

Definition at line 26 of file LinearSpline.h.

Constructor & Destructor Documentation

◆ LinearSpline() [1/2]

LinearSpline::LinearSpline ( )
default

Default constructor.

◆ LinearSpline() [2/2]

LinearSpline::LinearSpline ( 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 21 of file LinearSpline.cpp.

References init().

Here is the call graph for this function:

Member Function Documentation

◆ computeCoefficients()

void LinearSpline::computeCoefficients ( )
private

Compute linear spline coefficients.

Definition at line 89 of file LinearSpline.cpp.

References c_, m_, AbstractSpline::x_, and AbstractSpline::y_.

Referenced by init().

◆ computeIntegrals()

void LinearSpline::computeIntegrals ( )
private

Compute the integrals of the intervals.

Definition at line 98 of file LinearSpline.cpp.

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

Referenced by init().

Here is the call graph for this function:

◆ eval()

double LinearSpline::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 34 of file LinearSpline.cpp.

References c_, extrapolateLeft(), extrapolateRight(), AbstractSpline::findInterval(), AbstractSpline::Accelerator::last_index_, m_, and AbstractSpline::x_.

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

Here is the call graph for this function:

◆ evalIntegral()

double LinearSpline::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 LinearSpline.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 LinearSpline::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 110 of file LinearSpline.cpp.

References c_, and m_.

Referenced by eval(), and evalIntegral().

◆ extrapolateRight()

double LinearSpline::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 112 of file LinearSpline.cpp.

References c_, and m_.

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 CubicSpline::eval(), eval(), CubicSpline::evalIntegral(), and evalIntegral().

◆ init()

void LinearSpline::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 25 of file LinearSpline.cpp.

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

Referenced by LinearSpline(), and TEST_F().

Here is the call graph for this function:

◆ integral()

double LinearSpline::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 105 of file LinearSpline.cpp.

References c_, m_, and AbstractSpline::x_.

Referenced by computeIntegrals(), and evalIntegral().

Member Data Documentation

◆ c_

std::vector<double> LinearSpline::c_ {}
private

Definition at line 79 of file LinearSpline.h.

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

◆ integrals_

std::vector<double> LinearSpline::integrals_ {}
private

Definition at line 80 of file LinearSpline.h.

Referenced by computeIntegrals(), and evalIntegral().

◆ m_

std::vector<double> LinearSpline::m_ {}
private

Definition at line 78 of file LinearSpline.h.

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

◆ x_

◆ y_


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