me 747 introduction to computational fluid dynamics ...chainarong.me.engr.tu.ac.th/documents/me747...
TRANSCRIPT
ME 747 Introduction to computational
fluid dynamics
By Chainarong Chaktranond
Lecture 5_2Introduction to solve engineering
problems with finite-difference method
2Chainarong Chaktranond, Thammasat University
Lecture schedule
5. Introduction to solve engineering problems with finite-difference method
- Taylor series expansion, Approximation of the second derivative, Initial condition and
Boundary conditions
6 – 7
4. Introduction to numerical methods
- Finite different method, Finite volume method, Finite element method, etc.
5
3. Overviews of governing equations for flow and heat transfer
-Elliptic, Parabolic and Hyperbolic equations
4
2. Introduction to Fortran programming
- Basic commands in Fortran programming
2 - 3
1.Overviews of computational fluid dynamics
- Overviews and importance of heat transfer in real applications1
TopicsSession
3Chainarong Chaktranond, Thammasat University
Contents
Iteration method
Gauss-Seidel Method
Successive Over Relaxation Method
4Chainarong Chaktranond, Thammasat University
Iterative method: Gauss-Seidel Method
[ ]{ } { }A X C=
1
, 100n ni i
a i sni
x xx
ε ε−−
= × <
Controlled error
11 1 12 2 13 3 1 1
21 1 22 2 23 3 2 2
1 22 2 23 3
m m
m m
m mm m m
a x a x a x a x ca x a x a x a x c
a x a x a x a x c
+ + + + =+ + + + =
+ + + + =
……
…
5Chainarong Chaktranond, Thammasat University
Iterative method: Gauss-Seidel Method
1 2 3
1 2 3
1 2 3
3 0.1 0.2 7.850.1 7 0.3 19.30.3 0.2 10 71.4
x x xx x xx x x
− − =+ − = −
− + =
Example
1st Step:2 3
1
1 32
1 23
7.85 0.1 0.23
19.3 0.1 0.37
71.4 0.3 0.210
x xx
x xx
x xx
+ +=
− − +=
− +=
6Chainarong Chaktranond, Thammasat University
Iterative method: Gauss-Seidel Method
2nd Step: Trail with x2 = x3 = 0
( ) ( )1
7.85 0.1 0 0.2 02.616666667
3x
+ += =
3rd Step: Trail with x3 = 0 and employ x1 from 1st step
( ) ( )2
19.3 0.1 2.6166667 0.3 02.79452381
7x
− − += = −
4th Step: Trail with employ x1 from 1st step and x2 from 2nd step
( ) ( )3
71.4 0.3 2.616666667 0.2 2.794523817.005609524
10x
− + −= =
7Chainarong Chaktranond, Thammasat University
5th step: Control error
1
, 100n ni i
a i sni
x xx
ε ε−−
= × <
Iterative method: Gauss-Seidel Method
1
0 2.616666667 100 1002.616666667xε−
= × =
( )( )2
0 2.79452381100 100
2.79452381xε− −
= × =−
2
0 7.005609524 100 1007.005609524xε−
= × =
6th step: Repeat from 1st to 5th step
program gaussseidel
parameter (n=20)
real*8 x1(0:n),x2(0:n),x3(0:n)
open(1000,file='Gauss-seidel',status='unknown')
x1(0) = 0.d0
x2(0) = 0.d0
x3(0) = 0.d0
error1 = 100.d0
error2 = 100.d0
error3 = 100.d0
write(1000,1001) i,x1(0),x2(0),x3(0),error1,error2,error3
do 10 i = 1,n
x1(i) = (7.85+0.1d0*x2(i-1)+0.2d0*x3(i-1))/3.d0
x2(i) = (-19.3d0-0.1d0*x1(i)+0.3d0*x3(i-1))/7.d0
x3(i) = (71.4d0-0.3d0*x1(i)+0.2d0*x2(i))/10.d0
error1 = dabs((x1(i)-x1(i-1))/x1(i))*100.d0
error2 = dabs((x2(i)-x2(i-1))/x2(i))*100.d0
error3 = dabs((x3(i)-x3(i-1))/x3(i))*100.d0
write(1000,1001) i,x1(i),x2(i),x3(i),error1,error2,error3
1001 format(i2,2x,3e15.7,2x,3e15.7)
10 continue
close(1000)
stop
0.00E+000.00E+000.00E+007.000000-2.5000003.00000011
0.00E+000.00E+000.00E+007.000000-2.5000003.00000010
0.00E+001.78E-141.48E-147.000000-2.5000003.0000009
5.08E-146.39E-133.42E-127.000000-2.5000003.0000008
5.80E-129.05E-114.01E-107.000000-2.5000003.0000007
6.97E-101.83E-086.44E-087.000000-2.5000003.0000006
1.62E-071.41E-061.18E-057.000000-2.5000003.0000005
1.01E-054.82E-041.05E-037.000000-2.5000003.0000004
4.16E-031.45E-023.16E-016.999999-2.4999883.0000323
7.60E-021.18E+011.25E+017.000291-2.4996252.9905562
1.00E+021.00E+021.00E+027.005610-2.7945242.6166671
1.00E+021.00E+021.00E+020.0000000.0000000.0000000
error3error2error1x3x2x1Step
10Chainarong Chaktranond, Thammasat University
Successive Over Relaxation method (SOR)
( )1new new oldi i ix x xλ λ= + −
1 2 3
1 2 3
1 2 3
3 0.1 0.2 7.850.1 7 0.3 19.30.3 0.2 10 71.4
x x xx x xx x x
− − =+ − = −
− + =
Example
1st Step:2 3
1
1 32
1 23
7.85 0.1 0.23
19.3 0.1 0.37
71.4 0.3 0.210
x xx
x xx
x xx
+ +=
− − +=
− +=
1 2λ< <where
11Chainarong Chaktranond, Thammasat University
Iterative method: Gauss-Seidel Method
2nd Step: Trail with x2 = x3 = 0
( ) ( )1
7.85 0.1 0 0.2 02.616666667
3x
+ += =
3rd Step: find new x1
( )( ) ( )( )1 1.0005 2.616666667 1 1.0005 0 2.617975x = + − =
( )1new new oldi i ix x xλ λ= + −
1.0005λ =
12Chainarong Chaktranond, Thammasat University
4th Step: substitute x1 and Trail with x3 = 0
( ) ( )2
19.3 0.1 2.617975 0.3 0-2.7945425
7x
− − += =
5th Step: find new x2
( )( ) ( )( )2 1.0005 -2.7945425 1 1.0005 0 -2.79594x = + − =
( )1new new oldi i ix x xλ λ= + −
1.0005λ =
Iterative method: Gauss-Seidel Method
13Chainarong Chaktranond, Thammasat University
6th Step: substitute x1 and x2
7th Step: find new x2
( )( ) ( )( )2 1.0005 7.00554195 1 1.0005 0 7.009044x = + − =
( )1new new oldi i ix x xλ λ= + −
1.0005λ =
Iterative method: Gauss-Seidel Method
( ) ( )3
71.4 0.3 2.617975 0.2 -2.795947.00554195
10x
− += =
8th step: Repeat from 1st to 7th step
program sor
parameter (n=20)
real*8 x1(0:n),x2(0:n),x3(0:n)
open(1000,file='SOR-output',status='unknown')
x1(0) = 0.d0
x2(0) = 0.d0
x3(0) = 0.d0
error1 = 100.d0
error2 = 100.d0
error3 = 100.d0
ramda = 1.0005d0
write(1000,1001) i,x1(0),x2(0),x3(0),error1,error2,error3
do 10 i = 1,n
x1(i) = (7.85+0.1d0*x2(i-1)+0.2d0*x3(i-1))/3.d0
x1(i) = ramda*x1(i)+(1.d0-ramda)*x1(i-1)
x2(i) = (-19.3d0-0.1d0*x1(i)+0.3d0*x3(i-1))/7.d0
x2(i) = ramda*x2(i)+(1.d0-ramda)*x2(i-1)
x3(i) = (71.4d0-0.3d0*x1(i)+0.2d0*x2(i))/10.d0
x3(i) = ramda*x3(i)+(1.d0-ramda)*x3(i-1)
error1 = dabs((x1(i)-x1(i-1))/x1(i))*100.d0
error2 = dabs((x2(i)-x2(i-1))/x2(i))*100.d0
error3 = dabs((x3(i)-x3(i-1))/x3(i))*100.d0
write(1000,1001) i,x1(i),x2(i),x3(i),error1,error2,error3
1001 format(i2,2x,3e15.7,2x,3e15.7)
10 continue
close(1000)
stop
end
0.00E+000.00E+000.00E+007.000000-2.5000003.00000010
0.00E+001.78E-140.00E+007.000000-2.5000003.0000009
5.08E-143.55E-144.50E-127.000000-2.5000003.0000008
1.67E-121.51E-109.42E-117.000000-2.5000003.0000007
1.19E-091.18E-089.46E-087.000000-2.5000003.0000006
1.22E-072.56E-068.79E-067.000000-2.5000003.0000005
1.82E-054.46E-041.51E-037.000000-2.5000003.0000004
4.04E-032.62E-023.04E-016.999999-2.4999893.0000453
1.25E-011.19E+011.25E+017.000281-2.4993352.9909252
1.00E+021.00E+021.00E+027.009044-2.7959402.6179751
1.00E+021.00E+021.00E+020.0000000.0000000.0000000
error3error2error1x3x2x1Step
0.00E+000.00E+000.00E+007.000000-2.5000003.00000010
0.00E+001.78E-141.48E-147.000000-2.5000003.0000009
Gauss-Seidel
SOR
16Chainarong Chaktranond, Thammasat University
Solving the fluid dynamic equations
2 2
2 2
u u ut x y
∂ ∂ ∂= +
∂ ∂ ∂
m
l
i,j i+1,ji-1,j
i,j+1
i,j-1
17Chainarong Chaktranond, Thammasat University
2 2
2 2
u u ut x y
∂ ∂ ∂= +
∂ ∂ ∂
1, ,
1 ,2
i j i j
i j
u uux x
+
+
−Δ=
Δ Δ
, 1,
1 ,2
i j i j
i j
u uux x
−
−
−Δ=
Δ Δ
( ) ( )21, , , 1,
2,
1 i j i j i j i j
i j
u u u uux x xx
+ −⎛ ⎞− −Δ ⎜ ⎟= −⎜ ⎟Δ Δ ΔΔ ⎝ ⎠
1, , 1,2
2i j i j i ju u ux
− +− +⎛ ⎞= ⎜ ⎟Δ⎝ ⎠
( ) ( )2, 1 , , , 1
2,
1 i j i j i j i j
i j
u u u uuy y yy
+ −⎛ ⎞− −Δ ⎜ ⎟= −⎜ ⎟Δ Δ ΔΔ ⎝ ⎠
, 1 , , 12
2i j i j i ju u uy
− +− +⎛ ⎞= ⎜ ⎟Δ⎝ ⎠
Solving the fluid dynamic equations
18Chainarong Chaktranond, Thammasat University
2 2
2 2
u u ut x y
∂ ∂ ∂= +
∂ ∂ ∂
1 1 1 1 1 1 1, , 1, , 1, 1, , , 1
2 2
2 2n n n n n n n ni j i j i j i j i j j j i j i ju u u u u u u u
t x y
+ + + + + + +− + − +⎛ ⎞ ⎛ ⎞− − + − +
= +⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟Δ Δ Δ⎝ ⎠ ⎝ ⎠
1 1 1 1 1, 1, , 1, , 1 , 12 2 2 2 2 2
2 21n n n n n ni j i j i j i j i j i j
t t t t t tu u u u u ux x y x y y
+ + + + +− + − +
⎛ ⎞Δ Δ Δ Δ Δ Δ= − + + + − − −⎜ ⎟Δ Δ Δ Δ Δ Δ⎝ ⎠
a b c d e
Implicit Euler method
[ ]{ } { }1n ni iA X X+ =
19Chainarong Chaktranond, Thammasat University
1 1 1 1, 1, 1, , 1 , 12 2 2 2
1,
2 22 21
n n n n ni j i j i j i j i j
ni j
t t t tu u u u ux x y yu
t tx y
+ + + +− + − +
+
Δ Δ Δ Δ+ + + +Δ Δ Δ Δ
=⎛ ⎞Δ Δ+ +⎜ ⎟Δ Δ⎝ ⎠
Gauss-Seidel
{ } [ ]{ }1n ni iX A X +=
Implicit Euler method
1 1 1 11
n n n nn P S S N N W W E EP
P
Q A A A AA
φ φ φ φφ
+ + + ++ − − − −=
1 1 1 1 1, 1, , 1, , 1 , 12 2 2 2 2 2
2 21n n n n n ni j i j i j i j i j i j
t t t t t tu u u u u ux x y x y y
+ + + + +− + − +
⎛ ⎞Δ Δ Δ Δ Δ Δ= − + + + − − −⎜ ⎟Δ Δ Δ Δ Δ Δ⎝ ⎠
20Chainarong Chaktranond, Thammasat University
SOR
( )1 1 1 1
1 1n n n n n
n nP S S W W N N E EP P
P
u A u A u A u A uu u
Aλ λ
+ + + ++ − − − −= + −
( )1 1 1 1
1 1n n n n
n nP S S N N W W E EP P
P
Q A A A AA
φ φ φ φφ λ λ φ
+ + + ++ − − − −= + −
Implicit Euler method
1 1 1 1 1, 1, , 1, , 1 , 12 2 2 2 2 2
2 21n n n n n ni j i j i j i j i j i j
t t t t t tu u u u u ux x y x y y
+ + + + +− + − +
⎛ ⎞Δ Δ Δ Δ Δ Δ= − + + + − − −⎜ ⎟Δ Δ Δ Δ Δ Δ⎝ ⎠
Flow
1,1u 2,1u 3,1u 4,1u 5,1u6,1u
1,1u
1,2u
1,3u
1,4u
1,5u
1,6u
2,2u
( ),1 0u x =
( ),6 0u x =
( )( )1, 1
, 0
u y
u n y
=
=
( ), 0u x y =
Initial condition
a b c d e
0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0
0 0 0 00 0 0 0 0
0 0 0 0 00 0 0 0 0 00 0 0 0 0 00 0 0 0 0 00 0 0 0 0 00 0 0 0 0 00 0 0 0 0 00 0 0 0 00 0 0 0 00 0 0 00 0 00 0 0 0 0 0 0 0 0 0 0 0 0
b c ea b c e
a b c ea b c e
d a b c ed a b c e
d a b c ed a b c e
d a b c ed a b c e
d a b c ed a b c e
d a b cd a b c
d a b cd a b
⎡ ⎤⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎣ ⎦⎢
12,2 2,2
13,2 3,2
14,2 4
15,2
12,3
13,3
14,3
15,3
12,4
13,4
14,4
15,4
12,5
13,5
14,5
15,5
n n
n n
n
n
n
n
n
n
n
n
n
n
n
n
n
n
u du du duuuuuuuuuuuuu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
⎧ ⎫⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥ ⎪ ⎪ =⎨ ⎬⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎪ ⎪⎥⎥ ⎪ ⎪⎩ ⎭⎥
1 12,2 1,2 2,1
13,2 3,1
1,2 4,2 4,1
15,2 5,2 5,1
2,3 2,3
3,3 3,3
4,3 4
5,3
2,4
3,4
4,4
5,4
2,5
3,5
4,5
5,5
n n n
n n
n n n
n n n
n n
n n
n
n
n
n
n
n
n
n
n
n
u au duu duu du
d u dud ud ud uddddddddd
+ +
+
+
+
⎧ ⎫ − −⎪ ⎪ −⎪ ⎪⎪ ⎪ −⎪ ⎪
−⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪ =⎨ ⎬⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎩ ⎭
,3
5,3
2,4
3,4
4,4
5,41
2,5 2,61
2,5 3,61
2,5 4,61 1
2,5 6,5 5,6
n
n
n
n
n
n
n n
n n
n n
n n n
uuuuu
u euu euu eu
u cu du
+
+
+
+ +
⎧ ⎫⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎨ ⎬⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪⎪ ⎪
−⎪ ⎪⎪ ⎪−⎪ ⎪⎪ ⎪−⎪ ⎪
− −⎪ ⎪⎩ ⎭
1 1 1 1 1, 1, , 1, , 1 , 12 2 2 2 2 2
2 21n n n n n ni j i j i j i j i j i j
t t t t t tu u u u u ux x y x y y
+ + + + +− + − +
⎛ ⎞Δ Δ Δ Δ Δ Δ= − + + + − − −⎜ ⎟Δ Δ Δ Δ Δ Δ⎝ ⎠
23Chainarong Chaktranond, Thammasat University
SOR
( )1 1 1 1
1 1n n n n n
n nP S S W W N N E EP P
P
d A u A u A u A uu u
Aλ λ
+ + + ++ − − − −= + −
( )1 1 1 1
1 1n n n n
n nP S S N N W W E EP P
P
Q A A A AA
φ φ φ φφ λ λ φ
+ + + ++ − − − −= + −
Implicit Euler method
1 1 1 1 1, 1, , 1, , 1 , 12 2 2 2 2 2
2 21n n n n n ni j i j i j i j i j i j
t t t t t tu u u u u ux x y x y y
+ + + + +− + − +
⎛ ⎞Δ Δ Δ Δ Δ Δ= − + + + − − −⎜ ⎟Δ Δ Δ Δ Δ Δ⎝ ⎠
program flowsor
parameter(n=21,m =21,ntime=100)
real*8 unew(n,m),uold(n,m),a,b,c,d,e
open(1000,file='FlowSOR',status='unknown')
do 10 j = 1,m
do 20 i = 1,n
unew(i,j) = 0.d0
uold(i,j) = 0.d0
unew(1,j) = 1.d0
uold(1,j) = 1.d0
unew(i,1) = 0.d0
uold(i,m) = 0.d0
unew(n,j) = 0.d0
20 continue
10 continue
dx = 10.d0/dble(n-1)
dy = 10.d0/dble(m-1)
dt = 0.001d0
a = -1.d0*dt/dx/dx
b = 1.d0+2.d0/dx/dx+2.d0/dy/dy
c = -1.d0*dt/dx/dx
d = -1.d0*dt/dy/dy
e = -1.d0*dt/dy/dy
ramda = 1.5d0
do 100 nt = 1,ntime
do 110 j = 2,m-1
do 120 i = 2,n-1
unew(1,j) = 1.d0
uold(i,j) = unew(i,j)
unew(n,j) = 0.d0
unew(i,1) = 0.d0
unew(i,m) = 0.d0
unew(i,j) = ramda*(uold(i,j)-d*unew(i,j-1)-e*unew(i,j+1)
# -a*unew(i-1,j)-c*unew(i+1,j))/b+(1.d0-ramda)*uold(i,j)
120 continue
110 continue
100 continue
do 200 i = 1,n
do 210 j = 1,m
unew(i,1) = 0.d0
unew(i,m) = 0.d0
write(1000,1001) i,j,unew(i,j)
1001 format(2i2,2x,e15.8)
210 continue
200 continue
close(1000)
stop
end
25Chainarong Chaktranond, Thammasat University
1.0
0.8
0.6
0.4
0.2
0.0
Y
2015105
X
x = 1 x = 5 x = 10 x = 15 x = 21
Y
u