CVFDdiffusion2D[1]

Embed Size (px)

Citation preview

  • 8/7/2019 CVFDdiffusion2D[1]

    1/17

    The Control-Volume Finite-DifferenceApproximation to the Diffusion Equation

    Gerald W. RecktenwaldDepartment of Mechanical Engineering

    Portland State [email protected]

    January 12, 2010

    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. Thepartial differential equation is converted to a system of linear equations with the nite-volumemethod. The system is solved by a direct method, though extending the code to use iterativemethods would not be difficult. Use of the code requires the user to edit and run Matlabfunctions. Utility routines for prescribing a variety of boundary conditions and computing walluxes are provided to ease the programming tasks. The code is demonstrated with a handfulof sample problems.

    1 Introduction

    The control-volume nite-difference (CVFD) method is widely used in the numerical simulation of uid dynamics, heat transfer and combustion. Several commercial CFD (computational uid dy-namics) codes are based on this method. Though there is no one ultimate numerical approximationscheme, the CVFD method has numerous desirable features. It naturally maintains conservation of species when applied to conservation laws. It readily handles material discontinuities and conjugateheat transfer problems. It also has the pedagogical advantage that only simple calculus is requiredto 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

    x

    x

    + y

    y

    + S = 0 (1)

    where is the scalar eld, 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 dene a nite volume grid on a rectangulardomain. Following that the general form of the CVFD approximation to the diffusion equation isobtained. Next, the harmonic mean is introduced as the correct procedure for treating discontinuitiesin . 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 endswith a discussion of truncation error, including a quantitative procedure for verifying the correctnessof a CVFD code.

    1

  • 8/7/2019 CVFDdiffusion2D[1]

    2/17

    2 FINITE VOLUME MESH 2

    x

    y

    1 2 nx

    i = 0 2j = 0

    2

    3

    3 nx

    ny

    xu(1) = 0

    x(i)

    y(j)

    xu(i)

    1

    yv(j)

    yv(ny+1)

    xu(nx+1)

    1

    nx +1 nx +2

    nx ny

    yv(1) = 0

    Interior node

    Boundary node

    Ambiguous corner node

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

    2 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 dene the boundariesof the individual control volumes. The pattern created by the lines is called the computational gridor mesh. In Figure 1 the control volumes are square, but this is not required. At the center of eachcontrol volume is a node, designated by an open circle. Two sets of grid lines can be identied:the grid lines that dene the control volume faces, and the grid lines (not shown) that dene thelocations of the nodes. In the computer implementation the grid lines that dene node locations willbe stored in the variables x(i) and y(j) . The grid lines that dene the control volume interfaceswill 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 identied by their ( i, j ) grid indices. An additional naming con-

    vention 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 ) inFigure 1 is also referred to as node P in Figure 2. The ( i + 1 , j ) and ( i 1, j ) neighbors of P aredesignated E for east and W for west, respectively. The ( i, j + 1) and ( i, j 1) neighbors of P arereferred to as N and S for north and south, respectively. Figure 2 also denes numerous geometricvariables. In general the width, x, of a control volume will not be equal to the distances xe andxw between P and its east and west neighbors. Regardless of the grid spacing P is always located

  • 8/7/2019 CVFDdiffusion2D[1]

    3/17

    3 DISCRETE APPROXIMATION FOR INTERIOR CONTROL VOLUMES 3

    x w x e

    S

    PW E

    N

    x

    y

    x ex w

    y n

    y s y s

    y n

    Figure 2: Geometric variables for a typical control-volume.

    in the geometric center of its control volume. Thus

    xP xw = xe xP = x2

    (2)

    yP ys = yn yP = y2

    (3)

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

    3 Discrete Approximation for Interior Control Volumes

    The control volume nite-difference method is used to transform Equation (1) to a system of discreteequations for the nodal values of . First, Equation (1) is integrated over the typical control volumedepicted in Figure 2. This reduces the equation to one involving only rst derivatives in space.Then these rst derivatives are replaced with central difference approximations.

    Integrating the rst term in Equation (1) over the nite control volume yields

    y n

    y s

    x e

    x w

    x

    x

    dxdy =

    y n

    y s

    x e

    x w

    dy (4)

    x e

    x w

    y (5)

    eE P

    xe wP W

    xw y (6)

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

  • 8/7/2019 CVFDdiffusion2D[1]

    4/17

    4 NON-UNIFORM 4

    and e and w are the diffusion coefficients evaluated at the interfaces of the control volumes. Theprocedure 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

    x e

    x w y n

    y s

    y

    y

    dydx nN P

    yn sP S

    ys x (7)

    On the left side of Equation (7) the order of integration has been chosen so that the outer /yoperator is eliminated rst. This is allowable if the integrand is smooth, as is the case for solutionsto Equation (1).

    Integrating the source term in Equation (1) over the control volume gives

    x e

    x w y n

    y sSdydx S P x y (8)

    where S p is the source term evaluated at node P . Adding together Equations (6)8 and rearranging

    yieldsaS S aW W + aP P aE E aN N = b (9)

    where

    aE =e

    x x e(10)

    aW =w

    x x w(11)

    aN =n

    y yn(12)

    aS =s

    y ys(13)

    aP = aE + aW + aN + aS (14)

    b = S P (15)

    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 denes alinear system of N equations in the N unknown internal values of .

    4 Non-uniform

    Calculation of the coefficients in equations 1013 requires values of at the interfaces of the controlvolumes. Rather than using an interpolation scheme, the interface values of are dened byrequiring continuity of the diffusive ux at the control volume interfaces. Consider the situationdepicted in Figure 3 where two control volumes meet along a material discontinuity. This commonsituation occurs when the diffusion equation is solved in a composite material.

    Assume that is uniform within each of the control volumes. (When the nite volume grid isdened the control volume faces are aligned with discontinuities. Thus it is not an unreasonablerestriction to require that material properties are uniform within a control volume.) Continuity of ux at the interface requires

    P x x e

    = Ex x e +

    = ex x e

    (16)

  • 8/7/2019 CVFDdiffusion2D[1]

    5/17

    4 NON-UNIFORM 5

    xe

    material 1 material 2

    xe + x e -

    P E

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

    Equation (16) denes e . In other words, the value of e is chosen such that the ux, /x , iscontinuous. Central difference approximations to the ux continuity conditions in Equation (16)are

    eE P

    xe= P

    e P xe

    (17)

    eE P

    xe= E

    E exe +

    (18)

    where e is the value of at the interface. Equations 17 and 18 are discrete approximations for thediffusion ux 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 =xe P

    exe

    (E P ) (19)E e =

    xe +E

    exe

    (E P ) (20)Adding equations 19 and 20 gives

    E

    P =

    e

    xe(E

    P )

    xe

    P +

    xe +

    E.

    Cancel the factor of ( E P ) and solve for e /x e to getexe

    =xe P

    +xe +E

    1

    =E P

    xe E + xe + P .

    Thus,

    e =E P

    E + (1 )P (21)

  • 8/7/2019 CVFDdiffusion2D[1]

    6/17

    5 IMPLEMENTATION 6

    where

    xe

    xe=

    xe xP xE xP

    (22)

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

    5 Implementation

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

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

    Function Description

    fvAmatrix Store the nite volume coefficients aE , aW , aN , aS , and aP in the sparse matrix A in Equation (24).

    fvave Compute the volume-weighted average of a eld variableover the domain.

    fvbc Modify nite volume coefficients and source terms to in-

    clude the effect of boundary conditions. The nal value of aP is also computed.fvcoef Compute the neighboring nite volume coefficients ( aE ,

    aW , aN , and aS ) for all interior control volumes. No specialtreatment is applied to control volumes adjacent to bound-aries.

    fvpost Update unknown boundary values and heat uxes after thesolution to the interior nodes is obtained. An energy bal-ance is computed and printed. The temperature eld isstored in a matrix suitable for use with Matlab contourand surface plotting routines.

    fvUniformMesh Compute the location of cell centers and cell interfaces for

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

    fvUniBlockMesh Compute the location of cell centers and cell interfaces fora mesh consisting of blocks that contain uniform meshes.The overall mesh can contain blocks of unequal size andunequal numbers of control volumes. Within each block,the mesh is uniform.

  • 8/7/2019 CVFDdiffusion2D[1]

    7/17

    5 IMPLEMENTATION 7

    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 exible so that it can be applied to a number of different problems describedby 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, sacrice some efficiency orexibility in order to make the code easier to read.The solution to a particular problem is obtained by dening problem-specic grid and boundary

    values, and then using a set of generic Matlab functions. The generic Matlab functions are listedin Table 1.

    Table 2 represents the structure of an analysis code that uses the functions from Table 1. Onthe left is a block depicting the sequence of steps in the main program. On the right is a blockcontaining the names of the generic functions. Several of the steps in the main program are linkedby double-ended arrows to routine names Core Code box. These arrows indicate a function callin the main program that sends information to, and receives information from the generic routines.

    5.1 Mesh Variables

    The mesh is specied by four vectors: x, xu , y, and yv . As shown in Figure 1, x(i) and y(j) arethe x and y positions of the node for i,j . The indexing of the control volume faces is arbitrary. Wedene xu(i) to be the location of the face to the left of x(i) , and dene yv(j) to be the location of the face below y(j) . This convention comes from related codes that are used to model convectivetransport, which will not be discussed here.

    For many problems either a uniform or block-uniform mesh are suitable. We dene a uniformmesh to have uniform control volume widths in any one coordinate direction. The widths of thecontrol volumes in different directions need not be uniform. This situation is depicted in the lefthand side of Figure 4 where x = 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, thecalculation domain is divided into a number of panels in the x and y direction. The intersectionsof these panels dene 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 aparticular problem.

    Algorithm Tasks Core RoutinesDene the mesh fvUniformMeshDene boundary conditionsCompute nite-volume coefficients for interior cells fvcoefAdjust coefficients for boundary conditions fvbcSolve system of equationsAssemble coefficient matrix fvAmatrixSolveCompute boundary values and/or uxes fvpostPlot results

  • 8/7/2019 CVFDdiffusion2D[1]

    8/17

    5 IMPLEMENTATION 8

    Uniform Mesh Block-Uniform Mesh

    Lx1, nx 1 Lx2, nx 2

    Ly 1, ny1

    Ly 2, ny2

    Ly 3, ny3

    x

    y

    x

    y

    Figure 4: Uniform and block-uniform meshes. Note that the uniform mesh the widths of the controlvolumes in the x and y directions are not necessarily uniform. The term uniform describes thespacing of the control volumes along individual directions.

    x-direction panel, and adjacent panels can have different x. Similarly, y is uniform within ay-direction panel, but may vary from panel to panel. The fvUniBlockMesh function is used todene block-uniform meshes.

    For convenience, we dene 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 betweenadjacent 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 bestored in one-dimensional arrays (vectors) or multidimensional arrays. Storing the data in vectorshas the potential for greater computational efficiency, whereas multidimensional arrays allow themost straightforward programming.

    The grid in Figure 1 suggests that the discrete variable, , could be naturally stored as a two-dimensional array, phi(i,j) . If the indices of phi(i,j) run 0 i n x + 1 and 0 j ny + 1then 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 multidimensionalarrays does not preclude efficient programs. However, vector processors are more efficient whenoperating on longer vectors than shorter vectors. With stored in a two-dimensional array thelargest vector length is n x (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-dimensionalarray with the so-called natural ordering

    n = i + ( j 1)nxOther orderings are possible (see, e.g., [1, 2]).

    With natural ordering the neighbors in the compass point notation of Figure 2 have these indices

  • 8/7/2019 CVFDdiffusion2D[1]

    9/17

    5 IMPLEMENTATION 9

    np = i + (j-1)*nxne = np + 1nw = np - 1nn = np + nxns = np - nx

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

    1 , 12 , 1

    ...nx, 11 , 22 , 2

    ...i,j

    ...nx,ny

    12...

    nxnx +1nx +2

    ...n...

    N

    (23)

    If the interior values of are stored in a vector using natural ordering, additional storage for theboundary values must also be provided. One solution to this problem is to dene four additionalvectors

    ebcval(j), j = 1,..,nywbcval(j), j = 1,..,nynbcval(i), i = 1,..,nxsbcval(i), i = 1,..,nx

    The values stored in ebcval , etc., are the values of of the boundary nodes. This is sufficient forDirichlet 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 5matrix 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 boundariesare adjacent to nx control volumes. Table 3 documents the four types of boundary conditions thatare dened for the nite volume codes listed in Table 1.

    The names and dimensions of the boundary condition matrices are listed in Table 4. The rstletter of the matrix data structure indicates the location of the boundary. Thus, ebc contains datafor the east boundary, wbc contains data for the west boundary, etc. The structure of these matricesis the same for each boundary surface.

    Table 5 describes the contents of each column of ebc . The contents of the other boundarymatrices are analogous, except that the row index in nbc and sbc is the index of the boundary nodein the x direction, e.g. sbc(3,1) is the boundary condition type for the third cell from the left onthe south boundary.

  • 8/7/2019 CVFDdiffusion2D[1]

    10/17

    5 IMPLEMENTATION 10

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

    Boundarytype

    BoundaryCondition Post-processing in fvpost

    1 Specied T Compute q from discrete approximation to Fouriers law.

    q = kT b T ixb x i

    where T i and T b are interior and boundary temperatures,respectively.

    2 Specied q Compute T b from discrete approximation to Fouriers law.

    T b = T i + qxb

    x i

    kwhere T i and T b are interior and boundary temperatures,respectively.

    3 Convection From specied h and T , compute boundary temperatureand heat ux through the cell face on the boundary. Con-tinuity of heat ux requires

    kT b T ixb x i

    = h(T b T amb )which can be solved for T b to give

    T b =hT amb + ( k/x e )T i

    h + ( k/x e )

    where xe = xb x i4 Symmetry q = 0. Set boundary T b equal to adjacent interior T i .

    Table 4: Matrices for storing boundary condition data.

    Matrix boundary sizeebc east ny 5wbc west ny 5nbc north nx 5sbc south nx 5

  • 8/7/2019 CVFDdiffusion2D[1]

    11/17

    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 Valueebc(j,1) Integer from 1 to 4 indicating the type of boundary conditionebc(j,2) Value of T on the boundary node (if known)ebc(j,3) Value of heat ux 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 uid owing over the the bound-

    ary if ebc (j , 1) = 3.

    A = a S apa W a E a N

    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 eld requiressolving the system

    Ax = b (24)

    where the unknown vector x corresponds to the interior values of (cf. Equation (23)), the coefficientmatrix, A, consists of the coefficients of Equation (9), and the right hand side vector b, includes thesource term (Equation (15)) and boundary conditions. The matrix A is sparse in the sense thatthere are many more zero entries than non-zero entries. The structure of the A matrix is depicted

  • 8/7/2019 CVFDdiffusion2D[1]

    12/17

    6 MODEL PROBLEMS 12

    in Figure 5. The b vector is

    b =

    f 1 ,1 + aS1 , 1 1 ,0 + aW 1 ,1 0 ,1f 2 ,1 + aS2 , 1 2 ,0...f nx, 1 + aSnx, 1 nx, 0 + aEnx, 1 nx +1 ,1f 1 ,2 + aW 1 , 2 0 ,2f 2 ,2...f i,j...f nx,ny + aN nx,ny nx,ny +1 + aEnx,ny nx +1 ,ny

    (25)

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

    6 Model Problems

    Computer codes to solve Equation (1) may be exercised by applying them to a series of modelproblems. 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 withsimple 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 solutionstrategies.

    The model problems require solution of Equation (1) on a rectangular domain

    0 x Lx 0 y LyThe problems are distinguished by their different boundary conditions, and by the variation of thesource term and diffusivity in the domain.

    Model Problem 1

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

    f =

    Lx

    2

    +2Ly

    2

    sinxLx

    sin2yLy

    (26)

    The exact solution is = sin

    xLx

    sin2yLy

    (27)

    and is shown in Figure 6.

  • 8/7/2019 CVFDdiffusion2D[1]

    13/17

    6 MODEL PROBLEMS 13

    0

    0.5

    1

    00.20.40.60.81

    0

    0.5

    1

    1.5

    2

    yx

    0

    0.5

    1

    00.20.40.60.81

    0

    0.01

    0.02

    0.03

    0.04

    0.05

    0.06

    0.07

    0.08

    yx

    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. f (x, y ) = con-stant. 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 sourceterm and diffusion coefficient have different values in two subregions of the domain. Outside of thecentral region

    = 1 = 1 S = 0In the central region of the domain

    = 1 S = 1000

    where > 0 is a scalar. When = 1 there is a discontinuous diffusivity change between thetwo regions. Model problem 3 becomes more difficult to solve as the magnitude of increases ordecreases. The boundary conditions are

    (0, y) = 20 (Lx , y) = 0(x, 0) = 10 (x, L y ) = 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 fully-developed ow the governing equation for the axial velocity w is

    2 wx 2

    + 2 wy 2

    dpdz

    = 0 (28)

    The code for solving Equation (1) can be used to solve Equation (28) by making the followingdenitions

    = w, = (= constant) , S = dpdz

    .

  • 8/7/2019 CVFDdiffusion2D[1]

    14/17

    6 MODEL PROBLEMS 14

    0.25 Lx

    0.25 Ly

    0.5 Ly

    0.5 Lx

    Lx

    Ly 1 = 1

    S1 = 0

    2 = 1

    S2 = 1000

    0

    0.5

    1

    00.20.40.60.81

    0

    5

    10

    15

    20

    25

    30

    35

    yx

    Figure 7: Geometry of calculation domain (left) and nite-volume solution on a 64 64 mesh formodel problem 3.

    For the full duct simulation depicted on the left hand side of Figure 8, the boundary conditionsare no slip conditions on all four walls.

    w(x, 0) = w(x, L y ) = 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 conditionsare no slip conditions on the solid walls ( x = Lx and y = Ly

    w(Ly , y) = w(x, L x ) = 0 (quarter duct)

    and symmetry conditions on the other two planes

    ux x =0

    =uy y =0

    = 0 .

    After the solution to the w eld is obtained, the engineering quantity of interest is the product

    Full Duct

    x

    y

    Lx

    Ly

    Quarter Duct

    xy

    Lx

    Ly

    Figure 8: Two possible calculation domains (shaded regions) for fully-developed ow in a rectangularduct.

  • 8/7/2019 CVFDdiffusion2D[1]

    15/17

    7 TRUNCATION ERRORS 15

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

    f = D h12 w2 dpdz Re = wD h

    Dh is the hydraulic diameter

    D h =4 cross section area

    wetted perimeter=

    4AP

    and w is the average velocity in the cross section

    w =1A A wdA

    The wetted perimeter depends on whether the full duct or quarter duct is being used in the numericalmodel. (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

    f Re = 2D2h

    w dpdz

    7 Truncation Errors

    The truncation error for the approximation leading to Equation (9) is O(( x)2 ) + O(( y)2 ). Con-sider 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 nite- difference solution then at any point in the domain

    e ex fd O(h2 ) (29)

    Since e is dened wherever ex and fd are dened it is also a (discrete) eld variable. If e is somesuitably dened average nodal error then we also expect that

    eO(h2 ) (30)

    With these estimates of truncation error we can use model problem 1, which has an easilycomputable exact solution, to check the correctness of computer codes that implement the control-volume nite-difference method. After obtaining the numerical solution we compute the normalizedL2 norm of the error at each node

    e 2N

    = e2i

    N (31)

    Substitute the average error, e for ei

    e 2N e2N = N e2N = eN

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

    e 2N

    O(h2 )nx

    = O((Lx / (nx + 1))2 )

    nx O1

    nx

    3

    (32)

    If the code is working correctly, doubling the number of control volumes in each direction willreduce the normalized truncation error dened in Equation (31) by a factor of eight. The results of testing a correct code are given in Table 6. The data in the rst and last column of the table areconsistent with Equation (32).

  • 8/7/2019 CVFDdiffusion2D[1]

    16/17

    REFERENCES 16

    n x = ny N e 2N

    reduction ine 2N

    from

    the next coarser grid5 25 1.190 10

    2

    10 100 1.420 10 31.190

    0.1420= 8 .39

    20 400 1.755 10 41.420

    0.1755= 8 .09

    40 1600 2.187 10 51.755

    0.2187= 8 .02

    80 6400 2.714 10 62.187

    0.2732= 8 .06

    160 25600 3.414 10 7 2.7320.3414 = 8 .00

    Table 6: Reduction in normalized error for the control-volume nite-difference solution to modelproblem 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. Scientic Computing: An Introduction with Parallel Com-puting . Academic Press, Inc., Boston, 1993.

    [3] S.V. Patankar. Numerical Heat Transfer and Fluid Flow . Hemisphere, Washington D.C., 1980.

  • 8/7/2019 CVFDdiffusion2D[1]

    17/17

    A AXISYMMETRIC GEOMETRY 17

    P

    xw x e

    S

    W E

    N

    x

    r

    xe

    xw

    r n

    r s

    r s

    r n

    P

    S

    N

    W

    E

    Figure 9: Axisymmetric control-volume.

    A Axisymmetric Geometry

    The diffusion equation in axisymmetric coordinates is

    x

    x

    +1r

    r

    1r

    r

    + S = 0 (33)

    Integrating the rst term in Equation (33) over the nite control volume yields

    r n

    r s x e

    x w

    x

    x dxrdr =

    r n

    r s x e

    x w dy

    x e

    x w

    r r

    eE P

    xe wP W

    xw r

    Integrating the second term in Equation (33) gives

    x e

    x w r n

    r s

    1r

    r

    r r

    rdrdx r n nN P

    r n r s sP S

    r s x

    Integrating the source term in Equation (33) over the control volume gives

    x e

    x w r n

    r sSrd rdx S P x r p r (34)

    where r p is the radial position of node P , and S p is the source term evaluated at node P .