You are on page 1of 20

Finite dierence method

Principle: derivatives in the partial dierential equation are approximated by linear combinations of function values at the grid points 1D: = (0, X), grid points ui u(xi ), xi = ix i = 0, 1, . . . , N mesh size x =
X N


u () x x =


lim

First-order derivatives u( + x) u() x x u() u( x) x x = lim x0 x0 x x u( + x) u( x) x x (by denition) = lim x0 2x

Approximation of rst-order derivatives


Geometric interpretation

u x i u x i u x i

ui+1 ui x ui ui1 x ui+1 ui1 2x

forward dierence backward dierence central dierence

Taylor series expansion u(x) =

n=0

(xxi )n n!

nu xn i

u C ([0, X]) 3u x3 3u x3 + ...


i

T1 : T2 :

ui+1 = ui + x ui1 = ui x

u x u x

(x)2 + 2 i (x)2 + 2 i

2u x2 2u x2

(x)3 + 6 (x)3 6

+ ...
i

Analysis of truncation errors


Accuracy of nite dierence approximations T1 u x ui+1 ui x = x 2
forward dierence

2u x2

(x)2 6

3u x3

+ ...
i

truncation error O(x)

T2

u x

ui ui1 x + = x 2
backward dierence

2u x2

(x)2 6

3u x3

+ ...
i

truncation error O(x)

T1 T2

u x

ui+1 ui1 (x)2 = 2x 6


central dierence

3u x3

+ ...
i

truncation error O(x)2

Leading truncation error = m (x)m + m+1 (x)m+1 + . . . m (x)m

Approximation of second-order derivatives


Central dierence scheme T1 + T2 Alternative derivation 2u x2 =
i

2u x2

=
i

ui+1 2ui + ui1 + O(x)2 (x)2


u x i+1/2 u x i1/2

u x

= lim
i

x0

Variable coecients f x
i

ui+1 ui x

ui ui1 ui+1 2ui + ui1 x = x (x)2 diusive ux

f (x) = d(x) u x

fi+1/2 fi1/2 di+1/2 ui+1 ui di1/2 ui ui1 x x = x x di+1/2 ui+1 (di+1/2 + di1/2 )ui + di1/2 ui1 (x)2

Approximation of mixed derivatives


2D:

2u xy

u y

u x
u y

2u xy u y u y

u y

i+1,j

i,j

2x

i1,j

+ O(x)2

i+1,j

ui+1,j+1 ui+1,j1 + O(y)2 2y ui1,j+1 ui1,j1 + O(y)2 2y

i1,j

Second-order dierence approximation 2u xy =


i,j

ui+1,j+1 ui+1,j1 ui1,j+1 + ui1,j1 + O[(x)2 , (y)2 ] 4xy

One-sided nite dierences


u x =
0

u1 u0 + O(x) forward dierence x

backward/central dierence approximations would need u1 which is not available Polynomial tting u(x) = u0 + x u x x2 + 2 0 2u x2 x3 + 6 0 3u x3 u x + ...
0

u(x) a + bx + cx2 ,

u b + 2cx, x

b
0

approximate u by a polynomial and dierentiate it to obtain the derivatives u0 = a u1 = a + bx + cx2 u2 = a + 2bx + 4cx2 b= cx2 = u1 u0 bx 3u0 + 4u1 u2 2x

Analysis of the truncation error


One-sided approximation u x u x u x
i

ui + ui+1 + ui+2 x 2u x2 (x)3 + 6 i 3u x3 + ...


i

ui+1 = ui + x ui+2 = ui + 2x
ui +ui+1 +ui+2 x

(x)2 + 2 i (2x)2 + 2 i + ( + 2)

2u x2
u x i

(2x)3 + 6 i
x 2 (

3u x3
2u x2

+ ...
i

++ x ui

+ 4)

+ O(x2 )

Second-order accurate if
3 = 2,

+ + = 0,
u x i

+ 2 = 1, =

+ 4 = 0 + O(x2 )

= 2,

1 = 2

3ui +4ui+1 ui+2 2x

Application to second-order derivatives


One-sided approximation u x u x 2u x2 (x)2 + 2 i (2x)2 + 2 i +
+2 x

ui + ui+1 + ui+2 x2 (x)3 + 6 i 3u x3 + ...


i

ui+1 = ui + x ui+2 = ui + 2x
ui +ui+1 +ui+2 x2

2u x2

2u x2
u x i

(2x)3 + 6 i
+4 2 2u x2

3u x3

+ ...
i

++ x2 ui

+ O(x)

First-order accurate if = 1, = 2,

+ + = 0,
u x i

+ 2 = 0,
ui 2ui+1 +ui+2 x2

+ 4 = 2 + O(x)

=1

High-order approximations
u x u x u x 2u x2 =
i

2ui+1 + 3ui 6ui1 + ui2 + O(x)3 6x ui+2 + 6ui+1 3ui 2ui1 + O(x)3 6x ui+2 + 8ui+1 8ui1 + ui2 + O(x)4 12x

backward dierence forward dierence central dierence central dierence

=
i

=
i

=
i

ui+2 + 16ui+1 30ui + 16ui1 ui2 + O(x)4 2 12(x)

Pros and cons of high-order dierence schemes more grid points, ll-in, considerable overhead cost high resolution, reasonable accuracy on coarse grids Criterion: total computational cost to achieve a prescribed accuracy

Example: 1D Poisson equation


Boundary value problem 2u 2 =f x One-dimensional mesh ui u(xi ),

in = (0, 1),

u(0) = u(1) = 0

fi = f (xi )

xi = ix,

x =

1 , N

i = 0, 1, . . . , N

Central dierence approximation O(x)2 ui1 2ui +ui+1 = fi , i = 1, . . . , N 1 (x)2 u0 = uN = 0

Dirichlet boundary conditions

Result: the original PDE is replaced by a linear system for nodal values

Example: 1D Poisson equation


Linear system for the central dierence scheme i=1 u0 2u1 +u2 (x)2 i=2 u1 2u2 +u3 (x)2 i=3 u2 2u3 +u4 (x)2 ... uN 2 2uN 1 +uN
i=N 1
(x)2

= f1 = f2 = f3 = fN 1

Matrix form

Au = F

A RN 1N 1

u, F RN 1 u1 u2 u3 f1 f2 f3 fN 1

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

u=

uN 1

F =

The matrix A is tridiagonal and symmetric positive denite invertible.

Other types of boundary conditions


Dirichlet-Neumann BC u0 = 0, u(0) =
u x (1)

=0 uN +1 = uN 1 central dierence

uN +1 uN 1 =0 2x

Extra equation for the last node uN 1 2uN + uN +1 = fN (x)2 Au = F uN 1 + uN 1 = fN (x)2 2 u, F RN u1 u2 u3


N 1

Extended linear system

A RN N

The matrix A remains tridiagonal and symmetric positive denite.

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

, 2 1 1 1

u= u

uN

F = f

f1 f2 f3

N 1 1 2 fN

Other types of boundary conditions


Non-homogeneous Dirichlet BC u0 = g0 u(0) = g0 only F changes rst equation only F changes

2u1 u2 g0 = f1 + (x)2 (x)2


u x (1)

Non-homogeneous Neumann BC uN +1 uN 1 = g1 2x uN 1 2uN + uN +1 = fN (x)2

= g1

uN +1 = uN 1 + 2xg1 uN 1 + uN 1 g1 = fN + (x)2 2 x A and F change

Non-homogeneous Robin BC uN +1 uN 1 + uN = g2 2x uN 1 2uN + uN +1 = fN (x)2

u x (1)

+ u(1) = g2

uN +1 = uN 1 2xuN + 2xg2 uN 1 + (1 + x)uN 1 g2 = fN + (x)2 2 x

Example: 2D Poisson equation


Boundary value problem 2 u 2 u = f in = (0, 1) (0, 1) x2 y 2 Uniform mesh: x = y = h, ui,j u(xi , yj ), u=0 on = N=
1 h

fi,j = f (xi , yj ),

(xi , yj ) = (ih, jh),

i, j = 0, 1, . . . , N

Central dierence approximation O(h2 ) ui1,j +ui,j1 4ui,j +ui+1,j +ui,j+1 = fi,j , h2 ui,0 = ui,N = u0,j = uN,j = 0

i, j = 1, . . . , N 1

i, j = 0, 1, . . . , N

Example: 2D Poisson equation


Linear system row-by-row node numbering Au = F A R(N 1)
2

(N 1)2

u, F R(N 1)

u = [u1,1 . . . uN 1,1 u1,2 . . . uN 1,2 u1,3 . . . uN 1,N 1 ]T F = [f1,1 . . . fN 1,1 f1,2 . . . fN 1,2 f1,3 . . . fN 1,N 1 ]T 4 1 1 4 1 ... ... B= 1

B I I B I ... ... A= I I= 1 1 1 1

, B I I B

4 1 1 4

The matrix A is sparse, block-tridiagonal (for the above numbering) and SPD. cond2 (A) = |max | = O(h2 ) |min |

Caution: convergence of iterative solvers deteriorates as the mesh is rened

Treatment of complex geometries


2D Poisson equation 2u 2u = f x2 y 2 Dierence equation u1 + u2 4u0 + u3 + u4 = f0 h2 Linear interpolation u(R) = u4 (h ) + u0 = g0 (R) h u1 + u2 4 +
h
3 4 Q P R h 1 0 Q 2

in on

u = g0

stencil of Q
curvilinear boundary

u4 = u0

h + g0 (R) h h

Substitution yields

h u0 + u3 = h2 f0 + g0 (R) h

Neumann and Robin BC are even more dicult to implement

Grid transformations
Purpose: to provide a simple treatment of curvilinear boundaries

The original PDE must be rewritten in terms of (, ) instead of (x, y) and discretized in the computational domain rather than the physical one. Derivative transformations u u , ,... x y
dicult to compute

u u , ,...
easy to compute

PDE transformations for a direct mapping


Direct mapping Chain rule = (x, y), = (x, y) u u u = + y y y x y
2

u u u = + , x x x

2u u 2 u 2 2 u 2u = + +2 + 2 x2 x2 x2 x x 2u u 2 u 2 2 u 2 u = + +2 + 2 y 2 y 2 y 2 y y Example: 2D Poisson equation 2u 2 x


2

2u + 2 2u + 2

x y

u = f x
2

turns into y
2

2u 2

2 u + 2 x x y y

u 2 2 2 u 2 + 2 + 2 =f x2 y x2 y

transformed equations contain many more terms

The metrics need to be determined (approximated by nite dierences)

PDE transformations for an inverse mapping


Inverse mapping x = x(, ) y = y(, ) x x y y , , ,
known

Metrics transformations Chain rule


u u

, , , x y x y
unknown

= =

u x x u x x

+ +

u y y u y y

u u

x x J

y y

u x u y

where J =

(x,y) (,)

is the Jacobian which can be inverted using Cramers rule

Derivative transformations u 1 = x det J u y u y , u 1 = y det J u x u x

Direct versus inverse mapping


Total dierentials for both coordinate systems = (x, y) = (x, y) x = x(, ) y = y(, ) d = d = dx = dy =
x x y y x dx x dx x d y d

+ + + +

y dy y dy x d y d x y

d d dx dy

x x x y

y y x y

dx dy d d

Relationship between the direct and inverse metrics 1 y = , x det J 1 y = , x det J

x y

1 det J

y y

x x

1 x = , y det J

1 x = y det J

You might also like