Compact Finite Differences

class findiff.compact.CompactScheme(deriv, left: dict, right: list, coefficients=None)

Represents compact finite difference as in Lele, J. Comp. Phys 103, 16-42 (1992)

A more appropriate name for the scheme would be “implicite finite differences”.

Normal, i.e. “explicit” finite differences express the n-th derivative as a linear combination neighboring function values:

\[f^{(n)}_i = \sum_k c_k f_{i+k}\]
The compact/implicit finite difference scheme, however uses:

sum_k alpha_k f^{(n)}_{i+k} = sum_k c_k f_{i+k}

So, in order to apply implicit finite differences, one has to solve a (sparse) linear equation system.

The big advantage of the implicit scheme is that for the same accuracy order, one needs fewer neighboring points than in the explicit schemes.

Initializes a CompactScheme instance.

The compact/implicit finite difference scheme is defined by:

\[\sum_k \alpha_k f^{(n)}_{i+k} = \sum_k c_k f_{i+k}\]
Args:
deriv: int

The order of the derivative

left: dict

Defines the alphas in the formula above. Keys: k, Values: alpha_k

right: list|tuple

Which neighboring points to use (the k’s in the formula above)

coefficients: list|tuple|None

The c_k for the offsets in right. If None (default), they are determined from the alphas by maximizing the accuracy order.

for_deriv(deriv)

Returns a scheme of the same kind (and LHS width) for another derivative.

classmethod from_accuracy(acc, deriv, num_left)

Creates the compact scheme with the narrowest right-hand side that reaches accuracy order acc for an LHS bandwidth of num_left.

The LHS alphas and the RHS coefficients are determined jointly to maximize the accuracy order for the given stencil widths, as in Lele, J. Comp. Phys 103, 16-42 (1992).

modified_wavenumber(w)

Returns the modified wavenumber of the scheme for (scaled) wavenumbers w in \([0, \pi]\).

Applying the scheme to \(e^{i w x / h}\) yields \((i w')^n\) times the function (n = derivative order); this method returns the real part of \((w')^n\), which equals \(w^n\) for an exact derivative.

resolving_efficiency(tol=0.001)

Returns the fraction of \([0, \pi]\) in which the modified wavenumber has a relative error below tol (Lele, 1992).

rhs_coefficients(deriv=None)

Returns the RHS coefficients c_k (for unit grid spacing) for deriv.

classmethod spectral(deriv, num_left, num_right, acc=4, tol=0.001, max_wavenumber=None)

Creates a compact scheme with spectral-like resolution (Lele, 1992).

Instead of spending all free parameters on the accuracy order, only order acc is imposed. The remaining parameters minimize the error of the modified wavenumber in the least-squares sense on \([0, w_{max}]\), which resolves short waves much better than the scheme of maximal order with the same stencil widths.

Args:
deriv: int

The order of the derivative.

num_left: int

Number of LHS points (odd).

num_right: int

Number of RHS points (odd).

acc: int

Minimum accuracy order.

tol: float

Relative error of the modified wavenumber that defines the resolving efficiency maximized when max_wavenumber is None.

max_wavenumber: float or None

Upper end \(w_{max} \in (0, \pi)\) of the optimization range. If None, it is chosen to maximize the resolving efficiency for tol while keeping the LHS system well-conditioned.