The Finite Volume Method For Diffusion Problems: Div U Div Grad S T
The Finite Volume Method For Diffusion Problems: Div U Div Grad S T
P f D
Prof. Dr. Ib
Ibrahim
hi SSezaii
Department of Mechanical Engineering
Eastern Mediterranean University
Fall 2010-2011
Introduction
1
Finite Volume Method for One-dimensional Steady State Diffusion
Steady-state diffusion of a
general property φ in one-
di
dimensional
i lddomaini iis
d dφ
(Γ ) + Sφ = 0
dx dx
S 11: G
Step Grid
id generation:
i
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 2Δx
⎛ ∂φ ⎞ φ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 pφP (4.8)
Substituting (4.6), (4.7) and (4.8) into (4.4)
⎛ φ −φ ⎞ ⎛ φP − φW ⎞
Γ e Ae ⎜ E P ⎟ − Γ w Aw ⎜ ⎟ + ( Su + S pφP ) = 0 (4 9)
(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
or, aPφP = aW φW + aEφE + 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 δxP
E
0) boundary values φA ,φB specified.
Special case: no source terms (Sφ = 0), 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, aPφP = aW φW + aEφE + 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),
0) heat flux qw specified at west boundary.
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, aPφP = aW φW + aEφE + 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 ⎠
⎨
⎪ ⎛ a3 ⎞
⎪b3 ← b3 − ⎜ d ⎟ b2
⎩ ⎝ 2⎠
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 n−2 cn − 2 ⎥ ⎢φn − 2 ⎥ ⎢bn − 2 ⎥
⎢ ⎥⎢ ⎥ ⎢ ⎥
⎢⎣ d n −1 ⎥⎦ ⎢⎣φn −1 ⎥⎦ ⎢⎣ bn −1 ⎥⎦
Of course, the bi’s and di’s are not as they were at the beginning of this process, but
the ci’s are. The back substitution phase solves for φn–1, φn–2,…, φ2 as follows:
b
φn −1 ← n −1
d n −1
1
φn −2 ← (bn − 2 − cn −2φn −1 )
d n −2
In general
1
φi ← (bi − ciφi +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,
i n
real mult ! (multiplier)
for i = 3 to n–1 do
mult ← ai/di–1
di ← di – (mult)ci–1
bi ← bi – (mult)bi–1
end for
φn–1 ← bn–1/dn–1
for i = n–2 to 2, step –1 do
φi ← (bi – ciφi+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 =
10×10–3
In this case, S = 0
8
Solution: Let us divide the rod into 5 equal control volumes (CV’s).
Rules for grid generation:
1) Locations of the CV faces are defined first.
2) Then nodal points are placed at the centers of the CV
CV’ss.
3) Numbering starts from the boundary node at left.
4) All CV’s 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
N east bboundary
d ((node
d 6)
6), δx
δ PE = δx/2
δ /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 in Fortran language to find the
temperature distribution in the problem given in Example 1. Use 5
control volumes.
Use the algorithm given in the “Pseudo
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 ⎠
δ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: aPφP = aW φW + aEφE + 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 ggeneral equation
q is: (Γ ) + Sφ = 0 kA
d
dx dx
d S ΔV = Su + S pφP
Comparing the above equations, ΔV = AΔx
φ = T, Γ = 1, Su = n2T∞ΔV Sp = –n2ΔV
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
aPφP = aW φW + aEφE + Su
ME555 : Computational Fluid Dynamics 28 I. Sezai – Eastern Mediterranean University
14
(4-11)
aW aE aP Sp Su
For boundary
b d Γ 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 ⎤
⎢ ⎥ ⎢ 64 22 ⎥
⎢T2 ⎥ ⎢ 64.22 ⎥
⎢T3 ⎥ ⎢ 36.91⎥
⎢ ⎥ ⎢ ⎥
⎢T4 ⎥ = ⎢ 26.50 ⎥
⎢T5 ⎥ ⎢ 22.60 ⎥
⎢ ⎥ ⎢ ⎥
⎢T6 ⎥ ⎢ 21.30 ⎥
⎢ ⎥ ⎢ 21 30 ⎥
⎣T7 ⎦ ⎣ 21.30 ⎦
15
Comparison with the analytical solution
Node
2
3
4
5
6
Maximum
error: 2.08%
16
Homework 2:
Write a Fortran 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 app_coefficient
call tdma
end program
subroutine grids
for i = 2 to N–1
Find δxw(i), δxe(i)
end for
end subroutine grids
subroutine internal_coefficients
for i = 2 to N–1
Γ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 = N–1 (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
boundary_coefficients
coefficients
subroutine a_p coefficient
for i = 2 to N–1
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
i l controll volume
l is
i shown
h below.
b l
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
aPφP = ∑ anbφnb + Su
aP = ∑ anb − S p
source terms: S ΔV = Su + S pφP
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: aPφP = aW φW + aEφE + aSφS + aN φN + b
This is similar
to the TDMA aiφi −1 + diφi + ciφ j +1 = bi
equation
Procedure:
1)) Solve alongg e-w direction alongg the line for i = 2, 3,…, n–1
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)
Δ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 in Fortran language 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 countours.
Thickness = 1cm, k = 1000W/m/K
T = 100 oC
qw =500 04m
0.4
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
ll boundary_values
b d l
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 N–1
Find δxw(i), δxe(i), δx(i)
end for
for j = 2 to M–1
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 N–1 and j = 2 to M–1
Γ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 M–1 (!west boundary)
Su (i, j ) = Su (i, j ) + qw Aw
aw(i, j) = 0
end for
for i = N–1 and j = 2 to M–1 (!east boundary)
ae(i, j) = 0
end for
subroutine ap_coefficient
for i = 2 to N–1 and j = 2 to M–1
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 M–1
Calculate a(i), d(i), c(i), b(i) for TDMA for solving x(i) values along a
horizontal line for i = 2 to N–1
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 N–1
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
I 1N
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
J=1
DO I=1,N
T(I,J)=T(I,J+1)
END DO
END SUBROUTINE BOUNDARY_VALUES
29