numerical astrophysics: hydrodynamics · task 3 (optional): • implement the hll approximate...

13
Numerical Astrophysics: hydrodynamics

Upload: others

Post on 09-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Numerical Astrophysics: hydrodynamics

Page 2: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Part 3: Finite Volumes (Godunov) methods

Page 3: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Euler Equations in integral form: finite volume methods• Integral form of the Euler equations

• Considering spatial average of the quantities in the ith cell

• And time average of the fluxes

• The following exact expression is obtained

ii� 1 i+ 1

i� 12 i+ 1

2

U

x

1

�t�x

Zxi+1/2

xi�1/2

Zt+�t

t

@U(x, t)

@t

+@F (x, t)

@x

�= 0

) 1

�t�x

(Zxi+1/2

xi�1/2

[U(x, t+�t)� U(x, t)] dx

+

Zt+�t

t

⇥F (x

i+1/2, t)� F (xi�1/2, t)

⇤dt

)= 0

U

n

i

=1

�x

Zxi+1/2

xi�1/2

U(x, t)dx

F

n+1/2i+1/2 =

1

�t

Zt+�t

t

F [U(xx+1/2, t)]dx Cell interfaces

U

n+1i

= U

n

i

� �t

�x

hF

n+1/2x+1/2 � F

n+1/2x�1/2

i

Page 4: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Godunov’s method• (for simplicity dropped the tilde from U

and F)

• Estimate the time average fluxes by solving the Riemann problem at each interface

• Exact solution of the Riemann problem requires an iterative method (slow convergence).

• However, there are plenty of methods to solve approximately the Riemann problem (see Toro’s book: Riemann solvers and numerical methods for fluid dynamics: a practical introduction).

w/ piecewise constant data

Fn+1/2i+i/2 ⇡ F(U⇤i+1/2) = F(Un

i ,Uni+1)

U

n+1i = U

ni � �t

�x

hF

n+1/2i+1/2 � F

n+1/2i�1/2

i

ii� 1 i+ 1

i� 12 i+ 1

2

U

x

U⇤i+1/2 = Riemann(Un

i ,Uni+1)

Ui = UL

Ui+1 = UR

Page 5: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Approximate Riemann solvers example: the HLL method

• Harten, Lax and Van Leer (1983)

• Approximate the Riemann problem w/two waves and an intermediate state

• Thus the intercell flux is

• And the solution is advanced in time as

UL

UR

x

t

UR URU⇤

sRsR

U⇤(UL,UR)�sLUR � sLUL � (FR � FL)

sR � SL

sL = min(uL � csL, uR � csR)

sR = max(uL + csL, uR + csR)

FHLLi+1/2 =

8<

:

F(UL) = FL; if sL � 0srFL�slFR+sLsR(UR�UL)

sr�sl; if sL < 0 < sR

F(UR) = FR; if sR 0

Un+1i = Un

i � �t

�x

hFHLL

i+1/2 � FHLLi�1/2

i

Page 6: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Task 3 (optional):• Implement the HLL approximate Riemann solver to a finite volume

program to solve the shock tube test.

• The sample program euler_rusanov.f90 solves the shock tube test with a Godunov method and the Rusanov Fluxes, which are:

• Lambda is the speed magnitude of the fastest wave in the system (see program).

• To implement the HLL you will need (only) to modify the routine that computes the fluxes.

• you have to calculate the left and right wave speeds and modify the fluxes at the interface.

• Compare the results with those obtained with the Lax method with the Godunov scheme with both the Rusanov and the HLL fluxes.

FRUSi+1/2 =

1

2[FL + FR � |�| (UR �UL)]

Page 7: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Second order schemes: piece-wise linear data reconstruction

• add a slope to each cell: piece-wise constant ->piece-wise linear

• Best with the primitive variables

• Now the Riemann problem(s) at the cell interfaces is(are) evaluated with the value extrapolated to the edges of the cells

URi = Ui +

1

2�i

ULi = Ui �

1

2�i

WT = (⇢, vx

, vy

, vz

, P )

ii� 1 i+ 1

i� 12 i+ 1

2

U

x

Ui

URi

ULi+1

Ui+1

Ui�1

ULi

URi�1

Riemann(URi�1,U

Li )

Riemann(URi ,U

Li+1)

Page 8: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Monotonicity (or lack of it)• If we take for instance the central difference to obtain the slope

• Oscillations are because the method is not monotone

• New maxima and minima are introduced in the solution

• In fact, Godunov showed that no method of order higher than 1 is monotone

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, sod tube test, t=0.2

HLLC 1st order

HLLC 2nd order

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

�i =Wi+1 �Wi�1

2

Page 9: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

TVD schemes are designed to preserve monotonicity• Harten introduced the concept of Total Variation Diminishing scheme

• The Total Variation is defined as:

• A scheme is TVD if the TV doesn’t grow with each timestep

• There are plenty of schemes designed to be TVD, the most common are obtained with

• Flux Limiters

• Slope Limiters

TV =

Z ����@U

@x

���� dx

TV n+1 < TV n

ii� 1 i+ 1

i� 12 i+ 1

2

U

x

Ui

Ui+1

Ui�1

�L = (Ui �Ui�1)

�R(Ui�1 �Ui)

�C = Ui+1�Ui�1

2

Introducing new extrema kills monotonicity

Extrapolation with centered difference

Page 10: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Slope limiter approach• Choose the slope and restrict it to avoid introducing new extrema

ii� 1 i+ 1

i� 12 i+ 1

2

U

x

Ui

Ui+1

Ui�1

�Li = (Ui �Ui�1)

�Ri = (Ui�1 �Ui)

�Ci = Ui+1�Ui�1

2

ii� 1 i+ 1

i� 12 i+ 1

2

U

x

Ui

Ui+1

Ui�1

�Li = (Ui �Ui�1)

�Ri = (Ui�1 �Ui)

�Ci = Ui+1�Ui�1

2

if �Ri �

Li 0, then �i = 0

if �Ri �

Li > 0, then �i = average(�L

i ,�Ci ,�

Ri )

Page 11: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Slope limiter example: minmod• This is the most robust, but the most diffusive slope limiter

ii� 1 i+ 1

i+ 12

U

x

Ui

Ui+1

Ui�1

�Li

�Ri

�Ci

Ui+2

i+ 2

ULi+1UR

i

URi = Ui +

�i

2

For the interface i+ 1/2

with�i,minmod =

⇢0; if �L

i �Ri 0

min(�Li ,�

Ri ); if �L

i �Ri > 0

notice the need for 2 “ghost” cells

ULi+1 = Ui+1 �

�i+1

2

not really the minimum but the closest to 0

in fortran is something likes=sign(1.,DeltaL)delta=s*max( 0.,min(abs(DeltaL),s*DeltaR) )

Page 12: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Implementing a simple second order scheme:(1) Start with

(2) Compute the primitives

(3) Do a first order half-timestep, calculating the fluxes from the primitives of (2).

(4) Impose boundary conditions on the new conserved variables

(5) Obtain the new primitives

(6) Do a (slope-limited) linear reconstruction

(7) Solve the Riemann problem at the i+1/2 i-1/2 interfaces

(8) Obtain the updated conserved variables from

(9) Impose boundary conditions on the new conserved variables

(10) and go back to (2)

Un+1/2i = Un

i � �t

2�x

�Fn

i � Fni�1

�+

�t

2Sni

Wn+1/2i = W(Un+1/2

i )

Wn+1/2,Li+1 = Wn+1/2

i+1 � �i

2

Wn+1/2,Ri+1 = Wn+1/2

i+1 +�i

2

Wni = W(Un

i )

Uin

Fn+1/2i+1/2 = Riemann

⇣Wn+1/2,R

i ,Wn+1/2,Li+1

⌘,

Fn+1/2i�1/2 = Riemann

⇣Wn+1/2,R

i�1 ,Wn+1/2,Li

⌘.

t = t+�t

Un+1i = Un

i � �t

�x

hFn+1/2

i+1/2 � Fn+1/2i�1/2

i

Page 13: Numerical Astrophysics: hydrodynamics · Task 3 (optional): • Implement the HLL approximate Riemann solver to a finite volume program to solve the shock tube test. • The sample

Task 4:• Extend to second order one of the Godunov scheme programs that

you have.

• Use slope-limited linear reconstruction of the primitive variables.

• Compare the results with the first order version of the program.

���������������������������������������������������������������������������� ������