Examples#

This gallery walks through every public feature of mathematicskit.pde: Fourier’s series solution of the heat equation, Crank-Nicolson and the theta-method family, the method of lines in 2D, d’Alembert’s traveling waves, Poisson’s and Laplace’s equations with direct and relaxation solvers, the Courant-Friedrichs-Lewy condition, von Neumann stability analysis, the Lax equivalence theorem, finite elements, multigrid, Godunov’s method for shocks, the Hopf-Cole transformation, and Fourier and Chebyshev spectral methods.

Each script in this gallery is self-contained and can be run directly with python examples/pde/<section>/<script>.py.

Sections#

  • heat – Fourier’s sine-series solution, Crank-Nicolson against explicit FTCS and backward Euler, and the method of lines on a 2D plate.

  • wave – d’Alembert’s traveling-wave solution against a leapfrog finite-difference string.

  • advection – the Courant-Isaacson-Rees upwind, Lax-Friedrichs, and Lax-Wendroff schemes for linear advection.

  • conservation_laws – shocks in inviscid Burgers’ equation and Godunov’s method.

  • elliptic – Poisson’s equation on a square, Richardson-style relaxation (Jacobi, Gauss-Seidel, SOR) for Laplace’s equation, finite elements, and multigrid.

  • stability – the CFL condition for advection schemes, von Neumann amplification factors, and the Lax equivalence theorem.

  • spectral – Fourier pseudo-spectral Burgers’ equation, Chebyshev collocation for boundary-value problems, and the Hopf-Cole exact solution of viscous Burgers’ equation.

Advection schemes#

Upwind, Lax-Friedrichs, and Lax-Wendroff schemes for linear advection.

The Courant-Isaacson-Rees upwind scheme

The Courant-Isaacson-Rees upwind scheme

The Lax-Friedrichs scheme: stabilizing centered differences

The Lax-Friedrichs scheme: stabilizing centered differences

The Lax-Wendroff scheme: second order, and dispersive wiggles

The Lax-Wendroff scheme: second order, and dispersive wiggles

Conservation laws and shocks#

Inviscid Burgers’ equation: shocks, rarefactions, and Godunov’s finite-volume method against oscillating second-order schemes.

Godunov’s method: capturing shocks without oscillations

Godunov's method: capturing shocks without oscillations

Poisson and Laplace equations#

Steady boundary-value problems: a sparse direct Poisson solve, the relaxation iterations that preceded it, finite elements, and multigrid.

Poisson’s equation: a potential with sources

Poisson's equation: a potential with sources

Richardson’s relaxation: iterating toward Laplace’s solution

Richardson's relaxation: iterating toward Laplace's solution

Finite elements: Galerkin’s hat functions on an uneven mesh

Finite elements: Galerkin's hat functions on an uneven mesh

Multigrid: a solver whose cost does not grow with the grid

Multigrid: a solver whose cost does not grow with the grid

The heat equation#

Fourier’s series solution, the theta-method family (FTCS, Crank-Nicolson, backward Euler), and the method of lines on a 2D plate.

Fourier’s heat equation: a sine series whose modes decay

Fourier's heat equation: a sine series whose modes decay

Crank-Nicolson: large, stable, second-order heat steps

Crank-Nicolson: large, stable, second-order heat steps

The method of lines: a hot plate as a system of ODEs

The method of lines: a hot plate as a system of ODEs

Spectral methods#

Fourier pseudo-spectral time stepping for periodic problems, and Chebyshev collocation for boundary-value problems, checked against the Hopf-Cole exact solution of viscous Burgers’ equation.

Fourier pseudo-spectral methods: Burgers’ equation

Fourier pseudo-spectral methods: Burgers' equation

Chebyshev collocation: spectral accuracy without periodicity

Chebyshev collocation: spectral accuracy without periodicity

Burgers’ equation and the Hopf-Cole transformation

Burgers' equation and the Hopf-Cole transformation

Stability: CFL and von Neumann#

Why explicit schemes need small time steps: the Courant-Friedrichs-Lewy condition, von Neumann’s Fourier-mode analysis, and the Lax equivalence theorem.

The Courant-Friedrichs-Lewy condition

The Courant-Friedrichs-Lewy condition

Von Neumann stability analysis: one Fourier mode at a time

Von Neumann stability analysis: one Fourier mode at a time

The Lax equivalence theorem: consistency + stability = convergence

The Lax equivalence theorem: consistency + stability = convergence

The wave equation#

A plucked string: d’Alembert’s traveling-wave solution against a symplectic leapfrog finite-difference solve.

D’Alembert’s traveling waves on a plucked string

D'Alembert's traveling waves on a plucked string

Gallery generated by Sphinx-Gallery