Skip to main content

Module finite_difference

Module finite_difference 

Source
Expand description

Finite difference schemes for PDEs in 1D, 2D, and 3D.

Covers explicit/implicit time integration, Crank-Nicolson diffusion, upwind advection, 5th-order WENO, compact finite differences, boundary conditions (Dirichlet/Neumann/periodic), Richardson extrapolation, method of lines, stability analysis (CFL, von Neumann), staggered grids, fractional step method, and ADI (alternating direction implicit).

Structs§

FractionalStepResult
Fractional step result from one projection step.
StaggeredGrid1D
A staggered 1D grid holding cell-centred values u and face-centred fluxes f.

Enums§

BoundaryCondition
Boundary condition specification for finite difference solvers.

Functions§

adi_diffusion_step_2d
One full ADI time step for 2D diffusion ∂u/∂t = α(∂²u/∂x² + ∂²u/∂y²).
advection_beam_warming_step
Beam-Warming second-order upwind advection step (for c > 0).
advection_lax_wendroff_step
Lax-Wendroff second-order advection step for ∂u/∂t + c ∂u/∂x = 0.
advection_periodic_step
First-order upwind advection step on a periodic domain.
advection_upwind_step
First-order upwind advection: advances u one time step dt.
advection_weno5_step
One time step of the WENO-5 advection scheme for ∂u/∂t + c ∂u/∂x = 0.
apply_bc_1d
Applies 1D boundary conditions (left and right) to a solution vector.
apply_dirichlet_2d
Applies 2D Dirichlet boundary conditions to all four edges.
apply_neumann_reflection
Applies Neumann (zero-flux) conditions by ghost-cell reflection.
cfl_number
CFL (Courant-Friedrichs-Lewy) number for the advection equation.
compact_first_derivative
Compact (Padé) 4th-order first derivative.
compact_second_derivative
Compact (Padé) 4th-order second derivative.
diffusion_2d_explicit_step
One explicit 2D diffusion step using the FTCS scheme.
diffusion_crank_nicolson_step
Crank-Nicolson implicit diffusion step.
diffusion_explicit_step
Forward-time central-space (FTCS) explicit diffusion step.
diffusion_implicit_step
Fully implicit (backward Euler) diffusion step.
first_derivative_central
Computes the first derivative of u using second-order central differences.
first_derivative_fourth_order
Computes the fourth-order central difference first derivative.
fractional_step_1d
Fractional step (Chorin projection) method for 1D incompressible flow.
ftcs_amplification
Computes the von Neumann amplification factor magnitude for FTCS diffusion.
ftcs_max_amplification
Maximum amplification factor for the FTCS diffusion scheme over all wave numbers.
is_advection_stable
Returns true if the explicit advection scheme is stable (CFL ≤ 1).
is_diffusion_stable
Returns true if the explicit diffusion scheme (FTCS) is stable.
l1_norm
Computes the discrete L1 norm ||u||₁ = dx * Σ |u[i]|.
l2_error
Computes the discrete L2 error between computed and exact solutions.
l2_norm
Computes the discrete L2 norm ||u||₂ = sqrt(dx * Σ u[i]²).
laplacian_2d
Computes the 2D Laplacian using the standard 5-point stencil.
laplacian_3d
Computes the 3D Laplacian using the 7-point stencil.
linf_norm
Computes the L∞ (maximum) norm of u.
max_dt_advection
Computes the maximum stable time step for explicit advection.
max_dt_diffusion
Computes the maximum stable time step for explicit diffusion (FTCS).
mol_advection_rhs
Method-of-lines spatial operator for the 1D advection equation.
mol_diffusion_rhs
Method-of-lines spatial operator for the 1D diffusion equation.
richardson_derivative
Applies Richardson extrapolation to refine a 1D finite-difference derivative.
richardson_extrapolation
Richardson extrapolation to combine two estimates with step sizes h and h/2.
rk4_step
Runge-Kutta 4 integrator for method of lines.
second_derivative
Computes the second derivative of u with the standard 3-point Laplacian stencil.
thomas_algorithm
Solves the tridiagonal system A x = d using the Thomas algorithm.
total_variation
Computes the total variation TV(u) = Σ |u[i+1] - u[i]|.
uniform_grid_1d
Generates a uniform 1D grid from x_start to x_end with n points.
uniform_grid_2d
Generates a uniform 2D grid (row-major).
von_neumann_diffusion_number
Von Neumann diffusion stability number r = α dt / dx².
wave_equation_step
One explicit time step for the 1D wave equation ∂²u/∂t² = c² ∂²u/∂x².
weno5_flux
Computes the WENO-5 reconstructed flux at interface i + 1/2 for c > 0.
weno5_min_smoothness
Minimum smoothness indicator across stencils (for diagnostic use).