Algorithmcore
HLL Riemann solver
Also called Harten-Lax-van Leer solver, HLLE solver.
Approximates the Riemann fan by one intermediate state between the slowest and fastest wave estimates; robust and positive but diffusive at contacts.
- Time
- O(m M K) worst
- Space
- O(m M) extra
- Where
- K = the number of time steps (O(M) for a fixed end time and Courant number); M = the number of cells; m = the number of conserved components
- Model
- Real RAM
- Properties
- conservativedeterministicexplicitnot keeps stationary contact
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Amiram Harten, Peter D. Lax, Bram van Leer, Bernd Einfeldt, S. F. Davis, 1983
The HLL solver replaces the full solution of the Riemann problem at a cell face by a simpler one: a single constant state between a left speed and a right speed . If these speeds bound all waves of the exact solution, the integral form of the conservation law fixes and the flux with no further assumption. The solver needs no eigenvectors and no iteration, only two speed estimates. Harten, Lax and van Leer (1983) defined it. With the speed estimates of Einfeldt (1988) it is often called HLLE. It is the standard robust solver of Godunov type: it keeps density and pressure positive and gives entropy solutions. Its weakness is that the one middle state averages away a contact discontinuity, which HLLC restores.
In plain words
At each face between two cells, gas from the left meets gas from the right, and a set of waves goes out. The exact answer has several waves and needs an iteration. HLL keeps only the fastest wave to the left and the fastest wave to the right and puts one averaged state between them. The conservation law tells you exactly what that averaged state must be, once you know the two speeds. So the method is simple and it never makes negative density, but anything inside the fan, such as a contact between hot and cold gas, is blurred into the average.
The problem
Given cell averages of a hyperbolic conservation law , compute a face flux from and for the conservative update . The page uses the Euler equations with , , , and , and a scalar law .
The algorithm
HLL-FLUX(U_L, U_R)- 1
(S_L, S_R) <- WAVE-SPEEDS(U_L, U_R) - 2
if S_L >= 0: return F(U_L) ▷ all waves go right - 3
if S_R <= 0: return F(U_R) ▷ all waves go left - 4
return (S_R F(U_L) - S_L F(U_R) + S_L S_R (U_R - U_L)) / (S_R - S_L) FV-STEP(U, Δt, Δx)- 5
add one ghost cell on each side (copy for outflow, wrap for periodic) - 6
for each face j+1/2: F_{j+1/2} <- HLL-FLUX(U_j, U_{j+1}) - 7
for each cell j: U_j <- U_j - (Δt/Δx)(F_{j+1/2} - F_{j-1/2})
The code gives two choices for line L1.
- Davis: and .
- Einfeldt (the default): and , where , are the Roe averages, weighted by , and with .
For a scalar law the code takes and . The time step is with forward Euler.
The flux of line L4 comes from the HLL state
which are the integral form of the law over the fan and the jump condition across the left wave.
Example
The flux by hand. Take Sod's states and , so , , and . The enthalpies are and . With weights and , the Roe averages are and , so . The Einfeldt speeds are and . Then , , and line L4 gives
The exact Godunov flux is , and the Rusanov flux is . With the Davis speeds, , and the HLL flux is exactly the Rusanov flux.
The HLL state is an average. With and , which bound all Sod waves (the shock moves at 1.75216), the HLL state is . The test computes the average of the exact solution over with 4000 midpoints and finds the same state to , the error of the midpoint rule at the three jumps.
Sod's tube. On with the jump at , outflow boundaries and Courant number 0.9, the scheme runs to . The errors of the density against exact cell averages are measurements made with the code on this page.
| cells | steps | Einfeldt | Davis |
|---|---|---|---|
| 100 | 48 | 0.01505 | 0.01522 |
| 200 | 96 | 0.00994 | 0.01008 |
| 400 | 194 | 0.00629 | 0.00634 |
The observed orders with the Einfeldt speeds are 0.60 and 0.66. The Rusanov errors on the same grids are 0.02148, 0.01515 and 0.00998.
A smooth wave. For , , on a periodic grid, the density errors at for are , , and , with orders 1.00, 0.99 and 1.00. They are half of the Rusanov errors, because here is much smaller in size than .
A contact at rest. With on the left half and on the right half, and , after 8 steps on 40 cells the velocity and the pressure are exact to rounding, but the density around the contact is . HLL averages the contact into the middle state.
Correctness
The proof is in proofs/correctness.md. Theorem: the flux is consistent and the scheme is conservative. If the speeds bound the waves of each local Riemann problem and , then (1) is the average of the exact Riemann solution over the fan, (2) for the Euler equations, positive density and pressure are kept, because the admissible set is convex and the new cell average is an average of admissible states, and (3) for any convex entropy pair the scheme satisfies the cell entropy inequality with a consistent numerical entropy flux . With the Lax-Wendroff theorem, bounded limits are entropy weak solutions. For a convex scalar law the scheme is TVD for .
The estimates of Davis and Einfeldt are not proven bounds: for Sod's data they give and , below the shock speed 1.75216. The positivity of HLLE with the Einfeldt speeds rests on the analysis of Einfeldt, Munz, Roe and Sjögreen (1991), which the proof here does not repeat.
Proof: The HLL scheme is conservative and consistent, and with speeds that bound the waves it keeps positivity and satisfies a cell entropy inequalityfull
Setting. A system has a convex entropy pair , so that entropy solutions satisfy in the weak sense. The scheme stores cell averages on a uniform grid with width and steps with (line L7). At each face, with and , lines L1 to L4 give
with and . Let and . A short check shows that the middle formula with and in place of and gives all three cases: if it gives , and if it gives . So below we use only the middle formula, with speeds that satisfy .
Define the HLL state
The approximate Riemann solution is for , for , and for .
We say that the speeds bound the waves if every wave of the exact Riemann solution with data , moves at a speed in . The proofs of Lemma 3 and Theorems 1 and 2 need this. The estimates of line L1 do not give it in every case (see the remark at the end).
Lemma 1 (consistency and conservation). . On a periodic grid, .
Proof. With , the middle formula is , and the other two cases give directly. For conservation, each face flux enters cell with the factor and cell with , so the sum telescopes. The test checks this exactly for Burgers' equation in Fraction arithmetic.
Lemma 2 (the flux is the flux of the approximate solution). .
Proof. . So
The second form follows in the same way, or from the first form and the definition of .
The two forms are the Rankine-Hugoniot conditions of the two jumps of , at speed and at speed . So is a weak solution of the conservation law in the integral sense over the fan, though not a true solution.
Lemma 3 (the HLL state is the average of the exact fan). If the speeds bound the waves and is the exact Riemann solution, then for every
Proof. Integrate over the rectangle . Because the speeds bound the waves, on the left side and on the right side for . The integral form of the law gives
Divide by .
Lemma 4 (Jensen). Let be convex on a convex set and let be an integrable function on an interval with values in . Then the average is in and .
Proof. This is Jensen's inequality for the uniform probability measure on . is in the closed convex hull of the values of .
Lemma 5 (the admissible set is convex). For the Euler equations, the set of states with positive density and pressure is convex, and the pressure is a concave function on .
Proof. The function is convex on : its Hessian is , which has determinant 0 and trace , so it is positive semidefinite. Then is concave, and is the intersection of the half space with the set where a concave function is positive. Both are convex.
Theorem 1 (positivity). For the Euler equations, let every face use speeds that bound the waves, and let . If every is in , then every is in .
Proof. Put the approximate solution of each face at the face, and run it for the time . Because , each fan stays in the half cells next to its face, and the fans do not meet. Let be the function so made on cell at time . It is except on the part , where it is the state of the left face, and on the part , where it is the state of the right face. By Lemma 2 its cell average is
because the integral over each half fan changes by exactly times the flux difference across it. By Lemma 3, each is the average of an exact Riemann solution with data in . That solution has positive density and pressure except in a vacuum region, if the data make one, where . It equals or near the two sides of the fan. So the average density is positive, and by the concavity of Lemma 5 (Jensen's inequality for the concave pressure, with in the vacuum) the pressure of the average is at least the average pressure, which is positive. So is in . Then is the average of , whose values are in , so by Lemma 4 again it is in .
Theorem 2 (cell entropy inequality). Let every face use speeds that bound the waves, and let . Define the numerical entropy flux at each face by
with and . Then and
Proof. Consistency: with , the state is , so .
Fix a face and use local coordinates with the face at . The exact Riemann solution satisfies the integral form of the entropy inequality over the rectangle , and its side values are and , so
By Lemma 3 and Lemma 4, the left side is at least . So
Now split the fan of at . On the left half, by the definition of (with equality),
On the right half, (1) and the definition of give
Now take cell and the function of the proof of Theorem 1. Its integral of has three parts: the right half of the fan of the face (where ), the middle part where , and the left half of the fan of the face (where ). Add the two bounds above and times the length of the middle part, :
By Lemma 4, . Divide by .
With Lemma 1, this gives the conclusion of Harten, Lax and van Leer (1983): if the scheme converges boundedly in , the Lax-Wendroff theorem makes the limit a weak solution, and the same argument applied to the cell entropy inequality makes it satisfy .
Theorem 3 (TVD for a convex scalar law). For a scalar law with convex , let line L1 take and . If at every face, the scheme is TVD.
Proof. Let when . Since is nondecreasing, is a mean of over the interval between the states, so . Take the case . From the middle formula,
Write . This is Harten's incremental form , with
The sum is linear in . At it is , and at it is . So . In the case the flux is , so and . The case is the mirror case. Harten's lemma (proved on the Rusanov flux page, Lemma 3 of its proof) gives .
Remark (the speed estimates are not proven bounds). For Sod's data, the right shock moves at 1.75216. The Davis estimate gives , and the Einfeldt estimate gives . Neither bounds the shock, so Theorems 1 and 2 do not apply to these faces. The scheme still runs well in the tests, but its positivity and entropy properties then rest on the analysis of Einfeldt (1988) and Einfeldt, Munz, Roe and Sjögreen (1991), not on the proof above. Bounds that are proven, such as those built from the two-rarefaction or the two-shock pressure estimates (Toro 2009, Chapter 10), make the theorems apply.
Complexity
Theorem, in the real-RAM model: one HLL flux costs operations, plus a constant number of square roots for the speeds. One step costs and the memory is . A fixed end time at a fixed Courant number needs steps, so the total cost is . The cost per flux is close to that of the Rusanov flux and below that of the Roe flux, which needs the eigenvectors.
Properties
- First order and upwind. For supersonic flow, or , and the flux is the upwind flux or exactly. The measured order on the smooth wave is 0.99 to 1.00.
- Positive. On the 123 problem (, , , ), the smallest density is 0.0228 and the smallest pressure is 0.0070. The exact density at the center is 0.0219. Linearized solvers such as Roe's can give negative density on data of this kind (Einfeldt et al. 1991).
- Entropy satisfying. A transonic rarefaction is opened: for Burgers' equation with and the flux is , not , so the jump spreads. No entropy fix is needed.
- Smears contacts and shear waves. The middle state has no structure, so a contact, at rest or moving, is smeared like in the Rusanov scheme.
Variants and improvements
- HLLC. Restore the contact with two middle states separated by a contact speed . See HLLC.
- Rusanov. Use one speed . See the Rusanov flux.
- Pressure-based speeds. Estimate the middle pressure first, then set the speeds from the shock or rarefaction relations; this gives better bounds (Toro 2009, Chapter 10).
- HLLEM and other one-state solvers with anti-diffusion. Add back a part of the contact wave with an estimate of its strength (Einfeldt et al. 1991).
- High order. Use the flux on reconstructed values from MUSCL or WENO with a Runge-Kutta method. Positivity of the reconstruction then needs a positivity-preserving limiter.
When to use it
Use HLL or HLLE when robustness matters more than sharpness: near vacuum, strong rarefactions, strong shocks and for systems whose eigenstructure is costly. It is a good fallback in a code whose main solver is Roe or HLLC. Avoid it at first order when contacts, shear layers or boundary layers must stay sharp, because it smears them like the Rusanov flux.
Pitfalls
- Speeds that do not bound the waves. The simple estimates can be too small for a strong shock (Sod's shock moves faster than both estimates). The scheme usually still works, but the proven properties then do not apply. Use pressure-based estimates when this matters.
- The Roe average near vacuum. The Einfeldt speeds need . With extreme data, check it before the square root.
- Dividing by . Lines L2 and L3 handle the supersonic cases first, so line L4 has and the divisor is positive. Do not reorder the tests.
- Time step. The theorems need , a stricter bound than the usual Courant condition. The code uses with , which is a common choice that the tests show to work, not a proven bound.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hll-riemann-solver/. The authors are listed in prov/MA9G95.jsonl.
"""HLL approximate Riemann solver for the 1D Euler equations (Harten, Lax and van Leer 1983).
The fan between the slowest speed S_L and the fastest speed S_R is replaced by one
constant state. Two speed estimates are given: the one of Davis (1988) and the one of
Einfeldt (1988), which uses Roe averages (HLLE).
"""
from math import sqrt
GAMMA = 1.4
def prim_to_cons(w, g=GAMMA):
rho, u, p = w
return (rho, rho * u, p / (g - 1.0) + 0.5 * rho * u * u)
def cons_to_prim(q, g=GAMMA):
rho, m, e = q
u = m / rho
return (rho, u, (g - 1.0) * (e - 0.5 * m * u))
def euler_flux(q, g=GAMMA):
rho, m, e = q
u = m / rho
p = (g - 1.0) * (e - 0.5 * m * u)
return (m, m * u + p, u * (e + p))
def wave_speeds(ql, qr, g=GAMMA, method="einfeldt"):
"""Estimates (S_L, S_R) of the slowest and the fastest signal speed."""
rl, ul, pl = cons_to_prim(ql, g)
rr, ur, pr = cons_to_prim(qr, g)
cl, cr = sqrt(g * pl / rl), sqrt(g * pr / rr)
if method == "davis":
return min(ul - cl, ur - cr), max(ul + cl, ur + cr)
wl, wr = sqrt(rl), sqrt(rr) # Roe averages of u and the enthalpy H = (E + p) / rho
hl, hr = (ql[2] + pl) / rl, (qr[2] + pr) / rr
u = (wl * ul + wr * ur) / (wl + wr)
h = (wl * hl + wr * hr) / (wl + wr)
c = sqrt((g - 1.0) * (h - 0.5 * u * u))
return min(ul - cl, u - c), max(ur + cr, u + c)
def hll_flux(ql, qr, g=GAMMA, method="einfeldt"):
"""The HLL flux at the face between the conserved states ql and qr."""
sl, sr = wave_speeds(ql, qr, g, method) # @line L1
fl, fr = euler_flux(ql, g), euler_flux(qr, g)
if sl >= 0.0: # @line L2
return fl
if sr <= 0.0: # @line L3
return fr
return tuple((sr * a - sl * b + sl * sr * (y - x)) / (sr - sl) for a, b, x, y in zip(fl, fr, ql, qr)) # @line L4
def hll_scalar(ul, ur, f, df):
"""The HLL flux for a scalar law u_t + f(u)_x = 0 with speeds from f' at the two states."""
sl, sr = min(df(ul), df(ur)), max(df(ul), df(ur)) # @line L1
if sl >= 0: # @line L2
return f(ul)
if sr <= 0: # @line L3
return f(ur)
return (sr * f(ul) - sl * f(ur) + sl * sr * (ur - ul)) / (sr - sl) # @line L4
def hll_state(ql, qr, sl, sr, g=GAMMA):
"""The HLL intermediate state U* (the average of the exact fan when the speeds bound it)."""
fl, fr = euler_flux(ql, g), euler_flux(qr, g)
return tuple((sr * y - sl * x - (b - a)) / (sr - sl) for a, b, x, y in zip(fl, fr, ql, qr))
def step(cells, dt, dx, flux, periodic=False):
"""One forward Euler step of the conservative scheme. cells is a list of states (tuples or numbers)."""
ext = ([cells[-1]] + list(cells) + [cells[0]]) if periodic else ([cells[0]] + list(cells) + [cells[-1]]) # @line L5
faces = [flux(ext[j], ext[j + 1]) for j in range(len(ext) - 1)] # @line L6
lam = dt / dx
if isinstance(cells[0], tuple): # @line L7
return [tuple(q - lam * (b - a) for q, a, b in zip(cells[j], faces[j], faces[j + 1])) for j in range(len(cells))]
return [cells[j] - lam * (faces[j + 1] - faces[j]) for j in range(len(cells))]
def solve_euler(cells, dx, t_end, cfl=0.9, g=GAMMA, periodic=False, method="einfeldt"):
"""March to t_end with dt = cfl dx / max(|u| + c). Returns (cells, number of steps)."""
t, n = 0.0, 0
flux = lambda a, b: hll_flux(a, b, g, method)
while t < t_end - 1e-14:
smax = 0.0
for q in cells:
rho, u, p = cons_to_prim(q, g)
smax = max(smax, abs(u) + sqrt(g * p / rho))
dt = min(cfl * dx / smax, t_end - t)
cells = step(cells, dt, dx, flux, periodic)
t += dt
n += 1
return cells, n
test_hll_riemann_solver.py 192 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hll-riemann-solver/. The authors are listed in prov/MA9G95.jsonl.
import random
from fractions import Fraction
from math import cos, log2, pi, sqrt
from hll_riemann_solver import (
cons_to_prim,
euler_flux,
hll_flux,
hll_scalar,
hll_state,
prim_to_cons,
solve_euler,
step,
wave_speeds,
)
SOD = ((1.0, 0.0, 1.0), (0.125, 0.0, 0.1))
def exact_solution(left, right, g=1.4):
"""Reference: the exact Riemann solution. Returns a function of xi = x / t giving (rho, u, p)."""
(rl, ul, pl), (rr, ur, pr) = left, right
cl, cr = sqrt(g * pl / rl), sqrt(g * pr / rr)
z = (g - 1.0) / (2.0 * g)
def fk(p, rk, pk, ck):
if p > pk:
return (p - pk) * sqrt(2.0 / ((g + 1.0) * rk) / (p + (g - 1.0) / (g + 1.0) * pk))
return 2.0 * ck / (g - 1.0) * ((p / pk) ** z - 1.0)
lo, hi = 1e-12, 1e4
for _ in range(200):
mid = 0.5 * (lo + hi)
if fk(mid, rl, pl, cl) + fk(mid, rr, pr, cr) + ur - ul > 0.0:
hi = mid
else:
lo = mid
ps = 0.5 * (lo + hi)
us = 0.5 * (ul + ur) + 0.5 * (fk(ps, rr, pr, cr) - fk(ps, rl, pl, cl))
def sample(xi):
rk, uk, pk, ck, sg = (rl, ul, pl, cl, 1.0) if xi <= us else (rr, ur, pr, cr, -1.0)
xs, uss, uks = sg * xi, sg * us, sg * uk
if ps > pk:
if xs <= uks - ck * sqrt((g + 1.0) / (2.0 * g) * ps / pk + z):
return (rk, uk, pk)
r, gg = ps / pk, (g - 1.0) / (g + 1.0)
return (rk * (r + gg) / (gg * r + 1.0), us, ps)
if xs <= uks - ck:
return (rk, uk, pk)
if xs >= uss - ck * (ps / pk) ** z:
return (rk * (ps / pk) ** (1.0 / g), us, ps)
w = 2.0 / (g + 1.0) + (g - 1.0) / ((g + 1.0) * ck) * (uks - xs)
return (rk * w ** (2.0 / (g - 1.0)), sg * 2.0 / (g + 1.0) * (ck + 0.5 * (g - 1.0) * uks + xs), pk * w ** (2.0 * g / (g - 1.0)))
return sample, ps, us
def sod_l1(m, t=0.2):
"""L1 error of the density against exact cell averages (16-point midpoint rule per cell)."""
sample = exact_solution(*SOD)[0]
cells = [prim_to_cons(SOD[0] if (j + 0.5) / m < 0.5 else SOD[1]) for j in range(m)]
cells, _ = solve_euler(cells, 1.0 / m, t)
err = 0.0
for j, q in enumerate(cells):
ex = sum(sample(((j + (k + 0.5) / 16) / m - 0.5) / t)[0] for k in range(16)) / 16
err += abs(q[0] - ex) / m
return err
def density_wave(m, t):
"""Exact cell averages of rho = 1 + 0.2 sin(2 pi (x - t)), with u = 1 and p = 1."""
dx = 1.0 / m
return [1.0 + 0.2 * (cos(2 * pi * (j * dx - t)) - cos(2 * pi * ((j + 1) * dx - t))) / (2 * pi * dx) for j in range(m)]
def test_einfeldt_speeds_and_flux_at_the_sod_interface() -> None:
ql, qr = prim_to_cons(SOD[0]), prim_to_cons(SOD[1])
sl, sr = wave_speeds(ql, qr)
wr = sqrt(0.125)
h = (3.5 + wr * 2.8) / (1.0 + wr) # Roe average of the enthalpy; the Roe average of u is 0
assert abs(sl + sqrt(1.4)) < 1e-14 and abs(sr - sqrt(0.4 * h)) < 1e-14
f = hll_flux(ql, qr)
want = [(sr * a - sl * b + sl * sr * (y - x)) / (sr - sl) for a, b, x, y in zip((0, 1, 0), (0, 0.1, 0), ql, qr)]
assert all(abs(a - b) < 1e-14 for a, b in zip(f, want))
assert abs(sr - 1.151895) < 1e-6
assert abs(f[0] - 0.510714) < 1e-6 and abs(f[1] - 0.543964) < 1e-6 and abs(f[2] - 1.313264) < 1e-6
def test_davis_speeds_give_the_rusanov_flux_for_sod() -> None:
f = hll_flux(prim_to_cons(SOD[0]), prim_to_cons(SOD[1]), method="davis")
s = sqrt(1.4) # S_L = -S_R, so HLL equals the Rusanov flux
assert abs(f[0] - 0.5 * s * 0.875) < 1e-14 and abs(f[1] - 0.55) < 1e-14 and abs(f[2] - 0.5 * s * 2.25) < 1e-14
def test_consistency_and_upwinding() -> None:
rng = random.Random(1)
for _ in range(50):
w = (rng.uniform(0.1, 2), rng.uniform(-2, 2), rng.uniform(0.1, 2))
q = prim_to_cons(w)
for meth in ("davis", "einfeldt"):
assert all(abs(a - b) < 1e-12 for a, b in zip(hll_flux(q, q, method=meth), euler_flux(q)))
ql, qr = prim_to_cons((1.0, 3.0, 1.0)), prim_to_cons((0.8, 3.2, 0.9)) # supersonic to the right
assert hll_flux(ql, qr) == euler_flux(ql)
ql, qr = prim_to_cons((1.0, -3.0, 1.0)), prim_to_cons((0.8, -3.2, 0.9)) # supersonic to the left
assert hll_flux(ql, qr) == euler_flux(qr)
def test_hll_state_is_the_average_of_the_exact_fan() -> None:
sample, _, _ = exact_solution(*SOD)
sl, sr, n = -2.0, 2.0, 4000 # these speeds bound all Sod waves (the shock moves at 1.75216)
avg = [0.0, 0.0, 0.0]
for k in range(n):
q = prim_to_cons(sample(sl + (sr - sl) * (k + 0.5) / n))
for i in range(3):
avg[i] += q[i] / n
star = hll_state(prim_to_cons(SOD[0]), prim_to_cons(SOD[1]), sl, sr)
assert all(abs(a - b) < 2e-3 for a, b in zip(avg, star))
assert abs(star[0] - 0.5625) < 1e-14 and abs(star[1] - 0.225) < 1e-14 # (2 rho_R + 2 rho_L) / 4 and (0.1 - 1) / -4
def test_sod_l1_error_decreases() -> None:
e100, e200 = sod_l1(100), sod_l1(200)
assert e200 < 0.0105 and e100 < 0.0155
assert 0.4 < log2(e100 / e200) < 0.8
def test_first_order_on_a_smooth_wave() -> None:
t, errs = 0.1, []
for m in (25, 50, 100):
cells = [prim_to_cons((r, 1.0, 1.0)) for r in density_wave(m, 0.0)]
cells, _ = solve_euler(cells, 1.0 / m, t, periodic=True)
errs.append(sum(abs(q[0] - e) for q, e in zip(cells, density_wave(m, t))) / m)
orders = [log2(errs[i] / errs[i + 1]) for i in range(2)]
assert all(abs(p - 1.0) < 0.2 for p in orders)
def test_conservation_on_a_periodic_grid() -> None:
m = 64
cells = [prim_to_cons((r, 1.0, 1.0)) for r in density_wave(m, 0.0)]
before = [sum(q[k] for q in cells) for k in range(3)]
cells, _ = solve_euler(cells, 1.0 / m, 0.05, periodic=True)
after = [sum(q[k] for q in cells) for k in range(3)]
assert all(abs(a - b) <= 1e-12 * abs(a) for a, b in zip(before, after))
def test_exact_conservation_for_burgers_in_fractions() -> None:
f, df = (lambda u: u * u / 2), (lambda u: u)
rng = random.Random(2)
u = [Fraction(rng.randint(-8, 8), 4) for _ in range(12)]
total = sum(u)
for _ in range(5):
u = step(u, Fraction(1, 10), Fraction(1, 2), lambda a, b: hll_scalar(a, b, f, df), periodic=True)
assert sum(u) == total
def test_tvd_and_no_new_extrema_for_burgers() -> None:
f, df = (lambda u: u * u / 2), (lambda u: u)
m, dx = 80, 1.0 / 80
u = [1.0 if 0.2 < (j + 0.5) * dx < 0.5 else -0.5 for j in range(m)]
tv0 = sum(abs(u[j + 1] - u[j]) for j in range(m - 1))
for _ in range(60):
dt = 0.5 * dx / max(abs(v) for v in u)
u = step(u, dt, dx, lambda a, b: hll_scalar(a, b, f, df))
tv = sum(abs(u[j + 1] - u[j]) for j in range(m - 1))
assert tv <= tv0 + 1e-12
assert -0.5 - 1e-12 <= min(u) and max(u) <= 1.0 + 1e-12
tv0 = tv
def test_transonic_rarefaction_is_opened() -> None:
assert hll_scalar(-1.0, 1.0, lambda u: u * u / 2, lambda u: u) == -0.5 # not f(-1) = f(1), so the jump spreads
def test_stationary_contact_is_smeared_but_u_and_p_stay_exact() -> None:
m = 40
cells = [prim_to_cons((1.0 if j < m // 2 else 0.5, 0.0, 1.0)) for j in range(m)]
cells, _ = solve_euler(cells, 1.0 / m, 0.1)
w = [cons_to_prim(q) for q in cells]
assert all(abs(x[1]) < 1e-13 and abs(x[2] - 1.0) < 1e-13 for x in w)
assert abs(w[m // 2][0] - 0.5) > 0.05
def test_positivity_on_the_123_problem() -> None:
m = 100
cells = [prim_to_cons((1.0, -2.0, 0.4) if j < m // 2 else (1.0, 2.0, 0.4)) for j in range(m)]
cells, _ = solve_euler(cells, 1.0 / m, 0.15)
w = [cons_to_prim(q) for q in cells]
assert min(x[0] for x in w) > 0.02 and min(x[2] for x in w) > 0.0
History
Harten, Lax and van Leer (1983) set up the theory of approximate Riemann solvers that are consistent with the integral form of the conservation law and of the entropy condition, and gave the solver with one middle state as the simplest example. Davis (1988) and Einfeldt (1988) proposed the speed estimates. Einfeldt showed that the choice with Roe averages keeps the density and the internal energy positive, and Einfeldt, Munz, Roe and Sjögreen (1991) showed that linearized solvers such as Roe's cannot have this property. Toro, Spruce and Speares (1994) added the contact wave to get HLLC.
References
- Amiram Harten, Peter D. Lax and Bram van Leer, On upstream differencing and Godunov-type schemes for hyperbolic conservation laws, SIAM Review 25(1) (1983) 35-61, the approximate Riemann solver with one intermediate state, its consistency with the integral form of the conservation law and of the entropy condition; doi:10.1137/1025002
- Bernd Einfeldt, On Godunov-type methods for gas dynamics, SIAM Journal on Numerical Analysis 25(2) (1988) 294-318, the speed estimates with Roe averages (HLLE) and positivity; doi:10.1137/0725021
- S. F. Davis, Simplified second-order Godunov-type methods, SIAM Journal on Scientific and Statistical Computing 9(3) (1988) 445-473, the simple speed estimates from the two states; doi:10.1137/0909030
- Bernd Einfeldt, Claus-Dieter Munz, Philip L. Roe and Björn Sjögreen, On Godunov-type methods near low densities, Journal of Computational Physics 92 (1991) 273-295, positively conservative schemes; the HLLE scheme is positive and linearized solvers are not; doi:10.1016/0021-9991(91)90211-3
- Eleuterio F. Toro, Riemann Solvers and Numerical Methods for Fluid Dynamics, third edition, Springer, 2009, Chapter 10 (the HLL and HLLC solvers and the wave speed estimates)
- Randall J. LeVeque, Finite Volume Methods for Hyperbolic Problems, Cambridge University Press, 2002, Section 15.3 (approximate Riemann solvers, including the HLL solver), Section 12.10 (the Lax-Wendroff theorem)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag MA9G95 Edit this page History Report an error Markdown