You are on page 1of 32

4.

4.1 The scalar-transport equation

4.2 Control-volume notation
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.12 Implementation of boundary conditions
4.13 Solution of the algebraic equations
Summary
Examples

4.1 The Scalar-Transport Equation

This is a generic equation for transported physical quantities (momentum, energy,...) For an
arbitrary control volume V:
 RATE OF CHANGE  +  FLUX  =  SOURCE 
     
 inside V   out of boundary   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”) as: u
d ∂φ
( Vφ) + ∑( Cφ − A ) = SV V un
dt faces ∂n
rate of change advection diffusion source A

(Non-advective fluxes not described by gradient diffusion are assumed to be incorporated in

the source term.)

The commonest configurations are cell-centred storage or cell-vertex storage.

cell-centred cell-vertex

CFD 4–1 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 the 2nd edition of Versteeg and
Malalasekera’s book gives a much better description.)

A typical 3-d control volume is shown right. Relative T

to the cell centre (point P) the coordinate directions
are commonly denoted west, east, south, north,
bottom, top with: t
• lower case w, e, s, n, b, t used for cell faces; N
• upper case W, E, S, N, B, T for adjacent nodes. W w
n
For a Cartesian mesh these would usually correspond s P e
to ±x, ±y, ±z directions respectively. E
S
b
Cell-face areas will be denoted Aw, Ae, As, An, Ab, At. k
Cell volumes will be denoted V. In 2 dimensions one
j
can think of a single layer of cells with unit depth. B
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 i,j+2

N i,j+1
n
WW Ww P e E EE i-2,j i-1,j i,j i+1,j i+2,j

s
i,j-1
S
j i,j-2
SS
i

CFD 4–2 David Apsley

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.

Conservation for one control volume gives

area A
fluxe − flux w = source (1)
where “flux” means the rate of transport through a cell face.
flux w source flux e
If φ is the amount per unit mass, then the total flux has
advective and diffusive parts: ∆ x

diffusion: − A
dx
If S is the source per unit length then the advection-diffusion equation for φ is
 dφ   dφ 
 uAφ − A  −  uAφ − A  = S x (2)
 dx  e  dx  w

Dividing by x and taking the limit as x → 0 gives a corresponding differential equation:

d dφ
( uAφ − A ) = S (3)
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 (4)
dx dx dx

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, 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 separate transport equation.

CFD 4–3 David Apsley

4.4 Discretising Diffusion

Classroom Example 1
o o
T=100 C T=500 C

Rod

x= 0 1

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 m–1 K–1.

(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:

dφ  φ − φP 
W w P e E
− A → − ( A) e  E  (5)
∆x
dx e  x 
or
dφ A
− A → − De (φ E − φ P ) where D≡ (6)
dx e x
D is a diffusive transfer coefficient

A similar expression is used for the west face:

− A → − D w ( φ P − φW )
dx w

Note:
• 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 4–4 David Apsley

4.5 Discretising the Source Term

Classroom Example 2
o
Too=20 C
o
T=100 C

dT
Rod dx =0

0 S=-c(T-Too) 1

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 (Newton’s 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 m–1 K–1.

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:
− Dw φW + ( Dw + De − s p )φ P − De φ 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):
a P φ P − ∑ a F φ F = bP (8)
nodes

CFD 4–5 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
O O 0 M   M 
    
O O O  M   M 

− aW a P − a E  φ  = b 
 P  P
O O O  M   M 
or
Φ b
    
0 O O  M   M 

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 elements of the matrix are dependent on the solution
then it must be solved iteratively.

4.7 Extension to 2 and 3 Dimensions

flux n
For a multi-dimensional flow the net flux out of a cell can be
obtained by summing the outward fluxes through all faces.
flux w source flux e
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 flux s
equation may be written:
( flux e − flux w ) + ( flux n − flux s ) + ( fluxt − fluxb ) = source (9)

The discretised equations are still assembled in the same matrix form
a P φ P − ∑ a F φ F = bP (10)
F
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.
Φ b
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 4–6 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.

The 1-d steady-state advection-diffusion equation is u

fluxe − flux w = source
where, with mass flux C (= uA): W w P e E

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
(11)

φe and φw have yet to be approximated. The problem is … how to approximate these face
values in terms of the values at adjacent nodes. A method of specifying these face values in
order to calculate advective fluxes is called an advection scheme or advection-differencing
scheme.

Classroom Example 3.

φ=0 u dφ
dx =0
x= 0 L
point
source

A pipe of cross-section A = 0.01 m2 and length L = 1 m carries water (density

= 1000 kg m–3) at velocity u = 0.1 m s–1.

A faulty valve introduces a reactive chemical into the pipe half-way along its length at a
rate of 0.01 kg s–1. The diffusivity of the chemical in water is = 0.1 kg m–1 s–1. 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 m–1 s–1.

Assuming that the downstream boundary condition is 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 4–7 David Apsley

φP
φe
4.8.1 Central Differencing
φE
In central differencing the cell-face value is approximated by
the average of values at the nodes on either side: P E
φ e = 12 (φ P + φ E ) e
This is second-order accurate for φe in terms of ∆x (see later).
Substituting into (11) (with a similar expression for φw) gives
2 C e (φ P + φ E ) − 2 C w (φW + φ P ) − De (φ E − φ P ) + Dw (φ P − φW ) = bP + s P φ P
1 1

or, collecting terms,

− ( 12 C w + Dw )φW + ( 12 C e − 12 C w + De + Dw − s P )φ P − (− 12 C e + De )φ E = bP

In out canonical notation:

a P φ P − ∑ a F φ F = bP
F
where, in one dimension:
aW = 12 C w + Dw
a E = − 12 C e + De (12)
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.)

The graphs below show the solution of an advection-diffusion problem with no sources and
constant diffusivity for the two combinations
Pe = 1/2 (advection « diffusion) (equation: − 54 φW + 2φ P − 34 φ E = 0 )
Pe = 4 (advection » diffusion) (equation: − 3φW + 2φ P + φ E = 0 )
where the Peclet number Pe is defined by
C advection  u x
Pe =  i.e.  = (13)
D diffusion 

Pe = 1/2 Pe = 4

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 4–8 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 diffusion only
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. u advection
+
However, the central-differencing formula assigns diffusion
equal weight to both upwind and downwind nodes.

In upwind differencing φface is taken as the value at

whichever is the upwind node; i.e. in one dimension:
φP φe
φ
φe =  P
(if u > 0) φE
φ E (if u < 0)
P E
This is only first-order accurate in x (see later) but
acknowledges the directional nature of advection. The
alternatives can be summarised as e
φ 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.

CFD 4–9 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 flux
cells, so that what goes out of one cell goes into the adjacent cell;

This is automatically built into the finite-volume method.

(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 then 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 (sPφP) 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: a F ≥ 0 for all F

negative-slope linearisation of the source term: source = bP + s P φ P , s P ≤ 0
sum of neighbouring coefficients: aP = ∑ aF − sP
F

(vi) Order

Order is a measure of accuracy. Formally, it defines how fast the error in a numerical
approximation diminishes as the grid spacing gets smaller.

If, on a uniform grid of spacing x, the truncation error is proportional to xn as x 0 then

that scheme is said to be of order n.

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:
 ∂φ  x 1  ∂ 2φ  x 2 1  ∂ 3φ  x
φ E = φe +   ( ) + 
 
2 
( ) +  3  ( ) 3 + L (18)(a)
 ∂x  e 2 2!  ∂x  e 2 3!  ∂x  e 2
 ∂φ  x 1  ∂ 2φ  x 1  ∂ 3φ  x
φ P = φe −   ( ) +  2  ( ) 2 −  3  ( ) 3 + L (18)(b)
 ∂x  e 2 2!  ∂x  e 2 3!  ∂x  e 2
∆x

CFD 4 – 11 David Apsley

 ∂φ  1  ∂ 3φ  x
φE − φP = 0 +   x + 0 +  3  ( ) 3 + L
 ∂x  e 3  ∂x  e 2
whence, dividing by x:
φ E − φ P  ∂φ 
=   + O( x 2 )
x  ∂x  e
φ − φP  ∂φ 
As the leading error term is O(∆x2), E is a second-order approximation for   .
x  ∂x  e

Alternatively, adding (18)(a) – (b) gives:

 ∂ 2φ  x
φ P + φ E = 2φ e + 0 +  2  ( ) 2 + L
 ∂x  e 2
whence:
2 (φ P + φ E ) = φ e + O ( x )
1 2

As the error term is O( x2), the central differencing formula 12 (φ P + φ E ) is a second-order

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.

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.

Notes.
(1) Order is an asymptotic concept; i.e. it refers to behaviour as x 0. In this limit only
the first non-zero truncation term in the Taylor series is important. However, the full
expansion includes terms of higher order which may be non-negligible for finite x.

(2) Order refers to the theoretical truncation error in the approximation, not the
computer’s round-off error (the accuracy with which it can store floating-point
numbers).

(3) 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
fluxe − flux w ≡ source flux w source flux e
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:

flux = uAφ − A = constant
dx
If , u, A and are constant 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 −1 
Pe

where
C = uA = mass flux
A
D = = diffusive transfer coefficient
x
C u x
Pe = =
D
.
With a similar expression for the west face, one obtains
fluxe − flux w = a P φ P − ∑ a F φ F
where:
Ce Pe C
aW = Pe , a E = Pe , a P = a E + aW (20)
e −1 e −1

Assessment
• Conservative by construction.
• Transportive, because there is a larger weighting on the upwind node.
• Bounded: all aF are positive and aP is the sum of the neighbouring coefficients.

To see the last two of these you will have to consider separately the cases C > 0 (for which
ePe > 1) and C < 0 (for which ePe < 1).

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 isn’t 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 and the mass flux C and diffusive transport coefficient D are constant):
aW = 12 C + D , a E = − 12 C + D if Pe ≡ C/D ≤ 2

aW = C , aE = 0 if Pe > 2 (21)
a P = a E + aW

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/low-
diffusion 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 3rd-order
accuracy.
φP φ
e φE
For each cell face, QUICK uses the nodes either side of the
cell face, plus a further upwind node depending on the W P E
direction of the flow as shown right.
e

UU U D To emphasise the conservation u>0

property which associates
fluxes with cell faces, not
face nodes, we shall, in future, for φP
all such three-point schemes use the notation φD, φU and φUU φe
φE
for the Downwind, Upwind and Upwind-Upwind nodes at φEE
any particular face.
P E EE
By fitting a quadratic polynomial to these nodes (see the e
Examples) the QUICK scheme gives:
φ face = − 18 φUU + 34 φU + 83 φ D u<0 (22)

CFD 4 – 14 David Apsley

For example, if u > 0 on the east face then:
φ e = − 18 φW + 34 φ P + 83 φ E WW W P E EE
whereas, if u < 0: w e
φ e = − 18 φ E + 34 φ E + 83 φ P

Assessment
• 3rd-order accurate.
• Conservative by construction.
• Transportive (upwind bias in the selection of the third node and relative weightings).
• Not bounded; (for example, if u > 0 then aE is negative – see the Examples).

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 first-
order 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 if φUU < φU < φ D ,
monotonic decreasing if φUU > φU > φ D .
UU U D UU U D
A necessary condition for boundedness is that
the schemes must default to first-order
upwinding (i.e. φface = φU) if φ is not locally
monotonic non-monotonic
monotonic (either increasing or decreasing).

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) as the sum
of the upstream value (φU) and a solution-dependent fraction of the difference between
downstream and upstream nodal values:
φ + 1 (r )(φ D − φU ) if monotone
φ face =  U 2
φU otherwise
where r is the ratio of successive differences (>0 where monotonic): UU U D
φ − φUU
r= U
φ D − φU face

CFD 4 – 15 David Apsley

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

Scheme (r) (for r > 0)

Upstream Monotonic Interpolation for Scalar
min{2, 2r , 14 (1 + 3r ), 14 (3 + r )} Transport (Lien and Leschziner, 1993). A limited
UMIST
variant of QUICK, this is 3rd-order accurate where
monotone.
2r Van Leer (1974).
Harmonic Second-order accurate where monotone.
1+ r

(r) is taken as 0 if non-monotonic (i.e., r < 0).

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 elements
depend on, and hence change with, the solution φ). The last property means that an iterative
numerical solution is inevitable.

The general steady-state scalar transport equation is

∂φ

faces
( Cφ −
∂n
A ) = SV
(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 ∑C = 0
by mass conservation, it is convenient to subtract ∑ Cφ P (which is 0) from both sides:
∑ [C (φ
faces
face − φ P ) + D(φ P − φ F )] = bP + s P φ P (24)

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 )

CFD 4 – 16 David Apsley

C (φ face − φ P ) = C (φU − φ P ) + C (φ face − φU )
14243 14 4244 3
upwind correction (25)
= max(−C ,0)(φ P − φ F ) + C (φ face − φU )

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 won’t be updated until the next iteration):
∑F a F (φ P − φ F ) = bP + s P φ P − faces
∑ C (φ face − φU )
144 42444 3
deferred correction

The most common types of boundary condition are:

• value φ specified (Dirichlet boundary conditions);
e.g. φ = 0: velocity at a wall, or temperature fixed at some surface;
• gradient ∂φ/∂n specified (Neumann boundary conditions).
e.g. ∂φ/∂n = 0 on a symmetry plane, or at an outflow boundary.

In the finite-volume method,

boundary
both types of boundary
boundary

condition can be implemented 2 3 4 NI-3 NI-2 NI-1

by transferring the boundary
flux to the source term.

For a cell abutting a boundary:

∑ flux + fluxboundary = source
not
boundary

⇓ P B
aP φ P − ∑
not
a F φ F = bP − fluxboundary
boundary

Thus, there are two modifications: boundary

• the aF coefficient in the direction of the boundary is set to zero;
• the outward boundary flux is subtracted from the source terms.

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 )

 2 x 
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 back-
substitution.

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

N 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 direction of sweep
until convergence is achieved.

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 (which actually has the same solution):
 1 −4 0 0   A  − 7 
    
 − 4 1 − 4 0   B   − 14 
 0 − 4 1 − 4   C  =  − 21
    
 0 −   D  − 8 
 0 4 1    
Why does Gauss-Seidel not converge in this case?

Along any one coordinate line, the system is tri-

diagonal; e.g. in the i-direction: φ b- φ*
− a φ + a φ − a φ = b − a φ*
W W P P E E P ∑
not
F F

W ,E

Thus, using the tri-diagonal matrix algorithm a whole

N
line can be updated at one go and information can of sweep
direction

propagate right across the domain in one iteration, W P E

rather than (as in Gauss-Seidel) one node at a time. A
typical single iteration would consist of applying the S
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 doesn’t work for unstructured grids.

CFD 4 – 19 David Apsley

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.
sum of absolute residuals: Error = ∑ res
cells

1
root-mean-square (rms) error: Error = ∑
N cells
(res ) 2

where the residual is the error in satisfying the algebraic equations for any one cell:
res = a P φ P − ∑ a F φ F − bP
F
The tolerance is usually set to some small fraction (e.g. 10–4) 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

φP =
∑ a F φ F + bP
aP
and then written in terms of the change in φ by adding and subtracting the previous value:
 ∑ a F φ F + bP 
φ P = φ old
P +
 − φ old
P 

 a P 

If, instead, only a fraction of the change in φ is applied then

 ∑ a F φ F + bP 
φ P = φ old
P + 
 − φ old
P 

 a P 
is called an under-relaxation factor.

The equation can then be rearranged back as

a P φ 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, which
improves stability. Since φ P = φ old
P in the converged 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
− A → − (φ E − φ P )
∂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
various 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”)
aP = ∑ aF − sP (“sum of the neighbouring coefficients”)
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.

Appendix: Tri-Diagonal Matrix Algorithm

 b1 − c1 0 O 0   φ1   d1 
System of equations:     
− ai φ i −1 + bi φ i − ci φ i +1 = d i , i = 1,K, N O O O 0 O  M   M 
 0 −a b −c 0   φi  =  d i 
 i i i
   
Either φ 0 and φ N +1 are given, or a1 = cN = 0. O 0 O O O  M   M 
 0 O 0 −a bN   φ N   d N 
 N

Forward pass:
P0 = 0, Q0 = φ 0
ci d i + ai Qi −1
Pi = , Qi = , i = 1, K, N
bi − ai Pi −1 bi − ai Pi −1

Backward pass:
φ i = Pi φ i +1 + Qi , i = N , K, 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.
The central-differencing scheme for diffusion using cell- W P E EE
centred storage uses the approximation
dφ φ − φP
≈ 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 , U and D at locations − 32 x ,
− 12 x , and 12 x takes the value
− 18 φUU + 34 φU + 83 φ D
at x = 0. (This is the basis of the QUICK advection scheme).

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

Q3. UU U D
The QUICK scheme fits a quadratic function to three nodal values
to estimate the value of a scalar at a cell face, according to
φ face = − 18 φUU + 34 φU + 83 φ D face

(a) 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.

(b) 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).

(c) How do the expressions for φw and φe change if u < 0.

(d) Which of the following properties does the QUICK scheme satisfy:
transportiveness;
boundedness.

(e) Split the QUICK expression for φface in the form

“Upwind differencing” + “deferred correction”
Why is this decomposition used?

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

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):
(a) bP = 2 − 3 φ *P φ *P , s P = 0
2
(b) bP = 2 − 3φ*P , s P = 0
(c) bP = 2 − 4 φ*P φ*P , s P = φ*P
(d) bP = 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.

∆x
U0
uN

u j+1

H
uj ∆y
uj-1

u1

(a) What are the boundary conditions on upper and lower walls?

(b) What is the net pressure force on a single cell?

(c) Write down a second-order approximation for the shear stress on the upper face of
the jth internal cell, in terms of the velocities uj and uj+1.

(d) Write down similar approximations for on upper and lower walls.

(e) By balancing pressure and viscous forces set up the finite-volume equations for
velocity. (Separate equations are required for internal and boundary cells).

(f) Solve your equations for the nodal velocities in the case
GH 2
N = 4, =2
U0
leaving your answers in terms of U0.

(g) Using your answer to part (f), find the volume flow rate per unit span (leaving your
answer as a multiple of U0H).

(h) Solve the Navier-Stokes equation analytically for this case and compare with your
answers in parts (f) and (g).

CFD 4 – 25 David Apsley

Q8. (Computational Hydraulics Exam, June 2009)
A 2-d finite-volume calculation is to be undertaken for fully-developed, laminar flow
between stationary, plane, parallel walls. A streamwise pressure gradient dp/dx = −G is
imposed and the fluid viscosity is . The depth of the channel, H, is divided into N equally-
sized cells of dimension x × y × 1 as shown in the figure below, with the velocity u stored
at the centre of each cell.

uN

u j+1
uj
H ∆y
uj-1

u1

∆x

(b) What is the net pressure force on a single cell?

(c) Using a finite-difference approximation for velocity gradient, find expressions for the
viscous forces on upper and lower faces of the jth cell in terms of the nodal velocities
{uj}. (You will need to deal separately with interior cells and the boundary cells j = 1
and j = N.)

(d) By balancing pressure and viscous forces set up the finite-volume equations for the
velocity field.

(e) Solve for the nodal velocities in the case N = 6, leaving your answers as multiples of
U 0 = GH 2 / . (You are advised to note the symmetry of the problem.)

(f) Using your numerical solution, find the volume flow rate (per unit span) Q in terms of
U0 and H.

CFD 4 – 26 David Apsley

Q9. (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 e
WW W P 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.

(b) Write finite-difference expressions for dφ/dx on both w and e faces.

(c) Write expressions for φ on w and e faces of the shaded cell if u is positive for (i) first-
order upwind; and (ii) central advection schemes.

(d) 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.

A general expression for φe when u is positive is

φ P − φW
φ e = φ P + 12 (r )(φ E − φ P ) where r=
φE − φP
(e) Write the (constant) values of for (i) first-order upwind; and (ii) central advection
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 – 27 David Apsley

(**** Remaining questions for MSc Course only ****)
Q10. (MSc exam, May 2008 – part)
The general three-point scheme for the cell-face value of a transported scalar φ is
φ − φUU UU U D
φ face = φU + 12 (r )(φ D − φU ) , r= U
φ D − φU
where upstream (U) and downstream (D) are defined by flow direction face

(a) The linear upwind differencing (LUD) and QUICK schemes are:
LUD: φ face = 32 φU − 12 φUU
QUICK: φ face = − 18 φUU + 34 φU + 83 φ D
Identify the functional form of (r) for each of these schemes.

(b) Sweby’s conditions for total-variation-diminishing (TVD) schemes are that

=0 if r ≤ 0
≤ min(2r ,2) if r ≥ 0
Show that LUD and QUICK both contravene these conditions for some r 0.

(c) The Van Albada scheme has

 0, if r ≤ 0

(r ) =  r + r 2

 1 + r 2 , if r ≥ 0
Show that this satisfies Sweby’s criteria and also the symmetry property
(r ) 1
= ( ) for r > 0
r r

Q11. (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,K, 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 .

Q12. (MSc Exam, May 2008 – part)

The linear system of equations
− ai φ i −1 + bi φ i − ci φ i +1 = d i , i = 1,2,K, 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 ,K,1
where {Pi} and {Qi}are determined from an initial forward pass. Show that
ci
Pi = , i = 1,K, 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 – 28 David Apsley

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
0.01 in cell 4
Cells 2 – 6: − 0.507φW + 0.085φ P + 0.493φ E = 
0 otherwise
Cell 7: − 0.507φW + 0.578φ P = 0

(b) Upwind:
Cell 1: 1.092φ P − 0.007φ E = 0
0.01 in cell 4
Cells 2 – 6: − 1.007φW + 1.085φ P − 0.007φ E = 
0 otherwise
Cell 7: − 1.007φW + 1.078φ P = 0

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

CFD 4 – 29 David Apsley

− φ EE + 27φ E − 27φ P + φW
Q1.
24 x

Q3. (a)
φe = − 18 φW + 34 φ P + 83 φ E
φw = − 18 φWW + 34 φW + 83 φ P
φn = − 18 φ S + 34 φ P + 83 φ N
φs = − 18 φ SS + 34 φ S + 83 φ P

(b) a P φ P − ∑ a F φ F = bP
where:
aE = − 83 C e aN = − 83 C n
aW = 34 C w + 18 C e aS = 34 C s + 18 C n
aWW = − 18 C w a SS = − 18 C s
a P = aWW + aW + a E + a SS + a S + a N + (C e − C w + C n − C s )
144424443
= 0 by mass conservation

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

(c)
φe = − 18 φ EE + 34 φ E + 83 φ P
φw = − 18 φ E + 34 φ P + 83 φW

(d) QUICK is transportive, but not bounded

(e)
φ face = − 18 φUU + 34 φU + 83 φ D
= φU + {− 18 φUU − 14 φU + 83 φ D }
1444 424444 3
deferred correction

 φ e Pe − φ E 
Q4. F = u P Pe 
 e −1 

Q5. φ = 1, = 0, S = 0

Q6. (a) Not very efficient (and would fail for positive-definite quantities)
(b) Wrong source if φP < 0.
(c) Unstable, because sP > 0.
(d) This is the best method.

CFD 4 – 30 David Apsley

Q7 (a) on the lower wall: u = 0; on the upper wall: u = U0
(b) G x y
u j +1 − u j
(c) ( north )

y
U 0 − uN
(d) On the upper wall: ≈ 1
2 y

u −0
On the lower wall: ≈ 11
2 y

G y2
(e) Internal cells: − u j −1 + 2u j − u j +1 =

G y2
Top cell: − u N −1 + 3u N = + 2U 0

G y2
Bottom cell: 3u1 − u 2 =

(f) u1 = 14 U 0 , u 2 = 58 U 0 , u 3 = 78 U 0 , u 4 = U 0 ,
(g) q = 16
11
U0H
u y y y
(h) Analytical solution: = (1 − ) +
U0 H H H
u1 = 64 U 0 , u 2 = 64 U 0 , u 3 = 64 U 0 , u 4 = 64
15 39 55 63
U0
q = 3U0H
2

Q8. (a) u = 0 on both walls

(b) G x y
x
(c) viscous force on upper face = (u j +1 − u j )
y
x
viscous force on lower face = − (u j − u j −1 )
y
x
viscous force on upper face of top cell = −2 uN
y
x
viscous force on lower face of bottom cell = −2 u1
y
G y2
(d) Internal cells: − u j −1 + 2u j − u j +1 =

G y2
Top cell: − u N −1 + 3u N =

G y2
Bottom cell: 3u1 − u 2 =

(e) u1 = u 6 = 723 U 0 , u 2 = u 5 = 7
72 U0 , u3 = u 4 = 9
72 U0
(f) Q = 216
19
U0H
w = 2 GH
1
(g)

CFD 4 – 31 David Apsley

dφ dφ
e

Q9. (a) ( uφ − ) e − ( uφ − )w = ⌠  S dx
dx dx ⌡w
 dφ  φ − φP  dφ  φ − φW
(b)   ≈ E ;   ≈ P
 dx  e x  dx  w x
(c) (i) First-order upwind: φ e = φ P , φ w = φW
(ii) Central: φ e = 12 (φ P + φ E ) , φ w = 12 (φW + φ P )
u x
(d) ≤2
(e) (i) first-order upwind: = 0;
(ii) central: = 1.
8  dφ   dφ  64
(f) φ e = 4 , φ w = ,   = −20 ,   = 20 , S =
3  dx  e  dx  w 3

Q10. (a) LUD : (r ) = r

QUICK : (r ) = 14 (r + 3)