1 lecture 2 elliptic pdes and the finite difference method

30
1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

Upload: octavia-robinson

Post on 04-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

1

LECTURE 2

Elliptic PDEs and the Finite Difference Method

Page 2: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

2

Aim of Lecture• During this lecture we will discuss:

– Elliptic Partial Differential Equations– Finite Difference Method

• Taylor’s Series Expansions

• High Order Terms & Truncation

• Finite Difference Discretisation

– Solution Methods• Linear/Matrix System Solvers

• Iterative Solvers: Jacobi, Gauss-Seidel

• Use of Excel

Page 3: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

3

Elliptic PDEs• Elliptic PDEs represent phenomena that have already

reached a steady state and are, hence, time independent.• Two classic Elliptic Equations are:

– Laplace Equation

or

– Poisson’s Equation

or

– u(x,y) is dependent variable and g is a constant

02

2

2

2

y

u

x

u

02

2

2

2

gy

u

x

u 02 gu

02 u

Page 4: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

4

Elliptic PDE – Example

• Temperature, u(x,y) profile around two computer chips on a printed circuit board.

• Where g is the heat source.

02 gu Heat Source g

Page 5: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

5

FINITE DIFFERENCE METHOD

Page 6: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

6

Taylor’s Series Expansions

• Recall the Taylor’s Series expansion of a function about a point, x

• We will use this to find approximate solutions to PDEs

)(!3

1

!2

1)()( 4

3

33

2

22 hO

dx

fdh

dx

fdh

dx

dfhxfhxf

x x+hx-h

Page 7: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

7

High Order Terms• Note the in the previous expansion

• This refers to all powers of h greater than or equal to 4, e.g.

• When h is small, these high order terms are tiny, e.g.

• We can simplify expressions by making h small and ignoring high order terms

• This is known as truncation

)( 4hO

...,,,, 7654 hhhh

...,00000001.001.0 4 hh

Page 8: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

8

Taylor Series expansions in 2D

• Consider the function u expanded about the point (x,y)

)(!2

1),(),(

)(!2

1),(),(

32

22

32

22

yOy

uy

y

uyyxuyyxu

xOx

ux

x

uxyxuyxxu

x x+xx-xy-y

y

y+y

(x,y)

Page 9: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

9

Taylor Series expansions in 2D• Now consider a regular grid of

points and use the notation

• This gives1,

,1

,

),(

),(

),(

ji

ji

ji

uyyxu

uyxxu

uyxu

i i+1i -1j -1

j

j+1

)(2

1

)(2

1

3

,

2

22

,

,1,

3

,

2

22

,,,1

yOy

uy

y

uyuu

xOx

ux

x

uxuu

jiji

jiji

jijijiji

Page 10: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

10

Finite Differences• We can rearrange the Taylor’s series

gives

gives

)(,,1

,

xOx

uu

x

u jiji

ji

(known as

forward difference)

)(,1,

,

xOx

uu

x

u jiji

ji

)(2

1 3

,

2

22

,,,1 xO

x

ux

x

uxuu

jijijiji

)(2

1 3

,

2

22

,,,1 xO

x

ux

x

uxuu

jijijiji

(known as

backward difference)

Page 11: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

11

Finite Differences• We can also add and subtract Taylor’s series

(1) – (2) gives

(1) + (2) gives )(2 2

2

,1,,1

,

2

2

xOx

uuu

x

u jijiji

ji

)(2

2,1,1

,

xOx

uu

x

u jiji

ji

(known as central

difference)

(also known as central difference

[2nd order])

)2()(2

1

)1()(2

1

3

,

2

22

,,,1

3

,

2

22

,,,1

xOx

ux

x

uxuu

xOx

ux

x

uxuu

jijijiji

jijijiji

Page 12: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

12

Finite Differences: Summary• We can rearrange the Taylor’s series to get

• Then truncate the higher order terms and substitute for differentials in the PDE

)(2 2

2

,1,,1

,

2

2

xOx

uuu

x

u jijiji

ji

)(,1,

,

xOx

uu

x

u jiji

ji

)(2

2,1,1

,

xOx

uu

x

u jiji

ji

)(,,1

,

xOx

uu

x

u jiji

ji

- Forward difference

- Backward difference

- Central difference

- Central difference (2nd order)

Page 13: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

13

Exercise• Write down the central difference approximations for:

ji

ji

y

u

y

u

,

2

2

,

Page 14: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

14

Truncation Error• Approximating derivatives, in this case using finite

differences, is known as discretisation.• These approximations will result in errors known as

truncation error.

4

42

2

,1,,1

,

2

2

12

2

x

ux

x

uuu

x

u jijiji

ji

2,1,,1

,

2

2 2

x

uuu

x

u jijiji

ji

Truncation Error

Page 15: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

15

Finite Difference Method – Example• Consider Poisson’s equation.

02

2

2

2

gy

u

x

u

022

2

1,,1,

2

,1,,1

g

y

uuu

x

uuu jijijijijiji

gyxuuxuuyuyx jijijijiji22

1,1,2

,1,12

,222

• Difference formula for each node:

i i+1i -1j -1

j

j+1

• Discretise

Page 16: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

16

Finite Difference Method – Example

• Consider the case:• Then

• The difference equation can be written as:

or

hyx

4)(

4

1 2

1,1,,1,1,

ghuuuuu jijijijiji

ghuuuuhuh jijijijiji4

1,1,,1,12

,222

ghuuuuu jijijijiji2

1,1,,1,1, )(4

Page 17: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

17

Example

• Consider the PDE shown, on a square domain with zero boundary conditions (u = 0)

u = 0

y

x

(1,0)(0,0)

(0,1) (1,1)

092

2

2

2

y

u

x

u

u = 0

u = 0

u = 0

u = 0

Page 18: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

18

Approximate Solution• Represent using a Finite

Difference grid with

• Need to find approximations to u for all nodal values

• However we know that u = 0 on all boundaries

• So need only to find approximations for u at four internal nodes

• Required values are

i = 1 2 3 4

j = 1

2

3

4

3,33,22,32,2 ,,, uuuu

3/1 hyx

Page 19: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

19

Example• In general we have:• Or, in terms of the 4 unknowns:

• So that

and then (e.g. using Matlab)

i = 1 2 3 4

j = 1

2

3

4

193

14

2

1,,1,11,,

jijijijiji uuuuu

1

1

1

1

4110

1401

1041

0114

3,3

3,2

2,3

2,2

u

u

u

u

5.03,33,22,32,2 uuuu

)3,3(

)2,3(

)3,2(

)2,2(

14

14

14

14

3,22,33,3

3,32,22,3

3,32,23,2

3,22,32,2

ji

ji

ji

ji

uuu

uuu

uuu

uuu

Page 20: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

20

Solvers• Notice that the Finite Difference method will

generally result in a matrix system of the form

Au = b

where

u = [u1 u2 ……….. un ]T

b = [b1 b2 ……….. bn ]T

and

nnnnn

n

n

n

aaaa

aaaa

aaaa

aaaa

A

.

.....

.

.

.

321

3333231

2232221

1131211

Page 21: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

21

Solvers

16,1615,1612,16

16,1515,1514,1511,15

15,1414,1413,1410,14

14,1313,139,13

16,12121211,128,12

15,1112,11111110,117,11

14,1011,1010109,106,10

13,910,99995

12,8888784

11,778777673

10,667666562

59565551

484443

37343332

26232221

151211

0000000000000

000000000000

000000000000

0000000000000

000000000000

00000000000

00000000000

000000000000

000000000000

00000000000

00000000000

000000000000

0000000000000

000000000000

000000000000

0000000000000

aaa

aaaa

aaaa

aaa

aaaa

aaaaa

aaaaa

aaaa

aaaa

aaaaa

aaaaa

aaaa

aaa

aaaa

aaaa

aaa

A

• Generally in 2D we will get matrices of the form

Note the banded structure of the matrix.

Page 22: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

22

Banded matrices• Banded matrices arise in finite difference methods because

(in 2D) the value at each node is directly dependent only on its four nearest neighbours.

• Banded matrices are sparse (i.e. mostly full of zeroes) with a regular structure and hence can be stored in minimal space.

• For example, if the finite difference grid is 100 by 100, the number of unknowns is 10,000 and the number of entries in the matrix is 100,000,000 which might require 1,600Mb (megabytes) to store in a computer.

• However, by just storing five non-zero diagonals we can reduce the storage requirement to around 50,000 values or around 800Kb (kilobytes) = 0.8Mb.

• This means the system can be solved much more rapidly.

Page 23: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

23

Direct and Iterative Solvers• Exact solution requires inversion of A

– Very slow. Huge memory requirements.• Direct Solvers: (Gaussian Elimination, etc)

– Need to store whole matrix. (Disadvantage)– Slow, especially for large matrices. (Disadvantage)– Robust even with ill-conditioned matrices. (Advantage)

• Iterative Solvers: (Jacobi, Gauss Seidel, etc)– Good for large matrix systems. No need to store whole

matrix (Advantage)– Fast, even for large matrices. (Advantage)– Poor for ill-conditioned matrices. May converge only

slowly. (Disadvantage)

Page 24: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

24

Iterative Solvers• Two classical Examples are Jacobi and Gauss-Seidel• Consider following system of equations

• Start with initial vector x1 = [0, 0, 0] T. The final solution is x = [1, 1,1] T. It takes 8 iterations for Jacobi and 6 iterations for Gauss Seidel.

1292

427

88

321

321

321

xxx

xxx

xxx

Jacobi Gauss Seidel 9/212

7/24

8/8

211

3

311

2

321

1

kkk

kkk

kkk

xxx

xxx

xxx

9/212

7/24

8/8

12

11

13

31

11

2

321

1

kkk

kkk

kkk

xxx

xxx

xxx

Page 25: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

25

Iterative Solvers – Matrix Version• Need to solve Ax = b• Let A = D+L+U (Diagonal + Lower triangle + Upper triangle)

• The Jacobi method can be written as: Dx(k+1) = -(L+U)x(k) + b • The Gauss Seidel method can be written: (D+L)x(k+1) = -Ux(k) + b

(generally converges faster as it uses most recent information)

0000

000

00

0

0

00

000

0000

000

000

000

000

34

2423

141312

444241

3231

21

44

33

22

11

44444241

34333231

24232221

14131211

a

aa

aaa

U

aaa

aa

aL

a

a

a

a

D

aaaa

aaaa

aaaa

aaaa

A

Page 26: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

26

Iterative Solvers – Convergence• To ensure convergence of an iterative solver such as Jacobi or

Gauss Seidel, we require Diagonal Dominance in the matrix, i.e. for each row i

• In other words, the diagonal element in each row (or column) is greater in magnitude than the sum of the off diagonal elements

• We can sometimes rearrange the order of the equations to ensure diagonal dominance

ji

jiii aa |||| ,,

Page 27: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

27

Exercise• Write down the Jacobi method for the following

system

• Would you expect it to converge?• If not, how would you rewrite it so that it would

converge?

32

54

21

21

xx

xx

Page 28: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

28

Example – Gauss Seidel• Example: use Excel to solve the following

• Rewrite as Gauss-Seidel iterations

54

32

21

21

xx

xx

4/)5(

2/)3()1(

1)1(

2

)(2

)1(1

kk

kk

xx

xx

Page 29: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

29

Gauss Seidel in Excel

FLAG

(to reset, see Tutorial 1)

Formula for X1

(uses old value of X2)

Page 30: 1 LECTURE 2 Elliptic PDEs and the Finite Difference Method

30

Gauss Seidel in Excel

Formula for X2

(uses current value of X1)