You are on page 1of 29

Rony Keppens & Jon Sundqvist

Computational Methods for


Astrophysical Applications
–Hands-on simulating with MPI-AMRVAC–

September 28, 2020

Springer Nature
Contents

2 Partial Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


2.1 PDE notation and types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1.2 Second order PDE types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.3 Hyperbolic PDE considerations . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Numerical discretizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Hands-on with scalar advection . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2 Reaction-diffusion and IMEX . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.2.1 Numerical implementation: explicit approach . . . . . 12
2.2.2.2 Numerical implementation: IMEX variants . . . . . . 14
2.2.2.3 Examples in 2D and 3D using MPI-AMRVAC . . . . . . 17
2.3 More on IMEX(sim, sex, p) schemes∗∗ . . . . . . . . . . . . . . . . . . . . . . . . . . 20
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

v
Chapter 2
Partial Differential Equations

Abstract In this chapter, we commence with the study of Partial Differential Equa-
tions, where we will solve for functions having multiple arguments. We will gradually
evolve to the case where we have several unknown functions that all depend on three
space and one time dimension. We introduce notation and a commonly exploited
classification for second order PDEs, and make some statements specific to the
hyperbolic type of such PDEs. Some simple discretizations for handling the hyper-
bolic scalar advection equation are introduced. Particular attention is then given to
reaction-diffusion equations, which are of parabolic type, and for which we will dis-
cuss in more detail the possibility to mix implicit with explicit strategies in so-called
IMEX schemes. Example simulations with the open source MPI-AMRVAC tool are
presented.

2.1 PDE notation and types

A Partial Differential Equation or PDE expresses a relation between a function in


multiple arguments, e.g. u(x, t) which is both space and time dependent, and its
various partial derivatives. We start with emphasizing some notational convention
we adopt in this book, and then specify to second order PDEs.

2.1.1 Notation

When we have a function of two arguments, such as u(x, t), we denote the partial
derivatives as
∂u(x, t)
≡ ∂t u(x, t) ≡ ut (x, t) ,
∂t
∂u(x, t)
≡ ∂x u(x, t) ≡ u x (x, t) . (2.1)
∂x

1
2 2 PDEs

In the above, we assumed that x and t, usually indicating space and time dimensions,
are indeed fully independent coordinates. Sometimes, we may encounter a situation
where u(x(t), t), i.e. a function u is to be evaluated at a time-varying position x(t).
In that case, we should distinguish clearly whether we keep the position x(t) fixed or
not. This amounts to distinguishing between the partial and the total time derivative,
as in
∂u(x(t), t)
≡ ut ,
∂t
du(x, t)
≡ u x x 0 + ut . (2.2)
dt
In what follows, we will almost exclusively handle cases where we only have u(x, t)
with x and t independent, but extend our interests to systems of PDEs in more than
one space dimension as well as time, hence handling u(x, t).
PDE systems thus express relations between functions in multiple variables and
their various partial derivatives, and the order of the PDE relates to the highest
order derivative present. For a single function u(x, y), with x and y the independent
coordinates of a Cartesian system, we can write an example first order PDE as

u x + uy = 0 , (2.3)

or some example second order PDEs as

u xx − uy = 0 or u xx + uyy = 0 or u xx − uyy = 0 . (2.4)

Sometimes, these may actually express the ‘same’ relation, at least for sufficiently
smooth u(x, y). Indeed, if we take partial derivatives of our first order equation (2.3),
we find
∂x : u xx + u xy = 0
(
⇒ u xx − uyy = 0 . (2.5)
∂y : uyx + uyy = 0 |{z}
u x y =uy x

We will return to this aspect later on, noting that formally, the first order variant
assumes less smoothness for the function u(x, y). Needless to say, PDEs are com-
mon to many, if not all, scientific disciplines, such as (astro)physics, engineering,
chemistry, finance, . . . . Solving them by suitable numerical means is an intrinsically
interdisciplinary activity.
As our main concern will be with PDE systems for u(x, t), we can extend our
notation in obvious ways, such as

∂u
≡ ∂t u = ut (x, t) ,
∂t
∂u
≡ ∂x u = ux (x, t) , (2.6)
∂x
However, in handling scalar and vector quantities as encountered in many applica-
tions, we also have the usual meaning for the gradient, divergence, Laplacian defined
2.1 PDE types 3

in up to 3-dimensional space, and the curl (only in 3D) operator, i.e.

∇ = êx ∂x + êy ∂y + êz ∂z ,


∇T (x, t) = êx ∂x T + êy ∂y T + êz ∂z T ,
∇ · v(x, t) = ∂x vx + ∂y vy + ∂z vz ,
∇2 = ∇ · ∇ ,
   
∇ × v(x, t) = êx ∂y vz − ∂z vy + êy ∂z vx − ∂x vz + êz ∂x vy − ∂y vx . (2.7)


Note that in such expressions, we will consistently use vx to denote the x-component
of a vector v, and always denote the partial derivative with ∂x , in order not to
confuse the otherwise ambiguous notation from the very rightmost part of Eq. (2.1)
or Eq. (2.6).

2.1.2 Second order PDE types

A generic linear second order PDE governing a single function of two variables
u(x, y) can be written as

au xx + 2bu xy + cuyy + du x + euy + f u + g = 0 , (2.8)

where a, b, c, d, e, f , and g are, for now, assumed constant. The linear or nonlinear
nature of a PDE is similar to the one introduced for ODEs, noting that Eq. (2.8)
would still be considered linear even if we have spatially varying coefficient functions
a(x, y), b(x, y), . . . . This PDE is second order as long as not all coefficients a, b
and c vanish. Note the factor 2b in front of the mixed second order derivative u xy ,
adopted by convention, relating to the fact that we may introduce a quadratic form
aX 2 + bXY + bY X + cY 2 with this part, with a real and symmetric 2 × 2 coefficient
matrix.
The main classification for such second order PDEs depends on the forefactors
a, b and c of the highest order derivatives, in the sense that we distinguish three
categories:
1. Elliptic PDE: when b2 − ac < 0, such as in u xx +uyy = 0 for u(x, y), a 2D variant
of the Laplace equation generally written as ∇2 u(x) = 0.
2. Parabolic PDE: when b2 − ac = 0, such as in the heat diffusion problem for
T (x, t) that obeys Tt = Txx , or more generally when T (x, t) written as ∂t T = ∇2T.
3. Hyperbolic PDE: when b2 − ac > 0, such as in the wave equation for w(x, t)
that obeys wtt = w xx .
The PDE type determines indirectly the kind of numerical solution strategy that
needs to be adopted, and the way boundary (or initial, when a time integration is
involved) conditions need to be handled.
4 2 PDEs

Exercise
2.1 Determine the PDE type for the following equations:

∂ 2u ∂ 2u
+ = 4πG ρ(x, y) , (2.9)
∂ x2 ∂ y2

∂u ∂ 2u
=κ 2, (2.10)
∂t ∂x
∂ 2u ∂ 2u
2
− c2 2 = 0 , (2.11)
∂t ∂x
Discuss the meaning of the occuring coefficients and in which physical contexts
these equations arise.

The PDE type is an intrinsic property of the Eq. (2.8), as we may illustrate by the
following. Suppose we are given the elliptic PDE

f uu + f vv = 0 , (2.12)

governing a function f (u, v) where (u, v) are coordinates in the (x, y) plane that are
related to (x, y) as indicated in Fig. 2.1, where α is a constant angle (an example of
a linear transformation of the plane).

Fig. 2.1 A coordinate trans-


formation in the plane.

Using the transformation indicated in Fig. 2.1, we can rewrite the governing
equation in the Cartesian (x, y) coordinates, since
2.1 PDE types 5

∂x ∂y
fu = f x + fy = fx
∂u ∂u
∂x ∂y
f uu = f ux + f uy = f xx
∂u ∂u
f vv = f xx cos2 α + 2 cos α sin α f xy + f yy sin2 α (2.13)

The PDE becomes

f xx (1 + cos2 α) + 2 sin α cos α f xy + sin2 α f yy = 0 . (2.14)

It is easily verified that the PDE character dit not change, since the elliptic character
of f uu + f vv = 0 follows from (a, b, c) = (1, 0, 1) hence b2 − ac = −1 < 0, while
in the form of Eq. (2.14) we find (a, b, c) = (1 + cos2 α, sin α cos α, sin2 α) hence
b2 − ac = − sin2 α. For all α for which the transformation is one-to-one (α , 2nπ),
the ellipticity remains.
Two further remarks are in order. First, we assumed that all coefficients are
constants, but in actual applications, we may encounter coefficient functions that
depend on position and time, e.g. a(x, t). In such situations, the character of the PDE
may differ from place to place, and/or during the course of the temporal evolution.
Furthermore, we focused here on linear second order PDEs of the form (2.8), where
we have a function in 2D as u(x, y). For functions u(x, t), in total having four
arguments (x, y, z, t), we may need to extend the discussion of the second order
PDE classification, allowing for mixed types. Indeed, quadratic forms of the form
a11 X 2 + a22Y 2 + a33 Z 2 + a44T 2 + 2b12 XY + 2b13 X Z + . . ., can also be classified
categorically, using basic linear algebra techniques involving diagonalisation of
the real 4 × 4 symmetric matrix derived from all coefficients of the second order
derivatives. This then leads to a much richer classification of the governing PDEs.
In the basic classification of elliptic, parabolic and hyperbolic, the model problems
from Exercise 2.1 are well known, and we remark that
1. The elliptic Laplace equation is a special case of the Poisson equation (2.9) when
no source term is present. Its solution is fully specified by providing boundary
values for the function u along the edges of a (computational) domain of interest.
The solutions in the interior domain are actually analytic functions. For Poisson’s
equation written as ∇2 ϕ(x) = f (x), the solution can be written using a Green’s
function $
f (x̃)
ϕ(x) = − d 3 x̃ . (2.15)
4π|x − x̃|
2. The parabolic heat equation (2.10) will show a tendency of smoothing out initial
gradients in u(x, t = 0), as it diffuses the heat towards a uniform temperature
distribution over time, as long as no mechanism to maintain a fixed temperature
difference is at work. The diffusion of heat is non-reversible, and the coefficient
before the Laplacian is a diffusion coefficient. Formally, there is no physical
propagation speed associated with this equation: it is in essence infinite.
3. The hyperbolic wave equation (2.11) has finite propagation speeds, namely ±c
corresponding to a forward and backward traveling wave solution. It is time
6 2 PDEs

reversible, meaning that u(x, t) ↔ u(x, −t) can not be distinguished. When there
are discontinuities (in the function or its derivatives) present at t = 0, they will not
be smoothed out. Of course, such discontinuities seem to conflict with the form in
Eq. (2.11), which implicitly assumes that all second derivatives exist everywhere.

Exercise
2.2 Consider the Maxwell equations written as
ρc
∇·E= ∇ × E = −∂t B ,
0
∇·B=0 ∇ × B = µ0 (J +  0 ∂t E) . (2.16)

What PDE type should we associate with these equations? If you consider static
solutions (where ∂t ≡ 0), what type of PDE do we obtain then? Introduce a
vector potential through B = ∇ × A and a scalar potential through E =
−∇φ − ∂t A, can you get the standard Poisson form for the time-independent
case? What about the time-dependent case for vacuum, where charge density
ρc = 0 and current densities J = 0 all vanish?

Just as in the discussion of our 1D ODE model problem from Section ??, we can
distinguish three kinds of boundary prescriptions that complement the PDE, when
it is to be solved on a domain Ω with its (closed) bounding surface S ≡ ∂Ω.
1. Dirichlet boundary conditions give the function values on ∂Ω, in the form u =
f (x, t) for all x ∈ ∂Ω.
2. Neumann boundary conditions give the normal derivative on the surface, i.e. for
all x ∈ S, where locally the ourward normal on S is given by n̂, we are given

∂u
= n̂ · ∇u = f (x, t) , (2.17)
∂n
3. Robin boundary conditions provide on S the relation

∂u
αu + β = f (x, t) . (2.18)
∂n
where α, β and f are given.

2.1.3 Hyperbolic PDE considerations

In many physical applications we encounter wavelike phenomena, and hence the


hyperbolic wave equation deserves some more attention. Just as demonstrated earlier
for a function u(x, y) in Eq. (2.3) and Eq. (2.5), there is both a first and a second
2.1 Hyperbolic PDEs 7

order formulation possible for the wave equation in u(x, t), namely

ut + vu x = 0 equivalent to utt = v 2 u xx , (2.19)

in which we assumed that v is a constant. This factor has the physical dimension of
a propagation speed (in e.g. m/s or km/s), and is also termed the advection velocity.
The second order formulation collects both a left-going and a rightgoing (forward
and backward) wave solution, since it does not change when v → −v. The first order
form does not require that second derivatives of u exist. In fact, we may even allow
for discontinuous initial profiles u, as we will make clear by a physical analogy with
flow (at fixed speed) of a substance or fluid through a pipe of constant diameter
(see Fig. 2.2). That analogy will show that it actually expresses a conservation law,
and the general topic of handling multi-dimensional conservation laws, containing
gas dynamics as a special case, is relevant throughout many astrophysical and en-
gineering applications. We will in later chapters devote ample attention to handling
conservative systems numerically, and allow for discontinuous solutions that e.g.
arise when gas dynamic shocks occur.
The ‘equivalence’ in Eq. (2.19) can be written in a kind of operator splitting
means, namely

∂t2 u − v 2 ∂x2 u = 0
⇓ ⇑
(∂t + v∂x )(∂t − v∂x )u = 0 , (2.20)

which shows that the symmetry property is altered: the second order formulation is
time-symmetric, while the split first order one requires us to reverse both the time,
and the velocity (i.e. t, v → −t, −v). In the form ut +vu x = 0 for a constant coefficient
v, the equation is known as the scalar linear advection equation. The linearity implies
as usual that linear combinations of solutions u1 and u2 will again be valid solutions,
since e.g. ∂t (au1 + bu2 ) = a∂t u1 + b∂t u2 for real and constant a, b.

Fig. 2.2 Flow through a pipe: mass conservation.

The analogy with fluid flow through a pipe is illustrated in Fig 2.2, and it is clear
how the simple concept of mass conservation is applied here: the change of the
‘density’ u(x, t) in the finite segment from [xR 1, x 2 ] will lead to a change in the total
x
mass contained there, as given at time t by x 2 u(x, t) dx. That total mass changes
1
in time only by what is flowing across both ends, quantified by the time-varying
8 2 PDEs

fluxes across the endpoints F (x 1, t) and F (x 2, t). We could (assuming sufficient


smoothness) write this as
Z x2
[∂t u(x, t) + ∂x F (x, t)] dx = 0 when F (x, t) = vu(x, t) ⇒ ut + vu x = 0 .
x1
(2.21)

The linear advection equation is also trivially solved analytically: any initial
functional shape for u(x, t 0 ) = u0 (x) will be advected without distortion for all
t ≥ t 0 , as illustrated for t 1 > t 0 and t 2 > t 0 in Fig. 2.3 where we assumed v > 0 so
that a rightward advection occurs. Having analytic solutions is of course valuable for
testing numerical methods. In particular, we can take fairly arbitrary (single-valued)
initial profiles, containing discontinuities. A final note on this trivial equation is

Fig. 2.3 Linear advection and exact analytic solutions.

that we can already introduce the concept of characteristics. If we work in the


(x, t) plane, and focus on lines given by x − vt = constant, the advection of the
profile without shape-change implies that on those lines also the solution is constant:
u(x − vt) = constant. These (x, t) lines are then known as characteristics, and
they will come back later in full gas dynamical contexts, or for generic hyperbolic
conservation laws.

2.2 Numerical discretizations

2.2.1 Hands-on with scalar advection

As a preliminary to the full hydrodynamic and magnetohydrodynamic (MHD) sys-


tem, it is instructive (see e.g. [1, 2, 3]) to focus on the numerical solution to the
linear advection equation in one spatial (x) dimension as in Eq. (2.19). Numerically,
we need to discretize the problem both spatially and temporally, and come up with a
recipe to advance the discrete solution uin on grid cells indexed by i (e.g. equidistant
grid points spaced by ∆x) from time level t n to t n+1 . A forward Euler temporal
discretization, combined with a centered difference spatial gradient approximation,
2.2 Numerical discretizations 9

suggests as a time-stepping recipe:

uin+1 − uin un − ui−1


n
+ v i+1 = 0. (2.22)
∆t 2∆x
This is the unconditionally unstable FTCS (Forward in Time, Central in Space)
scheme. Unfortunately, this method leads unavoidably to a numerical instability
when initial discontinuities are present, as illustrated in Fig. 2.4, and this under all
combinations of time step ∆t and grid size ∆x. This can be predicted by a Von
Neumann stability analysis of the discrete formula (2.22), which inserts u(x, t n ) =
n+1
G n uo eik x and computes the amplification factor | G | defined from un+1 = GG n un ≡
Gun . The unconditional instability of the method is then found from
s
" #2
∆t
| G |= 1 + v sin (k∆x) > 1 (2.23)
∆x

for all wavenumbers k.

Fig. 2.4 Linear advection: failing to advect a square pulse with FTCS. At even later times, the
solution will ‘blow up’, producing nonsense (i.e. NaNs).

Luckily, there are several ways to ‘cure’ the instability (at least conditionally) by
slightly modifying the formula (2.22). One way is to actually solve another, related
equation, adding diffusion: the generic advection-diffusion equation has the form

ut = −vu x + Du xx , (2.24)

which introduces a diffusion coefficient D. If we try to stabilize the scheme (2.22),


we can e.g. replace the uin in the temporal gradient approximation by a centered
10 2 PDEs

average, namely
1 n ∆t n
uin+1 = (u + ui−1
n
)−v n
(u − ui−1 ). (2.25)
2 i+1 2∆x i+1
This scheme is known as the Lax-Friedrichs discretization. Performing a Von Neu-
mann stability analysis gives | G |=| cos(k∆x) − i v∆t
∆x sin(k∆x) | ≤ 1 if ∆t ≤ ∆x/v.
We can rearrange the terms in (2.25) to write it as
n n !
∆t ui+1 − ui−1
ui = ui − v
n+1 n
∆x 2
(∆x) ui+1 − 2ui + ui−1
2 n n n !
+ . (2.26)
2 (∆x) 2

We conclude from this formula that a diffusive term is added with coefficient DLF =
(∆x) 2 /2∆t. It is conditionally stable, since we must have ∆t ≤ ∆x/v.
Another discretization to approximate the linear advection equation starts from
considering the Taylor series

∂u ∂ 2u
u(x, t + ∆t) ≈ u(x, t) + ∆t (x, t) + 12 (∆t) 2 2 (x, t) , (2.27)
∂t ∂t
in which we now use the governing equation ut = −vu x to replace the time deriva-
tives. This leads to the Lax-Wendroff scheme [4] that is written as

1 ∆t (∆t) 2 2 n
uin+1 = uin − 2
n
v (ui+1 n
− ui−1 ) + 12 v (ui+1 − 2uin + ui−1
n
). (2.28)
∆x (∆x) 2
It is clear that this scheme also has intrinsic numerical dissipation.
Returning now to the ‘Local Truncation Error’ or LTE concept, this can be
analysed for the discretizations of the scalar advection equation we discussed so far.
To do so, one inserts the exact solution in the discrete formula, then adopts Taylor
expansions, assuming smoothness, and uses the equation itself ∂t u+v∂x u = 0. Doing
so for the Lax-Friedrichs (or LF) scheme from Eq. (2.25) we get that it is first order
since
∆t 2 ∆x 2
!
v − 2 u xx + O ∆t 2, ∆x 2 ,
 
L∆t =
LF
(2.29)
2 ∆t
which goes to zero like ∆t for ∆t → 0. This is not surprising since we used a Forward
Euler time discretization, and hence we end up with a first order method. The same
analysis applied to the Lax-Wendroff method gives instead

∆t 2 ∆x 2
!
2 3 3
 
L∆t =
LW
v − v u xxx + O ∆t , ∆x , (2.30)
6 ∆t 2

so we conclude that the Lax-Wendroff (or LW) method is second order accurate.
2.2 Numerical discretizations 11

Exercise
2.3 Demonstrate that the LW scheme is second order accurate by deriving
Eq. (2.30).

Exercise
2.4 Linear scalar advection Write a fortran or python program to solve the
linear advection equation ut + vu x = 0 on x ∈ [−1, 1], taking ∆x = 1/100 and
adopting periodic boundary conditions. Take as initial condition the triangular
profile u(x, 0) profile (x 0 = 0.5, h0 = 1) given by

 u0 x ≤ −x 0
x0 +x

+ <x≤0


 u 0 h 0 −x 0
u(x, 0) =  x0
(2.31)

x0 −x


 u 0 + h 0 x0 0 < x ≤ x0
x > x0

u
 0
Take v = 1 and implement the FTCS scheme. Show that it becomes unstable for
all ∆t. Implement the LF scheme and verify conditional stability: use different
∆t. Do the same for the LW scheme.

Some general considerations and further nomenclature can now be introduced.


For more extensive discussions of these concepts, we refer to LeVeque [2], Chapter
8, or to the original papers as e.g. [5].
• A method where the Local Truncation Error (LTE) goes to zero when ∆t → 0 is
said to be consistent.
• When a method is stable and smooth solutions are sought, the LTE and the global
error between the numerical and exact overall solution can be demonstrated to be
of the same order.
• The Lax equivalence theorem states that for a consistent method, stability of the
scheme is a necessary and sufficient condition for convergence.
• The stencil of a method can be drawn schematically by linking the discrete space-
time points involved in the discrete formula.
We found that conditional stability was expressed by ∆t ≤ ∆x/v for both usable
LF and LW schemes mentioned in Eqs. (2.25,2.28). For a chosen grid size ∆x, this
condition on the time step will apply to any explicit time stepping scheme where
future uin+1 values are directly computed from known values uin at time level t n .
12 2 PDEs

2.2.2 Reaction-diffusion and IMEX

While the previous section discussed explicit time stepping for the one-dimensional
hyperbolic scalar advection equation, in this section we introduce mixed implicit-
explicit (or IMEX) time stepping strategies. We will do so for a PDE system in more
than one spatial dimension, and which is in essence parabolic in nature. The generic
form of so-called reaction-diffusion equations, where we have various substances
collected in u(x, t) = (u1 (x, t), u2 (x, t), . . .), is given by

∂t u = ∇2 (Du u) + g(u, t) , (2.32)

where the presence of the diffusion terms (with diffusion coefficients Du that may
vary from species to species) introduces a parabolic PDE character. The reaction
terms denoted by g(u, t) may be nonlinear in u, so that Eq. (2.32) introduces all
complexity of handling nonlinear ODEs combined with parabolic PDEs. Note indeed
how the spatial dimension is uncoupled when all diffusion coefficients Du vanish,
such that the system then represents an ODE system at each spatial location x.
Reaction-diffusion systems can exhibit a wide variety of pattern-forming behav-
ior [6], as was first pointed out by Turing [7]. We specifically consider two types of
models, the first being the Gray-Scott model [8] for u(x, t) = (u(x, t), v(x, t)), which
in dimensionless units has the following form

∂t u = Du ∇2 u − uv 2 + F (1 − u) , (2.33)
2 2
∂t v = Dv ∇ v + uv − (F + k)v ,

where F and k are positive constants, and the diffusion coefficients are here set to
the constants Du = 2 × 10−5 and Dv = 10−5 . Note that u is converted to v, and
that the ‘feed’ term F (1 − u) drives the concentration of u to one, whereas the term
−(F + k)v removes v from the system. Depending on the values of F and k, a wide
range of patterns can be generated [9]. Here we will use F = 0.046 and k = 0.063.
The second type of model we consider is due to Schnakenberg [10]

∂t u = Du ∇2 u + κ(a − u + u2 v) , (2.34)
2 2
∂t v = Dv ∇ v + κ(b − u v) ,

where κ, a and b are positive constants. The reaction terms somewhat differ from
the Gray-Scott model, but the most important difference is that we will use much
larger diffusion coefficients: Du = 0.05, Dv = 1. These and other parameters, set to
κ = 100, a = 0.1305 and b = 0.7695, are taken from [11] (Chapter IV, section 4.4).

2.2.2.1 Numerical implementation: explicit approach

The numerical strategy to solve these reaction-diffusion models can be done in


several ways. We may start by handling all the terms in an explicit time stepping
2.2 Reaction-diffusion 13

fashion. For the reaction terms, this is done in the usual way discussed in Chapter ??.
Note that we may want to do so at a prescribed order of accuracy in the time step ∆t,
by picking any scheme that achieves the desired order.
For the diffusion terms, we note that when we handle the diffusion explicitly, this
will lead to a time step restriction

∆t < h2 /(2Ndim Dmax ) , (2.35)

where h is the grid spacing (in a 2D setup, a uniform Cartesian grid has h = ∆x = ∆y),
Ndim is the problem dimension (we can consider the equations in both 1D, 2D and
3D setups) and Dmax = max(Du, Dv ) is the maximum of the diffusion coefficients.
Explicit time step restrictions for the reaction and diffusion terms for the two model
systems considered are tabulated in Table 2.1. The large diffusion coefficients that
we adopted for the Schnakenberg model make this model numerically stiff, even on
relatively coarse grids.

Exercise
2.5 Show that, when using a standard second-order accurate discretization of
a diffusive term in
∂t u(x, t) = D∂xx u , (2.36)
a Von Neumann stability will require that ∆t < ∆x 2 /(2D). To do so, adopt a
FTCS approach with a second order accurate FD discretization for the term
∂xx u as in Eq. (2.37), combined with a forward Euler time step. Find that
the amplification factor can be written as G = 1 − 4α sin2 (k∆x/2) where
α = D∆t/∆x 2 , such that | G |< 1 if α < 1/2.

model reactions h = 1/128 1/256 1/512


Gray-Scott ∼1 0.76 0.19 0.048
Schnakenberg ∼ 10−2 1.5 × 10−5 3.8 × 10−6 0.95 × 10−6
Table 2.1 Restriction on ∆t due to reactions (first column) and due to handling diffusion explicitly
for a 2D problem with grid spacing h.

Nevertheless, a first strategy to solve the reaction-diffusion system is to handle


all terms (both the reaction and the diffusion) explicitly, where we then compute
the Laplacian term in a multidimensional manner as the generalization of the 2D
(Cartesian) case for grid point index i, j as
ui+1, j − 2ui j + ui−1, j ui, j+1 − 2ui j + ui, j−1
∇2 ui j ≈ 2
+ . (2.37)
∆x ∆y 2
14 2 PDEs

This discretization is to be used for evaluating the diffusion term at second order,
in all intermediate stages in a possibly multi-stage explicit time stepping strategy.
In particular, a predictor-corrector (PC) scheme would use two stages k = 1, 2 and
employ an update with partial stepsizes ∆t (k) , with ∆t (1) = ∆t/2 and ∆t (2) = ∆t in
sequence. For the Gray-Scott system, this twostep approach hence writes as

uk+1 = un + ∆t (k) Du ∇2 uikj − uikj (vikj ) 2 + F (1 − uikj ) ,


 

v k+1 = v n + ∆t (k) Dv ∇2 vikj + uikj (vikj ) 2 − (F + k)vikj .


 
(2.38)

When handling the system fully explicitly, the ∆t constraint must obey Eq. (2.35) for
stability related to the diffusion part, and impose a time step restriction related to the
reaction terms, which is estimated for the Gray-Scott system as
1
∆t < . (2.39)
2 max max(v 2 ) + F , max(vu) − F − k


The latter constraint on the time step derives directly from the reaction terms in both
equations, and will always need to be respected.

Exercise
2.6 State the time constraint derived from the reaction terms alone in the
Schnakenberg model. Verify the values of all timestep constraints as given in
Table 2.1 for both the Gray-Scott (Eq. (2.33)) and the Schnakenberg model of
Eq. (2.34).

2.2.2.2 Numerical implementation: IMEX variants

In an explicit strategy, the h2 dependence in Eq. (2.35) may eventually forbid high
resolution simulations at affordable costs. Therefore, the system is better handled in
a kind of mixed strategy, where we only are left with the time step constraint posed
by Eq. (2.39) for the Gray-Scott case. A detailed comparison of numerical methods
to better handle stiff reaction-diffusion problems can be found in [11, 12]. Here, we
discuss two implicit-explicit or IMEX schemes.
The first mixed strategy is a simple operator splitting method. The idea is to split
the time derivative as

∂t u = F(u) = Fim (u) + Fex (u) , (2.40)

where Fim are the stiff diffusion terms in this reaction-diffusion setting, and Fex are
the non-stiff reaction terms (i.e. the term g(u, t) from Eq. (2.32)). In an operator
splitting approach, we handle first the explicit part, i.e. we only solve
2.2 Reaction-diffusion 15

∂t u = Fex (u) , (2.41)

to obtain u(n+1)∗ based on un in a manner that respects the desired order of accuracy
in ∆t. A first order Forward Euler will give u(n+1)∗ = un + ∆tFex (un ). This is then
followed by the implicit part, where we solve for the actual un+1 . If we use a first
order backward-Euler discretization of that part, we get

un+1 = u(n+1)∗ + ∆t Fim (un+1 ) , (2.42)

which leads for both systems (Eq. (2.33) or Eq. (2.34)) to a Helmholtz equation for
each component u and v, collectively written as
1 1
∇2 un+1 − un+1 = − u(n+1)∗ . (2.43)
∆t Du ∆t Du

This equation is to be solved for un+1 with a strategy that suits the elliptic nature
of this equation, and requires a proper handling of the boundary prescriptions. We
will not go into further details on how elliptic PDEs are to be solved, but mention
that in the open-source code MPI-AMRVAC1, we can resort to a massively parallel
and adaptive mesh refinement (AMR) compatible geometric multigrid solver [13].
Such a multigrid method leads to a linear cost in the number of unknowns. The code
MPI-AMRVAC [14, 15, 16, 17] is written in Fortran, is parallelized using MPI (or
Message Passing Interface) and is a block-grid adaptive framework for especially
hyperbolic/parabolic partial differential equations (PDEs). The multigrid addition
also allows the handling of elliptic constraints, and turns MPI-AMRVAC in a flexible
PDE toolkit.
The combination of the first order, single step FE for the explicit part in Eq. (2.41),
and the first order BE for the implicit part from Eq. (2.42) delivers an overall first
order accurate scheme, which is known as the IMEX Euler scheme. We can write
the general strategy of this scheme as
f g
un+1 = un + ∆t Fex (un ) + Fim (un+1 ) , (2.44)

and we can denote it by a combination of two Butcher tableau’s, which we may write
as follows:
IMEX Euler
IMEX SP
FE BE
FE BE
0 0 versus (2.45)
0 11
11 101
1 1
10 01

Note how the IMEX Euler scheme from Eq. (2.44) rewrites the Butcher tableau for
the FE and the BE schemes, which we introduced earlier in Eq. (??) and Eq. (??)
(as repeated in the right IMEX SP combination), in a seemingly two-stage manner.

1 See http://amrvac.org.
16 2 PDEs

However, if we remember how this tableau encodes the ( A, b, c) information, in this


rewritten form we see that the b entries are identical to the last row of the 2 × 2
matrix A, so the scheme remains an obviously one-stage scheme, despite its formal
rewriting in a 2-stage Butler tableau. The IMEX SP (with SP denoting the splitting
approach) variant at right of (2.45) is in fact used to indicate another first order
IMEX scheme, that would operate as follows: first do an implicit step, then perform
an explicit step, as in

u(1) = un + ∆tFim (u(1) ) ,


f g
un+1 = un + ∆t Fex (un ) + Fim (u(1) ) . (2.46)

A higher order accurate IMEX scheme, given in [11] (eq. 4.12 of chapter IV), is a
combination of the implicit trapezoidal (or Crank-Nicholson) scheme from Eq. (??)
and the explicit trapezoidal (or Heun) scheme from Eq. (??), and writes as:

u(n+1)∗ = un + ∆tFex (un ) + 12 ∆t Fim (un ) + Fim (u(n+1)∗ ) ,


f g

un+1 = un + 21 ∆t F(un ) + F(u(n+1)∗ ) .


f g
(2.47)

Note how the total RHS F from Eq. (2.40) is used in the explicit second step,
while the first equation again corresponds to a Helmholtz equation for the unknown
u(n+1)∗ . This first step thus needs an elliptic solver, e.g. the multigrid solver coupled
to MPI-AMRVAC. Since we now combined two second order schemes, we achieve
an overall second order accuracy. This scheme is known as the IMEX trapezoidal
scheme (or sometimes denoted as IMEX CN, as it uses an implicit Crank-Nicholson
step). Since it involves one implicit stage, and two explicit stages, while achieving
second order accuracy, the IMEX trapezoidal scheme is denoted as an IMEX(1,2,2)
scheme. The IMEX Euler and IMEX SP are both IMEX(1,1,1).

Exercise
2.7 Verify how the IMEX trapezoidal scheme (2.47) mixes the Butcher
tableau’s for the explicit part according to Heun’s method (??) with the one
for the implicit part according to the CN scheme in (??).

The IMEX trapezoidal method from Eq. (2.47) may also be written as

u(n+1)∗ = un + ∆tFex (un ) + 21 ∆t Fim (un ) + Fim (u(n+1)∗ ) ,


f g

un + u(n+1)∗
!
un+1 = un + 12 ∆t Fex (un ) + Fex (u(n+1)∗ ) + ∆tFim
f g
. (2.48)
2

For the reaction-diffusion system, where the implicit diffusion term is linear in u,
this is completely equivalent to the form (2.47). For nonlinear implicit terms, it is
different.
2.2 Reaction-diffusion 17

Exercise
2.8 Implement (use python or Fortran) all three IMEX variants discussed
so far, to solve the one-dimensional (1D) version of the reaction-diffusion
equations from the Gray-Scott model (Eq. (2.33)) or the Schnakenberg model
(Eq. (2.34)). In 1D, the implicit part of these schemes requires one to solve
a linear tridagional system for each component equation. This is to be solved
using the Thomas algorithm: use a succession of a forwards and a backwards
sweep to get the solution as indicated in Fig. 2.5.

Fig. 2.5 Thomas algorithm for linear tridiagonal systems, from https://www.cfd-
online.com/Wiki/Tridiagonal_matrix_algorithm_-_TDMA_(Thomas_algorithm)

2.2.2.3 Examples in 2D and 3D using MPI-AMRVAC

Figure 2.6 shows the time evolution of a Gray-Scott model for which F = 0.046 and
k = 0.063. The model is solved up to t = 1.5 × 104 in a periodic 2D domain of size
L × L, with L = 2. With MPI-AMRVAC, an AMR mesh with three levels is used, corre-
sponding to grids of 1282 up to 5122 cells, and the size of individual grid blocks is set
to 82 cells. Time integration is performed with the IMEX trapezoidal scheme (2.47)
using a time step ∆t = 0.5. The initial condition is the steady state u = 1 and
v = 0 modified by two Gaussian perturbations of the form 12 exp(−25|r − ri | 2 ), with
r1 = (0.5, 0.5) and r2 = (0.55, 0.6). These perturbations are subtracted from u and
added to v. A complex maze-like pattern emerges. For other values of F and k, many
other types of patterns can emerge, see [9]. Interested readers can also interactively
explore such patterns at https://mrob.com/pub/comp/xmorphia/ogl/index.html.
18 2 PDEs

Fig. 2.6 Time evolution of the density u in a Gray-Scott model with F = 0.046 and k = 0.063,
see equation (2.33). Three refinement levels are used, indicated by the white number and the gray
shade. The levels correspond to an effective resolution of 1282 , 2562 and 5122 cells. In the rightmost
picture, the whole grid is at the highest refinement level.

Fig. 2.7 Time evolution of the density u in Schnakenberg’s model, see equation (2.34). Top row:
2D case on a 2562 uniform grid, bottom row: 3D case on a 1283 uniform grid.

The evolution in figure 2.6 is somewhat chaotic and therefore sensitive to small
numerical errors. To compare the numerical properties of reaction-diffusion schemes,
we consider a 2D and 3D example in which we solve Schnakenberg’s model, which
has a less chaotic time evolution. Solution examples are shown in figure 2.7, both
2.2 Reaction-diffusion 19

1e-02
IMEX
1e-03 split
1e-04

error (2-norm)
1e-05
1e-06
1e-07
1e-08
1e-09
5.0e-05 2.0e-04 8.0e-04 3.2e-03
∆t
Fig. 2.8 Time integration error (two-norm) of an IMEX and a split scheme for solving Schnaken-
berg’s model on a 2562 uniform grid. The solution at t = 2 is compared to a solution computed
with a small time step. The dashed lines indicate first and second order convergence.

for 2D and 3D cases. As in [11], we use a domain with sides of length L = 1, and
Neumann zero boundary conditions for the species densities. The initial condition
is v = b/(a + b) 2 and u(r) = a + b + exp(−100|r − r0 | 2 ), where r0 = (1/3, 1/2) in
2D and r0 = (1/3, 1/2, 1/2) in 3D.
Figure 2.8 shows the convergence behavior of the IMEX trapezoidal and the IMEX
Euler scheme for Schnakenberg’s problem in 2D solved on a uniform grid of 2562
cells. The solution at t = 2 is compared to a solution computed with an explicit third-
order scheme and a small time step ∆t = 3 × 10−6 . The IMEX trapezoidal scheme
from Eq. (2.47) performs well and exhibits second order convergence. The IMEX
Euler scheme converges more slowly, with slightly less than first order convergence,
which indicates that there are large splitting errors. These results are in agreement
with [11].

Exercise
2.9 Use MPI-AMRVAC to reproduce the 2D and the 3D results shown in
Figs. 2.6-2.7. Vary the parameters to obtain other interesting patterns.
20 2 PDEs

2.3 More on IMEX(sim, sex, p) schemes∗∗

The three IMEX(sim, sex, p) schemes given by Eq. (2.44)-(2.46)-(2.47) differed in


the number of stages used for the implicit (sim ) versus explicit (sex ) parts, and in the
overall order of accuracy p. Both IMEX(1,1,1) first order schemes from Eq. (2.44)-
(2.46) require one explicit stage, and one implicit one. The IMEX(1,2,2) trapezoidal
scheme from Eq. (2.47) has one implicit stage, and two explicit ones. We can design
another IMEX(1,2,2) scheme by combining the implicit midpoint scheme from
Eq. (??) or Eq. (??) with a twostep explicit midpoint or PC scheme as in Eq. (??) or
Eq. (??). This is done in the following double Butcher tableau fashion:

IMEX midpoint
PC IM
0 0 (2.49)
1/2 1/2 1/2 0 1/2
0 1 0 1

This corresponds to the following second order IMEX midpoint scheme

u(n+1)∗ = un + 12 ∆tFex (un ) + 12 ∆tFim (u(n+1)∗ ) ,


un+1 = un + ∆tF(u(n+1)∗ ) . (2.50)

There are more possibilities for achieving second order (or higher order) IMEX
schemes, when we also allow for negative coefficients in the Butcher tableau’s. E.g.,
we can mention the ARS(2,2,2) scheme [18] which combines

ARS(2, 2, 2)
explicit implicit
0 0 1
 κ = 1 − 2ω <0 (2.51)
ωω ω0 ω

 ω = 1 − √1

1 κ 1−κ 1 0 1−ω ω  2
κ 1−κ 0 0 1−ω ω

This ARS(2,2,2) achieves second order, and has only two explicit and two implicit
stages, since we note that the b entries in both the explicit and the implicit Butcher
tableau’s for ( A, b, c) are identical to the last rows in the A matrices.
Since we thus far almost exclusively handled Butcher tableau’s with positive
entries alone, we may prefer the ARK(2,3,2) scheme [19] which has also two implicit
stages, three explicit stages, at overall second order. It writes as
2.3 More on IMEX(sim, sex, p) schemes∗∗ 21

ARK(2, 3, 2)
explicit implicit
0 0
δ = 1 − √1 (2.52)
2δ 2δ 2δ δ δ

2


 ν = 1 (3 + 2 2)

1 1−ν ν 1 2√1 2 2√1 2 δ  6
1

2 2
1

2 2
δ 1
√ √
2 2 2 2
1
δ

Thus far, in terms of the ( A, b, c) matrices in the Butcher tables, we have been
combining schemes that have the same c entries for the implicit and the explicit
stages. The implicit part was always diagonally implicit, meaning that in the A-
matrix, only the a22, . . . , ass entries for an s-stage scheme can differ from zero. Such
a generic IMEX scheme with up to s implicit and explicit stages is then in general

Y0 = u n
i
X i−1
X
Yi = un + ∆t ai j Fim (Y j ) + ∆t âi j Fex (Y j ) for i = 1, . . . , s
j=1 j=1
Xs s
X
un+1 = un + ∆t bi Fim (Yi ) + b̂i Fex (Yi ) , (2.53)
i=1 i=1

where we denoted the explicit entries as ( Â, b̂, ĉ), while the implicit part has ( A, b, c).
Since one in practice implements the implicit stages seperate from the explicit ones,
one can relax the condition c = ĉ, and in [20] an IMEX-SSP scheme with 2 implicit
and 3 explicit stages where b = b̂ but c , ĉ was introduced. This writes as

IMEX − SSP(2, 3, 2)
explicit implicit
0 0
(2.54)
0.712 0.712 0.708 0.354 0.354
0.994 0.077 0.917 1 0.399 0.346 0.255
0.399 0.346 0.255 0.399 0.346 0.255

If we allow for tableau’s with also negative entries, we may even get third order
IMEX schemes, e.g. the ARS(2,3,3) scheme [18] (also denotes as ARS3) where

ARS3 or ARS(2, 3, 3)
explicit implicit
0 0 √
3+ 3 (2.55)
γ γ γ 0 γ γ= 6
1 − γ γ − 1 2(1 − γ) 1 − γ 0 1 − 2γ γ
0 1/2 1/2 0 1/2 1/2

It has the advantage of having only 2 implicit stages, which are usually more costly
to compute than explicit stages. Of course, to achieve higher than second order when
using this scheme for reaction-diffusion problems, we must then also improve on
22 2 PDEs

the second order approximation for the diffusion operator we denoted in Eq. (2.37).
This ARS3 [18] scheme has been shown to achieve better than 2nd order accuracy
on some tests [21], while needing three explicit and two implicit stages.

Exercise
2.10 For the IMEX-SSP(2,3,2) scheme from (2.54), rewrite the explicit
Butcher tableau part into an equivalent Shu-Osher form, based on the gen-
eral formulation given in Eq. (??). Find that the diagonal β̃ matrix given by
diag(0.712, 0.917, 0.255) leads to a r-value of about 0.118, which is positive,
but smaller than unity. The SSP character is thus to be generalized to r-values
smaller than one.
References 23

References

1. R.J. Leveque, in Saas-Fee Advanced Course 27: Computational Methods for Astrophysical
Fluid Flow., ed. by O. Steiner, A. Gautschy (1998), p. 1
2. R.J. Leveque, Finite volume methods for hyperbolic problems (Cambridge, UK: Cambridge
University Press, 2002)
3. R.J. Leveque, Numerical Methods for Conservation Laws, Second edition (Birkhäuser Verlag,
Basel-Boston-Berlin, 1992)
4. P. Lax, B. Wendroff, Communications on Pure and Applied Math-
ematics 13(2), 217 (1960). DOI 10.1002/cpa.3160130205. URL
https://onlinelibrary.wiley.com/doi/abs/10.1002/cpa.3160130205
5. P.D. Lax, R.D. Richtmyer, Communications on Pure and Applied Math-
ematics 9(2), 267 (1956). DOI 10.1002/cpa.3160090206. URL
https://onlinelibrary.wiley.com/doi/abs/10.1002/cpa.3160090206
6. S. Kondo, T. Miura, Science 329(5999), 1616 (2010). DOI 10.1126/science.1179047. URL
http://dx.doi.org/10.1126/science.1179047
7. A.M. Turing, Bulletin of Mathematical Biology 52(1-2), 153 (1990). DOI
10.1007/bf02459572. URL http://dx.doi.org/10.1007/BF02459572
8. P. Gray, S. Scott, Chemical Engineering Science 38(1), 29 (1983). DOI 10.1016/0009-
2509(83)80132-8. URL http://dx.doi.org/10.1016/0009-2509(83)80132-8
9. J.E. Pearson, Science 261(5118), 189 (1993). DOI 10.1126/science.261.5118.189. URL
http://dx.doi.org/10.1126/science.261.5118.189
10. J. Schnakenberg, Journal of theoretical biology 81(3), 389 (1979)
11. W. Hundsdorfer, J.G. Verwer, Numerical solution of time-dependent advection-diffusion-
reaction equations, vol. 33 (Springer Science & Business Media, 2013)
12. S.J. Ruuth, Journal of Mathematical Biology 34(2), 148 (1995). DOI 10.1007/bf00178771.
URL http://dx.doi.org/10.1007/BF00178771
13. J. Teunissen, R. Keppens, Computer Physics Communications 245, 106866 (2019). DOI
10.1016/j.cpc.2019.106866
14. R. Keppens, Z. Meliani, A.J. van Marle, P. Delmont, A. Vlasis, B. van der Holst, Journal of
Computational Physics 231, 718 (2012). DOI 10.1016/j.jcp.2011.01.020
15. O. Porth, C. Xia, T. Hendrix, S.P. Moschou, R. Keppens, ApJ Supplement Series 214, 4 (2014).
DOI 10.1088/0067-0049/214/1/4
16. C. Xia, J. Teunissen, I. El Mellah, E. Chané, R. Keppens, ApJ Supplement Series 234, 30
(2018). DOI 10.3847/1538-4365/aaa6c8
17. R. Keppens, J. Teunissen, C. Xia, O. Porth, Computers & Mathematics with
Applications (2020). DOI https://doi.org/10.1016/j.camwa.2020.03.023. URL
http://www.sciencedirect.com/science/article/pii/S0898122120301279
18. U.M. Ascher, S.J. Ruuth, R.J. Spiteri, Appl. Numer. Math. 25(2-3), 151 (1997). DOI
10.1016/S0168-9274(97)00056-1. URL https://doi.org/10.1016/S0168-9274(97)00056-1
19. F.X. Giraldo, J.F. Kelly, E.M. Constantinescu, SIAM J. Scientific Computing 35 (2013)
20. A. Rokhzadi, A. Mohammadian, M. Charron, Journal of Advances in Modeling Earth Systems
10, 18 (2018). DOI 10.1002/2017MS001065
21. T. Koto, Journal of Computational and Applied Mathematics 215, 182 (2008). DOI
10.1016/j.cam.2007.04.003
Index

advection velocity, 7 local truncation error or LTE, 10


advection-diffusion equation, 9
Neumann boundary condition, 6
characteristics, 8
conditional stability, 11 operator splitting, 7
consistency, 11
convergence, 11 Partial differential equation, see PDE
PDE, 1
Dirichlet boundary condition, 6 classification for second order PDEs, 3
discrete Laplacian, 13 Elliptic, 3
Hyperbolic, 3
explicit time stepping, 11 linear second order, 3
mixed types, 5
Forward in Time, Central in Space or FTCS, 9 order, 2
Parabolic, 3
Gray-Scott model, 12
PDE systems, 2
Green’s function, 5
Poisson equation, 5
Poisson equation, 5
IMEX, 12
ARK(2,3,2), 20
ARS(2,2,2), 20 quadratic form, 3
ARS(2,3,3), 21
ARS3, 21, 22 reaction-diffusion equations, 12
IMEX Euler, 15 Robin boundary condition, 6
IMEX midpoint, 20
IMEX SP, 16 scalar linear advection, 7
IMEX SSP(2,3,2), 21 Schnakenberg model, 12
IMEX trapezoidal scheme, 16 stencil, 11
IMEX(sim, sex, p), 20
implicit-explicit time stepping, see IMEX Thomas algorithm, 17

Lax equivalence theorem, 11 Von Neumann stability analysis, 9


Lax-Friedrichs scheme, 10
Lax-Wendroff scheme, 10 wave equation, 5, 7

25

You might also like