Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture I & II: Foundations of Numerical HydroDynamics

Similar presentations


Presentation on theme: "Lecture I & II: Foundations of Numerical HydroDynamics"— Presentation transcript:

1 Lecture I & II: Foundations of Numerical HydroDynamics
Yuichiro Sekiguchi (Yukawa Institute for Theoretical Physics)

2 Linear scalar advection equation
The essence of hydrodynamic equations is propagation of waves Let us consider the following advection equation as a prototype Most of important ingredients are included in this equation The 1D Euler equation may be written in the following form (Lecture II) The exact solution for this equation is given by The initial (t=0) profile is parallel-transported in x-direction by ct Let us try to solve this simple equation numerically

3 Finite difference method
Let us discretize the spacetime uniformly with Δx (and Δt) and then introduce the following notation Using the Taylor expansion around xj , We obtain finite difference expressions for the spatial derivative Finite differentiations in time go in a similar manner Note: central difference (of 1st order derivative) in uniform grid is 2nd order in Δx Exercise: consider finite difference expressions for 2nd order derivative

4 FTCS scheme (1) Let us adopt Forward-difference in Time & Central-difference in Space (FTCS) scheme 2nd order in Δx and 1st order in Δt : seems to be the better method The right-hand-side term is written by n-step quantities only ⇒ We can evaluate the (n+1)-step quantities straightforwardly (explicitly) A test problem: propagation of a block pulse Initial condition : CFL number : 0.25 Here we introduced the CFL number Lab Exercise: Make a code based on the FTCS scheme and solve the test problem

5 FTCS scheme (2) FTCS Result: A snapshot of the result at n=40 step. It can be seen that oscillation occurs and amplitude of the oscillation increases with time (unstable). A scheme which seems to work well fails to produce the correct result…..

6 What is wrong with FTCS scheme ?
Truncation term analysis Substitute the Taylor expansions into the finite-difference equation We obtain FTCS scheme intrinsically contains negative diffusion and dispersion Negative diffusion enhances gradients (the oscillations or small perturbation) Dispersion drives oscillatory behavior of amplitude We may capture the properties of the adopted scheme like this This procedure is applicable to finite differentiation of any hyperbolic system, such as Einstein equations negative diffusion dispersion term Exercise: Verify this result

7 What is wrong with FTCS scheme ?
von Neumann’s stability analysis Let us see how the amplitude of the following Fourier mode grows The exact solution must satisfy so that the amplitude is unchanged and only the phase shifts

8 What is wrong with FTCS scheme ?
von Neumann’s stability analysis Substituting the mode to the FTCS scheme, we obtain The amplification coefficient for the amplitude is so that the amplitude grows exponentially (unstable !!) The phase is given by The phase for higher frequency modes delay more ! The reason why the oscillations are retarded Exercise: Check this statement by plotting φ

9 Lax’s theorem For the importance of the stability, the following theorem exists Consistency: a finite difference scheme is said to be consistent when it satisfies the following condition : Convergency: a finite difference scheme has convergency when it satisfies the following condition : In short, (as consistency is satisfied usually) the stability is the most important property for numerical schemes FTCS scheme is not stable, and hence, cannot produce the correct result Lax’ theorem (Lax 1968) : For the consistent scheme, the necessary and sufficient condition for the convergency is the stability

10 Lax’s scheme Lax proposed the following modification to the FTCS scheme The result of the previous test problem in Lax’s scheme : CFL number : 0.25 Lax’ scheme : No unstable behavior but the discontinuities are obscured (due the numerical viscosity of Lax’s scheme (explained later)) Lab Exercise: Modify the FTCS code to implement Lax’s scheme and solve the test problem

11 Stability of Lax’s scheme & CFL condition
According to von Neumann’s stability analysis, the amplification coefficient of Lax’s scheme is Thus, Lax’s scheme is stable if the following CFL condition holds Intuitive meaning of the CFL condition If the CFL condition is not satisfied, propagation speed of numerical information is less than that of physical signal Physical domain is not contained in the numerical domain Insufficient information region ! Exercise: Verify this result Insufficient information Physical speed Numerical speed

12 On viscous nature of Lax’s scheme
Property of a scheme may be understood by truncation error analysis Substituting the Taylor expansion expressions into the scheme We obtain for Lax’s scheme Lax’s scheme intrinsically contains (strong) viscous/diffusive nature For small values of CFL number, Lax’s scheme is stable but rather diffusive For νCFL = 1, the diffusion term disappears (but may become unstable) Exercise: Verify this result diffusion term Lab Exercise: Check how the numerical result changes according to the CFL number

13 Upwind scheme (1) Curves determined by is called characteristics
u is conserved along the characteristics since Then we have In the 2nd line we used the linear interpolation (see Fig.) This scheme is the upwind (linear Godunov) scheme Upwind difference

14 Upwind scheme (2) : properties
Exercise: Verify these results Properties of the upwind scheme is stable if the CFL condition is satisfied : ∵ According to von Neumann’s stability analysis, the amplification factor is contains the diffusion term but the diffusivity is weaker than Lax’s scheme ∵ According to the truncation term analysis, the upwind scheme gives For example, the diffusion term is smaller by factor 1/3 for νCFL = 0.5 Alternatively, Lax’s scheme and the upwind scheme can be written as The ‘diffusion term’ is smaller in the upwind scheme

15 Upwind scheme (3) : conservative form
The upwind scheme, applicable to both positive/negative characteristic velocity, is Let us rewrite the scalar equation in the following conservative form Then, the change of u in the unit cell is described by the difference of flux f at the cell boundaries The finite difference expression is Here we have introduced, Gj+1/2 , called numerical flux λ is characteristic velocity at cell boundary, which is λ = c in this case How to determine Gj+1/2 is the central issue in Numerical HydroDynamics This modern conservative form is adopted in Numerical HydroDynamics We will see importance of conservative form later in non-linear problem and Euler equation Exercise: Verify this result

16 A physically motivated scheme gives a good result !
Upwind scheme (4) Lab Exercise: Solve the test problem by the upwind scheme CFL number : 0.25 Upwind : A snapshot of the result at n=40 step. The discontinuities are more sharply captured than Lax’s scheme, indicating less numerical viscosity A physically motivated scheme gives a good result !

17 Summary FTCS (Forward-difference in Time and Central-difference in Space) scheme cannot solve the linear scalar wave equation Truncation-term analysis von Neumann stability analysis Lax’s theorem : importance of stability Lax’s scheme is stable but rather diffusive CFL condition Analysis of its viscous nature by von Neumann stability analysis Upwind scheme shows a good performance Characteristics Conservative form Numerical flux

18 Extension to nonlinear equation
As a representative of nonlinear model, let us consider (inviscid) Burgers equation : Let us try to solve Burgers equation by the upwind scheme This is finite differentiation in the non-conservative form (explained later again) A test problem: propagation a block pulse Initial condition : CFL number : , Show result at t = 20 Note that the CFL number for Burger’s equation is given by from which Δt is determined Note: This is one of reasons why we prefer less diffusive scheme. In linear problems, a diffusive scheme with high CFL number would be sufficient.

19 Burgers equation Non-conservative form : A snapshot of the result at t=20. The left initial discontinuity turns to be a rarefaction wave while the right discontinuity, which should be a shock wave, does not move. Finite difference schemes in non-conservative form do not give correct results !

20 Conservative form and apply the upwind scheme
If we apply the conservation law for a unit cell, we have So, the following finite differentiation is well-motivated Fj+1/2 is sometimes denoted by Gj+1/2 and called numerical flux How to determine the numerical flux is the key problem in Numerical HydroDyn. Now, let us rewrite Burgers equation in the conservative form and apply the upwind scheme Note: For nonlinear problems , we need to specify a form for λ Here let us adopt Roe scheme:

21 Shock wave velocity How fast does the shock wave propagate ?
Let us denote the left (right) state of the shock with subscript L (R) Taking a frame ( Δx & Δt ) in which the characteristics of the shock wave is diagonal line Then the conservation argument gives For Burgers equation : This relation is also known to as the Rankine-Hugoniot relation, which will be used in Lecture 2 (remember !) shock wave

22 Burgers equation (conservative form)
Conservative form : A snapshot of the result at t=20. Propagations of both the rarefaction and shock waves are followed correctly Importance of taking conservative form is highlighted

23 Characteristic decomposition
For simplicity, let us consider isothermal gas with P = Kρ Then the basic equations of hydrodynamics are simplified as where the Jacobian matrix A is Now let us diagonalize A We can also ‘diagonalize’ the basic equations the hydrodynamic equations constitute a set of (nonlinear) wave equations we may apply the upwimd/Godunov-type scheme to determine the numerical flux

24 Characteristic decomposition
Then we may pull back the numerical flux to the original frame to obtain Recall that the invariant along the characteristics plays a key role in the upwind scheme All important ingredients are included in the (nonlinear) scalar wave equation This characteristic decomposition is fundamentally important in hydrodynamics and magnetohydrodynamics Further discussions will be given in the next lecture Exercise: Verify these results and consider the meaning of λ’s

25 Summary Burgers equation contains important ingredients to solve the hydrodynamic equations Importance of conservative form Usefulness of numerical flux Shock and rarefaction wave (lab exercises) Characteristic decomposition of the hydrodynamic equations A set of nonlinear scalar wave equations

26 Higher-order scheme All the schemes considered so far is 1st order scheme (but for FTCS) Let us make a 2nd order (in both time and space) scheme in the form Substituting the Taylor expansions of ujn+1 , unj-1 , and unj+1 and comparing 0th, 1st and 2nd order terms we obtain The resulting scheme is known to as Lax-Wendroff scheme memo. : The truncation terms in finite-differentiation of the time- and spatial derivatives cancel each other to give the 2nd order scheme Exercise: Verify this result

27 Lax-Wendroff scheme von Neumann’s stability analysis
Lax-Wendroff scheme is stable if the CFL condition is satisfied 2-step formulation of Lax-Wendroff scheme and the numerical flux Lax-Wendroff scheme is equivalent to the following 2-step scheme The 1st step can be regarded as evolution to (n + 1/2) step and u* = u n+1/2 Such a 2-step scheme is useful to extend 1st order (in time) scheme to 2nd order The expression in terms of the numerical flux is applicable to nonlinear problems Exercise: Verify this result

28 Lax-Wendroff scheme Lax Wendroff : A snapshot for the test problem at n=40 step with CFL number = 0.25 ・ The discontinuities are more sharply captured than Lax’s scheme ・ Oscillations are generated behind the discontinuities Lab Exercise: Solve the test problem by the Lax-Wendroff scheme and check how the result depends on the CFL number

29 On oscillatory nature of Lax-Wendroff scheme
The truncation term analysis for Lax-Wendroff scheme gives There is a dispersion or oscillatory term which causes oscillation of amplitude This is a version of the KdV (Korteweg–de Vries) equation The oscillatory term disappear for νCFL = 1 The dispersion term may generate new local extrema ! In fact, all higher order schemes have this type of oscillatory nature !

30 Godunov’s theorem and Monotonicity
For (linear) higher order schemes, undesirable oscillations appear In fact, this is inevitable for linear higher order scheme We cannot make a linear, monotone higher order scheme in the form : For the monotone scheme, 0 < ck < 1 is necessary For a monotone increasing initial profile, ck > 0 is necessary to preserve monotonicity ck < 1 is required so that local maximum (minimum) is non-increasing (non-decreasing) But this is impossible for higher order schemes, we have at least one negative ck Monotone higher order scheme must be nonlinear (ck’s are not constant) Godunov’ theorem (Godunov 1954) : Linear numerical schemes for solving partial differential equations, having the property of not generating new extrema (monotone scheme), can be at most first-order accurate

31 Summary Higher order schemes inevitably generate oscillations
Example of Lax-Wendroff scheme Truncation-term analysis Godunov’s theorem Notion of monotonicity (scheme which generates no new extrema)

32 Ways to avoid the numerical oscillation
According to Godunov’s theorem, any linear higher order schemes cannot preserve monotonicity and cause oscillation There are two ways to resolve this problem Starting from a higher order scheme, modify or limit the numerical flux to satisfy 0 < ck < 1 , so that the monotonicity be preserved MUSCL (Monotone Upstream Scheme for Conservation Laws) method : Based on the 1st order upwind scheme, sophisticate the numerical flux by introducing more ‘accurate’ quantities uL & uR at the cell boundary Note that the 1st order upwind scheme is monotone The introduction of the accurate quantities at the boundary is done so that the monotonicity is not violated

33 MUSCL scheme (1) In the 1st order upwind scheme, the physical quantities in [ xj-1/2, xj+1/2] are considered to have constant values In the MUSCL scheme, they are assumed to have some distribution in the cell First, let us consider that the physical quantities have the linear distribution Note that the spatial derivative is evaluated using both Δj-1/2u and Δj+1/2u Similarly, we have The numerical flux evaluated from these quantities will be 2nd order accurate

34 MUSCL scheme (2) : flux limiter
Substituting these expressions to the upwind scheme, we obtain For the monotone condition to be satisfied, we need 0 < Cj±1/2 < 1 For the difference terms L & R, let us introduce the following flux limiter function to suppress the appearance of local extrema If x and y have different sign, the gradient is set to zero (upper figure) If x and y have the same sign, take the gradient whose absolute value is small (lower figure)

35 MUSCL scheme (3): compression factor
Here, let us assume the characteristic speed is positive (c > 0) Under the flux limiter it can be shown that The monotone condition for Cj+1/2 is automatically satisfied. The condition for Cj-1/2 can be satisfied if we impose a more restrictive CFL condition : νCFL < 2/3 The lower band of the monotone condition inequality has a room to relax the flux limiter by introducing the compression factor b : In this case, Cj-1/2 satisfies so that as long as 1 < b < 2, the monotone and CFL conditions are satisfied without any modification

36 MUSCL scheme (4) : quadratic distribution
Let us extend the previous discussion to the case of quadratic distribution The quantities at the cell boundary are These results are derived in later slides (for those who interested in the derivation) The compression factor must be 1 ≦b ≦ 4 Using these values, the numerical flux is evaluated as (1st order upwind) And solve the equation according to

37 MUSCL scheme (5) : general formulation
Introducing a parameter κ, the MUSCL scheme is generalized so that it represents both 2nd (linear) and 3rd order (quadratic) schemes κ = -1 : 2nd order fully upwind (the previous linear distribution case) κ = 1/3 : 3rd order upwind (quadratic distribution) The compression factor should satisfy

38 MUSCL scheme (6) MUSCL Upwind : A snapshot at n=40 step with CFL number = 0.25, b=2, 3rd order MUSCL ・ The discontinuities are more sharply captured than the 1st order upwind scheme ・ NO oscillations are generated behind the discontinuities Exercise: Solve the test problem by the MUSCL upwind scheme and check how the result depends on the compression factor b

39 Finite volume method (1)
To derive the previous results, let us introduce notion of the Finite Volume Method (FVM) , on which the MUSCL scheme is based In the FVM, the cell value uj represents the average of u(x) in the cell : Not the value at x = xj : uj = u(xj) The dash denotes the spatial derivative Substitute the Taylor expansion to these integrals, we obtain Substituting back u(xj) to the Taylor expansion, we have quadratic distribution The quantities at cell boundary is evaluated as

40 Finite volume method (2)
The quantities at cell boundary are given by The FVM expressions of the derivatives are Substituting them, we obtain Finally, applying the limiter function to the gradient terms, we reach the desired result

41 Summary Higher order schemes inevitably generate oscillations
To avoid the oscillations, we use the MUSCL (Monotone Upstream Scheme for Conservation Laws) scheme The discontinuities are captured more sharply Flux limiter Compression factor Finite Volume Scheme

42 Treatment of rarefaction wave
In the numerical flux, the characteristic velocity at the cell boundary λj+1/2 is necessary Previously, we adapted Roe scheme for this : In Roe scheme, shock wave and rarefaction wave are not distinguished and the rarefaction wave become unphysical rarefaction shock, where the entropy decreases To overcome the situation, the characteristic velocity is modified as or you may use van Leer scheme : For Burgers Eq.

43 Treatment of rarefaction wave
Exercise : For Burgers equation with initial condition Show that the exact solution at t = 0.4 is Solve this problem with the upwind scheme and compare results for the different characteristic velocity (Roe, modified Roe, van Leer) Make an animation (you will see how the shock wave is formed)

44 2nd order in time Let us remind that Lax-Wendroff scheme is 2nd order in time and it is reformulated as the following 2-step scheme Simply generalizing this, we can make 2nd order schemes as follows: The stability property of the new 2nd (higher) order scheme should be analyzed

45 Examples of numerical codes
Yuichiro Sekiguchi (Yukawa Institute for Theoretical Physics)

46

47

48

49

50 Yuichiro Sekiguchi (Yukawa Institute for Theoretical Physics)
How to install cygwin Yuichiro Sekiguchi (Yukawa Institute for Theoretical Physics)

51 Downloading cygwin Go to the cygwin installing page and download exe file Chose 32-bit version or 64-bit version depending on your laptop

52 Installing cygwin Run the downloaded exe file

53 Installing cygwin Go ahead with default setting …
Choose a domestic download-site

54 Installing cygwin Click ‘All’ tab and change ‘Default’ to ‘Install’
Click next to start download and install … wait a moment

55 Checking to create the icons

56 How to use cygwin Launch the cygwin and type ‘xinit’, then you will have x-window Check if gnuplot and gfortran are installed by typing “which gnuplot” and “which gfortran”

57 Yuichiro Sekiguchi (Yukawa Institute for Theoretical Physics)
Tips for Lab Course Yuichiro Sekiguchi (Yukawa Institute for Theoretical Physics)

58 How to compile and run To run the execution file, type
If you want to compile a file, for example, ‘FTCS.f90’, type Then you will have a execution file, ‘a.exe’ To run the execution file, type

59 How to use GNUPLOT GNUPLOT will start if you type
To load a gnuplot file, for example, ‘FTCS.gnu’, type

60 FTCS.gnu You can change x-range (set xr), x-label (set xlabel), scale-markings (set xtics; set mxtics), position of caption (set key) file names

61 How to make an animation
Prepare time-series data with 2-line blank (see following format) Then use ‘anim.sh’ to make an animation Data 2-line blank (important point)

62 anim.sh You can change total step number (imax) and file names

63 How to make an animation
If you run ‘anim.sh’, you will have a number of gif file To make animation, type Then you will have an animation file ‘anim.gif’, which can be open using browsers


Download ppt "Lecture I & II: Foundations of Numerical HydroDynamics"

Similar presentations


Ads by Google