mod_interpolation Module

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.



Contents


Functions

public function lookup_table_value(x, x_values, y_values, allow_outside) result(y_found)

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.

Arguments

TypeIntentOptionalAttributesName
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

Return Value real(kind=dp)

interpolated y-value based on


Subroutines

public subroutine interpolate_table(n_interp, x_table, y_table, x_interp, y_interp)

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.

Read more…

Arguments

TypeIntentOptionalAttributesName
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

public subroutine get_numerical_derivative(x, y, dy, dxtol)

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:

Read more…

Arguments

TypeIntentOptionalAttributesName
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