You are on page 1of 119

18.

336 spring 2009

lecture 1

02/03/09

18.336 Numerical Methods for Partial Dierential Equations Fundamental Concepts


Domain Rn with boundary PDE in b.c. on

PDE = partial dierential equation b.c. = boundary conditions (if time involved, also i.c. = initial conditions) Def.: An expression of the form F (Dk u(x), Dk1 u(x), ..., Du(x), u(x), x) = 0, x Rn (1)

is called k th order PDE,


k k1 where F : Rn Rn ... Rn R R is given,
and u : R is the unknown.
A function u satisfying (1) is called solution of the PDE. = (ux1 , ..., uxn ) u x1 x1 . . . .. . D2 u = . . . u xn x1 . . . Du gradient (vector) ux1 xn . . Hessian (matrix) . u xn xn . . .
etc.
1

Def.: The PDE (1) is called... (i) linear, if


||k

a (x)D u = f (x)

homogeneous, if f = 0 (ii) semilinear, if


||k

a (x)D u + F0 (Dk1 u, ..., Du, u, x) = 0

(iii) quasilinear, if a (Dk1 u, ..., Du, u, x) D u + F0 (Dk1 u, ..., Du, u, x) = 0


||k

(iv) fully nonlinear, if neither (i), (ii) nor (iii). Def.: An expression of the form F (Dk u(x), Dk1 u(x), ..., Du(x), u(x), x) = 0, is called k th order system of PDE, where F : Rmn Rmn ... Rmn Rm Rm and u : Rm , u = (u1 , ..., um ). Typically: # equations = # unknowns , i.e. n = m. Some examples:
ut + ux = 0 linear advection equation
ut = uxx heat equation
uxx = f (x) Poisson equation (1D)
2 u = f Poisson equation (nD)
ut + cux = Duxx convection diusion equation
ut + ( 1 u2 )x = 0 ut + u ux = 0 Burgers equation (quasilinear)
2 2 u = u2 a semilinear PDE utt = uxx wave equation (1D) u 0 1 u wave equation, written as a system = v t 1 0 v x utt = vxt = vtx = uxx ut + uux = uxxx Korteweg-de-Vries equation ut + ( u ) u = p + 2 u incompressible Navier-Stokes equation u=0 [dynamic-algebraic system] shallow water equations ht + (uh)x = 0 ut + uux = ghx [system of hyberbolic conservation laws] |u| = 1 Eikonal equation (nonlinear) 2
k k1

x Rn

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 2

02/05/09

Well-Posedness
Def.: A PDE is called well-posed (in the sense of Hadamard), if (1) a solution exists (2) the solution is unique (3) the solution depends continuously on the data
(initial conditions, boundary conditions, right hand side)
Careful: Existence and uniqueness involves boundary conditions Ex.: uxx + u = 0 a) u(0) = 0, u( ) = 1 unique solution u(x) = sin(x) 2 b) u(0) = 0, u( ) = 1 no solution c) u(0) = 0, u( ) = 0 innitely many solutions: u(x) = A sin(x) Continuous dependence depends on considered metric/norm.
We typically consider || ||L , || ||L2 , || ||L1 .
Ex.: heat equation
ut = uxx u(0, t) = u(1, t) = 0 boundary conditions
u(x, 0) = u0 (x) initial conditions backwards heat equation
ut = uxx u(0, t) = u(1, t)
boundary conditions

u(x, 0) = u0 (x) initial conditions


well-posed

no continuous dependence

on initial data [later]

Notions of Solutions
Classical solution k th order PDE u C k Ex.: 2 u = 0 u C ut + ux = 0 u(x, t) C 1 u(x, 0) C 1 Weak solution k th order PDE, but u / Ck.

Ex.: Discontinuous coecients


( b ( x ) u ) = 0 x x 4 u (0) = 0

x x< 1 3 2 u(1) = 1
u ( x ) =
2 1 1
x +
x
1 3 3 2 1 x <
2
b(x) =
2 x 1 2 Ex.: Conservation laws u2 )x = 0 Burgers equation ut + ( 1 2

Image by MIT OpenCourseWare.

Fourier Methods for Linear IVP


IVP = initial value problem advection equation ut = ux ut = uxx heat equation
ut = uxxx Airys equation
ut = uxxxx

w=+ a) on whole real axis: u(x, t) =
eiwx u (w, t)dw Fourier transform

w=

b) periodic case x [, [: u(x, t) =

+ k=

u k (t)eikx Fourier series (FS)

Here case b). u nu PDE: (x, t) n (x, t) = 0


t
x
+ du k n insert FS:
(t) (ik ) u k (t) eikx = 0 dt k= Since (eikx )kZ linearly independent: du k = (ik )n u k (t) ODE for each Fourier coecient dt 2

Solution:

Fourier coecient of initial conditions: u k (0)= 21 + k=

u k (t) = e(ik) t u (0) k

u0 (x)eikx dx

u(x, t) =
k k
k

u k (0)eikx e(ik)

nt

n = 1: u(x, t) = n = 2: u(x, t) = n = 3: u(x, t) = n = 4: u(x, t) = Message:

u k (0)eik(x+t) u k (0)eikx ek u k (0)eik(xk u k (0)eikx ek


2t

all waves travel to left with velocity 1 frequency k decays with ek


2 t

2 t)

4t

frequency k travels to right


with velocity k 2 dispersion
all frequencies are amplied
unstable

For linear PDE IVP, study behavior of waves eikx .


The ansatz u(x, t) = eiwt eikx yields a dispersion relation of w to k .
The wave eikx is transformed by the growth factor eiw(k)t . Ex.: wave equation: heat equation: conv.-diusion: Schr odinger: Airy equation: utt = c2 uxx ut = duxx ut = cux + duxx iut = uxx ut = uxxx w w w w w = ck = idk 2 = ck idk 2 = k 2 = k3 conservative dissipative dissipative dispersive dispersive |eickt | = 1 2 |edk t | 0 2 |eickt edk t | 0 2 |eik t | = 1 3 |eik t | = 1

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 3

02/10/09

Four Important Linear PDE


Laplace/Poisson equation 2 u = f in u = g on 1 Dirichlet boundary condition u = h on 2 Neumann boundary condition n 2 = 1

Image by MIT OpenCourseWare.

f 0 Laplace equation 2 u = 0
u = harmonic function
Physical example: Heat equation: ut 2 u = f Dirichlet: prescribe u = g Neumann: prescribe ux u =h n
source

stationary (t ) : ut = 0 2 u = f

Fundamental solution of Laplace equation:



= Rn no boundary conditions Radially symmetric solution in Rn \{0} :
r 2xi xi
n 1 2 xi =
2|x| =
r 2 r = |x| = xi r 2 2
r
1 r xi x 1 xi
i i=1 =
=
3 xi 2 r2 r r u(x) = v (r) r uxi = v (r) x i

2 r
2r xi 2 1
xi 2 uxi xi = v (r) + v (r) = v (r) 2 + v (r)

3 xi xi 2 r r r n n 1
2 u = uxi xi = v (r) + v (r) r i=1 Hence:
n1 v (r) = 0
r v (r) 1n v =0 (log v (r)) = = r v (r) log v (r) = (1 n) log r + log b 2 u = 0 v (r) +
1n
v (r) = b r
br + c n = 1

b log r + c n = 2
v (r) =

b + c n 3
rn2

Def.: The function


1 n = 1

2 |x| log |x|
n = 2
(x
= 0, (n) = volume of unit ball in Rn ) (x) =
21
1
1 n3 n(n2)(n) |x|n2 is called fundamental solution of the Laplace equation. Rem.: In the sense of distributions, is the solution to 2 (x) =
Dirac delta

(x)

Poisson equation: Given f: Rn


R, u(x) = (x y )f (y ) dy (convolution)
solves u(x) = f (x). Motivation: 2 u(x) =
R2 Rn 2

x (x y )f (y ) dy =
R2

(x y )f (y ) dy = f (x).

is a Greens function for the Poisson equation on Rn . Properties of harmonic functions: Mean value property u harmonic u(x) = B (x,r) u ds u(x) = B (x,r) u dy for any ball B (x, r) = {y : ||y x|| r}.
Implication: u harmonic u C
Proof: u(x) = Rn B (0,r) (x y )u(y ) dy
u Ck
convolution average average

u C k+1

Maximum principle Domain Rn bounded. (i) u harmonic max u = max u


(weak MP) (strong MP)

(ii) connected; u harmonic If x0 : u(x0 ) = max u, then u constant

Implications u u max min uniqueness of solution of Poisson equation with Dirichlet


boundary conditions
2 u = f in
u = g on
Proof: Let u1 , u2 be two solutions.
Then w = u1 u2 satises
2 w = 0 in max principle = w 0 u1 u2 w = 0 on

Pure Neumann Boundary Condition: 2 u = f in


u = h on
h has innitely many solutions (u u + c), if f dx = h dS. Otherwise no solution.
Compatibility Condition:
2 f dx = u dx = divf dx = f n dS =

f dS = n

h dS.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009 Heat equation ut = 2 u


Physics:

lecture 4

02/12/09

Ficks law: ux F
= au d mass balance: u dx = b F n dS = b divF dx dt V V V ut = b div(au) = c 2 u

simple: c = 1

Fundamental Solution |x|2 1 4t (x, t) = e (4t)n/2 ut = 2 u in Rn ] 0, [ solves u(x, 0) = (x) t = 0

Superposition: u(x, t) = (x y, t)u0 (y ) dy Rn ut = 2 u in Rn ] 0, [ solves u(x, 0) = u0 (x) Maximum Principle Rn bounded T := [0, T ], T = ( {0}) ( ] 0, T [ )

C u C

Image by MIT OpenCourseWare.

If u is the solution to ut = 2 u in T
u = u0 on {0}
u=g on ] 0, T [
then (i) max u = max u
T T

(weak)

(ii) For is connected: If (x0 , t0 ) T : u(x0 , t0 ) = max u, then u = constant


T

(strong)

Implications: max min uniqueness (see Poisson equation)


innite speed of propagation:
ut = 2 u in T
u=0 on ] 0, T [
u=g on {0}
g 0 = u > 0 in T . Inhomogenous Case: ut 2 u = f in Rn ] 0, [
u=0 on Rn
{0} t solution: u(x, t) = (x y, t s)f (y, s) dy ds
0 Rn strong max principle

Duhamels Principle (variation of constants):


superposition of solutions starting at s with initial conditions f (s).
Transport equation ut + b u = 0 in Rn ] 0, [ u = u0 on Rn {0}
solution: u(x, t) = u0 (x tb).
check: ut = b u0 (x tb) = b u
Inhomogenous Case: ut + b u = f in Rn ] 0, [
u = u0 on Rn {0}
Duhamels principle yields the solution:
t

b = direction vector (eld)

u(x, t) = u0 (x tb) +
0

f (x + (s t)b, s) ds 2

Wave equation utt 2 u = f


source
utt uxx = 0 in Rn ] 0, [ 1D u = g, ut = h on Rn {0}
0 = utt uxx = (t + x )(t x )u
Dene: v (x, t) := (t x )u(x, t) vt + vx = 0 v (x, t) = a(x t)
Thus: ut ux = a(x t)
(inhomogenous transport) [b = 1, f (x, t) = a(x t)]

t transport

u(x, t) = =
1 2 0

a(x + (t s) s) ds + b(x + t)
x+t

a(y ) dy + b(x + t)
xt

initial conditions: b = g, a = h gx
u(x, t) =
1 (g (x + t)+ g (x t))+ 1 2 2

x+t

h(y ) dy
xt

dAlemberts formula. Ex.:

Image by MIT OpenCourseWare.

Higher space dimensions utt 2 u = 0 in Rn ] 0, [ u = g, ut = h on Rn {0} th(y ) + g (y ) + g (y ) (y x) dS (y ) 3D u(x, t) =


B (x,t)

Kirchhos formula. 2D Obtain from 3D solution by projecting to 2D


u (x1 , x2 , x3 , t) := u(x1 , x2 , t)
yields tg (y ) + t2 h(y ) + tg (y ) (y x) dy (t2 |y x|2 )1/2 B (x,t) Poissons formula. u(x, t) =
1 2

Image by MIT OpenCourseWare.

Ex.: g 0, h = . 3D u(x, t) = t

1 |x| = t
(y ) dy = 4t B (x,t) 0 else

sharp front t2 1 t2
1 ( y ) dy = 2D
u(x, t) = 2 2 2 1/2 2t2 (t2 |x|2 )1/2 B (x,t) (t |y x| ) 1 xt 2 2 1 / 2 = 2 (t |x| ) 0 else

signal never vanishes

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 5

02/19/09

Finite Dierence (FD) Approximation


Consider u C l .
Goal: Approximate derivative by nitely many function values:
m ku ( x ) ai u(xi ) (k l) 0 xk i=0

Image by MIT OpenCourseWare.

Vector of coecients a = (a0 , a1 , , am ) is called FD stencil. How to get stencil? Taylor expansion In 1D: u(x) = u(x0 ) + ux (x0 ) (x x0 ) + 1 u (x ) (x x0 )2 2 xx 0 +1 u (x ) (x x0 )3 + O(|x x0 |4 ) 6 xxx 0 Name x i = x i x0
1 = u(xi ) = u(x0 ) + ux (x0 ) x i + 1 u (x ) x 2 3 i |4 ) i + 6 uxxx (x0 ) x i + O (|x 2 xx 0 m m m = ai u(xi ) = u(x0 ) ai + ux (x0 ) ai x i i=0 i=0 i=0 m i=0

ai x 2 i + O(h3 ) where x i h i.

+uxx (x0 )

1 2

Match coecients: m ai u(xi ) ux (x0 ) ai = 0, ai x i = 1


i=0 m
i=0 i i

ai x 2 i

small ai x 3 i

ai u(xi ) uxx (x0 )

ai = 0,

ai x i = 0,

ai x 2 i

=2

small

etc. 1

Vandermonde matrix

1 1 1 1 1 x m 0 x 0 x 1 x m 2 2 x
x V = V (x0 , x1 , , xm ) = 0 m =
. . .
. . .
. . . . .

.

. .
.
. . .
k 0 x 1 x k k m x
k 0 x m V a=b linear system k=1:
ai u(xi ) ux (x0 ) : 1
1
x 0 x m

Constraints for stencil:


a0

0
.


. .


=
1
am a0 0

.


0
=

.
.
2 am

1
1
0 x m k=2: ai u(xi ) uxx (x0 ) :
x 2 x 0 x 2 m

If m = k = In general one unique stencil a If m > k = Multiple stencils Can add additional criteria, e.g. require higher order. Ex.: k = 1, m = 1 1 1 a0 0 = x 0 x 1 1 a1
1 , a1 = 1 = h = a0 = h x 0 = 0, x 1 h

1 1 x 0 = 0, x 1 = h = a0 = h , a1 = h

Image by MIT OpenCourseWare.

Ex.: k = 1, m = 2
x = (x0 , x0 + h, x0 h)


a0 1

1 1 1
0 a a = 1 2

a1
=
=
h 0 h h
1
a0 = a1 a2 a2 One-parameter family of stencils Additional criterion: second order accuracy

Image by MIT OpenCourseWare.

1 1 1 a0 0
0 h h


a1
=

1

=

a0 = 0, a1 = 2 2 0
h h a2 0

1 , a2 2h

=
21 h

Ex.: k = 2, m = 2
1 1
0 x 1 0 x 2 1

Image by MIT OpenCourseWare.

a0 = a1 a2 1 a0 0
2




( x1 x 2 ) x 2
a1 =
0
=

a1 = x 1 2 x 2 a2 2
2 a2 = x ( x2 x 1 ) 2
1 h2

Equidistant: x = (x0 , x0 + h, x0 h)
2 a0 = h 2 , a1 = a2 =

Image by MIT OpenCourseWare.

Higher space dimensions 2D x i = (xi , yi )

Image by MIT OpenCourseWare.

1 0 0 0
0 0

1 x 1 y 1 2 x
1 x 1 y 1 2 y 1

1
x m y m x 2 m x m y m 2 y m

a0 a1 . . .
.
. .

.
. . am

0
0
0
=

stencil a for uxx (x0 ) 2

0


0

3D
1 0 0 0 0 0 0 0
0 0 Ex.:


1 x i y i z i 2 x
i 2
y i
z i2 x i y i x i z i y i z i 2D

a0 1
a1 . .
. .
.
.
.


. .
. . .
.
.
.

.

. . am


0
0
0
0
2 2

stencil for
u(x0 ) = =
2
uxx + uyy + uzz 2
0

0


0

2
u(x0 )

Image by MIT OpenCourseWare.

4 1 1 1 1 2 1 2 1 1 1 a =

h =

h2 , h2 , 0, h , 0, h 2 , h2 , h2 , h2 , h2 2 , 0 +

2 , 0, h2 h2

Image by MIT OpenCourseWare.

a = ( exercise )

Poisson Equation
uxx = f (x) in ]0, 1[
u(0) = a Dirichlet boundary condition 1D
ux (1) = c Neumann boundary condition Discretize on regular grid x = (0, h, 2h, , nh, 1), where h =
1 n+1

Image by MIT OpenCourseWare.

u(xi1 ) + 2u(xi ) u(xi+1 ) Interior: f (xi ) = uxx (xi ) = + O(h2 ) 2 h u i 1 1 2 1 = h ui + O(h2 ) 2 , h2 , h2 ui+1 Dirichlet boundary condition: u0 = u(x0 ) = a (exact) Neumann boundary condition: Naive choice: c = ux (1) un+1 un 1 1 un = + O(h) = , +O(h) un+1 h h h O(h) on a single cell = Could preserve O(h2 ) globally, or drop accuracy to O(h). Here the bad event happens.
Second order approximation:
u(xn+2 ) u(xn ) c = ux (1) = + O(h2 ) 2h un + 2un+1 un+2 Obtain un+2 by = f (1) 2 h 1 1 h un = , = c + f (1) un+1 2 h h

right hand side correction yields 2nd order

Alternative:
un1
1 2 2h , h , 23 un = c
h un+1
nd 2 order one-sided stencil (check by V a = b).
5

Discretization generates linear system: 1 u0 1 2 1


h
1 2 h2 h2 u .
.. .. .. . .
.
.

.

.
. . . . . .
. .
. .

.
1 2 1



h h un 2 2 h2 1 1
h u n+1 h




A u

a f (x1 ) .
.
.
=
.
.
.


f (xn )
c +
h f (1)
2

()

Second order approximation (try it yourself!)


Big Question:
b?
How to solve sparse linear systems A u = lecture 11. Rem.: ()
()
2 1
h 2 h2 1 2 1
h2
h 2 h2 . .
. .
.
.
.
.
.
. . .
.
.
.
1

h 2
1 h2

.
.
.

2 h2 1 h 1
h 2 1 h

u1 . . . .
. .

. . .
un

1 f (x1 ) + h 2a f ( x ) 2 .
.
.
=
.
. .


f (xn1 )
c f (xn )+ h +
f (1) 2

()

from Neumann boundary conditions

un+1 = un + h c + h f (1) 2 1 1 1 h = h 2 un+1 = h2 un + h c + 2 f (1) Advantages: fewer equations matrix symmetric

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 6

02/24/09

General Linear Second Order Equation

a(x)uxx (x) + b(x)ux (x) +


c(x)u(x) = f (x) x ]0, 1[



diusion advection growth/decay source

u(0) =
u(1) = Approximation: ui1 2ui + ui+1 ui+1 ui1 ai + bi + ci ui = fi 2 h 2h
where ai = a(xi ), bi = b(xi ), ci = c(xi ).

Image by MIT OpenCourseWare.

Linear system: A
u=f 1 h2 c1 2a1 a1 + hb 2 a hb2 2 h2 c2 2a2 a2 + hb 2 2 2 ... ... ... 1 A = h2 .. .. .. . . . hbn1 1
an1 2 h2 cn1 2an1 an1 + hbn 2 n an hb h2 cn 2an 2 a1 b1 f1 h 2 2h f2 .

. f =
.

n1 f
an bn fn h2 + 2h

Potential Problems: A non-symmetric If |a(x)| |b(x)|, instabilities possible due to central dierences. Often better approximations possible. 1

Ex.: Heat equation in rod with variable conductivity ( ) ((x)ux )x = f (x) (x)uxx + x (x)ux = f (x) () Can discretize () as before. Suboptimal results. Better: discretize () directly (in line with physics)

Use cell centers

ui+1 ui Image by MIT OpenCourseWare. (xi+ 1 )ux (xi+ 1


) i+ 1

2 2
2 h

u ui ui1 i+1 ui 1
(ux )x (xi ) h i+ 1

i 1

2
2
h
h

1 =
h (i 1
ui1 (i 1
+ i+ 1
)ui + i+ 1
ui+1 )
2
2
2
2

1
A =
h 2

(
1
+ 3
)
3
2
2
2

3
(
3
+ 5
)
5
2
2
2
2
. .
. .
.
.
.
. .
3
3
1
1
(
+ )


n2
n2
n2
n2
3
1
1
n (n
+ n+ )

2
2
2

Symmetric matrix, A positive denite.


Great for linear solvers CG (conjugate gradient method).
2D/3D (u) = f
||
2D: ((x)ux )x + ((x)uy )y 2 1D

Errors, Consistency, Stability


Presentation for Poisson equation, but results transfer to any linear nite dierence scheme for linear PDE. u (x) = f (x) A
U = F

vector of approximate function values

Ui

= true solution values: U Local Truncation Error (LTE)

u(x1 )

. . . u(xn )

Plug true solution u(x) into FD scheme: i =


1 (u(xi1 ) 2u(xi ) + u(xi+1 )) f (xi ) h2 1 = u (xi ) + 12 u (xi )h2 + O(h4 ) f (xi )
1
= 12 u (xi )h2 + O(h4 )

1
. F
= . . =AU n =F + AU Global Truncation Error (GTE) Error vector: E : U U AU = F AE = and E = 0 at boundaries =F + AU e (x) = (x) ]0, 1[ Discretization of e(0) = 0 = e(1) T (x) e(x)
1 u (x)h2 12 1 12 u (x)h2

1 2 h (u (0) 12

+ x(u (1) u (0))

Message: Global error order = local error order if method stable. Stability Mesh size h : Ah E h = h E h = (Ah )1 h 1 ||E h || = ||(Ah ) h || ||(Ah )1 || || h ||

O(h2 )(LTE)

Stability: ||(Ah )1 || C h < h0 Inverse FD operators uniformly bounded. ||E h || C || h || h < h0 . Consistency || h || 0 as h 0 LTE goes to 0 with mesh size Convergence
||E h || 0 as h 0 GTE goes to 0 with mesh size Lax Equivalence Theorem
consistency + stability convergence Proof: (only = here) ||E h || ||(Ah )1 || || h || C || h || 0 as h 0

stability consistency Also: O(hP ) LTE + stability = O(hP ) GTE Stability for Poisson Equation Consider 2-norm 2 1 2
||U ||2 = i Ui ||A||2 = (A) = maxp |p | largest eigenvalue
||A1 ||2 = (A1 ) = maxp |p 1 | = (minp |p |)1
Stable, if eigenvalues of Ah bounded away from 0 as h 0
In general, dicult to show. But for Poisson equation with Dirichlet boundary conditions, it is known that p =
2 (cos(ph) 1) h2 2 1 2 2 4 1 = h 2 ( 2 h + O (h ))

= 2 + O(h2 )
1 || h ||2 . 2

Stable

Hence: ||E h ||2 ||(Ah )1 ||2 || h ||2

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 7

02/26/09

Spectral Methods
[ Reference: Trefethen, Spectral Methods in MATLAB, SIAM 2000 ] Classical Methods: error = O(hp ), p = 1, 2, 3... xed
Spectral: error = O(hp ) p
Error decays (with h) faster than any polynomial order
1 e.g. error = O(h h ) exponential decay
Only true if solution smooth: u C
Otherwise: u C p , u / C p+1 error = O(hp )
Message 1: Spectral methods have a restricted area of application: Linear problems on simple domains with simple boundary conditions and smooth solution. [often times subproblems] But for those, they are awesome. Two Cases: 1. Periodic: = [0, 2 ], where 0 = 2 u(x + 2 ) = u(x)

Use trigonometric functions: u(x) = 2. Non-Periodic: =] 1, 1[

ck eikx

Use polynomials on Chebyshev points (non-equidistant). Message 2: FD/FE/FV methods are local. Spectral methods are global. 1

Periodic Domains = [0, 2 ], 0 = 2 , u(x) = u(x + 2 ) Uniform grid

Task: Approximate u (xi )

ij uj
j

ui+1 ui O(h) : u (xi ) h


u ui1 i +1 (3 point)
O(h2 ) : u (xi ) 2h
ui+2 + 8ui+1 8ui1 + ui2
O(h4 ) : u (xi ) (5 point) 12h ui+3 9ui+2 + 45ui+1 45ui1 + 9ui2 ui3 O(h6 ) : u (xi ) (7 point) 60h Limit: use all points; expect O(hN ) = O(h h ) 1 h 1 2h u (xi ) cot (ui+1 ui1 ) cot (ui+2 ui2 ) 2 2 2 2
1
3h

(ui+3 ui3 ) . . . + cot 2 2 Limit N innite grid
1 1 1
(ui+3 ui3 ) . . . u (xi ) (ui+1 ui1 ) (ui+2 ui2 ) + 3h h 2h Matrix Notation: u = (u1 , u2 , . . . , uN )T w = (w1 , w2 , . . . , wN )T (u (x1 ), . . . , u (xN ))T
w = D u
5 point stencil: 0 2 3 1 12 D =

1 12
2 3 1 12 .. .. .. . . . .. .. .. .. . . . . . .
.
. .
.
. .
.
. .
.
... ... ... .. .. . . 1 1 12 12 2 3 1 12 2 3 1 12 !
1

banded sparse matrix


. .
.
... 1 12 .. 2 . 3 2 3 0 2

Spectral N = 6 :
3 4 5 0 1 2 1 0 1 2 3 4 2 1 0 1 2 3 full matrix
D6 =
3 2 1 0 1 2
4 3 2 1 0 1
5 4 3 2 1 0 j = 1 cot jh 2 2 How to obtain spectral dierentiation matrices? Fourier Basis: u periodic on [0, 2 ] = u(x) = u k eikx (Fourier series, bounded)
k Z

u only known at grid points xj = jh

where h =

2 N = N h 2
N

[here: N even]

2 1

uj = 2
N

u k eikxj

discrete Fourier series

k=

physical space : discrete, bounded



Fourier space : bounded, discrete u k = h
N j =1

+1

uj eikxj k =

N N + 1, . . . , 2
2

Discrete Fourier Transform (DFT) Use FFT to do in O(N log N )!


N 2 1
uj = 2
N

u k eikxj

k=

+1

2 1 = u k eikxj 2
N

k=

N 2

where

k= N 2

1 N N ,
u ck = 1 c
N + c


N N +1 +
+ c
1 +
2 c
N =
u 2
2 2 2 2 2 2

Finite Fourier sum due to grid aliasing:

j sin(x) = sin(5x) on the grid xj = 2 N Nyquist sampling theorem At grid points:

N 2 1
u(xj ) = u k eikxj 2 N

k=

Dene interpolant:

N 2 1
p(x) =
u k eikx 2 N

Band-Limited Interpolant (BLI)


N 2

k=

Trigonometric polynomial of degree Basis function: 1 j = 0 (mod N ) BLI for j 0 j = 0 (mod N )

uj = j u k = h
N 2

DFT

N j =1

j eikxj = h k

sin( x ) h
ikx
p(x) =
e = =
2 h x =: SN (x) 2
N tan( 2 )
h
k=
2

periodic sinc function 4

Arbitrary grid values: (u1 , u2 , . . . , uN ) uj =


N m=1 N m=1

um j m p(x) =

um SN (x xm )

Dierentiation: Dierentiate BLI p(x) p (x)



0 j = 0 (mod N )
SN (xj ) = 1 0 (mod N ) (1)j cot( jh ) j= 2 2

... ... ... ... h 1 h 1 2h cot( ) 0 cot( ) cot( )
. . .

DN =
. . .

1 2 2 2 2 2 2

.. .. .. .. . . . . . .. . . . . . . 1 csc( 2h ) 2 2 . ... 1 2 h .. csc ( 2 ) 2 .. 2 (2) 2 . 1 .
DN =
.
.
= DN 3 h 6 .. ... 1 2 h . csc ( ) 2 2 . 1 2 2h .. csc ( )

2 2 . .. . . .

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009 Non-periodic Domains

lecture 9

03/05/09

So use algebraic polynomials p(x) = a0 + a1 x + + aN xN Problem: Runge phenomenon on equidistant grids

u(x) as N p(x)

Remedy: Chebyshev points

j xj = cos N

PN (x) u(x) as N

Spectral Dierentiation:
Given (u0 , u1 , . . . , uN ) interpolating polynomial N k=j (x xk ) p(x) = uj
k=j (xj xk ) j =0 ai

aj (xi xj ) i = j p (x) p (xj ) Dij =
1
i=j
xj xk k=j
aj = k=j (xj xk ) Chebyshev Dierentiation Matrix: 2N 2 + 1 6 (1)j 2 1 xj (1)i+j xi xj DN = 1 2 (1)i 1 xi (1)i+j xi xj 1 (1)N 2 2 (1)N +j 1 + xj 2N 2 + 1 6 xj 2(1 x2 j)
1 2 1 (1)N 2

(1)N +i 1 + xi

where xj = cos( j ), j = 0, . . . , N N w = DN u( x) u ( x) with spectral accuracy. 2 w = DN u( x) u ( x) with spectral accuracy. etc.

Chebyshev Dierentiation using FFT:


1. Given u0 , . . . , uN at xj = cos( j ). N = (u0 , u1 , . . . , uN , uN 1 , . . . , u1 ) Extend: U
2N ikj 2. FFT: Uk = e Uj , k = N + 1, . . . , N N j =1

k = ikU k , W N = 0 (rst derivative) 3. W N 1 ikj 4. Inverse FFT: Wj = e Wk , j = 1, . . . , 2N 2 k=N +1


Wj
wj = , j = 1, . . . , N 1 1 xj 2 5. N N 1 2 1 nu n , wN = (1)n+1 n2 u n w0 = 2 2 n=0 n=0 p(x) = P (), x = cos N p(x) = n Tn (x) P () =
n=0 N n=0

Visualization for N = 10:

n cos(n)

Tn (x) = Chebyshev polynomial Tn+1 (x) = 2xTn (x) Tn1 (x) nn sin(n)
P ( ) p (x) = = n=0
dx sin
d
N nn sin(n)
= n=0
1 x2
N

Boundary value problems


uxx = e4x , x ] 1, 1[ Poisson equation with homogeneous Ex.: u(1) = 0 Dirichlet boundary conditions Chebyshev dierentiation matrix DN . Remove w0 w1 .

. .

wN 1 wN boundary points: 2 D =
N

2 DN

v0 [= 0] v1 .

. .



v N 1 vN [= 0]


Interior points
p13.m

Linear system:

2 u=f D
n

= (e4x1 , . . . , e4xN 1 ) where u = (u1 , . . . , uN 1 ), f Nonlinear Problem uxx = eu , x ] 1, 1[ Ex.: u(1) = 0 initial guess Need to iterate: u(0) = 0, u(1) , u(2) , . . .
(k+1) 2 = exp( u(k) ) xed point iteration
D Nu Can also use Newton iteration... Eigenvalue Problem uxx = u, x ] 1, 1[ Ex.: u(1) = 0 2 Find eigenvalues and eigenvectors of matrix D N Matlab: >> [V,L] = eig(D2) Higher Space Dimensions uxx + uyy = f (x, y ) =] 1, 1[2 Ex.: f (x, y ) = 10 sin(8x(y 1)) u=0
Tensor product grid: (xi , yj ) = (cos( i ), cos( j ))
N N

p14.m

p15.m

p16.m Matrix approach: Matlab: kron, 2 + D 2 I LN = I D N N >> L = kron(I,D20)+kron(d2,I) Linear system: LN u=f
Image by MIT OpenCourseWare.

spectral Helmholtz Equation Wave equation with source vtt + vxx + vyy = eikt f (x, y ) Ansatz: v (x, y, t) = eikt u(x, y ) Helmholtz equation: uxx + uyy + k 2 u = f (x, y ) =] 1, 1[2
u=0

classical FD

p17.m

Fourier Methods So far spectral on grids (pseudospectral). Can also work with Fourier coecients directly. Ex.: Poisson equation (uxx + uyy ) = f (x, y ) = [0, 2 ]2 periodic boundary conditions

Image by MIT OpenCourseWare.

f (x, y ) = u(x, y ) =

k,lZ

i(kx+ly ) f kl e

k,lZ

u kl ei(kx+ly) u kl ei(kx+ly) (k 2 ) u kl (k 2 + l2 )ei(kx+ly) = f (x, y )


!

uxx (x, y ) =
2

k,l

u(x, y ) = u kl =

k,l

f kl (k, l) = (0, 0) k 2 + l2

u 00 arbitrary constant, condition on f : f 00 = 0 In Fourier basis, dierential operators are diagonal.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 10

03/10/09

Elliptic Equations and Linear Systems


In rectangular geometries, construct 2D/3D from 1D by Tensor product. (uxx + uyy ) = f (x, y ) ] 1, 1[2 Ex.: u = 0 on

Image by MIT OpenCourseWare.

Assume have 1D discretization of uxx = f ] 1, 1[


u = 0
{1, 1}

Image by MIT OpenCourseWare.

e.g.: nite dierence

K1D =

sparse

2D discretization:

I K1D

K1D I

K2D =

Spectral (cheb.m (interior))

K1D =

full

2D discretization:

I K1D

K1D I

K2D =

Kronecker product:
1 2 3 4 a b
c d a b c d =
3a 3b 3c 3d 2a 2c 4a 4c 2b 2d 4b
4d

Matlab: K2D = kron(I1D, K1D) + kron(K1D, I1D)

Lexicographic ordering:

Image by MIT OpenCourseWare.

Also possible: red-black ordering

2D = K

1 h2

(advantageous for elimination) 3D:

Images by MIT OpenCourseWare.

K3D = kron(K2D, I1D) + kron(I2D, K1D)

Image by MIT OpenCourseWare.

Alternative to Tensor product: directly by Taylor expansion

Ex.: 2D Poisson equation: (uxx + uyy ) = f

1 h2

1 6h2

5-point stencil
2 2

9-point stencil

h2 5 u = u + (uxxxx + uyyyy ) + O(h4 ) 12 h2 9 2 u = 2 u + (uxxxx + 2uxxyy + uyyyy ) +O(h4 ) 12


=2 (2 u)=2 f

Advantage of 9-point stencil: deferred correction h2 9 2 uij = f (xi , yi ) 2 f (xi , yi ). 12 Fourth order scheme.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 11

03/12/09

Ecient Methods for Sparse Linear Systems


If spectral FFT ! If non-spectral (FD, FE): elimination (direct) iterative multigrid
Krylov methods (e.g. conjugate gradients)
Elimination Methods Solve A
x = b Matlab: x = A\b
If A square, regular: can use elimination methods A symmetric positive denite: Cholesky factorization
Otherwise: LU factorization
Fill-in

Image by MIT OpenCourseWare.

Adding rows creates nonzero entries and may thus destroy sparsity. Matlab: [L,U] = lu(A); spy(L) spy(U) Minimum degree algorithms: Reduce ll-in by reordering of rows and columns Ex.: Red-black ordering for K2D

Matlab:
A non-symmetric p = colamd(A) [L,U] = lu(A(p,:)) A symmetric p = symamd(A) [L,U] = lu(A(p,p)) or [L,U] = chol(A(p,p)) Strategy: Choose remaining meshpoint with fewest neighbors

Strategy: Choose remaining column with fewest nonzeros Further: Graph separators
Nested dissection

Elimination is great for small matrices whose entries are directly accessible. Preconditioning A
x = b Condition number: = cond(A) = ||A|| ||A1 ||
|max |
A symmetric: cond2 (A) = |min |
cond(A) 1 small error in b can yield large error in x Formulate equivalent system which is better conditioned.
Left preconditioning: solve (P 1 A) x = P 1 b
Right preconditioning: 1. solve (AP 1 ) y = b 2. solve P x = b 1 1 Ex.: A = {0.999, 1000.001} cond(A) 1000 1 1000 1 0 P = diag(A) = 0 1000
cond2 (P 1 A) = cond(AP 1 ) 2.65

Image by MIT OpenCourseWare.

Ex.: P = D P = D + L A=
Image by MIT OpenCourseWare.

P = Lapp Uapp (ILU = Incomplete LU factorization) [Matlab: luinc] Iterative Methods Ax=b x = (I A) x + b splitting
(k+1) (k) = (I A) x + b x iteration
(0) x = x0 (AP 1 )y = b Apply to precondition system: Px = y y (k+1) = (I AP 1 )y (k) + b
P x(k+1) = (P A)x(k) + b
x(k+1) = (I P 1 A) x(k) + P 1 b
=M

P (x Error:

(k+1)

=z (k)

(k) x )= bA x =r(k)

(k)

update

residual

x = A1 b e(k) = x x(k) e(k+1) = M e(k) [independent of b ] Iteration converges if (M ) < 1


Spectral radius (M ) = max |(M )|
Popular Preconditioners:

A=
Image by MIT OpenCourseWare.

P =D Jacobi P =D+L Gau-Seidel P = D + wL SOR (Successive OverRelaxation) [better: SSOR] 3

M = I D1 A M = I (D + L)1 A (overwrite entries as computed)

Theorem:
If A diagonal dominant |aii | >
j =1

|aij | Jacobi converges

If Jacobi converges Gau-Seidel converges ( 2 faster) If 0 < w < 2 SOR converges 2


wopt = , = (I (D + I )1 A). 2 1+ 1 Multigrid Heat Equation ut 2 u = f
1 p I t

Iterative Scheme P (u(k+1) u(k) ) = A


u(k) + f
Poisson matrix

Iterative schemes behave like heat equation.


Slow convergence, fast smoothing of error.
Smoothers:
3 P =2 D Weighted Jacobi
P =D+L Gau Seidel (popular)
P = D + wL SOR (costly)
Smoother reduces high frequency error components fast. Smooth error is rough on coarser grid. uxx = 1 Ex.: u(0) = 0 = u(1)

ne grid (h = 1 ) 8

1
. . 1 . . . . Ah = 64 ... ...
1 1 2 2

coarse grid

A2h = . . .

Interpolation: Linear

1 2 1 1 1 73 2
I =
2 R 1 1
2
1 Restriction: Full Weighting

1 2 1


1 2 1
R =
1 4 1 2 1 R= 1 IT 2 Coarse Grid Matrix: Galerkin: A2h 2 1 = R Ah I = 16
1 2 1
1
2

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009 Twogrid Method: Fine:


2h Rh

lecture 12

03/17/09

Ah u = bh

h
I2 h

Coarse: A2h v = b2h

Iterate Ah u = bh (1 GS) uh 2h Restrict residual rh = bh Ah uh by r2h = Rh rh Solve for coarse error: A2h e2h = r2h h Interpolate error: eh = I2 h e2h
Update u h = uh + eh
(5) Iterate Ah u = bh (2 GS) starting with u h (1) (2) (3) (4) v-cycle:

Multigrid:

Image by MIT OpenCourseWare.

Use twogrid recursively in (3) V-Cycle:

Image by MIT OpenCourseWare.

W-Cycle: Apply (3) twice

FMG (full multigrid):

Image by MIT OpenCourseWare.

Optimal: Cost = O(n). Krylov Methods

Image by MIT OpenCourseWare.

Consider A x = b already preconditioned. Iterative scheme: x(k+1) = x(k) + (b Ax(k) ) x(0) = 0 x(1) = b x(2) = 2b Ab x(3) = 3b 3Ab + A2 b Observe: x(k) Kk Kk = span{b, Ab, . . . , Ak1 b} where

Krylov subspace K1
x(1) K2
x(2) K3 x(3)
...

Find sequence x(k) Kk which converges fast to x = A1 b. Only requirement: Apply A (can be blackbox). Examples of Krylov Methods: Choose x(k) Kk , such that (1) rk = b Axk Kk conjugate gradients (CG) (2) ||rk ||2 minimal GRMES & MINRES (3) rk Kk (AT ) BiCG (4) ||ek ||2 minimal SYMMLQ 2

Conjugate Gradient Method A symmetric positive denite


Enforce orthogonal residuals: rk Kk
Know xk Kk rk = b Axk Kk+1 rk = k qk+1 (k R)
where q1 , q2 , q3 , . . . orthonormal, and qk Kk .
ri T rk = 0 i < k.
rk = rk rk1 Ki xi T
rk = 0 i < k
xi = xi xi1 Ki
Also: rk = (b Axk ) (b Axk1 ) = A xk xi T A xk = 0 i < k Updates (= directions) are A-orthogonal or conjugate;
Scalar product (xi , xk )A := xi T A xk .
Search direction: dk1
Update solution: xk = xk1 + k dk1
New direction: dk = rk + k dk1
k = k = ||rk1 ||2 2 , so that error in direction dk1 minimal
dT k1
A dk1 ||rk ||2 2 , so that (dk , dk1 )A = 0 ||rk1 ||2 2 (xmin = A1 b)

CG nds unique minimizer of E (x) = 1 xT A x xT b 2 using conjugate directions after at most n steps.

Image by MIT OpenCourseWare.

In practice much faster than n steps.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 13

03/19/09

Initial Value Problems (IVP)


ut = Lu u = u0
u=g where L in ]0, T [ PDE
on {0} initial condition on ]0, T [ boundary condition dierential operator.

Ex.: L = 2 Poisson equation heat equation Lu = b u advection equation 2 2 Lu = ( u) not done yet.
biharmonic equation beam equation
Lu = F |u| nonlinear
Eikonal equation level set equation
etc. Stationary solution of IVP: Lu = 0 in
(if it exists) u = g on
Later: second order problems
systems u 0 1 u utt = uxx =

1 0 t v x v (wave equation) Semi-Discretization In space (method of lines): Approximate u(, t) by u(t) Approximate Lu by A u (for linear problems) [FD, FE, spectral] d system of ODE: u = A u
dt In time:
Approximate time derivative by step: d u(x, t + t) u(x, t) u(x, t) [explicit Euler] dt t Stationary problem: unew (x) = u(x) + tLu(x) = (I + tL)u(x) Need to know about ODE solvers. 1

Numerical Methods for ODE


y (t) = f (y (t)) y (0) = y
y (t) Rd

y n y (t), y n+1 y (t + t)
y n+1 y n
Linear approximation: y t Explicit Euler (EE): y n+1 = y n + t f (y n ) Implicit Euler (IE): y n+1 t f (y n+1 ) = y n nonlinear system Newton iteration. Local truncation error (LTE):
EE: n = y (t + t) (y (t) + tf (y (t))) = 1 y (t)t2 = O(t2 )
2 IE: n = O(t2 ) Global truncation error (GTE): T Over N = time steps. t
E n = y n y (tn )
E n+1 = E n + t(f (y n ) f (y (tn ))) + n
= |E n+1 | |E n | + tL|E n | + | n
| T = |E N | eLT maxn | n | = O(t) t Time Stepping: GTE = one order less than LTE. Higher Order Time Stepping Taylor Series Methods: Start with EE, add terms to eliminate leading order error terms. PDE Lax-Wendro Runge-Kutta Methods: Each step = multiple stages k1 = f (y n + t aij kj )
. . . kr y n+1

= f (y n + t arj kj )
j
= y n + t bj kj

Butcher tableau: (cl =

alj )

c1 . . . cr

a11 . . . . .. . . . ar1 . . . b1 . . .

a1r . . c A . = bT arr br 0 1 1 1 1 0
1 2 1 2

EE: IE:

k1 = f (y n ) n+1 y = y n + tk1
=y n+1

k1 = f (y n + t k1 ) y n+1 = y n + t k1

Explicit midpoint:

0 1 Heuns: 0 1 1
1 2 1 2

0 RK4:
1 2 1 2 1 2 1 2

1
1 2 1 6 1 2 1 3

1
1 3 1 6

Implicit trapezoidal:

PDE Crank-Nicolson

Multistep Methods: r r n+j j y = t j f (y n+j )


j =0 j =0

Explicit Adams-Bashforth: = EE y n+1 = y n + tf (y n ) 3 1 n+2 n+1 n+1 n y = y + t [ 2 f (y ) 2 f (y )] . . . Implicit Adams-Moultion: f (y n ) + 1 (y n+1 )) y n+1 = y n + t ( 1 2 2 5 8 n+2 n+1 n+2 y = y + t ( 12 f (y ) + 12 f (y n+1 ) . . . BDF (backward dierentiation): y n+1 = y n + tf (y n+1 ) = IE 3y n+2 4y n+1 + y n = 2tf (y n+2 ) . . . 3

O(t) O(t2 )

= trapezoidal
1 f (y n )) 12

O(t2 ) O(t3 )

O(t) O(t2 )

Linear ODE Systems



y =Ay y (0) = y solution: y (t) = exp(tA) y solution stable, if Re(i (A)) < 0 i. EE: y n+1 IE: y n+1 EE
= (I + t A) y n = (I t
A)1 y
n
=MIE =M

Iteration y n+1 = M y n stable, if |i (M )| < 1 i i eigenvalue of A


2
1 + t i eigenvalue of MEE
|1 + t
i | < 1 if t <
|i |
1
1

< 1 always
eigenvalue of MIE
1 t i 1 t i 2
EE conditionally stable: t < (A) IE unconditionally stable Message: One step implicit is more costly than one step explicit. But: If (A) large, then implicit pays!

stiness

Ex.: Dierent time scales


50 49 2 A= , y= 49 50
0
1 1 t 99t Solution: y (t) = e +e 1 1




behavior restricts t for EE

Ex.:

2 1 . .
. .
.
.
1
1
A= 2 . .. ... 1 (x)
1 2

4<i <0

heat equation

4

( A ) <

(x)2

(x)2 . 2 OTOH: Crank-Nicolson t t n+1 I A y = I+ A yn 2 2 Unconditionally stable. EE stable if t < 4

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 14

03/31/09

Von Neumann Stability Analysis


Lax-equivalence theorem (linear PDE): Consistency and stability
convergence

(Taylor expansion) (property of numerical scheme)

Idea in von Neumann stability analysis:


Study growth of waves eikx .
(Similar to Fourier methods)
Ex.: Heat equation ut = D uxx Solution: Dk2 t ikx u(x, t) = e e
=G(k) growth factor

no growth if |G(k )| 1 k FD Scheme:


n n Ujn+1
Ujn Ujn +1 2Uj + Uj 1
=D t (x)2 (Explicit Euler) (Central) Dt n n Ujn+1 = Ujn + r Ujn +1 2Uj + Uj 1 , r = (x)2 Insert u(x, tn ) = eikx into FD scheme: Ujn+1 = eikxj + r eikx(j +1) 2eikxj + eikx(j 1)

= (1 + r(eikx + eikx 2))eikxj = G(k )


eikxj Growth factor: G(k ) = 1 2r (1 cos(k x))
FD scheme stable, if |G(k )| 1 k
Here: worst case: k x = G(k ) = 1 4r
Hence FD scheme conditionally stable: r
1 2

(seen before)

Fast version:
ei 2 + ei 2D
G1 =D = (cos() 1) t (x)2 (x)2 G = 1 2r (1 cos ), = k x Ex.: Crank-Nicolson Ujn+1 Ujn 1 =D t 2
+1 n+1 +1 n n Ujn + Ujn Ujn +1 2Uj 1 +1 2Uj + Uj 1 + (x)2 (x)2

G1 1 ei 2 + ei = D (G + 1) t 2 (x)2
1 r (1 cos )
G= 1 + r (1 cos ) Always |G| 1 unconditionally stable. Ex.: 2D heat equation ut = uxx + uyy Forward Euler n+1 n n n n n n U1 Uij Uin Ui,j j +1,j 2Ui,j + Ui1,j +1 2Ui,j + Ui,j 1
= + t (x)2 (y )2
x u(x, y, tn ) = ei(k,l)( y ) = eikx eily
G1 eikx 2 + eikx eily 2 + eily
= + t (x)2 (y )2
t t
G=12 (1 cos(k x)) 2 (1 cos(ly )) 2 (x) (y )2 t t Worst case: k x = = ly G = 1 4 4 2 (x) (y )2 Stability condition: 1 1 1 h2 t t 1 1 + t + = (x)2 (y )2 2 2 (x)2 (y )2 4
if x=h=y

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 15

02/13/08

Finite Dierence Methods for the One-Way Wave Equation


ut = cux u(x, 0) = u0 (x)

Solution: u(x, t) = u0 (x + ct) Information travels to the left with velocity c. Three Approximations: n Ujn +1 Uj c upwind x
n Ujn+1 Ujn Uj Ujn 1
= c downwind t x U n Ujn 1 c j +1 centered 2x Accuracy: Taylor expansion of solution u u(x, t + t) u(x, t) 1 1 = ut + utt t + uttt (t)2 + O((t)3 ) t 2 6
1 1
u(x + x, t) u(x, t) = ux + uxx x + uxxx (x)2 + O((x)3 ) x 2 6
1
u(x + x, t) u(x t, t) = ux + uxxx (x)2 + O((x)4 ) 2x 6 Substitute into FD scheme: 1 Upwind: ut + utt t cux 1 cuxx x + O(t2 ) + O(x2 ) 2 2
=cux
=1 c2 uxx t
2

Image by MIT OpenCourseWare.

Leading order error: 1 u t 1 cuxx x = 1 c2 uxx t 1 cuxx x = 1 cuxx x(r 1) 2 tt 2 2 2 2 = 0 if r = 1 1 First order if r = 1 ct x
Courant number
r=

Downwind: Analogous: rst order


u t cux 1 cuxxx x2 + O(t2 ) + O(x4 )
Centered: ut + 1 2 tt 6 t First order in time x2 Second order in space Stability: Upwind: G1 eikx 1 =c t x ikx G = 1 r + re |G| |1 r| + |reikx | = 1, if 0 r 1 conditionally stable
CFL-Condition

Image by MIT OpenCourseWare.

Downwind: G = 1 + r reikx unstable

Image by MIT OpenCourseWare.

eikx eikx = 1 + ir sin(k x) Centered: G = 1 + r 2 unstable

Image by MIT OpenCourseWare.

Messages: 1. Upwind works (CFL-condition on stability) 2. Centered needs a x Add Diusion: n n n Ujn+1 Ujn Ujn Ujn +1 Uj 1 +1 2Uj + Uj 1 =c + t 2x (x)2
Replace Ujn by average:
n n n n Ujn+1 U + (1 ) U + U Ujn j +1 j j 1 +1 Uj 1 2 2 =c t 2x t where = 2 (x)2
How much diusion?
Lax-Friedrichs:
Eliminate Ujn by = 1 = Ujn+1 = 1+r 2 Ujn +1 + (x)2
2t
1 r
Ujn 1 2

r=

ct x

0(for |r|1)

0(for |r|1)

Monotone scheme
Accuracy: First in time, Second in space (exercise)
Stability: G = ir sin(k x) + cos(k x)

central dierence diusion

conditionally stable |r| 1

Image by MIT OpenCourseWare.

Lax-Wendro: Choose to get second order in time: =


n Ujn+1 Ujn Ujn +1 Uj 1 =c t 2x

t 2 c 2 n t 2 Uj +1 2Ujn + Ujn 1 + c 2 2 (x) 3

t 2 t 2 Accuracy: ut + 1 u t+ 1 u t2 cux 1 cuxxx x2 c uxx c uxxxx x2 2 tt 6 ttt 6 2 24

=1 u t2 1 cuxxx x2 = O(t2 ) + O(x2 ) 6 ttt 6 ut cux = 0


1 u t 2 tt

t 2 c uxx 2

=0

Stability: = r2 G= r2 + r ikx r2 r ik(x) e + (1 r2 ) + e 2 2


= (1 r2 ) + r2 cos(k x) + ir sin(k x)

Worst case: k x = G = 1 2r2 Stable if |r| 1

Image by MIT OpenCourseWare.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 16

02/19/08

Modied Equation
Idea: Given FD approximation to PDE Find another PDE which is approximated better by FD scheme. Learn from new PDE about FD scheme. Ex.: ut = cux
n n n Ujn+1 Ujn Ujn Ujn +1 Uj 1 +1 2Uj + Uj 1 Lax-Friedrichs: c =0 t 2x 2t 1 1 1 1 Taylor: ut + utt t cux cuxxx x2 uxx x2 uxxxx x4 + . . . 2 6 2t 24t 1 x2 = (ut cux ) + utt t uxx + ... 2 t =c2 uxx 1 2 x2 = (ut cux ) + c t uxx 2 t
Modied equation:
x2
ct ut cux = (1 r2 )uxx r= 2t x
Advection-diusion equation with diusion constant
x2 D= ( 1 r2
) 2t added diusion antidiusion by central dierencing

Ex.: Upwind: ut cux = 1 cx(1 r)uxx 2

(exercise)

Compare:
DLF = 3 x , DUW = 1 x
For c = 1, r = 1 2 4 4 Upwind less diusive than LF. Ex.: Lax-Wendro cx2 (r2 1)uxxx ut cux = 1 6 (uxx cancels by construction)

Advection-dispersion equation with dissipation constant


= 1 cx2 (1 r2 )
6 Disturbances behave like Airys equation
Message: First order methods behave diusive. Second order methods behave dispersive. 1

More on Advection Equation


ut + cux = 0
So far:
1. Upwind:
Ujn+1 Ujn =
t
U n Ujn
c j +1 c<0 x 2. Lax-Friedrichs/Lax-Wendro:
n n n Ujn+1 Ujn Ujn Ujn +1 Uj 1 +1 2Uj + Uj 1 = + t 2x (x)2 (x)2
e = O(t) + O(x2 ) LF: = 2t t 2 c e = O(t2 ) + O(x2 )
LW: = 2

Ujn Ujn 1 c c>0


x

e = O(t) + O(x)

Semidiscretization: Uj +1 Uj 1 + O(x2 ) Central: ux = 2x





0 1 1
(ux )1 u1 . .
.
.
.
.
1
1
.
.

Matrix

.

.
.


=
2x
.
. . . . . . 1

(ux )k uk 1 1 0

=A

A = A eigenvalues purely imaginary Need time discretization that is stable for u = u with = i, R
Linear Stability for ODE:
= u}
Region of absolute stability = { C : method stable for u

Ex.: Forward Euler un+1 = un + tun = (1 + t)un Stable if |1 + t| 1 Backward Euler 1 un+1 = un 1 t Trapezoidal 1+ 1 t 2 n+1 u = 1 1 t 2

RK4

RK2

Adams-Bashforth 3

Can also use higher order discretization of ux (up to spectral). If central need ODE solver for timestep that is stable for u = iu. Spurious Oscillations Stable does not imply no oscillations. Ex.: Lax-Wendro

Image by MIT OpenCourseWare.

Overshoots remain bounded stable. Still bad (e.g. density can become negative) 3

Total Variation: T V (u) = |uj +1 uj | |ux (x)|dx total up and down


j

Method total variation diminishing (TVD), if


T V (un+1 ) T V (un ).
Bad News: Any linear method for advection that is TVD,
is at most rst order accurate.
[i.e.: high order spurious oscillations]
Remedy: Nonlinear Methods: 1. Flux-/Slope- Limiters conservation laws; limit ux TVD 2. ENO/WENO (weighted) essentially non-oscillatory
(essentially TVD; no noticeable spurious oscillations)

ENO/WENO Approximate ux by interpolation.

ENO: At each point consider multiple interpolating polynomials (through various choices of neighbors). Select the most stable one to dene ux . WENO: Dene ux as weighted average of multiple interpolants. Higher order when u smooth, no overshoots when u non-smooth.

Ex.: Fifth order WENO

Image by MIT OpenCourseWare.

s1 = s2 = s3 = a1 = a2 =

13 (v 12 1 13 (v 12 2 13 (v 12 3 1 /( 10 6 /( 10 3 /( 10

2v2 + v3 )2 + 1 (v 4v2 + 3v3 )2 4 1 2v3 + v4 )2 + 1 (v v4 )2 4


2 2v4 + v5 )2 + 1 (3v3 4v4 + v5 )2 4 + s1 )2 + s2 )2 vj =

Uj +1 Uj
x

= 106 max(vj 2 )
j

a3 = + s3 )2 sa = a1 + a2 + a3 1 w1 = a sa
w2 = w3 = w=
a2
sa
a3
sa 1 (w1 6

(2v1 7v2 + 11v3 ) + w2 (v2 + 5v3 + 2v4 ) + w3 (2v3 + 5v4 v5 )) Left sided approximation to ux at x4
Right sided approximation to ux at x3

ut + cux = 0
Upwind WENO with FE:

Ujn+1 Ujn c WENOleft Ujn > 0 = c WENOright Ujn 0 t TVD time stepping Consider method that is TVD with FE. Is it also TVD with high order time stepping? In general: no. But for special class of ODE schemes: yes. Strong Stability Preserving (SSP) methods

Ex.: FE (un ) = un + tf (un ) RK3-TVD n+1 n u


=
1 u
+2 FE (
3 un
+1 FE(FE(un
))) 3 3 4 4 Convex combination of FE steps Preserves TVD property Compare: Classical RK4 cannot by written this way. It is not SSP. Popular approach for linear advection:
ut + cux = 0
RK3-TVD in time, upwinded WENO5 in space.
2D/3D: Tensor product in space.

Image by MIT OpenCourseWare.

WENO5-stencil

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 17

04/09/09

Conservation Laws
ut + (f (u))x = 0
if uC 1

ut + f (u) ux = 0
=c(u)

Conservation form Dierential form d b u(x, t)dx = f (u(a, t)) f (u(b, t)) dt a Integral form Ex.: Transport equation f (u) = cu c(u) = f (u) = c Ex.: Burgers equation

f = ux function

u2 c(u) = f (u) = u f (u) = 1 2 ut + uux = 0


Model for uid ow
Du 1D Material derivative: = ut + (u )u = ut + uux Dt Ex.: Trac ow (x, t) = vehicle density = 0 empty = 1 packed

m(t) =
a

Image by MIT OpenCourseWare.

(x, t)dx = number of vehicles in [a, b]

d m(t) = f ((a, t)) f ((b, t)) dt Inux Outux 1

Equation:

t + (f ())x = 0 where f () = v Flux function f () = (1 )

vehicle velocity

Velocity function v = v () = 1

Velocity of information c() = f () = 1 2

Method of Characteristics ut + f (u)ux = 0


u(x, 0) = u0 (x)
Follow solution along line x0 + ct, where c = f (u0 (x0 )).
d
u(x + ct, t) = cux (x + ct, t) + ut (x + ct, t) dt = (c f (u(x + ct, t))) ux (x + ct, t) = 0
=0

u(x + ct, t) = constant = u(x0 , 0) = u0 (x0 ). Ex.: Transport Burgers Trac

Characteristic lines intersect shocks

Weak Solutions ut + (f (u))x = 0 () u(x, 0) = u0 (x) Solution for u0 C 1 smooth until characteristics cross. x1 + f (u0 (x1 )) t = x2 + f (u0 (x2 )) t x2 x1 1 t= = x [x1 , x2 ] (f u0 ) ( x) f (u0 (x2 )) f (u0 (x1 )) 1 = f (u0 ( x))u0 ( x) ts = 1 infx f (u0 (x))u0 (x)

Solution for t > ts : Weak formulation + () ut + f (u)x dx dt =


0 +

Image by MIT OpenCourseWare.


1 [u]t=0 dx C0

Test function, C 1 with compact support

If u C 1 (classical solution), then () ()


Proof: integration by parts.
In addition, () admits discontinuous solutions.
Riemann Problem uL x < 0 u0 (x) = uR x 0
d b
(uL uR ) s = u(x, t) dx dt a
= f (uL ) f (uR )
s= f (uR ) f (uL ) uR uL
Image by MIT OpenCourseWare.

Rankine-Hugoniot Condition for shocks

Ex.: Burgers

s =
2

1
2
uR

1 2 2 uL uL + uR = uR uL 2

Image by MIT OpenCourseWare.

Replace breaking wave by shock


Image by MIT OpenCourseWare.

Rarefactions Ex.: Burgers Many weak solutions...

Image by MIT OpenCourseWare.

This is what physics yields (stable w.r.t. small perturbations)

Entropy Condition to single out unique weak solution: Characteristics go into shock: f (uL ) > s > f (uR ) Solution to ut + (f (u))x = 0 is limit of ut + (f (u))x = uxx as 0 Vanishing viscosity Many more... All equivalent.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 18

04/14/09

Intermezzo:
Boundary Conditions for Advection

Linear advection ut + ux = 0 x [0, 1]

Image by MIT OpenCourseWare.

Upwind (rst order) treats boundary conditions naturally correctly.


LF, LW: Need articial/numerical boundary conditions at x = 1,
that acts as close to do nothing as possible.
WENO: Need information outside of domain.

Image by MIT OpenCourseWare.

Which values?
Extrapolate solution; works if u smooth.
E.g., constant/linear/etc. extrapolation.

Numerical Methods for Conservation Laws


Naive Schemes Ex.: Burgers with u > 0 upwind

n+1 n n Uj Uj U Ujn 1 n j = Uj t x Non-conservative; ne if u C 1 . But: Wrong if u has shocks (see pset 5). Conservative FD Methods ut + (f (x))x = 0 Discretize in conservation form conservation correct shock speeds Upwind:
f (Ujn ) f (Ujn 1 ) n+1
n
f (Ujn ) 0 Uj Uj x if
=
t
f (Ujn ) f (Ujn ) +1

f (Ujn ) < 0 x


ut + uux = 0

Lax-Friedrichs:
n n (Ujn Ujn+1 1 f (Ujn +1 + Uj 1 ) +1 ) f (Uj 1 ) 2 + =0 t 2x (no straightforward LW, since based on linear Taylor expansion)

Image by MIT OpenCourseWare.

Numerical Flux Function Ujn+1 Ujn Fj n Fj 1 n + =0 t x


Upwind: Fj n =
f (Ujn ) f (Uj +1 n ) 0
< 0
Image by MIT OpenCourseWare.

if

n )f (U n ) f (Uj +1 j n U n Uj +1 j

LF : Fj n = 1 (f (Ujn ) + f (Ujn +1 )) 2

x n (U Ujn ) 2t j +1 2

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 19

04/10/09

Finite Volume Methods (FVM)


FD: Ujn function value u(j x, nt) 1 1
(j + 2 )x n FV: Uj cell average u(x, nt)dx
x (j 1 )x 2 Fluxes through cell boundaries

n Fj 1 n Ujn+1 Ujn Fj + 1 2 2 +
=0 t x

Godunov Method REA = Reconstruct-Evolve-Average

Image by MIT OpenCourseWare.

Burgers equation

CFL Condition: t C x Local RP do not interact 1

Image by MIT OpenCourseWare.

If f (u) > 0 (convex ux function) n Ujn 1 > us , s > 0 f (Uj 1 ) n n n f (Uj ) if Uj < us , s < 0
Fj 1 = 2
n f (Us ) Ujn 1 < us < Uj s=
n f (un j ) f (uj 1 )
n un j uj 1


(1)
(2)

(3)

Shock speed
Sonic point [Burgers: us = 0 ]

f (us ) = 0

Transsonic rarefaction If no transsonics occur, we recover exactly upwind. FV


Close Relation

Image by MIT OpenCourseWare.

FD.

High Order Methods Linear case: Taylor series approach LW FD: Larger stencils
FV: Reconstruct with linear, quadratic, etc. functions in each cell.

j n = 0 Godunovs method
n un j +1 uj x Lax-Wendro

j n =

n + n (xx ) u n (x,tn )=Uj j i

Image by MIT OpenCourseWare.

Riemann Problem

High order not TVD need limiters. Nonlinear Stability Property Monotone L -contracting
1

Image by MIT OpenCourseWare.

Conservation law Initial conditions v0 (x) u0 (x) x v (x, t) u(x, t) x, t. ||u(, t2 )||L1 ||u(, t1 )||L1 t2 t1 TV(u(, t2 )) TV(u(, t1 )) t2 t1 [TV(u) = |u(x)|dx] ux (, t1 ) 0 ux (, t2 ) 0 if t2 > t1

Numerical scheme Vj n Ujn j Vj n+1 Ujn+1 j ||U n+1 V n+1 ||1 ||U n V n ||1 [||U ||1 = x |uj |]
j

TVD Monotonicity preserving TVB (bounded)

TV(U

n+1

) TV(U n ) |Uj +1 Uj |]

[TV(U ) =

Ujn Ujn +1 j n+1 +1 Uj Ujn +1 j TV(U n+1 ) (1+ t) TV (U n ) independent of t

Remark: Discontinuous solution L1 norm is appropriate

||uh (x) u(x)||L = 1 h ||uh (x) u(x)||L1 0


h0

Theorem (Godunov):

Image by MIT OpenCourseWare.

A linear, monoticity preserving method is at most rst order accurate. Need nonlinear schemes. 3

High Resolution Methods A. Flux Limiters ut + (f (u))x = 0 Ujn+1 Ujn Fjn Fjn 1 + =0 t x
Use two uxes:
TVD-ux (e.g. upwind) F High order ux F Smoothless indicator: uj uj 1 1 j = away from 1 uj +1 uj j + (F j F j ) (j ) Flux: Fj = F Ex.: ut + cux = 0 c t Fj = cUj + 2 1 c (Uj +1 Uj ) (j ) x
Fupwind FLW Fupwind

where smooth near shocks

Conditions for (): TVD: 0 () 2


0 () 2
Second order: (1) = 1
continuous

Two Popular Limiters:


Superbee

Image by MIT OpenCourseWare.

van Leer

() = max(0, min(1, 2), min(, 2))

() =

| | + 1 + ||

Images by MIT OpenCourseWare.

B. Slope Limiters

Image by MIT OpenCourseWare. Upwind: j = 0 Uj +1 Uj LW: j = x Minmod-limiter:



Uj Uj 1 Uj +1 Uj
, j = minmod x x |a| < |b| & ab > 0


a minmod(a, b)
=
b if |a| > |b| & ab > 0


0 ab < 0
Many more...

Slope limiters

relation

Flux limiters

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 20

04/23/09

Operator Splitting
IVP: ut = Au + Bu where A, B dierential operators.
Most accurate: Discretize Au + Bu, and time step with high order.
But: Sometimes not possible, or too costly.
Alternative: fractional steps
Time step t t + t : (1) Solve ut = Au (2) Solve ut = Bu Special case: A,B linear
Solution operators:
etA u0 : solution of ut = Au, u(0) = u0
tB e u0 : solution of ut = Bu, u(0) = u0
et(A+B ) u0 : solution of ut = Au + Bu, u(0) = u0
True solution: Lie splitting: Strang splitting: SWSS splitting: u(t + t) = et(A+B ) u(t)
uL (t + t) = etA etB u(t)
1 1 uS (t + t) = e 2 tA etB e 2 tA u(t) uSW (t + t) = 1 (etA etB + etB etA )u(t) 2

Local Truncation Errors: 2 Lie: uL (t + t) u(t + t) = 2t [A, B ]u(t) + O(t3 ) 1 1 Strang: us (t + t) u(t + t) = t3 ( 12 [B, [B, A]] 24 [A, [A, B ]])u(t) + O(t4 ) SWSS: usw (t + t) u(t + t) = O(t3 )
Commutator: [A, B ] = AB BA
If operators A and B commute, then all splittings are exact; Otherwise: Lie (globally) rst order accurate, Strang and SWSS (globally) second order accurate. Ex.: Convection-Diusion equation ut + cux = duxx Solution: u(x, t) = h(x ct, t), where h solves ht = dhxx Au = cux and Bu = duxx ABu = c(duxx )x = cduxxx = BAu [A, B ] = 0 splitting exact use Lie splitting

Ex.: Convection-Reaction equation ut + cux = a bu Au = cux and Bu = a bu ABu = c(a bu)x = bcux BAu = a b(cux ) = a + bcux [A, B ] = 0 use Strang splitting to be second order accurate Ex.: Dimensional splitting 2D Advection ut + aux + buy = 0 (1) ut + aux = 0 for t (2) ut + buy = 0 for t
Au = aux , Bu = buy , [A, B ] = 0
Remark: No error due to splitting, if ut = Au and ut = Bu solved exactly. If discretized in time, results will in general dier. Ex.: FE unsplit:
n+1 n n n n Uij Uij Uij Uin Uij Ui,j 1,j 1 = a b t x y n n Uij Uij Uij Uin 1,j Lie-splitting: (1) = a t x n+1 Uij Uij Uij Ui,j 1 (2) = b t y Hence: n+1 n Uij =Uij

[a, b > 0]

at n bt n n (Uij Uin (U Ui,j 1,j ) 1 ) x y ij ab(t)2 n n + (U Uin 1,j Ui,j 1 + Uij ) xy ij

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 21

04/28/09

Systems of IVP

u1 (x, t) . . Solution has multiple components: u(x, t) =


. m equations um (x, t)
Uncoupled (trivial) ut = uxx
vt = vxx
Solve independently
Triangular (easy) (1) ut + uux = 0 (2) t + ux = dxx Solve rst (1), then (2)
velocity eld density of pollutant

Fully Coupled (hard) ht + (uh)x = 0 shallow water equations ut + uux + ghx = 0 h uh + 1 2 = 0 u t u + gh x 2 hyperbolic conservation law Linear Hyperbolic Systems Linearize SW h u + u t g
Image by MIT OpenCourseWare.

u equations around base ow h, : h h =0 u u x A Rmm



=u gh

Linear system: () ut + A u =0 x u h SW: A = g u

() is called hyperbolic, if A is diagonalizable with real eigenvalues, and strictly hyperbolic, if the eigenvalues are distinct. A = R D R1 ; change of coordinates: v = R1 u vt = D vx = 0 Decoupled system
(vp )t + p (vp )x = 0 p = 1, . . . , m
vp (x, t) = vp (x p t, 0) Simple wave Solution is superposition of simple waves
Numerics: Implement simple waves into Godunovs method.
1

Wave Equation
1D utt = c2 uxx u 0 c u t = x v c 0 v Ex.: Maxwells Equations Et = cHx Ht = cEx Ett = (Et )t = (cHx )t = c(Ht )x = c(cEx )x = c2 Exx Htt = = c2 Hxx Schemes based on hyperbolic systems =u+v c 0 t cx = 0 t x = =uv 0 c
t + cx = 0 Upwind for , :
j n+1 j n j +1 n j n
= c
t x
n+1 n n n
j j j 1 j = c
t x
u= 1 ( + ) and v = 1 ( ) 2 2 Ujn+1 Ujn 1 j n+1 j n j n+1 j n c j +1 n j n j n j 1 n = + = + t 2 t t 2 x x n n n n c Uj +1 Uj Vj +1 n Vj n Uj Uj 1 Vj n Vj 1 n
= + + 2 x x x x
n n n n n Vj +1 Vj 1 cx Uj +1 2Uj + Uj 1 =c + 2x 2 x2 n Ujn Vj n+1 Vj n cx Vj +1 n 2Vj n + Vj 1 n +1 Uj 1 = = c + t x 2 x2
Lax-Friedrichs-like Scheme for u, v :
n
n+1 n n cx Uxx
U U 0 c U U 1 1 = + t V j c 0 2x V j +1 V j 1 Vyy V j 2
articial diusion

Stable (check by von-Neumann stability analysis).


More accurate schemes: Use WENO and SSP-RK for , .

Leapfrog Method utt = c2 uxx


n n Ujn+1
2Ujn + Ujn1 Ujn +1 2Uj + Uj 1
2 = c t2 x2
(Two-step method)
Accuracy: utt + 1 u t2 c2 uxx 2 tttt (using utt c2 uxx = 0) Stability:
ikx G2 2G + 1 2 + eikx 2 e = c G t2 x2 1 2 c uxxxx x2 12

= O(t2 ) + O(x2
) second order

G2 2G + 1 = 2r2 (cos(k x) 1) G G 2 (1 r2 (1 cos(k x))) G + 1 = 0 =a


G = a a2 1

ct r= x Courant number

If |a| > 1 one solution unstable


with |G| > 1 2 2 If |a| 1 G = a i 1 a |G| = a2 + (1 a2 ) = 1 stable Have 1 cos(k x) [0, 2], thus: |a| 1 |r| 1 Leapfrog conditionally stable for |r| 1. Staggered Grids u 0 c u t = x v c 0 v

Image by MIT OpenCourseWare.

Collocation Grid Central dierencing requires articial diusion 3

Staggered Grid Central dierencing comes naturally

n+1 Uj Ujn Vj n Vj 1 n = c t x n+1 n+1 n+1 n U Vj j +1 Uj Vj = c t x Both are explicit central dierences. Two step update:
Image by MIT OpenCourseWare.

n+1 n1 Ujn+1 2Ujn + Ujn+1 1 Uj Ujn Ujn Uj = t2 t t t n n c Vj Vj 1 n Vj n1 Vj 1 n1 c Vj Vj n1 Vj 1 n Vj 1 n1 = = t x x x t t n n n n n n n Uj Uj 1 Uj +1 2Uj + Uj 1 c2 Uj +1 Uj = = c2 x x x x2 Equivalent to Leapfrog.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 22

04/30/09

Level Set Method


2D : Moving Curve 3D : Moving Surface Orientable, with inside and outside region

Ex.: Interface between water and oil (surface tension) Propagating front of bush re Deformable elastic solid Movement of surface under velocity eld v .
Tangential motion does not change surface.
Only velocity component normal to surface is important.

Image by MIT OpenCourseWare.

Eective velocity eld: Ex.:

v = Fn

Image by MIT OpenCourseWare.

Explicit Tracking I. Lagrangian Markers: Place markers on surface: x1 , . . . , xn Rd xk = v ( xk , t) Move markers by ODE: xk (0) = xk Fast, easy to move Accurate (high order ODE solvers)

Uneven marker distribution

Image by MIT OpenCourseWare.

Incorrect entropy solution

Image by MIT OpenCourseWare.

Topology changes

Image by MIT OpenCourseWare.

Numerical instabilities with curvature


Image by MIT OpenCourseWare.

Marker connections in 3D?

II. Volume of Fluid: Regular grid Store volume/area inside surface Update volume value according to v Very robust Simple in 3D Not very accurate Exact surface shape and topology? Curvature reconstruction?
Image by MIT OpenCourseWare.

Implicit Representation
Dene function ( x), s.t. > 0 outside = 0 interface

< 0 inside Store on regular Eulerian grid PDE IVP for , yielding correct movement Recover n , K from n = | |
xx y 2 2x y xy + yy x 2 = =
3 || (x 2 + y 2 ) 2

Image by MIT OpenCourseWare.

Approximate x , y , xx , xy , yy by nite dierences (e.g. central). Signed Distance =0 || = 1


<0 Function: surface almost everywhere inside

Surface reconstruction very robust n = K = 2


Image by MIT OpenCourseWare.

PDE Movement under given velocity eld v: t + v = 0 Linear advection Special case: normal velocity v = Fn =F t + F || = 0 Level set equation 3
||

(x, y ) = x2 + y 2 1 describes unit circle

Numerical Methods Upwind


WENO
(Spectral) Ex.: Upwind for level set equation (rst order)
+1 n n i,j i,j = max(F, 0)+ ij + min(F, 0)ij t 1 x + , 0)2 +min(D+x , 0)2 +max(Dy , 0)2 +min(D+y , 0)2 ) 2 ij = (max(D

Dx , 0)2 +max(D+x , 0)2 +min(Dy , 0)2 +max(D+y , 0)2 ) 2 ij = (min(


all evaluated at n i,j

Higher order: WENO and SSP-RK. Reinitialization Desirable || = 1. But in general t + F || = 0 does not preserve || = 1. Fixes: Solve IVP + sign()(|| 1) = 0
In each time step, for 0 ?
Solve Eikonal equation

s.t. Given , nd , | = 1 | = 0} = { = 0}
{ Use fast marching method by Sethian.
Extension velocity:
, s.t.
Change velocity eld v to v = v v at { = 0}
v = 0 || = 1 preserved

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 23

05/05/08

Navier-Stokes Equations
ut + (u )u = p + u=0
1 2 u Re

[+g ] Momentum equation Incompressibility

Incompressible ow, i.e. density = constant.


Reynolds number:
Re = U L inertial forces = viscous forces

U = Characteristic velocity L = Characteristic length scale = Kinetic viscosity u in 2D: u = v 1 (1) ut + uux + vuy = px + Re (uxx + uyy ) (2) vt + uvx + vvy = py + (3) ux + vy = 0 Famous Problems: Lid driven cavity
1 (v Re xx

Image by MIT OpenCourseWare.

+ vyy )

Flow around cylinder

Image by MIT OpenCourseWare.

3 unknowns, 3 equations DAE (Dierential Algebraic System), (3) is a constraint

Solve by projection approach: In each time step


1
2 u I. Solve ut + (u )u = Re U Un 1 2 n
U = (U n )U n + t Re Note: U
=0 II. Project on divergence-free velocity eld U n+1 U = p
t What is p : 0 = U n+1 = U t2 P
1
2 p = U Poisson equation for pressure t Discretization: Solution:
u = v = 0,
p = constant

Image by MIT OpenCourseWare.


!

But: Central dierences on grid allow solution Uij = Vij = 0, P1 i + j even for Pij = P2 i + j odd Fix: Staggered grid

Image by MIT OpenCourseWare.

pressure p velocity u velocity v

Image by MIT OpenCourseWare.

Boundary Conditions:

U13 = uw U21 + U22 = us U21 + U22 = 2us 2

Image by MIT OpenCourseWare.

Numerical Method: I. a) Treat Nonlinear Terms uux + vuy = (u2 )x + (uv )y


uvx + vvy = (uv )x + (v 2 )y (U 2 ) x =

ij

(use ux + vy = 0)

(Ui+ 1 ,j )2 (Ui 1 ,j )2
2 2

x Ui,j + 1 Vi,j + 1 Ui,j 1 Vi,j 1


2 2 2 2

Uij

(U V ) y

=
ij

y Ui,j + 1
2

Ui+ 1 ,j Vi+ 1 ,j Ui 1 ,j Vi 1 ,j (U V )
2 2 2 2 =
x x ij (V 2 ) y =

ij

(Vi,j + 1 )2 (Vi,j 1 )2
2 2

(U V )
y ij
Image by MIT OpenCourseWare.

where Ui+ 1 ,j =

Ui,j + Ui+1,j Ui,j + Ui,j +1 ,


Ui,j + 1 =
2 2 2
n n n 2 Ui,j Ui,j (U ) (U V ) = t x i,j y i,j n n Vi,j Vi,j n (U V ) (V 2 ) = t x y i,j i,j

I. b) Implicit Diusion U U 1 = K 2D U t Re V V 1 = K 2D
V t Re
5 point Laplace stencil with Dirichlet boundary conditions II. Pressure Correction 1 U V K 2D P = + t x y with Neumann boundary conditions p = 0
n

U x

Image by MIT OpenCourseWare.

U P = t x n+1 V V P = t y U

n+1

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009

lecture 24

05/07/09

Pseudospectral Methods
Vorticity: w = u ut + ( u ) u = p + 1 2 u Re 1 ut + (( u ) u) = (p) + ( 2 u) Re =0 w t + u w = 1 2 w Re

and 2 commute

Navier-Stokes equations in vorticity formulation


How to nd u from w ?
2D
w = vx uy scalar Stream Function: ( x) s.t. u = , i.e.
2 = w u=

u = y
v = x

2 = xx + yy = vx + uy = w
Thus: w u

Remark: Incompressibility guaranteed u = ux + vy = yx xy = 0 Time Discretization Semi-implicit: u w explicit 2 w Crank-Nicolson


wn+1 wn
1 1 2 n w + 2 wn+1 + ( un wn ) = Re 2 t =N n 1 1 1 1 2 2 n+1 n I w = N + I+ wn t 2Re t 2Re If discretized in space linear system Here: want to use spectral methods

Fourier Transform Properties:



+ F (f ) = f (k ) =
f (x)e2ikx dx + 1 (k )e2ikx dk F (f ) = f (x) = f F (f ) = 2ikF (f )

F (2 f ) = 4 2 | k |2 F (f ) F (f g ) = F (f ) F (g ) F (f g ) = F (f ) F (g )

2D FT (| k |2 = kx 2 + ky 2 )

Use Here:

1
4 2 2 1 4 2 2 n+1 n n
+
|k |
w = N + |k
|
w
t 2Re
t 2Re


2 1 2 2 n n +
N | k |
w
t Re
w n+1 = 1 2 2 2 |k | + t Re :
Computation of N = N = u w N u w Inecient in Fourier space.
So perform multiplication in physical space.
Numerical Method: n+1 : Time step w n w
n n = 1 w 1. |k | n n u = 2iky n n v = 2ikx 2. n w = 2ikx w n xn w y = 2iky w n n u n v 3. iFFT wx n wy n

5. FFT

n ) (N

6. Truncate kx , ky > 2 k 3 max to prevent aliasing ) (N kx , ky 2 k 3 max n N = if 0 else 7. w n+1 = n+1 + N 1 2 2 2 |k | w n t Re 1 2 2 2 |k | + t Re

4. N n = un wx n + v n wy n

Particle Methods
Linear advection ut + cux = 0
u(x, 0) = u0 (x)
Solution:
u(x, t) = u0 (x ct)
Need to work hard to get good schemes for advection, on a xed grid.
Reason: Represent sideways motion by up and down motion. Alternative: Move computed nodes, rather than having a xed grid. Ex.: 1D Advection ut + cux = 0
u(x, 0) = u0 (x)
Particle method: 1. Sample initial conditions xj = j x, uj = u0 (xj ) 2. Move particles along characteristics: x j = c xj (t) = xj (0) + ct Exact solution on particles. u j = 0 uj (t) = u0 (xj (0))

Image by MIT OpenCourseWare.

Image by MIT OpenCourseWare.

Ex.: 2D Advection t + v ( x) = 0
( x, 0) = 0 ( x)
Particle method: 1. xj , j = 0 ( xj ) j = x v ( xj ) 2. j = 0 Solve characteristic ODE, e.g. by RK4; very accurate on particles.

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

18.336 spring 2009 Ex.: Continuity Equation (t) + (v (x))x = 0 t + v (x)x = v (x)
Characteristic ODE
x j = v (xj ) j = v (xj )j Ex.: Nonlinear conservation law
2 ut + ( 1 u
)x = 0 Burgers equation
2 x j = uj if solution smooth u j = 0

lecture 25 Trac on road

05/12/09

v = v (x)
Image by MIT OpenCourseWare.

Problem: Characteristic curves can intersect Particles collide

Image by MIT OpenCourseWare.

Particle management required:


Merge colliding particles (how?)
Insert new particles into gaps (where/how?) An Exactly Conservative Particle Method for 1D Scalar Conservation Laws [Farjoun, Seibold JCP 2009]
2 ut + ( 1 u
)x = 0
2

Observe: If we have a piecewise linear function initially, then the exact solution is a piecewise linear function forever (including shocks).

Two choices: (A) Move shock particles using Rankine-Hugoniot condition.

Image by MIT OpenCourseWare.

(B) Merge shock particles, then proceed in time.

Image by MIT OpenCourseWare.

Same for insertion:

Image by MIT OpenCourseWare.

Ex.: Shallow water equations


Dh
= ux h ht + (uh)x = 0 Dt ut + uux + ghx = 0
Du
= ghx Dt Df Lagrangian derivative = ft + u fx Dt Particle Method: j = uj
x
j = hj (x u)(xj )
h

u j = g (x h)(xj )
Required: Approximation to x h, x u at xj Particles non-equidistant. 2

Meshfree approximation (moving least squares):

Local t: u (x) = ax2 + bx + c Weighted LSQ-t: mina,b,c w(x) =


1 r

Image by MIT OpenCourseWare.

j :|xj x0 |r

|u (xj ) u(xj )|2 w(xj x0 )

or = e

or . . .

Dene (x u)(xj ) = u (x0 ) Smoothed Particle Hydrodynamics (SPH) Quantity f f (x) = f ( x) (x x )dx
Rd

Sequence of kernels W h h lim W (x) = (x), W h (x)dx = 1 h.


h0 R

Also:
W h (x) = wh (||x||),
w(d) = 0 d > h smoothing length
Approximation I: h f (x) = f ( x)W h (x x )dx
Rd

Image by MIT OpenCourseWare.

lim f (x) = f (x).


h0

Density Density measure (A) = dx A f ( x) h h f (x) = W (x x ) ( x)dx x) Rd (


=d ( x)

Sequence of point clouds {X (n) }hN X (n) = (x1 (n) , . . . , xn (n) ) Point measure n (m) X = mi (n) x(n)
i=1
i

Image by MIT OpenCourseWare.

Approximation II: f h (x) =


n

f ( x) h W (x x )dX (n) ( x) ( x)

f (xi (n) ) h W (x xi (n) ) =: f h,n (x) (n) ) ( x i i=1 n f (xi (n) ) h,n W h (x xi (n) ) f (x) = mi (n) (n) ) ( x i i=1 hard-code n m i fk h = fi Wki h i i=1 n mi fk h = fi Wki h i i=1 mi (n) Apply to Euler equations of compressible = ( u) density t D p u velocity = Dt De p energy = u Dt gas dynamics: D = u ( u) Dt p p D u = 2 Dt De p p u = u Dt

k u k ek k k u ek

= = = = = =

p = p(s, e)
uk mi Wki mi u i h Wki i i pk m i pi Wki mi Wki i i (k )2 i i mi pi mi pi vi uk Wki Wki i i i i i i mi ( uk ui )Wki i k pi mi + W ki (k )2 (i )2 i pi ( u u ) W mi k i ki 2 ( ) i i

d Since dt

i = 0 k =

mi Wki

SPH Approximation to Euler Equations: 0 if adaptive) m k = 0 (or = k = x uk k = u e k = k =


i

mi

pk pi + 2 (k ) (i )2

Wki

mi

pi ( uk ui )Wki (i )2

mi Wki

pk = p(k , ek )

MIT OpenCourseWare http://ocw.mit.edu

18.336 Numerical Methods for Partial Differential Equations


Spring 2009

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

You might also like