of 20

hsss500
• Category

Documents

• view

233

0

Transcript of Finite diﬀerence method

• 8/7/2019 Finite difference method

1/20

Finite difference method

Principle: derivatives in the partial differential equation are approximatedby linear combinations of function values at the grid points

1D: = (0 , X ), u i u (x i ), i = 0 , 1, . . . , N

grid points x i = i x mesh size x = XN

First-order derivatives

ux (x ) = lim x 0

u (x + x ) u (x) x = lim x 0

u (x ) u (x x) x

= lim x 0

u (x + x ) u (x x)2 x

(by denition)

• 8/7/2019 Finite difference method

2/20

Approximation of rst-order derivativesGeometric interpretation

ux i

u i +1 u i x forward difference

ux i

u i u i 1 x backward difference

ux i

u i +1 u i 12 x central difference

Taylor series expansion u (x ) =

n =0

(x x i ) n

n ! n ux n i , u C

([0, X ])

T 1 : u i+1 = u i + xux i +

( x )2

2 2ux 2 i +

( x )3

6 3ux 3 i + . . .

T 2 : u i 1 = u i xux i

+( x)2

2 2ux 2 i

( x)3

6 3ux 3 i

+ . . .

• 8/7/2019 Finite difference method

3/20

Analysis of truncation errorsAccuracy of nite difference approximations

T 1 u

x i=

u i+1 u i

x

x

2

2u

x2

i

( x)2

6

3u

x3

i+ . . .

forward difference truncation error O( x)

T 2 ux i

=u i u i 1

x+

x2

2ux 2 i

( x )2

6 3ux 3 i

+ . . .

backward difference truncation error O( x)

T 1 T 2 ux i

=u i+1 u i 1

2 x

( x )2

6 3ux 3 i

+ . . .

central difference truncation error O( x )2

= m ( x)m + m +1 ( x)m +1 + . . . m ( x )m

• 8/7/2019 Finite difference method

4/20

Approximation of second-order derivatives

Central difference scheme

T 1 + T 2 2ux 2 i

=u i+1 2u i + u i 1

( x)2+ O( x )2

Alternative derivation

2ux 2 i

=

xux i

= lim x 0

ux i+1 / 2

ux i 1/ 2

x

u i +1 u i

x u i u i 1

x x

= u i+1 2u i + u i 1

( x )2

Variable coefficients f (x ) = d(x ) ux diffusive ux

f x i

f i+1 / 2 f i 1/ 2

x= di+1 / 2

u i +1 u i x di 1/ 2

u i u i 1 x

x

=di+1 / 2u i+1 (di+1 / 2 + di 1/ 2)u i + di 1/ 2u i 1

( x)2

• 8/7/2019 Finite difference method

5/20

Approximation of mixed derivatives

2D: 2 u

xy =

xuy =

y

ux

2 u

xy i,j = uy i +1 ,j uy i 1 ,j2 x + O ( x )2

uy i +1 ,j =u i +1 ,j +1 u i +1 ,j 1

2 y+ O ( y)2

uy i 1 ,j =u i 1 ,j +1 u i 1 ,j 1

2 y+ O ( y)2

Second-order difference approximation

2uxy i,j

=u i+1 ,j +1 u i+1 ,j 1 u i 1,j +1 + u i 1,j 1

4 x y+ O[( x)2 , ( y)2]

• 8/7/2019 Finite difference method

6/20

One-sided nite differences

ux 0

=u 1 u0

x+ O( x ) forward difference

backward/central difference approximationswould need u 1 which is not available

Polynomial tting

u (x) = u 0 + xu

x 0+

x2

2

2u

x2

0

+x3

6

3u

x3

0

+ . . .

u (x ) a + bx + cx 2 ,ux

b + 2 cx,ux 0

b

approximate u by a polynomial and differentiate it to obtain the derivatives

u 0 = a

u 1 = a + b x + c x 2

u 2 = a + 2 b x + 4 c x2

c x 2 = u 1 u 0 b x

b = 3u 0 + 4 u 1 u 2

2 x

• 8/7/2019 Finite difference method

7/20

Analysis of the truncation error

One-sided approximationux i

u i + u i+1 + u i+2

x

u i+1 = u i + xux i

+( x )2

2 2ux 2 i

+( x)3

6 3ux 3 i

+ . . .

u i+2 = u i + 2 xu

x i +(2 x)2

2

2u

x 2 i +(2 x )3

6

3u

x 3 i + . . .

u i + u i +1 + u i +2 x =

+ + x u i + ( + 2 )

ux i +

x2 ( + 4 )

2 ux 2 i

+ O( x 2)

Second-order accurate if + + = 0 , + 2 = 1 , + 4 = 0

= 32 , = 2 , = 12

ux i =

3u i +4 u i +1 u i +22 x + O( x

2)

• 8/7/2019 Finite difference method

8/20

Application to second-order derivatives

One-sided approximation 2ux 2 i

u i + u i+1 + u i+2

x2

u i+1 = u i + xux i

+( x )2

2 2ux 2 i

+( x)3

6 3ux 3 i

+ . . .

u i+2 = u i + 2 xu

x i +(2 x)2

2

2u

x 2 i +(2 x )3

6

3u

x 3 i + . . .

u i + u i +1 + u i +2 x 2 =

+ + x 2 u i +

+2 x

ux i +

+4 2

2 ux 2 i

+ O( x)

First-order accurate if + + = 0 , + 2 = 0 , + 4 = 2

= 1 , = 2, = 1 ux i =u i 2u i +1 + u i +2

x 2 + O( x )

• 8/7/2019 Finite difference method

9/20

High-order approximations

ux i

=2u i+1 + 3 u i 6u i 1 + u i 2

6 x+ O( x)3 backward difference

ux i

= u i+2 + 6 u i+1 3u i 2u i 16 x

+ O( x)3 forward difference

ux i

= u i+2 + 8 u i+1 8u i 1 + u i 2

12 x+ O( x )4 central difference

2ux 2 i

= u i+2 + 16 u i+1 30u i + 16 u i 1 u i 2

12( x)2+ O( x )4 central difference

Pros and cons of high-order difference 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

• 8/7/2019 Finite difference method

10/20

Example: 1D Poisson equation

Boundary value problem

2u

x 2= f in = (0 , 1), u(0) = u(1) = 0

One-dimensional mesh

u i u (x i ), f i = f (x i ) x i = i x, x = 1N , i = 0 , 1, . . . , N

Central difference approximation O( x )2

u i 1 2u i + u i +1( x ) 2 = f i , i = 1 , . . . , N 1

u 0 = u N = 0 Dirichlet boundary conditions

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

• 8/7/2019 Finite difference method

11/20

Example: 1D Poisson equation

Linear system for the central difference scheme

i = 1 u 0 2u 1 + u 2( x ) 2 = f 1

i = 2 u 1 2u 2 + u 3

( x ) 2 = f 2i = 3 u 2 2u 3 + u 4( x ) 2 = f 3

. . .

i = N 1 u N 2 2u N 1 + u N( x ) 2 = f N 1

Matrix form Au = F A R N 1 N 1 u, F R N 1

A =1

( x )2

2 1 1 2 1

1 2 1. . . 1 2

, u =

u 1u 2u 3

u N 1

, F =

f 1f 2f 3

f N 1

The matrix A is tridiagonal and symmetric positive denite invertible.

• 8/7/2019 Finite difference method

12/20

Other types of boundary conditionsDirichlet-Neumann BC u (0) = ux (1) = 0

u 0 = 0 ,u N +1 u N 1

2 x= 0 u N +1 = u N 1 central difference

Extra equation for the last node

u N 1 2u N + u N +1

( x)2= f N

uN 1 + u N ( x)2

=12

f N

Extended linear system Au = F A R N N u, F R N

A =1

( x)2

2 1 1 2 1

1 2 1. . . 1 2 1

1 1

, u =

u1u2u3

uN 1u N

, F =

f 1f 2f 3

f N 112 f N

The matrix A remains tridiagonal and symmetric positive denite.

• 8/7/2019 Finite difference method

13/20

Other types of boundary conditions

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

u0 = g0 2u1 u 2

( x)2= f 1 +

g0( x )2

rst equation

Non-homogeneous Neumann BC ux (1) = g1 only F changes

uN +1 u N 12 x

= g1 u N +1 = u N 1 + 2 xg 1

u N 1 2u N + u N +1

( x)2= f N u

N 1 + u N ( x)2

= 12

f N + g1

x

Non-homogeneous Robin BC ux (1) + u (1) = g2 A and F change

u N +1 u N

12 x + u N = g2 u N +1 = u N

1 2 xu N + 2 xg 2

u N 1 2u N + u N +1

( x )2= f N

u N 1 + (1 + x )uN ( x )2

=12

f N +g2 x

• 8/7/2019 Finite difference method

14/20

Example: 2D Poisson equation

Boundary value problem

2 u

x 2 2 uy 2 = f in = (0 , 1) (0, 1)

u = 0 on =

Uniform mesh: x = y = h, N = 1h

u i,j u(x i , y j ), f i,j = f (x i , y j ), (x i , y j ) = ( ih,jh ), i, j = 0 , 1, . . . , N

Central difference approximation O(h 2)

u i 1 ,j + u i,j 1 4u i,j + u i +1 ,j + u i,j +1h 2 = f i,j , i, j = 1 , . . . , N 1

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

• 8/7/2019 Finite difference method

15/20

Example: 2D Poisson equation

Linear system Au = F A R (N 1)2 (N 1) 2 u, F R (N 1)

2

row-by-rownode numbering

u = [u 1,1 . . . u N 1,1 u 1,2 . . . u N 1,2 u1,3 . . . u N 1,N 1]T

F = [ f 1,1 . . . f N 1,1 f 1,2 . . . f N 1,2 f 1,3 . . . f N 1,N 1]T

A =

B I I B I

. . . . . .

I B I I B

, B =

4 1 1 4 1

. . . . . .

1 4 1 1 4

I =

11

11

The matrix A is sparse, block-tridiagonal(for the above numbering) and SPD.

cond2(A) =| max || min |

= O(h 2)

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

• 8/7/2019 Finite difference method

16/20

Treatment of complex geometries2D Poisson equation

2 u

x 2 2 uy 2 = f in

u = g0 on

Difference equation

u 1 + u2 4u0 + u 3 + u 4

h 2= f 0

curvilinear boundary

Q

P

Q04

h

2

1

3

R

stencil of Q

Linear interpolation

u (R ) =u 4(h ) + u 0

h= g0(R ) u 4 = u 0

h

+ g0(R )h

h

Substitution yields u 1 + u 2 4 + h u 0 + u3 = h2 f 0 + g0(R ) hh

Neumann and Robin BC are even more difficult to implement

• 8/7/2019 Finite difference method

17/20

Grid transformations

Purpose: to provide a simple treatment of curvilinear boundaries

The original PDE must be rewritten in terms of ( , ) instead of ( x, y ) anddiscretized in the computational domain rather than the physical one.

Derivative transformationsux

,uy

, . . .

difficult to compute

u

,u

, . . .

easy to compute

• 8/7/2019 Finite difference method

18/20

PDE transformations for a direct mapping

Direct mapping = (x, y ), = (x, y )

Chain rule ux

=u

x

+u

x

,uy

=u

y

+u

y

2ux 2

=u

2x 2

+u

2x 2

+ 2 2u

x

x

+ 2u 2

x

2+

2u 2

x

2

2uy 2

=u

2y 2

+u

2y 2

+ 2 2u

y

y

+ 2u 2

y

2

+ 2u 2

y

2

Example: 2D Poisson equation u = f turns into

2u 2

x

2

+y

2

2u 2

x

2

+y

2

2 2u

x

x

+y

y

u

2x 2

+ 2y 2

u

2x 2

+ 2y 2

= f transformed equationscontain many more terms

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

• 8/7/2019 Finite difference method

19/20

• 8/7/2019 Finite difference method

20/20

Direct versus inverse mappingTotal differentials for both coordinate systems

= (x, y )

= (x, y )

d = x dx +y dy

d = x dx + y dy

d

d=

x

y

x y

dx

dy

x = x (, )

y = y(, )

dx = x d +x d

dy = y

d + y

d

dx

dy=

x

x

y

y

d

d

x

y

x

y

=x

x

y

y

1

=1

det J

y

x

yx

Relationship between the direct and inverse metricsx

=1

det J y

,x

= 1

det J y

,y

= 1

det J x

,y

=1

det J x