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 CubicSpline
#include <cubic_spline.h>

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

Public Functions

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 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 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 *get_rtransform()

Return the transformation of the x-axis.

double get_first_x()

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

double get_last_x()

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

Extrapolation *get_extrapolation()

Return the extrapolation function used outside the spline range.

Public Members

double *y

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

double *dt

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

int n

The number of grid points.

Private Members

Extrapolation *extrapolation

Describes how function goes outside spline range.

RTransform *rtf

Transformation of the x-axis.

double first_x

Transformed first grid point.

double last_x

Transformed last grid point.

class Extrapolation
#include <cubic_spline.h>

Base class for extrapolation of cubic splines outside their range.

Public Functions

Extrapolation()

Constructor.

virtual ~Extrapolation()

Destructor.

virtual void prepare(CubicSpline *cs) = 0

Derive parameters from spline.

virtual double eval_left(double x) = 0

Compute extrapolation for low x.

virtual double eval_right(double x) = 0

Derivative of extrapolation for low x.

virtual double deriv_left(double x) = 0

Compute extrapolation for high x.

virtual double deriv_right(double x) = 0

Derivative of extrapolation for high x.

virtual bool has_tail() = 0

Returns true if right extrapolation is nonzero.

class ZeroExtrapolation
#include <cubic_spline.h>

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

Public Functions

virtual void prepare(CubicSpline *cs)

Derive parameters from spline.

virtual double eval_left(double x)

Compute extrapolation for low x.

virtual double eval_right(double x)

Derivative of extrapolation for low x.

virtual double deriv_left(double x)

Compute extrapolation for high x.

virtual double deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool has_tail()

Returns false because tail is zero.

class CuspExtrapolation
#include <cubic_spline.h>

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

Public Functions

CuspExtrapolation()

Constructor.

virtual void prepare(CubicSpline *cs)

Derive parameters from spline.

virtual double eval_left(double x)

Compute extrapolation for low x.

virtual double eval_right(double x)

Derivative of extrapolation for low x.

virtual double deriv_left(double x)

Compute extrapolation for high x.

virtual double deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool has_tail()

Returns false because tail is zero.

Private Members

double a0

The value of the spline at the first grid point.

double b0

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

double x0

The position of the first grid point.

class PowerExtrapolation
#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.

Public Functions

PowerExtrapolation(double power)

Construct a PowerExtrapolation.

Parameters
  • power -

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

virtual void prepare(CubicSpline *cs)

Derive parameters from spline.

virtual double eval_left(double x)

Compute extrapolation for low x.

virtual double eval_right(double x)

Derivative of extrapolation for low x.

virtual double deriv_left(double x)

Compute extrapolation for high x.

virtual double deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool has_tail()

Returns true because if R**power tail.

double get_power()

The power of the polynomial tail.

Private Members

double amp

The prefactor of the polynomial.

double power

The power of the polynomial.

class PotentialExtrapolation
#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.

Public Functions

PotentialExtrapolation(int64_t l)

Construct a PotentialExtrapolation.

Parameters
  • l -

    The angular momentum for which the Coulomb potential is generated.

virtual void prepare(CubicSpline *cs)

Derive parameters from spline.

virtual double eval_left(double x)

Compute extrapolation for low x.

virtual double eval_right(double x)

Derivative of extrapolation for low x.

virtual double deriv_left(double x)

Compute extrapolation for high x.

virtual double deriv_right(double x)

Derivative of extrapolation for high x.

virtual bool has_tail()

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

int64_t get_l()

The angular momentum of the Coulomb potential spline.

double get_amp_left()

The prefactor for the polynomial for low x.

double get_amp_right()

The prefactor for the polynomial for high x.

Private Members

int64_t l

The angular momentum for which the potential is computed.

double amp_left

The prefactor for the polynomial for low x.

double amp_right

The prefactor for the polynomial for high x.