Beruflich Dokumente
Kultur Dokumente
Fall 2010-2011
Introduction
1
Finite Volume Method for One-dimensional Steady State Diffusion
Steady-state diffusion of a
general property in one-
dimensional domain is
d d
( ) S 0
dx dx
Step 2: Discretisation
Integration of the diffusion equation over the CV gives
d d d d
dx dx dV S dV A dx
V V e
A S V 0
dx w
2 x 2
( x x ) ( x ) x 2
x x x x 2
2
2 x 2
( x x) ( x) x 2
x x x x 2
2 x 2
E P x 2
x P x P 2
2 x 2
W P x 2
x P x P 2
Neglect
E W
Adding and subtracting
x P 2x
E P
At the east face
x e x
ME555 : Computational Fluid Dynamics 5 I. Sezai Eastern Mediterranean University
d d
A A S V 0
dx e dx w (4.4)
On a uniform grid linear interpolation of is
W P P E
w e (4.5)
2 2
Diffusive flux terms are
d E P
A e Ae (4.6)
dx e xPE
d P W
A w Aw
(4.7)
dx w xWP
ME555 : Computational Fluid Dynamics 6 I. Sezai Eastern Mediterranean University
3
The source term S may be a function of express S in linear form as:
S V Su S pP (4.8)
Substituting (4.6), (4.7) and (4.8) into (4.4)
P W
e Ae E P w Aw ( Su S pP ) 0 (4.9)
xPE xWP
Rearranging,
e (4.10)
Ae w Aw S p P w Aw W e Ae E Su
xPE xWP xWP xPE
or, aPP aW W aEE Su (4.11)
where, aW aE aP
w Aw e Ae
aW aE S p
xWP xPE
ME555 : Computational Fluid Dynamics 7 I. Sezai Eastern Mediterranean University
1 2 3 4 5 6 7
A W P E B
xWP xPE
Special case: no source terms (S = 0), boundary values A ,B specified.
For the point near a west boundary (point 2):
P A
e Ae E P w Aw 0
xPE xWP
e
Ae w Aw P 0.W e Ae E w Aw A
xPE xWP xPE xWP
or, aPP aW W aEE Su
aW aE aP SP Su
e Ae A w Aw
0 aW aE S p w w
xPE xWP xWP A
ME555 : Computational Fluid Dynamics 8 I. Sezai Eastern Mediterranean University
4
1 2 3 4 5 6 7
qw
W P E B
xWP xP
No source terms (S = 0), heat flux qw specified at west boundary.
For the point near a west boundary (point 2):
e Ae E P qw Aw 0
xPE
e
Ae P 0.W e Ae E qw Aw
xPE xPE
or, aPP aW W aEE Su
aW aE aP SP Su
e Ae
0 aW aE S p 0 qw Aw
xPE
ME555 : Computational Fluid Dynamics 9 I. Sezai Eastern Mediterranean University
qB
2) Add source contributions B P
5
Step 3: Solution of equations
Discretised equations of the form (4.11)
6
Subtract (a3/d2) times row 1 from row 2 obtain 0 in a3 position.
a3
d3 d3 c2 Note: c2 is not altered
d2
b b a3 b
3 3 2
d2
In general
ai
di di ci 1
di 1
b b ai b (3 i n 1)
i i i 1
di 1
At the end of the forward elimination phase, the form of the system
is as follows:
ME555 : Computational Fluid Dynamics 13 I. Sezai Eastern Mediterranean University
d2 c2 2 b2
d3 c3 b
3 3
d4 c4 4 b4
di ci i bi
d n2 cn 2 n 2 bn 2
d n 1 n 1 bn 1
Of course, the bis and dis are not as they were at the beginning of this process, but
the cis are. The back substitution phase solves for n1, n2,, 2 as follows:
b
n 1 n 1
d n 1
1
n 2 (bn 2 cn 2n 1 )
d n 2
In general
1
i (bi cii 1 ) (i n 2, n 3, ......., 2
di
ME555 : Computational Fluid Dynamics 14 I. Sezai Eastern Mediterranean University
7
Use single dimensioned arrays (ai), (di), (ci), (bi)
Store the solution in array (i).
subroutine Tri(n, a, d, c, b, )
real array a(n), d(n), c(n), b(n), (n)
integer i, n
real mult ! (multiplier)
for i = 3 to n1 do
mult ai/di1
di di (mult)ci1
bi bi (mult)bi1
end for
n1 bn1/dn1
for i = n2 to 2, step 1 do
i (bi cii+1)/di
end for
end subroutine Tri
ME555 : Computational Fluid Dynamics 15 I. Sezai Eastern Mediterranean University
d dT
Governing equation k S 0
dx dx
k , T, S = heat generation per unit volume
Consider the problem of source-free heat conduction in an insulated
rod whose ends are maintained at constant temperatures of 100 oC and
500 oC respectively. Calculate the steady state temperature in the rod.
Take thermal conductivity k = 1000 W/mK, cross-sectional area A =
10103
In this case, S = 0
8
Solution: Let us divide the rod into 5 equal control volumes (CVs).
Rules for grid generation:
1) Locations of the CV faces are defined first.
2) Then nodal points are placed at the centers of the CVs.
3) Numbering starts from the boundary node at left.
4) All CVs have a volume of x.A
5) Inter-nodal distances are equal to x, (xWP = xPE = x)
6) Near west boundary (node 2), xWP = x/2
7) Near east boundary (node 6), xPE = x/2
1 2 3 4 5 6 7
TA TB
x/2 x x x/2
ME555 : Computational Fluid Dynamics 17 I. Sezai Eastern Mediterranean University
1 2 3 4 5 6 7
W P E (4.8)
A B
x
xPW xP
For interior nodes (nodes 3-5): E (4.9)
P W
e Ae E P w Aw 0
xPE xWP
e (4.10)
Ae w Aw TP w Aw TW e Ae TE
xPE xWP xWP xPE
or, aPTP aW TW aETE (4.11)
where, aW aE aP
w Aw e Ae
aW aE S p
xWP xPE
ME555 : Computational Fluid Dynamics 18 I. Sezai Eastern Mediterranean University
9
(4-11)
xPW xP
E
aW aE aP Sp Su
Interior nodes (nodes 3-5):
w Aw e Ae
Su = 0, Sp = 0, = k aW aE S p 0 0
xWP xPE
aW aE aP Sp Su
For boundary node 2: e Ae kA kA
0 aW aE S p TA
xPE xWP xWP
aW aE aP Sp Su
For boundary node 6: w Aw kA kA
0 aW aE S p TB
xWP xPE xPE
ME555 : Computational Fluid Dynamics 19 I. Sezai Eastern Mediterranean University
10
The solution is:
T1 100
T 140
2
T3 220
T4 300
T5 380
T6 460
T 500
7
Homework 1:
Write a computer program to find the temperature distribution in
the problem given in Example 1. Use 5 control volumes.
Use the algorithm given in the Pseudo program to find the aE
coefficients and source terms in 1-D Diffusion Problems given in
page 34 of the lecture notes.
11
ME555 : Computational Fluid Dynamics 23 I. Sezai Eastern Mediterranean University
d d
The general equation is: S 0
dx dx
= T, = k, Su = qV Sp = 0 where, V = Ax
xPW xP
E
Solution is similar to the previous example.
ME555 : Computational Fluid Dynamics 24 I. Sezai Eastern Mediterranean University
12
(4-11)
General equation: aPP aW W aEE Su
1 2 3 4 5 6 7
A W P E B
x
xPW xP
E
Node number 2 3 4 5 6
13
ME555 : Computational Fluid Dynamics 27 I. Sezai Eastern Mediterranean University
The governing d dT d dT 2
kA hP(T T ) 0 or n (T T ) 0
equation is: dx dx dx dx
hP
d d where n2
The general equation is: ( ) S 0 kA
dx dx S V Su S pP
Comparing the above equations, V = Ax
= T, = 1, Su = n2TV Sp = n2V
1 2 3 4 5 6 7
TB W P E
x q=0
xPW xP
E
Solution is similar to the previous example. Find coefficients of
aPP aW W aEE Su
ME555 : Computational Fluid Dynamics 28 I. Sezai Eastern Mediterranean University
14
(4-11)
aW aE aP Sp Su
For boundary e Ae w Aw w Aw
0 aW aE S p n 2 V n 2 VT TB
node 2: xPE x / 2 x / 2
aW aE aP Sp Su
For boundary node 6: w Aw
0 aW aE S p n 2 V n 2 VT
xWP
ME555 : Computational Fluid Dynamics 29 I. Sezai Eastern Mediterranean University
The solution is
T1 100
T 64.22
2
T3 36.91
T4 26.50
T5 22.60
T6 21.30
T 21.30
7
15
Comparison with the analytical solution
Node
2
3
4
5
6
Maximum
error: 2.08%
16
Homework 2:
Write a computer program to find the temperature distribution in the
rod in example 4.3. Compare the results obtained using 10 and 50
points on a graph. Use the algorithm given in the pseudo program
appearing in the following slide.
Pseudo Program to Find aE Coefficients and Source Terms in 1-D Diffusion Problems
Main program
call grids
call internal_coefficients
call boundary_coefficients
call ap_coefficient
call tdma
end program
subroutine grids
for i = 2 to N1
Find xw(i), xe(i)
end for
end subroutine grids
subroutine internal_coefficients
for i = 2 to N1
Aw Ae
aW (i ) ; aE (i ) ; S p (i ) n 2 V , Su (i ) n 2 VT
xw (i ) xe (i )
end for
end subroutine internal_coefficients)
ME555 : Computational Fluid Dynamics 34 I. Sezai Eastern Mediterranean University
17
subroutine boundary_coefficients (overwrite on near-boundary coefficients)
for i = 2 (west boundary)
Su (i ) Su (i ) aw (i )TB
Sp(i ) Sp(i) aw (i )
aw(i) = 0
end for
for i = N1 (east boundary)
no corrections are needed for Su and Sp since qe = 0 ( Su (i) Su (i) qe Ae )
ae(i) = 0
end for
end subroutine boundary_coefficients
subroutine a_p coefficient
for i = 2 to N1
ap(i) = aw(i) + ae(i) Sp(i)
end for
end subroutine a_p coefficient
ME555 : Computational Fluid Dynamics 35 I. Sezai Eastern Mediterranean University
18
x x dx dy y y dx dy S dV 0
V V V
e Ae w Aw n An s As S V 0
x e x w y n y s (4.53)
Equation (4.53) represents a balance of the generation of in a CV and the fluxes
through its cell faces
P W
Flux across the west face w Aw w Aw
x w xWP
Flux across the east face e Ae e Ae E P
x e xPE
Flux across the south face s As s As P S
y s ySP
P
Flux across the north face n An n An N
y n yPN
ME555 : Computational Fluid Dynamics 37 I. Sezai Eastern Mediterranean University
w Aw e Ae s As n An
S p P
xWP xPE ySP yPN
A A A A
w w W e e E s s S n n N Su
xWP xPE ySP yPN
19
Finite Volume Method for Three-dimensional Diffusion Problems
Steady state diffusion in a 3D situation is governed by
S 0 (4.58)
x x y y z z
A typical control volume is shown below.
aW aE aS aN aB aT aP
w Aw e Ae s As n An b Ab t At aW aE aS aN
xWP xPE ySP yPN zBP yPT aB aT S p
ME555 : Computational Fluid Dynamics 40 I. Sezai Eastern Mediterranean University
20
Summary of Discretized Equations for Diffusion Problems
aPP anbnb Su
aP anb S p
source terms: S V Su S pP
aW aE aS aN aB aT aP
w Aw e Ae
1D aW aE S p
xWP xPE
w Aw e Ae s As n An aW aE aS aN
2D
xWP xPE ySP yPN S p
w Aw e Ae s As n An b Ab t At aW aE aS aN
3D
xWP xPE ySP yPN z BP yPT aB aT S p
21
For a point P: aPP aW W aEE aSS aN N b
This is similar
to the TDMA aii 1 dii ci j 1 bi
equation
Procedure:
1) Solve along e-w direction along the line for i = 2, 3,, n1
using TDMA
2) Move to the next e-w line
3) Repeat step 1-2.
22
Application of the TDMA method to three-dimensional problems
For 3-D problems the TDMA method is applied line by line on a selected plane and
then the calculation is moved to the next plane.
Example:
Consider a 2D plate
Thickness = 1cm, k = 1000W/m/K
Calculate the temperature distribution
T = 100 oC
0.4 m
qw =500
insulated
kW/m2
0.3 m
insulated
ME555 : Computational Fluid Dynamics 46 I. Sezai Eastern Mediterranean University
23
T = 100 oC
j=5 y(5)
yn(4)
j=4 y(4)
xw(3) xe(3)
qw = 500kW/m2 insulated
ys(4)
j=3 y(3)
x(2) x(3) x(4)
Aw Ae As An yn
aW ; aE ; aS ; aN
xw xe xs xn xw xe
y
aP aW aE aS aN S p S p 0, Su 0
ys
x
ME555 : Computational Fluid Dynamics 48 I. Sezai Eastern Mediterranean University
24
After finding aP, aE,aW,aN,aS coefficients follow the following steps
1) Solve the general equation using TDMA along j = 2 line (nodes
(2, 2, (3, 2), and (4, 2))
aW TW aPTP aETE aS TS aN TN Su
unknowns Initially unknown, but set
them to zero
Temperatures along j = 2 are solved (Horizontal sweep)
2) Use TDMA along j = 3 line (nodes (2, 3), (3, 3) and (4, 3))
aW TW aPTP aETE aS TS aN TN Su
Known from Initially was set to
3) Repeat until j = 5 line previous iteration zero
4) Use TDMA along i = 2 line
Vertical sweep
5) Repeat until i =4 line
6) Go to step 1
ME555 : Computational Fluid Dynamics 49 I. Sezai Eastern Mediterranean University
and
r (i, j ) aW (i, j )T (i 1, j ) aE (i, j )T (i 1, j )
aS (i, j )T (i, j 1) aN (i, j )T (i, j 1)
Su (i, j ) aP (i, j )T (i, j )
ME555 : Computational Fluid Dynamics 50 I. Sezai Eastern Mediterranean University
25
Fast Iterative Solvers for Linear Systems of Equations
Apart from TDMA, there are other iterative methods for solving the
system of equations. Unlike TDMA, which solves the problem line
by line, these iterative methods solves all equations simultaneously.
As a result these methods are faster than TDMA. Some of the fast
iterative methods are
1) SIP (strongly implicit procedure)
2) MSIP (modified SIP)
3) CG (Conjugate gradient method)
4) BiCGSTAB (bi-conjugate gradient stabilized method)
CG method is used for solving linear systems of equations which
have a symmetric coefficient matrix. All other methods mentioned
above are used for systems of equations involving non-symmetric
coefficient matrices.
ME555 : Computational Fluid Dynamics 51 I. Sezai Eastern Mediterranean University
Homework 3:
Write a computer program to find the temperature distribution in the
2-D plate problem given in the previous example. Use the algorithm
given in the pseudo program on the next page. (a) Use 5x6 grids (b)
51x51 grids and plot the temperature contours.
qw =500 0.4 m
insulated
kW/m2
0.3 m
insulated
ME555 : Computational Fluid Dynamics 52 I. Sezai Eastern Mediterranean University
26
Pseudo Program to Solve the 2D Plate Problem
Main program
call grids
call internal_coefficients
call boundary_coefficients
call boundary_values
call ap_coefficient
for iter = 1 to itermax
call solver
call boundary_values
call residual
(check if residual is below a desired value)
end for
call print
end program
subroutine grids
for i = 2 to N1
Find xw(i), xe(i), x(i)
end for
for j = 2 to M1
Find ys(j), yn(j), y(j)
end for
Update near boundary values of xw(i), xe(i), ys(j), yn(j)
end subroutine grids
subroutine internal_coefficients
for i = 2 to N1 and j = 2 to M1
Aw Ae As An
aW (i, j ) ; aE ; aS ; aN
xw (i) xe (i ) xs ( j ) xn ( j )
S p (i, j ) 0, Su (i, j ) 0
end for
end subroutine internal_coefficients
27
subroutine boundary_coefficients (overwrite on near-boundary coefficients)
for i = 2 and j = 2 to M1 (!west boundary)
Su (i, j ) Su (i, j ) qw Aw
aW(i, j) = 0
end for
for i = N1 and j = 2 to M1 (!east boundary)
aE(i, j) = 0
end for
subroutine ap_coefficient
for i = 2 to N1 and j = 2 to M1
aP(i, j) = aW(i, j) + aE(i, j) + aS(i, j) + aN(i, j) sP(i, j)
end for
end subroutine ap_coefficient
Subroutine solver
Call horizontal_sweep
Call vertical_sweep
End subroutine solver
Subroutine horizontal_sweep
for j = 2 to M1
Calculate a(i), d(i), c(i), b(i) for TDMA for solving x(i) values along a
horizontal line for i = 2 to N1
call TDMA(a,d,c,b,x,N)
transfer values of x(i) to T(i, j) along a horizontal line for i = 2 to N1
end for
end subroutine horizontal_sweep
ME555 : Computational Fluid Dynamics 56 I. Sezai Eastern Mediterranean University
28
Subroutine vertical_sweep
for i = 2 to N-1
calculate a(j), d(j), c(j), b(j) for TDMA for solving x(j) values along a vertical line for j
= 2 to M-1
call TDMA(a,d,c,b,x,M)
transfer values of x(j) to T(i, j) along a horizontal line for j = 2 to M-1
end for
end subroutine vertical_sweep
SUBROUTINE PRINT !For contour plot of temperature using TECPLOT
OPEN (UNIT=15,FILE="txy.dat")
WRITE(15,*)'TITLE = "T data on XY plane,',N,',',M,' " '
WRITE(15,*)'VARIABLES = "X", "Y", "T" '
WRITE(15,*)'ZONE I=',N,' J=',M,' F=POINT'
DO J=1,M
DO I=1,N
WRITE (15,*) XCOOR(I,J),YCOOR(I,J),T(I,J)
END DO
END DO
CLOSE (15)
END SUBROUTINE PRINT
ME555 : Computational Fluid Dynamics 57 I. Sezai Eastern Mediterranean University
SUBROUTINE BOUNDARY_VALUES
! top
J=M
DO I=1,N
T(I,J)=100
END DO
! left
I=1
DO J=1,M-1
T(I,J)=Q*DXW(I+1)/COND+T(I+1,J)
END DO
! RIGHT
I=N
DO J=1,M-1
T(I,J)=T(I-1,J)
END DO
! BOTTOM
J=1
DO I=1,N
T(I,J)=T(I,J+1)
END DO
END SUBROUTINE BOUNDARY_VALUES
29