Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
33 views13 pages

CFD EM C4 FiniteDifferenceMethod

This document provides lecture notes on computational fluid dynamics and finite difference methods. It contains 7 chapters that will cover topics such as basic concepts in fluid dynamics, the finite difference method, the finite volume method, solving CFD problems with software, and applying CFD in engineering applications. Chapter 4 focuses on the finite difference method, discussing how to derive finite difference equations through Taylor series expansions and the approximations that can be obtained for first and second derivatives.

Uploaded by

Minh Trực
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views13 pages

CFD EM C4 FiniteDifferenceMethod

This document provides lecture notes on computational fluid dynamics and finite difference methods. It contains 7 chapters that will cover topics such as basic concepts in fluid dynamics, the finite difference method, the finite volume method, solving CFD problems with software, and applying CFD in engineering applications. Chapter 4 focuses on the finite difference method, discussing how to derive finite difference equations through Taylor series expansions and the approximations that can be obtained for first and second derivatives.

Uploaded by

Minh Trực
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

TS.

Nguyễn Thanh Nhã 1/21/2024

Lecture note

COMPUTATIONAL FLUID DYNAMICS - CFD


TÍNH TOÁN ĐỘNG LỰC HỌC LƯU CHẤT

Dr. Nguyễn Thanh Nhã


Department of Engineering Mechanics – Faculty of Applied Science – 106B4
Phone: Office: (84.28) 38 647 256 – Ext: 5306; 0908.568181
Site: https://orcid.org/0000-0001-9733-5189; https://cadfea.com.vn/
Email: [email protected]
FB: Nguyễn Thanh Nhã

Ho Chi Minh city, 2020 2020

CONTENTS

Chapter 1. Introduction to Fluid Mechanics

Chapter 2. Basic concepts in Fluid Dynamics

Chapter 3. Fundamental of Fluid Dynamics

Chapter 4. Finite Difference Method

Chapter 5. Finite Volume Method

Chapter 6. Solve CFD problems with ANSYS/CFX

Chapter 7. Turbulence

Chapter 8. Apply CFD in engineering

2020

[email protected] 1
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4.
Finite Difference Method
4.1. Derivation of finite diference equation

4.2. Solutions of finite diference equations

2020

Chapter 4. Finite Difference Method

4.1. Derivation of finite diference equation

2020

[email protected] 2
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.1. Derivation of finite diference equation
Introduction
• This is the oldest method for numerical solution of PDE's, believed to
have been introduced by Euler in the 18th century.
• It is also the easiest method to use for simple geometries, however, very
difficult to apply to problems with complex geometries
• Basic idea:
• derivatives in differential equations are written in terms of discreted
quantities of dependent and independent variables.
• finally, algebraic equations with all unknowns prescribed at discrete
mesh points for the entire domain.
• In principle, the FD method can be applied to any grid type. However, in
all applications it has been applied to structured grids. The grid lines
serve as local coordinate lines

• Taylor series expansion or polynomial fitting is used to obtain


approximations to the first and second derivatives of the variables with
respect to the coordinates
2020

Chapter 4. Finite Difference Method

2020

[email protected] 3
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.1. Derivation of finite diference equation
Simple method
• Consider a function u(x) and its derivative at point x

u ( x ) u ( x  x )  u ( x )
 lim
x x  0 x
• Expand u(x+∆x) in Taylor series about u(x)
u ( x )  x   2u( x )  x   3u( x )
2 3

u ( x   x )  u ( x )  x    ...
x 2 x 2 3! x 3
u ( x  x )  u ( x ) u( x ) x  2u ( x ) u( x )
    ...   O ( x )
x x 2 x 2
x
First order in ∆x
u ( x )  u ( x ) x  2u( x ) 
  lim    ... 
x  x  0
 x 2 x 2

First order accuracy
2020

Chapter 4. Finite Difference Method


4.1. Derivation of finite diference equation
Simple method Write u(x) in Taylor series at i+1 and i-1

 u  x   u  x   u  x   u 
2 2 3 3 4 4
ui 1  ui  x             ...
 x i 2  x 2 i 3!  x 3 i 4!  x 4 i

 u   x   u   x   u   x   u 
2 2 3 3 4 4
ui 1  ui  x       ...
 x  i 2  x 2 i 3!  x 3 i 4!  x 4 i
• Forward difference: • Central difference:

 u  ui 1  ui  u  ui 1  ui 1
    O ( x )     O ( x 2 )
 x i x  x i 2 x
• Backward difference: • Second derivative:

 u  ui  ui 1   2u  ui 1  2ui  ui 1
    O ( x )  2   O ( x 2 )
 x i x  x i  x 2

First order accuracy Second order accuracy


2020

[email protected] 4
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.1. Derivation of finite diference equation
General methods
• In general, finite difference equations may be generated for any order
derivative with any number of points involved (any order accuracy)
• Consider a first derivative associated with three points:

 u  aui  bui 1  cui 2


  
 x i x
• The coefficients a, b, c may be determined from a Taylor series
expansion of upstream nodes ui-1 and ui-2 about ui

 u   x    u   x    u 
2 2 3 3

ui 1  ui   x           ...
 x i 2  x 2 i 3!  x 3 i

 u   2 x    u   2 x    u 
2 2 3 3

ui 2  ui   2 x      2     ...
 x i 2  x i 3!  x 3 i

2020

Chapter 4. Finite Difference Method


4.1. Derivation of finite diference equation
General methods
• Backward difference

 u  3ui  4ui 1  ui 2   2u  ui  2ui 1  ui 2


    O  x 2   x 2    O  x 
 x  i 2 x  i x 2

• Forward difference
 u  3ui  4ui 1  ui  2   2u  ui  2ui 1  ui  2
 O  x 2   x 2    O  x 
    i x 2

 i
x 2  x

• Central difference
 u  ui  2  8ui 1  8ui 1  ui 2   2u  ui 1  2ui  ui 1
    O  x 4   2   O  x 2 

 i
x 12  x  x i  x 2

2020

10

[email protected] 5
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.1. Derivation of finite diference equation
Multidimensional finite difference formulas
• Can be derived using the results of 1D formulas
xi  x0  i x
yi  y 0  i  y
• The forward and backward operators are given by  x and  y
• The first partial derivatives in x-dir and y-dir are
 u  1  u u
    x uij  O ( x )  i 1, j i , j  O ( x )
 x ij x x
 u  1  ui , j 1  ui , j
 y   y  y uij  O ( y )  y
 O ( y )
 ij
• The second order derivatives with central difference formulas
  2u  ui 1, j  2ui , j  ui 1, j   2u  ui , j 1  2ui , j  ui , j 1
 x 2    2
 O ( x 2 )  y 2    2
 O ( y 2 )
 ij x  ij y
2020

11

Chapter 4. Finite Difference Method

4.2. Solutions of finite diference equations

2020

12

[email protected] 6
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 1: 1D First-order Linear Convection - The Wave Equation
1D linear convection equation, the most basic model that can be used to learn
something about CFD, is described as
u u u : velocity field
c 0
t x c : wave speed
With given initial conditions: u ( x, 0)  u0 ( x )
The equation represents the propagation of that initial wave with speed c

The exact solution of the equation is u ( x, t )  u0  ( x  ct )

Parameters:
• spatial domain: 0 x3
• initial conditions: u0  2 at 0.5  x  1; u0  1 at other place
• wave speed: c 1
2020

13

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 1: 1D First-order Linear Convection - The Wave Equation
Solution:
Consider discretizing the spatial coordinate x into points that indexed from i = 1 to N
and stepping in discrete time intervals of size ∆t

Forward difference in time Backward difference in space


n 1
u u  u n
u uin  uin1
 i i

t t x x
 n: index of grid in t  i: index of grid in x

Discrete equation

uin 1  uin uin  uin1 t n


t
c
x
0  uin 1  uin  c
x
 ui  uin1 

2020

14

[email protected] 7
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 1: 1D First-order Linear Convection - The Wave Equation
Matlab code: %% Start
clear; close all;
%% Parameters
L = 3; % domain length
nx = 41; % number of point in x-direction
dx = L/(nx-1); % deltaX
tt = 1; % total time
nt = 30; % number of time point
dt = tt/(nt-1); % deltaT
c = 1; % wave speed

%% Initial condition
u = ones(1,nx);
u(ceil(.5 / dx):ceil(1 / dx + 1)) = 2;

figure
hold on
plot(linspace(0,L,nx),u);

%% Loop on time and space


un = ones(1,nx);
for n = 1:nt
un = u; % copy current u to un
for i = 2:nx
u(i) = un(i) - c*dt/dx*(un(i) - un(i-1));
end
plot(linspace(0,L,nx),u,'r');
end

2020

15

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 1: 1D First-order Linear Convection - The Wave Equation
Results

2020

16

[email protected] 8
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 2: 1D First-order Non-Linear Convection
- The Inviscid Burgers’ Equation

1D non-linear convection equation is described as


u u u : velocity field
u 0
t x
With given initial conditions: u ( x, 0)  u0 ( x )

Parameters:
• spatial domain: 0 x3
• initial conditions: u0  2 at 0.5  x  1; u0  1 at other place
• wave speed: c 1

Homework
2020

17

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 2: 1D First-order Non-Linear Convection
- The Inviscid Burgers’ Equation
Solution:
Consider discretizing the spatial coordinate x into points that indexed from i = 1 to N
and stepping in discrete time intervals of size ∆t

Forward difference in time Backward difference in space


n 1
u u  u n
u uin  uin1
 i i

t t x x
 n: index of grid in t  i: index of grid in x

Discrete equation

uin 1  uin u n  uin1 t n


t
 uin i
x
0  uin 1  uin  uin
x
 ui  uin1 

2020

18

[email protected] 9
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 2: 1D First-order Non-Linear Convection
- The Inviscid Burgers’ Equation
Results:

2020

19

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 3: 2D Linear First-order Convection
The PDE governing 2-D Linear Convection is written as

u u u
c c 0
t x y
What is the final velocity profile for 2D linear convection when the initial conditions
are a square wave and the boundary conditions are unity?

Parameters:
• spatial domain: 0 x2 0 y2
2 0.5  x, y  1
• initial conditions: u0 ( x, y )  
1 everywhere else
• boundary conditions: u  1 for x  0, x  1, y  0, y  2

• wave speed: c 1 Homework


2020

20

[email protected] 10
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 3: 2D Linear First-order Convection
Solution:
• Use i as index for x values and j index for y values

• The discretization of the PDE should be relatively straightforward

uin, j 1  uin, j uin, j  uin1, j uin, j  uin, j 1


c c 0
t x y
t n t n
 uin, j 1  uin, j  c
x
 ui , j  uin1, j   c
y
 ui , j  uin, j 1 

Homework
2020

21

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 3: 2D Linear First-order Convection
Solution:

2020

22

[email protected] 11
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 4: 2D non-Linear First-order Convection
The PDE governing 2-D non-Linear Convection is written as

u u u v v v
u v 0 u v 0
t x y t x y
What is the final velocity profile for 2D non-linear convection when the initial
conditions are a square wave and the boundary conditions are unity?

Parameters:
• spatial domain: 0 x2 0 y2
2 0.5  x, y  1
• initial conditions: u0 ( x, y )  
1 everywhere else
• boundary conditions: u  1 for x  0, x  1, y  0, y  2

Homework
2020

23

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 4: 2D non-Linear First-order Convection
Solution:
• Use i as index for x values and j index for y values

• The discretization of the PDE should be relatively straightforward

uin, j 1  uin, j uin, j  uin1, j uin, j  uin, j 1


 uin, j  vin, j 0
t x y
 uin, j n vin, j n 
n 1
 u  u  t 
i, j
n
i, j  ui , j  ui 1, j  
n
 ui , j  uin, j 1 
 x y 
n 1
vi , j  ui , j
n
v v
n n
v v
n n

 uin, j i , j i 1, j  vin, j i , j i , j 1  0


t x y
 uin, j n vin, j n 
v n 1
i, j  v  t 
n
i, j  vi , j  vi 1, j  
n
 vi , j  vin, j 1 
 x y 
2020

24

[email protected] 12
TS. Nguyễn Thanh Nhã 1/21/2024

Chapter 4. Finite Difference Method


4.2. Solutions of finite diference equations
Example 4: 2D non-Linear First-order Convection
Solution:

2020

25

[email protected] 13

You might also like