numerical astrophysics: hydrodynamics · outline • numerical experiments are a valuable tool to...

15
Numerical Astrophysics: hydrodynamics

Upload: others

Post on 18-Aug-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Numerical Astrophysics: hydrodynamics

Page 2: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Part 1: Numerical solutions to the Euler Equations

Page 3: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Outline• Numerical experiments are a valuable tool to study astrophysical

objects (where we can rarely do direct experiments).

• Numerical simulations in astrophysics cover a wide range of situations, with many techniques and various degrees of complexity. The most widely used in astrophysics can be roughly divided into:

• N-Body dynamics;

• Fluid dynamics (hydrodynamics, magnetohydrodynamics, SPH...).

• This first series of lectures will provide a hands on approach to numerical hydrodynamics.

• The goal is to write a series of codes to solve the equations of gas dynamics in one dimension, or in multi-dimensions.

• Material (templates and sample codes) will be made available in fortran 90, as well as basic plotting scripts in gnuplot or python (matplotlib).

Page 4: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Hydrodynamics• In order to describe a system of particles as a fluid several conditions

must be met

• The mean free path has to be smaller than the scale-length of the fluctuations of the macroscopic variables (such as density, pressure...).

• The time between collisions must be small compared with the time-scale of changes in the flow.

• The mean distance between particles has to be smaller than the scale-length of the macroscopic variables.

�mfp ⌧ L

tcoll ⌧ tflow

l = n�1/3 ⌧ L

Page 5: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

The Euler equations• We consider a series of fixed volume elements (Eulerian mesh).

• The equations that describe the fluid dynamics in a fixed volume element (disregarding viscous effects) are:

• Mass conservation (continuity)

• Momentum (Newton’s 2nd Law)

• Energy equation

• Along with an equation of state they form a system of 5x5 PDE

@⇢

@t+r · (⇢u) = 0

@E

@t+r · [u (E + P )] = G� L+ fext · u

@(⇢u)

@t+r · (⇢uu) +rP = fext

E =1

2⇢u2 +

P

� � 1

Page 6: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Cartesian coordinates, written in matrix form@U

@t+

@F

@x+

@G

@y+

@H

@z= S

Where

U =

2

66664

⇢⇢u⇢v⇢wE

3

77775, F =

2

66664

⇢u⇢u2 + P⇢uv⇢uw

u(E + P )

3

77775, G =

2

66664

⇢v⇢vu

⇢v2 + P⇢vw

v(E + P )

3

77775, H =

2

66664

⇢w⇢wu⇢wv

⇢w2 + Pw(E + P )

3

77775, S =

2

66664

0fxfyfz

G� L+ f · u

3

77775.

and u = (u, v, w)

conserved variables

x,y, and z fluxes source terms

Page 7: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

• Discretize the x coordinate in N points

• consider a function

• the derivative of f(x) can be approximated by finite differences

Finite differences

xi = x0 + i�x, i = 1, 2, ...N

f 0(x) = limh!0

f(x+ h)� f(x)

h

Remember the formal definition of the derivative

f(x) ! f(xi) = fi

f

xxi xi+1xi�1

f(x)fi+1fi

fi�1

f 0cent(xi) ⇡ fi+1�fi�1

2�x

�x �x

f 0back(x) =

f(x)� f(x��x)

�x=

fi � fi�1

�x

f 0fwd(x) =

f(x+�x)� f(x)

�x=

fi+1 � fi�x

f 0cent(x) =

f(x+�x)� f(x��x)

2�x=

fi+1 � fi�1

2�x

Page 8: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Application of finite differences: FTCS• Discretize space as:

• And time as:

• With this notation

• Then we apply forward difference in time (FT), and centered differencing in space (CS)

• However, it turns out to be unconditionally unstable for hyperbolic equations (i.e. useless for our case)

tn = t0 + n�t; , n = 1, 2, ...

xi = x0 + i�x; i = 1, 2...nx

@F

@x⇡

Fni+1 � Fn

i�1

2�x

@U

@t⇡ Un+1

i �Uni

�t

U(x, t) = Uni

@U

@t+

@F

@x= S ) Un+1

i = Uni � �t

2�x

⇥Fn

i+1 � Fni�1

⇤+�tS

Page 9: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

The Lax-Friedrichs method• Lax fixed the problem of stability of the FTCS by replacing

• Thus the Lax Method reads:

• However, we can not take arbitrarily large values of , they are restricted by a stability criterium.

Uni ! 1

2

⇥Un

i+1 +Uni�1

Un+1i =

1

2

⇥Un

i+1 +Uni�1

⇤� �t

2�x

⇥Fn

i+1 � Fni�1

⇤+�tS

�t

Page 10: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

The advection equation• Consider the linear advection equation

• with initial conditions

• has the solution

@u

@t+ a

@u

@x= 0

@U

@t+

@F

@x= S U = u, F = au, and S = 0) with

u(x, t = 0) = f(x)

f

x

f(x, t = 0) a > 0a < 0

u(x, t) = f(x� at)

Page 11: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Von Neumann analysis• Consider the advection equation

• If one assumes that one has:

• Thus the error follows

• Apply Lax Method to one Fourier mode

• The error grows if

• The condition for stability becomes

• This is the famous Courant-Friedrichs-Lewy stability condition

@u

@t+ a

@u

@x= 0

u = u+ ⇠

true solution error(e.g. truncation)@⇠

@t+ a

@⇠

@x= 0

⇠n+1i =

1

2

⇥⇠ni+1 + ⇠ni�1

⇤+

a�t

2�x

⇥⇠ni+1 � ⇠ni�1

= cos(kx)� j

✓a�t

�x

◆sin(kx)

�����⇠n+1

⇠n

����� > 1

)

�����⇠n+1

⇠n

����� =1

2

�ejk�x + e�jk�x

�+

a�t

2�x

�ejk�x + e�jk�x

⇠(x, t) = ⇠ni = ⇠(t)ejkx = ⇠nejkx; j =p�1

����a�t

�x

���� =|a|�t

�x= Co 1

Page 12: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

General solution strategy (1D):1. Discretize domain in points

2. Initial conditions in the entire domain:

3. Determine the timestep allowed by the CFL condition

4. Calculate the Fluxes

5. Advance the solution, e.g.:

6. Apply boundary conditions

7. At this point and we iterate

�t = C�x|a| , with C < 1

Fni = F(Un

i )

Un+1i =

1

2

⇥Un

i+1 +Uni�1

⇤� �t

2�x

⇥Fn

i+1 � Fni�1

⇤+�tS

n = n+ 1, (t = t+�t)

Nx(+2) i = 0, 1, 2...Nx + (Nx + 1)

Un+10 , Un+1

Nx+1

Page 13: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Example of the advection equation solved with the Lax method• Advection of a regular pulse

• Periodic Boundary conditions: Un+10 = Un+1

Nx, Un+1

Nx+1 = Un+11

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

1.2

v

Advection eq. w/Lax method

t= 0⇥�t

t= 2⇥�t

t= 4⇥�t

t= 6⇥�t

Example code in fortran:advection_lax.f90Gnuplot plotting scriptplot_advection.gplpython (matpotlib) plotting scriptplot_advection.py

Download from:www.nucleares.unam.mx/astroplasmas

i = 0 i = 1 i = (Nx+ 1)i = Nx...i = 2

�x

Page 14: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Task 1:• Write a program (suggestion modify the advection_lax.f90)

to solve the Euler equations.

• Initial conditions: classic Sod tube test

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

Euler equations w/Lax’s Method, t=0.0

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

u

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

Pgas

⇢L = 1.0

⇢R = 0.1 uL = uR = 0

PL = 1.0

PR = 0.125

You will need to changeu(0:nx+1)to u(3,0:nx+1)u(1,i):density at x_iu(2,i): x momentum at x_iu(3,i): total energy density(same with F, UP)Set the initial conditions (see fig)Change output to writedensity, velocity, and PressureThe new CFL condition is

Boundary conditions: ouflow

Integrate only to

�t = min

✓Co �x

|u|+ cs

all domain

Un+10 = Un+1

1 , Un+1Nx+1 = Un+1

Nx

tmax = 0.2

Page 15: Numerical Astrophysics: hydrodynamics · Outline • Numerical experiments are a valuable tool to study astrophysical objects (where we can rarely do direct experiments). • Numerical

Here’s how the Sod tube test solution looks like after t=0.2

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

⇢Euler equations w/Lax’s Method, t=0.2

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

u

0.0 0.2 0.4 0.6 0.8 1.0x

0.0

0.2

0.4

0.6

0.8

1.0

Pgas

contact discontinuity

Rarefaction wave

Shock