Finite difference schemes for scalar linear hyperbolic PDE...

Post on 29-Feb-2020

8 views 0 download

Transcript of Finite difference schemes for scalar linear hyperbolic PDE...

Finite difference schemes forscalar linear hyperbolic PDE in 1-D

Praveen. Cpraveen@math.tifrbng.res.in

Tata Institute of Fundamental ResearchCenter for Applicable Mathematics

Bangalore 560065http://math.tifrbng.res.in/~praveen

February 4, 2013

1 / 50

Simplest hyperbolic PDELinear, scalar convection/advection equation (Initial value problem)

ut + aux =0 x ∈ R, t > 0

u(x, 0) =f(x) x ∈ R(1)

Exact solutionu(x, t) = f(x− at)

Initial condition is convected with speed a without change of form.

x

f(x)u(x, t)

at

Hence the extrema of the solution do not change with time. Also the L2-normof the solution does not change with time. If E(t) is the solution operator

u(x, t) = E(t)f(x) =⇒ ‖E(t)u‖ = ‖u‖

in both sup-norm and L2-norm.2 / 50

Method of characteristics

How does the solution vary along thespace-time curve x = x(t) with

d

dtx(t) = a

Variation of u along this curve

d

dtu(x(t), t)

=∂u

∂t(x(t), t) +

d

dtx(t) · ∂u

∂x(x(t), t)

= ut + aux

= 0

Solution is constant along thecharacteristic curve.

Backward characteristic through (x, t)hits initial time t = 0 at

x0 = x− at

t

x

(x, t)

x0

dxdt

= a

u(x, t) = u(x0, 0) = f(x− at)

3 / 50

Discontinuous solutions

If the initial condition is discontinuous, then we can still talk of a solution,even though the PDE is not satisfied everywhere. The MOC method is stillvalid and gives the solution at any later time. The solution is again obtainedby translating the initial condition. The discontinuity propagates along thecharacteristic curve.

f

x

ul

ur

Initial Condition t

x

dxdt

= au = ul u = ur

Such a discontinuity is called a contact discontinuity/wave. Thecharactersitics on either side of the discontinuity curve are parallel to it.

4 / 50

Finite difference scheme

Forward time, backward space (FTBS)

un+1j − unj

∆t+ a

unj − unj−1

h= 0 ⇒ un+1

j = (1− aλ)unj + aλunj−1

Forward time, central space (FTCS)

un+1j − unj

∆t+ a

unj+1 − unj−1

2h= 0 ⇒ un+1

j = unj +aλ

2(unj−1 − unj+1)

Forward time, forward space (FTFS)

un+1j − unj

∆t+ a

unj+1 − unjh

= 0 ⇒ un+1j = (1 + aλ)unj − aλunj+1

λ =∆t

h

5 / 50

Maximum principle

• a > 0: FTBS scheme is stable in maximum norm if aλ ≤ 1, others areunstable.

• a < 0: FTFS scheme is stable in maximum norm if |a|λ ≤ 1, others areunstable.

• FTCS scheme is never stable in maximum norm.

• Upwind scheme: switch between backward and forward difference

un+1j − unj

∆t+ a+

unj − unj−1

h+ a−

unj+1 − unjh

= 0

Stable in maximum norm for any a provided |a|λ ≤ 1 is satisfied.

Courant-Friedrichs-Levy (CFL) number, CFL condition

CFL = |a|λ =|a|∆th

, CFL ≤ 1, ∆t = O (h)

6 / 50

Numerical example

• PDEut + aux = 0, x ∈ (0, 1)

• with initial conditionu(x, 0) = sin(2πx)

• and periodic boundary conditions.

• Use a = 1. Try backward and forward difference scheme with CFL=0.5.The scheme is implemented in the matlab programlin hyp 1d periodic.m

• Backward difference: lin hyp 1d periodic(100, 0.5, ’bd’)

• Forward difference: lin hyp 1d periodic(100, 0.5, ’fd’)

7 / 50

Lax-Friedrichs (LF) scheme

• Forward time, central space (FTCS)

un+1j − unj

∆t+ a

unj+1 − unj−1

2h= 0

is not stable in maximum norm. We can modify it in following way.

• LF scheme

un+1j − 1

2 (unj−1 + unj+1)

∆t+ a

unj+1 − unj−1

2h= 0

un+1j =

1

2(1 + aλ)unj−1 +

1

2(1− aλ)unj+1

Stable in maximum norm if |a|λ ≤ 1.

8 / 50

Lax-Wendroff (LW) schemeTaylor’s formula

u(xj , tn+1) = u(xj , t

n) + ∆tut(xj , tn) +

1

2∆t2utt(xj , t

n) +O(∆t3

)Use the PDE

ut = −aux utt = a2uxx

to get

u(xj , tn+1) = u(xj , t

n)− a∆tux(xj , tn) +

1

2a2∆t2uxx(xj , t

n) +O(∆t3

)Approximate ux and uxx by central differences

un+1j = unj − a∆t

unj+1 − unj−1

2h+

1

2a2∆t2

unj−1 − 2unj + unj+1

h2+O

(∆t3

)LW scheme

un+1j = unj −

1

2aλ(unj+1 − unj−1) +

1

2a2λ2(unj−1 − 2unj + unj+1)

This scheme is not bounded in maximum norm but is stable in L2 norm.9 / 50

More schemes

• Leapfrog scheme (Three level scheme)

un+1j − un−1

j

2∆t+ a

unj+1 − unj−1

2h= 0

Not self-starting, need different scheme for first time step.

• Backward time, central space, BTCS (Backward Euler implicit scheme)

un+1j − unj

∆t+ a

un+1j+1 − un+1

j−1

2h= 0

10 / 50

Schemes via method of characteristics, CFL condition

Exact solution isu(xj , t

n+1) = u(xf , tn)

Assume a > 0 and aλ ≤ 1, i.e., a∆t ≤ ∆x

t

xj − 1 j j + 1

tn

tn+1

f

xf − xj−1 = h− a∆t

xj − xf = a∆t

h

∆t

• Linear interpolation between xj−1 and xj

un+1j =

xj − xfh

uj−1 +xf − xj−1

huj =⇒ un+1

j = aλunj−1 + (1− aλ)unj

which is the FTBS (upwind) scheme.

11 / 50

Schemes via method of characteristics, CFL condition

• Quadratic interpolation between xj−1, xj , xj+1 leads to the Lax-Wendroffscheme. Valid procedure for a > 0 and a < 0.

If aλ > 1, then foot of backward characteristic xf intersects t = tn outside theinterval (xj−1, xj+1).

t

x

j − 1 j j + 1

tn

tn+1

f

h

∆t

Interpolation using the values uj−1, uj , uj+1 would be wrong in this case. CFLcondition ensures correct domain of dependance

Exact domain of dependance ⊂ Numerical domain of dependance

12 / 50

Consistency and accuracyLocal truncation error : e.g. FTCS scheme

τnj =u(xj , t

n+1)− u(xj , tn)

∆t+ a

u(xj+1, tn)− u(xj−1, t

n)

2h

Truncation errorτ(∆t, h) = max

j,n|τnj |

Consistency

The numerical scheme is consistent if

τ(∆t, h)→ 0 as ∆t, h→ 0

Accuracy

The numerical scheme is accurate of order p in time and to the order q inspace, if for a sufficiently regular solution of the exact problem, we have

τ(∆t, h) = O (∆tp + hq)

13 / 50

Consistency and accuracy

Scheme τ(∆t, h)

FTCS O(∆t+ h2

)Upwind O (∆t+ h)

Lax-Friedrichs O(h2

∆t + ∆t+ h2)

Lax-Wendroff O(∆t2 + h2 + h2∆t

)Convergence in maximum norm

The scheme is convergent in the maximum norm if

lim∆t,h→0

maxj,n|u(xj , t

n)− unj | = 0

Remark: We will also consider weaker norms such as ‖·‖1,h and ‖·‖2,h

‖u‖1,h = h∑j

|uj |, ‖u‖2,h = (h∑j

|uj |2)12

14 / 50

Stability

Definition: Stable scheme (finite time stability)

A numerical scheme is stable if for each time T , there exists a constant CT > 0such that for each h > 0, there exists δ0 > 0 (possibly dependent on h) suchthat for any 0 < ∆t < δ0, we have

‖un‖ ≤ CT∥∥u0∥∥

for each n such that n∆t ≤ T , and for each initial condition u0. The constantCT cannot depend on h.

Remark: An equivalent statement of the above condition is

‖un‖ ≤ (1 + C∆t)∥∥un−1

∥∥ , C ≥ 0

where the constant C cannot depend on ∆t or h. Then

‖un‖ ≤ (1 + C∆t)n∥∥u0∥∥ ≤ eCT

∥∥u0∥∥

15 / 50

Stability

Strongly stable scheme

A numerical scheme is said to be strongly stable if

‖un‖ ≤∥∥un−1

∥∥i.e., if CT = 1.

Remark: For hyperbolic problems, one is often interested in solutions after along time (T � 1). In such cases, it is desirable to have strong stability sincethen the numerical solutions are guaranteed to be bounded for each value of T .

16 / 50

Stability in ‖·‖1,h (Upwind, LF and LW schemes)

If the CFL condition |a|λ ≤ 1 is satisfied, then the upwind, Lax-Friedrichs andLax-Wendroff schemes are strongly stable in the norm ‖·‖1,h.

Proof: (1) Consider the upwind scheme with a > 0

un+1j = (1− aλ)unj + aλunj−1

Then ∥∥un+1∥∥

1,h≤ h

∑j

|(1− aλ)unj |+ h∑j

|aλunj−1|

and since aλ > 0 and (1− aλ) > 0, we get∥∥un+1∥∥

1,h≤ h

∑j

(1− aλ)|unj |+ h∑j

aλ|unj−1| = ‖un‖1,h

(2) For the Lax-Friedrichs scheme

un+1j =

1

2(1 + aλ)unj−1 +

1

2(1− aλ)unj+1

17 / 50

with (1± aλ) ≥ 0 due to CFL condition, so that

∥∥un+1∥∥

1,h≤ 1

2h∑j

|(1 + aλ)unj−1|+1

2h∑j

|(1− aλ)unj+1|

=1

2h∑j

(1 + aλ)|unj−1|+1

2h∑j

(1− aλ)|unj+1|

= ‖un‖1,h

(3) For the Lax-Wendroff scheme, the proof is analogous.

Remark: We have already shown the upwind and LF schemes to be stable inmaximum norm. The LW scheme is NOT bounded in maximum norm.

un+1j =

1

2aλ(1 + aλ)unj−1 + (1− a2λ2)unj +

1

2aλ(−1 + aλ)unj+1

However this does not mean that it is unstable in maximum norm.

18 / 50

Stability in ‖·‖2,h (BTCS, FTCS)

(1) The BTCS scheme is strongly stable in the norm ‖·‖2,h with no restrictionon ∆t. (2) The FTCS is never strongly stable. However, it is stable withconstant CT = eT/2 provided we assume that ∆t satisfies the followingcondition (which is more restrictive than the CFL condition)

∆t ≤(h

a

)2

Proof: (1) BTCS (implicit Euler scheme)

un+1j

(un+1j − unj

∆t+ a

un+1j+1 − un+1

j−1

2h

)= 0

which can re-arranged as

(un+1j )2 + (un+1

j − unj )2 = (unj )2 − aλ(un+1j+1 − un+1

j−1 )un+1j

19 / 50

Summing up over all the cells, the last term vanishes (telescopic collapse) toyield ∥∥un+1

∥∥2

2,h= ‖un‖22,h − h

∑j

(un+1j − unj )2 ≤ ‖un‖22,h

(2) FTCS scheme

unj

(un+1j − unj

∆t+ a

unj+1 − unj−1

2h

)= 0

which can be rearranged as

(un+1j )2 = (unj )2 + (un+1

j − unj )2 − aλ(unj+1 − unj−1)unj

so that ∥∥un+1∥∥2

2,h= ‖un‖22,h + h

∑j

(un+1j − unj )2 ≥ ‖un‖22,h

and the FTCS scheme is not strongly stable. However if we write the scheme

un+1j − unj = −aλ

2(unj+1 − unj−1)

20 / 50

and use it in above equation, we get

(un+1j )2 = (unj )2 +

(aλ

2

)2

(unj+1 − unj−1)2 − aλ(unj+1 − unj−1)unj

Summing up over all the equations

∥∥un+1∥∥2

2,h= ‖un‖22,h + h

(aλ

2

)2∑j

(unj+1 − unj−1)2

≤ ‖un‖22,h + h

(aλ

2

)2

2∑j

[(unj+1)2 + (unj−1)2]

= ‖un‖22,h + a2λ2 ‖un‖22,h assume a2λ2 ≤ ∆t

≤ (1 + ∆t) ‖un‖22,h if ∆t ≤(h

a

)2

This yields

‖un‖22,h ≤ (1 + ∆t)n∥∥u0∥∥2

2,h≤ eT

∥∥u0∥∥2

2,h∀n s.t. n∆t ≤ T

which shows stability of FTCS scheme since ‖un‖2,h ≤ eT/2∥∥u0∥∥

2,h.

21 / 50

Remark: The proof in the last theorem requires the following algebraicidentities: for any A,B ∈ R

(B −A)B = (B −A)2 + (B −A)A

=1

2[B2 −A2 + (B −A)2]

=1

2[(B −A)2 + (B −A)(B +A)]

and

(B −A)A =1

2[B2 −A2 − (B −A)2]

Remark: The above proofs were possible due to the algebraic structure of theschemes. For other schemes, we may not be able to show stability in ‖·‖2,husing such algebraic techniques. In those cases, the Fourier or Von Neumannstability analysis will be useful. However this approach is limited to linearproblems. Even for non-linear problems, Fourier stability is a necessarycondition; from a computational viewpoint, it keeps roundoff errors undercontrol.

22 / 50

Discrete Fourier transformPeriodic initial condition

f : [0, 2π]→ R

Let N be an even integer. Consider a grid of N + 1 points with grid pointcoordinates

xj = jh, j = 0, 1, . . . , N with h =2π

N

We can approximate f(x) on the grid by the discrete Fourier series

f(x) =

N2 −1∑

k=−N2

αkeikx

Determine the coefficients αk by interpolation fj = f(xj) = f(xj), i.e.,

fj =

N2 −1∑

k=−N2

αkeikjh, j = 0, 1, . . . , N − 1

We ignore fN since fN = f0 by periodicity.

23 / 50

Discrete Fourier transform

To determine αk, multiply by e−iljh and sum

N−1∑j=0

fje−iljh =

N−1∑j=0

N2 −1∑

k=−N2

αkeikjhe−iljh =

N2 −1∑

k=−N2

αk

N−1∑j=0

ei(k−l)jh

We can show that

N−1∑j=0

ei(k−l)jh =2π

hδkl, −N

2≤ k, l ≤ N

2− 1

which gives the Fourier coefficient

αl =h

N−1∑j=0

fje−iljh

24 / 50

Parseval relation

We want to relate l2 norm of a grid function with the l2 norm of its Fouriercoefficients.

f2j = f∗j fj =

N2 −1∑

k=−N2

α∗ke−ikjhfj

Summing up over all the grid points

N−1∑j=0

f2j =

N2 −1∑

k=−N2

α∗k

N−1∑j=0

fje−ikjh =

h

N2 −1∑

k=−N2

α∗kαk

which gives the discrete Parseval relation

‖f‖22,h = h

N−1∑j=0

|fj |2 = 2π

N2 −1∑

k=−N2

|αk|2

25 / 50

Von Neumann stability analysis

Let us approximate the initial condition by the discrete Fourier series andapply any of the numerical schemes studied till now to this approximate initialcondition. Then the solution at any time tn can be written as

unj =

N2 −1∑

k=−N2

αk(γk)neikjh

where γk ∈ C is called the amplification coefficient of the k-th frequency (orharmonic). If |γk| > 1 then the numerical solution is likely to blow up withtime.FTCS scheme: Consider first time step

u1j = u0

j +aλ

2(u0j−1 − u0

j+1)

=

N2 −1∑

k=−N2

αkeikjh

[1 +

1

2aλ(e−ikh − eikh)

]︸ ︷︷ ︸

γk

26 / 50

Von Neumann stability analysis

But

γk = 1− iaλ sin(kh), |γk| = [1 + a2λ2 sin2(kh)]12 ≥ 1

and hence the FTCS scheme is not strongly unstable.

Scheme γk

FTCS 1− iaλ sin(kh)BTCS (imp. Euler) [1 + iaλ sin(kh)]−1

Upwind 1− |a|λ(1− e−ikh)Lax-Friedrichs cos(kh)− iaλ sin(kh)Lax-Wendroff 1− iaλ sin(kh)− a2λ2[1− cos(kh)]

27 / 50

Von Neumann stability

If ∃β ≥ 0 and a positive integer m such that, for suitable choices of ∆t and h,we have |γk| ≤ (1 + β∆t)

1m for each k, then the scheme is stable with respect

to ‖·‖2,h with a stability constant CT = eβTm . In particular, if β = 0 (so that

|γk| ≤ 1), then the scheme is strongly stable.

Proof: Using the Parseval relation, we get

‖un‖22,h = 2π

N2 −1∑

k=−N2

|αk|2|γk|2n

≤ (1 + β∆t)2nm 2π

N2 −1∑

k=−N2

|αk|2 = (1 + β∆t)2nm

∥∥u0∥∥2

2,h

≤ e2βn∆tm

∥∥u0∥∥2

2,hsince 1 + β∆t ≤ eβ∆t

≤ e2βTm

∥∥u0∥∥2

2,h∀n s.t. n∆t ≤ T

The second part of the theorem follows easily.

28 / 50

Stability of standard schemes in ‖·‖2,h

Scheme Stable Strongly stable CFL |γk| ≤FTCS∗ Yes No ∆t ≤ β h2

a2 (1 + β∆t)12

BTCS (imp. Euler) Yes Yes - 1Upwind Yes Yes |a|λ ≤ 1 1Lax-Friedrichs Yes Yes |a|λ ≤ 1 1Lax-Wendroff Yes Yes |a|λ ≤ 1 1

∗ For any β > 0.

Remark: Leapfrog scheme has

|γk| = 1, if |a|λ ≤ 1

so that it is neutrally stable.

29 / 50

Dissipation property

• The exact solution u(x, t) = f(x− at) can be written as a Fourier series

u(xj , tn) =

∞∑k=−∞

αkeik(xj−atn) =

∞∑k=−∞

αkeikjh(gk)n, gk = e−iak∆t

• Note that |gk| = 1 which reflects the property that the exact solution isadvected without change of shape (amplitude).

• In the numerical scheme, gk is replaced by γk and for strong stability, weneed |γk| ≤ 1.

• If |γk| < 1 the amplitude of numerical solution will decrease with time,which is a sign of some dissipative mechanism in the numerical scheme.

• We can measure the amplification error by

εa(k) =|γk||gk|

=Numerical amplitude

Exact amplitude

• Ideally, we would like to have εa(k) ≈ 1 for all wave numbers k that canbe represented on the grid.

30 / 50

Dispersion property• Let us set

φk = kh so that gk = e−iaλφk

φk is called the phase angle of the k-th harmonic.

• The speed of propagation of k-th harmonic is a which is independent ofthe wave number k.

• Similarly for the scheme we can write

γk = |γk|e−iωk∆t = |γk|e−iωkk λφk

• The quantity ωkk measures the numerical propagation speed of the k-th

harmonic, which is not equal to the exact propagation speed which is afor all harmonics. This means that different harmonics can propagatewith different speeds, which is known as dispersion error. This can bemeasured by

εd(k) =ωkak

=ωkh

aφk=: εd(φk,CFL), −π ≤ φk ≤ +π

• Ideally, we would like to have εd(k) ≈ 1 for all wave numbers k that canbe represented on the grid.

31 / 50

336 12 Finite differences for hyperbolic equations

0 20 40 60 80 100 120 140 160 1800

0.2

0.4

0.6

0.8

1

1.2Amplification error FE/C

! a

0 20 40 60 80 100 120 140 160 180

0

0.2

0.4

0.6

0.8

1

Dispersion error FE/C

" # x

! $

0 20 40 60 80 100 120 140 160 1800

0.2

0.4

0.6

0.8

1

1.2Amplification error BE/C

! a

0 20 40 60 80 100 120 140 160 180

0

0.2

0.4

0.6

0.8

1

Dispersion error BE/C

" # x

! $

0 20 40 60 80 100 120 140 160 1800

0.2

0.4

0.6

0.8

1

1.2Amplification error LF

! a

0 20 40 60 80 100 120 140 160 180

1

2

3

4

5

Dispersion error LF

" # x

! $

0 20 40 60 80 100 120 140 160 1800

0.2

0.4

0.6

0.8

1

1.2Amplification error U

! a

0 20 40 60 80 100 120 140 160 180

0

0.5

1

Dispersion error U

" # x

! $

0 20 40 60 80 100 120 140 160 1800

0.2

0.4

0.6

0.8

1

1.2Amplification error LW

! a

0 20 40 60 80 100 120 140 160 180

0

0.5

1

Dispersion error LW

" # x

! $

Fig. 12.6. Amplification and dispersion errors for different numerical schemes as a function ofthe phase angle !k = kh and for different values of the CFL number

interval 0 ! !k ! " and we have used degrees instead of radiants in the abscissa toindicate !k. Note how the forward/centered Euler scheme denotes a curve of the am-plification factor with values above one for all the CFL schemes we have considered,in accordance with the fact that such scheme is never strongly stable.

32 / 50

l = 20h

φk =π

10

338 12 Finite differences for hyperbolic equations

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Lax!Wendroff CFL= 0.75, !k="/10,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Lax!Wendroff CFL= 0.75, !k="/4,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Lax!Friedrichs CFL= 0.75, !k="/10,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Lax!Friedrichs CFL= 0.75, !k="/4,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Upwind CFL= 0.75, !k="/10,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Upwind CFL= 0.75, !k="/4,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Backward Euler CFL= 0.75, !k="/10,t= 1.0

!1 !0.5 0 0.5 1 1.5 2 2.5 3

!1

!0.5

0

0.5

1

x

u

Backward Euler CFL= 0.75, !k="/4,t= 1.0

Fig. 12.7. Numerical solution of the convective transport equation of a sinusoidal wave packetwith different wavelengths (l = 20h at the left, l = 8h at the right) obtained with differentnumerical schemes. The numerical solution for t = 1 is displayed in solid line, while the exactsolution at the same time instant is displayed in etched line

l = 8h

φk =π

4

33 / 50

12.5 Equivalent equations 339

!0.5 0 0.5 1 1.5

!1

!0.8

!0.6

!0.4

!0.2

0

0.2

0.4

0.6

0.8

1

x

u

Lax!Wendroff CFL= 0.75, !k x="/4

!0.5 0 0.5 1 1.5

!1

!0.8

!0.6

!0.4

!0.2

0

0.2

0.4

0.6

0.8

1

x

u

Lax!Friedrichs CFL= 0.75, !k="/4

!0.5 0 0.5 1 1.5

!1

!0.8

!0.6

!0.4

!0.2

0

0.2

0.4

0.6

0.8

1

x

u

Upwind CFL= 0.75, !k="/4

!0.5 0 0.5 1 1.5

!1

!0.8

!0.6

!0.4

!0.2

0

0.2

0.4

0.6

0.8

1

x

u

Backward Euler CFL= 0.75, !k="/4

Fig. 12.8. Numerical solution of the convective transport of a packet of sinusoidal waves. Thesolid line represents the solution after 8 time steps. The etched line represents the correspondingexact solution at the same time level

Formally differentiating such equation with respect to t, we find

vtt + avxt = RUt +O(!t3 + h3).

Instead, differentiating it with respect to x, we have

vxt + avxx = RUx +O(!t3 + h3). (12.46)

Hence,vtt = a

2vxx + RUt ! aRUx +O(!t3 + h3) (12.47)

which allows to obtain from (12.45)

vt+avx = µvxx!1

6(ah2vxxx+!t

2vttt)!!t

2(RUt !aRUx )+O(!t3+h3), (12.48)

having set

µ =1

2ah(1! (a")) (12.49)

34 / 50

Modified PDE/Equivalent equationThe numerical solution unj is known at the grid points xj and tn only, and ingeneral it is different from the exact solution u(x, t)

unj 6= u(xj , tn)

The exact solution does not exactly satisfy the numerical scheme, since thereis some truncation error. E.g., for FTBS scheme

u(xj , tn+1)− u(xj , t

n)

∆t+ a

u(xj , tn)− u(xj−1, t

n)

h= τnj 6= 0

Can we find a smooth function v(x, t) such that

v(xj , tn) = unj

and v(x, t) exactly satisfies the numerical scheme ?

v(xj , tn+1)− v(xj , t

n)

∆t+ a

v(xj , tn)− v(xj−1, t

n)

h= 0

What is the PDE satisfied by v(x, t) ?

35 / 50

MPDE for Upwind schemeWe begin with the Upwind scheme (a > 0)

v(x, t+ ∆t)− v(x, t)

∆t+ a

v(x, t)− v(x− h, t)h

= 0

and do a Taylor expansion about (x, t)

v(x, t+ ∆t)− v(x, t)

∆t= vt +

∆t

2vtt +

∆t2

6vttt +O

(∆t3

)av(x, t)− v(x− h, t)

h= avx −

ah

2vxx +

ah2

6vxxx +O

(h3)

which leads tovt + avx = R+O

(∆t3 + h3

)with

R =1

2(ahvxx −∆tvtt)−

1

6(ah2vxxx + ∆t2vttt)

We want to write R in terms of x-derivatives. Differentiating wrt t and x

vtt + avxt = Rt +O(∆t3 + h3

), vxt + avxx = Rx +O

(∆t3 + h3

)36 / 50

MPDE for Upwind scheme

This gives

vt + avx = µvxx −1

6(ah2vxxx + ∆t2vttt)−

∆t

2(Rt − aRx) +O

(∆t3 + h3

)where

µ =1

2ah(1− aλ) , µ = O (h)

We now want to replace vttt term.

vttt = a2vxxt +Rtt − aRxt +O(∆t3 + h3

)= −a3vxxx + a2Rxx +Rtt − aRxt +O

(∆t3 + h3

)Moreover

Rt =1

2ahvxxt −

∆t

2vttt −

ah2

6vxxxt −

∆t2

6vtttt

Rx =1

2ahvxxx −

∆t

2vttx −

ah2

6vxxxx −

∆t2

6vtttx

37 / 50

MPDE for Upwind scheme

We get

vt + avx = µvxx −ah2

6

[1− a2∆t2

h2− 3a∆t

2h

]vxxx

+∆t

4(∆tvttt − ahvxxt − a∆tvttx)

+∆t

12(∆t2vtttt − a∆t2vtttx + ah2vxxxt − a2h2vxxxx)

−a2∆t2

6Rxx −

∆t2

6Rtt +

a∆t2

6Rxt +O

(∆t3 + h3

)Due to CFL condition, ∆t = O (h) and the terms in blue are O

(h3). The

terms in red can be written as

vttt = −a3vxxx +O (h)

vttx = +a2vxxx +O (h)

vxxt = −avxxx +O (h)

38 / 50

MPDE for Upwind scheme

leads to the MPDE

vt + avx = µvxx + νvxxx +O(h3)

where

ν = −ah2

6(1− 3aλ+ 2a2λ2) , ν = O

(h2)

39 / 50

MPDE: LF, LW, FTCS schemes

Upto O(h2)

we can write the MPDE as

vt + avx = µvxx︸︷︷︸O(h)

+ νvxxx︸ ︷︷ ︸O(h2)

µ is called the numerical viscosity.

• Lax-Friedrichs scheme

µ =h2

2∆t(1− a2λ2), ν =

ah2

3(1− a2λ2)

• Law-Wendroff scheme

µ = 0, ν =ah2

6(a2λ2 − 1)

• FTCS scheme

µ = −a2∆t

2< 0

40 / 50

Meaning of MPDEThe MPDE gives us information about dissipation and dispersion propertiesof the numerical scheme. If we consider{

vt + avx = µvxx + νvxxx, x ∈ R, t > 0

v(x, 0) = eikx

its solution isv(x, t) = e−µk

2teik[x−(a+νk2)t]

The exact solution of the original PDE (µ = 0, ν = 0) is

u(x, t) = eik(x−at) (no dissipation, no dispersion)

• If µ > 0 then v is dissipated with time, indicating stability. For thenumerical schemes like Upwind and LF, we see that µ > 0 iff the CFLcondition |a|λ ≤ 1 is satisfied. LW scheme does not have any dissipation(It can have higher order dissipation, which would be much weaker.)

• If ν = 0 then every harmonic travels with speed a. But if ν 6= 0, then thek-th harmonic travels with speed a+ νk2 which leads to dispersion error.

41 / 50

MPDE example: Upwind scheme

PDE and MPDE for upwind scheme (we take a = 1)

ut + aux = 0, vt + avx = µvxx, µ =1

2|a|h(1− |a|λ)

Discontinuous initial condition (H is Heaviside function)

u0(x) = 2[1−H(x)]

Exact solution

u(x, t) = 2[1−H(x− at)], v(x, t) = erfc

(x− at√

4µt

)Numerical example

a = 1, h = 0.05, ∆t = 0.04, |a|λ = 0.8, µ = 5× 10−4

42 / 50

MPDE example: Upwind scheme156 8 Convergence, Accuracy, and Stability

(a) 0 0.5 1 1.5 2 2.5 3 3.5 4!0.5

0

0.5

1

1.5

2

2.5Time t = 1

(b) 0 0.5 1 1.5 2 2.5 3 3.5 4!0.5

0

0.5

1

1.5

2

2.5Time t = 3

Fig. 8.3. Dashed line: exact solution to the advection equation. Points: numerical solution obtainedwith the upwind method. Solid line: exact solution to the modified equation (8.44). (a) At time t = 1.(b) At time t = 3. [book/chap8/modeqn]

The numerical solution to the advection equation obtained using the upwind method, markedby the symbols in Figure 8.3, is well approximated by the exact solution to the modifiedequation.

It follows that we can use the modified equation to give us some insight into the expectedaccuracy of the upwind method on this problem. Comparing v(x, t) from (8.48) to the truesolution q(x, t) = 2H (ut ! x), it is possible to show that the 1-norm of the difference is

"q(·, t) ! v(·, t)"1 = 2! #

0erfc

"x$4!t

#dx

= 2$

4!t! #

0erfc(z) dz

= C1

$!t (8.51)

for some constant C1 independent of ! and t . Since ! is given by (8.49), this gives

"q(·, t) ! v(·, t)"1 % C2$

"x t (8.52)

as "x & 0 with "t/"x fixed. This indicates that the 1-norm of the error decays onlylike ("x)1/2 even though the method is formally “first-order accurate” based on the localtruncation error, which is valid only for smooth solutions.

This informal analysis only gives an indication of the accuracy one might expect from afirst-order method on a problem with a discontinuous solution. More detailed error analysisof numerical methods for discontinuous solutions (to nonlinear scalar equations) can befound, for example, in [251], [316], [339], [390], [436], [438].

Exercises

8.1. Consider the centered method (4.19) for the scalar advection equation qt + uqx = 0.Apply von Neumann analysis to show that this method is unstable in the 2-norm forany fixed "t/"x .

Numerical solution is very close to the solution of MPDE !!!

43 / 50

MPDE example: Upwind scheme

Error in numerical solution can beapproximated as

‖u(t)− v(t)‖1=

∫ ∞−∞|u(x, t)− v(x, t)|dx

=

∫ at

−∞|v(x, t)− 2|dx+

∫ ∞at

|v(x, t)|dxxx = at

2

These two areas are equal

Hence the 1-norm error is

‖v(t)− u(t)‖1 = 2

∫ ∞at

|v(x, t)|dx

= 2

∫ ∞at

erfc

(x− at√

4µt

)dx

= 2√

4µt

∫ ∞0

erfc(z)dz

= C1

õt

44 / 50

MPDE example: Upwind scheme

for some constant C1 independent of µ, ∆x and t. Using the expression for µwe get the following estimate for the error

‖v(t)− u(t)‖1 ≈ C2t12h

12

as h→ 0 with ∆t/h fixed. This indicates that the 1-norm of the error decays

only like h12 even though the method is formally first order accurate based on

the local truncation error, which is valid for smooth solutions only. We alsosee that the thickness of the transition zone (shock structure) increases with

time like t12 .

Remark:

erfc(x) =2√π

∫ ∞x

e−z2

dz

45 / 50

Boundary conditions

• Most of the schemes we have studied till now can be written as

un+1j = H(unj−1, u

nj , u

nj+1)

These are refered to asI two time level (n, n+ 1)I three point (j − 1, j, j + 1)

schemes.

• Consider a grid of N + 1 points indexed as j = 0, 1, 2, . . . , N

• At j = 0 and/or j = N we may need boundary conditions.

46 / 50

Periodic boundary condition

• At left boundary: j = 0

un+10 = H(unN−1, u

n0 , u

n1 )

• For j = 1, 2, . . . , N − 1

un+1j = H(unj−1, u

nj , u

nj+1)

• At right boundary: j = Nun+1N = un+1

0

Matlab code is lin hyp 1d periodic.m and contains backward difference,forward difference and Lax-Wendroff schemes.

47 / 50

Dirichlet boundary condition

Appropriate boundary conditions must come from considerations of thewell-posedness of the PDE problem.

ut + aux = 0, a > 0, x ∈ (0, 1)

Method of characteristics:

Need boundary conditions on

t = 0 and x = 0

for the solution to be fully determined.

x

t

u(x, 0) = f(x)

u(0, t) = g(t)

0 1

48 / 50

Dirichlet BC: Numerical implementation

• At left boundary: j = 0un+1

0 = g(tn+1)

• For j = 1, 2, . . . , N − 1

un+1j = H(unj−1, u

nj , u

nj+1)

• At right boundary: j = NWe cannot apply a three point scheme; use backward difference scheme

un+1N = (1− aλ)unN + aλunN−1

or do linear extrapolation of the solution from the interior

un+1N = un+1

N−1 + hun+1N−1 − un+1

N−2

h= 2un+1

N−1 − un+1N−2

49 / 50

Numerical Example for discontinuous solution

PDE

ut + aux = 0, x ∈ (0, 1), t ∈ (0,1

4)

Discontinuous initial condition

u(x, 0) = 2[1−H(x− 1/2)]

Matlab code lin hyp 1d disc.m. Try with N = 100 and CFL=0.5

• Backward difference: lin hyp 1d disc(100, 0.5, ’bd’)

• Forward difference: lin hyp 1d disc(100, 0.5, ’fd’)

• Lax-Wendroff: lin hyp 1d disc(100, 0.5, ’lw’)

• Also try with N = 1000 grid points

Remark: In this program, we do not update the solution at the first and lastgrid point. The final time t = 1

4 is small enough that the discontinuity doesnot reach the boundary.

50 / 50