Finite Difference Coefficients
This module determines finite difference coefficients for uniform and non-uniform grids for any desired even accuracy order.
Most important function:
coefficients(deriv, acc=None, offsets=None, symbolic=False)
to calculate the finite difference coefficients for a given derivative order and given accuracy order to given offsets.
- findiff.coefs.calc_coefs(deriv, offsets, symbolic=False, analytic_inv=False, alphas=None)
The working horse for calculating finite difference coefficients on equidistant grids.
- Args:
- deriv: int
The order of the derivative.
- offsets: list of ints
Which neighboring points to use.
- symbolic: bool
Compute symbolically or numerically.
- analytic_inv: bool
Use analytic inverse for Vandermonde matrix or numerical.
- alphas: dict
Specifies the implicit scheme to use (the left hand side of the system equation in CompactScheme). If None, normal (explicit) finite differences will be used.
- Returns:
A dict describing the finite difference scheme.
- findiff.coefs.calc_coefs_non_uni_batched(deriv, acc, coords)
Compute FD coefficients for all points on a non-uniform grid using batched linear algebra.
Instead of solving one linear system per grid point, this groups points by stencil type (forward/central/backward) and solves all systems in each group with a single batched
np.linalg.solvecall.- Parameters:
deriv – int > 0: The derivative order.
acc – even int > 0: The accuracy order.
coords – 1D numpy.ndarray: the coordinates of the axis.
- Returns:
dict with ‘forward’, ‘backward’, ‘center’ keys plus ‘num_bndry’. Each scheme dict contains ‘coefficients’ (2D array) and ‘offsets’ (1D array).
- findiff.coefs.coefficients(deriv, acc=None, offsets=None, symbolic=False, analytic_inv=False)
Calculates the finite difference coefficients for given derivative order and accuracy order.
If acc is given, the coefficients are calculated for central, forward and backward schemes resulting in the specified accuracy order.
If offsets are given, the coefficients are calculated for the offsets as specified and the resulting accuracy order is computed.
Either acc or offsets must be given.
Assumes that the underlying grid is uniform. This function is available at the findiff package level.
- Parameters:
deriv (int > 0) – The derivative order.
acc (even int > 0:) – The accuracy order.
offsets (list of ints) – The offsets for which to calculate the coefficients.
- Raises:
ValueError – if invalid arguments are given
- Returns:
dict with the finite difference coefficients and corresponding offsets
- findiff.coefs.coefficients_non_uni(deriv, acc, coords, idx)
Calculates the finite difference coefficients for given derivative order and accuracy order. Assumes that the underlying grid is non-uniform.
- Parameters:
deriv – int > 0: The derivative order.
acc – even int > 0: The accuracy order.
coords – 1D numpy.ndarray: the coordinates of the axis for the partial derivative
idx – int: index of the grid position where to calculate the coefficients
- Returns:
dict with the finite difference coefficients and corresponding offsets