Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

4. THE SCALAR-TRANSPORT EQUATION 4.1 The generic scalar-transport equation 4.2 Control-volume notation 4.

3 The steady-state 1-d advection-diffusion equation 4.4 Discretising diffusion 4.5 Discretising the source term 4.6 Assembling the algebraic equations 4.7 Extension to 2 and 3 dimensions 4.8 Discretising advection (part 1) 4.9 Discretisation properties 4.10 Discretising advection (part 2) 4.11 Implementation of advanced advection schemes 4.12 Implementation of boundary conditions 4.13 Solution of the algebraic equations Summary Examples

SPRING 2009

4.1 The Generic Scalar-Transport Equation This is a generic equation for transported physical quantities (momentum, energy,...) For an arbitrary control volume V:
RATE OF CHANGE inside V

FLUX out of boundary

SOURCE inside V

The total flux comprises advection (transport with the flow) and diffusion (molecular or due to turbulent fluctuations). The resulting advection-diffusion equation for concentration may be written, for each computational control volume (or cell): d ( V) + ( C A ) = SV V dt n faces A rate of change advection diffusion source (Any non-advective fluxes not described by gradient diffusion are assumed to be incorporated in the source term.)

un

4.2 Control-Volume Notation The commonest configurations are cell-centred or cell-vertex storage. cell-centred cell-vertex

CFD

41

David Apsley

This course focuses on structured meshes using cell-centred storage. (Unstructured meshes will be discussed briefly at the end of the course, but Versteeg and Malalasekeras book gives a better description.) A typical 3-d control volume is shown right. Relative to the cell centre (point P) the coordinate directions are commonly denoted west, east, south, north, bottom, top with: lower case w, e, s, n, b, t used for cell faces; upper case W, E, S, N, B, T for adjacent nodes. For a Cartesian mesh these would usually correspond to x, y, z directions respectively. Cell-face areas will be denoted Aw, Ae, As, An, Ab, At. Cell volumes will be denoted V. In 2 dimensions one can think of a single layer of cells having unit depth ( z = 1).

T
t

W S

w s

N P
b n e

E
k j i

When referring to the entire set of control volumes (as opposed to looking at a representative one) it is common to switch between geographic and ijk notation, so that P ijk, E i+1 jk , etc.

NN N
n

i,j+2

i,j+1

WW

Ww P
s

EE

i-2,j

i-1,j

i,j i,j-1

i+1,j

i+2,j

S
j i,j-2

SS
i

CFD

42

David Apsley

4.3 The Steady-State 1-D Advection-Diffusion Equation Consider first the steady-state, 1-d advection-diffusion equation. This is worthwhile because: it greatly simplifies the analysis; it permits a hand solution of the discretised equations; subsequent generalisation to 2 and 3 dimensions is straightforward; in practice, discretisation of fluxes is generally carried out coordinate-wise; many important theoretical problems are 1-d. Control-Volume Form Conservation for one control-volume gives fluxe flux w = source (1) where flux means the rate of transport through a cell face.

area A

flux w

source

flux e

If is the amount per unit mass, then the total flux has advective and diffusive parts: advection: ( uA) d diffusion: A dx If S is the source per unit length then the advection-diffusion equation for is d d uA A = S x uA A dx e dx w

(2)

Conservative Differential Form Dividing by x and taking the limit as x 0 gives a corresponding differential equation: d d (3) ( uA A ) = S dx dx

Non-Conservative Differential Form Mass conservation implies that uA = constant and hence (3) can also be written d d d uA ( A ) = S dx dx dx

(4)

Note: This system is quasi-1-d in the sense that the cross-sectional area A may vary. To solve a truly 1-d problem, simply set A = 1. The differential equation is then d d ( u )=S dx dx In this instance, , u, and S are assumed to be known. In the general CFD problem, u is itself the subject of a transport equation, which must be solved simultaneously.

CFD

43

David Apsley

4.4 Discretising Diffusion Classroom Example 1


T=100 C
o

T=500 C

Rod

x= 0

An insulated rod of length 1 m and 1 cm 1 cm square cross-section has its end temperatures fixed at 100 C and 500 C as shown. The heat flux across any section of area A is given by dT kA dx where the conductivity k = 1000 W m1 K1. (a) Divide the rod into 5 control sections with nodes at the centre of each section and carry out a finite-volume analysis to find the temperature along the rod. (b) Write down a differential equation for the temperature distribution along the rod. Solve analytically and compare with (a).

Gradient diffusion is usually discretised by central differencing: P d A ( A) e E dx e x or d A De ( E P ) where dx e D is a diffusive transfer coefficient A similar expression is used for the west face: d A D w ( P W ) dx w Note:

W
D

e (5) x
(6)

A x

In the finite-volume method, fluxes are required at cell faces, not nodes. This approximation for (d/dx)e is second-order accurate in x (see later). If the diffusivity varies then its cell-face value must be obtained by interpolation. Equal weighting is applied to the two nodes on either side of the cell face, consistent with diffusion acting equally in all directions. Later on, we shall see that this contrasts with advection, which has a directional bias.

CFD

44

David Apsley

4.5 Discretising the Source Term Classroom Example 2


T=100 C dT dx =0
o

Too=20 C

Rod

S=-c(T-Too)

The rod configuration is now changed such that the right-hand temperature is no longer fixed and the rod is allowed to cool along its length at a rate proportional to its difference from the ambient temperature (Newtons law of cooling); i.e. the heat loss per unit length is: S = c(T T ) where the ambient temperature T = 20 C and the coefficient c = 2.5 W m1 K1.

Repeat parts (a) and (b) of Example 1.

When the source is proportional to the amount of fluid, the total source strength for the cell is (source per unit volume) (volume) = S V (In 1-d problems V is the cell length, x). S may depend on the solution as in the example above. The source term is conveniently broken down into solution-independent and solution-dependent parts in the linear form

source = bP + s P P ,

sP 0

(7)

The reason for this particular form will become apparent later.

4.6 Assembling the Algebraic Equations

As seen in the above classroom examples, when there is no flow (u = 0) the steady-state diffusion problem discretises as follows. flux e flux w = source De ( E P ) + D w ( P W ) = b P + s P p or, collecting multiples of P, E and W together: D w W + ( D w + D E s p ) P D E E = bP This is commonly written a w W + a P P a E E = b P or, in a notation that generalises to 2 and 3 dimensions (and to the case with flow): aP P a F F = bP
adjacent nodes

(8)

CFD

45

David Apsley

(8) is a canonical form for the discretised scalar-transport equation. There will be a discretised equation of this form for each variable and for each control volume. For one variable , if the nodal values are assembled into a vector then the set of algebraic equations takes the form 0 aW 0 For a 1-d system this is tri-diagonal. If the coefficients are constants then it can be solved directly by Gaussian elimination or very efficiently on a computer by the tri-diagonal matrix algorithm (see the Appendix). If the coefficients are dependent on the solution then it must be solved iteratively. aP aE P = bP or

4.7 Extension to 2 and 3 Dimensions

For a multi-dimensional flow the net flux out of a cell can be obtained by summing the outward fluxes through all faces. For quadrilateral elements (in 2d) or hexahedral elements (in 3d) then the net flux out of a cell is simply the sum of the net fluxes through opposing sides and the general conservation equation may be written: ( flux e flux w ) + ( flux n flux s ) + ( fluxt fluxb ) = source

flux n flux w
source

flux e

flux s
(9)

The discretised equations are still assembled in the same matrix form a P P a F F = bP
F

(10)

with the summation extended to include nodes in the other directions. Combining the individual equations (10) from all control volumes gives a matrix equation for the set of nodal values. In two dimensions this gives the banded matrix system shown. Further bands appear in three dimensions.

Thus, (8) or (10) has the same form in 1-, 2- or 3-d problems, but in multiple dimensions the summation is extended to the other (S, N, B, T) nodes and there is a corresponding increase in the number of non-zero diagonals in the assembled matrix equation. This makes the matrix equation much harder to solve (see Section 4.13). Equation (10) formally describes the discretisation for a single control volume in an unstructured mesh. However, since the nodes do not have a simple ijk indexing, the resulting matrix and solution method for unstructured meshes are much more complex.

CFD

46

David Apsley

4.8 Discretising Advection (Part 1)

Purely diffusive problems (u = 0) are of passing interest only. In typical engineering flow problems, advection fluxes far exceed diffusive fluxes because the Reynolds number (Re UL/ = ratio of inertial forces [mass acceleration] to viscous forces) is very large. In 1-d the steady-state advection-diffusion equation is fluxe flux w = source where, with mass flux C (= uA): W w d flux = C A dx . Discretising the diffusion and source terms as before, the equation becomes [C e e C w w ] [ De ( E P ) Dw ( P W )] = bP + s P P advection diffusion source

u P
e

(11)

The problem is how to approximate the face values e and w in terms of the values at adjacent nodes. A method of specifying these face values is called an advection scheme or advection-differencing scheme.

Classroom Example 3.

=0
x= 0

u L point source

d dx =0

A pipe of cross-section A = 0.01 m2 and length L = 1 m carries water (density = 1000 kg m3) at velocity u = 0.1 m s1. A faulty valve introduces a reactive chemical into the pipe half-way along its length at a rate of 0.01 kg s1. The diffusivity of the chemical in water is = 0.1 kg m1 s1. The chemical is subsequently broken down at a rate proportional to its concentration (mass of chemical per unit mass of water), this rate amounting to per metre, where = 0.5 kg m1 s1. Assuming that the downstream boundary condition can be approximated by d/dx = 0, set up a finite-volume calculation with 7 cells to estimate the concentration along the pipe using: (a) Central (b) Upwind differencing schemes for advection.

CFD

47

David Apsley

P
4.8.1 Central Differencing

e
e

E
E

In central differencing the cell-face value is approximated by the average of values at the nodes on either side: e = 1 ( P + E ) 2

This is second-order accurate for e in terms of x (see later). Substituting into (11) (with a similar expression for w) gives 1 1 2 C e ( P + E ) 2 C w (W + P ) De ( E P ) + Dw ( P W ) = bP + s P P or, collecting terms, 1 1 1 (1 2 C w + Dw )W + ( 2 C e 2 C w + De + Dw s P ) P ( 2 C e + De ) E = bP In out canonical notation: a P P a F F = bP
F

where, in one dimension: aW = + 1 2 C w + Dw


aE = 1 2 C e + De a P = a E + aW s P + (C e C w ) (By mass conservation, Ce Cw = 0, so that the expression for aP can be simplified.)

(12)

The graphs below show the solution of an advection-diffusion problem with no sources and constant diffusivity for the two combinations 3 Pe = 1/2 (advection diffusion) (equation: 5 4 W + 2 P 4 E = 0 ) Pe = 4 (advection diffusion) (equation: 3W + 2 P + E = 0 )
where the Peclet number Pe is defined by C advection u x Pe = i.e. = D diffusion Pe = 1/2 Pe = 4

(13)

In the first case the solution is good (consistent with second-order accuracy). In the second case there are pronounced wiggles in what should be a perfectly smooth solution. What is wrong?

CFD

48

David Apsley

Mathematically, when the cell Peclet number Pe is bigger than 2, the aE coefficient becomes negative, meaning that, for example, an increase in E would lead to a decrease in P. This is impossible for a quantity that is simply advected and diffused. Physically, the advection process is directional; it transports properties only in the direction of the flow. However, the central-differencing formula assigns equal weight to both upwind and downwind nodes.

diffusion only

advection + diffusion

4.8.2 Upwind Differencing

In upwind differencing face is taken as the value at whichever is the upwind node; i.e. in one dimension: (if u > 0) e = P E (if u < 0)

P
P

E
E

This is only first-order accurate in x (see later) but acknowledges the directional nature of advection. The alternatives can be summarised as face = U where subscript U denotes whichever is the upwind node for that face.

With this scheme, the algebraic equation for each control volume takes the canonical form a P P a F F = bP
F

where: a E = max(C e ,0) + De aW = max(C w ,0) + Dw (14) a P = a E + aW s P If the max bit confuses you, consider separately the two cases where the mass flux is positive (flow from left to right) or negative (flow from right to left). When applied to the same advection-diffusion problem as the central-differencing scheme it is found that: when Pe = the upwind-differencing scheme is not as accurate as central differencing; this is to be expected from its order of accuracy; when Pe = 4 the upwind-differencing solution is not particularly accurate, but the wiggles have disappeared. In all cases, however, both aW and aE are unconditionally positive. So there is a pay-off accuracy versus boundedness (absence of wiggles). The next sections examine the desirable properties of discretisation schemes, the constraints that they impose upon the matrix coefficients and more advanced advection schemes that are both accurate and bounded (wiggle-free).

CFD

49

David Apsley

4.9 Discretisation Properties

(i) Consistency An approximation is consistent if the discretised equations are equivalent to the continuum equations in the limit as the grid size tends to zero. e.g., by the definition of a derivative, E P is a consistent approximation for x x (ii) Conservativeness A scheme is conservative if fluxes are associated with faces, not particular cells, so that what goes out of one cell goes into the adjacent cell; This is automatically built into the finite-volume method.
flux

(iii) Transportiveness An advection scheme is transportive if it is upstream-biased. In practice this means higher weighting to nodes on the upstream side of a face.

(iv) Boundedness A flux-differencing scheme is bounded if, in an advection-diffusion problem without sources: the value of at a node always lies between the maximum and minimum values at surrounding nodes; = constant is a possible solution. This imposes conditions on the matrix coefficients aP, aW, aE, ... If there are no sources then aP P aF F = 0 (15) Suppose that is only non-zero at one adjacent node, F. Then a aP P aF F = 0 or P = F F aP Since P must lie between 0 and F, this requires that a 0 F 1 aP Hence, aF and aP must have the same sign (invariably positive in practice). Thus, we require: a F 0 for all F (positive coefficients) (16) (It is the contravening of the positivity condition that leads the central-differencing scheme to produce wiggles. If the Peclet number is greater than 2, a small increase in F would produce a large decrease in the value of P, a situation which is completely unphysical.) If (15) is also to admit the solution = constant then this can be divided out to yield aP = aF (sum of neighbouring coefficients)

(17)

CFD

4 10

David Apsley

(v) Stability A solution method (not advection scheme) is stable if small errors do not grow in the course of the calculation. This determines whether it is possible to obtain a converged solution it says nothing about its accuracy or whether it contains wiggles. Stability is heavily influenced by how the source term is discretised. Any source term should be linearised as bP + s P P ; the complete equation for one cell is then a P P a F F = bP + s P P If the solution-dependent part of the source (sPP) is transferred to the LHS then the diagonal coefficient is modified to read aP = aF sP Numerical stability requires negative feedback; otherwise, an increase in would lead to an increase in the source, , which would lead to a further increase in and so on. Thus: sP 0 (negative-slope linearisation of the source term) If this condition and the positivity of the aF is maintained then aP aF (diagonal dominance) The last condition is, in fact, a necessary requirement of many matrix solution algorithms. In summary, boundedness and stability place the following constraints on the discretisation of flux and source terms:

positive coefficients: negative-slope linearisation of the source term: sum of neighbouring coefficients:

a F 0 for all F source = bP + s P P , s P 0 aP = aF sP


F

(vi) Order If, on a uniform grid of spacing x, the truncation error is proportional to xn as x that scheme is said to be of order n. 0 then

Order can be established formally by a Taylor-series expansion about a cell face. e.g. for the nodes either side of the east face: 1 x 2 2 1 x 3 3 x + ( ) + ( ) + (18)(a) E = e + ( ) 2! 2 x 2 e 3! 2 x 3 e 2 x e P = e (

x ) 2 x e

1 x 2 2 ( ) 2! 2 x 2 e

1 x 3 3 ( ) 3! 2 x 3 e

+
x

(18)(b)

Subtracting (18)(a) (b) gives: E P = x + 0 + x e E P = + O( x 2 ) x x e CFD

1 x3 3 24 x e
3

4 11

David Apsley

As the error term is O(x2),

E P . is a second-order approximation for x x e

Alternatively, adding (18)(a) (b) gives: 1 2 2 P + E = 2 e + x + 4 x 2 e


1 2

( P + E ) = e + O( x 2 )

As the error term is O( x2), the central differencing formula 1 ( P + E ) is a second-order 2 approximation for e. On the other hand, the Upwind-differencing approximations P or E (depending on the direction of the flow) are formally first-order accurate. Higher accuracy can be obtained by using more nodes in an approximation one node permits schemes of at most first-order accuracy, two permit second-order accuracy and so on. It can be shown that truncation errors in the advection terms of: odd order lead to numerical diffusion smearing out of discontinuities e.g. firstorder upwind differencing; even order lead to dispersion recognised by under- and overshoots or wiggles; e.g. second-order central differencing. Additionally, schemes of low-order accuracy e.g. Upwind lead to substantial numerical diffusion in 2- and 3-d calculations when the velocity vector is not aligned with the grid lines.

Note. Remember that order refers to the theoretical truncation error in the approximation, not the computers round-off error (the accuracy with which it can store floating-point numbers).
The more accurate a scheme then, in principle, the greater the reduction in numerical error as the grid is made finer or, conversely, the less nodes required for a given accuracy. However, high-order schemes tend to require more computational calculations and often have boundedness or stability problems. Also, the law of diminishing returns applies when the truncation error becomes of similar size to the floating-point round-off error.

CFD

4 12

David Apsley

4.10 Discretising Advection (Part 2)

With an understanding of the desirable properties of a flux-differencing scheme it is now possible to examine more advanced schemes.

4.10.1 Exponential Scheme

area A

The 1-d advection diffusion equation is source flux w flux e fluxe flux w source or, equivalently, x d d ( uA A ) = S (19) dx dx If there are no sources (S = 0) then the total flux must be constant: d flux = uA A = constant dx This equation can be solved exactly, with boundary conditions = P and = E at adjacent nodes, to give (see the Examples): e Pe P E fluxe = C e Pe 1 where C = uA = mass flux A D = = diffusive transfer coefficient x u x C Pe = = D . With a similar expression for the west face, one obtains fluxe flux w = a P P a F F where (for constant C): Ce Pe C , , a P = a E + aW (20) aW = Pe a E = Pe e 1 e 1
Assessment Conservative by construction. Transportive, because there is a larger weighting on the upwind node (consider separately the cases C > 0 and C < 0). Bounded: all aF are positive and aP is the sum of the neighbouring coefficients. This scheme by construction gives the exact solution for zero sources and constant velocity and diffusivity, but this is something we could have found analytically anyway. The scheme has never really found favour because: the scheme isnt exact when u or vary, or if there are sources, or in 2-d or 3-d flow; exponentials are extremely expensive to compute.

CFD

4 13

David Apsley

4.10.2 Hybrid Scheme (Spalding (1972)

This is based on a piecewise linear approximation to the exponential scheme. It amounts to: central differencing if Pe 2 upwind differencing (with zero diffusion!) if Pe > 2 .

fluxe flux w = a P P a F F where (if u > 0): aW = C w / 2 + Dw , a E = C e / 2 + De aW = C w , aE = 0


a P = a E + aW

if Pe C/D 2 if Pe > 2

(21)

Assessment The scheme is conservative, transportive and bounded. The hybrid scheme remained extremely popular in commercial codes for a long time because it was stable and robust. However, most flows of interest operate in the high-advection/lowdiffusion regime, where this scheme amounts to first-order upwinding (with no diffusion). Modern CFD practitioners seek much higher accuracy. Patankar also developed a power-law approximation to the exponential scheme, to overcome the heavy-handed switch-off of diffusion at Pe = 2. However, powers are as computationally expensive as exponentials.

4.10.3 QUICK (QUadratic Interpolation for Convective Kinematics Leonard, 1979)


W

Fits a quadratic polynomial through 3 nodes to get 3 -order accuracy. For each cell face, QUICK uses the nodes either side of the cell face, plus a further upwind node depending on the direction of the flow as shown right. To emphasise the conservation property which associates fluxes with cell faces, not nodes, we shall, face in future, for all such three-point schemes use the notation D, U and UU for the Downwind, Upwind and Upwind-Upwind nodes at any particular face. By fitting a quadratic polynomial to these nodes (see Examples) the QUICK scheme gives: 3 face = 1 +3 +8 D 8 UU 4 U For example, if u > 0 on the east face then:
W

rd

P e E
P e E

u>0
P e E
E e

UU

EE
EE

u<0
(22)

CFD

4 14

David Apsley

3 3 e = 1 8 W + 4 P + 8 E whereas, if u < 0: 3 3 e = 1 8 E + 4 E + 8 P

WW

EE

In 1-d: fluxe flux w = a P P aWW WW aW W a E E a EE EE where, in general, aWW = 1 8 max(C w ,0),


3 1 aW = 3 4 max(C w ,0) 8 max(C w ,0) + 8 max(C e ,0) + D w , 3 1 aE = 3 4 max(C e ,0) 8 max(C e ,0) + 8 max(C w ,0) + De ,

a EE = 1 8 max(C e ,0),

a P = aWW + aW + a E + a EE + (C e C w ) (Max operators are necessary to distinguish the two possible flow directions on each face.) Assessment 3rd-order accurate. Conservative by construction. Transportive, because upwind bias is built into selection of the third node. Not bounded; (for example, if u > 0 then aE is negative). Despite boundedness not being guaranteed (which can be a major problem in turbulent flows, where k and are required to be positive see later) the high-order accuracy of the QUICK scheme make it popular and widely-used.

4.10.4 Flux-Limited Schemes

Hitherto we have only seen schemes where the matrix coefficients aF are constants (i.e. independent of the solution ). The only unconditionally-bounded scheme of this type is firstorder upwind differencing. Schemes such as QUICK, which fit a polynomial through several points, are prone to generate cell-face values which lie outside the interpolating values D, U, UU. To prevent this, modern schemes employ solution-dependent limiters, which enforce boundedness whilst trying to retain high-order accuracy wherever possible. For three-point schemes, is said to be monotonic increasing or monotonic decreasing if UU < U < D or UU > U > D respectively. A necessary condition for boundedness is that the schemes must default to first-order upwinding (i.e. face = U) if is not locally monotonic (either increasing or decreasing).

UU

UU

monotonic

non-monotonic

Monotonic variation in may be gauged by whether the changes in between successive pairs of nodes have the same sign; i.e. monotonic ( D U )(U UU ) > 0 Such schemes can then be written (in the notation of Versteeg and Malalasakera):

CFD

4 15

David Apsley

U + 1 if monotone 2 ( r )( D U ) U otherwise where r is the ratio of successive differences (>0 where monotonic): UU r= U D U face =

UU

U face

The limiter (r) is given below for various schemes used at the University of Manchester. Scheme UMIST (r) (for r > 0)

Upstream Monotonic Interpolation for Scalar Transport 1 min{2,2r , 1 4 (1 + 3r ), 4 (3 + r )} (Lien and Leschziner, 1993). A limited variant of QUICK, this is 3rd-order accurate where monotone. 2r Van Leer (1974). Harmonic Second-order accurate where monotone. 1+ r Min-mod min(r,1) Roe (1985) (r) is taken as 0 if r < 0 (i.e. non-monotonic) The choice of these examples is (obviously!) parochial. Many other equally-good schemes exist (see Versteeg and Malalasekera, 2nd edition, for a list). The important points about these schemes are that they are (a) bounded, and (b) non-linear (i.e. the resulting matrix coefficients depend on, and hence change with, the solution ). The last property means that an iterative numerical solution is inevitable.

4.11 Implementation of Advanced Advection Schemes

The general steady-state scalar transport equation is ( C A ) = SV n faces advection diffusion source

(23)

If C and D are the outward mass flux and diffusive transport coefficient on each cell face, then, with the standard discretisation for diffusion and sources, (23) becomes [C face + D( P F )] = bP + s P P
faces

where F denotes an adjacent node and P is the index of the cell-centre node. Since by mass conservation, it is convenient to subtract
[C ( face P ) + D( P F )] = bP + s P P
faces

C=0 (24)

C P (which is 0) from both sides:

An advection scheme (Upwind, Central, QUICK, ) is needed to specify the cell-face value face. Because many matrix-solution algorithms require positive coefficients and diagonal dominance, it is common practice to separate face into the Upwind part plus a correction; i.e. face = U + ( face U ) Then, for the advective flux:

CFD

4 16

David Apsley

C ( face P ) = C (U P )
upwind

+ C ( face U )
correction

= max(C ,0)( P F ) + C ( face U )

(25)

The first part of (25) gives rise to a positive matrix coefficient a F = max(C ,0) + D whilst the latter part is transferred to the RHS of the equation as what is called a deferred correction; (deferred because it wont be updated until the next iteration): a F ( P F ) = b P + s P P C ( face U )
F faces deferred correction

4.12 Implementation of Boundary Conditions

The most common types of boundary condition are: specified (Dirichlet boundary conditions); e.g. = 0: velocity at a wall, or temperature fixed at some surface; /n specified (Neumann boundary conditions). e.g. /n = 0 on a symmetry plane, or at an outflow boundary. In the finite-volume method, both types of boundary condition can be implemented by transferring the boundary flux to the source term. For a cell abutting a boundary: flux + fluxbound = source
not boundary

boundary

boundary

NI-3

NI-2

NI-1

P
a F F = bP fluxbound
not boundary

aP P

Thus, there are two modifications: the aF coefficient in the direction of the boundary is set to zero; the outward boundary flux is subtracted from the source terms.

boundary

If flux() is specified on the boundary, then this is immediate. If itself is fixed on the boundary node B then, with x the width of the cell: P flux() = A B1 = 2 D ( B P ) x 2 To subtract this flux from the source term requires a simple change of coefficients: bP bP + 2 D B , sP sP 2D (26) (You should revisit the classroom examples of Sections 4.4 and 4.5 to see this in action.)

CFD

4 17

David Apsley

4.13 Solution of the Algebraic Equations

The discretisation of a single scalar-transport equation over a single control volume produces an algebraic equation of the form a P P a F F = bP where the summation is over adjacent nodes. Combining the equations for all control volumes produces a set of simultaneous equations, i.e. a matrix equation A = b where is the vector of nodal values. Matrix A is sparse (i.e. has only a few non-zero elements). Many algebraic methods have been used to tackle this problem; a few that are suitable for structured grids are mentioned below.

4.13.1 Matrix Solution Algorithms Gaussian Elimination

This is a direct (i.e. non-iterative) method. It consists of a sequence of row operations to obtain zeros below the main diagonal (upper-triangular matrix), followed by backsubstitution. In general, it is inefficient because it tends to fill in sparse matrices (tridiagonal systems are an important exception), whilst for fluid-flow problems the matrix elements vary with the solution, so that an iterative solution is necessary anyway. Gaussian elimination is OK for small hand calculations, but not recommended for large systems of equations.

Gauss-Seidel

Rearrange the equation for each control volume as an iterative update for the W P E central node: 1 P = (bP + a F * F) aP S (the asterisk * denotes the current value). Then repeatedly cycle through the entire set of equations until convergence is achieved.

direction of sweep

Gauss-Seidel is very simple to code and is often used for unstructured grids. However, it tends to converge slowly for large matrices and may require substantial under-relaxation (see below).

CFD

4 18

David Apsley

Classroom Example 4.

(a) Show how Gauss-Seidel can be used to solve the following matrix equation iteratively, and conduct 3 Gauss-Seidel sweeps. 4 1 0 0 A 2 1 4 1 0 B 4 = 0 1 4 1 C 6 0 0 1 4 D 13 Write a computer program (using any programming language or application of your choice) to solve this problem iteratively.

(b) Now try to do the same for the matrix equation 7 1 4 0 0 A 14 4 1 4 0 B = 21 0 4 1 4 C 8 0 0 4 1 D Why does Gauss-Seidel not converge in this case?

Line-Iterative Procedures (Line Gauss-Seidel)

Along any one coordinate line, the system is tridiagonal; e.g. in the i-direction: a + a a = b a *
W W P P E E P F F not W ,E

bN W P S E

Thus, using the tri-diagonal matrix algorithm a whole line can be updated at one go and information can propagate right across the domain in one iteration, rather than (as in Gauss-Seidel) one node at a time. A typical single iteration would consist of applying the update for each successive i line, then for each successive j line, then (if 3-d) for each successive k line.

This is probably the most popular method for block-structured grids, and is the basis of most of our in-house research codes. Note, however, that it doesnt work for unstructured grids.

CFD

4 19

David Apsley

direction of sweep

4.13.2 Convergence Criteria

Iteration is stopped when the total residual error becomes less than some small, pre-defined tolerance. The total residual error is a suitably-weighted sum over the errors for all cells; e.g. Error = res sum of absolute residuals:
cells

1 (res ) 2 N cells where the residual is the error in satisfying the algebraic equations for any one cell: res = a P P a F F bP

root-mean-square (rms) error: Error =

The tolerance is usually set to some small fraction (e.g. 104) of the error at the first iteration.

4.13.3 Under-Relaxation

If the algebraic methods described above are applied to the non-linear, coupled equations of fluid flow then the change in variables at each iteration may be large enough to cause numerical instability. To overcome this, under-relaxation reduces the change at each iteration (without affecting the final, converged, solution). The equation set a P P a F F = bP can be rearranged as a F F + bP P = aP and then written in terms of the change in by adding and subtracting the previous value: a F F + bP P = old old P + P aP If, instead, only a fraction of the change in is applied then a F F + bP P = old old P + P aP is called an under-relaxation factor. The equation can then be rearranged as aP P a F F = bP + (1 )a P old P Hence, under-relaxation can be achieved by a simple change of coefficients: aF aF

(27) bP bP + (1 )a P old P This has the advantage of making the matrix equations more diagonally dominant (i.e. ( a F ) / a P smaller), which improves stability. Since P = old in the converged P solution, the final solution is unaffected by under-relaxation.

CFD

4 20

David Apsley

Summary

The generic scalar-transport equation for a particular control volume has the form rate of change + net outward flux = source flux rate of transport through a surface and consists of: advection transport with the flow (other authors prefer convection); diffusion net transport by random molecular or turbulent fluctuations.

Discretisation of the (steady) scalar-transport equation yields an equation of form a P P a F F = bP


F

for each control volume, where the summation is over adjacent nodes. The collection of these simultaneous equations on a structured mesh yields a matrix equation with limited bandwidth (i.e. few non-zero diagonals), typically solved by iterative methods such as Gauss-Seidel or line-Gauss-Seidel. Source terms are linearised as bP + s P P , s P 0 . Diffusive fluxes are usually discretised by central differencing; e.g. A ( F P ) A x x Advection schemes are means of approximating on cell faces in order to compute advective fluxes. They include Upwind, Central, Exponential, Hybrid, QUICK, and flux-limited schemes. General desirable properties for a numerical scheme: consistent conservative bounded stable transportive accuracy / high-order Boundedness and stability impose certain constraints on the matrix equations: a F 0 for all F (positive coefficients) sP 0 (negative feedback in the source term) (sum of the neighbouring coefficients) aP = aF sP
F

To ensure positive coefficients (and implement non-linear schemes), advective fluxes are often decomposed into Upwind + deferred correction with the latter being transferred to the source term and treated explicitly (i.e. fixed for this iteration).

CFD

4 21

David Apsley

Boundary conditions can be implemented by transferring boundary fluxes to the source terms. Under-relaxation is usually required to solve coupled and/or non-linear equations.

(**** MSc course only ****)


Appendix: Tri-Diagonal Matrix Algorithm

System of equations: ai i 1 + bi i ci i +1 = d i , i = 1, Either 0 and N +1 are given, or a1 = cN = 0.

b1
,N

c1 ai 0

0 bi 0 0 ci aN

0 0 bN

1 i N

d1 = di dN

0 0

Forward pass: P0 = 0, Pi =

Q0 = 0 Qi = d i + ai Qi 1 , bi ai Pi 1 i = 1, ,N

ci , bi ai Pi 1

Backward pass: i = Pi i +1 + Qi ,

i = N,

,1

Guaranteed to converge if the coefficients are non-negative and diagonally dominant: ai 0, ci 0, ai + ci bi for all i except in the degenerate case where zero ai or ci allow successive rows to be multiples of each other and the matrix is consequently singular (rank < N).

Exercise: Code your own solver as a subroutine and test it on one of the classroom examples.

CFD

4 22

David Apsley

Examples

Q1. W P E EE The central-differencing scheme for diffusion using cellcentred storage uses the approximation P d E dx e x Show that this is second-order accurate. Making use of the W and EE nodes also, find a symmetric fourth-order-accurate scheme for the derivative on the cell face.

Q2. (a) Show that a quadratic function fitted to values UU , 1 1 2 x , and 2 x takes the value 3 3 1 8 UU + 4 U + 8 D at x = 0. (This is the basis of the QUICK advection scheme).

and

at locations 3 2 x,

(b) Show that the QUICK advection scheme is 3rd-order accurate (on a uniform mesh).

Q3. The QUICK scheme fits a quadratic function to three nodal values to estimate the value of a scalar at a cell face, according to 3 face = 1 +3 +8 D 8 UU 4 U (a)

UU

U face

For a two-dimensional problem, write down expressions for e, w, n, s in terms of the values at neighbouring nodes, assuming that velocity components u and v are known, constant and positive. Neglecting diffusion, and assuming a uniform source S per unit volume, derive an algebraic discretisation of the conservation equation (outward fluxes) = source in the form a P P a F F = bP where the sum is over local nodes. (Assume the cell to be Cartesian, with unit depth in the z direction, face areas Ae, Aw, An, As and volume V). How do the expressions for w and e change if u < 0. Which of the following properties does the QUICK scheme satisfy: transportiveness; boundedness. Split the QUICK expression for face in the form Upwind differencing + deferred correction Why is this decomposition used?

(b)

(c) (d)

(e)

CFD

4 23

David Apsley

Q4. Consider the advection-diffusion equation with no sources: d d ( u )=0 dx dx where , u, are constants. If = P at x = 0 and = E at x = x, find the value of the flux d u dx at any point between x = 0 and x. (This is the basis of the exponential differencing scheme).

Q5. If the continuity (mass-conservation) equation were to be regarded as a special case of the general scalar-transport equation, what would be the expressions for , and S? Q6. (From Patankar, 1980) The source term for a dependent variable is given by 2 3 P P . If this term is to be linearised as bP + s P P , comment on the following practices ( * P denotes the value from the previous iteration): * bP = 2 3 * sP = 0 (a) P P , (b) (c) (d) bP = 2 3* sP = 0 P ,
* bP = 2 4 * s P = * P P , P
2

b P = 2 , s P = 3 * P

(Ref: notes, Section 4.5).

CFD

4 24

David Apsley

Q7. A 2-d finite-volume calculation is to be undertaken for fully-developed, laminar flow between plane, parallel walls. The upper wall is moving at speed U0, whilst the lower wall is stationary. A streamwise pressure gradient dp/dx = G is also imposed. The depth of the channel, H, is divided into N equally-sized cells of dimension x y 1 as shown, with the velocity u stored at the centre of each cell.

U0

uN

u j+1
H

uj uj-1

u1

(a) (b) (c)

What are the boundary conditions on upper and lower walls? What is the net pressure force on a single cell? Write down a second-order approximation for the shear stress the jth internal cell, in terms of the velocities uj and uj+1. Write down similar approximations for
12 12

on the upper face of

(d) (e)

on upper and lower walls.

By balancing pressure and viscous forces set up the finite-volume equations for velocity. (Separate equations are required for internal and boundary cells). Solve your equations for the nodal velocities in the case GH 2 N = 4, =2 U0 leaving your answers in terms of U0. Using your answer to part (f), find the volume flow rate per unit span (leaving your answer as a multiple of U0H). Solve the Navier-Stokes equation analytically for this case and compare with your answers in parts (f) and (g).

(f)

(g)

(h)

CFD

4 25

David Apsley

Q8. (Computational Hydraulics Exam, May 2008) The local arrangement of nodes and faces in a 1-d finite-volume mesh with standard geographical notation and uniform mesh spacing x is shown in the figure below.

w WW W P

e E EE

x
(a) The 1-d advection-diffusion equation for a transported variable is d d u =S, dx dx where is density, u is velocity, is diffusivity, S is the source density. Write this in a corresponding integral form for the shaded cell in Figure 2.1. Write finite-difference expressions for d/dx on both w and e faces. Write expressions for on w and e faces of the shaded cell if u is positive for (i) firstorder upwind; and (ii) central advection schemes. Define the term bounded when applied to flux-differencing schemes and deduce a condition on , u, and x for the central scheme to be bounded. P W E P for (i) first-order upwind; and (ii) central advection where r=

(b) (c)

(d)

A general expression for e when u is positive is e = P + 1 2 ( r )( E P ) (e) Write the (constant) values of schemes.

(f)

The Van Leer flux limiter is 2r if r > 0 (r ) = 1 + r 0 otherwise In a particular case, = 1, u = 1, = 0.02 and x = 0.1 in consistent units. In a solution with the Van Leer advection scheme, takes the following values: WW = 1, W = 2, P = 4, E = 2, EE = 3, Find the values of and d/dx on w and e faces, and hence the mean source density S for cell P.

CFD

4 26

David Apsley

(**** Remaining questions for MSc Course only ****) Q9. (MSc exam, May 2008 part) The general three-point scheme for the cell-face value of a transported scalar is UU UU face = U + 1 r= U 2 ( r )( D U ) , D U where upstream (U) and downstream (D) are defined by flow direction (a) The linear upwind differencing (LUD) and QUICK schemes are: 1 LUD: face = 3 2 U 2 UU
3 3 QUICK: face = 1 8 UU + 4 U + 8 D Identify the functional form of (r) for each of these schemes.

U face

(b)

Swebys conditions for total-variation-diminishing (TVD) schemes are that =0 if r 0 if r 0 min(2r ,2) Show that LUD and QUICK both contravene these conditions for some r 0. The Van Albada scheme has 0, if r 0 2 (r ) = r + r , if r 0 1+ r2 Show that this satisfies Swebys criteria and also the symmetry property 1 (r ) = ( ) for r > 0 r r

(c)

Q10. (MSc Exam, May 2008 part) The discretisation of a 1-d scalar-transport equation results in a set of simultaneous equations for the nodal values {i} of the form 2 i 1 + 6 i i +1 = 2 2 i i , i = 1,2, , N where 0 and N+1 are given. Use the Gauss-Seidel method to solve this iteratively for the case N = 3 with boundary conditions 0 = 4 = 0 .

Q11. (MSc Exam, May 2008 part) The linear system of equations ai i 1 + bi i ci i +1 = d i , i = 1,2, , N (where ai, bi, ci and di are constants, and 0 and N are fixed) can be solved by the tri-diagonal matrix algorithm as i = Pi i +1 + Qi , i = N , ,1 where {Pi} and {Qi}are determined from an initial forward pass. Show that ci Pi = i = 1, , N ; P0 = 0 , bi ai Pi 1 and derive a similar recurrence relation for the {Qi}. (You may assume here that ai > 0, ci > 0, ai + ci bi for all i.)

CFD

4 27

David Apsley

Selected Answers

Classroom Example 1 (a) T1 = 140, T2 = 220, T3 = 300, T4 = 380, T5 = 460 d dT (b) ( kA ) = 0 ; solution T = 400 x + 100 dx dx

Classroom Example 2 (a) T1 = 64.23, T2 = 36.91, T3 = 26.50, T4 = 22.60, T5 = 21.30 d dT e 5 x + e10 5 x (b) ( kA ) = c (T T ) ; solution T = 80( ) + 20 dx dx 1 + e10 Classroom Example 3 (a) Central: Cell 1: 0.592 P + 0.493 E = 0 Cells 2 6: Cell 7: (b) Upwind: Cell 1: Cells 2 6: Cell 7: 0.507W + 0.085 P + 0.493 E = 0.507W + 0.578 P = 0 0.01 in cell 4 otherwise 0

1.092 P 0.007 E = 0
1.007W + 1.085 P 0.007 E = 1.007W + 1.078 P = 0 0.01 in cell 4 0 otherwise

Classroom Example 4 A = 1, B = 2, C = 3, D = 4

CFD

4 28

David Apsley

Q1. Q3.

EE + 27 E 27 P + W 24 x

(a) e w n s (b) = = = =
3 1 +3 +8 E 8 W 4 P 3 1 +3 +8 P 8 WW 4 W 3 3 1 8 S + 4 P + 8 N 3 1 +3 +8 P 8 SS 4 S

a P P a F F = bP where: 3 = 8 aE Ce 1 = 3 aW 4 C w + 8 Ce aWW = 1 8 Cw a P = aWW + aW + a E + a SS + a S


bP = SV and C e = uAe , C n = vAn , etc.

aN aS a SS

3 = 8 Cn 1 = 3 4 Cs + 8 Cn = 1 8 Cs

+ a N + (C e C w + C n C s )
= 0 by mass conservation

(c) e w (d) (e)


face
3 3 = 1 8 UU + 4 U + 8 D 3 = U + { 1 1 +8 D} 8 UU 4 U deferred correction
3 = 1 +3 +8 P 8 EE 4 E 3 3 1 = 8 E + 4 P + 8 W

QUICK is transportive, but not bounded

Q4.

F= u
= 1, (a) (b) (c) (d)

P e Pe E e Pe 1 = 0, S = 0 Not very efficient (and would fail for positive-definite quantities) Wrong source if P < 0. Unstable, because sP > 0. This is the best method.

Q5. Q6.

CFD

4 29

David Apsley

Q7

(a) (b) (c) (d)

(e)

on the lower wall: u = 0; on the upper wall: u = U0 G x y u j +1 u j ( north ) 12 y U 0 uN On the upper wall: 12 2 y u On the lower wall: 12 2 1 y G y2 Internal cells: u j 1 + 2u j u j +1 = Top cell: Bottom cell: u N 1 + 3u N = 3u1 u 2 =

G y2

+ 2U 0

G y2

(f) (g) (h)

u1 = 1 u2 = 5 u3 = 7 u4 = U 0 , 4U0, 8U0, 8U0, 11 q = 16 U 0 H u y y y Analytical solution: = (1 ) + U0 H H H 15 39 55 63 u1 = 64 U 0 , u 2 = 64 U 0 , u 3 = 64 U 0 , u 4 = 64 U0 q=2 3U0H


d d ) e ( u S dx )w = dx dx w W P d d ; P E dx e x dx w x (i) First-order upwind: e = P , w = W 1 (ii) Central: e = 1 2 ( P + E ) , w = 2 (W + P ) u x 2
e

Q8.

(a) (b) (c)

( u

(d) (e) (f) Q9. (a)

(i) (ii)

first-order upwind: = 0; central: = 1. d 8 e = 4 , w = , = 20 , dx e 3


LUD : (r ) = r (r ) = 1 QUICK : 4r +

d dx

= 20 , S =
w

64 3

3 4

Q10.

1 = 0.365, 2 = 0.456, 3 = 0.425

CFD

4 30

David Apsley

You might also like