8.2 Finite Difference, Finite Element and Finite Volume Methods For Partial Differential Equations
8.2 Finite Difference, Finite Element and Finite Volume Methods For Partial Differential Equations
8.2 Finite Difference, Finite Element and Finite Volume Methods For Partial Differential Equations
2
FINITE DIFFERENCE, FINITE ELEMENT
AND FINITE VOLUME METHODS
FOR PARTIAL DIFFERENTIAL
EQUATIONS
which is referred to as the integral form of the conservation law. For a fixed
(independent of t) volume and, under suitable conditions of smoothness of the
intervening quantities, we can apply Gauss’ theorem
∇ · f dV = f · n dA
V A
to obtain
∂u
+ ∇ · f (u) − S dV = 0. (2)
∂t
V
For the integral expression to be zero for any volume V , the integrand must be
zero. This results in the strong or differential form of the equation
∂u
+ ∇ · f (u) − S = 0. (3)
∂t
An alternative integral form can be obtained by the method of weighted
residuals. Multiplying Eq. (3) by a weight function w(x) and integrating over
the volume V we obtain
∂u
+ ∇ · f (u) − S w(x) dV = 0. (4)
∂t
V
If Eq. (4) is satisfied for any weight function w(x), then Eq. (4) is equivalent
to the differential form (3). The smoothness requirements on f can be relaxed
by applying the Gauss’ theorem to Eq. (4) to obtain
∂u
− S w(x) − f (u) · ∇w(x) dV + f · n w(x) dA = 0.
∂t
V A
(5)
This equation is elliptic and its solution depends on two families of integration
constants that are fixed by prescribing boundary conditions at the ends of the
domain. One can either prescribe Dirichlet boundary conditions at both ends,
e.g., u(0) = α0 and u(1) = α1 , or substitute one of them (or both if r =/ 0) by a
Neumann boundary condition, e.g., u x (0) = g. Here α0 , α1 and g are known
constant values. We note that if we introduce a perturbation into a Dirichlet
boundary condition, e.g., u(0) = α0 + , we will observe an instantaneous
modification to the solution throughout the domain. This is indicative of the
elliptic nature of the problem.
u t − (b u x )x = 0, (8)
u(x, t) = Am eβm t sin km x,
m
where Am and km represent the amplitude and the frequency of a Fourier mode,
respectively. The decay of the solution depends on the Fourier contents of the
initial data since βm = −km2 b. High frequencies decay at a faster rate than the
low frequencies which physically means that the solution is being smoothed.
This is illustrated in Fig. 1 which shows the time evolution of u(x, t) for
an initial condition u 0 (x) = 20x for 0 ≤ x ≤ 1/2 and u 0 (x) = 20(1 − x) for
1/2 ≤ x ≤ 1. The solution shows a rapid smoothing of the slope disconti-
nuity of the initial condition at x = 1/2. The presence of a positive diffusion
(b > 0) physically results in a smoothing of the solution which stabilizes it. On
the other hand, negative diffusion (b < 0) is de-stabilizing but most physical
problems have positive diffusion.
6 J. Peiró and S. Sherwin
11
u(x)
10
t0
9
t T
8
t 2T
7
t 3T
6
t 4T
5
t 5T
4
t 6T
3
2
1
0
0.0 0.5 1.0
x
u t + a u x = 0, (9)
u (x,t ) Characteristic
x at c
t
u (x,0 ) x
3. Numerical Schemes
There are many situations where obtaining an exact solution of a PDE is
not possible and we have to resort to approximations in which the infinite set
of values in the continuous solution is represented by a finite set of values
referred to as the discrete solution.
For simplicity we consider first the case of a function of one variable u(x).
Given a set of points xi ; i = 1, . . . , N in the domain of definition of u(x), as
8 J. Peiró and S. Sherwin
t3
t2
u
u>0 t1
x
t 0
u 0
ui
ui 1
ui 1
x
x1 xi 1 xi xi 1 xn
Ωi
xi 12 xi 12
The underlined term is called the remainder with xi ≤ x ∗ ≤ xi+1 , and repre-
sents the error in the approximation if only the first n terms in the expansion
are kept. Although the expression (15) is exact, the position x ∗ is unknown.
10 J. Peiró and S. Sherwin
1e 00
Backward FD Total Error
Backward FD Truncation Error
Centred FD Total Error
1e 02 Centred FD Truncation Error
1e 04
1
1e 06
1
ε 2
1e 08
1
1e 10
1e 12
1e 14
1e 00 1e 02 1e 04 1e 06 1e 08 1e 10 1e 12
∆x
Figure 5. Truncation and rounding errors in the finite difference approximation of derivatives.
αu i+1 + βu i + γ u i−1
u x |i ≈ . (21)
x
Using Taylor expansions around xi we can write
x 2 x 3
u i+1 = u i + x u x |i + u x x |i + u x x x |i + · · · (22)
2 6
x 2 x 3
u i−1 = u i − x u x |i + u x x |i − u x x x |i + · · · (23)
2 6
12 J. Peiró and S. Sherwin
αu i+1 + βu i + γ u i−1 1
= (α + β + γ ) u i + (α − γ ) u x |i
x x
x x 2
+ (α + γ ) u x x |i + (α − γ ) u x x x |i
2 6
x 3
+ (α + γ ) u x x x x |i + O(x 4 ) (24)
12
u i+1 − u i−1
u x |i = + O(x 2 ).
2x
αu i+1 + βu i + γ u i−1 1 1
= (α + β + γ ) 2 u i + (α − γ ) u x |i
x 2 x x
1 x
+ (α + γ ) u x x |i + (α − γ ) u x x x |i
2 6
x 2
+ (α + γ ) u x x x x |i + O(x 4 ). (25)
12
Finite methods for partial differential equations 13
In this section we seek to approximate the values of u(x) and its derivatives
by a polynomial P(x) at a given point xi . As way of an example we will
derive similar expressions to the centred differences presented previously by
considering an approximation involving the set of points {xi−1 , xi , xi+1 } and
the corresponding values {u i−1 , u i , u i+1 }. The polynomial of minimum degree
that satisfies P(xi−1 ) = u i−1 , P(xi ) = u i and P(xi+1 ) = u i+1 is the quadratic
Lagrange polynomial
(x − xi )(x − xi+1 ) (x − xi−1 )(x − xi+1 )
P(x) = u i−1 + ui
(xi−1 − xi )(xi−1 − xi+1 ) (xi − xi−1 )(xi − xi+1 )
(x − xi−1 )(x − xi )
+ u i+1 . (28)
(xi+1 − xi−1 )(xi+1 − xi )
We can now obtain an approximation of the derivative, u x |i ≈ Px (xi ) as
(xi − xi+1 ) (xi − xi−1 ) + (xi − xi+1 )
Px (xi ) = u i−1 + ui
(xi−1 − xi )(xi−1 − xi+1 ) (xi − xi−1 )(xi − xi+1 )
(xi − xi−1 )
+ u i+1 . (29)
(xi+1 − xi−1 )(xi+1 − xi )
If we take xi − xi−1 = xi+1 − xi = x, we recover the second-order accu-
rate finite difference approximation (14) which is consistent with a quadratic
14 J. Peiró and S. Sherwin
u N − u N −1
u x (1) ≈ = g. (32)
x
This expression is only first-order accurate and thus inconsistent with the
approximation used at the interior points. Given that the PDE is elliptic, this
error could potentially reduce the global accuracy of the solution. The alterna-
tive is to use a second-order centred approximation
u N +1 − u N −1
u x (1) ≈ = g. (33)
x
Here the value u N +1 is not available since it is not part of our discrete set of
values but we could use the finite difference approximation at x N given by
u N +1 − 2u N + u N −1
= sN
x 2
1
u N − u N −1 = (gx − s N x 2 ). (34)
2
It is easy to verify that the introduction of either of the Neumann boundary
conditions (32) or (34) leads to non-symmetric matrices.
u t − bu x x = s(x) in = {x, t : 0 ≤ x ≤ 1, 0 ≤ t ≤ T }
In this technique we assign to our mesh a set of values that are functions
of time u i (t) = u(xi , t); i = 1, . . . , N . Applying a centred discretization to
the spatial derivative of u leads to a system of ordinary differential equations
(ODEs) in the variable t given by
du i b
= 2 {u i−1 (t) − 2u i (t) + u i+1 (t)} + si ; i = 2, . . . , N − 1
dt x
with u 1 = α1 (t) and u N = α2 (t). This can be written as
bα1 (t)
s2 +
u2 −2 1 u2
x 2
u3 1 −2 1
d b u3 s3
.. .. .. .. . ..
. = . . . .. + .
dt x 2
u N −2 1 −2 1 u N −2
s N −2
u N −1 1 −2 u bα2 (t)
N −1
s N −1 +
x 2
or in matrix form as
du
(t) = A u(t) + s(t). (35)
dt
Equation (35) is referred to as the semi-discrete form or the method of lines.
This system can be solved by any method for the integration of initial-value
problems [3]. The numerical stability of time integration schemes depends on
the eigenvalues of the matrix A which results from the space discretization.
For this example, the eigenvalues vary between 0 and −(4α/x 2 ) and this
could make the system very stiff, i.e., with large differences in eigenvalues, as
x → 0.
This scheme is explicit as the values of the solution at time t n+1 are obtained
directly from the corresponding (known) values at time t n . If we use backward
differences in time, the resulting scheme is
u in+1 − u in b n+1
= u − 2u n+1
+ u n+1
. (37)
t x 2 i−1 i i+1
Here to obtain the values at t n+1 we must solve a tri-diagonal system of equa-
tions. This type of schemes are referred to as implicit schemes.
The higher cost of the implicit schemes is compensated by a greater numer-
ical stability with respect to the explicit schemes which are stable in general
only for some combinations of x and t.
The FDM uses the strong or differential form of the governing equations.
In the following, we introduce two alternative methods that use their integral
form counterparts: the finite element and the finite volume methods. The use
of integral formulations is advantageous as it provides a more natural treat-
ment of Neumann boundary conditions as well as that of discontinuous source
terms due to their reduced requirements on the regularity or smoothness of the
solution. Moreover, they are better suited than the FDM to deal with complex
geometries in multi-dimensional problems as the integral formulations do not
rely in any special mesh structure.
18 J. Peiró and S. Sherwin
These methods use the integral form of the equation as the starting point
of the discretization process. For example, if the strong form of the PDE is
L(u) = s, the integral from is given by
1 1
L(u)w(x) dx = sw(x) dx (38)
0 0
where the choice of the weight function w(x) defines the type of scheme.
where the set of functions Ni (x) is known as the expansion basis. Its support
is defined as the set of points where Ni (x) =/ 0. If the support of Ni (x) is the
whole interval, the method is called a spectral method. In the following we will
use expansion bases with compact support which are piecewise continuous
polynomials within each element as shown in Fig. 6.
The global shape functions Ni (x) can be split within an element into two
local contributions of the form shown in Fig. 7. These individual functions are
referred to as the shape functions or trial functions.
In the Galerkin FEM method we set the weight function w(x) in Eq. (38)
to be the same as the basis function Ni (x), i.e., w(x) = Ni (x).
Consider again the elliptic equation L(u) = u x x = s(x) in the region with
boundary conditions u(0) = α and u x (1) = g. Equation (38) becomes
1 1
w(x)u x x dx = w(x)s(x) dx.
0 0
At this stage, it is convenient to integrate the left-hand side by parts to get the
weak form
1 1
− wx u x dx + w(1) u x (1) − w(0) u x (0) = w(x) s(x) dx. (39)
0 0
Finite methods for partial differential equations 19
ui 1 ui
u1 ui 1
Ωi uN
x
x1 xi 1 xi xi 1 xN
u1 x 1
x
..
.
Ni (x)
ui x 1
x
..
.
uN x 1
x
N
Figure 6. A piecewise linear approximation u δ (x, t) = i=1 u i (t)Ni (x).
ui
ui 1 Ni Ni 1
Ωi ui 1 ui 1 1
xi x i 1 xi x i 1 x x i 1
matrices, unlike the FDM. The Dirichlet boundary condition u(0) = α can be
applied by imposing u 1 = α and requiring that w(0) = 0. In general, we will
impose that the weight functions
w(x) are zero at the Dirichlet boundaries.
Letting u(x) ≈ u δ (x) = Nj=1 u j N j (x) and w(x) = Ni (x) then Eq. (39) be-
comes
1 N 1
dNi dN j
− (x) uj (x) dx = Ni (x) s(x) dx (40)
dx j =1
dx
0 0
= Ni s dx + Ni s dx (41)
xi−1 xi
can be evaluated using a simple integration rule like the trapezium rule
xi+1
g(xi ) + g(xi+1 )
g(x) dx ≈ xi
2
xi
Finite methods for partial differential equations 21
and it becomes
xi−1 xi
F= + si .
2 2
Performing the required operations in the left-hand side of Eq. (41) and includ-
ing the calculated valued of F leads to the FEM discrete form of the equation
as
u i − u i−1 u i+1 − u i xi−1 + xi
− + = si .
xi−1 xi 2
u t dx + f x (u) dx = 0. (42)
xi−(1/2) xi−(1/2)
This expression could also been obtained from the weighted residual form (4)
by selecting a weight w(x) such that w(x) = 1 for xi−(1/2) ≤ x ≤ xi+(1/2) and
w(x) = 0 elsewhere. The last term in Eq. (42) can be evaluated analytically to
obtain
xi+(1/2)
f x (u) dx = f u i+(1/2) − f u i−(1/2)
xi−(1/2)
22 J. Peiró and S. Sherwin
and if we approximate the first integral using the mid-point rule we finally
have the semi-discrete form
u t |i xi+(1/2) − xi−(1/2) + f u i+(1/2) − f u i−(1/2) = 0.
This approach produces a conservative scheme if the flux on the boundary
of one cell equals the flux on the boundary of the adjacent cell. Conservative
schemes are popular for the discretization of hyperbolic equations since, if
they converge, they can be proven (Lax-Wendroff theorem) to converge to a
weak solution of the conservation law.
u x x dx = s dx.
xi−(1/2) xi−(1/2)
Evaluating exactly the left-hand side and approximating the right-hand side by
the mid-point rule we obtain
u x xi+(1/2) − u x xi−(1/2) = xi+(1/2) − xi−(1/2) si . (43)
If we approximate u(x) as a linear function between the mesh points i − 1 and
i, we have
u i − u i−1 u i+1 − u i
u x |i−(1/2) ≈ , u x |i+(1/2) ≈ ,
xi − xi−1 xi+1 − xi
and introducing these approximations into Eq. (43) we now have
u i+1 − u i u i − u i−1
− = (xi+(1/2) − xi−(1/2) ) si .
xi+1 − xi xi − xi−1
If the mesh is equispaced then this equation reduces to
u i+1 − 2u i + u i−1
= x si ,
x
which is the same as the FDM and FEM on an equispaced mesh.
Once again we see the similarities that exist between these methods
although some assumptions in the construction of the FVM have been made.
FEM and FVM allow a more general approach to non-equispaced meshes
(although this can also be done in the FDM). In two and three dimensions,
curvature is more naturally dealt with in the FVM and FEM due to the integral
nature of the equations used.
Finite methods for partial differential equations 23
(a) (b)
1 1 1 1
0 0 0 0
1 1 1 1
1 1 1 1
0 0 0 0
1 1 1 1
1 1 1 1
0 0 0 0
1 1 1 1
Figure 8. Shape of the fifth order ( p = 5) polynomial expansions typically used in (a) spectral
element and (b) p-type finite element methods.
24 J. Peiró and S. Sherwin
involved to implement, the advantage is that for a smooth problem (i.e., one
where the derivatives of the solution are well behaved) the computational cost
increases algebraically whilst the error decreases exponentially fast. Further
details on these methods can be found in Refs. [5, 6].
5. Numerical Difficulties
(a) (b)
0.3 0.3
t0.20 t0.20
t0.24 t0.24
t0.28 t0.28
t0.32 t0.32
0.2 0.2
0.1 0.1
u(x,t)
u(x,t)
0 0
0.1 0.1
0.2 0.2
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x
Figure 9. Solution to the diffusion equation u t + u x x = 0 using a forward in time and centred
in space finite difference discretization with x = 0.1 and (a) t = 0.004, and (b) t = 0.008.
The numerical solution in (b) is clearly unstable.
Finite methods for partial differential equations 25
u(x,t)
a
0
x ≤ −0.2 1.0
1 + 5x −0.2 ≤ x ≤ 0
u(x, 0) =
1 − 5x 0 ≤ x ≤ 0.2
0.0
0 x ≥ 0.2 x
0.2 0.2
Figure 10. A triangular wave as initial condition for the advection equation.
u in+1 − u in u n − u i−1
n
σ n
+ a i+1 =0 ⇒ u in+1 = u in − (u − u i−1
n
)
t 2x 2 i+1
(46)
where σ = (at/x) is known as the Courant number. We will see later that
this number plays an important role in the stability of hyperbolic equations.
Let us obtain the solution of u t + au x = 0 for all these schemes with the initial
condition given in Fig. 10.
As also indicated in Fig. 10, the exact solution is the propagation of this
wave form to the right at a velocity a. Now we consider the solution of the
three schemes at two different Courant numbers given by σ = 0.5 and 1.5. The
results are presented in Fig. 11 and we observe that only the upwinded scheme
when σ ≤ 1 gives a stable, although diffusive, solution. The centred scheme
when σ = 0.5 appears almost stable but the oscillations grow in time leading
to an unstable solution.
6.1. Consistency
A numerical scheme is consistent if the discrete numerical equation tends
to the exact differential equation as the mesh size (represented by x and t)
tends to zero.
26 J. Peiró and S. Sherwin
1 3
0.9
2
0.8
0.7
1
0.6
u(x,t)
u(x,t)
0.5 0
0.4
1
0.3
0.2
2
0.1
0 3
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
σ 0.5 σ 1.5
1 30
20
2
10
1
0
u(x,t)
0
10
u(x,t)
1
20
2 30
3 40
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
x x
σ 0.5 σ 1.5
1.2 3
1
2
0.8
1
0.6
0.4 0
u(x,t)
u(x,t)
0.2
1
0
2
0.2
3
0.4
0.6 4
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
x x
σ 0.5 σ 1.5
Figure 11. Numerical solution of the advection equation u t + au x = 0. Dashed lines: initial
condition. Dotted lines: exact solution. Solid line: numerical solution.
Consider the centred in space and forward in time finite diference approxi-
mation to the linear advection equation u t + au x = 0 given by Eq. (46). Let us
consider Taylor expansions of u in+1 , u i+1
n n
and u i−1 around (xi , t n ) as
t 2
u in+1 = u in + t u t |in + u tt |in + · · ·
2
Finite methods for partial differential equations 27
x 2 x 3
n
u i+1 = u in + x u x |in + u x x |in + u x x x |in + · · ·
2 6
x 2 x 3
n
u i−1 = u in − x u x |in + u x x |in − u x x x |in + · · ·
2 6
Substituting these expansions into Eq. (46) and suitably re-arranging the terms
we find that
u in+1 − u in u n − u i−1n
+ a i+1 − (u t + au x )|in = T (47)
t 2x
where T is known as the truncation error of the approximation and is
given by
t x 2
T = u tt |in + au x x x |in + O(t 2 , x 4 ).
2 6
The left-hand side of this equation will tend to zero as t and x tend to zero.
This means that the numerical scheme (46) tends to the exact equation at point
xi and time level t n and therefore this approximation is consistent.
6.2. Stability
(a) (b)
t ∆x t ∆x
Characteristic a∆t
P P
a∆t
∆t
∆t
x x
Q Q
Figure 12. Solution of the advection equation by the upwind scheme. Physical and numerical
domains of dependence: (a) σ = (at/x) > 1, (b) σ ≤ 1.
∞
u(x, t) = eβm t e I km x
m=−∞
u(x, t) = eβm t e I km x .
Finite methods for partial differential equations 29
The term e I km ix = cos(km ix) + I sin(km ix) is bounded and, therefore, any
growth in the numerical solution will arise from the term G = eβm t , known
as the amplification factor. Therefore the numerical method will be stable, or
the numerical solution u in bounded as n → ∞, if |G| ≤ 1 for solutions of the
form
u in = G n e I km ix .
We will now proceed to analyse, using the von Neummann method, the stabil-
ity of some of the schemes discussed in the previous sections.
Example 1 Consider the explicit scheme (36) for the diffusion equation
u t − bu x x = 0 expressed here as
bt
u in+1 = λu i−1
n
+ (1 − 2λ)u in + λu i+1
n
; λ= .
x 2
We assume u in = G n e I km ix and substitute in the equation to get
G = 1 + 2λ [cos(km x) − 1] .
and t based on the accuracy of the solution. The choice between an explicit
or an implicit method is not always obvious and should be done based on the
computer cost for achieving the required accuracy in a given problem.
Example 3 Consider the upwind scheme for the linear advection equa-
tion u t + au x = 0 with a > 0 given by
at
u in+1 = (1 − σ )u in + σ u i−1
n
; σ= .
x
Let us denote βm = km x and introduce the discrete Fourier expression in the
upwind scheme to obtain
G = (1 − σ ) + σ e−Iβm
ξ = 1 − σ + σ cos βm ; η = −σ sin βm
1 λ
1
G
λ ξ
The basics of the FDM are presented a very accessible form in Ref. [7].
More modern references are Refs. [8, 9].
An elementary introduction to the FVM can be consulted in the book by
Versteeg and Malalasekera [10]. An in-depth treatment of the topic with an
emphasis on hyperbolic problems can be found in the book by Leveque [2].
Two well established general references for the FEM are the books of
Hughes [4] and Zienkiewicz and Taylor [11]. A presentation from the point
of view of structural analysis can be consulted in Cook et al. [11]
The application of p-type finite element for structural mechanics is dealt
with in book of Szabo and Babus̆ka [5]. The treatment of both p-type and spec-
tral element methods in fluid mechanics can be found in book by Karniadakis
and Sherwin [6].
A comprehensive reference covering both FDM, FVM and FEM for fluid
dynamics is the book by Hirsch [13]. These topics are also presented using a
more mathematical perspective in the classical book by Quarteroni and Valli
[14].
32 J. Peiró and S. Sherwin
References
[1] J. Bonet and R. Wood, Nonlinear Continuum Mechanics for Finite Element Analysis.
Cambridge University Press, 1997.
[2] R. Leveque, Finite Volume Methods for Hyperbolic Problems, Cambridge University
Press, 2002.
[3] W. Cheney and D. Kincaid, Numerical Mathematics and Computing, 4th edn.,
Brooks/Cole Publishing Co., 1999.
[4] T. Hughes, The Finite Element Method: Linear Static and Dynamic Finite Element
Analysis, Dover Publishers, 2000.
[5] B. Szabo and I. Babus̆ka, Finite Element Analysis, Wiley, 1991.
[6] G.E. Karniadakis and S. Sherwin, Spectral/hp Element Methods for CFD, Oxford
University Press, 1999.
[7] G. Smith, Numerical Solution of Partial Differential Equations: Finite Diference
Methods, Oxford University Press, 1985.
[8] K. Morton and D. Mayers, Numerical Solution of Partial Differential Equations,
Cambridge University Press, 1994.
[9] J. Thomas, Numerical Partial Differential Equations: Finite Difference Methods,
Springer-Verlag, 1995.
[10] H. Versteeg and W. Malalasekera, An Introduction to Computational Fluid Dynam-
ics. The Finite Volume Method, Longman Scientific & Technical, 1995.
[11] O. Zienkiewicz and R. Taylor, The Finite Element Method: The Basis, vol. 1, Butter-
worth and Heinemann, 2000.
[12] R. Cook, D. Malkus, and M. Plesha, Concepts and Applications of Finite Element
Analysis, Wiley, 2001.
[13] C. Hirsch, Numerical Computation of Internal and External Flows, vol. 1, Wiley,
1988.
[14] A. Quarteroni and A. Valli, Numerical Approximation of Partial Differential Equa-
tions, Springer-Verlag, 1994.