You are on page 1of 19

4.

DISCRETIZATION OF EQUATIONS In a numerical solution, we seek the flow field or the values of the flow variable such as the velocity components and the pressure at discrete, predetermined grid points spread throught the flow domain. The location of these grid points is determined as part of the grid generation process which is discussed in detail in Chapter 9. Here only the basic concepts are presented. Two principal approachesthe structured mesh and the unstructured mesh-can be adopted to discretize the physical space. A structured mesh or grid is one in which the grid nodes are located at intersections of families of curvilinear coordinate lines (Figure 4.1a) and a grid cell is topologically rectangular in two dimensions and cubical in three dimensions. If a consistent numbering system is employed, then identification of neighbouring grid nodes is straightforward. An unstructured mesh does not have such structure and can be made up of arbitrarily shaped cells (Figure 4.1b). Meshing flow domains of irregular shapes, especially in three dimensions, is more easy with an unstructured mesh. Local grid refinement and grid adaptation are also simpler as compared to a structured mesh. However, the discretized equations are more difficult to solve and construction of higher order discretization schemes is more difficult. A number of techniques can be used to generate the grid and some of the salient ones are discussed later in Chapter 9. Once the physical discretization of the flow domain is completed, the discretization of the governing equations can be carried out. This process, as we have seen in Chapter 1, results in linear algebraic equations in which the values of the flow variables at these grid points are the unknowns which have to be solved simultaneously (except in cases where an explicit scheme is used for a marching-forward type of problem). There are several methods for the discretization of the equations, viz., the finite difference method, the finite volume method, the finite element methods, spectral methods, collocation methods, etc. While all these have been used for fluid flow problems, the first two methods are the most popular and can be said to be the first choice for systems of equations involving coupled non-linear partial differential equations as may happen, for example, with a turbulent combusting flow. In such cases, the coefficient matrix resulting from the use of, for example, the finite element method, may be too complicated for a generic solution scheme to work efficiently. Also, with the advent of the finite volume method, irregular physical geometries can be readily accounted for with an unstructured mesh at a simpler level than what is possible with the finite element method. We therefore focus our attention on the finite difference and the finite volume method in this book. The use of finite element method for fluid flow problems is described in Baker (1991), among others and the interested reader is referred to it. Of the two methods to be dealt with here, the finite difference method is the older and far simpler approach and is said to have started with Euler in about 250 years ago. The finite volume method is of more recent origin and some of the early papers using this method have been published by McDonald (1971). The finite difference method requires a structured mesh while the finite volume method can be used also on an unstructured mesh. The basic ideas and techniques of each method are discussed below.

4.1 The Finite Difference Method 4.1.1 Basic Concepts

For the purposes of the present chapter dealing with discretization of the equations, we assume for simplicity and without loss of generality that we are dealing with a structured mesh with uniform spacing in cartesian coordinates shown in Figure 4.1c. Here, the simple two-dimensional space is divided into cells of width of Dx and height of Dy. The grid nodes are located at intersections of constant x planes, each Dx apart, and constant y-planes, each Dy apart. Thus, the point P lying at the intersection of the ith x-plane and jth y-plane has the coordinates (xi, yj) where x = i Dx and yj = j Dy and the point P can be identified by the grid node (i,j). The point Q, which is the immediate left neighbour of P, is identified as (i-1, j). Similarly, the immediate right, top and bottom neighbours can be identified as (i+1, j), (i, j+1) and (i, j-1), respectively. Such simple identification of the neighbours is possible only in a structured grid and is of great help in discretization of equations, as we will see later. The finite difference method for the discretization of an equation is based on the properties of Taylor expansions using which each derivative appearing in the equation is written approximately in terms of finite differences. Consider the first derivative of u, du/dx at x in a one-dimensional space discretized with a uniform mesh spacing of dx (Figure 4.2). A finite difference approximation for this can be obtained from a Taylor series expansion of u(x+Dx) around point x: x ( x + x ) = u ( x ) + x u x ( x ) + x 2 u xx ( x ) + " 2

(4.1.1)

Note that we assume that u(x) is continuous enough that all the higher derivatives are defined. The series converges if dx is small and in such a case, successive terms of the series are progressively smaller. An approximation for u(x+dx) can be made involving only a finite number of terms in the series. For example, a second-order accurate series expansion is obtained by neglecting terms involving the third and higher derivatives: U(x + dx) = u(x) + du/dx dx + d2u/dx2 dx^2 + O(dx3) (4.1.2)

where O(dx3) indicates terms of the order of dx3 or less. Rearranging (4.1.2), we get an expression for the first derivative at x as du/dx)x = which can be written using the notation given in Figure 4.2 as du/dx)I = (ui+1 - ui)/dx + O(dx) (4.1.4) (4.1.3)

indicating that the grid spacing, dx, occurs as a first power in the leading term in the neglected part of the Taylor series, namely, Dx/2 d2u/dx2 at x. This implies that the error in the approximation for the first derivative decreases as (dx)^1 as dx decreases. Hence, this approximation is said to be first order-accurate. Expanding u(x-dx) around point x, another approximation can be derived for the first derivative. Thus, U(x-dx) = u(x) -dx du/dx)x Rearranging equation (4.1.5), we get Du/dx)x =[ u(x) - u(x-dx)]/dx + d2u/dx2 dx/2 + Or du/dx)I = (ui-ui-1)/dx + O(dx) which again gives a first-order approximation for the first derivative. (4.1.6) (4.1.7) (4.1.5)

Yet another approximation for du/dx at x can be obtained by subtracting (4.1.5) from (4.1.1): U(x+dx) - u(x-dx) = 2dx du/dx + 2dx3 d3u/dx3 + Rearranging eqn. (4.1.8), we obtain Du/dx)x = (ux+dx - ux-dx)/2dx + d3u/dx3)x dx2/3 + Or Du/dx)I = (ui+1 -ui-1)/2dx + O(dx2) (4.1.8)

(4.1.9) (4.1.10)

Since the grid spacing occurs in the leading term as dx^2, the error in the approximation decreases as (dx)^2. Thus, if the grid spacing is decreased by a factor of 2, the discretization error decreases by a factor of 4 provided the Taylor series expansions are converging. Thus, the approximation given by (4.1.10) is said to be second order accurate. The three approximations for the first derivative, given by (4.1.4), (4.1.7) and (4.1.10) are scehmatically represented in Figure 4.3 and are respectively called forward, backward and central differencing schemes. The forward difference approximation is given by slope of the line joining point I and I+1, the backward by the slope of the straight line joining points I-1 and I, and the central scheme by the slope of the line joining points I-1 and I+1. It can be seen readily that the central scheme gives a better approximation to the true first derivative, given by the slope of the tangent to the curve at point I than either the first or the second derivative. Generally, one-sided differences (i.e., forward and backward differences) are less accurate than central schemes for the same number of points. One-sided differences are required for approximating the derivatives at boundaries.

It is possible to construct finite difference approximations of higher accuracy but this requires inclusion of more number of adjacent points (which ultimately leads to a more complicated system of discretized equations). Let us construct a third-order difference approximation for the first derivative at i using forward differencing. As we will see later, this requires four adjacent points, namely, I, I+1, I+2 and I+3. Let us seek therefore an approximation of the form Du/dx)I = (aui + bui+1 + cui+2 dui+3)dx + O(dx^3) (4.1.11)

Noting that a third-order approximation for the first derivative implies elimination of the second and the third derivatives from the Taylor series approximation (just as the second order approximation of the central scheme in equation (4.1.10) meant elimination of the second derivative in the approximation, see equation 4.1.9), equation 4.1.11 can also be written as Du/dx)I = (aui+bui+1 + cui+2 + dui+3)/Dx + (0) d2u/dx2 (dx) + (0) d3u/dx3 (dx2) + (e) d4u/dx4 (dx3) (4.1.12a) Or aui+bui+1 + cui+2 + dui+3 = du/dx dx + (0) d2u/dx2 (dx2) + (0) d3u/dx3 (dx3) - (e) d4u/dx4 (dx4) (4.1.12b) where constants a, b, c and d are to be determined. Expanding ui+1, ui+2 and ui+3 in terms of Taylor series around ui, we have ui+1 = ui + du/dxdx + ui+2 = ui + du/dx2dz + ui+3 = ui + du/dx3dx + Evaluating (aui + bui+1 + cui+2 + dui+3), we get aui + bui+1 + cui+2 + dui+3 = aui + b(4.1.13a) + c(4.1.13b) + d(4.1.13c) z1 ui + z2 du/dx dx + z3 d2u/dx2 dx2 + z4 d3u/dx3 dx3 + z5 d4u/ dx4 dx4 (4.1.13a) (4.1.13b) (4.1.13c)

(4.1.14)

Comparing the coefficients of the like terms in equations(4.1.12b) and (4.1.14), we get Z1 = 0 Z2 = 1 Z3 = 0 Z4 = 0 Z5 = e =/ 0

(4.1.15)

Which yield a = 1/8, b = 1/8, c = 1/8 and d= 1/8. Thus, the third order approximation for the first derivative at point I using forward differences can be written as Du/dx)I = (4.1.16)
4

A second order accurate scheme for the first derivative at point i using forward differences can similarly be derived as Du/dux)I = And using backward differences as Du/dx)I = (4.1.18) (4.1.17)

Comparing expressions (4.1.17), (4.1.18) and (4.1.10), we find that a second order scheme for the first derivative using forward or backward scheme requires three points whereas a central scheme requires only two points. Also, comparing expressions (4.1.3), (4.1.17) and (4.1.16) for the first derivative with first, second and third order accuracy, we find that the increasing the accuracy of a scheme by one order requires the inclusion of one additional adjacent point. The result can be generalized and a general method for the derivation of an approximation of any order of accuracy has been discussed by Hildebrand (1956). The derivation of finite difference approximations for higher derivatives is straightforward. For example, the second derivative of u with respect to x at x can be approximated as D2u/dx2)I = d/dx(du/dux)]I = (1/dx)(du/dx)I+1/2 - du/dx)I-1/2) = 1/dx( u+1 - ui)/dx - (ui-ui-1)/dx) = 1/dx2(ui+1 -2ui - ui-1)

(4.1.19)

In the above approximation, central differences are used throughout over a mesh spacing of dx/2 and the resulting accuracy of the scheme is second-order, as can be verified by a Taylor series expansion. Thus, D2u/dx2)I = 1/dx2(ui+1 -2ui - ui-1) + O(dx2) (4.1.20)

The second derivative can also be evaluated in terms of forward differences alone. Thus, D2u/dx2)I = d/dx(du/dux)]I = (1/dx)(du/dx)I+1 - du/dx)I) = 1/dx( u+2 - ui+1)/dx - (ui+1- ui)/dx) = 1/dx2(ui+2-2ui+1 ui)

(4.1.21)

Since forward differences are used, this approximation will be of first order accuracy. Thus, D2u/dx2)I = 1/dx2(ui+2-2ui+1 ui) + O(Dx) (4.1.22)

A combination of backward and forward differences leads to a central difference approximation in this cases. Thus,
5

Du2/dx2)I = (1/dx) (du/dx)I - du/dx)I-1) = (1/dx)[ (ui+1 - ui)/dx - (ui -ui-1)/dx)] = (1/dx2) (ui+1 - 2ui + ui-1)

(4.1.23)

which is the same as equation (4.1.19). An approximation for the third derivative can also be obtained in similar way. Thus, d3u/dx3)I = d/dx(d2u/dx2)]I = 1/2dx(d2u/dx2)I+1 - d2u/dx2)I-1) = 1/2dx [(ui+2 -2ui+1 + ui)/dx2 - (ui -2ui-1 + ui-2)/dx2] = 1/2dx3(ui+2 -2ui+1 + 2ui-1 -ui-2) + O(dx2)

(4.1.24)

where central difference approximations for d2u/dx2 are substituted at points I+1 and I-1. The resulting expression is second order accurate. It is instructive to compare the second order accurate approximations for the first, the second and the third derivatives given by (4.1.10), (4.1.20) and (4.1.24), respectively. It can be seen that the even derivatives will have the value at the point I while the odd-derivatives do not involve the value at the point where the derivative is being evaluated . Also, for the same order of accuracy, increasing the order of derivative by one order requires the inclusion of an additional point. Thus, a general result can be stated that if p is the order the derivative being evaluated, q is the accuracy of discretization and n is the number of adjacent points used in the discretization, then n = p + q - 1, n>=2 for central differencing and n = p + q for one-sided differencing. This result is valid only for uniform meshes where some of the terms cancel out. The case of non-uniform meshes is discussed in Section 4.3. Finally, the evaluation of mixed derivatives, which usually occur in fluid mechanics problems as a result of coordinate transformation to a non-orthogonal system (see Chapter 9), is also straightforward. The second derivative of u with respect to x and y, d2u/dxdy, at the point (I,j) can be expressed as D2u/dxdy]I,j= d/dx(du/dy)I,j = 1/2dx(du/dy)I+1, j - du/dy)I-1,j) (4.1.25) = 1/2dx[1/2dy(uI+1,j+1 - uI+1,j-1) - (ui-1,j+1 -ui-1,j-1)] = 1/4dxdy [ uI+1,j+1 - uI+1,j-1 - ui-1,j+1 + ui-1,j-1] + O(dx2, dy2) Since central schemes are used throughout, the above expression is second-order accurate. Changing the order of differentiation and using backward differences, we get the following expression for d2u/dxdxy at point (I,j): D2u/dxdy]I,j= d/dy(du/dx)I,j = 1/dy(du/dx)I, j - du/dx)I,j-1) (4.1.26) = 1/dy[1/dx(uI,j - uI-1,j) - (ui,j-1 -ui-1,j-1)] = 1/dxdy [ uI,j - uI-1,j - ui,j-1 + ui-1,j-1] + O(dx, dy)

It is possible to use a combination of one-sided and central schemes, as may be required, for example, at a boundary. Thus, D2u/dxdy]I,j= d/dx(du/dy)I,j = 1/2dx(du/dy)I+1, j - du/dy)I-1,j) (4.1.27) = 1/2dx[1/dy(auI+1,j+2 +b uI+1,j+1 +cui+1,j) - (aui -1,j+2 +bui1,j+1+cui-1,j)] = 1/2dxdy [ auI+1,j+2+b uI+1,j+1 +cui+1,j - aui -1,j+2 -bui-1,j+1-cui1,j ) + O(dx2, dy2) where a second-order forward difference scheme is used to evaluate the derivatives with respect to y. Thus, a very large number of finite difference approximations can be obtained for the derivatives of functions. Some of these are summarized in Table 4.1.

4.1.2

Discretization of Differential Equations using Finite Differences

Finite difference approximations for differential (both ordinary and partial) equations can be readily obtained by writing the approximation for each derivative. Let us illustrate this with the case of a two-dimensional Poisson equation of the form D2u/dx2 + d2u/dy2 = f (4.1.28)

subject to the boundary condition that u is given by a Dirichlet condition on all the boundaries (see Figure 4.3). For an interior point (I,j), the first term on the left hand side of equation (4.1.28) can be written using central differencing as d2u/dx2)(I,j) = 1/dx^2 (ui+1,j - 2ui,j + ui-1,j) + d^3u/dx3 (dx)^2/2/3! + Similarly, the second term on the left hand side can be written as d2u/dy2)(I,j) = 1/dy^2 (ui,j+1 - 2ui,j + ui,j-1) + d^3u/dy3 (dy)^2/2/3! + Denoting by fi the value of f at the point (xi,yj), the discretized form of the equation (4.1.28) can be written as 1/dx^2 (ui+1,j - 2ui,j + ui-1,j) + 1/dy^2 (ui,j+1 - 2ui,j + ui,j-1) = fi (4.1.29) - [ d^3u/dx3 (dx)^2/2/3! + + d^3u/dy3 (dy)^2/2/3! + ] The quantity in square brackets on the right hand side is the overall truncation error in writing equation (4.1.28) in the following discretized form 1/dx^2 (ui+1,j - 2ui,j + ui-1,j) + 1/dy^2 (ui,j+1 - 2ui,j + ui,j-1) = fi (4.1.30)
7

Since Dirichlet boundary conditions are used throughout the boundary, the variable values over the boundary are specified and need not be determined. Equation (4.1.30) can therefore be used for all interior points, i.e., 2 = I = Ni and 2 = j = Nj, where Ni and Nj are the number of divisions in the ith and the jth directions, respectively. These result in Ni x Nj algebraic equations which have to be solved simultaneously for ui,j. If Neumann or other boundary condition is given over part of the boundary, then the values of ui,j on this boundary should be determined by solving additional algebraic equations. For example, the boundary AB in Figure 4.4 is plane along which the gradient is specified, viz., du/dy = c1. Approximating the gradient using forward difference, we can write for points on the boundary AB (u(I, j+1) -u(I,j))/dy = c1 or u(I,j) = u(I, j+1) - c1*dy (4.1.31)

However, the above approximation is only first order accurate. Using a second order accurate one-sided formula for the first derivative, we can write (au(I,J+2) +bu(I,J+1) + cu(I,j))/Dy = du/dy)i.j = c1 or u(I,j) = (c1*dy - a u(I,j+2) -b u(I,j+1) )/c (4.1.32)

Another boundary condition that is often encountered in heat conduction problems is the socalled convective boundary condition, namely, that, say, the heat flux from the surface is given by Q"w = h (Tinf - Tw) where h is the convective heat transfer coefficient, Tinf is the free stream temperature of air and Tw is the local wall temperature which is the unknown quantity. This boundary condition can be implemented readily by noting that q"w is also given by q"w = -kdT/dy)wall within the computational domain. Using a second order accurate forward differencing formula for the derivative, we thus have H(Tinf -T(I,j) ) = -k Dt/Dy)wall = -k(at(I,j+2) +bT(I,j+1) +c(tI,j))dy Or T(I,j) = (hdy/k(Tinf) - a T(I,j+2) -b T(I,j+1) )/c (4.1.33)

The above approach can be used to determine the wall temperature from a known temperature gradient or the wall heat flux from a known (calculated) temperature distribution. EX: One-dimensional heat conduction with source term

It is usual to maintain the same order of accuracy of discretization for each term. However, if the situation warrants, for example, if terms of unequal importance are present in the equation, it is sufficient to use a higher order approximation for the significant terms; using a lower order of approximation for the unimportant terms may be computationally efficient. For instance, the convective terms in creeping flow have very little effect and are usually neglected in analytical solutions. In a numerical solution, it would be sufficient to
8

treat these with a first order scheme while treating the diffusive term with a second order accurate scheme. Another case in question is the boundary layer flows where streamwise gradients are likely to be less significant at regions well away from the stagnation points. Similarly, when a time-dependent formulation is used for a steady problem (see chapter 6), the interest lies in the steady state solution and the time-dependent terms may therefore be treated in a simple manner. 4.1.3 Discretization of Time-dependent Equations

The discretization of time-dependent equations introduces a peculiar dilemma. Consider the unsteady state, one-dimensional heat conduction equation: DT/dt = alpha d2T/dx2 (4.1.34)

Where alpha is the thermal diffusivity. Consider a uniform discretization in space of with a step of Dx and in time with a time step of Dt. Using the subscript I to denote the ith space step and the superscript n to denote the nth time step, ie. Xi = iDx and tn = nDt, we seek a discretization of this equation of the form DT/dt)I,n = alpha d2T/dx2)I,n (4.1.35)

The left hand side of equation (4.1.35) can be readily discretized using, for example, forward differencing: DT/dt )i.n = 1/Dt (Ti n+1 - Ti,n) +O(Dt) (4.1.36)

The spatial discretization of the right hand side term is straightforward. For example, using central differencing and taking alpha to be constant, we have Alpha d2T/dx2)i = alpha/dx2 (Ti+1 -2Ti + Ti-1) + O(dx2) (4.1.37)

However, it remains to be specified at what time the RHS of equation (4.1.37) is to be evaluated. There can be three choices: evaluate it at the nth time step; evaluate it at (n+1)th time step; or evaluate it at n' where n < n' < n+1, e.g., n' = (1/2(n+ n+1). Accordingly, we can write (4.1.37) as Alpha d2T/dx2)I,n = alpha/dx2 (Ti+1,n -2Ti,n + Ti-1,n ) Or Alpha d2T/dx2)I,n = alpha/dx2 (Ti+1,n+1 -2Ti,n+1 + Ti-1,n+1 ) Or, Alpha d2T/dx2)I,n = alpha/dx2 (Ti+1,n' -2Ti,n' + Ti-1,n' ) (4.1.38c) (4.1.38b) (4.1.38a)

The first option (equation 4.1.38a) leads to the following discretization of equation (4.1.34): 1/Dt (Ti n+1 - Ti,n) = alpha/dx2 (Ti+1,n -2Ti,n + Ti-1,n ) or Ti,n+1 = Ti,n + alpha*dt/dx2(Ti+1,n -2Ti,n + Ti-1,n) (4.1.39)

Equation (4.1.39) has the special feature that all the terms on the right hand side are known at the beginning of a new time step calculation. Hence, if one sweeps through all the spatial points systematically at a given time step, equation (4.1.39) gives an explicit formulation for the calculation of Ti,n+1 in terms of known values of variables at the nth time step. Hence, one can march forward in space and time from given initial conditions. The second option (equation 4.1.38b) leads to the following discretization of equation (4.1.34): 1/Dt (Ti n+1 - Ti,n) = alpha/dx2 (Ti+1,n+1 -2Ti,n+1 + Ti-1,n+1 ) or Ti,n+1 = Ti,n + alpha*dt/dx2(Ti+1,n+1 -2Ti,n+1 + Ti-1,n+1) (4.1.40)

This implicit formulation does not allow one to march forward in time and space because in order to calculate Ti,n+1, both Ti+1,n+1 and Ti-,n+1 should be known whereas only one of these two is known. It is therefore necessary to solve equations for all the grid points simultaneously to get Ti,n+1. Hence the implicit method leads to a more complicated scheme. However, implicit methods are more stable than explicit methods and therefore can be used with larger time steps, as we will see in Chapter 5. The third choice (equation 4.1.38c) leads to the following discretization of equation (4.1.34): 1/Dt (Ti n+1 - Ti,n) = alpha/dx2 (Ti+1,n' -2Ti,n' + Ti-1,n' ) or Ti,n+1 = Ti,n + alpha*dt/dx2(Ti+1,n' -2Ti,n' + Ti-1,n') (4.1.41)

And will have some implicit component in it. Here, special mention must be made of two schemes: the Dufort-Frankel scheme and the Crank-Nicolson scheme. In the DufortFrankel (DuFort & Frankel, 1953), Ti,n is taken as the average of the Ti values at n-1 and n+1 time steps, i.e., Ti,n = 1/2(Ti,n-1 + Ti,n+1) Substituting this into equation (4.1.39), we obtain (Ti,n+1 - Ti,n-1)/2dt = alpha/dx2(Ti+1,n -Ti,n+1 -Ti,n-1 +Ti-1,n) or Ti,n+1 = (4.1.43)
10

(4.1.42)

which can be shown to be second order accurate in both time and space, explicit and unconditionally stable! However, as we will see later, it suffers from lack of consistency. In the Crank-Nicolson scheme (Crank & Nicolson, 1947), each term on the right hand side of equation (4.1.37) is taken as the average of the values at n and n+1. Thus, the discretized equation (4.1.34) becomes 1/dt(Ti,n+1 - Ti,n) = alpha/2dx2 (Ti+1,n + Ti+1,n+1 - 2Ti,n -2Ti,n+1 + Ti-1,n + Ti1,n+1) or -r Ti-1,n+1 + (2+2r) Ti,n+1 -r Ti+1,n+1 = r Ti-1,n + (2-2r) Ti,n +r Ti+1,n (4.1.44)

which is implicit, second-order accurate and unconditionally stable. The central question in equation (4.1.38) is how the time-averaged value of Ti etc are to be determined. Strictly, T_ = 1/dt int t-dt/2 t t+dt/2 (Tdt) (4.1.45)

This can be represented as a linear combination of the values of Ti at n and n+1, i.e., T_ = theta Ti,n + (1-theta) Ti,n+1 (4.1.46)

Explicit and implicit schemes represent the two extreme cases where theta is taken as one and zero, respectively, while the Crank-Nicolson scheme has a theta value of 1/2. Any other value of theta is possible. The appropriate approximation depends on the specific case. Consider the analytical integration of Dt/dt = T leading to T ~ exp(t). Thus, a typical variation of T with time may be as shown by the curve a in Figure 4.xxa. The idealized values of T ~ f(t) assumed by the explicit, implicit and the Crank-Nicolson schemes are shown by curves b, c and d, respectively. The explicit scheme assumes the value at Tn to prevail during the integration while the implicit scheme assumes the value at Tn+1 to prevail. The Crank-Nicolson takes an average value to be the representative value. If the actual time step used in the numerical calculation is small compared to, say, the time constant of the exponential variation, then explicit scheme is more likely to be accurate (Figure 4.xxb). If Dt is very large, then the implicit scheme gives a more accurate representation (Figure 4.xxc), while the Crank-Nicolson scheme is likely to be the most accurate for intermediate values of Dt (Figure 4.xxd). 4.1.4 Finite difference method on non-uniform meshes

Non-uniform meshes are often necessary in locations within flow domain where there is a rapid change in the properties of one or more flow variables. Common examples of such cases are the regions close to a solid wall where velocities may change rapidly in the
11

direction normal to the wall, regions in which rapid change of flow direction takes place, regions around shocks and other discontinuities. In order to resolve the flow variables accurately in these regions, it becomes necessary to use a fine mesh. However, the use of such a fine mesh throughout the flow domain may become impossible and often wasteful in terms of computational resources. Hence, a non-uniform mesh, the mesh spacing often reducing in a geometric progression, is employed. Here, we examine the implications of using such non-uniform meshes. The derivation of finite difference approximations on a non-uniform mesh is quite straightforward. Consider the non-uniform mesh in one-dimension shown in Figure 4.xxx. Here, the spacing between point I and point (I+1) is denoted by Dxi and that between points (I+1) and (I+2) by Dxi+1, and so on. A forward difference approximation for the first derivative at point I can be readily obtained as before by expanding u(I+1) about point 1. Thus, U(xi+1) = u (xi + Dxi) = u(xi) + dxi du/dx)xi + d2u/dx2)xi dxi^2/2! + . (4.1.47) Or Du/dx)I = (ui+1 -ui)/Dxi - d2u/dx2)I (dxi) + O(dxi2) (4.1.48)

Similarly, a backward difference approximation for the du/dx at xi can be obtained by expanding u(xi-1) about point i. Thus, U(xi-1) = u(x-dxi-1) = u(xi) - du/dx)I dxi-1 + d2u/dx2)I dxi-1^2/2! + . (4.1.49) Or Du/dx)I = (ui-ui-1)/dxi-1 + d2u/dx2)idxi-1 + O(dxi-1^2) (4.1.50)

So far, there is no difference between uniform and non-uniform meshes except for the subscript to the mesh spacing. If we subtract eqn. 4.1.49 from eqn. 4.1.47 in order to get a central difference approximation for du/dx)I, we obtain after algebraic manipulations Du/dx)I = (ui+1 -ui-1)/(dxi-1 + dxi+1) - d2u/dx2)I (dxi - dxi-1)/4 - (dxi2-dxi-1^2)/12 d3u/dx3) +

(4.1.51)

Here we see that the second derivative term does not cancel out unless dxi-1 = dxi and a first order accuracy results if (dxi-dxi-1) ~ dxi, as may happen with a sudden change in grid spacing. However, instead of arithmetic averaging of the forward and backward difference approximations, if a weighted average, using the mesh spacings as the relative weights, is used, a second-order accurate central difference scheme may be obtained. Multiplying eqn. 4.1.48 by dxi-1 and eqn. 4.1.50 by dxi and adding, we find that the second derivatives cancel out, and we get the following central scheme after some simplications: Du/dx)I = 1/[dxi-1 dxi (dxi-1 + dxi)] [ui+1 (dxi-1)^2 - ui-1 (dxi^2) + ui(dxi-1^2 dxi^2] - dxi-1 dxi/6 d3u/dx^3)I + .. (4.1.52)
12

which is thus second order accurate. Similarly, the following second-order accurate forward difference formula can be obtained for the first derivative on a non-uniform mesh: du/dx)I = [(dxi + dxi+1)/dxi+1][(ui+1 -ui)/dxi ] - [dxi/dxi+1] [ (ui+2 - ui)/(dxi + dxi+1)] + dxi (dxi+dxi+1)/6 d^3u/dx^3) I (4.1.53) Similarly, evaluating the second derivative at I using the central scheme D2u/dx2)I = [(du/dx)I+1/2 - (du/dx)I-1/2)]/[1/2(dxi-1 + dxi)] Results in the following central differencing formula for the second derivative on a nonuniform mesh: D2u/dx2)I = [ui+1 dxi-1 + ui-1 dxi - ui(dxi-1 + dxi)]/[1/2(dxi-1 +dxi) dxi-1 dxi] - (dxi - dxi-1)/3 d3u/dx3)I + - (dxi-1^3 + dxi^3)/[12(dxi-1 + dxi)] d4u/dx4 + (4.1.54) In the above expression, the leading term in the truncation error is proportional to the difference between successive mesh spacings and the scheme is therefore of first order accuracy if dxi ~ 2dxi-1. Thus, there is a general loss of accuracy on non-uniform meshes if care is not exercised in deriving the approximations. Ferziger & Peric (1999) argue however that although the schemes (4.1.51) and (4.1.54) are nominally first-order accurate, they asymptotically approach second-order accuracy with successive subdivision of the coarse grid. However, for any finite dxi, the scheme (4.1.52) will lead to a better approximation than scheme (4.1.51).

4.2 The Finite Volume Method The finite volume method offers two distinct advantages over the finite difference method of discretizing the governing equations. These are (i) that the satisfaction of the conservation law can be guaranteed at discrete level rather than only at global level, and (ii) that the method can be applied for an unstructured mesh also. The former gives the finite volume method a distinct advantage in dealing with discontinuous flows while the latter enables one to treat a geometry of arbitrary complexity. It also offers advantages in implementing algorithms for local grid refinement, grid adaptation and multigrid solution schemes. The method involves discretization of the integral formulation of the conservation laws directly in the physical space and is said to be introduced independently by McDonald (1971) and MacCormack and Paullay (1972) for the solution of two-dimensional, timedependent Euler equations. It can be considered as a finite difference method applied to the differential, conservative form of the conservation laws written in arbitrary co-ordinates, or as a variant of a weak formulation of the finite element method. In this section, we will examine the essential features of discretization of the governing equations using the finite volume method.

13

The method takes full advantage of an arbitrary mesh, where a large number of options are open for the definition of the control volumes around which the conservation laws are expressed. Modifying the shape and location of the control volumes associated with a given mesh point, as well as varying the rules and accuracy for the evaluation of the fluxes through the control surfaces, gives considerable flexibility to the finite volume method. In addition, by the direct discretization of the integral form of the conservation laws we can ensure that the basic quantities mass, momentum and energy will also remain conserved at the discrete level. This is a most fundamental property for numerical schemes, and its precise meaning will be discussed prior to the introduction of the finite volume method. 4.2.1 The Conservative Discretization The equations governing the flow of fluids are the expressions of a conservation law. Their general form for a scalar quantity phi, with volume sources Sphi, and flux Jphi (consisting of convective and diffusive fluxes), can be written as D/dt(int over CV rho phi dV + int over CS (J.dA) = int over CV (sphi dv) (4.2.1)

Here, the first integral represents the rate of accumulation of the scalar in the control volume, the second represents net efflux of the scalar through the surface enveloping the control volume while the third term is the source term of the scalar. The flux, J, consists of two components: the convective flux given by (rho u phi) and the diffusive flux given by (-phi dphi/dx) , where phi is the diffusivity of phi. For example, mass conservation may be obtained by putting phi = rho, J = rho u and Sphi =0. The other conservation equations can be obtained by setting the appropriate values for phi, phi and Sphi as listed in Table 4.2. The significance of writing the conservation laws in this way lies in the presence of the surface integral and the fact that the time variation of the scalar phi inside the control volume depends only on the surface values of the fluxes. Hence for an arbitrary subdivision of the domain into, say, three subdomains, we can write the conservation law for each subdomain and recover the global conservation law by adding up the three subdomain conservation laws. Consider the one-dimensional case shown in Figure 4.2x where the domain of integration AB is divided into three subdomains: AC, CD and DB. The conservation law, equation 4.2.1, written for the domain AB is given by

D/dt(int xA to xB (rhophi) dx + J dA)B JdA)A = int xA to xB (Sphi) dx (4.2.2)

The conservation law integrated over the subdomains AC, CD and DB can be written respectively as D/dt(int xA to xC (rhophi) dx + J dA)C JdA)A = int xA to xC (Sphi) dx (4.2.3a) D/dt(int xC to xD (rhophi) dx + J dA)D JdA)C = int xC to xD (Sphi) dx (4.2.3b) D/dt(int xD to xB (rhophi) dx + J dA)B JdA)D = int xD to xB (Sphi) dx (4.2.3c)
14

Adding the above three equations, we find that the flux terms at the internal boundaries at C and D cancel out leaving a conservation law for the entire domain AB. Thus, by writing the conservation law in terms of volumetric sources and surface flux terms, conservation can be ensured at any level provided the surface fluxes are evaluated properly such that the flux leaving one surface is the same as that coming into the adjacent control volume from the same surface. This allows the conservation law to be satisfied at the discrete, control volume level. The key feature that enables this that the convective and diffusive terms are written in their equivalent divergence forms. When a conservation law is written in this form, it is said to be in divergence or conservation form. If the resulting flux terms are evaluated consistently in the numerical discretization, then the discretized equation is said to be conservative. If not, the discretization is said to be non-conservative and the internal flux contributions appear as numerical volumetric source terms. Let us illustrate this for the case of the momentum equation for a one-dimensional, incompressible, inviscid flow. Here, the momentum balance equation can be written as Du/dt + udu/dx = -dp/dx Or equivalently as Du/dt + d/dx(u^2/2) = -dp/dx (4.2.5) (4.2.4)

Discretizing equation (4.2.4) over AB and using central differences to evaluate the spatial derivative, we get (Dui/dt) + ui(ui+3/2-ui-3/2)/3dx = -(pi+3/2-pi-3/2)/3Dx (4.2.6)

Where ui, the average value over AB, taken here as the value at the mid-point. Discretization of equation (4.2.4) over subdomains AC, CD and AB can be similarly written, respectively, as (Dui-1/dt) + (ui-1)(ui-1/2-ui-3/2)/ Dx = -(pi-1/2 pi-3/2)/dx (Dui/dt) + (ui)(ui-1/2-ui+1/2)/ Dx = -(pi+1/2 pi-1/2)/dx (Dui+1/dt) + (ui+1)(ui+3/2-ui+1/2)/ Dx = -(pi+3/2 pi+1/2)/dx (4.2.7a) (4.2.7b) (4.2.7c)

We find that upon adding equations (4.2.7a, 7b and 7c), we do not recover equation (4.2.6). For the case of equation (4.2.5), the discretized form of the equation over domains AB, AC, CD and DB can be written as Dui/dt + [(uI+3/2)^2 ui-3/2)^2]/3dx = -(pi+3/2 pi-3/2)/3dx Dui-1/dt + [(ui-1/2)^2 u(I-3/2)^2]/dx = -(pi-1/2-pi-3/2)/dx (4.2.9a) Dui/dt + [(ui+1/2)^2 u(I-1/2)^2]/dx = -(pi+1/2-pi-1/2)/dx (4.2.8)

(4.2.9b)

15

Dui+1/dt + [(ui+3/2)^2 u(I+1/2)^2]/dx = -(pi+3/2-pi+1/2)/dx (4.2.9c) In this case, we find that addition of equations (4.2.9a, 9b and 9c) allows us to recover equation (4.2.8). Thus the momentum equation written in the form of equation (4.2.5) is in conservation form whereas it is non-conservative when it is written as equation (4.2.4). It is worth noticing that the pressure gradient term on the right hand side of equations (4.2.4) and (4.2.5) has been treated as a surface force term. If it is treated as a volumetric source term, i.e., evaluating it as Int (dp/dx) dV = int(dp/dx)dx Area = ( dp/dx)bar (xB-xA) Area Rather than as Int (dp/dx)dV = int over area (p.dA) (4.2.11) (4.2.10)

Then the treatment of the pressure gradient may become non-conservative. Care should also be taken in dealing with grid-transformation associated terms (Ferziger & Peric, 1999) such that their treatment is also conservative in order to obtain a discretization which is strongly conservative. However, in many cases, the difference between conservative and nonconservative discretization is academic as it can be shown (Hirsch, 1988) that for smoothly varying functions, the errors due to non-conservative discretization are of second order in Dx, i.e., O(dx^2) and are thus of the same order as the truncation errors with a central scheme. However for potentially discontinuous flows such as those involving shocks, it has been shown (Lax ?) that using a conservative discretization scheme allows the discontinuities across shocks to be evaluated correctly. 4.2.2 Formulation of the Finite Volume Method Consider the three-dimensional hexahedral control volume shown in Figure 4.xxx.. Integration of the conservation law over this control volume gives D/dt(int over CV rho phi dV + int over CS (J.dA) = int over CV (sphi dv) Which becomes, in the discrete form, D/dt(int over CV rho phi dV + sum over all faces int (J.dA) = int over CV (sphi dv)(4.2.13) (4.2.12)

In order to evaluate the above integrals, it is necessary to determine the volume, the surface area and orientation of each face, the values of fluxes over each face and to evaluate the surface or volume integrals to account for the contribution of each term. These are dealt with in detail below. 4.2.3 Evaluation of the face areas and the cell volume

16

For a general quadrilateral ABCD, the area of the face can be determined from the vector product of the diagonals. This can be readily seen in Figure 4.xxx where the parallelogram EFGH is constructed with sides parallel to the diagonals AC and BD. The area of the quadrilateral ABCD is half the area of the parallelogram EFGH the area of which is given by the cross product of its adjacent sides EF and FG, for example, or equivalently by the cross product of the diagonals AC and BD of the quadrilateral ABCD. Denoting by xA the position vector of point A and noting that xAC = xC-xA, we can evaluate the area of the face ABCD as Area)ABCD = (xAC x xBD) = [(xC-xA) x (xD xB)] which reduces to the simple expression for a two-dimensional case that Area)ABCD = |(xC-xA) x (xD xB)| = [(xC-xA) (yD-yB) (yC-yA)(xD-xB)] where xA and yA are the x- and y-components, respectively, of the position vector xA, and so on. Thus, the area of the face is uniquely determined by the locations of the corner points. Equation (4.2.14) is applicable to non-coplanar cell faces. The volume of a cell can be obtained in a consistent manner using the divergence theorem, namely, for any vector a, Int over volume (del. a) dV = Int over cs area (a.ds) (4.2.15)

(4.2.14)

where cs refers to the closed surface enveloping the volume. Putting a = x, the position vector and noting that Del. x = dxi/dxi = 1+1+1 = 3, we obtain from equation (4.2.15) that Int over volume (Del.x) dv = 3 Int over volume (dV) = 3V = Int over cs (x.dS) or volume of cell = 1/3 Int over CS (x.dS) (4.2.16)

Here, x is any position vector originating from a fixed point and terminating at any point on the surface over which the dot product x.dS is being evaluated. This is illustrated in Figure 4.xa where the point O from which the position vector originates lies at the centre of the parallelopiped. Taking the position vector to be normal to each of the six surfaces, and noting that the position vector and the outward normal to each of the faces lie in the same direction, the total volume can be obtained as VABCDEFGH = 1/3(OO1.ABCD + OO2.EFGH + OO3. BCGF + OO4.ADHE + OO5.ABFE + OO6. CDHG) = 1/3(dx dy dz/2 )*6 = dx dy dz

17

In Figure 4.xb, the position vector originates from the corner F. Hence, surfaces EFGH, BCGF and ABFE do not contribute to the integral. Noting that the normal distance from surfaces ABCD, CDHG and ADHE is respectively dx, dy and dz, we obtain VABCDEFGH = 1/3(dx (dydz) + dy(dxdz) + dz(dxdy)) = dx dy dz Using equation (4.2.16), the volume of any hexahedra or pyramid can be evaluated by dividing it into its non-overlapping constituent tetrahedra. The volume of each tetrahedra can be determined from equation (4.2.16). With reference to Figure 4.xc showing the tetrahedral volume PABC, selecting the position to originate from P and terminate at A, the volume can be obtained as VPABC = 1/3 (xPA . SABC) = 1/3 xPA.1/2 (xAB X xBC) = 1/6 xPA.(xBC X xCA) which can be written as the determinant : VPABC = 1/6 |xP |xA |xB |xC yP yA yB yC zP zA zB zC 1 1 1 1 | | | |

(4.2.17)

Thus, the volume of the tetrahedra can be uniquely determined from the coordinate positions of its four corners. Care should be taken in evaluating the tetrahedra volumes since the sign of the constituent volumes depends on the orientation of the triangular decompositions. Using the coordinates of the points to determine the areas and volumes helps preserve conservation property of the numerical scheme. 4.2.4 Evaluation of fluxes at faces The flux term J appearing in equation (4.2.12) consists of two components: a convective flux, Jc, given by (rho u phi) and a diffusive flux, Jd, given by (Gammaphi dphi/dx). Assuming that the density, velocity etc. are known, the evaluation of fluxes at faces requires the determination of phi and its gradient on the faces in terms of the nodal values of phi through interpolation, if necessary. Here, two generic interpolation practices are used to take account of the directional dependence of the fluxes. Since convective flux is oriented in the direction of velocity, upwind schemes are used to evaluate it. Thus, if in a two-dimensional case, the face location is at (I+1/2, j) and if phi is evaluated at (I,j) and (I+1,j), then according to the upwind scheme, phi(I+1/2, j) = phi (I,j) if u >0 = phi(I+1,j) if u <0 (4.2.18)

where u is the local velocity component in the ith direction and is given by u.n at (I+1/2,j) where n is unit outward normal vector of the surface on which the flux is being evaluated. It can be shown through a Taylor series expansion that equation (4.2.18) corresponds to a first order scheme and is therefore highly diffusive. Higher order upwind schemes can be

18

constructed to improve the accuracy; the QUICK (Quadratic Upwind Interpolation for Convective Kinematics) scheme of Leonard (1979) is third-order accurate and can be written, assuming uniform spacing and that (u.n) >0, as phi(I+1/2, j) = 6/8 phi(I,j) + 3/8(phi(I+1,j) -1/8 phi(I+2, j) - 3/48 dx^3 (d3phi/dx3)at (I,j) + (4.2.19) The gradient of phi required for the evaluation of the diffusive flux is usually obtained by central differencing and can be written as dphi/dx)I+1/2, j = (phi(I+1, j ) - phi (I,j))/(x(I+1,j) - x(I,j)) (4.2.20)

which is formally second order accurate on a uniform grid. Second order accurate one-sided differencing for the gradient would be necessary at the boundary to preserve the overall accuracy of the scheme. 4.2.5 Evaluation of the surface and volume integrals Using schemes (4.2.19) and (4.2.20), it is possible to evaluate the fluxes at the centres of the faces. The areas of the faces can be evaluated using equation (4.2.14). The total flux through a given face can then be evaluated as product of the flux value at the face centre and the area of the face: Ji+1/2, j+1/2= Int over Si+1/2,j+1/2 (jds) = ji+1/2,j+1/2 Si+1/2,j+1/2 (4.2.21)

Provided the flux at the face centre is evaluated using a second order scheme, the total flux evaluated using equation (4.2.21) would be of second order accuracy. The surface integral can be approximated to higher orders of accuracy. For example, using Simpsons trapezoidal rule, the total flux through the (I+1/2,j) face can be written as Ji+1/2,j+1/2 = Si+1/2,j/6 (f I+1/2,j, + 4fi+1/2,j +1/2 + fi+1/2, j-1) However, this requires that the fluxes at (I+1/2,j+1), (I+1/2, j) and (I+1/2,j-1) should be evaluated using an interpolation scheme which is at least fourth-order accurate. The volume integrals in equation (4.2.13) can be evaluated in a straightforward manner as: Q = int over volume of qdV = phi (I,j) volume (4.2.22)

Since phi (I,j) is evaluated at the centre of the cell, no interpolation is necessary. If phi varies linearly or is constant within the CV, then the above evaluation is exact; otherwise it is second order accurate. Higher accuracy can be achieved to evaluate the volume intergral but interpolation would be required to evaluate phi at other points. Higher than second order accuracy is not easily achievable for arbitrarily shaped grid structure.

19

You might also like