You are on page 1of 11

Finite Difference Method 2.

11

A questionable scheme would be one for which the truncation error is O(∆t/∆x)
and not explicitly O(∆t) or O(∆x) or higher orders. In such cases the scheme
would not be formally consistent unless the mesh were refined in a manner
such that (∆t/∆x) → 0. Let us take Eq. (2.25) and the Dufort-Frankel (1953)
differencing scheme. The FDE is
" #
un+1
i − uin−1 uni+1 − un+1
i − uin−1 + uni−1
=α (2.28)
2∆t (∆x2 )

Now the leading terms of truncated series form the truncation error for the
complete equation:
n n  2 n
∂4u ∂2u ∂3u
  
α ∆t 1
(∆x)2 − α − (∆t)2
12 ∂x4 i ∂t2 i ∆x 6 ∂t3 i

The above expression for truncation error is meaningful if (∆t/∆x) → 0 together


with ∆t → 0 and ∆x → 0. However, (∆t) and (∆x) may individually approach
zero in such a way that (∆t/∆x) = β. Then if we reconstitute the PDE from
FDE and TE, we shall obtain
 2 
∂ u
lim (P DE − F DE) = lim (T E) = −αβ 2
∆t,∆x→0 mesh→0 ∂t2

and finally PDE becomes

∂u ∂2u ∂2u
+ αβ 2 2 = α 2
∂t ∂t ∂x
We started with a parabolic one and ended with a hyperbolic one!
So, DuFort-Frankel scheme is not consistent for the 1D unsteady state heat
conduction equation unless (∆t/∆x) → 0 together with ∆t → 0 and ∆x → 0.

2.3.2 Convergence
A solution of the algebraic equations that approximate a partial differential
equation (PDE) is convergent if the approximate solution approaches the exact
solution of the PDE for each value of the independent variable as the grid spacing
tends to zero. The requirement is

uni = ū(xi , tn ) as ∆x, ∆t → 0

where, ū(xi , tn ) is the solution of the system of algebraic equations.

2.3.3 Explicit and Implicit Methods


The solution of Eq. (2.26) takes the form of a “marching” procedure (or scheme)
in steps of time. We know the dependent variable at all x at a time level
2.12 Computational Fluid Dynamics

from given initial conditions. Examining Eq. (2.26) we see that it contains
one unknown, namely un+1i . Thus, the dependent variable at time (t + ∆t) is
obtained directly from the known values of uni+1 , uni and uni−1 .
un+1
 n
− uni u − 2uni + uni−1

i
= α i+1 (2.29)
∆t (∆x2 )
This is a typical example of an explicit finite difference method.
Let us now attempt a different discretization of the original partial differential
equation given by Eq. (2.25) . Here we express the spatial differences on the
right-hand side in terms of averages between n and (n + 1) time level
" #
n+1 n+1 n+1
un+1
i − uni α ui+1 + uni+1 − 2ui − 2uni + ui−1 + uni−1
= (2.30)
∆t 2 (∆x2 )

The differencing shown in Eq. (2.30) is known as the Crank-Nicolson implicit


scheme. The unknown un+1 i is not only expressed in terms of the known quan-
tities at time level n, but also in terms of unknown quantities at time level
(n + 1). Hence Eq. (2.30) at a given grid point i, cannot itself result in a so-
lution of un+1
i . Eq. (2.30) has to be written at all grid points, resulting in a
system of algebraic equations from which the unknowns un+1 i for all i can be
solved simultaneously. This is a typical example of an implicit finite-difference
solution (Fig. 2.3). Since they deal with the solution of large systems of simulta-
neous linear algebraic equations, implicit methods usually require the handling
of large matrices.
Generally, the following steps are followed in order to obtain a solution.
Eq. (2.30) can be rewritten as
r
un+1
i − uni = [un+1 + uni+1 − 2un+1 − 2uni + un+1 n
i−1 + ui−1 ] (2.31)
2 i+1 i

where r = α(∆t)/(∆x)2 or
−r un+1 n+1
i−1 + (2 + 2r)ui − r un+1 n n n
i+1 = rui−1 + (2 − 2r)ui + rui+1

or
   
2 + 2r 2 − 2r
−un+1
i−1 + un+1
i − un+1 n
i+1 = ui−1 + uni + uni+1 (2.32)
r r
Eq. (2.32) has to be applied at all grid points, i.e., from i = 1 to i = k + 1. A
system of algebraic equations will result (refer to Fig. 2.3).
at i = 2 − A + B(1)un+1
2 − un+1
3 = C(1)
at i = 3 − un+1
2 + B(2)un+1
3 − un+1
4 = C(2)
at i = 4 − un+1
3 + B(3)un+1
4 − un+1
5 = C(3)
.. ..
. .
at i = k − un+1 n+1
k−1 + B(k − 1)uk − D = C(k − 1)
Finite Difference Method 2.13

n+2

n+1

n x
i=1 i=k+1

BC u = A at BC u = D at
x=0 x=L

Figure 2.3: Crank Nicolson implicit scheme.

Finally the equations will be of the form:

un+1 (C(1) + A)n


    
B(1) −1 0 0 ... 0 2
 −1 B(2) −1 0 ... 0  un+1 C(2)n
  3n+1  
  
n
 
 0 −1 B(3) −1 ... 0  u C(3)
 4  = 
  
 .. .

 .  

 .   ..   .. 

n+1 n
0 0 0 . . . −1 B(k − 1) uk (C(k − 1) + D)
(2.33)
Here, we express the system of equations in the form of Ax = C, where C is
the right-hand side column vector (known), A the tridiagonal coefficient matrix
(known) and x the solution vector (to be determined). Note that the boundary
values at i = 1 and i = k + 1 are transferred to the known right-hand side.

For such a tridiagonal system, different solution procedures are available. In


order to derive advantage of the zeros in the coefficient-matrix, the well known
Thomas algorithm (1949) can be used (see appendix).
2.14 Computational Fluid Dynamics

2.3.4 Explicit and Implicit Methods for Two-Dimensional


Heat Conduction Equation
The two-dimensional conduction equation is given by
 2
∂ u ∂2u

∂u
=α + 2 (2.34)
∂t ∂x2 ∂y

Here, the dependent variable, u (temperature) is a function of space (x, y) and


time (t) and α is the thermal diffusivity. If we apply the simple explicit method
to the heat conduction equation, the following algorithm results

un+1 n  n
i,j − ui,j ui+1,j − 2uni,j + uni−1,j uni,j+1 − 2uni,j + uni,j−1

=α + (2.35)
∆t (∆x2 ) (∆y 2 )

When we apply the Crank-Nicolson scheme to the two-dimensional heat con-


duction equation, we obtain

un+1 n
i,j − ui,j α
= (δx2 + δy2 )(un+1 n
i,j + ui,j ) (2.36)
∆t 2
where the central difference operators δx2 and δy2 in two different spatial directions
are defined by
uni+1,j − 2uni,j + uni−1,j
δx2 [uni,j ] =
(∆x2 )
u,j+1 − 2uni,j + uni,j−1
n
δy2 [uni,j ] = (2.37)
(∆y 2 )

The resulting system of linear algebraic equations is not tridiagonal because of


the five unknowns un+1 n+1 n+1 n+1 n+1
i,j , ui+1,j , ui−1,j , ui,j+1 and ui,j−1 . In order to examine
this further, let us rewrite Eq. (2.36) as

a un+1 n+1 n+1 n+1 n+1 n


i,j−1 + b ui−1,j + d ui,j + b ui+1,j + a ui,j+1 = ci,j (2.38)

where
α∆t 1
a=− 2
= − Py
2(∆y) 2
α∆t 1
b=− = − Px
2(∆x)2 2
d = 1 + Px + Py
α∆t 2
cni,j = uni,j + (δx + δy2 )uni,j
2
Eq. (2.38) can be applied to the two-dimensional (6 × 6) computational grid
shown in Fig. 2.4. A system of 16 linear algebraic equations have to be solved
Finite Difference Method 2.15

y
jmax

u = ub 4 u = u b = boundary value
3
2

j=1 x
i= 1 2 3 4 5 imax

Figure 2.4: Two-dimensional grid on the (x-y) plane.

at (n + 1) time level, in order to get the temperature distribution inside the


domain. The matrix equation will be as the following:
 ′′′ 
   c2,2
d b 0 0 a 0 0 u2,2  c′ 
b d b a  u3,2   ′3,2 

c4,2 
   
0 b d b a  u4,2    ′′′ 

0 b d b a
 
 u5,2   c5,2 
  ′′ 
 u2,3  c2,3 
 
a 0 d b a


c3,3 
  
0 a b d b a  u3,3    
c4,3 
  

 a 0 b d b a  u4,3  
   ′′ 

 a b d 0 a  u5,3   c 5,3
 u2,4  = 
    
′′ 

 a 0 d b a    c 2,4 
a b d b a  u3,4   

    c 3,4 

 a b d b a 0  u4,4  c 
  4,4 
 a b d 0 a  u5,4    c
′′ 

   5,4 
 a 0 d b 0  u2,5   ′′′
    c2,5 
a b d b 0  u3,5   
  c′ 
 
 
a b d b  u4,5   ′3,5 
 
c4,5 
a b d u5,5 ′′′
c5,5
(2.39)
where

c = c − a ub
′′
c = c − b ub
′′′
c = c − (a + b) ub

The system of equations, described by Eq. (2.39) requires substantially more


computer time as compared to a tridiagonal system. The equations of this type
2.16 Computational Fluid Dynamics

are usually solved by iterative methods. These methods will be described in a


subsequent section. The quantity ub is the boundary value.

2.3.5 ADI Method


The difficulties described in the earlier section, which occur when solving the
two-dimensional equation by conventional algorithms, can be removed by alter-
nating direction implicit (ADI) methods. The usual ADI method is a two-step
scheme given by

n+1/2
ui,j − uni,j n+1/2
= α(δx2 ui,j + δy2 uni,j ) (2.40)
∆t/2

and
n+1/2
un+1
i,j − ui,j n+1/2
= α(δx2 ui,j + δy2 un+1
i,j ) (2.41)
∆t/2

The effect of splitting the time step culminates in two sets of systems of linear
algebraic equations. During step 1, we get the following
n+1/2
"( n+1/2 n+1/2 n+1/2
)  #
ui,j − uni,j ui+1,j − 2ui,j + ui−1,j uni,j+1 − 2uni,j + uni,j−1
=α +
(∆t/2) (∆x2 ) (∆y 2 )

or

[b ui−1,j + (1 − 2b) ui,j + b ui+1,j ]n+1/2 = uni,j − a [ui,j+1 − 2ui,j + ui,j−1 ]n

Now for each “j” rows (j = 2, 3...), we can formulate a tridiagonal matrix, for
the varying i index and obtain the values from i = 2 to (imax − 1) at (n + 1/2)
level Fig. 2.5(a). Similarly, in step-2, we get

n+1/2 n+1/2 n+1/2 n+1/2


un+1 un+1 n+1 n+1
"( ) ( )#
i,j − ui,j ui+1,j − 2ui,j + ui−1,j i,j+1 − 2ui,j + ui,j−1
=α 2
+
(∆t/2) (∆x ) (∆y 2 )

or

n+1/2
[a ui,j−1 + (1 − 2a) ui,j + a ui,j+1 ]n+1 = ui,j − b[ui+1,j − 2ui,j + ui−1,j ]n+1/2

Now for each “i” rows (i = 2, 3....), we can formulate another tridiagonal matrix
for the varying j index and obtain the values from j = 2 to (jmax − 1) at nth
level Figure 2.5(b).
With a little more effort, it can be shown that the ADI method is also second-
Finite Difference Method 2.17

t t
IMPLICIT

n+ 1
− n+1
2 y = j ∆.y
4 IMPLICIT
3
2 1
n n+ −
x = i ∆x 2 2 3 45 . . . . i

(a) (b)

Figure 2.5: Schematic representation of ADI scheme.

n+1/2
order accurate in time. If we use Taylor series expansion around ui,j on
either direction, we shall obtain
  2   3
1 ∂2u 1 ∂3u
    
n+1 n+1/2 ∂u ∆t ∆t ∆t
ui,j = ui,j + + + + ···
∂t 2 2! ∂t2 2 3! ∂t3 2

and
2 3
∂2u ∂3u
      
n+1/2 ∂u ∆t 1 ∆t 1 ∆t
uni,j = ui,j − + − + ···
∂t 2 2! ∂t2 2 3! ∂t3 2
Subtracting the latter from the former, one obtains
  3
2 ∂3u
  
∂u ∆t
un+1
i,j − u n
i,j = (∆t) + 3
+ ···
∂t 3! ∂t 2
or

un+1 n 2
i,j − ui,j ∂3u
 
∂u 1 ∆t
= − + ···
∂t ∆t 3! ∂t3 2
The procedure above reveals that the ADI method is second-order accurate with
a truncation error of O [(∆t)2 , (∆x)2 , (∆y)2 ].
The major advantages and disadvantages of explicit and implicit methods
are summarized as follows:

Explicit:
• Advantage: The solution algorithm is simple to set up.
• Disadvantage: For a given ∆x, ∆t must be less than a specific limit im-
posed by stability constraints. This requires many time steps to carry out
the calculations over a given interval of t.
2.18 Computational Fluid Dynamics

Implicit:
• Advantage: Stability can be maintained over much larger values of ∆t.
Fewer time steps are needed to carry out the calculations over a given
interval.

• Disadvantages:

- More involved procedure is needed for setting up the solution algo-


rithm than that for explicit method.
- Since matrix manipulations are usually required at each time step,
the computer time per time step is larger than that of the explicit
approach.
- Since larger ∆t can be taken, the truncation error is often large, and
the exact transients (time variations of the dependant variable for
unsteady flow simulation) may not be captured accurately by the
implicit scheme as compared to an explicit scheme.

Apparently finite-difference solutions seem to be straightforward. The over-


all procedure is to replace the partial derivatives in the governing equations with
finite difference approximations and then finding out the numerical value of the
dependant variables at each grid point. However, this impression is indeed in-
correct! For any given application, there is no assurance that such calculations
will be accurate or even stable! Let us now discuss about accuracy and stability.

2.4 Errors and Stability Analysis


2.4.1 Introduction
There is a formal way of examining the accuracy and stability of linear equations,
and this idea provides guidance for the behavior of more complex non-linear
equations which are governing the equations for flow fields.
Consider a partial differential equation, such as Eq. (2.25). The numerical
solution of this equation is influenced by the following two sources of error.

Discretization:
This is the difference between the exact analytical solution of the partial dif-
ferential Eq. (2.25) and the exact (round-off free) solution of the correspond-
ing finite-difference equation (for example, Eq. (2.26). The discretization error
for the finite-difference equation is simply the truncation error for the finite-
difference equation plus any errors introduced by the numerical treatment of
the boundary conditions.
Finite Difference Method 2.19

Round-off:
This is the numerical error introduced for a repetitive number of calculations in
which the computer is constantly rounding the number to some decimal points.
If A = analytical solution of the partial differential equation.
D = exact solution of the finite-difference equation
N = numerical solution from a real computer with finite accuracy
Then, Discretization error = A - D = Truncation error + error introduced due
to treatment of boundary condition
Round-off error = ǫ = N - D
or,
N =D+ǫ (2.42)
where, ǫ is the round-off error, which henceforth will be called “error” for con-
venience. The numerical solution N must satisfy the finite difference equation.
Hence from Eq. (2.26)

Din+1 + ǫn+1
 n
− Din − ǫni Di+1 + ǫni+1 − 2Din − 2ǫni + Di−1
n
+ ǫni−1

i

∆t (∆x2 )
(2.43)
By definition, D is the exact solution of the finite difference equation, hence it
exactly satisfies

Din+1 − Din
 n
Di+1 − 2Din + Di−1 n 
=α (2.44)
∆t (∆x2 )

Subtracting Eq. (2.44) from Eq. (2.43)

ǫn+1
 n
− ǫni ǫ − 2ǫni + ǫni−1

i
= α i+1 (2.45)
∆t (∆x2 )

From Equation 2.45, we see that the error ǫ also satisfies the difference equation.
If errors ǫi are already present at some stage of the solution of this equation,
then the solution will be stable if the ǫi ’s shrink, or at least stay the same, as
the solution progresses in the marching direction, i.e from step n to n + 1. If
the ǫi ’s grow larger during the progression of the solution from step n to n + 1,
then the solution is unstable. Finally, it stands to reason that for a solution to
be stable, the mandatory condition is
n+1
ǫi
ǫn ≤ 1 (2.46)

i

For Eq. (2.26), let us examine under what circumstances Eq. (2.46) holds good.
Assume that the distribution of errors along the x−axis is given by a Fourier
series in x, and the time-wise distribution is exponential in t, i.e,
X
ǫ(x, t) = eat eIkm x (2.47)
m
2.20 Computational Fluid Dynamics

where I is the unit complex number and k the wave number 1 Since the difference
is linear, when Eq. (2.47) is substituted into Eq. (2.45), the behaviour of each
term of the series is the same as the series itself. Hence, let us deal with just
one term of the series, and write

ǫm (x, t) = eat eIkm x (2.48)

Substitute Eq. (2.48) into ( 2.45) to get

ea(t+∆t) eIkm x − eat eIkm x


 at Ikm (x+∆x)
− 2eat eIkm x + eat eIkm (x−∆x)

e e

∆t (∆x)2
(2.49)
Divide Eq. (2.49) by eat eIkm x

ea∆t − 1
 Ikm ∆x
− 2 + e−Ikm ∆x

e

∆t (∆x)2
or,
α(∆t)
ea∆t = 1 + eIkm ∆x + e−Ikm ∆x − 2

2 (2.50)
(∆x)
Recalling the identity

eIkm ∆x + e−Ikm ∆x
cos(km ∆x) =
2
Eq. (2.50) can be written as

α(2∆t)
ea∆t = 1 + (cos(km ∆x) − 1)
(∆x)2
or,
α(∆t)
ea∆t = 1 − 4 2 sin2 [(km ∆x)/2] (2.51)
(∆x)
From Eq. (2.48), we can write

ǫn+1 ea(t+∆t) eIkm x


i
n = = ea∆t (2.52)
ǫi eat eIkm x

Combining Eqns. (2.51),(2.52) and (2.46), we have


n+1  
ǫi a∆t
α(∆t) 2 (km ∆x)
ǫn = |e | = 1 − 4 (∆x)2 sin ≤1 (2.53)

i 2

1
Let a wave travel with a velocity v. The time period “T ′′ is the time required for the
wave to travel a distance of one wave length λ, so that λ=vT . Wave number k is defined by
k = 2π/λ.
Finite Difference Method 2.21

Eq. (2.53) must be satisfied to have a stable solution. In Eq. (2.53) the factor
 
α(∆t) 2 (km ∆x)
1 − 4 2 sin

2

(∆x)

is called the amplification factor and is denoted by G.


Evaluating the inequality in Eq. (2.53) , the two possible situations which
must hold simultaneously are
(a)
 
α(∆t) (km ∆x)
1−4 2 sin2 ≤1
(∆x) 2

Thus,
 
α(∆t) 2 (km ∆x)
4 2 sin ≥0
(∆x) 2

Since α(∆t)/(∆x)2 is always positive, this condition always holds.


(b)
 
α(∆t) 2 (km ∆x)
1−4 2 sin ≥ −1
(∆x) 2

Thus,
 
4α(∆t) 2 (km ∆x)
2 sin −1≤1
(∆x) 2

For the above condition to hold

α(∆t) 1
2 ≤ (2.54)
(∆x) 2

Eq. (2.54) gives the stability requirement for which the solution of the difference
Eq. (2.26) will be stable. It can be said that for a given ∆x the allowed value
of ∆t must be small enough to satisfy Eq. (2.54). For α(∆t)/(∆x)2 ≤ (1/2) the
error will not grow in subsequent time marching steps in t, and the numerical
2
solution will proceed in a stable manner. On the contrary, if α(∆t)/(∆x) >
(1/2), then the error will progressively become larger and the calculation will
be useless.
The above mentioned analysis using Fourier series is called as the Von Neu-
mann stability analysis.

You might also like