Smoothed Particle Idrodynamics

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

a

r
X
i
v
:
1
0
0
7
.
1
2
4
5
v
2


[
a
s
t
r
o
-
p
h
.
I
M
]


2

O
c
t

2
0
1
0
As far as the laws of mathematics refer to real-
ity, they are not certain; and as far as they are
certain, they do not refer to reality.
Albert Einstein
3
Smoothed Particle Hydrodynamics
Or: How I Learned to Stop Worrying and Love the Lagrangian*
* With apologies to Drs. Strangelove and Price
1
Smoothed Particle Hydrodynamics 3.1. Introduction
3.1 Introduction
The study of astrophysical phenomena presents a multitude of obstacles to the po-
tential student. In addition to the usual obstacles of understanding the physical
properties of the system in question, the sheer scale of astrophysical events renders
laboratory experiments impossible in the vast majority of cases. To this end, it has
been necessary to assemble a new, numerical laboratory in the form of computational
simulations, and conduct experiments and analyses via this medium. The growth
of computing power over the past 80 years, from the Colossus of Bletchley Parks
Enigma code-cracking eorts in the 1940s, through ENIAC and Los Alamos Na-
tional Laboratorys modelling of thermonuclear detonations in the 1950s, up to the
supercomputers of today, has in turn allowed the computational domain to become
a mainstay of astrophysical experimentation.
Two principal approaches to computational simulations have evolved to enable
these numerical simulations. Eulerian methods use geometric grids, either xed
or adaptive (the so-called AMR or Adaptive Mesh Renement codes), with the
uid parameters evaluated over the grid cells. Such codes formed the basis of the
revolution in Computational Fluid Dynamics (CFD) that started in the late 1960s
and early 70s, and as such they remain the most widely used approach. Applications
of such codes cover a huge range, from industrial aerodynamics in the automotive
and aerospace sectors, to stress calculations and solid mechanics for civil engineering
and architecture, to chemical reaction modelling and protein folding in biomolecular
models.
Lagrangian methods on the other hand dispense with xed points in space and
instead evolve the uid equations in a co-moving frame. A common approach is
to use discrete particles that are carried with the ow hydrodynamic (and other)
properties are then evaluated at the particle positions, and are calculated from a
weighted average of the values on other local particles. In this manner each particle
is essentially smoothed over a nite volume of xed mass, and in this way these so-
called Smoothed Particle Hydrodynamics or SPH codes are naturally adaptive with
density. Although SPH was originally developed by the astrophysics community, it
too has found uses and applications in a much wider range of elds. In engineering it
has been applied to dam breaks and atomised oil lubrication ows, while a number
of physics engines in computer games use SPH as a basis. The community has grown
to the point where there is now a Europe-wide network of users called SPHERIC -
2
Smoothed Particle Hydrodynamics 3.1. Introduction
the SPH European Research Interest Community
1
. This aims to share advances in
code development across the user community, and to prevent the re-invention of the
wheel when it comes the solution of known problems.
Each of these approaches has advantages and disadvantages with respect to the
other. Generally speaking, AMR codes have a higher resolution for a given number
of grid cells than an SPH code with an equal number of particles. Furthermore, they
can be made to adapt to any ow parameter (although this is not always trivial!),
while SPH adapts primarily with density only. On the other hand, SPH naturally
handles vacuum boundary conditions, whilst large grids are required with AMR
codes to prevent the ow disappearing from the edge of the computational domain.
As SPH is a Lagrangian method, advection of ow properties is inherent, whereas
this presents problems for AMR codes, and which usually entails an unphysical
increase in entropy. In a similar manner, SPH codes can be implemented in such
a manner that they are inherently conservative of mass, momentum and energy,
and similarly, unless it is explicitly added in shocks, they likewise conserve entropy.
Nonetheless it is emphatically not true to say that either SPH or grid code methods
are better than the other, simply that the more appropriate approach should be
chosen for any given problem, and indeed greater condence in the results will ensue
if the two methods concur.
Having said that, throughout this chapter I shall however consider only the SPH
approach, as it is this one that I have used to generate all the results discussed
henceforth. Furthermore, as all the problems I have considered have been fully
three-dimensional, throughout this chapter I shall consider only the derivation and
discussion of SPH in 3D. This chapter is therefore structured as follows: In Sec-
tion 3.2 I shall introduce the basic concepts of the SPH method, then in Section 3.3
this is used to re-write the uid equations in a manner that can be solved numerically.
Section 3.4 discusses the dissipative processes required for the correct implementa-
tion of articial viscosity and the introduction of entropy in shock waves, and then
in Section 3.5 I discuss how the SPH formalism may be made more adaptive still by
the self-consistent inclusion of variable smoothing lengths. As many astrophysical
problems are strongly inuenced by gravitational forces I detail how these may be
implemented in Section 3.6. In Section 3.7 I briey summarise the methods used
to nd the nearest neighbours, and then in Section 3.8 I consider how the code is
evolved forward in time, and various time-stepping criteria. Finally in Section 3.9 I
1
http://wiki.manchester.ac.uk/spheric/index.php/SPHERIC Home Page
3
Smoothed Particle Hydrodynamics 3.2. SPH Basics
briey outline the properties of the code I have used, point the reader in the direc-
tion of some standard numerical tests used for code evaluation and consider further
extensions to the method.
3.2 SPH Basics
In the following section I shall discuss the derivation of the SPH formalism from
rst principles, showing how a continuous eld can be mapped on to (and thus
approximated by) a series of discrete particles, and the errors involved in this ap-
proximation. I then show how derivatives may be calculated, and discuss ways in
which the particles may be suitably smoothed to represent the eld.
3.2.1 Discrete Approximations to a Continuous Field
We start from the (mathematically) trivial identity
f(r) =
_
V
f(r

) (r r

) dr

, (3.1)
where f(r) is any (scalar) function dened on a three-dimensional co-ordinate system
r ranging over a volume V . Similarly, (r) is the Dirac delta function, and r

is a
dummy variable also ranging over V .
We may generalise the delta function to a so-called smoothing kernel W with a
characteristic width h (known as the smoothing length) such that
lim
h0
W(r, h) = (r), (3.2)
subject to the normalisation
_
V
W(r, h) dr

= 1. (3.3)
By expanding W(r r

, h) as a Taylor series, it can be shown that for symmetric


kernels W(r r

, h) = W(r

r, h), equation 3.1 becomes


f(r) =
_
V
f(r

) W(r r

, h) dr

+O(h
2
), (3.4)
4
Smoothed Particle Hydrodynamics 3.2. SPH Basics
the second order accuracy arising from the vanishing of the kernel gradient at r

= r
(see for instance Price 2005; Benz 1990; Monaghan 1992). Note that more elaborate
kernels accurate to O(h
4
) can be constructed, but these suer from the problem that
W(r, h) can become negative in certain ranges (Price, 2005; Monaghan, 1992), thus
potentially leading to negative density evaluations in certain pathological situations.
Nonetheless for a second order, symmetric kernel, for any nite density (r)
within V , equation 3.4 is exactly equivalent to
f(r) =
_
V
f(r

)
(r

)
W(r r

, h) (r

)dr

+O(h
2
). (3.5)
Discretising this continuous eld on to a series of particles of (potentially variable)
mass m = (r

)dr

, the original identity equation 3.1 becomes


f(r)

i
m
i

i
f(r
i
) W(r r
i
, h), (3.6)
where now f(r
i
), m
i
and
i
= (r
i
) are the scalar value, mass and density of the
i
th
particle, and i ranges over all particles within the smoothing kernel. Equation
3.6 therefore represents the discrete approximation to the continuous scalar eld
f at position r in the computational domain V , and is thus the basis of all SPH
formalisms. Note that the position r at which the function f is approximated is
completely general and is not restricted to particle positions, although in practice
this is where the values are actually evaluated.
3.2.2 Spatial Derivatives and Vector Calculus
In order for the SPH discretisation of a eld to be useful as a method of solving uid
ows, it is clear that the spatial derivatives of any given quantity must also have a
suitable approximate form
2
. Here therefore, I summarise the SPH approximations
for various vector calculus quantities.
3.2.2.1 Gradient of a Scalar Field
The approximation for the gradient of a scalar eld can be derived by taking the
spatial derivative of equation 3.1, and applying the smoothing kernel. Noting that
2
Temporal derivatives are naturally also required, and these will be discussed in due course
5
Smoothed Particle Hydrodynamics 3.2. SPH Basics
/r, we therefore see that
f(r) =

r
_
V
f(r

) (r r

) dr

(3.7)
=

r
_
V
f(r

) W(r r

, h) dr

+O(h
2
), (3.8)
in a similar manner to equation 3.4. Given that the only part to depend on r is the
smoothing kernel W, and again introducing the density (r

) in both the numerator


and the denominator we obtain
f(r) =
_
V
f(r

)
(r

r
W(r r

, h)(r

) dr

+O(h
2
). (3.9)
Finally this may be discretised in the same way as before, to give
f(r)

i
m
i

i
f(r
i
) W(r r
i
, h) (3.10)
as an estimator for the gradient of a scalar eld f(r). Notable from the above result
is that the gradient of a scalar eld can be approximated by the values of the eld
itself along with the gradient of the kernel. Computationally this is very useful as
at no point does f have to be evaluated for any particle, whilst the gradient of
the kernel will be known explicitly for any sensible choice of W.
3.2.2.2 Divergence of a Vector Field
Although equation 3.1 was given only for a scalar eld, a similar identity may be
given for a vector eld F(R), namely
F(r) =
_
V
F(r

) (r r

) dr

, (3.11)
Taking the divergence of this with respect to r, and noting once again that the only
term to depend on r is the smoothing kernel we nd that the integral approximation
becomes
F(r) =
_
V
F(r

) W(r r

, h)dr

+O(h
2
), (3.12)
6
Smoothed Particle Hydrodynamics 3.2. SPH Basics
and thus as before this can be discretised to obtain the approximation
F(r)

i
m
i

i
F(r
i
) W(r r
i
, h). (3.13)
3.2.2.3 Curl of a Vector Field
By a precisely similar argument, it is possible to show that the curl of a vector F,
F can be approximated using
F(r)

i
m
i

i
F(r
i
) W(r r
i
, h), (3.14)
although this is relatively little used unless magnetohydrodynamic (MHD) eects
are being taken into account.
3.2.3 Errors
The approximations given in equations 3.6, 3.10, 3.13 and 3.14 encompass both the
O(h
2
) errors of considering only the integral term, and also the errors inherent in the
discretisation (which arise due to incomplete sampling of the smoothing kernel). In
the former case we see that the O(h
2
) errors are reduced by decreasing the smoothing
length, while the discretisation (sampling) errors are minimised by increasing the
number of particles within the smoothing kernel. Barring numerical stability issues
(Read et al., 2010), this discrete approximation is therefore at its most accurate with
large numbers of particles contained within a small smoothing length. However, this
must be balanced against the need for computational speed and eciency, and hence
there is a compromise to be struck.
These errors are neatly illustrated by considering the approximations to a con-
stant function f(r) 1 and the zero function, which can be obtained by noting that
with this denition of f, f(r) = 0. The SPH approximations for one and zero
therefore become
1

i
m
i

i
W(r r
i
, h), (3.15)
0

i
m
i

i
W(r r
i
, h). (3.16)
Since in neither case does the equation reduce to an identity, we see that there are
7
Smoothed Particle Hydrodynamics 3.2. SPH Basics
inherent errors in estimating even constant functions. Nonetheless, with suitable
choices for the number of particles within the smoothing kernel and the smoothing
length, these may be kept to an acceptable level. For a more detailed derivation and
discussion of these errors, the reader is directed to Price (2005); Monaghan (1992);
Benz (1990) and Read et al. (2010).
3.2.4 Improved Approximations for Spatial Gradients
Although the approximations given in equations 3.6, 3.10, 3.13 and 3.14 are those
that arise most readily from the SPH approximation, it is possible to construct other
estimators for the gradient of a scalar eld. For instance, by noting that for any
quantity f(r) 1.f(r), we see that
f(r.1) = 1.f(r) + f(r)1 (3.17)
and therefore that
f(r) = f(r) f(r)1. (3.18)
Clearly, since 1 = 0 these forms should be identical. From equation 3.16 however,
we see that the SPH approximation for 1 is non-zero, and thus using equation 3.18
we may dene another estimate for f(r) as
f(r) =

i
m
i

i
f(r
i
) W(r r
i
, h) f(r)

i
m
i

i
W(r r
i
, h) (3.19)
=

i
m
i
f(r
i
) f(r)

i
W(r r
i
, h). (3.20)
This approximation clearly has the advantage that it vanishes identically for constant
functions.
A more general class of interpolants arises from considering the vector calculus
identity
(f
n
) nf
n1
+
n
f, (3.21)
valid for all n R. This in turn leads to the following identity for f
f
1

n
_
(f
n
) nf
n1

. (3.22)
Substituting and f
n
into equation 3.10, we obtain a general interpolant for f,
8
Smoothed Particle Hydrodynamics 3.2. SPH Basics
such that
f(r) =
1
(r)
n

i
m
i
_
f(r
i
)(r
i
)
n1
nf(r)(r)
n1
_
W(r r
i
, h). (3.23)
Two instances of this general case turn out to be particularly useful, namely where
n = 1 and n = 1. For the former case we obtain
f(r) =
1
(r)

i
m
i
(f(r) f(r
i
)) W(r r
i
, h). (3.24)
This is very similar in form to that given in equation 3.20, with the exception that
knowledge of the density at r is required a priori. Although no longer anti-symmetric
in f(r) and f
i
, it is nonetheless exact for constant functions.
In the case where n = 1 we obtain
f(r) = (r)

i
m
i
_
f(r)
(r)
2
+
f(r
i
)
(r
i
)
2
_
W(r r
i
, h). (3.25)
While this form is no longer exact for constant functions, it is commonly used as an
estimator for the pressure gradient (P)/, as it is pairwise symmetric and as such
ensures conservation of momentum. This is also the form of the gradient that arises
naturally from a Lagrangian formulation of the uid equations, as I shall show in
Section 3.3.2.
3.2.5 Improved Divergence Estimates
In a similar manner to the gradient, improved estimates can be made for the diver-
gence of a vector eld. By noting that F(r) = 1.F(r), the estimate
F(r)

i
m
i

i
(F(r
i
) F(r)) W(r r
i
, h). (3.26)
can be arrived at, which again becomes exact for constant functions. In a similar
manner to the expansion given in equation 3.21, a general class of estimates can be
arrived at by considering the identity
(
n
F) =
n
F + n
n1
F , (3.27)
9
Smoothed Particle Hydrodynamics 3.2. SPH Basics
the n = 1, 1 cases of which are given by
F(r)
1
(r)

i
m
i
(F(r
i
) F(r)) W(r r
i
, h) (3.28)
and
F(r) (r)

i
m
i
_
F(r
i
)
(r
i
)
2
+
F(r)
(r)
2
_
W(r r
i
, h) (3.29)
respectively. Once again these estimates have the advantages of being exact for
constant functions in the former case and pairwise symmetric in ( F)/ in the
latter case.
3.2.6 Smoothing Kernels
From the above it is clear that the choice of smoothing kernel is an important one.
It must by denition obey the criteria set out in equations 3.2 and 3.3 in that it
must tend to a -function as h 0 and it must be normalised so the area under the
curve is unity. For the purposes of calculating the gradients of quantities it is also
clear that it should have a continuous and well dened rst derivative, and from a
symmetry argument it should be spherically symmetric, and thus depend only on
r = |r r

| and h.
One of the rst choices for the smoothing kernel was the Gaussian function, such
that
W(r, h) =
1
h
3

3/2
e
x
2
, (3.30)
where x = r/h. However, this has the drawback that W > 0 for all r, and thus
all particles within the computational domain contribute. The computational cost
of such a kernel therefore scales as O(N
2
), where N is the number of particles in
the simulation. Given that (for purely hydrodynamical quantities) long range forces
are negligible, it makes sense to restrict the kernel to those with compact support,
i.e. make them subject to the condition that W(r, h) = 0 where r/h > k for some
constant k. This means that the computational cost scales as O(NN
neigh
), where
N
neigh
is the average number of particles within a sphere of radius r = kh about any
one particle.
For this reason, cubic spline kernels are often used (see Monaghan & Lattanzio
10
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
1985 for instance), where the kernel is dened as
W(r, h) =
1
h
3
_

_
1
3
2
x
2
+
3
4
x
3
0 x 1;
1
4
(2 x)
3
1 x 2;
0 x 2,
(3.31)
where x = r/h as in equation 3.30. Here only particles within 2h of the central
particle contribute to the smoothing kernel, which is spherically symmetric and
smoothly dierentiable for all r. Although many other kernels are possible (see
Monaghan 1992; Fulk & Quinn 1996; Price 2005; Read et al. 2010 for example) this
is a commonly used kernel, and is the one present in the code I have used throughout.
Note from the above the gradient of the kernel is well dened for all values of x,
such that
W(r, h) =

r
W(r, h) (3.32)
=
1
h
4
_

_
9
4
x
2
3x 0 x 1

3
4
(2 x)
2
1 x 2
0 x 2
. (3.33)
Finally it is worth noting that in general the form of the kernel makes little
overall dierence to the computational speed of the code. This is because most
codes tabulate the values of both the kernel and its gradient rather than compute
them directly, and thus the form of the kernel may be as simple or as complex as
required, even (theoretically at least) to the extent of being non-analytic functions.
3.3 Fluid Equations
Given that the SPH formalism has now been put on a sound mathematical footing,
in this section I shall use it to obtain approximations to the equations governing
uid motion, such that they can be used to construct a viable numerical algorithm
for solving uid ows. For the dual purposes of brevity and simplicity I shall here
consider only the case of an inviscid compressible ow in the absence of body forces,
although the inclusion of both gravity and (articial) viscosity will be discussed
in due course. First however, it is useful to summarise the principal equations of
11
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
motion in their standard conservative form.
The continuity (conservation of mass) equation is given by

t
+ (v) = 0 (3.34)
where as normal, is the density, t is time and v is velocity.
The Euler equation gives the equations of motion in the case of an inviscid uid,
and encapsulates the conservation of momentum. In the absence of external (body)
forces it becomes
v
t
+ (v v) +P = 0, (3.35)
where P is the uid pressure and represents the outer or tensor product
3
. For
compressible ows it is also necessary to take into account the energy equation, and
as such the conservation of energy is embodied in the following equation;
u
t
+ [(u + P)v] = 0, (3.36)
where u is the specic internal energy and v = |v| is the magnitude of the velocity
vector. Finally it is worth noting that these ve equations (there are 3 components
to the momentum equation) contain six unknowns (, the three components of
velocity v
x
, v
y
and v
z
, P and u). Therefore in order to solve the system we require
a further constraint; an equation of state is required. All the analysis I shall present
henceforth uses the ideal gas equation of state, where
P = (s)

, (3.37)
= ( 1)u, (3.38)
where is the adiabatic index (the ratio of specic heats), which throughout has
been set to 5/3, and (s) is the adiabat, itself a function of the specic entropy s.
In the case of isentropic ows, s and (thus ) remains constant.
I shall now discuss the SPH formulation of each of the continuity, momentum
and energy equations in turn. Note that again for the purposes of brevity I assume
that the smoothing length is held constant (i.e.

h = 0, where the dot denotes the
derivative with respect to time), and is equal for all particles. Individual, variable
smoothing lengths will be discussed in due course. Furthermore, I assume through-
3
The outer product of two vectors may be summarised as A B = AB
T
= A
i
B
j
(in indicial
notation).
12
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
out that the mass of each particle is held constant, such that m
i
= const, and again
that all particles are of equal mass. Although it is possible to have individually
varying particle masses, the code I use does not have this feature, and therefore I
have not included a discussion of it here. Finally note that from here onwards, all
the approximations are evaluated at specic particle positions, as this is how the
SPH algorithm is implemented within particle-based codes.
3.3.1 Conservation of Mass
Using equation 3.6, we see that in the case of the density, the SPH approximation
becomes very simple, namely that at particle j the density
j
becomes

j
=

i
m
i
W(r
j
r
i
, h),
=

i
m
i
W
ji
,
(3.39)
where we write W
ji
= W(r
j
r
i
, h), and where by symmetry, W
ji
= W
ij
. Note
that here and henceforth, as the SPH formalism is a discrete approximation to the
underlying continuous medium, we assume equality between the estimator on the
RHS and the SPH quantity on the LHS.
Taking the full time derivative of equation 3.39 we obtain
d
j
dt
=

i
m
i
_
W
ji
r
j

dr
j
dt
+
W
ji
r
i

dr
i
dt
+
W
ji
h
dh
dt
_
, (3.40)
and noting that
dr
j
dt
= v
j
,
dr
i
dt
= v
i
,
dh
dt
= 0,
we nd that the time derivative of density becomes
d
j
dt
=

i
m
i
(v
j

j
W
ji
+v
i

i
W
ji
)
=

i
m
i
v
ji

j
W
ji
(3.41)
where we use v
ji
= v
j
v
i
, and where we note that the gradient of the kernel is
antisymmetric, i.e. that

i
W
ji
=
j
W
ji
. (3.42)
13
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
From equation 3.28, we note that the RHS of equation 3.41 is simply an estimator
of
j

j
v
j
. Hence equation 3.41 becomes
d
j
dt
=
j

j
v
j
, (3.43)
which is simply a reformulation of the continuity equation equation 3.34 using the
Lagrangian time derivative
d
dt
=

t
+ (v ), (3.44)
in which the second term accounts for the advection of ow properties through
the uid. Therefore we see that the SPH estimate for density equation 3.39 is
automatically conservative of mass (as long as equation 3.28 is used as an estimate
for the divergence of velocity).
3.3.2 Conservation of Momentum
Although there are various ways of deriving the equations of motion consistently with
the SPH framework, a particularly appealing one is to use the Lagrangian formalism.
As long as the discrete Lagrangian functional preserves the fundamental symmetries
of the underlying continuous one, this confers the inherent advantages that the
resulting SPH equations of motion will automatically full the requisite conservation
laws (through Noethers Theorem) and also that the only approximations made are
in the discretisation of the Lagrangian itself.
3.3.2.1 Linear Momentum
Dened as the total kinetic energy of the system minus the total internal energy (for
purely hydrodynamical ows), the Lagrangian functional L for the uid is
L(r, v) =
_
V
1
2
v v u dr, (3.45)
where as before, u is the specic internal energy. For later simplicity, we note
that through the equation of state (equation 3.38) the specic internal energy is a
function of density and pressure u = u(, P), which in turn are functions of position.
This gives u = u(r). Now if we again make the discretisation m
i
= dr, the SPH
14
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
estimate of the Lagrangian becomes
L(r, v) =

i
m
i
_
1
2
v
i
v
i
u
i
(r
i
)
_
, (3.46)
where i ranges over all particles.
The equations of motion for particle j are obtained from the Lagrangian through
the Euler-Lagrange equations, as follows;
d
dt
_
L
v
j
_

L
r
j
= 0. (3.47)
By considering each of the terms in this equation it is therefore possible to obtain
an SPH approximation to the equations of motion that remains fully conservative.
If we therefore consider the derivative of the Lagrangian with respect to the velocity
at particle j, we nd
L
v
j
=

v
j

i
m
i
_
1
2
v
i
v
i
u
i
(r
i
)
_
,
= m
j
v
j
, (3.48)
noting that since the velocities are independent the dierential is zero unless i = j.
Considering now the second term in the Euler-Lagrange equation 3.47 we nd
that
L
r
j
=

i
_
u
i
P
i
P
i
r
j
+
u
i

i
r
j
_
, (3.49)
where we have used equation 3.38 to obtain the full derivative of the internal energy.
In the isentropic (dissipationless) case we see that (s) is constant, and thus the
pressure is a function of density only, leading to
L
r
j
=

i
_
u
i
P
i
dP
i
d
i
+
u
i

i
_

i
r
j
. (3.50)
From the equation of state equation 3.38 we nd that
u
i
P
i
dP
i
d
i
+
u
i

i
=
P
i

2
i
, (3.51)
and thus the derivative of the Lagrangian with respect to the position of particle j
15
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
becomes
L
r
j
=

i
P
i

2
i

i
r
j
. (3.52)
Using equation 3.39 we nd that

i
r
j
=

k
m
i
W
ik
r
j
(3.53)
=

k
m
i
W
ik
r
ik
r
ik
r
j
, (3.54)
where we take r
ik
= |r
ik
|, and use the fact that the kernel is spherically symmetric.
By direct dierentiation,
r
ik
r
j
= (
ij

kj
)r
ik
, (3.55)
with r
ik
= r
ik
/r
ik
the unit vector in the direction of r
ik
. Substituting this back into
equation 3.54 we nd that

i
r
j
=

k
m
k
W
ik
r
ik
(
ij

kj
)r
ik
(3.56)
=

k
m
k

j
W
ik
(
ij

kj
) , (3.57)
where in the second case we have used the fact that /r
j

j
.
With reference to equation 3.52 we nd therefore that
L
r
j
=

i
m
i
P
i

2
i

k
m
k

j
W
ik
(
ij

kj
) (3.58)
= m
j
P
j

2
j

k
m
k

j
W
jk

i
m
i
m
j
P
i

2
i

j
W
ij
(3.59)
= m
j

i
m
i
_
P
j

2
j
+
P
i

2
i
_

j
W
ji
, (3.60)
where we have changed the summation index in the rst term to i and used the fact
that the gradient of the kernel is antisymmetric, i.e. that
j
W
kj
=
j
W
jk
. Finally,
by substituting equations 3.48 and 3.60 into equation 3.47 and dividing through by
the common factor m
j
, we nd that the SPH equations of motion become
dv
j
dt
=

i
m
i
_
P
j

2
j
+
P
i

2
i
_

j
W
ji
. (3.61)
16
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
Since this equation is pairwise symmetric in i, j, it is clear that the pressure force
on particle j due to particle i is equal and opposite (due to the antisymmetry of
the kernel gradient) to the force on particle i from particle j. In this manner, it is
clear that this formulation of the equation of motion conserves linear momentum by
construction.
3.3.2.2 Angular Momentum
To check that angular momentum L = r mv is conserved, we note that its deriva-
tive with respect to time should be zero. By using equation 3.61 we see that the
time derivative of the angular momentum of particle j is given by
dL
j
dt
= m
j
v
j
v
j
+ m
j
r
j

dv
j
dt
(3.62)
= m
j

i
m
i
_
P
j

2
j
+
P
i

2
i
_
r
j

i
W
ij
, (3.63)
since by denition v
j
v
j
= 0. The total time derivative of the angular momentum
is therefore given by the sum over all particles j, such that
dL
dt
=

i
m
j
m
i
_
P
j

2
j
+
P
i

2
i
_
r
j

i
W
ij
. (3.64)
Hence we see that by reversing the summation indices the entire sum is
anti symmetric in i and j, i.e.
dL
dt
=

i
m
j
m
i
_
P
j

2
j
+
P
i

2
i
_
r
j

i
W
ij
, (3.65)
=

j
m
i
m
j
_
P
i

2
i
+
P
j

2
j
_
r
i

j
W
ji
, (3.66)
which can only be the case where the total sum is zero. Hence the angular momen-
tum is constant with time, and thus angular momentum is explicitly conserved.
3.3.3 Conservation of Energy
In the case of a purely hydrodynamical ow, the total energy E = u + v
2
/2 is
given by the sum of the kinetic and internal energies, such that the SPH estimator
17
Smoothed Particle Hydrodynamics 3.3. Fluid Equations
becomes
E =

i
m
i
_
1
2
v
i
v
i
+ u
i
_
. (3.67)
Clearly, where energy is conserved the time derivative of the total energy should be
zero. Taking the time derivative therefore, we nd that
dE
dt
=

i
m
i
_
v
i

dv
i
dt
+
u
i
P
i
dP
i
dt
+
u
i

i
d
i
dt
_
, (3.68)
=

i
m
i
_
v
i

dv
i
dt
+
P
i

2
i
d
i
dt
_
, (3.69)
where we have again used the fact that in the dissipationless case P = P() and we
can therefore amalgamate the latter two terms of the RHS of equation 3.68 using
equation 3.51. Using also the equation of motion derived above in equation 3.61 and
d/dt from the continuity equation 3.41 we therefore nd that
dE
dt
=

i
m
i
v
i

j
m
j
_
P
i

2
i
+
P
j

2
j
_

j
W
ji
+

i
m
i
P
i

2
i

j
m
j
(v
i
v
j
)
j
W
ji
(3.70)
=

j
m
i
m
j
_
P
j

2
j
v
i
+
P
i

2
i
v
j
_

j
W
ji
, (3.71)
where we have again used the fact that the kernel is antisymmetric to obtain equa-
tion 3.71. Now using the same argument we used to show that angular momentum
is conserved, we note that equation 3.71 is antisymmetric under a reversal of i and
j, and thus must be equal to zero. Hence we nd that
dE
dt
= 0, (3.72)
and therefore that the total energy is also explicitly conserved.
A corollary of this is that the time derivative of the internal energy is given by
the second term on the RHS of equation 3.69, such that
du
j
dt
=
P
j

2
j
d
j
dt
, (3.73)
=
P
j

2
j

i
m
i
(v
j
v
i
)
i
W
ji
, (3.74)
18
Smoothed Particle Hydrodynamics 3.4. Dissipative Eects
and indeed this is how the internal energy is evolved within SPH codes.
It is worth noting that the formulation of SPH outlined above is therefore explic-
itly conservative of mass, momentum (in both forms) and energy. Hence, while there
are inevitably errors inherent in the SPH discretisation of a continuous medium,
these are the only errors that appear, at least in the case of a dissipationless hydro-
dynamical ow.
3.4 Dissipative Eects
So far we have assumed the uid ow to be barotropic (i.e. P = P()), and poly-
tropic, with the polytropic index set equal to the adiabatic index , the ratio of spe-
cic heats. This in turn means that the ow is isentropic, and therefore completely
dissipationless. While this is an adequate approximation for many incompressible,
inviscid and unshocked compressible ows, it presents serious problems when it
comes to modelling transonic and supersonic ow regimes, as the conversion of me-
chanical (kinetic) energy into heat (internal) energy is not correctly captured. The
problem occurs because at a shock front, ow properties such as the velocity, pres-
sure, density and entropy change very rapidly, on the order of the mean free path
of the gas particles. On large scales therefore these changes appear discontinuous,
and ow solvers that do not resolve the mean free path (which is all of them) break
down due to the apparently singular ow gradients.
There are two principal workarounds that allow numerical codes to solve shocked
ows. One is to use a Riemann solver in a Gudonov-type code (see for instance
Inutsuka 2002; Cha & Whitworth 2003), but I shall not go into any detail here as
this is not the approach used in the code I have used. The alternative approach,
used in the majority of SPH codes, is to broaden the shock across a small number of
smoothing lengths. This ensures that the ow gradients do not become innite, and
gives the correct asymptotic behaviour away from the shock. This latter method is
implemented by including an articial dissipative term in the momentum and energy
equations that is triggered only in the presence of shocks, and it is this method that
I shall consider here.
19
Smoothed Particle Hydrodynamics 3.4. Dissipative Eects
3.4.1 Standard Articial Viscosity Prescription
Due to the fact that by construction, shock capturing through a viscous process is
an articial one, there is considerable latitude in the way in which such an articial
viscosity may be implemented. This being said, it must obey the following general
rules (von Neumann & Richtmyer, 1950; Rosswog, 2009):
- The ow equations should contain no discontinuities;
- The shock front should be of the order of a few times the smoothing length;
- The articial viscosity should reduce to zero away from the shock front;
- The Rankine-Hugoniot equations should hold over length scales larger than
that over which the shock is smoothed, i.e.

0
v
0
=
1
v
1
, (3.75)
P
0
+

0
v
2
0
2
= P
1
+

1
v
2
1
2,
(3.76)
P
0

0
+ u
0
+
v
2
0
2
=
P
1

1
+ u
1
+
v
2
1
2
, (3.77)
where the subscripts 0 and 1 refer to pre- and post-shock regions respectively.
- The overall conservation of momentum and energy should not be adversely
aected, while the entropy should rise from the pre- to post-shock regions.
By considering the SPH approximation to the momentum equation 3.61 where the
force is based on pairwise addition of terms of the form P/
2
, on dimensional grounds
it seems sensible to consider an articial viscosity term of the form

v
2

(3.78)
for some suitable velocity scale v. von Neumann & Richtmyer (1950) suggested a
viscous term dependent on the squared velocity divergence (which gives an indication
of the local expansion or contraction of the uid), which translates into SPH form
as
(
ij
)
NR
=

SPH
h
2
| v
ij
|
2

ij
, (3.79)
where h represents a characteristic length scale (in SPH this is equivalent to the
smoothing length),
ij
is the average density of particles i and j and
SPH
is a
20
Smoothed Particle Hydrodynamics 3.4. Dissipative Eects
constant term of order unity. Noting that to rst order
| v
ij
| =
|v
ij
|
|r
ij
|
(3.80)

|v
ij
r
ij
|
|r
ij
|
2
+ h
2
(3.81)
where as previously r
ij
= r
i
r
j
and where we have added the extra (small) term
in the denominator to prevent it becoming singular, this von Neumann-Richtmyer
term becomes
(
ij
)
NR
=

SPH

2
ij

ij
(3.82)
where

ij
=
hv
ij
r
ij
|r
ij
|
2
+ h
2
. (3.83)
By considering the bulk and shear viscosities of a generalised uid it is possible to
obtain a second form of the articial viscosity, and indeed this has been known for
some time (Landsho, 1930; Landau & Lifshitz, 1959). This form is linear in the
velocity divergence and uses the average sound speed
4
c
s,ij
as a second, characteristic
velocity component, giving the overall form
(
ij
)
b
=

SPH
c
s,ij

ij

ij
, (3.84)
where
ij
is as before, and
SPH
is a second constant of order unity. Note that the
negative on the RHS arises from the requirements that the viscous force component
must be non-negative (i.e.
ij
> 0) and that it should be present only for convergent
ows, where v
ij
r
ij
< 0. In fact these criteria also hold for the von Neumann-
Richtmyer form of the viscosity, and therefore in both cases the viscosity is set to
zero in expanding ow conditions.
These two forms have dierent and complementary numerical eects. At low
Mach numbers (M 5) the linear form performs very well in shock tube tests
(Monaghan, 1985), whereas for stronger shocks it fails to prevent inter-particle pen-
etration (Lattanzio et al., 1985). This is an unphysical phenomenon in which the
two streams pass through each other at the shock front, leading to the possibility of
two particles occupying the same position with diering velocities a multi-valued
velocity eld. This possibility can be prevented by using the quadratic form of
4
Where as usual, the sound speed is dened as c
2
s
= dP/d.
21
Smoothed Particle Hydrodynamics 3.4. Dissipative Eects
von Neumann & Richtmyer as it provides a stronger viscosity for high Mach num-
ber, although conversely, on its own this decays too rapidly at low Mach numbers
and fails to damp out the unphysical post-shock oscillations or ringing that oc-
curs. The standard solution is therefore to use the sum of the two terms (Monaghan,
1989), resulting in a standard SPH viscous term of the form

ij
=
_

SPH
c
s,ij

ij
+
SPH

2
ij

ij
v
ij
r
ij
< 0,
0 otherwise.
(3.85)
Various numerical tests have showed that in general the constant values
SPH
= 1,

SPH
= 2 and = 0.01 in equation 3.83 give good results without signicantly
aecting non-shocked ows. However, throughout the simulations discussed in the
later chapters of this thesis we have used values of
SPH
= 0.1 and
SPH
= 0.2, which
have been found to be adequate to accurately resolve (weak) shocks, while at the
same time minimising the articial heating which would have biased our simulation
results details can be found in Lodato & Rice (2004).
This general form of the viscosity can then be incorporated into the momentum
equation to give the following form;
dv
j
dt
=

i
m
i
_
P
j

2
j
+
P
i

2
i
+
ji
_

j
W
ji
. (3.86)
Given that the articial viscosity term is also pairwise symmetric in i, j (since both
r
ij
and v
ij
are anti-symmetric in i and j) it is clear that this form of the equation
of motion also conserves momentum exactly. Likewise it is clear that angular mo-
mentum is conserved, and furthermore, by a similar argument to that presented in
Section 3.3.3 it is possible to show that in order to preserve energy conservation, the
energy equation must be modied to include an extra dissipative term such that
du
j
dt
=
P
j

2
j

i
m
i
v
ji

i
W
ji
+

i
m
i

ji
v
ji

i
W
ji
. (3.87)
In this manner it is therefore possible to include a dissipative term such that shocks
can be accurately captured, albeit broadened across a few smoothing lengths. Since
mass, momentum and energy are still explicitly conserved across the shock the
Rankine-Hugoniot equations are automatically satised at distances greater than a
few smoothing lengths from the shock. Furthermore, since (in theory at least) the
22
Smoothed Particle Hydrodynamics 3.4. Dissipative Eects
articial viscosity is zero away from shocks, all the other initial criteria are satised
also. However, there are various improvements that can be implemented, and these
will now be briey discussed.
3.4.2 More Advanced Viscosities
The thorn in the side of all viscosity prescriptions is the requirement that in the ab-
sence of shocks or other natural dissipative processes the articial viscosity should
reduce to zero, thereby requiring some means to discriminate between shocks and
other ow features. Compounding the problem is the fact that careful consideration
of the articial viscosity given above (see for instance Lodato & Price 2010) shows
that it provides both a bulk and a shear viscosity, while to resolve shocks only the
bulk component is required. Any articial viscosity in the form of equation 3.85
therefore necessarily introduces an unrequired shear viscosity, which can be prob-
lematic in situations where shear ows are important (such as discs), leading to
spurious energy and angular momentum transport. Furthermore, since the shear
force across any given particle varies with its smoothing length, it is clear that this
shear component is resolution dependent. Generally speaking however this eect
can be reduced by sensible choices for
SPH
and
SPH
(Lodato & Rice, 2004) this
further explains the low values of
SPH
and
SPH
mentioned earlier.
3.4.2.1 The Balsara Switch
An attempt to reduce the induced viscosity in shear ows was presented by Balsara
(1995), in which the standard articial viscosity term
ij
is diminished by the factor
f
ij
= |f
i
+ f
j
|/2, where
f
i
=
| v
i
|
| v
i
| +|v
i
| + 0.0001c
s,i
/h
. (3.88)
The inclusion of the vorticity (the curl of the ow eld) allows this form of the
viscosity to perform better in shearing and obliquely shocked ows (see for instance
Steinmetz 1996), while remaining unaected in the case of normal shocks. In a
similar manner to the standard articial viscosity term, this form also includes a
small term 0.0001c
s,i
/h to prevent the viscosity from becoming singular.
23
Smoothed Particle Hydrodynamics 3.4. Dissipative Eects
3.4.2.2 The Morris & Monaghan Switch
Although the Balsara switch represents a considerable improvement over the stan-
dard form of articial viscosity, problems still arise in the case of shocks in shearing
ows, such as those found in accretion discs. For this reason, Morris & Monaghan
(1997) introduced the idea of a time-variant viscosity such that
ij
remains un-
changed from the standard form, but where
SPH
= (t), and where
SPH
= 2
SPH
.
The value of is then evolved for each particle according to the following equation;
d
dt
=

min

+ S
v
. (3.89)
Here
min
0.1 is some minimum value, justied by the requirement that some
level of articial viscosity is required to maintain particle order
5
, 0.1 0.2 h/c
s
is a decay timescale (chosen so that the viscosity decays away over a few smoothing
lengths) and S
v
= max( v, 0) is a source term, activated whenever the ow
becomes convergent. Although this form of the source term is still non-zero for pure
shear ows, this is counter-balanced to some extent by the decay term, and has been
found to work well in many tests of the articial viscosity (Dolag et al., 2005). Fur-
ther variations on this theme have been eected, including incorporating the Balsara
switch into the
ij
term, and capping the maximum value to which can rise by
using a source term of the form S
v
= max((
max
) v, 0) (Rosswog et al., 2000).
For a good general overview of the relative merits of a variety of articial viscosity
methods, see for instance Lombardi et al. (1999); Rosswog (2009); Cullen & Dehnen
(2010, in prep.).
3.4.3 A Note on Entropy
All of the above methods have essentially been aiming to capture the same phe-
nomenon, namely the increase in entropy found across a shock front, while simul-
taneously ensuring isentropic ow elsewhere. Furthermore all share the common
feature that ow evolution proceeds via integration of the energy equation. How-
ever, an approach espoused by Springel & Hernquist (2002) is to consider evolving
the entropy directly, thereby ensuring that the entropy can only increase.
In this manner, we recall that in terms of density and specic entropy s, the
5
Note that only very low levels of viscosity are required for this purpose
min
0.01 should
suce (Cullen & Dehnen, 2010, in prep.).
24
Smoothed Particle Hydrodynamics 3.5. Variable Smoothing Lengths
equation of state is given by
P
i
=
i
(s
i
)

i
. (3.90)
for some entropic function (s). Similarly, the internal energy u
i
may be obtained
from and s via
u
i
=

i
(s
i
)
1

1
i
. (3.91)
In the case of isentropic ow, we have (s) = const, and thus by denition
d
i
dt
= 0. (3.92)
However, in the case where articial viscosity is included, the time derivative of the
entropic function becomes
d
i
dt
=
1
2
1

1
i

j
m
j

ij
v
ij

i
W
ij
. (3.93)
By noting that

i
W
ij
= |
i
W
ij
|r
ij
, (3.94)
and also that
ij
is only non-zero for v
ij
r
ij
< 0, it is clear that the term on
the RHS of equation 3.93 is strictly non-negative, and thus that entropy can only
increase throughout the ow. Using this method of evolving the ow properties it
is therefore possible to explicitly ensure that the entropy of any particle increases
monotonically with time.
3.5 Variable Smoothing Lengths
Up to now, it has been assumed that the smoothing length h is held constant with
time, and is moreover equal for all particles. In regions where the density (and thus
the number of neighbours) is roughly constant, this maintains a constant (small)
sampling error within the SPH smoothing kernel. This requirement of constant
smoothing length is quite restrictive however, as it prevents the code adapting ef-
fectively to regions of higher or lower than average density (Steinmetz & Mueller,
1993). By allowing the smoothing length to vary both temporally and spatially, sam-
pling errors can be minimised across regions of varying density, as either the number
of neighbours or the mass within a smoothing kernel (and thus the resolution) may
25
Smoothed Particle Hydrodynamics 3.5. Variable Smoothing Lengths
be maintained. There are various simple ways of allowing variable eective smooth-
ing lengths that have been introduced, for instance Benz (1990) suggested using a
symmetrised smoothing length h
ij
= (h
i
+ h
j
)/2, such that the kernel becomes
W
ij
= W
_
r
ij
,
h
i
+ h
j
2
_
. (3.95)
An alternative method has been suggested by Hernquist & Katz (1989), in which
the average kernel value is used rather than the average smoothing length, such that
W
ij
=
W(r
ij
, h
i
) + W(r
ij
, h
j
)
2
. (3.96)
With variable smoothing lengths it then becomes necessary to determine the value
of h for each particle. A standard method of doing this is to link the smoothing
length to the local density, such that

i
h
3
i
= const. (3.97)
Since this constant clearly has units of mass, it is frequently linked to the particle
mass, giving the following prediction for the particle smoothing length;
h
i
=
_
m
i

i
_
1/3
, (3.98)
where the coupling constant is generally in the range 1.2 < < 1.5 (Rosswog,
2009). By construction this method maintains a constant mass within the smoothing
kernel. As each of the above formalisms remains pairwise symmetric, momentum
remains fully conserved, and increased spatial resolution is achieved at relatively
low computational cost. The latter method (using the averaged kernel value as in
equation 3.96) has additional advantages in it is less problematic across shocks, and it
couples better with tree methods for calculating self-gravity (Steinmetz & Mueller,
1993). Nonetheless, in both cases errors appear in either the entropy or energy
equation, such that either
dE
dt
or
d(s)
dt

W
h
h
t
= 0, (3.99)
(Hernquist, 1993), and the relevant quantity is therefore not explicitly conserved.
It is however possible to construct SPH estimates that self-consistently account
26
Smoothed Particle Hydrodynamics 3.5. Variable Smoothing Lengths
for the variation in smoothing length, and therefore ensure exact energy conserva-
tion. In this case, the estimator for density equation 3.39 becomes

j
=

i
m
i
W(r
ji
, h
j
), (3.100)
noting that the smoothing length used in the kernel is that associated with particle
j only, and thereby remains constant throughout the summation. By taking the
(Lagrangian) time derivative, we obtain
d
j
dt
=

i
m
i
_
v
ji

i
W
ji
(h
j
) +
W
ji
h
j
dh
j
dt
_
, (3.101)
noting the extra terms compared to equation 3.41, and where now we set W
ji
=
W(r
ji
, h
j
). Noting that
dh
j
dt
=
dh
j
d
j
d
j
dt
, (3.102)
and using equation 3.98 we see that
dh
j
d
j
=
h
j
3
j
. (3.103)
Substituting this into equation 3.101 and gathering like terms, we nd that the time
derivative of the density becomes
d
j
dt
=
1

i
m
i
v
ji

i
W
ij
(h
j
) (3.104)
where

j
= 1
dh
j
d
j

i
m
i
W
ji
(h
j
)
h
j
, (3.105)
= 1 +
h
j
3
j

i
m
i
W
ji
(h
j
)
h
j
, (3.106)
and where W
ji
/h
j
is known from the choice of kernel. Although it can be cal-
culated directly from the kernel, in the case of the cubic spline kernel given in
equation 3.31 it is generally evaluated by noting that
W
h
j
= xW
3
h
W, (3.107)
27
Smoothed Particle Hydrodynamics 3.5. Variable Smoothing Lengths
where W and W are given by equations 3.31 and 3.33 respectively.
Similarly, there is a correction factor to the momentum equation to allow for
the spatial variation in smoothing lengths. Recall from equation 3.52 that in order
to calculate the spatial variation of the Lagrangian, we need to know the spatial
derivative of the density. Allowing now for variable smoothing lengths and using
equation 3.57, we therefore nd that

j
r
i
=

k
m
k
_

j
W
ji
(h
j
) [
ji

jk
] +
W
jk
(h
j
)
h
j
dh
j
d
j

j
r
i
_
. (3.108)
By gathering like terms, we nd that the correction factor for the spatial derivative
of the density is same as that for the temporal one, namely that

j
r
i
=
1

k
m
k

i
W
jk
(h
j
) [
ji

jk
] , (3.109)
with the factor
j
dened as before in equation 3.106.
Following the same derivation as in Section 3.3.2, it is then easy to show that the
acceleration due to hydrodynamic forces with spatially varying smoothing lengths
is given by
dv
j
dt
=

i
m
i
_
P
j

2
j

i
W
ji
(h
j
) +
P
i

2
i

j
W
ji
(h
i
)
_
. (3.110)
Finally, from equation 3.73, we see that the evolution of the internal energy in the
presence of variable smoothing lengths becomes
du
j
dt
=
P
j

2
j

i
m
i
v
ji
W
ji
(h
j
). (3.111)
By an analogous process to that described in Section 3.3.3, it is possible to show that
this equation for the evolution of the internal energy is also explicitly conservative of
the total energy of the system, E. The three equations 3.100, 3.110 and 3.111 along
with the relationship between the density and the smoothing length equation 3.98
therefore form a fully consistent, fully conservative SPH formalism with spatially
varying smoothing lengths.
A problem exists however, in that in order to obtain the density, one needs to
know the smoothing length (equation 3.100) and to obtain the smoothing length one
needs to know the density (equation 3.98). In order to resolve this, this pair of equa-
28
Smoothed Particle Hydrodynamics 3.5. Variable Smoothing Lengths
tions can be solved iteratively by the Newton-Raphson method (Price & Monaghan,
2007). By rewriting equation 3.98, we can combine these two equations to reduce
the problem to that of nding the root h
j
of the equation (h
j
) = 0, where
(h
j
) = m
j
_

h
j
_
3

i
m
i
W(r
ji
, h
j
). (3.112)
Here the rst term represents the density obtained from assuming a xed mass
within the smoothing kernel, while the second term is the standard SPH estimate
for the density. From some initial estimate of the root h
j
, the Newton-Raphson
method gives a better estimate as being
h
j,new
= h
j

(h
j
)

(h
j
)
, (3.113)
where the prime denotes dierentiation with respect to h. By using equation 3.106
we see that

(h
j
) =
3
j

j
h
j
, (3.114)
and thus the updated value h
j,new
is given by
h
j,new
= h
j
_
1 +
(h
j
)
3
j

j
_
. (3.115)
This may be repeated until |h
j,new
h
j
|/h
j
< for some small value of , frequently
set to 10
3
. Then in turn, a self consistent value of the density is then obtained from
equation 3.98. As there is generally relatively little change in h
j
and
j
between
timesteps, the estimator for h
j
is taken as the value from the previous timestep, and
convergence usually occurs within a small number of iterations (Price & Monaghan,
2007). In pathological cases where the Newton-Raphson method does not converge,
other, universally convergent but slower methods such as the bisection method may
be used instead.
Although the inclusion of variable smoothing lengths through this method does
inevitably increase the computational cost of the code, this is relatively small, and
the conservation properties are recovered to within machine (and integrator) tol-
erance. Other tricks, such as predicting the change in the smoothing length using
equation 3.102 can reduce the computational cost still further (see for instance,
Price & Monaghan 2007).
29
Smoothed Particle Hydrodynamics 3.6. Including Gravity
3.6 Including Gravity
As many astrophysical situations are driven at some level by gravitational forces, it
is important to be able to include this consistently within the SPH framework, and
in such a manner that the inherent conservation properties of the algorithm are not
compromised. While much work has been put into N-body simulations of discrete
particles, within the SPH formalism we are aiming to model the gravitational force
over a continuum, and thus it should be smoothed (or softened in SPH parlance) in
a similar manner to that in which the discrete particle mass is smoothed into the
density of a uid continuum. In this section we therefore consider how this can be
done in a consistent manner, and one in which as before momentum and energy are
explicitly conserved.
3.6.1 Gravity in the Lagrangian
In an extension to the Lagrangian for the hydrodynamic equations of motion, it is
possible to incorporate the eects of gravity by considering a Lagrangian of the form
L(r, v) =

i
m
i
_
1
2
v
i
v
i
u
i
(r
i
)
_
, (3.116)
where is an as yet undened measure of the total gravitational potential energy of
the system. By comparison with equation 3.46 this is clearly just the hydrodynamic
Lagrangian with an additional term
L
grav
= (3.117)
which describes the eects of gravity.
Now, as with the density, at position r
i
we can obtain the local gravitational
potential
i
, via a sum over all particles such that

i
= G

j
m
j
(r
i
r
j
,
i
), (3.118)
where (r
i
r
j
) = (r
ij
) is known as the (gravitational) softening kernel, G is the
universal gravitational constant and where
i
is the softening length associated with
particle i. The softening kernel at this stage is fairly general, but it must have the
following properties:
30
Smoothed Particle Hydrodynamics 3.6. Including Gravity
(r, h) < 0 for all r, h, as the local potential must be strictly negative
denite;
(0, h) = 0, such that the gravitational force exerted by any particle on itself
is zero;
lim
r/h
(r, h) =
1
r
, i.e. the softening should reduce to zero at large inter-
particle distances, and the Newtonian potential should be recovered.
Generally speaking, and throughout this thesis, it is assumed that the softening
length is exactly equal to the smoothing length for all particles, i.e.
i
= h
i
for all
i. In a similar manner it is generally taken that the force should only be softened
when r < 2h, so that force softening and density smoothing occur over exactly the
same region.
Noting that the gravitational potential energy is just the mass times the gravi-
tational potential, since the latter is dened over pairs of particles, by denition the
total gravitational potential energy of the system is given by the sum over all pairs
of particles, such that
= G

i
m
i

ji
m
j

ij
(h
i
) (3.119)
=
G
2

j
m
i
m
j

ij
(h
i
) (3.120)
Note that equation 3.119 sums over all pairs of particles, including the so-called self-
interaction terms where i = j, and thus explains the factor of a half in equation 3.120.
From this denition we therefore nd that
=
1
2

i
m
i

i
, (3.121)
and thus that the full Lagrangian in the presence of gravity becomes
L(r, v) =

i
m
i
_
1
2
v
i
v
i
u
i
(r
i
)
1
2

i
_
. (3.122)
By considering only the gravitational term in the Lagrangian, we can as before
use the Euler-Lagrange equations 3.47 to obtain the acceleration due to gravity,
31
Smoothed Particle Hydrodynamics 3.6. Including Gravity
which becomes
m
j
dv
j
dt
=
L
grav
r
j
. (3.123)
Using equations 3.117 and 3.120 we therefore nd that the spatial derivative of the
gravitational Lagrangian becomes
L
grav
r
j
=
G
2

k
m
i
m
k

ik
(h
i
)
r
j
(3.124)
=
G
2

k
m
i
m
k
_

ik
(h
i
) +

ik
(h
i
)
h
i
h
i
r
j
_
. (3.125)
Here we see that in the case of xed smoothing (and therefore softening) lengths,
h
i
/r
k
= 0, and thus we only require the rst term to determine the eects of
gravity. The second term is therefore a correction term to allow for spatial variation
in h.
As before, using the method of equations 3.54 to 3.57 the spatial gradient be-
comes
L
grav
r
j

h
=
G
2

k
m
i
m
k

ik
(h
i
) [
ij

kj
] , (3.126)
=
G
2
m
j

k
m
k

jk
(h
j
) +
G
2

i
m
i
m
j

ij
(h
i
). (3.127)
Now by changing the summation index of the rst term to i, and noting again that
the kernel is antisymmetric we obtain
L
grav
r
j

h
=
G
2
m
j

i
m
i
(
j

ji
(h
j
) +
j

ji
(h
i
)) , (3.128)
which therefore encapsulates the eects of gravity in the case of constant smoothing
lengths.
If we now consider the second term in equation 3.125 and self-consistently correct
for spatial variation in the smoothing length, we nd that
L
grav
r
j

corr
=
G
2

k
m
i
m
k

ik
(h
i
)
h
i
dh
i
d
i

i
r
j
. (3.129)
32
Smoothed Particle Hydrodynamics 3.6. Including Gravity
By substituting equation 3.109 into the above we nd that
L
grav
r
j

corr
=
G
2

k
m
i
m
k

ik
(h
i
)
h
i
dh
i
d
i
1

l
m
l

j
W
il
(h
l
)[
ij

lj
] (3.130)
=
G
2
m
j

k
m
k

jk
h
j
dh
j
d
j
1

l
m
l

j
W
jl
(h
l
)
+
G
2

ik
(h
i
)
h
i
1

i
m
j

j
W
ij
(h
i
).
(3.131)
Now by changing the summation index of the second sum in the rst term of equa-
tion 3.131 to i, dening a new quantity
p
such that

p
=
dh
p
d
p

q
m
q

pq
(h
p
)
h
p
, (3.132)
and using the antisymmetry property of the gradient of the smoothing kernel, we
see that the correction term reduces to
L
grav
r
j

corr
=
G
2
m
j

i
m
i
_

j
W
ji
(h
j
) +

i

j
W
ji
(h
i
)
_
. (3.133)
Finally, using equation 3.123 and by incorporating the eects of gravity into the
equations of motion for a hydrodynamic ow with articial viscosity (while self-
consistently allowing for variable smoothing lengths) we nd that the full equations
of motion become
dv
j
dt
=

i
m
i
_
P
j

2
j

j
W
ji
(h
j
) +
P
i

2
i

j
W
ji
(h
i
) +
ji

j
W
ji
(h
j
) +
j
W
ji
(h
i
)
2
_

G
2

i
m
i
(
j

ji
(h
j
) +
j

ji
(h
j
)) (3.134)

G
2

i
m
i
_

j
W
ji
(h
j
) +

i

j
W
ji
(h
i
)
_
,
with
i
and
i
dened as per equations 3.106 and 3.132 respectively
6
. As in the case
for the pure hydrodynamic ow, the use of a Lagrangian in deriving these equations
ensures the explicit conservation of both linear and angular momentum, which is
also clear from the pairwise symmetry present in all terms in the above equation.
6
Note that for consistency, the articial viscosity term
ji
uses the average value of the smooth-
ing lengths h
ji
= (h
j
+h
i
)/2 in its denition of
ji
(equation 3.83).
33
Smoothed Particle Hydrodynamics 3.6. Including Gravity
3.6.2 Evolution of the Gravitational Potential
Clearly as particles move about within a gravitational potential, their potential
energy (given in SPH terms by m
j

j
) will also vary. Although the potential (and
thus the potential energy) is obtained at any point by the sum over particles using
equation 3.118, the time evolution of the potential energy is required to maintain
energy conservation. Hence in a similar manner to Section 3.3.3 we must consider
the total energy of the system, which including the gravitational potential energy
becomes
E =

j
m
j
_
1
2
v
j
v
j
+ u
j
+
1
2

j
_
. (3.135)
As before, to ensure energy conservation we require that the time derivative of the
total energy is zero, i.e. that

j
m
j
_
v
j

dv
j
dt
+
du
j
dt
+
1
2
d
j
dt
_
= 0. (3.136)
By considering equation 3.118, we see that
d
j
dt
=
G
2

i
m
i
_

ji
(h
j
)
dr
j
dt
+
i

ji
(h
j
)
dr
i
dt
+

ji
h
j
dh
j
d
j
d
j
dt
_
. (3.137)
Recalling the denition of
j
from equation 3.132, and using equation 3.104 for the
denition of d
j
/dt with variable smoothing lengths, we obtain
d
j
dt
=
G
2

i
m
i
v
ji

ji
(h
j
) +

j

j
W
ji
(h
j
)
_
, (3.138)
From Sections 3.3.3 and 3.5 we know that in the energy balance (equation 3.135),
over all particles the hydrodynamic terms in the equations of motion (equation 3.110)
exactly counteract the temporal rate of change of the internal energy,
dE
hydro
dt
=

j
m
j
_
v
j

dv
j
dt

hydro
+
du
j
dt
_
= 0, (3.139)
and thus pure hydrodynamic ows are exactly conservative of energy. With the
inclusion of gravity we therefore only need to show that over the whole system the
gravitational terms in the equations of motion balance the time derivative of the
34
Smoothed Particle Hydrodynamics 3.6. Including Gravity
gravitational potential, i.e. that
dE
grav
dt
=

j
m
j
_
v
j

dv
j
dt

grav
+
1
2
d
j
dt
_
= 0 (3.140)
in order to maintain exact conservation of energy in self-gravitating systems.
From equations 3.134 and 3.138 this gravitational energy balance becomes
dE
grav
dt
=
G
2

i
m
j
m
i
v
j

ji
(h
j
) +
j

ji
(h
i
)+

j
W
ji
(h
j
) +

i

j
W
ji
(h
i
)
_
+
G
2

i
m
j
m
i
v
ji

ji
(h
i
) +

j

j
W
ji
(h
j
)
_
(3.141)
Cancelling like terms, this reduces to
dE
grav
dt
=
G
2

i
m
j
m
i
_
v
j

j

ji
(h
j
) +v
i

j

ji
(h
i
)
+

i

i
v
j

j
W
ji
(h
i
) +

j

j
W
ji
(h
j
)
_
,
(3.142)
and nally, noticing that the gradients of both the smoothing and the softening
kernels are antisymmetric under a reversal of the summation indices i and j, we
obtain the desired result that
dE
grav
dt
= 0. (3.143)
Therefore, we see that gravity can be included into SPH in such a manner that the
algorithm remains explicitly conservative of energy.
3.6.3 Gravitational Potentials and the Softening Kernel
Finally for this section, we need to consider the form of the gravitational softening
kernel , and its relation to the smoothing kernel W. Recall that Poissons equation
links the gravitational potential (r) to the density (r) at position r, such that

2
(r) = 4G(r). (3.144)
35
Smoothed Particle Hydrodynamics 3.6. Including Gravity
Given that we implicitly assume each particle to be spherically symmetric, by using
spherical polar co-ordinates and substituting equations 3.39 and 3.118 into equa-
tion 3.144 we nd that (for a generalised radial co-ordinate r)
W(r, h) =
1
4r
2

r
_
r
2
(r, h)
r
_
, (3.145)
where we have neglected the spatial variation of h
7
.
We can now integrate this, to link the derivative of the softening kernel /r
(also known as the force kernel) to the smoothing kernel, such that

r
=
4
r
2
_
r
r
2
W(r

)dr

+
C
1
r
2
, (3.146)
with the integration constant C
1
subject to the condition that for r 2h we recover
the standard Newtonian inverse square law, which using our denitions becomes
/r = 1/r
2
. In a similar manner we can integrate this a step further (by parts),
to give the full softening kernel, such that
= 4
_

1
r
_
r
r
2
W(r

)dr

+
_
r
r

W(r

)dr

_
+
C
1
r
2
+
C
2
r
, (3.147)
where the second integration constant allows the correct asymptotic behaviour (i.e.
0 as r ) to be established.
With this in mind, for the cubic spline kernel dened in equation 3.31 the force
kernel /r becomes
(r, h)
r
=
_

_
1
h
2
_
4
3
x
6
5
x
3
+
1
2
x
4
_
0 x 1,
1
h
2
_
8
3
x 3x
2
+
6
5
x
3

1
6
x
4

1
15x
2
_
1 x 2,
1
r
2
x 2,
(3.148)
where x = r/h and where the integration constants have been absorbed to ensure
piecewise continuity. Finally, we therefore nd the full softening kernel consistent
7
This is because the smoothing length essentially acts as a normalising constant in both the
smoothing and the softening kernels, and for any given particle is held constant within Poissons
equation. Thus its spatial variation is immaterial here.
36
Smoothed Particle Hydrodynamics 3.7. Finding the Nearest Neighbours
with the cubic spline smoothing kernel to be
(r, h) =
_

_
1
h
_
2
3
x
2

3
10
x
3
+
1
10
x
5

7
5
_
0 x 1,
1
h
_
4
3
x
2
x
3
+
3
10
x
4

1
30
x
5

8
5
+
1
15x
_
1 x 2,

1
r
x 2.
(3.149)
Using this denition of the softening kernel along with the cubic spline smoothing
kernel equation 3.31, the equations of motion equation 3.134 and equation 3.138 for
the evolution of the gravitational potential therefore allows gravity to be included in
a manner that it is fully conservative, and is such that Poissons equation is satised
throughout.
3.7 Finding the Nearest Neighbours
Various methods exist for nding the nearest neighbours (i.e. those particles within
the smoothing kernel of any given particle), with the simplest being a direct search
over all particles. This becomes very expensive in the limit of large numbers of
particles N however, as the computational cost scales as O(N
2
). Other methods
such as using an overlaid grid or a linked list of particle positions have been used
(Hockney & Eastwood, 1981; Monaghan, 1985; Murray, 1996; Deegan, 2009). One
of the more ecient methods however is to use a hierarchical tree structure, an
approach that grew out the requirements of N-body codes to distinguish distant
particles (where the gravitational forces could be evaluated via multipole expan-
sions) from local particles (where direct N-body calculation of the forces was still
required). These in general reduce the cost of neighbour-nding from O(N
2
) to
O(N log N) (Barnes & Hut, 1986; Hernquist, 1987; Hernquist & Katz, 1989), al-
though reductions to O(N) have been achieved (Dehnen, 2002, 2000).
Trees are essentially data structures which decompose the computational domain
into a series of discrete volumes, the sum over which contains all the particles. The
smallest volumes generally contain only a single particle, but this is not strictly
necessary, and indeed may inhibit the eciency of the code (Dehnen, 2009, private
communication). By construction, particles which are near each other in space are
near each other within the tree structure, and thus by looping over a relatively small
part of the tree, the nearest neighbours may be found eciently. There are various
37
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
dierent algorithms that perform this decomposition described in the literature, none
of which are trivial, so I shall not attempt to go into any depth here. For further
details, see for instance Press et al. (2007); Dehnen (2002); Steinmetz & Mueller
(1993); Barnes & Hut (1986); Bentley (1975) and references therein.
A distinct advantage of using trees for neighbour nding within an SPH code is
that they couple readily with pre-existing methods for evaluating the gravitational
force between large numbers of particles. Rather than a direct summation (which
is of O(N
2
)) over all particles to nd the gravitational force at a specic location,
particles at large distances can be eectively treated as a single body, and multipole
expansions used to approximate the force. This approach has found success in
various N-body codes as a means of reducing the computation time to O(N log N)
or lower (Barnes & Hut, 1986; Hernquist, 1987; Hernquist & Katz, 1989). Use of
a tree algorithm therefore allows the process of neighbour nding to be coupled to
that of nding the gravitational forces acting on a particle, with an attendant saving
of computational expense.
3.8 Integration and Timestepping
So far we have obtained equations to evolve the density, the three components of
velocity under the inuence of pressure, gravitational and (articial) viscous forces,
the internal energy and the gravitational potential. Finally therefore it is time
to consider how these equations are actually evolved, and to discuss the issues of
temporal integration and time-stepping.
Generally speaking there are two principal methods used to perform the time
evolution, and indeed the code I have used throughout includes the option to use
either. They are the so-called Leapfrog integrator (also known as the kick-drift or
St ormer-Verlet integrator) and the Runge-Kutta-Fehlberg method, and I shall now
briey consider both of these.
3.8.1 The Leapfrog Integrator
The leapfrog integrator is a second-order integrator, so-called because the position
and the velocity are advanced half a timestep out of phase, with each update of
position or velocity using the value of the velocity or position evaluated at the
previous half timestep. In this manner, the positions and velocities leap-frog over
38
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
each other at every half timestep, giving rise to the name. The leapfrog method is
widely used in N-body codes, since in the case where the acceleration is independent
of the velocity, i.e. where a = a(r) only, it is particularly simple to implement. In
its pure form it is a time-reversible, symplectic integrator, which by denition
is explicitly conservative of both energy and angular momentum (see for instance
Springel (2005) and references therein).
In essence then, if the position, velocity and acceleration at time t
i
are given
by r
i
, v
i
and a
i
respectively, with a timestep t the standard form of the leapfrog
integrator gives the positions and velocities as
r
i+1
= r
i
+v
i1/2
t,
v
i+1/2
= v
i1/2
+a
i
t.
(3.150)
Here it is clear that the positions and velocities are evaluated at half timesteps with
respect to each other, and leap-frog over each other as they are evolved. In this
form it is also clear that the integrator should be perfectly time-reversible.
A form that is often more readily applied is the equivalent denition at integer
timesteps, which becomes
r
i+1
= r
i
+ t
_
v
i
+
t
2
a
i
_
,
v
i+1
= v
i
+
t
2
(a
i
+a
i+1
) .
(3.151)
Although it is now less obvious, these equations are still fully time reversible. Note
further that the form of the increments on the RHS of each of the above equations
is equivalent to an estimate of the relevant quantity at the following half timestep,
noting in particular that
v
i
+
t
2
a
i
= v
i+1/2
, (3.152)
to rst order.
Note however, that in both cases problems arise if the acceleration depends on
the velocity, since from equation 3.151 we see that to calculate v
i+1
we already
need to know the acceleration a
i+1
, and the scheme becomes implicit. Since in
SPH simulations both the pressure force and the articial viscous force depend on
the local velocity, it is clear that modications are required before this integrator
may be used. The standard way this correction is implemented (see for instance
Springel et al. 2001; Wetzstein et al. 2009) is as follows:
39
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
- Firstly, predict the positions at time t
i+1/2
in a manner analogous to equa-
tion 3.152 via
r
i+1/2
= r
i
+
t
2
v
i
. (3.153)
- Secondly, use equation 3.152 to obtain the velocity at time t
i+1/2
, and extrapo-
late other values (such as density, internal energy and gravitational potential)
at the half timestep also. Hence calculate the acceleration at the half timestep,
a
i+1/2
.
- Calculate the velocity at time t
i+1
using
v
i+1
= v
i
+ t a
i+1/2
. (3.154)
- Now update the positions to timestep t
i+1
using
r
i+1
= r
i
+
t
2
(v
i
+v
i+1
) . (3.155)
The process is now repeated as required.
Although the strict symmetry between the integration of positions and velocities
has been lost by the inclusion of these predictor steps, this method still remains
time-reversible. Furthermore, it is also now possible to include adaptive timestep-
ping, which would have been problematic before precisely because of the symme-
try between the integrations (Wetzstein et al., 2009). Generally speaking however,
maintaining time-reversibility with adaptive timestepping is dicult (Springel et al.,
2001; Quinn et al., 1997), though not impossible.
3.8.2 The Runge-Kutta-Fehlberg Integrator
Runge-Kutta methods for integrating systems of dierential equations are well
known, tried and trusted methods, which use multiple estimates of the derivative
across a given timestep to arrive at accurate, generally high order estimates for the
evolved quantities. Most common is the fourth order Runge-Kutta method, often
simply abbreviated to RK4, which has been known and used for over a century
(Kutta, 1901). Moreover, Fehlberg (1968, 1969) obtained a modied Runge-Kutta
integrator (now known as a Runge-Kutta-Fehlberg integrator) which embedded a
order n + 1 method within an order n method. This allows the two methods to be
compared to give an error estimate, and thus for the error to be controlled to some
40
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
given tolerance. The most common of these methods embeds a fth order estimate
within a fourth order scheme, and is therefore known as an RK45 integrator.
However, compared to the leapfrog integrator, which requires only one evaluation
of the acceleration per timestep, the RK4 scheme requires four, and the RK45
method requires six. Therefore these methods, although correct to much higher
order than the leapfrog, add signicantly to the computation time required. (Note
also that they are not necessarily more accurate either, as they are not explicitly
conservative in the way that the leapfrog method is. See for instance Springel
(2005); Wetzstein et al. (2009); Rosswog (2009) for a comparison of these integrators
as applied to a simple Keplerian orbit evolved over many dynamical times.) The
solution is to go to a lower order RKF method, where the implicit error control is
still present but the number of derivative evaluations is reduced. A common choice
for many SPH codes including VINE (Wetzstein et al., 2009; Nelson et al., 2009)
and the one used in the code I have used, is the RK12 integrator developed by
Fehlberg (1969) which proceeds as follows.
For a given variable z, the evolution from z
i
at time t
i
to z
i+1
at time t
i+1
= t
i
+t
is given by
z
i+1
= z
i
+
_
1
256
k
0
+
255
256
k
1
_
t, (3.156)
where the values of k
0
and k
1
are provided by evaluating z at various points, such
that
k
0
= z(t
i
, z
i
),
k
1
= z(t
i
+
t
2
, z
i
+
t
2
k
0
)
(3.157)
and where the dot as usual denotes dierentiation with respect to time. Expan-
sion via Taylor series shows that this is accurate to rst order, with the choice of
coecients in equation 3.156 producing a leading order truncation error
trunc
such
that

trunc
=
1
512
t
2
z. (3.158)
Using the values for k
0
and k
1
dened above, we can compute a further estimate
z

i+1
for z at time t
i+1
, such that
z

i+1
= z
i
+
t
2
_
1
512
k
0
+
255
256
k
1
+
1
512
k
2
_
, (3.159)
41
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
with the additional value k
2
dened such that
k
2
= z(t
i
+ t, z
i
+
_
1
256
k
0
+
255
256
k
1
_
t),
= z(t
i+1
, z
i+1
).
(3.160)
Again, by considering Taylor series expansions, this value z

i+1
can be shown to be
a second order estimate. One of the more appealing tricks of this method is that
here k
2
is simply k
0
evaluated for the next timestep, and thus per timestep, only
two derivative evaluations are required.
We now therefore have both a rst and a second order estimate for the value of
z at time t
i+1
, with a known truncation error for the rst order method. This can
therefore be used for error control, to ensure that the timestep used is appropriate
(see for instance, Press et al. 2007). However, in order for this error control to be
valid, the rst order scheme must be used for the evolution. To mitigate this, by con-
struction this rst order scheme has very small second order errors (equation 3.158),
and so is eectively a quasi-second order integrator.
3.8.3 Timestepping Criteria
For either integrator, it is crucial that the timestep size is chosen correctly, both
to ensure the accuracy of the evolution and to ensure numerical stability. In this
section I shall briey discuss the principal timestepping criteria in general use, and
one specic to the code I have used.
3.8.3.1 CFL Criterion
By far the most general timestep criterion for gas-dynamical systems is the so-called
Courant-Friedrichs-Lewy or CFL condition, given in it simplest form by
t
CFL

x
c
, (3.161)
where x is a characteristic length scale, and c is a characteristic speed (Anderson,
1995). For SPH simulations, these are both well dened; the smoothing length h
provides the characteristic length, and sound speed c
s
gives the characteristic speed
42
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
of the medium. The CFL condition for particle i then becomes
t
CFL

h
c
s
. (3.162)
This has a ready physical interpretation in that it prevents spatial information trans-
fer through the code at a rate greater than the local sound speed. In the presence
of articial viscosity this requires a slight alteration, and as such Bate et al. (1995)
recommend using the following criterion;
t
CFL
=
0.3h
c
s
+ h| v| + 1.2(
SPH
c
s
+
SPH
h| v|)
, (3.163)
where the factors of 0.3 in the numerator and 1.2 in the denominator are empirically
determined. The
SPH
and
SPH
terms are those used to determine the strength of
the articial viscosity (see Section 3.4), and it should be noted that the nal term
in the denominator is only included in the case where | v| < 0. The extra h| v|
term in the denominator accounts for the expansion or contraction of the ow, and
thus explicitly allows for compressibility eects. There are variations on this theme
(see for instance Deegan 2009; Monaghan 1992; Monaghan 1989) but the denition
given above is the one present in the code I have used.
3.8.3.2 Force Condition
A further commonly used timestep condition is that based on the acceleration of
the particle, known as the force condition. This is simple in form, and is given by
t
F
= f
F

h
|a|
, (3.164)
where as before a is the particle acceleration, and f
F
< 1 is a tuning constant.
Values for f
F
vary from code to code but are generally in the range 0.25 - 0.5
(Wetzstein et al., 2009; Bate et al., 1995; Monaghan, 1989). The code I have used
employs f
F
= 0.3.
3.8.3.3 Integrator Limits
Dependent on the choice of integrator, other timestep criteria may be required. In
particular, if using the RKF method the timestep criterion associated with the error
43
Smoothed Particle Hydrodynamics 3.8. Integration and Timestepping
correction must be incorporated. Using the method outlined above, this corresponds
to a timestep of
t
RKF
= t
old

512
|z
RK2
z
RK1
|
, (3.165)
where is the desired error tolerance (usually of the order of 10
4
- 10
5
) and the
z
RK1
, z
RK2
are the predictions for any quantity z from the rst and second order
methods within the integrator respectively. The t
old
term is simply the increment
used for the previous step.
3.8.3.4 Generalised Timestep Criteria
A general class of additional timestep criteria may be obtained by dimensional anal-
ysis, in that for any time-varying quantity z we may dene a characteristic timescale
on which it varies as

z
=
z
z
, (3.166)
where as usual z is the time derivative of z. To ensure that this timescale is properly
resolved, we can therefore dene a timestep condition such that
t
z
= f
z
z
z
, (3.167)
where f
z
< 1 is a tuning factor. Although seldom required in general, a timestep
criterion of this form was implemented into the code when looking at the eects of
strongly varying cooling times in Chapter 5, and will be discussed in more detail
there.
3.8.4 Setting the Timestep
There are therefore a variety of possible timestep choices, and thus to ensure that
they are all satised, the timestep for each particle used is the minimum of all
possibilities, i.e.
t
i
= min(t
CFL,i
, t
F,i
, t
RKF,i
, t
z
). (3.168)
Where there are only relatively small changes in the characteristic timescale, a stan-
dard choice is to use a global timestep t
glob
, which is set by the minimum of the
timesteps t
i
for the individual particles, such that
t
glob
= min
i
(t
i
). (3.169)
44
Smoothed Particle Hydrodynamics 3.9. Summary
This has the advantage that all particles are evolved in lockstep, and thus there is
no information lag due to particles being on separate timesteps.
On the other hand, individual particle timestepping has the advantage of be-
ing much faster and thus more computationally ecient wherever there are large
ranges in the timescales of the problem being investigated. It can however intro-
duce instabilities into the integrator (Wetzstein et al., 2009), and can also lead to
the phenomenon of low density particles on long timesteps drifting into regions of
high density evolving on much shorted timesteps, leading to spurious entropy gen-
eration (Pearce, 2010, private communication). This latter eect is particularly
noticeable in tests of Sedov blasts (see for instance Tasker et al. 2008), in which
small entropy-driven bubbles lead to granularity in the post-shock region. This is
a relatively uncommon phenomenon however, and occurs principally in the case of
strongly shocked systems.
Integrator stability may be maximised (particularly for the leapfrog scheme) by
using timesteps that are integer multiples of each other, and generally speaking, for
a maximum timestep T, sub-timesteps will be given by 2
n
T. The particle timesteps
are therefore rounded down to the nearest relevant power of two in this case. This
is the case in the code I have used for all the simulations presented in this thesis,
which uses individual particle timesteps and is only weakly shocked throughout.
3.9 Summary
In this chapter I have derived the SPH algorithm from rst principles, and then
built it up in a series of steps to solve for pure hydrodynamical isentropic ows, dis-
sipational ows, and nally dissipational ows under the inuence of gravitational
forces. Additionally I have shown that it is possible to self-consistently allow for spa-
tially variable smoothing lengths, which allows the algorithm to be highly adaptive
with the local uid density, but to maintain exact conservation of mass, linear and
angular momentum and energy, to within the integrator tolerance. In the case of
isentropic ows, entropy is also conserved by construction. Furthermore I have also
briey detailed various methods of nding the nearest neighbours, and two means
of evolving the uid ow forward in time.
Since the problems I shall be considering in later chapters require only that
dissipational ow in the presence of gravity to be modelled, this is all that I
have covered here. However this is by no means the limit for the SPH for-
45
Smoothed Particle Hydrodynamics 3.9. Summary
malism. Much eort has been put into including additional physics such as ra-
diative transfer (Nayakshin et al. (2009); Petkova & Springel (2009); Forgan et al.
(2009); Bisbas et al. (2009); Gritschneder et al. (2009); Pawlik & Schaye (2008) and
Altay et al. (2008) to name but few of the recent eorts) and magnetic elds/MHD
(see for instance Price (2010); Dolag & Stasyszyn (2009); Rosswog & Price (2007);
Price & Monaghan (2005, 2004) and Price & Monaghan 2004), and this will no
doubt continue as computing power steadily increases.
As with any numerical scheme however, SPH remains an approximation to real-
ity, and as such reality checks are required in the form of standard tests. These act
as calibration routines, to ensure the the results of any simulations are physically
realistic, and can be relied upon. Many such tests exist, and there are far too many
to do justice to here, but see for instance the astro code wiki
8
, which has a number
of cross-comparison tests with other codes, specically aimed at disc-like models.
As the code I use is a derivative of the one discussed in Price (2005) the discussion
of numerical tests found here is particularly appropriate. A further suite of stan-
dard tests including Sod shocks and Sedov blasts among others, used for both code
verication and comparison, is given in (Tasker et al., 2008).
8
http://www-theorie.physik.unizh.ch/astrosim/code/doku.php?id=home:home
46
References
Altay, G., Croft, R. A. C., & Pelupessy, I.: 2008, MNRAS 386, 1931
Anderson, J. D.: 1995, Computational Fluid Dynamics: The Basics With Applica-
tions, McGraw-Hill
Balsara, D. S.: 1995, Journal of Computational Physics 121, 357
Barnes, J. & Hut, P.: 1986, Nature 324, 446
Bate, M. R., Bonnell, I. A., & Price, N. M.: 1995, MNRAS 277, 362
Bentley, J. L.: 1975, Commun. ACM 18(9), 509
Benz, W.: 1990, in J. R. Buchler (ed.), Numerical Modelling of Nonlinear Stellar
Pulsations Problems and Prospects, p. 269
Bisbas, T. G., W unsch, R., Whitworth, A. P., & Hubber, D. A.: 2009, A&A 497,
649
Cha, S. & Whitworth, A. P.: 2003, MNRAS 340, 73
Cullen, L. & Dehnen, W.: 2010, arXiv:1006.1524
Deegan, P.: 2009, Ph.D. thesis, Univ. Leicester, (2009)
Dehnen, W.: 2000, ApJ 536, L39
Dehnen, W.: 2002, Journal of Computational Physics 179, 27
Dehnen, W.: 2009, Private Communication
Dolag, K. & Stasyszyn, F.: 2009, MNRAS 398, 1678
Dolag, K., Vazza, F., Brunetti, G., & Tormen, G.: 2005, MNRAS 364, 753
47
References References
Fehlberg, E.: 1968, NASA Technical Report, NASA-TR-R-287
Fehlberg, E.: 1969, NASA Technical Report, NASA-TR-R-315
Forgan, D., Rice, K., Stamatellos, D., & Whitworth, A.: 2009, MNRAS 394, 882
Fulk, D. A. & Quinn, D. W.: 1996, Journal of Computational Physics 126(1), 165
Gritschneder, M., Naab, T., Burkert, A., Walch, S., Heitsch, F., & Wetzstein, M.:
2009, MNRAS 393, 21
Hernquist, L.: 1987, ApJS 64, 715
Hernquist, L.: 1993, ApJ 404, 717
Hernquist, L. & Katz, N.: 1989, ApJS 70, 419
Hockney, R. W. & Eastwood, J. W.: 1981, Computer Simulation Using Particles
Inutsuka, S.: 2002, Journal of Computational Physics 179, 238
Kutta, W.: 1901, Zeitschrift fr. Mathematische Physik 46, 435
Landau, L. D. & Lifshitz, E. M.: 1959, Fluid mechanics
Landsho, R.: 1930, Los Alamos Laboratory Report
Lattanzio, J. C., Monaghan, J. J., Pongracic, H., & Schwarz, M. P.: 1985, MNRAS
215, 125
Lodato, G. & Price, D. J.: 2010, MNRAS 405, 1212
Lodato, G. & Rice, W. K. M.: 2004, MNRAS 351, 630
Lombardi, J. C., Sills, A., Rasio, F. A., & Shapiro, S. L.: 1999, Journal of Compu-
tational Physics 152, 687
Monaghan, J.: 1989, Journal of Computational Physics 82(1), 1
Monaghan, J. J.: 1985, Computer Physics Reports 3(2), 71
Monaghan, J. J.: 1992, ARA&A 30, 543
Monaghan, J. J. & Lattanzio, J. C.: 1985, A&A 149, 135
48
References References
Morris, J. P. & Monaghan, J. J.: 1997, Journal of Computational Physics 136(1),
41
Murray, J. R.: 1996, MNRAS 279, 402
Nayakshin, S., Cha, S., & Hobbs, A.: 2009, MNRAS 397, 1314
Nelson, A. F., Wetzstein, M., & Naab, T.: 2009, ApJS 184, 326
Pawlik, A. H. & Schaye, J.: 2008, MNRAS 389, 651
Pearce, F. R.: 2010, Private Communication
Petkova, M. & Springel, V.: 2009, MNRAS 396, 1383
Press, W., Teukolsky, S. A., Vetterling, W. T., & Flannery, B. P.: 2007, Numerical
Recipes the Art of Scientic Computing (3rd Edition), Cambridge University
Press
Price, D.: 2005, arXiv:0507.472
Price, D. J.: 2010, MNRAS 401, 1475
Price, D. J. & Monaghan, J. J.: 2004, MNRAS 348, 139
Price, D. J. & Monaghan, J. J.: 2005, MNRAS 364, 384
Price, D. J. & Monaghan, J. J.: 2007, MNRAS 374, 1347
Quinn, T., Katz, N., Stadel, J., & Lake, G.: 1997, arXiv:astro-ph/9710043
Read, J. I., Hayeld, T., & Agertz, O.: 2010, MNRAS 405, 1513
Rosswog, S.: 2009, New Astronomy Review 53, 78
Rosswog, S., Davies, M. B., Thielemann, F., & Piran, T.: 2000, A&A 360, 171
Rosswog, S. & Price, D.: 2007, MNRAS 379, 915
Springel, V.: 2005, MNRAS 364, 1105
Springel, V. & Hernquist, L.: 2002, MNRAS 333, 649
Springel, V., Yoshida, N., & White, S. D. M.: 2001, New Astronomy 6, 79
49
References References
Steinmetz, M.: 1996, MNRAS 278, 1005
Steinmetz, M. & Mueller, E.: 1993, A&A 268, 391
Tasker, E. J., Brunino, R., Mitchell, N. L., Michielsen, D., Hopton, S., Pearce, F. R.,
Bryan, G. L., & Theuns, T.: 2008, MNRAS 390, 1267
von Neumann, J. & Richtmyer, R. D.: 1950, Journal of Applied Physics 21, 232
Wetzstein, M., Nelson, A. F., Naab, T., & Burkert, A.: 2009, ApJS 184, 298
50

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy