Documente Academic
Documente Profesional
Documente Cultură
Finite element and finite volume schemes are both based on dividing the flow domain into a
(large) number of small cells, or volumes. These can be of any shape (triangles,
quadrilaterals, etc. in 2-D; tetrahedra, prisms, cubes, etc. in 3-D). They are thus more
suitable for application to complex flow geometries.
We will examine finite volume schemes later. However, to begin with we consider how finite
difference schemes can be devised.
Reading:
J. Ferziger, M. Peric, Computational Methods for Fluid
Dynamics
H.K. Versteeg, W. Malalasekara, An Introduction to Computational Fluid Dynamics: The Finite Volume Method
S.V. Patankar, Numerical Heat Transfer and Fluid Flow
Notes: http://cfd.mace.manchester.ac.uk/tmcfd
- People - T. Craft - Online Teaching Material
Despite not being generally used in industrial codes, finite difference schemes are useful for
introducing the ideas of accuracy, truncation error, stability and boundedness in a
well-defined and fairly transparent way.
- p. 3
Introduction
Approximating Derivatives
In this lecture we turn attention to the process of discretizing the governing partial differential
equations of a fluid flow.
Discretization is the process of approximating the differential equations by a system of
algebraic ones linking the (discrete) nodal values of velocity, pressure, etc.
In developing finite difference schemes a simple equation to consider, which is related to the
more complex Navier-Stokes system, is the 1-D convection-diffusion problem:
(1)
=
x
x
x
There are three broad methods employed for discretizing the governing partial differential
equations of a fluid flow:
is the variable being transported by the flow (ie. the quantity we need to solve for), U is the
convective velocity and the diffusivity. If, for example, represents the fluid temperature,
this equation describes the 1-D problem of temperature changes due to convection by the
fluid and diffusion by molecular action.
x
x1
x3
x4
f(x)
x
x1
- p. 2
x2
x2
x3
x4
- p. 4
Taylor series expansions can often be used to develop and/or analyse the accuracy of
numerical approximations for derivatives.
2!
f (xi ) +
(x)3
3!
f (xi ) + O(x4 )
(2)
(8)
f (xi ) f (xi1 )
+ O(x)
x
(9)
xi
This approximation,
Rearranging gives
(x)2
(x)3
f (xi )
f (xi ) + O(x4 )
2!
3!
f (xi ) =
(7)
(x)2
(x)3
f (xi )
f (xi ) + O(x4 )
2!
3!
f (xi )
f (xi ) + O(x3 )
x
2!
3!
(10)
f (xi + x) f (xi )
+ O(x)
x
(3)
xi-1
xi
If we take x as the uniform grid spacing, so x = xi+1 xi , then we get the approximation
f (xi ) =
f (xi+1 ) f (xi )
+ O(x)
x
(4)
fi+1 fi
+ O(x)
x
(5)
(11)
(12)
(x)3
f (xi ) + O(x5 )
3!
(13)
- p. 7
f (xi ) =
(6)
x
xi
f (xi+1 ) f (xi1 )
+ O(x2 )
2x
(14)
The approximation
x i+1
This is a first order scheme, since the error is proportional to x, so decreases linearly with
grid spacing.
(15)
- p. 6
x
xi-1
xi
x i+1
- p. 8
Order of Approximation
Polynomial Approximation
At this point it is worth considering exactly what is meant by the order of accuracy of a
discretization approximation.
Note that the above approximations for the derivatives could also have been derived by
fitting a polynomial to the function f through xi and surrounding points and then
differentiating this polynomial to get its gradient.
As we refine the grid, for any useful scheme, errors associated with the discretization
approximation can be expected to reduce.
We reach a grid independent solution when any further grid refinement produces no
significant difference in the computed solution. At this stage the discretization errors are
small enough that they can be neglected.
We have defined the order of a scheme in terms of the leading order error term in the Taylor
series expansion.
This should, therefore, determine at what rate the error reduces as the grid is refined.
For a first order scheme, if the grid spacing is halved the error is halved; for a second order
scheme the error would reduce by a factor of 4.
x
xi-1
xi
x i+1
(x xi )(x xi+1 )
(x xi1 )(x xi+1 )
(x xi )(x xi1 )
fi1 +
fi +
fi+1
(xi1 xi )(xi1 xi+1 )
(xi xi1 )(xi xi+1 )
(xi+1 xi )(xi+1 xi1 )
(18)
Note that this does not mean that a second order solution on one particular grid will always
be more accurate than a first order one (although this will usually be the case for a
sufficiently fine grid).
On a uniform grid with xi+1 xi = xi xi1 = x and xi+1 xi1 = 2x this becomes
It does, however, tell us that as we refine the grid the error in the higher order scheme goes
down more rapidly, so we should expect the higher order scheme to reach a grid
independent solution on a coarser grid than would be required for a lower order scheme.
f (x) =
(x xi )(x xi+1 )
(x xi1 )(x xi+1 )
(x xi )(x xi1 )
fi1
fi +
fi+1
2(x)2
(x)2
2(x)2
- p. 9
It is also worth noting that the behaviour as described above for a particular scheme can
only be expected to be seen on a reasonably fine grid.
fi fi1
(x)2
x
+
f (xi )
f (xi ) + O(x3 )
x
2!
3!
f (x) =
If the first term in the truncation is to be the leading error term, then x has to be small
enough so that
(x)2
x
|f (xi )| <<
|f (xi )|
3!
2!
or
(x xi + x xi+1 )
(x xi1 + x xi+1 )
(x xi + x xi1 )
fi1
fi +
fi+1 (20)
2(x)2
(x)2
2(x)2
and thus
(16)
f (xi )
x << 3
f (xi )
- p. 11
The reason for this can be seen from the Taylor series expansion. For example, in the first
order backward difference scheme we have
fi =
(19)
f (xi ) =
x
0
x
(fi+1 fi1 )
fi1
fi +
fi+1 =
2(x)2
(x)2
2(x)2
2x
(21)
The above procedure does not immediately show us what order the truncation error is.
(17)
However, the order of the scheme can be determined by expressing fi+1 and fi1 as Taylor
series expansions about xi as before, and substituting these into the right hand side
expression of equation (21).
For example, in a turbulent near-wall boundary layer we find that the turbulent kinetic energy
dissipation rate, , behaves like A/y + where A is some constant and y + the
non-dimensional distance to the wall. Then, differentiating with respect to y + ,
A/(y + )2
2A/(y + )3
6A/(y + )4
so
| / | y + /3
The above result therefore suggests that, if we are considering the flow region y + 30
(which is broadly where this behaviour of is found), then the grid spacing should be such
that y + is significantly less than 30 (typically y + . 5), in order to see errors from this first
order scheme scale linearly with grid spacing.
- p. 10
- p. 12
Non-Uniform Grids
In most CFD applications non-uniform grids are employed, allowing the grid to be more
refined in regions where strong gradients are expected.
Taylor series expansions or polynomial fits can also be used to derive approximations to
higher order derivatives. For example, to approximate the second derivative d2 f /dx2 we
could, as before, write:
(x)2
(x)3
f (xi ) +
f (xi ) + O(x4 )
2!
3!
(x)2
(x)3
f (xi )
f (xi ) + O(x4 )
f (xi1 ) = f (xi ) xf (xi ) +
2!
3!
f (xi+1 ) = f (xi ) + xf (xi ) +
(22)
(23)
xi
xi
x
xi+1
x i-1
(24)
From this we can see that the central difference approximation for the second derivative
(xi )2
(xi )3
(29)
f (xi ) +
f (xi ) + O((xi )4 )
2!
3!
2
3
(xi1 )
(xi1 )
f (xi1 ) = f (xi ) xi1 f (xi ) +
f (xi )
f (xi ) + O((xi1 )4 )
2!
3!
f (xi+1 ) = f (xi ) + xi f (xi ) +
(30)
fi
(x)2
(25)
Subtracting gives
f (xi+1 ) f (xi1 ) = (xi + xi1 )f (xi ) + (x2i x2i1 )f (xi ) + O(x3 )
Hence we obtain
f (xi ) =
f (xi+1 ) f (xi1 )
f (xi )
(xi xi1 ) + O(x2 )
+
xi + xi+1
2!
- p. 13
(26)
If is constant, then it can simply be taken outside the derivative, and the form above
(equation (25)) employed to approximate d2 f /dx2 .
df
dx
x1/2
fi fi1
x
(32)
- p. 15
Note that formally the central difference fi = (fi+1 fi1 )/(xi + xi1 ) is now only first
order accurate.
In many fluids related problems the second derivative that requires approximation is a
diffusion term of the form
x
x
However, in practice, one should avoid using very rapidly expanding grids, so that typically
xi = rxi1 where the grid expansion ratio r is not too far from unity. In this case the
factor (xi xi1 ) = xi (1 r) in the leading order error can still be essentially second
order.
Note that the approximation derived from the polynomial fit of equation (18) still gives a
formally second order approximation.
(31)
x
xi-1
df
dx
x+1/2
x i-1/2
xi
fi+1 fi
x
x
x
(x)2
xi+1/2
x i+1
Differentiating leads to
(27)
f (xi ) =
(x xi + x xi+1 )
(x xi1 + x xi+1 )
(x xi + x xi1 )
fi1 +
fi+1
fi +
(xi1 )(xi + xi1 )
xi xi1
(xi )(xi + xi1 )
(34)
(28)
Note that interpolation may be required to estimate values of at the midpoints xi+1/2 and
xi1/2 .
- p. 14
fi
xi
xi xi1
xi1
fi1 +
fi+1
fi +
(xi1 )(xi + xi1 )
xi xi1
(xi )(xi + xi1 )
(35)
- p. 16
If we express fi+1 and fi1 as Taylor series expansions about xi the above approximation
implies
Notice that the Peclet number gives a measure of the ratio of convective effects to diffusive
ones.
xi
(xi1 )2
(xi1 )3
fi xi1 fi +
fi
fi + O(x4 )
(xi1 )(xi + xi1 )
2!
2!
As can be seen, as the Peclet number increases (diffusive effects become weaker), the
region over which most of the variation in occurs becomes thinner, and the gradients of
across it become correspondingly larger.
fi
xi xi1
fi
xi xi1
If we discretize the convection-diffusion equation using a uniform grid and central differences
for both convective and diffusive terms, we get
i+1 i1
i+1 2i + i1
U
(38)
=
2x
x2
xi1
(xi )2
(xi )3
+
fi + xi fi +
fi +
fi + O(x4 )
(xi )(xi + xi1 )
2!
2!
= fi +
xi xi1
fi + O(x3 )
3!
or, on rearranging:
Thus showing that the approximation of equation (35) is indeed second order.
i1
2x
x2
2
i + i+1
x2
2x
x2
=0
(39)
U
2
=0
2
3
x2
2x
x2
U
2
U
n2
+
n1
2x
x2
x2
2x
x2
xn1 x n
(40)
(41)
- p. 17
The discretized form of equations can thus be represented in the tri-diagonal matrix form:
U
=
x
x
- p. 19
(36)
is the variable being transported by the flow, which could be temperature, chemical
species concentration, etc. U is the fluid velocity which, for simplicity, we take as constant.
The fluid density, , and diffusivity of the variable , , are also taken as constants.
b1 c1
0
B
Ba2 b2 c2
B
B0
a3 b3
B
B
B
B.
..
B ..
.
B
B
B
B. . . . . . .
0
B
B
@. . . . . . . . . . . .
0
c3
..
an3
0
....................
where ai = 2x
The term on the left hand side of the equation represents the transport effect of being
convected by the fluid. The right hand side represents the molecular diffusion of .
,
(x)2
bi =
10
1 0
2
CB
C B
. . . . . . . . . . . . . . . . . . . .C B 3 C B
CB
C B
B
B
C
0
. . . . . . . . . . . . C B .. C
C B
CB . C B
CB
C B
.. C B .. C B
..
B
C=B
.
. C
CB . C B
CB
C B
.
CB . C B
B
C B
bn3 cn3
0 C
CB . C B
CB
C B
an2 bn2 cn2 A @n2 A @
............................
an1
2
, ci
(x)2
bn1
U
2x
n1
0
0
..
.
..
.
..
.
0
(x)2
U
2x
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
A
(42)
.
(x)2
This system of equations can be solved by a variety of methods, some of which will be
examined later.
exp(xP e/L) 1
exp(P e) 1
(37)
- p. 20
U x
i1
U x
i+1
1
+
1+
i =
2
2
2
2
i+1
P ex
i1
P ex
=
1
+
1+
2
2
2
2
At P e = 1.5 both the 3 node and 5 node central difference solutions give a good
approximation to the exact result.
At P e = 3 the coarser grid solution (with P ex = 1.5) is becoming less accurate.
(43)
At P e = 10 both solutions with P ex = 2.5 and 5 give negative values of at some nodes.
For a given bulk Peclet number, U L/, as we divide the domain into a larger number of
intervals, the cell Peclet number U x/ decreases.
If we perform two sets of simulations on uniform grids,
one with 3 computational nodes, and one with 5, then
the resulting cell Peclet numbers, P ex , at different bulk
Peclet numbers, P e, are as given in the table.
3 nodes
5 nodes
x
L/2
L/4
At P e = 5 the fine grid solution (with P ex = 1.25) is still satisfactory, but with P ex = 2.5 the
estimated value of at x/L = 0.5 is now negative.
x=0
x=L
x1
x1
x2
x2
x3
P e = 0.5
P e = 1.5
Pe = 3
Pe = 5
P e = 10
0.25
0.125
0.75
0.375
1.5
0.75
2.5
1.25
5
2.5
x3
x4
x5
It can be shown that P ex < 2 is a sufficient condition to ensure the centered difference
scheme does not produce under/overshoots in this problem.
However, this is not a necessary condition. If a non-uniform grid is used large cells with
P ex > 2 can be placed towards the left hand side of the domain (where d/dx is small)
without having an adverse effect on the solution.
Generally, the centered convection scheme will produce under/overshoots when the cell
Peclet number is large and the solution has steep gradients.
(What exactly is large, or steep, can be problem-dependent).
The values of at the nodes can be found by solving equation (43) at each node, and the
results are shown in the following graphs.
- p. 21
- p. 23
Upwinding
A similar set of solutions can be generated using the first order upwind scheme (a backward
difference) for approximating the convective terms. The discretized equation is then
i+1 2i + i1
i i1
(44)
=
U
x
x2
Rearranging leads to
U
U
2
+ i
+ i+1
=0
+
i1
2
2
2
x
x
x
x
x
(45)
i1 (1 + P ex ) + i+1
2 + P ex
(46)
The results of solving these equations on the same grids as those used earlier for the central
difference scheme are also shown in the graphs.
As might be expected, once the grid is reasonably fine (P ex is not too large) the first order
upwind scheme is not as accurate as the second order central difference scheme.
However, the upwind slution is always bounded. Whereas the central difference gives
under/overshoots when the cell Peclet number is large, the upwind scheme does not.
Instead, it appears to underestimate the gradients in .
- p. 22
- p. 24
Numerical Diffusion
As seen in the convection/diffusion example, the first order upwind scheme always returns a
bounded solution. However, it is not particularly accurate.
The Taylor series expansions examined earlier show that
x
x2
i i1
= i
i +
+ O(x3 )
x
2!
3! i
i1 2i + i+1
2x2
=
i + O(x4 )
i +
x2
4!
(47)
(48)
Hence the differential equation actually solved when using the first order upwind scheme is
U
x d2
d
x2 d3
+
2
dx
2! dx
3! dx3
d2
2x2 d4
+
2
dx
4! dx4
+ O(x4 )
(49)
d
=
dx
so
1 = 2
(51)
A quadratic fit through the boundary and two neighbouring points on a uniform grid would
give
31 + 42 3
d
so
1 = (4/3)2 (1/3)3
(52)
dx 1
2x
Note the above expressions both use one-sided differences. Central differences can
sometimes be applied by adding imaginary nodes beyond the domain boundary (see
problem sheet example).
These expressions can then be used to modify the discretized equation at the
near-boundary nodes.
2 1
d
dx 1
x
P ex d2
U x d2
= 1+
+
2
2!
dx
2!
dx2
(50)
The error introduced by the upwind scheme is thus seen to be equivalent to increasing the
diffusivity. The error is thus referred to as diffusive, and generally acts to "smear" the
solution. This tends to exert a stabilizing influence on the numerical solution, although as
can be seen it has an adverse effect on accuracy.
- p. 25
- p. 27
Boundary Conditions
As in the example examined earlier, the form of the difference equation to be solved often
has to be modified at the edges of the domain to account for boundary conditions.
Dirichlet boundary conditions (where the value of
the variable is fixed) can usually be implemented
by simply setting the appropriate value at the
boundary node.
(i,j+1)
x2
2
2
+
= f (x, y)
x2
y 2
xn1 x n
Terms involving this boundary node in the discretized equations at neighbouring nodes can
then be moved to the source term on the right hand side, as was done in the example
earlier. The values of to be solved for are then 2 , 3 ,. . . ,n1 .
Note that if high order schemes with computational stencils covering more than three points
are used, it may be necessary to modify these at the near-boundary nodes (to avoid
referencing non-existent nodes).
Neumann boundary conditions (where the gradient of at the boundary is prescribed) are
typically implemented by using a discretized form of the boundary condition.
(i1,j) (i,j)
(53)
(i,j1)
(55)
an = as = 1/(y)2
(54)
- p. 26
(i+1,j)
ap = ae + aw + an + as
S
Su = fi,j
(56)
- p. 28