Sei sulla pagina 1di 21

Applications Parabolic Equation

One-Dimensional Conduction (Diffusion) Equation


The one-dimensional linear conduction equation can be written
as
2
2
x
u
t
u

(1)
where
u
is the conducted property and 0 > is the constant
diffusivity.
1. Forward in Time Central in Space (FTCS) Explicit Method
( )
( )
( ) ( ) [ ]
2
2
1 1
1
, ,
2
x t O
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i

+
+

or
( )
( )
( ) ( ) ( ) [ ]
2
1 1
2
1
, , 2 x t O u u u
x
t
u u
n
i
n
i
n
i
n
i
n
i
+

+
+
+

(2)
The modified equation for this scheme can be derived as
( ) ( )
( ) ( ) ( ) ( )
+
1
]
1

+
1
]
1


xxxxxx
xxxx xx t
u
x x t t
u
x t
u u
360 12 3
12 2
4 2 2 2 3
2 2

If
( ) ( )
6
1
/
2
r x t
, then the truncation error is zero. There
are no odd derivative terms in the truncation error so no
dispersion error is introduced. The amplification factor can
be derived as
( ) cos 1 2 1 r G
from which it can be deduced that this scheme is
conditionally stable for ( ) ( ) 2 / 1 /
2
x t r
2. Central in Time Central in Space (CTCS) Explicit Method
it is also known as the Richardson Method
( )
( )
( ) ( ) [ ]
2 2
2
1 1
1 1
, ,
2
2
x t O
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i

+
+

(3)
Page 1 of 21
Even though it is second-order accurate in time and space,
it is unconditionally unstable.
3. The DuFort-Frankel Explicit Method
It is a modification of the Richardson method where
n
i
u in
the right hand side of Eq. (3) is replaced by
( )
2
1 1 +
+
n
i
n
i
u u
.
Thus
( )
( )
2
1
1 1
1
1 1
2
2
2
x
u
u u
u
t
u u
n
i
n
i
n
i n
i
n
i
n
i

+
+

+
+

from which
( )
( )
( )
( )
( )
( )
[ ]
n
i
n
i
n
i
n
i
u u
x
t
u
x
t
u
x
t
1 1
2
1
2
1
2
2

2
1
2
1
+
+
+

+
1
]
1


1
]
1


(4)
The method is ( ) ( )
2
2 2
, ,

,
_


x
t
x t O and is unconditionally
stable.
The values of
i
u
at time levels
n
and 1 n are required to
start the computation. Therefore, either two sets of data
must be specified, or, from a practical point of view, a one-
step method can be used as a starter. Of course, for the
one-step (in t ) starter solution, only one set of initial
data, say at 1 n , is required to generate the solution at
n
.
With the values of
i
u
at 1 n and
n
specified, the DuFort-
Frankel method can be used. Two points about this
scheme must be kept in mind. First, the accuracy of the
solution provided by the DuFort-Frankel method is affected
by the accuracy of the starter solution. Second, since the
solution at the unknown station requires data from two
previous station, computer storage requirements will
increase.
4. Forward in Time Central in Space (FTCS) Implicit Method
It is also known as the Lassonen method. The finite
difference equation is given as
Page 2 of 21
( )
( )
( ) ( ) [ ]
2
2
1
1
1 1
1
1
, ,
2
x t O
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i

+
+
+ +

which can be rearranged as


i
n
i i
n
i i
n
i i
d u c u b u a + +
+
+
+ +

1
1
1 1
1
(5)
where
( )
( )
2
x
t
a
i



,
( )
( )
2
2
x
t
b
i


,
( )
( )
2
x
t
c
i



, and
n
i i
u d .This will
yield a tridiagonal system which can be solved by the
Thomas algorithm.
The modified equation for this scheme can be derived as
( ) ( )
( ) ( ) ( ) ( )
+
1
]
1


+

+

+
1
]
1


xxxxxx
xxxx xx t
u
x x t t
u
x t
u u
360 12 3
12 2
4 2 2 2 3
2 2

There are no odd derivative terms in the truncation error so


no dispersion error is introduced. The amplification factor
can be derived as
( ) cos 1 2 1
1
+

r
G
from which it can be deduced that this scheme is
unconditionally stable.
5. Crank-Nicolson Method
If the diffusion term in Eq. (1) is replaced by the average of
the central differences at time levels
n
and 1 + n the
discretized equation would be of the form
( )
( )
( )
( ) ( ) [ ]
2 2
2
1 1
2
1
1
1 1
1
1
, ,
2
2
2
1
x t O
x
u u u
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i
n
i
n
i
n
i

1
]
1

+
+

+
+
+
+ +

(6)
Page 3 of 21
Note that the left side of the Eq. (6) is a central difference of
step
( )
2
t
, i.e.,
( )
2
2
1
t
u u
t
u
n
i
n
i

+
which is ( ) [ ]
2
t O . In terms of the grid points (see Figure
above) the left side can be interpreted as the central
difference representation of
t
u

at point A, while the right


side is the average of the diffusion term at the same point.
The method may be thought of as the addition of two step
computations as follows. Using the explicit method,
( )
( )
2
1 1
1
2
2
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i

+
+

while using the implicit method,


( )
( )
2
1
1 1
1
1
2
2
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i

+
+
+ +

Eq. (6) can be rearranged as


i
n
i i
n
i i
n
i i
d u c u b u a + +
+
+
+ +

1
1
1 1
1
where
( )
( )
2
2 x
t
a
i


,
( )
( )
2
1
x
t
b
i

+

,
( )
( )
2
2 x
t
c
i


, and
( )
( )
( )
n
i
n
i
n
i
n
i i
u u u
x
t
u d
1 1
2
2
2
+
+

+

which will produce a tridiagonal system and can be solved
by the Thomas algorithm.
Page 4 of 21
The modified equation for this scheme can be derived as
( )
( ) ( )
+
1
]
1


xxxxxx
xxxx xx t
u
x t
u
x
u u
360 12
12
4 2 3
2

and the amplification factor is found to be


) cos 1 ( 1
) cos 1 ( 1

r
r
G
which is always less than 1 and hence the scheme is
unconditionally stable.
6. The Beta (General) Formulation
A general formula for the finite difference equation for the
conduction equation can be written as
( )
( )
( )
( )
1
]
1

+
+

+
+
+
+ +

+
2
1 1
2
1
1
1 1
1
1
2
1
2
x
u u u
x
u u u
t
u u
n
i
n
i
n
i
n
i
n
i
n
i
n
i
n
i


(6)
where
1 0
is multiplication factor. When
0
the FTCS
explicit scheme is obtained, when, the Crank-Nicolson
scheme is recovered, while FTCS implicit scheme is
obtained for
1
. When
2 / 1
the truncation error is
( ) ( ) [ ]
2 2
, x t O , when
r 12 / 1 2 / 1
, and when
r 12 / 1 2 / 1
and
20 / 1 r the truncation error is ( ) ( ) [ ]
6 2
, x t O .
The modified equation for the general formulation can be
derived to be
( )
( )
( ) ( ) ( )
( )
+
1
]
1

,
_

,
_

+ +
1
]
1

,
_


xxxxxx
xxxx xx t
u
x
x t t
u
x
t u u
360

2
1
6
1
3
1

12 2
1
4
2 2 2 3 2
2
2


The scheme is unconditionally stable if
1
2
1

and for the
case
2
1
0
, the scheme is stable if
4 2
1
0

r
.
Page 5 of 21
Application for One-Dimensional Conduction
(Diffusion) Equation
Consider a fluid bounded by two parallel plates extended to
infinity such that no end effects are encountered. The planer
walls and the fluid are initially at rest. Now the lower wall is
suddenly accelerated in the
x
-direction as shown in the figure.
A spatial coordinate system is selected such that the lower wall
includes the
xz
-plane to which the
y
-axis is perpendicular. The
spacing between the two plates is denoted by h.
The governing PDE for this problem is
2
2
y
u
t
u

where

is the kinematic viscosity of the fluid. It is required to


compute the velocity profile
( ) y t u u ,
. The initial and boundary
conditions are
0
) 0 , 0 ( U u
,
0 ) , 0 ( y u
,
0
) 0 , ( U t u
, and
0 ) , ( h t u
.
The analytical series solution for this problem can be expressed
as

,
_

,
_

h
y
n e
n h
y
U
u
t n
n

s i n
1 2
1
*
1
0
2 2
where
2
*
h
t
t

.
Page 6 of 21
The specific data are given as 000217 . 0 m
2
/s,
40
0
U
m/s, and
04 . 0 h m. A solution for
( ) y t u ,
is to be obtained up to 1.08 s.
The grid system you can use is shown in the sketch below. Use
001 . 0 y
m so that the maximum grid point number in the
y
-
direction, JM = 41.
Methods to be used
1. FTCS explicit scheme (use 002 . 0 t and 00232 . 0 )
2. DuFort-Frankel scheme (use 002 . 0 t and 003 . 0 )
3. FTCS implicit scheme (use 002 . 0 t and 01 . 0 )
4. Crank-Nicolson scheme (use 002 . 0 t and 01 . 0 )
For each method, compute the velocity profile at times 0.18 s,
0.36 s, 0.54 s, 0.72 s, 0.9 s, and 1.08 s. Plot these profiles for
each method for 002 . 0 t and comment on the effect of the
other t .
For the DuFort-Frankel method, the velocity profile at two
consecutive time levels (
0
u and
1
u ) are needed at the startup,
Page 7 of 21
but are not available. So you can calculate
1
u using the FTCS
explicit scheme for the first time step only, and then use DuFort-
Frankel scheme for the second and later time steps.
Also calculate the error between the exact solution and the
solution by each scheme at time 1.08 s with 002 . 0 t and plot
these errors as a function of
y
. The percent error can be
computed as
( ) ( )
( )
100
, 08 . 1
, 08 . 1 , 08 . 1
) (

analytical
computed analytical
y u
y u y u
y error
Page 8 of 21
Two-Dimensional Conduction (Diffusion) Equation
Consider the model equation
1
]
1

2
2
2
2
y
u
x
u
t
u

(7)
where

is the constant diffusivity. If the FTCS explicit scheme


is used to discretized this equation, we get
( )
( ) ( )
1
1
]
1

+
+

+ +
+
2
1 , , 1 ,
2
, 1 , , 1 ,
1
,
2 2
y
u u u
x
u u u
t
u u
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i

which is ( ) ( ) ( ) [ ]
2 2
, , y x t O . The method is stable if
( )
( )
( )
( ) 2
1
2 2

y
t
x
t
Let
( )
( )
2
x
t
r
x


and
( )
( )
2
y
t
r
y


, then the stability requirement can be
expressed as
2
1
+
y x
r r
. To make any comparison with the one-
dimensional case, let us make
( ) ( ) y x
so that
r r r
y x

in which
case the stability requirement becomes
4
1
r
, which is twice as
restrictive as the one-dimensional case. Such a severe
restriction on the time step size makes explicit formulation
inefficient.
Consider the FTCS implicit formulation for which the FDE is
( )
( ) ( )
1
1
]
1

+
+

+
+
+ +

+
+
+ +

+
2
1
1 ,
1
,
1
1 ,
2
1
, 1
1
,
1
, 1 ,
1
,
2 2
y
u u u
x
u u u
t
u u
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i

from which
( )
n
j i
n
j i y
n
j i y
n
j i y x
n
j i x
n
j i x
u u r u r u r r u r u r
,
1
1 ,
1
1 ,
1
,
1
, 1
1
, 1
2 2 1 + + + + +
+
+
+

+ +
+
+

This will yield a pentadiagonal system whose solution is again


very time consuming and hence this scheme is also not vey
useful. One way to overcome this is to use a splitting method
which is known as the Alternating Direction Implicit (ADI)
method. The algorithm produces two sets of tridiagonal systems
to be solved in sequence. The FDEs can be written as
( )
( ) ( )
1
1
1
]
1

+
+

+
+
+
+ +

+
2
1 , , 1 ,
2
2
1
, 1
2
1
,
2
1
, 1 ,
2
1
,
2 2
2
y
u u u
x
u u u
t
u u
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i

and
Page 9 of 21
( )
( ) ( )
1
1
1
]
1

+
+

+
+
+ +

+
+
+ +

+
+
2
1
1 ,
1
,
1
1 ,
2
2
1
, 1
2
1
,
2
1
, 1
2
1
,
1
,
2 2
2
y
u u u
x
u u u
t
u u
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i

These equations
can be rearranged as
( )
( )
n
j i
y n
j i y
n
j i
y
n
j i
x
n
j i x
n
j i
x
u
r
u r u
r
u
r
u r u
r
1 , , 1 ,
2
1
, 1
2
1
,
2
1
, 1
2
1
2

2
1
2
+
+
+
+ +

+ +
+ +
(8)
and
( )
( )
2
1
, 1
2
1
,
2
1
, 1
1
1 ,
1
,
1
1 ,
2
1
2

2
1
2
+
+
+ +

+
+
+ +

+ +
+ +
n
j i
x
n
j i x
n
j i
x
n
j i
y n
j i y
n
j i
y
u
r
u r u
r
u
r
u r u
r
(9)
The solution procedure starts with the solution of the tridiagonal
system in Eq. (8) whose formulation is implicit in the
x
-direction
and explicit in the
y
-direction; thus the solution at this stage is
referred to as the
x
sweep (see figure below).
Solving the system in Eq. (8) gives the necessary data for the
right hand side of Eq. (9) which can solved next to get the
solution for the 1 + n time level. This is referred to as the
y

sweep.
Page 10 of 21
Approximate Factorization
Let us apply the Crank-Nicolson scheme to the two-dimensional
parabolic equation to obtain
( )
( ) ( )
( ) ( )
1
1
]
1

+
+

+
+

+
+

+ +
+
+
+ +

+
+
+ +

+
2
1 , , 1 ,
2
, 1 , , 1
2
1
1 ,
1
,
1
1 ,
2
1
, 1
1
,
1
, 1
,
1
,
2 2

2 2
2
1

y
u u u
x
u u u
y
u u u
x
u u u
t
u u
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i
n
j i

(10)
which is ( ) ( ) ( ) [ ]
2 2 2
, , y x t O , but the resulting system is
pentadiagonal and time consuming to solve.
Let
j i j i j i j i x
u u u u
, 1 , , 1 ,
2
2
+
+
(11)
and
1 , , 1 , ,
2
2
+
+
j i j i j i j i y
u u u u
(12)
Insering Eqs. (11) and (12) into Eq. 10 we get
( )
( ) ( ) ( ) ( )
1
1
]
1

+ + +
2
,
2
2
1
,
2
2
,
2
2
1
,
2
,
1
,
2
1
y
u
y
u
x
u
x
u
t
u u
n
j i y
n
j i y
n
j i x
n
j i x
n
j i
n
j i

or
( )
( ) ( )
( )
( ) ( )
n
j i
y
x n
j i
n
j i
y
x n
j i
u
y x
t
u
u
y x
t
u
,
2
2
2
2
,
1
,
2
2
2
2
1
,
2

2
1
1
]
1

+
1
1
]
1

+ +


or
( ) ( )
n
j i y y x x
n
j i y y x x
u r r u r r
,
2 2 1
,
2 2
2
1
1
2
1
1
1
]
1

+ +
1
]
1

+
+

(13)
Let us add
( )
n
j i
n
j i y x y x
u u r r
,
1
,
2 2
4
1

+

to the left hand side of Eq. (13).
This term is less than the truncation error of Eq. (13), so no
significant error is included. Thus, the approximate Crank-
Nicolson scheme becomes
Page 11 of 21
( )
( )
n
j i y x y x y y x x
n
j i y x y x y y x x
u r r r r
u r r r r
,
2 2 2 2
1
,
2 2 2 2
4
1
2
1
1
4
1
2
1
1
1
]
1

+ + +
1
]
1

+ +
+


This can be factored into
n
j i y y x x
n
j i y y x x
u r r
u r r
,
2 2
1
,
2 2
2
1
1
2
1
1
2
1
1
2
1
1

,
_

,
_

,
_

,
_

+


(14)
Let us now consider the ADI scheme which can be written as
( )
( ) ( )
1
1
1
]
1

+ +
2
,
2
2
2
1
,
2
,
2
1
,
2
y
u
x
u
t
u u
n
j i y
n
j i x
n
j i
n
j i

and
( )
( ) ( )
1
1
1
]
1

+
+ +
+
2
1
,
2
2
2
1
,
2
2
1
,
1
,
2
y
u
x
u
t
u u
n
j i y
n
j i x
n
j i
n
j i

Rearranging we get,
( )
( )
( )
( )
n
j i y
n
j i
n
j i x
n
j i
u
y
t
u u
x
t
u
,
2
2
,
2
1
,
2
2
2
1
,
2 2

+ +
and
( )
( )
( )
( )
2
1
,
2
2
2
1
,
1
,
2
2
1
,
2 2
+ +
+ +

n
j i x
n
j i
n
j i y
n
j i
u
x
t
u u
y
t
u

Or
n
j i y y
n
j i x x
u r u r
,
2
2
1
,
2
2
1
1
2
1
1
1
]
1

+
1
]
1

+
(15)
and
2
1
,
2 1
,
2
2
1
1
2
1
1
+
+
1
]
1

+
1
]
1

n
j i x x
n
j i y y
u r u r (16)
Eqs. (15) and (16) can be combined by eliminating 2
1
,
+ n
j i
u
,
resulting in
Page 12 of 21
n
j i y y x x
n
j i y y x x
u r r
u r r
,
2 2
1
,
2 2
2
1
1
2
1
1
2
1
1
2
1
1

,
_

,
_

,
_

,
_

+


(17)
which is same as Eq. (14). Thus, the ADI scheme is the
approximate factorization of the Crank-Nicolson scheme. The
ADI scheme retains the accuracy of the Crank-Nicolson scheme
( ) ( ) ( ) [ ]
2 2 2
, , y x t O since it is obtained by adding
( )
n
j i
n
j i y x y x
u u r r
,
1
,
2 2
4
1

+

which is smaller than the truncation error of
the Crank-Nicolson scheme. But instead of solving the
pentadiagonal system for the Crank-Nicolson scheme, ADI
method solves tridiagonal system.
Page 13 of 21
Fractional Step Methods
This method splits the multi-dimensional equation into a series
of one-dimensional equations and solves them sequentially. For
two-dimensional case, we have
( )
( ) ( )
1
1
1
]
1

+ +
2
,
2
2
2
1
,
2
,
2
1
,
2
1
2
x
u
x
u
t
u u
n
j i x
n
j i x
n
j i
n
j i

(18)
and
( )
( ) ( )
1
1
1
]
1

+
+
+
+
2
2
1
,
2
2
1
,
2
2
1
,
1
,
2
1
2
y
u
y
u
t
u u
n
j i y
n
j i y
n
j i
n
j i

(19)
Note that the Crank-Nicolson scheme is used sequentially in
each space direction. The scheme is unconditionally stable and
is ( ) ( ) ( ) [ ]
2 2 2
, , y x t O .
Extension to Three-Dimensions
The PDE for three-dimension is
1
]
1

2
2
2
2
2
2
z
u
y
u
x
u
t
u

(20)
The ADI method can be used in three-dimensional case by
considering time intervals of
n
,
,
3
1
+ n

,
3
2
+ n
and 1 + n . The
resulting equations are
( )
( ) ( ) ( )
1
1
1
]
1

+ +
2
, ,
2
2
, ,
2
2
3
1
, ,
2
, ,
3
1
, ,
3
z
u
y
u
x
u
t
u u
n
k j i z
n
k j i y
n
k j i x
n
k j i
n
k j i

(21)
Page 14 of 21
( )
( ) ( ) ( )
1
1
1
]
1

+ + + + +
2
3
1
, ,
2
2
3
2
, ,
2
2
3
1
, ,
2
3
1
, ,
3
2
, ,
3
z
u
y
u
x
u
t
u u
n
k j i z
n
k j i y
n
k j i x
n
k j i
n
k j i

(22)
( )
( ) ( ) ( )
1
1
1
]
1

+
+ + +
+
2
1
, ,
2
2
3
2
, ,
2
2
3
2
, ,
2
3
2
, ,
1
, ,
3
z
u
y
u
x
u
t
u u
n
k j i z
n
k j i y
n
k j i x
n
k j i
n
k j i

(23)
This method is ( ) ( ) ( ) ( ) [ ]
2 2 2
, , , z y x t O and is only conditionally
stable if
( )
2
3
+ +
z y x
r r r
. For this reason this method is not very
attractive. A method that is unconditionally stable and is
second-order accurate uses t he Crank-Nicolson scheme for
which the finite difference equations are
( )
( )
( ) ( )
1
1
1
1
1
]
1

,
_

2
, ,
2
2
, ,
2
2
, ,
2 *
, ,
2
, ,
*
, ,
2
1
z
u
y
u
x
u u
t
u u
n
k j i z
n
k j i y
n
k j i x k j i x
n
k j i k j i

(24)
( )
( )
( ) ( )
1
1
1
1
1
]
1

,
_

+
+

,
_

2
, ,
2
2
, ,
2 * *
, ,
2
2
, ,
2 *
, ,
2
, ,
* *
, ,
2
1
2
1
z
u
y
u u
x
u u
t
u u
n
k j i z
n
k j i y k j i y
n
k j i x k j i x
n
k j i k j i

(25)
Page 15 of 21
( )
( )
( )
( )
1
1
1
1
1
1
1
1
]
1

,
_

+
+

,
_

+
+

,
_

+
+
2
, ,
2 1
, ,
2
2
, ,
2 * *
, ,
2
2
, ,
2 *
, ,
2
, ,
1
, ,
2
1
2
1
2
1
z
u u
y
u u
x
u u
t
u u
n
k j i z
n
k j i z
n
k j i y k j i y
n
k j i x k j i x
n
k j i
n
k j i


(26)
Page 16 of 21
Application of Two-Dimensional Conduction
(Diffusion) Equation
It is required to determine the temperature distribution in a long
bar with a rectangular cross section. The governing PDE is
1
]
1

2
2
2
2
y
T
x
T
t
T

where

is the constant thermal diffusivity, specified as 0.645


ft
2
/hr, and T is the temperature.
Page 17 of 21
The dimension of the bar is given as 5 . 3 h b ft. The initial and
boundary conditions are;
0 ) , , 0 (
0
T y x T
200 ) 0 , , (
1
T x t T
200 ) , 0 , (
2
T y t T
0 ) , , (
3
T h x t T
0 ) , , (
4
T y b t T
Solve the PDE using the ADI method up to time 1 . 0 t hr and
4 . 0 hr. Use
1 . 0 y x
ft so that IM = JM = 36, and 001 . 0 t hr.
1. Calculate the temperature distribution within the bar at
both times and show the surface plots and contour plots of
the temperature distribution.
2. Repeat the calculations for the case when the right and the
top boundary is insulated,
0

b x
x
T
and
0

h y
y
T
.
Page 18 of 21
Sample Program
rx=alpha*delt/delx/delx
ry=alpha*delt/dely/dely
C tn(i,j) is the temperature at time level n and n+1
C t(i,j) is the temperature at time level n+1/2
C Initialize
do i=2,im-1; do j=2,jm-1; tn(i,j)=0.; end do; end do
C apply boundary conditions
do i=1,im; tn(i,1)=200. (bottom); tn(i,jm)=0. (top); end do
do j=1,jm; tn(1,j)=200. (left); tn(im,j)=0. (right); end do
do i=1,im; t(i,1)=200. (bottom); t(i,jm)=0. (top); end do
do j=1,jm; t(1,j)=200. (left); t(im,j)=0. (right); end do
C time loop
do nstep=1,nstepmx
C x-sweep----------------------------------------------------------------
do j=2,jm-1
do i=2,im-1
a(i)=-rx/2.
b(i)=1+rx
c(i)=-rx/2.
d(i)=(ry/2.)*tn(i,j-1)+(1.-ry)*tn(i,j)+(ry/2.)*tn(i,j+1)
end do
C if the left boundary is Neumann type (jl), modify
coefficients
b(2)=b(2)+a(2)
d(2)=d(2)+jl*delx*a(2)
a(2)=0.
C if the right boundary is Neumann type (jr), modify
coefficients
b(im-1)=b(im-1)+c(im-1)
Page 19 of 21
d(im-1)=d(im-1)-jr*delx*c(im-1)
c(im-1)=0.
end if
call tridiagonal (im,a,b,c,d,u)
C convert one-dimensional array u(i) to two-dimensional
C array t(i,j)
do i=2,im-1
t(i,j)=u(i)
end do
end do
C end of x-sweep---------------------------------------------------------
C t(i,j) now stores the temperature at time level n+1/2.
C y-sweep----------------------------------------------------------------------
do i=2,im-1
do j=2,jm-1
a(j)=-ry/2.
b(j)=1+ry
c(j)=-ry/2.
d(j)=(rx/2.)*t(i-1,j)+(1.-rx)*t(i,j)+(rx/2.)*t(i+1,j)
end do
C if the bottom boundary is Neumann type (jb), modify
coefficients
b(2)=b(2)+a(2)
d(2)=d(2)+jb*dely*a(2)
a(2)=0.
C if the top boundary is Neumann type (jt), modify
coefficients
b(jm-1)=b(jm-1)+c(jm-1)
d(jm-1)=d(jm-1)-jt*dely*c(jm-1)
c(jm-1)=0.
end if
Page 20 of 21
call tridiagonal (jm,a,b,c,d,u)
C convert one-dimensional array u(j) to two-dimensional
C array tn(i,j)
do j=2,jm-1
tn(i,j)=u(j)
end do
end do
C end of y-sweep--------------------------------------------------------
C tn(i,j) now stores the temperature at time level n+1 from
which the next time marching can be done.
end do
C end of time loop-------------------------------------------------------
C calculate boundary temperatures for Neumann type
boundary conditions. Required for plotting but not for
computing.
If the left boundary is Neumann type (jl)
do j=1,jm; tn(1,j)=tn(2,j)-jl*delx; end do
end if
If the right boundary is Neumann type (jr)
do j=1,jm; tn(im,j)=tn(im-1,j)+jr*delx; end do
end if
If the bottom boundary is Neumann type (jb)
do i=1,im; tn(i,1)=tn(i,2)-jb*dely; end do
end if
If the top boundary is Neumann type (jt)
do i=1,im; tn(i,jm)=tn(i,jm-1)+jt*dely; end do
end if
C tn(i,j) now contains the solution at the desired time.
Page 21 of 21

Potrebbero piacerti anche