Tutorial · Numerical methods

Sod's shock tube through every method

One Euler model, 400 cells, 452 runs. Every discretization family, reconstruction, limiter, Riemann solver, time integrator and solver pair OneSimulation offers for this problem, each graded against the exact Riemann solution. Every combination produces a solution: 297 run as declared, and the 76 that must fail mathematically (high-order linear spatial schemes at a shock by Godunov's theorem, time integrators and the fixed-point iteration beyond their stability limit) are shown with their stabilized counterpart. None is refused. The density error spans 8.66 × 10−4 to 1.20 × 10−2. Nothing about the physics changed between runs, only one argument.

A shock, a contact and a rarefaction

A tube of ideal gas (γ = 1.4) is split at x = 0.5. The left half holds (ρ, u, p) = (1, 0, 1), the right half (0.125, 0, 0.1). When the diaphragm goes, a rarefaction runs left and a contact and a shock run right. At t = 0.2 the shock sits at x = 0.8504.

The exact solution comes from OneSimulation's own exact Euler sampler. Every run is evaluated at the 400 cell centres. The page reports the L1 errors of density, velocity and pressure, the shock position error and the wall time.

The model, declared once

tube = Line(start=(0.0, 0.0, 0.0), end=(1.0, 0.0, 0.0))
gas = CompressibleEuler(
    domain=tube.line, equation_of_state=IdealGasEquationOfState(gamma=gamma)
)
sod = Problem(
    name="Sod shock tube",
    geometry=tube,
    physics=(gas,),
    boundary_conditions=(
        TransmissiveBoundary(boundary=tube.boundaries.all, physics=gas),
    ),
    initial_conditions=(
        InitialValue(gas.density, lambda x: np.where(x < 0.5, 1.0, 0.125)),
        InitialValue(gas.momentum, 0.0),
        InitialValue(gas.total_energy, lambda x: np.where(x < 0.5, 2.5, 0.25)),
    ),
)

None of this names a method. The method is the numerics argument of Simulation. Three of the 452 choices:

numerics = Numerics(
    spatial=FiniteVolume(convection=HLLC(), reconstruction=MUSCL(), limiter=SuperbeeLimiter()),
    time_integrator=TimeMethod("ssprk2"),
)
numerics = Numerics(
    spatial=FiniteElement(element=DiscontinuousLagrange(2), convection=HLLC(),
                          limiter=DGPolynomialLimiter(slope_limiter=MinmodLimiter(),
                                                      invariant_domain=EulerInvariantDomain())),
    linear_solver=SparseDirect(),
    time_integrator=TimeMethod("ssprk2"),
)
numerics = Numerics(
    spatial=FiniteVolume(convection=HLLC(), reconstruction=MUSCL(), limiter=MinmodLimiter()),
    time_integrator=BDF(order=2),
    nonlinear_solver=Newton(linear_solver=GMRES(preconditioner=ILU()),
                            jacobian="colored_finite_difference"),
)
result = Simulation(problem=sod, mesh=mesh, numerics=numerics).run(
    start_time=0.0, end_time=0.2, time_step=2e-3)

Every spatial scheme with every Riemann solver

45 spatial schemes. Finite volumes with first-order, MUSCL and QUICK (seven limiters and the unlimited slope), ENO, WENO3, WENO5, WENO-Z and central WENO reconstructions. Finite elements (FEM): discontinuous Galerkin of degree 0 to 4, limited, unlimited or with a jump penalty; continuous Galerkin of degree 1 to 3 with graph viscosity, continuous interior penalty, volume interior penalty, SUPG, GLS or no stabilization. Finite differences: central, fourth-order and summation-by-parts stencils, with and without JST dissipation. Each is crossed with the Rusanov, HLL, HLLE and HLLC solvers and advanced with SSP-RK2 at the stable step.

The twelve most accurate combinations. Shock error in units of 10−3; one cell is 2.5 × 10−3 wide.
Spatial schemeRiemann solverL1 ρL1 uL1 pShockTime
FEM CG P2 + continuous interior penaltyHLLE8.66 × 10−41.69 × 10−36.97 × 10−4-0.4522 s
FEM CG P2 + continuous interior penaltyHLL8.66 × 10−41.69 × 10−36.97 × 10−4-0.4525 s
FEM CG P2 + continuous interior penaltyHLLC8.66 × 10−41.69 × 10−36.97 × 10−4-0.4523 s
FEM CG P2 + continuous interior penaltyRusanov8.66 × 10−41.69 × 10−36.97 × 10−4-0.4523 s
FVM WENO5-ZHLLC1.25 × 10−32.64 × 10−39.94 × 10−4+0.397 s
FVM WENO5-ZHLLE1.26 × 10−32.61 × 10−39.67 × 10−4+0.387 s
FVM WENO5-ZHLL1.26 × 10−32.61 × 10−39.67 × 10−4+0.387 s
FVM MUSCL + superbeeHLLC1.35 × 10−32.73 × 10−31.05 × 10−3+0.452 s
FVM WENO5HLLC1.40 × 10−32.74 × 10−31.06 × 10−3+0.425 s
FVM MUSCL + superbeeHLLE1.42 × 10−32.46 × 10−39.18 × 10−4+0.451 s
FVM MUSCL + superbeeHLL1.42 × 10−32.46 × 10−39.18 × 10−4+0.451 s
FVM WENO5HLLE1.43 × 10−32.75 × 10−31.05 × 10−3+0.425 s

What the profiles look like

Density, velocity and pressure of eight representative combinations against the exact solution, with a close-up of contact and shock
Representative combinations against the exact Riemann solution, 400 cells.

Every time integrator

29 time integrators. 30 explicit runs at the stable step and 31 implicit runs at Δt = 2 × 10−3, a CFL number of about 1.4 that no explicit method could take. All with HLLC fluxes.

See matrix 2 in the carousel at the top.

Every nonlinear and linear solver

Backward Euler on MUSCL-minmod-HLLC, Δt = 2 × 10−3. 30 solver pairs converged to the same discrete solution. Their density errors differ by a relative 2.8 × 10−7 at most. Wall time ranges from 6 s (quasi-Newton, sparse LU) to 17 s (quasi-Newton, GMRES + ILU).

See matrix 3 in the carousel at the top.

The same gas as particles

Smoothed-particle hydrodynamics solves the same problem without a mesh: 800 particles in a periodic box, 400 of them in [0, 1], the same resolution as the 400 cells. Every time integrator of the grid matrix is passed to the particle solver unchanged, with three choices of Monaghan's artificial viscosity. 85 of 87 combinations ran as declared; the most accurate is theta = 0.75 with Monaghan α = 0.5, β = 1, mean density error 4.67 × 10−3.

See matrix 4 in the carousel at the top.

400 against 200 cells

L1 density error and shock position error (10−3) on both meshes. For a discontinuous solution the L1 error falls roughly like Δx1/2 to Δx.
Combination200 cells400 cellsRatioShock, 200Shock, 400
FVM first order, Rusanov1.83 × 10−21.20 × 10−21.53+4.19+2.20
FVM first order, HLLC1.33 × 10−28.44 × 10−31.58+4.72+2.45
FVM MUSCL + minmod, HLLC4.56 × 10−32.55 × 10−31.79+1.73+0.94
FVM MUSCL + superbee, HLLC2.52 × 10−31.35 × 10−31.87+0.51+0.45
FVM WENO5, HLLC2.63 × 10−31.40 × 10−31.88+0.78+0.42
FEM DG P2 + minmod + invariant domain, HLLC4.54 × 10−32.54 × 10−31.79+1.66+0.90
FEM CG P1 + graph viscosity, HLLC1.84 × 10−21.20 × 10−21.53+4.01+2.12
FDM WENO5 flux splitting, Lax-Friedrichs splitting3.46 × 10−31.80 × 10−31.92+1.05+0.57

Schemes that must fail at a shock, and their stabilized counterparts

A linear scheme of higher than first order oscillates at a discontinuity (Godunov's theorem). On Sod's problem that drives density or pressure negative, and OneSimulation reports it instead of clipping the state. Each such scheme is shown hatched in the matrices, with the result of its stabilized counterpart behind the hatching: exactly one ingredient is added, or, for time integrators that are not A-stable and for the fixed-point iteration, the step is reduced to one they are stable for. Of the 373 declared runs, 297 ran directly and 76 are shown stabilized.

Declared schemeWhy it failsStabilized counterpartRuns
Adams-Moulton 4Euler state has non-positive pressureAdams-Moulton 4 at Δt = 5.0e-041
BDF4 (Gear)Euler state has non-positive pressureBDF4 (Gear) at Δt = 5.0e-041
BDF5 (Gear)Euler state has non-positive pressureBDF5 (Gear) at Δt = 5.0e-041
BDF6 (Gear)Euler state has non-positive pressureBDF6 (Gear) at Δt = 5.0e-042
FDM central, 2nd orderEuler state has non-positive pressurecentral differences + Jameson-Schmidt-Turkel artificial dissipation4
FDM polynomial, 4th orderEuler state has non-positive pressure4th-order differences + Jameson-Schmidt-Turkel artificial dissipation4
FDM summation by parts, order 2Euler state has non-positive pressureSBP order 2 with SAT boundary flux + Jameson-Schmidt-Turkel artificial dissipation4
FDM summation by parts, order 4Euler state has non-positive pressureSBP order 4 with SAT boundary flux + Jameson-Schmidt-Turkel artificial dissipation4
FEM CG P1 + GLSEuler state has non-positive pressureCG P1 + invariant-domain graph viscosity instead of GLS4
FEM CG P1 + SUPGEuler state has non-positive pressureCG P1 + invariant-domain graph viscosity instead of SUPG4
FEM CG P1 GalerkinEuler state has non-positive pressureFEM CG P1 + invariant-domain graph viscosity4
FEM CG P2 GalerkinEuler state has non-positive pressureFEM CG P2 + invariant-domain graph viscosity (positive Bernstein basis)4
FEM CG P3 GalerkinEuler state has non-positive pressureFEM CG P3 + invariant-domain graph viscosity (positive Bernstein basis)4
FEM DG P1 + jump penaltyEuler state has non-positive pressureDG P1 + Euler invariant-domain scaling instead of the jump penalty4
FEM DG P1, unlimitedEuler state has non-positive densityFEM DG P1 + Euler invariant-domain scaling (no slope limiter)3
FEM DG P1, unlimitedEuler state has non-positive pressureFEM DG P1 + Euler invariant-domain scaling (no slope limiter)1
FEM DG P2, unlimitedEuler state has non-positive pressureFEM DG P2 + Euler invariant-domain scaling (no slope limiter)4
FEM DG P3, unlimitedEuler state has non-positive pressureFEM DG P3 + Euler invariant-domain scaling (no slope limiter)4
FEM DG P4, unlimitedEuler state has non-positive pressureFEM DG P4 + Euler invariant-domain scaling (no slope limiter)4
FVM MUSCL, unlimitedEuler state has non-positive densityMUSCL unlimited + invariant-domain positivity limiter at the faces4
FVM QUICKEuler state has non-positive pressureQUICK + invariant-domain positivity limiter at the faces4
fixed pointEuler state has non-positive pressurefixed point at Δt = 2.5e-041
fixed point + Aitkenpartitioned coupling did not converge within maximum_iterationsfixed point + Aitken at Δt = 2.5e-041
leapfrogEuler state has non-positive pressureleapfrog + Robert-Asselin-Williams filter (ν = 0.2, α = 0.53; first order), safety factor 0.153
leapfrogunfiltered leapfrog has no stable region on the negative real axis, so the damping of SPH artificial viscosity grows its computational mode for every step size; select leapfrog_raw, or switch the artificial viscosity offleapfrog + Robert-Asselin-Williams filter (ν = 0.2, α = 0.53)2

Methods that do not apply to this problem

A few methods in OneSimulation are not in the matrix because the Euler system lacks what they are built for.

MethodBuilt for
Conjugate gradients, algebraic multigridSymmetric positive definite operators
Runge-Kutta-Chebyshev and -Legendre super-stepsParabolic (diffusive) operators
Staggered VerletSecond-order systems (structural dynamics, particles with forces)
IMEX splittingProblems with a stiff and a non-stiff part
Local time steppingSteady states
Hydrostatic reconstructionShallow water over topography
Scharfetter-Gummel fluxDrift-diffusion (semiconductors, plasmas)
Scalar upwind and central fluxesScalar transport; for the Euler system the library asks for a Riemann solver instead

Reproduce the run

The notebook declares the model once and runs the whole matrix in one loop. All wall times on this page were measured with the compiled OneSimulation runtime (machine code, the package customers install) on an Apple Silicon laptop; the 452 runs took 43 minutes in total. Lower cells for a quick look. Activate the Python environment described in the STEP tutorial first.

The earlier Poisson comparison on a 3D cube shows the same idea for an elliptic problem.