ASCOT5
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
interp.h File Reference

Spline interpolation library. More...

#include "../offload_acc_omp.h"
#include "../ascot5.h"
#include "../error.h"

Go to the source code of this file.

Data Structures

struct  interp1D_data
 Cubic interpolation struct. More...
 
struct  interp2D_data
 Bicubic interpolation struct. More...
 
struct  interp3D_data
 Tricubic interpolation struct. More...
 

Enumerations

enum  boundaryCondition { NATURALBC = 0 , PERIODICBC = 1 }
 Boundary conditions for the spline interpolation. More...
 
enum  splinesize {
  NSIZE_COMP1D = 2 , NSIZE_COMP2D = 4 , NSIZE_COMP3D = 8 , NSIZE_EXPL1D = 4 ,
  NSIZE_EXPL2D = 16 , NSIZE_EXPL3D = 64
}
 Number of coefficients stored for each data point. More...
 

Functions

int interp1Dcomp_init_coeff (real *c, real *f, int n_x, int bc_x, real x_min, real x_max)
 Calculate cubic spline interpolation coefficients for scalar 1D data.
 
int interp2Dcomp_init_coeff (real *c, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
 Calculate bicubic spline interpolation coefficients for scalar 2D data.
 
int interp3Dcomp_init_coeff (real *c, real *f, int n_x, int n_y, int n_z, int bc_x, int bc_y, int bc_z, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max)
 Calculate tricubic spline interpolation coefficients for 3D data.
 
int interp1Dexpl_init_coeff (real *c, real *f, int n_x, int bc_x, real x_min, real x_max)
 Calculate cubic spline interpolation coefficients for scalar 1D data.
 
int interp2Dexpl_init_coeff (real *c, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
 Calculate bicubic spline interpolation coefficients for scalar 2D data.
 
int interp3Dexpl_init_coeff (real *c, real *f, int n_x, int n_y, int n_z, int bc_x, int bc_y, int bc_z, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max)
 Calculate tricubic spline interpolation coefficients for 3D data.
 
void interp1Dcomp_init_spline (interp1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
 Initialize a cubic spline.
 
void interp2Dcomp_init_spline (interp2D_data *str, real *c, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
 Initialize a bicubic spline.
 
void interp3Dcomp_init_spline (interp3D_data *str, real *c, int n_x, int n_y, int n_z, int bc_x, int bc_y, int bc_z, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max)
 Initialize a tricubic spline.
 
void interp1Dexpl_init_spline (interp1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
 Initialize a cubic spline.
 
void interp2Dexpl_init_spline (interp2D_data *str, real *c, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
 Initialize a bicubic spline.
 
void interp3Dexpl_init_spline (interp3D_data *str, real *c, int n_x, int n_y, int n_z, int bc_x, int bc_y, int bc_z, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max)
 Initialize a tricubic spline.
 
a5err interp1Dcomp_eval_f (real *f, interp1D_data *str, real x)
 Evaluate interpolated value of 1D scalar field.
 
DECLARE_TARGET_END a5err interp2Dcomp_eval_f (real *f, interp2D_data *str, real x, real y)
 Evaluate interpolated value of a 2D field.
 
DECLARE_TARGET_END a5err interp3Dcomp_eval_f (real *f, interp3D_data *str, real x, real y, real z)
 Evaluate interpolated value of 3D scalar field.
 
DECLARE_TARGET_END a5err interp1Dexpl_eval_f (real *f, interp1D_data *str, real x)
 Evaluate interpolated value of 1D scalar field.
 
a5err interp2Dexpl_eval_f (real *f, interp2D_data *str, real x, real y)
 Evaluate interpolated value of 2D scalar field.
 
a5err interp3Dexpl_eval_f (real *f, interp3D_data *str, real x, real y, real z)
 Evaluate interpolated value of 3D scalar field.
 
a5err interp1Dcomp_eval_df (real *f_df, interp1D_data *str, real x)
 Evaluate interpolated value of 1D and its 1st and 2nd derivatives.
 
DECLARE_TARGET_END a5err interp2Dcomp_eval_df (real *f_df, interp2D_data *str, real x, real y)
 Evaluate interpolated value and 1st and 2nd derivatives of 2D field.
 
DECLARE_TARGET_END a5err interp3Dcomp_eval_df (real *f_df, interp3D_data *str, real x, real y, real z)
 Evaluate interpolated value of 3D field and 1st and 2nd derivatives.
 
DECLARE_TARGET_END a5err interp1Dexpl_eval_df (real *f_df, interp1D_data *str, real x)
 Evaluate interpolated value of 1D and its 1st and 2nd derivatives.
 
a5err interp2Dexpl_eval_df (real *f_df, interp2D_data *str, real x, real y)
 Evaluate interpolated value and 1st and 2nd derivatives of 2D field.
 
a5err interp3Dexpl_eval_df (real *f_df, interp3D_data *str, real x, real y, real z)
 Evaluate interpolated value of 3D field and 1st and 2nd derivatives.
 

Detailed Description

Spline interpolation library.

Spline interpolation fits cubic splines on data given on a uniform grid. Each axis may have either natural or periodic boundary condition.

There exists two representations for the splines: compact and explicit. Both give identical results but the difference is that compact requires fewer coefficients to be stored (and fetched from the memory at each evaluation) than the explicit. On the other hand, explicit requires less computations per evaluations, but compact is usually faster, and conserves memory, especially in 3D. Therefore compact splines are preferred.

To initialize splines, first call corresponding init_coeff() function which evaluates coefficients to a pre-allocated array (i.e. to the offload array). Then (after offloading is done) call init_spline() which assigns the coefficients to a spline struct.

In order to allocate the array for storing the coefficients, one needs to know how many coefficients are stored per data grid point:

Definition in file interp.h.

Enumeration Type Documentation

◆ boundaryCondition

Boundary conditions for the spline interpolation.

Enumerator
NATURALBC 

Second derivative is zero at both ends

PERIODICBC 

Function has same value and derivatives at both ends

Definition at line 36 of file interp.h.

◆ splinesize

enum splinesize

Number of coefficients stored for each data point.

Definition at line 44 of file interp.h.

Function Documentation

◆ interp1Dcomp_init_coeff()

int interp1Dcomp_init_coeff ( real * c,
real * f,
int n_x,
int bc_x,
real x_min,
real x_max )

Calculate cubic spline interpolation coefficients for scalar 1D data.

This function calculates the cubic spline interpolation coefficients and stores them in a pre-allocated array. Compact cofficients are calculated.

Parameters
callocated array of length n_x*2 to store the coefficients
f1D data to be interpolated
n_xnumber of data points in the x axis
bc_xboundary condition for the x axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis

Definition at line 25 of file interp1Dcomp.c.

◆ interp2Dcomp_init_coeff()

int interp2Dcomp_init_coeff ( real * c,
real * f,
int n_x,
int n_y,
int bc_x,
int bc_y,
real x_min,
real x_max,
real y_min,
real y_max )

Calculate bicubic spline interpolation coefficients for scalar 2D data.

This function calculates the bicubic spline interpolation coefficients and stores them in a pre-allocated array. Compact cofficients are calculated.

For each data point four coefficients are stored for spline-interpolation.

Parameters
callocated array of length n_y*n_x*4 to store the coefficients
f2D data to be interpolated
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
bc_xboundary condition for x axis (0) natural (1) periodic
bc_yboundary condition for y axis (0) natural (1) periodic
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis
Returns
zero if initialization succeeded

Definition at line 33 of file interp2Dcomp.c.

◆ interp3Dcomp_init_coeff()

int interp3Dcomp_init_coeff ( real * c,
real * f,
int n_x,
int n_y,
int n_z,
int bc_x,
int bc_y,
int bc_z,
real x_min,
real x_max,
real y_min,
real y_max,
real z_min,
real z_max )

Calculate tricubic spline interpolation coefficients for 3D data.

This function calculates the tricubic spline interpolation coefficients for the given data and stores them in an array. Compact cofficients are calculated.

Parameters
callocated array of length n_z*n_y*n_x*8 to store the coefficients
f3D data to be interpolated
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
n_znumber of data points in the z direction
bc_xboundary condition for x axis
bc_yboundary condition for y axis
bc_zboundary condition for z axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis
z_minminimum value of the z axis
z_maxmaximum value of the z axis
Returns
zero if initialization succeeded

Definition at line 37 of file interp3Dcomp.c.

◆ interp1Dexpl_init_coeff()

int interp1Dexpl_init_coeff ( real * c,
real * f,
int n_x,
int bc_x,
real x_min,
real x_max )

Calculate cubic spline interpolation coefficients for scalar 1D data.

This function calculates the cubic spline interpolation coefficients and stores them in a pre-allocated array. Explicit cofficients are calculated.

Parameters
callocated array of length n_x*4 to store the coefficients
f1D data to be interpolated
n_xnumber of data points in the x axis
bc_xboundary condition for the x axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis

Definition at line 25 of file interp1Dexpl.c.

◆ interp2Dexpl_init_coeff()

int interp2Dexpl_init_coeff ( real * c,
real * f,
int n_x,
int n_y,
int bc_x,
int bc_y,
real x_min,
real x_max,
real y_min,
real y_max )

Calculate bicubic spline interpolation coefficients for scalar 2D data.

This function calculates the bicubic spline interpolation coefficients and stores them in a pre-allocated array. Explicit cofficients are calculated.

For each data point four coefficients are stored for spline-interpolation.

Parameters
callocated array of length n_y*n_x*16 to store the coefficients
f2D data to be interpolated
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
bc_xboundary condition for x axis (0) natural (1) periodic
bc_yboundary condition for y axis (0) natural (1) periodic
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis
Returns
zero if initialization succeeded

Definition at line 33 of file interp2Dexpl.c.

◆ interp3Dexpl_init_coeff()

int interp3Dexpl_init_coeff ( real * c,
real * f,
int n_x,
int n_y,
int n_z,
int bc_x,
int bc_y,
int bc_z,
real x_min,
real x_max,
real y_min,
real y_max,
real z_min,
real z_max )

Calculate tricubic spline interpolation coefficients for 3D data.

This function calculates the tricubic spline interpolation coefficients for the given data and stores them in an array. Explicit cofficients are calculated.

Parameters
callocated array of length n_z*n_y*n_x*64 to store the coefficients
f3D data to be interpolated
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
n_znumber of data points in the z direction
bc_xboundary condition for x axis
bc_yboundary condition for y axis
bc_zboundary condition for z axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis
z_minminimum value of the z axis
z_maxmaximum value of the z axis
Returns
zero if initialization succeeded

Definition at line 37 of file interp3Dexpl.c.

◆ interp1Dcomp_init_spline()

void interp1Dcomp_init_spline ( interp1D_data * str,
real * c,
int n_x,
int bc_x,
real x_min,
real x_max )

Initialize a cubic spline.

Parameters
strpointer to spline to be initialized
carray where coefficients are stored
n_xnumber of data points in the x direction
bc_xboundary condition for x axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis

Definition at line 68 of file interp1Dcomp.c.

◆ interp2Dcomp_init_spline()

void interp2Dcomp_init_spline ( interp2D_data * str,
real * c,
int n_x,
int n_y,
int bc_x,
int bc_y,
real x_min,
real x_max,
real y_min,
real y_max )

Initialize a bicubic spline.

Parameters
strpointer to spline to be initialized
carray where coefficients are stored
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
bc_xboundary condition for x axis
bc_yboundary condition for y axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis

Definition at line 130 of file interp2Dcomp.c.

◆ interp3Dcomp_init_spline()

void interp3Dcomp_init_spline ( interp3D_data * str,
real * c,
int n_x,
int n_y,
int n_z,
int bc_x,
int bc_y,
int bc_z,
real x_min,
real x_max,
real y_min,
real y_max,
real z_min,
real z_max )

Initialize a tricubic spline.

Parameters
strpointer to spline to be initialized
carray where coefficients are stored
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
n_znumber of data points in the z direction
bc_xboundary condition for x axis
bc_yboundary condition for y axis
bc_zboundary condition for z axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis
z_minminimum value of the z axis
z_maxmaximum value of the z axis

Definition at line 203 of file interp3Dcomp.c.

◆ interp1Dexpl_init_spline()

void interp1Dexpl_init_spline ( interp1D_data * str,
real * c,
int n_x,
int bc_x,
real x_min,
real x_max )

Initialize a cubic spline.

Parameters
strpointer to spline to be initialized
carray where coefficients are stored
n_xnumber of data points in the x direction
bc_xboundary condition for x axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis

Definition at line 52 of file interp1Dexpl.c.

◆ interp2Dexpl_init_spline()

void interp2Dexpl_init_spline ( interp2D_data * str,
real * c,
int n_x,
int n_y,
int bc_x,
int bc_y,
real x_min,
real x_max,
real y_min,
real y_max )

Initialize a bicubic spline.

Parameters
strpointer to spline to be initialized
carray where coefficients are stored
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
bc_xboundary condition for x axis
bc_yboundary condition for y axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis

Definition at line 108 of file interp2Dexpl.c.

◆ interp3Dexpl_init_spline()

void interp3Dexpl_init_spline ( interp3D_data * str,
real * c,
int n_x,
int n_y,
int n_z,
int bc_x,
int bc_y,
int bc_z,
real x_min,
real x_max,
real y_min,
real y_max,
real z_min,
real z_max )

Initialize a tricubic spline.

Parameters
strpointer to spline to be initialized
carray where coefficients are stored
n_xnumber of data points in the x direction
n_ynumber of data points in the y direction
n_znumber of data points in the z direction
bc_xboundary condition for x axis
bc_yboundary condition for y axis
bc_zboundary condition for z axis
x_minminimum value of the x axis
x_maxmaximum value of the x axis
y_minminimum value of the y axis
y_maxmaximum value of the y axis
z_minminimum value of the z axis
z_maxmaximum value of the z axis

Definition at line 153 of file interp3Dexpl.c.

◆ interp1Dcomp_eval_f()

a5err interp1Dcomp_eval_f ( real * f,
interp1D_data * str,
real x )

Evaluate interpolated value of 1D scalar field.

This function evaluates the interpolated value of a 1D scalar field using bicubic spline interpolation coefficients of the compact form.

Parameters
fvariable in which to place the evaluated value
strdata struct for data interpolation
xx-coordinate
Returns
zero on success and one if x point is outside the domain.

Definition at line 97 of file interp1Dcomp.c.

◆ interp2Dcomp_eval_f()

DECLARE_TARGET_END a5err interp2Dcomp_eval_f ( real * f,
interp2D_data * str,
real x,
real y )

Evaluate interpolated value of a 2D field.

This function evaluates the interpolated value of a 2D scalar field using bicubic spline interpolation coefficients of the compact form.

Parameters
fvariable in which to place the evaluated value
strdata struct for data interpolation
xx-coordinate
yy-coordinate
Returns
zero on success and one if (x,y) point is outside the domain.

Definition at line 168 of file interp2Dcomp.c.

◆ interp3Dcomp_eval_f()

DECLARE_TARGET_END a5err interp3Dcomp_eval_f ( real * f,
interp3D_data * str,
real x,
real y,
real z )

Evaluate interpolated value of 3D scalar field.

This function evaluates the interpolated value of a 3D scalar field using tricubic spline interpolation coefficients of the compact form.

Parameters
fvariable in which to place the evaluated value
strdata struct for data interpolation
xx-coordinate
yy-coordinate
zz-coordinate
Returns
zero on success and one if (x,y,z) point is outside the grid.

< Index jump to cell

Definition at line 250 of file interp3Dcomp.c.

◆ interp1Dexpl_eval_f()

DECLARE_TARGET_END a5err interp1Dexpl_eval_f ( real * f,
interp1D_data * str,
real x )

Evaluate interpolated value of 1D scalar field.

This function evaluates the interpolated value of a 1D scalar field using bicubic spline interpolation coefficients of the explicit form.

Parameters
fvariable in which to place the evaluated value
strdata struct for data interpolation
xx-coordinate
Returns
zero on success and one if x point is outside the domain.

Definition at line 81 of file interp1Dexpl.c.

◆ interp2Dexpl_eval_f()

a5err interp2Dexpl_eval_f ( real * f,
interp2D_data * str,
real x,
real y )

Evaluate interpolated value of 2D scalar field.

This function evaluates the interpolated value of a 2D scalar field using bicubic spline interpolation coefficients of the explicit form.

Parameters
fvariable in which to place the evaluated value
strdata struct for data interpolation
xx-coordinate
yy-coordinate
Returns
zero on success and one if (x,y) point is outside the domain.

Definition at line 146 of file interp2Dexpl.c.

◆ interp3Dexpl_eval_f()

a5err interp3Dexpl_eval_f ( real * f,
interp3D_data * str,
real x,
real y,
real z )

Evaluate interpolated value of 3D scalar field.

This function evaluates the interpolated value of a 3D scalar field using tricubic spline interpolation coefficients of the explicit form.

Parameters
fvariable in which to place the evaluated value
strdata struct for data interpolation
xx-coordinate
yy-coordinate
zz-coordinate
Returns
zero on success and one if (x,y,z) point is outside the grid.

< Index jump to cell

Definition at line 200 of file interp3Dexpl.c.

◆ interp1Dcomp_eval_df()

a5err interp1Dcomp_eval_df ( real * f_df,
interp1D_data * str,
real x )

Evaluate interpolated value of 1D and its 1st and 2nd derivatives.

This function evaluates the interpolated value of a 1D scalar field and its 1st and 2nd derivatives using bicubic spline interpolation coefficients of the compact form.

The evaluated values are returned in an array with following elements:

  • f_df[0] = f
  • f_df[1] = f_x
  • f_df[2] = f_xx
Parameters
f_dfarray in which to place the evaluated values
strdata struct for data interpolation
xx-coordinate
Returns
zero on success and one if (x,y) point is outside the grid.

< Normalized x coordinate in current cell

Definition at line 155 of file interp1Dcomp.c.

◆ interp2Dcomp_eval_df()

DECLARE_TARGET_END a5err interp2Dcomp_eval_df ( real * f_df,
interp2D_data * str,
real x,
real y )

Evaluate interpolated value and 1st and 2nd derivatives of 2D field.

This function evaluates the interpolated value of a 2D scalar field and its 1st and 2nd derivatives using bicubic spline interpolation coefficients of the compact form.

The evaluated values are returned in an array with following elements:

  • f_df[0] = f
  • f_df[1] = f_x
  • f_df[2] = f_y
  • f_df[3] = f_xx
  • f_df[4] = f_yy
  • f_df[5] = f_xy
Parameters
f_dfarray in which to place the evaluated values
strdata struct for data interpolation
xx-coordinate
yy-coordinate
Returns
zero on success and one if (x,y) point is outside the grid.

< Index jump to cell

< Index jump one x forward

< Index jump one y forward

Definition at line 260 of file interp2Dcomp.c.

◆ interp3Dcomp_eval_df()

DECLARE_TARGET_END a5err interp3Dcomp_eval_df ( real * f_df,
interp3D_data * str,
real x,
real y,
real z )

Evaluate interpolated value of 3D field and 1st and 2nd derivatives.

This function evaluates the interpolated value of a 3D scalar field and its 1st and 2nd derivatives using bicubic spline interpolation coefficients of the compact form.

The evaluated values are returned in an array with following elements:

  • f_df[0] = f
  • f_df[1] = f_x
  • f_df[2] = f_y
  • f_df[3] = f_z
  • f_df[4] = f_xx
  • f_df[5] = f_yy
  • f_df[6] = f_zz
  • f_df[7] = f_xy
  • f_df[8] = f_xz
  • f_df[9] = f_yz
Parameters
f_dfarray in which to place the evaluated values
strdata struct for data interpolation
xx-coordinate
yy-coordinate
zz-coordinate
Returns
zero on success and one if (x,y,z) point is outside the grid.

Definition at line 416 of file interp3Dcomp.c.

◆ interp1Dexpl_eval_df()

DECLARE_TARGET_END a5err interp1Dexpl_eval_df ( real * f_df,
interp1D_data * str,
real x )

Evaluate interpolated value of 1D and its 1st and 2nd derivatives.

This function evaluates the interpolated value of a 1D scalar field and its 1st and 2nd derivatives using bicubic spline interpolation coefficients of the explicit form.

The evaluated values are returned in an array with following elements:

  • f_df[0] = f
  • f_df[1] = f_x
  • f_df[2] = f_xx
Parameters
f_dfarray in which to place the evaluated values
strdata struct for data interpolation
xx-coordinate
Returns
zero on success and one if (x,y) point is outside the grid.

Definition at line 131 of file interp1Dexpl.c.

◆ interp2Dexpl_eval_df()

a5err interp2Dexpl_eval_df ( real * f_df,
interp2D_data * str,
real x,
real y )

Evaluate interpolated value and 1st and 2nd derivatives of 2D field.

This function evaluates the interpolated value of a 2D scalar field and its 1st and 2nd derivatives using bicubic spline interpolation coefficients of the explicit form.

The evaluated values are returned in an array with following elements:

  • f_df[0] = f
  • f_df[1] = f_x
  • f_df[2] = f_y
  • f_df[3] = f_xx
  • f_df[4] = f_yy
  • f_df[5] = f_xy
Parameters
f_dfarray in which to place the evaluated values
strdata struct for data interpolation
xx-coordinate
yy-coordinate

Definition at line 220 of file interp2Dexpl.c.

◆ interp3Dexpl_eval_df()

a5err interp3Dexpl_eval_df ( real * f_df,
interp3D_data * str,
real x,
real y,
real z )

Evaluate interpolated value of 3D field and 1st and 2nd derivatives.

This function evaluates the interpolated value of a 3D scalar field and its 1st and 2nd derivatives using bicubic spline interpolation coefficients of the explicit form.

The evaluated values are returned in an array with following elements:

  • f_df[0] = f
  • f_df[1] = f_x
  • f_df[2] = f_y
  • f_df[3] = f_z
  • f_df[4] = f_xx
  • f_df[5] = f_yy
  • f_df[6] = f_zz
  • f_df[7] = f_xy
  • f_df[8] = f_xz
  • f_df[9] = f_yz
Parameters
f_dfarray in which to place the evaluated values
strdata struct for data interpolation
xx-coordinate
yy-coordinate
zz-coordinate
Returns
zero on success and one if (x,y,z) point is outside the grid.

Definition at line 340 of file interp3Dexpl.c.