3.4.12. horton/grid/cubic_spline.h – One-dimensional cubic splines (on uniform grids)

Functions

void tridiagsym_solve(double *diag_mid, double *diag_up, double *right, double *solution, int n)
void solve_cubic_spline_system(double *y, double *d, int npoint)
void compute_cubic_spline_int_weights(double *weights, int npoint)
class
#include <cubic_spline.h>

Construct and use cubic splines, with optional transformation of x-axis and extrapolation rules beyond spline range.

Public Functions

CubicSpline::CubicSpline(double *y, double *dt, Extrapolation *extrapolation, RTransform *rtf, int n)

Create a CubicSpline object.

Parameters
  • y -

    An array with y-values on the grid.

  • dt -

    An array with derivatives of y toward the uniform x-axis (thus t-axis).

  • extrapolation -

    An instance of an Extrapolation subclass that describes the function outside the spline range.

  • rtf -

    The transformation from the t-axis to the x-axis.

  • n -

    The number of grid points.

void CubicSpline::eval(const double *new_x, double *new_y, int new_n)

Evaluate the cubic spline in a set of new x values.

Parameters
  • new_x -

    An array with new x values.

  • new_y -

    An output array with the corresponding y values.

  • new_n -

    The number of values in new_x.

void CubicSpline::eval_deriv(const double *new_x, double *new_dx, int new_n)

Evaluate the derivative of the cubic spline (dy/dx) in a set of new x values.

Parameters
  • new_x -

    An array with new x values.

  • new_dx -

    An output array with the corresponding dy/dx values.

  • new_n -

    The number of values in new_x.

RTransform *CubicSpline::get_rtransform()

Return the transformation of the x-axis.

double CubicSpline::get_first_x()

Return the first grid point on the x-axis (transformed coordinates).

double CubicSpline::get_last_x()

Return the last grid point on the x-axis (transformed coordinates).

Extrapolation *CubicSpline::get_extrapolation()

Return the extrapolation function used outside the spline range.

Public Members

double *CubicSpline::y

The y-values of the spline at each grid point.

double *CubicSpline::dt

The derivative towards the t-axis (uniform x-axis).

int CubicSpline::n

The number of grid points.

Private Members

Extrapolation *CubicSpline::extrapolation

Describes how function goes outside spline range.

RTransform *CubicSpline::rtf

Transformation of the x-axis.

double CubicSpline::first_x

Transformed first grid point.

double CubicSpline::last_x

Transformed last grid point.

class
#include <cubic_spline.h>

Base class for extrapolation of cubic splines outside their range.

Subclassed by CuspExtrapolation, PotentialExtrapolation, PowerExtrapolation, ZeroExtrapolation

Public Functions

Extrapolation::Extrapolation()

Constructor.

virtual Extrapolation::~Extrapolation()

Destructor.

virtual void Extrapolation::prepare(CubicSpline *cs)
= 0

Derive parameters from spline.

virtual double Extrapolation::eval_left(double x)
= 0

Compute extrapolation for low x.

virtual double Extrapolation::eval_right(double x)
= 0

Derivative of extrapolation for low x.

virtual double Extrapolation::deriv_left(double x)
= 0

Compute extrapolation for high x.

virtual double Extrapolation::deriv_right(double x)
= 0

Derivative of extrapolation for high x.

virtual bool Extrapolation::has_tail()
= 0

Returns true if right extrapolation is nonzero.

class
#include <cubic_spline.h>

No extrapolation at all. Returns zero outside the spline range.

Inherits from Extrapolation

Public Functions

void ZeroExtrapolation::prepare(CubicSpline *cs)

Derive parameters from spline.

double ZeroExtrapolation::eval_left(double x)

Compute extrapolation for low x.

double ZeroExtrapolation::eval_right(double x)

Derivative of extrapolation for low x.

double ZeroExtrapolation::deriv_left(double x)

Compute extrapolation for high x.

double ZeroExtrapolation::deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool ZeroExtrapolation::has_tail()

Returns false because tail is zero.

class
#include <cubic_spline.h>

An extrapolation suitable for electronic densities. It uses a 1s Slater-type density function close to the nucleus.

Inherits from Extrapolation

Public Functions

CuspExtrapolation::CuspExtrapolation()

Constructor.

void CuspExtrapolation::prepare(CubicSpline *cs)

Derive parameters from spline.

double CuspExtrapolation::eval_left(double x)

Compute extrapolation for low x.

double CuspExtrapolation::eval_right(double x)

Derivative of extrapolation for low x.

double CuspExtrapolation::deriv_left(double x)

Compute extrapolation for high x.

double CuspExtrapolation::deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool CuspExtrapolation::has_tail()

Returns false because tail is zero.

Private Members

double CuspExtrapolation::a0

The value of the spline at the first grid point.

double CuspExtrapolation::b0

The exponent of the 1s Slater-type function for the cusp.

double CuspExtrapolation::x0

The position of the first grid point.

class
#include <cubic_spline.h>

An extrapolation with a polynomial of arbitrary order for high x values.

The prefactor of the polynomial is such that the function remains continuous at the last grid point of the spline.

Inherits from Extrapolation

Public Functions

PowerExtrapolation::PowerExtrapolation(double power)

Construct a PowerExtrapolation.

Parameters
  • power -

    The power of the polynomial tail, i.e. extrapolation on the right.

void PowerExtrapolation::prepare(CubicSpline *cs)

Derive parameters from spline.

double PowerExtrapolation::eval_left(double x)

Compute extrapolation for low x.

double PowerExtrapolation::eval_right(double x)

Derivative of extrapolation for low x.

double PowerExtrapolation::deriv_left(double x)

Compute extrapolation for high x.

double PowerExtrapolation::deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool PowerExtrapolation::has_tail()

Returns true because if R**power tail.

double PowerExtrapolation::get_power()

The power of the polynomial tail.

Private Members

double PowerExtrapolation::amp

The prefactor of the polynomial.

double PowerExtrapolation::power

The power of the polynomial.

class
#include <cubic_spline.h>

An extrapolation suitable for solutions of the Poisson equation.

The prefactor of the left and right polynomial are such that the function remains continuous at the last grid point of the spline. The power of R on the left and right side is consistent with the boundary conditions of the solutions of the Poisson equation.

Inherits from Extrapolation

Public Functions

PotentialExtrapolation::PotentialExtrapolation(int64_t l)

Construct a PotentialExtrapolation.

Parameters
  • l -

    The angular momentum for which the Coulomb potential is generated.

void PotentialExtrapolation::prepare(CubicSpline *cs)

Derive parameters from spline.

double PotentialExtrapolation::eval_left(double x)

Compute extrapolation for low x.

double PotentialExtrapolation::eval_right(double x)

Derivative of extrapolation for low x.

double PotentialExtrapolation::deriv_left(double x)

Compute extrapolation for high x.

double PotentialExtrapolation::deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool PotentialExtrapolation::has_tail()

Returns true because if 1/R**(l+1) tail.

int64_t PotentialExtrapolation::get_l()

The angular momentum of the Coulomb potential spline.

double PotentialExtrapolation::get_amp_left()

The prefactor for the polynomial for low x.

double PotentialExtrapolation::get_amp_right()

The prefactor for the polynomial for high x.

Private Members

int64_t PotentialExtrapolation::l

The angular momentum for which the potential is computed.

double PotentialExtrapolation::amp_left

The prefactor for the polynomial for low x.

double PotentialExtrapolation::amp_right

The prefactor for the polynomial for high x.