Anda di halaman 1dari 17

The Control-Volume Finite-Difference

Approximation to the Diffusion Equation


Gerald W. Recktenwald
Department of Mechanical Engineering
Portland State University
gerry@me.pdx.edu
January 27, 2012
Abstract
A two-dimensional computer code for solution of the diffusion equation (Poisson equation)
is described. The code is implemented in Matlab, and is intended for educational use. The
partial differential equation is converted to a system of linear equations with the finite-volume
method. The system is solved by a direct method, though extending the code to use iterative
methods would not be difficult. Use of the code requires the user to edit and run Matlab
functions. Utility routines for prescribing a variety of boundary conditions and computing wall
fluxes are provided to ease the programming tasks. The code is demonstrated with a handful
of sample problems.

Introduction

The control-volume finite-difference (CVFD) method is widely used in the numerical simulation of
fluid dynamics, heat transfer and combustion. Several commercial CFD (computational fluid dynamics) codes are based on this method. Though there is no one ultimate numerical approximation
scheme, the CVFD method has numerous desirable features. It naturally maintains conservation of
species when applied to conservation laws. It readily handles material discontinuities and conjugate
heat transfer problems. It also has the pedagogical advantage that only simple calculus is required
to derive the CVFD approximation to common conservation equations.
This article presents a brief derivation of the CVFD approximation to the diffusion equation.
The two dimensional diffusion equation in Cartesian coordinates is





+S =0
(1)
x
x
y
y
where is the scalar field, is the diffusion coefficient, and S is the source term. In this form
is assumed to be non-uniform. We seek the solution (x, y) to Equation (1) in a region of space ,
subject to appropriate conditions on the boundary, .
The article begins with the nomenclature necessary to define a finite volume grid on a rectangular
domain. Following that the general form of the CVFD approximation to the diffusion equation is
obtained. Next, the harmonic mean is introduced as the correct procedure for treating discontinuities
in . In 5 important details concerned with writing a CVFD program are discussed. A series of
model problems suitable for testing a CVFD code problems are presented in 6. The article ends
with a discussion of truncation error, including a quantitative procedure for verifying the correctness
of a CVFD code.
1

FINITE VOLUME MESH

xu(1) = 0
x(i)

xu(nx+1)

xu(i)
yv(ny+1)

ny

nx ny

y(j)

yv(j)

Interior node
Boundary node

j=0
i=0

nx+1

nx+2

Ambiguous corner node


nx
3

yv(1) = 0

nx

Figure 1: The control-volume finite-difference grid covering the calculation domain.

Finite Volume Mesh

Figure 1 depicts a rectangular domain of length Lx in the x-direction and Ly in the y-direction.
The domain is divided into non-overlapping control volumes by the lines that define the boundaries
of the individual control volumes. The pattern created by the lines is called the computational grid
or mesh. In Figure 1 the control volumes are square, but this is not required. At the center of each
control volume is a node, designated by an open circle. Two sets of grid lines can be identified:
the grid lines that define the control volume faces, and the grid lines (not shown) that define the
locations of the nodes. In the computer implementation the grid lines that define node locations will
be stored in the variables x(i) and y(j). The grid lines that define the control volume interfaces
will be stored in xu(i) and yv(j).
In section 3 we obtain an approximation to Equation (1) which applies to the interior nodes.
Boundary values are applied at the nodes indicated by full circles. Nodes at the very corner of
the domain, those marked with open squares, will not appear in the discrete approximation to
Equation (1).
Nodes in the domain may be identified by their (i, j) grid indices. An additional naming convention based on the directions on a map will be used to simplify the algebra in following sections.
Figure 2 is a detailed sketch of one of the control volumes in the domain. A typical node (i, j) in
Figure 1 is also referred to as node P in Figure 2. The (i + 1, j) and (i 1, j) neighbors of P are
designated E for east and W for west, respectively. The (i, j + 1) and (i, j 1) neighbors of P are
referred to as N and S for north and south, respectively. Figure 2 also defines numerous geometric
variables. In general the width, x, of a control volume will not be equal to the distances xe and
xw between P and its east and west neighbors. Regardless of the grid spacing P is always located

DISCRETE APPROXIMATION FOR INTERIOR CONTROL VOLUMES

xw

xe

N
yn

yn
P

E
y

ys

ys
xw

xe

S
Figure 2: Geometric variables for a typical control-volume.
in the geometric center of its control volume. Thus
xP xw
yP ys

x
2
y
= yn yP =
2
= xe xP =

(2)
(3)

In these expressions it is crucial to distinguish between upper and lower case letters used as subscripts. Lower case subscripts refer to the locations of the control volume faces. Upper case subscripts refer to the locations of the nodes.

Discrete Approximation for Interior Control Volumes

The control volume finite-difference method is used to transform Equation (1) to a system of discrete
equations for the nodal values of . First, Equation (1) is integrated over the typical control volume
depicted in Figure 2. This reduces the equation to one involving only first derivatives in space.
Then these first derivatives are replaced with central difference approximations.
Integrating the first term in Equation (1) over the finite control volume yields


 

Z yn Z xe
Z yn 

dx dy =


dy
(4)
x
x
x
ys
xw x
y
 e
 w
s


y
(5)
x e
x w


E P
P W

e
w
y
(6)
xe
xw
Equation (4) follows from an exact evaluation of the inner integral with respect to x. Equation (5)
is obtained by assuming that the flux terms, e.g. (/x)e , do not vary in the y direction over
a given control volume face. Equation (6) results from applying a central difference approximation
to each partial derivative term. In these expressions E , W , and P are the nodal values of ,

NON-UNIFORM

and e and w are the diffusion coefficients evaluated at the interfaces of the control volumes. The
procedure for evaluating e and w is described in section 4.
Starting with the second term in Equation (1) and applying the steps used to obtain Equation (6)
results in




Z xe Z yn

P S

N P
s
x
(7)

dy dx n
y
y n
y s
ys y
xw
On the left side of Equation (7) the order of integration has been chosen so that the outer /y
operator is eliminated first. This is allowable if the integrand is smooth, as is the case for solutions
to Equation (1).
Integrating the source term in Equation (1) over the control volume gives
Z xe Z yn
S dy dx SP x y
(8)
xw

ys

where Sp is the source term evaluated at node P . Adding together Equations (6)8 and rearranging
yields
aS S aW W + aP P aE E aN N = b
(9)
where
e
x xe
w
x xw
n
y y n
s
y y s

aE

aW

aN

aS

aP

= aE + aW + aN + aS

(14)

= SP

(15)

(10)
(11)
(12)
(13)

For additional information on the transformation of Equation (1) into Equation (9) (see Patankar [3]).
Equations 9 through 15 apply to each of the N = nx ny internal nodes in Figure 1. This defines a
linear system of N equations in the N unknown internal values of .

Non-uniform

Calculation of the coefficients in equations 1013 requires values of at the interfaces of the control
volumes. Rather than using an interpolation scheme, the interface values of are defined by
requiring continuity of the diffusive flux at the control volume interfaces. Consider the situation
depicted in Figure 3 where two control volumes meet along a material discontinuity. This common
situation occurs when the diffusion equation is solved in a composite material.
Assume that is uniform within each of the control volumes. (When the finite volume grid is
defined the control volume faces are aligned with discontinuities. Thus it is not an unreasonable
restriction to require that material properties are uniform within a control volume.) Continuity of
flux at the interface requires






P
=

(16)
E
e
x xe
x xe +
x xe

NON-UNIFORM

material 1

material 2

xe-

xe+
xe

Figure 3: Discontinuous variation in at the interface between two control-volumes.


Equation (16) defines e . In other words, the value of e is chosen such that the flux, /x, is
continuous. Central difference approximations to the flux continuity conditions in Equation (16)
are
E P
xe
E P
e
xe
e

=
=

e P
xe
E e
E
xe+
P

(17)
(18)

where e is the value of at the interface. Equations 17 and 18 are discrete approximations for the
diffusion flux into the left (minus) and right (plus) sides of the control volume interface in Figure 3.
Equations 17 and 18 can be rearranged as
e P

E e

xe e
(E P )
P xe
xe+ e
(E P )
E xe

(19)
(20)

Adding equations 19 and 20 gives


E P =



e
xe
xe+
(E P )
+
.
xe
P
E

Cancel the factor of (E P ) and solve for e /xe to get



1
xe
e
xe+
E P
=
+
=
.
xe
P
E
xe E + xe+ P
Thus,
e =

E P
E + (1 )P

(21)

IMPLEMENTATION

where

xe
xe xP
=
xe
xE xP

(22)

Equation (21) gives the interface diffusion coefficient as the harmonic mean of the diffusion coefficients in adjacent control volumes. This gives the proper limiting behavior as either E or P goes
to zero. Similar formulas for w , n , and s may be derived, or written down by direct analogy to
the formula for e . These interface values for are used in equations 1013.

Implementation

A good code to solve Equation (1) will have efficient data structures, a robust and efficient
solution procedure, it will be flexible enough to accommodate practical problems, and it will be
easy to maintain and debug. There are many possible ways to implement a code to achieve the
aforementioned goals. In this section, the design of a particular set of Matlab routines for the
solution of Equation (1) is described.

Table 1: Core Matlab routines used to solve Equation (1).


Function

Description

fvAmatrix

Store the finite volume coefficients aE , aW , aN , aS , and aP


in the sparse matrix A in Equation (24).

fvave

Compute the volume-weighted average of a field variable


over the domain.

fvbc

Modify finite volume coefficients and source terms to include the effect of boundary conditions. The final value of
aP is also computed.

fvcoef

Compute the neighboring finite volume coefficients (aE ,


aW , aN , and aS ) for all interior control volumes. No special
treatment is applied to control volumes adjacent to boundaries.

fvpost

Update unknown boundary values and heat fluxes after the


solution to the interior nodes is obtained. An energy balance is computed and printed. The temperature field is
stored in a matrix suitable for use with Matlab contour
and surface plotting routines.

fvUniformMesh

Compute the location of cell centers and cell interfaces for


a group of cells with uniform size. fvUniformMesh can be
applied to either x or y direction cells, and with care it can
be applied to subregions of the grid.

fvUniBlockMesh

Compute the location of cell centers and cell interfaces for


a mesh consisting of blocks that contain uniform meshes.
The overall mesh can contain blocks of unequal size and
unequal numbers of control volumes. Within each block,
the mesh is uniform.

IMPLEMENTATION

The code described here was designed with three primary objectives.
Make the code modular so that it can be more easily maintained.
Make the code flexible so that it can be applied to a number of different problems described
by Equation (1). In particular, allow users of the code to easily select different boundary
conditions, material properties, and source terms.
Make the code reasonably simple to understand. If necessary, sacrifice some efficiency or
flexibility in order to make the code easier to read.
The solution to a particular problem is obtained by defining problem-specific grid and boundary
values, and then using a set of generic Matlab functions. The generic Matlab functions are listed
in Table 1.
Table 2 represents the structure of an analysis code that uses the functions from Table 1. On
the left is a block depicting the sequence of steps in the main program. On the right is a block
containing the names of the generic functions. Several of the steps in the main program are linked
by double-ended arrows to routine names Core Code box. These arrows indicate a function call
in the main program that sends information to, and receives information from the generic routines.

5.1

Mesh Variables

The mesh is specified by four vectors: x, xu, y, and yv. As shown in Figure 1, x(i) and y(j) are
the x and y positions of the node for i,j . The indexing of the control volume faces is arbitrary. We
define xu(i) to be the location of the face to the left of x(i), and define yv(j) to be the location of
the face below y(j). This convention comes from related codes that are used to model convective
transport, which will not be discussed here.
For many problems either a uniform or block-uniform mesh are suitable. We define a uniform
mesh to have uniform control volume widths in any one coordinate direction. The widths of the
control volumes in different directions need not be uniform. This situation is depicted in the left
hand side of Figure 4 where x 6= y, but x is same for all control volumes. For a uniform mesh,
the x, xu, y, and yv vectors are computed in fvUniformMesh.
A block-uniform mesh is shown in the right hand side of Figure 4. In a block-uniform mesh, the
calculation domain is divided into a number of panels in the x and y direction. The intersections
of these panels define rectangular blocks. The width x of control volumes is uniform within an

Table 2: Relationship between generic routines (core code) and the main program used to solve a
particular problem.
Algorithm Tasks
Define the mesh
Define boundary conditions
Compute finite-volume coefficients for interior cells
Adjust coefficients for boundary conditions
Solve system of equations
Assemble coefficient matrix
Solve
Compute boundary values and/or fluxes
Plot results

Core Routines
fvUniformMesh
fvcoef
fvbc
fvAmatrix
fvpost

IMPLEMENTATION

Uniform Mesh

8
Block-Uniform Mesh
Ly3, ny3

y
Ly2, ny2
Ly1, ny1

y
x

Lx1, nx1

Lx2, nx2

Figure 4: Uniform and block-uniform meshes. Note that the uniform mesh the widths of the control
volumes in the x and y directions are not necessarily uniform. The term uniform describes the
spacing of the control volumes along individual directions.
x-direction panel, and adjacent panels can have different x. Similarly, y is uniform within a
y-direction panel, but may vary from panel to panel. The fvUniBlockMesh function is used to
define block-uniform meshes.
For convenience, we define the auxiliary vectors dx, dy, dxw, dys
dx(i) = xu(i + 1) xu(i)
dy(j) = yv(j + 1) yv(j)
dxw(i) = x(i) x(i 1)
dys(j) = y(j) y(y 1)
dx(i) and dy(j) are the x- and y-direction widths of the control volume around the node for i,j .
These code variables correspond to x and y in Figure 2. dxw and dxs are the distances between
adjacent nodes, which correspond to x and y in Figure 2.

5.2

Data Structures

The fundamental decision is whether the unknowns at the center of the control volume will be
stored in one-dimensional arrays (vectors) or multidimensional arrays. Storing the data in vectors
has the potential for greater computational efficiency, whereas multidimensional arrays allow the
most straightforward programming.
The grid in Figure 1 suggests that the discrete variable, , could be naturally stored as a twodimensional array, phi(i,j). If the indices of phi(i,j) run 0 i nx + 1 and 0 j ny + 1
then both the unknown interior values and the boundary conditions can be stored in the same array.
The primary advantage of this data structure is that it is easy to program. Use of multidimensional
arrays does not preclude efficient programs. However, vector processors are more efficient when
operating on longer vectors than shorter vectors. With stored in a two-dimensional array the
largest vector length is nx (if the code is written in Fortran) or ny (if the code is written in C).
Alternatively one can store the nodal values of at the interior grid points in a vector phi[n],
n = 1,...,N. Data on the two-dimensional grid of Figure 1 can be mapped to the one-dimensional
array with the so-called natural ordering
n = i + (j 1)nx
Other orderings are possible (see, e.g., [1, 2]).
With natural ordering the neighbors in the compass point notation of Figure 2 have these indices

IMPLEMENTATION

np
ne
nw
nn
ns

=
=
=
=
=

i + (j-1)*nx
np + 1
np - 1
np + nx
np - nx

where np is the index of node (i, j), ne is the index of node (i + 1, j), etc. Whether or not the
unknown values of are stored in a two-dimensional array corresponding to the grid indices or a
vector with natural ordering, the set of unknowns can be represented symbolically as a vector.

1
1,1
2
2,1

..
..

.
.

nx
nx,1

nx+1
1,2

(23)
2,2 nx+2

..
..

.
.

n
i,j

..
..

.
.
nx,ny

If the interior values of are stored in a vector using natural ordering, additional storage for the
boundary values must also be provided. One solution to this problem is to define four additional
vectors
ebcval(j),
wbcval(j),
nbcval(i),
sbcval(i),

j
j
i
i

=
=
=
=

1,..,ny
1,..,ny
1,..,nx
1,..,nx

The values stored in ebcval, etc., are the values of of the boundary nodes. This is sufficient for
Dirichlet boundary conditions. Additional information needs to be provided if multiple types of
boundary conditions (e.g., Neumann, symmetry, convective) are allowed in the code.
To allow for additional boundary types, the boundary condition information is stored in an n 5
matrix for each of the four boundaries. The value of n is either nx or ny depending on the boundary:
east and west boundaries are adjacent to ny control volumes, and the north and south boundaries
are adjacent to nx control volumes. Table 3 documents the four types of boundary conditions that
are defined for the finite volume codes listed in Table 1.
The names and dimensions of the boundary condition matrices are listed in Table 4. The first
letter of the matrix data structure indicates the location of the boundary. Thus, ebc contains data
for the east boundary, wbc contains data for the west boundary, etc. The structure of these matrices
is the same for each boundary surface.
Table 5 describes the contents of each column of ebc. The contents of the other boundary
matrices are analogous, except that the row index in nbc and sbc is the index of the boundary node
in the x direction, e.g. sbc(3,1) is the boundary condition type for the third cell from the left on
the south boundary.

IMPLEMENTATION

10

Table 3: Boundary condition types. The boundary type is expressed in terms of a heat conduction
problem where = T , = k, and S is a heat source term.
Boundary
type

Boundary
Condition

Post-processing in fvpost

Specified T

Compute q 00 from discrete approximation to Fouriers law.


Tb Ti
q 00 = k
xb xi
where Ti and Tb are interior and boundary temperatures,
respectively.

Specified q 00

Compute Tb from discrete approximation to Fouriers law.


xb xi
Tb = Ti + q 00
k
where Ti and Tb are interior and boundary temperatures,
respectively.

Convection

From specified h and T , compute boundary temperature


and heat flux through the cell face on the boundary. Continuity of heat flux requires
k

Tb Ti
= h(Tb Tamb )
xb xi

which can be solved for Tb to give


Tb =

hTamb + (k/xe )Ti


h + (k/xe )

where xe = xb xi
4

Symmetry

q 00 = 0. Set boundary Tb equal to adjacent interior Ti .

Table 4: Matrices for storing boundary condition data.


Matrix

boundary

size

ebc

east

ny 5

wbc

west

ny 5

nbc

north

nx 5

sbc

south

nx 5

IMPLEMENTATION

11

Table 5: Contents of ebc data structure for the east boundary. j is the index of the boundary node
in the y-direction.
Column of
ebc

Value

ebc(j,1)

Integer from 1 to 4 indicating the type of boundary condition

ebc(j,2)

Value of T on the boundary node (if known)

ebc(j,3)

Value of heat flux through the cell face on the boundary (if known)

ebc(j,4)

Value of convection coefficient h if ebc(j, 1) = 3.

ebc(j,5)

Value of free-stream temperature of fluid flowing over the the boundary if ebc(j, 1) = 3.

A=

aS

a W ap

aE

aN

Figure 5: Schematic representation of the A matrix.

5.3

Solving the Linear System

Equation (9) applies to each of the interior values of . Determining the discrete field requires
solving the system
Ax = b
(24)
where the unknown vector x corresponds to the interior values of (cf. Equation (23)), the coefficient
matrix, A, consists of the coefficients of Equation (9), and the right hand side vector b, includes the
source term (Equation (15)) and boundary conditions. The matrix A is sparse in the sense that
there are many more zero entries than non-zero entries. The structure of the A matrix is depicted

MODEL PROBLEMS

in Figure 5. The b vector is

b=

12

f1,1 + aS1,1 1,0 + aW


1,1 0,1
f2,1 + aS2,1 2,0
..
.

fnx,1 + aSnx,1 nx,0 + aE


nx,1 nx+1,1
f1,2 + aW

1,2 0,2
f2,2
..
.
fi,j
..
.

(25)

E
fnx,ny + aN
nx,ny nx,ny+1 + anx,ny nx+1,ny

where the superscripts refer to the compass point notation for the coefficients in equations 1013 and
the subscripts refer to the grid indices in Figure 1. In Equation (25) the values on the boundary
are referred to in terms of their two-dimensional grid indices. Storing as a vector is necessary
if the system of equations represented by 9 is to be solved with a direct technique, such as Gauss
elimination. For iterative methods the matrix A is never explicitly assembled. Rather the entries
in A are stored in arrays corresponding directly to the coefficients in Equation (9). Thus, iterative
methods can use the coefficient arrays whether they are stored as vectors or multidimensional arrays.

Model Problems

Computer codes to solve Equation (1) may be exercised by applying them to a series of model
problems. These problems contain features found in more complicated engineering situations. Since
the geometry and boundary conditions are relatively simple, the model problems may be solved with
simple codes that are not as complex as those capable of solving practical engineering problems.
These model problems are also useful for debugging more complex codes and testing different solution
strategies.
The model problems require solution of Equation (1) on a rectangular domain
0 x Lx

0 y Ly

The problems are distinguished by their different boundary conditions, and by the variation of the
source term and diffusivity in the domain.

Model Problem 1
Model problem 1 has = 0 on all boundaries, = 1, and the source term given by
" 
 2 #
 


2

2
x
2y
S=
+
sin
sin
Lx
Ly
Lx
Ly
The exact solution is


= sin

and is shown in Figure 6.

x
Lx


sin

2y
Ly

(26)


(27)

MODEL PROBLEMS

13

0.08
0.07

1.5

0.06
0.05

0.04
0.03

0.5

0.02
0.01

0
1

0
1
0.5
0

0.8

0.6

0.4

0.2

0.5
0

0.8

0.6

0.4

0.2

Figure 6: Solution to model problem 1 (left) and model problem 2 (right) on a 64 64 mesh.

Model Problem 2
Model problem 2 has = 0 on all boundaries, = 1, and a uniform source term, i.e. S(x, y) = constant. The solution is shown in the right hand side of Figure 6.

Model Problem 3
Model problem 3 involves solution to Equation (1) in the domain shown in Figure 7. The source
term and diffusion coefficient have different values in two subregions of the domain. Outside of the
central region
= 1 = 1 S = 0
In the central region of the domain
= 1

S = 1000

where > 0 is a scalar. When 6= 1 there is a discontinuous diffusivity change between the
two regions. Model problem 3 becomes more difficult to solve as the magnitude of increases or
decreases. The boundary conditions are
(0, y) = 20 (Lx , y) = 0
(x, 0) = 10 (x, Ly ) = 0

Model Problem 4: Fully-Developed Flow in a Rectangular Duct


Figure 8 shows two representations of the cross section of a rectangular duct. For simple fullydeveloped flow the governing equation for the axial velocity w is

 2
dp
w 2w
+

=0
(28)

2
2
x
y
dz
The code for solving Equation (1) can be used to solve Equation (28) by making the following
definitions
dp
= w,
= (= constant),
S= .
dz

MODEL PROBLEMS

14

35
30
25
20

Ly

0.5Ly

2 = 1

1 = 1

15

S2 = 1000

S1 = 0

10
5
0
1

0.25Ly

0.5

0.5Lx

0.25Lx

Lx

0.8

0.6

0.4

0.2

Figure 7: Geometry of calculation domain (left) and finite-volume solution on a 64 64 mesh for
model problem 3.
For the full duct simulation depicted on the left hand side of Figure 8, the boundary conditions
are no slip conditions on all four walls.
w(x, 0) = w(x, Ly ) = w(0, y) = w(Lx , y) = 0.

(full duct)

For the quarter duct simulation depicted on the right hand side of Figure 8, the boundary conditions
are no slip conditions on the solid walls (x = Lx and y = Ly )
w(Ly , y) = w(x, Lx ) = 0

(quarter duct)

and symmetry conditions on the other two planes




u
u
=
= 0.
x x=0
y y=0
After the solution to the w field is obtained, the engineering quantity of interest is the product

Full Duct

Quarter Duct
Ly

Ly

y
x

y
Lx

x
Lx

Figure 8: Two possible calculation domains (shaded regions) for fully-developed flow in a rectangular
duct.

TRUNCATION ERRORS

15

of the Darcy friction factor f , and the Reynolds number Re, where


Dh
wD
h
dp
f= 1 2
Re =
dz

2 w
Dh is the hydraulic diameter
Dh =

4 cross section area


4A
=
wetted perimeter
P

and w
is the average velocity in the cross section
w
=

1
A

Z
wdA
A

The wetted perimeter depends on whether the full duct or quarter duct is being used in the numerical
model. (See Figure 8.) For the full duct, P = 2(Lx + Ly ). For the quarter duct, P = Lx + Ly .
Combining the expressions for f and Re yields


2Dh2
dp
f Re =

dz

Truncation Errors

The truncation error for the approximation leading to Equation (9) is O((x)2 ) + O((y)2 ). Consider the case where the solution is obtained on a square domain with a uniform grid. Then
x = y = h
If ex is the exact solution and fd is the finite- difference solution then at any point in the domain
e ex fd O(h2 )

(29)

Since e is defined wherever ex and fd are defined it is also a (discrete) field variable. If e is some
suitably defined average nodal error then we also expect that
e O(h2 )

(30)

With these estimates of truncation error we can use model problem 1, which has an easily
computable exact solution, to check the correctness of computer codes that implement the controlvolume finite-difference method. After obtaining the numerical solution we compute the normalized
L2 norm of the error at each node
pP
e2i
kek2
=
(31)
N
N
Substitute the average error, e for ei

pP
e2
kek2
N e2
e

=
=
N
N
N
N
For a uniform grid on a square domain N = n2x , where nx is the number of control volumes in the
x-direction (cf. Figure 1). The grid spacing is h = Lx /(nx + 1). Thus
 3
2
kek2
O(h2 )
O((Lx /(nx + 1)) )
1

=
O
(32)
N
nx
nx
nx
If the code is working correctly, doubling the number of control volumes in each direction will
reduce the normalized truncation error defined in Equation (31) by a factor of eight. The results of
testing a correct code are given in Table 6. The data in the first and last column of the table are
consistent with Equation (32).

REFERENCES

16

nx = ny

kek2
N

25

1.190 102

10

100

1.420 103

20

400

1.755 104

40

1600

2.187 105

80

6400

2.714 106

160

25600

3.414 107

1.190
0.1420
1.420
0.1755
1.755
0.2187
2.187
0.2732
2.732
0.3414

kek2
from
reduction in
N
the next coarser grid

= 8.39
= 8.09
= 8.02
= 8.06
= 8.00

Table 6: Reduction in normalized error for the control-volume finite-difference solution to model
problem 1.

References
[1] Jack J. Dongarra, Iain S. Duff, Danny C. Sorensen, and Henk A. van der Vorst. Solving Linear
Systems on Vector and Shared Memory Computers. SIAM, Philadelphia, 1991.
[2] Gene Golub and James M. Ortega. Scientific Computing: An Introduction with Parallel Computing. Academic Press, Inc., Boston, 1993.
[3] S.V. Patankar. Numerical Heat Transfer and Fluid Flow. Hemisphere, Washington D.C., 1980.

AXISYMMETRIC GEOMETRY

17

xw

xe

N
N
E

rn

rn
W

E
r

P
W

rs

rs
xw

xe

Figure 9: Axisymmetric control-volume.

Axisymmetric Geometry

The diffusion equation in axisymmetric coordinates is







1
1

+
+S =0
x
x
r r r r

(33)

Integrating the first term in Equation (33) over the finite control volume yields


 

Z rn 
Z rn Z x e

dx rdr =
dy

x
x
x
r
rs
xw x
s
 e
 w


rr
x e
x w


P W
E P
w

e
r
xe
xw
Integrating the second term in Equation (33) gives




Z x e Z rn

N P
P S
1
r
r dr dx rn n
rs s
x
r
rn
rs
xw
rs r r
Integrating the source term in Equation (33) over the control volume gives
Z x e Z rn
S r dr dx SP x rp r
xw

rs

where rp is the radial position of node P , and Sp is the source term evaluated at node P .

(34)

Anda mungkin juga menyukai