Algorithmcore
Roe solver
Also called Roe approximate Riemann solver, Roe linearization.
Approximates the Riemann problem by a linear one with a Roe-averaged Jacobian that resolves single shocks exactly.
- Time
- O(m^2 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
- conservativedeterministicnot entropy satisfyingexact single discontinuityexplicitkeeps stationary contactnot positive
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Philip L. Roe, 1981
The Roe solver replaces the nonlinear Riemann problem at a cell face by a linear one, , with a constant matrix built from the two neighbor states. Roe (1981) chose so that holds exactly. This "property U" makes the method conservative and makes it resolve any single shock or contact exactly. For the Euler equations, is the Jacobian at a special average of the two states, the Roe average, weighted by . The flux needs the eigenvalues and eigenvectors of but no iteration. It is one of the sharpest first order fluxes. It has two known flaws: it accepts expansion shocks, so it needs an entropy fix, and it can give negative pressure near vacuum.
In plain words
The exact Riemann problem at a face is nonlinear and needs an iteration. Roe asks a simpler question: which linear problem gives the right answer? A linear problem is a set of waves that each move at one fixed speed. Roe found an average state such that the linear waves at that state add up exactly to the jump between the two cells, and their fluxes add up exactly to the jump in the flux. Then each wave is upwinded by the sign of its own speed. A single shock, or a single contact, is one wave of the linear problem, so it comes out exactly right.
The problem
Given cell averages of a hyperbolic conservation law , compute a face flux from and for the update . The flux should be exact for a single discontinuity. The page uses the Euler equations with , , , and , and a scalar law.
The algorithm
ROE-FLUX(U_L, U_R)- 1
ũ <- (√ρ_L u_L + √ρ_R u_R)/(√ρ_L + √ρ_R); H̃ <- (√ρ_L H_L + √ρ_R H_R)/(√ρ_L + √ρ_R); c̃ <- √((γ-1)(H̃ - ũ²/2)) - 2
λ <- (ũ - c̃, ũ, ũ + c̃); r_1 <- (1, ũ - c̃, H̃ - ũc̃); r_2 <- (1, ũ, ũ²/2); r_3 <- (1, ũ + c̃, H̃ + ũc̃) - 3
Δ <- U_R - U_L; α_2 <- (γ-1)/c̃² (Δ_0 (H̃ - ũ²) + ũ Δ_1 - Δ_2); α_1 <- (Δ_0 (ũ + c̃) - Δ_1 - c̃ α_2)/(2c̃); α_3 <- Δ_0 - α_1 - α_2 - 4
return (F(U_L) + F(U_R))/2 - (1/2) Σ_k |λ_k| α_k r_k 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} <- ROE-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})
For a scalar law the code uses the same lines with one wave: (or if the states are equal) and . This is the Murman-Roe scheme. The time step is with forward Euler. The code has no entropy fix. The Harten-Hyman entropy fix page adds one.
Example
The flux by hand. Take Sod's states and , so . Line L1 gives , and . Line L3 gives
The waves and have , the wave has . Line L4 gives the mass flux , the momentum flux (the two acoustic terms cancel), and the energy flux . The exact Godunov flux is . The Roe mass flux is closer to it than the HLL value .
Sod's tube. On with outflow boundaries and Courant number 0.9 at , the density errors against exact cell averages, measured with the code on this page, are 0.01319 (, 48 steps), 0.00886 (, 97 steps) and 0.00565 (, 194 steps). The observed orders are 0.57 and 0.65. On the same grids HLLC gives 0.01387, 0.00919 and 0.00581. The rarefaction of Sod's problem is not transonic: its head moves at and its tail at . So the missing entropy fix does no harm here.
A smooth wave. For , , on a periodic grid, the density errors at for are , , and , with orders 1.01, 0.99 and 1.00. These are the HLLC numbers to all digits shown: with constant and the data are pure contact waves, and both solvers give the upwind flux for them.
Three discontinuities at rest. Take a Mach 2 shock at rest: and . It satisfies the Rankine-Hugoniot condition with speed 0. On 40 cells, after 30 steps, the solution is unchanged to . A contact at rest is also kept. Now swap the two states. The result is a jump from subsonic to supersonic flow at rest, an expansion shock, which violates the entropy condition. The Roe scheme keeps it too, unchanged. For Burgers' equation the jump from to gives , the flux on every face, and the same steady expansion shock.
Negative pressure. The 123 problem has and . At the center face , and , and . The Roe flux is : no mass and no energy leaves the center, but the momentum flux is much less than the true . On 100 cells with the Courant number 0.9, after one step the two center cells have and . HLL and HLLC run the same problem with positive pressure.
Correctness
The proof is in proofs/correctness.md. Theorem: (1) for any two physical states. (2) Property U: with the parameter vector , both and are quadratic in , so exactly, where is the Jacobian at . (3) The are the eigenvectors of and . (4) The Roe flux is the Godunov flux of the linear problem . (5) The flux is consistent and the scheme is conservative. (6) If and are joined by a single discontinuity of speed , the flux is for and for , so a single shock or contact is exact, and one at rest is a steady solution. (7) For a scalar law, the Murman-Roe scheme is TVD for . The scheme does not satisfy the entropy condition and is not positive, as the examples show.
Proof: The Roe matrix has property U, the Roe flux is the Godunov flux of the linearized problem, and a single discontinuity is resolved exactlyfull
Setting. The system is the 1D Euler equations for an ideal gas with , , enthalpy and , so that . At a face with states , , line L1 computes the Roe averages with :
Line L2 takes , , and
Line L3 computes, with ,
and line L4 returns .
Lemma 1 (). For any two states with positive density and pressure, .
Proof. Let . Since ,
which is positive.
Lemma 2 (property U). Let be the state with velocity and enthalpy (its density does not matter), and let be the Jacobian written as a function of and evaluated at . Then .
Proof. Use Roe's parameter vector . A direct computation gives
using . Every component of and of is a quadratic form in . For a quadratic form with symmetric, with , exactly. So
where and are linear in . is lower triangular with diagonal , so for . Hence . By the chain rule at every state, so is the Jacobian at the state whose parameter vector is . That state has and . The Jacobian of the Euler equations depends on the state only through and , so it is .
Lemma 3 (eigenstructure and wave strengths). for , and .
Proof. In terms of and the Euler Jacobian is
For : the rows give , and , which is . For : the first row gives . The second row gives , and with this is . The third row minus is . So at every with , in particular at .
For the strengths, compare components of with . The first component is by the definition of . The second is , so we need . The third is . Put in and the value of : the condition becomes , which is the formula for because (positive by Lemma 1). Then , which is the formula of line L3.
Lemmas 2 and 3 together give . The test checks both identities on 100 random pairs of states.
Theorem 1 (the Roe flux is the Godunov flux of the linearized problem). Let solve the linear Riemann problem with data , . Then , so the Roe flux is the flux of the linearized solution at the face, made consistent with by property U.
Proof. The solution of the linear problem is . So
where the second form uses . The mean of the two forms is .
Theorem 2 (consistency and conservation). , and on a periodic grid the scheme keeps .
Proof. With , , so all , and the flux is . The update is in conservation form, so the sum telescopes.
Theorem 3 (a single discontinuity is exact). Let satisfy the Rankine-Hugoniot condition for some speed . Then is an eigenvector of with eigenvalue , and if and if , the flux of the moving discontinuity. If , a grid with on the left and on the right of one face is a steady solution of the scheme. This holds whether or not the discontinuity satisfies the entropy condition.
Proof. By Lemma 2, . The eigenvalues of are distinct (Lemma 1 gives ), so is a multiple of one eigenvector with , and by Lemma 3, has only that component. Then , and
which is for and for . For , . Every other face has equal states and the flux or . All flux differences are zero.
The tests check this for a contact at rest, a Mach 2 shock at rest, and the same pair of states swapped, which is an expansion shock at rest. The scheme keeps all three to . The last one is not an entropy solution: this is why Roe's scheme needs an entropy fix.
Theorem 4 (a scalar law). For the Roe flux is with . If the scheme is TVD.
Proof. The scheme is with and , since and . So , and Harten's lemma (Lemma 3 of the proof on the Rusanov flux page) applies.
Remark (what is not true). The Roe scheme does not satisfy the entropy condition (Theorem 3 with an expansion shock), and it is not positively conservative. Einfeldt, Munz, Roe and Sjögreen (1991) showed that schemes based on linearized Riemann solvers, Roe's among them, are not positive for all data. The test shows it on the 123 problem: after one step, the two center cells have negative pressure.
Complexity
Theorem, in the real-RAM model: for a system of equations, the Roe flux costs operations once the eigenvectors are known in closed form, as here, plus a constant number of square roots. One step costs and the memory is . A fixed end time at a fixed Courant number takes steps, so the total is . For the Euler equations, , and the cost is a few times that of HLL.
Properties
- Exact for single waves. The face flux of a single shock or contact is exact. One at rest stays sharp. A moving one still smears over a few cells, because the scheme averages over each cell every step.
- Upwind on each field. Each wave is upwinded by the sign of its own speed, so the dissipation on the contact wave is , which is zero for a contact at rest.
- Not entropy satisfying. A sonic point is where some changes sign. There the dissipation is zero and an expansion shock can stay. The Harten-Hyman fix adds dissipation there.
- Not positive. Near vacuum and in strong rarefactions it can give negative density or pressure, as on the 123 problem.
- Carbuncle. In 2D, a strong shock aligned with the grid can grow a spurious bump, the carbuncle (Quirk 1994).
Variants and improvements
- Entropy fixes. The Harten-Hyman fix replaces near a sonic point by a larger value. Harten's earlier fix uses a smooth parabola with a fixed width.
- Roe-type schemes for other systems. A matrix with property U exists for every system with a convex entropy (Harten, Lax and van Leer 1983). For shallow water, MHD and real gases, special averages are known.
- HLLE and HLLC. These need only speed estimates and are positive. HLLC keeps contacts like Roe.
- Flux difference splitting. The Roe flux can be written , a split of the flux difference into left and right going parts. It contrasts with flux vector splitting (LeVeque 2002, Section 4.13).
- High order. Use the flux on MUSCL or WENO values with a Runge-Kutta method.
When to use it
Use the Roe solver when sharp shocks and contacts matter and the flow stays away from vacuum, for example in steady aerodynamics. Always add an entropy fix. Prefer HLLC or HLLE near vacuum, in strong rarefactions and at strong shocks aligned with the grid. For systems with no closed form eigenvectors, the cost of the Roe solver grows, and HLL type solvers are simpler.
Pitfalls
- No entropy fix. Without one, a transonic rarefaction can turn into an expansion shock. This is the most common error with Roe's solver.
- The arithmetic mean. Taking as the Jacobian at breaks property U. The scheme is then still conservative, but shocks are no longer exact. The weights must be .
- Negative pressure. Check density and pressure after each step, and fall back to HLL in cells where they become negative.
- Dividing by . The strengths of line L3 divide by . Lemma 1 of the proof shows for physical states, but a state with gives a domain error.
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/roe-solver/. The authors are listed in prov/9FFHHH.jsonl.
"""Roe approximate Riemann solver for the 1D Euler equations (Roe 1981), without an entropy fix.
The flux is (F_L + F_R)/2 - (1/2) sum_k |lambda_k| alpha_k r_k, where lambda_k and r_k are the
eigenvalues and eigenvectors of the Jacobian at the Roe average and alpha = R^{-1}(U_R - U_L).
"""
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 roe_average(ql, qr, g=GAMMA):
"""The Roe averages (u, H, c), weighted by the square roots of the densities."""
rl, ul, pl = cons_to_prim(ql, g)
rr, ur, pr = cons_to_prim(qr, g)
wl, wr = sqrt(rl), sqrt(rr)
u = (wl * ul + wr * ur) / (wl + wr)
h = (wl * (ql[2] + pl) / rl + wr * (qr[2] + pr) / rr) / (wl + wr)
return u, h, sqrt((g - 1.0) * (h - 0.5 * u * u))
def roe_waves(ql, qr, g=GAMMA):
"""The eigenvalues, the right eigenvectors and the wave strengths of the Roe matrix."""
u, h, c = roe_average(ql, qr, g) # @line L1
lam = (u - c, u, u + c) # @line L2
vecs = ((1.0, u - c, h - u * c), (1.0, u, 0.5 * u * u), (1.0, u + c, h + u * c))
d0, d1, d2 = (b - a for a, b in zip(ql, qr)) # @line L3
a2 = (g - 1.0) / (c * c) * (d0 * (h - u * u) + u * d1 - d2)
a1 = (d0 * (u + c) - d1 - c * a2) / (2.0 * c)
return lam, vecs, (a1, a2, d0 - a1 - a2)
def roe_flux(ql, qr, g=GAMMA):
"""The Roe flux at the face between the conserved states ql and qr."""
lam, vecs, alpha = roe_waves(ql, qr, g)
fl, fr = euler_flux(ql, g), euler_flux(qr, g)
return tuple(0.5 * (fl[i] + fr[i]) - 0.5 * sum(abs(lam[k]) * alpha[k] * vecs[k][i] for k in range(3)) for i in range(3)) # @line L4
def roe_scalar(ul, ur, f, df):
"""The Roe flux for a scalar law: the speed is the slope of the chord of f."""
a = (f(ur) - f(ul)) / (ur - ul) if ur != ul else df(ul) # @line L1
return (f(ul) + f(ur)) / 2 - abs(a) * (ur - ul) / 2 # @line L4
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):
"""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: roe_flux(a, b, g)
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_roe_solver.py 200 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/roe-solver/. The authors are listed in prov/9FFHHH.jsonl.
import random
from fractions import Fraction
from math import cos, log2, pi, sqrt
from roe_solver import (
cons_to_prim,
euler_flux,
prim_to_cons,
roe_flux,
roe_scalar,
roe_waves,
solve_euler,
step,
)
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
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)
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 normal_shock(mach, g=1.4):
"""A shock at rest: the supersonic state (1, M c, 1) and the subsonic state behind it."""
u = mach * sqrt(g)
r = (g + 1.0) * mach**2 / ((g - 1.0) * mach**2 + 2.0)
p = (2.0 * g * mach**2 - (g - 1.0)) / (g + 1.0)
return (1.0, u, 1.0), (r, u / r, p)
def run_steps(cells, n, cfl=0.9):
dx = 1.0 / len(cells)
for _ in range(n):
smax = max(abs(cons_to_prim(q)[1]) + sqrt(1.4 * cons_to_prim(q)[2] / q[0]) for q in cells)
cells = step(cells, cfl * dx / smax, dx, roe_flux)
return cells
def test_flux_at_the_sod_interface_by_hand() -> None:
ql, qr = prim_to_cons(SOD[0]), prim_to_cons(SOD[1])
lam, _, alpha = roe_waves(ql, qr)
h = (3.5 + sqrt(0.125) * 2.8) / (1.0 + sqrt(0.125))
c = sqrt(0.4 * h)
a2 = 0.4 / (c * c) * (-0.875 * h + 2.25)
assert abs(alpha[1] - a2) < 1e-14 and abs(alpha[0] - (-0.875 - a2) / 2) < 1e-14 and alpha[0] == alpha[2]
f = roe_flux(ql, qr)
assert abs(f[0] + c * alpha[0]) < 1e-14 and abs(f[1] - 0.55) < 1e-14 and abs(f[2] + c * alpha[0] * h) < 1e-14
assert abs(f[0] - 0.390660) < 1e-6 and abs(f[2] - 1.295882) < 1e-6
def test_property_u() -> None:
rng = random.Random(4)
for _ in range(100):
ql = prim_to_cons((rng.uniform(0.1, 3), rng.uniform(-3, 3), rng.uniform(0.1, 3)))
qr = prim_to_cons((rng.uniform(0.1, 3), rng.uniform(-3, 3), rng.uniform(0.1, 3)))
lam, vecs, alpha = roe_waves(ql, qr)
df = [b - a for a, b in zip(euler_flux(ql), euler_flux(qr))]
for i in range(3):
assert abs(sum(alpha[k] * vecs[k][i] for k in range(3)) - (qr[i] - ql[i])) < 1e-11
assert abs(sum(lam[k] * alpha[k] * vecs[k][i] for k in range(3)) - df[i]) < 1e-10 * (1 + abs(df[i]))
def test_consistency() -> None:
rng = random.Random(1)
for _ in range(50):
q = prim_to_cons((rng.uniform(0.1, 2), rng.uniform(-2, 2), rng.uniform(0.1, 2)))
assert all(abs(a - b) < 1e-12 for a, b in zip(roe_flux(q, q), euler_flux(q)))
def test_stationary_contact_is_kept_exactly() -> 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[0] - (1.0 if j < m // 2 else 0.5)) < 1e-13 for j, x in enumerate(w))
assert all(abs(x[1]) < 1e-13 and abs(x[2] - 1.0) < 1e-13 for x in w)
def test_stationary_shock_is_kept_exactly() -> None:
a, b = normal_shock(2.0)
assert abs(b[0] - 8.0 / 3.0) < 1e-14 and abs(b[2] - 4.5) < 1e-14
cells = [prim_to_cons(a if j < 20 else b) for j in range(40)]
out = run_steps(cells, 30)
assert all(abs(x - y) < 1e-12 for p, q in zip(cells, out) for x, y in zip(p, q))
def test_stationary_expansion_shock_is_also_kept() -> None:
a, b = normal_shock(2.0)
cells = [prim_to_cons(b if j < 20 else a) for j in range(40)] # subsonic to supersonic: violates the entropy condition
out = run_steps(cells, 30)
assert all(abs(x - y) < 1e-12 for p, q in zip(cells, out) for x, y in zip(p, q))
u = [-1.0] * 10 + [1.0] * 10 # the same for Burgers' equation
out = step(u, 0.05, 0.1, lambda x, y: roe_scalar(x, y, lambda v: v * v / 2, lambda v: v))
assert out == u
def test_sod_l1_error_decreases() -> None:
e100, e200 = sod_l1(100), sod_l1(200)
assert e200 < 0.0092 and e100 < 0.0137
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() -> 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))
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 x, y: roe_scalar(x, y, lambda v: v * v / 2, lambda v: v), periodic=True)
assert sum(u) == total
def test_tvd_for_burgers() -> None:
f, df = (lambda v: v * v / 2), (lambda v: v)
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):
u = step(u, 0.9 * dx / max(abs(v) for v in u), dx, lambda x, y: roe_scalar(x, y, f, df))
tv = sum(abs(u[j + 1] - u[j]) for j in range(m - 1))
assert tv <= tv0 + 1e-12
tv0 = tv
def test_negative_pressure_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 = run_steps(cells, 1) # Roe's linearization is not positively conservative
assert min(cons_to_prim(q)[2] for q in cells) < 0.0
History
Roe (1981) introduced the linearization with property U and the parameter vector for the Euler equations. The scalar scheme is often called the Murman-Roe scheme, after earlier work of Murman on transonic flow. Harten, Lax and van Leer (1983) proved that a Roe matrix exists for every system with a convex entropy. Harten and Hyman (1983) gave the entropy fix used with the solver. Einfeldt, Munz, Roe and Sjögreen (1991) showed that linearized solvers are not positive, and Quirk (1994) collected the failures of the solver in 2D, among them the carbuncle.
References
- P. L. Roe, Approximate Riemann solvers, parameter vectors, and difference schemes, Journal of Computational Physics 43(2) (1981) 357-372, property U, the parameter vector and the averaged Jacobian for the Euler equations; doi:10.1016/0021-9991(81)90128-5
- Randall J. LeVeque, Finite Volume Methods for Hyperbolic Problems, Cambridge University Press, 2002, Section 4.14 (Roe's method for linear systems), Section 15.3 (approximate Riemann solvers, the Roe linearization and the entropy fix)
- Eleuterio F. Toro, Riemann Solvers and Numerical Methods for Fluid Dynamics, third edition, Springer, 2009, Chapter 11 (the Riemann solver of Roe, the Roe averages, the wave strengths and the entropy fix)
- 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, linearized Riemann solvers are not positively conservative; doi:10.1016/0021-9991(91)90211-3
- James J. Quirk, A contribution to the great Riemann solver debate, International Journal for Numerical Methods in Fluids 18(6) (1994) 555-574, failures of the Roe solver such as the carbuncle and the odd-even decoupling; doi:10.1002/fld.1650180603
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 9FFHHH Edit this page History Report an error Markdown