Algorithmadvanced
Piecewise parabolic method
Also called Colella-Woodward method.
Reconstructs a monotone parabola in each cell with steepening at contacts, a high order Godunov scheme for gas dynamics.
- 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
- conservativedeterministicexplicit
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Phillip Colella, Paul R. Woodward, 1984
The piecewise parabolic method (PPM) is a finite volume scheme for hyperbolic conservation laws that gives each cell a parabola instead of the straight line of MUSCL. The parabola has the cell average as its mean and matches face values from a fourth order interpolation. Three simple tests then change the face values so that the parabola is monotone in the cell and stays inside the range of the neighbors. For linear advection, moving the parabolas exactly gives a scheme that is TVD and sharper than MUSCL. For gas dynamics, Colella and Woodward add a steeper reconstruction at contacts and flattening near strong shocks, and the scheme is much used in astrophysics codes.
In plain words
A straight line in each cell cannot follow a curved profile well, so make it a parabola. Pick the values at the cell edges first, by fitting a cubic through four neighbor averages and reading off its value at the edge. Then fit the parabola in each cell with those two edge values and the cell average. If the cell is a local peak or dip, the parabola would overshoot, so make it flat. If the parabola would turn around inside the cell, pull the edge value on the far side toward the average until it no longer turns. What remains moves along with the flow.
The problem
Given cell averages of on a uniform grid with width , find a reconstruction that is accurate for smooth data and creates no new extrema, and use it in a conservative update. The page treats linear advection with in full, and uses the same reconstruction for the Euler equations with and . The values are cell averages, so errors are measured against exact cell averages.
The algorithm
PPM-ADVECTION-STEP(a, ν) ▷ u_t + c u_x = 0, c > 0, ν = cΔt/h ≤ 1- 1
add three ghost cells on each side (wrap for periodic, copy for outflow) - 2
δa_j <- MC slope: minmod((a_{j+1} - a_{j-1})/2, 2(a_j - a_{j-1}), 2(a_{j+1} - a_j)) - 3
a_{j+1/2} <- (a_j + a_{j+1})/2 - (δa_{j+1} - δa_j)/6 ▷ 7/12 and -1/12 when no slope is limited - 4
for each cell: a_L, a_R <- a_{j-1/2}, a_{j+1/2}, changed by the three monotonicity tests - 5
F_{j+1/2} <- a_R - (ν/2)(Δa - (1 - 2ν/3) a_6), Δa = a_R - a_L, a_6 = 6(a_j - (a_L + a_R)/2) - 6
a_j <- a_j - ν(F_{j+1/2} - F_{j-1/2})
The parabola in cell is for , and its mean is . The three tests of line L4 are:
- if is not strictly between and , set (flat at extrema);
- if the parabola would turn inside the cell near the left edge, set ;
- if it would turn near the right edge, set .
Line L5 is times the average of over the right part of the cell, which is the amount that crosses the face in one step divided by . For the Euler equations, the code computes and for each conserved component with lines L1 to L4, puts the values on the two sides of each face into the HLL flux with Davis speeds, and integrates with SSP RK3 at Courant number 0.5. This is a method of lines form. The original gas dynamics PPM instead traces characteristics through the parabolas to get time averaged face states for an exact Riemann solver, and adds contact steepening and flattening; the code leaves these out.
Example
One step by hand. Take , outflow boundaries and . The MC slopes are in cells 3 and 4 and zero elsewhere. Line L3 gives the face values between cells 2 and 3, between cells 3 and 4, and between cells 4 and 5. In cell 3, , and ; then and , so the tests do not apply (). The flux out of cell 3 is , and the new value is . The whole step gives . The test checks the face values and the step exactly in Fraction arithmetic. MUSCL with MC gives in cell 3 on the same data.
Smooth advection. For the cell averages of , and one period, these errors are measurements made with the code on this page.
| 20 | 40 | 80 | 160 | |
|---|---|---|---|---|
| error | 0.0189537 | 0.0039237 | 0.0007292 | 0.0001404 |
| order | 2.27 | 2.43 | 2.38 |
The orders lie between 2 and 3: the face values are fourth order, but test 1 flattens the parabolas at the crest and the trough. On the same runs, the MUSCL-Hancock code of the MUSCL page with the MC limiter has the errors 0.0228951, 0.0056305, 0.0012618 and 0.0002487, so PPM is better by a factor between 1.2 and 1.8. For a square wave on 100 cells after one period at , the error is 0.01941 for PPM and 0.02862 for MUSCL with MC.
Euler equations. For , , on a periodic grid to , the density errors at are 0.00124528, 0.00030744 and 0.00007047 (orders 2.02 and 2.13). For Sod's tube to , the density error is 0.005261 at (87 steps) and 0.002812 at (175 steps). The MUSCL page reports 0.00462 and 0.00265 for MUSCL-Hancock with the HLLC flux and the van Leer limiter. So this method of lines form, with the HLL flux and without contact steepening, does not do better than MUSCL on Sod's tube; the gain of PPM shows on the advection runs above.
Correctness
The proof is in proofs/correctness.md. Theorem: with the MC slopes, every face value lies between its two neighbor averages. After the three tests each parabola has the cell average as its mean, is monotone, and stays between the smallest and the largest of the three averages around it. The piecewise parabolic function then has exactly the total variation of the averages. For linear advection with , the step is the exact average of the moved parabolas, so it is conservative, TVD, and makes no new extrema; at it is the exact shift.
The order of accuracy is measured, not proved. For the Euler equations no TVD or positivity property is proved here.
Proof: The PPM reconstruction is exact for cubics away from limiting, gives monotone parabolas inside the range of the neighbors, and PPM for linear advection is conservative and TVD for Courant numbers up to 1full
Setting. The cell averages live on cells of width . Lines L2 to L4 of the page compute the slopes
with , the face values , and then, in each cell, and changed by three tests:
- if , set ;
- else if , set ;
- else if , set ;
where and . The parabola in cell , with across the cell, is
Lemma 1 (mean and fourth order face values). . If no slope is limited, that is for all , then , and this is exact when the are the averages of a cubic.
Proof. and , so the integral is . Inserting the central slopes gives the second formula. For the third claim, let be the primitive of the cubic, so . The formula is a linear combination of the values of at five faces, and its value at the face equals for by direct computation, so it is exact for of degree 4.
The test checks the cubic case exactly in Fraction arithmetic on the averages of , where no slope is limited.
Lemma 2 (face values lie between neighbors). lies between and .
Proof. If , both slopes are 0, because each has a factor in its sign test, and . Let (the other sign is the mirror image). Both and are zero or have the sign of , and both are at most . So and .
Lemma 3 (the tests give monotone parabolas). After the three tests, is monotone on , lies between and , and and lie between the values they had before the tests and .
Proof. is linear, so is monotone on if and only if and do not have strict opposite signs, which holds when , that is . Test 1 gives a constant. If test 1 does not apply, is strictly between and , so . If tests 2 and 3 do not apply, , so . In test 2, the new values , and give , so and is monotone. Also is on the same side of as , since has the sign of , and lies between and , because is the same as having the sign of . Test 3 is the mirror image.
Corollary. Every value of lies between the smallest and the largest of . The test test_parabolas_are_monotone_and_bounded checks this at 17 points in every cell for random data.
Lemma 4 (the reconstruction keeps the total variation). On a periodic grid, let be the function equal to on cell . Then .
Proof. Write and for the values on the two sides of the face after the tests. Suppose . By Lemma 2 the face value is in . The tests in cell move from toward (Lemma 3, or test 1), and the tests in cell move from toward . So . The case is the mirror image. In each cell, is monotone from to and passes through the level , which lies between them. So the function , read from left to right, visits monotonically between every two neighbor averages, and its variation between the levels and is exactly . Summing over gives the claim.
Theorem 1 (PPM for linear advection). For with , and line L5, the step of line L6 sets to the average over cell of moved right by . On a periodic grid the step is conservative, , and every new value lies between the smallest and the largest old value. At the step is the exact shift .
Proof. The value of line L5 is , by direct integration of the parabola; the test compares it with Simpson's rule, which is exact for parabolas, in Fraction arithmetic. Since , the part of that crosses the face in the step comes only from cell , so line L6 computes the average over cell of the moved function exactly. The fluxes telescope, so the sum is kept. For the total variation, let be the moved function. Then
and by Lemma 4. The bounds follow from the Corollary, because each new value is an average of values of . At the flux is by Lemma 1, so .
The tests check Theorem 1 on a square wave at and on 100 random data sets, and check conservation exactly in Fraction arithmetic.
What is not proved here. The order of accuracy is measured, not proved: on a sine wave for advection the orders are 2.27, 2.43 and 2.38, above 2 because the face values are fourth order, and below 3 because test 1 flattens the parabolas at extrema. For the Euler equations the page uses the reconstruction in a method of lines with the HLL flux and SSP RK3, without the characteristic tracing, contact steepening and flattening of the full gas dynamics scheme. No TVD or positivity property is proved for that case.
Complexity
Theorem, in the real-RAM model: lines L2 to L6 do a constant amount of work per cell and component, so one step costs and keeps numbers. A fixed end time at a fixed Courant number needs steps. Per step PPM costs a small constant factor more than MUSCL, and for the Euler runs here the SSP RK3 time stepper adds three flux evaluations per face and step.
Properties
- Fourth order face values, flat at extrema. Exact for cubics where no slope is limited; the order on smooth data with extrema is between 2 and 3.
- TVD for linear advection with , and exact at . Proved.
- Conservative. The parabola has the cell average as its mean, and the fluxes telescope.
- Low numerical diffusion. On the advection runs of the example, PPM has a smaller error than MUSCL with the MC limiter, for both the sine and the square wave.
- Not positivity preserving for the Euler equations in general.
Variants and improvements
- Contact steepening and flattening. Colella and Woodward steepen the face values at contacts, detected from the density and pressure, and flatten the parabolas behind strong shocks to reduce oscillations there.
- Characteristic tracing. For systems, the original scheme averages the parabolas over the domain of dependence of each characteristic family and solves a Riemann problem with the time averaged states.
- Better treatment of smooth extrema. Later work changes test 1 so that smooth peaks are not flattened, which restores higher order there.
- Method of lines. The face values of lines L1 to L4 can be used with any Riemann flux and Runge-Kutta method, as the code does for the Euler equations.
When to use it
Use PPM for gas dynamics with strong shocks and contacts where low numerical diffusion matters, for example in astrophysical codes with adaptive mesh refinement. For a simpler code, MUSCL with a good limiter is often enough. For very high order on smooth flows, use WENO.
Pitfalls
- Unlimited face values. The fourth order interpolation alone overshoots at jumps. Lines L2 and L4 are both needed.
- Extrema are flattened. Test 1 cuts smooth peaks to a constant, so the max norm error at extrema is first order. This is by design and not a bug.
- Three ghost cells. The face values need slopes, which need neighbors, so the stencil reaches three cells past each face.
- Courant number above 1. Line L5 assumes the part that crosses the face comes from one cell only.
- Calling the method of lines form PPM without saying so. The code's Euler runs use only the reconstruction. Results differ from the full gas dynamics scheme near contacts and strong shocks.
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/piecewise-parabolic-method/. The authors are listed in prov/4Q3HCS.jsonl.
"""The piecewise parabolic method of Colella and Woodward (1984).
Each cell gets a parabola with the cell average as its mean. The face values come from a fourth
order interpolation with limited slopes, and three tests make the parabola monotone in the cell.
For linear advection, advect_step moves the parabolas exactly over one time step (the PPM scheme
for u_t + c u_x = 0 with c > 0). For the Euler equations, solve_euler uses the PPM face values per
conserved component in a method of lines with the HLL flux and SSP RK3; it leaves out the contact
steepening, flattening and characteristic tracing of the full gas dynamics scheme.
Fraction data stay exact.
"""
from math import sqrt
GAMMA = 1.4
def mc_slope(left, mid, right):
"""The monotonized central slope of Colella and Woodward, in cell units."""
dl, dr = mid - left, right - mid
if dl * dr <= 0:
return 0 * dl
s = min(abs(dl + dr) / 2, 2 * abs(dl), 2 * abs(dr))
return s if dl > 0 else -s
def constrain(al, a, ar):
"""The three monotonicity tests: returns the new (aL, aR) for a cell with average a."""
if (ar - a) * (a - al) <= 0: # @line L4
return a, a
d, m = ar - al, a - (al + ar) / 2
if d * m > d * d / 6:
return 3 * a - 2 * ar, ar
if -d * d / 6 > d * m:
return al, 3 * a - 2 * al
return al, ar
def ppm_faces(cells, periodic=False):
"""The constrained face values (aL, aR) of every cell, for scalar data."""
m = len(cells)
if periodic: # @line L1
ext = list(cells[-3:]) + list(cells) + list(cells[:3])
else:
ext = [cells[0]] * 3 + list(cells) + [cells[-1]] * 3
d = [0 * ext[0]] + [mc_slope(ext[k - 1], ext[k], ext[k + 1]) for k in range(1, len(ext) - 1)] # @line L2
face = {k: (ext[k] + ext[k + 1]) / 2 - (d[k + 1] - d[k]) / 6 for k in range(1, len(ext) - 2)} # @line L3
out = []
for j in range(m):
k = j + 3
out.append(constrain(face[k - 1], ext[k], face[k]))
return out
def parabola(al, a, ar, xi):
"""The parabola of a cell at the local coordinate xi in [0, 1]."""
return al + xi * ((ar - al) + 6 * (a - (al + ar) / 2) * (1 - xi))
def right_flux_average(al, a, ar, nu):
"""The average of the parabola over [1 - nu, 1]: the flux through the right face divided by c."""
return ar - nu / 2 * ((ar - al) - (1 - 2 * nu / 3) * 6 * (a - (al + ar) / 2)) # @line L5
def advect_step(cells, nu, periodic=True):
"""One PPM step for u_t + c u_x = 0, c > 0, with Courant number 0 <= nu <= 1."""
pf = ppm_faces(cells, periodic)
flux = [right_flux_average(al, a, ar, nu) for (al, ar), a in zip(pf, cells)]
inflow = flux[-1] if periodic else cells[0]
return [a - nu * (flux[j] - (flux[j - 1] if j > 0 else inflow)) for j, a in enumerate(cells)] # @line L6
# Euler equations with U = (rho, rho u, E), in a method of lines.
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 hll_flux(ql, qr, g=GAMMA):
"""HLL with the speed estimates of Davis."""
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)
sl, sr = min(ul - cl, ur - cr), max(ul + cl, ur + cr)
fl, fr = euler_flux(ql, g), euler_flux(qr, g)
if sl >= 0:
return fl
if sr <= 0:
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))
def rate(cells, dx, periodic=False, g=GAMMA):
m = len(cells)
comps = [ppm_faces([q[c] for q in cells], periodic) for c in range(3)]
left = [tuple(comps[c][j][0] for c in range(3)) for j in range(m)]
right = [tuple(comps[c][j][1] for c in range(3)) for j in range(m)]
if periodic:
pairs = [(right[j - 1], left[j]) for j in range(m)] + [(right[-1], left[0])]
else:
pairs = [(cells[0], left[0])] + [(right[j - 1], left[j]) for j in range(1, m)] + [(right[-1], cells[-1])]
h = [hll_flux(a, b, g) for a, b in pairs]
return [tuple(-(h[j + 1][c] - h[j][c]) / dx for c in range(3)) for j in range(m)]
def solve_euler(cells, dx, t_end, cfl=0.5, periodic=False, g=GAMMA):
"""March to t_end with SSP RK3 and dt = cfl dx / max(|u| + c). Returns (cells, steps)."""
t, n = 0.0, 0
def speed(q):
rho, u, p = cons_to_prim(q, g)
return abs(u) + sqrt(g * p / rho)
def comb(a, x, b, y, s, z):
return tuple(a * xi + b * yi + s * zi for xi, yi, zi in zip(x, y, z))
while t < t_end - 1e-14:
dt = min(cfl * dx / max(speed(q) for q in cells), t_end - t)
L1 = rate(cells, dx, periodic, g)
u1 = [comb(1.0, c, 0.0, c, dt, d) for c, d in zip(cells, L1)]
L2 = rate(u1, dx, periodic, g)
u2 = [comb(0.75, c, 0.25, a, 0.25 * dt, d) for c, a, d in zip(cells, u1, L2)]
L3 = rate(u2, dx, periodic, g)
cells = [comb(1.0 / 3.0, c, 2.0 / 3.0, a, 2.0 / 3.0 * dt, d) for c, a, d in zip(cells, u2, L3)]
t += dt
n += 1
return cells, n
test_piecewise_parabolic_method.py 152 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/piecewise-parabolic-method/. The authors are listed in prov/4Q3HCS.jsonl.
import random
from fractions import Fraction
from math import cos, log2, pi, sqrt
from piecewise_parabolic_method import advect_step, parabola, ppm_faces, prim_to_cons, right_flux_average, solve_euler
SOD = ((1.0, 0.0, 1.0), (0.125, 0.0, 0.1))
def exact_sod_density(xi, g=1.4):
"""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 averages(m, t):
"""Exact cell averages of sin(2 pi (x - t)) on [0, 1]."""
dx = 1.0 / m
return [(cos(2 * pi * (j * dx - t)) - cos(2 * pi * ((j + 1) * dx - t))) / (2 * pi * dx) for j in range(m)]
def advect(m, nu=0.5, t=1.0):
dx = 1.0 / m
n = round(t / (nu * dx))
u = averages(m, 0.0)
for _ in range(n):
u = advect_step(u, t / (n * dx))
return sum(abs(a - b) for a, b in zip(u, averages(m, t))) * dx
def tv(u):
return sum(abs(u[j] - u[j - 1]) for j in range(len(u)))
def test_hand_trace_in_fractions() -> None:
u = [Fraction(x) for x in (0, 0, 1, 3, 4, 4)]
q = Fraction
assert ppm_faces(u) == [(0, 0), (0, 0), (q(1, 4), 2), (2, q(15, 4)), (4, 4), (4, 4)]
assert advect_step(u, q(1, 2), periodic=False) == [0, 0, q(9, 32), 2, q(119, 32), 4]
def test_face_values_are_exact_for_cubics() -> None:
# Averages of x^3 + x over [n, n + 1]: the slopes are not limited, so the faces use 7/12 and -1/12.
prim = lambda x: Fraction(x) ** 4 / 4 + Fraction(x) ** 2 / 2
v = [prim(n + 1) - prim(n) for n in range(2, 14)]
pf = ppm_faces(v)
for j in range(1, 10):
x = Fraction(j + 3)
assert pf[j][1] == x ** 3 + x == Fraction(7, 12) * (v[j] + v[j + 1]) - Fraction(1, 12) * (v[j - 1] + v[j + 2])
def test_flux_formula_matches_direct_integration() -> None:
rng = random.Random(2)
for _ in range(50):
al, a, ar = (Fraction(rng.randint(-9, 9), 4) for _ in range(3))
nu = Fraction(rng.randint(1, 10), 10)
lo = 1 - nu # Simpson's rule is exact for parabolas
simpson = (parabola(al, a, ar, lo) + 4 * parabola(al, a, ar, (lo + 1) / 2) + parabola(al, a, ar, Fraction(1))) / 6
assert right_flux_average(al, a, ar, nu) == simpson
assert right_flux_average(al, a, ar, Fraction(1)) == a # the mean of the parabola is the cell average
def test_parabolas_are_monotone_and_bounded() -> None:
rng = random.Random(4)
u = [Fraction(rng.randint(0, 20)) for _ in range(40)]
pf = ppm_faces(u, periodic=True)
for j, (al, ar) in enumerate(pf):
lo, hi = min(u[j - 1], u[j], u[(j + 1) % 40]), max(u[j - 1], u[j], u[(j + 1) % 40])
vals = [parabola(al, u[j], ar, Fraction(k, 16)) for k in range(17)]
steps = [vals[k + 1] - vals[k] for k in range(16)]
assert all(s >= 0 for s in steps) or all(s <= 0 for s in steps)
assert all(lo <= x <= hi for x in vals)
def test_exact_conservation_in_fractions() -> None:
rng = random.Random(3)
u = [Fraction(rng.randint(-8, 8), 4) for _ in range(16)]
total = sum(u)
for _ in range(3):
u = advect_step(u, Fraction(3, 7))
assert sum(u) == total
def test_courant_one_is_an_exact_shift() -> None:
rng = random.Random(6)
u = [Fraction(rng.randint(0, 9)) for _ in range(12)]
assert advect_step(u, Fraction(1)) == u[-1:] + u[:-1]
def test_tvd_and_no_new_extrema_for_advection() -> None:
m = 80
for nu in (0.3, 0.5, 0.9, 1.0):
u = [1.0 if 20 <= j < 40 else (0.5 if 50 <= j < 55 else 0.0) for j in range(m)]
t0 = tv(u)
for _ in range(60):
u = advect_step(u, nu)
assert tv(u) <= t0 + 1e-12 and -1e-12 <= min(u) and max(u) <= 1.0 + 1e-12
t0 = tv(u)
rng = random.Random(1)
for _ in range(100):
u = [rng.random() for _ in range(30)]
v = advect_step(u, rng.random())
assert tv(v) <= tv(u) + 1e-12 and min(u) - 1e-12 <= min(v) and max(v) <= max(u) + 1e-12
def test_order_on_smooth_advection() -> None:
e = [advect(m) for m in (20, 40, 80)]
assert abs(e[0] - 0.0189537) < 1e-7
assert all(2.2 < log2(e[i] / e[i + 1]) < 2.5 for i in range(2)) # above 2, below 3: clipped extrema
def test_euler_wave_and_sod() -> None:
t, errs = 0.1, []
for m in (25, 50, 100):
dx = 1.0 / m
cells = [prim_to_cons((1.0 + 0.2 * r, 1.0, 1.0)) for r in averages(m, 0.0)]
cells, _ = solve_euler(cells, dx, t, periodic=True)
errs.append(sum(abs(q[0] - 1.0 - 0.2 * e) for q, e in zip(cells, averages(m, t))) * dx)
assert all(1.9 < log2(errs[i] / errs[i + 1]) < 2.3 for i in range(2))
m, t = 100, 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)
err = sum(abs(q[0] - sum(exact_sod_density(((j + (k + 0.5) / 16) / m - 0.5) / t) for k in range(16)) / 16) for j, q in enumerate(cells)) / m
assert n == 87 and abs(err - 0.005261) < 5e-5
History
Van Leer's MUSCL (1979) used limited straight lines in each cell. Colella and Woodward (1984) used parabolas, with face values from a fourth order interpolation of the primitive function and three monotonicity tests. For gas dynamics they gave both a Lagrangian scheme with a remap and a direct Eulerian scheme, each with contact steepening and flattening near strong shocks. PPM is used in several astrophysics codes.
References
- Phillip Colella and Paul R. Woodward, The piecewise parabolic method (PPM) for gas-dynamical simulations, Journal of Computational Physics 54(1) (1984) 174-201, the interpolation of face values, the monotonicity tests on the parabolas, the scheme for linear advection, and the gas dynamics scheme with contact steepening and flattening; doi:10.1016/0021-9991(84)90143-8
- Chi-Wang Shu and Stanley Osher, Efficient implementation of essentially non-oscillatory shock-capturing schemes, Journal of Computational Physics 77(2) (1988) 439-471, the TVD (SSP) Runge-Kutta method of third order used for the Euler runs on this page; doi:10.1016/0021-9991(88)90177-5
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 4Q3HCS Edit this page History Report an error Markdown