0% found this document useful (0 votes)
10 views

Chapter 02 - Finite Different Method

The document discusses finite difference methods (FDM) for numerically solving differential equations. It introduces FDM, describing how it approximates derivatives using finite differences to convert differential equations into linear algebraic equations. It then covers different types of difference schemes, including forward, backward, and central differences for approximating first and second derivatives. It also discusses explicit and implicit FDMs. The document provides examples of applying these concepts to estimate derivatives and illustrates how FDM can be used to solve partial differential equations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Chapter 02 - Finite Different Method

The document discusses finite difference methods (FDM) for numerically solving differential equations. It introduces FDM, describing how it approximates derivatives using finite differences to convert differential equations into linear algebraic equations. It then covers different types of difference schemes, including forward, backward, and central differences for approximating first and second derivatives. It also discusses explicit and implicit FDMs. The document provides examples of applying these concepts to estimate derivatives and illustrates how FDM can be used to solve partial differential equations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Programming in applied fluids

Chapter 2

Finite Different Methods (FDM)

Dr. Ngo Ich Long


School of Transportation Engineering
Hanoi University of Science and Technology (HUST)
27-Oct-23 1
Contents
Chapter 02: Finite Different Methods

2.1. Approximation in FDM


2.2. Finite different method
2.3. Difference schemes
2.4. Applying FDM for 1D convection equation

27-Oct-23 2
2.1. Approximation in FDM
* Practice in MATLAB: Roots of a Quadratic

27-Oct-23 3
2.1. Approximation in FDM
* Practice in MATLAB: Roots of a Quadratic

27-Oct-23 4
2.1. Approximation in FDM
* Practice in MATLAB: Roots of a Quadratic

27-Oct-23 5
2.1. Approximation in FDM
* Practice in MATLAB: the parachutist problem

Practice-01:

27-Oct-23 6
2.1. Approximation in FDM
* Practice in MATLAB: the parachutist problem

Practice-02: Using M-file → analpara.m

27-Oct-23 7
2.1. Approximation in FDM
* Practice in MATLAB: the parachutist problem

Practice-03: Using M-file → analpara2.m

27-Oct-23 8
2.1. Approximation in FDM
* Practice in MATLAB: the parachutist problem

Practice-04:

27-Oct-23 9
2.1. Approximation in FDM
* Practice in MATLAB: the parachutist problem

Practice-04: Using M-file → numpara.m

27-Oct-23 10
2.1. Approximation in FDM
* Taylor series
+ In essence, the Taylor series provides a means to predict a function value at one
point in terms of the function value and its derivatives at another point.
+ In particular, the theorem states that any smooth function can be approximated as a
polynomial.

Zero-order approximation
First-order approximation

Second-order approximation
………………………..

Taylor series expansion

27-Oct-23 11
2.1. Approximation in FDM
* Remainder in Taylor series

+ Remainder term:

+ It is often convenient to simplify Taylor series with h=xi+1 – xi

or

27-Oct-23 Graphical depiction of a zero-order Taylor series 12


prediction and remainder.
2.1. Approximation in FDM
* An example for Taylor series

Exact estimate
27-Oct-23 13
2.1. Approximation in FDM
* The Effect of Nonlinearity and Step Size on the Taylor Series Approximation

Solution:

Effect of step size h:

27-Oct-23 14
2.2. Finite different method
* Introduction
+ In numerical analysis, finite-difference methods (FDM) are a class of numerical
techniques for solving differential equations by approximating derivatives with
finite differences.
+ FDM converts ordinary differential equations (ODE) or partial differential
equations (PDE), which may be nonlinear, into a system of linear equations that
can be solved by matrix algebra techniques.
+ Today, FDM are one of the most common
approaches to the numerical solution of
PDE, along with others like FEM, FVM,…

27-Oct-23
A practical example of Burger equation 15
2.2. Finite different method
* Introduction

27-Oct-23 16
2.2. Finite different method
* Basic idea in FDM

27-Oct-23 17
2.3. Difference schemes
* Let’s start with forward difference scheme

Based on Taylor series expansion, we have


f ( xi +1 ) = f ( xi ) + f ' ( xi )( xi +1 − xi ) + Rn
Neglecting truncation Rn , we have

f ( xi +1 ) = f ( xi ) + f ' ( xi )( xi +1 − xi )
f ( xi +1 ) − f ( xi ) fi
f ' ( xi ) = =
xi +1 − xi h

Note: It is termed a “forward” difference


because it utilizes data at i and i + 1 to
estimate the derivative.

27-Oct-23 18
2.3. Difference schemes
* Three schemes of first-order difference approximation
Forward difference Downwind scheme
f ( xi +1 ) − f ( xi )
method
fi
f ' ( xi ) = =
xi +1 − xi h

Backward difference Upwind scheme


method
f ( xi ) − f ( xi −1 ) fi
f ' ( xi ) = =
xi − xi −1 h

Center difference Center-scheme


f ( xi +1 ) − f ( xi −1 ) f ( xi +1 ) − f ( xi −1 )
method
f ' ( xi ) = =
xi +1 − xi −1 2h

All the above versions can also be developed for second,


third, and higher derivatives. 19
27-Oct-23
2.3. Difference schemes
* Second-order difference schemes
Forward difference Downwind scheme
method
f ( xi + 2 ) − f ( xi +1 ) f ( xi +1 ) − f ( xi )
− f ( xi + 2 ) − 2 f ( xi +1 ) + f ( xi )
f "( xi ) = h h =
h h2
Backward difference Upwind scheme
method
f ( xi ) − f ( xi −1 ) f ( xi −1 ) − f ( xi − 2 )
− f ( xi ) − 2 f ( xi −1 ) + f ( xi − 2 )
f " ( xi ) = h h =
h h2

Center difference Center-scheme


method
f ( xi +1 ) − f ( xi ) f ( xi ) − f ( xi −1 )
− f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
f "( xi ) = h h =
h h2

All the above versions can also be developed for second,


third, and higher derivatives. 20
27-Oct-23
2.3. Difference schemes
* Three schemes of difference approximation

Forward difference Backward difference Center difference

The Taylor series analysis yields the practical information


that the centered difference is a more accurate
representation of the derivative.

27-Oct-23 21
2.3. Difference schemes
* An example

Estimate first derivative of function at x=0.5 using h=0.5 and 0.25


Solution:

For both step sizes, the centered difference approximation


is more accurate than forward or backward differences. 22
27-Oct-23
2.3. Difference schemes
* For two-dimensional problem

By using these approximations to replace partial derivatives, the PDEs are


converted into difference equations and the resultant system of algebraic
27-Oct-23 equations are solved using any direct or iterative methods. 23
2.3. Difference schemes
* Explicit and implicit methods

 u u − u l l  u uil++11 − uil +1
 x = x
i +1 i
 x = x
 2  2 l +1 l +1 l +1
 l
− l
+ l
  u u − 2u + u
 u
=
ui +1 2ui ui −1 = i +1 i i −1

 x 2 x 2  x 2 x 2
27-Oct-23 24
2.4. Applying FDM for 1D convection equation
* Theory
u u
+c =0 1D convection/advection equation, also called wave Eq.
t x
where u(x,t), x Є R, is scalar (wave) advected by a nonzero constant c during time t.
+ Sign of c characterizes the direction of wave propagation and magnitude of c show how
fast the wave propagates.
+ If initial value for equation is given as u0(x) = u(x,0), the exact solution of equation is:

u ( x, t ) = u0 ( x − ct )

27-Oct-23 25
2.4. Applying FDM for 1D convection equation
* Implementation

Computational domain with ghost nodes

+ For transient term, uin+1 − uin uin − uin−1


u uin+1 − uin +c =0
= t x
t t ct n
+ For convection term with
n +1
→ ui = ui − n

x
( ui − uin−1 )
backward difference ct
CFL = is called Courant/convection number
u uin − uin−1 x
=
x x Stability criteria: CFL <= 1
27-Oct-23 26
2.4. Applying FDM for 1D convection equation
* Solution in Matlab

N=50, ∆t=0.009
→ CFL = 0.45

N=110, ∆t=0.009
→ CFL = 0.99

27-Oct-23 27
2.4. Applying FDM for 1D convection equation

N=110, ∆t=0.01
→ CFL = 1.1

N=110, ∆t=0.009
→ CFL = 0.99

N=110, ∆t=0.003
→ CFL = 0.33

27-Oct-23 28
2.1. Approximation in FDM
* Basic Idea

27-Oct-23 30
2.1. Approximation in FDM
* A simple mathematical model

where F = net force acting on the body (N, or kg m/s2), m


= mass of the object (kg), and a = its acceleration (m/s2)

(1)

More advanced techniques must be applied to obtain an


exact or analytical solution.

27-Oct-23 31
2.1. Approximation in FDM
* A simple mathematical model

Substituting into Eq. (1) to give

Euler’s method
27-Oct-23 32

You might also like