14. Numerical Methods

Every astrophysical simulation solves a problem that is not the one written down, and this module says which one. It derives the Courant condition that Module 10 used, the viscosity that every grid code adds to the equations it solves, and the exact Riemann solver on which Godunov's method is built. It then runs three one-dimensional codes against closed forms that this book already owns. Four checks: a stability boundary reproduced, a convergence rate predicted with no fitted parameter, a blast wave in the right place with its peak too low, and a particle method whose error at a contact does not decrease with resolution.

Contents

Module 10 §3 ended with a number: at a Reynolds number of $10^{6}$, one outer turnover of a directly simulated flow costs $10^{18}$ point-updates, and the $10$ pc molecular cloud of Module 10 §6 needs $6.24\times10^{17}$ grid points. Its conclusion was that "every astrophysical code therefore solves a different problem from the one written down here", and it named this module to say which problem that is. Module 10's count also used a result it did not derive: that an explicit code is limited to a time step of about one cell crossing, the Courant condition. Module 5 §8 named this module for how a gravitational collapse is followed once linear theory stops.

The originating plan of the book added one more debt: to say which results of Modules 1 to 13 came from a simulation and which from a closed-form solution. §11 pays it with a census of every module, and the census finds eight places where a shipped page calls the output of a simulation or a numerical model "measured" or "observed".

The scope is capped, and the codes are one-dimensional. The plan said of this module: "Numerics can absorb an unlimited budget. Cap it at one module, or cut it." Every code here is one-dimensional, written in about 400 lines of Python with numpy, and the whole run takes about five minutes. Nothing here is a production code, and nothing here tests a three-dimensional one. What the one-dimensional codes can do is run against exact solutions, and that is the only kind of test in this module.

1. What a code solves

The equations of Module 2 are conservation laws. In one dimension, with $U = (\rho, \rho u, E)$ the densities of mass, momentum and total energy and $F(U) = (\rho u, \rho u^{2} + P, u(E + P))$ their fluxes, they read $\partial_t U + \partial_x F(U) = 0$, where $E = P/(\gamma-1) + \rho u^{2}/2$ for an ideal gas. A code replaces the continuous $U(x,t)$ by a finite list of numbers. The method used for every grid code in this module keeps the conservation exact.

Definition 1 (a conservative finite-volume scheme). Divide the line into cells of width $\Delta x$ centred on $x_i = (i + \tfrac12)\Delta x$. Let $U_i^n$ be the average of $U$ over cell $i$ at time $t_n = n\Delta t$. A conservative scheme updates it by $$ U_i^{n+1} \;=\; U_i^n - \frac{\Delta t}{\Delta x}\left(F_{i+1/2} - F_{i-1/2}\right), \tag{1.1}$$ where the numerical flux $F_{i+1/2}$ depends on the cell averages on either side of the face between cells $i$ and $i+1$. The Courant number of a step is $C_{\rm CFL} = S_{\max}\Delta t/\Delta x$, with $S_{\max}$ the largest signal speed $|u| + c_{\rm s}$ on the grid.
Proposition 1 (what conservation guarantees, and what it does not). (a) A scheme of the form (1.1) conserves $\sum_i U_i\Delta x$ exactly, apart from the fluxes through the two ends of the grid. (b) If a conservative scheme that is consistent with $F$ converges, boundedly and almost everywhere, as $\Delta x$ and $\Delta t$ go to zero, then its limit is a weak solution of the conservation law, and in particular its shocks satisfy the jump conditions of Module 8 §2. Part (a) is derived; part (b), the Lax–Wendroff theorem, is stated.
(a) Sum (1.1) over $i = 0, \dots, N-1$ and multiply by $\Delta x$. Every interior face flux appears twice, once with each sign, so $\sum_i U_i^{n+1}\Delta x = \sum_i U_i^{n}\Delta x - \Delta t\,(F_{N-1/2} - F_{-1/2})$. What is stated. Part (b) is the theorem of Lax and Wendroff, read in their 1958 Los Alamos report, p. 9. Its hypothesis is the convergence itself: the theorem says what a convergent conservative scheme converges to, and nothing about whether it converges. §2 supplies one necessary condition for convergence. ∎

Part (b) is why this module uses conservative schemes only. A scheme that is not conservative can converge to a discontinuity that moves at the wrong speed, because the jump conditions of Module 8 are the integral form of conservation and nothing else. The run checks part (a) on the spherical blast of §6: over $80{,}935$ steps the total energy decreases by $3.9\times10^{-16}$ of itself, which is rounding. That code updates $U_iV_i$, with $V_i$ the cell volume, through faces of area $r^{2}$, and the same telescoping conserves its total mass and energy; its momentum equation has a geometric source, and radial momentum is not conserved in spherical symmetry.

2. The Courant condition

The simplest conservation law is the advection of a scalar at a constant speed $a \gt 0$: $\partial_t u + a\,\partial_x u = 0$, with exact solution $u(x,t) = u_0(x - at)$. Two schemes for it carry the whole of this section. The upwind scheme takes the flux from the cell the flow comes from, $F_{i+1/2} = a u_i$, so (1.1) becomes $$ u_i^{n+1} = u_i^n - C\,(u_i^n - u_{i-1}^n), \qquad C = \frac{a\Delta t}{\Delta x}. \tag{2.1}$$ The forward-time centred-space scheme (FTCS) takes the average of the two neighbours, $F_{i+1/2} = a(u_i + u_{i+1})/2$, and gives $u_i^{n+1} = u_i^n - \tfrac{C}{2}(u_{i+1}^n - u_{i-1}^n)$. Here $C$ is written bare for the Courant number of the linear problem; it is the $C_{\rm CFL}$ of Definition 1 with $S_{\max} = a$.

Proposition 2 (the Courant–Friedrichs–Lewy condition). An explicit scheme in which $u_i^{n+1}$ depends only on $u_{i-1}^n$, $u_i^n$ and $u_{i+1}^n$ cannot converge to the solution of $\partial_t u + a\,\partial_x u = 0$ for all initial data unless $$ C = \frac{|a|\,\Delta t}{\Delta x} \;\le\; 1. \tag{2.2}$$ The condition is necessary and not sufficient.
After $n$ steps, $u_i^n$ depends on the initial data only through the values on the cells $i-n$ to $i+n$, which cover the interval $[x_i - n\Delta x,\, x_i + n\Delta x]$: the numerical domain of dependence. The exact solution at the same point and time is $u_0(x_i - a t_n)$ with $t_n = n\Delta t$, so it depends on the single point $x_i - an\Delta t$. If $|a|\Delta t \gt \Delta x$, that point lies outside the numerical domain of dependence. Change $u_0$ in a small neighbourhood of that point and nowhere else. The exact solution at $(x_i, t_n)$ changes; the numerical one does not. Refine $\Delta x$ and $\Delta t$ at fixed ratio: the same argument holds at every refinement, so the numerical solution cannot converge to the exact one for both sets of data. ∎

Courant, Friedrichs and Lewy gave this argument in 1928. In the English translation of 1967 they write the time step as $h$ and the space step as $kh$, and conclude that the difference solution "in general cannot converge" when $k \lt 1$ (p. 228) and "If now $k \ge 1$ as we must require" (p. 230). For a unit wave speed $k \ge 1$ is $\Delta t/\Delta x \le 1$; the conversion to (2.2) is this book's. The argument proves necessity only, and the next proposition shows why that matters.

Proposition 3 (von Neumann stability of the two schemes). Substitute a single Fourier mode, $u_i^n = G(\theta)^n e^{\mathrm{i}i\theta}$, with $\theta = k\Delta x \in [0, \pi]$ and $G(\theta)$ the amplification factor per step. Then $$ |G_{\rm up}(\theta)|^{2} = 1 - 2C(1-C)(1-\cos\theta), \qquad |G_{\rm FTCS}(\theta)|^{2} = 1 + C^{2}\sin^{2}\theta. \tag{2.3}$$ The upwind scheme is stable, $|G| \le 1$ for every $\theta$, if and only if $0 \le C \le 1$, and at $\theta = \pi$, $|G(\pi)| = |1 - 2C|$: the most damped mode when $0 \le C \le 1$, and the fastest-growing mode when $C \gt 1$. FTCS is unstable for every $C \gt 0$, including every $C$ that satisfies (2.2).
For upwind, $G = 1 - C(1 - e^{-\mathrm{i}\theta}) = (1 - C + C\cos\theta) - \mathrm{i}C\sin\theta$. Then $|G|^{2} = (1-C)^{2} + 2C(1-C)\cos\theta + C^{2}\cos^{2}\theta + C^{2}\sin^{2}\theta = (1-C)^{2} + C^{2} + 2C(1-C)\cos\theta$, and since $(1-C)^{2} + C^{2} = 1 - 2C(1-C)$ this is $1 - 2C(1-C)(1-\cos\theta)$. For $0 \le C \le 1$ the product $C(1-C)$ is non-negative and $1 - \cos\theta \ge 0$, so $|G|^2 \le 1$. For $C \gt 1$ or $C \lt 0$ the product is negative and $|G|^2 \gt 1$ at every $\theta \ne 0$; at $\theta = \pi$, $G = 1 - 2C$. For FTCS, $G = 1 - \tfrac{C}{2}(e^{\mathrm{i}\theta} - e^{-\mathrm{i}\theta}) = 1 - \mathrm{i}C\sin\theta$, so $|G|^{2} = 1 + C^{2}\sin^{2}\theta \gt 1$ for every $C \gt 0$ and every $\theta \in (0,\pi)$. ∎

The trivial limit. At $C = 1$ the upwind scheme is $u_i^{n+1} = u_{i-1}^n$: it moves the data exactly one cell per step, which is the exact solution, and (2.3) gives $|G| = 1$ for every mode. Both schemes use only the three points of Proposition 2, so both satisfy it for $C \le 1$, and FTCS is still unstable. The domain-of-dependence condition is necessary; stability is a separate property of each scheme.

0 0.5 1 1.5 0 0.5 1 1.5 2 sawtooth, |G| = 0.8 sawtooth, |G| = 1.2 C = 1 stable for upwind upwind: max |G| = max(1, 2C − 1) FTCS: max |G| = (1 + C2)1/2 Courant number C |G|
The largest amplification factor over all Fourier modes, against the Courant number. Orange: the upwind scheme, equal to 1 up to $C = 1$ and $2C - 1$ above it. Red, dashed: FTCS, above 1 for every $C \gt 0$. The yellow dots are CHECK 1: the factor per step of the sawtooth mode measured by the run, $0.800000$ at $C = 0.9$ and $1.200000$ at $C = 1.1$.
CHECK 1 — the stability boundary. CONFIRMED, as a demonstration. The sawtooth $(-1)^i$ is the $\theta = \pi$ mode. Advanced 100 steps by (2.1) on 64 periodic cells, its amplitude is multiplied by $0.800000$ per step at $C = 0.9$, where it decays, and by $1.200000$ at $C = 1.1$, where it grows; both are $|1 - 2C|$ to the six figures printed. A Gaussian of width $0.1$ on 200 periodic cells at $C = 1.1$ passes $|u| = 10^{3}$ after $210$ steps. The growing modes are in the sampled Gaussian itself, not in rounding error. The Gaussian is not periodic on $[0, 1]$: its end cells hold $1.782\times10^{-11}$, and the samples have amplitudes $2.38\times10^{-15}$, $2.10\times10^{-15}$ and $1.84\times10^{-15}$ at wavenumbers 91, 92 and 93 of 200; at $C = 1.1$ every mode with $\theta \ne 0$ grows by (2.3). After the 210 steps the largest $|u|$ is $1159.2855264943$ in floating point, the same to $1.0\times10^{-14}$ of itself when the steps are done in exact rational arithmetic on the stored samples, and the same to $2.8\times10^{-11}$ of itself when the samples and the steps are computed to 60 digits. Rounding, in the steps or in the stored samples, changes the result by at most $2.8\times10^{-11}$ of itself. This check confirms the algebra of Proposition 3 in Fig. 1, and it tests nothing published.

What this does to Module 10's count. Module 10 Proposition 4 took the step of a simulation as $\delta t \sim \eta/U$: one smallest cell, crossed at the flow speed. For an explicit code that solves the compressible equations, the signal speed in Definition 1 is $|u| + c_{\rm s}$, and the step is $\Delta x/(U + c_{\rm s})$. That takes $1 + 1/M$ times as many steps, with $M = U/c_{\rm s}$ the Mach number. For Module 10's laboratory air, the thermal Mach number $U/\bar v = 0.0218$ (module10.html:148) and $c_{\rm s}/\bar v = (\pi\gamma/8)^{1/2} = 0.7415$ at $\gamma = 1.4$ give $M = 0.0294$ and a factor of $35.01$. For the supersonic cloud of Module 10 §6, $U = 2.64\ \mathrm{km\,s^{-1}}$ against $c_{\rm s} = 0.2439\ \mathrm{km\,s^{-1}}$ gives $M = 10.825$ and a factor of $1.0924$. Module 10's $\delta t \sim \eta/U$ is the step of a code that has removed sound waves, which is what an incompressible code does. It is right to within $9.24$ per cent for the cloud, and it undercounts a compressible code's work on the wind tunnel by a factor of $35.01$. Module 10 is not changed. Its $\mathrm{Re}^{3}$ counts the steps of a code without sound waves, so for a compressible explicit code it is a lower bound on the work, short by the factor $1 + 1/M$. Module 10 calls only its snapshot column a floor (module10.html:283); this result shows that its work column is one too.

3. The viscosity every grid carries

A stable scheme is not an exact one. The question that module10.html:285 left open is what equation the upwind scheme actually solves, and the answer is found by expanding (2.1) in a Taylor series about the grid point.

Proposition 4 (the modified equation of the upwind scheme). A smooth function that satisfies (2.1) exactly at the grid points satisfies, to second order in $\Delta x$ and $\Delta t$, $$ \partial_t u + a\,\partial_x u \;=\; D_{\rm num}\,\partial_x^{2}u, \qquad D_{\rm num} = \frac{a\Delta x}{2}\,(1 - C). \tag{3.1}$$ The upwind scheme solves the advection equation with an added diffusion, and the diffusivity is proportional to the cell size.
Expand about $(x_i, t_n)$: $u_i^{n+1} = u + \Delta t\,u_t + \tfrac12\Delta t^{2}u_{tt} + O(\Delta t^{3})$ and $u_{i-1}^n = u - \Delta x\,u_x + \tfrac12\Delta x^{2}u_{xx} + O(\Delta x^{3})$. Substituting into (2.1) and dividing by $\Delta t$: $$ u_t + \tfrac12\Delta t\,u_{tt} = -a\,u_x + \tfrac12 a\Delta x\,u_{xx} + O(\Delta^{2}).$$ To the order kept, $u_t = -a u_x + O(\Delta)$, so $u_{tt} = a^{2}u_{xx} + O(\Delta)$. Substituting, $u_t + a u_x = \tfrac12 a\Delta x\,u_{xx} - \tfrac12\Delta t\,a^{2}u_{xx} + O(\Delta^{2}) = \tfrac12 a\Delta x(1 - a\Delta t/\Delta x)\,u_{xx}$, which is (3.1). ∎

Two limits. At $C = 1$, $D_{\rm num} = 0$, which agrees with the exact shift found in §2. At $C = 0$ the time step is zero and nothing moves. $D_{\rm num}$ has its largest value, $a\Delta x/2$, but it acts for no time: the variance growth per step, $2D_{\rm num}\Delta t$, is zero. (3.1) is an expansion; the next proposition shows that, for the variance of a profile, it is exact.

Proposition 5 (the variance grows by exactly $C(1-C)\Delta x^{2}$ per step). Let $u_i \ge 0$ be advanced by (2.1) with $0 \le C \le 1$ on a grid long enough that nothing reaches its ends. Then the total $\sum_i u_i$ is unchanged, the mean position moves by $C\Delta x$ per step, and the variance of the profile grows by exactly $$ \Delta(\sigma^{2}) \;=\; C(1-C)\,\Delta x^{2} \;=\; 2D_{\rm num}\,\Delta t \quad\text{per step}. \tag{3.2}$$
Write (2.1) as $u_i^{n+1} = (1-C)u_i^n + C u_{i-1}^n$. Read $u_i/\sum_j u_j$ as a probability distribution on the cells. One step moves each unit of $u$ zero cells with weight $1-C$ and one cell with weight $C$, independently of where it is: the new distribution is the old one convolved with a two-point distribution of mean $C\Delta x$ and variance $C\Delta x^{2} - (C\Delta x)^{2} = C(1-C)\Delta x^{2}$. Under convolution, means and variances add. The last equality in (3.2) is $C(1-C)\Delta x^{2} = 2\cdot\tfrac12 a\Delta x(1-C)\cdot(C\Delta x/a)$. A diffusion equation with diffusivity $D$ grows a variance by $2D\Delta t$ in a time $\Delta t$, so the scheme diffuses exactly at the rate (3.1) predicts. ∎

The run advects a Gaussian 200 steps on 400 cells at $C = 0.25$, $0.5$ and $0.9$ and finds the ratio of measured to predicted variance growth to be $1.000000000$ each time. A code that runs at a flow speed $U$ on $N$ cells across a length $L$ therefore has a numerical Reynolds number $$ \mathrm{Re}_{\rm num} \;=\; \frac{UL}{D_{\rm num}} \;=\; \frac{2N}{1 - C}. \tag{3.3}$$ At $N = 1024$ this is $4096$ at $C = 0.5$ and $2.048\times10^{4}$ at $C = 0.9$. That is the answer to module10.html:285 for the upwind scheme: the code solves Euler's equations plus a viscosity that the grid sets, and the Reynolds number it runs at is a property of $N$ and $C$ and not of the gas. Better schemes than upwind reduce $D_{\rm num}$ in smooth flow, and §10 gives the bound that holds for any scheme.

4. The Riemann problem and Godunov's method

Upwinding a scalar is easy because the scalar has one speed and its sign says where the information comes from. The Euler equations have three signal speeds, $u - c_{\rm s}$, $u$ and $u + c_{\rm s}$, and they can point in different directions. Godunov's answer, in 1959, was to solve the problem exactly at every cell face.

Definition 2 (the Riemann problem). The Riemann problem for the Euler equations is the initial state $(\rho, u, P) = (\rho_{\rm L}, u_{\rm L}, P_{\rm L})$ for $x \lt 0$ and $(\rho_{\rm R}, u_{\rm R}, P_{\rm R})$ for $x \gt 0$. Its solution depends on $x/t$ only. It has four uniform regions separated by three waves: a left wave (shock or rarefaction), a contact discontinuity moving at $u^{*}$, and a right wave. Between the two outer waves the pressure $P^{*}$ and velocity $u^{*}$ are uniform; the density jumps at the contact.
Definition 3 (Godunov's method). Godunov's method is the scheme (1.1) in which $F_{i+1/2}$ is the flux $F(U)$ of the exact solution of the Riemann problem between the states $U_i$ and $U_{i+1}$, evaluated at $x/t = 0$ on the face.
Proposition 6 (the star pressure). For an ideal gas with index $\gamma$, sound speeds $c_K = (\gamma P_K/\rho_K)^{1/2}$ and $K = {\rm L}$ or ${\rm R}$, the star pressure $P^{*}$ is the root of $$ f_{\rm L}(P) + f_{\rm R}(P) + u_{\rm R} - u_{\rm L} = 0, \qquad f_K(P) = \begin{cases} (P - P_K)\left[\dfrac{A_K}{P + B_K}\right]^{1/2}, & P \gt P_K \ \text{(shock)},\\[1.2ex] \dfrac{2c_K}{\gamma-1}\left[\left(\dfrac{P}{P_K}\right)^{(\gamma-1)/2\gamma} - 1\right], & P \le P_K\ \text{(rarefaction)},\end{cases} \tag{4.1}$$ with $A_K = 2/((\gamma+1)\rho_K)$ and $B_K = P_K(\gamma-1)/(\gamma+1)$, and $u^{*} = \tfrac12(u_{\rm L} + u_{\rm R}) + \tfrac12(f_{\rm R}(P^{*}) - f_{\rm L}(P^{*}))$. The root is unique, and it exists with $P^{*} \gt 0$ if and only if $$ \frac{2}{\gamma - 1}\,(c_{\rm L} + c_{\rm R}) \;\gt\; u_{\rm R} - u_{\rm L}. \tag{4.2}$$
The shock branch is Module 8's jump conditions. In the frame of a shock that moves into the state $K$, let $j$ be the mass flux through it. Conservation of mass and momentum give $j^{2} = (P - P_K)/(1/\rho_K - 1/\rho^{*})$, and the Hugoniot relation gives $\rho^{*}/\rho_K = (P/P_K + b)/(bP/P_K + 1)$ with $b = (\gamma-1)/(\gamma+1)$. This is Module 8's (3.1) with the Mach number eliminated: write $\Pi = P/P_K$; the pressure ratio of (3.1) gives $M_1^{2} = [(\gamma+1)\Pi + (\gamma-1)]/(2\gamma)$, and substituting this into its density ratio gives $\rho^{*}/\rho_K = [(\gamma+1)\Pi + (\gamma-1)]/[(\gamma-1)\Pi + (\gamma+1)] = (\Pi + b)/(b\Pi + 1)$. At $\Pi = 1$ the ratio is $1$, and as $\Pi \to \infty$ it tends to $1/b = (\gamma+1)/(\gamma-1)$, Module 8's ceiling (3.3). Then $1/\rho_K - 1/\rho^{*} = (1-b)(P/P_K - 1)/[\rho_K(P/P_K + b)]$, so $j^{2} = \rho_K(P + bP_K)/(1-b)$. With $1 - b = 2/(\gamma+1)$ this is $j^{2} = (P + B_K)/A_K$. The velocity jump across the shock is $j(1/\rho_K - 1/\rho^{*}) = (P - P_K)/j$, which is the first line of (4.1). The rarefaction branch. Across a rarefaction the flow is isentropic, so $P \propto \rho^{\gamma}$ and $c \propto P^{(\gamma-1)/2\gamma}$. The Riemann invariant $u + 2c/(\gamma-1)$ is constant across a left-facing fan ($u - 2c/(\gamma-1)$ across a right-facing one). This result is stated, not derived: no module of this book derives the Riemann invariants, and Module 8 §3.1 names the fan and does not derive it. The velocity change from $P_K$ to $P$ is therefore $(2/(\gamma-1))(c^{*} - c_K)$ in magnitude, which is the second line. The equation. The left wave gives $u^{*} = u_{\rm L} - f_{\rm L}(P^{*})$ and the right wave gives $u^{*} = u_{\rm R} + f_{\rm R}(P^{*})$. Setting them equal gives (4.1), and adding them gives $u^{*}$. Uniqueness and existence. Both branches of $f_K$ increase with $P$ (the rarefaction branch visibly; the shock branch by the derivative written out in Problem D2) and join with equal value and equal slope $1/(\rho_Kc_K)$ at $P = P_K$, so the left side of (4.1) is strictly increasing and has at most one root. It tends to $+\infty$ as $P \to \infty$, and as $P \to 0$ it tends to $-2(c_{\rm L} + c_{\rm R})/(\gamma-1) + u_{\rm R} - u_{\rm L}$, which is negative exactly when (4.2) holds. What is stated. The rarefaction branch rests on the Riemann invariant, which this book states; everything else in the proof is derived. ∎

The trivial limit. If the two states are equal, $f_{\rm L}(P) + f_{\rm R}(P) = 0$ at $P = P_{\rm L}$, so $P^{*} = P_{\rm L}$ and $u^{*} = u_{\rm L}$: nothing happens, as it must. If (4.2) fails, the two rarefactions pull the gas apart faster than sound can fill the gap, and a vacuum opens between them; the solver of this module stops with an error rather than return a pressure. The run solves (4.1) by Newton's method from a linearised first guess and samples the solution at any $x/t$ by the standard construction of each wave; the whole solver is riemann_star and riemann_sample in afd/figs/m14_solvers.py.

5. The anchor: Sod's shock tube

In 1977 Gary Sod compared the difference schemes of his day on one problem: a tube of gas at rest with $\rho = 1$, $P = 1$ on the left of a diaphragm and $\rho = 0.125$, $P = 0.1$ on the right, $\gamma = 1.4$ (his report COO-3077-145, p. 17, on a grid of $\Delta x = 0.01$ at Courant number $0.9$). The problem has been the first test of every code since, because its exact solution contains all three waves of Definition 2: a rarefaction moving left, a contact, and a shock moving right. This book evaluates it at $t = 0.2$ with the diaphragm at $x = 0.5$ on $[0, 1]$.

0 0.2 0.4 0.6 0.8 1 0 0.25 0.5 0.75 1 exact (Riemann solution) Godunov, 100 cells Godunov, 800 cells SPH, 400 particles per unit length contact shock rarefaction fan x ρ
Density in Sod's shock tube at $t = 0.2$. White: the exact solution of Proposition 6. Orange, dashed: Godunov's method on 100 cells. Teal: on 800 cells. Violet dots: every second SPH particle of §8, at 400 particles per unit length. The contact is at $x = 0.685491$ and the shock at $0.850431$. The SPH particles overshoot the density at the head of the fan, near $x = 0.25$; this module does not measure that overshoot.
CHECK 2 (a) — the exact solution. CONFIRMED. Proposition 6 gives $P^{*} = 0.303130$, $u^{*} = 0.927453$, $\rho^{*}_{\rm L} = 0.426319$, $\rho^{*}_{\rm R} = 0.265574$, shock speed $1.752156$, rarefaction head $-1.183216$ and tail $-0.070273$. Marzouk (2020), Table 2, prints $0.30313$, $0.92745$, $0.42632$, $0.26557$ and $1.75216$; all five agree to every printed decimal. Across the computed shock the mass and momentum jump conditions are satisfied to $2.78\times10^{-17}$ and $8.33\times10^{-17}$, and across the fan $P/\rho^{\gamma}$ is $1.000000$ on both sides. Sod's own report prints $0.426$, $0.927$, $0.303$ and $0.266$ in its Table II (report p. 31). Those are the constant states of Glimm's method on 9 interior points, not a printed exact solution, and they agree with Proposition 6 at the three decimals printed. The check confirms both branches of the solver of Proposition 6: Module 8's jump conditions on the shock side, and on the rarefaction side the isentropic branch, which rests on the Riemann invariant that this book states and does not derive (Module 8 §3.1 names the fan and does not derive it).

What the exact solution makes possible is a measurement of the error of a code, region by region. The run applies Godunov's method at $C_{\rm CFL} = 0.9$ on $N = 100$ to $6400$ cells, measures the $L_1$ error of the density, $\sum_i|\rho_i - \rho_{\rm exact}(x_i)|\Delta x$, and splits it at the midpoints between the waves ($x = 0.585718$ and $0.767961$) into the fan, the contact and the shock.

The contact is predicted in advance. Inside the star region $P$ and $u$ are uniform. The Riemann problem between two cells with the same $P$ and $u$ and different $\rho$ has as its solution the contact alone, moving at $u^{*}$, so Godunov's flux of mass there is exactly $\rho_i u^{*}$: the upwind flux. The density across the contact is therefore advected by (2.1) at the Courant number $C_{\rm c} = u^{*}\Delta t/\Delta x$, which the run records step by step (its mean is $0.3810$ at $N = 6400$). Because $u^{*} \gt 0$, the upwind cell is the left one. A step has no variance, so Proposition 5 is applied to its differences. Let $d_i = \rho_{i-1} - \rho_i$. Because (2.1) is linear and its coefficients do not depend on $i$, the differences obey (2.1) too, with the Courant number $C_{\rm c}$ of each step. Initially $d_i$ is a single spike of height $\Delta\rho_{\rm c}$ at the contact. Each step replaces $d_i$ by the weighted average $(1 - C_{\rm c})d_i + C_{\rm c}d_{i-1}$, so for $0 \le C_{\rm c} \le 1$ the spike stays non-negative and Proposition 5 applies at every step: the total stays $\Delta\rho_{\rm c}$, and the variance grows to $\sigma^{2} = \sum_n C_{\rm c}(1 - C_{\rm c})\Delta x^{2}$. After many steps the sum of these independent two-point moves has a Gaussian profile, by the central limit theorem, whose conditions hold because each move is at most one cell and the variances sum without limit. The density is $\rho^{*}_{\rm L}$ minus the running sum of the $d_i$, so it is the step smoothed by that Gaussian. A step of height $\Delta\rho_{\rm c}$ smoothed by a Gaussian of width $\sigma$ has an $L_1$ error $2\Delta\rho_{\rm c}\int_0^\infty[1 - \Phi(y/\sigma)]\,\mathrm{d}y$, with $\Phi$ the standard normal distribution function, which is $$ E_{\rm c} \;=\; \Delta\rho_{\rm c}\,\sigma\left(\frac{2}{\pi}\right)^{1/2}, \qquad \sigma \propto \Delta x^{1/2}. \tag{5.1}$$ With $\Delta\rho_{\rm c} = 0.160746$ this has no free parameter. Because $\Delta t \propto \Delta x$, the number of steps is proportional to $1/\Delta x$, so $\sigma^{2} \propto \Delta x$ and the contact error falls as $\Delta x^{1/2}$. A shock does not smear this way: its characteristics converge on it, the width stays a fixed number of cells, and its error falls as $\Delta x$.

100 200 400 800 1600 3200 6400 10−5 10−4 10−3 10−2 total, order 0.646 rarefaction fan, 0.752 contact, 0.511 shock, 1.013 contact predicted by (5.1), no fit cells N L1
CHECK 2 (b). $L_1$ error of the density against the number of cells, by region. The contact error (teal) falls with slope $0.511$ and lies just above the dashed line, which is (5.1) evaluated with the run's own time steps and no fitted parameter. The shock error (orange) falls with slope $1.013$. The total (white) falls with slope $0.646$.
CHECK 2 (b) — THE ANCHOR. The contact law CONFIRMED; the formal order REFUTED. From $N = 100$ to $6400$ the $L_1$ error falls with order $1.013$ at the shock, $0.511$ at the contact, $0.752$ in the fan and $0.646$ in total. The contact error is $1.1293$ times (5.1) at $N = 100$ and $1.0659$ times at $N = 6400$, and the ratio falls at every doubling of $N$. (5.1) has no fitted parameter, and its rate $\Delta x^{1/2}$ agrees with Banks, Aslam and Rider (2008), who give the smeared width as $(4\nu t)^{1/2}$ with $\nu = O(\Delta x)$. What is refuted is the use of a scheme's formal order of accuracy as its rate of convergence on a flow that contains a contact. Godunov's method is first order, and on a flow that contains a contact its total error falls with order $0.646$. As $N$ grows the contact dominates and the order tends to $1/2$: the contact share of the error rises from $35.0$ per cent at $N = 100$ to $61.3$ per cent at $N = 6400$.

The fan, with order $0.752$, has no prediction here. Its solution is continuous, but its head and tail are corners where the derivative jumps, and a first-order scheme smears a corner too; this module does not derive the rate at which it does so. The ratio of $1.0659$ rather than $1$ is error that (5.1) does not model. The contact window also contains both star plateaus, and this module does not identify the source of the excess. The excess falls with $N$ faster than $E_{\rm c}$ does: it is $1.1293 - 1$ of $E_{\rm c}$ at $N = 100$ and $1.0659 - 1$ at $N = 6400$, and the ratio falls at every doubling.

6. A closed form tests a code: the Sedov blast

Module 8 §4 solved the blast wave of a point explosion exactly: the shock is at $R = \xi_0(Et^{2}/\rho_0)^{1/5}$ with $\xi_0 = 1.032777$ for $\gamma = 7/5$. Kamm and Timmes (2007) turned that into a standard problem for codes: $\rho_0 = 1$, $\gamma = 1.4$ and $E = 0.851072$ in spherical geometry put the shock at $r = 1.0$ at $t = 1.0$. The run imports Module 8's integrator unchanged (the routines are copied, not retyped), recomputes $\xi_0 = 1.032777$ and so an exact radius of $1.000000$ at $t = 1$.

The code is Godunov's method in spherical geometry: cells of volume $(r_+^{3} - r_-^{3})/3$ per steradian, face areas $r^{2}$, and in the momentum equation the geometric source $P(r_+^{2} - r_-^{2})/V$, which is the cell integral of $2Pr$ and makes a uniform pressure an exact steady state. The energy is deposited as heat in the innermost cell, the ambient pressure is $10^{-6}$, and the grid covers $0 \le r \le 1.2$. The run uses $n = 100$, $200$ and $400$ cells at $C_{\rm CFL} = 0.5$. The largest run takes $80{,}935$ steps, because the gas at the centre becomes hot and rarefied and its sound speed sets the step.

0 0.2 0.4 0.6 0.8 1 1.2 0 1 2 3 4 5 6 exact (Module 8, ξ0 = 1.032777) Godunov, 100 cells: peak 3.06 Godunov, 200 cells: peak 3.76 Godunov, 400 cells: peak 4.40 jump ceiling 6 r ρ
CHECK 3. Density against radius at $t = 1$. White: Module 8's exact profile, which jumps to the ceiling $6$ at $r = 1$. Violet, teal, orange: Godunov's method on 100, 200 and 400 cells. The outer edge converges on $r = 1$; the peak is $3.0559$, $3.7619$ and $4.4010$.
CHECK 3 — the Sedov problem of Kamm and Timmes. The position CONFIRMED; the peak NOT REACHED. The radius at which the density falls to half its peak value above ambient is $1.02764$, $1.01365$ and $1.00663$ at $n = 100$, $200$ and $400$: an error of $0.02764$, $0.01365$ and $0.00663$, which halves at each doubling, as a first-order scheme's shock should. The peak density is $3.0559$, $3.7619$ and $4.4010$ against the jump ceiling $(\gamma+1)/(\gamma-1) = 6$ of Module 8 §3. Total energy is conserved to $2.6\times10^{-16}$, $2.1\times10^{-15}$ and $3.9\times10^{-16}$ of itself.

The two halves of CHECK 3 point opposite ways for one reason. In the exact solution almost all the swept-up mass sits in a thin shell behind the shock (Module 8 §4). A scheme that smears by Proposition 4 spreads that shell over several cells and lowers its peak, while the position of the shock is fixed by conservation of energy and mass, which the scheme keeps exactly by Proposition 1. A code judged only on its peak density at $n = 400$ would appear to violate Module 8's jump condition by $26.65$ per cent. It does not: the peak is the quantity a first-order code converges on most slowly.

7. Smoothed particle hydrodynamics

A grid code fixes the cells and moves the fluid through them. Smoothed particle hydrodynamics (SPH) does the opposite: the fluid is a set of particles of fixed mass that move with the flow, and every field is an average over neighbours. It needs no grid, it follows collapsing gas to high density without refinement (its spatial resolution follows the density; its mass resolution does not, §9), and it conserves momentum exactly.

Definition 4 (the kernel and the density sum). Each particle $a$ has mass $m_a$, position $x_a$ and a smoothing length $h_a$. In one dimension the M4 cubic spline kernel is $$ W(x, h) = \frac{2}{3h}\begin{cases} 1 - \tfrac32 q^{2} + \tfrac34 q^{3}, & 0 \le q \lt 1,\\ \tfrac14(2 - q)^{3}, & 1 \le q \lt 2,\\ 0, & q \ge 2,\end{cases} \qquad q = |x|/h, \tag{7.1}$$ normalised so that $\int W\,\mathrm{d}x = 1$ (Monaghan 1992, pp. 554–555, with the constant $2/3$ in one dimension). The density is the sum $\rho_a = \sum_b m_b W(x_a - x_b, h_a)$, including $b = a$, and this module sets $h_a = 1.2\,m_a/\rho_a$, iterated with the sum.

Here bare $h$ is the smoothing length, a module-local meaning: Module 7's $h_B$, $h_S$ and Module 8's mixing width $h$ do not occur in this module. With $h = 1.2\,\Delta x$ the kernel reaches $2.4$ particle spacings on each side.

Proposition 7 (SPH conserves momentum exactly). Let the particles move by $$ \frac{\mathrm{d}v_a}{\mathrm{d}t} = -\sum_{b\ne a} m_b\left(\frac{P_a}{\rho_a^{2}} + \frac{P_b}{\rho_b^{2}} + \Pi_{ab}\right)\partial_{x_a}\overline{W}_{ab}, \qquad \overline{W}_{ab} = \tfrac12\left[W(x_a - x_b, h_a) + W(x_a - x_b, h_b)\right], \tag{7.2}$$ where $\Pi_{ab} = \Pi_{ba}$ is any symmetric pair term. Then $\sum_a m_a v_a$ is constant in time.
$\overline{W}_{ab}$ depends on the positions only through $x_a - x_b$ and is even in it, so $\partial_{x_b}\overline{W}_{ab} = -\partial_{x_a}\overline{W}_{ab}$, and $\overline{W}_{ba} = \overline{W}_{ab}$. The force on $a$ from $b$ is $-m_am_bT_{ab}\,\partial_{x_a}\overline{W}_{ab}$, with $T_{ab}$ the bracket in (7.2), which is symmetric in $a$ and $b$. The force on $b$ from $a$ is $-m_bm_aT_{ab}\,\partial_{x_b}\overline{W}_{ab} = +m_am_bT_{ab}\,\partial_{x_a}\overline{W}_{ab}$. Each pair contributes forces that are equal and opposite, so $\mathrm{d}(\sum_a m_av_a)/\mathrm{d}t = 0$. The trivial limit: with one particle there are no pairs, and it moves at constant velocity. ∎

What is stated. Shocks need dissipation that (7.2) does not have. Monaghan's artificial viscosity (1992, p. 550, printed without an equation number) is $\Pi_{ab} = (-\alpha\bar c_{ab}\mu_{ab} + \beta\mu_{ab}^{2})/\bar\rho_{ab}$ for approaching particles and zero otherwise, with $\mu_{ab} = \bar h_{ab}v_{ab}x_{ab}/(x_{ab}^{2} + 0.01\bar h_{ab}^{2})$ (his eq. 4.2), bars denoting pair averages, and "$\alpha = 1$ and $\beta = 2$" (p. 551), the values used here. The thermal energy per unit mass evolves by $\mathrm{d}u_a/\mathrm{d}t = \sum_b m_b(P_a/\rho_a^{2} + \Pi_{ab}/2)\,v_{ab}\,\partial_{x_a}\overline{W}_{ab}$, which with (7.2) conserves the total energy; Problem D3 shows it. The integrator is kick–drift–kick with a step of $0.2\,h/(c_{\rm s} + |v|)$.

8. Grid against particles at a contact

The same Sod problem, run with SPH, separates the two methods at one place. The particles have equal mass, so the right-hand gas, eight times less dense, has particles eight times further apart. The run places 200, 400 or 800 particles per unit length on the left, freezes the six outermost particles at each end of $[-0.5, 1.5]$ as walls, and measures the pressure near the contact at $t = 0.2$, where the exact pressure is $P^{*} = 0.303130$ everywhere between the fan and the shock.

0.5 0.6 0.7 0.8 0.9 0.27 0.29 0.31 0.33 exact p* = 0.30313 SPH, standard: +9.4 per cent at the contact SPH with conductivity: 2.2 per cent contact x P
CHECK 4. Pressure between $x = 0.45$ and $0.9$ at $t = 0.2$, SPH at 800 particles per unit length. White, dashed: the exact $P^{*} = 0.30313$. Red: standard SPH ($\alpha = 1$, $\beta = 2$), with a spike at the contact. Teal: the same with artificial conductivity $\alpha_u = 1$.
CHECK 4 — SPH at a contact. Standard SPH REFUTED as convergent there; the repair CONFIRMED. The largest pressure error within $0.05$ of the contact, $\max|P - P^{*}|/P^{*}$, is $0.0893$, $0.0938$ and $0.0942$ at 200, 400 and 800 particles per unit length. It does not fall with resolution. On the plateau between the fan and the contact the same error falls, $0.0158$, $0.0115$, $0.0049$, and the mean density error over $[0, 1]$ falls, $9.0355\times10^{-3}$, $5.7655\times10^{-3}$, $4.0975\times10^{-3}$. Of the two places where the run measures the pressure, the error falls on the plateau and does not fall at the contact. There the thermal energy per unit mass reaches $3.0943$ against the exact $2.8535$ on the hot side. With Price's (2008) artificial conductivity, his eq. (27) with the signal speed $(|P_a - P_b|/\bar\rho_{ab})^{1/2}$ of his eq. (33) and $\alpha_u = 1$, the contact error is $0.0371$, $0.0310$ and $0.0216$, and it falls.

Price describes this as "a large 'blip' in the pressure profile around the contact discontinuity" (arXiv preprint, p. 15). That run takes the density from the continuity equation, and he attributes the blip to "the unresolved gradient in density and a slight overshoot in the thermal energy at the same location". With the density computed by the sum of Definition 4, as here, he finds that "a spurious blip in the pressure is still apparent due to the overshoot in thermal energy" (p. 16). This run shows that overshoot: at 800 particles per unit length the thermal energy within $0.05$ of the contact reaches $3.0943$ against the exact $2.8535$, and $P = (\gamma-1)\rho u$ carries it into the pressure. His own tube uses $\gamma = 5/3$ with 450 particles; this module uses Sod's $\gamma = 1.4$, so the numbers are not his, only the finding. A grid code has the opposite behaviour: Godunov's method smears the contact in density by Proposition 5, but it never produces a pressure spike there, because both $\rho$ and $E$ are smeared by the same flux.

Why this matters beyond one dimension. A contact between gases of different entropy is exactly the interface of Module 7 §6. Price argues that the same pressure blip acts on a shearing interface as an artificial surface tension, and surface tension is what Module 7's dispersion relation shows stabilising short wavelengths. Agertz et al. (2007) ran the Kelvin–Helmholtz instability with density contrasts of 8 and 10, with a grid code (Enzo) and an SPH code (Gasoline), and found that in SPH "Perturbations are damped out very quickly" (arXiv preprint, p. 13), while the grid code grew the rolls. They attribute the failure to density gradients; Price (arXiv preprint, p. 28) attributes it to entropy gradients, "not density gradients as has often been assumed", and the interface named above follows Price. This module does not reproduce the two-dimensional test; it reproduces its one-dimensional cause.

9. Following a collapse

Module 5 §3 derived the Jeans length $\lambda_{\rm J} = (\pi c_{\rm s}^{2}/G\rho_0)^{1/2}$ and showed that perturbations longer than it grow. A code has its own shortest length, the cell. If the cell is comparable with $\lambda_{\rm J}$, rounding errors on the grid scale can grow under gravity where the gas should be stable, and the code fragments a cloud that should not fragment.

Proposition 8 (the Jeans condition as a resolution requirement). Truelove et al. (1997) define the Jeans number $J = \Delta x/\lambda_{\rm J}$ (their eq. 2, p. L180) and find that an isothermal collapse computed on a grid is free of artificial fragmentation when $J \le 0.25$. Because $\lambda_{\rm J} \propto \rho^{-1/2}$ at fixed temperature, following an isothermal collapse from density $\rho_0$ to $\rho$ requires the cell to shrink by the factor $(\rho/\rho_0)^{1/2}$. The first sentence is stated; the second is derived.
What is stated. The value $0.25$ is empirical. Truelove et al. established it on the collapse of a centrally condensed isothermal cloud computed with adaptive refinement at $J_{\max} = 0.5$, $0.375$, $0.25$ and $0.125$, and it is not derived from a stability analysis. Truelove et al. call the resolution of $\lambda_{\rm J}$ "a necessary (but not, in general, sufficient) condition for convergence" (p. L181). What is derived. By Module 5's (3.2), $\lambda_{\rm J} = (\pi c_{\rm s}^{2}/G\rho)^{1/2}$ with $c_{\rm s}$ fixed by the temperature, so $\lambda_{\rm J}(\rho)/\lambda_{\rm J}(\rho_0) = (\rho_0/\rho)^{1/2}$, and a cell that satisfies $\Delta x \le 0.25\,\lambda_{\rm J}$ at the density reached must be smaller by that factor. ∎

For Module 5's $10$ K core at $n(\mathrm{H_2}) = 10^{4}\ \mathrm{cm^{-3}}$, $\lambda_{\rm J} = 0.19479$ pc $= 40{,}178$ AU (the run converts Module 5's rounded $0.19479$ pc; module05.html:170 prints $40177$ AU from the unrounded value) and $M_{\rm J} = 2.658\,M_\odot$, so the cell must be at most $1.004\times10^{4}$ AU. At $10^{6}$, $10^{8}$ and $10^{10}\ \mathrm{cm^{-3}}$ the limit falls to $1004$, $100.4$ and $10.04$ AU. A uniform grid that covers four initial Jeans lengths, $0.77916$ pc, at the resolution needed at $10^{10}\ \mathrm{cm^{-3}}$ needs $1.6\times10^{4}$ cells per side and $4.096\times10^{12}$ in three dimensions. That is why collapse is followed with adaptive mesh refinement, which halves the cell only where $J$ would exceed the limit: a factor $10^{3}$ in $\lambda_{\rm J}$ is $9.966$ levels of factor-2 refinement. The whole of this paragraph assumes the gas stays at $10$ K; it stops being true when the gas becomes opaque to its own cooling radiation, which this book does not compute.

The SPH counterpart is stated, not derived. Bate and Burkert (1997) find that SPH resolves gravitational fragmentation only when the Jeans mass exceeds the mass of about twice the number of neighbours, $M_{\rm res} \approx 2N_{\rm neigh}m$ (their eq. 6, p. 1068), with $N_{\rm neigh} = 50$. At $10^{10}\ \mathrm{cm^{-3}}$ the core's $M_{\rm J}$ is $0.002658\,M_\odot$, so each particle may carry at most $2.66\times10^{-5}\,M_\odot$. The condition does not take care of itself as the gas collapses. The particles crowd together, so the smoothing length shrinks and the spatial resolution follows the density without refinement. The particle mass $m$ does not change, and $M_{\rm J} \propto \rho^{-1/2}$ falls. A calculation therefore resolves fragmentation only up to the density at which $M_{\rm J}$ has fallen to $2N_{\rm neigh}m$, which Bate and Burkert give as a maximum resolvable density (their eq. 7, p. 1068). The particle mass must be chosen at the start for the highest density the run is to follow; the limit above is the one for this core followed to $10^{10}\ \mathrm{cm^{-3}}$. A grid meets the Truelove condition by adding cells where they are needed; an SPH run of fixed particle mass meets the Bate and Burkert condition only if its particle mass was chosen small enough in advance.

10. The price of resolution

Module 10 §3 priced resolving the dissipation scale. This module adds two results. The first is a bound on what any scheme can represent, and it returns Module 10's own count. The second is the cost of a contact, and it makes the count worse.

A bound for any scheme. No scheme can represent a structure narrower than one cell, so a code with $N$ cells across the outer scale $L$ has a dissipation scale of at least $\Delta x = L/N$. By Module 10's (3.4), $L/\eta = \mathrm{Re}^{3/4}$, so the largest Reynolds number such a code can represent is $\mathrm{Re} \le N^{4/3}$: $1.032\times10^{4}$ at $N = 1024$ and $6.554\times10^{4}$ at $N = 4096$. A wind-tunnel flow at $\mathrm{Re} = 10^{6}$ needs $3.162\times10^{4}$ cells per side, which is Module 10's number again. At $C = 0.5$ the upwind scheme falls short of this bound: by (3.3) it runs at $\mathrm{Re}_{\rm num} = 2N/(1-C)$, which at $N = 1024$ and $C = 0.5$ is $4096$, below $N^{4/3} = 1.032\times10^{4}$.

The cost of a contact. CHECK 2 says what resolution buys where the flow has a contact. Fitted over the last doubling, the contact error of §5 falls with order $0.5209$. To bring it from its value at $N = 6400$ to $10^{-4}$ needs $N = 1.864\times10^{5}$ cells. In three dimensions the work scales as $N^{3}$ cells times $N$ Courant-limited steps, so that is $7.19\times10^{5}$ times the work at $N = 6400$ for a factor $5.79$ in error. A code user who expects first-order convergence would budget $N^{4}$ against $\Delta x$, and would be short by the difference between an error falling as $\mathrm{work}^{-1/4}$ and one falling as $\mathrm{work}^{-1/8}$.

11. Which numbers in this book came from a simulation

The plan of this book asked this module to say which of its results came from a simulation and which from a closed form. Two readers went through Modules 1 to 13 and classified every number that a module compares against or takes as an input: (a) the output of a numerical simulation; (b) a numerical model built by solving equations on a computer, such as the BS05 solar model table or the ATLAS9 model atmosphere; (c) an ordinary differential equation with no closed form, integrated numerically, by this book's own script or, in 3 of the 30 rows, by a published integration (Chandrasekhar's in Module 3, Kandori's in Module 5), such as Lane–Emden, Bonnor–Ebert, Sedov, or the critical solutions of Bondi and Parker. The count is by table row, and one row can hold several numbers from one source.

modules(a) simulation(b) numerical model(c) an ODE with no closed form, integrated numerically
1–78 (Modules 1, 6, 7)50 (mostly BS05 in Modules 3, 4, 6, and Wolfire et al. in Module 6)14 (Lane–Emden in 3, Bonnor–Ebert in 5)
8–1321 (11 in Module 8)21 (14 in Module 13, ATLAS9)16 (Sedov in 8, Bondi and Parker in 9, Hopf in 13)
total297130

The closed-form results that carry the book are the other column: the mean free paths of Module 1, the jump conditions and the $2/5$ exponent of Module 8, Kolmogorov's $5/3$ and $4/5$ in Module 10, the Eddington limit of Module 13. Class (c) is not simulation in the sense of this module: it is a quadrature whose error the book controls and reports, as Module 8 §4 does for $\xi_0$ to eight digits. Classes (a) and (b) are inputs whose error the book does not control.

The census also found places where a shipped page names a simulation or a numerical model as a measurement. They are listed here as findings. The pages are not edited.

wherewhat is printedwhat the number is
module12.html:683, :690, :692, :955Zhuravleva et al.'s bound on the viscosity of the Coma cluster, called "measured"A comparison of a Chandra image with direct numerical simulation. Module 12 never uses the word "simulation"; Module 10 discloses it for the same number at module10.html:462
module08.html:878, :883, :939$0.08\,R_{\rm BW}$ at Tycho, listed and plotted as one of three "observed widths"Wang and Chevalier's two-dimensional simulation. The text says so, and the column heading says "observed". The zero point of every width, $0.77$, is also a one-dimensional simulation
module01.html:607, :690Randall et al.'s $\sigma/m \lt 0.7\ \mathrm{cm^2\,g^{-1}}$, "an observational result"An observed offset turned into a limit by simulations of the merging cluster; only the title in Sources says so
module05.html:703, :709, :744, :747Nielbock et al.'s density slope, "measured"The output of their radiative-transfer model, as :703 and :751 themselves say
module06.html:216, :342, :345, :426"measured plateau $0.3957$"A slope read off the BS05 solar model table
module03.html:182, :630the sound speed "at the Sun's centre", $394.1\ \mathrm{km\,s^{-1}}$, and $1-\beta_c$ "evaluated in the Sun"BS05 model values
module07.html:516$\alpha_B = 0.038\pm0.008$, a "measurement"Its extraction uses a Richtmyer–Meshkov velocity that the source took from simulations; only Sources says so
module11.html:211, :583, :600$\alpha = 0.1$–$0.4$, "measured" and "observed"Not verified. The values come from a review whose primary papers the book did not read; if they are fits of disc-instability models, the row is class (b)

The census did not re-open the verdicts of the modules that print these numbers. What changes is the kind of evidence: a check against a simulation tests whether two calculations agree, and a check against a measurement tests whether a calculation agrees with nature. The first seven rows are established from the shipped pages and their sources; the last is not, because the primary papers behind it were not read.

12. What this module captures, and what it misses

The module captures the three properties of a numerical scheme that decide whether its output can be trusted as a solution of the equations of this book: stability (the Courant condition), the equation it actually solves (the numerical viscosity), and its convergence on the discontinuities that astrophysical flows contain. It misses everything that makes a production code: more than one dimension, higher-order reconstruction, magnetic fields, self-gravity, radiation, and adaptive grids.

idealisationwhat it costswhere it is repaid
One dimension onlyNo test here of a code's behaviour on vortices, fingers or turbulence. The Kelvin–Helmholtz failure of SPH is cited from Agertz et al., not reproducedNowhere in this book; the plan caps numerics at one module
First-order schemes onlyEvery rate in CHECK 2 and CHECK 3 is for a first-order method. In smooth flow a second-order method's error falls as $\Delta x^{2}$; at a contact Banks, Aslam and Rider estimate the rate $p/(p+1)$ for a method of order $p$, which is $2/3$ for $p = 2$, and this module does not test itNowhere in this book
The Truelove condition stated, not derived (module05.html:767)§9 pays the debt as a resolution count; the value $0.25$ is Truelove et al.'s empirical onePaid as a count
Pope's $\mathrm{Re}^{3}$ section (module10.html:1064)Only Pope's Fig. 9.3 caption was read, whose asymptote $(R_\lambda/70)^{6}$ is proportional to $\mathrm{Re}^{3}$ since $R_\lambda \propto \mathrm{Re}^{1/2}$. The section number Module 10 cites remains unconfirmedHalf paid
A grid cannot repair a closureModule 1's Problem K2 already shows a simulation with $10$ kpc cells resolving scales on which the gas has no fluid description. Nothing in this module changes that: a code converges to the solution of the equations it is givenModule 1
No self-gravity, no magnetic fields, no radiation in any code§9 counts cells; it runs no collapseNowhere in this book

Of the debts the shipped pages and the plan printed against this module, six are paid: the Courant condition that Module 10 Proposition 4 used, by Propositions 2 and 3; which problem a code solves (module10.html:285, :918), by Propositions 4 and 5 and §10; how a collapse is followed (module05.html:767), by §9; Riemann solvers, by §4 and §5; grid against SPH, by §7 and §8; and the census, by §11. One is half paid, Pope's section, in the table above.

13. Problems

C1. Use (2.3) to find the largest amplification factor of FTCS at $C = 0.5$ and the mode that has it. How many steps does that mode take to grow by a factor of $10^{3}$?
Solution
$|G|^2 = 1 + C^2\sin^2\theta$ is largest at $\theta = \pi/2$, a wavelength of four cells, where $|G| = (1 + 0.25)^{1/2} = 1.118034$. It grows by $10^{3}$ in $\ln 10^{3}/\ln 1.118034 = 61.91$ steps, so 62. The Courant condition (2.2) holds at $C = 0.5$, and the scheme still fails, because Proposition 2 is necessary and not sufficient.
C2. Sod's problem is run by Godunov's method on 400 cells of $[0, 1]$ at $C_{\rm CFL} = 0.9$. What is the first time step? Why does the run of §5 need $194$ steps to reach $t = 0.2$ rather than the $105$ this step would give?
Solution
At $t = 0$ the gas is at rest and the largest signal speed is the left sound speed, $c_{\rm L} = (1.4)^{1/2} = 1.183216$. So $\Delta t = 0.9\times(1/400)/1.183216 = 1.901597\times10^{-3}$, and $0.2/\Delta t = 105.17$. Once the flow starts, $|u| + c_{\rm s}$ rises: behind the shock the gas moves at $u^{*} = 0.927453$ with $c_{\rm s} = (1.4\times0.303130/0.265574)^{1/2} = 1.264$, so $S_{\max}$ nearly doubles and the step nearly halves.
C3. A code runs the upwind scheme on $N = 512$ cells at $C = 0.8$. What Reynolds number does it run at, by (3.3), and what is the largest Reynolds number that any scheme on 512 cells can represent, by §10?
Solution
$\mathrm{Re}_{\rm num} = 2\times512/0.2 = 5120.0$. The bound is $512^{4/3} = 4096.0$. The upwind number is above the bound, which is not a contradiction: (3.3) says the scheme's diffusion is weak enough to allow $\mathrm{Re} = 5120$, while the bound says that no structure smaller than one cell can be represented, whatever the diffusion. The smaller of the two numbers applies, and here that is the grid.
D1. Derive the modified equation (3.1) of the upwind scheme, and show that at $C = 1$ the scheme is exact.
Solution
See the proof of Proposition 4. At $C = 1$, (2.1) gives $u_i^{n+1} = u_{i-1}^n$: the data move exactly one cell, $a\Delta t = \Delta x$, which is the exact solution. (3.1) gives $D_{\rm num} = 0$, and (2.3) gives $|G| = 1$ for every mode. Every higher term of the modified equation also vanishes, because the scheme and the exact solution agree at the grid points.
D2. For a Riemann problem in which both waves are shocks, derive (4.1) from Module 8's jump conditions, and show that the root is unique.
Solution
See the proof of Proposition 6, shock branch, for each side. Both $f_{\rm L}$ and $f_{\rm R}$ increase with $P$ for $P \gt P_K$: $f_K' = [A_K/(P + B_K)]^{1/2}[1 - (P - P_K)/(2(P + B_K))]$, and the second factor is positive because $P - P_K \lt 2(P + B_K)$. So the left side of (4.1) is strictly increasing and has at most one root.
D3. Show that the SPH equations of §7, (7.2) with the energy equation given there, conserve $\sum_a m_a(\tfrac12v_a^{2} + u_a)$ exactly in continuous time.
Solution
$\mathrm{d}/\mathrm{d}t\sum_a m_a\tfrac12v_a^{2} = -\sum_a\sum_b m_am_bT_{ab}v_a\,\partial_{x_a}\overline W_{ab}$. Symmetrise over the pair using $\partial_{x_b}\overline W_{ab} = -\partial_{x_a}\overline W_{ab}$: it is $-\tfrac12\sum_{a,b}m_am_bT_{ab}v_{ab}\,\partial_{x_a}\overline W_{ab}$. The thermal term is $\sum_a m_a\mathrm{d}u_a/\mathrm{d}t = \sum_{a,b}m_am_b(P_a/\rho_a^2 + \Pi_{ab}/2)v_{ab}\partial_{x_a}\overline W_{ab}$, and symmetrising it gives $\tfrac12\sum_{a,b}m_am_b(P_a/\rho_a^2 + P_b/\rho_b^2 + \Pi_{ab})v_{ab}\partial_{x_a}\overline W_{ab}$, because $v_{ab}\partial_{x_a}\overline W_{ab}$ is symmetric in $a$ and $b$. The two sums cancel.
K1. Solve Toro's "123 problem" exactly: $\rho = 1$, $P = 0.4$ on both sides, $u_{\rm L} = -2$, $u_{\rm R} = +2$, $\gamma = 1.4$. Find $P^{*}$, $u^{*}$ and $\rho^{*}$, and check (4.2).
Solution
$c = (1.4\times0.4)^{1/2} = 0.748331$ on both sides, and (4.2) is $5\times1.496663 = 7.483$ against $u_{\rm R} - u_{\rm L} = 4$: no vacuum. Both waves are rarefactions. By symmetry $u^{*} = 0.000000$, and (4.1) gives $P^{*} = 0.001894$ and $\rho^{*} = 0.021852$ on both sides of the contact. The gas between the two fans is close to a vacuum without being one, which is why the problem is used to test whether a code keeps $\rho$ and $P$ positive.
K2. Module 5's $10$ K core, at $n(\mathrm{H_2}) = 10^{4}\ \mathrm{cm^{-3}}$, has $\lambda_{\rm J} = 0.19479$ pc. A uniform grid covers four of these Jeans lengths and is to follow the collapse, isothermally, to $n(\mathrm{H_2}) = 10^{8}\ \mathrm{cm^{-3}}$ with $J \le 0.25$. How many cells does it need?
Solution
At $10^{8}$, $\lambda_{\rm J} = 0.19479\times10^{-2} = 0.0019479$ pc by Proposition 8. The cell is at most a quarter of that, and the box is $4\times0.19479$ pc, so it needs $4\times0.19479/(0.25\times0.0019479) = 1600.0$ cells per side and $4.096\times10^{9}$ in three dimensions.
K3. CHECK 2 measures the contact error of Godunov's method on Sod's problem as $8.3074\times10^{-4}$ at $N = 3200$ and $5.7898\times10^{-4}$ at $N = 6400$. Assuming the same order continues, how many cells bring it to $10^{-4}$, and how much more work is that in three dimensions than $N = 6400$?
Solution
The order over the last doubling is $\ln(8.3074/5.7898)/\ln 2 = 0.5209$. Then $N = 6400\times(5.7898\times10^{-4}/10^{-4})^{1/0.5209} = 1.864\times10^{5}$. In three dimensions the work goes as $N^3$ cells times $N$ steps, so the ratio is $(1.864\times10^{5}/6400)^{4} = 7.19\times10^{5}$. At first order it would have been $(5.79)^{4} = 1.12\times10^{3}$.

Notation

symbolmeaningunitsfirst use
$U$, $F(U)$, $E$the conserved densities $(\rho, \rho u, E)$, their fluxes, and the total energy per unit volume $P/(\gamma-1) + \rho u^2/2$. Module 8's $E$ is the energy of an explosion; in §6 that energy is written $E$ as well, and the context says whichcgs; dimensionless in the test problems§1
$\Delta x$, $\Delta t$, $N$, $i$, $n$cell width, time step, number of cells or particles, cell index, step index. $N$ is Module 10's grid-point count; Module 6's Brunt–Väisälä $N$ does not occurcm, s, —Definition 1
$C_{\rm CFL}$, $C$Courant number; bare $C$ in the linear problems of §2 and §3. Module 2's $C[f]$, Module 9's integration constant and Module 10's $C$, $C_K$ do not occur—Definition 1
$S_{\max}$largest signal speed $|u| + c_{\rm s}$ on the grid$\mathrm{cm\,s^{-1}}$Definition 1
$a$advection speed in §2 and §3; as a subscript, the particle index in §7 and §8. Never the radiation constant, which is $a_{\rm rad}$$\mathrm{cm\,s^{-1}}$§2
$G(\theta)$, $\theta$amplification factor per step, always with its argument, and Fourier phase $k\Delta x$. Bare $G$ remains the gravitational constant in §9—Proposition 3
$D_{\rm num}$, $\mathrm{Re}_{\rm num}$numerical diffusivity of the upwind scheme and the Reynolds number it sets. Module 13's photon diffusivity $D$ does not occur$\mathrm{cm^2\,s^{-1}}$, —Proposition 4
$P^{*}$, $u^{*}$, $\rho^{*}_{\rm L}$, $\rho^{*}_{\rm R}$star-region pressure, velocity and the densities either side of the contactcgsDefinition 2
$f_K$, $A_K$, $B_K$, $c_K$the wave functions of (4.1), $K = {\rm L}$ or ${\rm R}$cgsProposition 6
$C_{\rm c}$, $\sigma$, $E_{\rm c}$, $\Delta\rho_{\rm c}$Courant number at the contact, $u^{*}\Delta t/\Delta x$; width of the smeared contact; its $L_1$ error; the density jump across it. This $\sigma$ is a length, in §5 only; Module 1's cross-section does not occur—, cm, —, $\mathrm{g\,cm^{-3}}$(5.1)
$h$, $W(x, h)$, $\overline W_{ab}$SPH smoothing length (module-local; Module 7's $h_B$ and Module 8's mixing width do not occur), the kernel with its arguments, and the pair-averaged kernelcm, $\mathrm{cm^{-1}}$Definition 4
$m_a$, $v_a$, $u_a$particle mass, velocity and thermal energy per unit mass. In §7 and §8 $u_a$ is a thermal energy and $v_a$ the velocity; elsewhere $u$ is the flow velocity, as in Module 2g, $\mathrm{cm\,s^{-1}}$, $\mathrm{erg\,g^{-1}}$Definition 4
$\Pi_{ab}$, $\alpha$, $\beta$, $\alpha_u$Monaghan's artificial viscosity and its two coefficients; Price's conductivity coefficient. Module 11's disc $\alpha$ and Module 3's $\beta = P_{\rm gas}/P$ do not occur—§7
$J$, $N_{\rm neigh}$, $M_{\rm res}$Truelove's Jeans number $\Delta x/\lambda_{\rm J}$; SPH neighbour number; Bate and Burkert's minimum resolvable mass. Module 8's energy integral $J$ does not occur—, —, gProposition 8
$\lambda_{\rm J}$, $M_{\rm J}$Jeans length and mass, Module 5's Definition 2cm, g§9

Sources

  1. Courant, R., Friedrichs, K. & Lewy, H. (1928), "Über die partiellen Differenzengleichungen der mathematischen Physik", Math. Ann. 100, 32–74. Read in the English translation, "On the Partial Difference Equations of Mathematical Physics", IBM J. Res. Dev. 11 (1967) 215–234, translated by Phyllis Fox; the 1928 original was not seen. P. 228: the difference solution "in general cannot converge" for $k \lt 1$; p. 230: "If now $k \ge 1$ as we must require".
  2. Sod, G. A. (1978), "A survey of several finite difference methods for systems of nonlinear hyperbolic conservation laws", J. Comput. Phys. 27, 1–31. Not obtained. Read instead: G. A. Sod, "A Survey of Numerical Methods for Compressible Fluids", Courant Institute report COO-3077-145 (June 1977), OSTI 7308221. P. 17 gives the initial states, $\gamma = 1.4$, $\Delta x = 0.01$ and Courant number $0.9$; Table II (p. 31) prints $0.426$, $0.927$, $0.303$, $0.266$, the constant states of Glimm's method on 9 interior points, not labelled as the exact solution. The pages read give no output time.
  3. Marzouk, O. A. (2020), "The Sod gasdynamics problem as a tool for benchmarking face flux construction in the finite volume method", Scientific African 10, e00573, read as arXiv:2108.01709. Table 2, at $t = 0.2$, is CHECK 2 (a).
  4. Lax, P. & Wendroff, B. (1960), "Systems of conservation laws", Comm. Pure Appl. Math. 13, 217–237. Not obtained. Read instead: the report of the same title, Los Alamos LA-2285 (1958), whose p. 9 states the theorem of Proposition 1 (b).
  5. Godunov, S. K. (1959), Mat. Sb. 47(89), 271–306. Bibliographic record checked on Math-Net.Ru; the paper was not read, and nothing here depends on its text.
  6. Banks, J. W., Aslam, T. & Rider, W. J. (2008), "On sub-linear convergence for linearly degenerate waves in capturing schemes", J. Comput. Phys. 227, 6985–7002, read as the authors' preprint (OSTI 945128). The smeared width $(4\nu t)^{1/2}$ with $\nu = O(\Delta x)$, hence $\Delta x^{1/2}$ at a contact.
  7. Kamm, J. R. & Timmes, F. X. (2007), LA-UR-07-2849, their Sect. 6, as read for Module 8: $\rho_0 = 1$, $\gamma = 1.4$, $E = 0.851072$, shock at $r = 1.0$ at $t = 1.0$.
  8. Monaghan, J. J. (1992), "Smoothed particle hydrodynamics", ARA&A 30, 543–574, read from the original scan. Density sum eq. 2.7 (p. 545); $\Pi_{ab}$ p. 550 (no equation number), $\mu_{ab}$ eq. 4.2; "$\alpha = 1$ and $\beta = 2$" and "$\eta^2 = 0.01h^2$", p. 551; the cubic spline and its normalisation $2/3$ in one dimension, pp. 554–555.
  9. Price, D. J. (2008), "Modelling discontinuities and Kelvin–Helmholtz instabilities in SPH", J. Comput. Phys. 227, 10040–10057, read as arXiv:0709.2772v3; pages are the preprint's. The conductivity term eq. (27), its signal speed eq. (33); the "blip", p. 15 (density from the continuity equation) and p. 16 (density by summation); entropy against density gradients, p. 28; his shock tube at $\gamma = 5/3$ with 450 equal-mass particles.
  10. Agertz, O. et al. (2007), "Fundamental differences between SPH and grid methods", MNRAS 380, 963–978, read as arXiv:astro-ph/0610051v1. The journal record lists 19 authors and the preprint 20; the preprint's text was read, and the quotation "Perturbations are damped out very quickly" is its p. 13.
  11. Truelove, J. K., Klein, R. I., McKee, C. F., Holliman, J. H., II, Howell, L. H. & Greenough, J. A. (1997), "The Jeans condition: a new constraint on spatial resolution in simulations of isothermal self-gravitational hydrodynamics", ApJ 489, L179–L183. $J \equiv \Delta x/\lambda_{\rm J}$, eq. (2), p. L180, and the value $0.25$; "necessary (but not, in general, sufficient)", p. L181.
  12. Bate, M. R. & Burkert, A. (1997), "Resolution requirements for smoothed particle hydrodynamics calculations with self-gravity", MNRAS 288, 1060–1072, read from the ADS scan. $M_{\rm res} \approx M_{\rm tot}(2N_{\rm neigh}/N_{\rm tot})$, eq. (6), p. 1068; the maximum resolvable density, eq. (7), p. 1068; $N_{\rm neigh} = 50$.
  13. Toro, E. F., Riemann Solvers and Numerical Methods for Fluid Dynamics, Springer. Not read; cited for the name of the "123 problem" of Problem K1 only. Its values in K1 are this module's own run.
  14. Pope, S. B. (2000), Turbulent Flows, Cambridge University Press. Not obtained. Only the caption of his Fig. 9.3 was read, with the asymptote $(R_\lambda/70)^6$.
  15. The census of §11 was compiled by two readers of Modules 1–13 and is kept with the book's working records; every row carries the file:line it was read from.