1 Numerical methods for solving the steady state, incompressible Navier-Stokes equations Rixin Yu 2017-04-24
1
Numerical methods for solving the steady state, incompressible
Navier-Stokes equations
Rixin Yu
2017-04-24
CFD of in-cylinder turbulent flow
2Yu. R. et al, Effect of turbulence on HCCI combustion, SAE Technique paper, 2007-01-0183
CFD study of turbulent flame propagation
3Yu. R. et al, A DNS study of interface propagation in homogenous turbulence, Journal of Fluid Mech. 772, 127 (2015)
CFD study of intrinsic flame instability
4
Numerical method for solving 2D steady, incompressible N-S eq.s.
• Review governing equations • The numerical ingredients of the solution method
– Choosing grid for variable discretization• Collocated grid / Staggered grid
– The iteration procedure to handle nonlinearity– The linear algebraic approach
• Discretize the governing equations to build matrix A and B for solving X; AX=B
• A directly coupled solution method– Step by step demonstration on a 3x3 cells grid.
5
2D, incompressible, Navier-Stokes equations
6
+ + = − + ++ + = − + +
+ + = 0
+ .⇒ ≡ + + y = −( + ) = 0Further is known (for instance from other eq. (T), or simply set to a constant)Finally, we then get 3 equations (1,2,3) matched for 3 unknown variable ( , , )
(0)
(2)
(3)
(1)
Non-dimentional form of 2D incompressible N-S equations
7
+ + = − + 1 +v + + = − + 1 +
+ = 0
ℎ =
(1)
(2)
(3)
(x∗ = , y∗ = , t∗ = / , ∗ = , ∗= , ∗ = , = . )After normalization, drop *
Convective term Diffusion term
Extract a Poisson-equation for pressure from incompressible N-S eq.
8
u + v = 0+ + = − (1)
(2)
Continuity eq.
u-mome. Eq.
1 − 2 + 3 ⇒
(Assume = .; Use , represent the convective and diffusive terms.)
+ p= − + + +
+ + = − (3)v-mome. Eq.
Numerical method for solving 2D steady, incompressible N-S eq.s.
• Review governing equations • The numerical ingredients of the solution method
– Choosing grid for variable descretization• Collocated grid / Staggered grid
– The iteration procedure to handle nonlinearity– The linear algebraic approach
• Discretize the governing equations to build matrix A and B for solving X; AX=B
• A directly coupled solution method– Step by step demonstration on a 3x3 cells grid.
9
The collocated grid(The discretized u,v,p are defined at the same location)
p
vu
x
y
j+1
j
j-1
i i+1i-1
The local control-volume-cell for u-momentum,v-momentum, p-continuityequations are the also the same
One problem using the collocated grid(Odd-even decoupling)
Assuming static fluid (u=v=0), no body force, we know the exact solution should be p=const. However the following p field being decoupled into 4 set of different constants (1,3, 7, and 9) also satisfy the discretized equations if 2nd order center difference is used for pressure term.
3 7 73 3 7
9
9
1
7 7
7 7
1
7
7
1
1
1 1 1
1
1
9
9
99
33
3 3
3
3
9
9
9
u-eq.+ = − + 1 += − 9 + 12 − (1 + 9)2Δ = 0
v-eq.+ = − + 1 += − 9 + 72 − (7 + 9)2Δ = 0
Cont.-eq.u + v = 0
Odd-even decoupling on collocated gridstill presented using unstructured grid: hexagon
u-eq. + = − + 1 +
v-eq. + = − + 1 +
= ∮ ⋅ =∮ ⋅= +2 + +2 − +2 − +2 2 3 = 012
34
ba
b a
c
12
34
ba
b a
c
56
d
d
d
d = ⋅ = = ⋅= +2 − +2 + +2 − +2 2 + +2 − +2= 0
Odd-even decoupling on collocated gridstill presented using unstructured grid: hexagon
a b
b ad
d
c
c
a b
a
a
a
a
a
a
a a
a b
a
c
c
c
c
c
c
c
c c
c
c
cd
d
d
d
d
d
d
d
d
dd
b
b
b
b
b
b
b b
b
b
a
ab
a b
d
c
c
ba
b a
c
d
d
For example: Switch a/b ; switch c/d(Permute a,b,c,d)
d
How to overcome the odd-even decoupling issue
• Still using collocated grid– Rhie & Chow 1983
• Using Staggered grid !14
Momentum Eq. (no change)
Continuity Eq.(modify) Not working!
The staggered arragment(u,v,p are stored at different location)
p
v
u
x
y
(i+½,j)(i,j)
(i,j+½)
j+1
j
j-1
j+½
j-½
i i+1i-1 i+½i-½
p : at the “p-cell” centeru,v : at the corresponding “p-cell” surface
Staggered grid(what is more than the location of variable definition)
p-cell
v-cell
u-cell
Based on the p-control-volume-cell, discretize the continuity equation. Based on the u-control-volume-cell, discretize the u-momentum equation. Based on the v-control-volume-cell, discretize the v-momentum equation.
The staggered grid arrangement
x
y
Numerical method for solving 2D steady, incompressible N-S eq.s.
• Review governing equations • The numerical ingredients of the solution method
– Choosing grid for variable discretization• Collocated grid / Staggered grid
– The iteration procedure to handle nonlinearity– The linear algebraic approach
• Discretize the governing equations to build matrix A and B for solving X; AX=B
• A directly coupled solution method– Step by step demonstration on a 3x3 cells grid.
18
-2 -1.5 -1 -0.5 0-2
-1.5
-1
-0.5
0
Using iterative method to solve a simple nonlinear equation− 2 − 3 = 0∗ = 3 − 2 ∗ = 2 + 3/
Iteration scheme 1
Converge
= 3 − 2
( − 2) = 3linearize ( − 2) = 3Iteration scheme 2
-1.5 -1 -0.5-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
= 2 + 3/=
=Diverge
Using under/over-relaxation factor in iterative method to achieve convergence
Based on the diverged Iteration shceme 2:
− ∗ = ′∗∗ = (1 − ) + × (2 + 3/ )
correction
A modified Iteration scheme using under-relaxation (or over) factor
∗ = 2 + 3/( ∗∗ − ) = × ∗ −
Set = 0.2-1.5 -1 -0.5
-1.5
-1
-0.5 == 0.8 + 0.2 2 +
Numerical method for solving 2D steady, incompressible N-S eq.s.
• Review governing equations • The ingredients of the solution method
– Choosing grid for variable discretization• Collocated grid / Staggered grid
– The iteration procedure to handle nonlinearity– The linear algebraic approach
• Discretize the governing equations to build matrix A and B for solving X; AX=B
• A directly coupled solution method– Step by step demonstration on a 3x3 cells grid.
21
Recap of the classic linear algebraic approach for solving a simple “linear” “non-couple” P.D.E.
= ( )
−Δ = − 2 +Δ = 0
for 0≤x≤5; B.C. will be specified later.
tn
tn+1
i=0 i=1 i=2 i=3 i=4
− + (2 + 1Δ ) − = 1Δ
Space : 2nd order Time : Euler implicit
i=5
Problem description( Transient heat conduction eq.)
Move unknown to the left, known to the right
( : Δ = 1)
Linear algebraic approach for P.D.E.Count the total number of unknowns, it should matches the total
number of equations, then write the matrix
1−1 2 + −1−1 2 + −1−1 2 + −1−1 2 + −10 1=
tn
tn+1
i=0 i=1 i=2 i=3 i=4 i=5
− + (2 + 1Δ ) − = 1ΔStrategy 1 (Lazy): 6-unknowns
Dirichelet B.C.
Linear algebraic approach for P.D.E Neumann Boundary condition
1 −1−1 2 + −1−1 2 + −1−1 2 + −1−1 2 + −1−1 1=
0
0
If using Neumann B.C. . . = 0
tn
tn+1
i=0 i=1 i=2 i=3 i=4 i=5
Linear algebraic approach for P.D.E More compact matrix, reduces number of unknowns, eases the solver.
2 + −1−1 2 + −1−1 2 + −1−1 2 +=
++
− + (2 + 1Δ ) − = 1ΔAnother compact strategy: 4-unknowns
tn
tn+1
i=0 i=1 i=2 i=3 i=4 i=5
Linear algebraic approach for P.D.E.One issue relate to using all Neumann B.C.s
1 −1−1 2 + 1Δ −1−1 1 = r. h. s.i=0 i=1 i=2
0 = r. h. s.The matrix determinant =0
Alternatively, if rewrite in the compact way(single unknown)
For steady state problem, the algebraic equations system become singular if all B.D. are set to be Neumann condition.
Arbitrary constant can be added to and still satisfy the eq.this issue persists to higher dimention.
Summary of the solution ingredients
• Staggered grid / collocated grid• Iteration method for locally linearize and solve
nonlinear equation– Initial guess (diverge/converge), under-relaxation factor,
residuals
• Linear Algreabic approach for solve linear P.D.E.– Determine and count unknowns, match number of eq.s, – Assemble A, B for solve AX=B.
• Treatment of different B.C.s
27
Numerical method for solving 2D steady, incompressible N-S eq.s.
• Review governing equations • The numerical ingredients of the solution method
– Choosing grid for variable discretization• Collocated grid / Staggered grid
– The iteration procedure to handle nonlinearity– The linear algebraic approach
• Discretize the governing equations to build matrix A and B for solving X; AX=B
• A directly coupled solution method– Step by step demonstration on a 3x3 cells grid.
28
29
Solution of 2D N-S eq. in rectangular domain of 3x3 p-cells
(constant density)Non-dimentional eq.Δx = Δy = 1= 2, U = U = 1
Inlet
Outlet
1 0.46
0.23
0.31
0.15
0.21
0.64 1
0.54
0.31
0.3
0.33
0.15
0.36
0
0.66
0.8
0.51
0.67
0.86
0.53
0.5
1.1
wall
wall
wall
wall
u,v,p definition on the staggered grid
0
0
0
0
0
0
0
0
0
Full display of all allocated u,v,p memory (In the above plot, the vector length has no meaning).
Extended B.D. values for convenience of discretizing algorithm, sometime are called “ghost”
The iterative solution procedure
Now u,v are shown with vector length indicating their value, (no vector means zero) p value are shown by text.
Initial guess fields After 1st iteration
After 2nd iterationAfter several iterations, converged
1 1.5 2 2.5 3 3.5 4 4.5 510-6
10-5
10-4
10-3
10-2
10-1
100
1 0.5
0.23
0.26
0.18
0.2
0.61 1
0.5
0.26
0.32
0.35
0.18
0.39
0
0.82
0.92
0.68
0.81
1
0.69
0.7
1.1
1 0.46
0.24
0.31
0.15
0.21
0.64 1
0.54
0.31
0.3
0.33
0.15
0.36
0
0.67
0.8
0.52
0.68
0.87
0.54
0.51
1.1
1 0.46
0.23
0.31
0.15
0.21
0.64 1
0.54
0.31
0.3
0.33
0.15
0.36
0
0.66
0.8
0.51
0.67
0.86
0.53
0.5
1.1
1
1
0
0
0
0
0
0
0
0
0
Determine number of unknown u, v and p
6 unknown u, 6 unknown v9 unknown p
0 5 10 15 20nz = 87
0
5
10
15
20X21=[U6 ; V6 ; P9 ]
A21X21 X21 =B21
Using the discretized cont. eq.s, u-eq.s and v-eq.s to assemble the matrix A and the source term vector B
1 0.46
0.23
0.31
0.15
0.21
0.64 1
0.54
0.31
0.3
0.33
0.15
0.36
0
0.66
0.8
0.51
0.67
0.86
0.53
0.5
1.1
Notation system (East/West/North/South/o-center)
o e
n
w
s
Discretize continuity eq. in a p-cell
Discretize u-momentum eq. in a u-cell
Rewrite u-momentum equation in a conservative form for us to apply finite volume discretization( − 1 + ) + ( − 1 ) = 0u-control-volume-cell:
1Δ Δ − 1 + ⋅ + − 1 ⋅ = 0
1Δ Δ . ℎ. . = 0Ae
Aw
As
An
Discretize u-momentum eq. in a u-cell
− 1 + − − 1 +Δ + − 1 − − 1Δ = 0
AeAw
As
An
The discretized u-momentum equation for interior points
−Δ + u + u2 − 1 u − uΔ − u + u2 − 1 u − uΔΔ +u + u2 v + v2 − 1 u − uΔ − u + u2 v + v2 − 1 u − uΔΔ = 0
− 1 + − − 1 +Δ − − 1 − − 1Δ = 0
As an demonstration, apply the simplest scheme (i) 2nd order center difference, (ii) 2nd order center interpolation
The discretized u-momentum equation for interior u-cells
−Δ + u + u2 − 1 u − uΔ − u + u2 − 1 u − uΔΔ +u + u2 v + v2 − 1 u − uΔ − u + u2 v + v2 − 1 u − uΔΔ = 0One equation corresponded to one unknown u ,
Linearize the nonlinear product: Strategy 1: Using the (frozen) value known from previous iteration ∗, v-first)
Another “demonstration” strategy: (couple v with u, not useful in practice)
u + u2 u∗ + u∗2u + u2 v∗ + v∗212 u + u2 v∗ + v∗2 + u∗ + u∗2 +2
The discretized u-momentum equation
−Δ + u + u2 u∗ + u∗2 − 1 u − uΔ − u + u2 u∗ + u∗2 − 1 u − uΔΔ +u + u2 v∗ + v∗2 − 1 u − uΔ − u + u2 v∗ + v∗2 − 1 u − uΔΔ = 0
u + + −Δ + = 0
After linearization, group terms according to the center u and all the neighboring unknown (u , u , u , u , … . ),find the corresponding coefficients for each unknown u . If some of the involved neighbour belongs to the already known boundary cells, we group such them into the source term . Note, the values of and
will only updated after one iteration)
Apply similar discretization of v-momentum eq in v-cellIn the following we collect all numerical schemes for
assemble the matrix A and source vector B
u + + −Δ + = 0v + + −Δ + = 0−Δ + −Δ = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)
(Loop for all unknown 9 v-cells)
Let’s prepare an empty matrix A and source vector B of size N=6+6+9=21
u + + −Δ + = 0v + + −Δ + = 0−Δ + −Δ = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)(Loop for all unknown 9 v-cells)
0 5 10 15 20nz = 0
0
5
10
15
20
A21x21
0 5 10 15 20nz = 0
012
B21
(1.a) Fill A and B using 6 u-momentum eq.s (without pressure term)
+ + −Δ + = 0v + + −Δ + = 0−Δ + −Δ = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)(Loop for all unknown 9 v-cells)
A21x21
B21
0 5 10 15 20nz = 20
0
5
10
15
20
0 5 10 15 20nz = 2
012
(1.b) Fill A and B by adding only the p-term in the 6 u-momentum eq.s
+ + − + = 0v + + −Δ + = 0−Δ + −Δ = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)(Loop for all unknown 9 v-cells)
A21x21
B21
0 5 10 15 20nz = 32
0
5
10
15
20
0 5 10 15 20nz = 2
012
(2.a) Fill A and B by the 6 v-momentum eq.s without p-terms
+ + − + = 0+ + −Δ + = 0−Δ + −Δ = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)(Loop for all unknown 9 v-cells)
A21x21
B21
0 5 10 15 20nz = 52
0
5
10
15
20
0 5 10 15 20nz = 2
012
(Not adding new non-zero term because v is entirely initialized to zero)
(2.b) Fill A and B by adding up the p-term in 6 v-momentum eq.s
+ + − + = 0+ + − + = 0−Δ + −Δ = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)(Loop for all unknown 9 v-cells)
A21x21
B21
0 5 10 15 20nz = 2
012
0 5 10 15 20nz = 64
0
5
10
15
20
0 5 10 15 20nz = 3
012
(3) Fill A and B by the 9 continuity eq.s
+ + − = 0+ + − = 0− + − = 0
(Loop for all unknown 6 u-cells)
(Loop for all unknown 6 v-cells)(Loop for all unknown 9 v-cells)
A21x21
B21
0 5 10 15 20nz = 87
0
5
10
15
20
Due to global mass conservation, the redundant continuity eq. is skipped at this point. Instead, the local p value at this cell is directly set to zero (can be any arbitrary constant).
A and B is ready, solve AX+B=0 to give XMatlab use direct matrix inversion, in fluent choose “coupled” method.
X21
Translate X to u, v, and p in the actual grid, draw the plot
0 5 10 15 20nz = 20
012
1 0.5
0.23
0.26
0.18
0.2
0.61 1
0.5
0.26
0.32
0.35
0.18
0.39
0
0.82
0.92
0.68
0.81
1
0.69
0.7
1.1
0
0
0
0
0
0
0
0
0
After 1st iteration
Initial guessed value + B.D. value
A procedural summary for direct/coupled solver
Initialize guessed u*, v* and p* ;
Assemble ANXN and BNusing frozen coefficient (u*,v*,p*,uBD,vBD,pBD)Sub-step 1: u-eq.sSub-step 2: v-eq.sSub-step 3: cont.-eq.s
Solve ANXNXN =BNXN=[XNu ; XNv; XNp ] u,v,p
u + + −Δ + = 0v + + −Δ + = 0−Δ + −Δ = 0
Converged?
Set u*=uv*=v,p*=p
Chosing proper B.C., decide the numbers of unknowns N=Nu+Nv+Np
Summary for coupled solver
• Determine the number of unknown u, v, and p to build the unknown vector X, give the same number of algebraic equations to build A and B, with AX+B=0.
• Linearize the non-linear product as multiplication of a coefficient c using the frozen value from previous iteration.
• Be aware of properly selecting boundary conditions.• A note
– We groups coefficients according to center u and all the neighboring (u , u , u , u , … . ). This corresponding to the diagonal and off-diagonal coefficents in the matrix A will be useful in tomorrow's lecture for segregated solver.
49