Algorithm Search⌘K

Algorithmcore

Strong stability preserving Runge-Kutta methods

Also called SSP Runge-Kutta methods, TVD Runge-Kutta methods.

Explicit Runge-Kutta methods that are convex combinations of forward Euler steps, so they keep the TVD or positivity property under a scaled CFL limit.

Time
O(K s^2 M) worst
Space
O(s M) extra
Counts
evaluations K s worst
Where
K = the number of time steps; M = the number of unknowns of the semidiscrete system; s = the number of stages
Properties
deterministicexplicit
Origin
C. W. Shu, S. Osher, S. Gottlieb, E. Tadmor, D. I. Ketcheson, 1988

Strong stability preserving (SSP) Runge-Kutta methods are explicit Runge-Kutta methods for the system u′=L(u)u' = L(u) that a spatial discretization of a conservation law gives by the method of lines. Each stage is a convex combination of forward Euler steps. So if forward Euler keeps a convex property for Δt≤ΔtFE\Delta t \le \Delta t_{FE}, such as a TVD bound, a maximum principle or positive density, the SSP method keeps it for Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE}, where CC is the SSP coefficient of the method. The SSP methods reach higher order in time without losing the nonlinear stability that a limiter gives the space discretization. The classical fourth-order method is not SSP: its coefficient is 0.

In plain words

A shock-capturing scheme is often built so that one simple time step, the forward Euler step, never creates new wiggles if the step is small enough. But that simple step is only first order accurate in time. A higher-order Runge-Kutta method mixes several evaluations, and some mixtures do create wiggles even when each simple step would not. SSP methods use only mixtures with positive weights that add up to one. Each stage is then an average of simple steps. An average of results that have no new wiggles has no new wiggles either. The price is a smaller allowed step for some methods, and a limit on the order.

The problem

Given L:RM→RML : \mathbb{R}^M \to \mathbb{R}^M, a convex functional ∥⋅∥\|\cdot\| (a norm, the total variation, or the indicator of a convex set), and a step ΔtFE\Delta t_{FE} such that ∥u+Δt L(u)∥≤∥u∥\|u + \Delta t\,L(u)\| \le \|u\| for all 0≤Δt≤ΔtFE0 \le \Delta t \le \Delta t_{FE}, find an explicit time stepping method of order p>1p > 1 that keeps ∥un+1∥≤∥un∥\|u^{n+1}\| \le \|u^n\| for a step Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE} with CC as large as possible.

The algorithm

A method with ss stages is given in Shu-Osher form by lower triangular tables αik\alpha_{ik} and βik\beta_{ik} with ∑kαik=1\sum_k\alpha_{ik} = 1.

  1. SSP-RK-STEP(u, Δt, L, α, β)
  2. 1y_0 ← u
  3. 2for i ← 1 to s do
  4. 3y_i ← Σ over k < i of (α_ik y_k + Δt β_ik L(y_k)) ▷ each L(y_k) is computed once
  5. 4return y_s
  6. SSP-COEFFICIENT(α, β)
  7. 5if some α_ik < 0 or β_ik < 0 then return 0
  8. 6return the minimum of α_ik/β_ik over all β_ik > 0

The methods on this page, with Lk=L(yk)L_k = L(y_k):

  • SSPRK(2,2) (C=1C = 1): y1=u+ΔtL0y_1 = u + \Delta t L_0, un+1=12u+12(y1+ΔtL1)u^{n+1} = \frac12u + \frac12(y_1 + \Delta t L_1). This is Heun's method.
  • SSPRK(3,3) (C=1C = 1, Shu and Osher 1988): y1=u+ΔtL0y_1 = u + \Delta t L_0, y2=34u+14(y1+ΔtL1)y_2 = \frac34u + \frac14(y_1 + \Delta t L_1), un+1=13u+23(y2+ΔtL2)u^{n+1} = \frac13u + \frac23(y_2 + \Delta t L_2).
  • SSPRK(10,4) (C=6C = 6, Ketcheson 2008): yi=yi−1+Δt6Li−1y_i = y_{i-1} + \frac{\Delta t}{6}L_{i-1} for i=1,…,4i = 1, \dots, 4; y5=35u+25(y4+Δt6L4)y_5 = \frac35u + \frac25(y_4 + \frac{\Delta t}{6}L_4); yi=yi−1+Δt6Li−1y_i = y_{i-1} + \frac{\Delta t}{6}L_{i-1} for i=6,…,9i = 6, \dots, 9; un+1=125u+925(y4+Δt6L4)+35(y9+Δt6L9)u^{n+1} = \frac1{25}u + \frac9{25}(y_4 + \frac{\Delta t}{6}L_4) + \frac35(y_9 + \frac{\Delta t}{6}L_9).

The effective coefficient C/sC/s compares methods with different numbers of stages at equal cost: it is 12\frac12 for SSPRK(2,2), 13\frac13 for SSPRK(3,3) and 0.60.6 for SSPRK(10,4).

Example

One step by hand. Take upwind advection L(u)j=−(uj−uj−1)L(u)_j = -(u_j - u_{j-1}) with Δx=1\Delta x = 1 on 4 periodic points. Forward Euler is TVD and keeps the values in [0,1][0, 1] for Δt≤1\Delta t \le 1. With SSPRK(2,2), Δt=12\Delta t = \frac12 and u=(1,0,0,0)u = (1, 0, 0, 0), the first stage is y1=(12,12,0,0)y_1 = (\frac12, \frac12, 0, 0). The forward Euler step from y1y_1 is (14,12,14,0)(\frac14, \frac12, \frac14, 0), and the average with uu gives

un+1=12(1,0,0,0)+12(14,12,14,0)=(58,14,18,0).u^{n+1} = \tfrac12(1, 0, 0, 0) + \tfrac12\big(\tfrac14, \tfrac12, \tfrac14, 0\big) = \big(\tfrac58, \tfrac14, \tfrac18, 0\big).

The values stay in [0,1][0, 1], the sum stays 1, and the total variation falls from 2 to 54\frac54.

Observed orders (measurement, with the code on this page). Error at t=1t = 1 for u′=−u2u' = -u^2, u(0)=1u(0) = 1, exact u(1)=12u(1) = \frac12:

method Δt=0.1\Delta t = 0.1 0.050.05 0.0250.025 last ratio
forward Euler 1.829e-2 8.895e-3 4.389e-3 2.03
SSPRK(2,2) 6.712e-4 1.621e-4 3.979e-5 4.07
SSPRK(3,3) 3.497e-5 4.137e-6 5.026e-7 8.23
SSPRK(10,4) 3.321e-8 2.096e-9 1.315e-10 15.94

A second-order method that is not SSP (measurement). Gottlieb and Shu (1998) give the second-order method u(1)=u−20Δt L(u)u^{(1)} = u - 20\Delta t\,L(u), un+1=u+Δt(4140L(u)−140L(u(1)))u^{n+1} = u + \Delta t\big(\frac{41}{40}L(u) - \frac1{40}L(u^{(1)})\big), which has a negative coefficient. Take Burgers' equation on 40 periodic cells with Δx=1\Delta x = 1, a MUSCL space discretization with minmod slopes and the Godunov flux, the data u=1u = 1 on cells 0 to 19 and u=−0.5u = -0.5 on cells 20 to 39, and Δt=0.3\Delta t = 0.3. In 26 steps the total variation of that method rises from 3 to 3.1398, and the maximum rises to 1.0699. SSPRK(2,2) with the same LL and the same step keeps the total variation at 3 and the values in [−0.5,1][-0.5, 1].

Correctness

The proof is in proofs/correctness.md. Theorem: if all αik\alpha_{ik} and βik\beta_{ik} are nonnegative and C>0C > 0, each stage is yi=∑kαik(yk+(βik/αik)Δt L(yk))y_i = \sum_k\alpha_{ik}\big(y_k + (\beta_{ik}/\alpha_{ik})\Delta t\,L(y_k)\big), a convex combination of forward Euler steps of size at most Δt/C\Delta t/C. Convexity and induction over the stages give ∥un+1∥≤∥un∥\|u^{n+1}\| \le \|u^n\| for Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE}. The proof also checks the coefficients and the orders of SSPRK(2,2) and SSPRK(3,3) from the Butcher conditions, and shows that C≤sC \le s for every explicit method with ss stages. The order of SSPRK(10,4) is cited and measured.

Proof: An SSP Runge-Kutta step keeps every convex bound of forward Euler for dt at most C dt_FEfull

Setting. The semidiscrete system is u′=L(u)u' = L(u) in RM\mathbb{R}^M. Let ∥⋅∥\|\cdot\| be a convex functional, for example a norm, the total variation seminorm TV(u)=∑j∣uj−uj−1∣\mathrm{TV}(u) = \sum_j|u_j - u_{j-1}|, or the maximum max⁡juj\max_ju_j. Assume that forward Euler is strongly stable for this functional up to a step ΔtFE\Delta t_{FE}:

∥u+Δt L(u)∥≤∥u∥for all u and all 0≤Δt≤ΔtFE.(FE)\|u + \Delta t\,L(u)\| \le \|u\| \quad \text{for all } u \text{ and all } 0 \le \Delta t \le \Delta t_{FE}. \tag{FE}

An explicit method in Shu-Osher form with ss stages computes y0=uy_0 = u (line L1), then for i=1,…,si = 1, \dots, s (line L2)

yi=∑k=0i−1(αikyk+Δt βikL(yk))(line L3),y_i = \sum_{k=0}^{i-1}\big(\alpha_{ik}y_k + \Delta t\,\beta_{ik}L(y_k)\big) \quad \text{(line L3)},

and returns unew=ysu^{\text{new}} = y_s (line L4). The code computes each L(yk)L(y_k) once, before it is first used, and then forms the sums exactly as written. Consistency requires ∑kαik=1\sum_k\alpha_{ik} = 1 for each ii, because a constant state with L=0L = 0 must stay constant.

The SSP coefficient (lines L5 and L6). If some αik<0\alpha_{ik} < 0 or βik<0\beta_{ik} < 0, then C=0C = 0. Otherwise C=min⁡{αik/βik:βik>0}C = \min\{\alpha_{ik}/\beta_{ik} : \beta_{ik} > 0\}, with C=0C = 0 when some βik>0\beta_{ik} > 0 has αik=0\alpha_{ik} = 0.

Theorem 1 (strong stability). Assume αik≥0\alpha_{ik} \ge 0, βik≥0\beta_{ik} \ge 0, ∑kαik=1\sum_k\alpha_{ik} = 1, and C>0C > 0. Then (FE) implies ∥unew∥≤∥u∥\|u^{\text{new}}\| \le \|u\| for all 0≤Δt≤C ΔtFE0 \le \Delta t \le C\,\Delta t_{FE}.

Proof. We show ∥yi∥≤∥u∥\|y_i\| \le \|u\| by induction on ii; the case i=0i = 0 is trivial. Let PiP_i be the set of k<ik < i with αik>0\alpha_{ik} > 0. Since C>0C > 0, βik>0\beta_{ik} > 0 implies αik>0\alpha_{ik} > 0, so the terms with k∉Pik \notin P_i are zero, and

yi=∑k∈Piαik(yk+βikαikΔt L(yk)).y_i = \sum_{k \in P_i}\alpha_{ik}\Big(y_k + \frac{\beta_{ik}}{\alpha_{ik}}\Delta t\,L(y_k)\Big).

The weights αik\alpha_{ik}, k∈Pik \in P_i, are positive and sum to 1, so this is a convex combination of forward Euler steps. Each step has size (βik/αik)Δt≤Δt/C≤ΔtFE(\beta_{ik}/\alpha_{ik})\Delta t \le \Delta t/C \le \Delta t_{FE}. By convexity, then (FE), then the induction hypothesis,

∥yi∥≤∑k∈Piαik∥yk+βikαikΔt L(yk)∥≤∑k∈Piαik∥yk∥≤∥u∥.□\|y_i\| \le \sum_{k \in P_i}\alpha_{ik}\Big\|y_k + \frac{\beta_{ik}}{\alpha_{ik}}\Delta t\,L(y_k)\Big\| \le \sum_{k \in P_i}\alpha_{ik}\|y_k\| \le \|u\|. \qquad \square

The same argument keeps any convex set invariant: if forward Euler maps a convex set SS (for example the states with positive density and pressure) into itself for Δt≤ΔtFE\Delta t \le \Delta t_{FE}, the SSP step does so for Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE}.

Theorem 2 (coefficients and orders of the four methods).

method CC order
forward Euler 1 1
SSPRK(2,2) 1 2
SSPRK(3,3) 1 3
SSPRK(10,4) 6 4

Proof. The values of CC follow from the tables by lines L5 and L6. In SSPRK(2,2) every ratio is 1. In SSPRK(3,3) the nonzero pairs are (1,1)(1, 1), (14,14)(\frac14, \frac14) and (23,23)(\frac23, \frac23). In SSPRK(10,4) every nonzero β\beta is 16\frac16 times its α\alpha; the weights α5,0=35\alpha_{5,0} = \frac35 and α10,0=125\alpha_{10,0} = \frac1{25} have β=0\beta = 0.

For the order, eliminate the intermediate stages to get the Butcher form. SSPRK(2,2) gives nodes c=(0,1)c = (0, 1) and weights b=(12,12)b = (\frac12, \frac12), so ∑bi=1\sum b_i = 1 and ∑bici=12\sum b_ic_i = \frac12: order 2. For SSPRK(3,3), y1=u+ΔtL0y_1 = u + \Delta t L_0, y2=u+Δt4(L0+L1)y_2 = u + \frac{\Delta t}{4}(L_0 + L_1) and y3=u+Δt(16L0+16L1+23L2)y_3 = u + \Delta t(\frac16L_0 + \frac16L_1 + \frac23L_2), with Lk=L(yk)L_k = L(y_k). So a21=1a_{21} = 1, a31=a32=14a_{31} = a_{32} = \frac14, c=(0,1,12)c = (0, 1, \frac12) and b=(16,16,23)b = (\frac16, \frac16, \frac23). The four conditions for order 3 hold:

∑bi=1,∑bici=16+13=12,∑bici2=16+16=13,∑biaijcj=23⋅14⋅1=16.\textstyle\sum b_i = 1, \quad \sum b_ic_i = \frac16 + \frac13 = \frac12, \quad \sum b_ic_i^2 = \frac16 + \frac16 = \frac13, \quad \sum b_ia_{ij}c_j = \frac23\cdot\frac14\cdot1 = \frac16.

For SSPRK(10,4) the order is cited from Ketcheson (2008); the tests on this page measure order 4 on a nonlinear ODE. □\square

Theorem 3 (upper bound C≤sC \le s). For an explicit method with ss stages, order at least 1 and C>0C > 0, C≤sC \le s.

Proof. Apply the method to u′=λuu' = \lambda u with z=λΔtz = \lambda\Delta t, and set w=1+z/Cw = 1 + z/C. Because βik/αik≤1/C\beta_{ik}/\alpha_{ik} \le 1/C,

1+βikαikz=(1−βikCαik)+βikCαik w1 + \frac{\beta_{ik}}{\alpha_{ik}}z = \Big(1 - \frac{\beta_{ik}C}{\alpha_{ik}}\Big) + \frac{\beta_{ik}C}{\alpha_{ik}}\,w

is a polynomial in ww with nonnegative coefficients. By induction, each stage yi/uy_i/u is a polynomial in ww of degree at most ii with nonnegative coefficients, and its value at w=1w = 1 is ∑kαik=1\sum_k\alpha_{ik} = 1. So the stability function is R(z)=∑j=0sγjwjR(z) = \sum_{j=0}^s\gamma_jw^j with γj≥0\gamma_j \ge 0 and ∑jγj=1\sum_j\gamma_j = 1. Order at least 1 gives R′(0)=1R'(0) = 1, and R′(0)=1C∑jjγj≤sCR'(0) = \frac1C\sum_jj\gamma_j \le \frac{s}{C}. So C≤sC \le s. □\square

So the effective coefficient C/sC/s is at most 1. SSPRK(10,4) has C/s=0.6C/s = 0.6, and SSPRK(3,3) has C/s=13C/s = \frac13.

Cited barriers, not proved here. No explicit Runge-Kutta method with four stages and order four has C>0C > 0 (Gottlieb and Shu 1998). No explicit Runge-Kutta method of order five or more has C>0C > 0 (Ruuth and Spiteri 2002). The classical fourth-order method in Shu-Osher form has α4,0=−13\alpha_{4,0} = -\frac13 and a pair with α2,1=0<β2,1\alpha_{2,1} = 0 < \beta_{2,1}, so lines L5 and L6 return 0 for it.

What the result does not say. Theorem 1 transfers a property that forward Euler has; it does not create one. The time step bound Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE} is sufficient, not necessary: for a particular LL a larger step can still keep the bound. And a method with C=0C = 0 can still keep the bound for some problems; the counterexample in the tests shows a second-order method with a negative coefficient that does not. ■\blacksquare

Complexity

Theorem: one step evaluates LL once per stage, ss times, and forms the stage sums in O(s2M)O(s^2M) operations in the general form. For the methods above most αik\alpha_{ik} are zero, and the sums cost O(sM)O(sM). The general form stores all stages, O(sM)O(sM) memory. Many SSP methods, SSPRK(10,4) among them, have low-storage forms with two or three registers of size MM (Ketcheson 2008). In practice the cost of LL dominates.

Properties

  • Convex combination of forward Euler steps, so any convex bound of forward Euler is kept: TVD, maximum principle, positivity, an entropy inequality of a fully discrete form.
  • Sufficient, not necessary. Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE} is a guarantee. For a given LL a larger step may still keep the bound.
  • Order barriers (theorems, cited). No four-stage fourth-order explicit method has C>0C > 0 (Gottlieb and Shu 1998), and no explicit method of order five or more has C>0C > 0 (Ruuth and Spiteri 2002).
  • C≤sC \le s for explicit methods with ss stages, so the effective coefficient is at most 1.
  • Optimal methods. SSPRK(2,2) and SSPRK(3,3) have the largest CC among methods with as many stages as their order (Gottlieb and Shu 1998).

Variants and improvements

  • More stages. SSPRK(s,2) with C=s−1C = s - 1 and SSPRK(s,3) methods with larger effective coefficients, and SSPRK(10,4) for order four.
  • Low-storage forms. Only two or three arrays of size MM, important for large 3D runs.
  • Multistep and multistep multistage SSP methods, and implicit SSP methods. Implicit SSP methods also have bounded CC, so they do not allow arbitrarily large steps.
  • Downwind operators. Methods with negative β\beta need a second operator L~\tilde L that is stable backward in time. They avoid some of the order barriers, at the cost of a second operator.
  • With limiters. WENO, MUSCL and the Runge-Kutta discontinuous Galerkin method use SSP time stepping, and a positivity-preserving limiter relies on it.

When to use it

Use an SSP method whenever the space discretization is proved TVD, monotone or positive only for forward Euler: limited finite volume schemes, WENO, DG with a limiter. SSPRK(3,3) is the usual default. SSPRK(10,4) gives order four with a larger stable step per evaluation. For smooth problems without limiters, where no nonlinear bound is needed, a method with a large stability region, such as classical RK4, can be more efficient.

Pitfalls

  • A non-SSP method with a TVD space discretization. The bound can fail, as in the example. Classical RK4 and many embedded pairs have C=0C = 0.
  • The wrong step limit. The guarantee is Δt≤C ΔtFE\Delta t \le C\,\Delta t_{FE}, where ΔtFE\Delta t_{FE} is the forward Euler limit of the space discretization, for example 12\frac12 of the CFL limit for MUSCL with minmod. It is not the linear stability limit.
  • Boundary conditions inside the stages. Apply the boundary conditions at each stage time, or the order drops near the boundary.
  • Time-dependent sources. Evaluate L(t,u)L(t, u) at the stage times tn+ciΔtt_n + c_i\Delta t, not at tnt_n.
  • The effective coefficient. Compare methods by C/sC/s, not by CC: SSPRK(10,4) allows a step six times larger but costs ten evaluations.

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.

strong_stability_preserving_runge_kutta.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/strong-stability-preserving-runge-kutta/. The authors are listed in prov/4YEW5E.jsonl.

"""Explicit SSP Runge-Kutta methods in Shu-Osher form for the semidiscrete system u' = L(u).

A method with s stages has lower triangular tables alpha and beta, where row i - 1 holds the
coefficients of stage i on the stages 0, ..., i - 1:

    y_0 = u,  y_i = sum over k < i of (alpha[i-1][k] y_k + dt beta[i-1][k] L(y_k)),  u_new = y_s.

States are lists of numbers. The arithmetic is generic, so Fraction data give exact results.
"""

from fractions import Fraction as Fr


def shu_osher_step(u: list, rhs, dt, alpha: list, beta: list) -> list:
    """One step of the method with tables alpha and beta. Each L(y_k) is computed once."""
    ys = [list(u)]  # @line L1
    ls = []
    for i in range(1, len(alpha) + 1):  # @line L2
        ls.append(rhs(ys[i - 1]))
        a, b = alpha[i - 1], beta[i - 1]
        y = [0] * len(u)
        for k in range(i):  # @line L3
            if a[k] or b[k]:
                y = [yv + a[k] * yk + dt * b[k] * lk for yv, yk, lk in zip(y, ys[k], ls[k])]
        ys.append(y)
    return ys[-1]  # @line L4


def ssp_coefficient(alpha: list, beta: list):
    """The SSP coefficient C of a Shu-Osher form: min of alpha/beta over beta > 0, and 0 if any entry is negative."""
    c = None
    for a_row, b_row in zip(alpha, beta):
        for a, b in zip(a_row, b_row):
            if a < 0 or b < 0:  # @line L5
                return Fr(0)
            if b > 0:  # @line L6
                c = a / b if c is None else min(c, a / b)
    return c


def _ssprk104():
    s = Fr(1, 6)
    alpha = [[Fr(0)] * i for i in range(1, 11)]
    beta = [[Fr(0)] * i for i in range(1, 11)]
    for i in (1, 2, 3, 4, 6, 7, 8, 9):
        alpha[i - 1][i - 1], beta[i - 1][i - 1] = Fr(1), s
    alpha[4][0], alpha[4][4], beta[4][4] = Fr(3, 5), Fr(2, 5), Fr(2, 5) * s
    alpha[9][0], alpha[9][4], alpha[9][9] = Fr(1, 25), Fr(9, 25), Fr(3, 5)
    beta[9][4], beta[9][9] = Fr(9, 25) * s, Fr(3, 5) * s
    return alpha, beta


# name: (alpha, beta, order)
METHODS = {
    "forward-euler": ([[Fr(1)]], [[Fr(1)]], 1),
    "ssprk22": ([[Fr(1)], [Fr(1, 2), Fr(1, 2)]], [[Fr(1)], [Fr(0), Fr(1, 2)]], 2),
    "ssprk33": (
        [[Fr(1)], [Fr(3, 4), Fr(1, 4)], [Fr(1, 3), Fr(0), Fr(2, 3)]],
        [[Fr(1)], [Fr(0), Fr(1, 4)], [Fr(0), Fr(0), Fr(2, 3)]],
        3,
    ),
    "ssprk104": _ssprk104() + (4,),
}


def integrate(u0: list, rhs, dt, steps: int, method: str = "ssprk33") -> list:
    """Take the given number of steps of a method from METHODS."""
    alpha, beta, _ = METHODS[method]
    if not isinstance(dt, Fr):
        alpha = [[float(a) for a in row] for row in alpha]
        beta = [[float(b) for b in row] for row in beta]
    u = list(u0)
    for _ in range(steps):
        u = shu_osher_step(u, rhs, dt, alpha, beta)
    return u
test_strong_stability_preserving_runge_kutta.py 104 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/strong-stability-preserving-runge-kutta/. The authors are listed in prov/4YEW5E.jsonl.

import random
from fractions import Fraction as Fr

from strong_stability_preserving_runge_kutta import METHODS, integrate, shu_osher_step, ssp_coefficient

# Classical RK4 in Shu-Osher form. It has a negative alpha, so its SSP coefficient is 0.
RK4_ALPHA = [[Fr(1)], [Fr(1), Fr(0)], [Fr(1), Fr(0), Fr(0)], [Fr(-1, 3), Fr(1, 3), Fr(2, 3), Fr(1, 3)]]
RK4_BETA = [[Fr(1, 2)], [Fr(0), Fr(1, 2)], [Fr(0), Fr(0), Fr(1)], [Fr(0), Fr(0), Fr(0), Fr(1, 6)]]


def total_variation(u):
    return sum(abs(u[j] - u[j - 1]) for j in range(len(u)))


def test_ssp_coefficients() -> None:
    expected = {"forward-euler": 1, "ssprk22": 1, "ssprk33": 1, "ssprk104": 6}
    for name, (alpha, beta, _) in METHODS.items():
        assert ssp_coefficient(alpha, beta) == expected[name]
        assert all(sum(row) == 1 for row in alpha)  # each stage is consistent
    assert ssp_coefficient(RK4_ALPHA, RK4_BETA) == 0


def test_stability_polynomials_exactly() -> None:
    # On u' = z u one step multiplies u by R(z); for s = p <= 4 stages R is the Taylor polynomial of e^z.
    for name, p in (("forward-euler", 1), ("ssprk22", 2), ("ssprk33", 3)):
        alpha, beta, _ = METHODS[name]
        for z in (Fr(-3, 2), Fr(-1, 3), Fr(2, 7)):
            r = shu_osher_step([Fr(1)], lambda v: [z * v[0]], Fr(1), alpha, beta)[0]
            taylor, term = Fr(0), Fr(1)
            for k in range(p + 1):
                taylor += term
                term = term * z / (k + 1)
            assert r == taylor
    r4 = shu_osher_step([Fr(1)], lambda v: [Fr(-1, 2) * v[0]], Fr(1), RK4_ALPHA, RK4_BETA)[0]
    assert r4 == 1 - Fr(1, 2) + Fr(1, 8) - Fr(1, 48) + Fr(1, 384)


def test_observed_orders_on_a_nonlinear_ode() -> None:
    # u' = -u^2, u(0) = 1, exact u(1) = 1/2. Halving dt divides the error by about 2^p.
    for name, (_, _, p) in METHODS.items():
        errs = [abs(integrate([1.0], lambda v: [-v[0] * v[0]], 1.0 / n, n, name)[0] - 0.5) for n in (10, 20, 40)]
        for e0, e1 in zip(errs, errs[1:]):
            assert 0.85 * 2**p < e0 / e1 < 1.25 * 2**p


def upwind(u):
    # u_t + u_x = 0, periodic, dx = 1: forward Euler with this L is TVD for dt <= 1.
    return [-(u[j] - u[j - 1]) for j in range(len(u))]


def test_tvd_up_to_the_ssp_time_step() -> None:
    rng = random.Random(11)
    u0 = [rng.uniform(-1, 1) for _ in range(30)]
    for name, dt in (("ssprk22", 1.0), ("ssprk33", 1.0), ("ssprk104", 6.0)):
        u = list(u0)
        tv = total_variation(u)
        for _ in range(40):
            u = integrate(u, upwind, dt, 1, name)
            assert total_variation(u) <= tv + 1e-12
            tv = total_variation(u)


def minmod(a, b):
    return 0.0 if a * b <= 0 else (a if abs(a) < abs(b) else b)


def burgers_muscl(u):
    """Burgers' equation, MUSCL with minmod slopes and the Godunov flux, periodic, dx = 1."""
    f = lambda v: v * v / 2

    def godunov(a, b):
        if a <= b:
            return 0.0 if a < 0 < b else min(f(a), f(b))
        return max(f(a), f(b))

    m = len(u)
    s = [minmod(u[(j + 1) % m] - u[j], u[j] - u[j - 1]) for j in range(m)]
    flux = [godunov(u[j] + s[j] / 2, u[(j + 1) % m] - s[(j + 1) % m] / 2) for j in range(m)]
    return [-(flux[j] - flux[j - 1]) for j in range(m)]


def gottlieb_shu_rk2(u, rhs, dt):
    """A second-order RK method with a negative coefficient (Gottlieb and Shu 1998)."""
    l0 = rhs(u)
    u1 = [a - 20 * dt * b for a, b in zip(u, l0)]
    l1 = rhs(u1)
    return [a + dt * (41 / 40 * b - 1 / 40 * c) for a, b, c in zip(u, l0, l1)]


def test_non_ssp_rk2_creates_oscillations_and_ssprk22_does_not() -> None:
    u0 = [1.0 if j < 20 else -0.5 for j in range(40)]
    dt = 0.3
    bad, good = list(u0), list(u0)
    tv_bad, tv_good = [], []
    for _ in range(26):
        bad = gottlieb_shu_rk2(bad, burgers_muscl, dt)
        good = integrate(good, burgers_muscl, dt, 1, "ssprk22")
        tv_bad.append(total_variation(bad))
        tv_good.append(total_variation(good))
    assert max(tv_good) <= 3 + 1e-12 and max(good) <= 1 + 1e-12
    assert max(tv_bad) > 3.1 and max(bad) > 1.03

History

Shu and Osher (1988) wrote explicit Runge-Kutta methods as convex combinations of forward Euler steps and gave the third-order TVD method that is now SSPRK(3,3). Gottlieb and Shu (1998) found the optimal second- and third-order methods and proved that no four-stage fourth-order method has a positive coefficient. Gottlieb, Shu and Tadmor (2001) introduced the name strong stability preserving. Ruuth and Spiteri (2002) proved the order barrier for explicit methods, and Ketcheson (2008) gave efficient low-storage methods such as SSPRK(10,4). The book by Gottlieb, Ketcheson and Shu (2011) collects the theory.

References

  1. 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 Shu-Osher form and the third-order TVD Runge-Kutta method
  2. Sigal Gottlieb and Chi-Wang Shu, Total variation diminishing Runge-Kutta schemes, Mathematics of Computation 67(221) (1998) 73-85, optimal second- and third-order methods, no four-stage fourth-order method with a positive SSP coefficient, the example of a non-TVD second-order method
  3. Sigal Gottlieb, Chi-Wang Shu and Eitan Tadmor, Strong stability-preserving high-order time discretization methods, SIAM Review 43(1) (2001) 89-112, survey, the name strong stability preserving
  4. Steven J. Ruuth and Raymond J. Spiteri, Two barriers on strong-stability-preserving time discretization methods, Journal of Scientific Computing 17 (2002) 211-220, no explicit SSP Runge-Kutta method of order five with a positive SSP coefficient
  5. David I. Ketcheson, Highly efficient strong stability-preserving Runge-Kutta methods with low-storage implementations, SIAM Journal on Scientific Computing 30(4) (2008) 2113-2136, the ten-stage fourth-order method SSPRK(10,4) with SSP coefficient 6 and its low-storage form
  6. Sigal Gottlieb, David Ketcheson and Chi-Wang Shu, Strong Stability Preserving Runge-Kutta and Multistep Time Discretizations, World Scientific, 2011, the SSP coefficient, optimal explicit methods, order barriers

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
  • a full proof of evaluations.worst
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