Finite Difference Suite

Einstein.FiniteDifferenceSuite.LocalBarycentricInterpolationType
LocalBarycentricInterpolation(points, values; degree=4)

Construct a local barycentric Lagrange interpolant for equispaced data points.

Creates a polynomial approximation of degree degree using the data values at uniformly spaced points points. The interpolation is performed locally using degree + 1 points nearest to the evaluation point.

Arguments

  • points::StepRangeLen{TF}: Equispaced points for interpolation
  • values::AbstractVector{TF}: Function values at the points
  • degree::Integer=4: Degree of the local polynomial interpolant

Returns

  • An interpolant function that can be evaluated at any point within [minimum(points), maximum(points)]

Notes

  • Requires length(points) >= degree + 1
  • points and values must have the same length
  • Uses barycentric Lagrange interpolation for numerical stability

References

source
Einstein.FiniteDifferenceSuite.fdm_boundary_weightsMethod
fdm_boundary_weights([TR=Rational{TI}], derivative_order::TI, accuracy_order::TI) where {TR<:Real, TI<:Integer}

Generate finite difference coefficients for shifted boundary conditions.

Arguments

  • derivative_order::Integer: The order of the derivative to approximate
  • accuracy_order::Integer: The desired order of accuracy

Returns

Tuple of left and right shifted boundary finite difference coefficients The coefficients are stored in a matrix with the rows representing the different grid points. The rows are ordered from the leftmost grid point to the rightmost grid point.

source
Einstein.FiniteDifferenceSuite.fdm_central_weightsMethod
fdm_central_weights([TR=Rational{TI}], derivative_order::TI, accuracy_order::TI) where {TR<:Real, TI<:Integer}

Generate central finite difference coefficients for a given derivative and accuracy order.

Arguments

  • derivative_order::Integer: The order of the derivative to approximate
  • accuracy_order::Integer: The desired order of accuracy (must be even)

Returns

Vector of rational coefficients for the finite difference stencil

source
Einstein.FiniteDifferenceSuite.fdm_derivative_operatorMethod
fdm_derivative_operator([TR=Float64], derivative_order::Integer, accuracy_order::Integer, dx::TR) -> FiniteDifferenceDerivativeOperator{TR}

Create a finite difference derivative operator with specified derivative and accuracy orders.

Arguments

  • TR: The element type of the operator
  • derivative_order::Integer: The order of the derivative
  • accuracy_order::Integer: The order of accuracy
  • dx::TR: The grid spacing
source
Einstein.FiniteDifferenceSuite.fdm_dissipation_operatorMethod
fdm_dissipation_operator([TR=Float64], dissipation_order::TI, σ::TR, dx::TR) -> FiniteDifferenceDerivativeOperator{TR}

Create a finite difference dissipation operator with specified dissipation order.

Arguments

  • TR: The element type of the operator
  • dissipation_order::Integer: The order of the dissipation operator
  • σ::TR: The dissipation coefficient
  • dx::TR: The grid spacing
source
Einstein.FiniteDifferenceSuite.fdm_extrapolation_weightsMethod
fdm_extrapolation_weights(extrapolation_order::Int, direction::Symbol)

Generate weights for left or right extrapolation.

Arguments

  • extrapolation_order::Int: Order of extrapolation
  • direction::Symbol: Direction of extrapolation (:left or :right)

Returns

Vector of Integer coefficients for the extrapolation weights.

source
Einstein.FiniteDifferenceSuite.fdm_hermite_weightsMethod
fdm_hermite_weights([TR=Rational{TI}], derivative_order::TI, accuracy_order::TI) where {TR<:Real, TI<:Integer}

Generate Hermite-type finite difference coefficients that include function value and derivative information.

Arguments

  • derivative_order::Integer: The order of the derivative to approximate (must be ≥ 2)
  • accuracy_order::Integer: The desired order of accuracy
    • For derivativeorder 2,3,6,7,10,11...: accuracyorder must be 4,8,12...
    • For derivativeorder 4,5,8,9,12...: accuracyorder must be 2,6,10...

Returns

Vector of rational coefficients for the Hermite-type finite difference stencil

source
Einstein.FiniteDifferenceSuite.fdm_operator_matrixMethod
fdm_operator_matrix(op::AbstractFiniteDifferenceOperator{TR}; boundary::Bool=false, transpose::Bool=false) -> BandedMatrix{TR}

Create a banded matrix representation of the finite difference operator.

Arguments

  • op::AbstractFiniteDifferenceOperator{TR}: The finite difference operator
  • boundary::Bool=true: Whether to include boundary weights
  • transpose::Bool=false: Whether to transpose the matrix
source
Einstein.FiniteDifferenceSuite.fdm_weights_fornbergMethod
fdm_weights_fornberg([TR=Float64], order::Integer, x0::Real, x::AbstractVector; 
                         hermite::Bool=false)

Calculate finite difference weights for arbitrary-order derivatives using the Fornberg algorithm. Taken from SciML/MethodOfLines.jl.

Arguments

  • TR: Type parameter for the weights (defaults to type of x0)
  • order: Order of the derivative to approximate
  • x0: Point at which to approximate the derivative
  • x: Grid points to use in the approximation
  • hermite: Whether to include first derivative values (Hermite finite differences)

Returns

If hermite == false:

  • Vector{TR}: Weights for standard finite differences

If hermite == true:

  • Tuple{Vector{TR}, Vector{TR}}: Weights for Hermite finite differences

Requirements

  • For standard finite differences: N > order
  • For Hermite finite differences: N > order/2 + 1

where N is the length of x

Examples

# Standard central difference for first derivative
x = [-1.0, 0.0, 1.0]
w = fdm_weights_fornberg(1, 0.0, x)
# Returns approximately [-0.5, 0.0, 0.5]

# Forward difference for second derivative
x = [0.0, 1.0, 2.0, 3.0]
w = fdm_weights_fornberg(2, 0.0, x)

# Hermite finite difference for third derivative
x = [-1.0, 0.0, 1.0]
w_f, w_d = fdm_weights_fornberg(3, 0.0, x, hermite=true)

References

source