04.05.2015 Views

Slides - School of Engineering - University of Warwick

Slides - School of Engineering - University of Warwick

Slides - School of Engineering - University of Warwick

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ES440/ES911: CFD<br />

Chapter 3. Finite Difference Methods<br />

Dr Yongmann M. Chung<br />

http://www.eng.warwick.ac.uk/staff/ymc/ES440.html<br />

Y.M.Chung@warwick.ac.uk<br />

<strong>School</strong> <strong>of</strong> <strong>Engineering</strong> & Centre for Scientific Computing<br />

<strong>University</strong> <strong>of</strong> <strong>Warwick</strong><br />

1


Chapter 3<br />

Finite Difference Methods<br />

2


3.1 Introduction<br />

A generic transport equation<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

3


3.1 Introduction<br />

A generic transport equation<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

In Cartesian Coordinates,<br />

∂ρuφ<br />

∂x + ∂ρvφ<br />

∂y + ∂ρwφ<br />

∂z<br />

= ∂<br />

∂x (Γ∂φ ∂x ) + ∂ ∂y (Γ∂φ ∂y ) + ∂ ∂z (Γ∂φ ∂z ) + q φ.<br />

3


3.1 Introduction<br />

A generic transport equation<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

In Cartesian Coordinates,<br />

∂ρuφ<br />

∂x + ∂ρvφ<br />

∂y + ∂ρwφ<br />

∂z<br />

= ∂<br />

∂x (Γ∂φ ∂x ) + ∂ ∂y (Γ∂φ ∂y ) + ∂ ∂z (Γ∂φ ∂z ) + q φ.<br />

Simplifications<br />

Convection Terms<br />

Diffusion Terms<br />

Source Term<br />

Unsteady Term (Ch. 6)<br />

3


3.2 Basic Concept<br />

First step is to discretise the geometric domain<br />

A numerical grid (or computational mesh) must be<br />

defined.<br />

Each node is uniquely identified by a set <strong>of</strong> indices, i in<br />

1D, (i, j) in 2D & (i, j, k) in 3D.<br />

4


3.2 - 1D Discretisation<br />

Divide the computational domain (L) using N grid points (or<br />

mesh points or nodes).<br />

x 1 , x 2 , x 3 , . . . , x i−1 , x i , x i+1 , . . . , x N−2 , x N−1 , x N .<br />

∆x i is the distance between the neighbour grid points.<br />

5


3.2 - Discretisation<br />

Each node has one unknown variable associated with it.<br />

1D: f 1 , f 2 , f 3 , . . . , f i−1 , f i , f i+1 , . . . , f N−2 , f N−1 , f N .<br />

2D: f 1,1 , f 2,1 , f 3,1 , . . . , f i−1,j , f i,j , f i+1,j , . . . , f N−1,N , f N,N .<br />

3D:<br />

f 1,1,1 , f 2,1,1 , f 3,1,1 , . . . , f i−1,j,k , f i,j,k , f i+1,j,k , . . . , f N,N,N .<br />

6


3.2 Basic Concept - Cont’d<br />

Uniform vs. Non-uniform grids<br />

7


3.2 Basic Concept - Cont’d<br />

Uniform vs. Non-uniform grids<br />

Structured vs. Unstructured.<br />

7


3.2 Basic Concept - Cont’d<br />

Each node has one unknown variable associated with it.<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

8


3.2 Basic Concept - Cont’d<br />

Each node has one unknown variable associated with it.<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

1D: f 1 , f 2 , f 3 , . . . , f i−1 , f i , f i+1 , . . . , f N−2 , f N−1 , f N .<br />

8


3.2 Basic Concept - Cont’d<br />

Each node has one unknown variable associated with it.<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

1D: f 1 , f 2 , f 3 , . . . , f i−1 , f i , f i+1 , . . . , f N−2 , f N−1 , f N .<br />

2D: f 1,1 , f 1,2 , f 1,3 , . . . , f i−1,j , f i,j , f i+1,j , . . . , f N,N−1 , f N,N<br />

8


3.2 Basic Concept - Cont’d<br />

Replacing each term <strong>of</strong> the PDE by a finite-difference<br />

approximation.<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

Convection Terms,<br />

Diffusion Terms,<br />

Source Term.<br />

9


3.2 Basic Concept - Cont’d<br />

A generic transport equation<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

10


3.2 Basic Concept - Cont’d<br />

A generic transport equation<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ<br />

∂x j<br />

) + q φ . (3.1 F&P )<br />

The numbers <strong>of</strong> equations and unknowns must be equal<br />

∂ρu j φ 1<br />

∂x j<br />

∂ρu j φ 2<br />

∂x j<br />

= ∂<br />

∂x j<br />

(Γ ∂φ 1<br />

∂x j<br />

) + q φ , (1)<br />

= ∂<br />

∂x j<br />

(Γ ∂φ 2<br />

∂x j<br />

) + q φ , (2)<br />

∂ρu j φ N<br />

∂x j<br />

.<br />

= ∂<br />

∂x j<br />

(Γ ∂φ N<br />

∂x j<br />

) + q φ .<br />

(N)<br />

10


3.2 - Finite Difference Approximations<br />

The idea behind FD Approximations is borrowed directly<br />

from the definition <strong>of</strong> a derivative<br />

( ) df<br />

dx<br />

x i<br />

= lim<br />

∆x→0<br />

f(x i + ∆x) − f(x i )<br />

. (3.2 F&P )<br />

∆x<br />

11


3.2 - Finite Difference Approximations<br />

Three Approximations<br />

Forward difference: f(x i ) and f(x i + ∆x),<br />

Backward difference: f(x i − ∆x) and f(x i ),<br />

Central difference: f(x i − ∆x) and f(x i + ∆x).<br />

12


3.2 - Finite Difference Approximations<br />

Three Approximations<br />

Forward difference: f(x i ) and f(x i + ∆x),<br />

Backward difference: f(x i − ∆x) and f(x i ),<br />

Central difference: f(x i − ∆x) and f(x i + ∆x).<br />

12


Taylor Series Expansion<br />

Taylor Series Expansion<br />

Any continuous differentiable function f(x) can, in the<br />

vicinity <strong>of</strong> x i , be expressed as a Taylor series:<br />

f(x) = f i +∆x<br />

( ) ∂f<br />

+ 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 + 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3<br />

· · · + 1 ( ∂ n f<br />

n! ∆xn ∂x<br />

)i<br />

n + H. (3.3 F&P )<br />

where H means all remaining HIGHER ORDER TERMS.<br />

+<br />

13


Taylor Series Expansion<br />

Taylor Series Expansion<br />

Any continuous differentiable function f(x) can, in the<br />

vicinity <strong>of</strong> x i , be expressed as a Taylor series:<br />

f(x) = f i +∆x<br />

( ) ∂f<br />

+ 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 + 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3<br />

· · · + 1 ( ∂ n f<br />

n! ∆xn ∂x<br />

)i<br />

n + H. (3.3 F&P )<br />

where H means all remaining HIGHER ORDER TERMS.<br />

+<br />

Expressions for the variable values in terms <strong>of</strong> the variable<br />

and its derivatives at x i .<br />

( ) ( ∂f ∂ 2 f<br />

f i , ,<br />

∂x<br />

i<br />

∂x 2 )i<br />

,<br />

( ∂ 3 f<br />

∂x 3 )i<br />

, . . . ,<br />

( ∂ n f<br />

∂x n )i<br />

.<br />

13


3.3 - Forward Difference: ∂f<br />

∂x<br />

Each node has one unknown variable associated with it.<br />

x 1 , x 2 , x 3 , . . . , x i−1 , x i , x i+1 , . . . , x N−2 , x N−1 , x N .<br />

f 1 , f 2 , f 3 , . . . , f i−1 , f i , f i+1 , . . . , f N−2 , f N−1 , f N .<br />

14


3.3 - Forward Difference: ∂f<br />

∂x<br />

Each node has one unknown variable associated with it.<br />

x 1 , x 2 , x 3 , . . . , x i−1 , x i , x i+1 , . . . , x N−2 , x N−1 , x N .<br />

f 1 , f 2 , f 3 , . . . , f i−1 , f i , f i+1 , . . . , f N−2 , f N−1 , f N .<br />

Finite Difference Formulae can be easily derived<br />

By replacing x by x i+1 .<br />

f i+1 = f i + ∆x<br />

( ) ∂f<br />

∂x<br />

i<br />

+ 1 2! ∆x2 ( ∂ 2 f<br />

∂x 2 )i<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H.<br />

14


3.3 - Forward Difference: ∂f<br />

∂x<br />

Each node has one unknown variable associated with it.<br />

x 1 , x 2 , x 3 , . . . , x i−1 , x i , x i+1 , . . . , x N−2 , x N−1 , x N .<br />

f 1 , f 2 , f 3 , . . . , f i−1 , f i , f i+1 , . . . , f N−2 , f N−1 , f N .<br />

Finite Difference Formulae can be easily derived<br />

By replacing x by x i+1 .<br />

f i+1 = f i + ∆x<br />

( ) ∂f<br />

∂x<br />

i<br />

+ 1 2! ∆x2 ( ∂ 2 f<br />

∂x 2 )i<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H.<br />

14


3.3 - Forward Difference: ∂f<br />

∂x<br />

Taylor Series <strong>of</strong> f i+1 at x i+1 .<br />

f i+1 = f i + ∆x<br />

( ) ∂f<br />

∂x<br />

i<br />

+ 1 2! ∆x2 ( ∂ 2 f<br />

∂x 2 )i<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H.<br />

15


3.3 - Forward Difference: ∂f<br />

∂x<br />

Taylor Series <strong>of</strong> f i+1 at x i+1 .<br />

f i+1 = f i + ∆x<br />

( ) ∂f<br />

∂x<br />

i<br />

+ 1 2! ∆x2 ( ∂ 2 f<br />

∂x 2 )i<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H.<br />

Rearranging Eqn. (3.3) and dividing by the finite-difference<br />

∆x gives<br />

∂f<br />

∂x = f i+1 − f i<br />

∆x<br />

− 1 2!<br />

∂ 2 f<br />

∂x 2 ∆x − 1 3!<br />

∂ 3 f<br />

∂x 3 ∆x2 + H. (3.4 F&P )<br />

The first term is a Finite Difference Approximation.<br />

The next term is the Leading Error term: O(∆x).<br />

15


3.3 - Forward Difference - Cont’d<br />

Formula (3.4) is usually recast in the following form<br />

∂f<br />

∂x = f i+1 − f i<br />

∆x<br />

+ O(∆x). (3.7 FP )<br />

This is referred to as the first-order forward difference.<br />

The exponent <strong>of</strong> ∆x in the leading error term is the order<br />

<strong>of</strong> accuracy.<br />

It is a useful measure <strong>of</strong> accuracy.<br />

It gives an indication <strong>of</strong> how rapidly the accuracy can be<br />

improved with the refinement <strong>of</strong> the grid spacing.<br />

16


3.3 - Forward Difference - Cont’d<br />

u<br />

u i+1<br />

Predicted du/dx<br />

u i<br />

True du/dx<br />

u i-1<br />

∆x ∆x<br />

∂f<br />

∂x ≈ f i+1 − f i<br />

. (3.7 F&P )<br />

∆x<br />

Truncation Error:<br />

T.E. ∼ O(∆x).<br />

x i-1<br />

x i<br />

x i+1<br />

x<br />

17


3.3 - Backward Difference: ∂f<br />

∂x<br />

By expanding f i−1 about the point x i .<br />

f i−1 = f i − ∆x<br />

( ) ∂f<br />

∂x<br />

i<br />

+ 1 2! ∆x2 ( ∂ 2 f<br />

∂x 2 )i<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H.<br />

18


3.3 - Backward Difference: ∂f<br />

∂x<br />

By expanding f i−1 about the point x i .<br />

f i−1 = f i − ∆x<br />

( ) ∂f<br />

∂x<br />

i<br />

+ 1 2! ∆x2 ( ∂ 2 f<br />

∂x 2 )i<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H.<br />

Similarly, rearranging the above Eqn. (3.3) and dividing by<br />

the finite-difference ∆x gives<br />

∂f<br />

∂x = f i − u i−1<br />

∆x<br />

+ 1 2!<br />

∂ 2 f<br />

∂x 2 ∆x − 1 3!<br />

∂ 3 f<br />

∂x 3 ∆x2 + H. (3.5 F&P )<br />

The first term is a Finite Difference Approximation.<br />

The next term is the Leading Error term: O(∆x).<br />

18


3.3 - Backward Difference - Cont’d<br />

Formula (3.5) is usually recast in the following form<br />

∂f<br />

∂x = f i − f i−1<br />

∆x<br />

+ O(∆x). (3.8 FP )<br />

This is referred to as the first-order backward<br />

difference.<br />

u<br />

u i+1<br />

u i<br />

True du/dx<br />

Predicted du/dx<br />

u i-1<br />

∂f<br />

∂x ≈ f i − f i−1<br />

. (3.8 F&P )<br />

∆x<br />

Truncation Error:<br />

T.E. ∼ O(∆x).<br />

∆x<br />

∆x<br />

x i-1<br />

x i<br />

x i+1<br />

x<br />

19


3.3 - Central Difference: ∂f<br />

∂x<br />

Taylor Series <strong>of</strong> f i+1 & f i−1 at both x i+1 & x i−1 .<br />

( ) ∂f<br />

f i+1 = f i + ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 ( ) ∂f<br />

f i−1 = f i − ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H,<br />

+ H.<br />

20


3.3 - Central Difference: ∂f<br />

∂x<br />

Taylor Series <strong>of</strong> f i+1 & f i−1 at both x i+1 & x i−1 .<br />

( ) ∂f<br />

f i+1 = f i + ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 ( ) ∂f<br />

f i−1 = f i − ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H,<br />

+ H.<br />

The widely used central difference formula can be<br />

obtained from subtraction <strong>of</strong> two Taylor series expansions.<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

− 1 3!<br />

∂ 3 f<br />

∂x 3 ∆x2 − 1 5!<br />

∂ 5 f<br />

∂x 5 ∆x4 + H. (3.6 F&P )<br />

20


3.3 - Central Differences - Cont’d<br />

Formula (3.6) is usually recast in the following form<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.8 FP )<br />

This is a second-order formula.<br />

u<br />

u i+1<br />

Predicted du/dx<br />

u i<br />

True du/dx<br />

u i-1<br />

∆x ∆x<br />

∂f<br />

∂x ≈ f i+1 − f i−1<br />

. (3.8 F&P )<br />

2∆x<br />

Truncation Error:<br />

T.E. ∼ O(∆x 2 ).<br />

x i-1<br />

x i<br />

x i+1<br />

x<br />

21


3.3 - Truncation Errors<br />

Numerically evaluated at x = 4.<br />

The absolute values <strong>of</strong> the differences from the exact<br />

solution.<br />

f(x) = sin x<br />

x 3 .<br />

With ∆x = 0.1<br />

f i−1 = −0.0115943,<br />

f i = −0.0118250,<br />

f i+1 = −0.0118726.<br />

22


3.3 - Fourth Order Accuracy<br />

In general, we can obtain higher accuracy if we include<br />

more points.<br />

Fourth Order Accuracy: T.E. ∼ O(∆x 4 ).<br />

23


3.3 - Fourth Order Accuracy<br />

In general, we can obtain higher accuracy if we include<br />

more points.<br />

Fourth Order Accuracy: T.E. ∼ O(∆x 4 ).<br />

Taylor Series <strong>of</strong> f i+2 , f i+1 , f i−1 & f i−2 at x i+2 , x i+1 , x i−1 &<br />

x i−2 .<br />

( ) ∂f<br />

f i+2 = f i + 2∆x + 1 ( ∂ 2 )<br />

f<br />

∂x 2! (2∆x)2 ∂x 2<br />

( ) ∂f<br />

f i+1 = f i + ∆x + 1 ( ∂ 2 )<br />

f<br />

∂x 2! ∆x2 ∂x 2<br />

( ) ∂f<br />

f i−1 = f i − ∆x + 1 ( ∂ 2 )<br />

f<br />

∂x 2! ∆x2 ∂x 2<br />

( ) ∂f<br />

f i−2 = f i − 2∆x + 1 ( ∂ 2 )<br />

f<br />

∂x 2! (2∆x)2 ∂x 2<br />

+ 1 3! (2∆x)3 ( ∂ 3 f<br />

∂x 3 )<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )<br />

+ H,<br />

+ H,<br />

− 1 3! (2∆x)3 ( ∂ 3 f<br />

∂x 3 )<br />

+ H,<br />

+ H.<br />

23


3.3 - Fourth Order Accuracy - Cont’d<br />

Rearranging the above equations and dividing by the<br />

finite-difference ∆x gives<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ 4 5!<br />

∂ 5 f<br />

∂x 5 ∆x4 + H.<br />

+ O(∆x 4 ). (3.14 F&P )<br />

24


3.3 - Fourth Order Accuracy - Cont’d<br />

Rearranging the above equations and dividing by the<br />

finite-difference ∆x gives<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ 4 5!<br />

∂ 5 f<br />

∂x 5 ∆x4 + H.<br />

+ O(∆x 4 ). (3.14 F&P )<br />

Fourth Order Accuracy: T.E. ∼ O(∆x 4 ).<br />

Requires four grid points to achieve the fourth order<br />

accuracy.<br />

24


3.3 - Fourth Order Accuracy - Cont’d<br />

Rearranging the above equations and dividing by the<br />

finite-difference ∆x gives<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ 4 5!<br />

∂ 5 f<br />

∂x 5 ∆x4 + H.<br />

+ O(∆x 4 ). (3.14 F&P )<br />

Fourth Order Accuracy: T.E. ∼ O(∆x 4 ).<br />

Requires four grid points to achieve the fourth order<br />

accuracy.<br />

24


3.3 - Higher Order Accuracy<br />

Second-Order Accuracy: T.E. ∼ O(∆x 2 ).<br />

Requires Two grid points, x i+1 & x i−1 .<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.9 FP )<br />

25


3.3 - Higher Order Accuracy<br />

Second-Order Accuracy: T.E. ∼ O(∆x 2 ).<br />

Requires Two grid points, x i+1 & x i−1 .<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.9 FP )<br />

Fourth-Order Accuracy: T.E. ∼ O(∆x 4 ).<br />

Requires Four grid points at x i+2 , x i+1 , x i−1 & x i−2 .<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ O(∆x 4 ). (3.14 F&P )<br />

25


3.3 - Higher Order Accuracy<br />

Second-Order Accuracy: T.E. ∼ O(∆x 2 ).<br />

Requires Two grid points, x i+1 & x i−1 .<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.9 FP )<br />

Fourth-Order Accuracy: T.E. ∼ O(∆x 4 ).<br />

Requires Four grid points at x i+2 , x i+1 , x i−1 & x i−2 .<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ O(∆x 4 ). (3.14 F&P )<br />

N-th Order Accuracy: T.E. ∼ O(∆x N ).<br />

Requires N grid points to achieve the N-th order<br />

accuracy.<br />

Taylor Series <strong>of</strong> f i+N/2 , . . . , f i+1 , f i−1 , . . . & f i−N/2 . 25


3.3 - High Order Accuracy - Cont’d<br />

N-th Order Accuracy: T.E. ∼ O(∆x N ).<br />

Requires N grid points to achieve the N-th order<br />

accuracy.<br />

The main difficulty with the higher order formulae occurs<br />

near boundaries <strong>of</strong> the domain.<br />

For example, the derivative <strong>of</strong> f at x 1 would require the<br />

value <strong>of</strong> f at x −1 which is not available.<br />

In practice, to alleviate this problem, we utilise lower<br />

order or non-central formulae near boundaries.<br />

26


3.3 - High Order Accuracy - Cont’d<br />

N-th Order Accuracy: T.E. ∼ O(∆x N ).<br />

Requires N grid points to achieve the N-th order<br />

accuracy.<br />

The main difficulty with the higher order formulae occurs<br />

near boundaries <strong>of</strong> the domain.<br />

For example, the derivative <strong>of</strong> f at x 1 would require the<br />

value <strong>of</strong> f at x −1 which is not available.<br />

In practice, to alleviate this problem, we utilise lower<br />

order or non-central formulae near boundaries.<br />

26


3.3 - High Order Accuracy - Cont’d<br />

N-th Order Accuracy: T.E. ∼ O(∆x N ).<br />

Requires N grid points to achieve the N-th order<br />

accuracy.<br />

The main difficulty with the higher order formulae occurs<br />

near boundaries <strong>of</strong> the domain.<br />

For example, the derivative <strong>of</strong> f at x 1 would require the<br />

value <strong>of</strong> f at x −1 which is not available.<br />

In practice, to alleviate this problem, we utilise lower<br />

order or non-central formulae near boundaries.<br />

26


3.4 Second Order Derivative: ∂2 f<br />

∂x 2<br />

Similar formulae can be derived for second order or higher<br />

order derivatives.<br />

( ) ∂f<br />

f i+1 = f i + ∆x<br />

∂x<br />

( ) ∂f<br />

f i−1 = f i − ∆x<br />

∂x<br />

i<br />

i<br />

+ 1 ( ∂ 2 f<br />

2! ∆x2 ∂x<br />

)i<br />

2<br />

+ 1 ( ∂ 2 f<br />

2! ∆x2 ∂x<br />

)i<br />

2<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H,<br />

+ H.<br />

27


3.4 Second Order Derivative: ∂2 f<br />

∂x 2<br />

Similar formulae can be derived for second order or higher<br />

order derivatives.<br />

( ) ∂f<br />

f i+1 = f i + ∆x<br />

∂x<br />

( ) ∂f<br />

f i−1 = f i − ∆x<br />

∂x<br />

i<br />

+ 1 ( ∂ 2 f<br />

2! ∆x2 ∂x<br />

)i<br />

2<br />

+ 1 ( ∂ 2 f<br />

2! ∆x2 ∂x<br />

)i<br />

2<br />

After minor rearrangement, we get<br />

i<br />

+ 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

− 1 3! ∆x3 ( ∂ 3 f<br />

∂x 3 )i<br />

+ H,<br />

+ H.<br />

∂ 2 f<br />

∂x 2 = f i+1 − 2f i + f i−1<br />

∆x 2<br />

+ 1 12 ∆x2∂4 f<br />

∂x 4 + H. (3.30FP )<br />

27


3.4 - Higher Order Accuracy: O(∆x 4 )<br />

Second Order Accuracy: O(∆x 2 )<br />

∂ 2 f<br />

∂x 2 = f i+1 − 2f i + f i−1<br />

∆x 2 + O(∆x 2 ). (3.30 FP )<br />

28


3.4 - Higher Order Accuracy: O(∆x 4 )<br />

Second Order Accuracy: O(∆x 2 )<br />

∂ 2 f<br />

∂x 2 = f i+1 − 2f i + f i−1<br />

∆x 2 + O(∆x 2 ). (3.30 FP )<br />

Fourth Order Accuracy: O(∆x 4 )<br />

∂ 2 f<br />

∂x 2 = −f i+2 + 16f i+1 − 30f i + 16f i−1 − f i−2<br />

12∆x 2 + O(∆x 4 ).<br />

(3.32 F&P )<br />

Taylor Series <strong>of</strong> f i+N/2 , . . . , f i+1 , f i−1 , . . . & f i−N/2 at N<br />

points.<br />

28


3.4 Third Order Derivative: ∂3 f<br />

∂x 3<br />

Similar formulae can be derived for higher order derivatives.<br />

( ) ∂f<br />

f i+1 = f i + ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 + 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3 + H,<br />

( ) ∂f<br />

f i−1 = f i − ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 − 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3 + H.<br />

29


3.4 Third Order Derivative: ∂3 f<br />

∂x 3<br />

Similar formulae can be derived for higher order derivatives.<br />

( ) ∂f<br />

f i+1 = f i + ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 + 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3 + H,<br />

( ) ∂f<br />

f i−1 = f i − ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 − 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3 + H.<br />

Second Order Accuracy<br />

∂ 3 f<br />

∂x 3 = f i+2 − 2f i+1 + 2f i−1 − f i−2<br />

2∆x 3 + O(∆x 2 ).<br />

29


3.4 Third Order Derivative: ∂3 f<br />

∂x 3<br />

Similar formulae can be derived for higher order derivatives.<br />

( ) ∂f<br />

f i+1 = f i + ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 + 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3 + H,<br />

( ) ∂f<br />

f i−1 = f i − ∆x + 1 ( ∂ 2 f<br />

∂x<br />

i<br />

2! ∆x2 ∂x<br />

)i<br />

2 − 1 ( ∂ 3 f<br />

3! ∆x3 ∂x<br />

)i<br />

3 + H.<br />

Second Order Accuracy<br />

∂ 3 f<br />

∂x 3 = f i+2 − 2f i+1 + 2f i−1 − f i−2<br />

2∆x 3 + O(∆x 2 ).<br />

Fourth Order Accuracy<br />

∂ 3 f<br />

∂x 3 = −f i+3 + 8f i+2 − 13f i+1 + 13f i−1 − 8f i−2 + f i−3<br />

8∆x 3 + O(∆x 4 ).<br />

29


First Order Accuracy: O(∆x)<br />

FORWARD & BACKWARD DIFFERENCES<br />

30


First Order Accuracy: O(∆x)<br />

FORWARD & BACKWARD DIFFERENCES<br />

Forward Difference<br />

∂f<br />

∂x = f i+1 − f i<br />

∆x<br />

+ O(∆x). (3.7 FP )<br />

30


First Order Accuracy: O(∆x)<br />

FORWARD & BACKWARD DIFFERENCES<br />

Forward Difference<br />

∂f<br />

∂x = f i+1 − f i<br />

∆x<br />

+ O(∆x). (3.7 FP )<br />

Backward Difference<br />

∂f<br />

∂x = f i − f i−1<br />

∆x<br />

+ O(∆x). (3.8 FP )<br />

30


Second Order Accuracy: O(∆x 2 )<br />

CENTRAL DIFFERENCES<br />

31


Second Order Accuracy: O(∆x 2 )<br />

CENTRAL DIFFERENCES<br />

First Derivative<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.9 FP )<br />

31


Second Order Accuracy: O(∆x 2 )<br />

CENTRAL DIFFERENCES<br />

First Derivative<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.9 FP )<br />

Second Derivative<br />

∂ 2 f<br />

∂x 2 = f i+1 − 2f i + f i−1<br />

∆x 2 + O(∆x 2 ). (3.30 FP )<br />

31


Second Order Accuracy: O(∆x 2 )<br />

CENTRAL DIFFERENCES<br />

First Derivative<br />

∂f<br />

∂x = f i+1 − f i−1<br />

2∆x<br />

+ O(∆x 2 ). (3.9 FP )<br />

Second Derivative<br />

Third Derivative<br />

∂ 2 f<br />

∂x 2 = f i+1 − 2f i + f i−1<br />

∆x 2 + O(∆x 2 ). (3.30 FP )<br />

∂ 3 f<br />

∂x 3 = f i+2 − 2f i+1 + 2f i−1 − f i−2<br />

2∆x 3 + O(∆x 2 ).<br />

31


Fourth Order Accuracy: O(∆x 4 )<br />

CENTRAL DIFFERENCES<br />

32


Fourth Order Accuracy: O(∆x 4 )<br />

CENTRAL DIFFERENCES<br />

First Derivative<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ O(∆x 4 ). (3.14 F&P )<br />

32


Fourth Order Accuracy: O(∆x 4 )<br />

CENTRAL DIFFERENCES<br />

First Derivative<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ O(∆x 4 ). (3.14 F&P )<br />

Second Derivative<br />

∂ 2 f<br />

∂x 2 = −f i+2 + 16f i+1 − 30f i + 16f i−1 − f i−2<br />

12∆x 2 + O(∆x 4 ).<br />

(3.32 F&P )<br />

32


Fourth Order Accuracy: O(∆x 4 )<br />

CENTRAL DIFFERENCES<br />

First Derivative<br />

∂f<br />

∂x = −f i+2 + 8f i+1 − 8f i−1 + f i−2<br />

12∆x<br />

+ O(∆x 4 ). (3.14 F&P )<br />

Second Derivative<br />

∂ 2 f<br />

∂x 2 = −f i+2 + 16f i+1 − 30f i + 16f i−1 − f i−2<br />

12∆x 2 + O(∆x 4 ).<br />

Third Derivative<br />

(3.32 F&P )<br />

∂ 3 f<br />

∂x 3 = −f i+3 + 8f i+2 − 13f i+1 + 13f i−1 − 8f i−2 + f i−3<br />

8∆x 3 + O(∆x 4 ).<br />

32


Finite Difference Method for Elliptic PDE<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 + ∂2 u<br />

∂y 2 = f(x, y). 33


Finite Difference Method for Elliptic PDE<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 + ∂2 u<br />

= f(x, y).<br />

∂y2 FDM: Using Central Differences with Second Order<br />

Accuracy<br />

∂ 2 u<br />

∂x 2 = u i+1 − 2u i + u i−1<br />

∆x 2 + O(∆x 2 ),<br />

∂ 2 u<br />

∂y 2 = u j+1 − 2u j + u j−1<br />

∆y 2 + O(∆y 2 ). (3.30 FP )<br />

33


Finite Difference Method for Elliptic PDE<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 + ∂2 u<br />

= f(x, y).<br />

∂y2 FDM: Using Central Differences with Second Order<br />

Accuracy<br />

∂ 2 u<br />

∂x 2 = u i+1 − 2u i + u i−1<br />

∆x 2 + O(∆x 2 ),<br />

∂ 2 u<br />

∂y 2 = u j+1 − 2u j + u j−1<br />

∆y 2 + O(∆y 2 ). (3.30 FP )<br />

Resulting Finite Difference Equation (FDE) is<br />

u i+1,j − 2u i,j + u i−1,j<br />

∆x 2<br />

+ u i,j+1 − 2u i,j + u i,j−1<br />

∆y 2 = f i,j .<br />

33


One-Dimensional FDM<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 = f(x). 34


One-Dimensional FDM<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 = f(x).<br />

Using Central Differences with Second Order Accuracy<br />

u i+1 − 2u i + u i−1<br />

∆x 2 = g i .<br />

34


One-Dimensional FDM<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 = f(x).<br />

Using Central Differences with Second Order Accuracy<br />

u i+1 − 2u i + u i−1<br />

∆x 2 = g i .<br />

Multiplying ∆x 2 & rearranging, FDE is<br />

u i−1 − 2u i + u i+1 = f i .<br />

where α = 1<br />

∆x 2 & f i = g i /α.<br />

34


One-Dimensional FDM<br />

Elliptic PDE: Laplace equation<br />

∂ 2 u<br />

∂x 2 = f(x).<br />

Using Central Differences with Second Order Accuracy<br />

u i+1 − 2u i + u i−1<br />

∆x 2 = g i .<br />

Multiplying ∆x 2 & rearranging, FDE is<br />

u i−1 − 2u i + u i+1 = f i .<br />

where α = 1<br />

∆x 2 & f i = g i /α.<br />

34


One-Dimensional FDM<br />

∂ 2 u<br />

∂x 2 = f(x).<br />

Divide the computational<br />

domain into NX steps<br />

(control volumes).<br />

∆x<br />

1 2 i i+1 NX NX+1<br />

u i−1 − 2u i + u i+1 = f i .<br />

35


One-Dimensional FDM<br />

∂ 2 u<br />

∂x 2 = f(x).<br />

Divide the computational<br />

domain into NX steps<br />

(control volumes).<br />

Apply the FDE to the<br />

interior points<br />

∆x<br />

1 2 i i+1 NX NX+1<br />

x 2 , x 3 , . . . , x i , . . . , x NX .<br />

x 1 & x NX+1 are<br />

boundary points.<br />

u i−1 − 2u i + u i+1 = f i .<br />

35


One-Dimensional FDM<br />

∂ 2 u<br />

∂x 2 = f(x).<br />

Divide the computational<br />

domain into NX steps<br />

(control volumes).<br />

Apply the FDE to the<br />

interior points<br />

∆x<br />

1 2 i i+1 NX NX+1<br />

x 2 , x 3 , . . . , x i , . . . , x NX .<br />

x 1 & x NX+1 are<br />

boundary points.<br />

Domain size L = 1 &<br />

∆x = 0.2<br />

u i−1 − 2u i + u i+1 = f i .<br />

x 1 , x 2 , x 3 , x 4 , x 5 , x 6 .<br />

x 1 & x 6 are boundary.<br />

35


3.8 Algebraic Equation System<br />

u 1 − 2u 2 + u 3 = f 2<br />

u 2 − 2u 3 + u 4 = f 3 ,<br />

.<br />

u i−1 − 2u i + u i+1 = f i ,<br />

.<br />

u NX−2 − 2u NX−1 + u NX = f NX−1 ,<br />

u NX−1 − 2u NX + u NX+1 = f NX .<br />

Here, NX is the number <strong>of</strong> ∆x and we have NX −1 number<br />

<strong>of</strong> equations for u 2 , u 3 , u 4 , . . . u i , . . . , u NX−2 , u NX−1 , u NX .<br />

u 1 and u NX+1 are boundary values.<br />

36


3.8 - Linear Algebraic Equation<br />

Finite Difference Equations, (FDE) are<br />

u i−1 − 2u i + u i+1 = f i .<br />

37


3.8 - Linear Algebraic Equation<br />

Finite Difference Equations, (FDE) are<br />

u i−1 − 2u i + u i+1 = f i .<br />

The result <strong>of</strong> discretisation is a system <strong>of</strong> linear algebraic<br />

equations:<br />

A P φ P + ∑ l<br />

A l φ l = Q P , (3.42 F&P )<br />

P denotes the node at which the FDE is approximated,<br />

Index l runs over the neighbour nodes involved in FDA.<br />

37


3.8 - Matrix Equations for 1D FDM<br />

The result <strong>of</strong> discretisation is a system <strong>of</strong> linear algebraic<br />

equations:<br />

⎛<br />

⎞⎛<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

⎜<br />

⎝ 1 −2 1 ⎟⎜<br />

⎠⎝<br />

1 −2<br />

u 2<br />

u 3<br />

u i<br />

u NX−1<br />

u NX<br />

⎞ ⎛<br />

⎞<br />

f 2 − u 1<br />

f 3<br />

=<br />

f i<br />

.<br />

⎟ ⎜<br />

⎠ ⎝ f NX−1<br />

⎟<br />

⎠<br />

f NX − u NX+1<br />

38


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

39


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2<br />

⎞<br />

,<br />

⎟<br />

⎠<br />

39


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2<br />

⎞<br />

,Q =<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

⎞<br />

f 2 − u 1<br />

f 3<br />

f i<br />

,<br />

f NX−1<br />

⎟<br />

⎠<br />

f NX − u NX+1<br />

39


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2<br />

⎞<br />

,Q =<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

⎞<br />

f 2 − u 1<br />

f 3<br />

f i<br />

,<br />

f NX−1<br />

⎟<br />

⎠<br />

f NX − u NX+1<br />

and φ = (u 2 , u 3 , . . . , u i , . . . u NX−1 , u NX ) T .<br />

39


1-D Navier-Stokes Equation<br />

Elliptic PDE: Laplace equation<br />

1<br />

Re<br />

∂ 2 u<br />

∂y 2 = dp<br />

dx . 40


1-D Navier-Stokes Equation<br />

Elliptic PDE: Laplace equation<br />

1<br />

Re<br />

∂ 2 u<br />

∂y 2 = dp<br />

dx .<br />

Using Central Differences with Second Order Accuracy<br />

1<br />

Re<br />

u j+1 − 2u j + u j−1<br />

∆y 2<br />

= dp<br />

dx . 40


1-D Navier-Stokes Equation<br />

Elliptic PDE: Laplace equation<br />

1<br />

Re<br />

∂ 2 u<br />

∂y 2 = dp<br />

dx .<br />

Using Central Differences with Second Order Accuracy<br />

1<br />

Re<br />

u j+1 − 2u j + u j−1<br />

∆y 2<br />

= dp<br />

dx .<br />

Multiplying Re∆y 2 & rearranging, FDE is<br />

u j−1 − 2u j + u j+1 = dp<br />

dx Re/α.<br />

where α = 1<br />

∆y 2 . 40


One-Dimensional FDM<br />

1<br />

Re<br />

∂ 2 u<br />

∂y 2 = dp<br />

dx .<br />

Divide the computational<br />

domain into NX steps<br />

(control volumes).<br />

∆x<br />

1 2 i i+1 NX NX+1<br />

u j−1 − 2u j + u j+1 = dp<br />

dx Re/α.<br />

41


One-Dimensional FDM<br />

1<br />

Re<br />

∂ 2 u<br />

∂y 2 = dp<br />

dx .<br />

Divide the computational<br />

domain into NX steps<br />

(control volumes).<br />

Apply the FDE to the<br />

interior points<br />

x 2 , x 3 , . . . , x i , . . . , x NX .<br />

∆x<br />

1 2 i i+1 NX NX+1<br />

x 1 & x NX+1 are<br />

boundary points.<br />

u j−1 − 2u j + u j+1 = dp<br />

dx Re/α.<br />

41


One-Dimensional FDM<br />

1<br />

Re<br />

∂ 2 u<br />

∂y 2 = dp<br />

dx .<br />

Divide the computational<br />

domain into NX steps<br />

(control volumes).<br />

Apply the FDE to the<br />

interior points<br />

x 2 , x 3 , . . . , x i , . . . , x NX .<br />

∆x<br />

1 2 i i+1 NX NX+1<br />

x 1 & x NX+1 are<br />

boundary points.<br />

Domain size L = 1.2 &<br />

∆x = 0.2<br />

u j−1 − 2u j + u j+1 = dp<br />

dx Re/α.<br />

x 1 , x 2 , x 3 , x 4 , x 5 , x 6 x 7 .<br />

x 1 & x 7 are boundary.<br />

41


3.8 Algebraic Equation System<br />

u 1 − 2u 2 + u 3 = f 2 /α,<br />

u 2 − 2u 3 + u 4 = f 3 /α,<br />

u 3 − 2u 4 + u 5 = f 4 /α,<br />

u 4 − 2u 5 + u 6 = f 5 /α,<br />

u 5 − 2u 6 + u 7 = f 6 /α.<br />

Here, NY = 6 is the number <strong>of</strong> ∆y = 0.2 and we have<br />

NY − 1 = 5 number <strong>of</strong> equations for u 2 , u 3 , u 4 , u 5 , u 6 .<br />

u 1 and u 7 are boundary values.<br />

f = Re<br />

α . 42


3.8 - Matrix Equations for 1D FDM<br />

The result <strong>of</strong> discretisation is a system <strong>of</strong> linear algebraic<br />

equations:<br />

⎛<br />

⎞⎛<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

⎜<br />

⎝ 1 −2 1 ⎟⎜<br />

⎠⎝<br />

1 −2<br />

⎞ ⎛<br />

u 2<br />

u 3<br />

u 4<br />

=<br />

u 5<br />

⎟ ⎜<br />

⎠ ⎝<br />

u 6<br />

⎞<br />

f2/α − u 1<br />

f3/α<br />

f 4 /α<br />

.<br />

f 5 /α ⎟<br />

⎠<br />

f 6 /α − u 7<br />

43


3.8 - Matrix Equations for 1D FDM<br />

The result <strong>of</strong> discretisation is a system <strong>of</strong> linear algebraic<br />

equations:<br />

⎛<br />

⎞⎛<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

⎜<br />

⎝ 1 −2 1 ⎟⎜<br />

⎠⎝<br />

1 −2<br />

⎞ ⎛<br />

u 2<br />

u 3<br />

u 4<br />

=<br />

u 5<br />

⎟ ⎜<br />

⎠ ⎝<br />

u 6<br />

⎞<br />

f2/α − u 1<br />

f3/α<br />

f 4 /α<br />

.<br />

f 5 /α ⎟<br />

⎠<br />

f 6 /α − u 7<br />

At walls, due to no-slip boundary condition, u 1 = 0 & u 7 = 0.<br />

43


Tri-Diagonal Matrix<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

AX = B<br />

⎞<br />

b 1 c 1<br />

a 2 b 2 c 2<br />

a 3 b 3 c 3<br />

,B =<br />

a NX−1 b NX−1 c NX−1<br />

⎟<br />

⎠<br />

a NX b NX<br />

⎛<br />

⎜<br />

⎝<br />

f 1<br />

f 2<br />

f 3<br />

f NX−1<br />

f NX<br />

⎞<br />

,<br />

⎟<br />

⎠<br />

X = (u 1 , u 2 , u 3 , u NX−1 , u NX ) T .<br />

44


TDMA: Thomas Algorithm<br />

An upper triangular form <strong>of</strong> the tridiagonal matrix may be<br />

obtained by computing the new b i by<br />

b i = b i −<br />

and the new f i by<br />

f i = f i −<br />

a i<br />

b i−1<br />

c i−1 ,<br />

a i<br />

b i−1<br />

f i−1 ,<br />

i = 2,3, . . . , NX,<br />

i = 2,3, . . . , NX,<br />

then computing the unknowns from back substitution according<br />

to u NX = f NX /b NX and then<br />

u k = f k − c k u k+1<br />

b k<br />

, k = NX − 1, NX − 2, . . . ,2,1.<br />

45


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

46


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2<br />

⎞<br />

,<br />

⎟<br />

⎠<br />

46


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2<br />

⎞<br />

,Q =<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

⎞<br />

f2/α − u 1<br />

f3/α<br />

f4/α<br />

,<br />

f5/α ⎟<br />

⎠<br />

f6/α − u 7<br />

46


3.8 - Matrix Equations - Cont’d<br />

Algebraic Equation:<br />

Aφ = Q. (3.43 F&P )<br />

A =<br />

⎛<br />

⎜<br />

⎝<br />

−2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2 1<br />

1 −2<br />

⎞<br />

,Q =<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

⎞<br />

f2/α − u 1<br />

f3/α<br />

f4/α<br />

,<br />

f5/α ⎟<br />

⎠<br />

f6/α − u 7<br />

and φ = (u 2 , u 3 , u 4 , u 5 , u 6 ) T .<br />

46


Solution to 1D Matrix Equations<br />

Direct solver using Gauss elimination.<br />

47


Solution to 1D Matrix Equations<br />

Direct solver using Gauss elimination.<br />

Tri-Diagonal Matrix Algorithm.<br />

47


Solution to 1D Matrix Equations<br />

Direct solver using Gauss elimination.<br />

Tri-Diagonal Matrix Algorithm.<br />

More details on Martix Computation (Ch. 5)<br />

47


Example <strong>of</strong> First-Order ODE<br />

Heat Tranfer for Conduction:<br />

d 2 T<br />

dx 2 + h′ (T a − T) = 0<br />

Computational domain: 0 ≤ x ≤ 10.<br />

T 1 = 40, T NX = 200, T a = 20 & h ′ = 0.01.<br />

48


Example <strong>of</strong> First-Order ODE<br />

Heat Tranfer for Conduction:<br />

d 2 T<br />

dx 2 + h′ (T a − T) = 0<br />

Computational domain: 0 ≤ x ≤ 10.<br />

T 1 = 40, T NX = 200, T a = 20 & h ′ = 0.01.<br />

Using the second-order central difference<br />

T i+1 − 2T i + T i−1<br />

∆x 2 − h ′ T i = −h ′ T a ,<br />

( )<br />

1 2<br />

∆x 2T i−1 −<br />

∆x 2 + h′ T i + 1<br />

∆x 2u i+1 = −h ′ T a .<br />

48


3.11 Example<br />

The generic transport equation is.<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(<br />

Γ ∂φ<br />

∂x j<br />

)<br />

+ q φ . (3.1 F&P )<br />

49


3.11 Example<br />

The generic transport equation is.<br />

∂ρu j φ<br />

∂x j<br />

= ∂<br />

∂x j<br />

(<br />

Γ ∂φ<br />

∂x j<br />

)<br />

+ q φ . (3.1 F&P )<br />

A one-dimensional generic transport equation is.<br />

∂ρuφ<br />

∂x = ∂ (<br />

Γ ∂φ )<br />

. (3.1 F&P )<br />

∂x ∂x<br />

With the boundary conditions: φ = φ 0 at x = 0, φ = φ L at<br />

x = L.<br />

The density ρ and the velocity u are assumed constant.<br />

49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!