Introduction to

Computational
AstrophysicalHydrodynamics

the Open Astrophysics Bookshelf

Michael Zingale© 2013, 2014, 2015, 2016, 2017 Michael Zingale
document git version: 64c838dee1a8 . . .
August 8, 2024
the source for these notes are available online (via git):
https://github.com/Open-Astrophysics-Bookshelf/numerical_exercises
c bnaThis work is licensed under the Creative Commons Attribution-NonCommercialShareAlike 4.0 International (CC BY-NC-SA 4.0) license.
iiChapter Listing

list of figuresxiii

list of exercises

xv

preface

xvii

I

1

Basics

1 Simulation Overview

3

2 Classification of PDEs

21

3 Finite-Volume Grids

25

II

35

Advection and Hydrodynamics

4 Advection Basics

37

5 Second- (and Higher-) Order Advection

49

6 Burgers’ Equation81

7 Euler Equations: Theory

93iii

8 Euler Equations: Numerical Methods

115

III

161

Elliptic and Parabolic Problems

9 Elliptic Equations and Multigrid

163

10 Diffusion

185

IV

Multiphysics applications

201

11 Model Multiphysics Problems

203

12 Reactive Flow

209

13 Planning a Simulation

217

V

223

Low Speed Hydrodynamics

14 Incompressible Flow and Projection Methods

225

15 Low Mach Number Methods

243

VI

Code Descriptions

253

A Using hydro_examples

255

B Using pyro259

C Using hydro1d265

References

267

iv

Table of Contents
list of figuresxiii

list of exercises

xv

preface

xvii

I

1

Basics

1 Simulation Overview
1.1 What is simulation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Numerical basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.1 Sources of error . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.2 Differentiation and integration . . . . . . . . . . . . . . . . . . . .
1.2.3 Root finding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.4 Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.5 ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.6 FFTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3
3
5
5
6
11
13
14
18

2 Classification of PDEs
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Hyperbolic PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Elliptic PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Parabolic PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21
21
21
22
22

3 Finite-Volume Grids
3.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Grid basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Finite-volume grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.1 Differences and order of accuracy . . . . . . . . . . . . . . . . . .
3.3.2 Conservation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.3 Boundary conditions with finite-volume grids . . . . . . . . . . .
3.4 Numerical implementation details . . . . . . . . . . . . . . . . . . . . . .
3.5 Going further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

25
25
26
27
29
30
30
31
32

v

II

35

Advection and Hydrodynamics

4 Advection Basics
4.1 The linear advection equation . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 First-order advection in 1-d and finite-differences . . . . . . . . . . . . .
4.3 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3.1 Domain of dependence . . . . . . . . . . . . . . . . . . . . . . . .
4.4 Implicit-in-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5 Eulerian vs. Lagrangian frames . . . . . . . . . . . . . . . . . . . . . . . .
4.6 Errors and convergence rate . . . . . . . . . . . . . . . . . . . . . . . . . .

37
37
38
42
43
45
46
47

5 Second- (and Higher-) Order Advection
5.1 Advection and the finite-volume method . . . . . . . . . . . . . . . . . .
5.2 Second-order predictor-corrector scheme . . . . . . . . . . . . . . . . . .
5.2.1 Limiting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2.2 Reconstruct-evolve-average . . . . . . . . . . . . . . . . . . . . . .
5.3 Method of lines approach . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4 Multi-dimensional advection . . . . . . . . . . . . . . . . . . . . . . . . .
5.4.1 Dimensionally split . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4.2 Unsplit multi-dimensional advection . . . . . . . . . . . . . . . .
5.4.3 Timestep limiter for multi-dimensions . . . . . . . . . . . . . . . .
5.4.4 Method-of-lines in multi-dimensions . . . . . . . . . . . . . . . .
5.5 High-Order Finite difference methods . . . . . . . . . . . . . . . . . . . .
5.5.1 The problem with higher-order finite volume methods . . . . . .
5.5.2 Finite differences . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.3 WENO reconstruction . . . . . . . . . . . . . . . . . . . . . . . . .
5.6 Going further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.7 pyro experimentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

49
49
50
53
57
60
62
64
66
67
70
71
72
72
73
78
80

6 Burgers’ Equation
6.1 Burgers’ equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2 Characteristic tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3 Going further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.4 WENO methods, nonlinear equations, and flux-splitting . . . . . . . . .

81
81
88
88
89

7 Euler Equations: Theory93
7.1 Euler equation properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.2 The Riemann problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.2.1 Rarefactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.2.2 Shocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
7.2.3 Finding the Star State . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.4 Complete Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.3 Other thermodynamic equations . . . . . . . . . . . . . . . . . . . . . . . 110vi8 Euler Equations: Numerical Methods
115
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
8.2 Reconstruction of interface states . . . . . . . . . . . . . . . . . . . . . . . 115
8.2.1 Piecewise constant . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.2.2 Piecewise linear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.2.3 Piecewise parabolic . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
8.2.4 Flattening and contact steepening . . . . . . . . . . . . . . . . . . 126
8.2.5 Limiting on characteristic variables . . . . . . . . . . . . . . . . . 127
8.3 Riemann solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
8.4 Conservative update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.4.1 Artificial viscosity . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.5 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.6 Multidimensional problems . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.6.1 3-d unsplit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
8.7 Source terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
8.8 Simple geometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
8.9 Some Test problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.9.1 Shock tubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.9.2 Sedov blast wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
8.9.3 Advection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
8.9.4 Slow moving shock . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8.9.5 Two-dimensional Riemann problems . . . . . . . . . . . . . . . . 148
8.10 Method of lines integration and higher order . . . . . . . . . . . . . . . . 149
8.11 Thermodynamic issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
8.11.1 Defining temperature . . . . . . . . . . . . . . . . . . . . . . . . . 151
8.11.2 General equation of state . . . . . . . . . . . . . . . . . . . . . . . 152
8.12 WENO methods for the Euler equations . . . . . . . . . . . . . . . . . . . 155
8.12.1 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

III

Elliptic and Parabolic Problems

161

9 Elliptic Equations and Multigrid
163
9.1 Elliptic equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.2 Fourier Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.3 Relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
9.3.1 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . 168
9.3.2 Residual and true error . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3.3 Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3.4 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
9.3.5 Frequency/wavelength-dependent error . . . . . . . . . . . . . . 173
9.4 Multigrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
9.4.1 Prolongation and restriction on cell-centered grids . . . . . . . . 176
vii

9.5
9.6

9.4.2 Multigrid cycles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
9.4.3 Bottom solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
9.4.4 Boundary conditions throughout the hierarchy . . . . . . . . . . 180
9.4.5 Stopping criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Solvability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Going Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
9.6.1 Red-black Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . 183
9.6.2 More General Elliptic Equations . . . . . . . . . . . . . . . . . . . 184

10 Diffusion
185
10.1 Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
10.2 Explicit differencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
10.3 Implicit with direct solve . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
10.4 Implicit multi-dimensional diffusion via multigrid . . . . . . . . . . . . . 194
10.4.1 Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
10.5 Non-constant Conductivity . . . . . . . . . . . . . . . . . . . . . . . . . . 196
10.6 Diffusion in Hydrodynamics . . . . . . . . . . . . . . . . . . . . . . . . . 199

IV

201

Multiphysics applications

11 Model Multiphysics Problems
203
11.1 Integrating Multiphysics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
11.2 Ex: diffusion-reaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
11.3 Ex: advection-diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
11.3.1 Convergence without an analytic solution . . . . . . . . . . . . . 208
12 Reactive Flow
209
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
12.2 Operator splitting approach . . . . . . . . . . . . . . . . . . . . . . . . . . 212
12.2.1 Adding species to hydrodynamics . . . . . . . . . . . . . . . . . . 213
12.2.2 Integrating the reaction network . . . . . . . . . . . . . . . . . . . 215
12.2.3 Incorporating explicit diffusion . . . . . . . . . . . . . . . . . . . . 215
12.3 Burning modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
12.3.1 Convective burning . . . . . . . . . . . . . . . . . . . . . . . . . . 215
12.3.2 Deflagrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
12.3.3 Detonations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
13 Planning a Simulation
217
13.1 How to setup a simulation? . . . . . . . . . . . . . . . . . . . . . . . . . . 217
13.2 Dimensionality and picking your resolution . . . . . . . . . . . . . . . . 217
13.3 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
13.4 Timestep considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
13.5 Convergence and multiphysics . . . . . . . . . . . . . . . . . . . . . . . . 220
viii

13.6 Computational cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
13.7 I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

V223

Low Speed Hydrodynamics

14 Incompressible Flow and Projection Methods
225
14.1 Incompressible flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
14.2 Projection methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
14.3 Cell-centered approximate projection solver . . . . . . . . . . . . . . . . 228
14.3.1 Advective velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
14.3.2 MAC projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
14.3.3 Reconstruct interface states . . . . . . . . . . . . . . . . . . . . . . 235
14.3.4 Provisional update . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
14.3.5 Approximate projection . . . . . . . . . . . . . . . . . . . . . . . . 236
14.4 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
14.5 Bootstrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
14.6 Test problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
14.6.1 Convergence test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
14.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
15 Low Mach Number Methods
243
15.1 Low Mach divergence constraints . . . . . . . . . . . . . . . . . . . . . . 243
15.2 Multigrid for Variable-Density Flows . . . . . . . . . . . . . . . . . . . . 245
15.2.1 Test problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
15.3 Atmospheric flows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
15.3.1 Equation Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
15.3.2 Solution Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
15.3.3 Timestep constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
15.3.4 Bootstrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
15.4 Combustion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
15.4.1 Species . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
15.4.2 Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
15.4.3 Solution Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . 252

VI

253

Code Descriptions

A Using hydro_examples
255
A.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
A.2 Getting hydro_examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
A.3 hydro_examples codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
B Using pyro

259
ix

B.1
B.2
B.3
B.4
B.5
B.6
B.7

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Getting pyro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
pyro solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
pyro’s structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Running pyro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Output and visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

C Using hydro1d265
C.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
C.2 Getting hydro1d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
C.3 hydro1d’s structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
C.4 Running hydro1d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
C.5 Problem setups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
267

ReferencesxList of Figures
1.1
1.2
1.3
1.4
1.5
1.6
1.7

The fluid scale. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Difference approximations to the derivative of sin( x ) . . . . . . . . . . .
Error in numerical derivatives . . . . . . . . . . . . . . . . . . . . . . . . .
Integration rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Convergence of Newton’s method for root finding . . . . . . . . . . . . .
The 4th -order Runge-Kutta method . . . . . . . . . . . . . . . . . . . . . .
Fourier transform of f ( x ) = sin(2πk0 x + π/4) . . . . . . . . . . . . . . .

3.1
3.2
3.3

Types of structured grids . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
A simple 1-d finite-volume grid with ghost cells . . . . . . . . . . . . . . 31
Domain decomposition example . . . . . . . . . . . . . . . . . . . . . . . 32

4.1
4.2
4.3
4.4
4.5
4.6

Characteristics for linear advection . . . . . . . . . . . . . . . . . . . . . .
A simple finite-difference grid . . . . . . . . . . . . . . . . . . . . . . . .
First-order finite-difference solution to linear advection . . . . . . . . . .
FTCS finite-difference solution to linear advection . . . . . . . . . . . . .
Domain of dependence space-time diagram . . . . . . . . . . . . . . . .
First-order implicit finite-difference solution to linear advection . . . . .

38
39
41
41
44
46

5.1 A finite-volume grid with valid cells labeled . . . . . . . . . . . . . . . .
5.2 The input state to the Riemann problem . . . . . . . . . . . . . . . . . . .
5.3 Reconstruction at the domain boundary . . . . . . . . . . . . . . . . . . .
5.4 Second-order finite-volume advection . . . . . . . . . . . . . . . . . . . .
5.5 The effect of no limiting on initially discontinuous data . . . . . . . . . .
5.6 The effect of limiters on initially discontinuous data . . . . . . . . . . . .
5.7 Piecewise linear slopes with an without limiting . . . . . . . . . . . . . .
5.8 The Reconstruct-Evolve-Average procedure . . . . . . . . . . . . . . . . .
5.9 Convergence of second-order finite-volume advection . . . . . . . . . . .
5.10 Effect of different limiters on evolution . . . . . . . . . . . . . . . . . . .
5.11 Method-of-lines spatial reconstruction . . . . . . . . . . . . . . . . . . . .
5.12 A 2-d grid with zone-centered indexes . . . . . . . . . . . . . . . . . . . .
5.13 The construction of an interface state with the transverse component . .
5.14 Advection of Gaussian profile in 2-d . . . . . . . . . . . . . . . . . . . . .
5.15 Advection of tophat profile in 2-d . . . . . . . . . . . . . . . . . . . . . .
5.16 Advection of tophat function with method-of-lines integration . . . . .

50
51
52
53
55
56
57
59
60
61
62
63
68
69
69
72

xi

4
8
9
11
12
16
20

5.17 Convergence rate of high-order reconstructions . . . . . . . . . . . . . .
5.18 WENO reconstruction and weights . . . . . . . . . . . . . . . . . . . . . .
5.19 High order WENO convergence rates for linear advection . . . . . . . .
5.20 Very high order WENO convergence rates for linear advection . . . . .

74
76
78
79

6.1
6.2
6.3
6.4
6.5
6.6
6.7

Characteristics for shock initial conditions . . . . . . . . . . . . . . . . .
Characteristics for rarefaction initial conditions . . . . . . . . . . . . . .
Rankine-Hugoniot conditions . . . . . . . . . . . . . . . . . . . . . . . . .
Rarefaction solution to the inviscid Burgers’ equation . . . . . . . . . . .
Shock solutions to the inviscid Burgers’ equation . . . . . . . . . . . . .
Comparing PLM and WENO methods for Burgers’ equation . . . . . . .
WENO convergence rates for Burgers’ equation . . . . . . . . . . . . . .

82
83
84
86
87
90
91

7.1
7.2
7.3
7.4
7.5

The Sod problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The Riemann problem wave structure for the Euler equations . . . . . . 101
The Hugoniot curves corresponding to the Sod problem . . . . . . . . . 109
Wave configuration for the Riemann problem . . . . . . . . . . . . . . . . 110
Rarefaction configuration for the Riemann problem . . . . . . . . . . . . 111

The left and right states for the Riemann problem . . . . . . . . . . . . . 116
Piecewise linear reconstruction of cell average data . . . . . . . . . . . . 118
The two interface states derived from a cell-center quantity . . . . . . . 122
Piecewise parabolic reconstruction of the cell averages . . . . . . . . . . 122
Integration under the parabola profile for to an interface . . . . . . . . . 123
Riemann wave structure at each interface . . . . . . . . . . . . . . . . . . 128
The approximate (2-shock) Hugoniot curves corresponding to the Sod
problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.8 The axisymmetric computational domain . . . . . . . . . . . . . . . . . . 138
8.9 Piecewise constant reconstruction Sod problem . . . . . . . . . . . . . . 140
8.10 Piecewise parabolic reconstruction Sod problem . . . . . . . . . . . . . . 141
8.11 Piecewise constant reconstruction double rarefaction problem . . . . . . 142
8.12 Piecewise constant reconstruction double rarefaction problem . . . . . . 143
8.13 1-d spherical Sedov problem . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.14 2-d cylindrical Sedov problem . . . . . . . . . . . . . . . . . . . . . . . . 145
8.15 2-d cylindrical Sedov problem . . . . . . . . . . . . . . . . . . . . . . . . 146
8.16 Simple advection test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8.17 1-d spherical Sedov problem . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.18 Two-dimensional Riemann problem from [69]. . . . . . . . . . . . . . . . 150
8.19 WENO r = 3 for the Sod test . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.20 WENO r = 5 for the Sod test . . . . . . . . . . . . . . . . . . . . . . . . . 158
8.21 WENO r = 3 for the double rarefaction test . . . . . . . . . . . . . . . . . 159
8.1
8.2
8.3
8.4
8.5
8.6
8.7

9.1
9.2

Data centerings for the discrete Laplacian . . . . . . . . . . . . . . . . . . 164
FFT solution to the Poisson equation . . . . . . . . . . . . . . . . . . . . . 167
xii

Node-centered vs. cell-centered data at boundaries . . . . . . . . . . . . 169
Convergence as a function of number of iterations using Gauss-Seidel
relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
9.5 Convergence of smoothing in different norms . . . . . . . . . . . . . . . 173
9.6 Convergence of smoothing in first-order BCs . . . . . . . . . . . . . . . . 174
9.7 Smoothing of different wavenumbers . . . . . . . . . . . . . . . . . . . . 175
9.8 The geometry for 1-d prolongation and restriction . . . . . . . . . . . . . 176
9.9 The geometry for 2-d prolongation and restriction . . . . . . . . . . . . . 178
9.10 A multigrid hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
9.11 Error in solution as a function of multigrid V-cycle number . . . . . . . 182
9.12 Convergence of the multigrid algorithm . . . . . . . . . . . . . . . . . . . 183
9.13 Red-black ordering of zones . . . . . . . . . . . . . . . . . . . . . . . . . . 184
9.3
9.4

10.1 Explicit diffusion of a Gaussian . . . . . . . . . . . . . . . . . . . . . . . . 188
10.2 Underresolved explicit diffusion of a Gaussian . . . . . . . . . . . . . . . 189
10.3 Unstable explicit diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
10.4 Error convergence of explicit diffusion . . . . . . . . . . . . . . . . . . . . 191
10.5 Implicit diffusion of a Gaussian . . . . . . . . . . . . . . . . . . . . . . . . 193
10.6 2-d diffusion of a Gaussian . . . . . . . . . . . . . . . . . . . . . . . . . . 195
10.7 Comparison of 2-d implicit diffusion with analytic solution . . . . . . . 196
10.8 Under-resolved Crank-Nicolson diffusion . . . . . . . . . . . . . . . . . . 197
10.9 Convergence of diffusion methods . . . . . . . . . . . . . . . . . . . . . . 198
11.1 Solution to the diffusion-reaction equation . . . . . . . . . . . . . . . . . 205
11.2 Viscous Burgers’ equation solution . . . . . . . . . . . . . . . . . . . . . . 207
11.3 Convergence of the viscous Burgers’ equation . . . . . . . . . . . . . . . 208
14.1 Example of a projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
14.2 MAC grid for velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
14.3 MAC grid data centerings . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
15.1 Solution and error of a variable-coefficient Poisson problem . . . . . . . 247
15.2 Convergence of the variable-coefficient Poisson solver . . . . . . . . . . . 248

xiii

List of Exercises
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9

Floating point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Machine epsilon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Convergence and order-of-accuracy . . . . . . . . . . . . . . . . . . . . .
Truncation error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Second derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Simpson’s rule for integration . . . . . . . . . . . . . . . . . . . . . . . . .
Newton’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ODE accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FFTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.1
2.2

Wave equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Diffusion timescale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.1
3.2

Finite-volume vs. finite-difference centering . . . . . . . . . . . . . . . . 27
Conservative interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.1
4.2
4.3
4.4
4.5
4.6
4.7

Linear advection analytic solution . . . . . . . . . . . . . . . . . . . . . .
Perfect advection with a Courant number of 1 . . . . . . . . . . . . . . .
A 1-d finite-difference solver for linear advection . . . . . . . . . . . . .
FTCS and stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Stability of the upwind method . . . . . . . . . . . . . . . . . . . . . . . .
Stability analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Implicit advection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37
40
40
41
42
43
45

5.1 A second-order finite-volume solver for linear advection . . . . . . . . .
5.2 Limiting and overshoots . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3 Limiting and reduction in order-of-accuracy . . . . . . . . . . . . . . . .
5.4 Convergence testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5 ENO stencils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.6 WENO weights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.7 WENO reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.8 Role of limiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.9 Grid effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.10 Split vs. unsplit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52
54
56
58
73
75
77
80
80
80

xiv

5
5
6
7
8
10
13
15
19

6.1
6.2
6.3

Burgers’ characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Simple Burgers’ solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Conservative form of Burgers’ equation . . . . . . . . . . . . . . . . . . . 88

7.1
7.2
7.4
7.5
7.6
7.7

Primitive variable form of the Euler equations . . . . . . . . . . . . . . . 95
The eigenvalues of the Euler system . . . . . . . . . . . . . . . . . . . . . 96
Characteristic form of the Euler equations . . . . . . . . . . . . . . . . . 97
Riemann invariants for gamma-law gas . . . . . . . . . . . . . . . . . . . 103
Shock jump conditions for γ-law EOS . . . . . . . . . . . . . . . . . . . . 106
Hugoniot curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

8.1
8.2
8.3
8.4
8.5

Characteristic projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
The average state reacting the interface . . . . . . . . . . . . . . . . . . . 123
Conservative interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Eigenvectors for the 2-d Euler equations . . . . . . . . . . . . . . . . . . 133
Spherical form of primitive variable equations . . . . . . . . . . . . . . . 137

9.1

Smoothing the 1-d Laplace equation . . . . . . . . . . . . . . . . . . . . . 174

10.1 Explicit diffusion stability condition . . . . . . . . . . . . . . . . . . . . . 186
10.2 1-d explicit diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
10.3 1-d implicit diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
10.4 Implicit multi-dimensional diffusion . . . . . . . . . . . . . . . . . . . . . 195
11.1 Diffusion-reaction system . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
12.1 Species advection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
14.1 An approximate projection . . . . . . . . . . . . . . . . . . . . . . . . . . 228

xv

prefaceThis text started as a set of notes to help new students at Stony Brook University
working on projects in computational astrophysics. They focus on the common methods used in computational hydrodynamics for astrophysical flows and are written at
a level appropriate for upper-level undergraduates. Problems integrated in the text
help demonstrate the core ideas. An underlying principle is that source code is provided for all the methods described here (including all the figures). This allows thereader to explore the routines themselves.
These notes are very much a work in progress, and new chapters will be added withtime. The page size is formatted for easy reading on a tablet or for 2-up printing ina landscape orientation on letter-sized paper.
This text is part of the Open Astrophysics Bookshelf. Contributions to these notes
are welcomed. The LATEX source for these notes is available online on github at:https://github.com/Open-Astrophysics-Bookshelf/numerical_exercises
Simply fork the notes, hack away, and submit a pull-request to add your contributions. All contributions will be acknowledged in the text.
A PDF version of the notes is always available at:https://open-astrophysics-bookshelf.github.io/numerical_exercises/CompHydroTutorial.
pdf
These notes are updated at irregular intervals, usually when I have a new student
working with me, or if I am using them for a course.
The source (usually python) for all the figures is also contained in the main git repo.
The line drawings of the grids are done using the classes in grid_plot.py. This needs
to be in your PYTHONPATH if you wish to run the scripts.
The best way to understand the methods described here is to run them for yourself.
There are several sets of example codes that go along with these notes:
1. hydro_examples is a set of simple 1-d, standalone python scripts that illustratexvii

some of the basic solvers. Many of the figures in these notes were created using
these codes—the relevant script will be noted in the figure caption.
You can get this set of scripts from github at:https://github.com/zingale/hydro_examples/
References to the scripts in hydro_examples are shown throughout the text as:Ï hydro_examples: scriptname
Clicking on the name of the script will bring up the source code to the script(on github) in your web browser.
More details on the codes available in hydro_examples are described in Appendix A.
2. The pyro code [86] is a 2-d simulation code with solvers for advection, diffusion,
compressible and incompressible hydrodynamics, as well as multigrid. A grayflux-limited diffusion radiation hydrodynamics solver is in development. pyro
is designed with clarity in mind and to make experimentation easy.
You can download pyro at:https://github.com/python-hydro/pyro2/
A brief overview of pyro is given in Appendix B, and more information can befound at:http://python-hydro.github.io/pyro2/
3. hydro1d is a simple one-dimensional compressible hydrodynamics code that
implements the piecewise parabolic method from Chapter 8. It can be obtained
from github at:https://github.com/zingale/hydro1d/
Details on it are given in Appendix C.
Wherever possible we try to use standardized notation for physical quantities, as
listed in Table 1.
These notes benefited immensely from numerous conversations and an ongoing collaboration with Ann Almgren, John Bell, Andy Nonaka, & Weiqun Zhang—prettymuch everything I know about projection methods comes from working with them.
Discussions with Alan Calder, Sean Couch, Max Katz, Chris Malone, and Doug
Swesty have also been influential in the presentation of these notes.
If you find errors, please e-mail me at michael.zingale@stonybrook.edu, or issue apull request to the git repo noted above.
Michael Zingale
Stony Brook University

xviii

Table 1: Definition of symbols.

symbolA

meaning

units

Jacobian matrix

N/Apg m−2 s−1

Γ1 pρ

C

Lagrangian sound speed, C =C

CFL numbercsound speed, c =cpspecific heat at constant pressure (c p∂h/∂T | p,Xk )≡erg g−1 K−1

cv

specific heat∂e/∂T |ρ,Xk )≡erg g−1 K−1

E

specific total energy

erg g−1especific internal energy

erg g−1F

flux vector

N/Aggravitational acceleration

cm s−2

Γ1

first adiabatic exponent (Γ1 ≡ d log p/d log ρ|s )–γ

ratio of specific heats, γ = c p /cv–γe

the quantity p/(ρe) + 1–

Hheat sources

erg g−1 s−1

Hnucnuclear energy source

erg g−1 s−1hspecific enthalpy

erg g−1Iintegral under a (piecewise) parabolic polynomial reconstruction

N/A

kth

thermal conductivity

erg cm−1 s−1 K− 1

Lmatrix of left eigenvectors–

Λ

diagonal matrix of eigenvalue–lleft eigenvector

N/Aλeigenvalue

N/A

M

Mach number, M = |U|/c

–

p

at

–
m s−1

Γ1 p/ρ

constant

density(cv

continued on next pagexix

Table 1—continued
symbolmeaning

units

ω̇k

species creation rates−1ppressureerg cm−3qprimitive variable vector

N/AR

matrix of right eigenvectors–

R(q L , q R )Riemann problem between states q L and q R

N/Arright eigenvector

N/Aρmass densityg cm−3S

source term to the divergence constraints−1sspecific entropy

erg g−1 K−1Ttemperature

K

t

time

s

τ

specific volume (τ = 1/ρ)

cm3 g−1Utotal velocity vector, U = (u, v)⊺ in 2-d

cm s−1U

conserved variable vector

N/Au

x-velocity

cm s−1v

y-velocity

cm s−1w

characteristic variables vector

N/A

Xk

mass fraction of the species (∑k Xk = 1)–xxAuthorship
Primary Author
Michael Zingale (Stony Brook)

Contributions
Thank you to the following people for pointing out typos or confusing remarks inthe text:• Chen-Hung• Rixin Li (Arizona)• Zhi Li (Shanghai Astronomical Observatory)• Chris Malone• Sai Praneeth (Waterloo)• Donald Willcox (Stony Brook)
Material on WENO schemes was contributed by Ian Hawke (Southampton).
See the git log for full details on contributions. All contributions via pull-requests
will be acknowledged here.

xxi

Part I

BasicsChapter1

Simulation Overview
1.1

What is simulation?

Astronomy is an observational science. Unlike in terrestrial physics, we do not havethe luxury of being able to build a model system and do physical experimentation on
it to understand the core physics. We have to take what nature gives us. Simulation
enables us to build a model of a system and allows us to do virtual experiments tounderstand how this system reacts to a range of conditions and assumptions.
It’s tempting to think that one can download a simulation code, set a few parameters, maybe edit some initial conditions, run, and then have a virtual realization ofsome astrophysical system that you are interested in. Just like that. In practice, it is
not this simple. All simulation codes make approximations—these start even before
one turns to the computer, simply by making a choice of what equations are to besolved. The main approximation that we will follow here, is the fluid approximation(see Figure 1.1). We don’t want to focus on the motions of the individual atoms, nuclei, electrons, and photons in our system, so we work on a scale that is much larger
than the mean free path of the system. This allows us to describe the bulk propertiesof a fluid element, which in turn is small compared to the system of interest.
Within the fluid approximation, additional approximations are made, both in termsof the physics included and how we represent a continuous fluid in the finite-memoryof a computer (the discretization process).
Typically, we have a system of PDEs, and we need to convert the continuous functional form of our system into a discrete form that can be represented in the finite
memory of a computer. This introduces yet more approximation.
Blindly trusting the numbers that come out of the code is a recipe for disaster. You
don’t stop being a physicist the moment you execute the code—your job as a comgit version: 64c838dee1a8 . . .

3

Chapter 1. Simulation Overview

4

fluid elementstaratomic scale(mean free path)

Figure 1.1: The fluid scale sits in an intermediate range—much smaller than the system
of interest (a star in this case), but much larger than the mean free path.

putational scientist is to make sure that the code is producing reasonable results, by
testing it against known problems and your physical intuition.
Simulations should be used to gain insight and provide a physical understanding.
Because the systems we solve are so nonlinear, small changes in the code or the programming environment (compilers, optimization, etc.) can produce large differencesin the numbers coming out of the code. That’s not a reason to panic. As such it
is best not to obsess about precise numbers, but rather the trends our simulations
reveal. To really understand the limits of your simulations, you should do parameterand convergence studies.
There is no “über-code”. Every algorithm begins with approximations and has limitations. Comparisons between different codes are important and common in ourfield (see, for example, [30, 31, 33]), and build confidence in the results that we areon the right track.
To really understand your simulations, you need to know what the code your areusing is doing under the hood. This means understanding the core methods usedin our field. These notes are designed to provide a basic tour of some of the more
popular methods, referring to the key papers for full derivations and details. The best

1.2—Numerical basics

5

way to learn is to code up these methods for yourself. A companion python code,pyro is available to help, and most of the exercises (or corresponding figures) havelinks to simple codes that are part of the hydro_examples repository* . Descriptions
and links to these codes are found in the appendices.

1.2

Numerical basics

We assume a familiarity with basic numerical methods, which we summarize below.
Any book on numerical methods can provide a deeper discussion of these methods.
Some good choices are the texts by Garcia [35], Newman [56], and Pang [60].

1.2.1

Sources of error

With any algorithm, there are two sources of error we are concerned with: roundoff
error and truncation error.
Roundoff arises from the error inherent in representing a floating point number witha finite number of bits in the computer memory. An excellent introduction to thedetails of how computers represent numbers is provided in [38].
Exercise 1.1
In your choice of programming language, create a floating point variable
and initialize it to 0.1. Now, print it out in full precision (you may need
to use format specifiers in your language to get all significant digits thecomputer tracks).
You should see that it is not exactly 0.1 to the computer—this is thefloating point error. The number 0.1 is not exactly representable in thebinary format used for floating point.

Exercise 1.2
To see roundoff error in action, write a program to find the value of ϵ for
which 1 + ϵ = 1. Start with ϵ = 1 and iterate, halving ϵ each iteration
until 1 + ϵ = 1. This last value of ϵ for which this was not true is themachine epsilon. You will get a different value for single- vs. doubleprecision floating point arithmetic.
Some reorganization of algorithms can help minimize roundoff, e.g. avoiding the* look for theÏ symbol.

Chapter 1. Simulation Overview

6subtraction of two very large numbers by factoring as:x3 − y3 = ( x − y)( x2 + xy + y2 ) ,(1.1)

but roundoff error will always be present at some level.
Truncation error is a feature of an algorithm—we typically approximate an operator or function by expanding about some small quantity. When we throw away
higher-order terms, we are truncating our expression, and introducing an error in
the representation. If the quantity we expand about truly is small, then the error issmall. A simple example is to consider the Taylor series representation of sin( x ):∞sin( x ) = ∑ (−1)n−1
n =1

x2n−1
(2n − 1)!

(1.2)

x3
6

(1.3)

For | x | ≪ 1, we can approximate this as:sin( x ) ≈ x −in this case, our truncation error has the leading term ∝ x5 , and we say that ourapproximation is O( x5 ), or 5th -order accurate.
Exercise 1.3
We will be concerned with the order-of-accuracy of our methods, and agood way to test whether our method is behaving properly is to perform
a convergence test. Consider our 5th -order accurate approximation tosin( x ) above. Pick a range of x’s (< 1), and compute the error in our
approximation asϵ ≡ sin( x ) − [ x − x3 /6]
and show that as you cut x in half, |ϵ| reduces by 25 —demonstrating
5th -order accuracy.
This demonstration of measuring the error as we vary the size of our small parameteris an example of a convergence test.

1.2.2

Differentiation and integration

For both differentiation and integration, there are two cases we might encounter:
1. We have function values, f 0 , f 1 , . . ., at a discrete number of points, x0 , x1 , . . .,and we want to compute the derivative at a point or integration over a range ofpoints.
2. We know a function analytically and we want to construct a derivative or integral of this function numerically.

1.2—Numerical basics

7

In these notes, we will mainly be concerned with the first case.
Differentiation of discretely-sampled function
Consider a collection of equally spaced points, labeled with an index i, with thephysical spacing between them denoted ∆x. We can express the first derivative of aquantity a at i as:∂aa − a i −1
≈ i
(1.4)
∂x i
∆x
or

a − ai∂a≈ i +1
∂x i
∆x

(1.5)

(Indeed, as ∆x → 0, this is the definition of a derivative we learned in calculus.) Bothof these are one-sided differences. By Taylor expanding the data about xi , we see
ai+1 = ai + ∆x

∂a
1
∂2 a
+ ∆x2 2 + . . .
∂x i 2∂x i(1.6)

Solving for ∂a/∂x |i , we see∂aa − a i −1 1
∂2 a= i
− ∆x 2 + . . .
∂x i
∆x
2
∂x i
a − a i −1
+ O(∆x )
= i
∆x

(1.7)
(1.8)

where O(∆x ) indicates that the leading term in the error for this approximation is∼ ∆x† . We say that this is first order accurate. This means that we are neglecting terms
that scale as ∆x or to higher powers. This is fine if ∆x is small. This error is our truncation error—just as discussed above, it arises because our numerical approximation
throws away higher order terms. The approximation ∂a/∂x |i = ( ai+1 − ai )/∆x has
the same order of accuracy.
Exercise 1.4
Show that a centered difference,∂aa − a i −1
= i +1∂x i
2∆xis second order accurate, i.e. its truncation error is O(∆x2 ).
Figure 1.2 shows the left- and right-sided first-order differences and the central difference as approximations to sin( x ). Generally speaking, higher-order methods have† in some texts, you see this O( ∆x n ) referred to as “big O notation”

Chapter 1. Simulation Overview

8

exact
left-sided
right-sided
centered

1.0
0.8
0.6
0.4
0.2
∆x

0.0
0.0

0.5

1.0

1.5

2.0

2.5

3.0

Figure 1.2: A comparison of one-sided and centered difference approximations to thederivative of sin( x ).
hydro_examples: derivatives.pyÏlower numerical error associated with them, and also involve a wider range of data
points.
Second- and higher-order derivatives can be constructed in the same fashion.
Exercise 1.5
Using the Taylor expansions for ai+1 and ai−1 , find a difference approximation to the second derivative at i.

Differentiation of an analytic function
An alternate scenario is when you know the analytic form of the function, f ( x ), andare free to choose the points where you evaluate it. Here you can pick a δx andevaluate the derivative as
df
f ( x0 + δx ) − f ( x0 )=dx x= x0
δx

(1.9)

An optimal value for δx requires a balance of truncation error (which wants a smallδx) and roundoff error (which becomes large when δx is close to machine ϵ). Figure 1.3 shows the error for the numerical derivative of f ( x ) = sin( x ) at the pointx0 = 1, as a function of δx. A nice discussion of this is given in [85]. A good rule-1.2—Numerical basics

9

error in difference approximation

10 0

10 −2

10 −4

10 −6

10 −8

10 −10
10 −1510 −1310 −11

10 −9

δx

10 −7

10 −5

10 −3

10 −1

Figure 1.3: Error in the numerical approximation of the derivative of f ( x ) = sin( x ) at
x0 = 1 as a function of the spacing δx. For small δx, roundoff error dominates the error
in the approximation. For large δx, truncation error dominates.
hydro_examples: deriv_error.pyÏof-thumb is to pick δx ≈truncation error.

√ϵ, where ϵ is machine epsilon, to balance roundoff andComparing the result with different choices of δx allows for error estimation and an
improvement of the result by combining the estimates using δx and δx/2 (this is thebasis for a method called Richardson extrapolation).
Integration
In numerical analysis, any integration method that is composed as a weighted sumof the function evaluated at discrete points is called a quadrature rule.
If we have a function sampled at a number of equally-spaced points, x0 ≡ a, x1 , . . . , x N ≡b‡ , we can construct a discrete approximation to an integral as:
I≡

Z b
a

N −1

f ( x )dx ≈ ∆x ∑ f ( xi )(1.10)

i =0

where ∆x ≡ (b − a)/N is the width of the intervals (see the top-left panel in Figure 1.4). This is a very crude method, but in the limit that ∆x → 0 (or N → ∞), thiswill converge to the true integral. This method is called the rectangle rule. Note that
‡ Note that this is N intervals and N + 1 points

Chapter 1. Simulation Overview

10

here we expressing the integral over the N intervals using a simple quadrature rulein each interval. Summing together the results of the integral over each interval to
get the result in our domain is called compound integration.
We can get a more accurate answer for I by interpolating between the points. The
simplest case is to connect the sampled function values, f ( x0 ), f ( x1 ), . . . , f ( x N ) witha line, creating a trapezoid in each interval, and then simply add up the area of all of
the trapezoids:
I≡

Z b
a

N −1

f ( x i ) + f ( x i +1 )2i =0f ( x )dx ≈ ∆x ∑(1.11)

This is called the trapezoid rule (see the top-right panel in Figure 1.4). Note here weassume that the points are equally spaced.
One can keep going, but practically speaking, a quadratic interpolation is as high as
one usually encounters. Fitting a quadratic polynomial requires three points.
Exercise 1.6
Consider a function, f ( x ), sampled at three equally-spaced points, α, β, γ,with corresponding function values f α , f β , f γ . Derive the expression for
Simpson’s rule by fitting a quadratic fˆ( x ) = A( x − α)2 + B( x − α) + C
to the three points (this gives you A, B, and C), and then analyticallyintegrating fˆ( x ) in the interval [α, γ]. You should findI=

γ−α
( fα + 4 f β + fγ )6(1.12)

Note that (γ − α)/6 = ∆x/3
For a number of samples, N, in [ a, b], we will consider every two intervals together.
The resulting expression is:
I≡

Z b
a

∆x
f ( x )dx ≈3( N −2)/2∑[ f ( x2i ) + 4 f ( x2i+1 ) + f ( x2i+2 )](1.13)i =0= f ( x 0 ) + 4 f ( x 1 ) + 2 f ( x 2 ) + 4 f ( x 3 ) + 2 f ( x 4 ) + . . . + 2 f ( x N −2 ) + 4 f ( x N −1 ) + f ( x N )This method is called Simpson’s rule. Note that for 2 intervals / 3 sample points(N = 2), we only have 1 term in the sum, ( N − 2)/2 = 0, and we get the result
derived in Exercise 1.6.
Figure 1.4 shows these different approximations for the case of two intervals (threepoints).
Analogous expressions exist for the case of unequally-spaced points.

1.2—Numerical basics

11

y

y

a

b

x

a

b

x

y

a

b

x

Figure 1.4: The rectangle rule (topleft), trapezoid rule (top right)
and Simpson’s rule (left) for integration.

The compound trapezoid rule converges as second-order over the interval [ a, b], while
Simpson’s rule converges as fourth-order.
As with differentiation, if you are free to pick the points where you evaluate f ( x ), you
can get a much higher-order accurate result. Gaussian quadrature is a very powerful
technique that uses the zeros of different polynomials as the evaluation points forthe function to give extremely accurate results. See the text by Garcia [35] for a niceintroduction to these methods.

1.2.3

Root finding

Often we want to find the root of a function (or the vector that zeros a vector offunctions). The most popular method for root finding is the Newton-Raphson method.
We want to find x, such that f ( x ) = 0. Start with an initial guess x0 that you believe
is close to the root, then you can improve the guess to the root by an amount δx bylooking at the Taylor expansion about x0 :f ( x0 + δx ) ∼ f ( x0 ) + f ′ ( x0 )δx + . . . = 0(1.14)

Chapter 1. Simulation Overview

12
15

0.4
0.2
0.0
0.2
0.4
2.8

10

15
0
2.9

3.0

3.1

0.4
0.2
0.0
0.2
0.4
2.8

10

3.2

5

2.9

3.0

3.1

3.2

5
1

0

0

1

2

3

4

5

5

0

1

2

3

4

5

5

10

10

root approx = 5.0

15

0.4
0.2
0.0
0.2
0.4
2.8

10

root approx = 3.5

15

0.4
0.2
0.0
0.2
0.4
2.8

2

10
2.9

3.0

3.1

3.2

5

0

0

3

2.9

3.0

3.1

3.2

5

0

1

2

32

5

4

5

0

0

1

2

3
3

4

5

5

10

root approx = 3.05

10root approx = 3.000609756097561

Figure 1.5: The convergence of Newton’s method for finding the root. In each pane,
the red point is the current guess for the root. The solid gray line is the extrapolationof the slope at the guess to the x-axis, which defines the next approximation to theroot. The vertical dotted line to the function shows the new slope that will be used forextrapolation in the next iteration.
hydro_examples: roots_plot.py

ÏKeeping only to O(δx ), we can solve for the correction, δx:f ( x0 )δx = − ′f ( x0 )(1.15)

This can be used to correct out guess as x0 ← x0 + δx, and we can iterate on thisprocedure until δx falls below some tolerance. Figure 1.5 illustrates this iteration.
The main “got-ya” with this technique is that you need a good initial guess. In the1.2—Numerical basics

13

Taylor expansion, we threw away the δx2 term, but if our guess was far from the root,
this (and higher-orders) term may not be small. Obviously, the derivative must be
non-zero in the region around the root that you search as well.
Exercise 1.7
Code up Newton’s method for finding the root of a function f ( x ) and test
it on several different test functions.
The secant method for root finding is essentially Newton-Raphson, but instead of using
an analytic derivative, f ′ is estimated as a numerical difference.
Newton’s method has pathologies—it is possible to get into a cycle where you don’t
converge but simply pass through the same set of root approximations. Many otherroot finding methods exist, including bisection, which iteratively halves an interval
known to contain a root by looking for the change in sign of the function f ( x ).
Brent’s method combines several different methods to produce a robust procedure forroot-finding. Most numerical analysis texts will give a description of these.

1.2.4

Norms

Often we will need to measure the “size” of an error to a discrete approximation.
For example, imagine that we know the exact function, f ( x ) and we have have anapproximation, f i defined at N points, i = 0, . . . , N − 1. The error at each point i
is ϵi = | f i − f ( xi )|. But this is N separate errors—we want a single number that
represents the error of our approximation. This is the job of a vector norm.
There are many different norms we can define. For a vector q, we write the norm as∥q∥. Often, we’ll put a subscript after the norm brackets to indicate which norm wasused. Some popular norms are:• inf norm:∥q∥∞ = max |qi |(1.16)

1 N −1| qi |
N i∑=0(1.17)i• L1 norm:∥ q ∥1 =• L2 norm:∥ q ∥2 ="1 N −1| q i |2
N i∑
=0

#1/2

(1.18)

Chapter 1. Simulation Overview

14• general p-norm∥q∥ p ="

1 N −1| qi | p
N i∑
=0

#1/p

(1.19)

Note that these norms are defined such that they are normalized—if you double
the number of elements (N), the normalization gives you a number that can still bemeaningfully compared to the smaller set. For this reason, we will use these norms
when we look at the convergence with resolution of our numerical methods.
We’ll look into how the choice of norm influences you convergence criterion, butinspection shows that the inf-norm is local—a element in your vector is given theentire weight, whereas the other norms are more global.

1.2.5

ODEs

Consider a system of first-order ordinary differential equations,ẏ = f(t, y(t))(1.20)

If k represents an index into the vector y, then the kth ODE isẏk = f k (t, y(t))(1.21)

We want to solve for the vector y as a function of time. Note higher-order ODEs canalways be written as a system of first-order ODEs by introducing new variables§ .
Broadly speaking, methods for integrating ODEs can be broken down into explicit
and implicit methods. Explicit methods difference the system to form an update thatuses only the current (and perhaps previous) values of the dependent variables in
evaluating f . For example, a first-order explicit update (Euler’s method) appears as:
ynk +1 = ynk + ∆t f k (tn , yn )(1.22)

where ∆t is the stepsize. Implicit methods instead evaluate the righthand side, fusing the new-time value of y we are solving for.
Perhaps the most popular explicit method for ODEs is the 4th-order Runge-Kutta
method (RK4). This is a multistage method where several extrapolations to the midpoint and endpoint of the interval are made to estimate slopes and then a weighted
average of these slopes are used to advance the solution. The various slopes areillustrated in Figure 1.6 and the overall procedure looks like:ynk +1 = ynk +∆t(k1 + 2k2 + 2k3 + k4 )6

§ As an example, consider Newton’s second law, ẍ = F/m.

ODEs by introducing the velocity, v, giving us: v̇ = F/m, ẋ = v.

(1.23)

We can write this as a system of two

1.2—Numerical basics

15

where the slopes are:k1 = f (tn , ynk )(1.24)n∆t
k2 = f (t + ∆t
2 , yk + 2 k1 )n∆t
k3 = f (tn + ∆t
2 , yk + 2 k2 )k4 = f (tn + ∆t, ynk + ∆tk3 )n(1.25)(1.26)(1.27)

Note the similarity to Simpson’s method for integration. This is fourth-order accurate
overall.
Exercise 1.8
Consider the orbit of Earth around the Sun. If we work in the units ofastronomical units, years, and solar masses, then Newton’s gravitational
constant and the solar mass together are simply GM = 4π 2 (this shouldlook familiar as Kepler’s third law). We can write the ODE system describing the motion of Earth as:ẋ = v(1.28)

GMrv̇ = − 3r(1.29)

If we take the coordinate system such that the Sun is at the origin, then,x = ( x, y)⊺ is the position of the Earth and r = x x̂ + yŷ is the radius
vector pointing from the Sun to the Earth.
Take as initial conditions the planet at perihelion:x0 = 0y0 = a (1 − e )r
GM 1 + e(v · x̂)0 = −a 1−e(v · ŷ)0 = 0
where a is the semi-major axis and e is the eccentricity of the orbit (these
expressions can be found in any introductory astronomy text that discusses Kepler’s laws).
Integrate this system for a single orbital period with the first-order Eulerand the RK4 method and measure the convergence by integrating at anumber of different ∆t’s. Note: you’ll need to define some measure oferror, you can consider a number of different metrics, e.g., the change inradius after a single orbit.
The choice of the stepsize, ∆t, in the method greatly affects the accuracy. In practice
you want to balance the desire for accuracy with the expense of taking lots of small

Chapter 1. Simulation Overview

16

analytic solution
slope

n
k y

analytic solution
slope
half-dt k1 step

n
k y

1

1

k2

tn

tn

tn+1
analytic solution
slope
half-dt k1 step
half-dt k2 step

n
k y
1

tn+1
analytic solution
slope
half-dt k1 step
half-dt k2 step
full-dt k3 step

n
k y
1

k3

k3

k2

k2
k4

tn

tn

tn+1
k1

yn
k3

tn+1

analytic solution
slope
half-dt k1 step
half-dt k2 step
full-dt k3 step
full 4th-order RK stepk2

yn + 1
k4

tn

tn+1

Figure 1.6: A graphical illustration of the four steps in the 4th -order Runge-Kutta
method. This example is integrating dy/dt = −y.

1.2—Numerical basics

17

steps. A powerful technique for doing this is to use error estimation and an adaptive
stepsize with your ODE integrator. This monitors the size of the truncation error andadjusts the stepsize, as needed, to achieve a desired accuracy. A nice introduction to
how this works for RK4 is given in [35].
Implicit methods
Implicit methods difference the system in a way that includes the new value of thedependent variables in the evaluation of f k (t, y(t))—the resulting implicit system isusually solved using, for example, Newton-Raphson iteration.
A first-order implicit update (called backward Euler) is:
yn+1 = yn + ∆tf(tn+1 , yn+1 )(1.30)

This is more complicated to solve than the explicit methods above, and generally will
require some linear algebra. If we take ∆t to be small, then the change in the solution,∆y will be small as well, and we can Taylor-expand the system.
To solve this, we pick a guess, y0n+1 , that we think is close, to the solution and we willsolve for a correction, ∆y0 such thatyn+1 = y0n+1 + ∆y0(1.31)

Using this approximation, we can expand the righthand side vector,f(tn+1 , yn+1 ) = f(tn+1 , y0n+1 ) +∂f∆y0 + . . .
∂y 0Here we recognize the Jacobian matrix, J ≡ ∂f/∂y,


∂
f
/∂y
∂
f
/∂y
∂
f
/∂y
.
.
.
∂
f
/∂y
n 
2
3
1
1
1
1
 1


 ∂ f 2 /∂y1 ∂ f 2 /∂y2 ∂ f 2 /∂y3 . . . ∂ f 2 /∂yn 


J=

..
..
..
..
..


.
.
.
.
.




∂ f n /∂y1 ∂ f n /∂y2 ∂ f n /∂y3 . . . ∂ f n /∂yn

(1.32)(1.33)

Putting Eqs. 1.31 and 1.32 into Eq. 1.30, we have:hiy0n+1 + ∆y0 = yn + ∆t f(tn+1 , y0n+1 ) + J|0 ∆y0(1.34)(I − ∆t J|0 ) ∆y0 = yn − y0n+1 + ∆tf(tn+1 , y0n+1 )(1.35)

Writing this as a system for the unknown correction, ∆y0 , we haveThis is a linear system (a matrix × vector = vector) that can be solved using standard matrix techniques (numerical methods for linear algebra can be found in mostnumerical analysis texts). After solving, we can correct our initial guess:y1n+1 = y0n+1 + ∆y0(1.36)

Chapter 1. Simulation Overview

18

Written this way, we see that we can iterate. To kick things off, we need a suitable
guess—an obvious choice is y0n+1 = yn . Then we correct this guess by iterating, withthe k-th iteration looking like:+1
n +1 n +1
I − ∆t J|k−1 ∆yk−1 = yn − ynk−
, y k −1 )(1.37)
1 + ∆tf ( t+1ynk +1 = ykn−
1 + ∆yk −1(1.38)

We will iterate until we find ∥∆yk ∥ < ϵ∥yn ∥. Here ϵ is a small tolerance, and we use
yn to produce a reference scale for meaningful comparison. Note that here we use avector norm to give a single number for comparison.
Note that the role of the Jacobian here is the same as the first derivative in the scalar
Newton’s method for root finding (Eq. 1.15)—it points from the current guess to thesolution. Sometimes an approximation to the Jacobian, which is cheaper to evaluate,
may work well enough for the method to converge.
Explicit methods are easier to program and run faster (for a given ∆t), but implicit
methods work better for stiff problems—those characterized by widely disparate
timescales over which the solution changes [20]¶ . A good example of this issue inastrophysical problems is with nuclear reaction networks (see, e.g., [78]). As with theexplicit case, higher-order methods exist that can provide better accuracy at reduced
cost.

1.2.6

FFTs

The discrete Fourier transform converts a discretely-sampled function from real space
to frequency space, and identifies the amount of power associate with discrete wavenumbers. This is useful for both analysis, as well as for solving certain linear problems(see, e.g., § 9.2).
For a function, f ( x ) sampled at N equally-spaced points (such that f n = f ( xn )), thediscrete Fourier transform, Fk is written as:
N −1

Fk = ∑ f n e−2πink/N
n =0k ∈ [0, N − 1]

(1.39)The exponential in the sum brings in a real (cosine terms, symmetric functions) andimaginary (sine terms, antisymmetric functions) part.
N −1

Re(Fk ) = ∑ f n cos
n =0
N −1

Im(Fk ) = ∑ f n sin
n =0





2πnk
N
2πnk
N





¶ Defining whether a problem is stiff can be tricky (see [20] for some definitions).

ODEs, a large range in the eigenvalues of the Jacobian usually means it is stiff.

(1.40)(1.41)For a system of

1.2—Numerical basics

19

Alternately, it is sometimes useful to combine the real and imaginary parts into an
amplitude and phase.
The inverse transform is:fn =1 N −1
Fk e2πink/NN k∑=0n ∈ [0, N − 1]

(1.42)

The 1/N normalization is a consequence of Parseval’s theorem—the total power inreal space must equal the total power in frequency space. One way to see that thismust be the case is to consider the discrete transform of f ( x ) = 1, which should be adelta function.
The FFT of a discrete function has the same amount of information as the original
discrete function. Note that if f ( x ) is real-valued, then the transform Fk has 2 numbers (the real and imaginary parts) for each of our original N real values. This would
mean that we have 2N pieces of information in frequency space where we only had N
pieces of information in real space. Since we cannot create information in frequency
space where there was no corresponding real-space information, half of the Fk ’s are
redundant (and F−k = Fk⋆ ).
Directly computing Fk for each k takes O( N 2 ) operations. The fast Fourier transform(FFT) is a reordering of the sums in the discrete Fourier transform to reuse partial
sums and compute the same result in O( N log N ) work. Many numerical methods
books can give a good introduction to how to design an FFT algorithm.
Exercise 1.9
Learn how to use a FFT library or the built-in FFT method in your programming language of choice. There are various ways to define the normalization in the FFT, that can vary from one library to the next. To
ensure that you are doing things correctly, compute the following transforms:• sin(2πk0 x ) with k0 = 0.2. The transform should have all of thepower in the imaginary component only at the frequency 0.2.
• cos(2πk0 x ) with k0 = 0.2. The transform should have all of thepower in the real component only at the frequency 0.2.
• sin(2πk0 x + π/4) with k0 = 0.2. The transform should haveequal power in the real and imaginary components, only at thefrequency 0.2. Since the power√ is 1, the amplitude of the real andimaginary parts will be 1/ 2.
An example of the transform of a single-frequency sine wave with a phaseshift is shown in Figure 1.7.
The FFT assumes that a function is periodic and that the points are evenly spaced. If
the function is not periodic, then a signal will show up in the FFT at a wavenumberChapter 1. Simulation Overview

20

Fk

f(x)

1
0
1

0

0.5
0.0
0.5

10

20

0.0

0.5

1.0

0.0

0.5

1.0

10

20

x

k

30

40

50

Re(F)

Im(F)

1.5

2.0

2.5

1.5

2.0

2.5

|F k |

1

F −1 (F k )

0
1
0
1

0

k

x

30

40

50

Figure 1.7: The Fourier transform of a sine wave with a phase of π/4, f ( x ) =sin(2πk0 x + π/4) with k0 = 0.2. The top shows the original function. The second
panel shows the real and imaginary components—we see all of the power is at our
input wavenumber, split equally between the real and imaginary parts. The third paneshows the power (the absolute value of the transform). Finally, the bottom panel shows
the inverse transform of our transform, giving us back our original function.
hydro_examples: fft_simple_examples.pyÏcorresponding to the size of the domain. Related to this, you need to ensure thatyour points are evenly spaced even at the boundary, e.g., if you have a function on[0, 1] represented by 5 points, you want the points to be {0, 0.2, 0.4, 0.6, 0.8} and not{0, 0.25, 0.5, 0.75, 1}. In the latter case, 0 and 1 are the same function value (due toperiodicity), but the FFT assumes that all points are evenly spaced (even across theboundary), so it will think that there is a spacing of 0.25 between these end points.

Chapter

2

Classification of PDEs
2.1

Introduction

Partial differential equations (PDEs) are usually grouped into one of three different
classes: hyperbolic, parabolic, or elliptic. You can find the precise mathematical definition of these classifications in most books on PDEs, but this formal definition is notvery intuitive or useful. Instead, it is helpful to look at some prototypical examplesof each type of PDE.
When we are solving multiphysics problems, we will see that our system of PDEs
spans these different types. Nevertheless, we will look at solutions methods for eachtype separately first, and then use what we learn to solve more complex systems ofequations.

2.2

Hyperbolic PDEs

The canonical hyperbolic PDE is the wave equation:
2
∂2 ϕ
2∂ ϕ
=
c
∂t2
∂x2

(2.1)

The general solution to this is traveling waves in either direction:
ϕ( x, t) = α f 0 ( x − ct) + βg0 ( x + ct)(2.2)

Here f 0 and g0 are set by the initial conditions, and the solution propagates f 0 to theright and g0 to the left at a speed c.

git version: 64c838dee1a8 . . .

21

Chapter 2. Classification of PDEs

22
Exercise 2.1

Show by substitution that Eq. 2.2 is a solution to the wave equation
A simple first-order hyperbolic PDE is the linear advection equation:
at + ua x = 0(2.3)

This simply propagates any initial profile to the right at the speed u. We will use
linear advection as our model equation for numerical methods for hyperbolic PDEs.
A system of first-order hyperbolic PDEs takes the form:
at + Aa x = 0(2.4)

where a = ( a0 , a1 , . . . a N −1 )⊺ and A is a matrix. This system is hyperbolic if theeigenvalues of A are real (see [46] for an excellent introduction).
An important concept for hyperbolic PDEs are characteristics—these are curves ina space-time diagram along which the solution is constant. Associated with thesecurves is a speed—this is the wave speed at which information on how the solutionchanges is communicated. For a linear PDE (or system of PDEs), these will tell you
everything you need to know about the solution.

2.3

Elliptic PDEs

The canonical elliptic PDE is the Poisson equation:∇2 ϕ = f(2.5)

Note that there is no time-variable here. This is a pure boundary value problem. The
solution, ϕ is determined completely by the source, f , and the boundary conditions.
In contrast to the hyperbolic case, there is no propagation of information here. The
potential, ϕ, is known instantaneously everywhere in the domain. For astrophysical flows, this commonly arises as the Poisson equation describing the gravitational
potential.

2.4

Parabolic PDEs

The canonical parabolic PDE is the heat equation:
∂ϕ
∂2 f
=k 2
∂t
∂x
This has aspects of both hyperbolic and elliptic PDEs.

(2.6)

2.4—Parabolic PDEs

23

The heat equation represents diffusion—an initially sharp feature will spread out intoa smoother profile on a timescale that depends on the coefficient k. We’ll encounter
parabolic equations for thermal diffusion and other types of diffusion (like species,mass), and with viscosity.
Exercise 2.2
Using dimensional analysis, estimate the characteristic timescale for diffusion from Eq. 2.6.

Chapter3

Finite-Volume Grids
3.1

Discretization

The physical systems we model are described by continuous mathematical functions,f ( x, t) and their derivatives in space and time. To represent this continuous systemon a computer we must discretize it—convert the continuous function into a discrete
number of points in space at one or more discrete instances in time. There are manydifferent discretization methods used throughout the physical sciences, engineering, and applied mathematics fields, each with their own strengths and weaknesses.
Broadly speaking, we can divide these methods into grid-based and gridless methods.
Gridless methods include those which represent the function as a superposition ofcontinuous basis functions (e.g. sines and cosines). This is the fundamental idea behind spectral methods. A different class of methods are those that use discrete particles
to represent the mass distribution and produce continuous functions by integratingover these particles with a suitable kernel—this is the basis of smoothed particle hydrodynamics (SPH) [55]. SPH is a very popular method in astrophysics.
For grid-based methods, we talk about both the style of the grid (structured vs.
unstructured) and the discretization method, e.g. the finite-difference, finite-volume,and finite-element methods.
Structured grids are logically Cartesian. This means that you can reference the location of any cell in the computational domain via an integer index in each spatial
dimension. From a programming standpoint, the grid structure can be represented
exactly by a multi-dimensional array. Unstructured grids don’t have this simple pattern. A popular type of unstructured grid is created using triangular cells (in 2-d)or tetrahedra (in 3-d). The main advantage of these grids is that you can easily
represent irregularly-shaped domains. The disadvantage is that the data structures
git version: 64c838dee1a8 . . .

25

Chapter 3. Finite-Volume Grids

26

required to describe the grid are more complicated than a simple array (and tend tohave more inefficient memory access).
Once a grid is established, the system of PDEs is converted into a system of discrete
equations on the grid. Finite-difference and finite-volume methods can both be applied to structured grids. The main difference between these methods is that the finitedifference methods build from the differential form of PDEs while the finite-volume
methods build from the integral form of the PDEs. The attractiveness of finite-volume
methods is that conservation is a natural consequence of the discretization—this is
why they are popular in astrophysics.
In these notes, we will focus on finite-volume techniques on structured grids.

3.2

Grid basics

The grid is the fundamental object for representing continuous functions in a discretized fashion, making them amenable to computation. In astrophysics, we typically use structured grids—these are logically Cartesian, meaning that the position ofa quantity on the grid can be specified by a single integer index in each dimension.
This works for our types of problems because we don’t have irregular geometries—
we typically use boxes, disks, or spheres.
We represent derivatives numerically by discretizing the domain into a finite numberof zones (a numerical grid). This converts a continuous derivative into a differenceof discrete data. Different approximations have different levels of accuracy.
There are two main types of structured grids used in astrophysics: finite-difference andfinite-volume. These differ in way the data is represented. On a finite-difference grid,
the discrete data is associated with a specific point in space. On a finite-volume grid,
the discrete data is represented by averages over a control volume. Nevertheless,these methods can often lead to very similar looking discrete equations.
Consider the set of grids show in Figure 3.1. On the top is a classic finite-difference
grid. The discrete data, f i , are stored as points regularly spaced in x. With thisdiscretization, the spatial locations of the points are simply xi = i∆x, where i =0, . . . , N * . Note that for a finite-sized domain, we would put a grid point precisely on
the physical boundary at each end.
The middle grid is also finite-difference, but now we imagine first dividing the domain into N cells or zones, and we store the discrete data, f i , at the center of the zone.
This is often called a cell-centered finite-difference grid. The physical coordinate of thezone centers (where the data lives) are: xi = (i + 1/2)∆x, where i = 0, . . . , N − 1.
Note that now for a finite-sized domain, the left edge of the first cell will be on the* When you see f i +1 , you can think of this as meaning f ((i + 1) ∆x ) or f ( xi + ∆x )

3.3—Finite-volume grids

27boundary and the first data value will be associated at a point ∆x/2 inside the boundary. A similar situation arises at the right physical boundary. Some finite-difference
schemes stagger the variables, e.g., putting velocity on the boundaries and density at
the center.
Finally, the bottom grid is a finite-volume grid. The layout looks identical to thecell-centered finite difference grid, except now instead of the discrete data being
associated at a single point in space, keep track of the total amount of f in the zone
(indicated as the shaded regions). Since we generally don’t know how f varies in thezone, we will typically talk about the average of f , ⟨ f ⟩i , over the zone, and represent
this by a horizontal. The total amount of f in the zone is then simply ∆x ⟨ f ⟩i . We
label the left and right edges of a zone with half-integer indices i − 1/2 and i + 1/2.
The physical coordinate of the center of the zone is the same as in the cell-centeredfinite-difference case.
In all cases, for a regular structured grid, we take ∆x to be constant. For the finitedifference grids, the discrete value at each point is obtained from the continuousfunction f ( x ) as:
f i = f ( xi )
(3.1)

3.3

Finite-volume grids

In the finite-volume discretization, f i represents the average of f ( x, t) over the interval
xi−1/2 to xi+1/2 , where the half-integer indices denote the zone edges (i.e. xi−1/2 =xi − ∆x/2):
Z xi+1/2
1⟨ f ⟩i =f ( x )dx
(3.2)
∆x xi−1/2
The lower panel of Figure 3.1 shows a finite-volume grid, with the half-integer indicesbounding zone i marked. Here we’ve drawn ⟨ f ⟩i as a horizontal line spanning theentire zone—this is to represent that it is an average within the volume defined by
the zone edges. To second-order accuracy,1⟨ f ⟩i =∆x

Z xi+1/2
xi−1/2f ( x )dx ∼ f ( xi )(3.3)

Exercise 3.1
Show that Eq. 3.3 is true to O(∆x2 ) by expanding f ( x ) as a Taylor series
in the integral, e.g., as:f ( x ) = f ( xi ) + f ′ ( xi )( x − xi ) ++1 ′′f ( xi )( x − xi )22

1 ′′′f ( xi )( x − xi )3 + . . .
6

(3.4)

Chapter 3. Finite-Volume Grids

28

fi

i−2

i−1

i

i+1

i+2

i+1

i+2

i+1

i+2

∆x

fi

i−2

i−1

i
∆x

hf ii

i−2

i − 1 i − 1/2ii + 1/2∆x

Figure 3.1: Different types of structured grids showing the same data. Top: a finitedifference grid—the discrete data are associated with a specific point in space. Middle:
a cell-centered finite-difference grid—again the data is at a specific point, but now we
imagine the domain divided into zone with the data living at the center of each zone.
Bottom: a finite-volume grid—here the domain is divided into zones and we store theaverage value of the function within each zone.

This means that we can treat the average of f over a zone as simply f ( x ) evaluated at
the zone center if we only want second-order accuracy. Using the subscript notation,
we can express the average of the zone to the right as ⟨ f ⟩i+1 .
When we want to interpolate data on a finite-volume grid, we want to construct aninterpolating polynomial that is conservative. A conservative interpolant reconstructs
a continuous functional form, f ( x ), from a collection of cell-averages subject to therequirement that when f ( x ) is averaged over a cell, it returns the original cell-average.

3.3—Finite-volume grids

29

Exercise 3.2
Consider three cell averages: ⟨ f ⟩i−1 , ⟨ f ⟩i , ⟨ f ⟩i+1 . Fit a quadratic polynomial through these points,f ( x ) = A ( x − x i )2 + B ( x − x i ) + C(3.5)

where the coefficients, A, B, and C are found by applying the constraints:Z

xi−1/2
1
f ( x )dx
∆x xi−3/2
Z xi+1/2
1
f ( x )dx
⟨ f ⟩i =∆x xi−1/2
Z xi+3/2
1
f ( x )dx
⟨ f ⟩ i +1 =∆x xi+1/2⟨ f ⟩ i −1 =

(3.6)
(3.7)
(3.8)

Show that the conservative interpolant is:
f (x) =

⟨ f ⟩ i −1 − 2 ⟨ f ⟩ i + ⟨ f ⟩ i +1
( x − x i )2 +2∆x2
⟨ f ⟩ i +1 − ⟨ f ⟩ i −1
( x − xi )+2∆x−⟨ f ⟩i−1 + 26⟨ f ⟩i − ⟨ f ⟩i+1
24

(3.9)

The Jupyter notebook Ï hydro_examples: conservative-interpolation.ipynb shows
how to derive these interpolants using SymPy, and gives higher-order interpolants.

3.3.1

Differences and order of accuracy

In practice, when computing derivatives in a finite-volume discretization, we can use
the second-order centered difference from § 1.2.2 treating the finite-volume data asliving at the cell-centers and still be second-order accurate. For higher accuracy, we
can fit a conservative interpolant (as illustrated in exercise 3.2) to a collection of points
and then differentiate the interpolant itself.
Notice that the righthand side of all derivative approximations involve some linear
combinations of f i ’s. We call this the stencil. The width of the stencil is a measure of
how many zones on either side of zone i we reach when computing our approximation.
For example, a second derivative can be discretized as:
d2 f
f − 2 f i + f i −1
= i +1
2
dx i∆x2
The stencil on the righthand side encompasses 3 zones.

(3.10)

Chapter 3. Finite-Volume Grids

30

3.3.2

Conservation

The finite-volume grid is useful when dealing with conservation laws. Consider thefollowing system:∂U+ ∇ · F( U ) = 0(3.11)∂twhere U is a vector of conserved quantities and F( U ) is the flux of each quantity.
This type of system arises, for example, in fluid flow, where the system will represent
conservation of mass, momentum, and energy.
Consider one-dimension. Integrating this system over a zone, and normalizing by∆x, we have:Z xi+1/2
Z xi+1/2
1∂U∂F
1dx = −
dx(3.12)∆x xi−1/2 ∂t∆x xi−1/2 ∂x
On the left, we can take the time derivative out of the integral, and we are left withthe definition of a zone average, so this becomes simply ∂⟨ U ⟩i /∂t. On the right, weapply the divergence theorem, giving:o∂ ⟨ U ⟩i
1 n
F( U )| xi+1/2 − F( U )| xi−1/2
=−
∂t
∆x

(3.13)o∂ ⟨ U ⟩ i +1
1 n=−
F( U )| xi+3/2 − F( U )| xi+1/2∂t∆x(3.14)

Independent of how we discretize in time, notice that we have the cell-average on theleft and that the righthand side is simply a difference of fluxes through the interfacesof the zone. For the i + 1 zone, the update would be:

Notice that this shares the flux at the xi+1/2 interface, but with the opposite sign.
When all of the updates are done, the flux through each boundary adds to one
zone and subtracts from its neighbor, exactly conserving (to round-off error) thequantity U . This cancellation of the sums is an example of a telescoping property, andis the main reason why finite-volume methods are attractive—conserved quantities
are conserved to machine (roundoff) precision.
Note that conservation is not the same as accuracy. We can construct the fluxes forour discretized equation by calling a random number generator and we’d still beconservative, but not at all accurate.

3.3.3

Boundary conditions with finite-volume grids

Imagine that we wish to compute the derivative in every zone using:∂f
f − f i −1
= i
.
∂x i
∆x

(3.15)

If we denote the index corresponding to the leftmost zone in our domain as ‘lo’, thenwhen we try to compute ∂ f /∂x |lo , we will “fall-off” the grid, i.e., we need a value of

3.4—Numerical implementation details

lo − 1

lo
∆x

i−1

31

i

i+1

hi

hi + 1Figure 3.2: A simple 1-d finite-volume grid with a single ghost cell at each end of thedomain. The domain boundaries are indicated by the heavy vertical lines. Here there
are hi − lo + 1 zones used in the discretization of the domain, with the first zone in thedomain labeled lo and the last in the domain labeled hi.

f for zone lo − 1, which is outside the domain. This is where boundary conditions
for our grid come into play.
We implement boundary conditions by extending the computational grid beyond thephysical domain (see Figure 3.2). These additional zones are called ghost cells. They
exist solely to handle the boundary conditions and allow us to use the same update
equation (e.g. Eq. 3.15) for all zones in the domain.
The number of ghostcells needed for the grid depends on how wide the stencils usedin the computation are. The wider the stencil, the more ghostcells are needed.
Periodic boundary conditions would be implemented as:
f hi+1 =f lo(3.16)

f lo−1 =f hi(3.17)

A simple outflow (zero-gradient) boundary condition would be implemented as:

3.4

f hi+1 =f hi(3.18)

f lo−1 =f lo(3.19)

Numerical implementation details

The computational grids used for finite-volume techniques maps nicely onto multidimensional arrays. For the cell-average data, a typical array would be dimensionedas
ilo = ng
ihi = nx + ng - 1state = np . zeros (( nx + 2* ng , nvar ))in python (using NumPy), where nx is the number of zones in the domain and ng is
the number of ghost cells. For some problems, there might be more than one stateChapter 3. Finite-Volume Grids

32

Figure 3.3: Domain decomposition of the computational domain into 6 separate subdomains. Each sub-domain here has 5 × 5 zones. For one of the sub-domains, theperimeter of ghost cells is illustrated as the red boundary.

variable, so nvar, is the number of state variables that live in each zone. We would
then loop from ilo to ihi to access the state data in the grid interior.
Fluxes are also stored in arrays, but since we cannot index an array with half-integer
indices, the standard convention is that the index i in an array refers to the flux on
the left edge of that zone. I.e.,flux[i]3.5←→

Fi−1/2Going further• Domain decomposition: when running on a parallel computer, the work is divided up across processor using domain decomposition. Here, we break thecomputational domain into smaller sub-domains, and put one (or more) subdomains on each processor. Each sub-domain has its own perimeter of ghost
cells. These are now filled by copying information from the neighboring subdomains or using the physical boundary conditions for the full domain, depending on where the ghost cells lie. Figure 3.3 shows a simple decompositionof a domain into 6 sub-domains.
• AMR for structured grids: adaptive mesh refinement uses a hierarchy of grids
to focus resolution in regions of complex flow. For finite-volume codes, the3.5—Going further

33

standard reference for AMR is Berger & Colella [15]. Each level is an eveninteger multiple finer in resolution, and the grid cells line up with one another(i.e. in two-dimensions, four fine cells will be completely enclosed by a single
coarse cell, when using a jump in resolution of 2×.) This provides a natural
way to enforce conservation. At coarse-fine interfaces, corrections are done toensure consistency.
• Mapped grids: mapped grids are (usually) logically Cartesian grids that use afunction (map) to transform from a rectangular mesh (that corresponds to thearray in memory) to a general curvilinear grid. These maintain the performance
characteristics of structured grids, since any zone can be directly indexed withan integer for each spatial dimension.
• Lagrangian grids: a hybrid of particle and grid methods is provided by methods
that move particles in a Lagrangian fashion and use a Voronoi tessellation ofthese particles to define the grid that finite-volume methods are applied to. See,for example, the Arepo code paper [75].

Part II

Advection and Hydrodynamics

Chapter

4

Advection Basics
4.1

The linear advection equation

The linear advection equation is simply:
at + ua x = 0(4.1)

where a( x, t) is some scalar quantity and u is the velocity at which it is advected(u > 0 advects to the right). The solution to Eq. 4.1 is to simply take the initial data,a( x, t = 0), and displace it to the right at a speed u. The shape of the initial data
is preserved in the advection. Many hyperbolic systems of PDEs, e.g. the equationsof hydrodynamics, can be written in a form that looks like a system of (nonlinear)advection equations, so the advection equation provides important insight into themethods used for these systems.
Exercise 4.1
Show via substitution that a( x − ut) is a solution to Eq. 4.1 for any choiceof a. This means that the solution is constant along the lines x = ut (thecurves along which the solution is constant are called the characteristics).
Figure 4.1 shows an initial profile, a( x ), and the corresponding characteristics in thet-x plane. With time, since the solution is constant along these characteristics, it
simply each point simply follows the characteristic curve, resulting in a shift of the
profile to the right.
An important concept that we will discuss shortly is stability. Not every discretizationthat we write down will be well behaved. For some, our initial state will begin to“blow-up”, and take on obscenely large and unphysical values after just a few steps.
git version: 64c838dee1a8 . . .

37

Chapter 4. Advection Basics

38

1.0
0.8

a

0.6
0.4
0.2
0.0
0.0

0.2

0.4

0.2

0.4

x

0.6

0.8

0.6

0.8

1.0

1.0
0.8

t

0.6
0.4
0.2
0.0
0.0

x

1.0

Figure 4.1: (top) Initially sinusoidal distribution (bottom) Characteristic structure forthe linear advection equation u = 1. Note that for this linear equation the characteristics are all parallel (they have the same slope in the t-x plane.

This is the hallmark of a method that is unstable. Some methods have restrictions on
the size of the timestep that result in a stable methods as well.

4.2

First-order advection in 1-d and finite-differences

To get a flavor of the methods for advection, we will use a simple finite-difference
discretization—here, the domain is divided into a sequence of points where we store
the solution. We will solve Eq. 4.1 numerically by discretizing the solution at thesepoints. The index i denotes the point’s location, and ai denotes the discrete value ofa( x ) in zone i. The data in each zone can be initialized as ai = a( xi ). Figure 4.2 shows
the grid.
We also need to discretize in time. We denote the time-level of the solution with asuperscript, so ain = a( xi , tn ). For a fixed ∆t, time level n corresponds to a time oft = n∆t.

4.2—First-order advection in 1-d and finite-differences

39

ai

−1

0

1

i−1

i

i+1

N −2

N −1

N

∆x

Figure 4.2: A simple finite-difference grid. The solution is stored at each of the labeledpoints. The dotted lines show the ghost points used to extend our grid past the physicalboundaries to accommodate boundary conditions. Note that if we are periodic, thenpoints 0 and N − 1 are at the same physical point in space, so we would only need to
update one of them.

A simple first-order accurate discretization is:an − ain−1
ain+1 − ain= −u i
∆t
∆x

(4.2)

This is an explicit method, since the new solution, ain+1 , depends only on information
at the old time level, n.
Finally, we also need to specify a boundary condition for this. Our choice of spatial
derivative is one-sided—it uses information from the zone to the left of the zone weare updating. This is because information is flowing from left to right in this problem(u > 0). This choice of the derivative is called upwinding—this choice of derivative
results in a stable method. Notice that if we use Eq. 4.2 to update the data in thefirst zone inside the boundary, we need data to the left of this zone—outside of thedomain. This means that we need a single ghost point to implement the boundary
conditions for our method. The presence of the ghost points allow us to use the same
update equation (e.g. Eq. 4.2) for all zones in the domain.
The last piece of information needed to update the solution is the timestep, ∆t. It canbe shown that for the solution to be stable, the timestep must be less than the time ittakes information to propagate across a single zone. That is:
∆x
.
(4.3)
u
This is called the Courant-Friedrichs-Lewy or CFL condition. A dimensionless quantity
called the CFL number is defined as
∆tu
C=
(4.4)
∆x
Stability requires C ≤ 1. We traditionally write the timestep as∆t ≤∆t = C

∆x
u

(4.5)

Chapter 4. Advection Basics

40

and specify C as part of the problem (a typical value may be C = 0.7).

Exercise 4.2
Show analytically that when you use C = 1 in the first-order differenced
advection equation (Eq. 4.2) that you advect the profile exactly, without
any numerical error.

Keep in mind that, in general, we will be solving a non-linear system of equations,
so it is not possible to run with C = 1, since u (and therefore C ) will change fromzone to zone. Instead, one looks at the most restrictive timestep over all the zones
and uses that for the entire system.

Exercise 4.3
Write a code to solve the 1-d linear advection equation using the discretization of Eq. 4.2 on the domain [0, 1] with u = 1 and periodic boundary conditions. For initial conditions, try both a Gaussian profile and a
top-hat:x < 1/3
 0 if
(4.6)
a=
1 if
1/3 ≤ x < 2/3
0 if
2/3 ≤ xNote: For a general treatment of boundary conditions, you would
initialize the ghost points to their corresponding periodic data and apply
the difference equations to zones 0, . . . , N − 1. However, for periodic BCs
on this grid, points 0 and N − 1 are identical, so you could do the updatein this special case on points 1, . . . , N − 1 without the need for ghost
points and then set a0 = a N −1 after the update.
Run you program for one or more periods (one period is T = 1/u) withseveral different CFL numbers and notice that there is substantial numerical dissipation (see Figure 4.3).

This method is first-order accurate.
Ultimately we will want higher-order accurate methods. The most obvious change
from our initial discretization is to try a higher-order spatial derivative.

4.2—First-order advection in 1-d and finite-differences

41

exact

1.0

C = 0.1
C = 0.5
C = 0.9

0.8

a

0.6
0.4
0.2
0.0
0.0

0.2

0.4

0.6

x

0.8

1.0

Figure 4.3: Finite-difference solution to the first-order finite-difference upwind method
for advection, using 65 points and a variety of CFL numbers.
hydro_examples: fdadvect.py

Ï

2.0

exact

1.25

C = 0.5

1.5

1.00
0.75

1.0

0.50

0.5

a

a

exact

C = 0.1

0.25

0.0

0.00

0.5

0.25
1.0
0.0

0.2

0.4

x

0.6

0.8

1.0

0.0

0.2

0.4

x

0.6

0.8

Figure 4.4: Finite-difference solution using the FTCS finite-difference method for advection using 65 points, modeling for only 1/10th of a period. The panel of the left iswith C = 0.1 and the panel on the right is C = 0.5.
hydro_examples: fdadvect.pyÏ

Exercise 4.4
You may think that using a centered-difference for the spatial derivative,a x ∼ ( ai+1 − ai−1 )/(2∆x ) would be more accurate. This method is called
FTCS (forward-time, centered-space). Try this on the same test problems.

1.0Chapter 4. Advection Basics

42

You will find that no matter what value of C you choose with the FTCS method,
the solution is unconditionally unstable (see Figure 4.4). If you continue to evolve theequation with this method, you would find that the amplitude grows without bound.
There is something about that discretization that simply gets the physics wrong.

4.3

Stability

The classic method for understanding stability is to consider the growth of a single
Fouriermode in our discretization. That is, substitute in ain = An e Iiθ , where I =√−1* , and θ represents a phase. A method is stable if | An+1 /An | ≤ 1. FTCS appears
as:
C
(4.7)
ain+1 = ain − ( ain+1 − ain−1 )2Examining a Fourier mode shows that:C  n I ( i +1) θA e− A n e I ( i −1) θ(4.8)
An+1 e Iiθ = An e Iiθ −2
C
An+1 = An − An e Iθ − e− Iθ(4.9)
2
An+1 = An (1 − I C sin θ )(4.10)
so the magnitude of the amplification is
A n +1An

2= 1 + C 2 sin2 θ(4.11)We see that there is no value of C that can make the method stable (| An+1 /An | > 1
always). Doing the same analysis for Eq. 4.2 would show that the upwind method isstable for 0 ≤ C ≤ 1.
Exercise 4.5
Using the above stability analysis, considering the amplitude of a single
Fourier mode, show that the growth of a mode for the upwind method(Eq. 4.2) is:2
A n +1= 1 − 2C(1 − C)(1 − cos θ )(4.12)
Anand stability requires 2C(1 − C) ≥ 0 or 0 ≤ C ≤ 1.
It is important to note that this stability analysis only works for linear equations,where the different Fourier modes are decoupled, nevertheless, we use its ideas fornonlinear advection problems as well.
* our use of i and j as spatial indices presents an unfortunate clash of notation here, hence the use of
I for the imaginary unit

4.3—Stability

43

Truncation analysis can also help us understand stability. The idea here is to keep
the higher order terms in the Taylor series to understand how they modify the actual
equation you are trying to solve.
Exercise 4.6
To get an alternate feel for stability, we can ask what the terms left out by
truncation look like. That is, we can begin with the discretized equation:
ain+1 − ain = −u∆t n( a − ain−1 )∆x i(4.13)

and replace ain+1 with a Taylor expansion in time, and replace ain−1 witha Taylor expansion in space, keeping terms to O(∆t3 ) and O(∆x3 ). Replacing ∂a/∂t with −u∂a/∂x in the higher-order terms, show that ourdifference equation more closely corresponds toat + ua x =

=



u∆x
∆tu ∂2 a1−
2∆x ∂x2u∆x∂2 a(1 − C) 22∂x(4.14)(4.15)

Notice that the righthand side of Eq. 4.14 looks like a diffusion term, however, if
C > 1, then the coefficient of the diffusion is negative—this is unphysical. Thismeans that the diffusion would act to take smooth features and make them morestrongly peaked—the opposite of physical diffusion.
For FTCS, a similar truncation analysis would show that the diffusion term is always
negative.

4.3.1

Domain of dependence

Another important view of our numerical difference scheme is to look at the domainof dependence. Figure 4.5 illustrates this for the updated point ain+1 (shown at the topof center of the space-time diagram). The numerical domain of dependence shows
the points that can influence the updated value of ai using our difference method.
For the upwind scheme, we see that this is a triangle that includes ain−1 and ain . The
physical domain of dependence is shown as the orange triangle—this is formed bytracing backwards in time from ain+1 along a characteristic, reaching out to the pointxi − C∆x = xi − u∆t over ∆t.
Any stable numerical method must have a numerical domain of dependence that includes the physical domain of dependence. If it does not, then the update to the solution simply does not see the points that contribute to the solution over the timestep∆x. Notice that this is a necessary, but not sufficient condition for stability. FTCS has

Chapter 4. Advection Basics

44t
ain + 1tn+1

upwindain− 1tn

xi − 1ainxi − C∆xxi

ain+ 1xi + 1xt
ain + 1tn+1

downwindain− 1tn

xi − 1ainxi − C∆xxi

ain+ 1xxi + 1t
ain + 1

tn+1

FTCS

tn

ain− 1xi − 1ainxi − C∆xxi

ain+ 1xxi + 1Figure 4.5: Space-time diagrams showing the numerical domain of dependence (blueregion) for three different difference methods. Also show is the physical domain of
dependence—that formed by tracing backwards from ain+1 along a characteristic.

a domain of dependence that includes the physical domain of dependence, but it is
not stable.

4.4—Implicit-in-time

4.4

45

Implicit-in-time

An alternate approach to time-discretization is to do an implicit discretization. Hereour upwind method would appear as:
an+1 − ain−+11
ain+1 − ain= −u i∆t∆x(4.16)The only change here is that the righthand side is evaluated at the new timelevel,n + 1. We can write this as a linear system with coupled equations:−C ain−+11 + (1 + C) ain+1 = ain(4.17)

If we use periodic boundary conditions, then point 0 and N − 1 are identical, so weonly need to update one of these. Taking a0n+1 = anN+−11 , our system in matrix form
appears as:

 

n +1
n
1
+
C
−C
a
a
1
 1

 



 

  a n +1   a n  −C 1 + C
 2

 

2


 

  n +1  −C 1 + C  a3  a3n 


 

  n +1    a4 =  a4n −C 1 + C   ..   .. 

..
..






.
.
 .   . 




 
  a n +1   a n


−C
1
+
C
  N −2   N −2 



 

n +1
n
−C 1 + C
a N −1a N −1(4.18)
This requires a matrix solve—this makes implicit methods generally more expensive
than explicit methods. However, stability analysis would show that this implicit discretization is stable for any choice of C . (But one must not confuse stability withaccuracy—the most accurate solutions with this method will still have a small C ).
Also note that the form of the matrix will change depending on the choice of boundary conditions. Figure 4.6 shows the result of solving this implicit system.


Exercise 4.7
Code up the implicit advection scheme, but using outflow instead of periodic boundary conditions. This will change the form of the matrix. You
can use the code from Figure 4.6 as a starting point.

Chapter 4. Advection Basics

46

exact

1.0

C = 0.5
C = 1.0
C = 10.0

0.8

a

0.6
0.4
0.2
0.0
0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 4.6: Finite-difference solution to the implicit first-order finite-difference upwind
method for advection, using 65 points and a variety of CFL numbers.
hydro_examples: fdadvect_implicit.pyÏ
4.5

Eulerian vs. Lagrangian frames

It is useful to think about how our advected quantity, a( x, t), changes in time. The
full time derivative is:∂a∂a dxda( x, t)=+(4.19)dt∂t∂x dt
So the value of this derivative depends on the path, x (t), that we choose to follow.
Consider an observer who is stationary. They will watch the flow move past them,so dx/dt = 0, and da/dt = ∂a/∂t. This fixed frame is called Eulerian frame.
Instead imagine an observer who moves with the flow, at the velocity u. This way
they keep pace with an individual feature in the flow and track the changes it experiences. In this case, dx/dt = u, and our derivative, commonly written as D/Dt
is:
D
∂
∂
=
+u
(4.20)
Dt∂t∂x
This is the Lagrangian frame, and the derivative, D/Dt is called the Lagrangian derivative, material derivative, convective derivative, or advective derivative† .
Our linear advection equation can be written simply as Da/Dt = 0. We’ve beensolving the equations in the Eulerian frame—our grid is fixed and the fluid moves† and there are actually many more names...

4.6—Errors and convergence rate

47

through it. For hydrodynamics, it will be useful conceptually to consider the Lagrangian frame to understand how the fluid properties change in a particular fluid
element over time.

4.6

Errors and convergence rate

For the advection problem (with u > 0), the analytic solution is to simply propagate
the initial profile to the right. This means that with periodic boundary conditions,after advecting for one period, our numerical solution should be identical to theinitial conditions. Any differences are our numerical error. We can quantify the error
by taking the norm of error‡ as:ϵabs = ∥ afinal − ainit ∥2 ≡"1 N final
2( ai − ainit
i )
N i∑
=1

#1/2

(4.21)

It is sometimes useful to compare to the norm of the original solution to get a measureof the relative error:∥ afinal − ainit ∥2
ϵrel ≡(4.22)∥ ainit ∥2

Note that for the absolute norm, it is important in these definitions to normalize by
the number of zones, N, otherwise our error will be resolution-dependent. For the
relative norm, since we scale by a norm on the same grid, this normalization willcancel.

‡ see § 1.2.4 for the definition of the norms

Chapter

5

Second- (and Higher-) Order
Advection
5.1

Advection and the finite-volume method

In these notes, we will typically use a finite-volume discretization. Here we explore
this method for the advection equation. First we rewrite the advection equation inconservation form:
at + [ f ( a)] x = 0(5.1)
where f ( a) = ua is the flux of the quantity a. In conservation form, the time derivative of a quantity is related to the divergence of its flux.
Recall that in the finite-volume discretization, ⟨ a⟩i represents the average of a( x, t)over the interval xi−1/2 to xi+1/2 , where the half-integer indexes denote the zone edges(i.e. xi−1/2 = xi − ∆x/2). Figure 5.1 shows an example of such a grid with 2 ghost
cells at each end. (For simplicity of notation, we drop the ⟨⟩ going forward). To
discretize Eq. 5.1, we integrate it over a zone, from xi−1/2 to xi+1/2 , normalizing by thezone width, ∆x:
Z xi+1/2

Z

xi+1/2 ∂1
at dx = −f ( a) dx(5.2)∆x xi−1/2 ∂xxi−1/2o∂
1 nai = −(5.3)[ f ( a)]i+1/2 − [ f ( a)]i−1/2∂t∆xThis is an evolution equation for the zone-average of a, and shows that it updates intime based on the fluxes through the boundary of the zone.

1∆x

We now have a choice on how to proceed with the time-discretization:
1. We can discretize ∂ai /∂t directly as ( ain+1 − ain )/∆t. Then to achieve secondorder accuracy, we need to evaluate the righthand side of Eq. 5.3 at the midpoint
git version: 64c838dee1a8 . . .

49

Chapter 5. Second- (and Higher-) Order Advection

50

haii
lo − 2lo − 1lo

i − 1 i − 1/2ii + 1/2 i + 1

hi

hi + 1

hi + 2∆x

Figure 5.1: A finite-volume grid running from lo, . . . , hi, with two ghost cells at eachend.

in time (n + 1/2). This gives rise to a predictor-corrector method (as describedin [24]. Sometimes this is called a characteristic tracing method (a name which
will be more clear when we discuss the Euler equations).
2. We can recognize that with the spatial discretization done, our PDE has now
become an ODE, and we can use standard ODE methods (like Runge-Kutta) tointegrate the system in time. This is a method-of-lines integration.
We’ll look at both of these in the next sections.

5.2

Second-order predictor-corrector scheme

We discretize Eq. 5.3 in time by evaluating the righthand side at the midpoint intime—this gives a centered-difference in time, which is second-order accurate:
n+1/2

n+1/2

[ f ( a)]i+1/2 − [ f ( a)]i−1/2
ain+1 − ain
=−
∆t
∆x

(5.4)

To evaluate the fluxes at the half-time, we need the state at the half-time, that is, wedo :[ f ( a)]in++1//22 = f ( ain++1//22 ) .
1

1

(5.5)

We construct a second-order accurate approximation to ain++1//22 by Taylor expanding
the data in the cell to the interface. The construction of the interface state at the
midpoint in time is the prediction and the conservative update in the correction here.
1

Notice that for each interface, there are two possible interface states we can construct—
one using the data to the left of the interface (which we will denote with a “L” subscript) and the other using the data to the right of the interface (denoted with an “R”

5.2—Second-order predictor-corrector scheme

51

n+1/2

ai

n+1/2

ai+1/2,L

ai+1/2,R

i + 1/2

i

ai+1

i+1

Figure 5.2: The left and right interface state at the i + 1/2 interface. Here, the left state,1
ain++1//22,L , was predicted to the interface from the zone to the left of the interface, using

ai , and the right state, ain++1//22,R , was predicted to the interface from the zone to the right,
using ai+1 .
1

subscript)—see Figure 5.2. These states are:
∆t ∂a
∆x ∂a
+
+ O(∆x2 ) + O(∆t2 )2 ∂x i2 ∂t i


∆x ∂a
∆t
∂a
ain +
+
−u
+...
2 ∂x i
2
∂x i


∆t
∂a
∆x
n
1−
u
+...
ai +
2
∆x
∂x i
∆x ∂a
∆t ∂a
ain+1 −++ O(∆x2 ) + O(∆t2 )2 ∂x i+1
2 ∂t i+1


∆t
∂a
∆x ∂a
n
a i +1 −+−u+...
2 ∂x i+12∂x i+1∆t∆x∂aain+1 −
1+
u
+...
2
∆x
∂x i+1

ain++1//22,L = ain +1==
ain++1//22,R =
1

=
=

(5.6)

(5.7)

A suitable estimate is needed for the slope of a that appears in these expressions (as∂a/∂x). We can approximate this simply asa − a i −1∂a
= i +1
∂x i
2∆x

(5.8)

We can think of this method as reconstructing the function form of the data from thecell-average data in each cell using a piecewise linear polynomial. Don’t be worried
that this looks like FTCS—we’ll do upwinding next.
We now have two states, ain++1//22,L and ain++1//22,R separated by an interface—this is called
the Riemann problem. The solution to this will depend on the equation being solved,
and results in a single state at the interface:
1

1

ain++1//22 = R( ain++1//22,L , ain++1//22,R )
1

1

1

(5.9)

Chapter 5. Second- (and Higher-) Order Advection

52

n+1/2

alo+1/2,R
n+1/2
alo+1/2,L

lo − 2lo − 1lo − 1/2

lolo + 1Figure 5.3: Reconstruction near the boundary, showing the need for two ghostcells.
Here we see the left and right state at the left physical boundary of the domain (marked
as lo − 1/2). The gray dotted lines are the piecewise constant cell averages and the redlines are the reconstructed slopes. Note that we need the slope in lo − 1 to get theleft interface state at lo − 1/2, and that slope in turn needed the data in zone lo − 2 toconstruct a centered-difference.

In our case, the advection equation simply propagates the state to the right (foru > 0), so the solution to the Riemann problem is to take the left state (this is anotherexample of upwinding). That is we do: an+11/2 u > 0
i + /2,L
n+1/2
n+1/2
R( ai+1/2,L , ai+1/2,R ) =(5.10)n a +1/2 u < 0
i +1/2,R

To complete the update, we use this interface state to evaluate the flux and update
the advected quantity via Eq. 5.4 and 5.5.

Boundary conditions are implemented by filling the ghost cells outside each endof the domain based on data in the interior. Note that at the very left edge of then+1/2
domain, the state alo−1/2 requires the construction of states on the left and right. The
n+ /2
left state at that interface, alo−1/2,L depends on the slope reconstructed in the lo − 1ghost cell, ∂a/∂x |lo−1 . This in turn is constructed using a limited center-difference
that will consider the value in the cell to the left, lo − 2. Therefore, we need two
ghost cells at each end of the domain for this method—figure 5.3 illustrates this.
Higher-order limiters may require even more ghost cells.
1

Exercise 5.1
Write a second-order solver for the linear advection equation. To mimica real hydrodynamics code, your code should have routines for finding
initializing the state, filling boundary conditions, computing the timestep,
constructing the interface states, solving the Riemann problem, and doing
the update. The problem flow should look like:• set initial conditions• main evolution loop—loop until final time reached– fill boundary conditions

5.2—Second-order predictor-corrector scheme

53

exact
unlimited
minmod limiter

1.0
0.8

a

0.6
0.4
0.2
0.0
0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 5.4: Second-order finite volume advection showing the result of advecting
a tophat profile through five periods with both unlimited and limited slopes. This
calculation used 64 zones and C = 0.7.
hydro_examples: advection.pyÏ– get timestep (Eq. 4.5)
– compute interface states (Eqs. 5.6 and 5.7)
– solve Riemann problem at all interfaces (Eq. 5.10)– do conservative update (Eqs. 5.4 and 5.5)
Use both the top-hat and Gaussian initial conditions and periodic boundary conditions and compare to the first-order method. See Figure 5.4.

5.2.1

Limiting

The second-order method likely showed some oscillations in the solution, especiallyfor the top-hat initial conditions. Godunov’s theorem says that any monotonic linear
method for advection is first-order accurate (see, e.g., [44]). In this context, monotonicmeans that no new minima or maxima are introduced. The converse is true too,
which suggests that in order to have a second-order accurate method for this linear
equation, the algorithm itself must be nonlinear.

Chapter 5. Second- (and Higher-) Order Advection

54
Exercise 5.2

To remove the oscillations in practice, we limit the slopes to ensure thatno new minima or maxima are introduced during the advection process.
There are many choices for limited slopes. A popular one is the minmod
limiter. Here, we construct the slopes in the interface states as:
a i − a i −1 a i +1 − a i∂a= minmod,(5.11)∂x i∆x∆xinstead of Eq. 5.8. with
 a if | a| < |b| and a · b > 0
minmod( a, b) =b if |b| < | a| and a · b > 0
0 otherwise(5.12)

Use this slope in your second-order advection code and notice that theoscillations go away—see Figure 5.4.
We can get a feel for what happens with and without limiting pictorially. Figures 5.5
and 5.6 show the evolution of an initial discontinuity with and without limiting.
Without limiting, we see an overshoot behind the discontinuity and an undershootahead of it—these develop after only a single step. With each additional step, theovershoots and undershoots move further away from the discontinuity. In contrast,
the case with limiting shows no over- or undershoots around the initial discontinuity.
By the end of the evolution, we see that the profile is much narrower in the limitingcase than in the case without limiting.
See the text by LeVeque [46] for alternate choices of limiters. Note: most limiters will
have some sort of test on the product of a left-sided and right-sided difference (a · babove)—this is < 0 at an extremum, which is precisely where we want to limit.
A slightly more complex limiter is the MC limiter (monotonized central difference).
First we define an extrema test,ξ = ( a i +1 − a i ) · ( a i − a i −1 )Then the limited difference ishi(
1 − a i −1 |1 − ai |∂amin |ai+2∆x, 2 |ai+∆x, 2 |ai −∆xai−1 | sign( ai+1 − ai−1 ) ξ > 0=∂x i0otherwise(5.13)(5.14)

Note that a slightly different form of this limiter is presented in [46], where all quantities are in a minmod, which appears to limit a bit less. This is second-order accurate
for smooth flows.
The main goal of a limiter is to reduce the slope near extrema. Figure 5.7 shows afinite-volume grid with the original data, cell-centered slopes, and MC limited slopes.

5.2—Second-order predictor-corrector scheme

55

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

Figure 5.5: Initially discontinuous data evolved for several steps with no limiting. Notice that there are overshoots and undershoots surrounding the discontinuity.

Note that near the strong gradients is where the limiting kicks in. The different
limiters are all constructed by enforcing a condition requiring the method to be total
variation diminishing, or TVD. More details on TVD limiters can be found in [46, 82].
A popular extension of the MC limiter is the 4th -order MC limiter, which is moreaccurate in smooth flows (this is shown in [23], Eqs. 2.5 and 2.6; and [24], Eq. 191).

Chapter 5. Second- (and Higher-) Order Advection

56

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

Figure 5.6: Initially discontinuous data evolved for several steps with limiting. Notethat unlike the sequence without limiting (Figure 5.5), the discontinuity remains
sharper with limiting and there are no over- or undershoots.

Exercise 5.3
Show analytically that if you fully limit the slopes (i.e. set ∂a/∂x |i = 0,
that the second-order method reduces to precisely our first-order finite-5.2—Second-order predictor-corrector scheme

i−2

i−1

57

i

i+1

i+2

Figure 5.7: A finite-volume grid showing the cell averages (gray, dotted, horizontal
lines), unlimited center-difference slopes (gray, solid) and MC limited slopes (red).
Note that in zones i and i + 1, the slopes are limited slightly, so as not to overshootor undershoot the neighboring cell value. Cell i − 1 is not limited at all, whereas cells
i − 2, and i + 2 are fully limited—the slope is set to 0—these are extrema.

difference discretization, Eq. 4.2.
It is common to express the slope simply as the change in the state variable:
∆ai =

∂a
∆x
∂x i

(5.15)and to indicate the limited slope as ∆ai .

5.2.2

Reconstruct-evolve-average

Another way to think about these methods is as a reconstruction, evolve, and average(R-E-A) process (see Figure 5.8).
We can write the conservative update as:∆t
1
1(uain−+1//22 − uain++1//22 )∆x
1
1= ain + C( ain−+1//22 − ain++1//22 )ain+1 = ain +(5.16)(5.17)

If we take u > 0, then the Riemann problem will always choose the left state, so we
can write this as:

 

1
1
n +1
n
n
n
ai
= ai + C ai−1 + (1 − C)∆ai−1 − ai + (1 − C)∆ai(5.18)
2
2
{z
} |
{z
}
|
ai−1/2,L

ai+1/2,L

If we instead look at this via the R-E-A procedure, we write the reconstructed a ineach zone in the form of a piecewise linear polynomialai ( x ) = ai +∆ai
( x − xi )∆x(5.19)

Chapter 5. Second- (and Higher-) Order Advection

58

Consider zone i. If we are advecting with a CFL number C , then that means that thefraction C of the zone immediately to the left of the i − 1/2 interface will advect intozone i over the timestep. And only the fraction 1 − C in zone i immediately to theright of the interface will stay in that zone. This is indicated by the shaded regionsin Figure 5.8.
The average of the quantity a from zone i − 1 that will advect into zone i isZ

xi−1/2
1
a ( x )dx
C ∆x xi−1/2 −C ∆x i−1
Z xi−1/2
1
∆ai−1
=
a +
( x − xi−1 ) dx
C ∆x xi−1/2 −C ∆x i−1∆x1= ai−1 + ∆ai−1 (1 − C)2

I< =(5.20)(5.21)(5.22)

And the average of the quantity a in zone i that will remain in zone i isI> =1
(1 − C)∆xZ xi−1/2 +(1−C)∆xxi−1/2ai ( x )dx
Z xi−1/2 +(1−C)∆x 
∆ai
1
ai +
=
( x − xi ) dx
(1 − C)∆x xi−1/2∆x1= ai − ∆ai C
2(5.23)(5.24)(5.25)

The final part of the R-E-A procedure is to average the over the advected profiles in
the new cell. The weighted average of the amount brought in from the left of theinterface and that that remains in the cell isain+1 = CI< + (1 − C)I>




1
1
= C ain−1 + ∆ai−1 (1 − C) + (1 − C) ain − ∆ai C
2
2




1
1
n
n
n
= ai + C ai−1 + (1 − C)∆ai−1 − C ai + (1 − C)∆ai
2
2(5.26)(5.27)(5.28)

This is identical to Eq. 5.18. This demonstrates that the R-E-A procedure is equivalent
to our reconstruction, prediction of the interface states, solving the Riemann problem,and doing the conservative flux update.
Exercise 5.4
Run the first-order solver for several different values of ∆x, each a factorof 2 smaller than the previous. Compute ϵ for each resolution and observethat it converges in a first-order fashion (i.e. ϵ decreases by 2 when we
decrease ∆x by a factor of 2).

5.2—Second-order predictor-corrector scheme

59

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

i−2

i−1

i

i+1

i+2

Figure 5.8: Reconstruct-Evolve-Average. The top panel shows the original cell-averagedata. The second panel shows the (limited) piecewise linear reconstruction of the data.
Assuming a CFL number of 0.6 and advection to the right, the shaded regions in thethird panel show the data that will wind up in cell i after advecting for a single step.
The fourth panel shows the piecewise-linear data advected to the right by 0.6 of a cellwidth (corresponding to a CFL of 0.6). The final panel shows the new averages of thedata, constructed by averaging the advected piecewise linear data in each cell.

Chapter 5. Second- (and Higher-) Order Advection

60

10 −1

O(∆x 2 )ka final − a init k 2

unlimited centerMC
minmod

10 −2

10 −3

10 −4

10 2

N

Figure 5.9: Convergence for the second-order finite-volume method with no limiting,MC, and minmod limiting advecting a Gaussian initial profile with C = 0.8 for 5
periods.
hydro_examples: advection.pyÏDo the same with the second-order solver and observe that it converges
as second-order. However: you may find less than second-order if yourinitial conditions have discontinuities and you are limiting. Figure 5.9
shows the convergence of the method with no limiting, MC, and minmod
limiting, C = 0.8, and a Gaussian initial condition for 5 periods.
As seen in figure 5.9, the choice of limiters can have a great effect on the accuracy.
Figure 5.10 shows the Gaussian and tophat profiles with several different limiters.

5.3

Method of lines approach

In the above constructions, we computed a time-centered flux by predicting the interface state to the half-time (by Taylor-expanding in time through ∆t/2). Instead,
we can recognize that with the spatial discretization done in Eq. ??, we are left withan ordinary differential equation in time that can then be solved using standard ODE
techniques.
Substituting in the flux as f ( a) = ua, we have the ODE:ua
− uai−1/2∂ai= − i+1/2∂t∆x(5.29)

5.3—Method of lines approach61

piecewise constant2.0

centered (unlimited)

2.0

1.8

1.8

1.8

1.6

1.6

1.6

1.4

1.4

1.4

1.2

1.2

1.2

1.0

1.0
0.0

0.2

0.4

0.6

0.8

1.0

MC limiter

2.0

1.0
0.0

1.8

1.6

1.6

1.4

1.4

1.2

1.2

1.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

0.8

1.0

superbee limiter

2.0

1.8

minmod limiter

2.0

1.0
0.0

0.2

0.4

0.6

0.8

1.0

0.0

piecewise constant

1.0

0.2

0.4

0.6

0.8

1.0

centered (unlimited)
1.0

0.8

0.8

0.8

0.6

0.6

0.6

0.4

0.4

0.4

0.2

0.2

0.2

0.0

0.0
0.0

0.2

0.4

0.6

0.8

1.0

MC limiter

1.0

0.0
0.0

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

superbee limiter

1.0

0.8

minmod limiter

1.0

0.0
0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

Figure 5.10: The effect of different limiters on the evolution of a Gaussian initial profile(top) and a tophat initial profile (bottom), using C = 0.8 and 5 periods.
hydro_examples: advection.pyÏNote that there is no time-level indicated on the righthand side. We find the interface
values of a by interpolating in space only. For a second-order accurate method, we
can use a piecewise linear reconstruction (see Figure 5.11), and evaluate the interface

Chapter 5. Second- (and Higher-) Order Advection

62

ai+1/2,L

i−1

ai+1/2,R

i + 1/2ii+1

Figure 5.11: Piecewise linear reconstruction of the zones showing the interface statesused with the method of lines approach.

states as simply the point on the reconstructed line on the interface, e.g.,1
ai+1/2,L = ai + ∆ai
2
1
ai+1/2,R = ai+1 − ∆ai+1
2(5.30)(5.31)The same limiting ideas discussed above apply here. As usual, we resolve the leftright degeneracy on the interface by solving the Riemann problem:
ai+1/2,j = R( ai+1/2,j,L , ai+1/2,j,R )(5.32)

Once we have this interface state, we can integrate the ODE. A Runge-Kutta method
works fine here (it should be atleast second-order to match the spatial accuracy).

5.4

Multi-dimensional advection

The two-dimensional linear advection equation is:
at + ua x + vay = 0(5.33)

where u is the velocity in the x-direction and v is the velocity in the y-direction.
We denote the average of a( x, y, t) in a zone i, j as ai,j . Here, i is the index in thex-direction and j is the index in the y-direction. A 2-d grid is shown in Figure 5.12.
Just as in the one-dimensional case, we will extend the domain with a perimeter ofghost cells to set the boundary conditions.
To derive the finite-volume form of the update, we start by writing this in conservative form. Since u and v are constant, we can move them inside the divergences:
at + (ua) x + (va)y = 0(5.34)

This is the form we will integrate over zones. As before, we will define the averageof a in a zone by integrating it over the volume:
ai,j =1∆x∆y

Z xi+1/2 Z y j+1/2
xi−1/2y j−1/2a( x, y, t) dx dy(5.35)

5.4—Multi-dimensional advection

63

ai,j+1j+1

n+1/2

ai,j+1/2,R
n+1/2

ai,j+1/2,L
n+1/2

ai+1/2,j,R

n+1/2

ai+1/2,j,L

ai,j

j

ai+1,j

j−1

i−1

i

i+1

Figure 5.12: A simple 2-d grid with the zone-centered indexes. The ×s mark the left
and right interface states at the upper edge of the i, j zone in each coordinate direction.
For a finite-volume discretization, ai,j represents the average of a( x, y) over the zone.

Integrating Eq. 5.34 over x and y, we have:1∆x∆y

Z xi+1/2 Z y j+1/2
xi−1/2ZZ

xi+1/2
y j+1/2
1
at dx dy = −(ua) x dx dy∆x∆y xi−1/2 y j−1/2
y j−1/2
Z xi+1/2 Z y j+1/21−(va)y dx dy∆x∆y xi−1/2 y j−1/2(5.36)or using the divergence theorem,
Z y j+1/2 
∂ai,j
1
=−
(ua)i+1/2,j − (ua)i−1/2,j dy∂t∆x∆y y j−1/2
Z xi+1/2 1−(va)i,j+1/2 − (va)i,j−1/2 dx∆x∆y xi−1/2(5.37)

Now we integrate over time—the left side of our expression becomes just the differ-Chapter 5. Second- (and Higher-) Order Advection

64
ence between the new and old state.
1
n +1
n
ai,j
− ai,j
=−
∆x∆y

−

1
∆x∆y

Z tn+1 Z y j+1/2 tn

y j−1/2

Z tn+1 Z xi+1/2 tn

xi−1/2(ua)i+1/2,j − (ua)i−1/2,j dydt(va)i,j+1/2 − (va)i,j−1/2 dxdt

(5.38)We define the flux through the interface as the average over the face of that interface
and time:• x-face:⟨(ua)i+1/2,j ⟩(t) =1∆y∆t

Z tn+1 Z y j+1/2(ua)i+1/2,j dydt

(5.39)⟨(va)i,j+1/2 ⟩(t) =1∆x∆t

Z tn+1 Z xi+1/2(va)i,j+1/2 dxdt

(5.40)• y-facetn

y j−1/2

tn

xi−1/2where ⟨.⟩(t) denotes the time-average over the face. For a second-order accurate
method in time, we replace the average in time with the flux at the midpoint in time
and the average over the face with the flux at the center of the face:⟨(ua)i+1/2,j ⟩(t) ≈ (ua)in++1//22,j1(5.41)

Then we have:


n +1
n
ai,j
= ai,j− ∆t 

(ua)in++1//22,j − (ua)in−+1//22,j
1

∆x

n+ /2
n+ /2
(va)i,j+1/2 − ( va )i,j−1/2
1

1

+

1

∆y




(5.42)For the advection problem, since u and v are constant, we need to find the interface states of a alone. There are two methods for computing these interface states,1
n+1/2
ain±+1//22,j on x-interfaces and ai,j
±1/2 on y-interfaces: dimensionally split and unsplit. Dimensionally split methods are easier to code, since each dimension is operated on
independent of the others, so you can simply call a one-dimensional method for eachdirection. Unsplit methods, however, are more accurate and less susceptible to grid
effects.

5.4.1

Dimensionally split

In a split method, we update the state in each coordinate direction independently.
This is simple and a straightforward way to use one-dimensional methods in multid. To be second-order accurate in time, we do Strang splitting [77], where we alternate

5.4—Multi-dimensional advection65

the order of the dimensional updates each timestep. An update through ∆t consistsof x and y sweeps and appears as:⋆ − an
ai,j
i,j

∆t
n +1
⋆
ai,j − ai,j∆tuain++1//22,j − uain−+1//22,j
1

= −
= −

1

∆x
⋆,n+1/2⋆,n+1/2
vai,j+1/2 − vai,j−1/2∆y(5.43)(5.44)

Here, Eq. 5.43 is the update in the x-direction. In constructing the interface states,
1
1
ain++1//22,j and ain−+1//22,j , we do the exact same procedure as the one-dimensional case,constructing the left and right states at each interface and then solving the sameRiemann problem to find the unique state on the interface. Each dimensional sweep
is done without knowledge of the other dimensions. For example, in the x-update,
we are solving:at + ua x = 0(5.45)and in the y-update, we are solving:at + vay = 0(5.46)

The construction of the interface states largely mimics the one-dimensional case1
(Eq. 5.6 and 5.7). For example, the ain++1//22,j,L state is:
∆t ∂a
∆x ∂a
+
+ O(∆x2 ) + O(∆t2 )2 ∂x i,j
2 ∂t i,j
!
∆x ∂a
∂a
∆t
n
= ai,j +−u++...
2 ∂x i,j2∂x i,j


∆t
∂a
∆x
n
+...
1−
u
= ai,j +2∆x∂x i,jnain++1//22,j,L = ai,j+1

(5.47)

Notice that when substituting for ∂a/∂t, we use the one-dimensional split versionof the advection equation (Eq. 5.45) instead of the full multi-dimensional equation.
There are no y-direction terms that come into play in the split method when considering the x-direction.
The x-update (Eq. 5.43) updates the state only accounting for the x-fluxes—we denote
this intermediate state with the ‘⋆’ superscript. For the y-update, we construct ourinterface states in the analogous way as in the x-direction, but begin with the ‘⋆’ state
instead of the old-time state. In this fashion, the y-update ‘sees’ the result of thex-update and couples things together.
To achieve second-order accuracy in time, it is necessary to alternate the directions of
the sweeps each timestep, i.e., x-y then y-x. Furthermore, this pair of sweeps should
use the same timestep, ∆t.

Chapter 5. Second- (and Higher-) Order Advection

66

5.4.2

Unsplit multi-dimensional advection

The unsplit case differs from the dimensionally split case in two ways: (1) in predicting the interface states, we use knowledge of the flow in the transverse direction,and (2), only a single conservative update is done per timestep, with all directions
updating simultaneously. See [24] for more details. This idea is sometimes called the“corner transport upwind” or CTU method.
The construction of the ain++1//22,j,L interface state appears as
1

∆t ∂a
∆x ∂a
+
+ O(∆x2 ) + O(∆t2 )2 ∂x i,j
2 ∂t i,j
!
∆x
∂a
∆t
∂a
∂a
n
= ai,j
+
+
−u
−v
+...
2 ∂x i,j2∂x i,j∂y i,j


∆t ∂a
∂a
∆t
∆x
n
− v
1−
u
+...
= ai,j+2∆x∂x i,j2 ∂y i,j
{z
}
|
|
{z
}

n
ain++1//22,j,L = ai,j+1

(5.48)“transverse flux difference′′âin++1//22,j,L
1

The main difference between the split and unsplit interface states is the explicitly appearance of the “transverse flux difference” in the unsplit interface state. We rewrite
this as:∆t ∂a1
1
ain++1//22,j,L = âin++1//22,j,L − v(5.49)
2 ∂y i,jHere, the âin++1//22,j,L term is just the normal prediction without considering the transverse direction (e.g., Eq. 5.47). The basic update procedure is:1• Construct the normal predictor term, âin++1//22,j,L , in a fashion identical to the onedimensional and split methods. We compute these one-dimensional â’s at theleft and right every interface in both coordinate directions. Note that thesestates are still one-dimensional, since we have not used any information fromthe transverse direction in their computation.
1• Solve a Riemann problem at each of these interfaces:
aiT+1/2,j = R( âin++1//22,j,L , âin++1//22,j,R )
1

1

n+1/2

n+1/2

T
ai,j
+1/2 = R( âi,j+1/2,L , âi,j+1/2,R )(5.50)(5.51)(5.52)

These states are given the ‘T ’ superscript since they are the states that are usedin computing the transverse flux difference.
• Correct the previously computed normal interface states (the â’s) with the transverse flux difference:TT∆t ai,j+1/2 − ai,j−1/2
n+1/2
n+1/2
ai+1/2,j,L = âi+1/2,j,L − v
2∆y(5.53)

5.4—Multi-dimensional advection

67

Notice that the fluxes that are differenced for the left state are those that aretransverse, but to the left of the interface. Similarly, for the right state, it would
be those that are transverse, but to the right of the interface:TT∆t ai+1,j+1/2 − ai+1,j−1/2
n+1/2
n+1/2
ai+1/2,j,R = âi+1/2,j,R − v
2∆y(5.54)

A similar procedure happens at the y-interfaces.
Figure 5.13 illustrates the steps involved in the construction of the ain++1//22,j,L state.
1

Once all of the full states (normal prediction + transverse flux difference) are computed to the left and right of all the interfaces (x and y), we solve another Riemannproblem to find the final state on each interface.
ain++1//22,j = R( ain++1//22,j,L , ain++1//22,j,R )1

1

1(5.55)

The final conservative update is then done via Eq. 5.38.
See [24] for more details on this unsplit method, and [66] for details of the extension
to 3-d.
Figures 5.14 and 5.15 show the advection of a smooth Gaussian and a discontinuous
tophat diagonally on a coarse 32 × 32 zone domain. Each show a diffusion of theinitial function, similar to what we saw in 1-d. In the tophat, we also see a slightundershoot on the trailing side of the tophat after one period.

5.4.3

Timestep limiter for multi-dimensions

The timestep criterion we used in one-dimension (Eq. 4.5) needs to be generalized
for multi-dimensions. For the dimensionally split case, since we are basically piecing
together two one-dimensional sweeps, the timestep limit is usually taken as:


∆x ∆y
,
(5.56)∆t = C min|u| |v|
This is, for example, the construction that is used with the dimensionally-split hydrodynamics solver in the original Flash code [34]* . Stability requires picking a CFL
number, C ≤ 1.
A general extension of the timestep restriction for a fully-multi-dimensional algorithm is often written in the form (see, e.g., [71])∆t = Cd|U · e |∑ ∆xddi =1* although, the paper does not explicitly write this out! −1(5.57)

Chapter 5. Second- (and Higher-) Order Advection

68

ai,j+1j+1

n+1/2

âi,j+1/2,R
n+1/2

âi,j+1/2,L
n+1/2

âi+1/2,j,L

ai,j

j

ai+1,j

n+1/2

âi,j−1/2,R
n+1/2

âi,j−1/2,Lai,j−1

j−1

i−1

i

i+1

ai,j+1j+1

aTi,j+1/2

n+1/2

âi+1/2,j,L

ai,j

j

ai+1,jaTi,j−1/2

ai,j−1

j−1

i−1

i

i+1

Figure 5.13: The construction of the ain++1//22,j,L state. Top: first we compute the â’s—here
we show all of the â’s that will be used in computing the full left interface state at (i +1/2, j ). Bottom: after the transverse Riemann solves, we have the two transverse states
n+1/2
T
T
(ai,j
+1/2 and ai,j−1/2 ) that will be differenced and used to correct âi +1/2,j,L (illustrated by1

the dotted lines) to make ain++1//22,j,L .
1

5.4—Multi-dimensional advection

69

density

1.0

density

1.0

1.8
0.8

1.8

0.8

0.6

1.6

0.6

0.4

1.4

1.7

1.5

y

y

1.6

1.4

0.4

1.3
1.2

0.2

1.2

0.2

1.1
0.0
0.0

0.2

0.4

t = 0.00000

x

0.6

0.8

1.0

1.0

0.0
0.0

0.2

0.4

t = 1.00000

x

0.6

0.8

1.0

1.0

Figure 5.14: Advection of a Gaussian profile with u = v = 1 for one period on a
32 × 32 grid, with C = 0.8. This was run with pyro as ./pyro.py advection smooth
inputs.smoothdensitydensity

1.0

1.0

0.8

0.8

0.8

0.8

0.6

0.6

0.6

0.6

0.4

0.4

0.4

0.2

0.2

0.2

0.0
0.0

0.0

0.0
0.0

1.0

y

y

1.0

0.4
0.2
0.0

0.2

t = 0.00000

0.4

x

0.6

0.8

1.0

t = 1.00000

0.2

0.4

x

0.6

0.8

1.0

Figure 5.15: Advection of a tophat function with u = v = 1 for one period on a 32 × 32
grid, with C = 0.8. This was run as ./pyro.py advection tophat inputs.tophat

where d is the coordinate direction, U = (u, v) is the velocity vector, and ed is theunit vector in direction d. For these methods C ≲ 1. This is usually more restrictive
than Eq. 5.56.
For the CTU method described above, [24] argues that the inclusion of the transverse
information removes some of the some of the instability inherent in simpler schemes,
allowing for a larger timestep, restricted by Eq. 5.56.
Note, because of the different form of the timestep limiters here, it is not enoughto simply cite a CFL number when describing results, you must also explain which
form of the timestep calculation (Eq. 5.56 or Eq. 5.57) is being used.

Chapter 5. Second- (and Higher-) Order Advection

70

5.4.4

Method-of-lines in multi-dimensions

The multidimensional version of method-of-lines integration follows the ideas fromthe one-dimensional case. We can start with Eq. 5.37, and define the fluxes overthough a face as:• x-face:1⟨(ua)i+1/2,j ⟩ =∆y

Z y j+1/2(ua)i+1/2,j dy(5.58)

1⟨(va)i,j+1/2 ⟩ =∆x

Z xi+1/2(va)i,j+1/2 dx(5.59)• y-facey j−1/2

xi−1/2

These are similar to the expressions above, except there is no integral over time.
Again, to second order in space, we can just use the flux evaluated at the midpointin the face:⟨(ua)i+1/2,j ⟩ ≈ (ua)i+1/2,j(5.60)The result is the ODE:(ua)i+1/2,j − (ua)i−1/2,j (va)i,j+1/2 − (va)i,j−1/2
dai,j
=−
−
dt
∆x
∆y

(5.61)For the interface states, we separately construct slopes in each dimension: ∆(x) ai,jis the slope in the x-direction, and ∆(y) ai,j is the slope in the y-direction. Then theinterface states are:1 (x)ai+1/2,j,L = ai,j + ∆ai,j2
1 (x)ai+1/2,j,R = ai+1,j − ∆ai+1,j2(5.62)(5.63)and1 (y)ai,j+1/2,L = ai,j + ∆ai,j2
1 (y)ai,j+1/2,R = ai,j+1 − ∆ai,j+12(5.64)(5.65)

With these interface states, we have the method for evaluating the righthand side of
our ODE. We can then evolve the ODE using a Runge-Kutta integration method. At
each stage of the RK integration, we do the same construction of the interface states,
solve the Riemann problem, etc. Notice that unlike the directionally-split method,
we are doing the update in both directions at the same time—we are relying on the
ODE integrator to do the coupling in the different directions for us.
This construction is a lot simpler than the unsplit method described previously. The
cost of this simplicity is a reduced range of stability.

5.5—High-Order Finite difference methods

71

Performaing the stability analysis here is much more complicated. For simplicity,
consider a simple first-order upwind scheme in two-dimensions. Higher order time
integrators (like RK4) will have separate stages that look like a first-order-in-time
update, so this stability analysis can be thought of as applying to a single stage. Our
difference equation is:
n +1
n
ai,j
− ai,j∆t= −un − anai,ji −1,j∆x−v

n − an
ai,j
i,j−1

∆y

(5.66)

We introduce a single-mode Fourier function, as before, but this time with a mode ineach direction:nai,j= An e Iiθ e I jϕ
(5.67)
Next, to simplify things, we’ll assume that u = v, and ∆x = ∆y, then C = u∆t/∆x =v∆t/∆y. Inserting this into our difference equation gives:
A n +1
− Iθ
− Iϕ
=
1
−
C
1
−
e
−
C
1
−
e
An

(5.68)

This form looks very close to the one-dimensional case, but it is difficult to analytically find the values of C , but we can numerically find the maximum | An+1 /An |2for θ ∈ [0, 2π ] and ϕ ∈ [0, 2π ] as a function of C . In doing this, we find that thisdiscretization is unstable (| An+1 /An |2 > 1) for C > 1/2† .
This restriction is 1/d, where d is the dimensionality, and it is analogous to thedifference between the timestep limits for stability from the more generous Eq. 5.56
to the more restrictive Eq. 5.57. This reduced C for stability is discussed in [71] (seesection 4), and is also discussed in [52, 81]. Different reconstruction and integration
methods can vary this limit some, for instance, the fourth-order method in [52] allows
for ∆t ∑id=1 (|U · ed |)/∆xd ≲ 1.4. Total variation diminishing Runge-Kutta methods
are popular for this application [39].

5.5High-Order Finite difference methods

Chapter 4 introduced numerical methods for the linear advection equation
at + ua x = 0(5.69)

that were first or second order in space. The advantages of using numerical methods
that are higher order can be large, especially when in regions where the flow issmooth. However, these must be balanced against the additional computational costand complexity. In addition, many higher order methods do no better than second
order methods in cases with discontinuities.
† See the script cfl.py

Chapter 5. Second- (and Higher-) Order Advection72
density

1.0

1e7

density

1.0

8

0.7

6
0.8

0.8

4
2

0.6

0.4

y

y

2
4

0.2

0.5

0.6

0
0.4

0.6

0.4

0.3
0.2

0.2

6
0.0
0.0

0.2

t = 1.00000

0.4

x

0.6

0.8

1.0

8

0.1
0.0
0.0

0.2

t = 1.00000

0.4

x

0.6

0.8

1.0

0.0

Figure 5.16: Advection of a tophat function using the method-of-lines approach with
4th-order Runge-Kutta time integration. We use u = v = 1 for one period on a 32 × 32
grid. On the left is C = 0.8—this is clearly unstable. On the right is C = 0.4, which isstable. This was run as ./pyro.py advection_rk tophat inputs.tophat

5.5.1

The problem with higher-order finite volume methods

The finite volume approach outlined in chapter 3 matches the physics of hyperbolicbalance laws perfectly, by maintaining the conservation of appropriate quantities
using the fluxes through the surfaces of each control volume or computational cell.
However, this leads to significant computational costs and complexities when going
beyond second order methods.
The inter-cell fluxes are computed by integrals over the face of the computational
cell. In one dimension the face is a single point and the integral needs the flux
evaluated at a single point, as in equation 3.14. In higher dimensions the face is
one dimensional (e.g., a line) or two dimensional (e.g., a square) and so the integral
must be approximated by evaluating the flux at multiple points. If we use Gauss
quadrature, this means that a third order method would require at least two flux
evaluations per face in two dimensions, and typically four evaluations per face inthree dimensions.

5.5.2

Finite differences

The conservative finite difference method starts from the endpoint for finite volume
methods, by considering the update formula (3.14)∂ ⟨ U ⟩i1 =−F 1 − Fi−1/2 .
∂t∆x i+ /2

(3.14)In the finite difference method a interpretation used is different. We are now thinkingof1 
F 1 − Fi−1/2(5.70)∆x i+ /2

5.5—High-Order Finite difference methods73

as representing a direct approximation to the derivative of the flux at xi . In particular,
we are not thinking of Fi+1/2 as being directly linked to the flux. Crucially the updatestill ensures global conservation, as the “flux” term is re-used for neighbouring points
in the same way as in the finite volume case.
When we combine this viewpoint with the Method of Lines approach in section 5.3,
the implementation of a high-order finite boils down to• using a high-order time integration scheme (such as a high order Runge-Kutta
method);• finding a way that the finite difference in equation (5.70) approximates thederivative of the flux both stably, and to a sufficiently high order.

5.5.3

WENO reconstruction

For the advection equation with constant advection speed u, our higher-order method
requires us to find a high-order approximation to ai+1/2 . If we considered the five
points a j , j ∈ [i − 2, . . . , i + 2] then we could use the information from all five of thesepoints to approximate ai+1/2 as(Fifth)1
ai+1/2 = 60
(2⟨ a⟩i−2 − 13⟨ a⟩i−1 + 47⟨ a⟩i + 27⟨ a⟩i+1 − 3⟨ a⟩i+2 ) + O(∆x5 ).

(5.71)

Alternatively we could use only three of the points, in three different ways:(Third,2)

ai+1/2(Third,1)

ai+1/2(Third,0)

ai+1/2= 61 (2⟨ a⟩i−2 − 7⟨ a⟩i−1 + 11⟨ a⟩i ) + O(∆x3 ),(5.72a)= 16 (−⟨ a⟩i−1 + 5⟨ a⟩i + 2⟨ a⟩i+1 ) + O(∆x3 ),(5.72b)= 61 (2⟨ a⟩i + 5⟨ a⟩i+1 − ⟨ a⟩i+2 ) + O(∆x3 ).

(5.72c)Which is better? The five point stencil gives higher order accuracy, but includes
information from both sides of the point. This ignores information from the characteristics and, near discontinuities, will lead to Gibbs oscillations. The three pointstencils give lower accuracy. However, they give us the flexibility to choose a stencil toavoid discontinuities, possibly using the characteristic information. The advantagesof the higher-order methods are illustrated by reconstructing a smooth function infigure 5.17. The disadvantages of using a fixed stencil are illustrated by reconstructing a non-smooth function in figure 5.18.
Exercise 5.5
Check that equations (5.71) and (5.72) give the claimed order of accuracy
results.

Chapter 5. Second- (and Higher-) Order Advection

74
1.00
0.75
Smooth function

0.50
0.25
0.00
0.25
0.50
0.75
1.00
0.0

0.2

0.4

x

0.6

0.8

1.0

10 3
10 4
10 5
10 6

10 9

stencil 5
WENO
stencil 3 (0)stencil 3 (1)stencil 3 (2)
x3
x5

10 11
10 13
10 3

x

|Error|2|Error|1

10 7
10 8
stencil 5
WENO
stencil 3 (0)stencil 3 (1)stencil 3 (2)
x3
x5

10 10
10 12
10 14

10 2

10 3

x

10 2

Figure 5.17: A smooth sine function is reconstructed on the unit interval from the(integral-average) data, at the blue circles in the top plot, to the right, at the red triangles in the top plot. The convergence rate with grid resolution for the 5 point stencil
of equation (5.71) and the 3 point stencils of equation (5.72) are shown to match expectations in the bottom plots. The error from the WENO reconstruction described in
section 5.5.3 is, on this smooth function, converging with the expected order but larger
in magnitude.

The method of choosing the “best” stencil (to avoid discontinuities as far as possible)
is called Essentially Non-Oscillatory (ENO) reconstruction. It is not as accurate as it
could be given the size of the stencil it uses, and the logical branches required to findthe “best” stencil can reduce computational performance.
An alternative that avoids the problems of ENO schemes are the Weighted ENO, or
WENO, schemes. These use a combination of the possible ENO stencils to reconstructai+1/2 . This relies on the observation that there are constants Ck such that, for example,2

ai+1/2 = ∑ Ck ai+1/2(Fifth)k =0(Third,r ).

(5.73)

5.5—High-Order Finite difference methods

75

Exercise 5.6
3
1
Check that the constants C0 = 10
, C1 = 35 , C2 = 10
make equation (5.73)
consistent with equations (5.71) and (5.72).

The WENO methods work by retaining the sum over all stencils as in equation (5.73),
but adjusting the weights to avoid oscillations. Ideally, in regions where the a(0,1)
stencils include a shock but the a(2) stencil does not the weights should be C̃0 = 0 =C̃1 and C̃2 = 1. In order for this sum to make sense we will need the weights to add
to 1.
WENO algorithm
We can now write out the full WENO algorithm of order (2r − 1). The constant r
sets the size of the individual stencils as well as the (optimal) order of the scheme.
This section mostly uses the notation of Gerolymos et al. [36], and we will drop theintegral average notation (so ⟨ a⟩i will be denoted ai ).
First compute the individual stencils
r −1

ar,k,i+1/2 = ∑ Ar,k,ℓ ai+k−ℓ ,ℓ=0

k = 0, . . . , r − 1.

(5.74)

Here the Ar,k,ℓ terms are constants which, for given scheme accuracy r are needed tocompute the kth stencil.
We then want to combine these individual stencils to compute the WENO result. For
this we writer −1ar,WENO,i+1/2 = ∑ ωr,k,i+1/2 ar,k,i+1/2 .

(5.75)

k =0

Here the ωr,k,i+1/2 terms are the weights that vary from point to point. They mustsum to one, so that we have a convex combination of the stencils:r −1∑ ωr,k,i+ / = 1.
1 2

(5.76)

k =1

We also want the weights to match the optimal weights Cr,k in smooth regions. The
optimal weights are defined such thatr −1

ar,WENO,i+1/2 = ∑ Cr,k ar,k,i+1/2(5.77)

k =0

is accurate to order O(∆x (2r−1) ) when q is smooth.
The choice of how to get from the optimal weights Cr,k to the nonlinear weights
ωr,k,i+1/2 defines the WENO scheme. The standard choice of Jiang and Shu is toChapter 5. Second- (and Higher-) Order Advection

76

1.00

1.0

0.75
0.50
0.25
0.0

0.00

Non-smooth function

5 point stencil

0.5

0.25
0.5

0.50
0.75

1.0

1.00
Jiang-Shu 0
Jiang-Shu 1
Jiang-Shu 2

1.0

3 point stencils

0.5

5
4

0.0

3

0.5

2

1.0
1
1.5
0
Optimal weight C0
Optimal weight C1
Optimal weight C2
WENO weight 0
WENO weight 1
WENO weight 2

1.00
0.75

0.25

0.8
0.6

0.00

C,

WENO stencils

0.50

1.0

0.4

0.25
0.50

0.2

0.75
0.0

1.00
0.0

0.2

0.4

x

0.6

0.8

1.0 0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 5.18: A non-smooth function is reconstructed on the unit interval. The 5 pointstencil of equation (5.71) and the 3 point stencils of equation (5.72) both show oscillations near the discontinuity, whilst the WENO reconstruction does not. The WENO algorithm depends on measuring the smoothness of the function. The Jiang-Shu smoothness indicators β are mostly zero, but spike near the discontinuity. This feeds into theweight ω that the WENO algorithm gives to each 3 point stencil it uses. Away from thediscontinuity the weights revert to the optimal C weights, but near the discontinuity asingle ω weight dominates meaning only a single 3 point stencil is used.

5.5—High-Order Finite difference methods

77

introduce a measure of the smoothness of the kth stencil by computing the sum of
the integral averages of its derivatives from order 1 up to order 2r − 1. For practicalimplementation purposes this means computing the smoothness indicators β r,k,i+1/2 as
β r,k,i+1/2 = σr,k,ℓ,m ai+k−ℓ ai+k−m .

(5.78)The terms σr,k,ℓ,m are pre-computed constants which give the coefficients in the quadratic
form for the kth stencil of width r in the reconstruction. These smoothness indicators
are non-negative, and will be large when the derivatives are large in magnitude. The
Jiang and Shu weights are then set byωr,k,i+1/2 =αr,k,i+1/2,
r −1∑k=0 αr,k,i+1/2(5.79a)αr,k,i+1/2 =Cr,k.
ϵ + β2r,k,i+1/2(5.79b)

Here ϵ is a small number introduced to avoid division-by-zero problems. The formof ωr,k,i+1/2 in equation (5.79a) guarantees that the convex sum condition in equation (5.76) holds. The form of αr,k,i+1/2 ensures that when all the smoothness indicators β r,k,i+1/2 are the same magnitude the weights ωr,k,i+1/2 will match the optimal
weights Cr,k , but when a smoothness indicator is large (i.e., when the associated stencil has large derivatives, typically associated with discontinuities), the contributionof its associated stencil will be small. An example of this is shown in figure 5.18.
Finally, we note that this method has reconstructed ai+1/2 from the left. For the advection equation case where the advection speed u is positive this is all we need: thecharacteristic information tells us that we should use this reconstruction. In the casewhere the advection speed is negative we should reconstruct from the right. In theimplementation it is easiest to implement only one reconstruction direction and pass
the data in in reverse order.
Exercise 5.7
Taking the values for the C, A and σ constants from Gerolymos et al. or
Shu’s review [72], construct a WENO reconstruction method for r = 2.
Check your results on smooth and non-smooth functions.

Implementation issues with WENO schemes
A convergence test on the WENO schemes with r = 3 and r = 5 is shown in figure 5.19. This should be compared to figure 5.9, as in both a Gaussian profile isadvected five times around a periodic domain. The WENO schemes show higher
absolute accuracy for moderate size grids (N ≳ 100) and show faster convergence.

Chapter 5. Second- (and Higher-) Order Advection

78

Convergence of Gaussian, RK4
10-2

O(∆x 5 )O(∆x 4 )WENO, r = 3
WENO, r = 5

ka final − a init k 2

10-3
10-4
10-5
10-6

6 × 101

N

102

Figure 5.19: WENO solutions for advecting a Gaussian five periods, using two different
orders. A fourth order Runge-Kutta method is used for time evolution. For r = 3 we
see the expected fifth (2r − 1) order convergence. For r = 5 we see fourth order, rather
than the expected ninth order, convergence. This is as the error from the time integrator
dominates.
hydro_examples: weno.py

ÏHowever, it is clear that whilst the r = 3 method converges at fifth order as expected,
the r = 5 WENO method does not converge at ninth order but at fourth order. Thisis explained by the time integrator. We remember that any solver has an error bothfrom the spatial and the time discretization. In figure 5.19 the time integrator isthe classic fourth order Runge-Kutta, and it is the error from this integrator that is
dominating.
To confirm this, figure 5.20 uses the eigth order Dormand-Price Runge-Kutta methodwith adaptive step size control (using the scipy.integrate.ode routine). Here wesee high order convergence for all r, and in each case the convergence rate is 2r − 2
for no reason I can understand.

5.6

Going further• Slope limiting: there are a wide variety of slope limiters. All of them are designed to reduce oscillations in the presence of discontinuities or extrema, butsome are higher-order and can be less restrictive when dealing with smooth
flows. Most hydro texts (e.g. [46, 82]) provide an introduction to the design ofsuch limiters.
• Multi-dimensional limiting: the procedure described above still does the limiting

5.6—Going further

79

Convergence of Gaussian, DOPRK8

10-1
10-2

ka final − a init k 2

10-3
10-4
10-5
10-6
10-7
10-8
10-9

O(∆x 4 )O(∆x 6 )O(∆x 8 )O(∆x 10 )WENO, r = 3
WENO, r = 4
WENO, r = 5
WENO, r = 6
3 × 101 4 × 101

6 × 101
N

102

Figure 5.20: WENO solutions for advecting a Gaussian one periods, using four different orders. An eighth order Dormand-Price Runge-Kutta method is used for time
evolution. This minimizes the time integrator error and we see convergence at order
2r − 2 for all schemes, although the time integrator error eventually shows in the highest order case.
hydro_examples: weno.pyÏin each dimension independent of the other when doing the unsplit reconstruction. This can lead to overshoots/ undershoots. An example of a method thatconsiders the limiting in multi-dimensions is [11, 51].
• Spatially-varying velocity field: if we consider a spatially varying velocity field,u( x, y) and v( x, y) that is specified externally, then we can describe the advection of a quantity ϕ as:
ϕt + (ϕu) x + (ϕv)y = 0(5.80)The solution procedure is largely the same as described above. We write:∆x ∂ϕ ∆t ∂ϕ
+
+...
2 ∂x
2 ∂t

∆x ∂ϕ ∆t n
= ϕi,j++−(ϕu) x − (ϕv)y i,j
2 ∂x
2



∆x
∆t
∂ϕ ∆t
∆t 
n
= ϕi,j +1−ui,j− [ϕu x ]i,j −(ϕv)y i,j
2
∆x
∂x
2
2
|
{z
}

n
ϕin++1//22,j,L = ϕi,j+1(5.81)

ϕ̂in++1//22,j,L
1

and upwinding is used to resolve the Riemann problem for both the transverse
and normal interface states. This type of construction comes up in low Mach
number flows, where the density can be advected according to the velocity fieldin much the fashion shown here, and is described in § 15.3.2.

Chapter 5. Second- (and Higher-) Order Advection

80

For compressible hydrodynamics, we often have density-weighted quantities
that we advect. This extension is described in § ??.

5.7

pyro experimentation

To gain some experiences with these ideas, we can use the advection solver in pyro(see Appendix B to get started). The pyro advection solver implements the secondorder unsplit advection algorithm described in the previous sections. To run thissolver on the Gaussian advection problem, do:./pyro.py advection smooth inputs.smooth
By default, this will advect a Gaussian profile diagonally across the domain for asingle period.
To get a feel for the advection algorithm, here are some suggested exercises:
Exercise 5.8
Implement a tophat initial profile and run with and without limiters (thisis controlled by the advection.limiter runtime parameter).

Exercise 5.9
Look at the solution when you advect purely in the x- or y-direction andcompare to the diagonal case—notice how the direction affects the error in
the solution. This is the imprint of the grid we discretize on.

Exercise 5.10
Implement a dimensionally-split version of the advection algorithm andcompare the results to the unsplit version. Pick a suitable norm andmeasure the convergence of the methods.

Chapter

6

Burgers’ Equation
6.1

Burgers’ equation

The inviscid Burgers’ equation is the simplest nonlinear hyperbolic equation:
ut + uu x = 0(6.1)

Here u is both the quantity being advected and the speed at which it is moving.
Recall that for the linear advection equation, we saw that the solution was constantalong lines x = ut + x0 , which are parallel, since u is spatially constant. For Burgers’
equation, this is no longer the case, and the characteristic lines are now given by
dx/dt = u, with x (0) = x0 . Since u = u(t), we cannot integrate this directly.
Exercise 6.1
To find the lines along which the solution to Burgers’ equation is constant,consider the full change in u:
du =

∂u
∂u
dt +
dx = 0
∂t x
∂x t

(6.2)

Here, we seek u = constant, so we set du = 0. Now, using the Burgers’ equation itself, show that this implies that the lines along which thesolution is constant are:dx
= u( x, t)(6.3)
dt
If we take u0 = u(t = 0), then we can look at how the characteristic behave over asmall time interval (before u( x, t) changes significantly). Figure 6.1 shows the behavior for an initial velocity with sinusoidal profile. We see that after a short period of
git version: 64c838dee1a8 . . .

81

Chapter 6. Burgers’ Equation

82

1.0
0.8

u

0.6
0.4
0.2
0.0
0.0

0.2

0.4

0.2

0.4

x

0.6

0.8

0.6

0.8

1.0

1.0
0.8

t

0.6
0.4
0.2
0.0
0.0

x

1.0

Figure 6.1: (top) Initially sinusoidal velocity distribution (bottom) Approximate characteristic structure for Burgers’ equation, using u0 = u(t). Note that after a shortperiod of time, the characteristics intersect, signaling the formation of a shock.

time, the characteristics intersect. At the point, ( xs , ts ) where they intersect, there is
no way to trace backwards along the characteristics to find a unique initial state. Thismerging of the characteristics in the x-t plane is a shock, and represents just one waythat nonlinear problems can differ from linear ones.
Another type of wave not present in a linear system is a rarefaction. Figure 6.2 shows
initial conditions of slower velocity to the left of faster velocity. We see that thecharacteristics diverge in this case, and we will be left with having to fill in thesolution inbetween as some intermediate state.
In conservative form, Burgers’ equation appears as:ut + 1 2
2u x = 0(6.4)

The solution of this follows the same methodology as described in Chapter 4. Theinterface states are predicted as to second order by Taylor expanding in space and6.1—Burgers’ equation

83

1.0
0.8

u

0.6
0.4
0.2
0.0
0.0

0.2

0.4

0.2

0.4

x

0.6

0.8

0.6

0.8

1.0

1.0
0.8

t

0.6
0.4
0.2
0.0
0.0

x

1.0

Figure 6.2: (top) Initially discontinuous velocity distribution with low velocity leftof high velocity (bottom) Approximate characteristic structure for Burgers’ equation,using u0 = u(t). Note that after a short period of time, the characteristics diverge—thisis a rarefaction.

time:∆x ∂u ∆t ∂u
+
+...
2 ∂x
2 ∂t i∆x ∂u ∆t∂un= ui +
+
− ui
+...
2 ∂x
2
∂x i


∆x
∆t
∂u
n
= ui +
+...
1−
ui
2
∆x
∂x i

uin++11/2,L = uin +

(6.5)
(6.6)
(6.7)

The only difference with the linear advection equation is that now ui ∆t/∆x varies
from zone to zone, whereas with linear advection, it is the constant C. The slopes arecomputed using the same limiters as with linear advection.
The Riemann problem differs from linear advection. As we saw above, the characteristic curves can intersect in the x-t plane, and it is not possible to trace backwardfrom time to learn where the flow originated. This is the condition for a shock.

Chapter 6. Burgers’ Equation

84

tshock: S = ∆x/∆t

tn+1
ul
f = f(ul )f = f(ur )

ur
tn

xl

xr

x

Figure 6.3: A rightward moving shock in the x-t plane separating two states: ul andur .

The shock speed is computed through the Rankine-Hugoniot jump conditions. For ascalar equation, these are easy to construct. We’ll follow the method of [46]. Figure 6.3 shows two states separated by a rightward moving shock in the x-t plane. At
time tn , the state in our interval (x ∈ [ xl , xr ]) is entirely ur . As time evolves, we imagine our interval [ xl , xr ] moving vertically upwards in the diagram, and we see that it
contains a mix of states ul and ur . Finally, at time, tn+1 it is entirely ul . The shock
moves with a speed S = ∆x/∆t in this figure. To determine the speed, we integrate
our conservation law over both space and time (and normalize by ∆x = xr − xl ):
1
∆x

Z xr
xl

dx

Z t n +1tn

1dt ut = −
∆x

Z xr
xl

dx

Z t n +1tn

dt [ f (u)] x(6.8)

Doing the t integral on the left and x integral on the right, we have1∆x

Z xr nxl

Z t n +1o1u(tn+1 ) − u(tn ) dx = −{ f (u)| x=xr − f (u)| x=xl } dt
∆x tn

(6.9)

Recognizing that at t = tn , u = ur and at t = tn+1 , u = ul , in the left side becomes1∆x

Z xr nxlou(tn+1 ) − u(tn ) dx = {u(tn+1 ) − u(tn )} = ul − ur .

(6.10)For the right side, we see that all along x = xl the flux is f = f (ul ) for t ∈ [tn , tn+1 ].
Likewise, all along x = xr , the flux is f = f (ur ) in the same time interval (see the6.1—Burgers’ equation

85

figure). Therefore, our expression becomes:( u l − ur ) = −∆t[ f (ur ) − f (ul )]∆x(6.11)

and using S = ∆x/∆t, we seeS=f ( ur ) − f ( u l )ur − u l(6.12)For Burgers’ equation, substituting in f (u) = u2 /2, we getS=1( u + ur )2 l

(6.13)

With the shock speed known, the Riemann problem is straightforward. If there is ashock (compression, so ul > ur ) then we compute the shock speed and check whether
the shock is moving to the left or right, and then use the appropriate state. If there is
no shock, then we can simply use upwinding, as there is no ambiguity as to how to
trace backwards in time to the correct state. Putting this together, we have: ul if S > 0
us =u if S < 0 r
0 if S = 0

if ul > ur :(shock) ul if ul > 0
us =u if ur < 0 r
0 otherwise

otherwise :(6.14)(6.15)

Once the interface states are constructed, the flux is calculated as:
Fin++1//2 2 =1and the conservative update is
uin+1 = uin +1  n+1/2 2u
2 i+1/2

∆t  n+1/2
1
Fi−1/2 − Fin++1//2 2∆x(6.16)(6.17)The timestep constraint now must consider the most restrictive Courant condition
over all the zones:∆t = min {∆x/ui }(6.18)i

Figure 6.4 shows the solution to Burgers’ equation using the 2nd-order piecewise
linear method described here, with the MC limiter. The initial conditions chosen are
all positive velocity, with a lower velocity to the left of the higher velocity. As theChapter 6. Burgers’ Equation

86

2.0
1.8

u

1.6
1.4
1.2
1.0
0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 6.4: Solution to the inviscid Burgers’ equation with 256 zones and a Courant
number, C = 0.8 for initial conditions that generate a rarefaction: the left half of thedomain was initialized with u = 1 and the right half with u = 2. This initial velocity
state creates a divergent flow. The curves are shown 0.02 s apart, with the darker
grayscale representing later in time.
hydro_examples: burgers.py

Ïsolution evolves, the state on the right will rush away from the state on the left, andspread out like a fan. This is called a rarefaction wave or simply a rarefaction.
Figure 6.5 shows the solution to Burgers’ equation with initially sinusoidal data:u( x, t = 0) =









1

1 + 2 sin







1


2π ( x −1/3)
1/3

1

x < 1/3

1/3 ≤ x ≤ 2/3(6.19)

x > 2/3

This is analogous to the case shown in Figure 6.1—we see the solution steepen andform a shock which propagates to the right. The shock is practically infinitesimallythin here, since there is no explicitly viscosity to smear it out* .

* Numerical diffusion, in the form of truncation error of our method, will smear things a little.

6.1—Burgers’ equation

87

1.4

u

1.2
1.0
0.8
0.6
0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 6.5: Solution to the inviscid Burgers’ equation with 256 zones and a Courant
number, C = 0.8. The initial conditions here are sinusoidal and the solution quickly
steepens into a shock.The curves are shown 0.02 s apart, with the darker grayscale
representing later in time.
hydro_examples: burgers.pyÏ

Exercise 6.2
Extend your 1-d finite-volume solver for advection (from Exercise 5.1) tosolve Burgers’ equation. You will need to change the Riemann solver anduse the local velocity in the construction of the interface states. Run theexamples shown in Figures 6.4 and 6.5.
As we’ll see shortly, these two types of waves can also appear in the Euler equations
for hydrodynamics.
A final thing to note is that we solved Burgers’ equation in conservative form. For
shock solutions, this is essential, since as we noted earlier, that finite-volume method
relates to the integral form of the PDEs, the discontinuity is nicely handled by
the Riemann solver. We could also imagine differencing Burgers’ equation in nonconservative form, i.e., starting with:
ut + uu x = 0(6.20)

If you did this (for instance, using a finite difference scheme and an upwind difference for u x ), you would find that you get the wrong shock speed.

Chapter 6. Burgers’ Equation

88
Exercise 6.3

Using a simple first-order finite-difference method like we describedin Ch. 4 for linear advection, difference the conservative and nonconservation formulations of Burgers’ equation as:
uin+1 − uin
1 (uin )2 − (uin−1 )2
=−
∆t
2
∆x

(6.21)andun (un − uin−1 )uin+1 − uin=− i i∆t∆x(Note: these discretizations are upwind so long as u > 0).
Run these with the shock initial Riemann conditions:
 2 x < 1/2u( x, t = 0) =
 1 x > 1/2(6.22)(6.23)and measure the shock speed from your solution by simply differencing
the location of the discontinuity at two different times. Compare to theanalytic solution for a shock for the Riemann problem.

6.2

Characteristic tracing

A concept that will be useful in the next section is characteristic tracing. The idea
is that we only include information in the interface states if the characteristic thatcarries that information is moving toward the interface. For Burgers equation, thisis simple, since there is only a single characteristic—the velocity. So for the left state
on an interface, we’d only add the change if the velocity ui > 0 (moving toward theinterface i + 1/2):


∆x
∆t
∂u
n +1
n
ui+1/2,L = ui +1−
max(0, ui )+...
(6.24)
2∆x∂x i
Notice that the effect of this is to set the interface state simply to the value given by
the piecewise linear reconstruction on the interface if the wave isn’t moving to theinterface.

6.3

Going further• The equation we’ve been dealing with here is the inviscid Burgers’ equation.
The full Burgers’ equation includes viscosity (a velocity diffusion):
ut + uu x = ϵu xx(6.25)

6.4—WENO methods, nonlinear equations, and flux-splitting

89

To solve this, we need to first learn about techniques for diffusion, and then
how to solve equations that span multiple PDE types. This will be described in§11.3.
• Aside from pedagogical interest, Burgers’ equation can be used as a simple
model of traffic flow (where shocks can arise from people slamming on thebrakes). Many sources discuss this application, including the text by [46].

6.4

WENO methods, nonlinear equations, and flux-splitting

For a nonlinear scalar conservation law
ut + f (u) x = 0(6.26)

the WENO method introduced in section ?? above does not work, as we have assumed the characteristic information travels in one direction only. We have also
reconstructed the variable q and from that constructed the “flux” which we feed into
the differencing formula of equation (5.5) to update the solution: this will not work
either.
In the nonlinear case, we instead reconstruct the flux directly. That is, given the stateui at location xi , we compute the flux f i = f (ui ) and reconstruct the flux f i+1/2 using
the WENO reconstruction above.
This has the significant problem that we have no characteristic information for theflux: does it propagate to the left or to the right? To get around this we introduce
flux splitting. We write(6.27)
f (u) = f (+) (u) + f (−) (u)where we choose the functions such that the information contained in f (+) propagates to the right and that in f (−) propagates to the left. There are many ways of
doing this, but the simplest is the Lax-Friedrichs flux splitting
f (±) (u) = 21 ( f (u) ± αu)(6.28)

where α ≥ max |∂u f |. With α being larger than the maximum propagation speed,
this means that∂u f (+) ≥ 0, ∂u f (−) ≤ 0,
(6.29)and the characteristic information contained in f (±) will propagate as required.
The simplest flux-split algorithm is then
1. Compute the maximum characteristic speed α over the entire computationalgrid;
2. Compute the split fluxes f (±) from equation (6.28);

Chapter 6. Burgers’ Equation

90

High resolution
PLM, MCWENO, r=3
WENO, r=5

1.4

u

1.2
1.0
0.8
0.6

0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90
xFigure 6.6: Numerical solutions to Burgers’ equation using the piecewise linear
method as in figure 6.5 and two flux-split WENO methods as outlined in section 6.4.
This uses the same sinusoidal data as figure 6.5 shortly after shock formation. Notethat the WENO methods are not obviously any better at resolving the shock than thesimpler piecewise linear approach.
hydro_examples: weno_burgers.py

Ï

3. Reconstruct f (+) to the right using, e.g., the WENO algorithm of section 5.5.3;
4. Reconstruct f (−) to the left using the same method;
(+)

(−)

5. Compute f i+1/2 = f i+1/2 + f i+1/2 ;6. Update the state using equation (3.14).
As a direct comparison between the piecewise linear method used at the start ofthis chapter, and the more complex WENO methods introduced here, we start withlooking at a shock forming from smooth initial data. Figure 6.6 shows the evolutionof the sinusoidal initial data as used in figure 6.5, but only showing the result at one
time, shortly after characteristic crossing leads to a shock. We see that there is very
little difference between the different numerical methods. The characteristic focusingmeans that all the methods have a similar number of points within the shock. The
piecewise linear method appears to capture the edges of the shock slightly moreaccurate than the (higher order) WENO method with r = 3. This is likely as thepiecewise linear method is using the exact solution to the Riemann Problem, whilst
the WENO method is using the more diffusive Lax-Friedrichs flux splitting. At thehigher r = 5 order there is a marginal advantage to the WENO method.
The advantages of the WENO method arise when the profile is still continuous, asin the rarefaction problem, or at times before shocks have formed. To confirm that

6.4—WENO methods, nonlinear equations, and flux-splitting

10-3

91

Convergence of Burger's, Gaussian, RK4

ka final − a init k 2

10-4
10-5
10-6
10-7
6 × 101

O(∆x 5 )O(∆x 7 )WENO, r = 3
WENO, r = 4
102

N

2 × 102

Figure 6.7: WENO solutions from evolving Burgers’ equation for an initial Gaussian
profile, stopping before the solution is discontinuous. A fourth order Runge-Kutta
method is used for time evolution. For r = 3 we see the expected fifth (2r − 1) orderconvergence. For r = 5 we see seventh order convergence briefly, before the error fromthe time integrator dominates.
hydro_examples: weno_burgers.pyÏhigh-order convergence is still possible for a nonlinear problem, an initially Gaussian
profile is evolved for a short time and compared to the exact solution (computedfrom characteristic tracing). The resulting error convergence is shown in figure 6.7.
We see the expected fifth and seventh order convergence rates, at least for some of
the resolutions. At too low a resolution the higher order terms in the error expansion
affect the solution. At too high a resolution, for the higher-order method, the time
integration error starts to dominate.

Chapter

7

Euler Equations: Theory
7.1

Euler equation properties

The Euler equations* describe conservation of mass, momentum, and energy in thefluid approximation. Their general form, without any source terms, is:∂ρ+ ∇ · (ρU) = 0∂t∂(ρU)+ ∇ · (ρUU) + ∇ p = 0∂t∂(ρE)+ ∇ · (ρEU + pU) = 0
∂t

(7.1)
(7.2)
(7.3)

Here ρ is the density, U is the velocity vector, U = u x̂ + vŷ, p is the pressure, andE is the total energy / mass, and can be expressed in terms of the specific internalenergy, e, and kinetic energy as:
1
E = e + | U |2
2

(7.4)

The equations are closed with the addition of an equation of state. A common choiceis the gamma-law EOS:
p = ρe(γ − 1)
(7.5)
where γ is the ratio of specific heats for the gas/fluid (for an ideal, monatomic gas,
γ = 5/3), but any relation of the form:p = p(ρ, e)(7.6)* We focus on the Euler equations, which are the most commonly modeled set of fluid equations inastrophysics. The more general equation set, the Navier-Stokes equations, includes dissipative terms.
However, for astrophysical flows, the scales on which these dissipative terms operate are usually muchsmaller than the system of interest (equivalently, Reynolds numbers of astrophysical flows are verylarge).

git version: 64c838dee1a8 . . .

93

Chapter 7. Euler Equations: Theory

94

will work. For many astrophysical environments, we may not be able to express
this relation analytically, but instead will solve it via numerical integration or byinterpolating from tabulated results.
For a derivation of the equations of hydrodynamics using moments of the Boltzmann
equation see [22, 73]. For a physically-motivated derivation from conservation, see[22, 46].
In one dimension, they appear as† :∂ρ ∂(ρu)+=0∂t∂x∂(ρu) ∂(ρuu + p)
+
=0
∂t
∂x
∂(ρE) ∂(ρuE + up)
+
=0
∂t
∂x

(7.7)
(7.8)
(7.9)

One thing that we can notice immediately is that there is no need for temperaturein this equation set, although often, when source terms are present, we will need toobtain temperature from the equation of state.
In this form, the equations are said to be in conservative form, i.e. they can be writtenas:

U t + [F( U )] x = 0
with


ρ
U =  ρu 
ρE



ρu
F( U ) =  ρuu + p ρuE + up

(7.10)(7.11)

We can write this in quasi-linear form by first expressing the flux vector in terms of theconserved variables directly. Taking m ≡ ρu, E ≡ ρE, and assuming a gamma-law
EOS‡ ,

1 m2
p = ρe(γ − 1) = E −( γ − 1)
(7.12)
2 ρ
we havem
 1 m2
F ( U ) =  2 ρ (3 − γ ) + E ( γ − 1) 

(7.13)mE
1 m3
ρ γ − 2 ρ2 ( γ − 1 )† assuming Cartesian coordinates‡ we can relax this assumption by writing p =p(ρ, e), and then taking the derivatives of this asneeded: ∂p/∂ρ, ∂p/∂m = ∂p/∂e|ρ ∂e/∂m, and ∂p/∂E = ∂p/∂e|ρ ∂e/∂E , with e = (E − 1/2m2 /ρ)/ρ. But
as we’ll see, there are simpler systems to work with.

7.1—Euler equation properties

95

The Jacobian§ of this flux vector can now be computed as A = ∂F/∂ U :


0
1
0

− 21 u2 (3 − γ)u (3 − γ )γ−1 (7.14)A( U ) = 

2
2
3
−
2γ
uc
c
1
3
2
uγ
2 ( γ − 2 ) u − γ −1
2 u + γ −1pwhere the speed of sound is c = γp/ρ. With this, our system can be written as:

U t + A( U ) U x = 0(7.15)

This matrix is quite complex and difficult to work with. The eigenvectors of thismatrix can be found in a variety of sources (e.g. [76, 82]).
An alternate way to express these equations is using the primitive variables: ρ, u, p.
Exercise 7.1
Show that the Euler equations in primitive form can be written as
∂ρ
∂ρ
∂u
+u +ρ
=0
∂t
∂x
∂x
∂u
∂u 1 ∂p+u +=0∂t∂x ρ ∂x∂p∂u∂p+ u + γp
=0
∂t
∂x
∂x

(7.16)(7.17)(7.18)

Notice that the velocity equation looks like Burgers’ equation, and is nonlinear. Thisnonlinearity will admit shock and rarefaction solutions like we saw with Burgers’
equation.
The primitive variable system can be written compactly as:
qt + A(q)q x = 0
where




ρ
q= u p

(7.19)u ρ
0A(q) =  0 u 1/ρ 
0 γp u(7.20)The eigenvalues of A can be found via |A − λI| = 0, where | . . . | indicates the determinant and λ are the eigenvalues.
§ The Jacobian, J of a vector F ( U ) with F = ( f , f , . . . , f )⊺ and U = ( u , u , . . . , u )⊺ is
n
n
1 2
1 2



∂ f 1 /∂u1
∂F
 ∂ f 2 /∂u1
J≡
=
..
∂U

.
∂ f n /∂u1

∂ f 1 /∂u2
∂ f 2 /∂u2..
.
∂ f n /∂u2

...
...
..
.
...


∂ f 1 /∂un
∂ f 2 /∂un 


..

.
∂ f n /∂un

Chapter 7. Euler Equations: Theory

96

Exercise 7.2
Show that the eigenvalues of A are λ(−) = u − c, λ(◦) = u, λ(+) =u + c.
Note that both the conserved Jacobian matrix, A( U ), and the primitive variable matrix, A(q), have the same eigenvalues, since they represent the same physics.
In Eq. 7.18, we used the algebraic gamma-law equation of state to replace e with p,
however, for a general equation of state, we can get the appropriate expression by
writing p = p(ρ, s):
0
7
Dp
∂p Dρ
∂p Ds
=+Dt∂ρ s Dt∂s ρ Dt(7.21)

where Ds/Dt = 0 when no entropy sources are present (we will relax this assumption in § 15.1). Recognizing that Γ1 ≡ ∂ log p/∂ log ρ|s , we have:∂p∂p∂u+ u + Γ1 p
=0
∂t
∂x
∂x

(7.22)

as the generalization of the pressure equation¶ . The sound speed is then c2 = Γ1 p/ρ.
These eigenvalues are the speeds at which information propagates through the fluid.
Since the eigenvalues are real, this system (the Euler equations) is said to be hyperbolic.
Additionally, since A = A(q), the system is said to be quasi-linear. Note, physically,
these eigenvalues are telling us that information is communicated at the speed of thefluid (u), as well as the speed of sound moving with respect to the fluid (u ± c).
We’ll use the symbols {−, ◦, +} to denote the eigenvalues and their corresponding
eigenvectors throughout these notes. The right and left eigenvectors can be foundvia:
A r(ν) = λ(ν) r(ν) ;l(ν) A = λ(ν) l(ν)(7.23)

where ν = {−, ◦, +} corresponding to the three waves, and there is one right and
one left eigenvector for each of the eigenvalues.

¶Γ

1 is one of the many adiabatic indices that describe the coupling between different thermodynamic
quantities under compression/expansion. Any stellar structure book should give a good background,e.g., [40]. Note that for an ideal gas, Γ1 = γ

7.1—Euler equation properties

97

Exercise 7.3
Show that the right eigenvectors are:1r(−) =  −c/ρ 
c2



1
r(+) =  c/ρ  (7.24)c2

1r(◦) =  0 0and the left eigenvectors are:l(−) =l(◦) =
l

(+)

1

=

0



1
2c2

0 − c12

ρ
1
2
2c
2c
ρ

0 − 2c(7.25)(7.26)(7.27)

Note that in general, there can be an arbitrary constant in front of eacheigenvector. Here they are normalized such that l(i) · r( j) = δij .
A Jupyter notebook using SymPy that derives these eigenvectors is available: Ïhydro_examples: euler.ipynb ||A final form of the equations is called the characteristic form. Here, we wish to diagonalize the matrix A. We take the matrix R to be the matrix of right eigenvectors,
R = (r(−) |r(◦) |r(+) )(7.28)(i.e., R is a square matrix whose columns are the eigenvectors), and L is the corresponding matrix of left eigenvectors:



l(−)


L =  l(◦) l(+)(7.29)

Note that L R = I = R L, and L = R−1 .
Exercise 7.4

Show that Λ = LAR is a diagonal matrix with the diagonal elements
simply the 3 eigenvalues we found above:


Λ=

λ(−)
λ(◦)
λ(+)




|| if you don’t have Jupyter, you can view this rendered online via the github link.

(7.30)

Chapter 7. Euler Equations: Theory

98

To transform our primitive variable system into the characteristic form, we start bymultiplying by L:
Lqt + LAq x = 0(7.31)
Next, recalling that RL = I (we can insert the identity matrix where we please), we
can rewrite our system as:
Lqt + LARLq x = 0(7.32)
Finally, defining dw = Ldq,
wt + Λw x = 0(7.33)

Here, the w are the characteristic variables. Note that we cannot in general integrate
dw = Ldq to write down the characteristic quantities. Since Λ is diagonal, thissystem is a set of decoupled advection-like equations:
(−)

wt

(−)

+ λ(−) wx

=0

(◦)
(◦)
wt + λ(◦) wx = 0(+)(+)
wt + λ(+) wx = 0(7.34)(7.35)(7.36)

If the system were linear, then the solution to each would simply be to advect thequantity w(ν) at the wave speed λ(ν) . We could then get back the primitive variables
as dq = L−1 dw = Rdw.
The basic idea of hyperbolic systems of PDEs is that there is one wave for eacheigenvalue, and these define the characteristic curves, dx/dt = λ(ν) . As we discussedwith linear advection and Burgers’ equation, along the characteristics the solution isconstant. Across them, the solution jumps. For a linear system, the characteristics
are straight lines.
Imagine initial conditions consisting of a jump in the primitive variables, ∆q. The
corresponding jumps in characteristic variables are ∆w ∼ L∆q (where the ∼ accounts
for the fact that in a nonlinear system, L = L(q)). The characteristic form of theequations says that each of the waves will carry its respective jump, ∆w. Since dq =L−1 dw = Rdw, the jump in the primitive variable across each wave is proportional
to the right-eigenvector associated with that wave. So, for example, since r(◦) is only
non-zero for the density element (see Eq. 7.24), this then means that only density
jumps across the λ(◦) = u wave—pressure and velocity are constant across this wave
(see for example, Toro [82], Ch. 2, 3 or LeVeque [46] for a thorough discussion).
Figure 7.1 shows the three waves emanating from an initial discontinuity. This is aclassic problem called the Sod problem [74]. The initial conditions areρl = 1

ρr = 1/8

ul = 0ur = 0pl = 1

pr = 1/10(7.37)

7.2—The Riemann problem

99

Here we see the three waves propagating away from the initial discontinuity. The left(u − c) wave is a rarefaction, the middle (u) is the contact discontinuity, and the right(u + c) is a shock. Note that all 3 primitive variables jump across the left and rightwaves, but only the density jumps across the middle wave. This reflects the righteigenvectors. Also note that no waves have reached the far left and far right yet, theconditions there are the same as the initial conditions.

7.2

The Riemann problem

Just like with advection and Burgers’ equation, we will need to solve a Riemannproblem. However, as our system is nonlinear, and has 3 waves, the solution isconsiderably more complex, but the general ideas are straightforward. Here we
review the basic outline of operations, and refer to Toro [82] for full details on avariety of methods for solving the Riemann problem.
The Riemann problem consists of a left and right state separated by an interface.
For the Euler equations, there are three eigenvalues, which are the speeds at which
information propagates. Each of these correspond to a wave that will move out fromthe interface with time, and each wave will carry with it a jump in the characteristic
variables. Figure 7.2 shows the three waves moving out from the interface, separating
space into 4 regions, marked: L, L∗ , R∗ , and R. We typically work in terms ofprimitive variables. The states in the L and R regions are simply the left and right
input states—the waves have not had time to reach here, so they are unmodified.
Looking at the middle right eigenvector, r(◦) , we identify the middle wave as a contact
discontinuity. There is neither compression nor expansion across this wave (since thevelocity does not jump across it) and it simply separates two states. We also know
from the eigenvectors that the pressure is constant across the contact.
The left and right waves can be either a rarefaction or a shock. It will be a shock if
the flow is compressing and a rarefaction otherwise.
We already see that the only unknowns are u⋆ , p⋆ , ρ⋆,L , and ρ⋆,R .

7.2.1

Rarefactions

The conditions across a rarefaction can be understood by considering a system whereentropy replaces pressure, qs = (ρ, u, s)⊺ . The entropy equation is simply Ds/Dt = 0.
We need to express the pressure gradient in the velocity equation in terms of qs .
∂p(ρ, s)
∂p ∂s
∂p ∂ρ
∂p ∂s
pΓ ∂ρ
=
+
=
+ 1
∂x
∂s ρ ∂x∂ρ s ∂x∂s ρ ∂xρ ∂x
giving
∂u
∂u 1
+u +
∂t
∂x ρ

"

∂p ∂s
pΓ ∂ρ
+ 1
∂s ρ ∂x
ρ ∂x

#

=0

(7.38)(7.39)

Chapter 7. Euler Equations: Theory

100

1.0

ρ

0.8
0.6
0.4
0.2

0.8

u

0.6
0.4
0.2
0.0
1.0

p

0.8
0.6
0.4
0.2
0.0

0.2

0.4

0.6

0.8

1.0

x
Figure 7.1: Evolution following from an initial discontinuity at x = 0.5. These particular conditions are called the Sod problem, and in general, a setup with two states
separated by a discontinuity is called a shock-tube problem. We see three waves carrying changes in the solution.
hydro_examples: riemann-sod.py

Ï7.2—The Riemann problem

101

λ(−) = u − cλ(◦) = uL∗λ(+) = u + c

R∗(ρ?L , u? , p? )(ρ?R , u? , p? )LR(ρL , uL , pL )(ρR , uR , pR )qi+1/2ii+1

Figure 7.2: The wave structure and 4 distinct regions for the Riemann problem. Timecan be thought of as the vertical axis here, so we see the waves moving outward fromthe interface.

This gives a system:
qs t + As (qs )qs x = 0
where



u

ρ


As =  c2 /ρ u
0

0

0
1 ∂p
ρ ∂s ρ

u(7.40)


(7.41)The eigenvalues of As are again u, u − c, and u + c. The right eigenvectors are**



1
(−)
rs =  −c/ρ 
0




1
(◦)

rs = 
02−c /ps1(+)
rs =  c/ρ 
0(7.42)

Here, we define ps ≡ ∂p/∂s|ρ . Since the jump in qs is proportional to these eigenvectors, we see that entropy does not change across the left, (−), and right, (+),
waves.
Consider the (+) wave, which moves at a speed λ(+) = u + c. Across this wave, thecharacteristic variable w(+) will jump, but the others will not. Similarly, w(+) will be
constant across the (−) wave. So we can use this constancy to tell us how the evolution behaves across that wave. The constancy of the middle and right characteristic** Again, see the SymPy Jupyter notebook:Ï hydro_examples: euler.ipynb

Chapter 7. Euler Equations: Theory

102

variables across the left wave gives us the conditions (using our original primitive
variable system):l(+) · dq = 0(7.43)l(◦) · dq = 0

or
0

ρ
2c

1
2c2




dρ
 du  = 0dp

1 0 − c12

Expanding these, we have the system:(7.44)dρ
 du  = 0
dp

1
dp = 0ρc1dρ − 2 dp = 0c

du +(7.45)(7.46)(7.47)

Defining the Lagrangian sound speed, C ≡ ρc, and the specific volume, τ = 1/ρ, we
can rewrite this system as:
du = −dp
dp, dτ = − 2CCacross the left wave

(7.48)

Similar arguments would give the condition across the right wave as:
du =

dp
dp
, dτ = − 2CCacross the right wave

(7.49)

These are completely general at this point. Note that the condition of the second
wave, dτ/dp is essentially the definition of the adiabatic index Γ1 , dp/p − Γ1 dρ/ρ =0 for constant entropy. Finding the solution across the rarefaction then involves
integrating the system from pl,r to p⋆ , where l, r is the original left or right state,
depending on which wave you are considering. Coupled with this, we need ourequation of state to provide C = C (τ, p). These solutions are called the Riemanninvariants.
Considerable simplification can be made if we assume a gamma-law gas. The eigensystem with entropy showed us that entropy is constant across the solution. This
allows us to write our equation of state as:
p = Kργ(7.50)

where K is a constant that depends on the entropy, and do the integrals analytically.

7.2—The Riemann problem

103

Exercise 7.5
Assume a gamma-law gas, then you only need to integrate a single equation to find the solution across the left rarefaction:u=−where c =

p

u+

Z

dp
ρc

(7.51)

γp/ρ. Using p = Kργ , show that2c= constantγ−1across the left rarefaction(7.52)

This allows you to link the state to the left of the rarefaction to the starstate:
2c L
2c⋆
uL +
= u⋆ +(7.53)
γ−1
γ−1

and

pL
p⋆
γ = γ
ρL
ρ⋆

(7.54)

from our constant-entropy equation of state. Together, show that thisgives:" (γ−1)/2γ #2c Lp⋆u⋆,L = u L +1−(7.55)γ−1
pL
A similar construction can be done for the right rarefaction, yielding:" (γ−1)/2γ #
p⋆
2c R
1−
(7.56)u⋆,R = u R −γ−1pR
For a general equation of state, there is not a closed form, but we would need tointegrate our system to get u⋆ = u( p⋆ ) and ρ⋆,s = 1/τ ( p⋆ ).
We’ll denote the solution across the left rarefaction as u⋆ = urare
L ( p⋆ ) and across theright rarefaction as u⋆ = urare
(
p
)
.
⋆
R

7.2.2

ShocksEntropy is not constant across a shock—there is dissipation, so we need a different
way to connect the states across the shock. As with Burgers’ equation, we can understand the shock by looking at the Rankine-Hugoniot jump conditions. There will be
one condition for each of our conservation laws, and together they tell us the speedof the shock and how density and pressure jump across it.

Chapter 7. Euler Equations: Theory

104
The Rankine-Hugoniot conditions are:

F( U ⋆ ) − F( U s )=SU⋆ − Us(7.57)

where S is the shock speed. It is easiest to work in the frame of the shock. If theshock speed is S, then we define the velocity in the shock frame as:ûs = us − Sû⋆ = u⋆ − S(7.58)(7.59)and the Rankine-Hugoniot conditions become:F( Û ⋆ ) − F( Û s )=0Û ⋆ − Û s

(7.60)For the one-dimensional system of Euler equations, we have the conditions:ρ⋆ û⋆ = ρs ûs2ρ⋆ û⋆ + p⋆ = ρs û2s + ps11ρ⋆ û⋆ e⋆ + ρ⋆ û3⋆ + û⋆ p⋆ = ρs ûs es + ρs û3s + ûs ps
2
2(7.61)(7.62)(7.63)

Our goal is to find how each variable jumps across the shock. We’ll work this out for
the general EOS case, following the ideas in [25].
Starting with the mass flux, we can express:
û⋆ =

ρs
ûs
ρ⋆

and then insert this into the momentum equation to get:


1
1
2
−
û2s = p⋆ − ps
ρs
ρs
ρ⋆

(7.64)(7.65)

Introducing compact notation for the jump across the shock:[q] ≡ q⋆ − q(7.66)[ p]
ρ2s û2s(7.67)

we have:−[τ ] =

We now introduce the mass flux, Ws . For a shock separating L/L⋆ (the 1-shock),mass will be moving through the shock to the right, so, in the frame of the shock, themass flux is
WL ≡ ρ L û L = ρ⋆ û⋆(7.68)

7.2—The Riemann problem

105

Likewise, for a shock separating R/R⋆ (the 3-shock), mass will move to the left
passing through the shock, and in the frame of the shock, the mass flux isWR ≡ −ρ R û R = −ρ⋆ û⋆(7.69)

Thus, our first jump condition becomes−[τ ] =

[ p]
Ws2

(7.70)

Next, going back to the momentum equation, we can substitute in the mass flux. For
the left (1-shock), we have:
WL û⋆ + p⋆ = WL û L + p L(7.71)

giving[ p](7.72)
WL
where we recognized that û⋆ − û L = u⋆ − u L = [u], since the shock speed is the samefor u⋆ and u.
[u] = −

Likewise, for the right (3-shock), we have:−WR û⋆ + p⋆ = −WR û R + p R(7.73)

giving

[u] =

[ p]
WR

(7.74)The last jump condition is for energy. Since all the terms in the energy equation areproportional to velocity, there will be no sign difference between the left and rightshock jump conditions. We start by introducing the mass flux:
1
Ws
1
Ws
Ws e⋆ + Ws û2⋆ +p⋆ = Ws es + Ws û2s +
ps
2
ρ⋆
2
ρs

(7.75)The mass flux cancels, leaving

[e] +


ps 1 2p⋆− +û⋆ − û2s = 0ρ⋆ρs2getting rid of the velocities using û2⋆ = Ws2 /ρ2⋆ and û2s = Ws2 /ρ2s , we have:p⋆
ps 1 2 1
1[e] +− + Ws− 2 =0
ρ⋆
ρs
2
ρ2⋆
ρs

(7.76)(7.77)

Then introducing Ws2 = −[ p]/[τ ], and after a lot of algebra, we arrive at:[e] = −p⋆ + ps[τ ]2(7.78)

Chapter 7. Euler Equations: Theory

106
Some sources write p̄ ≡ ( p⋆ + ps )/2.

To summarize, our jump conditions across the shock are:

[ p]
Ws2
[ p]
[u] = ∓‘−’ for left, ‘+’ for rightWsp⋆ + ps[e] = −[τ ]2
[τ ] = −(7.79)(7.80)(7.81)

As with the rarefaction, the goal is to express this as a function, u⋆ = ushock( p⋆ ). Thesgeneral solution procedure is starts with a proposed value for p⋆ , then:
1. root find to find ρ⋆ corresponding to the p⋆ :(a) guess a value for ρ⋆(b) using the equation of state, express e⋆ = e( p⋆ , ρ⋆ )(c) use Newton’s method (or another technique) with [e] = − p̄[τ ] to find acorrection to ρ⋆
2. compute
1
[τ ]
=−
2
Ws
[ p]

(7.82)

3. find the star velocity:[ p]
Wswhere we use ‘−’ for the left shock, and ‘+’ for the right shocku⋆ = us ∓(7.83)The one other piece of information we need is the shock speed. We can get this fromthe mass flux, Ws , definition, e.g., WL = ρ L û L = ρ L (u L − S),:S = us ∓Wsρs‘−’ for left, ‘+’ for right(7.84)

This procedure gives us ρ⋆,s , p⋆ , and S, the shock speed.
Just as with the rarefaction, considerable simplification can be made if we assume agamma-law gas.
Exercise 7.6
Introducing
e=

p 1
ρ γ−1

(7.85)

7.2—The Riemann problem

107

into the jump condition for energy, Eq. 7.81, show that we can express
the jump in density in terms of the ratio of pressure, p⋆ /ps , as:" p⋆#
ps ( γ + 1) + ( γ − 1)ρ⋆,s = ρs(7.86)(γ + 1) + pp⋆s (γ − 1)
Now, compute the mass flux, Ws starting with
Ws2 = −[ p][τ ]use the γ-law equation of state and show that
 

1
p⋆
2
Ws = ps ρs( γ + 1) + ( γ − 1)2
ps(7.87)(7.88)

With this, show that the star velocity is:p
1/2
1 − p⋆s2u⋆ = us ± c1/2
γ ( γ − 1)p ⋆ γ +1+
1
p s γ −1(7.89)

with ‘+‘ for the left shock and ‘−‘ for the right shock. Also show that theshock speed is:
S = us ∓ c



p⋆
ps




γ + 1 γ − 1 1/2+
2γ
2γ(7.90)

with the ‘−’ or the left shock and the ‘+’ for the right shock.

7.2.3

Finding the Star StateThe left and right states are connected to the state in the star region by a Hugoniot
curve—this is a curve in the u-p plane that shows all of the possible states one canreach from the current state through either a shock or rarefaction. There are two such
curves, one corresponding to the left and one to the right state:
(
(
(
p
)
p
>
p
ushockushockL⋆,R ( p ) p > p R
⋆,L
u
(
p
)
=
(7.91)u⋆,L ( p) =
⋆
,r
rare
rare
u⋆,R ( p)p ≤ pRu⋆,L ( p)p ≤ pLThe solution to the Riemann problem is the point in the u-p plane where these two
curves intersect, e.g., we solve for p⋆ in:u⋆,l ( p⋆ ) − u⋆,r ( p⋆ ) = 0(7.92)

This is equivalent to saying that pressure and velocity do not jump across the contact
wave.

Chapter 7. Euler Equations: Theory108

For a gamma-law equation of state, using the results from the exercises, we have: (γ−1)/2γ p
2cp⋆ ≤ psus ± γ−1 1 − p⋆s(7.93)u⋆,s ( p⋆ ) =

h
i1/2
p

1− p⋆s2p⋆ > ps
1/2 u s ± c γ ( γ −1)
p ⋆ γ +1
+1
p s γ −1

Figure 7.3 shows the Hugoniot curves for the Sod problem. Comparing to Figure 7.1,
we see that the right state is linked to the star state with a shock while the left stateis linked to the star state with a rarefaction.
Exercise 7.7
Download the code demonstrated in Figure 7.3 and experiment with different initial conditions to see how the solution changes based on thestates. Try to create initial states that give rise to two rarefactions anda separate set of states that give rise to two shocks.

7.2.4

Complete Solution

To complete the solution, we need to find which of the 4 regions, L, L⋆, R⋆, R we fallin. For hydrodynamics, we are usually interested only in the solution on the interface,
but we can look along any ray in the x-t plane by defining ξ = ( x − xinterface )/t. If
the initial discontinuity is on the interface, then ξ = 0.
Figure 7.4 shows the possible configurations of the waves. Note that the middle
wave is always a contact but the left (1) and right (3) waves can be either a shockor rarefaction. To find out which region the interface falls in, we simply look at the
speeds.
The first speed to consider is the contact wave, that has a speed of simply Sc = u⋆ . If
Sc < ξ, then we are choosing between R and R⋆ states (cases a and b). If Sc > ξ, thenwe are choosing between the L and L⋆ states (cases c and d in Figure 7.4)†† .
The direction of the contact reduces the problem down to choosing between just two
regions, either L-L⋆ or R-R⋆ . This leaves just a single wave to consider: the right wave
for cases a and b; and the left wave for cases c and d. We need the wave speed for
this—it will depend on whether it is a shock or a rarefaction.
For a shock, the wave speed is given by Eq. 7.84. We do the same procedure as before.
For example, for cases a and b, we look at SR , the right-moving shock speed for the†† for the special case where S

c = 0, we usually take the solution to be the average of the L⋆ and R⋆
states. Testing for this explicitly rather than using ≥ in a check is important for maintaining symmetry(see § 8.9.1).

7.2—The Riemann problem

109

6

shock
rarefaction

4

u

2
0

right

left

2
4
0.0

0.2

0.4

0.6

p

0.8

1.0

1.2

1.4

Figure 7.3: The Hugoniot curves corresponding to the Sod problem. The shock andrarefaction curves are shown. The solution to the Riemann problem is the point where
the curves intersect. The line style of the curve indicates where we are a shock or
rarefaction. Where p > ps , where s ∈ L, R, we have a shock.
hydro_examples: riemann-phase.pyÏ

3-wave. If SR > 0, then the interface is in the R⋆ state (case b), while if SR < 0, thenthe interface is in the R state (case a). A similar process holds for the left-moving
shock and cases c and d.
For a rarefaction, the relevant speeds are the characteristic speeds on either side of
the rarefaction. We usually talk about the leading part of the rarefaction (the head)
and trailing part (the tail). The corresponding wave speeds are:• left (1) rarefaction:– λhead = u L − c L– λtail = u⋆ − c⋆• right (3) rarefaction:– λhead = u R + c R– λtail = u⋆ + c⋆
The nature of the rarefaction is such that it spreads out, |λhead | > |λtail |. To determineChapter 7. Euler Equations: Theory

110

(a)

(b)

L

L

R

R

L

(c)

L

R

R

(d)

L

L

R

R

L

L

R

R

Figure 7.4: An illustration of the 3 waves emanating from an initial discontinuity (theorigin of the axes). The 4 cases show all possible cases of waves being to the left or
right of the interface (corresponding to the choice ξ = 0). In all cases, the middle wave
is a contact and the left (1) and right (3) waves are either a shock or a rarefaction. The
state on the interface is: R (case a); R⋆ (case b); L⋆ (case c); L (case d).

which state we are in, we look to see where both the head and tail are with respect
to the interface. Figure 7.5 shows the possibilities for a left (1) rarefaction. In case (a),λhead , λtail < 0, so the L⋆ state is on the interface. In case (c), λhead , λtail > 0, so the L
state is on the interface. Case (b) is more complicated—we have λhead < 0, λtail > 0,so the rarefaction spans the interface. We need to therefore solve for the state in therarefaction itself.
To find the structure inside of a rarefaction, consider some point, ( x, t), in the x-t
plane. For an initial discontinuity at the origin, we can imagine a line connecting thispoint and the origin, which has the form:
x
= u−c
t

7.3

(7.94)

Other thermodynamic equations

At times we will want to use alternate forms of the energy equation. The internalenergy is governed by the first law of thermodynamics. In the absence of any heat

7.3—Other thermodynamic equations

111

(a)
λhead
L

λtail
L

R

R

(b)
λhead

λtail
L

L

R

R

(c)
λhead
L

λtail
L

R

R

Figure 7.5: An illustration of the structure of the left rarefaction wave, for the casewhere the contact and right wave are to the right of the interface. Here, we are choosing
between states L and L⋆ . In (a), both the head and tail of the rarefaction are to the leftof the interface, so state L⋆ is on the interface. In (c), both the head and tail of therarefaction are to the right of the interface, so state L is on the interface. Inbetween,case (b), shows a rarefaction that spans the interface. For this case, we need to integrate
the Riemann invariants to find the state on the interface.

Chapter 7. Euler Equations: Theory112
sources, we have:

dq = 0 = de + pd(1/ρ)(7.95)

where e is the specific internal energy. Applying this to a Lagrangian fluid element,
we have:De
D (1/ρ)
+p
=0
Dt
Dt
De
p Dρ
− 2
=0
Dt ρ DtDeρ+ p∇ · U = 0
Dt(7.96)(7.97)(7.98)

where we used the continuity equation in the last step to eliminate Dρ/Dt. This canbe rewritten by adding e× the continuity equation to give:∂(ρe)+ ∇ · (ρUe) + p∇ · U = 0∂t(7.99)

Notice that internal energy, (ρe) is not a conserved quantity (in particular, the p∇ · U
term is not in conservative form).
Another energy-like quantity that we can consider is specific enthalpy,
h = e+pρ

(7.100)Differentiating this, and using the internal energy equation,De
p Dρ 1 Dp
Dh
=
− 2
+
Dt
Dt ρ Dtρ Dt
p Dρp Dρ 1 Dp
= 2
− 2
+
ρ Dt
ρ Dt
ρ Dt
so
ρ

Dh
Dp
=
Dt
Dt

(7.101)(7.102)(7.103)This form is useful for very subsonic flows (see, e.g. [13]), where Dp/Dt = 0, whichthen shows that enthalpy is conserved:∂(ρh)+ ∇ · (ρhU) = 0∂t(7.104)(here we added h× the continuity equation to transform from the Lagrangian derivative to a conservation equation).
We can also look at the temperature evolution. It is interesting to approach thisfrom both the internal energy and enthalpy equations. Starting with internal energy,
writing it as e(ρ, T ), we have:
De
∂e Dρ
∂e DT
p
=
+
= − ∇·U
Dt∂ρ T Dt∂T ρ Dtρ(7.105)

7.3—Other thermodynamic equations

113

The specific heat at constant volume is defined as cv = ∂e/∂T |ρ , allowing us to write:


∂e
DT
p
=
−
cv
∇·U
(7.106)Dt∂ρ T ρ
If we alternately start with enthalpy, expressing it as h = h( p, T ), we have:
Dh
∂h Dp
∂h DT
1 Dp
=
+
=
Dt
∂p T Dt∂T p Dt
ρ Dt(7.107)The specific heat at constant pressure is defined as c p = ∂h/∂T | p , letting us write:


Dp
1
∂h
DT
=
−
(7.108)cp
Dt
ρ∂p T Dt
These two temperature evolution equations are equivalent, but one describes theevolution in terms of density and the other in terms of pressure. Later, we’ll see
how these can be useful when we approximate the evolution of reactive flow underconstant density or constant pressure behaviors.

Chapter

8

Euler Equations: Numerical
Methods
8.1

Introduction

The numerical methods we use for the Euler equations mirror those used with advection in Ch. 4. The basic process is:• Reconstruct the state variables to the interfaces.
• Solve the Riemann problem (as described in § 7.2) and construct the fluxes
through the interfaces.
• Perform the conservative update on the state variables.
The Euler equations are much more complicated than linear advection—we alreadysaw this with the Riemann problem. But we will also see that in different parts of
the algorithm we will use conservative or primitive variables. Additional physics canenter as source terms, which we’ll see how to add to both the interface states andconservative update here.

8.2

Reconstruction of interface states

We will solve the Euler equations using a high-order Godunov method—a finite volume method whereby the fluxes through the interfaces are computed by solving the
Riemann problem for our system. The finite-volume update for our system appearsas:
∆t  n+1/2
1
Fi−1/2 − Fin++1//22(8.1)
U in+1 = U in +∆x
git version: 64c838dee1a8 . . .

115

Chapter 8. Euler Equations: Numerical Methods

116

n+1/2

F (Ui+1/2 )

Ui

n+1/2

Ui+1/2,L

n+1/2

Ui+1/2,R

i + 1/2

i

Ui+1

i+1

Figure 8.1: The left and right states at interface i + 1/2. The arrow indicates the flux
through the interface, as computed by the Riemann solver using these states as input.

This says that each of the conserved quantities in U change only due to the flux ofthat quantity through the boundary of the cell.
Instead of approximating the flux itself on the interface, we find an approximation
1
1
to the state on the interface, U in−+1//22 and U in++1//22 and use this with the flux function todefine the flux through the interface:Fin−+1//22 = F( U in−+1//22 )
1

1

1
1
Fin++1//22 = F( U in++1//22 )

(8.2)
(8.3)

To find this interface state, we predict left and right states at each interface (centeredin time), which are the input to the Riemann solver. The Riemann solver will thenlook at the characteristic wave structure and determine the fluid state on the interface,which is then used to compute the flux. This is illustrated in Figure 8.1.
Finally, although we use the conserved variables for the final update, in constructing
the interface states it is often easier to work with the primitive variables. These
have a simpler characteristic structure. The interface states in terms of the primitive
variables can be converted into the interface states of the conserved variables througha simple algebraic transformation,

U in++1//22,L = U (qin++1//22,L )
1

1

(8.4)

As we saw with linear advection in § 5.1, at the start of a timestep, each zones contains
cell-averages. Consider a cell average quantity, qi . Constructing the interface statesrequires reconstructing the cell-average data as a continuous function, q( x ), definedfor each cell. This polynomial is only piecewise continuous, since each cell has its own
q( x ). Standard choices are piecewise constant,q ( x ) = qi

(8.5)

8.2—Reconstruction of interface states

117

piecewise linear,q ( x ) = qi +∆qi
( x − xi )
∆x

(8.6)

or piecewise parabolic,q ( x ) = α ( x − x i )2 + β ( x − x i ) + γ(8.7)

where in each case, the average of q( x ) over the cell gives qi . Most of the complexityof the method is then figuring out the coefficients of the polynomial.
Characteristic tracing is then done under this polynomial to see how much of eachcharacteristic quantity comes to the interface over the timestep. The jump in the primitive variables is projected into the characteristic variables, and only jumps moving
toward the interface are included in our reconstruction. We look at several methods
below that build off of these ideas below.

8.2.1

Piecewise constant

The simplest possible reconstruction of the data is piecewise constant. This is what
was done in the original Godunov method [37]. For the interface marked by i + 1/2,
the left and right states on the interface are simply:

U i+1/2,L = U i(8.8)

U i+1/2,R = U i+1(8.9)

This does not take into account in any way how the state U may be changing throughthe cell. As a result, it is first-order accurate in space, and since no attempt was madeto center it in time, it is first-order accurate in time.

8.2.2

Piecewise linear

For higher-order reconstruction, we first convert from the conserved variables, U ,to the primitive variables, q. These have a simpler characteristic structure, making
them easier to work with. Here we consider piecewise linear reconstruction—thecell average data is approximated by a line with non-zero slope within each cell.
Figure 8.2 shows the piecewise linear reconstruction of some data.
Consider constructing the left state at the interface i + 1/2 (see Figure 8.1). Just likefor the advection equation, we do a Taylor expansion through ∆x/2 to bring us to
the interface, and ∆t/2 to bring us to the midpoint in time. Starting with qi , the cellcentered primitive variable, expanding to the right interface (to create the left stateChapter 8. Euler Equations: Numerical Methods

118

i−2

i−1

i

i+1

i+2

Figure 8.2: Piecewise linear reconstruction of the cell averages. The dotted line shows
the unlimited center-difference slopes and the solid line shows the limited slopes.

there) gives:
qin++1//22,L = qin +
1

∆x ∂q
∆t
+
2 ∂x i2∂q∂t| {z }i+...

(8.10)=−A∂q/∂x



∂q
∆t
∂q
−
A
2 ∂x i
2
∂x i


∆t
1
1−
Ai ∆qi= qin +
2∆x∆x
= qin +

(8.11)(8.12)

where ∆qi is the reconstructed slope of the primitive variable in that cell (similar to
how we compute it for the advection equation). We note that the terms truncated in
the first line are O(∆x2 ) and O(∆t2 ), so our method will be second-order accurate inspace and time.
As with the advection equation, we limit the slope such that no new minima or
maxima are introduced. Any of the slope limiters used for linear advection apply
here as well. We represent the limited slope as ∆qi .
We can decompose A∆q in terms of the left and right eigenvectors and sum over
all the waves that move toward the interface. First, we recognize that A = RΛL andrecognizing that the ‘1’ in Eq. 8.12 is the identity, I = LR, we rewrite this expression
as:


1
∆t
n+1/2
n
qi+1/2,L = qi +RL −RΛL ∆qi(8.13)
2∆xi
We see the common factor of L∆q. We now write this back in component form.
Consider:





(−)
(−)
(−)
(−)
(◦)
(+)
(−)
l
l
l
∆ρ
r
r
r
λ
2
3
1
1
 1



 1

 (−) (◦) (+)    (◦)

(◦)
(◦)


 l

RΛL∆q = 
r2
r2 
λ(◦)
l2
l3 
 r2

 1
  ∆u 





(−)
(◦)
(+)
(+)
(+)
(+)
∆p
r3
r3
λ(+)
r3
l1
l2
l3
(8.14)

8.2—Reconstruction of interface states

119

Starting with L∆q, which is a vector with each component the dot-product of a left
eigenvalue with ∆q, we have




(−)
(◦)
(+)
(−)
(−)
r1
r1   λ· ∆q 
 r1
 l (−) (◦) (+)    l(◦) · ∆q RΛL∆q = (8.15)
r2
r2 
λ(◦)
 r2







(−)
(◦)
(+)
r3
r3
r3
λ(+)
l(+) · ∆q
Next we see that multiplying this vector by Λ simply puts the eigenvalue with its
respective eigenvector in the resulting column vector:



(−)
(◦)
(+)
(−)
(−)
r1
r1   λ l· ∆q 
 r1
 (−) (◦) (+)    λ(◦) l(◦) · ∆q 
(8.16)
RΛL∆q = 
r
r
r
 2


2
2



(−)
(◦)
(+)
r3
r3
r3
λ(+) l(+) · ∆qFinally, the last multiply results in a column vector:(−) (−) (−)(◦) (◦) (◦)(+) (+) (+)
r
λ
l
·
∆q
+
r
λ
l
·
∆q
+
r
λ
l
·
∆q
1
1
 1

 (−)

(◦)
(+)
(−) (−) · ∆q + r(◦) l(◦) · ∆q + r(+) l(+) · ∆q RΛL∆q = λλ
 r2 λ l

2
2


(−)
(◦)
(+)
r3 λ(−) l(−) · ∆q + r3 λ(◦) l(◦) · ∆q + r3 λ(+) l(+) · ∆q

(8.17)

We can rewrite this compactly as:∑ λ(ν) (l(ν) · ∆q)r(ν)(8.18)

ν

where we use ν to indicate which wave we are summing over. A similar expansion
is used for RL∆q. In fact, any vector can be decomposed in this fashion:
χ = Iχ = RLχ = ∑(l(ν) · χ)r(ν)(8.19)

νAnd then it is easy to see that the above manipulations for A∆q can be expressed as:A∆q = A ∑(l(ν) · ∆q)r(ν) = ∑(l(ν) · ∆q)Ar(ν) = ∑(l(ν) · ∆q)λ(ν) r(ν)νν

(8.20)

ν

where we used Ar(ν) = λ(ν) r(ν) . The quantity (l(ν) · ∆q) that shows up here is the
projection of the vector ∆q into the characteristic variable carried by wave ν. Thissum shows, as discussed earlier, that each wave carries a jump in the characteristic
variable, with the jump in the primitive variables proportion to the right eigenvector,r(ν) .
The resulting vector for the left state is:1
1
qin++1//22,L = qin +2∑

ν;λ(ν) ≥0∆t (ν)(ν)(ν)
1−(li · ∆qi )ri
λ∆x i(8.21)

Chapter 8. Euler Equations: Numerical Methods

120

Note that we make a slight change here, and only include a term in the sum if its
wave is moving toward the interface (λ(ν) ≥ 0). The quantity ∆tλ(ν) /∆x inside thebrackets is simply the CFL number for the wave ν.
Starting with the data in the i + 1 zone and expanding to the left, we can find theright state on the i + 1/2 interface:∆t (ν)
11(ν)(ν)
qin++1//22,R = qin+1 −1+
λ(8.22)
i +1 ( li +1 · ∆qi +1 ) ri +1
2 ∑
∆x
(ν)
ν;λ

≤0

A good discussion of this is in Miller & Colella [53] (Eq. 85). This expression issaying that each wave carries a jump in r(ν) and only those jumps moving toward
the interface contribute to our interface state. This restriction of only summing up
the waves moving toward the interface is sometimes called characteristic tracing. This
decomposition in terms of the eigenvectors and eigenvalues is commonly called acharacteristic projection. In terms of an operator, P, it can be expressed as:Pχ = ∑(l(ν) .χ)r(ν)(8.23)ν

Exercise 8.1
Show that Pq = q, using the eigenvectors corresponding to the primitive
variable form of the Euler equations.
In the literature, sometimes a ‘>’ or ‘<’ subscript on P is used to indicate the characteristic tracing.
We could stop here, but Colella & Glaz [25] (p. 278) argue that the act of decomposing
A in terms of the left and right eigenvectors is a linearization of the quasi-linear
system, and we should minimize the size of the quantities that are subjected to thischaracteristic projection. To accomplish this, they suggest subtracting off a reference
state. Saltzman (Eq. 8) further argues that since only jumps in the solution are usedin constructing the interface state, and that the characteristic decomposition simply
adds up all these jumps, we can subtract off the reference state and project the result.
In other words, we can write:


1
∆t
1
qin++1//22,L − qref = qin − qref +1−
Ai ∆qi(8.24)
2∆x
Then we subject the RHS to the characteristic projection—this tells us how much of1
the quantity qin++1//22,L − qref reaches the interface. Colella & Glaz (p. 278) and Colella(Eq. 2.11) suggest


1
∆t
(+)
n
qref = q̃i,L ≡ qi +1−
max(λi , 0) ∆qi(8.25)
2∆x

8.2—Reconstruction of interface states

121

where λ(+) is the fastest eigenvalue, and thus will see the largest portion of thelinear profiles. Physically, this reference state represents the jump carried by thefastest wave moving toward the interface. Then,qin++1//22,L − q̃i,L =1

i
1 ∆t h(+)
max(λi , 0) − Ai ∆qi
2 ∆x(8.26)and projecting this RHS (see Colella & Glaz Eq. 43; Miller & Colella Eq. 87), andisolating the interface state, we haveqin++1//22,L = q̃i,L +

1 ∆t
2 ∆x

= q̃i,L +

1 ∆t
2 ∆x

1

∑

li

∑

h

ν;λ(ν) ≥0
ν;λ(ν) ≥0

(ν)

h
i
(+)
(ν)
· max(λi , 0) − Ai ∆qi ri(+)

max(λi(ν), 0) − λ i

i

(ν)

( li

(8.27)(ν)· ∆qi ) ri

(8.28)

This is equivalent to the expression in Saltzman [66] (p. 161, first column, secondto-last equation) and Colella [24] (p. 191, the group of expressions at the end)* . The
corresponding state to the right of this interface is:qin++1//22,R = q̃i+1,R +
1

1 ∆t
2 ∆x

∑

ν;λ(ν) ≤0

h

i
(ν)
(ν)
(−)
(ν)
min(λi+1 , 0) − λi+1 (li+1 · ∆qi+1 ) ri+1

(8.29)

where now the reference state captures the flow from the i + 1 zone moving to theleft to this interface (hence the appearance of λ(−) , the leftmost eigenvalue):


1
∆t
(−)
q̃i+1,R = qi+1 −1+min(λi+1 , 0) ∆qi+1(8.30)
2∆x
Side note: the data in zone i will be used to construct the right state at i − 1/2 (theleft interface) and the left state at i + 1/2 (the right interface) (see Figure 8.3). For thisreason, codes usually compute the eigenvectors/eigenvalues for that zone and then1
1compute qin−+1//22,R together with qin++1//22,L in a loop over the zone centers.

8.2.3

Piecewise parabolic

The piecewise parabolic method uses a parabolic reconstruction in each cell. Thisis more accurate than the linear reconstruction. Figure 8.4 shows the reconstructedparabolic profiles within a few cells. Since the original PPM paper [28], there havebeen many discussions of the method, with many variations. Here we focus on
the presentation by Miller & Colella [53], since that is the most straightforward.
Note: even though a parabolic profile could be third-order accurate, the temporal
discretization and prediction in this method is still only second-order.
* Since the combination l(ν) · ∆q appears so frequently, some sources represent this as β(ν) and thenwrite the interface states as a linear combination of the β’s. Some variation in the literation, dependingon whether ρ or τ = 1/ρ is used as a primitive variableChapter 8. Euler Equations: Numerical Methods

122

qi

n+1/2

qi−1/2,R

n+1/2

qi+1/2,Li

Figure 8.3: The two interface states that are constructed using qi as the starting point.

i−2

i−1

i

i+1

i+2

Figure 8.4: Piecewise parabolic reconstruction of the cell averages. The dotted line
shows the unlimited parabolas—note how they touch at each interface, since the interface values come from the same interpolant initially. The solid line shows the limited
parabolas.

Miller & Colella give an excellent description of how to take the results for piecewise linear reconstruction and generalize it to the case of PPM [28] (see Eqs. 88-90).
Starting with Eq. 8.24, we can write this (after the characteristic projection) as1
qin++1//22,L = q̃+ −∑ν;λ(ν) ≥0

(ν)
li ·



q̃+ −



1
qin +
2





∆t (ν)
(ν)
1−
λ
∆qi
ri
∆x i

(8.31)

Miller & Colella rewrite the portion inside the [. . .] recognizing that (similar to M&C
Eq. 88, but for the i + 1/2, L interface):
1
qin +

2




Z xi+1/2∆t (ν)
1
1−
λi
∆qi ≈
q( x )dx∆x
λ∆t xi+1/2 −λ∆twhere q( x ) is the reconstructed functional form of q in the zone.

(8.32)

8.2—Reconstruction of interface states123

σi(ν) ∆x

I(+ν)

i

i +1

Figure 8.5: Integration under the parabolic profile. For each of the waves, σ(ν) is thefraction of the cell that they cross in a timestep, and σ(ν) ∆x = λ(ν) ∆t is the distancethey can travel. Here we are integrating under the parabola to the right interface of
(ν)

(ν)

cell i to define I+ (this is indicated by the shaded region). The I+ carried by thiswave will be added to those carried by the other waves to form the left state at interface
i + 1/2.

Exercise 8.2
Show that this is exactly true for a linear reconstruction of q( x ), i.e.,q( x ) = qi + (∂q/∂x )( x − xi ).
The integral on the right represents the average of q that can reach the right interfaceof the cell i over timestep ∆t, moving at the wavespeed λ. This suggests that we canreplace the linear reconstruction of q with a parabolic one, and keep our expressions
for the interface states.
In particular, we define(ν)
I+ ( qi ) =1(νσ ) ∆xZ xi+1/2

xi+1/2 −σ(ν) ∆x

q( x )dx

with σ(ν) = |λ(ν) |∆t/∆x (see Almgren et al. Eq. 31) (see Figure 8.5). Then


1
(ν)
(ν)
(ν)
qin++1//22,L = q̃+ − ∑ li · q̃+ − I+ (qi ) ri

(8.33)(8.34)

ν;λ(ν) ≥0

Miller & Colella choose the reference state as((+)
I+ (qi ) if u + c > 0q̃+ =qi
otherwise(8.35)

where the superscript (+) on I indicates that the fastest eigenvalue (λ(+) = u + c)
is used. This is similar in spirit to Eq. 8.25. Note: in the original PPM paper, if theChapter 8. Euler Equations: Numerical Methods

124

wave is not approaching the interface, instead of using the cell-average, qi , they use
the limit of the quadratic interpolant. In contrast to the above, the Castro paper [2]just uses qi for the reference state regardless of whether the wave is moving toward
or away from the interface. Note that if the system were linear, then the choice ofreference state would not matter.
To finish the reconstruction, we need to know the parabolic form of q( x ). Here, we
do the reconstruction from the original PPM paper:q( x ) = q− + ξ ( x ) (∆q + q6 (1 − ξ ( x )))(8.36)

with ∆q = q+ − q− , and q− , q+ the values of the polynomial on the left and rightedges, respectively, of the current cell, and
1
q6 ≡ 6 q i − ( q − + q + )(8.37)
2andξ (x) =x − xi−1/2∆x(8.38)

To complete the description, we need to determine the parameters of the parabola.
The values of q− and q+ are computed and limited as described in the original PPM
paper. With this definition, we can do the integral I+ :


(ν) 
σi
2 (ν)
(ν)
I+ (qi ) = q+,i −∆qi − q6,i 1 − σi2(8.39)

3

Figure 8.5 illustrates the process of integrating under the parabolic profile.
Exercise 8.3
Show that q( x ) is a conservative interpolant. That is1∆x

Z xi+1/2
xi−1/2q( x )dx = qi

(8.40)

You can also see that the average over the left half of the zone is qi − 41 ∆q
and the average over the right half of the zone is qi + 14 ∆q. This meansthat there are equal areas between the integral and zone average on theleft and right sides of the zone. This can be seen by looking at Figure 8.4.

(ν)

Aside: Note that this characteristic projection of q̃+ − I+ is discussed in
the original PPM paper in the paragraph following their Eq. 3.5. They
do not keep things in this form however, and instead explicitly multiply

8.2—Reconstruction of interface states

125

out the l · [. . .]r terms to arrive at their Eq. 3.6. For example, starting with
Eq. 8.34, we can write the left velocity state as (leaving off the i subscripts
on the vectors):
uin++1//22,L = ũ+ − ∑ l(ν) · (q̃+ − I+ (q)) |{z}
r(ν)
(ν)

1

ν

(8.41)

only theu ‘slot′(where, as above, the ∼ indicates the reference state). Here the r eigenvector on the end is representative—we only pick the row corresponding
to u in the q vector (in our case, the second row).
Putting in the eigenvectors and writing out the sum, we have:



(−)
ρ̃+ − I+ (ρ)
1

1


ρ
(−)
uin++1//22,L = ũ+ − 0 − 2c 2c12  ũ+ − I+(u)   −c/ρ (−)
c2p̃+ − I+ ( p)
 

(◦)
ρ̃+ − I+ (ρ)
1− 1 0 − c12  ũ+ − I+(◦) (u)   0 (◦)
0p̃+ − I+ ( p)




(+)
ρ̃+ − I+ (ρ)
1− 0 2cρ 2c12  ũ+ − I+(+) (u)   c/ρ (8.42)
2(+)
cp̃+ − I ( p)+Here again we show the entire right eigenvector for illustration, but only
the element that comes into play is drawn in black. This shows that thesecond term is 0—the contact wave does not carry a jump in velocity.
(ν)
Multiplying out l(ν) · (q̃+ − I+ ) we have:"#(−)
p̃+ − I+ ( p)
1
(−)
n+1/2
ui+1/2,L = ũ+ −(ũ+ − I+ (u)) −
2
C
"
#
(+)
p̃
−
I
(
p
)
1
+
(+)
+
(ũ+ − I+ (u)) +(8.43)−
2
C√
where C is the Lagrangian sound speed (C = γpρ). Defining"#(+)
p̃+ − I+ ( p)
1
(+)
(+)
β
=−
(ũ+ − I+ (u)) +
2C
C
"
#
(−)
p̃+ − I+ ( p)
1
(−)
(−)
β
=+
(ũ+ − I+ (u)) −2C
C(8.44)(8.45)

we can write our left state as:uin++1//22,L = ũ+ + C ( β(+) − β(−) )1(8.46)

Chapter 8. Euler Equations: Numerical Methods

126

This is Eqs. 3.6 and 3.7 in the PPM paper. Note that in their construction
appears to use the reference state in defining the Lagrangian sound speed(in their β expressions is written as C̃). This may follow from the comment
before Eq. 3.6, “modified slightly for the present application”. Similarly,
the expressions for ρ L and p L can be written out.
Similar expressions can be derived for the right state at the left interface of the zone1(qin−+1//22,R ). Here, the integral under the parabolic reconstruction is done over theregion of each wave that can reach the left interface over our timestep:(ν)

I− (q) =1(νσ ) ∆xZ xi−1/2 +σ(ν) ∆x
xi−1/2q( x )dx(8.47)The right state at i − 1/2 using zone i data is:qin−+1//22,R = q̃− −1where the reference state is now:
(
q̃− =

∑

ν;λν ≤0

(ν)

li



(ν)
(ν)
· q̃− − I− (qi ) ri

(8.48)(−)

I− (qi ) if u − c < 0qiotherwise(8.49)

where the (−) superscript on I indicates that the most negative eigenvalue (λ− =(ν)
u − c) is used. The integral I− (q) can be computed analytically by substituting in
the parabolic interpolant, giving:


(ν) 
σi
2 (ν)
(ν)
I− (qi ) = q−,i +∆qi + q6,i 1 − σi23(8.50)

This is equivalent to Eq. 31b in the Castro paper.
New PPM limiters
Recent work [27] has formulated improved limiters for PPM that do not clip the
profiles at extrema. This only changes the limiting process in defining q+ and q− ,and does not affect the subsequent parts of the algorithm.

8.2.4

Flattening and contact steepening

Shocks are self-steepening (this is how we detect them in the Riemann solver—welook for converging characteristics). This can cause trouble with the methods here,
because the shocks may become too steep.
Flattening is a procedure to add additional dissipation at shocks, to ensure that they
are smeared out over ∼ 2 zones. The flattening procedure is a multi-dimensional

8.2—Reconstruction of interface states

127

operation that looks at the pressure and velocity profiles and returns a coefficient,χ ∈ [0, 1] that multiplies the limited slopes. The convention most sources use is thatχ = 1 means no flattening (the slopes are unaltered), while χ = 0 means complete
flattening—the slopes are zeroed, dropping us to a first-order method. See for example in Saltzman [66]. Once the flattening coefficient is determined, the interface stateis blended with the cell-centered value via:
qin++1//22,{ L,R} ← (1 − χ)qi + χqin++1//22,{ L,R}
1

1

(8.51)

Note that the flattening algorithm increases the stencil size of piecewise-linear andpiecewise-parabolic reconstruction to 4 ghost cells on each side. This is because
the flattening procedure itself looks at the pressure 2 zones away, and we need toconstruct the flattening coefficient in both the first ghost cell (since we need theinterface values there) and the second ghost cell (since the flattening procedure looks
at the coefficients in its immediate upwinded neighbor).
In contrast to shocks, contact waves do not steepen (they are associated with the middle characteristic wave, and the velocity does not change across that, meaning there
cannot be any convergence). The original PPM paper advocates a contact steepening
method to artificially steepen contact waves. While it shows good results in 1-d, it
can be problematic in multi-dimensions.
Overall, the community seems split over whether this term should be used. Many
people advocate that if you reach a situation where you think contact steepening may
be necessary, it is more likely that the issue is that you do not have enough resolution.

8.2.5

Limiting on characteristic variables

Some authors (see for example, [76] Eqs. 37, 38) advocate limiting on the characteristic
variables rather than the primitive variables. The characteristic slopes for the quantity
carried by the wave ν can be found from the primitive variables as:∆w(ν) = l(ν) · ∆q

(8.52)

any limiting would then be done to ∆w(ν) and the limited primitive variables would
be recovered as:(ν)∆q = ∑ ∆w r(ν)(8.53)
ν(here we use an overline to indicate limiting).
This is attractive because it is more in the spirit of the linear advection equation andthe formalism that was developed there. A potential downside is that when you limiton the characteristic variables and convert back to the primitive, the primitive variables may now fall outside of valid physical ranges (for example, negative density).

Chapter 8. Euler Equations: Numerical Methods

128

i − 3/2

i−1

i − 1/2ii + 1/2

i+1

i + 3/2i+2i + 5/2

Figure 8.6: The Riemann wave structure resulting from the separate Riemann problems
at each interface. For each interface, we find the state on the interface and use this toevaluate the flux through the interface.

8.3

Riemann solvers

Once the interface states are created, the Riemann solver is called. This returns thesolution at the interface:
qin++1//22 = R(qin++1//22,L , qin++1//22,R )
1

1

1(8.54)

This is done for every interface, as illustrated in Figure 8.6.
As discussed in § 7.2.4, we need to determine which state is on our interface tocompute the fluxes through the interface. The full solution of the Riemann problem
can be quite expensive, so in practice, approximate Riemann solvers are used to speed
the computation. Different Riemann solvers will have different approximations forfinding the speeds of the left, center, and right wave, and evaluating the star state.
In the ‘star’ region, only ρ jumps across the middle (contact) wave, the pressureand velocity are constant across that wave (see r(◦) ). We determine the state in thestar region (ρ∗l , ρr∗ , u∗ , p∗ ) by using the jump conditions for the Euler equations or
the Riemann invariants, as shown in § 7.2.3. Some approximate Riemann solvers
assume that both waves are shocks or both are rarefactions, aimplying the form of
the equation that must be solved to find p⋆ .
Two-shock solvers, like the one in [25] are quite common in astrophyiscs. Figure 8.7
shows the Hugoniot curves for the Sod problem under the 2-shock assumption—theyare quite close to those for the true solution. To further save on cost, approximate
Riemann solvers for general equations of state often include additional thermodynamic information at the interfaces that overconstrains the system, but can remove
the need to call an expensive equation of state routine in solving for the star state.
An additional approximation concerns rarefactions. Recall that a rarefaction involves
diverging flow—it spreads out with time. Special consideration needs to be taken if
the rarefaction wave spans the interface (a transonic rarefaction, § 7.2.4). In this case,most approximate Riemann solvers simply linearly interpolate between the left or8.3—Riemann solvers

129

6
4

u

2
0 right

left

2
4
0.0

0.2

0.4

0.6

p

0.8

1.0

1.2

1.4

Figure 8.7: The approximate Hugoniot curves under the 2-shock approximation corresponding to the Sod problem. Also shown as the gray dotted line is the exact Hugoniot
curves (compare to Figure 7.3). We see that the 2-shock approximation does a reasonable job near the intersection and only diverges significantly for small p (which is where
the solution should really be a rarefaction).
hydro_examples: riemann-2shock.pyÏright state and the appropriate star state instead of solving for the structure inside
the rarefaction.
With this approximate state, the fluxes are computed as:

1
Fin++1//22 = 






1
1
ρin++1//22 uin++1//22
1
1
1
ρin++1//22 (uin++1//22 )2 + pin++1//22

uin++1//22 pin++1//22 /(γ − 1) + 21 ρin++1//22 (uin++1//22 )3 + uin++1//22 pin++1//22
1

1

1

1

1

1







(8.55)

A different class of approximate Riemann solvers (the HLL family) approximate thefluxes directly instead of approximating the state first. These require estimates of
the wave speeds, and care must be taken to ensure those estimates are valid fora general equation of state. These wave speeds are then used together with the
Rankine-Hugoniot jump conditions to give the fluxes.

Chapter 8. Euler Equations: Numerical Methods

130

8.4

Conservative update

Once we have the fluxes, the conservative update is done as

U in+1 = U in +

∆t  n+1/2
1
Fi−1/2 − Fin++1//22∆x(8.56)The timestep, ∆t is determined by the time it takes for the fastest wave to cross asingle zone:∆x(8.57)∆t < min|U · ed | + cd(This is the limit for the CTU unsplit scheme here, but see the discussion in § 5.4.3).
Often simulation codes will further restrict the timestep. Commonly used restrictions
for pure hydrodynamics include a limit on the factor by which a timestep can growfrom one step to the next (a typical value is 1.2), and an initial scaling, say of 1/10,
for the first timestep. Together, these will force the code to take a few initial steps
before working up to the CFL limit.

8.4.1

Artificial viscosity

Colella and Woodward argue that behind slow-moving shocks these methods canhave oscillations. The fix they propose is to use some artificial viscosity—this isadditional dissipation that kicks in at shocks. (They argue that flattening alone is notenough).
We use a multidimensional analog of their artificial viscosity ([28], Eq. 4.5) which
modifies the fluxes. By design, it only kicks in for converging flows, such that you
would find around a shock.

8.5

Boundary conditions

Boundary conditions are implemented through ghost cells. The following are themost commonly used boundary conditions. For the expressions below, we use thesubscript lo to denote the spatial index of the first valid zone in the domain (justinside the left boundary).
• Outflow: the idea here is that the flow should gracefully leave the domain. The
simplest form is to simply give all variables a zero-gradient: ρlo−1,jρlo,j (ρu)lo−1,j   (ρu)lo,j   (ρv)lo−1,j  =  (ρv)lo,j (ρE)lo−1,j(ρE)lo,j(8.58)

8.6—Multidimensional problems

131

Note that these boundaries are not perfect. At the boundary, one (or more)of the waves from the Riemann problem can still enter the domain. Only forsupersonic flow, do all waves point outward.
• Reflect: this is appropriate at a solid wall or symmetry plane. All variables arereflected across the boundary, with the normal velocity given the opposite sign.
At the x-boundary, the first ghost cell is:

 

ρlo,j
ρlo−1,j (ρu)lo−1,j   −(ρu)lo,j  (8.59)
 (ρv)lo−1,j  =  (ρv)lo,j (ρE)lo−1,jThe next is: ρlo+1,jρlo−2,j (ρu)lo−2,j   −(ρu)lo+1,j   (ρv)lo−2,j  =  (ρv)lo+1,j (ρE)lo−2,jand so on . . .

(ρE)lo,j(8.60)(ρE)lo+1,j• Inflow: inflow boundary conditions specify the state directly on the boundary.
Technically, this state is on the boundary itself, not the cell-center. This can be
accounted for by modifying the stencils used in the reconstruction near inflow
boundaries.
• Hydrostatic: a hydrostatic boundary can be used at the base of an atmosphereto provide the pressure support necessary to hold up the atmosphere against
gravity while still letting acoustic waves pass through. An example of this is
described in [87].

8.6

Multidimensional problems

The multidimensional case is very similar to the multidimensional advection problem. Our system of equations is now:

U t + [F(x) ( U )] x + [F(y) ( U )]y = 0
with




ρ
 ρu 
U =
 ρv 
ρEρu ρuu + p F( x) ( U ) = ρvuρuE + up

(8.61)



ρv


ρvu

F(y) ( U ) =  ρvv + p  (8.62)
ρvE + vp

We note that there is no transformation that can convert the multidimensional system into characteristic variables, since we cannot simultaneously diagonalize the Jacobians corresponding to F(x) and F(y) . Related to this is that when limiting, weChapter 8. Euler Equations: Numerical Methods

132

limit one-dimensional slopes instead of doing a full multidimensional reconstruction
and limiting (see [11] for a multidimensional limiting procedure for linear advection.
For the Euler equations, since we cannot write the multidimensional system in acharacteristic form, we cannot use this type of method).
For a directionally-unsplit discretization, we predict the cell-centered quantities tothe edges by Taylor expanding the conservative state, U , in space and time. Now,
when replacing the time derivative (∂ U /∂t) with the divergence of the fluxes, wegain a transverse flux derivative term. For example, predicting to the upper x edgeof zone i, j, we have:∆x ∂ U∆t ∂ U
+
+...
2 ∂x
2 ∂t
∆x ∂ U∆t ∂F(x)∆t ∂F(y)n= U i,j
+
−
−
2 ∂x
2 ∂x
2 ∂y


∆t (x)∆t ∂F(y)1n= U i,j1−
A ( U) ∆ U −
+
2
∆x
2 ∂y

n
U in++1//22,j,L = U i,j+1(8.63)(8.64)(8.65)

where A(x) ( U ) ≡ ∂F(x) /∂ U . We decompose this into a normal state and a transverse
flux difference. Adopting the notation from Colella (1990), we use Û to denote thenormal state:n+1/2

nÛ i+1/2,j,L ≡ U i,j
+
n+1/2



1
∆t (x)1−
A ( U) ∆ U
2∆x

U in++1//22,j,L = Û i+1/2,j,L −1(8.66)∆t ∂F(y)2 ∂y(8.67)The primitive variable form for this system is
qt + A( x ) ( q ) q x + A(y) ( q ) qy = 0(8.68)

where

0 ρ
0
v 0
0 

0 v 1/ρ 
0 γpv(8.69)
There are now 4 eigenvalues. For A(x) (q), they are u − c, u, u, u + c. If we just lookat the system for the x evolution, we see that the transverse velocity (in this case, v)
just advects with velocity u, corresponding to the additional eigenvalue.



ρ
 u 

q=
 v 
p



u ρ

0 u
A( x) (q) = 
 0 0
0 γp


0
0
0 1/ρ 

u
0 
0
u



v

0
A(y) ( q ) =  008.6—Multidimensional problems

133

Exercise 8.4
Derive the form of A(x) (q) and A(y) (q) and find their left and righteigenvectors.
n+1/2

We note here that Û i+1/2,j,L is essentially one-dimensional, since only the x-fluxes are
involved (through A(x) ( U )). This means that we can compute this term using the
one-dimensional techniques developed in § 8.2. In particular, Colella (1990) suggestthat we switch to primitive variables and compute this as:
n+1/2Û i+1/2,j,L = U (q̂in++1//22,j,L )1(8.70)

Similarly, we consider the system projected along the y-direction to define the normal states on the y-edges, again using the one-dimensional reconstruction on theprimitive variables from § 8.2:
n+1/2

n+ /2
Û i,j+1/2,L = U (q̂i,j+1/2,L )1(8.71)

To compute the full interface state (Eq. 8.67), we need to include the transverse term.
Colella (1990) gives two different procedures for evaluating the transverse fluxes. The
first is to simply use the cell-centered U i,j (Colella 1990, Eq. 2.13); the second is to use
the reconstructed normal states (the Û ’s) (Eq. 2.15). In both cases, we need to solvea transverse Riemann problem to find the true state on the transverse interface. Thislatter approach is what we prefer. In particular, for computing the full x-interface left
1
state, U in++1//22,j,L , we need the transverse (y) states, which we define as
n+1/2

n+1/2

n+1/2

n+1/2

T
U i,j
+1/2 = R( Û i,j+1/2,L , Û i,j+1/2,R )(8.72)

TU i,j−1/2 = R( Û i,j−1/2,L , Û i,j−1/2,R )(8.73)

Taken together, the full interface state is now:∆t
1
1
U in++1//22,j,L = U (q̂in++1//22,j,L ) −
2

T
T
(y)
F(y) ( U i,j+1/2 ) − F ( U i,j−1/2 )∆y(8.74)The right state at the i + 1/2 interface can be similarly computed (starting with thedata in zone i + 1, j and expanding to the left) as:∆t
1
1
U in++1//22,j,R = U (q̂in++1//22,j,R ) −2

F(y) ( U iT+1,j+1/2 ) − F(y) ( U iT+1,j−1/2 )∆y(8.75)

Note the indices on the transverse states—they are now to the right of the interface(since we are dealing with the right state).

Chapter 8. Euler Equations: Numerical Methods

134

We then find the x-interface state by solving the Riemann problem normal to ourinterface:1
1
1
U in++1//22,j = R( U in++1//22,j,L , U in++1//22,j,R )(8.76)
Therefore, construction of the interface states now requires two Riemann solves: atransverse and normal one. The fluxes are then evaluated as:( x ),n+1/2

Fi+1/2,j= F(x) ( U in++1//22,j )1(8.77)

Note, for multi-dimensional problems, in the Riemann solver, the transverse velocities are simply selected based on the speed of the contact, giving either the left or
right state.
The final conservative update is done as:
n +1
n
U i,j
= U i,j+8.6.1

 ∆t 
∆t  (x),n+1/2(y),n+1/2(y),n+1/2( x ),n+1/2+
Fi−1/2,j − Fi+1/2,jFi,j−1/2 − Fi,j+1/2∆x∆y(8.78)

3-d unsplit

The extension of the unsplit methodology to 3-d is described by Saltzman [66]. The
basic idea is the same as in 2-d, except now additional transverse Riemann solve areneeded to fully couple in the corners.

8.7

Source terms

Adding source terms is straightforward. For a system described by

U t + [F(x) ( U )] x + [F(y) ( U )]y = H(8.79)

we predict to the edges in the same fashion as described above, but now when we
replace ∂ U /∂t with the divergence of the fluxes, we also pick up the source term.
This appears as:∆x ∂ U∆t ∂ U
+
+...
2 ∂x
2 ∂t
∆x ∂ U∆t ∂F(x)∆t ∂F(y)∆tn= U i,j+−−+ Hi,j
2 ∂x
2 ∂x
2 ∂y
2


(
1
∆t (x)∆t ∂F y)∆tn
= U i,j+1−
A ( U) ∆ U −+ Hi,j
2
∆x
2 ∂y
2

n
U in++1//22,j,L = U i,j+1(8.80)(8.81)(8.82)

We can compute things as above, but simply add the source term to the Û ’s andcarry it through.
Note that the source here is cell-centered. This expansion is second-order accurate.
This is the approach outlined in Miller & Colella [53]. Also notice the similarity ofthis source term to a second-order Euler method for integrating ODEs.

8.7—Source terms

135

Alternately, we can include the source terms in the characteristic tracing of the interface states. This is the approach taken in, e.g., the original PPM paper. To makethings more concrete, let’s consider just gravity as the source. Our primitive variable
equations in this case are:qt + A(q)q x = G(8.83)
where G = (0, g, 0)T —i.e. the gravitational source only affects u, not ρ or p† .
First we construct a parabolic profile of g in each zone and integrate under thatprofile to determine the average g carried by each wave to the interface, we’ll denote(ν)
these as I± ( g). Then we include the gravitational source term in the characteristic
projection itself. Our projections are now:∑(ν)l(ν) · (q̃ − I+ (q) − ∆t
2 G)r

∑

(ν)
l(ν) · (q̃ − I− (q) − ∆t2 G)rν;λ(ν) ≥0(ν)(8.84)

for the left state, andν;λ(ν) ≤0(ν)(8.85)

for the right state. Since G is only non-zero for velocity, only the velocity changes.
Writing out the sum (and performing the vector products), we get:1
1
uin++1//22,L = ũ+ −
2
1
−
2

"
"

∆t (−)(−)
ũ+ − I+ (u) − I+ ( g)2

∆t (+)(+)
ũ+ − I+ (u) − I+ ( g)
2

(−)





(−)

p̃+ − I+ ( p)−C(+)

p̃+ − I+ ( p)
+
C

#
#

(8.86)(+)

where the only change from Eq. 8.43 are the I+ ( g) and I+ ( g) terms. ‡Regardless of how the source term information is included in the interface states, we
also need to include it in the conservative update. To second-order, we need it to betime-centered, which usually means averaging the time-level n and n + 1 sources:∆t  (x),n+1/2( x ),n+1/2
Fi−1/2,j − Fi+1/2,j∆x ∆t 
∆t  (y),n+1/2(y),n+1/2nn +1+Fi,j−1/2 − Fi,j+1/2+
H( U i,j) + H( U i,j
)
∆y
2

n +1
n
U i,j
= U i,j+(8.87)† Note that in the PPM paper, they put G on the lefthand side of the primitive variable equation, so

our signs are opposite.
‡ These differ from the expression in the PPM paper, where ∆tG, not ( ∆t/2) G is used in the projection, however this appears to be a typo. To see this, notice that if both waves are moving toward the
(−)

(+)

interface, then the source term that is added to the interface state is (∆t/4)(I+ ( g) + I+ ( g)) for theleft state, which reduces to (∆t/2) g for constant g—this matches the result from the Taylor expansion
above (Eq. 8.82).

Chapter 8. Euler Equations: Numerical Methods

136

As written, this appears to be an implicit update (since U n+1 depends on Hn+1 ), but
often, the form of the source terms allows you to update the equations in sequence
explicitly.
Again, using a constant gravitational acceleration as an example, and looking in 1-dfor simplicity, U = (ρ, ρu, ρE)⊺ and H = (0, ρg, ρug)⊺ , so our update sequence is:i∆t h n+1/2 n+1/2
11ρi−1/2 ui−1/2 − ρin++1//22 uin++1//22(8.88)∆xi ∆t 
∆t h n+1/2 n+1/2 211
11
ρi−1/2 (ui−1/2 ) − ρin++1//22 (uin++1//22 )2 +pin−+1//22 − pin++1//22(ρu)in+1 = (ρu)in +
∆x
∆x
∆t n
n +1
(8.89)+ ( ρi + ρi ) g
2

h
∆t
1
1
1
1
ρin−+1//22 Ein−+1//22 + pin−+1//22 uin−+1//22 −(ρE)in+1 = (ρE)in +∆x
i ∆t h


i
1
1
1
1
ρin++1//22 Ein++1//22 + pin++1//22 uin++1//22 +(ρu)n + (ρu)n+1 g
2(8.90)
ρin+1 = ρin +These updates can be done one after another without any implicit coupling. Other
sources, like the Coriolis force, will involve an implicit update, but even then, it islocal to a single zone and can be solved analytically.

8.8

Simple geometries

So far we have been working only with Cartesian geometries, but it is easy to extend these methods to simple non-Cartesian geometies, like spherical and cylindrical.
These geometies allow us to capture 3-d volume expansion effects in lower dimensions.
For a 1-d solver, a spherical geometry means that our coordinate is the radius in
the sphere, and as we move outward from the origin, the volume of a zone (which isactually now a spherical shell) grows. There are two places where we need to take thegeometry into account: the reconstruction of the interface states and the conservative
update.
Our 1-d system in spherical coordinates appears as:∂U
1 ∂r2 F
+ 2
=0
∂t
r ∂r

(8.91)The geometry factors that appear are from the spherical form of the divergence.
Expanding out the radial derivative, we have:
∂F
2F
∂U
+
=−
∂t
∂r
r

(8.92)

8.8—Simple geometries

137

Likewise, the primitive variable equations now have source terms:
∂ρ
∂u
2ρu
∂ρ
+u +ρ
=−
∂t
∂x
∂x
r
∂u
∂u 1 ∂p+u +=0∂t∂x ρ ∂x
∂p
∂p
∂u
2Γ pu
+ u + Γ1 p
=− 1
∂t
∂x
∂x
r

(8.93)(8.94)(8.95)

Exercise 8.5
Derive the above system of 1-d spherical primitive variable equations
starting from the conservative equations. Be sure to include the geometry factors everywhere there is a divergence.
For the prediction of the interface states, we now include these geometric source
terms as sources to the interface state, following the same ideas as in § 8.7.
The conservative update now needs to include the geometry factors. However, it
is complicated by the fact that in the momentum equation, the pressure term is a
gradient, not a divergence, and therefore has different geometic factors. The updateof the system appears as:
i
∆t h
1
1
1
1
ρin+1 = ρin +(8.96)
Ai−1/2 ρin−+1//22 uin−+1//22 − Ai+1/2 ρin++1//22 uin++1//22
Vi
i
∆t h
1
1
1
1
(ρu)in+1 = (ρu)in +Ai−1/2 ρin−+1//22 (uin−+1//22 )2 − Ai+1/2 ρin++1//22 (uin++1//22 )2Vi∆t  n+1/2
1(8.97)
pi−1/2 − pin++1//22
+
∆r


h
∆t
1
1
1
1
(ρE)in+1 = (ρE)in +Ai−1/2 ρin−+1//22 Ein−+1//22 + pin−+1//22 uin−+1//22 −
Vi


i
1
1
1
1
(8.98)
Ai+1/2 ρin++1//22 Ein++1//22 + pin++1//22 uin++1//22

Here, the geometry factors are:Ai−1/2 = (ri−1/2 )2
Vi = (ri ) ∆r2

(8.99)(8.100)

It is also common to do 2-d axisymmetric models—here the r and z coordinates froma cylindrical geometry are modeled. Again, this appears Cartesian, except there is a
volume factor implicit in the divergence that must be accounted for. Our system inaxisymmetric coordinates§ is:∂U
1 ∂rF(r)
∂F(z)
+
+
=0
∂t
r ∂r
∂z

(8.101)§ Some sources will call this cylindrical coordinates, but note that the grid is not a polar grid—it isstill CartesianChapter 8. Euler Equations: Numerical Methods

138

Simulation plane

Figure 8.8: The axisymmetric computational domain. Here we imagine that the 2-dplane rotates through the cylindrical θ angle to create a volume.

Expanding out the r derivative, we can write this as:
∂U
∂F(r)
∂F(z)
F (r )
+
+
=−
∂t
∂r
∂z
r

(8.102)

Again, the primitive variable version of this expanded form is used for the interface
state prediction. The conservative update follows the same idea as the 1-d sphericalversion. The area and volume factors only differ from their Cartesian counterparts in
the radial direction, and take the form:
Ai−1/2,j = ri−1/2 ∆z(8.103)

Vi,j = ri ∆r∆z

(8.105)Ai,j−1/2 = ri ∆z(8.104)

These choices of geometric factors reproduce a discretized form of the cylindrical
divergence:∇·ϕ =1 ∂(rϕ(r) ) ∂ϕ(z)
+
r
∂r
∂z

(8.106)

Just as with the 1-d spherical case, the pressure term in the momentum equationneeds to be treated separately from the flux, since it enters as a gradient and not adivergence.¶¶ It is common to see the divergence term expressed as∇·ϕ =1 ∂ (r α ϕ (r ) )
+...
rα
∂r

(8.107)

where α = 1 for axisymmetric and α = 2 for 1-d spherical. This allows for the geometry correction to
be expressed more concisely, as the source term takes the form −αF/r.

8.9—Some Test problems

8.9

139

Some Test problems

There are a large number of standard test problems that are used to test out our
methods. Like we say with advection, it is best to have a problem with an analytic
solution. Here we show just a few of the most popular test problems.

8.9.1

Shock tubes

Shock tubes are Riemann problems—consider the evolution of an initial discontinuity
in the domain. The evolution with time will just be the solution to the Riemannproblem that we described § 7.2. The initial conditions can be varied to produce any
combination of shocks and rarefactions as the left and right waves. A popular initialcondition is the Sod problem [74] which results is a right moving shock and contact
and a left moving rarefaction.
Note: it is a good test of your code’s ability to preserve symmetry to flip the initialconditions left/right and rerun. The results should be the same to machine precision,
but atleast to roundoff error. A common reason for breaking symmetry is using
inequalities in your code that are biases in a direction, e.g.,
if u > 0:# positive velocity test caseelse :# negative or zero velocity test caseThis has a left-right bias, since we don’t handle the case where u = 0 separately. A
better construction would test on u < 0 alone, and then have a final else clause tocatch u = 0.
Since these tests start out with a discontinuity, they are not the best tests to use forconvergence testing. Wherever there is an initiali discontinuity, the limiters will kickin and drop your method to first-order accurate.
For a general equation of state, you can still solve the Riemann problem exactly anddefine analogous test problems to those commonly used for a gamma-law gas. Someshock tube test problems for a stellar equation of state are shown in [88].
For the tests shown below, we use the hydro1d code described in Appendix C.
Sod problem
The initial conditions for the Sod problem [74] are:ρl = 1

ρr = 1/8

ul = 0ur = 0pl = 1

pr = 1/10(8.108)

Chapter 8. Euler Equations: Numerical Methods

140

1.00

exact
piecewise constant

ρ

0.75
0.50
0.25
0.00
0.0
1.00

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

2.75
2.50
2.25
2.00
1.75
0.0

0.2

0.4

0.6

0.8

1.0

u

0.75
0.50
0.25
0.00
0.0
1.00
p

0.75
0.50

e

0.25

x

Figure 8.9: Piecewise constant reconstruction with the Sod problem, using 128 zones,
C = 0.8, and the CGF Riemann solver. This was run with hydro1d using the sod
problem setup, setting godunov_type=0 and visualized with the sod_compare.py script
there.

usually with γ = 1.4

These result in a left wave moving contact and rightward moving contact and shock.
The shock is not particularly strong, but this problem is a nice demonstration of thetypes of hydrodynamic waves.

8.9—Some Test problems

141

1.00

exact
piecewise parabolic

ρ

0.75
0.50
0.25
0.00
0.0
1.00

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

u

0.75
0.50
0.25
0.00
0.0
1.00
p

0.75
0.50
0.25
0.0

e

2.5
2.0
0.0

x

Figure 8.10: Piecewise parabolic reconstruction with the Sod problem, using 128 zones,
C = 0.8, and the CGF Riemann solver. This was run with hydro1d using the sod
problem setup, setting godunov_type=2 and visualized with the sod_compare.py script
there.

Double rarefaction
The double rarefaction problem starts with initially diverging flow that creates a
vacuum state in the middle. The initial conditions (as given in [82] areρl = 1

ρr = 1

ul = −2.0

ur = 2.0

pl = 0.4

pr = 0.4(8.109)

Chapter 8. Euler Equations: Numerical Methods

142

1.00

exact
piecewise constant

ρ

0.75
0.50
0.25
0.00
0.0

0.2

0.4

0.6

0.8

1.0

2
0.0

0.2

0.4

0.6

0.8

1.0

0.4
0.3
0.2
0.1
0.0
0.0

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

2

u

1
0

p

1

1.0
e

0.8
0.6
0.4
0.2
0.0

x

Figure 8.11: Piecewise constant reconstruction with the double rarefaction problem,
using 128 zones, C = 0.8, and the CGF Riemann solver. This was run with hydro1d using the sod problem setup, setting godunov_type=0 and visualized with thesod_compare.py script there.

8.9.2

Sedov blast wave

The Sedov (or Sedov-Taylor) blast wave [70] is a point explosion—energy, Eexpl , isplaced at a point in a uniform domain. A spherical shockwave propagates outward,
evacuating the region in the center. The Sedov problem also has an analytic solution|| , and this problem is a good way of testing out the geometric factors for 1-d
spherical and 2-d axisymmetric geometries.
|| See [42] for a nice code to general the solutions

8.9—Some Test problems

143

1.00

exact
piecewise parabolic

ρ

0.75
0.50
0.25
0.00
0.0

0.2

0.4

0.6

0.8

1.0

2
0.0

0.2

0.4

0.6

0.8

1.0

0.4
0.3
0.2
0.1
0.0
0.0

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

2

u

1
0

p

1

1.0
e

0.8
0.6
0.4
0.2
0.0

x

Figure 8.12: Piecewise parabolic reconstruction with the double rarefaction problem,
using 128 zones, C = 0.8, and the CGF Riemann solver. This was run with hydro1d using the sod problem setup, setting godunov_type=2 and visualized with thesod_compare.py script there.

The major difficulty with initializing the Sedov problem is representing a point,where all the energy desposited, on the grid. If you just initialize a singe zone,
then the size of the point changes as you change resolution. Additionally, in 2- or 3-dCartesian coordinates, the point will be squared off. A standard way of initializing
this (see, e.g., [58]) is to imagine the energy deposition inflating a region of radius rinit
3 /3
like a balloon, resulting in an energy density, E = Eexpl /Vinit , where Vinit = 4πrinit
2
for a spherical blast wave and Vinit = πrinit
for a cylindrical blast wave. Then theChapter 8. Euler Equations: Numerical Methods

144

exact
simulation

5

ρ

4
3
2
1
0
0.00

0.05

0.10

0.15

0.20

0.25

0.30

0.35

0.05

0.10

0.15

0.20

0.25

0.30

0.35

0.05

0.10

0.15

0.20

0.25

0.30

0.35

5

u

4
3
2

p

1
0
0.00
35
30
25
20
15
10
5
0
0.00

r

Figure 8.13: 1-d Sedov explosion with piecewise parabolic reconstruction, using 128
zones (on r ∈ [0, 1]), C = 0.8, and the CGF Riemann solver. This was run with hydro1dusing the sedov problem setup and visualized with the sedov_compare.py script there.
The 1-d spherical geometry used makes this act as if it were a sphere.

pressure is
p=

Eexpl
( γ − 1)
Vinit

(8.110)Figure 8.13 shows the solution to the Sedov problem in 1-d in a spherical geometry.
This is compared to the spherical Sedov solution (solid line). There is good agreementin the position of the shock and density and velocity profiles. The pressure behindthe shock is a little low—this is likely an artifact of the initialization process.

8.9—Some Test problems

145
U

ρ

1.0

1.2

0.8

3.2

0.6

2.4

0.4

1.6

0.2

0.8

y

0.9

0.0

0.3

0.0

p

1.0

0.6

0.0

e

400

1.6

0.8
1.2

300

0.8

200

0.4

100

y

0.6
0.4
0.2
0.0
0.00

0

0.0
0.25

0.50
x

0.75

1.00

0.00

0.25

0.50
x

0.75

1.00

t = 0.1

Figure 8.14: 2-d Sedov explosion with piecewise linear reconstruction, using 1282
zones (on r ∈ [0, 1] × [0, 1]), C = 0.8, and the HLLC Riemann solver. This was run withpyro as ./pyro.py compressible sedov inputs.sedov. An initial perturbation size ofrinit = 0.01 was used.

In 2-d, we run the problem in Cartesian coordinates—this produces a cylindrical
blast wave. Figure 8.14 shows the solution in 2-d. The density and pressure lookvery symmetric. In the velocity magnitude plot, we see an imprint of the grid along
coordinate axes, and likewise in the internal energy. The bump in internal energy
near the origin arises because of the error in defining e from E and U. We can produce
an angle-averaged profile of this and compare to the analytic solution, shown in
Figure 8.15.

8.9.3

Advection

We can run a simple advection test analogous to the tests we used in Ch. 4. However,
because we are now doing hydrodynamics, we need to suppress the dynamics. Thisis accomplished by putting the profile we want to advect in the density field andthen put it in pressure equilibrium by adjusting the internal energy. For example,

Chapter 8. Euler Equations: Numerical Methods

146

exact
simulation

5

ρ

4
3
2
1
0
0.0

0.1

0.2

0.3

0.4

0.5

0.6

0.1

0.2

0.3

0.4

0.5

0.6

0.1

0.2

0.3
r

0.4

0.5

0.6

1.25

u

1.00
0.75
0.50
0.25
0.00
0.0
2.0

p

1.5
1.0
0.5
0.0
0.0

Figure 8.15: Angle-average profile for the 2-d Sedov explosion from Figure 8.14 shownwith the analytic solution. This was constructed using the sedov_compare.py script in
pyro.

consider a Gaussian profile. We initialize the density as:22

ρ = (ρ1 − ρ0 )e−(x− xc ) /σ + ρ0

(8.111)

8.9—Some Test problems

147

1.0

exact
simulation

0.8

0.6

0.4

0.2

0.0
0.0

0.2

0.4

0.6

0.8

1.0

Figure 8.16: Piecewise parabolic reconstruction with an advection test, using 128 zones,
C = 0.8, and the CGF Riemann solver. A Gaussian profile was advected for 10 periods.
This was run with hydro1d using the advect problem setup and visualized with theadvect_compare.py script there.

To advect the profile to the right, we choose a constant velocity,u = u0(8.112)and to suppress dynamics, we make the pressure constant,p = p0(8.113)

Finally, we compute the total energy as
ρE =

1
p
+ ρu2
γ−1 2

(8.114)

Figure 8.16 shows an example of a Gaussian profile advected for 10 periods. The
initial conditions used ρ0 = 10−3 , ρ1 = 1, p0 = 10−6 , u0 = 1, and σ = 0.1 (thesecoincide with the choices used in [34]). The non-zero value for the ambient density,
ρ0 , ensures that any quantities that are derived by dividing by density remain welldefined. The result is similar to what we saw when we considered pure advection—
the shape is mostly preserved, but the peak of the Gaussian is clipped.

8.9.4

Slow moving shock

Slow moving (or stationary) shocks can be difficult to model, as oscillations can be
setup behind the shock (this is discussed a little in [28, 46]). We can produce a slow

Chapter 8. Euler Equations: Numerical Methods

148

moving shock as a shock tube, and we can use the jump conditions across a shock thatwere derived for the Riemann problem to find the conditions to setup a stationary(or slow-moving) shock.
The speed of a right-moving shock was found (see Eq. 7.90) as:
1 p⋆ γ + 1 γ − 1 /2+
S = ur + cr
pr2γ2γ
We want S = 0, which allows us to express the pre-shock velocity, ur , as: 1p⋆ γ + 1 γ − 1 /2
ur = − cr
+
pr
2γ
2γ

(8.115)(8.116)

We have the freedom to choose the density and pressure ahead of the shock, ρr andpr , which in turn gives us cr . Next, we can pick the strength of the shock by choosing
the jump in pressure, p⋆ /pr . Together, this allows us to compute ur , and thus weknow the entire pre-shock state. We can compute the post-shock state (which was
the star state when we discussed the Riemann problem) using the jump conditions,Eqs. 7.86 and 7.89.**
For a pressure jump of 100 across a shock, the following conditions will generate astationary right-facing shock (with γ = 1.4):
ρl = 5.6698

ρr = 1

ul = −1.9336

ur = −10.9636

pl = 100(8.117)

pr = 1

By adjusting the velocity of both the left and right state, we can produce a strong
shock that moves slowly across the grid. For instance, a shock with S = 0.4 resultsfromρl = 5.6698

ρr = 1

ul = −1.5336

ur = −10.5636

pl = 100

8.9.5(8.118)pr = 1

Two-dimensional Riemann problems

Several different 2-d Riemann problems were introduced in [69], to explore the multidimensional interactive of the different hydrodynamic waves. These problems initialize the 4 quadrants of the domain with different states, and watch the ensuing
evolution. There are some analytic estimates that can be compared to, but also thesetests can provide a means of assessing the symmetry of a code in the presence ofcomplex flows. We use the setup corresponding to configuration 3 in that paper (thissame setup is used in [45]).
** The script slow_shock.py will find the initial conditions to generate a stationary shock.

8.10—Method of lines integration and higher order

149

6

exact
simulation

5
ρ

4
3
2
1
0.0

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

0.2

0.4

0.6

0.8

1.0

2

u

4
6
8
10
0.0
100
80
p

60
40
20
0
0.0

x

Figure 8.17: 1-d slow moving shock problem with piecewise parabolic reconstruction,using 128 zones (on r ∈ [0, 1]), C = 0.8, and the CGF Riemann solver. This was run withhydro1d using the sod problem setup and visualized with the sod_compare.py script
there.

8.10

Method of lines integration and higher order

Just like we explored with linear advection (§ 5.3), instead of doing the characteristic
tracing, we could rely on the integrator to do the work for us.
Discretizing our system in space leads to the following system:
F(x) ( U i+1/2,j ) − F(x) ( U i−1/2,j ) F(y) ( U i,j+1/2 ) − F(y) ( U i,j−1/2 )d U i,j
=−
−
dt
∆x
∆y

(8.119)

Chapter 8. Euler Equations: Numerical Methods

150

U

ρ

1.0

1.6

2.0

1.2

1.5

0.8

y

0.6

1.0

0.8

0.4
0.2

0.5

0.4

0.0

p

1.0

0.0

e
1.6

3.0

1.2

2.4

0.8

1.8

0.4

1.2

0.8

y

0.6
0.4
0.2
0.0
0.00

0.6
0.25

0.50
x

0.75

1.00

0.00

0.25

0.50
x

0.75

1.00

t = 0.8

Figure 8.18: Two-dimensional Riemann problem from [69].

Note that there is no time superscript in the U used to evaluate the fluxes on therighthand side—we have not done any time discretization yet. Now we can use an
ODE integrator to solve this system.
Consider second-order Runge-Kutta. We evaluate two slopes,

k1 = ∆t −

−k2 = ∆t −F(x) ( U in+1/2,j ) − F(x) ( U in−1/2,j )
∆x


n
n
(y)
F(y) ( U i,j+1/2 ) − F ( U i,j−1/2 )(8.120)∆y

F(x) ([ U n + k1/2 ]i+1/2,j ) − F(x) ([ U n + k1/2 ]i−1/2,j )∆xF(y) ([ U n + k1/2 ]i,j+1/2 ) − F(y) ([ U n + k1/2 ]i,j−1/2 )−∆y(8.121)and then
n +1
n
U i,j
= U i,j+ k2(8.122)

8.11—Thermodynamic issues

151

In the construction of the interface states, U in+1/2,j or [ U n + k1/2 ]i+1/2,j , there is non
in time throughexplicit transverse term, since that arose from Taylor expanding U i,j∆t/2. Instead, we simply construct these interface states using a one-dimensional
reconstruction and solve a Riemann problem at each interface. The evaluation of thesecond slope, k2 , implicitly includes the transverse information since we add k1/2 ton
U i,jbefore doing the prediction to the interfaces. Also note, however, that in thisconstruction of the interface states, there is no characteristic projection, since thatarises from predicting the interface states forward in time. Again, these interface
states are at a constant time, not predicted into the future.
Generally speaking we want the order of accuracy in time to match that in space.
The fourth-order Runge-Kutta method is a popular method for integrating ODEs, so
it makes sense to couple this with a fourth-order-in-space method. However, goinghigher-order than second-order is more challenging. The key issue is that we canno longer simply approximate the cell average as the cell-center value, i.e., ⟨ϕ⟩i ̸= ϕi .
This comes into play, for instance, in translating between the conserved and primitive
variables. A fully fourth-order method is presented in [52]Note that when using a Runge-Kutta method-of-lines integrator for the time-discretizationof a multidimensional system, the timestep is actually more restrictive than the cases
presented above that predicted the interface states to the half-time and performed
characteristic tracing. Titarev & Toro [81] claim that you need 0 < C < 1/2 for 2-dflows and 0 < C < 1/3 for 3-d flows.
An additional complexity arises when doing multiphysics. Often we split the different physical processes up and treat them in turn. There are standard methods to do
this with second-order accuracy in time, but higher-order is more tricky.

8.11

Thermodynamic issues

8.11.1

Defining temperature

Although not needed for the pure Euler equations, it is sometimes desirable to define
the temperature for source terms (like reactions) or complex equations of state. The
temperature can typically be found from the equation of state given the internalenergy:1e = E − u22
T = T (e, ρ)(8.123)(8.124)

Trouble can arise when you are in a region of flow where the kinetic energy dominates (high Mach number flow). In this case, the e defined via subtraction can become
negative due to truncation error in the evolution of u compared to E. In this instance,
one must either impose a floor value for e or find an alternate method of deriving it.

Chapter 8. Euler Equations: Numerical Methods152

In [19], an alternate formulation of the Euler equations is proposed. Both the totalenergy equation and the internal energy equation are evolved in each zone. Whenthe flow is dominated by kinetic energy, then the internal energy from the internalenergy evolution equation is used. The cost of this is conservation—the internalenergy is not a conserved quantity, and switching to it introduces conservation ofenergy errors.

8.11.2

General equation of state

The above methods were formulated with a constant gamma equation of state. A
general equation of state (such as degenerate electrons) requires a more complex
method. Most methods are designed to reduce the need to call a complex equationof state frequently, and work by augmenting the vector of primitive variables withadditional thermodynamic information. There are two parts of the adaption to a
general equation of state: the interface states and the Riemann problem.

Carrying γe
The classic prescription for extending this methodology is presented by Colella andGlaz [25]. They construct a thermodynamic index,
γe =

p
+1
ρe

(8.125)and derive an evolution equation for γe (C&G, Eq. 26). We can derive a similar
expression as
Dγe
D
=
Dt
Dt



p
+1
ρe



=−

p D (ρe)
1 Dp+2(ρe) Dt
ρe Dt= (γe − 1)(γe − Γ1 )∇ · U(8.126)

where we used Eqs. 7.22 and 7.99, and the definition of the sound speed.
This evolution equation is used to predict γe to interfaces, and these interface valuesof γe are used in the Riemann solver presented there to find the fluxes through theinterface. A different adiabatic index (they call Γ, we call Γ1 ) appears in the definitionof the sound speed. They argue that this can be brought to interfaces in a piecewise
constant fashion while still making the overall method second order, since Γ1 does
not explicitly appear in the fluxes (see the discussion at the top of page 277).
We can derive the characteristic structure of this system for use in the tracing in the8.11—Thermodynamic issues

153

construction of interface states†† . If we write our system as

τ
 u 

q=
 p 
γe


(8.127)(we use τ = 1/ρ here for consistency with CG), we have


u −τ
 0
u
A=
 0 c2 /τ
0 −α

0
τ
u
0


0
0 

0 
u

(8.128)where we define α = (γe − 1)(γe − Γ1 ) for convenience. The right eigenvectors are:
1
 c/τ r(−) =  −c2 /τ 2 
α/τ



1
 0 

r(◦) = 
 0 
0


0
 0 

r(◦,γe ) = 
 0 
1





and corresponding left eigenvectors are:τl(−) = 0 2cτl(◦) = 0 2cl(◦,γe ) =l(+) =



0 0

2

τ
− 2c
2

0

2

τ
− 2c
2
ατ
c2

τ
0 − 2c

1

0


2

τ
− 2c
2


1
 −c/τ r(+) =  −c2 /τ 2 α/τ
(8.129)(8.130)
0(8.131)(8.132)(8.133)Carrying (ρe)
Alternately, the Castro paper [2] relies on an idea from an unpublished manuscript by
Colella, Glaz, and Ferguson that predicts ρe to edges in addition to ρ, u, and p. Sinceρe comes from a conservation-like equation (Eq. 7.99), predicting it to the interface inthe unsplit formulation is straightforward. This over-specifies the thermodynamics,
but eliminates the need for γe .
With the addition of ρe, our system becomes:



ρ
 u 

q=
 p 
ρe




u ρ
0
0
 0 u 1/ρ 0 A= 0 ρc2
u
0 
0 ρh
0
u

†† A Jupyter notebook using SymPy that derives these eigenvectors is available here:

dro_examples: euler-generaleos.ipynb(8.134)

Ï hy-

Chapter 8. Euler Equations: Numerical Methods

154

where h = e + p/ρ is the specific enthalpy. The eigenvalues of this system are:λ(−) = u − cλ(◦) = uλ(◦,ρe) = u

λ(+) = u + c(8.135)and the eigenvectors are:1
 −c/ρ r(−) =  c2 
h



0
 0 

r(◦,ρe) = 
 0 
1


1
 0 

r(◦) = 
 0 
0






1
 c/ρ r(+) =  c2 
h(8.136)andl(−) = ( 0 − 2c

1
2c2

ρ

l

(◦)

=( 1 0

0 )

1
2c2

0 )

l(◦,ρe) = ( 0 0 − ch2l(+) = ( 0

ρ
2c

0 )

− c12

1 )
(8.137)

Remember that the state variables in the q vector are mixed into the other states byl · q. Since all l(ν) ’s have 0 in the ρe ‘slot’ (the last position) except for l(◦,ρe) , and thecorresponding r(◦,ρe) is only non-zero in the ρe slot, this means that ρe is not mixed
into the other state variables. This is as expected, since ρe is not needed in the system.
Also recall that the jump carried by the wave ν is proportional to r(ν) —since r(−) ,r(◦,ρe) , and r(+) have non-zero ρe elements, this means that ρe jumps across thesethree waves.
Working through the sum for the (ρe) state, and using a ∼ to denote the reference
states, we arrive at:



1
1 
ρ
1
(1)
(1)
ρe) −
(ρe)in++1//22,L = (g− ũ − I+ (u) + 2 p̃ − I+ ( p) h
2
c
c





h
(3)
(3)
g
− − 2 p̃ − I+ ( p) + (ρe) − I+ (ρe)
c
 


1 ρ
1 
(4)
(4)
−
ũ − I+ (u) + 2 p̃ − I+ ( p) h
(8.138)2 ccThis is the expression that is found in the Castro code. If you are dealing with asimple geometry, then the divergences have metric terms. In 1-d, we then have:∂(ρe)
1 ∂(r α ρue)
1 ∂ (r α u )
+ α
+p α
∂t
r
∂r
r
∂r

(8.139)

Expanding out the derivatives gives use the equation in Cartesian form with a geometric source term:∂uαρhu∂(ρe) ∂(ρue)++p=−(8.140)∂t∂r∂rr

8.12—WENO methods for the Euler equations

155

where h is the specific enthalpy. This can be accommodated using the proceduredescribed in § 8.8.
All of these methods are designed to avoid EOS calls where possible, since generalequations of state can be expensive.
Extending these to an unsplit formulation requires carrying an additional auxiliary variable from the primitive state back to the conserved state and adding thetransverse gradients to its interface state. Castro deals with a conserved state of
U = (ρ, ρU, ρE, p), and explicitly adds the transverse terms found in the multidimensional form of Eq. 7.22 to the normal states of p.

8.12

WENO methods for the Euler equations

When dealing with nonlinear systems the flux split method introduced in section 6.4
generalizes directly. The simplest, and most diffusive flux splitting uses the maximum characteristic speed α. For a system, such as the Euler equations, the simplest
method is to compute α by maximizing over all characteristics. The directional fluxes
F(±) (u) can then be reconstructed using a high order WENO scheme component bycomponent.
However, this approach can lead to significant oscillations, even in moderate tests.
Rather than doing the reconstruction of the components of the directional fluxes, asafer approach is to work with characteristic variables. The discussion in chapter 7
suggests that, by computing the left and right eigenvectors of the appropriate Jacobian matrix A = ∂F/∂ U , we can project the directional fluxes into the directional
characteristic fluxes (using the left eigenvectors), reconstruct these characteristic fluxes
using a high order method, and then compute the reconstructed directional fluxes
required (using the right eigenvectors). As the characteristic fluxes should contain
information about only a single wave at a time, this should give similar results to thescalar case and reduce problems from close waves from different families.
The Jacobian matrix needs to be computed separately for each point at which theflux needs computing. The best choice of state from which the Jacobian is computed
is not clear: often the arithmetic average of neighbouring states is used, but more
complex choices can give better results.
A direct comparison of component-wise and characteristic-wise flux-vector split WENO
methods, applied to the Sod test, is given in figure 8.19 for r = 3 and in figure 8.20 for
r = 5. The comparison to the PPM method in figure 8.10 is particularly instructive.
The PPM method is specifically designed for hydrodynamic problems, and is muchbetter at cleanly capturing the discontinuities, especially the contact. The WENO approach will have a higher order of accuracy, which will be clearest on tests with moresmooth variation. The oscillations introduced by the WENO methods are more pronounced as the order is increased, but are reduced by the use of characteristic-wiseChapter 8. Euler Equations: Numerical Methods

156

reconstruction. This is most clearly seen in the results for the internal energy in ther = 5 case shown in figure 8.20.
Another illustration of the advantages of a numerical method, such as PPM, that is
specifically designed for the Euler equations, is shown in the double rarefaction test
in figure 8.21. The advantages of the higher order methods are shown by how wellthe WENO schemes capture the edges of the rarefaction waves, even with so few
points and the diffusive Lax-Friedrichs flux splitting. However, the artificial heating
effect seen at the trivial contact at the center of the domain is about as bad as thatfrom piecewise constant reconstruction, and nowhere near as good as PPM. Whilst
increasing the reconstruction order has a small impact, a less diffusive flux splitting
would be needed to approach PPM’s performance.

8.12.1

Extensions

The main advantage of the WENO method is that it retains its high order when extending to multiple dimensions using dimensional splitting. From the finite-difference
form there are no transverse Riemann problems to solve. From using the Method ofLines there is no issue about ordering the dimensional sweeps: the updates in eachdirection are computed separately but applied together in the time integrator. This
formally retains the high-order accuracy but can lose significant absolute accuracy –compare the advection of a top-hat function with lower order methods using transverse Riemann problem solutions.
The global Lax-Friedrichs flux splitting above can be excessively diffusive. A local
Lax-Friedrichs flux splitting, where α is computed at each point by maximising overthe characteristic speed within the stencil at that point, is less diffusive but slightly
more expensive. Roe-style flux splittings are possible but not always stable.

8.12—WENO methods for the Euler equations

157

e

p

u

WENO, r = 3, componentwise WENO, r = 3, characteristicwise

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.0

0.0

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

3.0
2.8
2.6
2.4
2.2
2.0
1.8
0.0 0.2 0.4 0.6 0.8 1.0
x

2.8
2.6
2.4
2.2
2.0
1.8
0.0 0.2 0.4 0.6 0.8 1.0
x

Figure 8.19: The Sod test solved with WENO methods, r = 3, using characteristic-wiseand component-wise reconstruction, using 64 zones and a cfl of 0.5. To compare with
Godunov’s method see figure 8.9 and with PPM see figure 8.10. The WENO method
does not capture discontinuities, especially the contact, as well as the PPM method
which is specifically designed for the Euler equations. The small oscillations visible
in the component-wise reconstruction are damped by using the more complex and
expensive characteristic-wise approach.
hydro_examples: weno_euler.pyÏChapter 8. Euler Equations: Numerical Methods

158

e

p

u

WENO, r = 5, componentwise WENO, r = 5, characteristicwise

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.0

0.0

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

3.0
2.8
2.6
2.4
2.2
2.0
1.8
0.0 0.2 0.4 0.6 0.8 1.0
x

2.8
2.6
2.4
2.2
2.0
1.8
0.0 0.2 0.4 0.6 0.8 1.0
x

Figure 8.20: The Sod test solved with WENO methods, r = 5, using characteristic-wiseand component-wise reconstruction, using 64 zones and a cfl of 0.5. Compare with
figure 8.19 to see the effect of the higher order of WENO scheme. The oscillations in
the component-wise approach are much more pronounced as the order of the reconstruction is increased, and the characteristic-wise approach continues to help with this.
hydro_examples: weno_euler.pyÏ8.12—WENO methods for the Euler equations

159

Double rarefaction, WENO, r = 3

1.0
0.8
0.6
0.4
0.2
0.0
2

u

1
0
1
2
0.4

p

0.3
0.2
0.1
0.0
1.0

e

0.8
0.6
0.4
0.2
0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 8.21: The double rarefaction test solved with WENO methods, r = 3, using
characteristic-wise and component-wise reconstruction, using 64 zones and a cfl of 0.5.
To compare with Godunov’s method see figure 8.11 and with PPM see figure 8.12.
The WENO method captures the edges of the rarefactions almost as well as the PPM
method, but is as almost as poor as Godunov’s method at the trivial contact at thecenter. A less diffusive flux-splitting may help here. Increasing the reconstruction
order has little effect.
hydro_examples: weno_euler.pyÏPart III

Elliptic and Parabolic Problems

Chapter

9

Elliptic Equations and Multigrid
9.1

Elliptic equations

The simplest elliptic PDE is Laplace’s equation:∇2 ϕ = 0(9.1)

Only slightly more complex is Poisson’s equation (Laplace + a source term):∇2 ϕ = f(9.2)

These equations can arise in electrostatics (for the electric potential), solving for thegravitational potential from a mass distribution, or enforcing a divergence constraint
on a vector field (we’ll see this when we consider incompressible flow).
Another common elliptic equation is the Helmholtz equation:(α − ∇ · β∇)ϕ = f(9.3)

A Helmholtz equation can arise, for example, from a time-dependent equation (likediffusion) by discretizing in time.
Notice that there is no time-dependence in any of these equations. The quantity ϕ is
specified instantaneously in the domain subject to boundary conditions. This makes
the solution methods very different then what we saw for hyperbolic problems.

9.2

Fourier Method

A direct way of solving a constant-coefficient elliptic equation is using Fourier transforms. Using a general Fourier transform (which we consider here) works only for
git version: 64c838dee1a8 . . .

163

Chapter 9. Elliptic Equations and Multigrid

164dφ
dx i−1/2

φi−1

i−1

φi

dφ
dx i+1/2

d2 φ
dx2 i

i − 1/2ii + 1/2

φi+1

i+1

Figure 9.1: The centerings of the first and second derivatives for a standard Laplacian
discretization. Our data, ϕ, is cell-centered. The first-derivatives, dϕ/dx, are edgecentered, and the second-derivative, d2 ϕ/dx2 , is cell-centered.

periodic boundary conditions, but other basis functions (e.g., all sines or all cosines)
can be used for other boundary conditions.
Consider the Poisson equation:∇2 ϕ = f(9.4)

We will difference this in a second-order accurate fashion—see Figure 9.1. In 1-d, theLaplacian is just the second-derivative. If our solution is defined at cell-centers, thenwe first compute the first-derivative on cell edges:dϕ
ϕ − ϕi−1= i
dx i−1/2∆xdϕ
ϕ − ϕi= i +1dx i+1/2
∆x

(9.5)
(9.6)

These are second-order accurate on the interface. We can then compute the secondderivative at the cell-center by differencing these edge values:
dϕ/dx |i+1/2 − dϕ/dx |i−1/2
d2 ϕ
=
dx2 i
∆x

(9.7)

The extension to 2-d is straightforward. Thinking of the Laplacian as ∇2 ϕ = ∇ · ∇ϕ,
we first compute the gradient of ϕ on edges:
ϕi+1,j − ϕi,j∆x
ϕi,j+1 − ϕi,j[∇ϕ · ŷ]i,j+1/2 =∆y[∇ϕ · x̂ ]i+1/2,j =

(9.8)
(9.9)

Again, since this is defined on edges, this represents a centered difference, and istherefore second-order accurate. We then difference the edge-centered gradients to9.2— Fourier Method165

the center to get the Laplacian at cell-centers:[∇ϕ · x̂ ]i+1/2,j − [∇ϕ · x̂ ]i−1/2,j [∇ϕ · ŷ]i,j+1/2 − [∇ϕ · ŷ]i,j−1/2+∆x∆y
ϕi+1,j − 2ϕi,j + ϕi−1,jϕi,j+1 − 2ϕi,j + ϕi,j−1=+= f i,j2∆x∆y2[∇2 ϕ]i,j =(9.10)

Again, since we used a centered-difference of the edge values, this expression issecond-order accurate. This is the standard 5-point stencil for the 2-d Laplacian* .
We now assume that we have an FFT subroutine (see § 1.2.6) that can take our discrete
real-space data, ϕi,j and return the discrete Fourier coefficients, Φk x ,ky , and likewise
for the source term:
Φk x ,ky = F (ϕi,j )Fk x ,ky = F ( f i,j )(9.11)The power of the Fourier method is that derivatives in real space are multiplications
in Fourier space, which makes the solution process in Fourier space straightforward.
We now express ϕi,j and f i,j as sums over their Fourier components. Here we define
M as the number of grid points in the x-direction and N as the number of grid points
in the y-direction. As before, we are using i as the grid index, we will use I as theimaginary unit:
ϕi,j =

1 M −1 N −1
∑ Φkx ,ky e2π Iikx /M e2π I jky /N
MN k∑=0 k =0(9.12)

1 M −1 N −1
∑ Fkx ,ky e2π Iikx /M e2π I jky /N
MN k∑=0 k =0(9.13)x

f i,j =xyyInserting these into the differenced equation, we have:i
1 M−1 N −1 Φk x ,ky 2π I jky /N h 2π I (i+1)k x /M
2π Iik x /M
2πI (i −1)k x /M
e
e
−
2e
+
e
+
∑ ∆x2
MN k∑
=
0
k
=
0
x
y
i
Φk x ,ky 2π Iik /M h 2π I ( j+1)k /N
2π I jk y /N
2πI ( j−1)k y /N
x
y
e
e
− 2e
+e
=
∆y2
1 M −1 N −1
∑ Fkx ,ky e2πIikx /M e2πI jky /N
MN k∑=0 k =0x(9.14)

y

We can bring the righthand side into the sums on the left, and we can then look at* There are other possible second-order accurate stencils, including a 9-point stencil in 2-d, that areless commonly used.

Chapter 9. Elliptic Equations and Multigrid

166
just a single (k x , k y ) term in the series:
e2πIik x /M e2πI jky /NiΦk x ,k x h 2πIk x /M
−2π Ik x /M
e
+
e
−
2
+
∆x2

i
Φk x ,k x h 2πIky /N−2π Ik y /Ne+e
− 2 − Fk x ,ky = 0∆y2(9.15)

Simplifying, we have:Φk x ,ky =Fk x ,ky1
2 [cos(2πk x /M ) − 1] ∆x −2 + cos(2πk y /N ) − 1 ∆y−2

(9.16)

This is the algebraic solution to the Poisson equation in Fourier (frequency) space.
Once we evaluate this, we can get the real-space solution by doing the inverse transform:
ϕi,j = F −1 (Φk x ,ky )(9.17)

We can test this technique with the source term:
f = 8π 2 cos(4πy) [cos(4πx ) − sin(4πx )] −
16π 2 sin(4πx ) cos(2πy)2 + sin(2πx )2 cos(4πy)(9.18)

ϕ = sin(2πx )2 cos(4πy) + sin(4πx ) cos(2πy)2(9.19)

which has the analytic solution† :Note that this solution has the required periodic behavior. Figure 9.2 shows thesolution.
The main downside of this approach is that, because we solve for a single component independently (Eq. 9.16), this only works for linear problems with constantcoefficients. This makes it an excellent choice for cosmological problems solving thegravitational Poisson equation with periodic boundaries on all sides of the domain(see, e.g., [41]). However, for a problem like:∇ · ( β∇ϕ) = f(9.20)

there would be “cross-talk” between the Fourier modes of β and ϕ, and we would not
be able to solve for a single mode of Φk x ,ky independently. We discuss more general
methods that work for these forms next.
† Note: throughout this chapter, we devise test problems by picking a function that meets the desired

boundary conditions and then inserting it into the analytic equation we are solving to find the righthandside9.3—Relaxation

167

1.0

1.5

0.8

0.4

0.0

0.2

0.5

y

0.5

0.2

0.4

0.6

x

0.8

L2 norm of abs error

1.0

0.6

0.0
0.0

O(∆x 2 )

10 −2

10 −3

10 −4

1.0

10 2

number of zones

Figure 9.2: (left) Solution to the Poisson equation on a 642 grid with source from
Eq. 9.18. (right) Error vs. the true solution as a function of resolution for the Fourier
method, showing second-order convergence.
hydro_examples: poisson_fft.pyÏ

9.3

Relaxation

Relaxation is an iterative technique, and as we will see shortly, it provides the basis
for the multigrid technique.
Consider Poisson’s equation, again differenced as:
ϕi+1,j − 2ϕi,j + ϕi−1,jϕi,j+1 − 2ϕi,j + ϕi,j−1+= f i,j∆x2∆y2(9.21)For each zone (i, j), we couple in the zones ±1 in x and ±1 in y. For the moment,
consider the case where ∆x = ∆y. If we solve this discretized equation for ϕi,j , thenwe have:
1
ϕi,j = (ϕi+1,j + ϕi−1,j + ϕi,j+1 + ϕi,j−1 − ∆x2 f i,j )(9.22)
4
A similar expression exists for every zone in our domain, coupling all the zones
together. We can’t separate the solution of ϕi,j for the neighboring zones, but instead
can apply an iterative technique called relaxation (also sometimes called smoothing
because generally speaking the solution to elliptic equations is a smooth function) tofind the solution for ϕ everywhere.
(0)

Imagine an initial guess to ϕ: ϕi,j . We can improve that guess by using our difference(1)equation to define a new value of ϕ, ϕi,j :(1)

ϕi,j =

1 (0)
(0)
(0)
(0)
(ϕ
+ ϕi−1,j + ϕi,j+1 + ϕi,j−1 − ∆x2 f i,j )4 i+1,j(9.23)or generally, the k + 1 iteration will see:( k +1)

ϕi,j

1 (k)
(k)
(k)
(k)
= (ϕi+1,j + ϕi−1,j + ϕi,j+1 + ϕi,j−1 − ∆x2 f i,j )4(9.24)

Chapter 9. Elliptic Equations and Multigrid

168

This will (slowly) converge to the true solution‡ , since each zone is coupled to eachother zone (and to the boundary values that we need to specify—more on that in a
moment). This form of relaxation is called Jacobi iteration. To implement this, youneed two copies of ϕ—the old iteration value and the new iteration value.
An alternate way to do the relaxation is to update ϕi,j in place, as soon as the newvalue is known. Thus the neighboring cells will see a mix of the old and new solutions. We can express this in-place updating as:
ϕi,j ←

1(ϕi+1,j + ϕi−1,j + ϕi,j+1 + ϕi,j−1 − ∆x2 f i,j )4(9.25)

This only requires a single copy of ϕ to be stored. This technique is called Gauss-Seidel
iteration. A host of other relaxation methods exist, including linear combinations ofthese two. An excellent discussion of these approaches, and their strengths andweaknesses is given in [17].
Next consider the Helmholz equation with constant coefficients:( α − β ∇2 ) ϕ = f
We can discretize this as:
ϕi+1,j − 2ϕi,j + ϕi−1,jϕi,j+1 − 2ϕi,j + ϕi,j−1
αϕi,j − β+
= f i,j∆x2∆y2(9.26)(9.27)and the update of ϕi,j through relaxation is:



β
β
β
β
2β
2β
ϕi,j ← f i,j +ϕi+1,j +ϕi−1,j +ϕi,j+1 +ϕi,j−1
α+
+ 2
∆x2
∆x2
∆y2
∆y2
∆x2
∆y
(9.28)
Notice that if α = 0, β = −1, and ∆x = ∆y, we recover the relaxation expression for
Poisson’s equation from above.

9.3.1

Boundary conditions

When using a cell-centered grid, no points fall exactly on the boundary, so we need
to use ghost cells to specify boundary conditions. A single ghost cell is sufficientfor the 5-point stencil used here. The common types of boundary conditions are
Dirichlet (specified value on the boundary), Neumann (specified first derivative on theboundary), and periodic. Some restrictions apply (see discuss this later, in § 9.5).
Consider Dirichlet boundary conditions, specifying values ϕl on the left and ϕr on theright boundaries.§ We’ll label the first zone inside the domain, at the left boundary,‡ Formally, convergence is only guaranteed if the matrix in our linear system is diagonally dominant.
The Laplacian used here is not quite diagonally domainant, but these methods still converge.
§ If the value, ϕ or ϕ is zero, we call this a homogeneous boundary condition. Otherwise we call it anrlinhomogeneous boundary condition

9.3—Relaxation

169

fi
i−2

i

i−1

i +1

i +2

∆x

fi
lo−1

i−1

lo

left BC

i

i +1

∆x

hi

hi +1
right BC

Figure 9.3: A node-centered (top) and cell-centered (bottom) finite difference gridshowing the data and domain boundaries. Notice that for the cell-centered grid, there
is no data point precisely at the boundary.

lo, and the last zone inside the domain, at the right boundary, hi—see Figure 9.3. To
second order, we can average the zone values on either side of the interface to get theboundary condition:
ϕl

=

ϕr =

1
(ϕ + ϕlo−1 )2 lo
1(ϕ + ϕhi+1 )2 hi(9.29)(9.30)

This then tells us that the values we need to assign to the ghost cells are:ϕlo−1 = 2ϕl − ϕlo

ϕhi+1 = 2ϕr − ϕhi(9.31)(9.32)

If we instead consider Neumann boundary conditions, we specify values of thederivative on the boundaries: ϕx |l on the left and ϕx |r on the right. We note thata single difference across the boundary is second-order accurate on the boundary (itis a centered-difference there), so to second-order:
ϕx | l=ϕx | r =ϕlo − ϕlo−1∆xϕhi+1 − ϕhi∆x(9.33)(9.34)

Chapter 9. Elliptic Equations and Multigrid

170

This then tells us that the ghost cells are filled as:
ϕlo−1 = ϕlo − ∆x ϕx |l

ϕhi+1 = ϕhi + ∆x ϕx |r

9.3.2(9.35)(9.36)

Residual and true error

The residual error is a measure of how well our discrete solution satisfies the discretized equation. For the Poisson equation, we can the residual as:
ri,j = f i,j − ( Lϕ)i,j(9.37)ϵ (r ) = ∥ r ∥(9.38)and the residual error as:
where L represents our discretized Laplacian. Note that r is the error with respect
to the discrete form of the equation. The true error is the measure of how well our
discrete solution approximates the true solution. If ϕtrue satisfies ∇2 ϕtrue = f , then
the true error in each zone isei,j = ϕtrue ( xi , y j ) − ϕi,j(9.39)

ϵtrue = ∥ei,j ∥(9.40)

andWe can make ϵ(r) approach machine precision by performing more and more relaxation iterations, but after some point, this will no longer improve ϵtrue . The only way
to improve ϵtrue is to make ∆x and ∆y smaller. In practice we do not know the true
solution so we cannot compute ϵtrue and will instead have to rely on ϵ(r) to monitor
our error.
Note that since our operator is linear,
Le = Lϕtrue − Lϕ = f − Lϕ = r(9.41)

so the error in our solution obeys a Poisson equation with the residual as the source—
we’ll see this in the next section.

9.3.3

Norms

There are several different norms that are typically used in defining errors on thegrid. The L∞ norm (or ‘inf’-norm) is just the maximum error on the grid:∥e∥∞ = max{|ei,j |}i,jThis will pick up on local errors.

(9.42)

9.3—Relaxation171

L2 norm of true error (solid) and residual (dotted)

100

16
32
64

10 2
10 4
10 6
10 8
10 10
10 12
10 14
100

101

102
# of iterations

103

104

Figure 9.4: Gauss-Seidel relaxation applied to ϕxx = sin( x ) with ϕ(0) = ϕ(1) = 0.
Shown are the L2 norm of the error compared with the true solution (solid lines) andthe L2 norm of the residual (dotted lines) for 3 different resolutions (16, 32, and 64
zones).
hydro_examples: smooth.pyÏ

The L1 norm and L2 norms are more global.

∥ e ∥1 =∥ e ∥2 =1|ei,j |
N∑i,j
1
|ei,j |2
N∑i,j(9.43)!1/2(9.44)

Generally, the measure in L2 falls between L∞ and L1 . Regardless of the norm used,
if the problem converges, it should converge in all norms. For reference, the AMReX
library¶ uses L∞ in its multigrid solvers.

Chapter 9. Elliptic Equations and Multigrid

172

9.3.4

Performance

Consider the simple Poisson problem|| on x ∈ [0, 1]:
ϕxx = sin( x ),ϕ (0) = ϕ (1) = 0(9.45)

The analytic solution to this is simply
ϕ a ( x ) = − sin( x ) + x sin(1)(9.46)

We can perform smoothing and compute both the error against the analytic solution (the ‘true’ error), e ≡ ∥ϕ a ( xi ) − ϕi ∥2 and the residual error, ∥ri ∥2 . Figure 9.4
shows these errors as a function of the number of smoothing iterations for 3 different
resolutions.
Notice that the true error stalls at a relatively high value—this is the truncation error of the method. From one resolution to the next, the true error changes as ∆x2 ,indicating that we are converging as our method should. No additional amount ofsmoothing will change this—we are getting the best answer to the problem we canwith our choice of discretization. In contrast, the residual error decreases to machine
precision levels—this is indicating that our solution is an exact solution to the discrete
equation (to roundoff-error). In practice, we can only monitor the residual error, notthe true error, and we hope that small residual error implies a small true error.
Figure 9.5 shows the error with respect to the true solution and of the residual for
pure smoothing in three different norms. The overall behavior is qualitative similar
regardless of the choice of norm.
To demonstrate the influence of the boundary conditions, Figure 9.6 shows the normof the true error for the same problem, but this time with a naive implementation of
the boundary conditions—simply initializing the ghost cell to the boundary value,
instead of averaging to the interface:ϕlo−1 = ϕlo

ϕhi+1 = ϕhi(9.47)(9.48)We see that with this mistake at the boundaries, the error of the entire solution isaffected, and we get only first-order convergence with resolution (this can be seen bylooking at the spacing of the curves). The previous solution, with the correct BCs isshown for reference, and shows second-order convergence. It is important to notethat because every zone is linked to every other zone (and the boundary) in elliptic
problems, an error at the boundary can pollute the global solution.
¶ https://github.com/amrex-codes|| This is the test problem used throughout A Multigrid Tutorial [17]. We use the same problem here

to allow for easy comparison to the discussions in that text.

Norm of true error (solid) and residual (dotted)

9.3—Relaxation

173

L1
L2
L-inf

10 1
10 3
10 5
10 7
10 9
10 11
10 13
100

101

102
# of iterations

103

104

Figure 9.5: Gauss-Seidel relaxation applied to ϕxx = sin( x ) with ϕ(0) = ϕ(1) = 0.
This is like figure 9.4, but now we show the error in 3 different norms: L1 , L2 , and L∞ .
hydro_examples: smooth-norms.py

Ï

9.3.5

Frequency/wavelength-dependent error

We can think of the error in the solution as a superposition of high (short) and low(long) frequency (wavelength) modes. Smoothing works really well to eliminate theshort wavelength noise quickly, but many iterations are needed to remove the longwavelength noise (see Figure ??). A very important concept to understand here isthat when we talk about long wavelength error, we are expressing it in terms of thenumber of zones across the feature, not as physical length. We can get an intuitive
feel for this behavior by thinking about how smoothing works. Every zone is coupled
to every other zone, and we can think about each zone seeing one more zone awayfor each iteration. When the error is short wavelength, that means that there are
only a few zones across it, and after a few iterations, all of the zones have seen the
short wavelength error, and can eliminate it. For a very long wavelength error, many
iterations will be needed until the smoothing couples one zone to another that is awavelength away.
This behavior suggests that if we could represent our problem on a coarser grid, theerror will now be of shorter wavelength, and smoothing will be more efficient. This

Chapter 9. Elliptic Equations and Multigrid

174

16
32
64

L2 norm of true error

10 2

10 3

10 4

10 5
101

100

102
# of iterations

103

104

Figure 9.6: The same problem as in figure 9.4, but now we done with a naive firstorder boundary conditions—just initializing the ghost cell to the boundary value (solidlines). We see that this achieves only first-order convergence in the true error. The
correct second-order implmentation is shown as the dotted lines.
hydro_examples: smooth-badbcs.pyÏis the core idea behind multigrid, which we see next.

Exercise 9.1
Implement 1-d smoothing for the Laplace equation on cc-grid. Use an
initial guess for the solution:
ϕ0 ( x ) =1(sin(2πx ) + sin(2π 8x ) + sin(2π 16x ))3(9.49)

on a 128 zone grid with Dirichlet boundary conditions. This initial guesshas both high-frequency and low-frequency noise. Observe that the highfrequency stuff goes after only a few smoothing iterations, but many iterations are needed to remove the low-frequency noise. You should see
something like Figure ??.

9.4—Multigrid

175# smooth = 1# smooth = 10
# smooth = 100# smooth = 1000

0.8
0.6

absolute error

0.4
0.2
0.0
0.0
0.2

0.2

0.4

x

0.6

0.8

1.0

0.4
0.6

Figure 9.7: Error in the solution to ϕ′′ = 0 given an initial guess with 3 different
wavenumbers of noise. A 128 zone grid was used. The different curves are different
numbers of smoothing iterations.
hydro_examples: smooth-modes.pyÏFigure 9.7 illustrates this behavior. We are solving the Laplace equation, ϕ′′ = 0 in 1d on [0, 1] with homogeneous Dirichlet boundary conditions. The solution is simply
ϕ = 0. We use Eq. 9.49 as an initial guess—this is a superposition of 3 different
modes. We see that the after just a few iterations, the shortest wavelength mode,sin(2π16x ) is no longer apparent in the error, and just the two longer wavelength
modes dominate. By 100 iterations, the error appears to be only due to the longest
wavelength mode, sin(2πx ). Even after 1000 iterations, we still see this mode in theerror. This demonstrates that the longest wavelength modes in the error take thelongest to smooth away.

9.4

Multigrid

The text A Multigrid Tutorial [17] provides an excellent introduction to the mechanics
of multigrid. The discussion here differs mainly in that we are dealing with cell-Chapter 9. Elliptic Equations and Multigrid

176

φfi−2

φfi−1

φfi

φfi+1

i−2

i−1

i

i+1

φcj−1

φcj

j−1

j

Figure 9.8: A fine grid and corresponding underlying coarse grid.

centered/finite-volume data. We already saw that the treatment of boundary conditions is more complicated because we do not have a point directly on the boundary.
The other complication comes in transferring the data from a fine grid to a coarser
grid, and back. Before we discuss the multigrid technique, we’ll understand how theoperations between grids work.

9.4.1

Prolongation and restriction on cell-centered grids

Multigrid relies on transferring the problem up and down a hierarchy of grids. The
process of moving the data from the fine grid to the coarse grid is called restriction.
The reverse process, moving data from the coarse grid to the fine grid is called prolongation. If the data on our grid is a conserved quantity, we want restriction andprolongation to conserve the amount of stuff when transitioning data between thefine and coarse grids.
1-d
Consider a 1-d finite-volume/cell-centered finite-difference grid shown in Figure 9.8—
we see a fine grid and the corresponding coarser grid. If ϕ represents a density, thenconservation requires:
1
f
f
ϕcj =
(9.50)(∆x f ϕi + ∆x f ϕi+1 )∆x c

9.4—Multigrid

177

or, for a jump in 2 in resolution (∆x c = 2∆x f ),
ϕcj =

1 f
f
(ϕi + ϕi+1 )2(9.51)

This latter form appears as a simple average to the interface of the two fine cells /center of the corresponding coarse cell.
The simplest type of prolongation is simply direct injection:
ϕi = ϕcjf(9.52)

ϕi+1 = ϕcj

f(9.53)A higher-order method is to do linear reconstruction of the coarse data and thenaverage under the profile, e.g.,ϕ( x ) =ϕcj+1 − ϕcj−12∆x c( x − x cj ) + ϕcj
f(9.54)f

To second-order, we can find the values of ϕi and ϕi+1 by evaluating ϕ( x ) at thex-coordinate corresponding to their cell-centers,
∆x c
4
c
∆x
f
xi+1 = x cj +4fxi = x cj −(9.55)(9.56)

giving1f
ϕi = ϕcj − (ϕcj+1 − ϕcj−1 )81
f
ϕi+1 = ϕcj + (ϕcj+1 − ϕcj−1 )8f(9.57)(9.58)

f

Notice that this is conservative, since ∆x f (ϕi + ϕi+1 ) = ∆x c ϕcj .
2-dRestriction from the fine grid to the coarse grid is straightforward. Since the fine cells
are perfectly enclosed by a single coarse cell, we simply average:
c
ϕi,j
=

1 f
f
f
f
(ϕ + ϕ+− + ϕ−+ + ϕ++ )4 −−(9.59)

Prolongation requires us to reconstruct the coarse data and use this reconstruction todetermine what the fine cell values are. For instance, a linear reconstruction of thecoarse data in x and y is:ϕ( x, y) =mymxc
( x − xic ) + c (y − ycj ) + ϕi,jc∆x∆y(9.60)

Chapter 9. Elliptic Equations and Multigrid

178

j

+1

c

φi,j +1

f

f

φ− +
c

c

φi−1,j

j

φ+ +

f

f

φ +−

φ−−

j

c

φi +1,j

φi,j

−1

c

φi,j−1

i

−1

i

i

+1

Figure 9.9: Four fine cells and the underlying coarse grid. For prolongation, the finecells in red are initialized from a coarse parent. The gray coarse cells are used in thereconstruction of the coarse data. For restriction, the fine cells are averaged to theunderlying coarse cell.

with slopes:
mx =
my =

1 c
(ϕ
− ϕic−1,j )2 i+1,j1 cc(ϕ− ϕi,j−1 )2 i,j+1(9.61)(9.62)c in that cell (thisWhen averaged over the coarse cell, ϕ( x, y) recovers the average, ϕi,jmeans that our interpolant is conservative). We can evaluate the value in the finecells by evaluating ϕ( x, y) at the center of the fine cells,
f

∆x c
4
c
∆y
= ycj ±
4x± = xic ±fy±(9.63)(9.64)(9.65)

9.4—Multigrid

179

This gives
11fc
ϕ±± = ϕi,j
± m x ± my
44

(9.66)(Note: you would get the same expression if you averaged ϕ( x, y) over the fine cell.)There are other options for prolongation and restriction, both of higher and lower
order accuracy. However, the methods above seem to work well.

9.4.2

Multigrid cycles

The basic idea of multigrid** is to smooth a little on the current grid solving Lϕ = f ,compute the residual, r, then restrict r to a coarser grid and smooth on that grid
solving Le = r, restrict again, . . .. Once you reach a sufficiently coarse grid, theproblem solved exactly. Then the data is moved up to the finer grids, a process called
prolongation. The error on the coarse grid, e, is prolonged to the finer grid. This error
is then used to correct the solution on the finer grid, some smoothing is done, andthen the data is prolonged up again.
Note: on the coarse grids, you are not solving the original system, but rather an error
equation. If the boundary conditions in the original system are inhomogeneous, theboundary conditions for the error equations are now homogeneous. This must be
understood by any ghost cell filling routines.
There are many different forms of the multigrid process. The simplest is called theV-cycle. Here you start of the fine grid, restrict down to the coarsest, solve, and thenprolong back up to the finest. The flow looks like a ‘V’. You continue with additional
V-cycles until the residual error is smaller than your tolerance.

9.4.3

Bottom solverOnce the grid is sufficiently coarse, the linear system is small enough to be solved
directly. This is the bottom solver operation. In the most ideal case, where thefinest grid is some power of 2, Nx = Ny = 2n , then the multigrid procedure cancontinue down until a 2 × 2 grid is created (Figure 9.10 illustrates this idea for a
one-dimensional grid). This is the coarsest grid upon which one can still impose
boundary conditions. With this small grid, just doing additional smoothing is sufficient enough to ‘solve’ the problem. No fancy bottom solver is needed.
For a general rectangular grid or one that is not a power of 2, the coarsest grid will
likely be larger. For the general case, a linear system solver like conjugate gradient(or a variant) is used on the coarsest grid.
** In these discussions, we use multigrid to mean geometric multigrid, where the coarsening is done to
the grid geometry directly. The alternative is algebraic multigrid, where it is the structure of the matrix
in the linear system itself that is coarsened.

180

Chapter 9. Elliptic Equations and Multigrid

Figure 9.10: Illustration of the hierarchy of grids leading to the coarsest 2-zone grid(in one-dimension). Each grid has a single ghost cell to accommodate boundary conditions.

9.4.4

Boundary conditions throughout the hierarchy

The general inhomogeneous boundary conditions from Eqs. 9.31 and 9.35 apply tothe finest level. But because we are solving the residual equation of the coarsest levelsin the multigrid hierarchy, the boundary conditions on Le = r are all homogeneous(but of the same type, Dirichlet, Neumann, or periodic, as the fine level).
Implementing these boundary conditions in your multigrid solver means that you
will have separate actions for the fine level (where inhomogeneous boundaries may
apply) and the coarser levels (where you will always be homogeneous).
An alternate way to enforce boundary conditions is via boundary charges. For inhomogeneous boundary conditions, boundary charges can be used to convert the BCs tohomogeneous BCs. This has the advantage of allowing the ghost cell filling routines
only deal with the homogeneous case.
Consider the one-dimensional Poisson equation, near the left boundary our discretized equation appears as:
ϕlo−1 − 2ϕlo + ϕlo+1= f lo∆x2(9.67)

9.4—Multigrid

181

Inhomogeneous BCs at the left boundary would give the condition:
ϕlo−1 = 2ϕl − ϕlo(9.68)

Substituting this into the discrete equation, we have:
2ϕl − ϕlo − 2ϕlo + ϕlo+1= f lo∆x2(9.69)

Bringing the boundary condition value over to the RHS, we see
2ϕ−3ϕlo + ϕlo+1= f lo − l22∆x∆x(9.70)

Now the left side looks precisely like the differenced Poisson equation with homogeneous Dirichlet BCs. The RHS has an additional ‘charge’ that captures the boundary
value. By modifying the source term, f , in the multigrid solver to include this charge,
we can use the homogeneous ghost cell filling routines throughout the multigrid algorithm. This technique is discussed a bit in [26].
Note that the form of the boundary charge will depend on the form of the elliptic
equation—the expressions derived above apply only for ∇2 ϕ = f .

9.4.5

Stopping criteria

Repeated V-cycles are done until:∥r ∥ < ϵ ∥ f ∥(9.71)

on the finest grid, for some user-input tolerance, ϵ. Here, ∥ f ∥ is called the source
norm. If ∥ f ∥ = 0, then we stop when∥r ∥ < ϵ(9.72)

Picking the tolerance ϵ is sometimes problem-dependent, and generally speaking, aproblem with a large number of zones will require a looser tolerance.
The general rule-of-thumb is that each V-cycle should reduce your residual by about
1 order of magnitude. It is important that your bottom solver solves the coarse
problem to a tolerance of 10−3 or 10−4 in order for the solver to converge. Figure 9.11
shows the true and residual errors for ϕxx = sin( x ) as a function of V-cycle number,
illustrating the expected performance.
The overall convergence of the multigrid algorithm is limited by the discretizationof the Laplacian operator used and the implementation of the boundary conditions.
Figure 9.12 shows the error in the solution as the number of zones is increased—
demonstrating second-order convergence for our implementation.

Chapter 9. Elliptic Equations and Multigrid

L2 norm of error

182

10

-1

10

-2

10

-3

10

-4

10

-5

10

-6

10

-7

10

-8

10

-9

e

|| ||

r

|| ||

10

-10

10

-11

10

-12

0

4

2

6
# of V-cycles

8

10

12

Figure 9.11: Error in the multigrid solution to our model problem (ϕxx = sin( x )) as afunction of V-cycle. We see that the true error, ∥e∥ stalls at truncation error while theresidual error, ∥r ∥ reaches roundoff error, the same behavior as seen with smoothingalone (as expected).
hydro_examples: mg_test.pyÏ

9.5

Solvability

For ∇2 ϕ = f with periodic or Neumann boundaries all around, the sum of f must
equal 0 otherwise the solution will not converge. Instead, we will simply find thesolution increase each V-cycle. This is seen as follows:ZΩf dΩ =Z2Ω∇ ϕdΩ =

Z∂Ω

∇ϕ · ndS = 0(9.73)For all homogeneous Neumann boundaries, we have ∇ϕ · dS = 0 by construction,
so that integral is zero, requiring that the source integrate to zero. If the Neumannboundaries are inhomogeneous, there is still a solvability condition on f based on
the sum on the boundary values.
A simple example of solvability is:ϕ′′ = 0(9.74)

9.6—Going Further

10-3

183
Multigrid convergenceO(∆x2 )

L2 norm of absolute error

10-4

10-5

10-6

10-7

10-8 1
10

102
N

103

Figure 9.12: Convergence of the multigrid algorithm.

Ï hydro_examples: mg_converge.py
on [ a, b] withϕ′ ( a) = A′

ϕ (b) = B

(9.75)(9.76)

We can integrate ϕ′′ = 0 to get ϕ( x ) = αx + β where α and β are integration constants.
But note that this is just a straight line, with a single slope, α, so it is not possible tospecify two unique slopes, A and B at the boundary unless there is a non-zero sourceterm.
For all periodic boundaries, we have ∇ϕ|left = −∇ϕ|right on the left and right boundaries by definition of the periodicity (and similarly for the top and bottom). Again
this implies that f must integrate to zero.
Sometimes, with periodic boundary conditions all around, you need to enforce thatf integrate to zero numerically to test convergence. This is discussed in § 15.2.1.

9.6

Going Further

9.6.1

Red-black Ordering

When using domain decomposition to spread the problem across parallel processors,
the smoothing is often done as red-black Gauss-Seidel. In this ordering, you imagine

184

Chapter 9. Elliptic Equations and Multigrid

Figure 9.13: The red-black ordering of zones.

the grid to be a checkerboard (see Figure 9.13). In the first Gauss-Seidel pass you
update the red squares and in the second, the black squares. The advantage is thatwhen updating the red, you can be sure that none of the zones you depend on (theneighboring black zones) will change. This makes the decomposition parallel. Note:
this works for the standard 5-point Laplacian. If you are doing some other operator
with a different stencil, then this decomposition may no longer hold.

9.6.2

More General Elliptic Equations

The most general second-order elliptic equation takes the form:
αϕ + ∇ · ( β∇ϕ) + γ · ∇ϕ + ∇ · (ζϕ) = f(9.77)

Here, γ and ζ are vectors. Solving a general elliptic equation of this form can beaccomplished with multigrid using the same basic ideas here. The main change isthat the smoothing algorithm and the construction of the residual will need to discretize the more general operator, and these coefficients will need to be restricted tothe coarser grids (some on edges). This is explored in § 15.2 for a variable-coefficient
Poisson equation:∇ · ( β∇ϕ) = f(9.78)

Chapter

10

Diffusion
10.1

Diffusion

Physically, a diffusive process obeys Fick’s law—the quantity that is diffusing, ϕ,moves from higher to lower concentration at a rate proportional to the gradient,
F = −k∇ϕ(10.1)

If we think of this as a diffusive flux, then we can write the time-rate-of-change of ϕas a conservation law:ϕt + ∇ · F (ϕ) = 0(10.2)
This gives rise to the diffusion equation:
ϕt = ∇ · (k ∇ϕ)(10.3)

Diffusion has a time-dependence like the advection equations we already saw, butalso has a global character like an elliptic problem. Unlike advection, there is no senseof upwinding in diffusion. As we will see, we can cast our differenced equations in
a form reminiscent of an elliptic problem.
In one-dimension, and assuming that the diffusion coefficient, k, is constant, we have


∂ϕ
∂
∂ϕ
=
k
(10.4)∂t∂x∂x
The diffusion equation can describe thermal diffusion (for example, as part of the energy equation in compressible flow), species/mass diffusion for multi-species flows,or the viscous terms in incompressible flows. In this form, the diffusion coefficient(or conductivity), k, can be a function of x, or even ϕ.
git version: 64c838dee1a8 . . .

185

Chapter 10. Diffusion

186

We will consider a constant diffusion coefficient as our model problem:
∂ϕ
∂2 ϕ
=k 2
∂t
∂x

(10.5)The diffusion equation is the prototypical parabolic PDE. The basic behavior of the
diffusion equation is to take strongly peaked concentrations of ϕ and smooth themout with time.

10.2

Explicit differencing

A nice overview of the discretizations for diffusion and their stability is given in [64].
The simplest way to difference this equation is explicit in time (i.e., the righthand side
depends only on the old state):
ϕn − 2ϕin + ϕin−1
ϕin+1 − ϕin= k i +1∆t
∆x2

(10.6)

This is second-order accurate in space, but only first order accurate in time (since therighthand side is not centered in time).
As with the advection equation, when differenced explicitly, there is a constraint on
the timestep required√for stability. Looking at the growth of a single Fourier mode,
ϕin = An eiIθ with I = −1, we find:A n +1k∆t= 1 + 2 2 (cos θ − 1)nA∆x(10.7)

Stability requires that | An+1 /An | ≤ 1, which can only be true if 2k∆t/∆x2 ≤ 1.
Therefore, our timestep constraint in this case is
∆t <

1 ∆x2
2 k

(10.8)

As with advection, we often write the timestep as
∆t =

C ∆x2
2 k

(10.9)

where C is a constant, C < 1. Note the ∆x2 dependence—this constraint can become
really restrictive.
Exercise 10.1
Derive Eq. 10.7 by inserting ϕin = An eijθ into Eq. 10.6

10.2—Explicit differencing

187

To complete the solution, we need boundary conditions at the left (xl ) and right (xr )boundaries. These are typically either Dirichlet:
ϕ | x = xl

= ϕl(10.10)ϕ | x = xr

= ϕr(10.11)

ϕx | x = x l= ϕx | l(10.12)or Neumann:

ϕx | x = xr

= ϕx | r(10.13)

Physically, a Dirichlet BC means fixing the value of ϕ (e.g., temperature) on theboundary. A Neumann BC means fixing the flux on the boundary.
Like with advection, it helps to have a good test problem to evaluate our methods
for diffusion. We can use the fact that the diffusion of a Gaussian is a Gaussian witha smaller amplitude and greaterwidth.
Exercise 10.2
Write a one-dimensional explicit diffusion solver for the domain [0, 1]
with Neumann boundary conditions at each end and k = 1, using thediscretization of Eq. 10.6.
If we begin with a Gaussian, the resulting solution is also a Gaussian,giving a solutiona :rt0 − 1 (x− xc )2 /k(t+t0 )ϕ( x, t) = (ϕ2 − ϕ1 )e 4
+ ϕ1
(10.14)t + t0Initialize our problem with t = 0, and take t0 = 0.001, ϕ1 = 1, and
ϕ2 = 2, and xc is the coordinate of the center of the domain. Run until
t = 0.01 and compare to the analytic solution above.
a Note: the 2- and 3-d solutions are slightly different than this 1-d solution

Figure 10.1 shows the solution for 64 zones and a value of C = 0.8. We see good
agreement with the analytic solution. Note that if the initial conditions are not wellresolve initially, then the solution will be bad (see Figure 10.2).
As with advection, if we exceed the timestep limit (C > 1), then the solution isunstable. This is shown in Figure 10.3.
Our spatial order-of-accuracy is second-order. Figure 10.4 shows the error as a function of number of zones, using the L2 norm of the solution with respect to the analytic
solution. Notice that at the coarsest resolution the error is very high—we are not resolving the initial conditions well enough to have a meaningful solution. At higher

Chapter 10. Diffusion

188

explicit diffusion, nx = 64, C = 0.80

t = 8e − 08 s
t = 8e − 07 s
t = 8e − 06 s
t = 8e − 05 s
t = 0.0008 s

1.8

φ

1.6
1.4
1.2
1.0
0.35

0.40

0.45

0.50

x

0.55

0.60

0.65

Figure 10.1: Diffusion of a Gaussian using the explicit differencing of Eq. 10.6 with 64
zones and C = 0.8, shown at several times. The dotted line is the analytic solution.
hydro_examples: diffusion_explicit.pyÏresolutions, we converge as O(∆x2 ). Recall though that our method has a truncation
error that is O(∆t) + O(∆x2 ), but we don’t see the first-order in time scaling. This isbecause of the timestep restriction. Since ∆t ∼ ∆x2 /k, as we cut ∆x by 2, ∆t drops by4, so the timestep choice makes our O(∆t) truncation error go as O(∆x2 ).
Note, this is not the case for advection, where ∆t ∼ ∆x, so for our advection discretizations we will want the same order of accuracy in our spatial and temporal
discretizations.

10.3

Implicit with direct solve

Recall that an implicit discretization of advection did not have a timestep restriction
for stability. The same holds true for diffusion. A backward-Euler implicit discretization would be:
ϕn+1 − 2ϕin+1 + ϕin−+11
ϕin+1 − ϕin= k i +1∆t∆x2

(10.15)

10.3—Implicit with direct solve

189

Explicit diffusion, C = 0.80, t = 0.005

1.14

N = 16
N = 32N = 64
N = 128
N = 256
N = 512

1.12
1.10

φ

1.08
1.06
1.04
1.02
1.00
0.0

0.2

0.4

x

0.6

0.8

1.0

Figure 10.2: Diffusion of a Gaussian using the explicit differencing of Eq. 10.6 withdifferent resolutions. several times. The dotted line is the analytic solution.
hydro_examples: diffusion_explicit.pyÏ

The only difference with Eq. 10.6 is the time-level of ϕ on the righthand side. Defining:∆t
α≡k 2(10.16)∆xThis is still first-order in time. We can do the stability analysis to see the growth of amode, giving,A n +11=(10.17)nA
1 − 2α(cos θ − 1)

We see that | An+1 /An | ≤ 1 for all θ, α, so this discretization is unconditionally stable.
However, the timestep will still determine the accuracy.
We can write Eq. 10.15 as:−αϕin++11 + (1 + 2α)ϕin+1 − αϕin−+11 = ϕin(10.18)This is a set of coupled algebraic equations. We can write this in matrix form. Usinga cell-centered grid, we will solve for the values [lo, hi]. The implicit method can use
any C > 0.

Chapter 10. Diffusion

190

×10 13

explicit diffusion, nx = 64, C = 2.00, t = 0.005

0.75
0.50

φ

0.25
0.00
0.25
0.50
0.75
0.35

0.40

0.45

0.50

x

0.55

0.60

0.65

Figure 10.3: Diffusion of a Gaussian using the explicit differencing of Eq. 10.6 with 64
zones, but a timestep with C > 1, showing that the solution is unstable.
hydro_examples: diffusion_explicit.pyÏ

We specify boundary conditions by modifying the stencil (Eq. 10.18) for the updates
to lo and hi* . For example, homogeneous Neumann BCs on the left mean:
ϕlo−1 = ϕlo(10.19)and substituting this into Eq 10.18, the update for the leftmost cell is:
n +1
n +1
n
(1 + α)ϕlo− αϕlo+1 = ϕlo(10.20)If we choose Dirichlet BCs on the right (ϕ| x= xl = A), then:ϕhi+1 = 2A − ϕhi(10.21)Substituting this into Eq 10.18 the update for the rightmost cell is:
n +1
n +1
n
−αϕhi
−1 + (1 + 3α ) ϕhi = ϕhi + α2A* Here, we use the lo, hi notation for grid indices from § 3.3.3(10.22)

10.3—Implicit with direct solve

10 −1

191

Convergence of Explicit Diffusion, C = 0.80, t = 0.005
O(∆x 2 )L2 norm of absolute error

explicit diffusion

10 −2
10 −3
10 −4
10 −5
10 −6

10 2

N

Figure 10.4: Error convergence with resolution of the explicit diffusion using the differencing of Eq. 10.6
hydro_examples: diffusion_explicit.pyÏFor all other interior cells, the stencil is unchanged. The resulting system appears asa tridiagonal matrix.

 


n +1
n
1
+
α
−
α
ϕ
ϕ
lo

  lo  


 


n

  ϕ n +1   −α 1 + 2α−αϕlo  lo+1  

+1

 



  n +1  n−α
1 + 2α −αϕlo  ϕlo+2  

+2

 


.
.






..
..
..
..
.
.
.

  ..  = 


 








..
..  
..
..
..




.
.
.
.
.

 



 







n +1 
n
ϕ
ϕ
−
α
1
+
2α
−
α

  hi−1  

hi−1

 


n +1
n
ϕhi + α2Aϕhi
−α
1 + 3α(10.23)This can be solved by standard matrix operations, using a tridiagonal solvers (forexample). Notice that the ghost cells do not appear in this linear system—we are
only updating the interior points.

Chapter 10. Diffusion

192
Crank-Nicolson time discretization

A second-order in time discretization requires us to center the righthand side in time.
We do this as:
ϕin+1 − ϕin
k
=
∆t
2

ϕin++11 − 2ϕin+1 + ϕin−+11
ϕin+1 − 2ϕin + ϕin−1
+
∆x2
∆x2

!

(10.24)This looks like the average of the explicit and implicit systems we just saw. This timediscretization is called Crank-Nicolson. Again, using α ≡ k∆t/∆x2 , and grouping all
the n + 1 terms on the left we have:α  n +1
α nϕi+1 − 2ϕin+1 + ϕin−+11 = ϕin +ϕi+1 − 2ϕin + ϕin−122(10.25)αα nαϕi+1 − 2ϕin + ϕin−1− ϕin++11 + (1 + α)ϕin+1 − ϕin−+11 = ϕin +22
2(10.26)

ϕin+1 −and grouping together the the n + 1 terms by zone, we have:

Considering homogeneous Neumann boundary conditions on the left and right, we
n +1
n +1
n +1
n +1
again have ϕlo
and ϕhi−1 = ϕlo+1 = ϕhi , and our stencil at the boundary becomesα n
α  n +1
α n +1 nnnϕlo = ϕlo+
ϕlo+1 − 2ϕlo
+ ϕlo
+
1
+
− ϕlo
−1
+
1
2
2
2

(10.27)The matrix form of this system is:α 1+ 2


 −α

2

















− α2
1+α

− α2

− α2

1 + α − α2
..
..
.
.
..
.

..

.

..

.

− α2

n +1
ϕlo





n + k∆t [∇2 ϕ ]n
ϕlo
lo
2



 


 


  ϕn+1   ϕn + k∆t [∇2 ϕ]n  lo+1   lo+1
lo+1 2   n +1   n
2 ϕ]n
[∇

  ϕlo+2   ϕlo+2 + k∆t
lo
+
2
2

 

..

  ..   .  = 
.
 







..
..

  ...  
.
.
 


 


 n +1   n

k∆t
2 n
1 + α − α2   ϕhi−1   ϕhi−1 + 2 [∇ ϕ]hi−1 
 


n +1
n + k∆t [∇2 ϕ ]nϕhi
ϕhi
− α2 1 + α2hi2
(10.28)Figure 10.5 shows the result of using α = 0.8 and α = 8.0. We see that they are both
stable, but that the smaller timestep is closer to the analytic solution (especially atearly times).

10.3—Implicit with direct solve

193
implicit diffusion, N = 128, C = 0.80

1.7

t = 0.000190735 s
t = 0.00038147 s
t = 0.000762939 s
t = 0.00152588 s
t = 0.00305176 s

1.6
1.5

φ

1.4
1.3
1.2
1.1
1.0
0.35

0.40

0.45

0.50

x

0.55

0.60

0.65

implicit diffusion, N = 128, C = 8.00

1.7

t = 0.000190735 s
t = 0.00038147 s
t = 0.000762939 s
t = 0.00152588 s
t = 0.00305176 s

1.6
1.5

φ

1.4
1.3
1.2
1.1
1.0
0.35

0.40

0.45

0.50

x

0.55

0.60

0.65

Figure 10.5: Implicit diffusion of a Gaussian (with Crank-Nicolson discretization) with
C = 0.8 and C = 8.0. The exact solution at each time is shown as the dotted line.
hydro_examples: diffusion_implicit.pyÏ

Exercise 10.3
Write a one-dimensional implicit diffusion solver for the domain [0, 1]
with Neumann boundary conditions at each end and k = 1. Your solver
should use a tridiagonal solver and initialize a matrix like that above. Use

Chapter 10. Diffusion

194

a timestep close to the explicit step, a grid with N = 128 zones.
Use a Gaussian for your initial conditions (as you did for the explicit
problem.

10.4

Implicit multi-dimensional diffusion via multigrid

Instead of doing a direct solve of the matrix form of the system, we can use multigrid
techniques. Consider the Crank-Nicolson system we just looked at:
ϕin+1 − ϕin1 2 n=k ∇ ϕi + k∇2 ϕin+1∆t2(10.29)∆t 2 n+1∆t= ϕin + k∇2 ϕink ∇ ϕi22(10.30)Grouping all the n + 1 terms on the left, we find:
ϕin+1 −

This is in the form of a constant-coefficient Helmholtz equation,( α − β ∇ 2 ) ϕ n +1 = f(10.31)

α = 1
∆t
k
β =
2

(10.32)withf= ϕn +(10.33)∆t 2 nk∇ ϕ2(10.34)This can be solved using multigrid techniques with a Helmholtz operator. The same
boundary conditions discussed in Chapter 9 apply here. The main difference between
the multigrid technique for the Poisson problem and the Helmholtz problem is theform of the smoother. In 1-d, we discretize Eq. 10.31 with a second-order difference
expression for the second derivative, and isolate ϕi , giving a smoothing operation of
the form:



β
2β
ϕi ← f i +
[
ϕ
+
ϕ
]
α
+
(10.35)
i +1
i −1
∆x2
∆x2
Note that when you take α = 0 and β = −1 in Eq. 10.35, the smoothing operation
reduces to the form that we saw in Chapter 9 for just the Poisson equation.
Recall, when using multigrid, you do not need to actually construct the matrix. Thisis usually the most efficient way to implement diffusion in a multi-dimensional simulation code, especially when distributing the grid across parallel processors. Since
the discretization is the same as the direct matrix solve, Eq. 10.28, the result will be
exactly the same (to the tolerance of the multigrid solver).

10.4—Implicit multi-dimensional diffusion via multigrid

195

phi

1.0

phi

1.0

1.8
0.8

1.004

0.8

1.6
0.6

1.003

0.4

1.002

y

y

0.6

1.4

0.4

0.2

0.0
0.0

0.2

0.4

0.6

0.8

1.0

1.2

0.2

1.0

0.0
0.0

x
t = 0.00000

1.001

0.2

0.4

0.6

0.8

1.0

x
t = 0.02000

Figure 10.6: Diffusion of a Gaussian in 2-d with 1282 zones using k = 1.0 and C = 2.0.
This used Crank-Nicolson time-discretization and multigrid. This can be run in pyroas ./pyro diffusion gaussian inputs.diffusion.

Figure 10.7 shows the result of diffusing a Gaussian profile on a 2-d grid using CrankNicolson time-discretization, a constant coefficient, and multigrid to solve the discretized system, using pyro. There is a good agreement between the analytic andnumerical solution, showing that this scheme models the diffusion of an initiallyresolved Gaussian well.
Exercise 10.4
The diffusion solver in pyro uses Crank-Nicolson differencing in time.
Modify the solver to do first-order backward Euler. This will change theform of the linear system (coefficients and righthand side), but should not
require any changes to the multigrid solver itself.
Compare the solution with the Crank-Nicolson solution for a very
coarsely-resolved Gaussian and a finely-resolved Gaussian.

10.4.1

Convergence

One needs to be careful with the Crank-Nicolson discretization. If the initial data
is under-resolved and you are taking a big timestep (C ≫ 1), then the method canbe unstable. Figure 10.8 shows such a case for the Gaussian diffusion with CrankNicolson discretization and 64 zones with C = 10. For this reason, simulation codes
often drop down to the simple backwards difference time-discretization for implicit
diffusion of under-resolved flows. A good discussion of the different types of stability
can be found in [47].

Chapter 10. Diffusion

196
1.05

1.04

φ

1.03

1.02

1.01

1.00
0.00

0.05

0.10

0.15

0.20
r

0.25

0.30

0.35

0.40

Figure 10.7: A comparison of 2-d implicit diffusion from Figure 10.6 with the analytic
solution at several times. The 2-d solution was averaged over angles to yield a profile
as a function of radius, using the gauss_diffusion_compare.py in pyro.

Figure 10.9 shows the convergence of several of the methods discussed here on the
diffusion of a Gaussian, for two different Courant numbers, 0.8 and 8.0. For the
lower case, we can do the diffusion explicitly as well as implicitly, and we see that
all methods show the same trends, with the Crank-Nicolson method being the mostaccurate (since it is the only second-order-in-time method shown). For the larger
timestep, we only run the implicit methods (the explicit case is unstable). We seethat at coarse resolution, the errors in the methods are similar—this is because thesolution is unresolved. At higher resolution, the error for the Crank-Nicolson method
is an order of magnitude lower.

10.5

Non-constant Conductivity

For a non-constant conductivity, our equation has the form:
∂
∂ϕ
=
∂t
∂x



∂ϕ
k
∂x



(10.36)

10.5—Non-constant Conductivity

197

implicit diffusion, N = 64, C = 10.00, t = 0.001

1.16
1.14
1.12

φ

1.10
1.08
1.06
1.04
1.02
1.00
0.2

0.3

0.4

0.5

0.6

x

0.7

0.8

Figure 10.8: Crank-Nicolson diffusion of a Gaussian on under-resolved initial datawith a large timestep. Here we use 64 zones and C = 10.
hydro_examples: diffusion_implicit.pyÏFor the case where k = k ( x ), we discretize as:
ϕin+1 − ϕin{k∇ϕ}i+1/2 − {k∇ϕ}i−1/2=∆t∆x(10.37)

Here we need the values of k at the interfaces, k i−1/2 and k i+1/2 . We can get these fromthe cell-centered values in a variety of ways including straight-averaging:k i+1/2 =or averaging the inverses:
11=
k i+1/2
2

1( k i + k i +1 )
2


1
1
+
ki
k i +1(10.38)(10.39)The actual form should be motivated by the physics
Slightly more complicated are state-dependent transport coefficients—the transportcoefficients themselves depend on the quantity being diffused:oϕin+1 − ϕin1n∇ · [k(ϕn )∇ϕn ]i + ∇ · [k(ϕn+1 )∇ϕn+1 ]i=∆t
2(10.40)Chapter 10. Diffusion

198

L2 norm of absolute error

10 −1
10

−2

diffusion convergence, C = 0.80, t = 0.005
O(∆x 2 )C-N implicit diffusion
backwards-difference diffusion
forward-difference (explicit) diffusion

10 −3
10 −4
10 −5
10 −6

N

L2 norm of absolute error

10 −1
10

10 2

diffusion convergence, C = 8.00, t = 0.005
O(∆x 2 )C-N implicit diffusion
backwards-difference diffusion

−2

10 −3
10 −4
10 −5
10 −6

N

10 2

Figure 10.9: Convergence of the explicit, backward-difference, and Crank-Nicolson
diffusion methods for C = 0.8 (top) and C = 8.0 (bottom). For the latter case, theexplicit method is not valid and is not shown. We see that the Crank-Nicolson method
has the lowest error, and when resolving the data, has second-order convergence.
hydro_examples: diff_converge.pyÏ(for example, with thermal diffusion, the conductivity can be temperature dependent). In this case, we can achieve second-order accuracy by doing a predictorcorrector. First we diffuse with the transport coefficients evaluated at the old time,10.6—Diffusion in Hydrodynamics

199

giving a provisional state, ϕ⋆ :ϕi⋆ − ϕin1
= {∇ · [k(ϕn )∇ϕn ] + ∇ · [k(ϕn )∇ϕ⋆ ]}∆t2(10.41)

Then we redo the diffusion, evaluating k with ϕ⋆ to center the righthand side in time,
giving the new state, ϕn+1 :o
ϕin+1 − ϕin1n=∇ · [k(ϕn )∇ϕn ] + ∇ · [k(ϕ⋆ )∇ϕn+1 ]∆t
2(10.42)This is the approach used, for example, in [13].

10.6

Diffusion in Hydrodynamics

Often we find diffusion represented as one of many physical processes in a single
equation. For example, consider the internal energy equation with both reactions
and diffusion:∂eρ + ρU · ∇e + p∇ · U = ∇ · k ∇ T + ρS
(10.43)∂tThis can be solved via an explicit-implicit discretization. First the advection terms
are computed as:
A = ρU · ∇e + p∇ · U(10.44)
Then the advective-diffusive part is solved implicitly. Expressing e = e(ρ, T ), andusing the chain rule,∇ e = e T ∇ T + eρ ∇ ρ(10.45)where eT = ∂e/∂T |ρ ≡ cv is the specific heat at constant volume and eρ = ∂e/∂ρ| T .
Rewriting, we have:∇ T = (∇e − eρ ∇ρ)/cv(10.46)and then∂e= ∇ · (k/cv )∇e − ∇ · (keρ /cv )∇ρ − A + ρS
(10.47)∂tThis is now a diffusion equation for e, which can be solved by the techniques described above. Note: if the transport coefficients (including cv , eρ ) are dependent one, then we still need to do a predictor-corrector method here. This is discussed, forexample, in [13, 48]. A simple case for this type of advection-diffusion is also shownin § 11.2.
ρPart IV

Multiphysics applications

11

ChapterModel Multiphysics Problems
11.1

Integrating Multiphysics

Consider a system whose evolution depends on several different physical processes,
represented by the operators A, D, R (advection, diffusion, and reactions, respectively).
ϕt = − A(ϕ) + D (ϕ) + R(ϕ)(11.1)
One way to solve this system is to discretize each of the operators in space. For
instance the discrete advection operator, [ A(ϕ)]i might use the ideas on piecewise
linear reconstruction techniques discussed in chapter 4, [ D (ϕ)]i can use the discrete
form of the Laplacian from chapter 10, and [ R(ϕ)]i may be an algebraic relation. This
leaves us with an ordinary differential equation for the time-evolution of ϕ,dϕi= −[ A(ϕ)]i + [ D (ϕ)]i + [ R(ϕ)]idt(11.2)

which can be solve using standard ODE techniques. This is the method of lines technique we saw with advection (§ 5.3) and compressible hydrodynamics (§ 8.10), andcan be a powerful technique to solve PDEs or systems of PDEs with multiple physics
operators
A difficulty arises if these processes each have different timescales associated withthem. For instance, reactions may be vigorous and require a small timestep to accurately capture the changes, but the advection is slow. Or, recall that the timestep
limiter for explicit diffusion scales as ∆x2 while explicit advection scales as ∆x, sothese processes could demand very different timescale for evolution. Therefore, we
don’t want to use the same timestep for all the processes, since that will needlessly
make things computationally expensive. Operator splitting solves for the effects ofeach operator separately, using whichever timestep (and time-discretization, e.g., explicit or implicit) is most suited to the operation. The result of one operation is used
git version: 64c838dee1a8 . . .

203

Chapter 11. Model Multiphysics Problems

204

as the input to the next* . The downside of this approach is that the operations may
not be well coupled.

11.2

Ex: diffusion-reaction

Consider a diffusion-reaction equation:
ϕt = κϕxx +

1
R(ϕ)
τ

(11.3)

This can be thought of as a simple model for a combustion flame, and can propagate
a front. It is often the case that the reactions are stiff, and require a smaller timestep
then the diffusion part. In fact, we may want to use an implicit integration method
designed for stiff ODEs for the reaction part, but use a standard explicit method forthe diffusion part. This requires operator splitting.
We can use Strang splitting [77] to make the integration second-order accurate overall:
ϕn+1 = R∆t/2 D∆t R∆t/2 ϕn(11.4)
where R∆t/2 represents reacting for a step of ∆t/2 and D∆t represents diffusing for a
step of ∆t. In each case, these operators act as if the other were not present, but they
see the effect of the previous operation on the input ϕ. Note that no explicit source
terms describing one process appear in the other process’s update. The procedurefor updating appears as:
1. Evolve reaction ODE system for ∆t/2
Define ϕ⋆ as the the solution to the ODE:dϕ
1
= R ( ϕ ),dtτϕ(tn ) = ϕn ,t ∈ [tn , tn+ /2 ]1

(11.5)

2. Solve the diffusion equation for ∆t with an implicit Crank-Nicolson discretizationϕ⋆⋆ − ϕ⋆1
= ( D (ϕ⋆ ) + D (ϕ⋆⋆ ))∆t2(11.6)

Note that the starting point is ϕ⋆ .
3. Evolve reaction ODE system for ∆t/2
Define ϕn+1 as the the solution to the ODE:
define ϕn+1 :dϕ1= R ( ϕ ),dt
τϕ(tn+ /2 ) = ϕ⋆⋆ ,1t ∈ [tn+ /2 , tn+1 ]1* This directly parallels the dimensional splitting approach we saw for advection in § 5.4.1(11.7)

11.2—Ex: diffusion-reaction

205

1.0
0.8

φ

0.6
0.4
0.2
0.0
0

20

40

x

60

80

100

Figure 11.1: Solution to the diffusion-reaction equation with 256 zones, and κ = 0.1,
τ = 1.0. The lines shown are spaced 8.0 time-units apart. We see the initial smoothedtophat profile giving rise to a traveling front.
hydro_examples: diffusion-reaction.pyÏConsider a simple reaction source
R(ϕ) =1
ϕ (1 − ϕ )4(11.8)

This is called a KPP reaction source. Here ϕ can be thought of as a progress variable
that varies between pure ash (ϕ = 0) and pure fuel (ϕ = 1). Figure 11.1 shows thesolution to our diffusion-reaction equation with 256 zones, κ = 0.1, τ = 1.0 at several
times.
√√The solution in this case is a wave with speed S = κ/τ and thickness δ = κτ (see[84] for some details of this system).
Exercise 11.1
Solve the the difusion reaction equation with the source given in Eq. ??.
Note that you should begin with some smooth initial conditions—if they
are too sharp than the C-N discretization will cause jagged features toappear. Compare your results to Figure 11.1.

Chapter 11. Model Multiphysics Problems

206

11.3

Ex: advection-diffusion

The viscous Burgers’ equation appears as:
ut + uu x = ϵu xx(11.9)

This admits shocks and rarefactions just like the inviscid form we studied in Chapter 6, but now the viscosity can act to smooth out the shock—instead of being infinitely thin, it will have a physical width.
As we saw earlier, there are efficient, accurate methods for handling the advective
parts explicitly, but for diffusion, we often want to solve it implicitly. We can split thesolution up, but couple the two processes together to make a method that is overall
second-order accurate in time. We write our equation as:
ut + A(u) = D (u)(11.10)with A(u) = [ 12 u2 ] x and D (u) = ϵu xx . Then our update appears in two steps.
1. Find the advective update over the timestep: We use an approximation of the diffusion term at time-level n, D (un ) as a source in the construction of the interface
1
states for the advective part. Once the interface states, uin++1//22 are known, weconstruct the advective update term as:

Ain+ /2 =
1

 
1
2

uin++1//22
1

2 

−
∆x

 
1
2

uin−+1//22
1

2 (11.11)

2. Solve the diffusion equation with the advective source: We use a Crank-Nicolson
discretization of the diffusion part of our equation, with the advective update
term appearing as a source.
u n +1 − u n111= D (un ) + D (un+1 ) − An+ /2∆t2
2(11.12)This is a linear system that can be solved as a tridiagonal matrix or with multigrid. The result of this step is that un+1 is updated with both the advection anddiffusion terms.
Because the diffusion is done implicitly, the timestep constraint (for stability) for thissolve is due to the advective portion only.
For step 1, the addition of the explicit diffusion source requires a small change to themethod we used to predict the interface states.

11.3—Ex: advection-diffusion

207

1.6

² =0.005000² =0.000500² =0.000050

1.4
1.2
1.0
0.8
0.6
0.4
0.0

0.2

0.4

0.6

0.8

1.0

Figure 11.2: Solution to the viscous Burgers’ equation with a variety of different viscosities. The initial conditions was a single wavelength of a sine wave for x ∈ [1/3, 2/3],
and u = 1 otherwise.
hydro_examples: burgersvisc.pyÏ∆x ∂u ∆t ∂u
+
+...
2 ∂x
2 
∂t

∆x ∂u ∆t∂unn= ui ++− ui+ D ( ui ) + . . .
2 ∂x
2
∂x


∆x
∆t
∂u ∆t
n
= ui +1−ui+ D (un ) + . . .
2
∆x
∂x
2

uin++11/2,L = uin +(11.13)(11.14)(11.15)here the source term (shown in red) incorporates the effects of the diffusion on theprediction of the states for advection. This entered into our states when we replaced∂u/∂t with our PDE equation. The spatial derivative, ∂u/∂x is replaced by a monotonized difference, and the method then proceeds as with the regular Burgers’ equation. The Riemann problem is unchanged from the inviscid case.
Figure 11.2 shows the solution of the viscous Burgers’ equation for shock initial conditions with different amounts of viscosity. Notice that the effect of the viscosity is
to smooth the shock profile, but the shock position itself agrees between the cases.

Chapter 11. Model Multiphysics Problems

208

L2 norm of absolute error

10 2( x 2)
Burgers' solution

10 3

10 4

10 5
102

N

103

Figure 11.3: Convergence of the Burgers’ solution with ϵ = 0.005. To test convergencea run with 4096 zones was done as a benchmark solution. We see second-order convergence for the higher-resolution runs in this sample.
hydro_examples: burgersvisc_converge.py

Ï
11.3.1

Convergence without an analytic solution

Assessing the convergence of this is more difficult than the tests we looked at before,
since there is no analytic solution to compare to. In this case, we can compare a very
high-resolution solution and take this to be the right answer / benchmark solution,and then compare coarser simulations to a coarsened version of the benchmark solution. This is done in Figure 11.3. The fine zones of the benchmark are averaged
into a corresponding coarse grid zone to produce a coarsened representation of thebenchmark, and the norm of the error with the coarse simulation is computed.

12

Chapter

Reactive Flow
12.1

Introduction

Many astrophysical problems involve modeling nuclear (or chemical) reactions coupled with hydrodynamics. Astrophysical reacting flows share a lot of similarities
with terrestrial combustion, including both subsonic (deflagrations) and supersonic(detonations) burning fronts. Nice discussions of the physics of reacting flows can befound in, e.g., [59, 62]
For multifluid flows, the Euler equations are augmented with continuity equations
for each of the nuclear (or chemical) species. If we denote the density of species k asρk , then conservation of mass for each species individually implies:∂ρk+ ∇ · (ρk U) = 0∂t(12.1)

Summing Eq. 12.1 over k gives us back the mass contunity equation, since ∑k ρk = ρ.
The ρk are sometimes called partial densities. Note that using both Eq. 12.1 and thenormal mass continuity equation for ρ overspecifies the system.
It is often easier to define a mass fraction of species k, Xk , as
Xk =

ρk
ρ

(12.2)and it is easy to see that ∑k Xk = 1, and∂(ρXk )
+ ∇ · (ρXk U) = 0∂t
git version: 64c838dee1a8 . . .

209(12.3)

Chapter 12. Reactive Flow

210
Exercise 12.1

Using the continuity equation, show that we can write Eq. 12.3 as anadvection equation:∂Xk+ U · ∇ Xk = 0(12.4)∂torDXk=0(12.5)
Dt
This latter form says that as a fluid element advects with the flow, its composition
does not change. However, reactions can turn one species into another, so for reacting
flow, DXk /Dt ̸= 0. If we define the creation rate for species k as ω̇k , then we have:
DXk
= ω̇k
Dt
Since ∑k Xk = 1, it must be that ∑k ω̇k = 0.

(12.6)

Reactions will also release (or consume) energy, due to the change in nuclear or
chemical binding energy. This energy will be a source to the internal energy. In
particular, our first law of thermodynamics now has a source: 
1Tds = de + pd
= qreact(12.7)
ρ
where qreact is the specific energy release due to reactions (energy / mass). Following
a fluid element, this takes the form:
DsDe
D (1/ρ)=+p= HnucDt
Dt
Dt
Where now Hnuc is the time-rate of energy release per unit mass (dqreact /dt).
T(12.8)

An additional energy source that we often consider along with reactions is thermal
diffusion. Fick’s law says that the heat flux is proportional to ∇ T, so we write:
Fcond = −kth ∇ T(12.9)

as the conductive heat flux. Here the ‘−’ indicates that heat flows from hot to cold
and kth is the thermal conductivity. See § 10.1 for more discussion.
The conservative Euler equations with reactive and diffusive source terms appear as:∂ρ+ ∇ · (ρU) = 0∂t(12.10)∂ρXk+ ∇ · (ρUXk ) = ρω̇k∂t

(12.11)∂(ρU)+ ∇ · (ρUU) + ∇ p = 0∂t∂(ρE)+ ∇ · (ρEU + pU) = ∇ · (kth ∇ T ) + ρHnuc∂t(12.12)(12.13)

12.1—Introduction

211

We’ll write the heat sources simply as H,
1
H = Hnuc + ∇ · kth ∇ Tρ(12.14)

In primitive form, the derivation of the pressure equation is a complex. Previously,
we found the pressure evolution in the absence of sources by differentiating pressure
along streamlines (Eq. 7.21):
Dp
∂p Dρ
∂p Ds
=
+
Dt
∂ρ s Dt∂s ρ Dt(12.15)where, as before, we recognize that Γ1 ≡ ∂ log p/∂ log ρ|s . Now, however, we have an
entropy source, so Ds/Dt ̸= 0. The Maxwell relations* tell us that∂p/∂s|ρ = ρ2 ∂T/∂ρ|s(12.16)

Dp
p Dρ
∂T H
= Γ1
+ ρ2
Dt
ρ Dt
∂ρ s T(12.17)This gives us the form:

We need an expression for ∂T/∂ρ|s in terms of derivatives of ρ and T (since that iswhat our equations of state typically provide). Consider Γ1 , with p = p(ρ, T ):


ρ
ρ dp
dT
=
(12.18)Γ1 =pρ + p T
p dρ spdρ swhere we use the shorthand pρ ≡ ∂p/∂ρ| T and p T ≡ ∂p/∂T |ρ . This tells us that∂Tp
( Γ1 − χ ρ )
=
∂ρ s
ρp T

(12.19)where χρ ≡ ∂ log p/∂ log ρ| T . To further simplify this, we use some standard relations
for general equations of statecpΓ1=(12.20)χρcv
andc p − cv =

p χ2T
ρT χρ

(12.21)

with χ T ≡ ∂ log p/∂ log T |ρ (see, e.g., [40] for both of these relations). These allow us
to write∂Tpχ
= 2T(12.22)∂ρ s
ρ cv* see, for instance, [73], for some discussion on these relations

Chapter 12. Reactive Flow

212
Putting this all together, we have:
p Dρ
pχ
Dp
= Γ1
+ TH
Dt
ρ Dt
cv T

(12.23)and using the continuity equation, Dρ/Dt = −ρ∇ · U, we finally have:∂p+ U · ∇ p + Γ1 p∇ · U = Γ1 pσH∂twhere we definedσ=
The σ notation follows from [6].

∂p/∂T |ρρc p ∂p/∂ρ| T(12.24)(12.25)The primitive variable is then∂ρ
+ U · ∇ρ + ρ∇ · U = 0∂t∂U1+ U · ∇U + ∇ p = 0∂tρ∂p+ U · ∇ p + Γ1 p∇ · U = Γ1 pσH∂t∂Xk+ U · ∇ Xk = ω̇k∂t(12.26)(12.27)(12.28)(12.29)Finally, we can derive a temperature evolution equation following the method from§ 7.3. We find


p
DT
∂e
cv
−
=
∇·U+H
(12.30)Dt∂ρ T ρ
or


1
∂h
Dp
DT
cp
=
−
+H
(12.31)Dtρ∂p T Dt
depending on whether we start with e or h.

12.2

Operator splitting approach

Using operator splitting, we separate the equations into hydrodynamics and reactive
parts and we do these operations in turn. Following the ideas from § 11.2, we performthe update in stages. If we denote the reaction update operator as R∆t and thehydrodynamics operator as A∆t , then our update appears as:

U n+1 = R∆t/2 A∆t R∆t/2 U n(12.32)

To make it more explicit, we write out system as:∂U+ ∇ · F( U ) = R( U )∂t(12.33)

12.2—Operator splitting approach

213

where R = (0, ω̇k , 0, ρHnuc )⊺ is the vector of reactive sources. The advance through∆t in time is:
1. Evolve reaction part for ∆t/2.
We define U i⋆ as the result of integratingd Ui= R( U i )dt(12.34)over t ∈ [tn , tn+1/2 ] with initial conditions, U i (tn ) = U in .
2. Solve the hydrodynamics portion for ∆t, beginning with the state U ⋆FU i⋆⋆ − U i⋆=∆t( x ) ( U ⋆,n+1/2 ) − F( x ) ( U ⋆,n+1/2 )i −1/2i +1/2∆x(12.35)/2where U i⋆−,n1+
is the predict interface state (using the ideas from § 8.2), begin/2
ning with the state U ⋆ . Note that R does not appear here explicitly.
1

Alternately, we could use the MOL hydrodynamics update here, but the basic
idea will be the same—the hydrodynamics does not explicitly see the reaction
terms.
3. Evolve reaction part for ∆t/2
We reach the final update, U n+1 , by integratingdU= R( U )dt(12.36)over t ∈ [t1/2 , tn+1 ] with initial conditions U (tn+1/2 ) = U ⋆⋆ .

12.2.1

Adding species to hydrodynamics

In the hydrodynamics algorithm, we neglect the diffusion and reaction terms. Their
effects are incorporated implicitly by performing the hydrodynamics update startingwith the state that has already experienced burning.
∂ρ+ ∇ · (ρU) = 0∂t∂(ρXk )
+ ∇ · (ρUXk ) = 0∂t∂(ρU)+ ∇ · (ρUU) + ∇ p = 0∂t∂(ρE)+ ∇ · (ρEU + pU) = 0∂t(12.37)(12.38)(12.39)(12.40)Chapter 12. Reactive Flow214

When we now consider our primitive variables: q = (ρ, u, p, Xk ), we find



u ρ
0
0
 0 u 1/ρ 0 
A(q) =  0 Γ1 p u
0 
0 0
0
u

(12.41)

There are now 4 eigenvalues, with the new one also being simply u. This says thatthe species simply advect with the flow. The right eigenvectors are now:1
 c/ρ r(+) =  c2 
0(12.42)
(−)
(◦)
(◦
,X
)
(+)
corresponding to λ= u − c, λ = u, λ= u, and λ= u + c. We see that forthe species, the only non-zero element is for one of the u eigenvectors (r(◦,X ) ). Thismeans that Xk only jumps over this middle wave. In the Riemann solver then, there
is no ‘star’ state for the species, it just jumps across the contact wave.
1
 −c/ρ r(−) =  c2 
0


1
 0 

r(◦) = 
 0 
0



0
 0 

r(◦,X ) = 
 0 
1




To add species into the solver, you simply need to reconstruct Xk as described in
Chapter 8 to find the interface values. If we are doing characteristic tracing, then we
use this new A(q) and associated eigenvectors. We then solve the Riemann problem,with Xk on the interface taken as simply the left or right state depending on the signof the contact wave speed, and do the conservative update for ρXk using the species
flux.
One issue that can arise with species is that even if ∑k Xk = 1 initially, after the
update, that may no longer be true. There are a variety of ways to handle this:• You can update the species, (ρXk ) to the new time and then define the density
to be ρ = ∑k (ρXk )—this means that you are not relying on the value of thedensity from the mass continuity equation itself.
• You can force the interface states of Xk to sum to 1. Because the limiting is
non-linear, this is where problems can arise. If the interface values of Xk areforced to sum to 1 (by renormalizing), then the updated cell-centered value of
Xk will as well. This is the approach discussed in [63].
• You can design the limiting procedure to preserve the summation property.
This approach is sometimes taken in the combustion field. For piecewise linear
reconstruction, this can be obtained by computing the limited slopes of all the
species, and taking the most restrictive slope and applying this same slope toall the species.

12.3—Burning modes

12.2.2215

Integrating the reaction network

The reactive portion of our operator split system is:
dXk
= ω̇k
dt
d(ρe)
= ρHnucdt(12.43)(12.44)

As written, this system is not closed without the equation of state, since ω̇k =ω̇k (ρ, T, Xk ), and likewise for Hnuc . Our temperature evolution equation reducestodTcx= Hnuc(12.45)dt
where c x is cv or c p , depending on the physical effects we are trying to capture. Thisdifference only arises because we are neglecting the hydrodynamic portions of thetemperature evolution during the reaction step.
Many simulation codes neglect the evolution of temperature during the reaction step(see, e.g., [34]).
An excellent introduction to integrating astrophysical nuclear reaction networks isfound in [79]. The main issue with reaction networks is that they tend to be stiff,
which means that implicit integration techniques are needed. There are a number ofwell-tested, freely available implicit ODE integrators (e.g. [18]).
For stiff systems, you need to supply both a righthand side routine and a Jacobianroutine† .

12.2.3

Incorporating explicit diffusion

12.3

Burning modes

12.3.1

Convective burning

12.3.2

Deflagrations

A deflagration or flame is a subsonic burning front that propagates via a balance ofdiffusion and reactions. Thermal diffusion raises the temperature of fuel ahead of theflame to ignition and the energy release heats the ash, keeping the thermal gradientneeded for diffusion. In terrestrial flames, species diffusion can be important as well,
but this is usually negligible in astrophysical flames.
Because the burning front is subsonic, sound waves can communicate across theflame and therefore the fuel and ash are at the same pressure. The temperature jump
† although this could be calculated via finite-differences if neededChapter 12. Reactive Flow216

across the flame means that the density will drop behind the flame to preserve theconstant pressure. Our temperature evolution equation, taking Dp/Dt = 0, isρc pDT= ∇ · kth ∇ T + ρHnuc
Dt(12.46)

We can estimate the timescale for diffusion by neglecting the reactions and writing1
DT=∇ · kth ∇ T ≈ D∇2 T
Dt
ρc p(12.47)

where D = kth /(ρc p ) is the diffusion coefficient (assuming ρc p is spatially constant).
Dimensional analysis suggests that the diffusion timescale is thentdiff ≈

δ2
D

(12.48)where δ is the width of the region where diffusion takes place—we’ll identify this as
the flame thickness.
Similarly, we can estimate the reaction timescale by consideringρc pDT= ρHnuc
Dt(12.49)and writing
tburn ≈

cpT
Hnuc

(12.50)We can alternately expand Hnuc in terms of temperature if we wish to capture someof the temperature sensitivity.
Equating these timescales gives
δ∼



kth T
ρHnuc

1/2

(12.51)

which is an estimate of the flame thickness. We can define the flame speed as thetime it takes to burn through this thickness:
vf ∼

δ
tburn

∼



kth Hnucρc p T1/2(12.52)

We note the main dependences are:vf ∼12.3.3

Detonationspkth Hnuc

δ∼

s

kth
Hnuc

(12.53)

13

Chapter

Planning a Simulation
13.1

How to setup a simulation?

When you perform a simulation, you are making a series of approximations. The firstcomes with the choice of equation set. As discussed earlier, for pure hydrodynamics,
this often means solving the Euler rather than the full Navier-Stokes equations. The
next approximation is made when discretizing the equations, using the methods we
described in the earlier chapters.
Astrophysical flows involve a range of length and timescales. Often it is not possible
to capture all these scales in a single simulation, so some comprimises must be made.
If you are interested in the dynamics on the full scale of the system, L, then you will
resolve down to some cutoff scale l, where L/l ∼ O(103 –104 ). At scales smaller thanl, you neglect the flow features. The smallest scale of importance is the disipation
scale λ ≪ L.
If you are not resolving down to the dissipation scales in our problem, then you areworking in the realm of large eddy simulations (LES; see [67]). Proper LES requires
a subgrid model to treat the unresolve scales and their feedback onto your grid. If
you instead rely on numerical diffusion of your method to do the dissipation, you
are doing implicit large eddy simulation or ILES—for many flows, this be sufficient tocapture the dynamics (including turbulence) that are important [8, 49].

13.2

Dimensionality and picking your resolution

Nature is three-dimensional, so realistic simulaitons generally require full 3-d modeling. Nevertheless, 2-d simulations can be useful to scope out the problem space,and in particular, to get a feel for the timescales and resolution needed to resolve
git version: 64c838dee1a8 . . .

217

Chapter 13. Planning a Simulation

218

smallscale features. The major place where dimensionality affects results is for instabilities and turbulence. The trend in 2-d is for small scale vortices to merge and build
larger and larger structures (see, e.g., [16]), while in 3-d motions at the largest scalecascade down to smaller scales, driving turbulent flow down to the smallest scales.
Turbulence can be very important in astrophysical flows, and properly capturing it
requires modeling a large range of lengthscales (physically, the objective is to get alarge Reynolds number: the ratio of the advective force to the dissipative force). Generally, you’ll just start to get a resolved inertial range over a decade in wavenumber
in your power spectrum at around 512 zones on a side of your domain (using themethods that we discussed here). With fewer points than this, you are unlikely tocapture turbulence.
If nuclear burning is modeled, the steepness of the reaction rate will set a lengthscale.
Burning can also wash out instabilities, a process sometimes called fire polishing [12,80]. Here, if the timescale for reactions is faster than the growth rate of an instability,
the instability is suppressed. This can set a small scale cutoff that is well above theviscous dissipation scale.
Hydrostatic equilibrium also puts demands on the resolution. Recall that the momentum equation is:DUρ+ ∇ p = ρg
(13.1)Dt
If hydrostatic equilibrium, ∇ p = ρg, is not exactly satisfied, then the residual willappear as a force that generates an acceleration and non-zero velocities will build up.
A good rule of thumb is that you need 10 points per pressure scale height to get areasonable hydrostatic balance (this is discussed at bit in [87]).
Spatial resolution is often in contention with improved physics—both can add to thecomputational cost of a simulation, so for fixed cost, you have often have to choose
between more physics (e.g., larger reaction network) or more resolution.
An important part of the simulation process is to ensure that your results are converged. In a convergence study, you run the same simulation at various resolutions
and look to see that the major results (e.g., integral quantities) do not change significantly with resolution. Ideally you would show that any results you are interested
are moving toward an asymptotic value. Even if you are not converged however, you
could use the trends observed with resolution to help understand the possible error
in your simulation.

13.3

Boundary conditions

Another approximation you make is how to treat the boundaries. Usually one
chooses symmetry / reflecting, outflow / zero-gradient, inflow (specifying the valueon the boundary), or periodic. In the case of symmetry, the fluid state is reflected13.4—Timestep considerations

219

and the normal velocity is reflected with a sign change. The transverse velocity canbe left as is (a slip wall) or set to zero at the boundary (no-slip wall).
Generally speaking, you should put your boundaries as far away from the place
where the action is occuring as possible. For example, if you are modeling a convective region bounded by stably stratified flow, then you should have a large buffer ofstable atmosphere bounding it.
Periodic boundary conditions don’t magically fix everything either. With a triplyperiodic box (periodic on all boundaries), then you are confining the flow. If energy
is injected into the box, then there is no place for it to expand, and this can lead to
artifical heating or compression.
Symmetry / reflecting boundaries provide a simple way to reduce a problem size,for example, modeling only an octant of a star in 3-d instead of the full star. But
they also introduce artifacts, since they force the normal velocity to zero right on theboundary. This means that flow through the center of a star (e.g., if we model only anoctant) can be restricted, resulting in artifical flow / convective features. Wall heating
can also be an issue—forcing the normal velocity to zero at the symmetry boundary
can lead to stagnation of the flow there, allowing hot spots to develop and not betransported away.

13.4

Timestep considerations

The timestep constraint we discussed (the CFL condition) is required for stability,
but that is different than accuracy. In particular, accurately capturing some physicalprocesses (that may appear as source terms) might require more restrictive timesteps
to ensure that they are properly coupled with the hydrodynamics.
An example where this can commonly arise is reactive flows—combining hydrodynamics with nuclear or chemical reactions. If the reactions are very vigorous, thenyou may run into a situation where you exaust your fuel in a zone in a single step,
without giving the hydrodynamics a chance to advect new fuel in. This represents a
breakdown of the coupling of the hydrodynamics and reactions. A common way to
improve the accuracy here is to monitor the change in mass fractions of a fuel andset a timestep limit such that:∆treact = Creact

Xfuel|ω̇fuel |(13.2)

where Creact < 1. The species creation rate, Ẋreact , is typically evaluated using thevalue from the previous step.

Chapter 13. Planning a Simulation

220

13.5

Convergence and multiphysics

For a full simulation, with hydrodynamics coupled to other physics, you should
test your code to ensure that it is converging at the rate that you expect. Usuallyin this case there is no analytic solution, so you need to measure the convergencenumerically. A standard way to do this is to run pairs of simulations that differ bya factor of two in resolution, we’ll denote the coarser simulation with the subscript
c and the finer simulation with the subscript f . The error is computed for a field ϕby coarsening the finer simulation by a factor of two, and computing the norm of thedifference:ϵ ≡ ∥ϕc − C(ϕ f )∥(13.3)
Here, we denote the coarsening operator as C(.). In this case, two simulations give usa single error. We then repeat this, taking the fine simulation from this comparisonas the coarse for the next, and using an even finer simulation to generate a new error.
We can then measure the convergence of a multiphysics simulation by comparing theerrors from the two pairs of the simulations. This procedure was used in, e.g., [4, 52].
Ideally, a smooth problem should be used, since discontinuities by definition do notconverge with resolution (and limiters, if used, would kick in there as well).

13.6

Computational cost

The main limitation to your choice of resolution and timestep is computational cost.
For a three-dimensional simulation in a box with N zones on a side, the work scalesas O( N 4 ). The cost to advance a single timestep is based on the volume, N 3 , andthe number of timesteps to get you to a fixed simulation time, tmax , is tmax /∆t, but∆t ∼ ∆x/s ∼ L/( Ns), where s is the fastest information speed. So the number oftimesteps increases with N, making the total cost N 4 . Think about this for a minute—if you double the number of zones, then the amount of work you need to do increases
by 16×.
A common conflict that arises is: Do you do one “hero” calculation or many smaller
calculations to understand the sensitivity of your results to input parameters? Computing centers that grant allocations usually setup their queues to favor big jobs thatuse as much of the machine as possible (as that’s what their funders use as a metricfor their success).
It is important to understand that no single algorithm will offer everything you need.

13.7

I/O

Another challenge with simulations is data storage. For a calculation on a 10243
grid, using double precision, each number you store takes 8 bytes / zone, so a single

13.7—I/O

221

variable on the grid will require 8 GB. For compressible hydro, you will have atleast
5 variables (in 3-d), ρ, (ρU), and (ρE), so this is a minimum of 40 GB per file. Often
you will want some derived quantities (like temperature) and composition quantities
in your output, which will greatly increase your storage requirements.
For this reason, simulation codes often have different types of output. Checkpoint
files store all the variables that are needed to restart the calculation from where youleft off—these should be stored in a (portable) binary format at machine precision.
You don’t need to keep these around forever, perhaps only saving the last few asnecessary to restart your calculation as it works through a computing center’s queue.
Plotfiles store a lot of variables—basically anything that will be needed for the analysis of the simulation. Since you don’t need these to restart, you can probably afford
to store the variables at single precision. Sometimes you might have multiple levelsof plotfiles, storing a few variables (like density) very frequently to allow for the production of smooth movies, and storing a lot of variables and derived quantities at amuch longer cadence.
A perpetual challenge with the analysis and visualization of simulations is that sometimes you don’t know what you are looking for until the simulation is complete, so
you cannot simply do runtime visualization and not save the raw data as the simulation progresses. This leads to collections of plotfiles that can easily top 100 TB per
simulation. Runtime diagnostics can help a little—if you know any global quantities
that you will be interested in over the course of the simulation (like peak temperature, or total energy) you can compute these on the fly and simply store a single
number per step (or every N steps) into a file.

Part V

Low Speed Hydrodynamics

14

Chapter

Incompressible Flow and
Projection Methods
14.1

Incompressible flow

As a fluid parcel advects through a domain, it compresses and expands due to avariety of effects (stratification, local heat release, acoustic/shock waves). The Lagrangian derivative of the density captures the changes in the fluid, and is a measureof its compressibility. From the continuity equation, we see:

−

1 Dρ
= ∇·U
ρ Dt

(14.1)

Note that for ∇ · U > 0, we have −(1/ρ)( Dρ/Dt) > 0, which means that ρ getssmaller—this is expansion of the Lagrangian fluid element.
A fluid in which the density (and therefore volume) of a fluid element is not allowed to change is called incompressible. An incompressible fluid obeys the velocity
constraint:∇·U = 0(14.2)(since Dρ/Dt = 0). The incompressible fluid approximation is a reasonable approximation when the Mach number of the fluid is small (≪ 1). To complete the system,
we add the momentum equation. If we take the density to be constant everywherein the domain (not just in our fluid element), then we have:∂U+ U · ∇U + ∇ p = 0∂t(14.3)

Note that p here looks like a pressure, but it is not subject to any equation of state.
This system is closed as written. The value of p is determined such that the velocity
constraint is satisfied.
git version: 64c838dee1a8 . . .

225

Chapter 14. Incompressible Flow and Projection Methods

226

We can gain more insight into the applicability of the incompressible equations by
doing an asymptotic expansion. Starting with the momentum equation from theEuler equations:∂(ρU)+ ∇ · (ρUU) + ∇ p = 0(14.4)∂t
we can introduce dimensionless variables:
Ū =

U
;
| U0 |

t̄ =

t
;
t0

ρ̄ =

ρ
;
ρ0

x̄ =

x
;
L0

p̄ =

p
ρ0 c20(14.5)

and we find the dimensionless evolution equation:∂(ρ̄Ū)¯ · (ρ̄ŪŪ) + 1 ∇¯ p̄ = 0+∇∂t̄
M2(14.6)

Now we introduce an expansion of pressure in terms of Mach number:p = p0 + p1 M + p2 M 2(14.7)

Grouping terms by power of Mach number, we find:∇ p0 = ∇ p1 = 0(14.8)∂(ρU)+ ∇ · (ρUU) + ∇ p2 = 0∂t(14.9)

and

Only p2 , which is sometimes called the dynamical pressure appears in the dynamics.
All of the thermodynamic content is in p0 , consistent with our argument previouslythat no equation of state is needed.
Recalling that pressure evolves according to∂p+ γp∇ · U + U · ∇ p = 0∂t(14.10)

The general expression for the velocity divergence is:
1 Dp
γp Dt

(14.11)∇ · U ∼ O( M2 )(14.12)∇·U = −
from our pressure expansion, we see that

This justifies our argument that the incompressible equations apply at low Mach
number.

14.2—Projection methods

14.2

227

Projection methods

The basic idea behind a projection method is that any vector field can be decomposed
into a divergence free part and the gradient of a scalar (this is sometimes called a
Hodge decomposition). Given a velocity field U⋆ , we can express it in terms of thedivergence free part Ud and a scalar, ϕ as:
U⋆ = Ud + ∇ϕ

(14.13)

Taking the divergence of each side, and noting that ∇ · Ud = 0, we have

∇ · U ⋆ = ∇2 ϕ

(14.14)This is an elliptic equation. Given suitable boundary conditions, we can solve for ϕ(for instance, using multigrid) and recover the divergence free part of U⋆ as:
Ud = U⋆ − ∇ϕ(14.15)

We call this operation of extracting the divergence free part of a velocity field aprojection. This can be expressed by defining an operator P, such that PU⋆ = Ud , and( I − P)U⋆ = ∇ϕ. From the momentum equation, we see that ∂U/∂t + ∇ p is in theform of a divergence free term + the gradient of a scalar. This means that advancing
the velocity field subject to the constraint involves solving:
Ut = P(Ut + ∇ p) = P(−U · ∇U)(14.16)

See Bell, Colella, and Howell [10] for a nice discussion of this.
The original projection method for incompressible flows goes back to Chorin [21].
Instead of evolving Eq. 14.16 directly, we break the update into pieces. The basic idea
is to evolve the velocity advection equation without regard to the constraint, yielding a provisional velocity field which is then subjected to a projection to enforce thedivergence-free constraint. Bell, Colella, and Glaz (BCG) [9] introduced a projection
method that uses standard Godunov methods for the advection terms (much likeis done with compressible flow) and then solves an elliptic equation to enforce theconstraint. This division of the operations in the algorithm (advect then project) is a
type of fractional step method.
There are different ways to discretize the operators that make up the projection. We
denote the discretized divergence as D and the discretized gradient operation as G.
For an exact projection, the discretized Laplacian, L, would be the same as applying
G and D in succession (i.e. L = DG). Depending on our data centerings, we may
prefer to discretize the Laplacian independently to D and G, such that L ̸= DG. Thisis called an approximate projection. Note that for an approximate projection, P is not
idempotent: P2 U ̸= PU.
Many variations on this basic idea exist, using alternate forms of the projection,different grid centerings of the ϕ variable, and additional physics.

Chapter 14. Incompressible Flow and Projection Methods

228

Figure 14.1 shows an example of a projection. The initial velocity field is specified as:
u = − sin(πx )2 sin(2πy)
v=

2sin(πy) sin(2πx )(14.17)(14.18)which is divergence free and doubly-periodic. This is then modified by adding thegradient of a scalar, ϕ, of the form:ϕ=1
cos(2πy) cos(2πx )10(14.19)yielding a new velocity, U p = U + ∇ϕ. The result is the middle panel in the figure,and is not divergence free. A projection is then done, to recover ϕ by solving∇2 ϕ = ∇ · U p(14.20)For this figure, we use the standard 5-point Laplacian and a divergence built via
centered-differences:∇·U =ui+1,j − ui−1,jvi,j+1 − vi,j−1
+
2∆x
2∆y

(14.21)

Together, these represent an approximation projection.
Exercise 14.1
Implement an approximate projection, using pure smoothing for solving
the elliptic equation. Start with the velocity field described by Eqs. 14.17
and 14.18 and the scalar from Eq. 14.19. Compute a poluted velocity field,
U p = U + ∇ϕ and then project it to recover the original velocity field.

14.3

Cell-centered approximate projection solver

Here we describe an incompressible algorithm that uses cell-centered data throughout—
U and p are both cell-centered. The projection at the end is an approximate projection. The basic algorithm flow is• Create the time-centered advective velocities through the faces of the zones.
• Project the advective velocities such that they obey the velocity constraint• Construct the time-centered interface states of all quantities on the faces of thezones using the advective velocity.
• Update the velocity to the new time. This is defines the provisional velocity
field—it does not yet satisfy the constraint.

14.3—Cell-centered approximate projection solver

120
100
80
60
40
20
0
120
100
80
60
40
20
0
120
100
80
60
40
20
0

original u229

original v
0.8

0.8

0.4

0.4

0.0

0.0

0.4

0.4

0.8

0.8

'polluted' u'polluted' v
0.8

0.8

0.4

0.4

0.0

0.0

0.4

0.4

0.8

0.8

projected u

projected v
0.8

0.8

0.4

0.4

0.0

0.0

0.4

0.4

0.8

0.8

0 20 40 60 80 100 120

0 20 40 60 80 100 120

Figure 14.1: An example of an approximate projection, on a 1282 grid. The top shows
the original velocity field, Eqs. 14.17 and 14.18. This was poluted by adding the gradient of a scalar, Eq. 14.19 (middle) and then a projection was done to recover the original
velocity field (bottom). In this case, the L2 norm of the error on the velocity (comparing
before and after projection) is 0.000189.
hydro_examples: project.pyÏ• Enforce the velocity constraint by projecting the velocity.
The description below is pieced together from a variety of sources. BCH describes acell-centered method, but with an exact projection (with a larger, decoupled stencil).
Almgren, Bell, and Szymczak (ABS) [7] describes an approximate projection method,
but with a node-centered final projection. We follow this paper closely up until the
projection. Martin and Colella [50] (and Martin’s PhD thesis) method uses a cell-Chapter 14. Incompressible Flow and Projection Methods

230

centered projection, as is described here. They go into additional effort to describe
this for a refined grid. All of these method are largely alike, aside from how thediscretization of the final projection is handled.

14.3.1

Advective velocity

In predicting the interface states, we first seek to construct the velocities through theinterfaces. A key concept throughout the advection step is that once we have thenormal velocities on the interfaces, we can use these to upwind left and right statesof any quantity to get their interface value. The advective velocities we construct
here, uadv and vadv , will later be used to upwind the various states we predict to theinterfaces. We only need the velocity through the interfaces, as shown in the figure
14.2. This staggered grid arrangement is sometimes called a MAC grid.

ui,j +1
vi,j +1

j +1

adv

vi,j +1/2

adv

ui,j
vi,j

ui +1/2,jadv

ui−1/2,jui−1,jvi−1,jjui +1,jvi +1,jadvvi,j−1/2j−1ui,j−1vi,j−1

i

−1

i

i +1

Figure 14.2: The staggered ‘MAC’ grid for the advective velocities.

We follow ABS. Our velocity evolution system (writing out the individual compo-

14.3—Cell-centered approximate projection solver

231

nents of U: u and v) is
∂u
∂t
∂v
∂t

∂u
∂u ∂p
−v −
=0
∂x
∂y
∂x
∂v
∂v ∂p
= −u − v −
=0
∂x
∂y ∂y

= −u

(14.22)(14.23)

Our goal in this step is to predict time-centered interface values of the normal velocity(u on x-edges and v on y-edges). The prediction follows from Taylor expanding thestate to the interface (through ∆x/2 or ∆y/2) and to the half-time (through ∆t/2). As
with the regular advection, we can have left and right states which we will resolveby solving a Riemann problem. The left interface state of u at i + 1/2, j is found as:
∆x ∂u
∆t ∂u
+
(14.24)2 ∂x i,j
2 ∂t i,j


∆x ∂u
∆t
∂u
∂u ∂p
= ui,j ++−u − v −(14.25)2 ∂x i,j2∂x∂y∂x i,j




∆t
∂u
∆t
∂u
∆t ∂p
∆x
1−
ui,j
−
v
−
(14.26)= ui,j +2∆x∂x i,j2∂y i,j2 ∂x i,j

uin++1//22,j,L = ui,j +1(14.27)(x)(x)

We express ∂u/∂x |i,j as ∆ui,j /∆x, where ∆ui,j is the limited slope of u in the xdirection in zone i, j. Our interface state is then:1
1
uin++1//22,j,L = ui,j +
2
|






∆t ∂p
∆t
∆t
∂u
(x)
−
1−
u ∆ui,j −v∆x2∂y i,j 2 ∂x i,j
{z
} |
{z
}

≡ûin++1//22,j,L
1(14.28)transverse term

Similarly, for v through the y faces, we find:
1
n+1/2
vi,j
+1/2,L = vi,j + 2
|






∆t
∆t
∂v
∆t ∂p
(y)
1−
v ∆vi,j −u−∆x2∂x i,j 2 ∂y i,j
{z
} |
{z
}

n+ /2
≡v̂i,j+1/2,L1(14.29)transverse term

As indicated above (and following ABS and the similar notation used by Colella [24]),
we denote the quantities that will be used to evaluate the transverse states (consisting
only of the normal predictor) with a ‘ˆ’. These will be used to evaluate the transverse
terms labeled above.
We predict u and v to both the x and y interfaces, using only the normal part of thepredictor. This gives us the left and right ‘hat’ states on each interface.

Chapter 14. Incompressible Flow and Projection Methods

232
u on x-interfaces:1ûin++1//22,j,Lûin++1//22,j,R
1

v on x-interfaces:


∆t
(x)
1−
ui,j ∆ui,j
∆x


1
∆t
(x)
ui+1,j ∆ui+1,j= ui+1,j −
1+
2
∆x
1
= ui,j +
2


∆t
(x)
ui,j ∆vi,j
1−
∆x


1
∆t
(x)
= vi+1,j −1+
ui+1,j ∆vi+1,j2∆xv̂in++1//22,j,L = vi,j +
1

n+ /2
v̂i,j
+1/2,R
1



1
2



(14.30)(14.31)(14.32)(14.33)u on y-interfaces:
n+1/2
ûi,j
+1/2,Ln+ /2
ûi,j+1/2,R
1


∆t
(y)
1−
vi,j ∆ui,j
∆y


∆t
1
(y)
1+
vi,j+1 ∆ui,j+1= ui,j+1 −2∆y1= ui,j +2

(14.34)(14.35)v on y-interfaces:
n+1/2
v̂i,j
+1/2,Ln+ /2
v̂i,j+1/2,R
1


∆t
(y)
1−
vi,j ∆vi,j
∆y


∆t
1
(y)
1+
vi,j+1 ∆vi,j+1= vi,j+1 −2∆y1= vi,j +2

(14.36)(14.37)Note that the ‘right’ state is constructed using the data to the right of the interface.
Also note that in constructing these transverse velocities, we do not include the pterm.
Next we find the advective velocity through each interface. The incompressible velocity equation looks like the inviscid Burger’s equation, and the Riemann solver follows
that construction. BCG provide the implementation used here (and throughout theincompressible literature). Also see Toro [82]. We denote the resulting velocities withthe ‘adv’ superscript, as these are the normal velocities used to advect the hat states.
The Riemann problem solution is:
qL + qR > 0
 q L if q L > 0,
R(q L , q R ) =(14.38)0 if q L ≤ 0,
qR ≥ 0q R otherwise
We solve this for each of the normal velocities, giving:

n+ /2
n+ /2
ûadv
i +1/2,j = R( ûi +1/2,j,L , ûi +1/2,j,R )
1

1

n+1/2

n+1/2

v̂adv
i,j+1/2 = R( v̂i,j+1/2,L , v̂i,j+1/2,R )(14.39)(14.40)14.3—Cell-centered approximate projection solver

233

These advective velocities (sometimes called the transverse velocities) are used to resolve the left and right states of all the hat quantities by simple upwinding. For a u
or v state on the x-interface, we upwind based on ûadv ; and for a u or v state on they-interface, we upwind based on v̂adv . If we write the upwinding as:qL
if sadv > 0adv
1(14.41)
U [s ](q L , q R ) =(q + q R ) if sadv = 0
 2 L
adv
qR
if s
<0
Then the interface states are:

n+ /2
n+ /2
ûi+1/2,j = U [ûadv
i +1/2,j ]( ûi +1/2,j,L , ûi +1/2,j,R )
1

1

n+ /2
n+ /2
v̂i+1/2,j = U [ûadv
i +1/2,j ]( v̂i +1/2,j,L , v̂i +1/2,j,R )
1

1

n+ /2
n+ /2
ûi,j+1/2 = U [v̂adv
i,j+1/2 ]( ûi,j+1/2,L , ûi,j+1/2,R )
1

1

n+ /2
n+ /2
v̂i,j+1/2 = U [v̂adv
i,j+1/2 ]( v̂i,j+1/2,L , v̂i,j+1/2,R )1

1(14.42)(14.43)(14.44)(14.45)Now we can construct the full left and right predictions for the normal velocities oneach interface (Eqs. 14.28 and 14.29). This involves simply adding the transverse term
to the hat quantities and adding the pressure gradient.
  ûn+1/2 − ûn+1/2
∆t 1 adv11i,j−1/2
 − ∆t ( Gp)(x),n−1/2
 i,j+1/2
uin++1//22,j,L = ûin++1//22,j,L −v̂i,j−1/2 + v̂adv
i,j+1/2
i,j
2 2
∆y
2
(14.46)and v̂n+1/2 − v̂n+1/2
 
∆t 1 adv
i −1/2,j
n+1/2
n+1/2
 i+1/2,j − ∆t ( Gp)(y),n−1/2vi,jûi−1/2,j + ûadv
i +1/2,ji,j+1/2,L = v̂i,j+1/2,L − 22∆x2(14.47)(y),n−1/2( x ),n−1/2
Here ( Gp)i,j
and ( Gp)i,j
are difference-approximations to ∇ p in the x andy directions respectively. Note that they are lagged—these come from the projection
at the end of the previous timestep. See BCG for a discussion. A similar construction
is done for the right states at the interface.
Finally, we do a Riemann solve (again, using the Burger’s form of the Riemann problem) followed by upwinding to get the normal advective velocities. This is basicallythe R(., .) operation followed by U (., .). Together, it is:

1
1
1
1

uin++1//22,j,L
if uin++1//22,j,L > 0,
uin++1//22,j,L + uin++1//22,j,R > 0

 

1
1
n+1/2
n+1/2
1
if uin++1//22,j,L ≤ 0,
uin++1//22,j,R ≥ 0
uadv
i +1/2,j =  2 ui +1/2,j,L + ui +1/2,j,R1un+ /2otherwisei +1/2,j,R(14.48)and similar for vadv.
These
velocities
aresometimes
referred
to
as
the
MAC
velocii,j+1/2
ties.

Chapter 14. Incompressible Flow and Projection Methods

234

φi,j +1

j +1

j +1

adv

(Gφ)i,j +1/2

vi,j +1/2

φi +1,jj(Gφ)i,j−1/2

advvi,j−1/2j−1

φi,j−1i−1(DGφ)i,j(DUadv )i,j(Gφ)i +1/2,jφi,j(Gφ)i−1/2,jadv

ui +1/2,jadv

ui−1/2,jφi−1,j

j

j

−1

i +1

i

i

−1

i

i +1

Figure 14.3: The centerings of the various components that make up the MAC projection.

14.3.2

MAC projection

We could simply use these time-centered advective velocities to construct the fluxes
through the interfaces and update to the new time level. However BCH showed thatsuch a method is unstable for CFL > 0.5. The fix is to enforce the velocity constraint
on these advective velocities. This involves projecting the velocity field onto the spacethat is divergence free. This projection is usually called the MAC projection. Once theMAC-projected advective velocities are computed, we can reconstruct the interface
states using this divergence-free velocity field. Figure 14.3 shows the location of thevarious quantities that participate it the MAC projection.
The divergence of the MAC velocities is cell-centered and constructed as:( DU)i,j =

adv
uadv
i +1/2,j − ui −1/2,j

∆x

+

adv
vadv
i,j+1/2 − vi,j−1/2∆y(14.49)We define a cell-centered ϕ. Gϕ will then be edge-centered on a MAC grid, andLϕ = DGϕ is again cell-centered. Since L = DG, this makes the MAC projection an
exact projection.
We solve
Lϕ = DU(14.50)using multigrid V-cycles and then update the MAC velocities as:
ϕi+1,j − ϕi,j
∆x
ϕ
i,j
+
1 − ϕi,j= vadvi,j+1/2 −
∆y

adv
uadv
i +1/2,j = ui +1/2,j −(14.51)

vadv
i,j+1/2(14.52)

14.3—Cell-centered approximate projection solver

14.3.3235

Reconstruct interface states

Next we redo the construction of the interface states. This procedure is identicalto that above—construct the interface states û L,R , v̂ L,R on all edges, upwind basedon ûadv , v̂adv , and use these to construct the full states (including transverse terms).
Now however, we construct the interface states of u and v on both the x and yinterfaces (not just the normal component at each interface). Finally, instead of solving a Riemann problem to resolve the left and right states, we simply upwind using
1
1
the MAC-projected uadv and vadv . This results in the interface state uin++1//22,j , vin++1//22,j ,
n+ /2
n+ /2
ui,j
+1/2 , vi,j+1/2 .
1

1The only reason we need to do this step over, instead of using the interface statesthat we predicted previously is we want to ensure that they are consistent with the
MAC-projected advective velocities (and therefore, consistent with the constraint).

14.3.4

Provisional update

Once we have the time-centered interface states that are consistent with the MACprojected advective velocities, we can update the velocities to the new time by discretizing the advective terms (U · ∇U). We express the advective terms for u as(v),n+1/2(u),n+1/2. These have the form:
and those for v as Ai,jAi,j un+1 /2 − un+1 /2
1  adv
i + /2,ji − /2,jadv
ui−1/2,j + ui+1/2,j+2∆x un+11/2 − un+11/2
1  adv
i,j+ /2
i,j− /2advvi,j−1/2 + vi,j+1/2
2
∆y
1/2
n
+
 v 1 − vn+11/2
1  adv
i + /2,ji − /2,jadv
ui−1/2,j + ui+1/2,j+2∆x vn+11/2 − vn+11/2
1  adv
i,j+ /2
i,j− /2
adv
v 1 + vi,j+1/2
2 i,j− /2∆y1(u),n+1/2=
Ai,j(v),n+1/2

Ai,j

=

1

(14.53)(14.54)

The normal update for u, v would include the Gp term and appear as:⋆nui,j= ui,j− ∆tAi,j− ∆t( Gp)i,j( x ),n−1/2(14.55)⋆nvi,j= vi,j− ∆tAi,j− ∆t( Gp)i,j(y),n−1/2(14.56)(u),n+1/2(v),n+1/2

Note that at this point, we don’t have an updated p, so we use a lagged value fromthe previous step’s projection.
Alternately, we can note that for an exact projection, Gp, is the gradient of a scalar
and would be removed by the projection, so we can omit it in this update, giving an

Chapter 14. Incompressible Flow and Projection Methods

236
alternate provisional update:(u),n+1/2⋆⋆n= ui,j− ∆tAi,jui,j(14.57)⋆⋆nvi,j= vi,j− ∆tAi,j(14.58)(v),n+1/2

Following the notation in Martin, we distinguish between these with an ‘⋆’ vs. ‘⋆⋆’ * .

14.3.5

Approximate projection

This provisional velocity field does not yet obey the constraint. To enforce the constraint, we need to do a projection. Here is where we have the flexibility on whether
to include the Gpn−1/2 term. If we were doing an exact projection, then adding thegradient of a scalar would not change the divergence-free velocity field, so there
would be no need to add it.
BCH did an exact projection on a cell-centered grid. There, the divergence operator
is:vi,j+1 − vi,j−1
ui+1,j − ui−1,j+(14.59)( DU)i,j =2∆x2∆yThis gives a cell-centered DU. If we want ϕ cell-centered, then the gradient, Gϕ mustalso be cell centered so Lϕ = DGϕ is cell-centered. This means that we must have

( Gϕ)i,j

(x)

=

(y)

=

( Gϕ)i,jϕi+1,j − ϕi−1,j2∆xϕi,j+1 − ϕi,j−12∆y(14.60)(14.61)

The resulting Laplacian would then be a 5-point stencil that skips over the immediateneighbors:
ϕi,j+2 − 2ϕi,j + ϕi,j−2
ϕi+2,j − 2ϕi,j + ϕi−2,j+(14.62)( Lϕ)i,j =
2
4∆x
4∆y2
This decomposes the domain into 4 distinct grids that are only linked together at theboundaries. While an exact projection, this decoupling can be undesirable.
Approximate projections relax the idea that L = DG. In an exact projection, when
you apply the projection operator, P, in succession, the result is unchanged (P2 = P).
This is not the case for an approximate projection. As a result, exactly what form
you project matters. For an approximate projection, we can use the standard 5-pointstencil for the Laplacian,( Lϕ)i,j =ϕi+1,j − 2ϕi,j + ϕi−1,jϕi,j+1 − 2ϕi,j + ϕi,j−1
+
∆x2
∆y2

(14.63)* Note that these are identical to ABC [3] approximation projections (1) and (2) (a quick look at ABC
might suggest the opposite, but note that their definition of U⋆ already includes a − Gpn−1/2 term, so by
explicitly adding it back in, you are dealing with the case where U⋆ was updated without any Gpn−1/2
term, like the ‘⋆⋆’ case above.)14.3—Cell-centered approximate projection solver

237

together with the cell-centered divergence above (Eq. 14.59).
Rider [65] and Almgren, Bell, and Crutchfield (ABC) [3] explore various forms ofwhat to project when doing the approximate projection. For instance, do we include
the Gpn−1/2 term in the provisional velocity or not? Chorin noted that if viscosity is
being modeled, then it is necessary to include it here to get second-order accuracy.
Also, one can project the update to the velocity, (U⋆ − Un )/∆t instead of just the
new velocity, since Un should already be divergence free. Rider argues that projecting the update is not desirable with approximate projections, since any error in Un
being divergence-free is carried forward to the new Un+1 . One issue is that a cellcentered approximate projection cannot remove all sources of divergence (see Rider
and Martin’s PhD thesis).
When projecting the new velocity, we scale by ∆t to get a quantity that has dimensions of pressure. The procedure for the projection differs slightly depending onwhether we project U⋆ or U⋆⋆ :• case I: projecting U⋆ /∆t.
From the expression above, this looks like:
U⋆
Un
1
1
=
− A(u),n+ /2 − ( Gp)(x),n− /2∆t∆t(14.64)

Ideally, Un is already divergence free, and Gpn−1/2 is the gradient of a scalar,which will be removed, so the projection should pick out the divergence free
portion of A(u) . We solve:
Lϕ = D (U⋆ /∆t)(14.65)using multigrid V-cycles. We then find the new, divergence free velocity fieldas:Un+1 = U⋆ − ∆tGϕ
(14.66)Since we already included Gpn−1/2 in what we projected, Gϕ will be the correction,
1
1
Gϕ = Gpn+ /2 − Gpn− /2(14.67)or
Gpn+ /2 = Gpn− /2 + Gϕ1

1

(14.68)(see Martin 2.5 or ABC). We store this for the next timestep.
• case II: projecting U⋆⋆ /∆t.
From the expression above, this looks like:
U⋆⋆
Un
1
=
− A(u),n+ /2∆t∆t(14.69)

Chapter 14. Incompressible Flow and Projection Methods

238

There is no explicit Gpn−1/2 term. We solve:
Lϕ = D (U⋆⋆ /∆t)(14.70)using multigrid V-cycles. We then find the new, divergence free velocity fieldas:Un+1 = U⋆⋆ − ∆tGϕ
(14.71)Since there was no Gpn−1/2 in what we projected, pn+1/2 = ϕ, andGpn+ /2 = Gϕ1

(14.72)

We store this for the next timestep.
One pathology of this form of the projection is that ( DU)i,j does not actually makeuse of the velocity field in zone (i, j). This decoupling from the local zone can resultin a checkerboarding pattern in the projected velocity field.

14.4

Boundary conditions

For the advection portion of the algorithm, the boundary conditions on u and v are
implemented in the usual way, using ghost cells. For the projection,
For a periodic domain, the boundary conditions on ϕ are likewise periodic. At a solid
wall or inflow boundary, we already predicted the velocity that we want at the wall(in the advection step), and we do not want this value to change in the projection
step. Since the correction is:
U n +1 = U ⋆ − ∇ ϕ(14.73)we want ∇ϕ · n = 0.

At outflow boundaries, we do not want to introduce any shear as we go throughthe boundary. This means that we do not want any tangential acceleration. Setting
ϕ = 0 on the boundary enforces ∇ϕ · t = 0, where t is the unit vector tangential tothe boundary.
See ABS for a discussion of the boundary conditions.

14.5

Bootstrapping

At step 0, we do not have a value of Gp−1/2 . To get an initial value for Gp, we run
through the entire evolution algorithm starting with the initial data. At the end of astep, we reset u and v to the initial values and store the Gp at the end of this step as
Gp−1/2 .
It is also common to precede this initialization by first projecting the velocity field toensure it is divergence free. This way, we do not have to rely on the initial conditions
to always set a divergence free velocity field.

14.6—Test problems

239

14.6

Test problems

14.6.1

Convergence test

Minion [54] introduced a simple test problem with an analytic solution. The velocity
field is initialized as:u( x, y) = 1 − 2 cos(2πx ) sin(2πy)
v( x, y) = 1 + 2 sin(2πx ) cos(2πy)(14.74)(14.75)The exact solution at some time t is:u( x, y, t) = 1 − 2 cos(2π ( x − t)) sin(2π (y − t))v( x, y, t) = 1 + 2 sin(2π ( x − t)) cos(2π (y − t))(14.76)(14.77)

Minion also gives the pressure, but this is not needed for the solution. This is run on adoubly-periodic unit square domain. The main utility of this set of initial conditions
is that we can use the analytic solution to measure the convergence behavior of thealgorithm.

14.7

Extensions• Variable density incompressible: Bell & Marcus [14] describe how to extend thesemethods to variable density flows. This means that the density in the domain
may not be constant, but within a fluid element, the density does not change.
This can arise, for instance, in modeling the Rayleigh-Taylor instability.
The basic idea follows the method described above. Now the mass continuity
equation is also evolved:∂ρ+ ∇ · (ρU) = 0(14.78)∂t
The density is predicted to the interfaces follow the same procedure above andupwinded using the MAC velocities. For the projection, the decomposition is
written as:
1
U = Ud + ∇ϕ
(14.79)ρand the elliptic equation is now a variable-coefficient equation:
1∇ · ∇ϕ = ∇ · Uρ(14.80)• Viscosity: When viscosity is included in the system, our momentum equation
becomes:
U t + U · ∇ U + ∇ p = ϵ ∇2 U
(14.81)

Chapter 14. Incompressible Flow and Projection Methods

240

The solution process for this equation is largely the same. Following BCH, firstthe advective term is computed by predicting the velocities to the interfaces,
doing the MAC projection, and then forming An+1/2 . Now there is an explicit
viscosity term (at time-level n) present in the prediction, as a source term. The
provision velocity update is no longer a simple flux update, but instead requires
solving two decoupled diffusion-like equations (one for u and one for v). These
are differenced using Crank-Nicolson centering:u⋆ − un∆tv⋆ − vn∆tϵ1
1= − A(u),n+ /2 − ∇ p(x),n− /2 + ∇2 (un + u⋆ )2ϵ 2 n(v),n+1/2(y),n−1/2= −A− ∇p+ ∇ (v + v⋆ )2

(14.82)(14.83)This involves two separate multigrid solves. Once U⋆ is found, the final projection is done as usual.
• Low Mach number combustion: In low-Mach number combustion flows, the fluid
is allowed to respond to local heat release by expanding. The velocity constraint
is derived by differentiating the equation of state along particle paths, leading
to the appearance of a source term:∇·U = S(14.84)Here, S, incorporates the compressibility effects due to the heat release anddiffusion. This system is used when modeling burning fronts (flames). This
type of flow can be thought of as linking two incompressible states (the fueland the ash) by the expansion across the interface.
The solution technique largely follows that of the incompressible flow. One
caveat, because the constraint now has a local heat source, S, doing the cellcentered divergence described above leads to a decoupling of DU from thelocal source, since the stencil of DU does not include the zone upon which it iscentered.
This system is described in detail in [13, 29, 61].
• Stratified flows: When the background is stratified, a different velocity constraint
can arise, capturing the expansion of the fluid element due to the pressurechange with altitude. For example, with an ideal gas, the equation of state canbe recast as:∇ · ( p1/γ
(14.85)0 ) =0where p0 (z) is the pressure as a function of height, representing the hydrostaticbackground, and γ is the ratio of specific heats. For a general equation of(state, p0 1/γ) is replaced with something more complicated (see [4–6] for thedevelopment of a low Mach hydrodynamics method for stratified astrophysicalflows).

14.7—Extensions

241• Nodal projection: instead of discretizing the final projection using a cell-centeredϕ, ABS use a node-centered ϕ. While this is still an approximate projection, thisdiscretization couples in the zone we are centered on, and is said to be able to
do a better job removing pathological divergent velocity fields that cell-centeredprojections stumble on.

Chapter

15

Low Mach Number Methods
Incompressible flow represents the zero-Mach number limit of fluid flow—no compressibility effects are modeled. We can extend the ideas of incompressibe flow toallow us to model some compressibility effects, giving rise to low Mach number
methods.

15.1

Low Mach divergence constraints

The key idea in solvers for low Mach number flows is that, as a fluid element advects, its pressure remains the same as the background state. For an atmosphere,
this background state is a hydrostatic profile. For a smallscale combustion flow, thisbackground state is a spatially constant pressure (and constant-in-time if the domain
is open). We’ll denote this background pressure as p0 (r, t), where r is a radial coordinate.
Previously, we derived the pressure evolution with reactive sources (see Eq. 12.24)
by following the evolution of pressure as a fluid element moves (e.g., the Lagrangianderivative). For the low Mach flows, we want to see the evolution p0 in the fluid
element, which is expressed as:∂p0+ U · ∇ p0 + Γ1 p0 ∇ · U = Γ1 p0 σHnuc∂t(15.1)

We can rewrite this as a constraint on the velocity field by solving for ∇ · U:

∇·U+

1 Dp0
= σHnuc ≡ S
Γ1 p0 Dtwithσ=git version: 64c838dee1a8 . . .

∂p0 /∂T |ρρc p ∂p0 /∂ρ| T
243(15.2)(15.3)

Chapter 15. Low Mach Number Methods

244This is the general constraint equation for low Mach flow. Note that the only approximation we made is p → p0 . This form of the constraint, for a general equation ofstate, was originally derived in [5].
Combustion limit
A useful limit is smallscale combustion. In an open domain, we can take p0 as
constant, so Dp0 /Dt = 0, and we are left with∇·U = S(15.4)

This looks like the constraint for incompressible flow, but with a source to the divergence. This source captures the compressible effects due to local heat release—asa fluid parcel moves, the only changes to its density will come through local heatrelease. Methods for this type of constraint are discussed in [13, 29, 61].
Atmospheric case
Another interesting case is that of an atmosphere. If we consider an ideal gas, then
Γ1 = γ = constant. A second appromation we take is that p0 = p0 (r )—i.e., no timedependence to the atmosphere. Finally, we’ll consider the case with no local heatsources (S = 0). Then we have∇·U+
which is equivalent to1
U · ∇ p0 = 0
γp0(15.5)


∇ · p1/γU=00(15.6)∇ · ( ρ0 U ) = 0(15.7)

This constraint captures the changes in compressibilty due to the background stratification of an atmosphere. This form was originally derived for atmospheric flows
by [32] and generalized to stellar flows in [5]. If the structure of the atmosphere isisentropic, then we know that d log p0 = γd log ρ0 , where we use ρ0 to represent thedensity corresponding to p0 , and we can write this constraint as:This is the traditional anelastic constraint.
Extensions involving external heating sources or reactions are discussed in [4, 6], anddealing with the non-constant Γ1 is discussed in [5, 43]. The time-dependence of the
background atmosphere is explored in [6] for plane-parallel atmospheres, following
the ideas from [1], and in [57] for spherical, self-gravitating bodies.

15.2—Multigrid for Variable-Density Flows

15.2

245

Multigrid for Variable-Density FlowsThe solution methodology for these low Mach number systems follows that of theincompressible flow, but with two additions. First, we need to incorporate a density (mass continuity) evolution equation—this will follow the same techniques wealready saw for advection, as we’ll see later. Next, we need to be able to enforce moregeneral forms of the divergence constraint, which as we’ll see in a moment, require
us to solve a variable-coefficient elliptic equation. Our multigrid technique will need
to be suitably modified.
We now need to solve an elliptic equation of the form:∇ · (η ∇ϕ) = f(15.8)

If we denote the discrete divergence and gradient operators as D and G, then ouroperator will be Lη ≡ DηG. If we wish to use a cell-centered discretization for ϕ,then using a standard centered-difference for D and G will result in a stencil thatreaches two zones on either side of the current zone. This can lead to an odd-evendecoupling.
Instead, we again use an approximate projection. We discretize the variable-coefficientLaplacian as:( Lη ϕ)i,j =ηi+1/2,j (ϕi+1,j − ϕi,j ) − ηi−1/2,j (ϕi,j − ϕi−1,j )+∆x2
ηi,j+1/2 (ϕi,j+1 − ϕi,j ) − ηi,j−1/2 (ϕi,j − ϕi,j−1 )∆y2(15.9)

We can define the interface values of η as the averages of the cell-centered values,e.g.,1
ηi,j+1/2 = (ηi,j + ηi,j+1 )(15.10)2
Our elliptic equation is then
( Lη ϕ)i,j = f i,j(15.11)
The relaxation method for this operator again relies on isolating ϕi,j , yielding:
ϕi,j =

η̃i+1/2,j ϕi+1,j + η̃i−1/2,j ϕi−1,j + η̃i,j+1/2 ϕi,j+1 + η̃i,j−1/2 ϕi,j−1 − f i,jη̃i+1/2,j + η̃i−1/2,j + η̃i,j+1/2 + η̃i,j−1/2(15.12)

with the shorthand that η̃i±1/2,j = ηi±1/2,j /∆x2 and η̃i,j±1/2 = ηi,j±1/2 /∆y2 .
To put this into our multigrid framework, there are three changes we need to make:• The smoothing function needs to implement the more general smoothing described by Eq. 15.12.

Chapter 15. Low Mach Number Methods

246• The residual function needs to compute ( Lη ϕ)i,j according to Eq. 15.9, and thenri,j = f i,j − ( Lη ϕ)i,j .
• The coefficients, η should be averaged to the edges on the fine grid and thenrestricted down the multigrid hierarchy as edge-based quantities.

15.2.1

Test problem

Periodic
To test the solver, we need to devise a problem with a known analytic solution. The
easiest way to do this is to pick an η ( x ) and ϕ and then do the divergence andgradients to find the required righthand side, f . We’ll use periodic BCs, and for ourequation ∇ · (η ∇ϕ) = f , the following provide a well-posed test problem:η = 2 + cos(2πx ) cos(2πy)(15.13)2

f = −16.0π [cos(2πx ) cos(2πy) + 1] sin(2πx ) sin(2πy)
with the solution:
ϕtrue = sin(2πx ) sin(2πy)
There is an important caveat when dealing with a purely-periodic problem. Since
there is no boundary values to “anchor” the solution, it is free to float. Solving theelliptic problem will give use the correct ∇ϕ, but the average of ϕ over the domain is
unconstrained. For our algorithms, it is ∇ϕ that matters (that is the forcing term thatenters into the momentum equation).
When for checking convergence, we want to compare to the exact solution. We
therefore normalize ϕ by subtracting off its average value before computing the normof the error with respect to the exact solution:true
ϵ = ∥ϕi,j − ϕ̄ − ϕi,j
∥ ,

where
ϕ̄ =

1
ϕi,j
Nx Ny ∑
i,j

(15.14)(15.15)

As discussed in § 9.6, this can arise if the discrete form the righthand side, f i,j does
not sum exactly to zero. Figure 15.1 shows the solution to this problem with a 5122
grid. and the convergence of the solver described here is shown in Figure 15.2.
Dirichlet
We can run the same problem with Dirichlet boundary conditions on ϕ, and weare free to pick different boundary conditions for η, since it represents a different
physical quantity. Since we only have homogeneous Dirichlet or Neumann BCs implemented, we’ll run with Neumann BCs on η.

15.3—Atmospheric flows

247

nx = 512

1.0

1.00

error

1.0

−0.0000025

0.75
0.8

0.50
0.25

0.6

0.6

−0.0000100−0.0000075−0.0000125

0.4

−0.25
−0.50

0.2

−0.0000050

y

y

0.00
0.4

0.8

−0.0000150−0.0000175

0.2−0.0000200

−0.75
0.0
0.0

0.2

0.4

x

0.6

0.8

1.0

0.0
0.0

−1.00

−0.0000225
0.2

0.4

x

0.6

0.8

1.0

Figure 15.1: Solution and error to the variable-coefficient Poisson problem defined in
Eq. 15.13. This test can be run with pyro multigrid/test_mg_vc_periodic.py.

15.3

Atmospheric flows

15.3.1Equation Set

For atmospheric flows, we define a one-dimensional base state that is in hydrostatic
equilibrium. In general, this base state can be time-dependent, expanding in response to heating in the atmosphere (see e.g. [1, 6]. Here we’ll consider only atime-independent state.
We’ll follow the procedure defined in [57]: we define ρ0 as the lateral average of ρ:
1
ρi,j
Nx ∑
i

ρ0 j =(15.16)and then we define the base state pressure, p0 , by integrating the equation of hydrostatic equilibrium, dp0 /dy = ρg, as:∆y( ρ 0 j + ρ 0 j +1 ) g
2(15.17)1
pinitial
i,jlo
Nx ∑
i

(15.18)p 0 j +1 = p 0 j +with an initial condition of
p0 jlo =The compressible momentum equation (written in terms of velocity is):ρ∂U
+ ρU · ∇U + ∇ p = ρg∂t(15.19)Subtracting off the base state, and defining the perturbational pressure (sometimes
called the dynamic pressure) as p′ = p − p0 , and perturbational density as ρ′ = ρ − ρ0 ,we have:∂Uρ+ ρU · ∇U + ∇ p′ = ρ′ g
(15.20)∂tChapter 15. Low Mach Number Methods

248

10-2

error

10-3

10-4

10-5

10-6 1
10

102
N

103

Figure 15.2:
Convergence of the variable-coefficient multigrid solver forthe test problem defined in Eq. 15.13.
This test can be run with pyromultigrid/test_mg_vc_periodic.py.

or

∂U
1
ρ′
+ U · ∇U + ∇ p′ = g∂tρρ(15.21)

Several authors [43, 83] explored the idea of energy conservation in a low Mach
number system and found that an additional term (which can look like a buoyancy)
is needed in the low Mach number formulation, yielding:β0∂U+ U · ∇U + ∇
∂t
ρ



p′
β0



=

ρ′
g
ρ

(15.22)Completing the system are the continuity equation,∂ρ+ ∇ · (ρU) = 0∂t(15.23)∇ · ( β0 U) = 0(15.24)and the constraint,
1/γwith β 0 = p0 .

15.3—Atmospheric flows

15.3.2

249

Solution Procedure

The general solution procedure is for a single step is:
I. Predict U to the interfaces
II. Enforce the divergence constraint on the interface U’s (the MAC projection) to get
Uadv .
Decomposing the velocity field as
U⋆ = Ud +β0∇ϕρ(15.25)as suggested from the form of the momentum equation, our Poisson equation
can be defined by multiplying by β 0 and taking the divergence, and using∇ · ( β 0 Ud ) = 0, giving
β2∇ · 0 ∇ϕ = ∇ · ( β 0 U⋆ )(15.26)
ρNote that when written like this, ϕ has units of p′ /β 0 .
For the MAC projection, we have edge-centered velocities (in their respective
coordinate direction). We define an edge-centered β 0 as
β 0 j+1/2 =1( β 0 j + β 0 j +1 )2

(15.27)(note that, since β 0 is one-dimensional, we only average in the vertical direction). The divergence term is then:[∇ · ( β 0 U)]adv
i,j = β 0 j

adv
uadv
i +1/2,j − ui −1/2,j

∆x

+

adv
β 0 j+1/2 vadv
i,j+1/2 − β 0 j−1/2 vi,j−1/2∆y(15.28)

We define the coefficient, η, in the Poisson equation as:
ηi,j =

β 0 2jρi,j(15.29)and bring it to edges simply through averaging. Multigrid is used to solve for
ϕi,j .
We then solve( Lη ϕ)i,j = [∇ · ( β 0 U)]adv
i,j(15.30)Once we solve for ϕ, we correct the velocity as:
Unew = U⋆ −

β0
∇ϕ
ρ

(15.31)

Chapter 15. Low Mach Number Methods

250

Since the MAC velocities are edge-centered, our correction appears as: 
ϕi+1,j − ϕi,jβ0
adv
(15.32)uadv=
u−i +1/2,j
i +1/2,jρ i+1/2,j∆x
 
ϕi,j+1 − ϕi,j
β0
adv
adv
vi,j+1/2 = vi,j+1/2 −(15.33)
ρ i,j+1/2∆yIII. Predict ρ to the interfaces
We need to solve the continuity equation. We use the same techniques thatwere used for advection. Our equation is:ρt + (ρu) x + (ρv)y = 0
The x-interface left state would be:∆x ∂ρ ∆t ∂ρ
1nρin++1//22,j,L = ρi,j
+
+
+...
2 ∂x
2 ∂t

∆x ∂ρ ∆t n= ρi,j++−(ρu) x − (ρv)y i,j
2 ∂x
2



∆x
∆t
∂ρ ∆t
∆t 
n
= ρi,j+1−ui,j− [ρu x ]i,j −(ρv)y i,j
2
∆x
∂x
2
2
|
{z
}

(15.34)(15.35)ρ̂in++1//22,j,L
1

A similar construction would yield the right state at that interface, and they-interface states.
Since we already have the MAC-projected advected velocities at this point, we
can use them in the construction of the interface states and the upwinding. As
before, we split this into a normal part (the ρ̂ term) and “transverse” part (which
here includes the non-advective part of the divergence). We first construct thenormal parts as1∆t adv(x)1nρ̂in++1//22,j,L = ρi,j+1−
ui+1/2,j ∆ρi,j(15.36)2∆x
and then solve the Riemann problem (upwinding) for these:( n+1/2
ρ̂i+1/2,j,L uadv
n+1/2
n+1/2
n+1/2
i +1/2,j > 0adv
ρ̂i+1/2,j = U [ui+1/2,j ](ρ̂i+1/2,j,L , ρ̂i+1/2,j,R ) =n+1/2
ρ̂i+1/2,j,R uadv
i +1/2,j < 0(15.37)The same procedure is done for the y-interfaces.
The full states are then constructed using these “hat” states. For example,
ρin++1//22,j,L = ρ̂in++1//22,j,L −
1

1

−

adv
adv
∆t ui+1/2,j − ui−1/2,j
ρi,j
2
∆x
n+1/2 adv
n+1/2 adv∆t ρ̂i,j+1/2 vi,j+1/2 − ρ̂i,j−1/2 vi,j−1/22∆y(15.38)

15.3—Atmospheric flows

251

Once the new states on both the x- and y-interfaces are constructed, we again
upwind to find the final ρ state on each interface:( n+1/2
ρi+1/2,j,L uadv
1
1
1
n+ /2
n+ /2
i +1/2,j > 0
ρin++1//22,j = U [uadv
](
ρ
,
ρ
)
=
(15.39)1
n+1/2
i + /2,j
i +1/2,j,L i +1/2,j,R
adv
ρi+1/2,j,R ui+1/2,j < 0
IV. Do the conservative update of ρOnce the interface states are found, we can conservatively-difference the continuity equation:∆t  n+1/2 adv
1
ρi+1/2,j ui+1/2,j − ρin−+1//22,j uadv
1
i − /2,j∆x∆t
n+1/2 adv
n+1/2 adv
ρi,j
v
−
ρ
v
−
+1/2 i,j+1/2
i,j−1/2 i,j−1/2
∆y

n +1
n
ρi,j
= ρi,j−(15.40)V. Update Un to Un+1,⋆
VI. Enforce the divergence constraint on Un+1
For the final projection, we have cell-centered velocties. We define the divergence term as:⋆⋆ui⋆+1,j − ui⋆−1,j
β 0 j+1 vi,j
+1 − β 0 j−1 vi,j−1⋆+[∇ · ( β 0 U)]i,j = β 0 j2∆x2∆y15.3.3(15.41)Timestep constraint

In addition to the advective timestep constraint, an additional constraint is needed if
the velocity field is initialially zero. In [4], a constraint based on the buoyancy forcing
is used. First, we compute the maxiumum buoyancy acceleration,
 ′ 
ρg(15.42)
amax = maxρand then∆tforce =



2∆x
amax

1/2

(15.43)This is based simply on ∆x = (1/2) at2 —the time it takes for the buoyant force toaccelerate a fluid element across a zone width.

15.3.4

BootstrappingFirst we need to make sure that the initial velocity field satisfies our constraint
Next we need to find ∇ p′n−1/2

for the first step.

Chapter 15. Low Mach Number Methods

252

15.4

Combustion

Taking p = p0 + p′ , with p0 = constant, the system becomes:

15.4.1

Species

15.4.2

Constraint∂ρ+ ∇ · (ρU) = 0∂t(15.44)∂ρU+ ∇ · (ρUU) + ∇ p′ = 0∂t∇·U = S(15.45)(15.46)

Our constraint equation is ∇ · U = S. Decomposing the velocity field as
1
U⋆ = Ud + ∇ϕρ(15.47)

our Poisson equation can be defined by taking the divergence, and using ∇ · Ud = S,
giving1∇ · ∇ϕ = ∇ · U⋆ − S(15.48)ρ

15.4.3

Solution Procedure

The general solution procedure is for a single step is:• React for ∆t/2
• Do the hydrodynamcis for ∆t– Predict U to the interfaces– Enforce the divergence constraint on the interface U’s (the MAC projection) to get Uadv .
– Predict ρ to the interfaces– Do the conservative update of ρ
– Update Un to Un+1
– Enforce the divergence constraint on Un+1
• React for ∆t/2

Part VI

Code Descriptions

Appendix

A

Using hydro_examples
A.1

Introduction

The hydro_examples codes are simple 1-d solvers written in python that illustrate
many of the ideas in these nodes. They are used for making many of the figures
found throughout (wherever the “Ï hydro_examples: ” note is found). Most are
written for python 3.x.

A.2

Getting hydro_examples

The hydro_examples codes are hosted on github:https://github.com/zingale/hydro_examples
There are a few ways to get them. The simplest way is to just clone from github on
the commandline:
git clone https://github.com/zingale/hydro_examples
This will create a local git repo on your machine with all of the code. You canthen run the scripts, “as is” without needing to go to github anymore. Periodically,
there may be updates to the scripts, which you can obtain by issuing “git pull”
in the hydro_examples/ directory. Note that if you have made any local changes tothe scripts, git may complain. The process of merging changes is descibed online
in various places, e.g. “Resolving a merge conflict from the command line” fromgithub.
Alternately, you can use github’s web interface to fork it. Logon to github (or createan account) and click on the “Fork” icon on the hydro_examples page. You can theninteract with your version of the repo as needed. This method will allow you to
git version: 64c838dee1a8 . . .

255

Chapter A. Using hydro_examples

256

push changes back to github, and, if you think they should be included in the mainhydro_examples repo, issue a pull-request.

A.3 hydro_examples codes
The codes in hydro_examples are organized into directories named after the chaptersin these notes. Each directory is self-contained. The following scripts are available:• advection/– advection.py: a 1-d second-order linear advection solver with a wide
range of limiters.
– fdadvect_implicit.py: a 1-d first-order implicit finite-difference advection
solver using periodic boundary conditions.
– fdadvect.py: a 1-d first-order explicit finite-difference linear advection
solver using upwinded differencing.
• burgers/– burgers.py: a 1-d second-order solver for the inviscid Burgers’ equation,with initial conditions corresponding to a shock and a rarefaction.
• compressible/– cfl.py: a simple brute force script used to find the stability limit of amultidimensional advection discretization.
– euler.ipynb: an Jupyter notebook using SymPy that derives the eigensystem for the primitive-variable form of the Euler equations.
– euler-generaleos.ipynb: an Jupyter notebook using SymPy that derives
the eigensystem for the primitive-variable form of various forms of Euler
equations with a general EOS (with either (ρe) or γe augmenting the system) and for gray radiation hydrodynamics. Additionally, this notebook
computes the full form of the interface states.
– riemann.py: the main Riemann class for gamma-law Euler equations. The
RiemannProblem class has methods to find the star state, plot the Hugoniot
curves, and sample the solution.
– riemann-2shock.py: draw the Hugoniot curves in the u-p plane for a pairof states that comprise a Riemann problem, under the 2-shock approximation.
– riemann-phase.py: draw the Hugoniot curves in the u-p plane for a pairof states that comprise a Riemann problem.

A.3—hydro_examples codes257– riemann-sod.py: solve the Riemann problem for the Sod initial conditions
and plot the exact solution.
• diffusion/– diff_converge.py: make a convergence plot (error vs. resolution) of different explicit and implicit diffusion methods.
– diffusion_explicit.py: solve the constant-diffusivity diffusion equation
explicitly. The method is first-order accurate in time, but second-orderin space. A Gaussian profile is diffused—the analytic solution is also a
Gaussian.
– diffusion_fo_implicit.py: solve the constant-diffusivity diffusion equation implicitly. Backwards-difference time-discretization is used, resulting
in a first-order-in-time method. Spatial discretization is second order. A
Gaussian profile is diffused.
– diffusion_implicit.py: solve the constant-diffusivity diffusion equation
implicitly. Crank-Nicolson time-discretization is used, resulting in a secondorder method. A Gaussian profile is diffused.
• elliptic/– poisson_fft.py: an FFT solver for a 2-d Poisson problem with periodic
boundaries.
• finite-volume/– conservative-interpolation.ipynb: an Jupyter notebook using SymPy
that derives conservative interpolants.
• incompressible/– project.py: a simple example of using a projection to recover a divergencefree velocity field.
• multigrid/– mg_converge.py: a convergence test of the multigrid solver. A Poissonproblem is solved at various resolutions and compared to the exact solution. This demonstrates second-order accuracy.
– mg_test.py: a simple driver for the multigrid solver. This sets up andsolves a Poisson problem and plots the behavior of the solution as a function of V-cycle number.
– multigrid.py: a multigrid class for cell-centered data. This implements
pure V-cycles. A square domain with 2 N zones (N a positive integer) is
required.

Chapter A. Using hydro_examples

258– patch1d.py: a class for 1-d cell-centered data that lives on a grid. This
manages the data, handles boundary conditions, and provides routines
for prolongation and restriction to other grids.
– smooth.py: solve a Poisson equation with smoothing only (but we still use
the interface through the multigrid object).
• multiphysics/– burgersvisc.py: solve the viscous Burgers equation. The advective terms
are treated explicitly with a second-order accurate method. The diffusive
term is solved using an implicit Crank-Nicolson discretization. The overall
coupling is second-order accurate.
– diffusion-reaction.py: solve a diffusion-reaction equation that propagates a diffusive reacting front (flame). A simple reaction term is modeled. The diffusion is solved using a second-order Crank-Nicolson discretization. The reactions are evolved using the VODE ODE solver (via
SciPy). The two processes are coupled together using Strang-splitting to
be second-order accurate in time.

Appendix

B

Using pyro
B.1

Introduction

pyro is a simple two-dimensional code that implements the core solvers described inthese notes. It is written primarily in python, with some kernels in Fortran. Clarityof the methods is emphasized over performance.

B.2

Getting pyro

pyro can be downloaded from its github repository, https://github.com/python-hydro/
pyro2 as:git clone https://github.com/python-hydro/pyro2
pyro uses the h5py, matplotlib, and numpy libraries. Several routines are written
in Fortran and need to be compiled. The script mk.sh will build the packages. Thisrequires that f2py is installed. By default, pyro will use python 3. The following
sequence will setup pyro:• Set the PYRO_HOME environment variable to point to the main pyro2/ directory,e.g.,export PYRO_HOME=/path/to/pyro2• Set the PYTHONPATH environment variable to point to the main pyro2/ directory,e.g.,export PYTHONPATH="$PYTHONPATH:$PYRO_HOME"

git version: 64c838dee1a8 . . .

259

Chapter B. Using pyro260

• Build the Fortran source using the mk.sh script. In the pyro2/ directory, simply
do./mk.shB.3 pyro solvers
pyro offers the following 2-d solvers:• advection: an unsplit, second-order method for linear advection, following theideas from Chapter 4.
• advection_rk: an alternate advection algorithm using method-of-lines time integration, again following the ideas from Chapter 4.
• compressible: an unsplit, second-order compressible hydrodynamics solver using the piecewise linear reconstruction discussed in Chapter 8.
• compressible_rk: an alternate compressible algorithm using method-of-lines time
integration, using the piecewise linear reconstruction discussed in Chapter 8.
• diffusion: a second-order implicit diffusion solver, based on the ideas from
Chapter 10.
• incompressible: a second-order incompressible hydrodynamics solver using acell-centered approximate projection, as discussed in Chapter 14.
• lm_atm: a low-Mach number hydrodynamics solver for atmospheric flows, as
discussed in S 15.3
• multigrid: a multigrid solver for constant-coefficient Helmholtz elliptic equations. This follows the ideas from Chapter 9, and is used by the diffusion andincompressible solvers.

B.4 pyro’s structure
The structure of the code and descriptions of the various runtime parameters isfound on the pyro webpage, http://python-hydro.github.io/pyro2/, and describedin [86]. Here we provide a summary.
The grid structure is managed by the patch.Grid2d class. Data is that lives on thegrid is contained in a patch.CellCenterData2d object. Methods are available to provide access to the data and fill the ghost cells. When accessing the data on thegrid, a array_indexer.ArrayIndexer object is returned. This is a subclass of the normal NumPy ndarray that provides additional methods that are useful for interactingwith finite-volume data. In particular, for an object a, you can do a.ip(1) to mimic

B.5—Running pyro261

ai+1,j . The Jupyter notebook mesh-examples.ipynb walks through these classes todemonstrate how they work.
Each pyro solver is its own python module. All but the multigrid solver represent
time-dependent problems. Each of these provide a Simulation class that provides
the routines necessary to initialize the solver, determine the timestep, and evolve thesolution in time. Each solver has one or more sets of initial conditions defined in thesolver’s problems/ directory.
All time-dependent problems are run through the pyro.py script. The general formis:./pyro.py solver problem inputs
where solver is one of {advection, advection_rk, compressible, compressible_rk,
diffusion, incompressible, lm_atm}, problem is one of the problems defined in thesolver’s problems/ directory, and inputs is the name of an input file that defines thevalues of runtime parameter.
The possible runtime parameters and their defaults are defined in the _defaults files
in the main directory and each solver and problem directory. Note that the inputs
file need not be in the pyro2/ directory. The solver’s problems/ directory will also bechecked.

B.5

Running pyro

A simple Gaussian advection simulation is provided by the advection smooth problem. This is run as:./pyro.py advection smooth inputs.smooth
As this is run, the solution will be visualized at each step, showing the progressionof the simulation.
A list of the problems available for each solver is given in Table B.1. For the multigrid
solver, there are scripts available in the multigrid/ directory that illustrate its use.

B.6

Output and visualization

pyro uses HDF5 for I/O* The simple script plot.py in the pyro/ directory can readin the data and plot the output. It will determine which solver was used for the run
and do the visualization using that solver’s methods.
* Previously a simple python pickle was done, but this was not very portable.

Chapter B. Using pyro

262

B.7

Testing

The script test.py provides an interface to pyro’s unit and regression tests. Simply
running it was ./test.py will executate all of the tests. The unit tests are enabledthrough the pytest framework.

advect a smooth Gaussian profile
advect a discontinuous tophat profile

diffuse an initial Gaussian profile
A simple incompressible problem with known analytic solution.
a doubly-periodic shear layersmoothtophatgaussianconvergeshear§ 5.4.2

§ 5.3

Ch. 8

Ch. 8

§ 10.4

Ch. 14

Ch. 15.3

advection

advection_rk

compressible

compressible_rk

diffusion

incompressible

lm_atma buoyant bubble in a stratified atmosphere
setup a shear layer to drive Kelvin-Helmholtz instabilities
2-d Riemann problem based on [68]a simple Rayleigh-Taylor instability
the classic Sedov-Taylor blast wave
the Sod shock tube problem

bubble
kh
quad
rt
sedov
sod

a buoyant bubble in a stratified atmosphere

Table B.1: pyro solvers and their distributed problems. The relevant section in these notes that describes the implementation is also given.

bubblesame as compressible

a Gaussian profile in the density field advected diagonally(in constant pressure background)advectsame as advection

problem description

problem

sectionsolver

B.7—Testing
263

Appendix

C

Using hydro1d
C.1

Introductionhydro1d is a one-dimensional compressible hydrodynamics code written in modern
Fortran. In particular, it implements the piecewise parabolic method described in§ 8.2.3, in both Cartesian and spherical geometries. It assumes a gamma-law equationof state and supports gravity.

C.2

Getting hydro1dhydro1d can be downloaded from its github repository, https://github.com/zingale/hydro1d as:
git clone https://github.com/zingale/hydro1dSome details on the code can be found on its webpage: http://zingale.github.io/hydro1d/ . As with the other codes detailed here, if you wish to contribute, fix bugs,
etc., you can create issues or pull requests through the code’s github page.

C.3 hydro1d’s structure
There a few major data structures in hydro1d, defined in the grid.f90 file:• grid_t : this holds the grid information, with fields for the low and high indicies of the valid domain, and coordinate information (including interface areasand volumes, to support spherical geometry).
• gridvar_t : data that lives on a grid. This holds both a data array and thegrid_t that it is defined on.
git version: 64c838dee1a8 . . .

265

Chapter C. Using hydro1d266• gridedgevar_t : like gridvar_t, but for data defined at the interfaces between
zones.
The integer keys defined in the variables_module allow you to index the difference
state fields in the data arrays of the grid variables.

C.4

Running hydro1d

Each problem is in it’s own directory, and the code is built and run there. For example, to run the Sod shock tube problem, do:
cd hydro1d/sod
make./hydro1d inputs-sod-xp
As the code is built, object files and modules will be output into the _build subdirectory. make realclean will clean up the objects. Things are setup for gfortranby default—you will need to edit the Ghydro.mak with different options for different
compilers. Some bits of Fortran 2003 and 2008 are used, so an up-to-date compiler isneeded.
A number of runtime options can be set—these are listed in params.f90 and probparams.f90(the latter is problem-specific parameters).

C.5

Problem setups

The following problem setups are provided:• advect : a simple advection test where a density profile is advected throughperiodic boundaries, in a uniform pressure medium (to suppress dynamics)• hse : a simple 1-d atmosphere in hydrostatic equilibrium. This test works to
see if the atmosphere stays in HSE.
• sedov : a 1-d spherical Sedov explosion.
• sod : a shock tube setup for testing against exact Riemann solvers.

Bibliography[1] A. Almgren. A new look at the pseudo-incompressible solution to Lamb’s problem of hydrostatic adjustment. J Atmos Sci, 57:995–998, April 2000. No citations.
[2] A. S. Almgren, V. E. Beckner, J. B. Bell, M. S. Day, L. H. Howell, C. C. Joggerst,
M. J. Lijewski, A. Nonaka, M. Singer, and M. Zingale. CASTRO: A New Compressible Astrophysical Solver. I. Hydrodynamics and Self-gravity. Astrophys J,
715:1221–1238, June 2010. No citations.
[3] A. S. Almgren, J. B. Bell, and W. Y. Crutchfield. Approximate projection methods: Part I. Inviscid analysis. SIAM J Sci Comput, 22(4):1139–59, 2000. No citations.
[4] A. S. Almgren, J. B. Bell, A. Nonaka, and M. Zingale. Low Mach Number
Modeling of Type Ia Supernovae. III. Reactions. Astrophys J, 684:449–470, 2008.
No citations.
[5] A. S. Almgren, J. B. Bell, C. A. Rendleman, and M. Zingale. Low Mach Number
Modeling of Type Ia Supernovae. I. Hydrodynamics. Astrophys J, 637:922–936,
February 2006. No citations.
[6] A. S. Almgren, J. B. Bell, C. A. Rendleman, and M. Zingale. Low Mach Number
Modeling of Type Ia Supernovae. II. Energy Evolution. Astrophys J, 649:927–938,
October 2006. No citations.
[7] A. S. Almgren, J. B. Bell, and W. G. Szymczak. A numerical method for theincompressible Navier-Stokes equations based on an approximate projection.
SIAM J Sci Comput, 17(2):358–369, March 1996. No citations.
[8] A. Aspden, N. Nikiforakis, S. Dalziel, and J. B. Bell. Analysis of implicit
LES methods. Communications in Applied Mathematics and Computational Science,3(1):103–126, 2008. No citations.
git version: 64c838dee1a8 . . .

267

268

BIBLIOGRAPHY[9] J. B. Bell, P. Colella, and H. M. Glaz. A Second Order Projection Method for the
Incompressible Navier-Stokes Equations. J Comput Phys, 85:257, December 1989.
No citations.
[10] J. B. Bell, P. Colella, and L. H. Howell. An efficient second-order projection
method for viscous incompressible flow. In Proceedings of the Tenth AIAA Computational Fluid Dynamics Conference, pages 360–367. AIAA, June 1991. see also:
https://seesar.lbl.gov/anag/publications/colella/A_2_10.pdf. No citations.
[11] J. B. Bell, C. N. Dawson, and G. R. Shubin. An unsplit, higher order Godunov
method for scalar conservation l aws in multiple dimensions. J Comput Phys,
74:1–24, 1988. No citations.
[12] J. B. Bell, M. S. Day, C. A. Rendleman, S. E. Woosley, and M. Zingale. Direct
Numerical Simulations of Type Ia Supernovae Flames. II. The Rayleigh-Taylor
Instability. Astrophys J, 608:883–906, June 2004. No citations.
[13] J. B. Bell, M. S. Day, C. A. Rendleman, S. E. Woosley, and M. A. Zingale. Adaptive
low Mach number simulations of nuclear flame microphysics. J Comput Phys,
195(2):677–694, 2004. No citations.
[14] J. B. Bell and D. L. Marcus. A second-order projection method for variabledensity flows. J Comput Phys, 101(2):334 – 348, 1992. No citations.
[15] M. J. Berger and P. Colella. Local adaptive mesh refinement for shock hydrodynamics. J Comput Phys, 82(1):64–84, May 1989. No citations.
[16] G. Boffetta and R. E. Ecke. Two-Dimensional Turbulence. Annual Review of Fluid
Mechanics, 44:427–451, January 2012. No citations.
[17] W. L. Briggs, V-E. Henson, and S. F. McCormick. A Mutigrid Tutorial, 2nd Ed.
SIAM, 2000. No citations.
[18] P. N. Brown, G. D. Byrne, and A. C. Hindmarsh. VODE: A variable coefficientode solver. SIAM J. Sci. Stat. Comput., 10:1038–1051, 1989. No citations.
[19] G. L. Bryan, M. L. Norman, J. M. Stone, R. Cen, and J. P. Ostriker. A piecewise
parabolic method for cosmological hydrodynamics. Computer Physics Communications, 89:149–168, August 1995. No citations.
[20] G. D. Byrne and A. C. Hindmarsh. Stiff ODE Solvers: A Review of Current andComing Attractions. UCRL-94297 Preprint, 1986. No citations.
[21] A. J. Chorin. Numerical solution of the Navier-Stokes equations. Math. Comp.,
22:745–762, 1968. No citations.
[22] A. R. Choudhuri. The physics of fluids and plasmas : an introduction for astrophysicists /. November 1998. No citations.

BIBLIOGRAPHY

269[23] P. Colella. A direct Eulerian MUSCL scheme for gas dynamics. SIAM J Sci Stat
Comput, 6(1):104–117, 1985. No citations.
[24] P. Colella. Multidimensional upwind methods for hyperbolic conservation laws.
J Comput Phys, 87:171–200, March 1990. No citations.
[25] P. Colella and H. M. Glaz. Efficient solution algorithms for the Riemann problem
for real gases. J Comput Phys, 59:264–289, June 1985. No citations.
[26] P.
ColellaandE.
G.
Puckett.
Modern Numerical Methods for Fluid Flow.
unpublished manuscript.
obtained fromhttp://www.amath.unc.edu/Faculty/minion/class/puckett/. No citations.
[27] P. Colella and M. D. Sekora. A limiter for PPM that preserves accuracy at smooth
extrema. J Comput Phys, 227:7069–7076, July 2008. No citations.
[28] P. Colella and P. R. Woodward. The Piecewise Parabolic Method (PPM) for
Gas-Dynamical Simulations. J Comput Phys, 54:174–201, September 1984. No
citations.
[29] M. S. Day and J. B. Bell. Numerical simulation of laminar reacting flows withcomplex chemistry. Combust. Theory Modelling, 4(4):535–556, 2000. No citations.
[30] M. de Val-Borro, R. G. Edgar, P. Artymowicz, P. Ciecielag, P. Cresswell,
G. D’Angelo, E. J. Delgado-Donate, G. Dirksen, S. Fromang, A. Gawryszczak,
H. Klahr, W. Kley, W. Lyra, F. Masset, G. Mellema, R. P. Nelson, S.-J.
Paardekooper, A. Peplinski, A. Pierens, T. Plewa, K. Rice, C. Schäfer, and
R. Speith. A comparative study of disc-planet interaction. Mon Not R Astron
Soc, 370:529–558, August 2006. No citations.
[31] G. Dimonte, D. L. Youngs, A. Dimits, S. Weber, M. Marinak, S. Wunsch,
C. Garasi, A. Robinson, M. J. Andrews, P. Ramaprabhu, A. C. Calder, B. Fryxell, J. Biello, L. Dursi, P. MacNeice, K. Olson, P. Ricker, R. Rosner, F. Timmes,
H. Tufo, Y.-N. Young, and M. Zingale. A comparative study of the turbulent
Rayleigh-Taylor instability using high-resolution three-dimensional numericalsimulations: The Alpha-Group collaboration. Physics of Fluids, 16:1668–1693,
May 2004. No citations.
[32] D. R. Durran. Improving the anelastic approximation. J Atmos Sci, 46(11):1453–
1461, 1989. No citations.
[33] C. S. Frenk, S. D. M. White, P. Bode, J. R. Bond, G. L. Bryan, R. Cen, H. M. P.
Couchman, A. E. Evrard, N. Gnedin, A. Jenkins, A. M. Khokhlov, A. Klypin,
J. F. Navarro, M. L. Norman, J. P. Ostriker, J. M. Owen, F. R. Pearce, U.-L. Pen,
M. Steinmetz, P. A. Thomas, J. V. Villumsen, J. W. Wadsley, M. S. Warren, G. Xu,
and G. Yepes. The Santa Barbara Cluster Comparison Project: A Comparisonof Cosmological Hydrodynamics Solutions. Astrophys J, 525:554–582, November
1999. No citations.

270

BIBLIOGRAPHY[34] B. Fryxell, K. Olson, P. Ricker, F. X. Timmes, M. Zingale, D. Q. Lamb, P. MacNeice, R. Rosner, J. W. Truran, and H. Tufo. FLASH: An Adaptive Mesh Hydrodynamics Code for Modeling Astrophysical Thermonuclear Flashes. Astrophys J
Supplement, 131:273–334, November 2000. No citations.
[35] A. Garcia. Numerical Methods for Physics, 2nd Edition. Addison-Wesley, 1999. No
citations.
[36] G.A. Gerolymos, D. Sénéchal, and I. Vallet. Very-high-order WENO schemes.
Journal of Computational Physics, 228(23):8481–8524, dec 2009. No citations.
[37] S. K. Godunov. A difference method for numerical calculation of discontinuous
solutions of the equations of hydrodynamics. Mat. Sb. (N.S.), 47(89):271–306,
1959. No citations.
[38] David Goldberg. What every computer scientist should know about floating
point arithmetic. ACM Computing Surveys, 23(1):5–48, 1991. No citations.
[39] S. Gottlieb and C.-W. Shu. Total Variation Diminishing Runge-Kutta Schemes.
ICASE Report No. 96-50, NASA Langley Research Center, July 1996. No citations.
[40] C. J. Hansen, S. D. Kawaler, and V. Trimble. Stellar interiors : physical principles,
structure, and evolution. 2004. No citations.
[41] K. Heitmann, Z. Lukić, P. Fasel, S. Habib, M. S. Warren, M. White, J. Ahrens,
L. Ankeny, R. Armstrong, B. O’Shea, P. M. Ricker, V. Springel, J. Stadel, and
H. Trac. The cosmic code comparison project. Computational Science and Discovery, 1(1):015003, October 2008. No citations.
[42] J. R. Kamm and F. X. Timmes. On Efficient Generation of Numerically Robust
Sedov Solutions. 2007. Los Alamos preprint la-ur-07-2849, http://cococubed.
asu.edu/papers/la-ur-07-2849.pdf. No citations.
[43] Rupert Klein and Olivier Pauluis. Thermodynamic consistency of a pseudoincompressible approximation for general equations of state. J Atmos Sci, March
2012. No citations.
[44] C. B. Laney. Computational Gasdynamics. Cambridge, 1998. No citations.
[45] R. J. LeVeque. Wave Propagation Algorithms for Multidimensional Hyperbolic
Systems. Journal of Computational Physics, 131:327–353, March 1997. No citations.
[46] Randall J. LeVeque. Finite-Volume Methods for Hyperbolic Problems. Cambridge
University Press, 2002. No citations.
[47] Randall J. LeVeque. Finite Difference Methods for Ordinary and Partial Differential
Equations: Steady-State and Time-Dependent Problems. Classics in Applied Mathematics. SIAM, Society of Industrial and Applied Mathematics, 2007. No citations.

BIBLIOGRAPHY

271[48] C. M. Malone, A. Nonaka, A. S. Almgren, J. B. Bell, and M. Zingale. Multidimensional Modeling of Type I X-ray Bursts. I. Two-dimensional Convection Prior to
the Outburst of a Pure 4 He Accretor. Astrophys J, 728:118, February 2011. No
citations.
[49] Len G. Margolin and William J. Rider. A rationale for implicit turbulence modelling. International Journal for Numerical Methods in Fluids, 39(9):821–841, 2002.
No citations.
[50] D. F. Martin and P. Colella. A Cell-Centered Adaptive Projection Method for the
Incompressible Euler Equations. Journal of Computational Physics, 163:271–312,
September 2000. No citations.
[51] S. May, A. J. Nonaka, A. S. Almgren, and J. B. Bell. An unsplit, higher order
Godunov method using quadratic reconstruction for advection in multiple dimensions. Communications in Applied Mathematics and Computational Science, 6(1),2011. No citations.
[52] P. McCorquodale and P. Colella. A high-order finite-volume method for conservation laws on locally refined grids. Communication in Applied Mathematics andComputational Science, 6(1):1–25, 2011. No citations.
[53] G. H. Miller and P. Colella. A Conservative Three-Dimensional Eulerian Method
for Coupled Solid-Fluid Shock Capturing. J Comput Phys, 183:26–82, November
2002. No citations.
[54] M. L. Minion. A Projection Method for Locally Refined Grids. J Comput Phys,
127:158–177, 1996. No citations.
[55] J. J. Monaghan. An introduction to SPH. Computer Physics Communications,
48:89–96, January 1988. No citations.
[56] M. Newman. Computational Physics. CreateSpace Independent Publishing Platform, 2012. No citations.
[57] A. Nonaka, A. S. Almgren, J. B. Bell, M. J. Lijewski, C. M. Malone, and M. Zingale. MAESTRO: An adaptive low mach number hydrodynamics algorithm forstellar flows. Astrophys J Supplement, 188:358–383, 2010. No citations.
[58] M. Omang, S. Børve, and J. Trulsen. SPH in spherical and cylindrical coordinates. Journal of Computational Physics, 213:391–412, March 2006. No citations.
[59] E. S. Oran and J. B. Boris. Numerical Simulation of Reactive Flow. Cambridge
University Press, 2nd edition, 2005. No citations.
[60] T. Pang. An Introduction to Computational Physics, 2nd Edition. Cambridge, 2006.
No citations.

272

BIBLIOGRAPHY[61] R. B. Pember, L. H. Howell, J. B. Bell, P. Colella, W. Y. Crutchfield, W. A. Fiveland,
and J. P. Jessee. An adaptive projection method for unsteady low-Mach number
combustion. Comb. Sci. Tech., 140:123–168, 1998. No citations.
[62] Norbert Peters. Turbulent Combustion. Cambridge University Press, 2000. No
citations.
[63] T. Plewa and E. Müller. The consistent multi-fluid advection method. AstronAstrophys, 342:179–191, February 1999. No citations.
[64] R. D. Richtmyer and K. W. Morton. Different Methods for Initial-Value Problems.
Krieger Publishing Company, 2nd edition, 1994. No citations.
[65] W. J. Rider. Approximate projection methods for incompressible flow: Implementation, variants and robustness. Technical report, LANL UNCLASSIFIEDREPORT LA-UR-94-2000, LOS ALAMOS NATIONAL LABORATORY, 1995. No
citations.
[66] J. Saltzman. An Unsplit 3D Upwind Method for Hyperbolic Conservation Laws.
J Comput Phys, 115:153–168, November 1994. No citations.
[67] W. Schmidt. Large Eddy Simulations in Astrophysics. Living Reviews in Computational Astrophysics, 1:2, December 2015. No citations.
[68] C. W. Schulz-Rinne, J. P. Collins, and H. M. Glaz. Numerical Solution of the
Riemann Problem for Two-Dimensional Gas Dynamics. SIAM J Sci Comput,
14(6):1394–1414, 1993. No citations.
[69] Carsten W. Schulz-Rinne, James P. Collins, and Harland M. Glaz. Numerical solution of the riemann problem for two-dimensional gas dynamics. SIAM Journal
on Scientific Computing, 14(6):1394–1414, 1993. No citations.
[70] L. I. Sedov. Similarity and Dimensional Methods in Mechanics. Academic Press,
1959. translated from the 4th Russian Ed. No citations.
[71] C.-W. Shu and S. Osher. Efficient implementation of essentially non-oscillatory
shock-capturing schemes II. J Comput Phys, 83:32–78, 1989. No citations.
[72] Chi-wang Shu. Essentially Non-Oscillatory and Weighted Essentially NonOscillatory Schemes for Hyperbolic Conservation Laws. Technical Report 97,
1997. No citations.
[73] F. H. Shu. Physics of Astrophysics, Vol. II. University Science Books, 1992. No
citations.
[74] G. A. Sod. A survey of several finite difference methods for systems of nonlinear
hyperbolic conservation la ws. J Comput Phys, 27:1–31, April 1978. No citations.

BIBLIOGRAPHY273[75] V. Springel. E pur si muove: Galilean-invariant cosmological hydrodynamical
simulations on a moving mesh. Mon Not R Astron Soc, 401:791–851, January
2010. No citations.
[76] J. M. Stone, T. A. Gardiner, P. Teuben, J. F. Hawley, and J. B. Simon. Athena: A
New Code for Astrophysical MHD. Astrophys J Suppl S, 178:137–177, September
2008. No citations.
[77] G. Strang. On the construction and comparison of difference schemes. SIAM
Journal on Numerical Analysis, 5(3):pp. 506–517, 1968. No citations.
[78] F. X. Timmes. Integration of Nuclear Reaction Networks for Stellar Hydrodynamics. Astrophys J Supplement, 124:241–263, September 1999. No citations.
[79] F. X. Timmes. Integration of Nuclear Reaction Networks for Stellar Hydrodynamics. APJ:sup, 124:241–263, September 1999. No citations.
[80] F. X. Timmes and S. E. Woosley. The conductive propagation of nuclear flames.
I - Degenerate C + O and O + NE + MG white dwarfs. Astrophys J, 396:649–667,
September 1992. No citations.
[81] V.A. Titarev and E.F. Toro.
Finite-volume {WENO} schemes for threedimensional conservation laws. Journal of Computational Physics, 201(1):238 –
260, 2004. No citations.
[82] E. F. Toro. Riemann Solvers and Numerical Methods for Fluid Dynamics. Springer,
1997. No citations.
[83] Geoffrey M. Vasil, Daniel Lecoanet, Benjamin P. Brown, Toby S. Wood, andEllen G. Zweibel. Energy conservation and gravity waves in sound-proof
treatments of stellar interiors. ii. lagrangian constrained analysis. Astrophys J,
773:169–, 2013. No citations.
[84] Natalia Vladimirova, V. Gregory Weirs, and Lenya Ryzhik. Flame capturingwith an advection-reaction-diffusion model. Combustion Theory and Modelling,10(5):727–747, 2006. No citations.
[85] S. Yakowitz and F. Szidarovszky. An Introduction to Numerical Computations, 2ndedition. Prentice Hall, 1989. No citations.
[86] M. Zingale. pyro: A teaching code for computational astrophysical hydrodynamics. Astronomy and Computing, 2014. accepted for publication. No citations.
[87] M. Zingale, L. J. Dursi, J. ZuHone, A. C. Calder, B. Fryxell, T. Plewa, J. W. Truran,
A. Caceres, K. Olson, P. M. Ricker, K. Riley, R. Rosner, A. Siegel, F. X. Timmes,
and N. Vladimirova. Mapping Initial Hydrostatic Models in Godunov Codes.
Astrophys J Supplement, 143:539–565, December 2002. No citations.

274

BIBLIOGRAPHY[88] M. Zingale and M. P. Katz. On the Piecewise Parabolic Method for Compressible
Flow With Stellar Equations of State. Astrophys J Supplement, 216:31, February
2015. No citations.