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§
- Fractional
Step Result - Fractional step result from one projection step.
- Staggered
Grid1D - A staggered 1D grid holding cell-centred values
uand face-centred fluxesf.
Enums§
- Boundary
Condition - 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
uone time stepdt. - 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
uusing 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
trueif the explicit advection scheme is stable (CFL ≤ 1). - is_
diffusion_ stable - Returns
trueif 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
handh/2. - rk4_
step - Runge-Kutta 4 integrator for method of lines.
- second_
derivative - Computes the second derivative of
uwith the standard 3-point Laplacian stencil. - thomas_
algorithm - Solves the tridiagonal system
A x = dusing 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_starttox_endwithnpoints. - 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/2forc > 0. - weno5_
min_ smoothness - Minimum smoothness indicator across stencils (for diagnostic use).