IIHR—Hydroscience & Engineering
C. Maxwell Stanley Hydraulics Laboratory
The University of Iowa
ME:5160 Intermediate Mechanics of Fluids http://css.engineering.uiowa.edu/~me_160/
Sept. 21, 2015
1.
Introduction to Numerical Methods
2.
Components of Numerical Methods
2.1. Properties of Numerical Methods
2.2. Discretization Methods
2.3. Application of Numerical methods in PDE
2.4. Numerical Grid and Coordinates
2.5. Solution of Linear Equation System
2.6. Convergence Criteria
3.
Methods for Unsteady Problems
4.
Solution of Navier-Stokes Equations
5.
Example
2
Approaches to Fluid Dynamical Problems:
1. Simplifications of the governing equations AFD
2. Experiments on scale models EFD
3. Discretize governing equations and solve by computers CFD
CFD is the simulation of fluids engineering system using modeling and numerical methods
Possibilities and Limitations of Numerical Methods:
1. Coding level: quality assurance, programming defects, inappropriate algorithm, etc.
2. Simulation level : iterative error, truncation error, grid error, etc.
3
•
Consistence
1. The discretization should become exact as the grid spacing tends to zero
2. Truncation error : Difference between the discretized equation and the exact one
•
Stability : does not magnify the errors that appear in the course of numerical solution process.
1. Iterative methods: not diverge
2. Temporal problems: bounded solutions
3. Von Neumann’s method
4. Difficulty due to boundary conditions and non-linearities present.
•
Convergence : solution of the discretized equations tends to the exact solution of the differential equation as the grid spacing tends to zero.
4
•
Conservation
1. The numerical scheme should on both local and global basis respect the conservation laws.
2. Automatically satisfied for control volume method, either individual control volume or the whole domain.
3. Errors due to non-conservation are in most cases appreciable only on relatively coarse grids, but hard to estimate quantitatively
•
Boundedness :
1. Numerical solutions should lie within proper bounds (e.g. nonnegative density and TKE for turbulence; concentration between
0% and 100%, etc.)
2. Difficult to guarantee, especially for higher order schemes.
•
Realizability : models of phenomena which are too complex to treat directly (turbulence, combustion, or multiphase flow) should be designed to guarantee physically realistic solutions.
•
Accuracy : 1. Modeling error 2. Discretization errors 3. Iterative errors
5
•
Components of numerical methods
(Discretization Methods)
Finite Difference Method (focused in this lecture)
1. Introduced by Euler in the 18 th century.
2. Governing equations in differential form domain with grid replacing the partial derivatives by approximations in terms of node values of the functions one algebraic equation per grid node linear algebraic equation system.
3. Applied to structured grids
•
Finite Volume Method (not focused in this lecture)
1. Governing equations in integral form solution domain is subdivided into a finite number of contiguous control volumes conservation equation applied to each CV.
2. Computational node locates at the centroid of each CV.
3. Applied to any type of grids, especially complex geometries
4. Compared to FD, FV with methods higher than 2 nd order will be difficult, especially for 3D.
•
Finite Element Method (not covered in this lecture) :
1. Similar to FV
2. Equations are multiplied by a weight function before integrated over the entire domain.
6
Discretization methods (Finite Difference, introduction)
•
First step in obtaining a numerical solution is to discretize the geometric domain to define a numerical grid
•
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.
•
The approach is to replace each term of the PDE at the particular node by a finite-difference approximation.
•
Numbers of equations and unknowns must be equal
7
Discretization methods (Finite Difference, approximation of the first derivative)
•
Taylor Series Expansion : Any continuous differentiable function, in the vicinity of x series: i
, can be expressed as a Taylor
i x
x i
x
i
x
x i
2
2 !
2
x 2
i
x
x i
3
3 !
3
x 3
i
...
x
x i
n n !
n
x n
i
H
x i
i
1 x i
1
x i i
x i
1
2
x i
2
x
2
i
x i
1
6 x i
2
3
x
3
i
H
•
Higher order derivatives are unknown and can be dropped
•
1 when the distance between grid points is small.
By writing Taylor series at different nodes, x and x i+1
, we can have: i-1
, x i+1
, or both x i-
x i
i
1 x i
1
i
x i
Forward-FDS
(forward difference scheme)
x i
i x i
i
1
x i
1
Backward-BDS
x i
i
1 x i
1
i
1
x i
1
Central-CDS
1 st order, order of accuracy P kest
=1
2 nd order, order of accuracy P kest
•
Polynomial fitting : fit the function to an interpolation curve and differentiate the resulting curve.
Example : fitting a parabola to the data at points x x i+1
, and computing the first derivative at x
x i
i
1
i
2
i
1 x i
x i
1
x i
1
2
x i
i x i
x i
1
i
1 i-1
i
2
,x
i
, and
, we obtain:
x i
x i
x i
1
2 nd order truncation error on any grid. For uniform meshing, it reduced to the CDS approximation given in previous slide.
•
Compact schemes : Depending on the choice of parameters α,
β, and γ, 2 nd order and 4 th order CDS, 4 th order and 6 th order
Pade scheme are obtained.
x i
1
x i
x i
1
i
1
2
x
i
1
i
2
4
x
i
2
•
Non-Uniform Grids : to spread the error nearly uniformly over the domain, it will be necessary to use smaller x in regions where derivatives of the function are large and larger x where function is smooth
9
Discretization methods (Finite Difference, approximation of the second derivative)
•
Geometrically, the second derivative is the slope of the line tangent to the curve representing the first derivative.
2
x
2
i
x i
1 x i
1
x i
x i
Estimate the outer derivative by FDS, and estimate the inner derivatives using BDS, we get
2
x
2
i
i
1
x i
x i
1
x i
1
i
1 x i
x i
1 x i
x i
x i
1
i
x i
1
x i
1
For equidistant spacing of the points:
2
x
2
i
i
1
2
i
2
i
1
Higher-order approximations for the second derivative can be derived by including more data points, such as x i-2
, and x i+2
, even x i-3
, and x i+3
10
Discretization methods (Finite Volume)
•
FV methods uses the integral form of the conservation equation
•
FV defines the control volume boundaries while FD define the computational nodes
WW
NW
W nw w
N n ne e n e
NE
E
y
EE
P
•
Computational node located at the Control
Volume center
•
Global conservation automatically satisfied j y i x
SW sw
x s se
SE
Typical CV and the notation for Cartesian 2D
•
FV methods use the integral form of the conservation equation
S fdS
k
S k fdS
11
S
S
C
Application of numerical methods in PDE
•
Fluid Mechanics problems are governed by the laws of physics, which are formulated for unsteady flows as initial and boundary value problems (IBVP), which is defined by a continuous partial differential equation (PDE) operator L errors, T is the true or exact solution)
T
(no modeling or numerical
0
L
T
T
IC : T x , t
0
G
T x BC : T x
B
, t
H
T t
•
Analytical and CFD approaches formulate the IBVP by selection of the PDE, IC, and BC to model the physical phenomena
0
L
M
L
N
M
•
Using numerical methods, the continuous IBVP is reduced to a discrete IBVP (computer code) , and thus introduce numerical errors:
1
IC :
IC
M
: S
x , x t
, t
0
0
G
M g
N x
BC
BC
:
:
M
S
x x
B
B
,
, t
t
h
H
N
M
t
A1
A2
A3
•
Numerical errors can be defined and evaluated by transforming the discrete IBVP back to a continuous IBVP.
J
j
1 i
1
i !
j i i
x
S i j
L
Modified
N
1
L
M
j
J
1
j
N
BC
IC :
:
S
S
x
x
, t
B
, t
0
H
Modified
A4
G
Modified
Truncation error 12
Application of numerical methods in PDE
(Truncation and Discretization errors)
•
Subtracting equations A2 and A4 gives the IBVP that governs the simulation numerical error
L
M
IC
( S
:
SN
M
x ,
) t
L
M
0
SN
N
G
Modified x
1
G
M j
J
1
j
SN
S
M
A5
BC
( M
t
H
Modified
SM
•
An IBVP for the modeling error M-T can be obtained by subtracting A1 and A2:
L
M
:
SN
T x
B
)
,
L
M
M
H
M
L
M
IC :
BC
:
SM
x , t
0
G
M
G
T
BC
•
Adding A5 and A6
IC
L
M
:
:
SM
x
B
,
( S
x ,
T
)
S
t
L
M
H
M
S
G
Modified
H
T
N
G
T
M
S
x t
B
,
H
Modified
H
T
S
S
T
SN
A6
SM
13
•
The discrete locations at which the variables are to be calculated are defined by the numerical grid
•
Numerical grid is a discrete representation of the geometric domain on which the problem is to be solved. It divides the solution domain into a finite number of sub-domains
•
Type of numerical grids: 1. structured (regular grid), 2. Block-structured grids, and
3. Unstructured grids
•
Detailed explanations of numerical grids will be presented in the last lecture of this CFD lecture series.
•
Different coordinates have been covered in
“Introduction to CFD”
14
•
The result of the discretization using either FD or
FV, is a system of algebraic equations, which are linear or non-linear
A
Q
•
For non-linear case, the system must be solved using iterative methods, i.e. initial guess iterate converged results obtained.
•
The matrices derived from partial differential equations are always sparse with the non-zero elements of the matrices lie on a small number of well-defined diagonals
15
Solution of linear equation systems (direct methods)
•
Gauss Elimination : Basic methods for solving linear systems of algebraic equations but does not vectorize or parallelize well and is rarely used without modifications in CFD problems.
A
A
11
A
21
.
.
.
A n 1
A
12
A
22
A n
.
.
.
2
A
13
A
23
A n
.
.
.
3
.
.
.
.
.
.
.
.
.
.
.
.
A
1 n
A
2
.
.
.
A nn n
.
U
knowing the vector Q
A
11
0
.
.
.
0
A
A
12
A
22
.
.
.
0
A
13
A
23
.
.
.
0
.
.
.
.
.
.
.
.
.
.
.
.
A
1 n
A
2
.
.
.
A nn n
.
i
n
Q i
Q n
A nn k n
i
1
A ik
A ii
Algorithm (TDMA) P95
A i
W
i
1
A i
P
LU
i
A i
E
U
i
1
Y
Q i
LY
•
Tridiagonal Systems : Thomas Algorithm or Tridiagonal Matrix
•
LU Decomposition : the factorization can be performed without
Q k
A i
P
A i
P
A i
W
A
A i
P
1 i
E
1
Q i
*
Q i
A i
W
Q i
*
1
A i
P
1
i
Q i
*
A i
E
i
1
A i
P
16
Solution of linear equation systems
(iterative methods)
•
Why use iterative methods :
1. in CFD, the cost of direct methods is too high since the triangular factors of sparse matrices are not sparse.
2. Discretization error is larger than the accuracy of the computer arithmetic
•
Purpose of iteration methods : drive both the residual and iterative error to be zero
•
Rapid convergence of an iterative method is key to its effectiveness.
n n
A
Q A
n
Q
n
A
n n
n
Approximate solution after n iteration
n Iteration error
n residual
17
Solution of linear equation systems
(iterative methods, cont’d)
•
Typical iterative methods :
1. Jacobi method
2. Gauss-Seidel method
3. Successive Over-Relaxation (SOR), or LSOR
4. Alternative Direction Implicit (ADI) method
5. Conjugate Gradient Methods
6. Biconjugate Gradients and CGSTAB
7. Multigrid Methods
18
Solution of linear equation systems
(iterative methods, examples)
•
Jacobi method :
i k
1 i k
R i k
R i k
Q i
j n
1
A
k ij j
i
1 , 2 ,..., n
A ii
•
Gauss-Seidel method : similar to Jacobi method, but most recently computed values of all are used in all computations.
i i k
1 i k
R i k
A ii
R i k
Q i
i j
1
1
A ij j
1
•
Successive Overrelaxation (SOR): n
A
k ij j
i
1 , 2 ,..., n
i k
1 i k
R i k
A ii
R i k
Q i
i j
1
1
A ij j n
A
k ij j
i
1 , 2 ,..., n
19
Solution of linear equation systems
(coupled equations and their solutions)
•
Definition: Most problems in fluid dynamics require solution of coupled systems of equations, i.e. dominant variable of each equation occurs in some of the other equations
•
Solution approaches:
1. Simultaneous solution : all variables are solved for simultaneously
2. Sequential Solution : Each equation is solved for its dominant variable, treating the other variables as known, and iterating until the solution is obtained.
•
For sequential solution, inner iterations and outer iterations are necessary
20
Solution of linear equation systems (nonlinear equations and their solutions)
•
Definition:
Given the continuous nonlinear function f(x), find the value x= α, such that f(α)=0 or f(α)=β
•
Solution approaches:
1. Newton-like Techniques: faster but need good estimation of the solution. Seldom used for solving
Navier-Stokes equations. f
f
0
f
'
0 x
x
0
x k
x k
1
f f
'
k 1
k
1
2. Global : guarantee not to diverge but slower, such as sequential decoupled method
21
Solution of linear equation systems
(convergence criteria and iteration errors)
•
Convergence Criteria: Used to determine when to quit for iteration method
1. Difference between two successive iterates
2. Order drops of the residuals
3. Integral variable vs. iteration history
k i ,
1 j
(for all i, j)
i , k
1 j
f i , k j
(for all i, j)
, i n j
i k
j ,
1 i , n j
i , k
1 j
k i , j
i , n j
i k
,
j
1
2
1 2
•
Inner iterations can be stopped when the residual has fallen by one to two orders of magnitude.
•
Details on how to estimate iterative errors have been presented in CFD lecture.
22
Methods for unsteady problems
(introduction)
•
Unsteady flows have a fourth coordinate direction– time, which must be discretized.
•
Differences with spatial discretization: a force at any space location may influence the flow anywhere else, forcing at a given instant will affect the flow only in the future (parabolic like).
•
These methods are very similar to ones applied to initial value problems for ordinary differential equations.
•
The basic problem is to find the solution a short time t after the initial point. The solution at t
2
=t
1
+ t , t
3
=t
2
1
=t
+ t, ….etc.
0
+ t, can be used as a new initial condition and the solution can be advanced to t
23
•
Methods for Initial Value Problems in ODEs
1. Two-Level Methods (explicit/implicit Euler)
2. Predictor-Corrector and Multipoint Methods
3. Runge-Kutta Methods
4. Other methods d
f
t ,
0
0 dt
•
Application to the Generic Transport Equation
1. Explicit methods
2. Implicit methods
3. Other methods
t
u
x
2
x
2
24
•
Methods for Initial Value Problems in ODEs ( explicit and implicit Euler method ) explicit n
1 n f t
n
,
n
t
n
1 n f t
n
1
,
n
1
t implicit
•
Methods for Initial Value Problems in ODEs ( 4 th order
Runge-Kutta method )
* n
* * n
1
2
1
2
n n
t
2
t
2 f f
t t n n
,
1
2
, n
* n
1
2
n
1 n
t
6
f
* n
1
n t
,
n
n
2 f
tf
t n
t n
1
2
,
1
2
,
* n
* * n
1
2
2
1
2 f
t n
1
2
,
* * n
1
2
f t
n
1
,
* n
1
25
•
Application to the Generic Transport Equation
( Explicit Euler methods )
i n
1 i n
u
i n
1
2
x
i n
1
i n
1
x i n
1
2
2
i n
t
i n
1
1
2 d
i n c
2
i n
1
c
2
i n
1
Assume constant velocity d
t
2
Time required for a disturbance to be transmitted
By diffusion over a distance
x c
u
t
x
Courant number, when diffusion negligible,
Courant number should be smaller than unity to make the scheme stable
26
•
Application to the Generic Transport Equation
( Implicit Euler methods )
i n
1
i n
u
i n
1
1
2
x
i n
1
1
i n
1
1
i n
1
1
2
2
i n
1
t Assume constant velocity
1
2 d
i n
1
2 d
i n
1
1
c
2
d
i n
1
1 i n
•
Advantage : Use of the implicit Euler method allows arbitrarily large time steps to be taken
•
Disadvantage : first order truncation error in time and the need to solve a large coupled set of equations at each time step.
27
Solution of Navier-Stokes equations
•
•
•
•
28
• Navier-Stokes equations (3D in Cartesian coordinates)
u
t
u
u
x
v
u
y
w
u
z
ˆ
x
2 x u
2
2 u
y 2
2 u
z 2
v
t
u
v
x
v
v
y
w
v
z
ˆ
y
2 v
x 2
2 v
y 2
2 v
z 2
w
t
u
w
x
v
w
y
w
w
z
ˆ
z
2 w
x 2
2 w
y 2
2 w z 2
Local acceleration
Convection Piezometric pressure gradient Viscous terms
t
x
y
z
0 Continuity equation
•
Discretization of Convective, pressure and Viscous terms
•
Conservation properties: 1. Guaranteeing global energy conservation in a numerical method is a worthwhile goal, but not easily attained;
2. Incompressible isothermal flows, significance is kinetic energy; 3. heat transfer: thermal energy>>kinetic energy
29
•
Collocated arrangement :
1. Store all the variables at the same set of grid points and to use the same control volume for all variables
2. Advantages : easy to code
3. Disadvantages : pressure-velocity decoupling, approximation for terms
•
Staggered Arrangements :
1. Not all variables share the same grid
2. Advantages : (1). Strong coupling between pressure and velocities, (2).
Some terms interpolation in collocated arrangement can be calculated with interpolation.
3. Disadvantages : higher order numerical schemes with order higher than
2 nd will be difficult
Colocated
Staggered
30
Solution of Navier-Stokes equations
(Pressure Poisson equation)
•
Why need equation for pressure: 1. N-S equations lack an independent equation for the pressure; 2. in incompressible flows, continuity equation cannot be used directly
•
Derivation: obtain Poisson equation by taking the divergence of the momentum equation and then simplify using the continuity equation.
•
Poisson equation is an elliptic problem , i.e. pressure values on boundaries must be known to compute the whole flow field
x i
p
x i
x i
i u j
x j
31
Solution methods for the Navier-Stokes equations
•
Analytical Solution (fully developed laminar pipe flow)
•
Vorticity-Stream Function Approach
•
The SIMPLE (Semi-Implicit Method for pressure-Linked Equations)
Algorithm:
1. Guess the pressure field p*
2. Solve the momentum equations to obtain u*,v*,w*
3. Solve the p’ equation (The pressure-correction equation)
4. p=p*+p’
5. Calculate u, v, w from their starred values using the velocity-correction equations
6. Solve the discretization equation for other variables, such as temperature, concentration, and turbulence quantities.
7. Treat the corrected pressure p as a new guessed pressure p*, return to step 2, and repeat the whole procedure until a converged solution is obtained.
32
• The driven cavity problem is a classical problem that has wall boundaries surrounding the entire computational region.
• Incompressible viscous flow in the cavity is driven by the uniform translation of the moving upper lid.
• the vorticity-stream function method is used to solve the driven cavity problem.
u=v=0 o y u=U
TOP
, v=0 x u=v=0 u=v=0
U
TOP
33
u
t
v
t
u
u
x
u
x
v
u
y
v
y
0
p
x
2 u
x
2
2 u
y
2
v
x
u
y
y
x
u
v
u
v
x
v
v
y
p
y
2 v
x
2
2 v
y
2
t
u
x
v
y
1
Re l
2
x
2
2
y
2
2 p
x
2
2 p
y
2
2
2
x
2
2
y
2
2
x
y
2
u
x
v
y
x
y
2
x
2
2
y
2
Re l
Ul
34
The top wall
i , NJ
0
2
w
1 i ,
NJ
w
n
y
2
i ,
n
NJ
1
w on all walls
1
2
2
2
n
2
w w
o
2
1
n
w
2
w
The other
Three walls
p
s w
1
Re l
n w p s
1 , w
2
s p s
1 , w
1
Re l
3
s , w
4
s , w
1
2
n
s , w
2
For wall pressures, using the tangential momentum equation to the fluid adjacent to the wall surface, get:
* s is measured along the wall surface and n is normal to it
* Pressure at the lower left corner of the cavity is assigned 1.0
35
Example (lid-driven cavity, discretization methods)
1 st
n
1 i , j
t
n i , j order upwind for time derivative
u i n
1 , j
i n
1 , j
2
x u i n
1 , j
i n
1 , j v i n
, j
1
i n
, j
1
2
y v i n
, j
1
i n
, j
1
1
Re l
i n
1 , j
2
n i , j
(
x )
2
i n
1 , j
i n
1 , j
2
i , n j
(
x )
2
i n
1 , j
i n
, j
1
2
n i , j
(
y )
2
i n
, j
1
2
n i , j
(
y )
2
i n
, j
1 n i , j
i n
, j
1 p i n
1 , j
2 p i , n j
(
x )
2
p i n
1 , j p i , n j
1
2 p i , n j
(
y )
2
p i , n j
1
2
i n
1 , j
2
n i , j
(
x )
2
i n
1 , j
i n
, j
1
2
n i , j
(
y )
2
i n
, j
1
i n
1 , j
1
i n
1 , j
1
4
x
y i n
1 , j
1
i n
1 , j
1
2
2 nd order central difference scheme used for all spatial derivatives
36
1.
2.
3.
4.
5.
6.
7.
8.
9.
Specify the geometry and fluid properties
Specify boundary conditions
Determine t
Solve the vorticity transport equation for
Solve stream function equation for n
1 n
1
Solve for u n+1 and v n+1
Continue marching to time of interest, or until the steady state is reached.
37
NI
1
NJ i
i
NI
1 ,
,
j j
1
NJ
i , n
1 j
i , n j
1
10
8 and
NI
1
NJ i
i
NI
1 ,
, j
j
1
NJ
i , n
1 j
n i , j
1
10
8
38
Example (lid-driven cavity, sample results)
1
1 29
27 Level psi
29
27
25 23
31 0.0018
0.9
0.9
19
17
17
14 9
1
29 -0.0009
0.8
15
27 -0.0064
0.8
3
2
13
11
13
25 -0.0119
7
2
5
2
7
9
1
1
0.7
0.7
2
1
9
5
23 -0.0174
21 -0.0228
0.6
3
0.6
9
1 7
19 -0.0283
y
0.5
y
17 -0.0338
0.5
5
7
1
15 -0.0393
0.4
5
1
3
5
1
9
1
0.4
0.3
27
25
3
2
21
13 11
9
9
7
11
3
1
1
2
13 -0.0448
11 -0.0502
9 -0.0557
0.3
0.2
13 7
2
7 -0.0612
0.2
0.1
28 15
17 25
5 -0.0667
19 3 -0.0721
0.1
25
21
23 29
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
1 1.1
29
27
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
1
1 -0.0776
x x 1
17
15
19
8
4
Level zeta
1
15 17 19 21 23 27 29
0.9
17
5
2 25 Level p
21
21
29 11.2711
0.9
29 1.1905
27 8.3232
7
11 13
0.8
19
27 1.1754
25 5.3753
0.8
17
25 1.1604
0.7
23 2.4273
9
15
0.7
23 1.1454
21 -0.5206
11
13 0.6
19 -3.4686
7
21 1.1303
1
2
17 -6.4165
0.6
19 1.1153
y
0.5
5
17 1.1003
15 -9.3644
y
0.5
9
15 1.0852
0.4
13 -12.3124
11 -15.2603
0.4
13 1.0702
11 1.0552
0.3
9 -18.2082
7 7 -21.1562
0.3
3
9 1.0401
0.2
21 24
5 -24.1041
5 7 1.0251
21
0.2
1
2
3 -27.0521
5 1.0101
0.1
1 -30.0000
3 0.9950
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
1 x
1 0.9800
0 25
23
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
1 x
39
1. J. H. Ferziger, M. Peric, “ Computational Methods for Fluid
Dynamics
,” 3 rd edition, Springer, 2002.
2. Patric J. Roache, “ Verification and Validation in
Computational Science and Engineering ,” Hermosa publishers, 1998
3. Frank, M. White, “ Viscous Fluid Flow
,” 3 rd edition,
McGraw-Hill Inc., 2006
40