Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban...

34
Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal

Transcript of Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban...

Page 1: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 1

An Introduction to Numerical Methods

For Weather Predictionby

Joerg Urbanoffice 012

Based on lectures given by Mariano Hortal

Page 2: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 2

Shallow water equations in 1 dimension

)(

)(

x

hK

xx

uh

x

hu

t

hx

uK

xx

hg

x

uu

t

u

advection adjustement diffusion

u … velocity along x directionh … absolute heightg … acceleration due to gravityK …diffusion coefficient

Non linear equations

Velocity is equalin layers vertical direction (shallow)

h

Page 3: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 3

Linearization

u=U0+u’h=H +h’

Const. + perturb. in the x-comp. of velocityConst. + perturb. in the height of the free surface

Substitute and drop products of perturbations

''''

''''

2

2

0

2

2

0

hx

Kux

Hhx

Uht

ux

Khx

gux

Uut

Small perturbations

Page 4: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 4

Classification of PDE’s• Boundary value problems( ) ( )

( ) ( )

L f x

B g x

Dx

Dx

D

ΓD

f, g: known function; L, B: differential operatorφ: unknown function of x

0

( ) ( )

t

L f t

g

φ: unknown function of t

t=0 t

• Initial value problems (most important to us)

open domain

boundary

Page 5: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 5

• Initial and boundary value problems

• Eigenvalue problems

Classification of PDE’s (II)

0

( ) ( , )

( )

( ) ( , )t

L f x t

g x

B h t

( )L φ: unknown eigenfunctionλ: eigenvalue of operator L

Page 6: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 6

Existence and uniqueness of solutions

),( ytfdt

dy ; y(t0)=y0 (initial value problem)

•Does it have a solution?•Does it have only one solution?•Do we care?

If it has one and only one solution it is called a well posed problem

Page 7: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 7

Picard’s TheoremLet

y

f

f and be continuous in the rectangle

byy

atttR

0

00: then, the initial-value problem

00 )(

),(

yty

ytfdt

dy Has a unique solution y(t)on the interval attt 00

Finding the solution (not analytical)Numerical methods (finite dimensions)

Page 8: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 8

Discretization

• Finite differences

• Spectral

• Finite elements

Transform the continuous differential equationinto a system of ordinary algebraic equations where the unknowns are the numbers fj

M

jjj xfxf

1

)(~)(

Njxfxf j .....1),(~)(

Page 9: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 9

• Convergence

• Consistency

• Stability

• Lax-Richtmeyer theorem

Discretized equation ---------> continuous equation

The Lax-Richtmeyer theorem

Discretized solution ---------> continuous solution

discretization finer and finer

Discretized solution bounded

If a discretization scheme is consistent and stablethen it is convergent, and vice versa

Page 10: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 10

Finite Differences - Introduction1 j-1 j j+12 N N+1

<------------------------------- L ---------------------------------->

Taylor series expansion:

2 31

2 31

1 1' '' ( ) ''' ( ) ....

2! 3!1 1

' '' ( ) ''' ( ) ....2! 3!

j j j j j

j j j j j

x x x

x x x

1,........, 1j jx x j N

x

Page 11: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 11

Finite differences approximations1

1 1

1 1 2'' ''' ( ) ..2! 3!

' .j jj j jwhere E x xE

x

forward approximation Consistent if … are bounded

12 2

1 1 2'' ''' ( ) ..2! 3!

' .j jj j jwhere E x xE

x

backward approximationadding both

1 1 1 2''' ( ) ..3!

' .2

j jj jwhere E xE

x

centered differences

" "', ,j j

Consistent if … are bounded"' ,j

Page 12: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 12

Finite differences approximations (2)

Also

1 1 2 2 44 1' ( )

3 2 3 4j j j j

j O xx x

1 1 22

2'' ( )

( )j j j

j O xx

fourth order approximation to the first derivative

second order approximation of the second derivative

Using the Taylor expansion again we can easily get the second derivative:

Page 13: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 13

The linear advection equation

00

xU

t00

xU

t+ initial and boundary conditions

We start with a guess: )()(),( tTxXtx

Substituting we get: 00 1

UCdt

dT

Tdx

dX

X

U

TUdt

dT

Xdx

dX

0

Eigenvalue problems for

tU

x

eTT

eXX0

0

0

dt

dand

dx

d

With periodic B.C. λ can only have certain (imaginary) values where k is the wave number ik

The general solution is a linear combination of several wave numbers

Page 14: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 14

The linear advection equation (2)

The analytic solution is then:

)(),( 0)(

0)(

0000 tUxfeeTXtx tUxtUx

Propagating with speed U0

For a single wave of wave number k the frequency is ω=kU0

No dispersion

Energy: L

dxtE0

2

2

1)(

022 0

20

0

20

L

L Udx

x

U

t

EFor periodic B.C.:

Page 15: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 15

Space discretization

xxjj

j

211

dt

d

xU

tjjjj

211

0 ( ) ( )jikj xt t e

0)sin(

0

xk

xkikU

dt

d

whose solution is ikcte 0 with 0

sin( )( )

k xc k U

k x

U0

c

kΔx

The phase speed c depends on k dispersion

kΔx= π ---> λ=2Δx ==> c=0

centered second-order approximation

Try:

results in

π

Page 16: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 16

Group velocity

dk

dcg

)cos()(

)(

0*

00

xkUdk

kcdc

Udk

kUdc

g

g Continuous equation

Discretized equation

=-U0 for kΔx=π

Approximating the space operator introduces dispersion

Page 17: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 17

Time discretization

11 1

0 2

n n n nj j j jj

Ut t x

n

Tryxikj

etninj e 0

Substituting we get 1 sin( )0U ti t i k xx

e

Courant-Friedrich-Levy number

ω=a+ib

If b>0, φjn increases exponentially with time (unstable)

If b<0, φjn decreases exponentially with time (damped)

If b=0, φjn maintains its amplitude with time (neutral)

Also another dispersion is introduced, as we have approximated the operator ∂/ ∂t

In addition to our 2nd order centered approx. for the space derivative we use a 1st order forward approx. for the time derivative:

1 110 2

n nj jn n

j j tUx

Page 18: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 18

Three time level scheme (leapfrog)

)( 1111

j

nj

nnj

nj

)( 1111

j

nj

nnj

nj

This scheme is centered (second order accurate) in both space and time

Try a solution of the form

xikjnk

nj e 0

exponential

If |λk| > 1 solution unstableif |λk| = 1 solution neutralif |λk| < 1 solution damped

Substituting 2 2 1 0 where sin( )k kip p k x

21 pipk 11

11

2

2

pip

pip

k

kΔx--->0Δt --->0

physical mode

computational mode

Page 19: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 19

Stability analysisEnergy method

We have defined ;2

1)(

0

2L

dxtE

L

LUdx

x

U

t

E

00

202

0 0]22

For periodic boundary conditions

We have discretized t and

hence the discretized analog of E(t) is En

N

j

nj

n xE1

2)(2

1φn

N+1≡ φn1

If En=const, than the scheme is stable t

Page 20: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 20

Example of the energy method

xU

t

jnn

jn

jn

j

10

1upwind if U0>0downwind if U0<0 x

j-1 j

1 2 2 11 0( ) ( ) ( )( )n n n n n n

j j j j j j

tU

x

21

21

2221 ))(1(})(){()()( j

nnj

nj

nj

nj

nj

j

0

1

21

1 )()1(

N

jj

nj

nnn xEE

En+1=En ifα=0 => U0=0 no motionα=1 Δt= Δx/U0

En+1 > En unstable

En+1 < En if α > 0 => U0 > 0 upwindα < 1 U0 Δt/ Δx < 1 CFL cond. damped

Page 21: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 21

Von Neumann methodConsider a single wave jikxn

kknj ectx ),(

if |λk| < 1 the scheme is damping for this wave number kif |λk| = 1 k the scheme is neutralif |λk| > 1 for some value of k, the scheme is unstable

alternatively jikxtniknj eectx ),(

if Im(ω) > 0 scheme unstableif Im(ω) = 0 scheme neutralif Im(ω) < 0 scheme damping

Vf= ω/k vg=∂ω/∂k

Page 22: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 22

Stability of some schemes• Forward in time, centered in space (FTCS) scheme

• Upwind or downwind

xU

t

nj

nj

nj

nj

211

0

1

using Von Neumann, we find

1 sin( ) 1k ki k x k scheme unstable

xU

t

nj

nj

nj

nj

10

1 upwind if U0 > 0downwind if U0 < 0

Using Von Neumann, we find2

0

1 (1 ) hence 1 2 ( 1) (1 cos( ))ik xk ke k x

α(α-1) > 0 unstableα < 0 downwindα > 1 CFL limit

-1/4 < α(α-1) < 0 => 0 ≤ α ≤ 1 stable damped scheme

Page 23: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 23

Stability of some schemes (cont)

• Leapfrog xU

t

nj

nj

nj

nj

2211

0

11

Using von Neumann we find |α|≤1 as stability condition

0

tU

x

As a reminder α is the Courant-Friedrich-Levy number:

Page 24: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 24

• Lax Wendroff scheme

Stability of some schemes (cont)

From a Taylor expansion in t we get:

2

22)(

!2

1),(),(

tt

tttxttx

2

220

20 )(

!2

1),(),(

xUt

xtUtxttx

)2(2

)(2 11

2

111 n

jnj

nj

nj

nj

nj

nj

Applying Von Neumann we can find that |α| ≤1 -----> stable

Discretization:

Substitution the advection equation we:

Page 25: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 25

Stability of some schemes (cont)• Implicit centered scheme

1 1 1 1 1 11 1 1 10

2

n n n n n nj j j j j jU

t x x

using von Neumann

1)sin(1

)sin(12

xki

xki

)tan(0 t

t

U

c

We replace the space derivation by the average value of the centred space derivation at time level n-1 and n+1

Always neutral, however an Expensive implicit equation need to solved

Dispersion worse than leapfrog

Page 26: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 26

“Intuitive” look at stabilityIf the information for the future time step “comes from” inside the interval used for the computation of the space derivative, the scheme is stable.Otherwise it is unstable

x, x’ … point where the information comes from (xj-U0Δt) Interval used for the computation of ∂φ/∂xj-1 j j+1

x

U0ΔtDownwind scheme (unstable)

j-1 j j+1x’ x

x if α < 1x’ if α > 1

Upwind scheme (conditionally stable)

CFL number ==> fractionof Δx traveled in Δt seconds

Leapfrog (conditionally stable)

Implicit (unconditionally stable)

j-1 j j+1

x’ x

Page 27: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 27

Dispersion and group velocity

ωΔt

π/2 π

U0

vg vf

Leapfrog

K-N

Implicit

Vf= ω/k vg=∂ω/∂k

Page 28: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 28

Effect of dispersionIn

itial

Lea

pfro

gim

plic

it

Page 29: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 29

Two-dimensional advection equation

000

yV

xU

t

Using von Neumann, assuming a solution of the form)(0 lykxinn e

we obtain

y

ylV

x

xkUt

)sin()sin( 00

using )sin,cos(),( 00 RRVUV

we obtain, for |λ| ≤ 1 the condition

2R

st

where Δs= Δx= Δy

This is more restrictive than in one dimension by a factor 2

Page 30: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 30

0

x

uu

t

u

x

u(x,0)

x

u(x,t)

Change in shape evenfor the continuous form

One Fourier component ukeikx no longer moving with constantspeed but interacting with other componentsFourier decomposition valid at each individual timebut it changes amplitude with time

k

ikxtik eetuu )(

No analytical solution!

Non linear advection equation Continuous form

Page 31: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 31

Energy conservation

Define again: L

dxuE0

2

2

1

0)(2

10

222

Lufdxx

uu

t

E

x

uu

t

u

t

uu

x

uu

t

u

periodic B.C.==

Discretization in space

First attempt:1 1 1 1 2 2

j j j j jj j

u u u u uuu u u

x x t x

2 2 21 1

1 1( )

2 2

'0j j j j j

j

u x u u u ut

E

t

1 1

~ averaging

1 1

3 2j

j j j

u

j jju u uu u u

t x

Second attempt:

2 2 2 21 1 1 1

1( )

'0

6 j j j j j j j jj

u u u uE

u u u ut

terms joined by arrows cancel from consecutive j’s

Page 32: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 32

Aliassing

Consider the productdx

xdxA

)()(

k

kk

k kxxkxx )sin()()sin()( in the interval 0≤x ≤2π

2

1]})sin[(])sin[({

)cos()sin(

21212

221

2

1 2

1

1 2

21

xkkxkkk

xkkxkA

kk k

k

k kkk

Minimum wavelength 2 2m M

m

L Nx k

<---------------L------------->

1 2 n N+1Maximum wave number representable with the discretized grid

Aliasing occurs when the non-linear interactions in the advection term produce a wave which is too short to be represented on the grid.

Page 33: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 33

Aliassing (cont.)Trigonometrical manipulations lead to: sin(kxj)=-sin[(2kM-k)xj]

wave number k wave number 2kM-k

x

x

x

Therefore, it is not possible to distinguish wave numbers k and (2kM-k)on the grid.

Page 34: Numerical methods 1 An Introduction to Numerical Methods For Weather Prediction by Joerg Urban office 012 Based on lectures given by Mariano Hortal.

Numerical methods 34

Non-linear instabilityIf k1+k2 is misrepresented as k1 there is positive feedback, which causes instability

k1 = 2kM - (k1+k2) ----------> 2k1=2kM-k2

2kM 2k1 kM

2Δx ≤ λ1 ≤ 4ΔxThese wavelengths keep storing energy and total energy is not conserved

We can remove energy from the smallest wavelengths by - Fourier filtering - Smoothing - Diffusion - Use some other discretization (e.g. semi-Lagrangian)