Lecture Series on CFD - I
Based on: Sponsored by: Presented by:
Milovan Perić
Lecture 4
Introduction to Finite-Difference
(FD) Methods
milovan@[Link]
[Link]
Contents 3
• Principles of finite-difference (FD) methodology
• Approximation of derivatives using Taylor series expansion
• Approximation of derivatives based on polynomial fitting
• First- and second-order approximations of the 1st and 2nd derivative
• Approximations of derivatives on non-uniform grids
• Numerical experiments: Checking the order of approximations
Basic FD Concepts 4
• FD is the oldest numerical method for solving PDEs (Euler, 18th century)…
• Starting point – conservation equation in differential form, e.g. steady-state scalar
transport by convection and diffusion:
• FD is usually applied on structured or block-structured grids…
• It requires approximation of derivatives in terms of variable values at grid nodes…
• For each grid node, one algebraic equation is obtained, in which variable value at
that node and values at some neighbor nodes are unknowns…
• For the whole solution domain, a system of algebraic equations needs to be solved.
FD Grids 5
• Structured Cartesian grids (1D, 2D) with lexicographic ordering of nodes:
Black symbols:
Boundary nodes (where
boundary conditions are
applied);
Open symbols:
Internal nodes, where
equations are discretized.
Intuitive Approximations of 1st Derivative 6
• Mathematical definition of 1st derivative, geometric interpretation, and three intuitive
approximations:
A sketch of variable variation in one
dimension: the exact derivative and
three approximations at node i.
Observations:
Central is closer to Exact than
Forward or Backward;
Each approximation becomes better
when grid spacing is reduced…
Taylor Series Expansion Approach – I 7
• Variation of around node i can be described by Taylor series expansion:
H: Higher-order terms
• From this expression for x = xi+1, one obtains:
Blue: Approximation
• For x = xi-1, we have: Red: Truncation error
Taylor Series Expansion Approach – II 8
• By subtracting the expression for x = xi–1 from expression for x = xi+1, one obtains:
• These expressions are exact, if all terms on the r.h.s. are retained…
• Because higher-order derivatives are unknown, only the blue-framed part can be used
as an approximation of the 1st derivative at node i.
• The red-framed part is called truncation error; the leading term is usually the largest.
• The exponent of mesh spacing in the leading term represents the order of
approximation.
• By using expressions written for more grid points around x = xi , one can eliminate one
or more leading terms in the truncation error (one term per additional node)…
Taylor Series Expansion Approach – III 9
• The three approximations and their leading truncation error terms are:
− Forward difference (FD): ;
− Backward difference (BD): ;
− Central difference (CD): ;
• FD and BD are 1st-order schemes, because is proportional to x.
• The leading truncation error term for CD becomes zero on uniform grids – the next one
is proportional to (x)2 – 2nd-order…
Polynomial Fitting - I 10
• Approximations of derivatives can be also obtained by assuming a certain variation of
the variable (polynomial fitting)…
• Example: Fit a parabola to variable values at three nodes, setting a local coordinate
system origin at node i. For a constant spacing:
Three equations for 3
coefficients (a0, a1 and a2)
Polynomial Fitting - II 11
• Add 2nd and 3rd equation:
• It is now easy to obtain the remaining coefficient:
• The 1st and the 2nd derivative at node i are then:
Non-Uniform Grids – I 12
• Fitting a parabola to three nodes on a non-uniform grid leads to:
where
• It will be shown in an exercise in Lecture 6 that this is a 2nd-order approximation on
both uniform and non-uniform grids.
• Non-uniform grids are used to achieve a more uniform distribution of errors – by using
larger spacing where discretization errors are small.
• Many approximations loose the first term in truncation error when the grid is uniform…
• The question: Is the order of approximation really lower when the grid is non-uniform
(as it formally appears to be)?
Non-Uniform Grids – II 13
• Consider the truncation error of the central-difference approximation:
where
• The leading truncation error term can be re-written as:
where
re – constant expansion factor
Non-Uniform Grids – III 14
• The ratio of leading truncation error terms from two grids at the same node i is:
• On a grid with a constant expansion factor, the following relations hold:
and
• Under these conditions, the above ratio becomes:
4 → 2nd-order convergence!
Approximation of 2nd Derivative – I 15
• Apply differentiation twice, using methods for 1st derivative…
• Choose approximations for each step (they may be different, e.g. first FD, then BD):
• The result is:
• This is a second-order approximation – the leading error terms from backward and
forward approximations cancel out…
Approximation of 2nd Derivative – II 16
• Using central-difference approximations in both steps leads to an approximation that
involves 5 nodes, from i–2 to i+2.
• Compact central-difference approximations can be applied using an imaginary twice
finer grid:
;
i −½ i+½
i−1 i i+1
Approximation of 2nd Derivative – III 17
• From Taylor-series expansion at i–1 and i+1 one obtains:
• It is the same approximation as in the previous slide, but with the leading term in
truncation error.
• The leading term becomes zero on uniform grids, but on non-uniform grids, the ratio of
truncation errors on two systematically refined grids is the same as for the 1 st derivative:
4 → 2nd-order convergence!
See slides 13 & 14
for derivation!
Approximation of Diffusion Term – I 18
• When fluid properties are not constant, the diffusion term in the conservation equation
involves the derivation of a product of two variables, which can be performed by parts:
• This term can be approximated at grid point i using any approximation for 1st and 2nd
derivative:
• It is desirable to use approximations of the same order for each term!
Approximation of Diffusion Term – II 19
• Another option is a two-step approximation described in slide 16:
• Approximations of inner derivatives are of 2nd order because the auxiliary points are
midway between grid nodes.
• The approximation of the outer derivative has a first-order leading term in the truncation
error, but it converges with 2nd order also on uniform grids, as shown in slides 13 & 14.
i −½ i+½
i−1 i i+1
Numerical Experiments to Check the Order of Approximations 20
• The order of approximation can be tested by computing
approximations of derivatives at a given point using
systematically refined grids and variable values at grid
points taken from an analytical function.
• The following function is used here: = cos(3.2(x− 0.1)).
• Discretization errors are obtained by comparing
approximations with the exact values of the derivatives,
= − 3.2 sin(3.2(x− 0.1)), = − 3.22 sin(3.2(x− 0.1)).
• We check first the backward, forward and central f(x) = cos(3.2*(x-0.1))
fp(x) = -3.2*sin(3.2*(x-0.1))
difference approximations for on uniform grids…
fpbd=(f(zero)-f(-dx))/dx
fpfd=(f(dx)-f(zero))/dx
fpcd=(f(dx)-f(-dx))/(2.0*dx)
Approximations of 1st Derivative, Uniform Grids 21
Slope 1
Slope 2
BD and FD approach the exact value from different sides, but the errors are almost the same.
CD is much more accurate – its error is ca. 2 orders of magnitude lower than BD and FD error…
Approximations of 1st Derivative, Non-Uniform Grids 22
Slope 1
Slope 2
Expansion factor on the coarsest grid: re = sqrt(2). The
simple CD-approximation converges with 2nd order on
• • • both uniform and non-uniform grids (see slide 13).
Approximations of 2nd Derivative 23
Slope 2
Expansion factor on the coarsest non-uniform grid:
re = sqrt(2). The simple CD-approximation converges to a
• • • wrong value on non-uniform grids. The approximation based
on parabola-fit converges with 2nd order on non-uniform grids.
Approximations of Diffusion Term 24
= 0 (1 + 0.1x); 0 = 1.0
Slope 2
Both differentiation by parts and differentiation of the product
• • • converge with 2nd order on both uniform and non-uniform
grids when appropriate CD-approximations are used.
Summary 25
• FD-approximations of 1st and 2nd derivative can be obtained using
− Taylor series expansion, or
− Polynomial fitting.
• Taylor series expansion is always used to determine the truncation error of an
approximation, from which the order of approximation can be derived.
• The order tells us at what rate is the error reducing when the grid is refined – not how
large the error on a given grid is.
• Methods of the same order can have errors that differ by as much as an order of
magnitude!
• Some approximations contain a 1st-order term in the truncation error when the grid is
non-uniform, but the errors are still reducing with 2nd order on systematically refined
grids.
The PowerPoint presentation file is available at the following link within Siemens Community environment:
[Link]