Numerical Methods in Fluid Dynamics
Numerical Methods in Fluid Dynamics
1
Computational Fluid Dynamics
Obtain approximate solutions to complex problems by Numerical Method
1. Mathematical Model:
Set of PDEs or integro-differantial eqs. and the corresponding
boundary conditions.
2. Discretization Method:
Finite difference Method
Finite volume Method
Finite element Method
Spectral (element) methods
Boundary element
Absolute convergence: a a *
(tolerance)
aa *
Relative convergence:
a
Discretization methods (Finite Difference)
Each node has one unknown and need one algebraic equation,
which is a relation between the variable value at that node and
those at some of the neighboring nodes.
f 1 2 f 1 3 f 1 n f
f ( x x) f ( x) x 2
x
2
3
x ...
3
n
(x) n ...
x 2! x 3! x n! x
If the PDEs are totally replaced by a system of algebraic equations which can be solved
for the values of the flow-field variables at the discrete points only, then in this sense,
the original PDEs have been discretized.
f
f ( xi 1 ) f ( xi ) ( ) i ( xi 1 xi )
( xi 1 xi ) 2 2 f
( 2 )i
xi 1 xi 3 f
3
( 3 ) i ...
( xi 1 xi ) n n f
( n ) i ...
x 2! x 3! x n! x
f f ( xi 1 ) f ( xi ) f ( xi 1 ) f ( xi )
( )i ………. (a)
x xi 1 xi xi 1
where xi 1 xi 1 xi
(2) Backward difference:
Neglecting higher-order terms, we can get
f
f ( xi 1 ) f ( xi ) ( ) i ( xi xi 1 )
( xi xi 1 ) 2 2 f
( 2 )i
xi xi 1 3 f
3
( 3 ) i ... ( 1) n ( xi xi 1 )
n
n f
( n ) i ...
x 2! x 3! x n! x
f f ( xi ) f ( xi 1 ) f ( xi ) f ( xi 1 )
( )i (b)
x xi xi 1 xi ……………..
where xi xi xi 1
3) Central difference:
(a)-(b) and neglecting higher-order terms, we can get
f f ( xi 1 ) f ( xi 1 )
( )i
x xi 1 xi 1
Truncation error:
The higher-order term neglecting in Eqs. (a), (b), (c) constitute the
truncation error & can be written as
Forward: f f i 1 f i
( )i o(x)
x x
Backward: f fi fi 1
( )i o(x)
x x
f f i 1 f i 1
Central: ( )i o(x) 2
x 2x
Second derivatives:
* Central difference:
If xi xi 1 x , then (a)+(b) becomes
2 f f 2 fi fi 1 2
( 2 ) i i 1 o ( x )
x (x) 2
* Forward difference:
2 f f i 2 2 f i 1 f i
( 2 )i 2
o(x)
x (x)
* Backward difference:
2 f f 2 fi 1 fi 2
( 2 )i i 2
o(x)
x (x)
Mixed Derivatives:
* Taylor series expansion:
* Central difference:
2 f f f i 1, j 1 f i 1, j 1 f i 1, j 1
i 1, j 1 o[(x) 2 , (y ) 2 ]
xy i , j 4(x)(y )
2 f f f i , j 1 f i 1, j f i , j
* Forward difference: i 1, j 1 o[( x) , (y ) ]
xy i , j (x)( y )
2 f f f i 1, j f i , j 1 f i 1, j 1
i , j o[(x) , (y ) ]
* Backward difference: xy i, j ( x )( y )
EXPLICIT METHODS
u 2 u
t
y2
t
Δt
ui,j+1
Δy
ui+1,j+1
Present time
ui-1,j P ui+1,j
Previous time
ui,j
ui,j-1 y
y1 y2 yi ym FTCS
tn = nΔt (uniform time step)
L
2u
u
ui, j 1 ui, j t .... Forward-difference in time
t t 2 i, j 2
t
i, j
O(t )
2ui, j
2 u
2
= ui1, j u i1, j Second order central-difference in space
y y
i, j
2
2ui, j
ui, j 1 ui, j
=
ui1, j u i1, j (A) Difference equation
t
y
After rearragement
t 2
ui, j 1 =ui, j
i1, j
2ui, j i1, j (B)
y u
Difference u
equation (A) is just an approximation for original PDE due to truncation error.
2
Δt
Time-marching
Previous time direction
i-1,j i,j i+1,j
Properties at level (j+1) (present time) to be calculated from values at level j (previous
time) Remember that parabolic PDEs lend themselves to a marching solution, here
marching variable is time, t
Eq.(B) allows direct calculation of ui,j+1 from the known values on the RHS of eq.(B)
Explicit approach: each difference eq. contains only one unknown and therefore can
be solved explicitly for this unknown in a straight forward manner.
For a given (Δy), Δt must be less than some limit imposed by stability constraints
• Relatively simple to set up and program
IMPLICIT METHODS:
In implicit method information at the boundaries at the same level does not feed
into the computation.
i-1,j+1 i,j+1
i+1,j+1 Present time-unknown
xi Previous time-known
i,j
BTCS Method
In equation (1): 3 unknowns ui-1,j+1 , ui,j+1 , ui+1,j+1
Thus, it results in a set of coupled finite difference equations at all grid
points
Rearrange equation (1)
t
uj t u j1 j j
2 1
i1 1 2 ux 2 1
i1 ui
x xt2 i i
c d
i ai
bi
u 2
2 u2
u 2
Marching technique (1)
x
t y
u(t+Δt) will be obtained, in some fashion, from the known values of u(t)
where
t
bi c i t2
2 2 , ai 1
x
d un x t u n 2u n un
i i, j i, j i, j
i, j 1 1
2 y
Eq.(2’) yields a solution for ui, j
n1/ 2
for all i, keeping j fixed, via Thomas Algorithm
2
In Eq.(2’) first set j=1, and sweep in x (i=1,...,N) to find u i,n1/
j 2
1
n+1/2
y
(1,M) (i,j)=(N,M)
Δt/2
Sweep j+1
direction j
x
(i,j)=(1,1) (i,j)=(N,1)
n
At the end of step1 (after M sweeps), the values of u at the intermediate time (t+Δt/2)
n1/ 2
are known at all grid points: i.e. ui, j is known at all (i,j)
Step 2:
Take the solution to the time (t+Δt), using the known values at time (t+Δt/2)
Again replace spatial derivatives with central differences, but this time treat y
derivative implicitly
u n1 u n1/ 2
n1/ 2
i, j i, j
= u j
i1, 2u n1/
i, j 2 u n1/ 2
u i,n1
j 2u n1
i, j u n1
(3)
i1, j 1 i, j 1
t
x y
2 2
dj (3')
b u n1 a u n1 c u n1
j i, j 1 j i, j
j i, j 1
where
t t
bj c j , aj
2 2
2
2 x
1
x2 t
d j i,n j1/
2
ui1,
n1/2
j 2ui,n1/2
j
ui1,
n1/2
j
u
x 2
yields a solution for ui,n1 for all j, keeping i fixed, via Thomas Algorithm
j
j=1,....,M i=1
j=1,....,M
i=2
......... :
N times Thomas Algorithm
i=
N
t
Present time
n+1
y
(1,M) i i+1 (i,j)=(N,M)
Δt/2
Sweep direction
x
(i,j)=(1,1) (i,j)=(N,1)
n+1/2
Remarks:
• Involves only tridiagonal forms
• Alternating direction implicit
• Scheme is second-order accurate
•General class of scheme involving splitting of two or more directions in an implicit
solution of the governing flow equation to obtain tridiagonal forms
• Approximate factorization
•For 3-D, see the scheme in Computational Fluid Dynamics for Engineers Vol.1
Klaus A. Hoffmann & S.T. Chiang pg.90
Errors Involved in Numerical Solutions
The truncation error identifies the difference between the exact solution of a
differential equation and its finite difference solution without round-off error.
Error
Round off
error
Optimum
Truncation
error
Number of ste* ps
Explicit v/s implicit Finite Difference Schemes
However, the main drawback is that stable solutions are obtained only
when
𝜕2y/𝜕𝑥2 are evaluated (at least partially) at the new time step.
In implicit finite difference schemes, the spatial derivatives
Where.
f ( x) sin 2 x
at : x 0.2 f ( x) 0.9511
f
f x x f ( x) x
x
u t + 2 u2 t
u x, t t =u x, t t +O t
3
t
2 2! (1)
+
n1 u t + 2
u2 t (2)
uor interms of
t indicest +O t
Now 2!2 the model eq. 3
u n i consider
i
u u (3)
a
t x
u 2 2 u (4)
tu2 a tx
2
u a x t a x2
Substituting (3) & (4) into (2) produces
a u t + t 2
u
u n1
i i
22
2
a x2
x
un
Use central differencing of second order for the spatial derivatives
n un
n1
ui n
a ui1 i1 1 2 2
n
ui1 2u ni 2 u ni1
2x t + a t
i
u 2
x
O t , x
Lax-Wendroff method 2 2
Implicit Formulations
1. Euler’s BTCS method:
u n1
i u ni a i1n1 ui1n1
t 2x u
1 n1 n1 1 n1
Cui1 u i Cui1 uin
2 2
t, x TDMA
2
2. Crank-Nicolson method:
u n
u n1
i
u i n n1
a ui1 u n1
i1
u n
i12x i1
t 2 2x
O t , x TDMA
2 2
SOLUTION OF EULER’S EQUATIONS
Lax-Wendroff Technique
• Explicit
• Particularly suited to marching solutions: hyperbolic & parabolic eqs.
Example: Time-marching solution of an inviscid flow using unsteady Euler eqs.
For unsteady, 2-D inviscid flow eqs. (HYPERBOLIC IN TIME)
n n
if & i,n1j
2
are found can be calculated explicitly, from eq.(5)
t
t i, j
2
i, j
Analogous Taylor series for all other dependent variables can be written as follows:
2u t +...
n n
u (6)
u n1
t + t 2!
t i, j 2
i, j
un i, j 2
2 v2 t +...
n n
i, j v (7)
v n1
v t + t
n
2!
i, j
t i, j
i, j
i, j
2
e n1
e n
e
n
2 e
n t +... (8)
i, j t + t 2
i, j
t i, j
i, j
2!
2
Using spatial derivatives (second-order central dif.) from eq.(1)
n un i1,
n vi,n j 1 i,n j 1
n
u i 1, j n j
i1, j
n v ni, j 1 vi,n j i,n j 1
(9)
i,n j i 1, j
u ni, i, j
t j 2x 2x 2y 2y
i, j
In (9), all quantities on RHS are known.
n
Differentiate eq.(1) with respect to time 2 2
t ?
i, j
n 2 u u 2 u 2 v v 2 v
2 u v
2 xt
x t xt x t yt y t yt y t (10)
t
i, j
2 u
=?
x
t
Differentiate eq.(2) wrt x;
1 P
2u 2 u u 2 2u u (11)
u 2 2 x x
xt x x
v
v are1 expressed
In eq.(11) all terms on RHS P xy 2
as second-order, central dif. eqs. at time
level n:
y
n n
2u n un i1, j 2
n u i1, u i1, u
u u
2 i, j
i, j j i1, j j
2x
xt i, j
x
2
ni1, j ui1,
u u ui,n j 1 i1, vi1,
n n n n
u j 1 i1, j 1 i1, j
u ni, j v n j
v i,n j 1 1 1
2y
j
2x
4 x y
2P n P n
j i1, i1, j
n n
1 Pi1,
n i, j 1 n j
Pi1, P i1,
n
(12)
j
j 2 2
i, j
i1, j 2
n
i, j
x 2
x x
In eq.(12) all terms on RHS are known.
2
Continuing with the evaluation of eq.(10), a number for is found by
xt
differentiating eq.(1) wrt x & replacing all derivatives on RHS with second-
order central differences, similar to eq.(12).
2 v
differentiate eq.(3) wrt y
yt
2
differentiate eq.(1) wrt y
y
t
u v central difference; eqs.(2) & (3) , respectively.
t , t
Finally;
n
2 2 is calculated from eq.(10)
t
i, j
From eq.(5) i,n1j is known
ui,n1
j f un
i, j , , u n
i, j 1 i, j 1 , u
i1, j ,
n
i1, j
un un
Remarks on Lax-Wendroff
•second-order accuracy in both space & time
•Algebra is lengthy
n1
i
stable solution
ni 1
ebt cos(k x) iC sin(k
x)
m
m t
where C ax
the stability requirement is ebt 1
t
Ca 1 Courant number (CFL condition) (6)
x
important stability requirement for hyperbolic eqs.
Relaxation methods are used to solve the linear equations resulting from a
discretization of the differential equation, for example by finite differences
Iterative relaxation of solutions is commonly dubbed smoothing because
with certain equations, such as Laplace's equation, it resembles repeated
application of a local smoothing filter to the solution vector
Case Study: 1 Dimensional Unsteady State Conduction
Study the temperature distribution across the engine block
wall which is exposed to external heat source and its
outside temperature kept 900k Assumptions:
Solution • No heat generation inside the wall
(study domain).
• Initial condition: the temperature
at the beginning is 1
900k 900k • One dimensional conduction;
• An explicit approach will be
employed
Numerical problems
. Discretize the governing equation
T ( x ,t +dt ) - T ( x ,t ) ( T ( x- dx, t ) - 2 T ( x, t ) + T ( x+dx ,t ) )
=ᾳ
dt dx × d 𝑥
Note dx is spatial step in the domain and dt is time step of the simulation.
Recall the spatial index i, which runs upto N (i.e. the total number of division), then
if the total thickness of the wall is W, then dx = W/N. Similarly, for the time
marching let j be the index which runs upto M(the total number of times the
equation will be solved for each node), if the simulation time considered is T, then
dt=T/M
Numerical problems
Therefore, the nodal temperature at time t+dt (j+1), at node
i is given by;
T ( i , j+ 1 )=T (i , j) + C( T ( i- 1 , j) − 2 T ( i , j ) + T ( i + 1 ,j ))
Where: , i=1:N; j=1:M
This equation will be written for each node in the study domain
Node 1:
Node 2:
…
Node N:
Numerical problems
MATLAB Program for FDM
and i =N/11
else
phi(i) = phi(i)+r*(phi(i+1)-2*phi(i)+phi(i-1)); % For the internal gird
points
end
end % ending the calculation
phi0 = phi;
plot(x,phi0)
xlabel('node location')
ylabel ('temp')
shg
pause(0.05)
end
Shock Wave Discontinuities
Shock waves are mathematically treated as discontinuities, but it was
quickly recognized this would cause problems for any numerical solution.
Artificial Viscosity
The proper formulation and magnitude needed for an artificial viscosity has
undergone many refinements over the years and includes tests to apply this
viscosity only in regions undergoing strong compression and with
magnitudes that are various functions of the first and/or second power of the
compression rate.
Numerical viscosity arises from discrete approximations to the
momentum advection terms in Eulerian equations, or from re-zoning operations
used in Lagrangian formulations.
Numerical Approximations
The difficulty in developing such schemes is that some smoothing must
always be incorporated into a numerical solution to keep it computationally
stable and to smooth out dispersion errors.
Dispersion errors are those errors that arise because components of a
solution having different grid resolution requirements may propagate through
the grid with slightly different speeds. Whenever this occurs, unphysical
oscillations develop in the solution where these components reinforce or cancel
one another.
The trick is to develop approximation schemes that remain accurate (i.e., have
a minimum of numerical smoothing)
and
at the same time are robust (i.e., have sufficient numerical smoothing to
compensate for dispersion errors and to remain computationally stable for a
wide range of applications).
Software and Resources
• CFD software was built upon physics, modeling, numerics.
• Two types of available software
– Commercial (e.g., FLUENT, CFX, Star-CCM, COMSOL)
– Research (e.g., CFDSHIP-IOWA, U2RANS)
• More information on CFD can be got on the following website:
– CFD Online: [Link]
– CFD software
• FLUENT: [Link]
• COMSOL [Link]
• CD-adapco: [Link]
– Grid generation software
• Gridgen: [Link]
• GridPro: [Link]
– Visualization software
• Tecplot: [Link]
• Fieldview: [Link]
?
Questions are Welcome
Thank You