Algorithm Search⌘K

Algorithmadvanced

AUSM scheme

Also called advection upstream splitting method.

Splits the flux into a convective part upwinded by an interface Mach number and a pressure part, and keeps contacts at rest exactly.

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
Properties
conservativedeterministicexplicitnot keeps moving contactkeeps stationary contact
Origin
Meng Sing Liou, Christopher J. Steffen, 1993

The AUSM scheme (advection upstream splitting method) of Liou and Steffen (1993) is a face flux for the Euler equations that sits between flux vector splitting and Riemann solvers. It writes the Euler flux as a convective part, the velocity times (ρ,ρu,ρH)(\rho, \rho u, \rho H), plus a pressure part (0,p,0)(0, p, 0). The convective part is upwinded with one interface Mach number, made from the right-going Mach part of the left state and the left-going Mach part of the right state. The pressure is split in the same way. The flux costs about as much as flux vector splitting and needs no Riemann solver. Unlike van Leer's splitting, it keeps a contact at rest exactly. The price is that no mass and no energy cross a face between two states at rest, which limits the time step on shock tubes.

In plain words

Gas carries mass, momentum and energy along with it, and pressure pushes on it. AUSM treats these two effects apart. For the carried part, it asks how fast the gas crosses the face, in units of the speed of sound. Each side gives its share of that Mach number, the two shares are added, and the sign of the sum says which side the carried values come from. For the push, each side gives its share of the pressure. When the gas is faster than sound, everything comes from upstream. When the gas is at rest on both sides, the two Mach shares cancel, so nothing is carried, and the pressure is the mean of the two sides.

The problem

Given cell averages UjnU_j^n of the Euler equations Ut+F(U)x=0U_t + F(U)_x = 0 with U=(ρ,ρu,E)U = (\rho, \rho u, E), F(U)=(ρu,ρu2+p,u(E+p))F(U) = (\rho u, \rho u^2 + p, u(E + p)), E=p/(γ−1)+ρu2/2E = p/(\gamma - 1) + \rho u^2/2, c=γp/ρc = \sqrt{\gamma p/\rho}, H=(E+p)/ρH = (E + p)/\rho, M=u/cM = u/c and γ=1.4\gamma = 1.4, compute face fluxes from the two neighbor states that make the conservative update Ujn+1=Ujn−ΔtΔx(Fj+1/2−Fj−1/2)U_j^{n+1} = U_j^n - \frac{\Delta t}{\Delta x}(F_{j+1/2} - F_{j-1/2}) consistent and upwind, and that keep contacts sharp.

The algorithm

  1. AUSM-FLUX(U_L, U_R)
  2. 1M^± <- ±(M ± 1)²/4 if |M| ≤ 1, else (M ± |M|)/2
  3. 2p^± <- p (M ± 1)² (2 ∓ M)/4 if |M| ≤ 1, else p (M ± |M|)/(2M)
  4. 3M_{1/2} <- M_L^+ + M_R^-
  5. 4p_{1/2} <- p_L^+ + p_R^-
  6. 5Φ <- c(ρ, ρu, ρH) of U_L if M_{1/2} ≥ 0, else of U_R
  7. 6return M_{1/2} Φ + (0, p_{1/2}, 0)
  8. FV-STEP(U, Δt, Δx)
  9. 7add one ghost cell on each side (copy for outflow, wrap for periodic); F_{j+1/2} <- AUSM-FLUX(U_j, U_{j+1})
  10. 8for each cell j: U_j <- U_j - (Δt/Δx)(F_{j+1/2} - F_{j-1/2})

Line L1 is van Leer's Mach number split. Line L2 splits the pressure with weights that are 1 and 0 for supersonic flow and that join those values with matching slopes at M=±1M = \pm 1. Since Mc(ρ,ρu,ρH)=(ρu,ρu2,u(E+p))Mc(\rho, \rho u, \rho H) = (\rho u, \rho u^2, u(E + p)), lines L5 and L6 give the Euler flux when both states are equal. Liou and Steffen write line L5 as 12M1/2(ΦL+ΦR)−12∣M1/2∣(ΦR−ΦL)\frac12 M_{1/2}(\Phi_L + \Phi_R) - \frac12|M_{1/2}|(\Phi_R - \Phi_L), which is the same thing. The code uses the time step Δt=0.5 Δx/max⁡(∣u∣+c)\Delta t = 0.5\,\Delta x/\max(|u| + c).

Example

Split values by hand. At M=12M = \frac12, line L1 gives M+=916M^+ = \frac9{16} and M−=−116M^- = -\frac1{16}, and line L2 with p=1p = 1 gives p+=2732p^+ = \frac{27}{32} and p−=532p^- = \frac5{32}. The sums are 12\frac12 and 1. The test checks these values exactly in Fraction arithmetic.

Sod's face. For WL=(ρ,u,p)=(1,0,1)W_L = (\rho, u, p) = (1, 0, 1) and WR=(0.125,0,0.1)W_R = (0.125, 0, 0.1), both states are at rest, so M1/2=14−14=0M_{1/2} = \frac14 - \frac14 = 0, p1/2=0.55p_{1/2} = 0.55, and the flux is (0,0.55,0)(0, 0.55, 0). The exact Godunov flux is (0.395391,0.669837,1.154038)(0.395391, 0.669837, 1.154038) (see the exact Riemann solver). AUSM moves momentum but no mass and no energy across this face in the first step.

A moving contact. For WL=(1,0.5,1)W_L = (1, 0.5, 1) and WR=(0.5,0.5,1)W_R = (0.5, 0.5, 1), the sound speeds are cL=1.183216c_L = 1.183216 and cR=1.673320c_R = 1.673320, so ML=0.422577M_L = 0.422577 and MR=0.298807M_R = 0.298807. Then ML+=0.505931M_L^+ = 0.505931, MR−=−0.122918M_R^- = -0.122918 and M1/2=0.383013M_{1/2} = 0.383013. The pressure is pL++pR−=0.798068+0.282564=1.080632p_L^+ + p_R^- = 0.798068 + 0.282564 = 1.080632. With ΦL=cL(1,0.5,3.625)\Phi_L = c_L(1, 0.5, 3.625), the flux is (0.453188,1.307226,1.642806)(0.453188, 1.307226, 1.642806). The exact flux of this contact is F(UL)=(0.5,1.25,1.8125)F(U_L) = (0.5, 1.25, 1.8125), which the Roe solver gets. So AUSM keeps contacts at rest but not moving contacts.

Sod's tube. On [0,1][0, 1] with the jump at x=0.5x = 0.5, outflow boundaries and Courant number 0.5, the scheme runs to t=0.2t = 0.2. The table gives the L1L^1 error of the density against exact cell averages (a 16-point midpoint rule in each cell), measured with the code on this page and with the codes of the Roe and flux vector splitting pages at the same Courant number.

cells MM AUSM steps Roe van Leer splitting
50 0.02250 43 0.02362 0.02506
100 0.01484 87 0.01626 0.01748
200 0.00952 174 0.01077 0.01151

The Rusanov flux gives 0.02350 with 100 cells. At 100 cells the velocity in the first cell right of the initial jump is 1.010, against the exact value 0.9274 behind the rarefaction. The largest velocity of the Roe run is 0.932. The other cells near the jump are close to the Roe values.

A smooth wave. For ρ=1+0.2sin⁡(2π(x−t))\rho = 1 + 0.2\sin(2\pi(x - t)), u=1u = 1, p=1p = 1 on a periodic grid to t=0.1t = 0.1, the L1L^1 density errors at M=25,50,100,200M = 25, 50, 100, 200 are 0.007065, 0.003573, 0.001797 and 0.000901 (orders 0.98, 0.99 and 1.00).

Correctness

The proof is in proofs/correctness.md. Theorem: the Mach and pressure splits add up to MM and pp and have continuous first derivatives at M=±1M = \pm 1, so the face flux is consistent and continuous, and the scheme is conservative; by the Lax-Wendroff theorem a limit of the scheme is a weak solution. For supersonic flow on both sides the flux is F(UL)F(U_L) or F(UR)F(U_R). Between states at rest the flux is (0,12(pL+pR),0)(0, \frac12(p_L + p_R), 0), so a contact at rest is kept exactly, also in floating point arithmetic. The same fact gives a bound for the first step of a shock tube: the low pressure cell keeps its density and energy but gains the momentum 12λ(pL−pR)\frac12\lambda(p_L - p_R), and its pressure stays positive only if λ<2pL−pR2ρRpR/(γ−1)\lambda < \frac{2}{p_L - p_R}\sqrt{2\rho_R p_R/(\gamma - 1)}.

Proof: The AUSM splits add up to the Mach number and the pressure, the AUSM flux is consistent and upwind for supersonic flow, it keeps contacts at rest exactly, and on a shock tube its first step needs a Courant number bound for positive pressurefull

Setting. The scheme stores cell averages UjnU_j^n of the Euler equations with U=(ρ,ρu,E)U = (\rho, \rho u, E), p=(γ−1)(E−12ρu2)p = (\gamma - 1)(E - \frac12\rho u^2), c=γp/ρc = \sqrt{\gamma p/\rho}, H=(E+p)/ρH = (E + p)/\rho and M=u/cM = u/c. It steps Ujn+1=Ujn−λ(Fj+1/2−Fj−1/2)U_j^{n+1} = U_j^n - \lambda(F_{j+1/2} - F_{j-1/2}) with λ=Δt/Δx\lambda = \Delta t/\Delta x (line L8). The face flux of lines L1 to L6 is

F1/2=M1/2 ΦL/R+(0,p1/2,0),M1/2=ML++MR−,p1/2=pL++pR−,F_{1/2} = M_{1/2}\,\Phi_{L/R} + (0, p_{1/2}, 0), \qquad M_{1/2} = M_L^+ + M_R^-, \qquad p_{1/2} = p_L^+ + p_R^-,

where Φ=c(ρ,ρu,ρH)\Phi = c(\rho, \rho u, \rho H) is taken from the left state if M1/2≥0M_{1/2} \ge 0 and from the right state otherwise. For ∣M∣≤1|M| \le 1 the splits are M±=±14(M±1)2M^\pm = \pm\frac14(M \pm 1)^2 and p±=p4(M±1)2(2∓M)p^\pm = \frac p4(M \pm 1)^2(2 \mp M). For ∣M∣>1|M| > 1 they are M±=12(M±∣M∣)M^\pm = \frac12(M \pm |M|), and p+=pp^+ = p, p−=0p^- = 0 if M>1M > 1, and p+=0p^+ = 0, p−=pp^- = p if M<−1M < -1.

Lemma 1 (the splits). For all MM: M++M−=MM^+ + M^- = M and p++p−=pp^+ + p^- = p. Also M+≥0≥M−M^+ \ge 0 \ge M^-, p±≥0p^\pm \ge 0, M+M^+, M−M^- and p+p^+ do not decrease in MM, and p−p^- does not increase. All four splits are continuous with continuous first derivatives, also at M=±1M = \pm 1.

Proof. For ∣M∣>1|M| > 1 the claims are direct. For ∣M∣≤1|M| \le 1: (M+1)2−(M−1)2=4M(M + 1)^2 - (M - 1)^2 = 4M, so M++M−=MM^+ + M^- = M. Next, (M+1)2(2−M)=−M3+3M+2(M + 1)^2(2 - M) = -M^3 + 3M + 2 and (M−1)2(2+M)=M3−3M+2(M - 1)^2(2 + M) = M^3 - 3M + 2, and the sum is 4, so p++p−=pp^+ + p^- = p. Since 2∓M≥12 \mp M \ge 1, both p±≥0p^\pm \ge 0. The derivatives are ddMM±=12(M±1)\frac{d}{dM}M^\pm = \frac12(M \pm 1), which is ≥0\ge 0 on [−1,1][-1, 1], and ddMp±=±3p4(1−M2)\frac{d}{dM}p^\pm = \pm\frac{3p}4(1 - M^2). At M=1M = 1: M+=1M^+ = 1 with slope 1, M−=0M^- = 0 with slope 0, p+=pp^+ = p and p−=0p^- = 0 with slope 0. These match the supersonic branch M+=MM^+ = M, M−=0M^- = 0, p+=pp^+ = p, p−=0p^- = 0. The point M=−1M = -1 is the mirror image. □\square

The tests check the sums, the signs and the monotonicity exactly in Fraction arithmetic on a grid of 81 Mach numbers in [−2.5,2.5][-2.5, 2.5], and the matching slopes at M=±1M = \pm 1 by one-sided difference quotients.

Lemma 2 (consistency). F1/2(U,U)=F(U)F_{1/2}(U, U) = F(U).

Proof. By Lemma 1, M1/2=MM_{1/2} = M and p1/2=pp_{1/2} = p. Then F1/2=uc c(ρ,ρu,ρH)+(0,p,0)=(ρu,ρu2+p,u(E+p))=F(U)F_{1/2} = \frac uc\,c(\rho, \rho u, \rho H) + (0, p, 0) = (\rho u, \rho u^2 + p, u(E + p)) = F(U). □\square

Lemma 3 (supersonic flow). If ML≥1M_L \ge 1 and MR≥1M_R \ge 1, then F1/2=F(UL)F_{1/2} = F(U_L). If ML≤−1M_L \le -1 and MR≤−1M_R \le -1, then F1/2=F(UR)F_{1/2} = F(U_R).

Proof. In the first case ML+=MLM_L^+ = M_L, MR−=0M_R^- = 0, pL+=pLp_L^+ = p_L and pR−=0p_R^- = 0 (at M=1M = 1 the subsonic formulas give the same values by Lemma 1). So M1/2=ML>0M_{1/2} = M_L > 0, Φ\Phi comes from the left, and F1/2=MLΦL+(0,pL,0)=F(UL)F_{1/2} = M_L\Phi_L + (0, p_L, 0) = F(U_L) as in Lemma 2. The second case is the mirror image. □\square

Lemma 4 (states at rest). If uL=uR=0u_L = u_R = 0, then F1/2=(0,12(pL+pR),0)F_{1/2} = (0, \frac12(p_L + p_R), 0), for any densities.

Proof. ML=MR=0M_L = M_R = 0, so M1/2=14−14=0M_{1/2} = \frac14 - \frac14 = 0 and p1/2=12pL+12pRp_{1/2} = \frac12 p_L + \frac12 p_R. □\square

Proposition 5 (contacts at rest are kept). If all cells have u=0u = 0 and the same pressure pp, then every face flux is (0,p,0)(0, p, 0) and one step leaves every cell unchanged. In floating point arithmetic this holds exactly: M=0M = 0, 14(0+1)2=0.25\frac14(0 + 1)^2 = 0.25, and p4⋅1⋅2+p4⋅1⋅2=p\frac p4 \cdot 1 \cdot 2 + \frac p4 \cdot 1 \cdot 2 = p are computed without rounding.

Proof. Lemma 4 with pL=pR=pp_L = p_R = p. All flux differences are zero. □\square

The test runs a density jump from 1 to 0.125 at rest with p=1p = 1 for 67 steps and finds every cell equal to its start value. A moving contact is not kept: with u=1u = 1 on both sides, ML≠MRM_L \ne M_R because the sound speeds differ, and the test finds uu and pp off by about 0.03 after the contact has moved 0.2.

Proposition 6 (the first step of a shock tube). Let the data be two states at rest, (ρL,0,pL)(\rho_L, 0, p_L) left of a face and (ρR,0,pR)(\rho_R, 0, p_R) right of it, with pL>pRp_L > p_R. After one step the cell right of the face has the pressure

pR−(γ−1)λ2(pL−pR)28ρR,p_R - \frac{(\gamma - 1)\lambda^2(p_L - p_R)^2}{8\rho_R},

which is positive if and only if λ<λ∗=2pL−pR2ρRpRγ−1\lambda < \lambda^* = \frac{2}{p_L - p_R}\sqrt{\frac{2\rho_R p_R}{\gamma - 1}}. The cell left of the face has the same formula with ρL\rho_L and pLp_L.

Proof. By Lemma 4 the cell right of the face has the flux (0,12(pL+pR),0)(0, \frac12(p_L + p_R), 0) on its left face and (0,pR,0)(0, p_R, 0) on its right face. So its density and energy do not change, and its momentum becomes λ12(pL−pR)\lambda\frac12(p_L - p_R). The new pressure is (γ−1)(ER−(ρu)22ρR)(\gamma - 1)\big(E_R - \frac{(\rho u)^2}{2\rho_R}\big) with ER=pR/(γ−1)E_R = p_R/(\gamma - 1), which is the formula. For the left cell the argument is the same. □\square

For Sod's data, λ∗=20.90.0625=0.5556\lambda^* = \frac{2}{0.9}\sqrt{0.0625} = 0.5556, and with the largest speed cL=1.4c_L = \sqrt{1.4} at the start, the largest safe Courant number is λ∗cL=0.6574\lambda^* c_L = 0.6574. The code fails with a negative pressure on Sod's tube for Courant numbers 0.7 to 0.9 and runs at 0.5 and 0.6. For the data (1,0,1000)(1, 0, 1000) and (1,0,0.01)(1, 0, 0.01) the bound is 0.01670.0167. The test checks the formula and the sign change at 0.99λ∗0.99\lambda^* and 1.01λ∗1.01\lambda^*. The cause is that no mass and no energy cross a face between states at rest, while the pressure jump pushes momentum across it.

Theorem 1. The AUSM scheme is conservative and its face flux is consistent with the Euler flux, so by the Lax-Wendroff theorem a limit of the scheme under grid refinement, if it converges boundedly almost everywhere, is a weak solution. Its flux is pure upwinding for supersonic flow and it keeps contacts at rest exactly.

Proof. The update is in flux form, so the sums of the cell values change only by boundary fluxes. Consistency is Lemma 2; the face flux is a continuous function of the two states, because the splits are continuous and M1/2ΦM_{1/2}\Phi is continuous where M1/2M_{1/2} changes sign (both sides give 0 there). The other claims are Lemma 3 and Proposition 5. □\square

What is not proved here. No entropy condition, TVD bound or positivity bound beyond Proposition 6 is proved. The order of accuracy is measured: on the smooth wave ρ=1+0.2sin⁡(2π(x−t))\rho = 1 + 0.2\sin(2\pi(x - t)), u=1u = 1, p=1p = 1 the measured L1L^1 orders are 0.98, 0.99 and 1.00. On Sod's tube the code shows a velocity of 1.010 in the first cell right of the initial jump, against the exact value 0.9274; this glitch is measured, not explained here.

Complexity

Theorem, in the real-RAM model: each face flux costs O(m)O(m) operations and two square roots, for m=3m = 3 conserved components. One step costs O(mM)O(mM) and the memory is O(mM)O(mM). To reach a fixed time at a fixed Courant number takes O(M)O(M) steps, so O(mM2)O(mM^2) in all. There is no iteration, no average state and no eigenvector.

Properties

  • First order. The measured order on the smooth wave is 1.00. For higher order, put reconstructed face values into the flux.
  • Upwind for supersonic flow. If M≥1M \ge 1 on both sides, the face flux is F(UL)F(U_L).
  • Keeps contacts at rest. Proved and tested exactly. Van Leer's flux vector splitting moves mass across such a contact.
  • Does not keep moving contacts. The two sides use their own sound speeds, so a contact moving at u=0.5u = 0.5 gets a mass flux of 0.453 instead of 0.5 in the example. After the contact has moved 0.2 on 100 cells, uu and pp are off by about 0.03.
  • Not positivity preserving. On Sod's tube the first step gives a negative pressure for Courant numbers above 0.6574 (proved). The code fails at 0.7 to 0.9 and runs at 0.5 and 0.6.

Variants and improvements

  • AUSM+. Liou (1996) uses one common sound speed at the face for both Mach numbers and split polynomials of higher degree.
  • High order. Use the flux with MUSCL or WENO face values and a Runge-Kutta time step, as with any face flux.
  • Riemann solvers. HLLC and Roe keep both contacts at rest and moving contacts, at the cost of more work per face.

When to use it

Use AUSM as a cheap face flux for steady and unsteady gas dynamics when contacts at rest must stay sharp and flux vector splitting smears them too much. For shock tubes with large pressure ratios, use a smaller time step, a variant from the AUSM family, or a Riemann solver such as HLLC. If moving contacts must stay sharp, use HLLC or Roe.

Pitfalls

  • The time step on shock tubes. Between states at rest no mass and no energy cross a face. A Courant number that is safe for Roe or HLLC can give a negative pressure in the first step. For the data (1,0,1000)(1, 0, 1000) and (1,0,0.01)(1, 0, 0.01) the bound is 0.0167.
  • A glitch near the initial jump. The code shows a velocity overshoot of about 9 percent in one cell next to the initial jump on Sod's tube.
  • Expecting a sharp moving contact. Only contacts at rest are kept exactly.
  • Mixing up the sides. The interface Mach number is ML++MR−M_L^+ + M_R^-. Taking MR+M_R^+ gives a downwind flux.
  • Mixing AUSM and AUSM+. The original scheme uses cLc_L for MLM_L and cRc_R for MRM_R; AUSM+ uses one common value and other polynomials. The results differ.

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.

ausm_scheme.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ausm-scheme/. The authors are listed in prov/H6NW64.jsonl.

"""The AUSM flux of Liou and Steffen (1993) for the 1D Euler equations.

The Euler flux is split into a convective part, u times (rho, rho u, rho H), and a pressure part
(0, p, 0). The convective part is written as M c (rho, rho u, rho H) and upwinded with one
interface Mach number M_L+ + M_R-. The pressure is p_L+ + p_R-. The split polynomials take
exact Fraction input; the full flux uses a square root for the sound speed.
"""

from math import sqrt

GAMMA = 1.4


def mach_split(mach):
    """(M+, M-): van Leer's Mach number split."""
    if abs(mach) <= 1:  # @line L1
        return (mach + 1) ** 2 / 4, -((mach - 1) ** 2) / 4
    return (mach + abs(mach)) / 2, (mach - abs(mach)) / 2


def pressure_split(mach, p):
    """(p+, p-): the pressure split with the weights (M +- 1)^2 (2 -+ M) / 4."""
    if abs(mach) <= 1:  # @line L2
        return p * (mach + 1) ** 2 * (2 - mach) / 4, p * (mach - 1) ** 2 * (2 + mach) / 4
    return (p, 0 * p) if mach > 0 else (0 * p, p)


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 _side(q, g):
    """(M, p, c (rho, rho u, rho H)) of one state."""
    rho, u, p = cons_to_prim(q, g)
    c = sqrt(g * p / rho)
    return u / c, p, (rho * c, rho * c * u, c * (q[2] + p))


def ausm_flux(ql, qr, g=GAMMA):
    """The AUSM face flux between the states ql and qr."""
    ml, pl, phil = _side(ql, g)
    mr, pr, phir = _side(qr, g)
    m_half = mach_split(ml)[0] + mach_split(mr)[1]  # @line L3
    p_half = pressure_split(ml, pl)[0] + pressure_split(mr, pr)[1]  # @line L4
    phi = phil if m_half >= 0 else phir  # @line L5
    return (m_half * phi[0], m_half * phi[1] + p_half, m_half * phi[2])  # @line L6


def step(cells, dt, dx, flux=ausm_flux, periodic=False):
    """One first order finite volume step with the face flux flux(U_L, U_R)."""
    ext = ([cells[-1]] + list(cells) + [cells[0]]) if periodic else ([cells[0]] + list(cells) + [cells[-1]])  # @line L7
    faces = [flux(ext[j], ext[j + 1]) for j in range(len(ext) - 1)]
    lam = dt / dx
    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))]  # @line L8


def solve_euler(cells, dx, t_end, cfl=0.5, flux=ausm_flux, periodic=False, g=GAMMA):
    """March to t_end with dt = cfl dx / max(|u| + c). Returns (cells, number of steps).

    On Sod's tube the first step gives a negative pressure for cfl above about 0.657.
    """
    t, n = 0.0, 0
    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_ausm_scheme.py 165 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ausm-scheme/. The authors are listed in prov/H6NW64.jsonl.

import random
from fractions import Fraction
from math import cos, log2, pi, sqrt

from ausm_scheme import ausm_flux, cons_to_prim, euler_flux, mach_split, pressure_split, prim_to_cons, solve_euler, step

SOD = ((1.0, 0.0, 1.0), (0.125, 0.0, 0.1))
G = 1.4


def exact_sod_density(xi, g=G):
    """Reference: the exact Sod density at xi = x / t, from the star state found by bisection."""
    (rl, ul, pl), (rr, ur, pr) = SOD
    cl, cr = sqrt(g * pl / rl), sqrt(g * pr / rr)
    z = (g - 1.0) / (2.0 * g)

    def fl(p):  # rarefaction to the left
        return 2.0 * cl / (g - 1.0) * ((p / pl) ** z - 1.0)

    def fr(p):  # shock to the right
        return (p - pr) * sqrt(2.0 / ((g + 1.0) * rr) / (p + (g - 1.0) / (g + 1.0) * pr))

    lo, hi = pr, pl
    for _ in range(100):
        mid = 0.5 * (lo + hi)
        lo, hi = (lo, mid) if fl(mid) + fr(mid) > 0.0 else (mid, hi)
    ps = 0.5 * (lo + hi)
    us = 0.5 * (fr(ps) - fl(ps))
    r = ps / pr
    rs_r = rr * (r + (g - 1.0) / (g + 1.0)) / ((g - 1.0) / (g + 1.0) * r + 1.0)
    shock = ur + cr * sqrt((g + 1.0) / (2.0 * g) * r + z)
    cs = cl * (ps / pl) ** z
    if xi <= -cl:
        return rl
    if xi <= us - cs:
        return rl * (2.0 / (g + 1.0) + (g - 1.0) / ((g + 1.0) * cl) * (-xi)) ** (2.0 / (g - 1.0))
    if xi <= us:
        return rl * (ps / pl) ** (1.0 / g)
    return rs_r if xi <= shock else rr


def sod(m, flux=ausm_flux, t=0.2):
    cells = [prim_to_cons(SOD[0] if (j + 0.5) / m < 0.5 else SOD[1]) for j in range(m)]
    cells, n = solve_euler(cells, 1.0 / m, t, flux=flux)
    ex = [sum(exact_sod_density(((j + (k + 0.5) / 16) / m - 0.5) / t) for k in range(16)) / 16 for j in range(m)]
    return sum(abs(q[0] - e) for q, e in zip(cells, ex)) / m, n, cells


def rusanov(ql, qr):
    """Reference baseline: the Rusanov flux."""
    s = max(abs(w[1]) + sqrt(G * w[2] / w[0]) for w in (cons_to_prim(ql), cons_to_prim(qr)))
    fl, fr = euler_flux(ql), euler_flux(qr)
    return tuple(0.5 * (a + b) - 0.5 * s * (y - x) for a, b, x, y in zip(fl, fr, ql, qr))


def close(a, b, tol=1e-12):
    return all(abs(x - y) <= tol * (1.0 + abs(y)) for x, y in zip(a, b))


def test_split_values_by_hand() -> None:
    q = Fraction
    assert mach_split(q(1, 2)) == (q(9, 16), q(-1, 16))
    assert pressure_split(q(1, 2), q(1)) == (q(27, 32), q(5, 32))
    assert mach_split(q(0)) == (q(1, 4), q(-1, 4)) and pressure_split(q(0), q(1)) == (q(1, 2), q(1, 2))


def test_splits_add_up_and_have_signs() -> None:
    grid = [Fraction(k, 16) for k in range(-40, 41)]
    for m in grid:
        mp, mm = mach_split(m)
        pp, pm = pressure_split(m, Fraction(3))
        assert mp + mm == m and pp + pm == 3
        assert mp >= 0 >= mm and pp >= 0 and pm >= 0
    for a, b in zip(grid, grid[1:]):  # M+, M- and p+ do not decrease in M, p- does not increase
        assert mach_split(a)[0] <= mach_split(b)[0] and mach_split(a)[1] <= mach_split(b)[1]
        assert pressure_split(a, 1)[0] <= pressure_split(b, 1)[0] and pressure_split(a, 1)[1] >= pressure_split(b, 1)[1]


def test_splits_are_smooth_at_the_sonic_points() -> None:
    h = Fraction(1, 1000)
    for s in (1, -1):
        one = Fraction(s)
        for f in (lambda m: mach_split(m)[0], lambda m: mach_split(m)[1], lambda m: pressure_split(m, 1)[0], lambda m: pressure_split(m, 1)[1]):
            inside, outside = (f(one - s * h) - f(one)) / (-s * h), (f(one + s * h) - f(one)) / (s * h)
            assert abs(inside - outside) <= h  # the one-sided slopes agree up to O(h)


def test_consistency_with_the_euler_flux() -> None:
    rng = random.Random(5)
    for _ in range(200):
        q = prim_to_cons((rng.uniform(0.1, 3.0), rng.uniform(-4.0, 4.0), rng.uniform(0.1, 3.0)))
        assert close(ausm_flux(q, q), euler_flux(q))


def test_supersonic_flow_is_pure_upwinding() -> None:
    rng = random.Random(7)
    for _ in range(100):
        wl, wr = [(rng.uniform(0.1, 2.0), 0.0, rng.uniform(0.1, 2.0)) for _ in range(2)]
        cl, cr = sqrt(G * wl[2] / wl[0]), sqrt(G * wr[2] / wr[0])
        speed = rng.uniform(1.0, 3.0) * max(cl, cr)
        ql, qr = prim_to_cons((wl[0], speed, wl[2])), prim_to_cons((wr[0], speed, wr[2]))
        assert close(ausm_flux(ql, qr), euler_flux(ql))
        ql, qr = prim_to_cons((wl[0], -speed, wl[2])), prim_to_cons((wr[0], -speed, wr[2]))
        assert close(ausm_flux(ql, qr), euler_flux(qr))


def test_face_fluxes_by_hand() -> None:
    ql, qr = prim_to_cons(SOD[0]), prim_to_cons(SOD[1])
    assert close(ausm_flux(ql, qr), (0.0, 0.55, 0.0))  # states at rest: no mass or energy crosses
    got = ausm_flux(prim_to_cons((1.0, 0.5, 1.0)), prim_to_cons((0.5, 0.5, 1.0)))
    assert close(got, (0.453188, 1.307226, 1.642806), 1e-6)


def test_stationary_contact_is_kept_exactly() -> None:
    m = 100
    cells = [prim_to_cons((1.0 if (j + 0.5) / m < 0.5 else 0.125, 0.0, 1.0)) for j in range(m)]
    out, n = solve_euler(cells, 1.0 / m, 0.1)
    assert out == cells and n == 67


def test_first_step_pressure_bound() -> None:
    # Two states at rest: the cell right of the jump gains momentum lam (pL - pR) / 2 and keeps rho and E.
    (rl, _, pl), (rr, _, pr) = SOD
    lam_star = 2.0 / (pl - pr) * sqrt(2.0 * rr * pr / (G - 1.0))
    cells = [prim_to_cons(SOD[0])] * 4 + [prim_to_cons(SOD[1])] * 4
    for f in (0.99, 1.01):
        lam = f * lam_star
        new = step(cells, lam, 1.0)
        p = (G - 1.0) * (new[4][2] - 0.5 * new[4][1] ** 2 / new[4][0])
        assert abs(p - (pr - (G - 1.0) * (lam * (pl - pr) / 2.0) ** 2 / (2.0 * rr))) < 1e-12
        assert (p > 0.0) == (f < 1.0)
    assert abs(lam_star * sqrt(G * pl / rl) - 0.6574) < 1e-4  # the largest safe Courant number for Sod


def test_sod_against_the_exact_solution() -> None:
    e100, n, cells = sod(100)
    assert n == 87 and abs(e100 - 0.01484) < 5e-5
    e50, _, _ = sod(50)
    assert abs(e50 - 0.0225) < 1e-4 and e100 < e50
    assert e100 < sod(100, rusanov)[0]  # sharper than the Rusanov baseline
    u = [cons_to_prim(q)[1] for q in cells]
    assert 1.0 < max(u) < 1.02  # the glitch in the first cell right of the jump; exact u* = 0.9274


def test_first_order_on_a_smooth_wave() -> None:
    t, errs = 0.1, []
    for m in (25, 50, 100):
        dx = 1.0 / m
        avg = lambda j, s: (cos(2 * pi * (j * dx - s)) - cos(2 * pi * ((j + 1) * dx - s))) / (2 * pi * dx)
        cells = [prim_to_cons((1.0 + 0.2 * avg(j, 0.0), 1.0, 1.0)) for j in range(m)]
        out, _ = solve_euler(cells, dx, t, periodic=True)
        errs.append(sum(abs(q[0] - 1.0 - 0.2 * avg(j, t)) for j, q in enumerate(out)) * dx)
    assert abs(errs[0] - 0.007065) < 1e-6
    assert all(0.95 < log2(errs[i] / errs[i + 1]) < 1.05 for i in range(2))


def test_moving_contact_is_not_kept() -> None:
    m = 100
    cells = [prim_to_cons((1.0 if (j + 0.5) / m < 0.3 else 0.125, 1.0, 1.0)) for j in range(m)]
    out, _ = solve_euler(cells, 1.0 / m, 0.2)
    dev = max(abs(cons_to_prim(q)[1] - 1.0) for q in out)
    assert 0.02 < dev < 0.04  # u and p are no longer constant

History

Van Leer (1982) split the Euler flux by polynomials in the Mach number. Liou and Steffen (1993) took his Mach number split and used it only for the interface Mach number that carries the convective part, with the pressure split apart. They called the result the advection upstream splitting method. Liou (1996) gave AUSM+, with a common sound speed at the face, and the scheme grew into a family of fluxes.

References

  1. Meng-Sing Liou and Christopher J. Steffen, A new flux splitting scheme, Journal of Computational Physics 107(1) (1993) 23-39, the split into convective and pressure parts, the interface Mach number from the Mach number split, and the pressure split; doi:10.1006/jcph.1993.1122
  2. Bram van Leer, Flux-vector splitting for the Euler equations, in Eighth International Conference on Numerical Methods in Fluid Dynamics, Lecture Notes in Physics 170, Springer, 1982, 507-512, the split of the Mach number into the parts (M + 1)^2/4 and -(M - 1)^2/4; doi:10.1007/3-540-11948-5_66
  3. Meng-Sing Liou, A sequel to AUSM: AUSM+, Journal of Computational Physics 129(2) (1996) 364-382, the AUSM+ scheme, with a common interface sound speed and split polynomials of higher degree; doi:10.1006/jcph.1996.0256

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example