Sie sind auf Seite 1von 45

Numerical Hydrodynamics:

A Primer

Wilhelm Kley
Institut fur Astronomie & Astrophysik
& Kepler Center for Astro and Particle Physics Tubingen

Bad Honnef 2016


Hydrodynamics: Hydrodynamic Equations
The Euler-Equations in conservative form read


+ (~u ) = 0 (1)
t
(~u )
+ (~u ~u ) = p + ~k (2)
t
()
+ (~u ) = p~u (3)
t

~u : Velocity, ~k : external forces,  specific internal energy


The equations describe the conservation of mass, momentum and energy.
For completion we need an equation of state (eos):

p = ( 1)  (4)

Using this and eq. (3), we can rewrite the energy equation as an equation
for the pressure
p
+ (p~u ) = ( 1)p ~u (5)
t
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 2
Hydrodynamics: Reformulating
Expanding the divergences on the left side and use for the momentum and
energy equation the continuity equation

+ (~u ) = ~u (6)
t
~u 1
+ (~u )~u = p + ~k (7)
t
p
+ (~u )p = p~u (8)
t
Since all quantities depend on space (~r ) and time (t), for example (~r , t), we
can use for the left side the total time derivative (Lagrange-Formulation). For
example, for the density one obtains
D
= + (~u ) = ~u . (9)
Dt t
The Operator
D
= + ~u (10)
Dt t
is called material derivative (equivalent to the total time derivative, d/dt).
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 3
Hydrodynamics: Lagrange-Formulation
Use now the material derivative
D
= ~u (11)
Dt
D~u 1
= p + ~k (12)
Dt
Dp
= p~u (13)
Dt
These equations describe the change of the quantities in the
comoving frame = Lagrange-Formulation.
For the Euler-Formulation, one analysed the changes at a specific,
fixed point in space !
The Lagrange-Formulation can be used conveniently for
1D-problems, for example the radial stellar oscillations, using
comoving mass-shells.
For the Euler-Formulation a fixed grid is used.
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 4
Numerical Hydrodynamics: The problem
Consider the evolution of the full time-dependent hydrodynamic equations.
The non-linear partial differential equations of hydrodynamics will be solved
numerically Continuum Discretisation

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 5


Numerical Hydrodynamics: Method of solution
Grid-based methods (Euler) Particle methods (Lagrange)

moving Grid/Particle
fixed Grid - flow moved grid
- matter flows through grid
d ~u

~u
 = p
+ ~u ~u = p dt
t Well known method:
Methods: Smoothed Particle Hydrodynamics, SPH
finite differences
non-conservative
Control Volume
conservative
Riemann-solver
wave properties smeared out particles
Problem: Discontinuities good for free boundaries, self-gravity
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 6
Numerical Hydrodynamics: consider: 1D Euler equations
describe conservation of mass, momentum and energy

u
+ = 0 (14)
t x
u uu p
+ = (15)
t x x
 u u
+ = p (16)
t x x
: density
u: velocity
p: pressure
: internal specific energy (Energy/Mass)
with the equation of state
p = ( 1) (17)
: adiabatic exponent
partial differential equation in space and time
need discretisation in space and time.
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 7
Numerical Hydrodynamics: Discretisation

Consider funktion: (x, t)


discretisation in space
cover with a grid
xmax xmin
x =
N

j1 j j+1 X

jn cell average of (x, t) at the grdipoint xj at time t n


Z (j+1/2)x
1
jn = (xj , t n ) (x, nt)dx
x (j1/2)x

jn is piecewise constant. j spatial index, n time step.

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 8


Numerical Hydrodynamics: Integration in time
Consider general equation


= L((x, t)) (18)
t
with a (spatial) differential operator L.
typical Discretisation (1. order in time), at time: t = t n = nt

(t + t) (t) n+1 n
= = L( n ) (19)
t t t
now at a special location, the grid point xj (with moving terms)

jn+1 = jn + tL(kn ) (20)

L(kn ): discretised differential operator L (here explicit)


- k in L(k ): set of spatial indices:
- typical for 2. order: k {j 2, j 1, j, j + 1, j + 2}
(need information from left and right, 5 point Stencil)

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 9


Numerical Hydrodynamics: Operator-Splitting

~
A ~ + L2 (A)
= L1 (A) ~ (21)
t
~ i = 1, 2 individul (Differential-)operators
Li (A),
~ = (, u, ).
applied to the quantities A
Here, for 1D ideal hydrodynamics

L1 : Advection

L2 : pressure, or external forces

To solve the full equation the solution is split in several substeps

~1
A ~ n + tL1 (A
= A ~ n)
~ n+1
A ~2
=A ~ 1 + tL2 (A
= A ~ 1) (22)

Li is the differential operator to Li .

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 10


Numerical Hydrodynamics: advection-step

u
=
t x
(u) (uu)
=
t x
() (u)
=
t x
In explicit conservation form

~u ~f (~u )
+ =0 (23)
t x

for ~u = (u1 , u2 , u3 ) and ~f = (f1 , f2 , f3 ) we have:

~u = (, u, ) and ~f = ( u, uu, u).


This step yields: n 1 = n+1 , un u1, n 1

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 11


Numerical Hydrodynamics: Force terms
Momentum equation
u 1 p
= (24)
t x

1 pj pj1
ujn+1 = uj t for j = 2, N (25)
n+1
j
x

energy equation
 p u
= (26)
t x

pj uj+1 uj
n+1
j = j t for j = 1, N (27)
n+1
j
x

on the right hand side we use the actual values for u,  and p, i.e.
here u 1 , p1 , 1 .
This step yields: u 1 u n+1 , 1 n+1
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 12
Numerical Hydrodynamics: Model equation for advection
The continuity equation was

u
+ =0 (28)
t x

Here, F m = u is the mass flow

Using the notation and u a = const. we obtain the Linear


Advection Equation

+a = 0. (29)
t x
with a constant velocity a, the solution is a wave traveling to the right

using (x, t = 0) = f (x) we get (x, t) = f (x at)

Here f (x) is the initial condition at time t = 0, that is shifted by the advection
with a constant velocity a to the right.
The numerics should maintain this property as accurately as possible.
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 13
Numerical Hydrodynamics: Linear Advection
FTCS: Forward Time Centered Space algorithm

+a =0 (30)
t x
j1 j j+1

Specify the grid :


x j1 xj x j+1
and write
jn+1 jn
n

= (31)
t j t
n n n
j+1 j1
= (32)
x j 2 x
it follows
at
jn+1 = jn n n

j+1 j1 (33)
2x

The method looks well motivated: but it is unstable for all t !


W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 14
Numerical Hydrodynamics: Upwind-Method I
a
+ =0 (34)
t x
or

a t

+a =0 (35)
t x
a: constant (velocity) > 0
(x, t) arbitrary transport quantity

change of in grid cell j in


out
jn+1 x = jn x +t(Fin Fout ) (36)
X
The flux Fin is for constant j j1 j j+1

Fin n
= a j1 (37) purple regions will be trans-
ported into the next neighbour
Fout = a jn (38)
cell
Upwind-Method
Information comes from upstream
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 15
Numerical Hydrodynamics: Upwind-Method II

Extension for non-constant states a t

 
at I (x)
Fin = a I xj1/2 (39)
2

I (x) interpolation polynomial


Here linear interpolation (straight line) in
out
This yields

 n 1 X
Fin = a j1 + (1 )j1 (40) j1 j j+1
| {z } 2
1st Order x xj
I (x) = jn + j (41)
x
| {z }
2nd Order

with = at/x j undivided differences


2nd order upwind

j x I (x) is evaluated in the middle
x xj
of the purple area.

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 16


Numerical Hydrodynamics: Undivided Difference

a) j = 0 Upwind, 1st Order, piece-wise constant


b) j = 21 j+1 j1 Fromm, centered derivative


c) j = j j1 Beam-Warming, upwind slope


d) j = j+1 j Lax-Wendroff, downwind slope

Often used is the 2nd Order Upwind (van Leer) Geometric Mean
(maintains the Monotonicity)

(j+1 j )(j j1 )
2 (j+1 j1 )
if (j+1 j )(j j1 ) > 0
j =

0 otherwise

(42)
The derivatives are evaluated at the corresponding time step level
or the intermediate time step

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 17


Numerical Hydrodynamics: Lax-Wendroff Method
n+1
n+1 j
t Schematic overview of the me-
thod
~ n+1/2 ~ n+1/2
n+1/2 j1/2 j+1/2 uses centered spatial and tem-
t
poral differences
that makes it 2nd order in space
tn
n
j1 jn n
j+1 and time

Using two steps:


predictor-step (at intermediate time t n+1/2 )

1 n n+1/2
n
 
n

j + j+1
j+1/2 = j+1 jn (43)
2 2
The corrector-step (to new time t n+1 )
 
n+1/2 n+1/2
jn+1 = jn j+1/2 j1/2 (44)

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 18


Numerical Hydrodynamics: Example: Linar Advection
(x)
Upwind - (Diffusive)
Linear Advection (N=600,t=40): Upwind, sigma=0.8
1
Analytic
Upwind

0.8

Square function: 0.6

Phi-Achse
Width 0.6 in the intervall [1, 1] 0.4

velocity a = 1, until t = 40
0.2
periodic boundaries
= at/x = 0.8 - (Courant no.) 0
-1 -0.5 0 0.5 1
X-Achse

Van Leer Linear Advection (N=600,t=40): Van Leer, sigma=0.8


Lax-Wendroff - (Dispersive)
Linear Advection (N=600,t=40): Lax Wendroff, sigma=0.8
1 1.4
Analytic Analytic
Van Leer Lax Wendroff
1.2

0.8
1

0.8
0.6
Phi-Achse

Phi-Achse

0.6

0.4
0.4

0.2

0.2 0

-0.2

0 -0.4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
X-Achse X-Achse

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 19


Numerical Hydrodynamics: Stability analysis I
Substitute for the solution a Fourier series (von Neumann 1940/50s)
consider simplifying one component, and analyse its growth properties

jn = V n eij (45)
here, is defined through grid size x and the total length L
2x
= (46)
L
Consider simple Upwind method with = at/x

jn+1 jn + (jn j1
n
)=0 (47)
Substituting eq. (45)
h i
V n+1 eij = V n eij + V n ei(j1) eij

dividing by V n and eij yields


V n+1 
i

= 1 + e 1 (48)
Vn
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 20
Numerical Hydrodynamics: Stability annalysis II
For the square of the absolute value one obtains
n+1 2
V h  i h  i
() n = 1 + ei 1 1 + ei 1

V
   
= 1 + ei + ei 2 2 ei + ei 2
= 1 + (1 )(2 cos 2)
 
2
= 1 4(1 ) sin (49)
2
The method is now stable, if the magnitude of the amplification factor () is
smaller than unity. The upwind-method is stable for 0 < < 1, the
|()| < 1. Rewritten
x
t < fCFL (50)
a
with the Courant-faktor fCFL < 1. Typically fCFL = 0.5.
Theorem: Courant-Friedrich-Levy
There is no explizit, consistent and stable finite difference method which is
unconditionally stable (i.e. for all t).
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 21
Numerical Hydrodynamics: Modified Equation I
Consider again Upwind method mit = at/x

jn+1 jn + (jn j1
n
)=0 (51)
substitute differences by derivatives, i.e. Taylor-series (up to 2. order)
1 2
 
1 2 3
t + t +O(t )+ x x +O(tx 2 ) = 0
2
t 2 t x 2 x 2
(52)
divied by t, and substitute for
2
 
1
+a + t a 2 x + O(t 2 ) + O(x 2 ) = 0 (53)
t x 2 t x
Use wave equation tt = a2 xx modified equation (index M)
M M 1 2 M
+a = ax (1 ) (54)
t x 2 x 2
The FDE adds a new diffusive term to the original PDE
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 22
Numerical Hydrodynamics: Modified Equation II
with the diffusion coefficient
1
D= ax (1 ) (55)
2
Note: only for D > 0 this is a diffusion equation, and it follows < 1
for stability. (Hirt-method). For Upwind-Method D > 0 Diffusion.
Lax-Wendroff yields
M t 2 a  2  3
+a M = 1 M
(56)
t x x 3
The equation has the form
t + ax = xxx (57)
2
t a 2 
1= (58)

This implies Dispersion. Here: waves are too slow ( < 0)
Oscillations behind the diskontinuity (cp. square function)
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 23
Numerical Hydrodynamics: The time step
From the above analysis: the time step t has to be limited for a
stable numerical evolution.
For the linear Advection (with the velocity a) we find
x
t < (59)
a
In the more general case the sound speed has to be included and it
follows the Courant-Friedrich-Lewy-condition
x
t < (60)
cs + |~u |
physically this means that information cannot travel in one timestep
more than one gridcell. Typically one writes
x
t = fC (61)
cs + |~u |
with the Courant-Factor fC . For 2D situations: fC 0.5.
Only for impliciten methods there are (theoretically) no limitations of t.
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 24
Numerical Hydrodynamics: Time step size - graphically

The numerical region of dependence (dashed line) should be larger


than the physical one (gray shaded area) since x/t > a.
The complete information from inside the physical sound cone
should be considered.

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 25


Numerical Hydrodynamics: Multi-dimensional

Grid definition (in 2D, staggered): Fluxes across cell boundaries


skalers in cell centers Top: mass flux
(hier: , , p, v3 , ) bottom: X-momentum (griud shifted)
Vectors ar interfaces
(here: v1 , v2 )

from: ZEUS-2D: A radiation magnetohydrodynamics code for astrophysical flows in


two space dimensions. I in The Astrophysical Journal Suppl., by Jim Stone and Mike
Norman, 1992.
Use Operator-Splitting and Directional Splitting: The x and y direction are dealt
with subseuqently. First x-scans, then y -scans.

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 26


Numerical Hydrodynamics: Summary: Numerics
Numerical methods should resemble the conservation properties.
write equations in conservative form
Numerical Methods should resemble the wave properties.
Shock-Capturing methods, Riemann-solver
Numerical Methods should control discontinuites.
need diffusion ( stability)
either explicitly (artificial viscosity) or intrinsically (through method)
Numerical methods should be accurate
min. 2nd order in space and time
Freely available codes:
ZEUS: http://www.astro.princeton.edu/~jstone/zeus.html
classical Upwind-Code, 2nd order, staggered grid, RMHD
ATHENA: https://trac.princeton.edu/Athena/
successo of ZEUS: Riemann solver, centered grid, MHD
NIRVANA: http://www.aip.de/Members/uziegler/nirvana-code
3D, AMR, finite volume code, MHD
PLUTO: http://plutocode.ph.unito.it/
3D, relativistic, Riemann-solver/finite volume, MHD
GADGET:
W. Kley http://www.mpa-garching.mpg.de/galform/gadget/
Numerical Hydrodynamics: A Primer Bad Honnef 2016 27
Hydrodynamics: Wave structure

Consider one-dimensional equtions (motion in x-direction):


From Euler equations: With p = ( 1) and separation of derivatives

u u
t + x = 0 t + u x + x = 0
u uu p u u 1 p
t + x = x = t + u x + x = 0
 u u p p u
t + x = p x t + u x + p x = 0

As Vector equation
W W
+A =0 (62)
t x
mit
u 0
W= u und A= 0 u 1/ (63)
p 0 p u
Equations are non-linear and coupled.
Try decoupling: Diagonalisation of A

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 28


Hydrodynamics: Diagonalisation
Eigenvalues (EV)

u 0
u 1/
det(A) = 0 u 1/ = (u )
p u
0 p u
h i
= (u ) (u )2 p/ = 0 (64)
It follows
0 = u
(65)
= u cs
with the sound speed
p
cs2 = (66)

The Eigenvalues are the charakteristic velocities,
with which the information is spreading.
It is a combination of fluid velocity (u) and sound speed (cs )
3 real Eigenvalues A diagonalisable

Q1 AQ = (67)

Q is built up from the Eigenvalues to the EV (i , i = 0, +, ), is a diagonal matrix.


W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 29
Hydrodynamics: Charakteristic Variables
For Q it follows
1 0 c12

1
12 cs

1 2 cs s
Q= 0 1 1 und Q1 = 0 1 1

2 2 cs
1 1
0 2 cs 2 cs 0 1 c1 s

We had
W W
+A =0 (68)
t x
and
Q1 AQ =
Define:
dv Q1 dW also dW = Qdv (69)
1
Multiply eq. (68) with Q
v v
+ =0 (70)
t x
v = (v0 , v+ , v ) are the charakteristic Variables: vi = const. in curves
dx
= i
dt
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 30
Hydrodynamics: The variable v0
from the definitions
1
dv0 = d dp (71)
cs2
v0 v0
+ 0 =0 mit 0 = u (72)
t x
What is dv0 ?
From thermodynamics (1. Law) for specific quantities)
   
1 p 1
Tds = d + p d = d 2 d (73)

with p = ( 1),  = cv T , = cp /cv it follows
 
cp dp cp
ds = d 2 = dv0 (74)
cs
s s
+u
= =0 (75)
t x
i.e. s is const. along stream lines, hence
ds
=0 (76)
dt

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 31


Hydrodynamics: Riemann-Invariants

For the additional variables


v v
+ (u cs ) =0 (77)
t x
with
1
dv = du dp (78)
cs
it follows Z
dp
v = u
. (79)
cs
Let the entropy constant everywhere (i.e. p = K )
2cs
= v = u (80)
1
Riemann-Invariants: v = const. on curves
dx
= u cs
dt

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 32


Hydrodynamics: Steepening of sound waves
Linearisation of the Euler-equation resukts in the wave equation for the
perturbations:
1 2 1 Example for (receeding) shock wave
= cs2 2
(81)
t x
but: cs is not constant steepening

Diskontinuities
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 33
Examples: Shocktube
Initial discontinuity in a tube at position x0 (one-dimensional)
Riemann-Problem Jump in pressure (p) and density
Bereich 2 Bereich 1
()
Diskontinuitt

P 2
Evolution:
- a shock wave to the right (X4 )

2
(supersonically ush > cs )

- a contact discontinuity
1
density jump (along X3 )
P1
- a rarefaction wave
x0 (between X1 and X2 )

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 34


Examples: Sod-Shocktube
A standard test problem for numerical hydrodynamics, x [0, 1] with
X0 = 0.5, = 1.4
1 = 1.0, p1 = 1.0, 1 = 2.5, T1 = 1 and 2 = 0.1, p2 = 0.125, 2 = 2.0, T2 = 0.8
Hier solution with van Leer method (at time t = 0.228 after 228 time steps:)
Shock-Tube: Sod; Mono: Geometric Mean; Nx=100, Nt=228, dt=0.001
1 1
0.9 0.9
0.8 0.8
0.7 0.7
0.6 Red: Exact
Velocity

Density
0.6
0.5
0.4
0.5
0.4
Green: Nume-
0.3
0.2 0.3 rics
0.1 0.2
0
0 0.2 0.4 0.6 0.8 1
0.1
0 0.2 0.4 0.6 0.8 1
The solution is:
1.15 1 self similar
1.1
1.05
0.9
0.8
obtained
through stret-
Temperature

1 0.7
Pressure

0.95 0.6
0.9 0.5 ching
0.85 0.4
0.8 0.3
0.75 0.2
0.7 0.1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
X-Axis X-Axis
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 35
Examples: Sedov-Explosion
An example for bomb explosions (Sedov & Taylor, 1950s), analytical solution (Sedov)
Basic setup for Supernovae-outbusts, e.g. estimate of the remnant size
Standard test problem of multi-dimensional hydrodynamics, e.g. for
x, y [0, 1] [0, 1]
Energy-Input at origin, E = 1, in = 1, = 1.4, 200 200 grid points
Here: solution with van Leer method (solve for total energy variable). Plotted: density

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 36


Examples: Water droplet: SPH
Water sphere (R=30cm), Basin (1x1 m, 60cm high) Incl. surface tension,
time in seconds (TU-Munchen, 2002)

(Website)
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 37
Examples: Ster formation: SPH

Molecular Cloud

Mass:
50 M

Diameter:
1.2 LJ = 76,000 AU

Temperature:
10 K

(M. Bate, 2002)

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 38


Examples: Kelvin-Helmholtz Instability I

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 39


Examples: Kelvin-Helmholtz Instability II

Direct comparision: moving < > fixed grid


Left: Moving grid (Voronoi-Tesselation)
Right: fixed square grid (Euler)
with grid motion displayed

(Kevin Schaal, Tubingen)


Youtube channel

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 40


Examples: Kelvin-Helmholtz Instability III

(Boulder (NCAR), USA)


W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 41
Examples: Rayleigh-Taylor Instability
PPM Code, 128 Nodes, ASCI Blue-Pacific ID System at LLNL
5123 Grid Cells (LLNL, 1999)

(Web-Link)
W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 42
Examples: Diesel Injection
Finite Volumen Method (FOAM)
Velocity, Temperature, Particles (+Isosurfaces) (Nabla Ltd, 2004)

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 43


Examples: Cataclysmic Variable: Grid
.6

.4

.2

0
y

.2

.4

.6
1 .8 .6 .4 .2 0 .2 .4 .6
x

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 44


Examples: Kataclysmic Variable: Disk formation
RH2D Code, Van Leer slope
5122 Gridpoints, mass ratio: q = m2 /m1 = 0.15

W. Kley Numerical Hydrodynamics: A Primer Bad Honnef 2016 45

Das könnte Ihnen auch gefallen