Module responsible for table interpolations and array lookups. Contains subroutines for table interpolations, numerical derivatives of arrays and lookup functions. Subroutines are loosely based on routines implemented in the MPI-AMRVAC code.
Function for fast table-lookup, returns the corresponding y-value in y_values based on a given based on a given . If the allow_outside flag is given as .true. then values on the edge of the table are returned when the lookup value is outside the array. Uses simple linear interpolation.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | x |
value to look up |
||
real(kind=dp), | intent(in) | :: | x_values(:) |
array of x-values |
||
real(kind=dp), | intent(in) | :: | y_values(:) |
array of y-values, assuming relation |
||
logical, | optional | :: | allow_outside |
flag to allow for lookups outside of the array |
interpolated y-value based on
Interpolates a given set of tables (x, y(x)) into a smooth curve. Assumes that x_table is an array with a monotone increase in values. Interpolation is done using n_interp points, in general a second order polynomial approximation is used except near sharp jumps.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | n_interp |
number of points used for interpolation |
||
real(kind=dp), | intent(in) | :: | x_table(:) |
x-values in the table |
||
real(kind=dp), | intent(in) | :: | y_table(:) |
y-values in the table |
||
real(kind=dp), | intent(out) | :: | x_interp(n_interp) |
interpolated x-values |
||
real(kind=dp), | intent(out) | :: | y_interp(n_interp) |
interpolated y-values |
Calculates the numerical derivative of a given array. A sixth-order accurate central difference stencil is used to calculate the derivative. Near the edges a sixth-order accurate forward and backward difference stencil is used for the left and right boundary, respectively. It is assumed that the x values are all equally spaced. If this is not the case, a polynomial interpolation on a uniform grid can be done and that one can be differentiated instead. The stencils are as follows:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | x(:) |
x-values against which to differentiate |
||
real(kind=dp), | intent(in) | :: | y(:) |
array of y-values, assuming relation |
||
real(kind=dp), | intent(out) | :: | dy(size(y)) |
derivative of with respect to , same size as input arrays |
||
real(kind=dp), | intent(in), | optional | :: | dxtol |
optional tolerance for equally spaced arrays |
Calculates the second numerical derivative of a given array. A sixth-order accurate central difference stencil is used to calculate the derivative. Near the edges a sixth-order accurate forward and backward difference stencil is used for the left and right boundary, respectively. It is assumed that the x values are all equally spaced. If this is not the case, a polynomial interpolation on a uniform grid can be done and that one can be differentiated instead.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | x(:) |
x-values against which to differentiate |
||
real(kind=dp), | intent(in) | :: | y(:) |
array of y-values, assuming relation |
||
real(kind=dp), | intent(out) | :: | dy(size(y)) |
derivative of with respect to , same size as input arrays |
||
real(kind=dp), | intent(in), | optional | :: | dxtol |
optional tolerance for equally spaced arrays |