Вы находитесь на странице: 1из 29

# Chapter 4:

Problems

## Prof. Dr. Ibrahim Sezai

Department of Mechanical Engineering
Eastern Mediterranean University

Fall 2010-2011

Introduction

## General transport equation is

( )
div( u ) div(grad ) S
t
Control volume integration gives

CV CV A CV

## ME555 : Computational Fluid Dynamics 2 I. Sezai Eastern Mediterranean University

1
Finite Volume Method for One-dimensional Steady State Diffusion

general property in one-
dimensional domain is

d d
( ) S 0
dx dx

## ME555 : Computational Fluid Dynamics 3 I. Sezai Eastern Mediterranean University

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

## To find expressions at the east and west faces, use

Taylor series approximations

2 x 2
( x x ) ( x ) x 2
x x x x 2

## ME555 : Computational Fluid Dynamics 4 I. Sezai Eastern Mediterranean University

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
x P 2x

E P
At the east face
x e x
ME555 : Computational Fluid Dynamics 5 I. Sezai Eastern Mediterranean University

## Rewriting the diffusion equation for an interior point P:

d d
dx dx dV S dV 0
V V

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

## For a one-dimensional CV of width x near boundary B:

1) Set coefficient aB(i) = 0 (i P) x

qB
2) Add source contributions B P

## (a) Fixed value B:

k B AB
x / 2
k A
S p B B aB
x / 2
to the source terms Su and Sp
(b) Fixed flux qB:
Add qBAB in the form of Su + SpP to the source terms Su and Sp.
ME555 : Computational Fluid Dynamics 10 I. Sezai Eastern Mediterranean University

5
Step 3: Solution of equations
Discretised equations of the form (4.11)

## must be set up at each nodal point.

We obtain a system of linear algebraic equations
Solve the system for values
Use any matrix solution method.
e.g. Tri-diagonal matrix algorithm.
ME555 : Computational Fluid Dynamics 11 I. Sezai Eastern Mediterranean University

## Tridiagonal Matrix Algorithm

Consider a system of equations that has a tridiagonal form
d 22 c23 b2
a32 d 33 c34 b3
a43 d 44 c45 b4
. . . . . . . .
aii 1 dii cii 1 bi
. . . . . .
an 2n 3 d n 2n 2 cn 2n 1 bn 2
an 1n 2 d n 1n 1 bn 1
In matrix form:
d2 c2 2 b2
a d3 c3 b
3 3 3
a4 d4 c4 4 b4

ai di ci i bi

an 2 d n2 cn 2 n 2 bn 2

an 1 d n 1 n 1 bn 1

## ME555 : Computational Fluid Dynamics 12 I. Sezai Eastern Mediterranean University

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

## Worked Examples: 1) One-dimensional steady state diffusion

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

## ME555 : Computational Fluid Dynamics 16 I. Sezai Eastern Mediterranean University

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)

## General equation: aPP aW W aEE Su

1 2 3 4 5 6 7
A W P E B
x

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

## aP2 aE2 T Su2

2
aW3 a p3 aE3
T3 Su3

aW4 a p4 aE4
T4 Su4

aWi a pi aE i
i T Su i

aWn2 a pn2 T
a E n 2 n 2 Su
T Su
n2

aWn1 a pn1 n 1 n 1

## Solve the system of equations using Tri-diagonal matrix algorithm

(TDMA) for T2, T3, Tn-1 , where (n = 7)
ME555 : Computational Fluid Dynamics 20 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

## Exact solution is:

Comparison of the numerical result with the
analytical solution.
T 800 x 100

## ME555 : Computational Fluid Dynamics 21 I. Sezai Eastern Mediterranean University

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.

## ME555 : Computational Fluid Dynamics 22 I. Sezai Eastern Mediterranean University

11
ME555 : Computational Fluid Dynamics 23 I. Sezai Eastern Mediterranean University

## The governing equation is: d dT

k q 0
dx dx

d d
The general equation is: S 0
dx dx

## Comparing the above equations, where S V Su S pP

= T, = k, Su = qV Sp = 0 where, V = Ax

## Take area A = 1 in the y-z plane

1 2 3 4 5 6 7
A W P E B
x

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

## Interior nodes (nodes 3-5): aW aE aP Sp Su

w Aw e Ae
x, Sp = 0, = k
Su = qA aW aE S p 0 x
qA
xWP xPE
aW aE aP Sp Su
For boundary node 2:
e Ae k w Aw kw Aw
0 aW aE S p x
qA TA
xPE xWP xWP
aW aE aP Sp Su
For boundary node 6: w Aw ke Ae ke Ae
0 aW aE S p x
qA TB
xWP xPE xPE
ME555 : Computational Fluid Dynamics 25 I. Sezai Eastern Mediterranean University

Node number 2 3 4 5 6

## The solution is:

T1 100
T 150
2
T3 218

T4 254
T5 258

T6 230
T 200
7
Comparison of the numerical result with the
analytical solution.
T T q
Exact solution is: T B A ( L x) x TA
L 2k
ME555 : Computational Fluid Dynamics 26 I. Sezai Eastern Mediterranean University

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)

## General equation: aPP aW W aEE Su

1 2 3 4 5 6 7
TB W P E
x q=0
xPW xP
E
Interior nodes (nodes 3-5): aW aE aP Sp Su
Su = n2VT, Sp = n2V, w Aw e Ae
aW aE S p n 2 V n 2 VT
=k xWP xPE

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

## ME555 : Computational Fluid Dynamics 30 I. Sezai Eastern Mediterranean University

15
Comparison with the analytical solution

Node

2
3
4
5
6

## Maximum error: 6.27%

The numerical solution can be improved by employing a
finer grid.
Consider the same problem, but use 10 control volumes.
Comparison of the results is given as follows
ME555 : Computational Fluid Dynamics 31 I. Sezai Eastern Mediterranean University

Maximum
error: 2.08%

## ME555 : Computational Fluid Dynamics 32 I. Sezai Eastern Mediterranean University

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.

## ME555 : Computational Fluid Dynamics 33 I. Sezai Eastern Mediterranean University

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

S 0
x x y y

## Integrating the above equation over the CV,

ME555 : Computational Fluid Dynamics 36 I. Sezai Eastern Mediterranean University

18

x x dx dy y y dx dy S dV 0
V V V

## Noting that Ae = Aw = y and An = As = x, we obtain:

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

## By substitution of the above expressions into eqn. (4.53) we obtain

E P P
e Ae w Aw P W n An N s As P S S V 0
xPE xWP yPN ySP
Substituting the linearised form of the source term S V Su S PP

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

## aPP aW W aEE aSS aN N Su

where
aW aE aS aN aP
Aw Ae y w Aw e Ae s As n An
aW aE aS aN S p
As An x xWP xPE ySP yPN
ME555 : Computational Fluid Dynamics 38 I. Sezai Eastern Mediterranean University

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.

## Integration of eqn (4.58) over the control volume gives

e Ae w Aw n An s As
x e x w y n x s

t At b Ab S V 0
z t z b
which can be discretized as
E P P
e Ae w Aw P W n An N s As P S
xPE xWP yPN ySP
P
t At T b Ab P B ( Su S p )P 0
z PT z BP
Rearranging aPP aW W aEE aSS aN N aBB aT T Su

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

## Line by line application of TDMA method

ME555 : Computational Fluid Dynamics 42 I. Sezai Eastern Mediterranean University

21
For a point P: aPP aW W aEE aSS aN N b

## a) Sweep direction: n-s

Rearranging aSS aPP aN N aW W aEE b W and E are known
from previous
iteration
This is similar
to the TDMA a j j 1 d j j c j j 1 b j
equation
Procedure:
1) Solve along n-s direction along the line for j = 2, 3,, n-1
using TDMA
2) Move to the next n-s line
3) Repeat step 1-2.
ME555 : Computational Fluid Dynamics 43 I. Sezai Eastern Mediterranean University

## Rearranging aW W aPP aEE aSS aN N b S and N are known

from previous iteration

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.

## ME555 : Computational Fluid Dynamics 44 I. Sezai Eastern Mediterranean University

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.

## To solve along e-w direction: aW W aPP aEE aSS aN N aBB aT T b

ME555 : Computational Fluid Dynamics 45 I. Sezai Eastern Mediterranean University

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

## (1, 6) (2, 6) (3, 6) (4, 6) (5, 6)

(M=6) j = 6

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)

## (1, 2) (2, 2) (3, 2) (4, 2) (5, 2)

j=2 y(2)
(1, 1) (2, 1) (3, 1) (4, 1) (5, 1)
j=1
i=1 i=2i=3 i = 4 i = 5 (N=5)
insulated
First draw control volumes, with equal spacings
Then, place nodes at the center of the control volumes.
x = Lx/N 2 = 0.3/(5 2 ) = 0.1, y = Ly/M 2 = 0.4/(6 2 ) = 0.1
ME555 : Computational Fluid Dynamics 47 I. Sezai Eastern Mediterranean University

## The governing equation is

T T
0 ( k )
x x y y
which can be discretised as
aPTP aW TW aETE aS TS aN TN Su

## This equation is written for each node (i, j) in the domain

aP (i, j )T (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 )

## For interior points: (i = 2 4, j = 2 6)

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

## 7) Repeat steps 1-6 until scaled residual norm becomes R where

= tolerance (use = 1.E6)
r
R
aP (i, j )TP (i, j )
j i

## r r (i, j ) (Note the absolute value sign)

j i

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)
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.

## Thickness = 1cm, k = 1000W/m/K

T = 100 oC

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

## ME555 : Computational Fluid Dynamics 53 I. Sezai Eastern Mediterranean University

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

## ME555 : Computational Fluid Dynamics 54 I. Sezai Eastern Mediterranean University

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

## for i = 2, N1 and j = 2 (!south boundary)

aS(i, j) = 0
end for
for i = 2, N1 and j = M1 (!north boundary)
Su(i, j) = Su(i, j) +an(i, j)*Tnorth
Sp(i, j) = Sp(i, j) an(i, j)
aN(i, j) = 0
end for
end subroutine boundary coefficients
ME555 : Computational Fluid Dynamics 55 I. Sezai Eastern Mediterranean University

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