Professional Documents
Culture Documents
Discretization PDF
Discretization PDF
Introduction
TPFE MSc CFD-1
◮ In this lecture we consider the process of discretizing the governing
partial differential equations of a fluid flow.
T. J. Craft ◮ There are three broad methods employed for discretizing the governing
George Begg Building, C41 partial differential equations of a fluid flow:
◮ Finite Difference (FD)
◮ Finite Element (FE)
Reading: ◮ Finite Volume (FV)
J. Ferziger, M. Peric, Computational Methods for Fluid
Dynamics ◮ Although there are obvious similarities in the resulting set of discretized
H.K. Versteeg, W. Malalasekara, An Introduction to
Computational Fluid Dynamics: The Finite Volume algebraic equations, the methods employ different approaches to
Method obtaining these. As a result, there can be differences in both the
S.V. Patankar, Numerical Heat Transfer and Fluid Flow accuracy and ease of application of the various methods.
Notes: http://cfd.mace.manchester.ac.uk/tmcfd
- People - T. Craft - Online Teaching Material
Finite Difference Schemes 2010/11 2 / 35
◮ Finite difference schemes can generally be ◮ Finite element approaches are traditionally used in solid mechanics.
applied to regular-shaped domains using These can be adapted to fluid problems, but finite volume schemes tend
body-fitted grids (curved grid lines, following to be the more popular choice in CFD (and are currently used in most, if
domain boundaries). not all, of the major commercial packages).
◮ Large grid distortions need to be avoided, and ◮ We will examine finite volume schemes later. However, to begin with we
the schemes cannot easily be applied to very consider how finite difference schemes can be devised.
complex flow geometry shapes.
◮ Despite not being generally used in industrial codes, finite difference
◮ Finite element and finite volume schemes are both based on dividing the schemes are useful for introducing the ideas of accuracy, truncation error,
flow domain into a (large) number of small cells, or volumes. These can stability and boundedness in a well-defined and fairly transparent way.
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.
Taylor Series Approximation ◮ If we take ∆x as the uniform grid spacing, so ∆x = xi+1 − xi , then we get
the approximation
◮ Taylor series expansions can often be used to develop and/or analyse the f (xi+1 ) − f (xi )
f ′ (xi ) = + O(∆x ) (4)
accuracy of numerical approximations for derivatives. ∆x
which we will write in shorthand form as
◮ Writing a Taylor series expansion to evaluate f at positions x close to xi :
fi+1 − fi
(∆x )2 ′′ (∆x )3 ′′′ fi′ = + O(∆x ) (5)
f (xi + ∆x ) = f (xi ) + ∆xf ′ (xi ) + f (xi ) + f (xi ) + O(∆x 4) (2) ∆x
2! 3!
where fi represents f evaluated at xi , etc.
′
where f denotes the derivative df /dx , f
f (xi + ∆x ) − f (xi )
= + O(∆x ) (3)
∆x ◮ This is a first order scheme, since the error is proportional to ∆x , so
where O(∆x ) means the leading term is proportional to ∆x . decreases linearly with grid spacing.
Finite Difference Schemes 2010/11 7 / 35 Finite Difference Schemes 2010/11 8 / 35
◮ Alternatively, we could use equation (2) to evaluate f at a point xi − ∆x : ◮ We could combine the two Taylor series approximations above:
(∆x )2 ′′ (∆x )3 ′′′ (∆x )2 ′′ (∆x )3 ′′′
f (xi − ∆x ) = f (xi ) − ∆xf ′ (xi ) + f (xi ) − f (xi ) + O(∆x 4) (7) f (xi+1 ) = f (xi ) + ∆xf ′ (xi ) + f (xi ) + f (xi ) + O(∆x 4) (11)
2! 3! 2! 3!
(∆x )2 (∆x )3
◮ Taking ∆x as the grid spacing now leads to f (xi−1 ) = f (xi ) − ∆xf ′ (xi ) + f ′′ (xi ) − f ′′′ (xi ) + O(∆x 4) (12)
2! 3!
(∆x )2 ′′ (∆x )3 ′′′
f (xi−1 ) = f (xi ) − ∆xf ′(xi ) + f (xi ) − f (xi ) + O(∆x 4) (8) ◮ Subtracting one from the other results in
2! 3!
(∆x )3 ′′′
◮ Rearranging leads to the approximation f (xi+1 ) − f (xi−1 ) = 2∆xf ′ (xi ) + 2 f (xi ) + O(∆x 5) (13)
3!
f (xi ) − f (xi−1 ) Rearranging gives the approximation
f ′ (xi ) = + O(∆x ) (9) ◮
∆x
f (xi+1 ) − f (xi−1 )
f ′ (xi ) = + O(∆x 2) (14)
2∆x
◮ This approximation, f
◮ This approximation
f
fi′ ≈ (fi − fi−1 )/∆x (10)
fi′ ≈ (fi+1 − fi−1 )/(2∆x ) (15)
is referred to as a backward differencing
scheme. is referred to as a centred difference. xi-1 xi x i+1
x
x
xi-1 xi
◮ This is a second order approximation, since the error reduces as (∆x )2 : if
◮ It is again a first order scheme. the grid spacing is halved, the error goes down by a factor of 4.
Finite Difference Schemes 2010/11 9 / 35 Finite Difference Schemes 2010/11 10 / 35
Order of Approximation ◮ Note this does not mean 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).
◮ At this point it is worth considering exactly what is meant by the order of
accuracy of a discretization approximation. ◮ It does, however, imply that as we refine the grid the error in the higher
order scheme goes down more rapidly, so we expect the higher order
◮ As we refine the grid, for any useful scheme, errors associated with the scheme to reach a grid independent solution on a coarser grid than
discretization approximation can be expected to reduce. would be required for a lower order scheme.
◮ We reach a grid independent solution when any further grid refinement ◮ It is worth noting that the behaviour described above for a particular
produces no significant difference in the computed solution. At this stage scheme can only be expected on a reasonably fine grid.
the discretization errors are small enough that they can be neglected.
◮ The reason for this can be seen from the Taylor series expansion. For
◮ We have defined the order of a scheme in terms of the leading order error example, in the first order backward difference scheme we have
term in the Taylor series expansion. f −f ∆x ′′ (∆x )2 ′′′
fi′ = i i−1 + f (xi ) − f (xi ) + O(∆x 3) (16)
∆x 2! 3!
◮ This should, therefore, determine at what rate the error reduces as the
grid is refined. If the first term in the truncation is to be the leading error term, then ∆x
has to be small enough so that
◮ For a first order scheme, if the grid spacing is halved the error is halved;
∆x ′′
′′
(∆x )2 ′′′
f (x )
for a second order scheme the error would reduce by a factor of 4. |f (xi )| << |f (xi )| or ∆x << 3 ′′′ i (17)
3! 2! f (xi )
Finite Difference Schemes 2010/11 11 / 35 Finite Difference Schemes 2010/11 12 / 35
Polynomial Approximation ◮ On a uniform grid with xi+1 − xi = xi − xi−1 = ∆x and xi+1 − xi−1 = 2∆x this
becomes
◮ The above approximations for the derivatives could also have been (x − xi )(x − xi+1) (x − xi−1)(x − xi+1) (x − xi )(x − xi−1)
f (x ) = fi−1 − fi + fi+1
derived by fitting a polynomial to the function f through xi and surrounding 2(∆x )2 (∆x )2 2(∆x )2
points and then differentiating this polynomial to get its gradient. (19)
◮ Differentiating with respect to x then gives
◮ The forward and backward difference schemes arise from fitting a first
order polynomial (a straight line) through the points (xi , xi+1 ) and (xi−1 , (x − xi + x − xi+1) (x − xi−1 + x − xi+1) (x − xi + x − xi−1 )
f ′ (x ) = fi−1 − fi + fi+1
xi ) respectively. 2(∆x )2 (∆x )2 2(∆x )2
(20)
and thus
◮ The centred difference scheme can be f
Approximating Higher Order Derivatives ◮ Note the computational stencil (the nodal points used) is now larger,
because we need more points to give information about curvature etc.
◮ Taylor series expansions or polynomial fits can also be used to derive ◮ In many fluids related problems the second derivative that requires
approximations to higher order derivatives. approximation is a diffusion term of the form
∂ ∂f
2 2
◮ For example, to approximate the second derivative d f /dx we could, as Γ (26)
before, write: ∂x ∂x
(∆x )2 ′′ (∆x )3 ′′′ This can be approximated using central f
f (xi+1 ) = f (xi ) + ∆xf (xi ) +
′ ◮
f (xi ) + f (xi ) + O(∆x 4) (22)
2! 3! differences to estimate df /dx at the
(∆x )2 ′′ (∆x )3 ′′′ mid-points xi+1/2 and xi−1/2 , followed by a
f (xi−1 ) = f (xi ) − ∆xf (xi ) +
′
f (xi ) − f (xi ) + O(∆x 4) (23) central difference between these values to
2! 3! x
estimate the second derivative term: xi-1 xi x i+1
◮ Adding the two equations and rearranging now results in x i-1/2
xi+1/2
f (xi+1 ) − 2f (xi ) + f (xi−1 ) df f −f df f −f
′′
f (xi ) = + O((∆x )2 ) (24) ≈ i i−1 ≈ i+1 i (27)
(∆x )2 dx i−1/2
∆x dx i+1/2
∆x
This gives the central difference approximation for the second derivative ∂ ∂f Γi+1/2 (fi+1 − fi ) − Γi−1/2(fi − fi−1 )
◮
Γ ≈ (28)
fi+1 − 2fi + fi−1 ∂x ∂x (∆x )2
fi′′ ≈ (25)
(∆x )2 ◮ Note that interpolation may be required to estimate values of Γ at the
which is again second order accurate when applied on a uniform grid. midpoints xi+1/2 and xi−1/2 .
Finite Difference Schemes 2010/11 15 / 35 Finite Difference Schemes 2010/11 16 / 35
Non-Uniform Grids ◮ Hence we obtain
f (xi+1 ) − f (xi−1 ) f ′′ (xi )
f ′ (xi ) = + (∆xi − ∆xi−1) + O(∆x 2) (32)
◮ In most CFD applications non-uniform grids are employed, allowing the ∆xi + ∆xi+1 2!
grid to be more refined in regions where strong gradients are expected. ◮ Note that formally the central difference fi′ = (fi+1 − fi−1 )/(∆xi + ∆xi−1) is
now only first order accurate.
f
◮ In such a case, the simple forward/backward
differences are clearly still first order. ◮ In practice, one should avoid using rapidly expanding grids, so typically
∆xi = r ∆xi−1 with grid expansion ratio r not too far from unity. The factor
◮ Analysis of the central difference scheme, (∆xi − ∆xi−1 ) = ∆xi (1 − r ) in the leading order error can then still be
however, is a little different. ∆ x i-1 ∆xi x essentially second order.
xi-1 xi xi+1
◮ The discretized form of equations can thus be represented in the ◮ In this case, rearranging equation (39) to solve for φi gives
tri-diagonal matrix form:
φ ρ U∆x φ ρ U∆x
φi = i+1 1 − + i−1 1 +
φ2 2 2Γ 2 2Γ
b1 c1 0 . . . . . . . . . . . . . . . . . . . . . . . . . 0
φ
a2 b2 c2 0 . . . . . . . . . . . . . . . . . . 0 φ φ
Pex Pex
3
= i+1 1 − + i−1 1 + (43)
. .
0 a3 b3 c3 0 . . . . . . . . . . . . ..
2 2 2 2
.
.
where Pex is the cell Peclet number, Pex = ρ U∆x /Γ.
. .. .. .. ... .. = ..
..
. . . .
.
..
..
◮ For a given bulk Peclet number, ρ UL/Γ, as we divide the domain into a
. . . . . . . 0 an−3 bn−3 cn−3 0 .
larger number of intervals, the cell Peclet number ρ U∆x /Γ decreases.
an−2 bn−2 cn−2 φn−2
0
. . . . . . . . . . . .
0
ρU
Γ
.................. 0 an−1 bn−1 φn−1 (∆x ) 2 − 2∆x ◮ For uniform grids with 3 gnd 5 grid nodes, the x=0 x=L
(42) cell Peclet numbers, Pex , at different bulk x1 x2 x3
ρU ρU
where ai = − 2∆x − (∆xΓ )2 , bi = (∆x 2Γ
)2
, ci = 2∆x − (∆xΓ )2 . Peclet numbers, Pe, are given in the table. x1 x2 x3 x4 x5
◮ This system of equations can be solved by a variety of methods, some of ∆x Pe = 0.5 Pe = 1.5 Pe = 3 Pe = 5 Pe = 10
which will be examined later. 3 nodes L/2 0.25 0.75 1.5 2.5 5
5 nodes L/4 0.125 0.375 0.75 1.25 2.5
◮ 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.
Finite Difference Schemes 2010/11 23 / 35 Finite Difference Schemes 2010/11 24 / 35
◮ At Pe = 1.5 both the 3 node and 5 node central difference solutions give
a good approximation to the exact result.
◮ At Pe = 5 the finer grid solution (with Pex = 1.25) is still satisfactory, but
with Pex = 2.5 the estimated value of φ at x /L = 0.5 is now negative.
◮ It can be shown that Pex < 2 is a sufficient condition to ensure the centred
difference scheme does not produce under/overshoots in this problem.
◮ Rearranging leads to
ρU Γ ρU Γ
2Γ
φi−1 − − + φi + + φi+1 − 2 = 0 (45)
∆x ∆x 2 ∆x ∆x 2 ∆x
and introducing the cell Peclet number, Pex , results in
φi−1 (1 + Pex ) + φi+1
φi = (46)
2 + Pex
◮ 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.
Finite Difference Schemes 2010/11 27 / 35 Finite Difference Schemes 2010/11 28 / 35
◮ As might be expected, once the grid is reasonably fine (Pex not too large) Numerical Diffusion
the first order upwind solution is not as accurate as the second order
central difference one. ◮ As seen in the above example, the first order upwind scheme always
returns a bounded solution. However, it is not particularly accurate.
◮ However, the upwind solution is always bounded.
◮ The Taylor series expansions examined earlier show that
◮ Whereas the central difference gives under/overshoots when the cell
Peclet number is large, the upwind scheme does not. Instead, it appears φi − φi−1 ∆x ′′ ∆x 2 ′′′
to underestimate the gradients in φ . = φi′ − φ + φ + O(∆x 3) (47)
∆x 2! i 3! i
φi−1 − 2φi + φi+1 2∆x 2 ′′′′
= φi′′ + φ + O(∆x 4) (48)
∆x 2 4! i
◮ Hence the differential equation actually being solved when using the first
order upwind scheme is
d φ ∆x d 2 φ ∆x 2 d 3 φ d φ 2∆x 2 d 4 φ
2
ρU − + =Γ + + O(∆x 4 ) (49)
dx 2! dx 2 3! dx 3 dx 2 4! dx 4
◮ If we retain only leading order error terms, this can be written as Boundary Conditions
dφ ρ U∆x d 2 φ Pex d 2 φ
ρU = Γ+ = Γ 1+ (50) ◮ As in the example examined earlier, the form of the difference equation to
dx 2! dx 2 2! dx 2
be solved often has to be modified at the edges of the domain to account
for boundary conditions.
◮ The error introduced by the upwind scheme is seen to be equivalent to
increasing the diffusivity.
◮ Dirichlet boundary conditions (where the
◮ The error is thus referred to as diffusive, and generally acts to ”smear” the value of the variable is fixed) can usually
x1 x2 xn−1 x n
solution. This tends to exert a stabilizing influence on the numerical be implemented by simply setting the
solution, although as seen it has an adverse effect on accuracy. appropriate value at the boundary node.
ap φP = ae φE + aw φW + an φN + as φS + Su (55) W P E
2 2
ae = aw = 1/(∆x ) an = as = 1/(∆y )
ap = ae + aw + an + as Su = −fi,j