Jonathan Whiteley Auth. Finite Element Methods A Practical Guide
Jonathan Whiteley Auth. Finite Element Methods A Practical Guide
Jonathan Whiteley Auth. Finite Element Methods A Practical Guide
JonathanWhiteley
Finite
Element
Methods
A Practical Guide
Mathematical Engineering
Series editors
Jrg Schrder, Essen, Germany
Bernhard Weigand, Stuttgart, Germany
Today, the development of high-tech systems is unthinkable without mathematical
modeling and analysis of system behavior. As such, many elds in the modern
engineering sciences (e.g. control engineering, communications engineering,
mechanical engineering, and robotics) call for sophisticated mathematical methods
in order to solve the tasks at hand.
The series Mathematical Engineering presents new or heretofore little-known
methods to support engineers in nding suitable answers to their questions,
presenting those methods in such manner as to make them ideally comprehensible
and applicable in practice.
Therefore, the primary focus iswithout neglecting mathematical accuracyon
comprehensibility and real-world applicability.
To submit a proposal or request further information, please use the PDF Proposal
Form or contact directly: Dr. Jan-Philip Schmidt, Publishing Editor (jan-philip.
[email protected]).
123
Jonathan Whiteley
Department of Computer Science
University of Oxford
Oxford
UK
This book has evolved from courses on the nite element method that have been
taught as part of several graduate programmes at the University of Oxford. These
courses have all focused on the practical application of the nite element method.
A typical course would begin with a specic class of differential equations being
written down. The course would then provide students with all the detail that is
required to develop a computational implementation of the nite element method
for this class of differential equations. This approach requires the following topics
to be addressed: (i) derivation of the weak formulation of a differential equation;
(ii) discretisation of the domain on which the differential equation is dened into
elements; (iii) specication of suitable basis functions; (iv) derivation of a system of
algebraic equations that is derived from the nite element formulation of the dif-
ferential equation; (v) solution of this system of algebraic equations; and (perhaps
most importantly) (vi) the practical implementation of all steps. This book is written
in the spirit in which these courses have been taught. Mathematical rigour is cer-
tainly needed when discussing some of these topics, such as the use of Sobolev
spaces when deriving the weak formulation of a differential equation. The focus,
however, is on the practical implementation of the nite element method for a given
differential equation.
This book begins with a brief overview of the nite element method in Chap. 1.
Chapters 26 then focus on the application of the nite element method to ordinary
differential equations. In Chap. 2, we begin with a very simple example differential
equation. Although simple, this example allows illustration of the key ideas that
underpin the nite element method. We then consider general, linear ordinary
differential equations in Chap. 3, providing a more rigorous discussion than in
Chap. 2. The material in Chap. 3 focuses exclusively on nite element solutions that
are a linear approximation to the true solution on each element. These concepts are
extended in Chap. 4 to explain how a higher order polynomial approximation may
be used on each element. We then explain how nonlinear ordinary differential
equations are handled by the nite element method in Chap. 5, and how systems of
ordinary differential equations are handled in Chap. 6. In all of these chapters, we
carefully explain how the values of the solution at each node of the computational
v
vi Preface
vii
viii Contents
Differential equations play a central role in quantitative sciences and are used to
describe phenomena as diverse as the flow of traffic through a city, the evolution of
an oilfield over many years, the flow of ions through an electrochemical solution and
the effect of a drug on a given patient. Most differential equations that are encountered
in practice do not possess an analytic solution, that is a solution that can be written
in terms of known functions. Under these circumstances, a numerical solution to
the differential equation is often sought. The finite element method is one common
technique for calculating a numerical solution of a differential equation.
The underlying principle of the finite element method is very simple to express.
The domain on which the differential equation is defined is partitioned into many
smaller regions known as elements, and the solution of the differential equation is
approximated on each of these elements using a low-order polynomial function.
Consider the example partial differential equation, defined on the interior of the
ellipse x 2 /4 + y 2 = 1 by:
2u 2u
+ 2 = 1.
x 2 y
u(x, y) = x,
and Neumann boundary conditions on the boundary of the ellipse where y > 0,
given by
y
0.5
1
2 1 0 1 2
x
2
u
2
2
2
0 0
y 2 2 x
The vector n that appears in the specification of the Neumann boundary conditions
is the normal vector pointing out of the ellipse, with unit length.
To calculate the finite element solution of the differential equation above, we first
partition the domain on which the differential equation is defined, namely the interior
of the ellipse x 2 /4 + y 2 = 1, into elements. We illustrate how this domain may be
partitioned into triangular elements in Fig. 1.1.
Having partitioned the ellipse into triangular elements, we then calculate the
finite element solution of the differential equation. The finite element solution that
is a linear approximation to the solution on each element is shown in Fig. 1.2.
We will see in later chapters that the finite element method is a very flexible method
for calculating the numerical solution of differential equations. In particular, it has
three key features that make it very attractive from a practical viewpoint. First, the
1.1 Features of the Finite Element Method 3
finite element method can handle domains, such as that shown in Fig. 1.1, that are of
arbitrary shape. This is clearly a useful property, as in practice differential equations
are posed on domains such as the exterior of an aircraft (when estimating the forces
acting on the aircraft); a whole country (when modelling the spread of a disease); or a
subjects lungs (when modelling oxygen transport from air into the subjects blood).
The second key feature of the finite element method is that boundary conditions that
include the derivative of the solution, such as the Neumann boundary conditions for
the example differential equation presented earlier in this chapter, may be handled
very easily. Finally, when we desire more accuracy in our finite element solution, we
have two optionswe may partition the domain into smaller triangular elements or
increase the degree of the polynomial approximation on each element.
The finite element method also has attractive features when viewed from a theoret-
ical standpoint. As we are approximating the true solution by a polynomial function
on each element, functional analysis may be used to assess how well the finite element
solution approximates the true solution. Very powerful theorems exist for estimating
the error between the finite element solution and the true solution of a differential
equation. These theorems have spawned practical techniques for guiding the parti-
tioning of the domain so that the finite element solution is within a user supplied
tolerance of the true solution.
This book is organised so that the application of the finite element method to ordinary
differential equations is covered in Chaps. 26, and the application to partial differen-
tial equations is covered in Chaps. 713. For both ordinary differential equations and
partial differential equations, we first explain how to calculate finite element solutions
that use a linear approximation to the solution on each element. Subsequent chapters
then address the use of higher order approximations to the solution on each element;
nonlinear differential equations; and systems of differential equations. Some readers
may not want to read all chapters as they may, for example, only be interested in
learning how to apply the finite element method to linear differential equations. In
Table 1.1, we list the prerequisite chapters for each chapter of this book.
Many chapters include exemplar computational implementations that are written
for use with Matlab. The Matlab functions are intended to aid the readers under-
standing through being written in a way that is as close as possible to the algorithms
that are derived earlier in the chapter. As a consequence, some fragments of these list-
ings are written using more lines of code than is strictly necessary; some for loops,
for example, could be written in a more elegant style using the vectorisation feature
offered by Matlab. The justification for this more verbose programming style is that
it will allow readers who choose to use a programming language other than Matlab
to easily translate the listings provided into their programming language of choice.
These Matlab listings may be downloaded from http://extras.springer.com.
Chapter 2
A First Example
In Chap. 1, we explained the fundamental philosophy that underpins the finite element
methodthat is, the region on which a differential equation is defined is partitioned
into smaller regions known as elements, and the solution on each of these elements
is approximated using a low-order polynomial function. In this chapter, with the aid
of a simple example, we illustrate how this may be done. This overview will require
the definition of some terms that the reader may not be familiar with, as well as
a few technical details. We will, however, undertake to keep these definitions to a
minimum and will focus on the underlying strategy of applying the finite element
method without getting bogged down by these technical details. As a consequence,
we will inevitably skate over some mathematical rigour, but will make a note to
return to these points in later chapters.
We make a few comments on notation before we begin our overview of the finite
element method. Throughout this book, we use the convention that a solution of a
differential equation that is represented by a lowercase letter, for example u(x), is the
exact, or analytic, solution of the differential equation. The corresponding uppercase
letter, U(x) in this case, will represent the finite element approximation to the exact
solution.
We will frequently make use of vectors and matrices, and adopt the following
conventions.
1. Vectors will be assumed to be column vectors, i.e. a vector with many rows but
only one column, and will be denoted by bold font. Entry i of the vector x will
be denoted by xi .
2. Matrices will be represented by upper case letters typeset in italic font. The entry
in row i and column j of the matrix A will be denoted by Ai,j .
3. The indexing of both vectors and matrices will start from 1. A vector b with
N entries, for example, will have entries b1 , b2 , . . . , bN . This allows the finite
element algorithms to be written in a way that facilitates the writing of software
in programming languages or environments such as Matlab, Octave or Fortran,
where array indexing starts from 1 (known as one-based indexing). Readers
using programming languages such as C, C++ and Python, where the indexing
of arrays starts from 0 (known as zero-based indexing) will need to adapt the
algorithms to take account of this feature of the programming language being
used.
d2 u
= 2, 0 < x < 1, (2.1)
dx 2
and the Dirichlet boundary conditions given by
The region 0 < x < 1 on which the equation is defined is known as the domain.
This simple example, with solution u(x) = x(1 x), will now be used to exhibit
the underlying principles of calculating the finite element solution of a differential
equation.
Let u(x) be the solution of the model differential equation, Eq. (2.1), subject to the
boundary conditions given by Eq. (2.2). The function u(x) is known as the classical
solution of this differential equation, and specification of u(x) through Eqs. (2.1) and
(2.2) is known as the classical formulation.
2.3 The Weak Formulation 7
We now introduce the weak formulation of the model problem, a concept that
may be unfamiliar to some readers. In this chapter, we limit ourselves to illustrating
the weak formulation of a differential equation by example, rather than giving a
watertight definition through precise mathematical statements. A more complete
and rigorous treatment of this material will be presented in Sect. 3.2.
To derive the weak formulation of our model problem, we first define v(x) to be
a continuous function that satisfies
We now apply integration by parts to the left-hand side of the equation above to
obtain
1 1 1
du du dv
v(x) + dx = 2v(x) dx,
dx 0 0 dx dx 0
where
du du
and
dx x=1 dx x=0
Assuming that all derivatives and integrals we have used exist, we may now specify
the weak formulation of our model differential equation by:
8 2 A First Example
find u(x) that satisfies the Dirichlet boundary conditions given by Eq. (2.2) and
is such that
1 1
du dv
dx = 2v(x) dx, (2.5)
0 dx dx 0
The solution u(x) given by Eq. (2.5) is known as the weak solution. The functions
v(x) that appear in Eq. (2.5) are known as test functions.
The concept of weak solutions will be revisited in the next chapter, providing
some mathematical details that have been omitted above. For now, the reader need
only know what has been derived above, namely that a classical solution of the
differential equation and boundary conditions given by Eqs. (2.1) and (2.2) is also a
weak solution that satisfies Eq. (2.5).
We now begin to lay out some of the ingredients required by the finite element
method. We have already explained that we need to partition the domain on which
the differential equation is specified into smaller regions. Our model differential
equation, Eq. (2.1), is defined on the domain 0 < x < 1, and we now partition this
domain into N intervals of equal length h = N1 . If we define
i1
xi = , i = 1, 2, . . . , N + 1, (2.6)
N
Fig. 2.1 The nodes and elements in a finite element mesh when the interval 0 < x < 1 is partitioned
into five equally sized elements
2.4 Elements and Nodes 9
The mesh we have described above contains elements that are equally sized. We
will see in the next chapter that it is straightforward to generalise the definition of
the mesh so that it contains elements that are of different sizes.
In this chapter, we will use the finite element method to calculate a linear approxima-
tion to the solution on each element, that is continuous across element boundaries.
In the previous section, we partitioned the domain 0 < x < 1 into N equally sized
elements, each of length h = N1 . Note that this implies that
xj+1 xj = h, j = 1, 2, . . . , N. (2.7)
We now specify some functions that will be required when calculating the finite
element solution. Using the property of h given by Eq. (2.7), the functions j (x), for
j = 1, 2, . . . , N + 1, are defined by
(x2 x)/h, x1 x x2 ,
1 (x) = (2.8)
0, otherwise,
(x xj1 )/h, xj1 x xj ,
j (x) = (xj+1 x)/h, xj x xj+1 , j = 2, 3, . . . , N, (2.9)
0, otherwise,
(x xN )/h, xN x xN+1 ,
N+1 (x) = (2.10)
0, otherwise.
These functions are illustrated in Fig. 2.2. For reasons that will soon become clear,
we refer to these functions as basis functions.
The functions j (x), j = 1, 2, . . . , N + 1, defined by Eqs. (2.8)(2.10) have three
properties that are useful when calculating the finite element solution: (i) they are
linear functions on each element; (ii) they are continuous functions; and (iii) they
satisfy, for i = 1, 2, . . . , N + 1, the condition
1, i = j,
j (xi ) = (2.11)
0, i = j.
These properties may easily be verified using the definition of basis functions given
by Eqs. (2.8)(2.10), and the plots of these functions in Fig. 2.2. As a consequence,
the function j (x) takes the value 1 at the node where x = xj , and the value 0 at all
other nodes. This is a very important property of basis functions, as we will see in
later chapters when using more general basis functions to calculate the finite element
approximation of more complex differential equations.
10 2 A First Example
0
x1 x2 xj1 xj xj+1 xN xN+1
We will now use the basis functions j (x), j = 1, 2, . . . , N +1, defined by Eqs. (2.8)
(2.10), to generate a finite element solution of our model differential equation that is
a linear approximation to the solution on each element. We claim that we can write
the finite element solution, U(x), as a linear sum of these basis functions:
N+1
U(x) = Uj j (x), (2.12)
j=1
N+1
U(xi ) = Uj j (xi )
j=1
= Ui , (2.13)
2.6 The Finite Element Solution 11
and so Ui is the finite element approximation to the solution at the node where x = xi .
We now move on to describe how to determine the values Ui , i = 1, 2, . . . , N + 1,
that complete the definition of the finite element solution given by Eq. (2.12).
Having prescribed the functional form for the finite element solution by Eq. (2.12),
we now generate a system of algebraic equations satisfied by the coefficients Uj ,
j = 1, 2, . . . , N + 1. This is achieved by modifying the weak formulation of the
model differential equation, given by Eq. (2.5), to specify the finite element solution
U(x) by:
find U(x) that satisfies the Dirichlet boundary conditions given by Eq. (2.2)
and is such that
1 1
dU di
dx = 2i (x) dx, (2.14)
0 dx dx 0
The statement above is nothing more than the weak formulation, Eq. (2.5), restated
with two minor modifications. First, we replace the weak solution u(x) by the finite
element solution U(x). Second we restrict the test functions to be the finite set of
basis functions i (x) that satisfy
i (0) = i (1) = 0.
We see, from the definitions of the basis functions given by Eqs. (2.8)(2.10) and their
illustration in Fig. 2.2, that this condition on i (x) is satisfied by all basis functions
except 1 (x) and N+1 (x). We therefore have N 1 functions 2 (x), 3 (x), . . . , N (x)
that satisfy this condition.
We now use Eq. (2.14) to derive a system of algebraic equations, satisfied by the
N + 1 unknown values U1 , U2 , . . . , UN+1 , that specify the finite element solution
given by Eq. (2.12). As we have N + 1 unknown values, we require a system of N + 1
algebraic equations to determine these values.
The first condition in the specification of the finite element solution by Eq. (2.14)
is that U(x) satisfies the Dirichlet boundary conditions given by Eq. (2.2). These
boundary conditions are applied at the node where x = x1 and the node where
x = xN+1 and may be written as
U(x1 ) = 0, U(xN+1 ) = 0.
12 2 A First Example
Using Eq. (2.13), we see that these Dirichlet boundary conditions are satisfied pro-
vided that
U1 = 0, (2.15)
UN+1 = 0, (2.16)
dU
dj N+1
= Uj ,
dx j=1
dx
dU
substitution of dx
into the integral equation given by Eq. (2.14) yields
1
N+1 1
dj di
Uj dx = 2i (x) dx, i = 2, 3, . . . , N,
0 j=1
dx dx 0
1
N+1
di dj
1
dx Uj = 2i (x) dx, i = 2, 3, . . . , N. (2.17)
j=1 0 dx dx 0
N+1
Ai,j Uj = bi , i = 2, 3, . . . , N, (2.18)
j=1
where for i = 2, 3, . . . , N,
1
di dj
Ai,j = dx, j = 1, 2, 3, . . . , N + 1, (2.19)
0 dx dx
1
bi = 2i (x) dx. (2.20)
0
2.7 Algebraic Equations Satisfied by the Finite Element Solution 13
We may combine Eqs. (2.15), (2.16) and (2.18) into the (N + 1) (N + 1) linear
system
AU = b. (2.21)
The entries of A and b in row i, where i = 2, 3, . . . , N, are given by Eqs. (2.19) and
(2.20). Using Eqs. (2.15) and (2.16), we see that the entries of A and b in rows 1 and
N + 1 are given by
1, j = 1,
A1,j = (2.22)
0, j = 1,
1, j = N + 1,
A(N+1),j = (2.23)
0, j = N + 1,
b1 = 0, (2.24)
bN+1 = 0. (2.25)
The algebraic equations that comprise the linear system given by Eq. (2.21) fall
into two categories. The first category is equations such as Eqs. (2.15) and (2.16) that
arise from demanding that the finite element solution satisfies all Dirichlet boundary
conditions. The second category is equations such as Eq. (2.18) that arise from using a
suitable basis function as the test function in the integral condition given by Eq. (2.14).
This categorisation of equations will be a feature of all the systems of algebraic
equations that we derive in later chapters.
Having derived the linear system of algebraic equations that determines the values
U1 , U2 , . . . , UN+1 , we now introduce a flexible technique for the practical computa-
tion of the entries of the matrix A and the vector b.
Most entries of the matrix A and vector b that appear in the linear system given
by Eq. (2.21) are of the form specified by Eqs. (2.19) and (2.20) and are defined by
integrals over the whole domain on which the differential equation is specified. We
will now demonstrate that, from a computational implementation viewpoint, it is
convenient to compute these entries by summing the contributions from individual
elements. That is, for i = 2, 3, . . . , N, we write Eqs. (2.19) and (2.20) as the sum of
integrals over individual elements:
14 2 A First Example
N
xk+1
di dj
Ai,j = dx, j = 1, 2, . . . , N + 1, (2.26)
xk dx dx
k=1
N
xk+1
bi = 2i (x) dx. (2.27)
k=1 xk
Using Eq. (2.26) we see that the contribution to entry Ai,j from integrating over
the element that occupies xk x xk+1 is given by
xk+1
di dj
dx. (2.28)
xk dx dx
From the definition of the basis functions, given by Eqs. (2.8)(2.10) and illustrated
in Fig. 2.2, we see that k (x) and k+1 (x) are the only basis functions that are nonzero
on the element occupying xk x xk+1 : all other basis functions are identically
zero on this element. Hence, the integral above, over xk x xk+1 , yields nonzero
contributions only to the entries Ak,k , Ak,k+1 , Ak+1,k , Ak+1,k+1 of A. Motivated by this
observation, we calculate only these nonzero contributions when integrating over this
element and store these contributions in a 2 2 matrix called A(k) local . The relationship
between the location of the entries of A(k) local and the location of the entries of A that
they contribute to is given in Table 2.1.
The entries of A(k)local are known as the local contributions to the matrix A from ele-
ment k, and A is often referred to as the global matrix. We may compute A efficiently
by looping over all elements, calculating only the nonzero local contributions from
each element, before adding the local contributions to the appropriate entries of the
global matrix A. Having calculated the entries of A that are given by Eq. (2.19), we
complete the specification of the matrix by setting the remaining entries, i.e. those
defined by Eqs. (2.22) and (2.23).
The entries of b that are given by Eq. (2.27) may be calculated in a similar manner
to that used for the entries of A that are given by Eq. (2.26). The contribution to
bi , i = 2, 3, . . . , N, from integrating over the element that occupies xk x xk+1
is given by
(k)
Table 2.1 The relationship between the location of the entries of Alocal and the location of the
entries of A that they contribute to
Entry in A(k)
local Entry in A
Row Column Row Column
1 1 k k
1 2 k k+1
2 1 k+1 k
2 2 k+1 k+1
2.8 Assembling the Algebraic Equations 15
xk+1
2i (x) dx. (2.29)
xk
As k (x) and k+1 (x) are the only basis functions that are nonzero inside the element
that occupies xk x xk+1 , the only nonzero contributions to b from this element
are to the entries bk and bk+1 . We again calculate only these nonzero contributions
and store them in a vector of length 2 called b(k)
local , known as the local contribution
to the global vector b. The relationship between the location of the entries of b(k) local
and the location of the entries of b that they contribute to is given in Table 2.2. We
may then calculate the global vector b by looping over all elements, calculating
only the nonzero contributions to Eq. (2.27) from each element, and adding these
contributions into b. We then use Eqs. (2.24) and (2.25) to set the other entries.
We explained above that the entries of the global matrix A and global vector b
that are given by Eqs. (2.19) and (2.20) should be assembled by summing the local
contributions to these entries from each element. We now explain how these local
contributions may be calculated.
Using the mapping between the entries of A(k) local and the entries of A, given by
Table 2.1, and the definition of the contribution to entries of A from element k, given
by Eq. (2.28), we see that the entries of A(k)
local are given by
xk+1 dk dk
xk+1 dk dk+1
dx dx
A(k)
xk dx dx xk dx dx
local = xk+1 dk+1 dk xk+1 dk+1 dk+1
. (2.30)
xk dx dx
dx xk dx dx
dx
Similarly, using Table 2.2 and Eq. (2.29), the entries of b(k)
local may be written as
xk+1
2k (x) dx
b(k) = xk
xk+1 . (2.31)
local
xk 2k+1 (x) dx
xk+1 x
k (x) = ,
h
x xk
k+1 (x) = ,
h
and so the derivatives of these functions take the constant values given by
dk 1
= ,
dx h
dk+1 1
= .
dx h
We have proposed calculating the entries of the global matrix A and global vector
b that are of the form given by Eqs. (2.19) and (2.20), by looping over all elements
in the mesh, calculating the nonzero local contributions A(k) (k)
local and blocal from each
element, and using these contributions to increment the appropriate entries of A and
b, given by Tables 2.1 and 2.2.
Readers may have spotted a potential flaw with this approach for calculating A
and b. The expressions for Ai,j and bi given by Eqs. (2.19) and (2.20) are only valid
for i = 2, 3, . . . , N, with the entries for rows 1 and N +1 given by Eqs. (2.22)(2.25).
When calculating the local contributions from the element that occupies x1 x x2 ,
we evaluate contributions to both row 1 and row 2 of A and b. The entries of row 1 of A
and b do not, however, fall into the pattern given by Eqs. (2.19) and (2.20), although
the contribution to row 2 of both A and b from this element is correct. Similarly,
when calculating the local contribution from the element occupying xN x xN+1
we calculate contributions to row N + 1 of A and b that are not of the correct form.
We could avoid adding these incorrect entries into rows 1 and N + 1 by performing
a check, before adding any local contributions into the global matrix and vector, to
ensure we do not add any entries into rows 1 and N + 1. There is nothing wrong
with this approach. However, to promote clear, modular codeespecially for the
more complex problems encountered later in this bookit is easier to add the local
contributions into rows 1 and N + 1 and then to overwrite these erroneous entries
afterwards with the correct values, given by Eqs. (2.22)(2.25).
2.8 Assembling the Global Matrix 17
Having assembled the matrix A and the vector b, most of the work required to cal-
culate the finite element solution given by Eq. (2.12) has been done. All that remains
is to solve the linear system given by Eq. (2.21) to calculate U, before substituting
the entries of U into Eq. (2.12). We now summarise the steps we have taken when
applying the finite element method and then present an exemplar computational
implementation.
The aim of this chapter has been to give an overview of the finite element method
by illustrating its application to an example boundary value problem. We now give
a summary of the steps required when applying the finite element method. We will
see in later chapters that this summary may be used as a guide for the application of
the finite element method to more general differential equations.
1. Derive the weak formulation of the boundary value problem from the specified
differential equation and boundary conditions.
2. Define the finite element mesh by partitioning the domain into elements, and
specifying the nodes defined by these elements.
3. Use the nodes and elements in the mesh to define suitable basis functions.
4. Write the finite element solution as a linear sum of the basis functions. Modify the
weak formulation of the problem to determine the system of algebraic equations
that the finite element solution satisfies. These algebraic equations will fall into
one of two categories. The first category is equations that ensure that all Dirichlet
boundary conditions are satisfied. The second category is equations that arise
from substituting suitable test functions into an integral condition on the finite
element solution.
5. Assemble the algebraic equations. Begin with the second category of equations
given in step #4 above. Calculate the nonzero contributions from each element,
and use these local contributions to increment the correct entries of the global
matrix and vector. After this has been done, modify the equations to take account
of the boundary conditions.
6. Solve the system of algebraic equations.
defined in Sect. 2.4 requires only specification of the number of elements, N. This is
sufficient to define the location of the nodes x1 , x2 , . . . , xN+1 , and the element length
h. Further, these nodes allow us to specify the basis functions through the material
given in Sect. 2.5. We are then in a position to assemble the algebraic equations. We
will therefore implement the material described in this chapter by writing a function
that accepts a positive integer, N, that represents the number of elements, as an
input, and returns the vector x (containing the nodes in the mesh) and the vector U
(containing the finite element solution at each node).
A Matlab script for the implementation described above is given in Listing 2.1.
This function may be called by saving the file as Chap2_CalculateModelFem-
Solution.m and typing, in a Matlab session,
[x, U] = Chap2_CalculateModelFemSolution(40);
to run with N = 40 elements. Variable names in this script have been chosen to
correspond to the mathematical notation used in this chapter. This function begins
by initialising entries of the global matrix A and global vector b to zero in lines 4
and 5, before generating a vector containing the equally spaced nodes in the mesh in
line 8. We then loop over all elements in lines 1223, calculating the nonzero local
contributions to A and b given by Eqs. (2.30) and (2.31), before incrementing the
appropriate entries of the global linear system, given by Tables 2.1 and 2.2. Matlab
users will be aware that the expression A(k:k+1, k:k+1) that appears in line 21
is shorthand for the submatrix given by
Ak,k Ak,k+1
,
Ak+1,k Ak+1,k+1
and that the expression b(k:k+1) that appears in line 22 represents the subvector
given by
bk
.
bk+1
Note that the loop over elements introduces incorrect entries into rows 1 and N + 1 of
A and b, for the reasons explained in Sect. 2.8.2. These entries are overwritten with
the correct values in lines 2631. Note that line 26 uses Matlab notation to set all
entries of row 1 to zero. We then solve the linear system using Matlabs backslash
operator in line 34. This is a suitable method for solving linear systems of the modest
size generated here. However, iterative techniques may be more suitable for solving
the larger systems of algebraic equations that arise from the application of the finite
element method to partial differential equations in later chapters. A summary of these
linear algebra techniques is given in Appendix A. Finally, in lines 3739, we plot the
finite element solution that has been calculated, which is a linear approximation to
the solution on each element. This finite element solution may be plotted by drawing
a straight line between the finite element solution at adjacent nodes: this is exactly
what is plotted by line 37 of the listing.
2.10 Computational Implementation 19
3 % I n i t i a l i s e A and b to zero
4 A = z e r o s ( N +1 , N +1);
5 b = z e r o s ( N +1 , 1);
6
7 % G e n e r a t e N +1 nodes , e q u a l l y s p a c e d b e t w e e n 0 and 1
8 x = l i n s p a c e (0 , 1 , N +1);
9
16 % C a l c u l a t e local c o n t r i b u t i o n s
17 A _ l o c a l = [1/ h , -1/ h ; -1/ h , 1/ h ];
18 b _ l o c a l = [ h ; h ];
19
25 % Set D i r i c h l e t b o u n d a r y c o n d i t i o n s
26 A (1 ,:) = 0;
27 A (1 ,1) = 1;
28 b (1) = 0;
29 A ( N +1 ,:) = 0;
30 A ( N +1 , N +1) = 1;
31 b ( N +1) = 0;
32
36 % Plot f i n i t e e l e m e n t s o l u t i o n
37 plot ( x , U , - o )
38 x l a b e l ( x )
39 y l a b e l ( U )
point x, that is, evaluate U(x). If x is a node in the mesh, i.e. xi = x for some i, we
may then use Eq. (2.13) to write
U(x) = Ui .
If x is not a node in the mesh, then it will lie in element k for some k, where
xk < x < xk+1 . We first locate the element k that x lies in. Noting, as we did earlier in
this chapter, that only the basis functions k (x) and k+1 (x) are nonzero on element
k, the finite element solution given by Eq. (2.12) may be written, for xk < x < xk+1 ,
as
We then use the definition of the basis functions k (x) and k+1 (x), given by
Eqs. (2.8)(2.10), to deduce that
xk+1 x x xk
U(x) = Uk + Uk+1 .
h h
It is always worth checking the solution to any mathematical problem, whether the
solution has been obtained by analytic pen and paper techniques or as the output
from a computer program. Easily made typographical errors, such as a missed factor
of 2, will at best lead to inaccuracies in the solution. There is, however, the potential
for completely nonsensical output, for example a physical quantity being assigned
a value that is calculated from taking the square root of a negative number. It is,
therefore, useful to perform some verification of the computation of a finite element
solution. An exhaustive verification, such as comparing the finite element solution of
a differential equation with the true solution of the equation, is rarely possible. After
all, if we knew the true solution of a differential equation, we would be unlikely to go
to the effort of computing the finite element solution. Nevertheless, some validation
is possible. Below we list a few simple tests that can usually be carried out.
The simplest test that can be carried out is to plot the finite element solution to
check that the solution looks realistic and takes values that are reasonablea
computed chemical concentration that takes a negative value, for example, should
set alarm bells ringing.
Another simple check that should be carried out is to compare finite element
solutions that have been calculated using different numbers of elements. The finite
element solution should become more accurate, and approach a limit as the number
of elements is successively increased.
Finally, analytic solutions may exist for some choices of parameter values that
appear in the differential equation, or for simplifications of the differential equa-
2.12 Is the Finite Element Solution Correct? 21
tion. The finite element solution should be computed in these cases and compared
to the analytic solution.
2.13 Exercises
For these exercises, you will need to download the Matlab script given in Listing 2.1.
Remember that the true solution to the differential equation on which this script is
based is u(x) = x(1 x).
2.1 In this exercise, we will modify the Matlab script given in Listing 2.1 so that
it returns the finite element solution at the point x = 0.45.
(a) Modify the Matlab script so that it returns the finite element solution at
x = 0.45 when this point is a node of the mesh. Use the true solution, and
a mesh with N = 100 elements, to verify that your answer is correct.
(b) Use the material given in Sect. 2.11 to modify the Matlab script to evaluate the
finite element solution at x = 0.45 when this point is not a node of the mesh.
Use the true solution, and a mesh with N = 101 elements, to verify that your
answer is correct.
(c) Combine your answers to parts (a) and (b) so that the Matlab script first deter-
mines whether or not x = 0.45 is a node of the mesh, before returning the finite
element solution at that point.
2.2 We denote the error between the finite element solution and the true solution by
E(x) = U(x) u(x). The L 2 norm of the error of the finite element solution, EL2 ,
is defined to be
1
EL =
2 (U(x) u(x))2 dx,
0
which may be written as the sum of the contribution from individual elements:
N
xk+1
EL2 = (U(x) u(x))2 dx.
k=1 xk
(a) In Sect. 2.11, we saw that, for xk < x < xk+1 , the finite element solution is given
by
xk+1 x x xk
U(x) = Uk + Uk+1 .
h h
Use this expression for U(x) to explain why, for the model problem used in this
chapter, we may write
22 2 A First Example
N
2
xk+1
xk+1 x x xk
E2L2 = Uk + Uk+1 x(1 x) dx.
xk h h
k=1
EL2 = Chp ,
for some constants C and p. Taking the logarithm of both sides of this expression
gives
and so plotting log (EL2 ) against log h will give a straight line of gradient p
as h 0. By plotting log (EL2 ) against log h for several values of h, estimate
the constant p.
2.3 In Sect. 2.11, we saw that, for xk < x < xk+1 , the finite element solution is given
by
xk+1 x x xk
U(x) = Uk + Uk+1 .
h h
d2 u
3 = 2, 0 < x < 1,
dx 2
together with boundary conditions
u(0) = 1, u(1) = 2.
2.13 Exercises 23
(a) Write down the analytic solution to this boundary value problem.
(b) By working through the steps required to calculate the finite element solution,
summarised in Sect. 2.9, modify the Matlab script given in Listing 2.1 to cal-
culate the finite element approximation of the boundary value problem above.
Compare your finite element solution to the true solution.
Chapter 3
Linear Boundary Value Problems
In the previous chapter, we demonstrated how to calculate the finite element solution
of a very simple differential equation. The intention of this simple example was to
give the reader an overview of the steps required when applying the finite element
method. As a consequence, for the sake of clarity, some mathematical rigour was
neglected. In this chapter, we introduce more rigour into our description of the finite
element method and demonstrate how to calculate the finite element solution of
general linear, second-order, boundary value problems.
for given functions p(x), q(x), r (x) and f (x), where the function p(x) satisfies the
condition that p(x) = 0 for a < x < b. A differential equation for u(x) is described
as linear provided the differential equation is linear in u(x) and its derivatives. The
equation above will then still classified as a linear differential equation even if the
functions p(x), q(x), r (x) and f (x) are nonlinear functions of x.
To fully specify the boundary value problem, we require one boundary condition
at x = a and one boundary condition at x = b. At this point, we consider only two
types of boundary conditions: Dirichlet boundary conditions, where the value of the
function u(x) is specified on the boundary, and Neumann boundary conditions, where
the derivative of the function u(x) is specified on the boundary. We will consider
more general boundary conditions in Sect. 3.8. For the purpose of illustrating the
application of the finite element method, we will specify one Dirichlet boundary
condition and one Neumann boundary condition. This will allow us to demonstrate
Springer International Publishing AG 2017 25
J. Whiteley, Finite Element Methods, Mathematical Engineering,
DOI 10.1007/978-3-319-49971-0_3
26 3 Linear Boundary Value Problems
how both categories of boundary condition are handled by the finite element method.
It should then be clear how to adapt the finite element method for any suitable
combination of these boundary conditions. We impose a Dirichlet boundary condition
at x = a:
u = ua , x = a, (3.2)
du
p(x) = b , x = b, (3.3)
dx
where b is another given constant. Note the presence of p(x) in both Eqs. (3.1) and
(3.3): the left-hand side of Eq. (3.3) has the same pattern as the contents of the brackets
on the left-hand side of Eq. (3.1). A Neumann boundary condition written in this
form is known as a natural boundary condition. The reason for this terminology will
become clear shortly when we derive the weak solution of the differential equation
given by Eq. (3.1), subject to the boundary conditions given by Eqs. (3.2) and (3.3).
We have written the Neumann boundary condition, Eq. (3.3), as a natural Neu-
mann boundary condition. It is straightforward to write other Neumann boundary
conditions, such as
du
= b , x = b, (3.4)
dx
as natural Neumann boundary conditions; we simply multiply the boundary condition
given by Eq. (3.4) by p(x), which we assumed earlier was nonzero. Writing b =
p(b)b then yields a natural Neumann boundary condition in the form of Eq. (3.3).
d2 u
+ u = 0, (3.5)
dx 2
subject to the boundary conditions
u(0) = 0, u( ) = 1. (3.6)
3.1 A General Boundary Value Problem 27
The general solution of Eq. (3.5) is u(x) = K 1 sin x + K 2 cos x, for constants K 1
and K 2 that we would expect to determine from the boundary conditions given by
Eq. (3.6). However, it is not possible to find values of K 1 and K 2 that satisfy both of
these boundary conditions, and we deduce that no solution exists to this boundary
value problem.
Suppose, instead, that the boundary conditions are given by
u(0) = 0, u( ) = 0. (3.7)
The solution of Eq. (3.5), subject to the boundary conditions given by Eq. (3.7),
is u(x) = K 1 sin x for any constant K 1 . Hence, the solution is not unique. A full
discussion of the existence and uniqueness of solutions to boundary value problems is
beyond the scope of this book. Throughout this book, you may assume, unless stated
otherwise, that a unique solution exists to any differential equation considered.
The discussion of the weak formulation of a boundary value problem in Sect. 2.3,
although entirely adequate for the purposes of Chap. 2, lacked sufficient detail to
allow the reader to apply the finite element method to a general boundary value
problem such as that presented in Sect. 3.1. In particular, the model problem con-
sidered in Chap. 2 included only the very simple Dirichlet boundary conditions that
u(x) = 0 on both boundaries. As promised, we now provide more detail, allow-
ing more general boundary conditions to be handled. Our treatment of the weak
formulation will also be more rigorous than that presented in Chap. 2.
The weak formulation of the example differential equation derived in Sect. 2.3
assumed the existence of several derivatives and integrals. We now provide some
notation that aids us in deriving the weak formulation of differential equations in
a more rigorous manner. Suppose that a function v(x) is defined on the interval
a x b. We say that v(x) is square integrable on this interval if the integral
b
(v(x))2 dx
a
exists: in practice, this integral is said to exist if it takes a finite value. We define
L 2 (a, b) to be a set of all functions v(x) that are square integrable on the interval
a x b and write L 2 (a, b) in set notation as
28 3 Linear Boundary Value Problems
b
L (a, b) = functions v(x) such that the integral
2
(v(x)) dx exists .
2
(3.8)
a
We now define the Sobolev space of order 1, denoted by H 1 (a, b), to be the set of
functions v(x) that: (i) are defined and continuous on the interval a x b; (ii)
are square integrable on a x b; and (iii) possess a first derivative that is square
integrable on a x b. In set notation,
H (a, b) =
1
functions v(x) such that v(x) is continuous, and the integrals
b b 2
dv
(v(x))2 dx and dx exist . (3.9)
a a dx
Suppose that a differential equation, together with suitable boundary conditions, has
been specified. Using these boundary conditions, we specify two subsets of H 1 (a, b)
that will be required later:
HE1 (a, b) = functions v(x) in H 1 (a, b) such that v(x) satisfies all Dirichlet
boundary conditions , (3.10)
H01 (a, b) = functions v(x) in H 1 (a, b) such that v(x) = 0 at all points x where
Dirichlet boundary conditions are specified . (3.11)
The use of these sets of functions when deriving the weak formulation of a differential
equation ensures the existence of all integrals that are used.
The definitions of the Sobolev space of order 1, and subsets of this space, laid out
in Eqs. (3.9)(3.11), may be used to aid the derivation of the weak formulation of
the differential equation given by Eq. (3.1), subject to the boundary conditions given
by Eqs. (3.2) and (3.3). We begin by multiplying the differential equation, Eq. (3.1),
by any test function v(x) H01 (a, b), and integrating the resulting product over the
interval a < x < b:
b b
d du du
p v + q v + r uv dx = f v dx.
a dx dx dx a
3.2 The Weak Formulation 29
We now integrate the first term on the left-hand side by parts to give
b b
du b du dv du
p v + p + q v + r uv dx = f v dx. (3.12)
dx a a dx dx dx a
We have chosen v(x) H01 (a, b) and so, by the definition of this set given in
Eq. (3.11), we have v(x) = 0 at any value of x where a Dirichlet boundary condition
is applied. As a Dirichlet boundary condition, given by Eq. (3.2), is applied at x = a,
we have v(a) = 0. Substituting both this Dirichlet boundary condition, and the
Neumann boundary condition given by Eq. (3.3) into Eq. (3.12) gives, after a little
rearrangement:
b b
du dv du
p + q v + r uv dx = f v dx + b v(b). (3.13)
a dx dx dx a
Note that writing the Neumann boundary condition, Eq. (3.3), as a natural boundary
condition allows the contribution to Eq. (3.13) from the Neumann boundary condition
to be independent of the function p(x).
In deriving Eq. (3.13), we have used the differential equation, Eq. (3.1), and the
Neumann boundary condition, Eq. (3.3). We have not yet used the Dirichlet bound-
ary condition given by Eq. (3.2), other than to specify the set H01 (a, b). We satisfy
the Dirichlet boundary condition by demanding that the weak solution lies in the
set HE1 (a, b) defined by Eq. (3.10), as all functions in this set satisfy this Dirichlet
boundary condition.
Using Eq. (3.13), we may now define the weak solution of Eqs. (3.1)(3.3) by:
The derivation above has illustrated one key feature of the weak formulation of a
differential equation. Dirichlet boundary conditions are satisfied through specifying
the set in which u(x) lies, i.e. the set HE1 (a, b). Neumann boundary conditions
are handled through incorporating these boundary conditions into Eq. (3.14), the
equation that is satisfied by the weak solution for all suitable test functions. We will
see in the next section that this remark also applies to the finite element solution.
30 3 Linear Boundary Value Problems
In Chap. 2, we used a mesh with equally spaced nodes, often known as a uniform
mesh, when computing the finite element solution. A consequence of using equally
spaced nodes is that all elements are the same size. We now relax this condition
and allow computational meshes where the nodes are not equally spaced across the
computational domain a < x < b.
As before, the computational mesh will consist of N elements and N + 1 nodes.
The nodes are again denoted by x1 , x2 , . . . , x N +1 . We demand that these nodes satisfy
three conditions: (i) x1 = a, (ii) x N +1 = b and (iii) xk+1 > xk for k = 1, 2, . . . , N .
Defining element k to occupy the region xk x xk+1 , we see that nodes
satisfying the conditions above generate elements that cover the whole of the domain
a < x < b without overlapping, and all have positive length. The mesh containing
these nodes and elements is therefore a suitable partitioning of the domain.
We will now define basis functions that allow us to calculate a finite element solution
that is a linear approximation to the solution of a differential equation on each ele-
ment. These basis functions will be defined using two different formulations, which
we will show are equivalent. The first formulation defines the basis functions by
modifying the basis functions used in Chap. 2, so that they may be applied on the
nonuniform mesh described in Sect. 3.3.1. We then present an alternative formula-
tion for defining these basis functions. Both methods for defining the basis functions
generate identical basis functions. We will see, however, that the second technique
that we present is more flexible. Later in this chapter, we will see that the linear sys-
tem that arises from the implementation of the finite element method includes some
entries that are defined by integrals that are difficult, or impossible, to evaluate ana-
lytically. The second method for defining basis functions will aid us in approximating
these integrals using numerical techniques. Further, we will see in later chapters that
the second method for defining basis functions allows the material presented in this
chapter to be extended, relatively easily, to both higher order basis functions and the
3.3 The Finite Element Solution 31
The basis functions defined by Eqs. (2.8)(2.10) assume that each element is of a
constant length h. Noting that element k is of length xk+1 xk , for k = 1, 2, . . . , N ,
it is straightforward to modify these basis functions for use on the nonuniform
mesh described in Sect. 3.3.1, by replacing the constant h in Eqs. (2.8)(2.10) by
the appropriate element length. We may then define the basis functions j (x), for
j = 1, 2, . . . , N + 1, on the nonuniform mesh described in Sect. 3.3.1 by
x2 x
x2 x1
, x1 x x2 ,
1 (x) = (3.15)
0, otherwise,
xx
j1
, x j1 x x j ,
x j x j1
x j+1 x
j (x) = x x , x j x x j+1 , j = 2, 3, . . . , N , (3.16)
j+1 j
0, otherwise,
xx
N
, x N x x N +1 ,
N +1 (x) = x N +1 x N (3.17)
0, otherwise.
Should each element have the same length h, the basis functions defined above are
identical to the basis functions defined by Eqs. (2.8)(2.10).
When deriving the basis functions in Sect. 2.5, we noted that the basis functions
had three useful properties: (i) they are linear functions on each element; (ii) they are
continuous functions; and (iii) they satisfy, for j = 1, 2, . . . , N + 1, the condition
1, i = j,
j (xi ) = (3.18)
0, i = j.
It is straightforward to verify that these properties are also true for the basis functions
defined above. Writing the finite element solution as
N +1
U (x) = U j j (x), (3.19)
j=1
U (xi ) = Ui , i = 1, 2, . . . , N + 1, (3.20)
and so Ui is, as before, the finite element solution at the node where x = xi .
As promised earlier, we will now present a more general definition of the basis
functions. The global basis functions are now defined through: (i) a mapping between
a general element in the mesh and a canonical element, and (ii) local basis functions
defined on the canonical element.
We may map between element k of the mesh described in Sect. 3.3.1, and the unit
interval 0 X 1, by using the change of variable
The unit interval 0 X 1 is known as the canonical element. We now define local
basis functions local,1 (X ), local,2 (X ) on the canonical element by
local,1 (X ) = 1 X, 0 X 1, (3.22)
local,2 (X ) = X, 0 X 1. (3.23)
k (X ) = local,1 (X ), 0 X 1, (3.24)
k+1 (X ) = local,2 (X ), 0 X 1, (3.25)
j (X ) = 0, 0 X 1, j = k, j = k + 1. (3.26)
(k) xk+1 x
local,1 (x) = , xk x xk+1 , (3.27)
xk+1 xk
(k) x xk
local,2 (x) = , xk x xk+1 . (3.28)
xk+1 xk
3.3 The Finite Element Solution 33
(k) (k)
We introduce the superscript (k) to the functions local,1 (x), local,2 (x) when writing
these functions as a function of x, to emphasise that they depend on the element
through the change of variable given by Eq. (3.21). We place this superscript in
brackets to avoid any confusion with these functions being raised to the power k.
We may now use Eqs. (3.27) and (3.28) to write the global basis functions given
by Eqs. (3.24)(3.26) as functions of x on element k:
xk+1 x
k (x) = , xk x xk+1 , (3.29)
xk+1 xk
x xk
k+1 (x) = , xk x xk+1 , (3.30)
xk+1 xk
j (x) = 0, xk x xk+1 , j = k, j = k + 1. (3.31)
1
(k)
lo cal,1(x) = k (x)
(k)
lo cal,2(x) = k+1 (x)
0
xk xk+1
x
Fig. 3.1 The basis functions k (x) and k+1 (x) defined by Eqs. (3.29) and (3.30)
34 3 Linear Boundary Value Problems
We now identify some sets of potential finite element solutions that mirror the Sobolev
spaces that were used when deriving the weak formulation in Sect. 3.2. First, we
specify the set of all potential finite element solutions that do not take account of any
boundary conditions, i.e. the set of continuous functions, that are linear functions
when restricted to a given element. This set, denoted by S h , is defined by
N +1
Sh = functions V (x) given by V (x) = V j j (x) where j , j = 1, 2, . . . , N + 1,
j=1
are suitably defined basis functions . (3.32)
conditions , (3.33)
S0h = functions V (x) S h such that V (x) = 0 at all points x where Dirichlet
boundary conditions are specified . (3.34)
Having defined the set S h , and the subsets S Eh and S0h of this set, in Sect. 3.3.3, we
are now in a position to define the finite element solution. As in Chap. 2, this is done
by modifying the definition of the weak solution, given by Eq. (3.14). The sets of
functions HE1 (0, 1) and H01 (0, 1) that appear in the weak solution are replaced by the
sets S Eh and S0h , allowing us to specify the finite element solution by:
U (x1 ) = U1 , (3.37)
U1 = u a . (3.38)
The condition that U (x) satisfies the Dirichlet boundary condition has allowed
us to derive one algebraic equation, Eq. (3.38). We therefore require a further N
algebraic equations to determine the N +1 unknown values. Using Eq. (3.18), we see
that i (x1 ) = 0 for i = 2, 3, . . . , N + 1. Hence, i (x) S0h for i = 2, 3, . . . , N + 1,
as these functions take the value zero at the value of x where Dirichlet boundary
conditions are applied. Substituting i (x), for i = 2, 3, . . . , N + 1, into Eq. (3.35)
will then generate a further N algebraic equations, as required. Noting that Eq. (3.36)
implies that
N +1
dU d j
= Uj , (3.39)
dx j=1
dx
36 3 Linear Boundary Value Problems
N +1
b b
d j di d j
p +q i + r j i dx U j = f i dx + b i (b),
j=1 a dx dx dx a
(3.40)
for i = 2, 3, . . . , N + 1.
We may combine Eqs. (3.38) and (3.40) into the linear system
AU = b, (3.41)
where for j = 1, 2, . . . , N + 1,
1, j = 1,
A1, j = (3.42)
0, j = 1,
b
di d j d j
Ai, j = p + qi + r i j dx, i = 2, 3, . . . , N + 1,
a dx dx dx
(3.43)
and
b1 = u a , (3.44)
b
bi = f i dx + b i (b), i = 2, 3, . . . , N + 1. (3.45)
a
and so this term only affects the equation generated with i = N + 1. We may now
write Eqs. (3.44) and (3.45), the entries of b, as
b1 = u a , (3.46)
b
bi = f i dx, i = 2, 3, . . . , N , (3.47)
a
b
b N +1 = f N +1 dx + b . (3.48)
a
We now discuss how to assemble the algebraic equations given by Eq. (3.41), with
a particular focus on handling the integration that is required.
3.4 Assembling the Algebraic Equations 37
We assemble the entries of the global matrix A and the global vector b that appear in
the linear system Eq. (3.41) using the same strategy as in Sect. 2.8. We first evaluate
those entries that are defined by integrals, namely Eqs. (3.43), (3.47) and (3.48), by
decomposing these integrals into the sum of integrals over the elements in the mesh.
Remembering that element k occupies xk x xk+1 , we may write Eqs. (3.43),
(3.47) and (3.48) as follows:
N
xk+1
di d j d j
Ai, j = p + qi + r i j dx,
k=1 xk dx dx dx
i = 2, 3, . . . , N + 1, j = 1, 2, . . . , N + 1, (3.49)
N xk+1
bi = f i dx, i = 2, 3, . . . , N , (3.50)
k=1 xk
N
xk+1
b N +1 = f N +1 dx + b . (3.51)
k=1 xk
We then complete the assembly of the linear system by setting the entries that are
defined explicitly by Eqs. (3.42) and (3.46). We now explain this process in more
detail.
We see from Eq. (3.49) that the contribution to entry Ai, j of the global matrix A, from
integration over element k, is given by, for i = 2, 3, . . . , N +1, j = 1, 2, . . . , N +1:
xk+1
di d j d j
p + qi + r i j dx.
xk dx dx dx
In Sect. 2.8, we noted that the only basis functions that are nonzero on element k
are k (x) and k+1 (x). The integral above will therefore be zero unless both i and
j take the values k or k + 1. Consequently, the integral above generates nonzero
contributions only to the entries Ak,k , Ak,k+1 , Ak+1,k , Ak+1,k+1 of the global matrix
(k)
A. These nonzero contributions may be stored in the local matrix Alocal , of size 2 2,
(k) (k) (k)
where entry Alocal,1,1 contributes to Ak,k ; Alocal,1,2 contributes to Ak,k+1 ; Alocal,2,1
(k) (k)
contributes to Ak+1,k ; and Alocal,2,2 contributes to Ak+1,k+1 . The entries of Alocal are
given by:
38 3 Linear Boundary Value Problems
xk+1
(k) dk dk dk
Alocal, 1,1 = p + qk + r k k dx, (3.52)
x dx dx dx
kxk+1
(k) dk dk+1 dk+1
Alocal, 1,2 = p + qk + r k k+1 dx, (3.53)
x dx dx dx
kxk+1
(k) dk+1 dk dk
Alocal, 2,1 = p + qk+1 + r k+1 k dx, (3.54)
x dx dx dx
kxk+1
(k) dk+1 dk+1 dk+1
Alocal, 2,2 = p + qk+1 + r k+1 k+1 dx. (3.55)
xk dx dx dx
Similarly, using Eqs. (3.50) and (3.51), the contribution to the entry bi , i =
2, 3, . . . , N + 1, of the global vector b from integration over element k is given by
xk+1
f i dx.
xk
Using the same argument as above, we see that this integral generates nonzero contri-
butions only to the entries bk and bk+1 of the global vector b. We store these nonzero
(k) (k)
contributions in a local vector blocal with two entries. Entry blocal,1 of this local vector
(k)
contributes to entry bk of the global vector b, and entry blocal,2 contributes to entry
(k)
bk+1 of b. The entries of blocal are given by:
xk+1
(k)
blocal, 1 = f k dx, (3.56)
x
kxk+1
(k)
blocal, 2 = f k+1 dx. (3.57)
xk
We may therefore compute the integrals that appear in Eqs. (3.43), (3.47) and
(3.48) by looping over all elements, calculating only the nonzero local contributions
(k) (k)
Alocal and blocal from each element, before using these local contributions to increment
the appropriate entries of A and b. We then complete the assembly of Eqs. (3.43),
(3.47) and (3.48) by adding the extra algebraic term that appears in Eq. (3.48) to entry
b N +1 of b. However, before we may use this technique for assembling these entries
of A and b, we must first be able to evaluate the integrals that define the entries of
(k) (k)
Alocal and blocal on each element.
For some functions p(x), q(x), r (x) and f (x), the integrals given by Eqs. (3.52)
(3.57) may be evaluated analytically. This was the case for the simple example
differential equation in Chap. 2, where p(x) = 1, q(x) = 0, r (x) = 0 and f (x) = 2.
For more general functions, it may not be possible to evaluate these integrals ana-
lytically, and we must approximate these integrals numerically. This is one instance
where the specification of the global basis functions through local basis functions on
the canonical element 0 X 1, described in Sect. 3.3.2.2, is useful, as we now
describe.
3.4 Assembling the Algebraic Equations 39
We will see, in Sect. 3.5, that when making a numerical approximation to the
integrals above, it is convenient to use the change of variable, given by Eq. (3.21),
that maps between element k and the canonical element 0 X 1. Writing
h = xk+1 xk , k = 1, 2, . . . , N ,
x = xk + h X, 0 X 1. (3.58)
(k) (k)
We now use this change of variable to write the entries of Alocal and blocal , given by
Eqs. (3.52)(3.57), as integrals over the canonical element. On using Eq. (3.24) and
(3.25), we may write k and k+1 in terms of the local basis functions defined by
Eqs. (3.22) and (3.23). Noting that
dlocal, i 1 dlocal, i
= , i = 1, 2,
dx h dX
(k) (k)
we may write the entries of Alocal and blocal as
1
(k) 1 dlocal, i dlocal, j
Alocal, i, j = h 2
p(xk + h X ) +
0 h dX dX
1 dlocal, j
q(xk + h X )local, i (X ) +
h dX
r (xk + h X )local, i (X )local, j (X ) dX, i, j = 1, 2, (3.59)
1
(k)
blocal, i =h f (xk + h X )local, i (X ) dX, i = 1, 2. (3.60)
0
We will explain in Sect. 3.5 how these integrals may be approximated numerically.
We noted in Sect. 2.8.2 that when looping over elements to calculate the contributions
to A and b that arise from integrals, we introduce incorrect entries into the rows where
the entries are given by Eqs. (3.42) and (3.46). We complete the assembly of the linear
system by overwriting these incorrect entries and assigning the correct entries defined
explicitly by Eqs. (3.42) and (3.46).
40 3 Linear Boundary Value Problems
The integrals given by Eqs. (3.59) and (3.60) cannot be evaluated explicitly for general
functions p(x), q(x), r (x), f (x). Even if the integrals can be evaluated analytically,
the integration may be tedious and time-consuming. Furthermore, if these functions
were altered, we would then need to evaluate these integrals again using the new
functions. Instead, we advise allocating this task to the computer, especially as a
simple, flexible technique exists for approximating these integrals, namely numerical
quadrature.
Suppose we wish to evaluate the integral
1
g(X ) dX,
0
which is of the form given by Eqs. (3.59) and (3.60). When using numerical quadra-
ture, the function g(X ) is evaluated at a collection of M points X 1 , X 2 , . . . , X M in
the interval 0 X 1, and the approximation to the integral is given by a weighted
sum of these function evaluations:
1
M
g(X ) dX wm g(X m ), (3.61)
0 m=1
Table 3.1 Gaussian quadrature points and weights for M = 1, 2, 3, 4 quadrature points
M =1 M =2 M =3 M =4
X m wm X m wm X m wm X m wm
2 1 2 1 2 1 7 + 7 5 72 18 30
1 1 1 1 1 3 5 1 3 2 6 1
2 1 2 5 18
3
1
2 1+ 1 1
2
1
2
4
9
1
2 1 3
7 2
7
6
5
1
72 18 + 30
3
1
2 1 + 35 5
18
1
2 1+ 3
7 2
7
6
5
1
72 18 + 30
1
2 1+ 3
7 + 2
7
6
5
1
72 18 30
The quadrature approximation given by Eq. (3.61) may now be used to approxi-
mate the integrals given by Eqs. (3.59) and (3.60) as follows: for i = 1, 2, j = 1, 2:
(k) (k)
M
1 dlocal,i dlocal, j
(k)
Alocal, i, j = h wm p(x + h X ) +
dX X =X m dX X =X m
k m
m=1
h2
(k)
1 (k) dlocal, j
q(xk + h X M )local,i (X M ) +
h dX X =X m
(k) (k)
r (xk + h X M )local,i (X M )local, j (X M ) , (3.62)
and for i = 1, 2:
(k)
M
(k)
blocal, i = h wm f (xk + h X M )local,i (X M ), i = 1, 2. (3.63)
m=1
In Chap. 2, we explained how to calculate the finite element solution of the simplest
possible boundary value problem. A summary of the tasks required when calculating
the finite element solution of this simple example was given in Sect. 2.9. In this
chapter, we have developed the material presented in Chap. 2 to allow calculation of
the finite element solution of a very general second-order boundary value problem. It
is worth revisiting the summary of tasks given in Sect. 2.9 at this point. We see that,
even for more general problems, this summary still forms a perfectly valid summary.
42 3 Linear Boundary Value Problems
u = e, x = 0.5, (3.65)
du
x = 5e2 , x = 1. (3.66)
dx
The boundary value problem above has solution
u(x) = ex K 1 + K 2 x 3 + e2x x 2 2x + 2 ,
where
32 e
K 1 = 3e 3e + ,
31 4
8 e
K2 = 3e + .
31 4
The boundary value problem above may be related to the general differential equation
and boundary conditions given by Eq. (3.1)(3.3) by setting
p(x) = x,
q(x) = (2x + 3),
r (x) = x + 2,
f (x) = x 3 e2x ,
u a = e, (3.67)
b = 5e2 . (3.68)
A Matlab function for implementing the finite element method to solve the
boundary value problem defined by Eqs. (3.64)(3.66) is given in Listing 3.1. This
function follows the outline for calculating a finite element solution given in Sect. 2.9,
3.7 Computational Implementation 43
and variable names follow the mathematical notation used in Chaps. 2 and 3. One
difference to the implementation given in Sect. 2.9 is the input required to the Matlab
function. In this chapter, we have not assumed that the nodes are equally spaced, and
specifying only the number of elements N is no longer sufficient to define the mesh
and basis functions. Instead, the vector of nodes used in the mesh is required as
input. If N elements are used, this vector will contain N + 1 nodes. The vector of
nodes supplied as input to the function is assumed to satisfy the conditions on the
mesh set out in Sect. 3.3.1, that is (i) x1 = a, (ii) x N +1 = b and (iii) xk+1 > xk for
k = 1, 2, . . . , N . The function returns the vector U that specifies the finite element
solution at each node.
We now give a commentary on how the Matlab function in Listing 3.1 imple-
ments the material presented in this chapter. After taking a suitable vector of nodes,
x, we then define the functions p(x), q(x), r (x), f (x), the value of the Dirichlet
boundary condition, u a , and the value of the Neumann boundary condition, b , in
lines 49 of the listing. The number of nodes in the mesh is equal to length of the
vector x. The number of elements, N , will be one less than the number of nodes:
the value of N is set in line 12. After initialising all entries of A and b to zero in
lines 15 and 16, we then loop over the elements in lines 2026 calculating the local
contributions to A and b from each element, before incrementing the global matrix
A and global vector b appropriately. The local contributions on each element are
calculated using the function CalculateContributionOnElement which is
defined in lines 4589 of the listing. In this function, we first deduce the element
length, h, in line 49. We define the quadrature scheme we are usingthat is, the
number of quadrature points M, the weights and the quadrature pointsin lines 52
(k) (k)
54. We initialise the local contributions to Alocal and blocal to zero in lines 5758 and
(k) (k)
then use this quadrature scheme to calculate the entries of Alocal and blocal , given by
Eqs. (3.62) and (3.63), by looping over the quadrature points in lines 6189. Inside
this loop, we first evaluate the local basis functions, local,1 , local,2 , the derivatives
of the local basis functions and the functions p(x), q(x), r (x), f (x) at each quadra-
(k) (k)
ture point, before using these values to increment the entries of Alocal and blocal by
weighting the contributions according to the quadrature rule.
Returning to the main body of code, the contribution from the Neumann boundary
condition at x = 1 is added into b N +1 in line 30 using the value of b given by
Eq. (3.68), before the Dirichlet boundary condition at x = 0.5 is imposed in lines 33
35 using the value of u a given by Eq. (3.67). Finally, the linear system is solved in
line 38, before the finite element solution is plotted in lines 3941.
This Matlab function may be called by typing, for example,
U = Chap3_CalculateFemForBvp(linspace(0.5, 1, 101));
into a Matlab session to use a computational mesh with 101 nodes (and, therefore,
100 elements) with the nodes equally spaced between 0.5 and 1.
44 3 Linear Boundary Value Problems
In Sect. 3.1, we defined a general second-order differential equation, Eq. (3.1), that
was subject to one Dirichlet boundary condition, Eq. (3.2), and one natural Neumann
boundary condition, Eq. (3.3). Many boundary value problems can be written in the
form of Eq. (3.1), subject to some combination of Dirichlet and Neumann boundary
conditions, and so this can be thought of as a reasonably general boundary value
problem. There is, however, a third variety of boundary conditionknown as a
Robin boundary conditionthat relates both the function value and the derivative
of the function on the boundary.
We demonstrate how Robin boundary conditions may be handled by the finite
element method using a slight modification of the boundary value problem given in
Sect. 3.1. We use the differential equation given by Eq. (3.1) on the interval a < x < b
and the Dirichlet boundary condition at x = a given by Eq. (3.2). Rather than using
46 3 Linear Boundary Value Problems
the Neumann boundary condition given by Eq. (3.3), we specify a Robin boundary
condition at x = b. The differential equation and boundary conditions are then given
by
d du du
p(x) + q(x) + r (x)u = f (x), (3.69)
dx dx dx
u = ua , x = a, (3.70)
du
p(x) + u = b , x = b, (3.71)
dx
where p(x), q(x), r (x), f (x) are given functions, and u a , b , are given constants.
As before, the first step when computing the finite element solution of Eqs. (3.69)
(3.71) is to write the problem in weak form. We have a Dirichlet boundary condition
at x = a, and so the space H01 (a, b) for this boundary value problem comprises
those functions v(x) H 1 (a, b) that also satisfy v(a) = 0. We then proceed as
in Sect. 3.2.2. We multiply the given differential equation by a test function v(x)
H01 (a, b) and integrate over the interval a < x < b. After integrating by parts, we
obtain
b b
du b du dv du
p v + p + q v + r uv dx = f v dx.
dx a a dx dx dx a
Using v(a) = 0 (a consequence of v(x) H01 (a, b)) and the Robin boundary condi-
tion, Eq. (3.71), the equation above may be written as
b b
du dv du
p + q v + r uv dx + u(b)v(b) = f v dx + b v(b). (3.72)
a dx dx dx a
find u(x) HE1 (a, b) such that Eq. (3.72) holds for all v(x) H01 (a, b),
where as defined by Eq. (3.10), HE1 (a, b) is the set of u(x) H 1 (a, b) that also
satisfy the Dirichlet boundary condition given by Eq. (3.70).
3.8 Robin Boundary Conditions 47
Having derived the weak solution, we then specify the set S h , and the subsets of this
set S Eh and S0h , as in Sect. 3.3.2. We then define the finite element solution, U (x), of
Eqs. (3.69)(3.71) by
The only difference between Eq. (3.73) and the finite element solution given by
Eq. (3.35) is the extra term U (b)i (b) on the left-hand side of Eq. (3.73). This extra
term is straightforward to handle: using Eq. (3.18), we see that
1, i = N + 1,
i (b) =
0, i = N + 1,
and so this term will contribute only to row N + 1 of the linear system. Furthermore,
using Eq. (3.20),
U (b) = U (x N +1 ) = U N +1 .
The extra term in Eq. (3.73) therefore adds an extra term U N +1 to the left-hand side
of equation generated by using i = N +1 in Eq. (3.73), that is row N + 1 of the
linear system given by Eq. (3.41). This may be implemented very easily by adding
the quantity to the value of A N +1,N +1 defined earlier by Eq. (3.43).
In this chapter, we have set out the theory necessary to apply the finite element method
to a general linear, second-order, boundary value problem. We have not yet, however,
said anything about whether the finite element solution is a good approximation to
the true solution, or how this approximation improves as the number of elements in
the mesh is increased. We now providewithout proofa theorem on the accuracy
of the finite element solution.
Theorem 3.1 Let p(x), q(x), r (x), f (x) be functions such that p(x), q(x), r (x),
f (x) and ddxp are continuous functions on the interval a < x < b. Suppose the
second-order differential equation, defined on a < x < b, and given by
48 3 Linear Boundary Value Problems
d du du
p(x) + q(x) + r (x)u = f (x),
dx dx dx
has a unique solution, subject to suitable given Dirichlet, Neumann or Robin bound-
ary conditions. Let U (x) be the finite element solution, calculated on a uniform mesh
of elements of length h, that is a linear approximation to the solution on each element.
Define the error, E(x), by
There then exists a constant C > 0, independent of the mesh used, such that, as the
element size h 0, the error satisfies
E L 2 = Ch 2 .
The constant C that appears in Theorem 3.1 is not easy to obtain. If C is not
known, the reader may ask, quite reasonably, what the purpose of this error bound
is. There is a very compelling answer to this question. Suppose we calculate the
finite element solution on a mesh of elements with constant length h 1 . Suppose we
then compute a second finite element solution on a mesh where each element of the
original mesh is divided into two, so that the length of each element in the new mesh
is h 2 = h 1 /2. As the error in the L 2 norm depends on h 2 , we see that halving the
element length will reduce the L 2 norm of the error to a quarter of its original value.
As such, we can use the error bound to assess the relative error between these two
finite element solutions.
The error bound in Theorem 3.1 may also be used to confirm the efficiency of
the implementation of the finite element method when it is used to solve a model
problem with known solution, as was first introduced in Exercise 2.2 at the end of
Chap. 2. Taking the logarithm of both sides of the error bound in Theorem 3.1 gives
we may easily compute E L 2 for a given h, using quadrature if the integration is
difficult, or impossible, to evaluate analytically. See Exercise 2.2 at the end of Chap. 2
for more details on performing this computation. Plotting log E L 2 against log h
for a range of values of h, we see, from Eq. (3.74), that this graph should have slope
2 as h 0. If this slope is less than 2, then the implementation is not optimal.
3.10 Exercises
3.1 In this exercise, we will develop code that may be used to calculate the finite
element solution of the boundary value problem, given by the differential equation
d du du
4 +8 + 5u = (sin x + 8 cos x) , < x < ,
dx dx dx
du
4 = 4, x = ,
dx
and one Dirichlet boundary condition
u = 2, x = ,
where and are constants. This boundary value problem has solution
x ( + 1 2e2 ) x
u(x) = 2ex e sin + cos + sin x.
2 e 2
You may want to develop your code for calculating the finite element solution in
the subparts below based on the overview of the steps required given in Sect. 2.9,
and Listing 3.1.
The integrals required to assemble the global linear system for this example prob-
lem may all be evaluated analytically without too much difficulty. The reader may
decide for themselves whether to evaluate these integrals analytically, or to approx-
imate them numerically using Gaussian quadrature.
(a) Write down the weak formulation of the boundary value problem. Be sure to state
clearly how the Dirichlet boundary conditions are handled, and what conditions
are required on the test functions.
(b) Define the finite element solution and the linear system that determines the
coefficients of the basis functions in the finite element solution.
(c) Write code to calculate the finite element solution of the boundary value problem
in the case where = 0 and = 0. Note that some terms appearing in the linear
system do not need to be computed for these values of and .
50 3 Linear Boundary Value Problems
(d) Extend the code you wrote in part (c) so that it may be used to calculate the finite
element solution of the boundary value problem in the case where = 5 and
= 0.
(e) Extend the code you wrote in part (d) so that it may be used to calculate the finite
element solution of the boundary value problem in the case where = 5 and
= 1.
(f) Investigate the use of a nonuniform mesh with the code that you wrote for part
(e).
In parts (c)(f) above be sure to validate your finite element solution by comparison
with the true solution.
for constants K 1 and K 2 that are determined from the boundary conditions. We will
now consider different selections of boundary conditions and derive the finite element
solution in each case. Remember that the weak formulation will change when the
boundary conditions are changed.
We suggest that the reader uses Gaussian quadrature to approximate the integrals
required to assemble the global linear system in this exercise.
(a) Compute the finite element approximation to the differential equation when u(x)
satisfies the Dirichlet boundary conditions
u(0) = 2, u( ) = 1 + .
In this case, the constants K 1 , K 2 that appear in the general solution are given
by
1 2e 1
K1 = , K2 = .
1 e 1 e
Check that your finite element solution is correct by comparison with the true
solution.
Calculate the finite element solution on several uniform meshes, and calculate
the L 2 norm of the error for each mesh. Confirm the result of Theorem 3.1,
3.10 Exercises 51
namely that the graph of log E L 2 against log h, where h is the element size,
has slope 2 as h 0.
(b) Compute the finite element approximation to the differential equation when u(x)
satisfies one Dirichlet boundary condition:
u = 0, x = 0,
du
(1 + x)2 = 0, x = .
dx
In this case, the constants K 1 , K 2 that appear in the general solution are given
by
2 1+ 2 1+
K1 = , K2 = .
1 + e (1 + 2 ) 1 + e (1 + 2 )
Check that your finite element solution is correct by comparison with the true
solution.
Calculate the finite element solution on several uniform meshes, and calculate
the L 2 norm of the error for each mesh. Confirm the result of Theorem 3.1, as in
part (a).
3.3 Calculate the finite element solution of the partial differential equation
d2 u
u = 0, 0 < x < 1,
dx 2
subject to one Robin boundary condition:
du
+ u = 2, x = 0,
dx
and one Dirichlet boundary condition:
u = e, x = 1.
Confirm your finite element solution is correct by comparison with the true solution,
u = ex .
u(x, y) = 0, x 2 + y 2 = 1.
This partial differential equation may be written in, cylindrical polar coordinates, as
the ordinary differential equation
1 d du
r = 1, (3.76)
r dr dr
du
= 0, r = 0, (3.77)
dr
u = 0, r = 1, (3.78)
1
u(x, y) = 1 x 2 y2 .
4
By writing Eq. (3.76) in the form of Eq. (3.1), calculate the finite element solution
of Eqs. (3.76)(3.78). Verify that your solution is correct by comparison with the true
solution.
3.5 There is no guarantee that a solution exists to a general boundary value problem.
Furthermore, if a solution does exist, then it may not be unique. Should we attempt
to compute the finite element solution to a boundary value problem without a unique
solution, we would anticipate problems. In this exercise, we investigate this concept
using a simple example. The differential equation
d2 u
+ u = 0, 0 < x < ,
dx 2
has general solution u(x) = K 1 sin x + K 2 cos x, where K 1 , K 2 are constants deter-
mined from the boundary conditions.
u(0) = u( ) = 0,
the differential equation has the nonunique solution u(x) = K 1 sin x for any
constant K 1 . Attempt to calculate the finite element solution to this boundary
value problem. How does the solution vary with the number of elements N ?
3.10 Exercises 53
u(0) = 1, u( ) = 0,
the differential equation has no solution. Attempt to calculate the finite element
solution to this boundary value problem. How does the solution vary with the
number of elements N ?
Chapter 4
Higher Order Basis Functions
We claimed, in Chap. 1, that the finite element method is a very flexible technique for
calculating the numerical solution of differential equations. One justification for this
claim is that the finite element method allows the solution of a differential equation to
be approximated, on each element of the computational mesh, using a polynomial of
any degree chosen by the user. The material presented in earlier chapters of this book
has focused entirely on finite element solutions that are linear approximations on
each element. In this chapter, we extend this material to allow a general polynomial
approximation on each element.
The key to defining higher order global basis functions is to provide a mapping
between each element of the mesh and a canonical element, and to specify local
basis functions of the required degree on this canonical element. This approach was
introduced for linear basis functions in Chap. 3, and in this chapter, we will show
how it may be extended to higher order basis functions.
for given functions p(x), q(x), r (x) and f (x), where p(x) = 0 for a < x < b,
subject to a Dirichlet boundary condition at x = a:
u = ua , x = a, (4.2)
Springer International Publishing AG 2017 55
J. Whiteley, Finite Element Methods, Mathematical Engineering,
DOI 10.1007/978-3-319-49971-0_4
56 4 Higher Order Basis Functions
du
p(x) = b , x = b, (4.3)
dx
for a given constant b .
The first step when calculating a finite element solution of a differential equation
is to derive the weak formulation of the differential equation. This step is independent
of the basis functions used and will therefore be identical to that derived in Sect. 3.2.2,
re-stated below:
We now describe how to calculate the finite element solution of the model boundary
value problem, using a quadratic approximation to the solution on each element.
The nodes and elements for a suitable computational mesh are illustrated in Fig. 4.1.
We now define quadratic basis functions on the mesh illustrated in Fig. 4.1. We follow
the same approach as in Sect. 3.3.2.2 and specify global basis functions through local
basis functions defined on the canonical element 0 X 1.
As element k occupies the interval x2k1 x x2k+1 , a suitable change of vari-
able that maps between element k and the canonical element is given by
These local basis functions are illustrated in Fig. 4.2. We now define the global basis
functions on element k by:
Fig. 4.1 The nodes and elements for a mesh that may be used to calculate a finite element solution
that is a quadratic approximation to the true solution on each element. Nodes on the boundary of
an element are denoted by a filled circle, and nodes in the interior of an element are denoted by an
open circle
58 4 Higher Order Basis Functions
local,1(X)
1.2 local,2(X)
local,3(X)
1
0.8
0.6
0.4
0.2
0.2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
X
Fig. 4.2 The local basis functions local,1 (X ), local,2 (X ) and local,3 (X ) defined by Eqs. (4.7)
(4.9)
j (X ) = 0, 0 X 1, j = 2k 1, j = 2k, j = 2k + 1.
(4.13)
(x2k x)(x2k+1 x)
2k1 (x) = , (4.14)
(x2k x2k1 )(x2k+1 x2k1 )
(x x2k1 )(x2k+1 x)
2k (x) = , (4.15)
(x2k x2k1 )(x2k+1 x2k )
(x x2k1 )(x x2k )
2k+1 (x) = , (4.16)
(x2k+1 x2k1 )(x2k+1 x2k )
j (x) = 0, j = 2k 1, j = 2k, j = 2k + 1. (4.17)
The basis functions 2k1 (x), 2k (x), 2k+1 (x) are plotted in Fig. 4.3. We note
that the global basis functions fall into two categories. The first category contains
basis functions such as 2k1 (x) and 2k+1 (x) that are nonzero in two neighbouring
4.2 Quadratic Basis Functions 59
(x)
2k1
(x)
2k
1
2k+1
(x)
elements. The second category is the basis functions such as 2k (x) that are nonzero
in only one element.
Using Eqs. (4.14)(4.17) we see that, on element k,
and, if j = 2k 1, j = 2k and j = 2k + 1,
As this is true for all elements, we may deduce that, for all basis functions j (x),
j = 1, 2, . . . , 2N + 1, we have:
1, i = j,
j (xi ) = (4.22)
0, i = j,
60 4 Higher Order Basis Functions
and so the quadratic global basis function j (x) takes the value 1 at the node where
x = x j , and the value zero at all other nodes.
In Chap. 3, we defined the set S h through the linear basis functions specified in
Sect. 3.3.2. We now modify the definition of this set to take account of the quadratic
basis functions specified in Sect. 4.2.2. The set S h is now defined to be those functions
V (x) that can be written in the form
2N +1
V (x) = V j j (x), (4.23)
j=1
where j (x), j = 1, 2, . . . , 2N + 1, are the quadratic basis functions that are given
by Eqs. (4.6)(4.13). The subsets S Eh and S0h of the set S h are then defined in a similar
manner to Sect. 3.3.3: the set S Eh contains functions of the form given by Eq. (4.23)
that satisfy all Dirichlet boundary conditions, and the set S0h contains functions of
the form given by Eq. (4.23) that take the value zero at all points where Dirichlet
boundary conditions are applied.
Having defined the sets S Eh and S0h , we may now define the finite element solution,
U (x), by the following modification of the weak solution given by Eq. (4.4):
We write our finite element solution as a linear sum of the basis functions defined by
Eqs. (4.6)(4.13):
2N +1
U (x) = U j j (x), (4.25)
j=1
and note that U (x), as written above, lies in the set S h defined in Sect. 4.2.3. Using
Eq. (4.22), we have
4.2 Quadratic Basis Functions 61
U (xi ) = Ui , i = 1, 2, . . . , 2N + 1, (4.26)
U1 = u a , (4.27)
2N +1 b b
d j di d j
p +q i + r j i dx U j = f i dx + b i (b),
j=1 a dx dx dx a
(4.28)
for i = 2, 3, . . . , 2N + 1.
When defining the mesh in Sect. 4.2.1, we set x2N +1 = b. Using Eq. (4.22), we
may write
i (b) = i (x2N +1 )
1, i = 2N + 1,
= (4.29)
0, i = 2N + 1,
Equations (4.27) and (4.28) specify the required 2N + 1 equations for the 2N + 1
unknown U j , j = 1, 2, . . . , 2N + 1, that appear in the expression for U (x) given by
Eq. (4.25). These equations may be written as the linear system
AU = b, (4.30)
where, for j = 1, 2, . . . , 2N + 1,
1, j = 1,
A1, j = (4.31)
0, j = 1,
b
di d j d j
Ai, j = p + qi + r i j dx, i = 2, 3, . . . , 2N + 1, (4.32)
a dx dx dx
and
b1 = u a , (4.33)
b
bi = f i dx, i = 2, 3, . . . , 2N , (4.34)
a
b
b2N +1 = f 2N +1 dx + b . (4.35)
a
We will assemble the system of algebraic equations given by Eq. (4.30) in the same
spirit as in Sect. 3.4, when linear basis functions were used. We first calculate entries
of the form given by Eqs. (4.32), (4.34) and (4.35) that require the evaluation of
integrals of known functions over the whole domain a < x < b. These integrals
are evaluated by decomposing them into the sum of contributions from individual
elements. Remembering that element k occupies the region x2k1 x x2k+1 , we
may write Eq. (4.32) as, for i = 2, 3, . . . , 2N + 1, j = 1, 2, . . . , 2N + 1:
N
x2k+1
di d j d j
Ai, j = p + qi + r i j dx, (4.36)
k=1 x2k1 dx dx dx
N
x2k+1
bi = f i dx, i = 2, 3, . . . , 2N , (4.37)
k=1 x2k1
N
x2k+1
b2N +1 = f 2N +1 dx + b . (4.38)
k=1 x2k1
4.2 Quadratic Basis Functions 63
Having calculated these entries, we complete the assembly of the linear system by
setting entries defined by Eqs. (4.31) and (4.33) that are given by explicit expressions.
We now describe the assembly of both categories of entry in more detail.
We now explain how to evaluate the contributions to Eqs. (4.36)(4.38) from indi-
vidual elements. When evaluating local contributions from individual elements in
Sect. 3.4.1, when linear basis functions were used, we noted that only two basis func-
tions were nonzero on each element. Nonzero contributions from element k to the
(k)
global matrix A and global vector b were then stored in a local matrix Alocal of size
(k)
2 2, and a local vector blocal with two entries. We take a similar approach here.
The contributions from element k to Eq. (4.36) are given by, for i = 2, 3, . . . ,
2N + 1, j = 1, 2, . . . , 2N + 1:
x2k+1
di d j d j
p + qi + r i j dx.
x2k1 dx dx dx
The only basis functions that are nonzero on element k are the three basis functions
2k1 , 2k and 2k+1 . The integral above is therefore zero, unless both i and j take
one of the values 2k 1, 2k or 2k + 1. We may therefore store the nonzero local
(k)
contributions to Eq. (4.36) from element k in the 3 3 matrix Alocal . The relationship
between the indices of the entries in this local matrix, and the indices of the entries
in the global matrix A that they contribute to, is given in Table 4.1.
Similarly, the contributions from element k to Eqs. (4.37) and (4.38) are given by,
for i = 2, 3, . . . , 2N + 1:
N
x2k+1
f i dx.
k=1 x2k1
Table 4.1 The relationship between the location of the entries of A(k) (k)
local and blocal , and the location
of the entries of A and b that they contribute to, when quadratic basis functions are used
Local index Global index
1 2k 1
2 2k
3 2k + 1
64 4 Higher Order Basis Functions
entries in this local vector, and the indices of the entries in the global vector b that
they contribute to, is given in Table 4.1.
(k) (k)
The entries of Alocal and blocal are given below.
x2k+1
(k) d2k1 d2k1 d2k1
Alocal, 1,1 = p + q2k1 + r 2k1 2k1 dx,
x2k1 dx dx dx
x2k+1
(k) d2k1 d2k d2k
Alocal, 1,2 = p + q2k1 + r 2k1 2k dx,
x2k1 dx dx dx
x2k+1
(k) d2k1 d2k+1 d2k+1
Alocal, 1,3 = p + q2k1 + r 2k1 2k+1 dx,
x dx dx dx
2k1
x2k+1
(k) d2k d2k1 d2k1
Alocal, 2,1 = p + q2k + r 2k 2k1 dx,
x2k1 dx dx dx
x2k+1
(k) d2k d2k d2k
Alocal, 2,2 = p + q2k + r 2k 2k dx,
x2k1 dx dx dx
x2k+1
(k) d2k d2k+1 d2k+1
Alocal, 2,3 = p + q2k + r 2k 2k+1 dx,
x2k1 dx dx dx
x2k+1
(k) d2k+1 d2k1 d2k1
Alocal, 3,1 = p + q2k+1 + r 2k+1 2k1 dx,
x dx dx dx
2k1
x2k+1
(k) d2k+1 d2k d2k
Alocal, 3,2 = p + q2k+1 + r 2k+1 2k dx,
x2k1 dx dx dx
x2k+1
(k) d2k+1 d2k+1 d2k+1
Alocal, 3,3 = p + q2k+1 + r 2k+1 2k+1 dx,
x dx dx dx
2k1
x2k+1
(k)
blocal, 1 = f 2k1 dx,
x2k1
x2k+1
(k)
blocal, 2 = f 2k dx,
x2k1
x2k+1
(k)
blocal, 3 = f 2k+1 dx.
x2k1
As with the integrals over each element that arose in Chap. 3 when linear basis
functions were used, there is no guarantee that the integrals above may be evaluated
analytically. Even if analytic evaluation is possible, it may require much tedious,
error-prone algebra. As such, it is often necessary, or desirable, to approximate these
integrals using numerical quadrature, as described in Sect. 3.5. When approximating
these integrals over element k using quadrature, we will use the change of variable
given by Eq. (4.6), which we now write as
x = x2k1 + h X, 0 X 1, (4.39)
4.2 Quadratic Basis Functions 65
where h = x2k+1 x2k1 . Using the change of variable given by Eq. (4.39), and the
(k)
definition of global basis functions given by Eqs. (4.6)(4.13), the entries of Alocal
(k)
and blocal may be written as
1
(k) 1 dlocal, i dlocal, j
Alocal, i, j = h 2
p(x2k1 + h X ) +
0 h dX dX
1 dlocal, j
q(x2k1 + h X )local, i (X ) +
h dX
r (x2k1 + h X )local, i (X )local, j (X ) dX, i, j = 1, 2, 3, (4.40)
1
(k)
blocal, i =h f (x2k1 + h X )local, i (X ) dX, i = 1, 2, 3. (4.41)
0
The final task when assembling the system of algebraic equations given by Eq. (4.30)
is to set the entries that are given by Eqs. (4.31) and (4.33). We explained in Sect. 2.8.2
that, when computing the entries of the linear system that are given by equations
such as Eqs. (4.32), (4.34) and (4.35) using the method described in Sect. 4.2.5.1,
incorrect entries would be entered into the rows of the linear system where equations
such as Eqs. (4.31) and (4.33) apply. We therefore have to ensure that these entries
are overwritten by the correct entries.
u = e, x = 0.5, (4.43)
du
x = 5e2 , x = 1. (4.44)
dx
This boundary value problem has solution
u(x) = ex K 1 + K 2 x 3 + e2x x 2 2x + 2 ,
where
32 e
K 1 = 3e 3e + ,
31 4
8 e
K2 = 3e + .
31 4
This boundary value problem may be related to the model problem defined by
Eqs. (4.1)(4.3) by writing
p(x) = x,
q(x) = (2x + 3),
r (x) = x + 2,
f (x) = x 3 e2x ,
u a = e,
b = 5e2 .
A Matlab implementation is given in Listing 4.1. This listing uses the same
pattern as in earlier chapters, where variable names follow the notation used in this
chapter.
The Matlab function requires an array x_ele_bound as input. This array
should contain only the nodes on the boundary of elements, and the entries should
be listed in ascending order. Thus, if N elements are used, the array should be of
length N + 1. The first entry should take the value 0.5, i.e. the value of x at the left
hand boundary, and the last entry should take the value 1, i.e. the value of x at the
right hand boundary. The function then returns a vector x that contains all nodes in
the mesh, and a vector U that contains the finite element solution at each node. The
function may be called by typing, for example,
4.2 Quadratic Basis Functions 67
x_ele_bound = linspace(0.5,1,101);
[x, U] = Chap4_CalculateQuadraticFemForBvp(x_ele_bound);
into a Matlab session. This will calculate the finite element solution on a mesh with
100 equally sized elements.
The functions p(x), q(x), r (x), f (x) and the values u a , b are defined in lines 5
10 of the listing. Noting that the vector x_ele_bound contains N + 1 nodes, where
N is the number of elements, we set the number of elements in line 13. There will be
2N + 1 nodes in the mesh, and so we allocate the appropriate memory for the vector
of nodes x in line 16. The nodes x2k1 , k = 1, 2, . . . , N + 1, are the entries of the
vector x_ele_boundthese are set in line 19. The nodes x2k , k = 1, 2, . . . , N ,
are the midpoints of the elementsthese are set in line 22. We then initialise the
entries of the global matrix A and vector b to zero in lines 25 and 26, before looping
over all elements in lines 3037 to first calculate the local contributions to A and b,
and then increment A and b appropriately.
The local contributions to both A and b from each element are calculated using
the function CalculateContributionOnElement given by lines 58102 of
the listing. This function first calculates the length of the interval in line 62 before
setting the number of Gaussian quadrature points, the quadrature points and the
quadrature weights in lines 6567. The entries of the local contributions to A and
b are initialised to zero in lines 7071. We then loop over all Gaussian quadrature
points in lines 74102. At each Gauss point, we calculate the value of all functions
appearing in Eqs. (4.40) and (4.41) in lines 7885. We then loop over all entries of
the nonzero local contributions to the linear system, incrementing each entry with
the appropriate weighting from the Gaussian quadrature scheme.
Returning to the main function, we handle the Neumann boundary conditions in
line 41, and the Dirichlet boundary conditions using lines 4446. Finally, we solve
the linear system in line 49, before plotting the solution using lines 5254. Note that
the solution plotted is not exactly the finite element solutionline 52 of the code
simply joins successive points in the mesh using a straight line, rather than plotting
the quadratic approximation to the solution on each element. We leave plotting the
finite element solution as a quadratic approximation on each element as an exercise
for the reader.
13 N = l e n g t h ( x _ e l e _ b o u n d ) -1;
14
15 % A l l o c a t e m e m o r y for nodes
16 x = zeros (2* N +1 , 1);
17
18 % Define nodes on edge of e l e m e n t s
19 x ( 1 : 2 : 2 * N +1) = x _ e l e _ b o u n d ;
20
21 % Define nodes at c e n t r e of e l e m e n t s
22 x ( 2 : 2 : 2 * N ) = 0 . 5 * ( x ( 1 : 2 : 2 * N -1) + x ( 3 : 2 : 2 * N + 1 ) ) ;
23
24 % I n i t i a l i s e A and b to zero
25 A = zeros (2* N +1 , 2* N +1);
26 b = zeros (2* N +1 , 1);
27
28 % Loop over e l e m e n t s c a l c u l a t i n g local c o n t r i b u t i o n s and
29 % i n s e r t i n g into linear s y s t e m
30 for k = 1: N
31 [ A_local , b _ l o c a l ] = ...
32 C a l c u l a t e C o n t r i b u t i o n O n E l e m e n t ( x , k , p , q , r , f );
33
34 A (2* k -1:2* k +1 , 2* k -1:2* k +1) = ...
35 A (2* k -1:2* k +1 , 2* k -1:2* k +1) + A _ l o c a l ;
36 b (2* k -1:2* k +1) = b (2* k -1:2* k +1) + b _ l o c a l ;
37 end
38
39 % Add c o n t r i b u t i o n s from N e u m a n n b o u n d a r y c o n d i t i o n s into
40 % linear system
41 b (2* N +1) = b (2* N +1) + eta_b ;
42
43 % Set D i r i c h l e t b o u n d a r y c o n d i t i o n s in row 1
44 A (1 ,:) = 0;
45 A (1 ,1) = 1;
46 b (1) = u_a ;
47
48 % Solve linear system
49 U = A\b;
50
51 % Plot finite e l e m e n t s o l u t i o n
52 plot ( x , U , - o )
53 xlabel ( x )
54 ylabel ( U )
55
56
57
58 f u n c t i o n [ A_local , b _ l o c a l ] = ...
59 C a l c u l a t e C o n t r i b u t i o n O n E l e m e n t (x , k , p , q , r , f )
60
61 % Calculate element length
62 h = x (2* k +1) - x (2* k -1);
63
64 % D e f i n e q u a d r a t u r e rule
65 M = 3;
66 Q u a d W e i g h t s = [5/18 , 4/9 , 5 / 1 8 ] ;
67 Q u a d P o i n t s = [0.5*(1 - sqrt (0.6)) , 0.5 , 0 . 5 * ( 1 + sqrt ( 0 . 6 ) ) ] ;
68
69 % I n i t i a l i s e local c o n t r i b u t i o n s to A and b to zero
70 A _ l o c a l = zeros (3 ,3);
71 b _ l o c a l = zeros (3 ,1);
72
73 % Loop over q u a d r a t u r e p o i n t s
74 for m = 1: M
75 X = Q u a d P o i n t s ( m );
4.2 Quadratic Basis Functions 69
76
77 % E v a l u a t e local basis f u n c t i o n s and their d e r i v a t i v e s
78 p h i _ l o c a l = [2*(1 - X )*(0.5 - X ) , 4* X *(1 - X ) , 2* X *( X - 0 . 5 ) ] ;
79 p h i _ p r i m e _ l o c a l = [4* X -3 , 4 -8* X , 4* X -1];
80
81 % E v a l u a t e p , q , r , f at q u a d r a t u r e p o i n t s
82 p_val = p ( x (2* k -1)+ h * X );
83 q_val = q ( x (2* k -1)+ h * X );
84 r_val = r ( x (2* k -1)+ h * X );
85 f_val = f ( x (2* k -1)+ h * X );
86
87 % I n c r e m e n t e n t r i e s of A _ l o c a l and b _ l o c a l
88 % with s u i t a b l y w e i g h t e d f u n c t i o n e v a l u a t i o n s
89 for i =1:3
90 for j =1:3
91 A _ l o c a l (i , j ) = A _ l o c a l (i , j ) + ...
92 h * Q u a d W e i g h t s ( m )*( ...
93 p_val / h / h * p h i _ p r i m e _ l o c a l ( i )* ...
94 p h i _ p r i m e _ l o c a l ( j ) + ...
95 q_val / h * p h i _ l o c a l ( i )* ...
96 p h i _ p r i m e _ l o c a l ( j ) + ...
97 r_val * p h i _ l o c a l ( i )* p h i _ l o c a l ( j ));
98 end
99 b _ l o c a l ( i ) = b _ l o c a l ( i ) + h * Q u a d W e i g h t s ( m )* ...
100 f_val * p h i _ l o c a l ( i );
101 end
102 end
We have seen that the assembly of the system of algebraic equations that deter-
mines the finite element solution requires the evaluation of many integrals over the
whole computational domain. Throughout this book, we evaluate the integrals by
first calculating the nonzero contributions from each element, before adding these
local contributions into the global matrix A and global vector b. These integrals may
not, in general, be evaluated analytically and are usually computed using Gaussian
quadrature. It should be noted that increasing the order of the approximating poly-
nomial on each element increases the overall degree of the function that is being
integrated. As a consequence, more quadrature points may be needed to evaluate
these integrals sufficiently accurately.
to the solution on each element. In this section, we explain, albeit in less detail, how
to calculate a finite element solution that is a cubic approximation to the solution on
each element. The key ingredients required that we do not already have are a suitable
computational mesh, and cubic basis functions defined on this mesh. We again use
the boundary value problem given by Eqs. (4.1)(4.3) when explaining how cubic
basis functions may be used.
We again partition the computational domain a < x < b into N elements. A cubic
approximation to the solution on each element requires that every element contains
four nodes. Two of these nodes will be the end-points of these elements. The other
two nodesthe interior nodeswill be placed inside the element so that the four
nodes are uniformly spaced across the element. There will be a total of N + 1 nodes
at the end-points of the N elements, and a further 2N nodes in the interior of the
elements, giving a total of 3N + 1 nodes.
The nodes are numbered as follows. We demand that: (i) x1 = a; (ii) x3N +1 = b;
(iii) the nodes are listed in ascending order, so that x j+1 > x j for j = 1, 2, . . . , 3N ;
and (iv) the nodes contained in each element are uniformly spaced across the ele-
ment. Using this convention, element k, where k = 1, 2, . . . , N , occupies the region
x3k2 x x3k+1 , and the elements span the whole of the computational domain
a < x < b. Insisting that the interior nodes of element k, where k = 1, 2, . . . , N , are
uniformly spaced across the element implies that:
1
x3k1 = (2x3k2 + x3k+1 ) , (4.45)
3
1
x3k = (x3k2 + 2x3k+1 ) . (4.46)
3
An example mesh, that may be used to calculate a finite element solution that is
a cubic approximation to the solution on each element, is illustrated in Fig. 4.4.
Fig. 4.4 The nodes and elements of a finite element mesh that may be used to calculate a finite
element solution that is a cubic approximation on each element. Nodes on the boundary of an
element are denoted by a filled circle, and nodes in the interior of an element are denoted by an
open circle
4.3 Cubic Basis Functions 71
The quadratic basis functions used in Sect. 4.2 were defined in terms of local basis
functions defined on the canonical element 0 X 1. This approach may be
adapted to allow cubic basis functions to be defined. We first need a mapping between
element k of the mesh and the canonical element 0 X 1. As element k, where
k = 1, 2, . . . , N , occupies the region x3k2 x x3k+1 , we may map between this
element and the canonical element using the change of variable
These local basis functions are illustrated in Fig. 4.5. Global basis functions j (x),
j = 1, 2, . . . , 3N + 1, may now be defined using these local basis functions. On
element k, we define the global basis functions in terms of the local basis functions
by:
The basis functions 3k2 (x), 3k1 (x), 3k (x), 3k+1 (x) are shown in Fig. 4.6.
Using the global basis functions given by Eqs. (4.47)(4.56), and remembering
the location of interior nodes given by Eqs. (4.45) and (4.46), we may deduce the
following properties of these global basis functions on element k:
72 4 Higher Order Basis Functions
local,1(X)
1.6 local,2(X)
1.4 local,3(X)
local,4(X)
1.2
0.8
0.6
0.4
0.2
0.2
0.4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
X
Fig. 4.5 The local basis functions local,1 (X ), local,2 (X ), local,3 (X ) and local,4 (X ) defined by
Eqs. (4.48)(4.51)
(x)
3k2
(x)
3k1
1 (x)
3k
(x)
3k+1
x3k5 x3k4 x3k3 x3k2 x3k1 x3k x3k+1 x3k+2 x3k+3 x3k+4
x
Fig. 4.6 The basis functions 3k2 (x), 3k1 (x), 3k (x) and 3k+1 (x) defined by Eqs. (4.47)
(4.56)
4.3 Cubic Basis Functions 73
These properties of basis functions hold on all elements. Hence, these basis functions
satisfy the usual property that, for j = 1, 2, . . . , 3N + 1,
1, i = j,
j (xi ) = (4.57)
0, i = j.
We now explain how the cubic basis functions, defined in Sect. 4.3.2, may be used
to calculate the finite element solution of the boundary value problem given by
Eqs. (4.1)(4.3). The set S h is now defined to be those functions V (x) that can be
written as
3N +1
V (x) = V j j (x),
j=1
3N +1
U (x) = U j j (x), (4.59)
j=1
74 4 Higher Order Basis Functions
the specification of the finite element solution by Eq. (4.58) allows us to derive a sys-
tem of algebraic equations that determines the unknown values U1 , U2 , . . . , U3N +1 .
As usual, these equations are drawn from two sources: (i) equations that ensure that
the finite element solution is in the set S Eh , i.e. we insist that U (x) satisfies the Dirich-
let boundary conditions and (ii) the substitution of suitable test functions i (x) S0h
into Eq. (4.58).
There is one Dirichlet boundary condition, given by Eq. (4.2), and it is applied
at the node where x = x1 . Using Eqs. (4.57) and (4.59), we see that this equation is
satisfied if
U1 = u a . (4.60)
AU = b, (4.61)
where, for j = 1, 2, . . . , 3N + 1,
1, j = 1,
A1, j = (4.62)
0, j = 1,
b
di d j d j
Ai, j = p + qi + r i j dx, i = 2, 3, . . . , 3N + 1, (4.63)
a dx dx dx
and
b1 = u a , (4.64)
b
bi = f i dx, i = 2, 3, . . . , 3N , (4.65)
a
b
b3N +1 = f 2N +1 dx + b . (4.66)
a
We now give a very brief account of how the linear system given by Eq. (4.61) may
be assembled. We use the same strategy as in previous examples, and first compute
the entries, given by Eqs. (4.63), (4.65) and (4.66), that are defined by integrals over
the whole domain. Having computed these entries, we then complete the assembly
of A and b by setting the entries given by Eqs. (4.62) and (4.64).
4.3 Cubic Basis Functions 75
(k) (k)
Table 4.2 The relation between the location of the entries in Alocal and blocal , and the location of
the entries of A and b that they contribute to, when cubic basis functions are used
Local index Global index
1 3k 2
2 3k 1
3 3k
4 3k + 1
As in earlier examples, the entries of the linear system given by Eqs. (4.63), (4.65)
and (4.66) may be calculated efficiently by decomposing them into the sum of the
nonzero contributions from integrals over individual elements. We note that, on
element k, there are only four nonzero basis functions: 3k2 (x), 3k1 (x), 3k (x),
3k+1 (x). Using the relation between local and global indices given in Table 4.2, we
may store the nonzero contributions from element k to Eqs. (4.63), (4.65) and (4.66)
(k) (k)
in a 4 4 local matrix Alocal , and a local vector blocal with four entries. These local
contributions are given in terms of integrals over the canonical element by
1
(k) 1 dlocal, i dlocal, j
Alocal, i, j =h 2
p(x3k2 + h X ) +
0 h dX dX
1 dlocal, j
q((x3k2 + h X )local, i (x) +
h dX
r ((x3k2 + h X )local, i (X )local, j (X ) dX, i, j = 1, 2, 3, 4, (4.67)
1
(k)
blocal, i =h f (x3k2 + h X )local, i (X ) dX, i = 1, 2, 3, 4, (4.68)
0
where h = x3k+1 x3k2 , and the local basis functions are defined by Eqs. (4.47)
(4.56).
Entries of the linear system given by Eqs. (4.63), (4.65) and (4.66) may therefore
be calculated by looping over all elements, calculating the nonzero local contri-
butions from each element given by Eqs. (4.67) and (4.68), and adding these local
contributions into the global matrix A and global vector b. We then add the final
term required to assemble Eq. (4.66), before setting the entries given by Eqs. (4.62)
and (4.64).
The material presented in Sect. 4.2 on quadratic basis functions, and in Sect. 4.3 on
cubic basis functions, may easily be generalised to a polynomial approximation of
an arbitrary degree. We now give a very brief overview of how this may be done.
76 4 Higher Order Basis Functions
1
x(k1)+ j+1 = ( j)x(k1)+1 + j xk+1 , j = 1, 2, . . . , 1.
Global basis functions are again defined by: (i) defining a transformation between
element k and the canonical element 0 X 1; (ii) defining local basis functions
on the canonical element; and (iii) defining the global basis functions in terms of the
transformation and local basis functions.
Element k, where k = 1, 2, . . . , N , occupies the region x(k1)+1 x xk+1 .
A transformation between element k and the canonical element 0 X 1 is given
by
x = x(k1)+1 + xk+1 x(k1)+1 X, 0 X 1. (4.69)
i= j (X X i )
local, j (X ) = , j = 1, 2, . . . , + 1, (4.70)
i= j X j X i
where
i 1
Xi = , i = 1, 2, . . . , + 1,
and the expression i= j (X X i ) is defined by
4.4 General Basis Functions 77
i= j (X X i ) = (X X 1 ) (X X 2 ) . . . X X j1 X X j+1 . . . (X X +1 ) .
Using this definition of global basis functions, we may use Eq. (4.71) to deduce that,
for j = 1, 2, . . . , N + 1:
1, i = j,
j (xi ) =
0, i = j.
The set S h is now defined to be those functions V (x) that can be written as
N +1
V (x) = V j j (x),
j=1
Writing the finite element solution as the member of the set S h given by
N +1
U (x) = U j j (x),
j=1
78 4 Higher Order Basis Functions
We conclude this chapter by presenting a bound on the L 2 norm of the error of the
finite element solution when a general polynomial approximation is made to the
solution on each element.
Theorem 4.1 Let p(x), q(x), r (x), f (x) be functions such that p(x), q(x), r (x),
f (x) and ddxp are continuous functions on the interval a < x < b. Suppose the second
order differential equation, defined on a < x < b, and given by
d du du
p(x) + q(x) + r (x)u = f (x),
dx dx dx
has a unique solution, subject to suitable given Dirichlet, Neumann or Robin bound-
ary conditions. Let U (x) be the finite element solution, calculated on a uniform
mesh of elements of length h, using an approximating polynomial of degree to the
solution on each element. Define the error, E(x), by
There then exists a constant C > 0, independent of the mesh, such that, as the element
size h 0, the error satisfies
E L 2 = Ch +1 .
We see, from the theorem above, that if we increase the degree of the approxi-
mating polynomial by one, then the exponent of h in the error bound is increased by
4.5 Convergence of the Finite Element Solution 79
one. We also note that Theorem 3.1 is a special case of the theorem above, using the
value = 1.
4.6 Exercises
The exercises below are all based on the same boundary value problem as Exercise 3.1
from Chap. 3, with parameters = 5 and = 1, that is, the differential equation
d du du
4 +8 + 5u = sin x + 8 cos x, < x < ,
dx dx dx
du
4 = 20, x =
dx
and one Dirichlet boundary condition
u = 2, x = .
(a) Write down the weak formulation of the boundary value problem. State clearly
the sets that the weak solution and test functions lie in.
(b) Develop a computational implementation to calculate the finite element solution
of the boundary value problem that is a quadratic approximation to the solution on
each element. You may like to base this implementation on Listing 4.1. Confirm
that your implementation is correct by comparing the finite element solution
with the true solution.
(c) Write down an expression for the L 2 error of the finite element solution. Extend
your computational implementation so that it also outputs the L 2 error of the
finite element solution. Use your implementation to confirm the theoretical error
bound given by Theorem 4.1. If you are unsure how to do this, more details are
given in Exercise 2.2 from Chap. 2, and in Sect. 3.9.
80 4 Higher Order Basis Functions
The differential equations investigated in earlier chapters have all been linear differ-
ential equations. The finite element discretisation of these equations yielded systems
of linear algebraic equations that may be solved using established, robust and reliable
linear algebra techniques. In this chapter, we describe the application of the finite
element method to nonlinear boundary value problems.
The key difference when applying the finite element method to nonlinear differ-
ential equations, rather than linear differential equations, is that we must solve a
system of nonlinear algebraic equations. Finding the solution of a system of non-
linear algebraic equations is, in general, more challenging than for linear systems.
An extensive discussion of the existence and uniqueness of the solution of a general
system of nonlinear algebraic equations is beyond the scope of this book. We do,
however, provide an introduction to the computation of the solution in Section A.2
of Appendix A that will be sufficient for most finite element applications.
We introduce the finite element method for nonlinear differential equations
through the use of a simple example. We then present a discussion of how this
implementation may be extended for more general nonlinear differential equations.
Throughout this chapter, we calculate finite element solutions that are a linear approx-
imation to the solution on each element. We leave the use of higher order basis
functions, described in Chap. 4, as an exercise for the reader.
The implementation of the finite element method for nonlinear problems may be
demonstrated using the example nonlinear boundary value problem, defined by
d du
(1 + u 2 ) + 2(1 + x 4 ) + 8u 2 = 0, 1 < x < 2, (5.1)
dx dx
subject to one Dirichlet boundary condition and one natural Neumann boundary
condition:
u = 1, x = 1, (5.2)
du
(1 + u 2 ) = 68, x = 2. (5.3)
dx
As with linear differential equations, we begin by writing the boundary value problem
given by Eqs. (5.1)(5.3) in weak form using the Sobolev space, and subsets of
the Sobolev space, defined in Sect. 3.2.1. We multiply the differential equation by a
function v(x) H01 (1, 2) and integrate the resulting product over the computational
domain 1 < x < 2. After an application of integration by parts, we obtain
2
du 2 du dv
(1 + u 2 ) v + (1 + u 2 ) + 2(1 + x 4 )v + 8u 2 v dx = 0. (5.4)
dx 1 1 dx dx
Our boundary value problem specifies one Dirichlet boundary condition, Eq. (5.2),
that applies at x = 1. As v(x) H01 (1, 2), we have v(x) = 0 at any value of
x where a Dirichlet boundary condition is applied, and so v(1) = 0. Using this
condition on v(1), and the Neumann boundary condition given by Eq. (5.3), we
may write Eq. (5.4) as
2
du dv
(1 + u 2 ) + 2(1 + x 4 )v + 8u 2 v dx 68v(2) = 0.
1 dx dx
So far we have used the differential equation, Eq. (5.1), and the Neumann bound-
ary condition, Eq. (5.3). We have not yet used the Dirichlet boundary condition, other
than to ensure that test functions v(x) lie in the appropriate set of functions. We com-
plete the weak formulation by insisting that the weak solution satisfies the Dirichlet
boundary condition, given by Eq. (5.2). The weak solution of Eqs. (5.1)(5.3) is then
given by:
find u(x) H E1 (1, 2) such that
5.1 A First Example 83
2 du dv
(1 + u 2 ) + 2(1 + x 4 )v + 8u 2 v dx 68v(2) = 0, (5.5)
1 dx dx
We will calculate a finite element solution that is a linear approximation to the solution
of the boundary value problem on each element. The mesh and basis functions
described in Chap. 3 are suitable for this purpose. We therefore use the mesh of N
elements and N + 1 nodes described in Sect. 3.3.1, and the basis functions j (x),
j = 1, 2, . . . , N + 1, described in Sect. 3.3.2.2. Note that we use the definition of
the global basis functions in terms of local basis functions, defined on the canonical
element 0 X 1, and given by Eqs. (3.2.1)(3.2.6). This will aid the integration
over individual elements that is required when setting up the system of algebraic
equations later in this chapter.
The set S h takes the same definition as in Sect. 3.3.3. This set contains all functions
V (x) that can be written in the form
N +1
V (x) = V j j (x),
j=1
N +1
U (x) = U j j (x), (5.7)
j=1
84 5 Nonlinear Boundary Value Problems
U1 = 1. (5.8)
The basis functions i (x), i = 2, 3, . . . , N +1, all satisfy the condition i (1) =
0 and therefore lie in the set S0h . These basis functions may be substituted into Eq. (5.6)
to deduce that, for i = 2, 3, . . . , N + 1:
2
dU di
(1 + U 2 ) + 2(1 + x 4 )i + 8U 2 i dx 68i (2) = 0.
1 dx dx
(5.9)
and
2
dU d N +1
(1 + U 2 ) + 2(1 + x 4 ) N +1 + 8U 2 N +1 dx 68 = 0. (5.11)
1 dx dx
Combining Eqs. (5.8), (5.10) and (5.11), we have N + 1 algebraic equations for the
N + 1 unknown values U1 , U2 , . . . , U N +1 , as required.
5.1 A First Example 85
We now explain how the system of algebraic equations, given by Eqs. (5.8), (5.10) and
(5.11), is assembled in practice. These equations contain the same features as those
seen in earlier chapters: (i) contributions from integrals over the whole domain (in
Eqs. (5.10) and (5.11)); (ii) a contribution from the Neumann boundary condition (in
Eq. (5.11)) that includes only a known explicit term; and (iii) an algebraic equation
to satisfy the Dirichlet boundary condition where all terms may be written down
explicitly (Eq. (5.8)).
As in earlier chapters, we decompose the integrals that appear in Eqs. (5.10) and
(5.11) into the sum of the contributions from each element. We write Eq. (5.10) as,
for i = 2, 3, . . . , N ,
N
xk+1
dU di
(1 + U 2 ) + 2(1 + x 4 )i + 8U 2 i dx = 0. (5.12)
k=1 xk dx dx
Contributions to the integral in Eq. (5.11) may be written in a similar manner. The
contribution to this sum from element k, i.e. the integral over xk x xk+1 , may
be calculated by mapping this element to the canonical element 0 X 1 using
the change of variable
x = xk + h X, 0 X 1, (5.13)
where h = xk+1 xk . Remembering, from Eqs. (3.22) and (3.23), that the local basis
functions are given by
local,1 (X ) = 1 X, (5.14)
local,2 (X ) = X, (5.15)
We see from Eq. (5.12) that the term U 2 appears in the integral over each element.
On element k, this quantity is given by
U 2 = Uk2 local,1
2
(X ) + 2Uk Uk+1 local,1 (X )local,2 (X ) + Uk+1
2
local,2
2
(X ). (5.17)
It is clear from this expression for U 2 that the integral over each element required
to compute Eq. (5.12) is a nonlinear function of the values U1 , U2 , . . . , U N +1 . As
a consequence, it is not possible to write the system of algebraic equations as the
linear system AU = b as we did in Chaps. 2, 3 and 4. Instead, we write Eqs. (5.8),
(5.10) and (5.11) as the nonlinear system
86 5 Nonlinear Boundary Value Problems
R(U) = 0, (5.18)
where the vector Rcommonly known as the residual vectorhas entries given by
R1 (U) = U1 1, (5.19)
N x k+1 dU di
Ri (U) = (1 + U 2 ) + 2(1 + x 4 )i + 8U 2 i dx, i = 2, 3, . . . , N ,
xk dx dx
k=1
(5.20)
N x k+1
dU d N +1
R N +1 (U) = (1 + U 2 ) + 2(1 + x 4 ) N +1 + 8U 2 N +1 dx 68.
dx dx
k=1 x k
(5.21)
Equations (5.20) and (5.21) reveal that, on element k, we have to calculate a contri-
bution to the residual of the form
xk+1
dU di
(1 + U 2 ) + 2(1 + x 4 )i + 8U 2 i dx, (5.22)
xk dx dx
The local residuals, given by Eqs. (5.23) and (5.24), may easily be evaluated
by mapping element k to the canonical element 0 X 1, using the change of
variable given by Eq. (5.13). On element k, the basis functions k and k+1 are
given by Eqs. (5.14) and (5.15), and so the local contributions to the residual may be
written
1
(k) 1 dU dlocal,1
Rlocal,1 (U) = h 2
(1 + U 2 ) + 2(1 + (xk + h X )4 )local,1 +
0 h dX dX
8U 2 local,1 dX, (5.25)
1
(k) 1 dU d local,2
Rlocal,2 (U) = h 2
(1 + U 2 ) + 2(1 + (xk + h X )4 )local,2 +
0 h dX dX
8U 2 local,2 dX, (5.26)
dU dlocal,1 dlocal,2
= Uk + Uk+1 . (5.27)
dX dX dX
The integrals given by Eqs. (5.25) and (5.26) may now be evaluated, either ana-
lytically or using quadrature. We then add these local contributions into the global
(k)
residual by incrementing the appropriate entry of R. The local contribution Rlocal,1
(k)
from element k was the integral generated from Eq. (5.22) with i = k: hence, Rlocal,1
should be added to entry Rk of the global residual. Similarly, the local contribution
(k)
Rlocal,2 from element k was the integral generated from Eq. (5.22) with i = k + 1
and should be added to entry Rk+1 of the global residual.
The integral contributions to R(U) may therefore be computed by looping over
all elements, calculating all nonzero local contributions as described above, and then
adding these local contributions into the global residual vector.
To complete specification of R(U), we need to: (i) add the final term into Eq. (5.21)
to satisfy the Neumann boundary condition; and (ii) specify R1 , given by Eq. (5.19),
to satisfy the Dirichlet boundary conditions. We now give an example computational
implementation of the material presented in this section.
57
58 % C a l c u l a t e local values of basis functions ,
59 % their derivatives , x , U and the d e r i v a t i v e of U
60 p h i _ l o c a l = [1 - X , X ];
61 p h i _ p r i m e _ l o c a l = [ -1 , 1];
62 x_local = x(k) + h*X;
63 L o c a l U = U ( k )* p h i _ l o c a l (1) + U ( k +1)* p h i _ l o c a l (2);
64 L o c a l U P r i m e = U ( k )* p h i _ p r i m e _ l o c a l (1) + ...
65 U ( k +1)* p h i _ p r i m e _ l o c a l (2);
66
67 % E v a l u a t e i n t e g r a n d and add into sum
68 for i =1:2
69 L o c a l R e s i d u a l ( i ) = L o c a l R e s i d u a l ( i ) + ...
70 h * Q u a d W e i g h t s ( m )* ...
71 (1/ h / h * ( 1 + L o c a l U * L o c a l U )* ...
72 L o c a l U P r i m e * p h i _ p r i m e _ l o c a l ( i ) + ...
73 2 * ( 1 + x _ l o c a l ^4)* p h i _ l o c a l ( i ) + ...
74 8* L o c a l U * L o c a l U * p h i _ l o c a l ( i ));
75 end
76 end
Ri
Ji, j (U) = , i, j = 1, 2, . . . , N + 1. (5.28)
U j
Even if the numerical method being used does not require the Jacobian matrix to
be specified, it may provide the option to specify this matrix; the Matlab function
fsolve (that was used in Listing 5.1) allows the user to do this. Supplying the
Jacobian matrix will usually improve the efficiency and the reliability of the root-
finding algorithm.
We now explain how entries of the Jacobian matrix, defined by Eq. (5.28), may
be calculated. Clearly from Eq. (5.19), the first row of the Jacobian matrix is given
by, for j = 1, 2, . . . , N + 1,
1, j = 1,
J1, j = (5.29)
0, j = 1.
5.1 A First Example 91
N xk+1
dU di
Ji, j = (1 + U 2 ) + 2(1 + x 4 )i +8U 2 i dx,
k=1
U j x k
dx dx
j = 1, 2, . . . , N + 1,
(5.30)
Remembering that k (x) and k+1 (x) are the only basis functions that are nonzero on
element k, the integrand above will be zero unless i = k or i = k + 1. We therefore
need only calculate the contributions to this integral using i = k and i = k + 1, as
all other entries will be zero. Recalling the definition of the local contributions to the
(k) (k)
residual on element k, denoted by Rlocal,1 (U), Rlocal,2 (U) and defined by Eqs. (5.23)
and (5.24), we see that the nonzero contributions to Eq. (5.31) when i = k are, for
j = 1, 2, . . . , N + 1,
(k)
Rlocal,1
, (5.32)
U j
and so the local contributions from element k to the Jacobian given by Eq. (5.30)
depend only on the entries Uk and Uk+1 of the vector U. As a consequence, the
expressions given by Eqs. (5.32) and (5.33) are zero unless j = k or j = k + 1.
We now see that the local contribution from element k to the global Jacobian matrix,
given by Eq. (5.30), is nonzero for only four entries of J : Jk,k , Jk,k+1 , Jk+1,k and
92 5 Nonlinear Boundary Value Problems
Jk+1,k+1 . As such, only these entries need be calculated. They may be stored in the
(k)
2 2 matrix denoted by Jlocal , with entries given by
(k) (k)
Rlocal,1 Rlocal,1
(k) U U k+1
Jlocal = k
(k) (k) , (5.35)
Rlocal,2 Rlocal,2
Uk Uk+1
U U
= local,1 (X ), = local,2 (X ),
Uk Uk+1
dU dlocal,1 dU dlocal,2
= , = .
Uk dX dX Uk+1 dX dX
The global Jacobian may therefore be computed by looping over all elements,
calculating the local nonzero contributions on each element, before adding these
local contributions into the global matrix J . Having done this, we set the entries
corresponding to rows of the residual that enforce Dirichlet boundary conditions,
that is, the entries given by Eq. (5.29).
into a Matlab session. We encourage the reader to execute both Listings 5.1 and
5.2 for meshes containing different numbers of elements, and to record the execution
time for both functions. The reader will observe that specification of the Jacobian
matrix allows the finite element solution to be computed much more efficientlysee
Exercise 5.1.
94 5 Nonlinear Boundary Value Problems
57
58 % D e f i n e q u a d r a t u r e rule
59 M = 3;
60 Q u a d W e i g h t s = [5/18 , 4/9 , 5 / 1 8 ] ;
61 Q u a d P o i n t s = [0.5*(1 - sqrt (0.6)) , 0.5 , 0 . 5 * ( 1 + sqrt ( 0 . 6 ) ) ] ;
62
63 % I n i t i a l i s e local r e s i d u a l and J a c o b i a n to zero
64 L o c a l R e s i d u a l = zeros (2 ,1);
65 L o c a l J a c o b i a n = zeros (2 ,2);
66
67 % Loop over q u a d r a t u r e p o i n t s to e v a l u a t e i n t e g r a l
68 % using G a u s s i a n q u a d r a t u r e
69 for m =1: M
70 % Set local c o o r d i n a t e X
71 X = Q u a d P o i n t s ( m );
72
73 % C a l c u l a t e local values of basis functions ,
74 % their derivatives , x , U and the d e r i v a t i v e of U
75 p h i _ l o c a l = [1 - X , X ];
76 p h i _ p r i m e _ l o c a l = [ -1 , 1];
77 x_local = x(k) + h*X;
78 L o c a l U = U ( k )* p h i _ l o c a l (1) + U ( k +1)* p h i _ l o c a l (2);
79 L o c a l U P r i m e = U ( k )* p h i _ p r i m e _ l o c a l (1) + ...
80 U ( k +1)* p h i _ p r i m e _ l o c a l (2);
81
82 % E v a l u a t e i n t e g r a n d and add into sum
83 for i =1:2
84 L o c a l R e s i d u a l ( i ) = L o c a l R e s i d u a l ( i ) + ...
85 h * Q u a d W e i g h t s ( m )* ...
86 (1/ h / h * ( 1 + L o c a l U * L o c a l U )* ...
87 L o c a l U P r i m e * p h i _ p r i m e _ l o c a l ( i ) + ...
88 2 * ( 1 + x _ l o c a l ^4)* p h i _ l o c a l ( i ) + ...
89 8* L o c a l U * L o c a l U * p h i _ l o c a l ( i ));
90
91 for j =1:2
92 L o c a l J a c o b i a n (i , j ) = L o c a l J a c o b i a n ( i , j ) + ...
93 h * Q u a d W e i g h t s ( m )* ...
94 (1/ h / h * ( 2 * L o c a l U * p h i _ l o c a l ( j )* ...
95 L o c a l U P r i m e + ...
96 (1+ L o c a l U * L o c a l U )* p h i _ p r i m e _ l o c a l ( j ))* ...
97 p h i _ p r i m e _ l o c a l ( i ) + ...
98 16* L o c a l U * p h i _ l o c a l ( j )* p h i _ l o c a l ( i ));
99 end
100
101 end
102 end
96 5 Nonlinear Boundary Value Problems
Ri (U + e j ) Ri (U)
Ji, j ,
where takes a sufficiently small value for the approximation to the derivative to
be accurate. Performing this for all columns j will indeed generate a numerical
approximation to the Jacobian matrix. This approach is, however, very inefficient.
To evaluate the partial derivatives in this way, we would first need to compute the
original residual. We would then need to compute N + 1 perturbed residuals to
approximate the partial derivatives with respect to each U j , j = 1, 2, . . . , N + 1,
as demonstrated above. This would require the function CalculateResidual to
be evaluated a total of N + 2 times.
A more efficient approach to approximating the Jacobian matrix is to calculate
an approximation to the partial derivatives that appear in the local contribution to
the Jacobian matrix from an individual element, given by Eq. (5.35). These partial
derivatives may easily be approximated by the finite difference method, using the
function CalculateResidualOnElement given in Listing 5.1. Taking this
approach, we may assemble the Jacobian matrix as described in Sect. 5.1.6, using a
numerical approximation to Eq. (5.35). We then supply both the residual vector and
Jacobian matrix to the Matlab function fsolve as in Listing 5.2.
5.2 A General Nonlinear Boundary Value Problem 97
We now discuss how the material that has been used to calculate the finite element
solution of the example nonlinear differential equation, given by Eqs. (5.1)(5.3),
may be applied to more general nonlinear boundary value problems. The most general
second-order, nonlinear, differential equation satisfied by a function u(x) on the
interval a < x < b is of the form
du d2 u
f x, u, , 2 = 0, a < x < b,
dx dx
du d2 u
for some given function f x, u, dx , dx 2 , combined with suitable boundary condi-
tions. Throughout this book, the first step when calculating the finite element solution
of a differential equation has always been to write the differential equation in weak
form. To do this, we have multiplied the differential equation by a suitable test
function and used integration by parts to eliminate the dependence on the second
derivative of u(x). Writing the equation in the general form above does not always
allow us to integrate by parts. Hence, we restrict ourselves to differential equations
that may be written in the form
d du du
p x, u, + r x, u, = 0, a < x < b, (5.37)
dx dx dx
du
du
for specified functions p x, u, dx , r x, u, dx . Although this is not the most general
possible differential equation, most practical applications can be written in this form.
We require suitable boundary conditions to completely specify the problem. As with
the example given earlier in this chapter, we shall impose one Dirichlet boundary
condition and one natural Neumann boundary condition:
u = ua , x = a, (5.38)
du
p x, u, = pb , x = b. (5.39)
dx
We now give an overview of how the finite element solution of Eq. (5.37), subject to
the boundary conditions given by Eqs. (5.38) and (5.39), may be calculated.
The weak formulation is obtained in the usual way: we multiply the differential
equation, given by Eq. (5.37), by a function v(x) H01 (a, b), and integrate this
product over the interval a < x < b:
98 5 Nonlinear Boundary Value Problems
b
d du du
p x, u, + r x, u, v(x) dx = 0.
a dx dx dx
As v(x) H01 (a, b), we have v(a) = 0. The Neumann boundary condition given by
Eq. (5.39), together with v(a) = 0, allows us to write Eq. (5.40) as
b
du dv du
p x, u, + r x, u, v(x) dx pb v(b) = 0. (5.41)
a dx dx dx
We use the same mesh, basis functions and sets S h , S Eh , S0h that were used for the
example problem that we considered earlier in this chapter. The finite element solu-
tion, U (x), may then be written as
N +1
U (x) = U j j (x).
j=1
As U (x) S Eh , the finite element solution must satisfy any Dirichlet bound-
ary conditions that have been specified. We have one Dirichlet boundary condition,
specified at the node where x = x1 , and given by Eq. (5.38). Remembering that
U (x1 ) = U1 , we may deduce our first algebraic equation:
U1 = u a . (5.44)
The final term on the left-hand side of Eq. (5.45) may be simplified by remembering
that
i (b) = i (x N +1 )
1, i = N + 1,
=
0, i = N + 1.
The algebraic equations given by Eqs. (5.44) and (5.45) may now be written in
the form
R(U) = 0,
R 1 = U1 u a ,
N xk+1
dU di du
Ri = p x, U, + r x, u, i (x) dx, i = 2, 3, . . . , N ,
xk dx dx dx
k=1
N
xk+1
dU d N +1 du
R N +1 = p x, U, + r x, u, N +1 (x) dx pb .
dx dx dx
k=1 xk
These residuals may then be calculated, as described for the example differen-
tial equation in Sect. 5.1.4. The Jacobian matrix may, if required, be calculated as
described in Sect. 5.1.6.
100 5 Nonlinear Boundary Value Problems
5.3 Exercises
5.1 Listing 5.1 contains a computational implementation for calculating the finite
element solution of the boundary value problem given by Eqs. (5.1)(5.3), specifying
only the residual vector given by Eq. (5.18). Listing 5.2 also solves this boundary
value problem, specifying both the residual vector and the Jacobian matrix given
by Eq. (5.28). Execute the functions given by both Listings 5.1 and 5.2 for differ-
ent numbers of elements: try, for example, N = 50, 100, 150, 200, . . .. Record the
execution time for both functions for all values of N that you use. How much more
efficient is it to specify the global Jacobian matrix in addition to the global residual
vector?
5.2 Using Listings 5.1 and 5.2, write a computational implementation that calculates
the finite element solution of the boundary value problem given by Eqs. (5.1)(5.3),
using a numerical approximation to the Jacobian matrix as described in Sect. 5.1.7.
u = 1, at x = 0,
u = e, at x = 1.
a. Write down the weak formulation of the given differential equation. State clearly
the definition of the sets HE1 (0, 1) and H01 (0, 1) that you will require.
b. Calculate a finite element solution to the given differential equation, using a
linear approximation to the solution on each element. You may want to start
by using the function Matlab fsolve, specifying only the residual vector
as in Listing 5.1. When you are confident that this implementation is working
correctly, develop your code so that it also specifies the Jacobian matrix, either
calculated analytically or approximated numerically.
c. Repeat part (b) using a quadratic approximation to the solution on each element.
So far we have only considered scalar boundary value problems, that is, a single
differential equation that contains one unknown function u(x). We now generalise
the finite element method so that it may be applied to coupled systems of differ-
ential equations. We illustrate the basic principles using a simple example, before
explaining how these ideas may be generalised for application to more complex
systems.
d2 u 1 d2 u 2
3 u 1 + 8u 2 = 20 sin 2x, (6.1)
dx 2 dx 2
d2 u 2
2 + 2u 1 4u 2 = 2 sin x. (6.2)
dx
As with scalar equations, we require suitable boundary conditions to be specified.
In general, we expect one boundary condition for each equation at x = 0, and one
boundary condition for each equation at x = . As with scalar differential equations,
these boundary conditions may be any combination of Dirichlet, Neumann and Robin
boundary conditions, subject to constraints on the existence and uniqueness of the
solution. The boundary conditions that we use to illustrate the application of the finite
element method to the model system of equations above are, at x = 0:
du 1 du 2
3 = 7, (6.3)
dx dx
u 2 = 0, (6.4)
Springer International Publishing AG 2017 103
J. Whiteley, Finite Element Methods, Mathematical Engineering,
DOI 10.1007/978-3-319-49971-0_6
104 6 Systems of Ordinary Differential Equations
and at x = , we impose
u 1 = 0, (6.5)
du 2
= 2. (6.6)
dx
We shall see later that the Neumann boundary condition given by Eq. (6.3) is a natural
boundary condition for Eq. (6.1), and the Neumann boundary condition given by
Eq. (6.6) is a natural boundary condition for Eq. (6.2). The solution of this model
problem is
The method for deriving the weak formulation in earlier chapters has been to multiply
the differential equation by a suitable test function and to integrate this product over
the region on which the differential equation is defined. This is easily generalised for
systems of equations such as Eqs. (6.1) and (6.2). We multiply the first differential
equation, Eq. (6.1), by a suitable test function v1 (x), and the second differential
equation, Eq. (6.2), by a suitable test function v2 (x). We must, however, choose
suitable test functions.
We have already claimed that Eq. (6.3) is a natural Neumann boundary condition
at x = 0 for the first differential equation, Eq. (6.1). Further, Eq. (6.5) may be used
as a Dirichlet boundary condition for Eq. (6.1) at x = . We then view Eq. (6.1),
subject to the boundary conditions given by Eqs. (6.3) and (6.5), as a boundary value
problem that satisfies a Neumann boundary condition at x = 0, and a Dirichlet
boundary condition at x = . We therefore specify v1 to be a member of the set
H 1 (0, ) that satisfies the condition
v1 ( ) = 0, (6.7)
v2 (0) = 0. (6.8)
We now multiply Eq. (6.1) by the test function v1 (x) defined above and integrate
the resulting product over 0 < x < . After integrating by parts, we obtain
6.2 The Weak Formulation 105
du 1 du 2 du 1 dv1 du 2 dv1
+3 v1 + +3 u 1 v1 + 8u 2 v1 dx =
dx dx 0 dx dx dx dx
0
20v1 sin 2x dx.
0
Applying the Neumann boundary condition given by Eq. (6.3) at x = 0, and the
condition on v1 given by Eq. (6.7) allows us to write the equation above as
du 1 dv1 du 2 dv1
+3 u 1 v1 + 8u 2 v1 dx = 20v1 sin 2x dx 7v1 (0).
0 dx dx dx dx 0
In the same spirit, we: (i) multiply Eq. (6.2) by the test function v2 (x); (ii) integrate
the resulting product over 0 < x < ; (iii) integrate by parts; (iv) apply the Neumann
boundary condition given by Eq. (6.6) at x = ; and (v) apply the condition on v2 (x)
given by Eq. (6.8). We then obtain
du 2 dv2
+ 2u 1 v2 4u 2 v2 dx = 2v2 sin x dx + 2v2 ( ).
0 dx dx 0
All that is now required to complete the weak formulation of the problem is to
demand that u 1 (x) satisfies the Dirichlet boundary condition given by Eq. (6.5) and
that u 2 (x) satisfies the Dirichlet boundary condition given by Eq. (6.4). We may then
write the weak formulation of Eqs. (6.1) and (6.2), subject to the boundary conditions
given by Eqs. (6.3)(6.6) as:
find u 1 (x), u 2 (x) HE1 (0, ) such that
du 1 dv1 du 2 dv1
+3 u 1 v1 + 8u 2 v1 dx = 20v1 sin 2x dx 7v1 (0), (6.9)
0 dx dx dx dx
0
du 2 dv2
+ 2u 1 v2 4u 2 v2 dx = 2v2 sin x dx + 2v2 ( ). (6.10)
0 dx dx 0
We will calculate a linear approximation to both u 1 (x) and u 2 (x) on each element.
As such, we will use the mesh of N elements described in Sect. 3.3.1, and the linear
basis functions described in Sect. 3.3.2.
106 6 Systems of Ordinary Differential Equations
Before we define the finite element solution, we need to specify the set S h , and the
subsets S Eh and S0h of this set. The set S h is defined to be the set of all functions
V (1) (x), V (2) (x) that may be written as linear sums of the basis functions:
N +1
V (1)
(x) = V j(1) j (x),
j=1
N +1
V (2) (x) = V j(2) j (x).
j=1
The set S Eh is, as usual, defined to be the subset of S h that contains functions that
satisfy the Dirichlet boundary conditions. On using Eqs. (6.4) and (6.5), we see that
these are the functions V (1) (x) and V (2) (x) that satisfy
The set S0h is the subset of S h that contains functions that take the value zero where
Dirichlet boundary conditions are applied. As our model problem is the special case
where the Dirichlet boundary conditions, given by Eqs. (6.4) and (6.5), set the solution
to zero, the set S0h is identical to the set S Eh .
We now define the finite element solution by
Find U (1) (x), U (2) (x) S Eh such that
dU (1) dV (1) dU (2) dV (1)
+3 U (1) V (1) + 8U (2) V (1) dx =
dx dx dx dx
0
20V (1) sin 2x dx 7V (1) (0),
0
(6.11)
dU (2) dV (2)
+ 2U (1) V (2) 4U (2) V (2) dx =
dx dx
0
2V (2) sin x dx + 2V (2) ( ). (6.12)
0
We write the finite element solutions, U (1) (x) and U (2) (x), as members of the set S h
given by
N +1
U (1)
(x) = U (1)
j j (x), (6.13)
j=1
N +1
U (2) (x) = U (2)
j j (x), (6.14)
j=1
We note that x N +1 = and x1 = 0. From the definition of the finite element solutions
given by Eqs. (6.13) and (6.14), we see that these boundary conditions are satisfied
if
U N(1)+1 = 0, (6.15)
U1(2) = 0. (6.16)
Eqs. (6.15) and (6.16) then specify our first two algebraic equations.
Test functions V (1) (x) for Eq. (6.11) must satisfy V (1) (x N +1 ) = 0 so that they lie
in the space S0h . The N basis functions i (x), i = 1, 2, . . . , N , satisfy this condition
and are therefore suitable candidates. Substituting V (1) (x) = i (x), i = 1, 2, . . . , N ,
into Eq. (6.11), together with the finite element solutions given by Eqs. (6.13) and
(6.14), yields, after some manipulation,
N +1
di d j
i j dx U (1)
j +
j=1 0 dx dx
N +1
di d j
3 + 8i j dx U (2)
j = 20i sin 2x dx 7i (x1 ).
j=1 0 dx dx 0
N +1
N +1
Ai(11) (1)
j Uj + Ai(12) (2) (1)
j U j = bi , i = 1, 2, . . . , N , (6.17)
j=1 j=1
where for i = 1, 2, . . . , N , j = 1, 2, . . . , N + 1,
di d j
Ai(11)
j = i j dx, (6.18)
dx dx
0
di d j
Ai(12)
j = 3 + 8i j dx, (6.19)
0 dx dx
and
b1(1) = 201 sin 2x dx 7, (6.20)
0
bi(1) = 20i sin 2x dx, i = 2, 3, . . . , N . (6.21)
0
We now combine Eqs. (6.15) and (6.17) into the single matrix equation
where the entries of A(11) , A(12) , b(1) are given by Eqs. (6.18)(6.21), together with
1, j = N + 1,
A(11)
N +1, j = (6.23)
0, j = N + 1,
A(12)
N +1, j = 0, j = 1, 2, . . . , N + 1, (6.24)
b(1)
N +1 = 0. (6.25)
We now consider the integral given by Eq. (6.12). Suitable test functions will
satisfy V (2) (x1 ) = 0, and this condition is satisfied by the N basis functions i (x),
i = 2, 3, . . . , N + 1. Substituting these basis functions, and Eqs. (6.13) and (6.14),
into Eq. (6.12) we obtain, in a similar fashion to above:
N +1
N +1
Ai(21) (1)
j Uj + Ai(22) (2) (2)
j U j = bi , i = 2, 3, . . . , N + 1, (6.26)
j=1 j=1
where for i = 2, 3, . . . , N + 1, j = 1, 2, . . . , N + 1,
Ai(21)
j = 2i j dx, (6.27)
0
di d j
Ai(22)
j = 4i j dx, (6.28)
0 dx dx
6.5 The Algebraic Equations 109
and
bi(2) = 2i sin x dx, i = 2, 3, . . . , N , (6.29)
0
b(2)
N +1 = 2 N +1 sin x dx + 2. (6.30)
0
As before, Eqs. (6.16) and (6.26) may be written as the single equation
where the entries of the A(21) , A(22) , b(2) are given by Eqs. (6.27)(6.30), together
with
A(21)
1, j = 0, j = 1, 2, . . . , N + 1, (6.32)
1, j = 1,
A(22) = (6.33)
1, j 0, j = 1,
b1(2) = 0. (6.34)
Finally, we may combine Eqs. (6.22) and (6.31) into the single matrix equation
AU = b, (6.35)
where
A(11) A(12) U(1) b(1)
A= , U= , b= . (6.36)
A(21) A(22) U(2) b(2)
The values U1(1) , U2(1) , . . . , U N(1)+1 and U1(2) , U2(2) , . . . , U N(2)+1 that specify the finite
element solution for U (1) (x) and U (2) (x) given by Eqs. (6.13) and (6.14) may then
be obtained by solving the linear system given by Eq. (6.35).
We will assemble the global matrix A and global vector b that appear in the linear
system Eq. (6.35) by assembling the submatrices and subvectors that A and b are
comprised of, as shown in Eq. (6.36).
We start by assembling the matrix A(11) that is defined by Eqs. (6.18) and (6.23).
We see that these entries take the same form as those calculated in earlier chapters:
most entries (those defined by Eq. (6.18)) take the form of integrals of products
of basis functions and their derivatives over the whole domain; other entries (those
defined by Eq. (6.23)) take the form of very simple, explicit numerical values. We
110 6 Systems of Ordinary Differential Equations
may therefore assemble A(11) using the techniques developed in earlier chapters. To
do this, we first evaluate the entries that are defined by integrals, i.e. those given
by Eq. (6.18). These are assembled by decomposing these integrals into the sum of
integrals over individual elements. We loop over all elements, calculating only the
nonzero local contributions to the entries of A(11) from each element, before adding
these local contributions into A(11) . Having done this, we then complete the assembly
of this matrix by setting the entries defined by Eq. (6.23).
The other matrices A(12) , A(21) , A(22) may be assembled using the same approach
to that described above for assembling A(11) . Finally, the vectors b(1) and b(2) may
also be assembled in a similar manner: we do, however, have an additional term in
Eqs. (6.20) and (6.30) to add into these vectors that arise from the Neumann boundary
conditions.
the equation in line 53. The vectors U1 and U2 are extracted from the solution of the
linear system in lines 56 and 57. Finally, in lines 6062, we plot the finite element
solution given by both U (1) (x) and U (2) (x).
56 U1 = U (1: N +1);
57 U2 = U ( N +2:2* N +2);
58
59 % Plot the s o l u t i o n
60 plot ( x , U1 , r - ,x , U2 , k - )
61 xlabel ( x )
62 l e g e n d ( U_1 , U_2 )
63
64
65
66 f u n c t i o n [ A_local_11 , A_local_12 , A_local_21 , ...
67 A_local_22 , b_local_1 , b _ l o c a l _ 2 ] = ...
68 C a l c u l a t e C o n t r i b u t i o n O n E l e m e n t (x , k )
69
70 % C a l c u l a t e l e n g t h of e l e m e n t
71 h = x ( k +1) - x ( k );
72
73 % C a l c u l a t e a n a l y t i c a l c o n t r i b u t i o n s to A
74 A _ l o c a l _ 1 1 = [1/ h , -1/ h ; -1/ h , 1/ h ] - [ h /3 , h /6; h /6 , h /3];
75 A _ l o c a l _ 1 2 = 3*[1/ h , -1/ h ; -1/ h , 1/ h ] + ...
76 8*[ h /3 , h /6; h /6 , h /3];
77 A _ l o c a l _ 2 1 = 2*[ h /3 , h /6; h /6 , h /3];
78 A _ l o c a l _ 2 2 = [1/ h , -1/ h ; -1/ h , 1/ h ] - ...
79 4*[ h /3 , h /6; h /6 , h /3];
80
81 % D e f i n e q u a d r a t u r e rule
82 M = 3;
83 Q u a d W e i g h t s = [5/18 , 4/9 , 5 / 1 8 ] ;
84 Q u a d P o i n t s = [0.5*(1 - sqrt (0.6)) , 0.5 , 0 . 5 * ( 1 + sqrt ( 0 . 6 ) ) ] ;
85
86 % I n i t i a l i s e local c o n t r i b u t i o n s to b to zero
87 b _ l o c a l _ 1 = zeros (2 ,1);
88 b _ l o c a l _ 2 = zeros (2 ,1);
89
90 % Loop over q u a d r a t u r e p o i n t s to e v a l u a t e local
91 % c o n t r i b u t i o n s to b
92 for m = 1: M
93 X = Q u a d P o i n t s ( m );
94 p h i _ l o c a l = [1 - X , X ];
95 for i =1:2
96 b _ l o c a l _ 1 ( i ) = b _ l o c a l _ 1 ( i ) + h * Q u a d W e i g h t s ( m )* ...
97 20* sin (2*( x ( k )+ h * X ))* p h i _ l o c a l ( i );
98 b _ l o c a l _ 2 ( i ) = b _ l o c a l _ 2 ( i ) + h * Q u a d W e i g h t s ( m )* ...
99 2* sin ( x ( k )+ h * X )* p h i _ l o c a l ( i );
100 end
101 end
We now give a brief summary of how to calculate the finite element solution of a
system of Neq ordinary differential equations. Suppose the unknown functions are
u 1 (x), u 2 (x), . . . , u Neq (x). Using vector notation, we may write
6.8 More General Linear Problems 113
du 1 d2 u 1
u 1 (x) dx
dx 2
u 2 (x) du d2 u d2 u 2
du 2
u(x) = ,
.. = .
,
dx
= . .dx 2
. dx .. dx 2 ..
u Neq (x) du Neq d2 u Neq
dx dx 2
where P(x), Q(x), R(x) are matrices of size Neq Neq , and f is a vector of length Neq .
Alternatively, we may write Eq. (6.37) in component form as, for m = 1, 2, . . . , Neq ,
a < x < b,
du n
Neq Neq Neq
d du n
Pmn (x) + Q mn (x) + Rmn (x)u n = f m (x). (6.38)
n=1
dx dx n=1
dx n=1
We assume that each equation has one boundary condition prescribed at x = a, and
one boundary condition prescribed at x = b.
The boundary conditions for the system of differential equations given by Eq. (6.38)
allow us to define the Sobolev spaces HE1 (a, b) and H01 (a, b) for this system of equa-
tions. Multiplying each component m = 1, 2, . . . , Neq of the differential equation
by a suitable test function vm (x), integrating the resulting product over the domain
a < x < b and integrating the first term by parts, we may then write the weak
formulation of the differential equation as:
find u 1 (x), u 2 (x), . . . , u Neq (x) HE1 (a, b) such that, for m = 1, 2, . . . , Neq :
Neq
b
du n dvm du n
Pmn + Q mn vm + Rmn u n vm dx =
a n=1
dx dx dx
b
f m vm dx + h m (vm (a), vm (b)),
a
After specifying a suitable mesh, and defining basis functions on this mesh, we
define S h to be the set of vector-valued functions, with Neq components, where each
component may be written as a linear sum of these basis functions, that is,
N node
V (m)
(x) = V j(m) j (x), m = 1, 2, . . . , Neq , (6.39)
j=1
where Nnode is the number of nodes in the mesh. The sets S Eh and S0h are then subsets
of S h , with definitions that depend on the boundary conditions used. Having defined
the sets S Eh and S0h , we then define the finite element solution by:
find U (1) (x), U (2) (x), . . . , U (Neq ) (x) S Eh such that, for m = 1, 2, . . . , Neq :
Neq
b
dU (n) dV (m) dU (n) (m) (n) (m)
Pmn + Q mn V + Rmn U V dx =
a n=1
dx dx dx
b
f m V (m) dx + h m (V (m) (a), V (m) (b)),
a
(6.40)
N node
As usual, for each differential equation, a system of Nnode algebraic equations may
be derived by: (i) ensuring that U (m) (x) S Eh ; and (ii) substituting V (m) = i (x)
into Eq. (6.40) for suitable test functions i (x) S0h . Using a similar approach to
that described in Sect. 6.5, this results in a linear system that may be written in the
form AU = b where
(11)
A A(12) . . . A(1,Neq )
A(21) A(22) . . . A(2,Neq )
A= . .. .. .. ,
.. . . .
A(Neq ,1) A(Neq ,2) . . . A(Neq ,,Neq )
U(1)
U(2)
U = . ,
..
U(Neq )
6.8 More General Linear Problems 115
b(1)
b(2)
b= ,
..
.
b(Neq )
We then solve the linear system AU = b to evaluate the coefficients in the finite
element solution given by Eq. (6.41).
We conclude this chapter with a brief summary of how the material in Sects. 6.16.7
may be adapted for nonlinear boundary value problems. Suppose we are solving the
nonlinear system defined by, for a < x < b,
d du 1 du 2 du 1 du 2
p1 x, u 1 , u 2 , , + r1 x, u 1 , u 2 , , = 0,
dx dx dx dx dx
d du 1 du 2 du 1 du 2
p2 x, u 1 , u 2 , , + r2 x, u 1 , u 2 , , = 0,
dx dx dx dx dx
b
du 1 du 2 dv2 du 1 du 2
p2 x, u 1 , u 2 , , + r2 x, u 1 , u 2 , , v2 (x) dx+
a dx dx dx dx dx
h 2 (v2 (a), v2 (b)) = 0,
where HE1 (a, b) and H01 (a, b) are defined using the boundary conditions for each
equation, and h 1 (v1 (a), v1 (b)) and h 2 (v2 (a), v2 (b)) represent the contributions, if
any, from Neumann boundary conditions.
Defining the computational mesh allows us to specify suitable basis functions
and, in turn, the sets S Eh and S0h . We then write the finite element solutions as the
members of S h given by:
116 6 Systems of Ordinary Differential Equations
N node
N node
where Nnode is the number of nodes in the mesh. The finite element solution is then
defined by:
b
dU (1) dU (2) dV (2)
p2 x, U (1) , U (2) , , +
a dx dx dx
(1)
(1) (2) dU dU (2)
r2 x, U , U , , V (2) (x) dx+
dx dx
h 2 (V (2) (a), V (2) (b)) = 0,
(6.43)
Substituting i (x) into Eq. (6.42) for all permissible i (x), when combined with
enforcing U (1) (x) S Eh , will result in Nnode algebraic equations, which we write as
R(1) U1(1) , U2(1) , . . . , U N(1)node , U1(2) , U2(2) , . . . , U N(2)node = 0. (6.44)
Similarly, substituting i (x) into Eq. (6.43) for all permissible i (x) S0h , and
enforcing U (2) (x) S Eh , will result in a further Nnode algebraic equations,
R(2) U1(1) , U2(1) , . . . , U N(1)node , U1(2) , U2(2) , . . . , U N(2)node = 0. (6.45)
The residuals R(1) and R(2) may be calculated in the same way as the residuals for
the scalar value nonlinear differential equations discussed in Chap. 5.
The two systems of nonlinear algebraic equations defined by Eqs. (6.44) and
(6.45) may then be combined into a single system of nonlinear algebraic equations
given by:
6.9 Nonlinear Problems 117
(1)
R
R = 0, where R= .
R(1)
Provided the Jacobian matrix is not required, this residual vector may be used to
determine U1(1) , U2(1) , . . . , U N(1)node , U1(2) , U2(2) , . . . , U N(2)node . If the Jacobian is required,
it may be written in the form
J (11) J (12)
J= ,
J (21) J (22)
where the entries of the submatrices of J are given by, for i = 1, 2, . . . , Nnode ,
j = 1, 2, . . . , Nnode ,
Ri(1) Ri(1)
Ji,(11)
j = (1)
, Ji,(12)
j = ,
U j U (2)
j
Ri(2) Ri(2)
Ji,(21)
j = (1)
, Ji,(22)
j = .
U j U (2)
j
The entries of these submatrices may be calculated in the same way as the Jacobian
matrix for scalar value nonlinear differential equations, described in Chap. 5.
6.10 Exercises
d2 u 1 d2 u 2
2 2
+ 2u 1 + 5u 2 = 2e2x ,
dx dx 2
d2 u 1 d2 u 2
3 + 12u 2 = ex ,
dx 2 dx 2
subject to Dirichlet boundary conditions at x = 0 given by
u 1 (0) = 1,
u 2 (0) = 2,
du 1 du 2
2 + = 2e + 4e2 ,
dx dx
du 1 du 2
3 = e 12e2 .
dx dx
118 6 Systems of Ordinary Differential Equations
The first Neumann boundary condition is a natural boundary condition for the first dif-
ferential equation, and the second Neumann boundary condition is a natural boundary
condition for the second differential equation.
This boundary value problem has analytic solution u 1 (x) = ex , u 2 (x) = 2e2x .
(a) In this chapter, we wrote down a model boundary value problem in Sect. 6.1 that
was similar to the system above. We then explained how to solve this system,
providing a computational implementation in Sect. 6.7. Using a similar pattern
to that presented for this model problem, define: (i) the weak formulation, (ii)
the finite element solution that is a linear approximation to the solution on each
element and (iii) the algebraic system of equations satisfied by the finite element
solution. Then, develop a computational implementation for setting up and solv-
ing the system of algebraic equations and confirm that your solution agrees with
the analytic solution.
(b) Develop the material presented in this chapter to allow computation of a finite
element solution to the boundary value problem above, using a quadratic approx-
imation to the solution on each element.
Chapter 7
Linear Elliptic Partial Differential Equations
In earlier chapters, we described how to apply the finite element method to ordinary
differential equations. For the remainder of this book, we will focus on extending
this technique for application to partial differential equations. As with ordinary dif-
ferential equations, we begin with a simple example to illustrate the key features. We
then discuss more complex differential equations in later chapters.
The material in this chapter requires some knowledge of vector calculus and inte-
gration over two-dimensional regions. We assume that the reader has some familiar-
ity with this topic, including: (i) the definition of the gradient operator ; (ii) basic
identities that use the gradient operator; (iii) use of the divergence theorem; and
(iv) surface and line integrals. A very brief summary of some of the vector calculus
required is given in Appendix B.
Our strategy when applying the finite element method to this model problem
will be the same as that used when applying the finite element method to ordinary
Springer International Publishing AG 2017 119
J. Whiteley, Finite Element Methods, Mathematical Engineering,
DOI 10.1007/978-3-319-49971-0_7
120 7 Linear Elliptic Partial Differential Equations
differential equations. A summary of this strategy was written down in Sect. 2.9. We
encourage the reader to revisit this summary before reading the remainder of this
chapter.
As we have seen throughout this book, the first step when using the finite element
method is to derive the weak formulation of the differential equation. As with ordinary
differential equations, this is done by first multiplying the given differential equation
by a function in an appropriate Sobolev subspace. Before we may do this for the
model problem given in Sect. 7.1, we must define Sobolev spaces for functions of
two variables that generalise the definitions given for functions of one variable in
Sect. 3.2.1.
Let be a subset of the (x, y)-plane. In Sect. 3.2.1, we defined the concept of
square integrable functions for functions of one variable. This definition may easily
be extended to functions of two variables. A function v(x, y) that is defined on the
region is said to be square integrable on this region if the integral
(v(x, y))2 d A
exists. The set of square integrable functions on this region, denoted by L 2 (), is
then defined by
L 2 () = functions v(x, y) such that the integral (v(x, y))2 d A exists .
The Sobolev space of order 1 for functions defined on the region , denoted by
H 1 (), is now defined to be those functions v(x, y) that (i) are defined and continu-
ous on ; (ii) lie in the set L 2 (); and (iii) have first partial derivatives with respect
to both x and y that lie in L 2 (). Hence,
H () = functions v(x, y) such that v(x, y) is continuous, and the integrals
1
2 2
v v
(v(x, y))2 d A, d A, and d A exist .
x y
(7.6)
7.2 The Weak Formulation 121
We may also define the subsets HE1 () and H01 () of H 1 () that mirror those
defined for functions of one variable in Sect. 3.2.1. Suppose a differential equation,
together with suitable boundary conditions, has been specified. Using these boundary
conditions, we define these two subsets by:
HE1 () = functions v(x, y) in H 1 () such that v(x, y) satisfies all Dirichlet
boundary conditions , (7.7)
H01 () = functions v(x, y) in H 1 () such that v(x, y) = 0 at all points (x, y)
where Dirichlet boundary conditions are specified . (7.8)
The example differential equation, Eq. (7.1), is defined on the region 0 < x < 1,
0 < y < 1, which we will denote by . This differential equation may be written in
terms of the gradient operator as
(u) = 1, (x, y) .
v (u) = v, (x, y) .
After a little vector calculusthe use of Eq. (B.2) from Appendix Bthis may be
written
We now integrate this equation over the region and apply the divergence theorem
to the first term on the left-hand side. Denoting the boundary of by yields
v (u) n ds + (v) (u) d A = v d A, (7.9)
where n denotes the normal vector to the boundary that points out of the region
and is of unit length. Note that, at this stage, some authors use the notation
u
= (u) n.
n
122 7 Linear Elliptic Partial Differential Equations
Remembering that v(x, y) H01 (), the function v(x, y) will take the value zero
at all points on the boundary of where Dirichlet boundary conditions are applied.
The boundary conditions for our model problem, Eqs. (7.2)(7.5), prescribe Dirichlet
boundary conditions on the whole boundary . Consequently, v(x, y) = 0 for every
point on . The first integral on the left-hand side of Eq. (7.9) will therefore be
zero, and we may write
(v) (u) d A = v d A. (7.10)
We are now ready to define the weak solution of our example differential equa-
tion. As with ordinary differential equations, the weak solution will satisfy both the
Dirichlet boundary conditions and the integral condition given by Eq. (7.10), for all
functions v(x, y) H01 (). More precisely, the weak solution of Eqs. (7.1)(7.5) is
given by
find u(x, y) H E1 () such that
(v) (u) d A = v d A, (7.11)
Having derived the weak formulation of the differential equation, the next task is to
partition the region on which the differential equation is specified into elements and
to define the basis functions on these elements. In this chapter, we will partition
into a mesh of triangular elements. An alternative approach would be to partition
into quadrilateral elements; we will discuss this approach in Chap. 9. Both strategies
for partitioning the domain have their merits, which are beyond the scope of this
book. For most problems, however, either approach is suitable. We will consider only
linear basis functions in this chapter; higher order basis functions will be introduced
in Chap. 10.
The domain for the model problem, i.e. the square 0 < x < 1, 0 < y < 1, may
be partitioned into triangular elements by first partitioning the region into equally
sized rectangles so that there are N x rectangles in the x-direction and N y rectangles
in the y-direction. This is illustrated for N x = 2 and N y = 3 in Fig. 7.1a. We then
partition each rectangle into two triangles by drawing a line across one diagonal
of the rectangle, as illustrated in Fig. 7.1b. The elements of the mesh are then the
triangles generated, and the nodes are the vertices of the elements.
We now number both the nodes and the elements of the mesh shown in Fig. 7.1b.
When numbering nodes, we start with the node at the bottom left-hand corner of
the mesh and number the nodes consecutively moving in the positive x-direction.
We then move up to the next row in the y-direction and repeat this process, starting
from the left-hand end of this row. We proceed through the mesh in this fashion until
all nodes have been numbered. This numbering convention is illustrated in Fig. 7.2a
when N x = 2 and N y = 3. A similar process is used to number the elementsthis
is illustrated in Fig. 7.2b when N x = 2 and N y = 3.
When implementing the finite element method later in this chapter, we will find
it useful to have access to an array that contains the nodes of each element listed in
an anticlockwise direction. This array is known as the connectivity array, and the
(a) (b)
1 1
0.8 0.8
0.6 0.6
y
0.4 0.4
0.2 0.2
0 0
(a) (b)
10 11 12
1 1
0.8 0.8 10 12
7 8 9 9 11
0.6 0.6
y
6 8
0.4 4 5 6 0.4 5 7
0.2 0.2 2 4
1 2 3 1 3
0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x
Fig. 7.2 a Labelling of the nodes in the mesh. b Labelling of the elements in the mesh
124 7 Linear Elliptic Partial Differential Equations
variable name traditionally used for this array in computer programs is lnods,1
and we follow this convention here. Suppose our mesh contains Nele elements. In
matrix notation, lnodsk,i , where k = 1, 2, . . . , Nele and i = 1, 2, 3, contains node i
of element k. A suitable matrix lnods for the mesh shown in Fig. 7.2 is given by
1 2 4
5 4 2
2 3 5
6 5 3
4 5 7
8 7 5
lnods =
5
.
6 8
9 8 6
7 8 10
11 10 8
8 9 11
12 11 9
Note that the ordering of the nodes in each row of the connectivity array is not
uniquewe require only that the nodes of each element are listed in an anticlockwise
order. The first row of the matrix lnods above could, for example, be stored in the
order 4, 1, 2 or 2, 4, 1. The reason for insisting that the elements are ordered in an
anticlockwise direction will become apparent when we define basis functions in the
next section. It is also important to note that the order in which the elements are listed
in the matrix lnods is not important. As such, we may interchange any rows of this
matrix.
When assembling the system of algebraic equations that determine the finite
element solution, we will require the value of x and y at each node. Suppose we have
Nnode nodes in the mesh. The values of x and y at node i, where i = 1, 2, . . . , Nnode ,
are denoted by xi and yi .
We now make some general comments on the partitioning of a domain into tri-
angular elements. The partitioning of illustrated in Fig. 7.2 has a key property
that is required by any finite element mesh in more than one spatial dimensionany
point in that is a node of one element is also a node of any other element that
it is contained in. For example, the partitioning of shown in Fig. 7.3 is not an
admissible partitioning, as a point existsdenoted by an open circlethat is a node
of one element, but lies on the edge of another element without being a node of that
element. This node is known as a hanging node.
1 This variable name is a consequence of the design of early programming languages and their
conventions for naming variables. Early versions of Fortran, the most common language of choice
for scientific computing until fairly recently, used the convention that variables representing integers
should have a variable name that starts with one of the letters i, j, k, l, m, n, or upper-case letters
corresponding to these letters. Furthermore, variable names were restricted to a maximum of six
characters.
7.3 The Mesh and Basis Functions 125
0.8
0.6
y
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1
x
In this chapter, we will calculate a finite element solution of the model problem that is
a linear approximation to the true solution on each element. We now identify suitable
basis functions for the mesh described in Sect. 7.3.1. We first define a canonical
triangular element in (X, Y )-coordinates to be the triangle that occupies the region
X 0, Y 0, 1 X Y 0, as shown in Fig. 7.4. The global basis functions are
then defined through (i) specification of local linear basis functions on this canonical
triangular element; and (ii) a linear transformation that maps between an element
of the mesh in (x, y)-coordinates and the canonical triangular element in (X, Y )-
coordinates.
Suppose the nodes of element k in a mesh of triangular elements, ordered in
an anticlockwise direction, are the nodes k1 , k2 and k3 . For the mesh described
in Sect. 7.3.1, these nodes will be the entries in row k of the matrix lnods, and the
values of x and y at these nodes are given by xk1 , xk2 , xk3 and yk1 , yk2 , yk3 . A mapping
between this triangular element, in (x, y)-coordinates, and the canonical triangular
element described above, in (X, Y )-coordinates, is given by
0.6
Y
y
0.4
0.2
(xk2 , yk2 )
(xk1 , yk1 ) 0
Fig. 7.4 Mapping between a general element in (x, y)-coordinates and the canonical element in
(X, Y )-coordinates
This mapping is illustrated in Fig. 7.4. It is straightforward to verify that the trans-
formation given by Eqs. (7.12) and (7.13) correctly maps the canonical element in
(X, Y )-coordinates to element k in (x, y)-coordinates. The vertices of the canonical
triangle, listed in an anticlockwise order, are the point X = 0, Y = 0, the point
X = 1, Y = 0 and the point X = 0, Y = 1. These three points are clearly mapped,
respectively, to nodes k1 , k2 and k3 of element k by Eqs. (7.12) and (7.13). Further,
as the map is a linear function of X and Y , straight lines (such as the edges of a
triangle) in the (X, Y )-coordinate system will be mapped to straight lines in the
(x, y)-coordinate system.
It is now apparent why we insisted that the nodes of each element are listed in an
anticlockwise order in the array lnods. If they were not, then the mapping between
element k and the canonical element given by Eqs. (7.12) and (7.13) would include
a reflection, which is not the intention of this transformation.
Local linear basis functions local,1 (X, Y ), local,2 (X, Y ), local,3 (X, Y ) are defined
on the canonical element by
These local basis functions are illustrated in Fig. 7.5 and have the property that they
take the value 1 at one node of the canonical triangle, and 0 at all other nodes:
If there are Nnode nodes in the mesh, there will be a total of Nnode global basis func-
tions j , j = 1, 2, . . . , Nnode . We now define these global basis functions in terms
7.3 The Mesh and Basis Functions 127
1 1 1
Fig. 7.5 Local basis functions local,1 (X, Y ), local,2 (X, Y ) and local,3 (X, Y ) defined by
Eqs. (7.14)(7.16)
0.5
0
1
0.5
y 0 0.5 1
0 x
The global basis functions defined above may be written, if desired, as functions
of x and y on each element, by inverting the transformation given by Eqs. (7.12) and
(7.13), giving X and Y as functions of x and y. We shall see, however, that we do not
need to do this to assemble the system of algebraic equations satisfied by the finite
element solution. We do, however, illustrate an example global basis function as a
function of x and y in Fig. 7.6.
We now derive a useful property of the global basis functions defined by
Eqs. (7.12)(7.20). Remember that the node of the canonical triangle located at
X = 0, Y = 0 is mapped to node k1 of element k by Eqs. (7.12) and (7.13). We
then see that, on element k,
128 7 Linear Elliptic Partial Differential Equations
k1 (x = xk1 , y = yk1 ) = k1 (X = 0, Y = 0)
= local,1 (0, 0)
= 1,
k2 (x = xk1 , y = yk1 ) = k2 (X = 0, Y = 0)
= local,2 (0, 0)
= 0,
k3 (x = xk1 , y = yk1 ) = k3 (X = 0, Y = 0)
= local,3 (0, 0)
= 0,
j (x = xk1 , x = yk1 ) = 0, j = k1 , j = k2 , j = k3 ,
where we have emphasised above whether we are working in the (x, y)-coordinate
system, or the (X, Y )-coordinate system. Similar consideration of the nodes k2 and
k3 allows us to write
As the property given by Eq. (7.21) holds on every element, we may deduce that it
holds for the whole domain.
We now define the sets of functions S h , S Eh , S0h that will be used when specifying
the finite element solution. These mirror the sets that were specified for functions of
one variable in Sect. 3.3.3. In this chapter, we will calculate a finite element solution
that is a linear approximation to the solution of the differential equation on each
triangular element. An appropriate set S h is
7.4 Sets of Functions 129
N node
We now write the finite element solution as a linear sum of the global basis functions
defined by Eqs. (7.12)(7.20):
N node
and note that U (x, y) is a member of the set S h . On using Eqs. (7.21) and Eqs. (7.25)
we see that, for i = 1, 2, . . . , Nnode ,
N node
U (xi , yi ) = U j j (xi , yi )
j=1
= Ui , (7.26)
and so Ui is, as usual, the value taken by the finite element solution at node i of the
mesh.
The coefficients of the basis functions U1 , U2 , . . . , U Nnode that appear in Eq. (7.25)
are determined by demanding that U (x, y) satisfies the following modification of
the weak formulation, Eq. (7.11):
The finite element solution given by Eq. (7.25) contains Nnode unknown quantities
U1 , U2 , . . . , U Nnode . We must therefore use the definition of the finite element solution,
given by Eq. (7.27), to identify Nnode algebraic equations to determine these values.
These equations are, as usual, drawn from two sources: (i) equations that ensure
that the finite element solution satisfies the Dirichlet boundary conditions; and (ii)
equations that arise from substituting suitable test functions i (x, y) S0h () into
the integral given by Eq. (7.27). We now discuss these two categories of equations
separately.
We noted earlier that U (x, y), as given by Eq. (7.25), lies in the set S h . One of the
conditions imposed on the finite element solution is that it lies in the set S Eh that
is a subset of S h . To ensure that U (x, y) lies in S Eh , we therefore need to ensure
that it satisfies the Dirichlet boundary conditions. In our model problem, Dirichlet
boundary conditions are applied on the whole of the boundary. Suppose node i lies
on boundary, . Using Eq. (7.26), we see that the Dirichlet boundary conditions,
Eqs. (7.2)(7.5), are satisfied provided that
Ui = 0, (xi , yi ) , (7.28)
Suppose that node i does not lie on the boundary, . Then it follows that i (x, y)
S0h (). Noting that Eq. (7.25) allows us to write
7.6 The System of Algebraic Equations 131
N node
we may substitute i (x, y) into Eq. (7.27) to obtain, after a little manipulation,
N
node
(i ) j d A U j = i d A,
j=1
N node
Ai, j U j = bi ,
j=1
where
Ai, j = (i ) j d A, j = 1, 2, . . . , Nnode , (7.29)
bi = i d A. (7.30)
AU = b. (7.31)
If node i lies on the boundary, then Eq. (7.28) applies. The entries of A and b in row
i are then given by
1, j = i,
Ai, j = (7.32)
0, j = i,
bi = 0. (7.33)
If node i does not lie on the boundary, then the entries of A and b in row i are given
by Eqs. (7.29) and (7.30).
The system of algebraic equations derived above takes the same form as those
derived in earlier chapters. Some entries of the matrix A and vector b take the form of
integrals over the whole domain, while other entries may be written down explicitly.
132 7 Linear Elliptic Partial Differential Equations
As in earlier chapters, we will assemble the linear system given by Eq. (7.31) by
first evaluating the entries of A and b that are given by integrals, that is, Eqs. (7.29)
and (7.30). Having done this, we will then set the entries that are given explicitly
by Eqs. (7.32) and (7.33). We now describe how these two categories of entries are
handled in practice.
We write the entries of the linear system that are defined by integrals, Eqs. (7.29) and
(7.30), as the sum of integrals over individual elements: when node i does not lie on
the boundary, we have
Nele
Ai, j = (i ) j d A, j = 1, 2, . . . , Nnode , (7.34)
k=1 ek
Nele
bi = i d A, (7.35)
k=1 ek
where Nele is the number of elements in the mesh, and ek is the region occupied
by element k. We now explain how the integrals over individual elements may be
evaluated.
Suppose the nodes of element k are the nodes k1 , k2 and k3 , listed in an anticlock-
wise order. Using the definition of the global basis functions, given by Eqs. (7.12)
(7.20), we see that the only global basis functions that are not identically zero on
this element are k1 , k2 and k3 . Hence, using the definition of the entries of A
given by Eq. (7.34), the only nonzero contributions from this element to the global
matrix A are to the entries Ai, j where i = k1 , k2 , k3 and j = k1 , k2 , k3 . We therefore
calculate only these nonzero local contributions, and store them in the 3 3 matrix
(k) (k)
Alocal , where Alocal,i, j contributes to Aki ,k j for i = 1, 2, 3, j = 1, 2, 3. Similarly, the
contributions from this element to the entries of b given by Eq. (7.35) are zero unless
i = k1 , k2 , k3 . We again calculate only these nonzero contributions, which we store
(k) (k)
in the local vector blocal that contains three entries, where blocal,i contributes to bki for
i = 1, 2, 3.
(k) (k)
The entries of Alocal and blocal may be calculated using the transformation between
element k and the canonical element given by Eqs. (7.12) and (7.13), and writing the
global basis functions in terms of the local basis functions given by Eqs. (7.17)
(k)
(7.19). We derive the entries of Alocal first. For i = 1, 2, 3, j = 1, 2, 3, we may
write
7.7 Assembling the System of Algebraic Equations 133
(k)
Alocal, i, j = ki k j d A
ek
ki k j ki k j
= + dA
ek x x y y
local,i local, j local,i local, j
= + det(F) d A X , (7.36)
x x y y
where , combined with d A X , denotes integration over the canonical element, and
F is the Jacobian matrix of the transformation defined by Eqs. (7.12) and (7.13),
which may be written as
x x
X Y
F= y y
X Y
x k2 x k1 x k3 x k1
= . (7.37)
yk2 yk1 yk3 yk1
The determinant of F, which appears in Eq. (7.36), takes a constant value on element
k, given by
det(F) = xk2 xk1 yk3 yk1 xk3 xk1 yk2 yk1 . (7.38)
The integrand in Eq. (7.36) contains partial derivatives of local basis functions with
respect to the coordinates x and y. As the local basis functions are written in terms
of the coordinates X and Y , we use the chain rule to evaluate the quantities required.
The chain rule may be written in matrix form as
local,1 local,1 local,1 local,1
x y X Y
X X
local,2 local,2 local,2 local,2 x y
= X
x y Y Y Y
local,3 local,3 local,3 local,3 x y
x y X Y
1 1 X X
x y
= 1 0 Y Y
, (7.39)
0 1 x y
where the partial derivatives of the local basis functions with respect to X and Y
follow from their definitions, Eqs. (7.14)(7.16). It can be shown that
X X
1
x x
x y X Y
Y Y
= y y
x y X Y
1
=F ,
where we have used an explicit expression for the inverse of a 22 matrix. Combining
Eqs. (7.39) and (7.40) allows us to evaluate the partial derivatives that appear in
Eq. (7.36). Noting that the Jacobian is given by Eq. (7.38), we now have explicit
expressions for all terms in the integrand in Eq. (7.36). Finally, we see that all terms in
the integrand are constant, and so the integral may be evaluated by simply multiplying
this constant integrand by the area of the canonical trianglei.e. the value 0.5to
give, for i = 1, 2, 3, j = 1, 2, 3:
(k) 1 local,i local, j local,i local, j
Alocal, i, j = det(F) + . (7.41)
2 x x y y
(k)
The entries of blocal may be calculated in a similar fashion. We first note that, for
i = 1, 2, 3, integration of the local basis functions over the canonical element may
be written
1 1Y
local,i (X, Y ) d A X = local,i (X, Y ) dX dY
Y =0 X =0
1
= .
6
(k)
Using the definition of blocal given by Eq. (7.35), and the expression for the determi-
nant of F given by Eq. (7.38), we may write, for i = 1, 2, 3:
(k)
blocal,i = k i d A
ek
= local,i (X, Y ) det(F) d A X
1
= det(F). (7.42)
6
We may now assemble the entries of A and b that are given by Eqs. (7.34) and
(7.35) by looping over all elements, and calculating only the nonzero contributions
from each element, given by Eqs. (7.41) and (7.42). These local contributions from
each element are then added to the appropriate entry of the global matrix A and global
vector b; the relationship between the indices of the entries in the global linear system
and the indices of the entries of local contributions is given in Table 7.1.
7.7 Assembling the System of Algebraic Equations 135
When looping over all elements, as described in Sect. 7.7.1, we will add contributions
into the global matrix A and global vector b from every node of every element. This
will include not only the rows where the entries of A and b are given by Eqs. (7.29)
and (7.30), but also the rows where A and b are given by Eqs. (7.32) and (7.33). We
therefore set these entries correctly by using the explicit values given by Eqs. (7.32)
and (7.33).
Suppose we want to evaluate the finite element solution at some point (x, y), i.e. we
want to evaluate U (x, y) for given x and y. The first task is to identify the element
that this point lies in. This may be done by first writing the transformation between
element k and the canonical element, Eqs. (7.12) and (7.13), as
If the point (x, y) is mapped by this transformation to a point inside the canonical
trianglethat is, X 0, Y 0, and X + Y 1then (x, y) lies inside element k.
Having identified the element k that contains the point (x, y), suppose that the nodes
of this element are k1 , k2 , k3 . Using the definition of local basis functions given by
Eqs. (7.14)(7.16), and the values of X , Y , given by Eqs. (7.43) and (7.44), we may
deduce that
U (x, y) = Uk1 local,1 (X, Y ) + Uk2 local,2 (X, Y ) + Uk3 local,3 (X, Y ).
136 7 Linear Elliptic Partial Differential Equations
over all elementssee Sect. 7.7.2 for more details. We then solve the linear system. In
Appendix A, we propose solving large linear systems using preconditioned, iterative
methods. Lines 2932 solve the linear system using an incomplete LU -factorisation
(calculated in line 29), preconditioned GMRES (line 32). When using GMRES, we
use a restart value of 30. For more details on what these terms mean, see Appendix A.
Finally, the solution is plotted using lines 3538.
This Matlab function may be executed by typing, for example,
[x, y, lnods, U] = Chap7_CalculateExampleFem(50, 50);
44 % Set e n t r i e s of l n o d s
45 lnods = zeros (2* Nx * Ny , 3);
46 for j =1: Ny ;
47 for i =1: Nx ;
48 ele = 2*( j -1)* Nx +2* i -1;
49 lnods ( ele ,:) = ...
50 [( j -1)*( Nx +1)+ i , (j -1)*( Nx +1)+ i +1 , j *( Nx +1)+ i ];
51
52 ele = ele +1;
53 lnods ( ele ,:) = ...
54 [ j *( Nx +1)+ i +1 , j *( Nx +1)+ i , (j -1)*( Nx +1)+ i +1];
55 end
56 end
57
58 % Set e n t r i e s of x and y over the i n t e r v a l from 0 to 1
59 x = zeros (( Nx +1)*( Ny +1) ,1);
60 y = zeros (( Nx +1)*( Ny +1) ,1);
61
62 for i =1: Nx +1
63 x ( i : Nx +1:( Nx +1)*( Ny +1)) = ( i -1)/ Nx ;
64 end
65
66 for j =1: Ny +1
67 y (( j - 1 ) * ( Nx + 1 ) + 1 : j *( Nx +1)) = ( j -1)/ Ny ;
68 end
69
70 % S p e c i f y l o c a t i o n s of D i r i c h l e t b o u n d a r y c o n d i t i o n s
71 % Nodes on y =0
72 d i r _ n o d e s (1: Nx +1) = 1: Nx +1;
73 % Nodes on x =1
74 d i r _ n o d e s ( Nx +2: Nx + Ny +1) = 2*( Nx +1): Nx +1:( Ny +1)*( Nx +1);
75 % Nodes on y =1
76 d i r _ n o d e s ( Nx + Ny +2:2* Nx + Ny +1) = ...
77 ( Ny + 1 ) * ( Nx +1) -1: -1: Ny *( Nx + 1 ) + 1 ;
78 % Nodes on x =0
79 d i r _ n o d e s (2* Nx + Ny + 2 : 2 * ( Nx + Ny )) = ...
80 ( Ny -1)*( Nx +1)+1: -( Nx +1): Nx +2;
81
82
83
84 % C a l c u l a t e local c o n t r i b u t i o n s to A and b from elem e n t k
85 f u n c t i o n [ A_local , b _ l o c a l ] = ...
86 C a l c u l a t e C o n t r i b u t i o n O n E l e m e n t ( x , y , lnods , k )
87
88 % D e f i n e x and y c o o r d i n a t e of each node
89 x1 = x ( lnods (k ,1));
90 x2 = x ( lnods (k ,2));
91 x3 = x ( lnods (k ,3));
92 y1 = y ( lnods (k ,1));
93 y2 = y ( lnods (k ,2));
94 y3 = y ( lnods (k ,3));
95
96 % C a l c u l a t e J a c o b i a n of t r a n s f o r m a t i o n b e t w e e n c a n o n i c a l
97 % e l e m e n t and e l e m e n t k
98 detF = ( x2 - x1 )*( y3 - y1 ) - ( x3 - x1 )*( y2 - y1 );
99
100 % E v a l u a t e d e r i v a t i v e s of basis f u n c t i o n s in terms of (x , y )
101 % coordinates
102 Finv = [ y3 - y1 , x1 - x3 ; y1 - y2 , x2 - x1 ]/ detF ;
7.9 Computational Implementation 139
that are on the part of the boundary where Dirichlet boundary conditions are applied.
In general, mesh generation packages may be used to create at least the first three of
these. One word of caution is that the user should perform a check to ensure that the
connectivity array does list the nodes of each element in an anticlockwise direction.
This is straightforward to doif the determinant of the Jacobian of the transformation
between an element and the canonical element, given by Eq. (7.38), is negative, then
the nodes are not listed in the correct order. If the nodes are not ordered correctly,
then this may be fixed by interchanging the order of two nodes of that element in the
connectivity array. Suppose a list of nodes lying on the boundary where Dirichlet
boundary conditions are applied is not available. This list may easily be generated
simply loop over all nodes, and check whether they lie on this boundary.
7.11 Exercises
7.1 Modify the computational implementation given in Listing 7.1 so that it may
be used to solve the partial differential equation
2u 2u
+ = 5, 3 < x < 3, 1 < y < 0,
x2 y2
7.2 Use a mesh generation package such as DistMesh, described in Sect. 7.10, to
generate a mesh of triangular elements that is a partitioning of the square 0 < x < 1,
0 < y < 1. Modify Listing 7.1 so that it uses the mesh that you have generated.
Confirm that your implementation is correct by comparison with the output from the
original implementation given by Listing 7.1.
7.3 In this exercise, we will calculate the finite element solution of the differential
equation given by
2u 2u
+ = 1, x 2 + y 2 < 1,
x2 y2
7.11 Exercises 141
u(x, y) = 0, x 2 + y 2 = 1.
1
u(x, y) = 1 x 2 y2 .
4
(a). Use a mesh generation package such as DistMesh, described in Sect. 7.10,
to generate a mesh of triangular elements that is a partitioning of the domain
x 2 + y 2 = 1.
(b). Modify Listing 7.1 so that it uses the mesh generated in part (a) to calculate
the finite element solution of the boundary value problem defined above. Verify
your solution is correct by comparison with the analytic solution.
7.4 Modify Listing 7.1 so that (i) the matrix A is stored as a full matrix, rather than
a sparse matrix; and (ii) the linear system is solved using the Matlabs backslash
operator. Investigate the performance of both implementations by varying the values
of N x and N y used as input.
Chapter 8
More General Elliptic Problems
In the previous chapter, we explained how to calculate the finite element solution of a
very simple elliptic partial differential equation, where Dirichlet boundary conditions
were applied on the whole boundary. We develop these ideas in this chapter to allow
the application of the finite element method to more general linear, elliptic partial
differential equations, and more general boundary conditions.
In this chapter, we will illustrate the application of the finite element method to the
model partial differential equation
where is some finite region of the (x, y)-plane, the vector-valued function q(x, y)
is given by
q1 (x, y)
q(x, y) = ,
q2 (x, y)
and p(x, y), q(x, y), r (x, y) and f (x, y) are given functions. We partition the bound-
ary into two regions, D and N . On the boundary D , we apply Dirichlet
boundary conditions:
where n is the normal vector to the boundary N , pointing out of the domain ,
and of unit length.
The Sobolev space H 1 () and the subspaces HE1 () and H01 () of H 1 () are
defined in Sect. 7.2.1. The first step when deriving the weak formulation of the
differential equation given by Eq. (8.1), subject to the boundary conditions given
by Eqs. (8.2) and (8.3), is to multiply the differential equation by a test function
v(x, y) H01 (), and to integrate the resulting product over the domain :
( ( pu) + q u + r u) v d A = f v d A. (8.4)
Applying the divergence theorem to the first term on the left-hand side of this equation
gives
v p (u) n ds + p (v) (u) + vq u + r uv d A = f v d A.
(8.5)
All that is now required to state the weak formulation of the boundary value
problem defined by Eqs. (8.1)(8.3) is to demand that the weak solution u(x, y)
satisfies the Dirichlet boundary conditions given by Eq. (8.2). We then define the
weak solution by:
find u(x, y) HE1 (), such that
p (v) (u) + vq u + r uv d A = f v dA + vg N ds, (8.6)
N
Having defined the weak solution by Eq. (8.6), the sets S Eh and S0h allow us to define
the finite element solution by
find U (x, y) S Eh , such that
p (i ) (U ) + i q U + rU i d A = f i d A + i g N ds,
N
(8.7)
N node
where Nnode is the number of nodes in the mesh, and note that U (x, y) written in
this form is a member of the set S h . We will assemble a system of Nnode algebraic
equations for the unknown values U1 , U2 , . . . , U Nnode using a similar procedure to
that used in Sect. 7.6 for the simple model partial differential equation. As in earlier
chapters, this system comprises two categories of equations. The first category of
equations ensure that U (x, y) satisfies the Dirichlet boundary conditions, so that
U (x, y) lies in the subset S Eh of the set S h , as required. The second category of
equations arises from substituting a suitable test function i (x) into Eq. (8.7). We
now discuss both categories of equations separately.
Suppose that node i of the mesh lies on D , the part of the boundary where Dirichlet
boundary conditions are applied. The Dirichlet boundary condition is satisfied at this
node if
U (xi , yi ) = g D (xi , yi ).
Recall from Eq. (7.26) that U (xi , yi ) = Ui . A suitable algebraic equation that ensures
that U (x, y) satisfies a Dirichlet boundary condition at node i is then
Ui = g D (xi , yi ). (8.9)
Suppose that node i of the mesh does not lie on the part of the boundary where Dirich-
let boundary conditions are applied. The basis function i (x, y) will be nonzero at
node i and will take the value zero at all other nodes. As such, i (x, y) will take
the value zero at all nodes on the part of the boundary where Dirichlet boundary
conditions are applied, and so i (x, y) S0h . Noting that Eq. (8.8) allows us to write
N node
we then substitute i (x, y) into Eq. (8.7) and obtain, after some manipulation,
N
node
p (i ) j + i q j + r i j d A U j =
j=1
f i d A + i g N ds.
N
(8.10)
8.5 The Algebraic Equations 147
We may now combine Eqs. (8.9) and (8.10) into the linear system
AU = b, (8.11)
and, if node i does not lie on D , we deduce from Eq. (8.10) that
Ai, j = p (i ) j + i q j + r i j d A,
j = 1, 2, . . . , Nnode , (8.14)
bi = f i d A + i g N ds. (8.15)
N
The only boundary conditions satisfied by the model partial differential equation in
Chap. 7 were Dirichlet boundary conditions. The model differential equation used in
this chapter contains the additional feature of some Neumann boundary conditions.
This results in an extra term in some entries of the vector on the right-hand side of
the linear system given by Eq. (8.11), specifically the integral over N that appears
in Eq. (8.15). We will see later that it is convenient to write this extra integral as the
sum of contributions from individual element edges.
As in earlier chapters, the linear system given by Eq. (8.11) is assembled by first
evaluating the entries given by Eqs. (8.14) and (8.15), i.e. the entries that are given by
integrals over the whole domain and, for the vector b, an extra integral over N . As
usual, the integrals over will be calculated by decomposing the integral into the
sum of integrals over individual elements. The integrals over N will, as explained
above, be calculated by decomposing these integrals into the sum of integrals over
individual element edges. We then write Eqs. (8.14) and (8.15), the equations that
apply when node i does not lie on D , as:
Nele
Ai, j = p (i ) j + i q j + r i j d A,
k=1 ek
j = 1, 2, . . . , Nnode , (8.16)
148 8 More General Elliptic Problems
Nele
NNeu
bi = f i d A + i g N ds, (8.17)
k=1 ek k=1 e Nk
where Nele is the number of elements in the mesh, ek is the region occupied by
element k, NNeu is the number of element edges that lie on N and e Nk is edge k
of the element edges that lie on N .
After the entries of A and b given by Eqs. (8.14) and (8.15) have been assembled,
we set the entries that are given explicitly by Eqs. (8.12) and (8.13). We now give
more details on how these tasks may be carried out.
We begin by calculating the contributions to Eqs. (8.16) and (8.17) that arise from
integrating over an element. Suppose that element k contains the nodes k1 , k2 , k3 ,
listed in an anti-clockwise order. We explained in Sect. 7.7.1 that only the basis
functions k1 (x), k2 (x), k3 (x) are nonzero on this element, and that the nonzero
contributions to Eqs. (8.16) and (8.17) from integrating over this element can be
(k)
stored in a 3 3 matrix Alocal with entries given by, for i = 1, 2, 3, j = 1, 2, 3:
(k)
Alocal,i, j = p(x, y) ki k j + ki q(x, y) k j + r (x, y)ki k j d A,
ek
(k)
and a vector with three entries blocal , where the entries are given by, for i = 1, 2, 3:
(k)
blocal,i = f (x, y)ki d A.
ek
(k)
As explained in Sect. 7.7.1, the entry Alocal,i, j contributes to entry Aki ,k j of the global
(k)
matrix A for i = 1, 2, 3, and j = 1, 2, 3. Similarly, the entry blocal,i contributes to
entry bki of the global vector b for i = 1, 2, 3.
We use the local basis functions given by Eqs. (7.12)(7.20) to write these local
(k)
contributions as integrals over the canonical triangle. The entries of Alocal,i, j are given
by, for i = 1, 2, 3, j = 1, 2, 3:
(k)
Alocal,i, j = p(x, y) local,i local, j + local,i q(x, y) local, j +
r (x, y)local,i local, j det(F) d A X ,
(8.18)
8.6 Assembling the Algebraic Equations 149
where, as in Chap. 7, , coupled with d A X , denotes integration over the canonical
triangular element and det(F) is the Jacobian of the transformation between element
k and the canonical element, given by Eq. (7.37). The partial derivatives that appear in
the integrand above may all be calculated using the method described in Sect. 7.7.1.
To evaluate the integral above, we need to write the functions p, q and r as functions
of X and Y , as these are the variables that we are integrating with respect to. This
is done by using Eqs. (7.12) and (7.13) to evaluate x and y as functions of X and
Y we note that these equations may be written in the form:
The function p(x, y), for example, may be evaluated for any values of X and Y by
first using the expressions above to calculate the required values of x and y.
(k)
Similarly, the entries, of blocal,i, j are given by, for i = 1, 2, 3,
(k)
blocal,i = f (x, y)local,i det(F) d A X , (8.19)
where the function f (x, y) may be written as a function of X and Y using the same
method as for functions of x and y that appear in Eq. (8.18).
The local contributions to A and b, given by Eqs. (8.18) and (8.19), are now
written as integrals of functions of X and Y over the canonical element. Although
we can write down explicit expressions for all terms that appear in the integrand of
these equations, performing the integration analytically may be very difficult, or even
impossible. For ordinary differential equations, we saw that the (one-dimensional)
integrals arising may be approximated numerically using quadrature. We will explain
in Sect. 8.7 how to approximate integrals over the canonical triangle, such as those
given by Eqs. (8.18) and (8.19), using quadrature.
Having evaluated the local contributions to A and b, we then add these local
contributions into the appropriate entries of A and b as described in Sect. 7.7.1. We
perform this operation on every element to assemble the integral over .
We now turn our attention to the second integral on the right-hand side of Eq. (8.17),
the integral over the part of the boundary where Neumann boundary conditions are
applied. Suppose that edge k of the element edges that lie on N , denoted by e Nk ,
connects node k1 to node k2 . Only the basis functions k1 and k2 will be nonzero
on this edge, and so there will be a nonzero contribution from this edge only to the
entries bk1 and bk2 of the global vector b. In the spirit of calculating only nonzero
local contributions, we store these two nonzero local contributions to b from this
150 8 More General Elliptic Problems
(k)
element edge in the vector blocal edge with two entries given by, for i = 1, 2,
(k)
blocal edge,i = ki (x, y)g N (x, y) ds. (8.20)
e Nk
As the edge e Nk connects node k1 to node k2 , points (x, y) that lie on this edge are
parameterised by, for 0 X 1,
Further, we may write the basis functions k1 and k2 in terms of the variable X on
this edge as, for 0 X 1,
k1 (X ) = 1 X,
k2 (X ) = X.
and x and y are given as functions of X by Eqs. (8.21) and (8.22), allowing g N (x, y)
to be evaluated along this edge as a function of X .
The integral given by Eq. (8.23) is an integral over the interval 0 X 1. It may
therefore be approximated using quadrature techniques, as described in Sect. 3.5. On
each element edge, having calculated the nonzero local contributions, we then add
(k)
these contributions into the global vector b: entry blocal edge,i contributes to the entry
bki of b for i = 1, 2.
Having assembled all entries of the linear system that are of the form given by
Eqs. (8.14) and (8.15), we then complete the assembly of the linear system by setting
8.6 Assembling the Algebraic Equations 151
the entries given by Eqs. (8.12) and (8.13). As explained in earlier chapters, it is
important to explicitly set all entries given by Eqs. (8.12) and (8.13), as incorrect
values may have been inserted into these entries while assembling the contributions
to Eqs. (8.14) and (8.15).
Assembling the linear system, as described in Sect. 8.6, requires us to evaluate inte-
grals of the form
h(X, Y ) d A X ,
X = X ,
Y = (1 X )Y .
Using this transformation, an integral over the canonical triangle of a function writ-
ten in (X, Y )-coordinates is related to an integral over the unit square in ( X , Y )-
coordinates by
1 1
h(X, Y ) d A X = h(X, Y )(1 X ) d X dY .
Y =0 X =0
where
1
h(Y ) = h(X, Y )(1 X ) d X
X =0
1
= h X , (1 X )Y (1 X ) d X .
X =0
M
h(Y ) = wm h Z m , (1 Z m )Y (1 Z m ). (8.25)
m=1
Similarly, the integral on the right-hand side of Eq. (8.24) is an integral over the
interval 0 Y 1, and may be approximated, using the same Gaussian quadrature
scheme, by
M
h(X, Y ) d A X = wn h(Z n ). (8.26)
n=1
Substituting Eqs. (8.25) into (8.26) yields our desired quadrature rule:
M
M
h(X, Y ) d A X = wm wn (1 Z m )h (Z m , (1 Z m )Z n ) . (8.27)
m=1 n=1
We calculate the finite element solution of the model problem defined, for 1 < x <
1, 1 < y < 1, by
u u
ex u + 3x + 2y 6u = 2ex (1 + x + 6y) ,
x y
The Dirichlet boundary conditions are handled by lines 5256, completing the
assembly of the linear system. The linear system is then solved (lines 5962), and
the finite element solution plotted in lines 6568.
The Matlab function in Listing 8.1 may be executed by typing, for example,
[x, y, lnods, U] = Chap8_CalculateExampleFem(50, 50);
50
51 % Handle Dirichlet boundary conditions
52 A ( dir_nodes ,:) = 0;
53 for i =1: l e n g t h ( d i r _ n o d e s )
54 A ( d i r _ n o d e s ( i ) , d i r _ n o d e s ( i )) = 1;
55 end
56 b ( d i r _ n o d e s ) = x ( d i r _ n o d e s ).^2 + 2* y ( d i r _ n o d e s ).^3;
57
58 % C o m p u t e ILU f a c t o r i s a t i o n of A
59 [ Lower , Upper ] = ilu ( A );
60
61 % Use ILU p r e c o n d i t i o n e d GMRES to solve linear system
62 U = gmres (A , b , 100 , [] , 1000 , Lower , Upper );
63
64 % Plot s o l u t i o n
65 t r i s u r f ( lnods , x , y , U );
66 x l a b e l ( x )
67 y l a b e l ( y )
68 z l a b e l ( U )
69
70
71
72
73 % F u n c t i o n to g e n e r a t e data s t r u c t u r e s r e q u i r e d by the mesh
74 f u n c t i o n [x , y , lnods , dir_nodes , n e u _ e d g e s ] = ...
75 G e n e r a t e M e s h ( Nx , Ny )
76
77 % Set e n t r i e s of l n o d s
78 lnods = zeros (2* Nx * Ny , 3);
79 for j =1: Ny ;
80 for i =1: Nx ;
81 ele = 2*( j -1)* Nx +2* i -1;
82 lnods ( ele ,:) = ...
83 [( j -1)*( Nx +1)+ i , (j -1)*( Nx +1)+ i +1 , j *( Nx +1)+ i ];
84
85 ele = ele +1;
86 lnods ( ele ,:) = ...
87 [ j *( Nx +1)+ i +1 , j *( Nx +1)+ i , (j -1)*( Nx +1)+ i +1];
88 end
89 end
90
91 % Set e n t r i e s of x and y over the i n t e r v a l from 0 to 1
92 x = zeros (( Nx +1)*( Ny +1) ,1);
93 y = zeros (( Nx +1)*( Ny +1) ,1);
94
95 for i =1: Nx +1
96 x ( i : Nx +1:( Nx +1)*( Ny +1)) = 2*( i -1)/ Nx -1;
97 end
98
99 for j =1: Ny +1
100 y (( j - 1 ) * ( Nx + 1 ) + 1 : j *( Nx +1)) = 2*( j -1)/ Ny -1;
101 end
102
103 % S p e c i f y l o c a t i o n s of D i r i c h l e t b o u n d a r y c o n d i t i o n s
104 % Nodes on y = -1
105 d i r _ n o d e s (1: Nx +1) = 1: Nx +1;
106 % Nodes on x =1
107 d i r _ n o d e s ( Nx +2: Nx + Ny +1) = 2*( Nx +1): Nx +1:( Ny +1)*( Nx +1);
108
109 % S p e c i f y l o c a t i o n s of N e u m a n n b o u n d a r y c o n d i t i o n s
110 % Edges on y =1
111 n e u _ e d g e s (1: Nx ,:) = [(( Ny +1)*( Nx +1): -1: Ny *( Nx +1)+2) , ...
112 (( Ny +1)*( Nx +1) -1: -1: Ny *( Nx +1)+1) ];
156 8 More General Elliptic Problems
113 % Edges on x = -1
114 n e u _ e d g e s ( Nx +1:2* Nx ,:) = [( Ny *( Nx +1)+1: -( Nx +1): Nx +2) , ...
115 (( Ny -1)*( Nx +1)+1: -( Nx +1):1) ];
116
117
118
119
120 % C a l c u l a t e local c o n t r i b u t i o n s to A and b from e l e m e n t k
121 f u n c t i o n [ A_local , b _ l o c a l ] = ...
122 C a l c u l a t e C o n t r i b u t i o n O n E l e m e n t ( x , y , lnods , k , p , ...
123 q1 , q2 , r , f )
124
125 % D e f i n e x and y c o o r d i n a t e of each node
126 x1 = x ( lnods (k ,1));
127 x2 = x ( lnods (k ,2));
128 x3 = x ( lnods (k ,3));
129 y1 = y ( lnods (k ,1));
130 y2 = y ( lnods (k ,2));
131 y3 = y ( lnods (k ,3));
132
133 % C a l c u l a t e J a c o b i a n of t r a n s f o r m a t i o n b e t w e e n c a n o n i c a l
134 % e l e m e n t and e l e m e n t k
135 detF = ( x2 - x1 )*( y3 - y1 ) - ( x3 - x1 )*( y2 - y1 );
136
137 % E v a l u a t e d e r i v a t i v e s of basis f u n c t i o n s in terms of (x , y )
138 % coordinates
139 Finv = [ y3 - y1 , x1 - x3 ; y1 - y2 , x2 - x1 ]/ detF ;
140 d p h i _ d X = [ -1 , -1; 1 , 0; 0 , 1];
141 d p h i _ d x = d p h i _ d X * Finv ;
142
143 % Define quadrature points
144 M = 3;
145 Q u a d W e i g h t s = [5/18 , 4/9 , 5 / 1 8 ] ;
146 Q u a d P o i n t s = [0.5*(1 - sqrt (0.6)) , 0.5 , 0 . 5 * ( 1 + sqrt ( 0 . 6 ) ) ] ;
147
148 % I n i t i a l i s e local A and b to zero
149 A _ l o c a l = zeros (3 ,3);
150 b _ l o c a l = zeros (3 ,1);
151
152 % Loop over q u a d r a t u r e p o i n t s to c a l c u l a t e local ...
153 % c o n t r i b u t i o n s to A and b
154 for n =1: M
155 for m =1: M
156 % Set v a l u e s of basis f u n c t i o n s
157 phi (1) = 1 - Q u a d P o i n t s ( m ) - ...
158 (1 - Q u a d P o i n t s ( m ))* Q u a d P o i n t s ( n );
159 phi (2) = Q u a d P o i n t s ( m );
160 phi (3) = (1 - Q u a d P o i n t s ( m ))* Q u a d P o i n t s ( n );
161
162 % Set v a l u e s of x and y
163 x_val = x1 * phi (1) + x2 * phi (2) + x3 * phi (3);
164 y_val = y1 * phi (1) + y2 * phi (2) + y3 * phi (3);
165
166 % E v a l u a t e f u n c t i o n s of x and y
167 p_val = p ( x_val , y_val );
168 q 1 _ v a l = q1 ( x_val , y_val );
169 q 2 _ v a l = q2 ( x_val , y_val );
170 r_val = r ( x_val , y_val );
171 f_val = f ( x_val , y_val );
172
173 % Add w e i g h t e d q u a d r a t u r e value to local A and b
174 for i =1:3
175 for j =1:3
8.8 Computational Implementation 157
176 A _ l o c a l ( i , j ) = A _ l o c a l (i , j ) + ...
177 detF * Q u a d W e i g h t s ( m )* ...
178 Q u a d W e i g h t s ( n )*(1 - Q u a d P o i n t s ( m ))* ...
179 ( p _ v a l *( d p h i _ d x (i ,1)* dph i _ d x ( j ,1) + ...
180 d p h i _ d x ( i ,2)* dphi_dx (j ,2)) + ...
181 q 1 _ v a l * phi ( i )* d p h i _ d x ( j ,1) + ...
182 q 2 _ v a l * phi ( i )* d p h i _ d x ( j ,2) + ...
183 r_val * phi ( i )* phi ( j ));
184 end
185 b _ l o c a l ( i ) = b _ l o c a l ( i ) + ...
186 detF * Q u a d W e i g h t s ( m )* Q u a d W e i g h t s ( n )* ...
187 (1 - Q u a d P o i n t s ( m ))* f_val * phi ( i );
188 end
189 end
190 end
191
192
193
194
195
196
197 f u n c t i o n b _ l o c a l = ...
198 C a l c u l a t e C o n t r i b u t i o n O n N e u m a n n E d g e (x , y , neu_edges , ...
199 k , gn )
200
201 % D e f i n e x and y c o o r d i n a t e of each node
202 x1 = x ( n e u _ e d g e s ( k ,1));
203 x2 = x ( n e u _ e d g e s ( k ,2));
204 y1 = y ( n e u _ e d g e s ( k ,1));
205 y2 = y ( n e u _ e d g e s ( k ,2));
206
207 % C a l c u l a t e l e n g t h of edge
208 h = sqrt (( x1 - x2 )^2 + ( y1 - y2 )^2);
209
210 % D e f i n e q u a d r a t u r e rule
211 M = 3;
212 Q u a d W e i g h t s = [5/18 , 4/9 , 5 / 1 8 ] ;
213 Q u a d P o i n t s = [0.5*(1 - sqrt (0.6)) , 0.5 , 0 . 5 * ( 1 + sqrt ( 0 . 6 ) ) ] ;
214
215 % I n i t i a l i s e local b to zero
216 b _ l o c a l = zeros (2 ,1);
217
218 % Loop over q u a d r a t u r e p o i n t s to c a l c u l a t e local
219 % c o n t r i b u t i o n s to b
220 for m =1: M
221 % Define basis f u n c t i o n s at each q u a d r a t u r e point
222 phi = [1 - Q u a d P o i n t s ( m ); Q u a d P o i n t s ( m )];
223
224 % D e f i n e v a l u e s of x and y
225 x_val = x1 * phi (1) + x2 * phi (2);
226 y_val = y1 * phi (1) + y2 * phi (2);
227
228 % E v a l u a t e g_N
229 g n _ v a l = gn ( x_val , y_val );
230
231 % Add w e i g h t e d c o n t r i b u t i o n to b
232 b _ l o c a l = b _ l o c a l + h * Q u a d W e i g h t s ( m )* g n _ v a l * phi ;
233 end
158 8 More General Elliptic Problems
8.9 Exercises
8.1 Calculate the finite element solution of the boundary value problem, defined for
0 < x < 2, 0 < y < 1, by
2u 2u u u
4 + +4 +2 + 2u = 1,
x2 y2 x y
1
u(x, 0) = ex + , 0 < x < 2,
2
1
u(2, y) = e y+2
+ , 0 < y < 1,
2
1
u(x, 1) = ex+1 + , 0 < x < 2,
2
1
u(0, y) = e y + , 0 < y < 1.
2
The solution of this boundary value problem is u(x, y) = ex+y + 21 . Use this analytic
solution to verify that your finite element solution is correct.
8.2 Calculate the finite element solution of the boundary value problem, defined for
0 < x < 2, 1 < y < 0, by
2 2 u u
ex y u + ex + ey ey u = 2xe y 2,
x y
8.3 Modify your solution to Exercise 8.2 to calculate the finite element solution of
the boundary value problem, defined for 0 < x < 2, 1 < y < 0, by
2 2 u u
ex y u + ex + ey ey u = 2xe y 2,
x y
8.9 Exercises 159
ex y (u) n = 1
2
0 < x < 2, y = 1,
ex y (u) n = 0
2
x = 0, 1 < y < 0.
2
+y
Use the true solution, u(x, y) = ex , to verify that your finite element solution is
correct.
(u) n = 2,
0 < x < 10, y = 1,
(u) n = 2(x + y), 10 < x < 11, x + y = 11.
(a) Modify the mesh generated in Listing 8.1 so that it covers the region given by
0 < x < 10, 0 < y < 1.
(b) Scale the values of xi at each node in the mesh generated in part (a) by a factor
of 1 + 0.1(1 yi ), and verify that this new mesh partitions the region .
(c) Use the mesh generated in part (b) to calculate the finite element solution of the
boundary value problem above. Verify that your finite element solution is correct
by comparison with the true solution.
8.5 A more general partial differential equation than that given by Eq. (8.1) is defined
on some region by
160 8 More General Elliptic Problems
and P11 , P12 , P21 , P22 , q, r, f are given functions. On the boundary D , we apply
Dirichlet boundary conditions:
where n is the normal vector to the boundary N , pointing out of the domain ,
and of unit length.
(a) Write down the weak formulation of the boundary value problem above.
(b) Note that, if
4 0
P(x, y) = ,
0 1
then
2u 2u
(P(x, y)u) = 4 + .
x2 y2
Calculate the finite element solution of the partial differential equation, defined
for 0 < x < 1, 0 < y < 1, by
2u 2u
4 2+ 2 + 2x + 4x 2 y 2 + 4y 4 u = 0,
x y
where is some finite region of the (x, y)-plane, and p(x, y), q(x, y), r (x, y) and
f (x, y) are given functions. The boundary, , is partitioned into two regions, D
and N . On the boundary D , we apply Dirichlet boundary conditions:
where n is the normal vector to the boundary N , pointing out of the domain ,
and of unit length.
The weak formulation of Eqs. (9.1)(9.3) is identical to that derived in Sect. 8.2 and
is given by:
In the exercises at the end of this chapter, we will develop computational imple-
mentations for calculating the finite element solution of boundary value problems.
These boundary value problem will be posed on rectangular domains a < x < b,
c < y < d, where a, b, c, d are constants, and so we now explain how to partition a
rectangular domain into a mesh of quadrilateral elements.
A rectangular domain may easily be partitioned into a mesh of uniform rectangles,
with N x rectangles in the x-direction and N y rectangles in the y-direction, as shown in
Fig. 9.1 when N x = 2 and N y = 3. As with the mesh of triangular elements developed
in Sect. 7.3.1, we number the nodes, starting with the node at the bottom left-hand
corner of the mesh, and number the nodes consecutively moving in the x-direction
from this first node. We then move up to the next row in the y-direction and repeat
this process, starting from the node at the left-hand end of these nodes. We proceed
through the mesh in this fashion until all nodes have been numbered. This numbering
convention is illustrated in Fig. 9.1a when N x = 2 and N y = 3. A similar process
is used to number the elementsthis is illustrated in Fig. 9.1b when N x = 2 and
N y = 3.
As when using a mesh of triangular elements, we will require a connectivity
array, again called lnods, to store the nodes of each element. Row k of this array will
store the nodes of element k, listed in an anticlockwise direction. Each quadrilateral
element will contain four nodes and so, if there are Nele elements in the mesh, this
array will be of size Nele 4. For the mesh shown in Fig. 9.1, where N x = 2 and
N y = 3, the connectivity array may be written as
1 2 5 4
2 3 6 5
4 5 8 7
lnods =
5
.
6 9 8
7 8 11 10
8 9 12 11
9.3 The Computational Mesh 163
(a) (b)
10 11 12
1 1
0.8 0.8 5 6
7 8 9
0.6 0.6
y
y
3 4
0.4 4 5 6 0.4
0.2 0.2
1 2
1 2 3
0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x
Fig. 9.1 a The labelling of the nodes in the mesh. b The labelling of the elements in the mesh
In common with a mesh of triangular elements, the connectivity array is not unique.
First, the order that the elements of the mesh are stored in does not matter, and so we
may interchange any of the rows of this array. Furthermore, we only have to list the
nodes of each element in an anticlockwise directionthe first row of the connectivity
array above could be written 2, 5, 4, 1, or 5, 4, 1, 2 or 4, 1, 2, 5 instead of 1, 2, 5, 4.
In Sect. 7.3.1, we defined a hanging node to be a point in the domain that
is a node of one element, but lies on an edge of another element without being a
node. We illustrate an example of a hanging node in a mesh of quadrilateral elements
in Fig. 9.2, with the hanging node identified by an open circle. As with triangular
elements, we do not permit hanging nodes in a mesh of quadrilateral elements.
Finally, we reiterate the warning about long, thin elements that we first gave
in Sect. 7.3.1. Symptoms of long, thin elements include the following: (i) a high
ratio between the length of the longest edge and the length of the shortest edge of
an element; (ii) a very low interior angle between edges of an element; or (iii) an
interior angle between edges of an element that is close to 180 . Elements such
as these should be avoided, as they can degrade the accuracy of the finite element
solution.
0.8
0.6
y
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1
x
164 9 Quadrilateral Elements
In the previous chapters, whether calculating the finite element solution of an ordi-
nary differential equation or a partial differential equation, we defined global basis
functions through: (i) a transformation between a general element of the mesh and
a canonical element and (ii) the definition of local basis functions on this canonical
element. For a mesh of quadrilateral elements, a suitable canonical element is the
unit square in (X, Y )-coordinates, defined by 0 X 1, 0 Y 1, and illustrated
in Fig. 9.3.
Suppose element k of the mesh includes nodes the k1 , k2 , k3 , k4 , listed in an
anticlockwise direction. A mapping between this element (in (x, y)-coordinates)
and the canonical element (in (X, Y )-coordinates) is defined by, for 0 X 1,
0 Y 1:
Local basis functions on the canonical element are defined by, for 0 X 1,
0 Y 1,
The local basis functions defined by Eqs. (9.7)(9.10) are known as bilinear local
basis functions, as they are products of a linear function of X and a linear function
of Y . They are not, however, linear functions when viewed as a function of both X
0.6
Y
y
0.4
0.2
(xk2 , yk2 )
(xk1 , yk1 ) 0
1 1
0.5 0.5
1 1
0 0.5 0 0.5
0 0.5 0 0 0.5 0
1 Y 1 Y
X X
1 1
0.5 0.5
1 1
0 0.5 0 0.5
0 0.5 0 0 0.5 0
1 Y 1 Y
X X
Fig. 9.4 The local basis functions local,1 , local,2 , local,3 , local,4 defined by Eqs. (9.7)(9.10)
and Y however, as they include the quadratic term X Y . These local basis functions
are illustrated in Fig. 9.4.
Global basis functions are now defined on element k, in terms of the local basis
functions given by Eqs. (9.7)(9.10), by
We now define the sets of functions S h , S Eh , S0h that will be used when specifying the
finite element solution. We define
N node
Having defined the weak solution by Eq. (9.4), the sets S Eh and S0h defined in Sect. 9.5
allow us to define the finite element solution by:
9.7 The System of Algebraic Equations 167
N node
where Nnode is the number of nodes in the mesh. It is easy to see that U (x, y), as
defined above, lies in the set S h .
Although the basis functions, 1 , 2 , . . . , Nnode , used in this chapter are different
from the basis functions used in Chap. 8, both the form of the finite element solution,
Eq. (9.18), and the finite element formulation, Eq. (9.17), are identical to those given
in Eqs. (8.7) and (8.8) in Chap. 8. As a consequence, we may use the same arguments
as in Sect. 8.5.3 to deduce that the algebraic equations satisfied by U1 , U2 , . . . , U Nnode
may be written as:
AU = b, (9.19)
The entries of A and b given by Eqs. (9.22) and (9.23) are therefore written in an
identical form to those given by Eqs. (8.14) and (8.15). They differ, however, as the
basis functions used in this chapter are different to those used in Chap. 8.
We will follow the usual procedure when calculating the entries of the linear system
given by Eq. (9.19)that is, we first evaluate the entries, given by Eqs. (9.22) and
(9.23), that are given by integrals over the domain, , and integrals over the part
of the boundary where Neumann boundary conditions are applied, N . As before,
the integrals over will be calculated by decomposing the integral into the sum of
integrals over individual elements, and the integrals over N will be calculated by
decomposing the integral into the sum of integrals over element edges that lie on
N . We therefore write Eqs. (9.22) and (9.23), the equations for row i of the linear
system given by Eq. (9.19), where node i of the mesh does not lie on D , as
Nele
Ai, j = p (i ) j + i q j + r i j d A,
k=1 ek
j = 1, 2, . . . , Nnode , (9.24)
Nele
NNeu
bi = f i d A + i g N ds, (9.25)
k=1 ek k=1 e Nk
where Nele is the number of elements in the mesh, ek is the region occupied by ele-
ment k, NNeu is the number of element edges that lie on N , and e Nk is edge k of
the element edges that lie on N . We note that Eqs. (9.24) and (9.25) appear iden-
tical to Eqs. (8.16) and (8.17). The difference is that the basis functions i (x, y) are
now defined by Eqs. (9.5)(9.15) rather than Eqs. (7.12)(7.20). We may, however,
assemble these entries of A and b in the same fashion as in Sects. 8.6.1 and 8.6.2
that is, we first calculate the local contributions from integrating over each element,
before calculating the local contributions from integrating along each element edge
that lies on N .
Having assembled the entries of the linear system that are of the form given by
Eqs. (9.22) and (9.23), we then set the entries given by Eqs. (9.20) and (9.21) to
complete the assembly of the linear system. We now describe each of these steps in
a little more detail.
9.8 Assembling the System of Algebraic Equations 169
We begin by calculating the contributions to Eqs. (9.24) and (9.25) that arise from
integrating over each element. Suppose element k contains the nodes k1 , k2 , k3 ,
k4 , listed in an anticlockwise order. The only basis functions that are nonzero on
this element are k1 (x), k2 (x), k3 (x), k4 (x), and so the nonzero contributions to
(k)
Eq. (9.24) from integrating over this element can be stored in a matrix Alocal of size
4 4, with entries given by, for i = 1, 2, 3, 4, j = 1, 2, 3, 4:
(k)
Alocal,i, j = p(x, y) ki k j + ki q(x, y) k j + r (x, y)ki k j d A,
ek
(k)
where entry Alocal,i, j contributes to entry Aki ,k j of the global matrix A.
Similarly, the only nonzero contributions to Eq. (9.25) from integrating over this
(k)
element may be stored in a vector with four entries, blocal , with entries given by, for
i = 1, 2, 3, 4:
(k)
blocal,i = f (x, y)ki d A,
ek
(k)
where entry blocal,i contributes to entry bki of the global vector b.
As in earlier chapters, we will find it convenient to write these local contributions
as integrals over the canonical element, in this case the unit square given by 0
X 1, 0 Y 1. Using the transformation between element k and the canonical
element given by Eqs. (9.5)(9.6), and the definition of local basis functions given
by Eqs. (9.11)(9.14), we may write, for i = 1, 2, 3, 4, j = 1, 2, 3, 4:
(k)
1 1
local,i local, j local,i local, j
Alocal,i, j = p(x, y) + +
Y =0 X =0 x x y y
local, j local, j
local,i q1 (x, y) + q2 (x, y) +
x y
r (x, y)local,i local, j det(F) dX dY,
(9.26)
which may be computed using the definitions of x and y given by Eqs. (9.5)(9.6).
To evaluate the integral that appears in Eq. (9.26), we must first write all terms
in the integrand as functions of X and Y . We may use the chain rule to evaluate the
170 9 Quadrilateral Elements
partial derivatives of the basis functions that appear in the integral, as was done for
basis functions on a triangular element in Eq. (7.39):
local,1 local,1
local,1 local,1
x y
local,2 local,2 X Y
local,2 local,2 X X
X x y
x y Y
local,3 local,3 = local,3 local,3 Y Y
X
x y Y x y
local,4 local,4 local,4 local,4
x y X Y
(1 Y ) (1 X )
1Y X
=
F 1 ,
(9.27)
Y X
Y 1 X
where we have used the definition of local basis functions given by Eqs. (9.7)(9.10)
to evaluate the partial derivatives of these local basis functions with respect to X and
Y , and noted that
X X
x 1
x
x y
Y Y
= X Y
y y
x y X Y
= F 1 .
On using Eq. (9.27), we may now express all the partial derivatives that appear in
Eq. (9.26) as functions of X and Y . Note that, in contrast to the partial derivatives of
linear basis functions in Chaps. 7 and 8, the partial derivatives of the bilinear basis
functions used in this chapter are not constant on each element.
Functions such as p(x, y) may be evaluated as functions of X and Y by first
using Eqs. (9.5)(9.6) to calculate x and y as functions of X and Y , before using
these expressions for x and y to evaluate p(x, y). We may now evaluate all terms
that appear in the integrand of Eq. (9.26) as functions of X and Y . If this integral
cannot be evaluated analytically, we may use quadrature to approximate its value
numerically; we explain in Sect. 9.9 how quadrature may be performed over the unit
square 0 X 1, 0 Y 1.
Using the same change of variable as above, we may write the local nonzero
contributions to b from element k as, for i = 1, 2, 3, 4:
1 1
(k)
blocal,i = f (x, y) local,i (X, Y ) det(F) dX dY. (9.28)
Y =0 X =0
The function f (x, y) may be evaluated on the canonical element as described earlier
for functions such as p(x, y). The integral above may then be evaluated analytically,
or approximated numerically, using quadrature.
9.9 Quadrature 171
Having assembled the contributions to Eqs. (9.24) and (9.25) from integration over
elements, we now assemble the contribution to (9.25) from integration over element
edges that lie on N . This may be done in an identical fashion to that described in
Sect. 8.6.2.
Finally, we set the entries of A and b given by Eqs. (9.20) and (9.21). At this stage,
it is important to correct any incorrect entries that have been introduced into these
rows earlier in the assembly processsee Sect. 8.6.3 for more details.
9.9 Quadrature
When calculating the contributions to the global matrix A and global vector b that
are given by Eqs. (9.26) and (9.28), we have to evaluate integrals of the form
1 1
h(X, Y ) dX dY. (9.29)
Y =0 X =0
where
1
h(Y ) = h(X, Y ) dX, (9.31)
X =0
we will now show that we may evaluate Eq. (9.29) using numerical quadrature,
by adapting the material presented in Sect. 3.5. Suppose we have a quadrature
rule for integrating over the interval 0 Z 1 that uses m quadrature points
Z 1 , Z 2 , . . . , Z m , with weights w1 , w2 , . . . , w M . We may then write Eq. (9.31) as
M
h(Y ) = wm h(Z m , Y ).
m=1
1 1
M 1
h(X, Y ) dX dY = wm h(Z m , Y ) dY,
Y =0 X =0 m=1 Y =0
where we have interchanged the order of integration and summation. We then apply
the same quadrature rule to the integral over 0 Y 1 on the right-hand side of the
equation above to obtain
1 1
M
h(X, Y ) dX dY = wm wn h(Z m , Z n ),
Y =0 X =0 m=1 n=1
which may be used to approximate the integrals given by Eqs. (9.26) and (9.28).
9.10 Exercises
We suggest that the reader begins with the exercise below. Other suitable exercises
are then the exercises at the end of Chap. 8, where a finite element solution to the
boundary value problems given in these exercises can be calculated using a mesh of
quadrilateral elements and bilinear basis functions.
u u
ex u + 3x + 2y 6u = 2ex (1 + x + 6y) ,
x y
(a) Lines 7889 of Listing 8.1 generate the connectivity array lnods for a mesh of
triangular elements. Modify this function so that it generates the connectivity
array for a mesh of quadrilateral elements, discussed in Sect. 9.3.
(b) Modify the function CalculateContributionOnElement so that it com-
putes the nonzero local contributions to the linear system that arise from integrat-
(k) (k)
ing over element k, Alocal and blocal , discussed in Sect. 9.8.1. When modifying
this function, you should remember the following: (i) there are now four nodes
(k)
in each element, and so there will be four local basis functions, and Alocal and
(k)
blocal will be of a different size; (ii) expressions for the Jacobian of the transfor-
mation F and local basis functions will be different; (iii) the Jacobian and partial
derivatives of the basis functions will no longer be constant over the element;
and (iv) the quadrature rule for integrating over the canonical square element is
different to the quadrature rule for integrating over the canonical triangle that is
used in Listing 8.1.
(c) Make any other modifications that are needed, such as the number of elements
that are looped over in lines 2129 of Listing 8.1, and verify your implementation
is correct by comparison with the true solution.
Chapter 10
Higher Order Basis Functions
In Chap. 4, we described the use of quadratic, and higher order, basis functions
when calculating the finite element solution of ordinary differential equations. In this
chapter, we will explain how higher order basis functions may be used to calculate the
finite element solution of a partial differential equation. We give a concrete example
of the use of quadratic basis functions on a mesh of triangular elements. The exercises
at the end of the chapter contain examples of higher order basis functions on meshes
of both triangular and quadrilateral elements.
where is some finite region of the (x, y)-plane, and p(x, y), q(x, y), r (x, y) and
f (x, y) are given functions. The boundary, , is partitioned into two regions, D
and N . On the boundary D , we apply Dirichlet boundary conditions:
where n is the normal vector to the boundary N , pointing out of the domain
and of unit length. The weak solution, derived in Sect. 8.2, is defined by:
find u(x, y) HE1 (), such that
p (v) (u) + vq u + r uv d A = f v dA + N vg N ds, (10.4)
We partition the mesh into triangular elements, as described in Sect. 7.3.1. A quadratic
approximation to the solution on an element will take the form
a1 + a2 x + a3 y + a4 x 2 + a5 x y + a6 y 2 ,
k1 , k2 , k3 , k4 , k5 , k6 ,
or k2 , k3 , k1 , k5 , k6 , k4 ,
or k3 , k1 , k2 , k6 , k4 , k5 .
The connectivity array for the mesh shown in Fig. 10.1 could be written as
10.2 Quadratic Basis Functions on a Mesh of Triangular Elements 177
1.2
31 32 33 34 35
1
26 27 28 29 30
0.8
21 22 23 24 25
0.6
y
16 17 18 19 20
0.4
11 12 13 14 15
0.2 6 7 8 9 10
1 2 3 4 5
0
Fig. 10.1 The nodes and elements of a mesh of triangular elements that may be used with quadratic
basis functions
(xk3 , yk3 )
(xk4 , yk4 )
(xk5 , yk5 )
y
(xk2 , yk2 )
(xk6 , yk6 )
(xk1 , yk1 )
1
local,1 (X, Y ) = 2(1 X Y ) X Y , (10.7)
2
1
local,2 (X, Y ) = 2X X , (10.8)
2
1
local,3 (X, Y ) = 2Y Y , (10.9)
2
local,4 (X, Y ) = 4X Y, (10.10)
local,5 (X, Y ) = 4Y (1 X Y ), (10.11)
local,6 (X, Y ) = 4X (1 X Y ). (10.12)
0 0 0
0 1 0 1 0 1
0 0.5 0 0.5 0 0.5
0.5 1 0 0.5 1 0 0.5 1 0
Y Y Y
X X X
(a) 1 (b) 1
0.5 0.5
0 0
4 4
0 2 0 2
2 0 2 0
4 y 4 y
x x
Some example basis functions are shown in Fig. 10.4. In Fig. 10.4a, we show an
example basis function that takes the value 1 at a node that is at the vertex of a
triangle. In Fig. 10.4b, we show an example basis function that takes the value 1 at a
node that is at the mid-point of the edge of a triangle.
Remember that nodes that are not at a vertex of a triangular element are placed at
the mid-point of an edge of an element. Suppose the mesh contains Nnode nodes. It is
then straightforward to verify that the basis functions given by Eqs. (10.5)(10.14)
satisfy, for j = 1, 2, . . . , Nnode , the usual condition:
1, i = j,
j (xi ) = (10.15)
0, i = j.
180 10 Higher Order Basis Functions
N
node
S = functions V (x, y) given by V (x, y) =
h
V j j (x, y), where j (x, y),
j=1
j = 1, 2, . . . , Nnode , are defined by Eqs. (10.5)(10.14) ,
S Eh = functions V (x, y) in S h such that V (x, y) satisfies all Dirichlet boundary
conditions ,
S0h = functions V (x, y) in S h such that V (x, y) = 0 at all points (x, y) where
Dirichlet boundary conditions are specified .
These sets, and the weak formulation of the problem given by Eq. (10.4), allow us to
define the finite element solution by
N node
where Nnode is the number of nodes in the mesh. As explained in Sects. 8.5.3 and 9.7,
the algebraic equations satisfied by U1 , U2 , . . . , U Nnode may be written as
AU = b, (10.18)
10.4 The Algebraic Equations 181
The entries of the linear system given by Eq. (10.18) are assembled in the same
way as they have been throughout this book. We first assemble the entries given
by Eqs. (10.21) and (10.22). There are two components to handle when assembling
these entries. First, we calculate the terms in Eqs. (10.21) and (10.22) that arise from
integrating over . We then calculate the terms in Eq. (10.22) that arise from inte-
grating over N . Having calculated the entries given by Eqs. (10.21) and (10.22),
we then set the entries given by Eqs. (10.19) and (10.20). We now give more details
on how these tasks are performed for quadratic basis functions. We assume that the
reader is familiar with the assembly of the linear system described in Sect. 8.6 when
linear basis functions were used and focus on the description of additional features
that arise when using quadratic basis functions.
We calculate the integrals over that appear in Eqs. (10.21) and (10.22) by summing
the contributions to these integrals from individual elements. Suppose the nodes of
element k are k1 , k2 , k3 , k4 , k5 , k6 , listed in the order prescribed for the connectivity
array lnods. Only the basis functions ki , i = 1, 2, . . . , 6, will be nonzero on this
element, and so the nonzero local contributions to Eqs. (10.21) and (10.22) from
(k) (k)
integration over this element may be stored in a 6 6 matrix Alocal and a vector blocal,
(k)
with six entries. Using Eqs. (10.5)(10.14), we may write the entries of Alocal,i, j as
integrals over the canonical element given by, for i = 1, 2, . . . , 6, j = 1, 2, . . . , 6:
182 10 Higher Order Basis Functions
(k)
Alocal,i, j = p(x, y) local,i local, j + local,i q(x, y) local, j +
(k)
Entry Alocal,i, j , i = 1, 2, . . . , 6, j = 1, 2, . . . , 6, contributes to entry Aki ,k j of A, and
(k)
entry blocal,i , i = 1, 2, . . . , 6, contributes to entry bki of b.
We now need to write each term in the integrands of Eqs. (10.23) and (10.24) as
a function of X and Y . Remembering from Eq. (7.37) that
x x
X Y
F= y y
X Y
x k2 x k1 x k3 x k1
= , (10.25)
yk2 yk1 yk3 yk1
we may easily evaluate the determinant of F. Further, Eq. (7.40) allows us to write
X X
x y
Y Y
= F 1 ,
x y
allowing us to use the chain rule to evaluate partial derivatives of the basis local
functions with respect to x and y. These partial derivatives are given by, for i =
1, 2, . . . , 6:
Functions such as p(x, y) may be written as functions of X and Y by using Eqs. (10.5)
and (10.6) to first write x and y as functions of X and Y .
All terms in the integrands of Eqs. (10.23) and (10.24) may now written as a
function of X and Y . The integrals may then be evaluated, either analytically, or
using the quadrature rules over the canonical triangle derived in Sect. 8.7.
10.5 Assembling the Algebraic Equations 183
In contrast to the integrals over element edges described in Sect. 8.6.2, the edges of
elements will now contain three nodes. Suppose that edge k of the element edges
that lie on N , denoted by e Nk , starts at node k1 , passes through node k2 and ends
at node k3 . Only the basis functions k1 , k2 and k3 will be nonzero on this edge. As
a consequence, the contribution to Eq. (10.22) from integration over this edge will
generate nonzero contributions only to the entries bk1 , bk2 and bk3 of the global vector
b. We store only these three nonzero local contributions from integrating over this
(k)
edge in the vector blocal edge with entries given by, for i = 1, 2, 3,
(k)
blocal edge,i = ki (x, y)g N (x, y) ds. (10.26)
e Nk
(k)
Entry blocal edge,i , i = 1, 2, 3, of these local contributions will contribute to the entry
bki of the global vector b. As the edge e Nk connects node k1 to node k3 , and the
edge is a straight line, points x and y that lie on this edge are parameterised by, for
0 X 1,
Further, we may write the basis functions k1 , k2 and k3 in terms of the variable X
as, for 0 X 1,
1
k1 (X ) = 2 X (1 X ),
2
k2 (X ) = 4X (1 X ),
1
k3 (X ) = 2X X .
2
Finally, we set the entries of A and b given by Eqs. (10.19) and (10.20). At this stage,
it is important to correct any incorrect entries that have been introduced earlier in the
assembly processsee Sect. 8.6.3 for more details.
10.6 Exercises
The exercises below implement the material described in this chapter. Should the
reader wishes to apply these techniques to other boundary value problems, then
suitable examples are given in the exercises at the end of Chap. 8.
u u
ex u + 3x + 2y 6u = 2ex (1 + x + 6y) ,
x y
(a) The function GenerateMesh contained in Listing 8.1 generates the coordi-
nates of nodes, the connectivity array lnods, a list of nodes on the Dirichlet
10.6 Exercises 185
boundary and an array that stores the nodes that lie on each element edge of the
boundary N . Replace the function GenerateMesh contained in Listing 8.1
by a new function that generates these arrays for quadratic basis functions.
(b) Modify the function CalculateContributionOnElement so that it com-
putes the local contributions to the linear system that arise from integrating over
(k) (k)
element k, Alocal and blocal , when quadratic basis functions are used. When mod-
ifying this function, you should remember that: (i) there are now six nodes in
(k)
the local element, and so there will be six local basis functions, and Alocal and
(k)
blocal will be of a different size; (ii) expressions for the local basis functions will
be different to the original listing; and (iii) the partial derivatives of the basis
functions will no longer be constant over the element.
(c) Modify the function CalculateContributionOnNeumannEdge so that
it now calculates the contribution from integrating over an element edge that lies
on N when quadratic basis functions are used.
(d) Make any other modifications to Listing 8.1 that are needed, such as changing
the size of the global matrix A and global vector b in lines 1617.
Verify that your implementation is correct by comparison with the true solution.
a1 + a2 x + a3 y + a4 x 2 + a5 x y + a6 y 2 + a7 x 3 + a8 x 2 y + a9 x y 2 + a10 y 3 ,
and so we have ten degrees of freedom on each element. We therefore need to define
ten local basis functions on the canonical triangular element. Ten nodes on this
element are shown in Fig. 10.5, together with a local numbering of nodes. Suitable
local basis functions are then
9 1 2
local,1 (X, Y ) = X Y X Y (1 X Y ) ,
2 3 3
9 1 2
local,2 (X, Y ) = X X X ,
2 3 3
9 1 2
local,3 (X, Y ) = Y Y Y ,
2 3 3
27 1
local,4 (X, Y ) = XY X ,
2 3
27 1
local,5 (X, Y ) = XY Y ,
2 3
27 1
local,6 (X, Y ) = Y Y (1 X Y ) ,
2 3
27 2
local,7 (X, Y ) = Y X Y (1 X Y ) ,
2 3
186 10 Higher Order Basis Functions
6 5
2/3
Y
7 10 4
1/3
1 8 9 2
0
0 1/3 2/3 1
X
27 2
local,8 (X, Y ) = X X Y (1 X Y ) ,
2 3
27 1
local,9 (X, Y ) = X X (1 X Y ) ,
2 3
local,10 (X, Y ) = 27X Y (1 X Y ) .
(a) Generate a mesh that partitions the region 0 < x < 1, 0 < y < 1 into triangular
elements. Generate nodes so that each element has nodes that may be mapped
to the nodes of the canonical element shown in Fig. 10.5.
(b) The model boundary value problem in Chap. 7 was defined by
2u 2u
+ = 1, 0 < x < 1, 0 < y < 1,
x2 y2
Use the mesh generated in part (a) to calculate the finite element solution of this
boundary value problem that makes a cubic approximation to the solution on each
element. Validate your solution by comparison with the output of Listing 7.1.
8 9 6
Y
1/2
1 5 2
0
0 1/2 1
X
a1 + a2 x + a3 y + a4 x 2 + a5 x y + a6 y 2 + a7 x 2 y + a8 x y 2 + a9 x 2 y 2 ,
1
Q 1 (Z ) = 2 Z (1 Z ) ,
2
Q 2 (Z ) = 4Z (1 Z ),
1
Q 3 (Z ) = 2Z Z ,
2
local,1 (X, Y ) = Q 1 (X )Q 1 (Y ),
local,2 (X, Y ) = Q 3 (X )Q 1 (Y ),
local,3 (X, Y ) = Q 3 (X )Q 3 (Y ),
local,4 (X, Y ) = Q 1 (X )Q 3 (Y ),
local,5 (X, Y ) = Q 2 (X )Q 1 (Y ),
local,6 (X, Y ) = Q 3 (X )Q 2 (Y ),
local,7 (X, Y ) = Q 2 (X )Q 3 (Y ),
local,8 (X, Y ) = Q 1 (X )Q 2 (Y ),
local,9 (X, Y ) = Q 2 (X )Q 2 (Y ).
188 10 Higher Order Basis Functions
(a) Generate a mesh that partitions the region 0 < x < 1, 0 < y < 1 into quadri-
lateral elements. Generate nodes so that each element has nodes that may be
mapped to the nodes of the canonical element shown in Fig. 10.6.
(b) Use the mesh generated in part (a) to calculate the finite element solution to
the boundary value problem given in Exercise 10.2, where your finite element
solution makes a biquadratic approximation to the solution on each element.
Validate your solution by comparison with the output of Listing 7.1.
Chapter 11
Nonlinear Elliptic Partial Differential
Equations
In Chap. 5, we explained how to apply the finite element method to nonlinear ordinary
differential equations. We saw that calculating the finite element solution of nonlinear
differential equations required us to solve a nonlinear system of algebraic equations
and discussed how these algebraic equations could be solved.
In this chapter, we explain how to apply the finite element method to nonlinear
partial differential equations by combining: (i) the material on calculating the finite
element solution of linear partial differential equations given in Chaps. 710 and
(ii) the material on calculating the finite element solution of nonlinear ordinary
differential equations in Chap. 5. We consider equations of the form
u u u u
p x, y, u, , + r x, y, u, , = 0, (x, y) ,
x y x y
where is some subset of the (x, y)-plane, subject to suitable boundary conditions
on the boundary . The application of the finite element method to equations of
this form is illustrated using an example.
We illustrate the application of the finite element method to nonlinear elliptic partial
differential equations using the model differential equation, defined for the region
defined by 0 < x < 1, 0 < y < 1, by
2 2
u u
eu u + ex +y
2 2
+ + 4 = 0, (11.1)
x y
where n is the normal vector pointing out of , with unit length. This boundary
value problem has solution u(x, y) = x 2 + y 2 .
The weak formulation of the differential equation given by Eq. (11.1), subject to
the boundary conditions given by Eqs. (11.2)(11.5), is obtained by first multiplying
Eq. (11.1) by a test function v(x, y) H01 () and integrating the resulting product
over the region :
2 2
u u
v eu u + ex +y
2 2
+ +4 d A = 0.
x y
where is the boundary of , and n is the normal vector of unit length pointing out
of . As v(x, y) H01 (), then, by definition, v(x, y) = 0 on D , the part of the
boundary where Dirichlet boundary conditions are applied. Using this observation,
and the Neumann boundary condition given by Eq. (11.5), we may write the integral
above as
2
x 2 +y 2 u 2 u
2e y +1 v ds = 0,
2
e (u) (v) + ve
u
+ + 4 dA
x y N
11.2 The Weak Formulation 191
where N is the part of the boundary where Neumann boundary conditions are
applied, namely x = 1, 0 < y < 1.
The weak solution is then defined by:
find u(x, y) H E1 () such that
2 2
2 +y 2 u u
eu (u) (v) + ve x + +4 d A
x y
2 +1
2e y v ds = 0, (11.6)
N
N node
where Nnode is the number of nodes in the mesh. Using the definition of the weak
solution given by Eq. (11.6), we define the finite element solution by
find U (x, y) S Eh such that
2 2
2 +y 2 U U
eU (U ) (i ) + i e x + +4 d A
x y
2 +1
2e y i ds = 0, (11.8)
N
When applying the finite element method to linear differential equations, whether
ordinary differential equations or partial differential equations, the definition of the
finite element solution allowed us to derive a linear system of algebraic equations.
In Chap. 5, we saw that, for nonlinear ordinary differential equations, the definition
of the finite element solution resulted in a system of nonlinear algebraic equations
that we write as
R(U) = 0, (11.9)
where R is a vector of length Nnode . As with linear differential equations, the indi-
vidual equations that comprise Eq. (11.9) fall into two categories: (i) equations that
arise from forcing U (x, y) to satisfy the Dirichlet boundary conditions and lie in
the set S Eh ; and (ii) equations that arise from substituting a suitable basis function
i (x, y) into Eq. (11.8). We now discuss these categories separately.
We may combine the Dirichlet boundary conditions given by Eqs. (11.2)(11.4) into
the single boundary condition
Ui = g D (xi , yi ).
Entry i of the residual vector R that appears in Eq. (11.9) is therefore given by
Ri = Ui g D (xi , yi ). (11.10)
In Sect. 11.5.1, we derived an expression for entry Ri of the residual R that appears
in Eq. (11.9) when node i lies on D . Suppose, instead, that node i does not lie on
D . The basis function i (x, y) is then a member of the set S0h and is a suitable
11.5 The Nonlinear System of Algebraic Equations 193
test function for Eq. (11.8). When node i does not lie on D , we then have
2
x 2 +y 2 U U 2
Ri = e (U ) (i ) + i e
U
+ + 4 d A
x y
2e y +1 i ds.
2
N
(11.11)
Nele
U i U i
Ri = eU
+ +
k=1 ek
x x y y
2 2 Nneu
U U
x +y
2e y +1 i ds, (11.12)
2 2 2
i e + +4 dA
x y k=1 e Nk
where Nele is the number of elements in the mesh, ek is the area occupied by element
k, Nneu is the number of element edges that lie on N , and e Nk is element edge k
that lies on N .
To use the finite element solution given by Eq. (11.7), we first have to solve the system
of nonlinear algebraic equations, Eq. (11.9), with entries given by Eqs. (11.10) and
(11.11). In Chap. 5, we saw that computational methods exist for solving systems
of nonlinear algebraic equations that require only the specification of the residual
vector R. These methods are, however, inefficient for systems with a large number
of unknowns. Under these conditions, more efficient computational methods should
be used that require, in addition to the residual vector R, the Jacobian matrix J , with
entries given by
Ri
Ji, j = . (11.13)
U j
We now explain how both R and J may be evaluated in practice. As before, this is
done by: (i) evaluating integrals over , (ii) evaluating integrals over N and (iii)
194 11 Nonlinear Elliptic Partial Differential Equations
evaluating contributions that can be set explicitly. We now give some more details
on each of these tasks.
(k)
Entry i, where i = 1, 2, 3, of Rlocal , then contributes to entry ki of the global
residual R.
For a given U (x, y), the local residual vector discussed above may be calculated
by mapping element k to the canonical triangle using the transformation given by
Eqs. (7.12) and (7.13). The terms in the integrand may all be written as functions of
X and Y on the canonical elementEqs. (7.17)(7.19) allow us to write
Finally, Eqs. (7.12) and (7.13) allow x and y to be written as functions of X and Y ,
allowing us to evaluate the terms that include x and y. We may now evaluate the
integral given by Eq. (11.14), either analytically, or using quadrature as described in
Sect. 8.7.
We now turn our attention to computing the entries of the Jacobian matrix
defined by Eq. (11.13). Let node i be a node of the mesh that does not lie on
D . Using Eq. (11.12), entries of the Jacobian matrix in row i may be written,
for j = 1, 2, . . . , Nnode ,
11.6 Assembling the Nonlinear System of Algebraic Equations 195
N
Ri ele
U i U i
= eU + +
U j k=1 ek U j x x y y
x 2 +y 2 U 2 U 2
i e + +4 d A, (11.16)
x y
and so entries depend only on integrals over individual elements, and there is no
contribution from integrals over element edges that lie on N . We now consider
contributions to the Jacobian matrix from the same element k, with nodes k1 , k2 , k3 ,
as used above when evaluating local contributions to the residual vector. We imme-
diately see that contributions from element k to the Jacobian matrix are nonzero only
for the three rows i = k1 , i = k2 and i = k3 . Furthermore, we see from Eq. (11.15),
that the finite element solution U (x, y) on element k depends on only three values of
U: the values U j , with j = k1 , j = k2 and j = k3 . The partial derivative with respect
to U j that appears in Eq. (11.16) is therefore zero unless j takes one of the values
k1 , k2 , k3 . As such, we may store all nonzero local contributions to J from element
(k)
k in the 3 3 matrix Jlocal , with entries given by, for i = 1, 2, 3, j = 1, 2, 3:
(k) U ki U ki
Jlocal,i, j = eU + +
ek Uk j x x y y
x 2 +y 2 U 2 U 2
k i e + +4 d A.
x y
This integral may be evaluated by mapping to the canonical triangle, and evaluating
all quantities as functions of X and Y as was done for the local contribution to the
residual. The local contributions are then added to the appropriate entry of the global
(k)
Jacobian matrix; for i = 1, 2, 3, j = 1, 2, 3, the entry Jlocal,i, j of the local Jacobian
matrix contributes to the entry Jki ,k j of the global Jacobian matrix.
The contributions to Eq. (11.12) from integrals over element edges that lie on N
take exactly the same form as the integrals evaluated in Sect. 8.6.2. These contri-
butions may, therefore, be evaluated in exactly the same way. We noted in the pre-
vious section that there is no contribution to the Jacobian matrix from integrating
over N .
196 11 Nonlinear Elliptic Partial Differential Equations
The entries of R that take the form of Eq. (11.10) may easily be evaluated explicitly.
The entries of the Jacobian matrix that arise from these rows are given by:
1, i = j,
Ji, j =
0, i = j,
and so these entries may also be set explicitly. Remember, however, to remove any
incorrect entries that were earlier introduced into these rows when integrating over
and N . See Sect. 8.6.3 for more details.
11.7 Exercises
11.1 Use the material in this chapter to calculate the finite element solution of the
differential equation given by Eq. (11.1), subject to the boundary conditions given by
Eqs. (11.2)(11.5). Verify that your finite element solution is correct by comparison
with the true solution u(x, y) = x 2 + y 2 .
11.2 Calculate the finite element solution of the differential equation, defined for
0 < x < 1, 0 < y < 1, by:
2 2
u u
(1 + u 2 )u + (x 2 + y 2 )u + 3 + u = 0,
x y
Use your own choice of triangular elements or quadrilateral elements and your own
choice of polynomial approximation on each element. Verify that your finite element
solution is correct by comparison with the true solution u(x, y) = ex y .
Chapter 12
Systems of Elliptic Equations
We saw, in Chap. 6, how the finite element method may be applied to systems of
ordinary differential equations. Then, in Chaps. 711, we saw how to apply the finite
element method to elliptic partial differential equations, using a variety of meshes
and basis functions. In this chapter, we combine this material, allowing us to apply
the finite element method to systems of elliptic partial differential equations.
We define to be the region 0 < x < 1, 0 < y < 1. Our model problem is the
system of partial differential equations, defined on by:
(u 1 + u 2 ) + 3u 1 + 3u 2 = 2ex+y , (12.1)
(2u 1 + u 2 ) + 3u 1 = ex 3e y ey , (12.2)
where n is the normal vector pointing out of , of unit length. This model problem
has true solution
We will follow a similar method to derive the weak formulation as we did in Sect. 6.2
for systems of ordinary differential equations. We multiply the first differential
equation, Eq. (12.1), by a suitable test function v1 (x, y), and the second equation,
Eq. (12.2), by another suitable test function v2 (x, y). Before we do this, we must
decide which sets v1 and v2 belong to. This requires us to allocate the boundary
conditions, given by Eqs. (12.3)(12.7), to each of the two differential equations.
The Neumann boundary condition given by Eq. (12.7) is a natural boundary
condition for the first differential equation, Eq. (12.1). If we combine this boundary
condition with the Dirichlet boundary conditions on u 1 given by Eqs. (12.3)(12.5),
we then have boundary conditions on the whole of the boundary for Eq. (12.1).
We then allocate the Dirichlet boundary conditions on u 2 given by Eqs. (12.3)
(12.6) to the second partial differential equation, Eq. (12.2). We now have boundary
conditions for both equations on the whole boundary .
The first differential equation, Eq. (12.1), satisfies Neumann boundary condi-
tions on x = 0, 0 < y < 1, and Dirichlet boundary conditions on the remainder of
the boundary. The test function v1 (x, y) then belongs to the set H 1 (), subject to
the condition that v1 (x, y) = 0 where Dirichlet boundary conditions are applied for
Eq. (12.1). Performing the usual tasks of multiplying Eq. (12.1) by v1 (x, y), inte-
grating the resulting product over , applying the divergence theorem and using the
Neumann boundary condition given by Eq. (12.7), we obtain:
(u 1 ) (v1 ) + (u 2 ) (v1 ) + 3u 1 v1 + 3u 2 v1 d A =
2ex+y v1 d A 2e y v1 ds,
N
(12.10)
The weak solutions, u 1 (x, y) and u 2 (x, y), are then defined by:
find u 1 (x, y), u 2 (x, y) that satisfy the Dirichlet boundary conditions and are
such that
(u 1 ) (v1 ) + (u 2 ) (v1 ) + 3u 1 v1 + 3u 2 v1 d A =
2ex+y v1 d A 2e y v1 ds,
N
(12.12)
2 (u 1 ) (v2 ) + (u 2 ) (v2 ) + 3u 1 v2 d A =
ex 3e y ey v2 d A,
(12.13)
for all test functions v1 (x, y), v2 (x, y) that are zero when Dirichlet boundary
conditions are applied to the appropriate equation.
We will partition into a mesh of triangular elements and use the linear basis func-
tions described in Sect. 7.3.2. The sets S h , S Eh and S0h are then defined by Eqs. (7.22)
(7.24).
N node
N node
where Nnode is the number of nodes in the mesh, and j (x), j = 1, 2, . . . , Nnode , are
the basis functions defined in Sect. 7.3.2. The finite element solutions, U (1) (x, y) and
U (2) (x, y), are then defined by:
find U (1) (x, y), U (2) (x, y), given by Eqs. (12.14) and (12.15), that satisfy the
Dirichlet boundary conditions and are such that
U (1) (i ) + U (2) (i ) + 3U (1) i + 3U (2) i d A =
2ex+y i d A 2e y i ds, (12.16)
N
for all test functions i (x, y) that are zero when Dirichlet boundary conditions
are applied to Eq. (12.1), and
2 U (1) (i ) + U (2) (i ) + 3U (1) i d A =
ex 3e y ey i d A,
(12.17)
for all test functions i (x, y) that are zero when Dirichlet boundary conditions
are applied to Eq. (12.2).
We now derive the system of algebraic equations that arises from substituting the
expressions for U (1) (x, y), U (2) (x, y), given by Eqs. (12.14) and (12.15), into the
conditions required from the finite element solution that were stated in the previous
section.
Suppose node i of the mesh lies on the part of the boundary where Dirichlet
boundary conditions are applied for the first differential equation, Eq. (12.1). To
satisfy the Dirichlet boundary conditions, we must set
where g D1 (x, y) is the function that encapsulates the Dirichlet boundary conditions
on u 1 given by Eqs. (12.3)(12.5). If node i does not lie on the part of the boundary
where Dirichlet boundary conditions are applied for the first differential equation,
then i (x, y) will be zero on this boundary and is a suitable basis function for
substituting into Eq. (12.16). Using the expressions for U (1) (x, y), U (2) (x, y), given
by Eqs. (12.14) and (12.15), we obtain, after some manipulation:
12.5 The Algebraic Equations 201
N
node
j (i ) + 3i j d A U (1)
j +
j=1
N
node
j (i ) + 3 j i d A U (2)
j =
j=1
2e x+y
i d A 2e y i ds,
N
(12.19)
where if node i of the mesh lies on the part of the boundary where Dirichlet boundary
conditions are applied for the first differential equation, then
1, j = i,
Ai,(11)
j = 0, j = i,
Ai,(12)
j = 0,
bi(1) = g D1 (xi , yi ),
Applying a similar approach for the second differential equation, Eq. (12.2), we
obtain, after much manipulation, the equation
where if node i of the mesh lies on the part of the boundary where Dirichlet boundary
conditions are applied for the second differential equation, then
202 12 Systems of Elliptic Equations
Ai,(21)
j = 0,
(22) 1, j = i,
Ai, j =
0, j = i,
bi(2) = g D2 (xi , yi ),
where g D2 (x, y) is the function that encapsulates the Dirichlet boundary conditions
on u 2 given by Eqs. (12.3)(12.6). If node i does not lie on this boundary, then
Ai,(21)
j = 2 j (i ) + 3i j d A,
Ai,(22)
j = j (i ) d A,
bi(2) = ex 3e y ey i d A.
We then compute the vectors U(1) and U(2) by combining Eqs. (12.20) and (12.21)
into the single linear system
AU = b,
where
A(11) A(12) U(1) b(1)
A= , U= , b= .
A(21) A(22) U(2) b(2)
12.6 Exercises
12.1 Using the material presented in this chapter, calculate the finite element solu-
tion of the system of equations given by Eqs. (12.1)(12.7), using a mesh of triangular
elements and making a linear approximation to the solution on each element.
12.2 Extend the computational implementation that you wrote in Exercise 12.1 to
use, for example, a quadrilateral mesh and/or higher order basis functions.
Chapter 13
Parabolic Partial Differential Equations
We now describe how to apply the finite element to parabolic partial differential
equations. This is done by approximating the parabolic partial differential equation
by either a sequence of ordinary differential equations or a sequence of elliptic partial
differential equations. We may then solve these ordinary differential equations or
elliptic partial differential equations using the techniques developed earlier in this
book.
Our first example is the parabolic partial differential equation, defined for 0 < x < 1,
0 < y < 1, 0 < t < 3, by
u
= (u) + f (x, y, t), (13.1)
t
where
subject to the Dirichlet boundary conditions given by, for 0 < t < 3:
The function u (m) (x, y) is often called the solution on timestep m. We place the
superscript m in parentheses in Eq. (13.7) to avoid confusion with u being raised to
the power of m. Clearly, from the initial conditions given by Eq. (13.6), we have
u (0) (x, y) = x y(1 x)(1 y), 0 < x < 1, 0 < y < 1. (13.8)
The partial derivative of u with respect to time on the interval tm1 < t tm ,
m = 1, 2, . . . , M, may be approximated using
2u 2 u (m) 2u 2 u (m)
= , = .
x2 x2 y2 y2
13.1 A Linear Parabolic Partial Differential Equation 205
Provided we know u (m1) (x, y), Eqs. (13.9)(13.13) are a linear elliptic partial
differential equation and boundary conditions for u (m) (x, y), m = 1, 2, . . . , M. A
finite element solution to this boundary value problem may easily be computed
using the finite element techniques given in Chaps. 710. As u (0) (x, y) is given by
Eq. (13.8), we may use Eqs. (13.9)(13.13) to compute the finite element solution
U (1) (x, y) that is an approximation to u (1) (x, y). This finite element approximation
U (1) (x) may be used, along with Eqs. (13.9)(13.13), to compute the finite element
solution U (2) (x, y) that is an approximation to u (2) (x, y). We then proceed in this
manner, calculating a finite element solution U (m) (x, y) that is an approximation to
u (m) (x, y), until we reach the final time where m = M.
We leave the computational implementation of the calculation of this finite element
solution as an exercise for the reader. There is, however, one very important point to
be made on the finite element solution of the sequence of elliptic partial differential
equations described above, which has a significant effect on the efficiency of the
computational implementation. When solving each linear elliptic partial differential
equation given by Eq. (13.13), where m = 1, 2, . . . , M, the finite element solution
on timestep m will require the solution of the linear system
Suppose the points t0 , t1 , ..., t M are equally spaced, so that tm tm1 takes a
constant value for m = 1, 2, ..., M. It will be seen in Exercise 13.1 that A(m) is
identical on each timestep, and so this matrix only need be computed once, at the
start of the computational implementation.
u 2u
= 2 + u(1 u), 1 < x < 10, 0 < t < 10, (13.15)
t x
206 13 Parabolic Partial Differential Equations
u
= 0, x = 1, 10, (13.16)
x
and initial conditions
where
1, 1 < x 0,
u 0 (x) =
0, 0 < x < 10.
As with the linear differential equation discussed in Sect. 13.1, we let 0 = t0 <
t1 < t2 < < t M1 < t M = 10 be the values of t where we approximate u(x, t)
and then define, for m = 0, 1, 2, . . . , M,
du (m)
= 0, x = 1, 10. (13.19)
dx
An implicit discretisation in time of Eq. (13.15) on the interval tm1 < t tm , m =
1, 2, . . . , M then satisfies
Provided we know u (m1) (x), the differential equation given by Eq. (13.20) is a
nonlinear differential equation for u (m) , subject to the boundary conditions given
by Eq. (13.19). We may calculate the finite element approximation U (m) using the
techniques discussed in Chap. 5 for nonlinear ordinary differential equations. We
may therefore proceed through all timesteps m as in Sect. 13.1, calculating finite
13.3 A Semi-implicit Discretisation in Time 207
element solutions U (m) that approximate the functions u (m) (x), until we reach the
final time where m = M.
We have used an implicit approximation to the time derivative in all examples pre-
sented so far in this chapter. We explained earlier that this ensured that the finite
element solutions calculated had good numerical stability properties. There are some
equations where the so-called semi-implicit approximation is more computationally
efficient and also possesses good stability properties. Suppose we are solving the
reaction-diffusion system given, for a < x < b, 0 < t < T , by
u
= D (u) + f (x, y, t, u), (13.21)
t
where D is constant, subject to suitable initial and boundary conditions. Calculating
the finite element solution at times 0 = t0 < t1 < t2 < < t M1 < t M = T , and
writing u (m) (x) u(x, tm ) for m = 0, 1, 2, . . . , M, the implicit approximation of
Eq. (13.21) is a nonlinear differential equation for u (m) , m = 1, 2, . . . , M given by
u (m) u (m1)
D u (m) + f (x, y, tm , u (m) ) = 0.
tm tm1
u (m) u (m1)
D u (m) + = + f (x, y, tm1 , u (m1) ). (13.22)
tm tm1 tm tm1
The semi-implicit approximation given by Eq. (13.22) has two attractive features.
First, the differential equation for u (m) , given by Eq. (13.22), is a linear equation.
The finite element solution can therefore be calculated by solving a linear system of
algebraic equations rather than a nonlinear system. Secondly, provided the timestep
tm tm1 is constant for m = 1, 2, ..., M, the matrix that appears in the linear sys-
tem is the same for each timestep, as discussed in Sect. 13.1. Thus, the semi-implicit
approximation has the computational advantage that this matrix need only be calcu-
lated once. Although the stability properties of the semi-implicit method are not as
good as the implicit method, this very rarely causes a problem.
208 13 Parabolic Partial Differential Equations
13.4 Exercises
13.1 Calculate the finite element solution of the parabolic partial differential equa-
tion given by Eqs. (13.1)(13.6). Validate your finite element solution by comparison
with the true solution u(x, y, t) = x y(1 x)(1 y)et .
On each timestep, you need to solve a linear system. Use a constant timestep, so
that tm tm1 is constant for m = 1, 2, ..., M. Verify that for this model problem,
you need only calculate the matrix that appears in this linear system once, before
looping over timesteps.
13.2 A parabolic partial differential equation in one spatial dimension is defined by,
for 0 < x < , 0 < t < 10:
u 2u 1
= 2 + 2 sin x + t + ,
t x 4
(a) Calculate the finite element solution of this nonlinear partial differential equation
using the implicit method described in Sect. 13.2.
(b) Calculate the finite element solution of this nonlinear partial differential equation
using the semi-implicit method described in Sect. 13.3.
for 0 < x < 10, 0 < t < 50, with parameter values = 1.5, = 9, K = 0.1, =
18.5, a = 92, b = 64, d = 10, initial conditions u 1 (x, 0) = 10 + sin x, u 2 (x, 0) =
9 + sin x, and boundary conditions
u 1 u 2
= = 0, x = 0, 10, 0 < t < 50.
x x
Calculate the finite element solution of this system of equations. This system may
be solved using the semi-implicit approximation described in Sect. 13.3.
13.5 The system of parabolic partial differential equations given in Exercise 13.4
may be generalised to two dimensions by writing them as, for 0 < t < 50,
u 1 u 1 u 2
= (u 1 ) + a u 1 ,
t 1 + u 1 + K u 21
u 2 u 1 u 2
= d (u 2 ) + (b u 2 ) ,
t 1 + u 1 + K u 21
using the same parameter values as in Exercise 13.4, initial conditions u 1 (x, y, 0) =
10 + sin x + sin y, u 2 (x, y, 0) = 9 + sin x + sin y, and boundary conditions
n u 1 = n u 2 = 0,
(a) Solve the partial differential equations above on the square 0 < x < 10,
0 < y < 1, for times 0 < t < 50. This system may be solved using the semi-
implicit approximation described in Sect. 13.3.
(b) Repeat part (a), with the parameter now taking the value = 0.9.
Appendix A
Methods for Solving Linear and Nonlinear
Systems of Algebraic Equations
All applications of the finite element method in this book have required the solution
of a system of algebraic equations. These algebraic equations were linear when
the differential equation was linear, and nonlinear when the differential equation
was nonlinear. Despite the central role played by the solution of these systems of
equations, we have said very little about how to solve them.
The numerical solution of both linear and nonlinear systems of equations is under-
pinned by very elegant mathematics and is a fascinating field in its own right. There
are many excellent expositions of this subject, for example Trefethen and Bau [11],
Golub and van Loan [3], Greenbaum [4], van der Vorst [12] and the recent review
article by Wathen [13], to name a few. A more specialised treatment from a finite ele-
ment standpoint may be found in Elman, Silvester and Wathen [1]. It is not possible
to do justice to this field in a short appendix, and we do not attempt to do so. Instead,
we present an overview of established, practical techniques that may be used to solve
the systems of algebraic equations arising from the finite element method. Although
we provide an outline of the algorithms that may be used, we do not recommend that
the user develops software to implement these algorithms themselves. Indeed, we
would discourage the reader from doing so, as many commercial and open-source
software packages (for example, Matlab, Octave, PETSc) are readily available and
provide reliable, computationally efficient and robust implementations. The purpose
of outlining the algorithms here is to allow the reader to understand both the oper-
ations performed by each algorithm andmost importantlythe consequences of
these operations in terms of computational requirements. It is intended that this will
give the reader guidance in choosing the most appropriate technique for their compu-
tations. In the discussion that follows, we assume some familiarity with basic linear
algebra and continuous mathematics, but aim to make the material as accessible as
possible.
Throughout this book, we have used the convention that the finite element solution
at node i in a finite element mesh is given by Ui . Using this convention, systems of
algebraic equations have been written as the linear system AU = b, or the nonlinear
system R(U) = 0. In a slight abuse of this convention, in this appendix, we write
these systems of equations as Au = b and R(u) = 0, respectively, i.e. we write the
vector of unknowns as u rather than U. This is mainly to avoid confusion with upper
triangular matrices, which will be used in this chapter and are commonly denoted
by U. Furthermore, writing the vector of unknowns as u fits in with a common
convention from linear algebra, namely that vectors are represented by lower-case
letters.
Linear systems arising from the finite element method have two key properties: (i)
they are nonsingular, and (ii) they are sparse, i.e. they have very few nonzero entries
in each row of the matrix. Techniques for solving these linear systems fall into two
categories, direct methods and iterative methods, that we now discuss.
We begin by describing a method for solving linear systems that most readers will
be familiar with: Gaussian elimination with partial pivoting, sometimes known as
row pivoting. This technique, although not requiring sophisticated mathematics, is a
practical solver for many linear systems. As explained above, we do not provide full
details of the computational implementation of this technique, but merely enough
detail to allow the reader to understand both the computational operations that are
required and the practical consequences of these operations. First, we require some
definitions.
A matrix is said to be lower triangular if all entries above the diagonal take the
value zero. Clearly, the matrix L is lower triangular if, and only if, Li,j = 0 when
i < j. Similarly, a matrix U is upper triangular if, and only if, all entries below the
diagonal take the value zero, that is Ui,j = 0 if i > j. Finally, a permutation matrix is
a square matrix with the following two properties: (i) each row and each column of
the matrix contain precisely one entry that takes the value 1, and (ii) all other entries
of the matrix take the value 0. Permutation matrices take their name because they
permute rows of a matrix, as we shall now explain. Suppose P is a permutation matrix
of size N N where, in row i, the entry that takes the value 1 appears in column j.
Let A be another matrix of size N N and b be a row vector with N entries. The
entries of row j of A will appear in row i of PA, and the entry in row j of b will appear
in row i of Pb. Permutation matrices are used to implement the pivoting steps of
Gaussian elimination.
Suppose we solve the nonsingular linear system
Au = b, (A.1)
Appendix A: Methods for Solving Linear and Nonlinear 213
PAu = b,
where
b = Pb,
we see that the LU decomposition of A allows us to write the given linear system as
LUu = b. (A.2)
Care should be taken not to confuse the upper triangular matrix U with the vector of
unknows u. Setting v = Uu allows us to decompose the linear system as the coupled
system
Lv = b, Uu = v. (A.3)
Although it may appear that decomposing the linear system into the two systems
above doubles the work required, this is not the case. The structure of triangular
matrices allows us to explicitly solve the system very simply. Remembering that L
is a lower triangular matrix with all diagonal entries taking the value 1 and that U is
an upper triangular matrix, we may write Eq. (A.3) as:
1 0 0 ...
0 v1 b1
L2,1 1
0 0
... v2
b2
L3,1 L3,2
1 0
...
v3 = b3 , (A.4)
.. .. .. .. ..
..
. ..
. . . .
. .
LN,1 LN,2 LN,3 . . . 1 vN bN
U1,1 U1,2 . . . U1,N2 U1,N1 U1,N u1 v1
0 U2,2 . . . U2,N2 U2,N1 U2,N v2
u2
.. .. .. .. .. .. .. ..
. . . . . . .
. = . (A.5)
0 0 . . . UN2,N2 UN2,N1 UN2,N uN2 vN2
0 0 ... 0 UN1,N1 UN1,N uN1 vN1
0 0 ... 0 0 UN,N uN vN
We may sweep through the first of these linear systems, Eq. (A.4), solving for each
value of vi in turn:
214 Appendix A: Methods for Solving Linear and Nonlinear
v1 = b1 ,
v2 = b2 L2,1 v1 ,
v3 = b3 L3,1 v1 L3,2 v2 ,
.. ..
. .
vN = bN LN,1 v1 LN,2 v2 LN,3 v3 . . . LN,N1 vN1 .
1
uN = vN ,
UN,N
1
uN1 = vN1 UN1,N uN ,
UN1,N1
1
uN2 = vN2 UN2,N uN UN2,N1 uN1 ,
UN2,N2
.. ..
. .
1
u1 = v1 U1,N uN U1,N1 uN1 . . . U1,2 u2 .
U1,1
Note that division by the diagonal entries of U in the equations above is well defined,
as we have explained that these entries are nonzero when using Gaussian elimination.
This completes the solution of the original linear system, Eq. (A.1).
We now evaluate LU decomposition as a practical method for solving the linear
systems that arise from the finite element method. As the size of the system increases,
the computational work required is dominated by computing the matrices P, L, U,
and the solution of Eq. (A.3) requires an insignificant computational effort in compar-
ison. This is a very useful observation when many linear systems defined by the same
matrix A are to be solved, as is the case for some of the parabolic partial differential
equations seen in Chap. 13. For these systems, we need only evaluate P, L, U once:
these matrices may then be reused. A further feature of LU decomposition to bear
in mind is that although A is a sparse matrix, the computed factors L and U will not,
in general, be sparse. Should N, the number of rows in the linear system, be large,
then, although storing the sparse matrix A is feasible, storing the dense matrices L
and U may not be possible. LU decomposition would then fail as a practical method
for solving Eq. (A.1).
In summary, LU decomposition is suitable for problems with a relatively small
number of unknowns. What a small number of unknowns actually means in this
context will depend on the computer being usedit is likely that small may mean
hundreds of thousands of modern laptop or desktop computers.
Readers may have wondered why we have not yet explained what a direct solver
is. This is because it is easier to do so with the aid of an example, such as Gaussian
elimination with partial pivoting. This algorithm uses prescribed steps, with a compu-
Appendix A: Methods for Solving Linear and Nonlinear 215
In the previous section, we loosely defined a direct method for solving a linear system
to be a method that used prescribed steps, with computational complexity known a
priori, to calculate the exact solution to a problem. An alternative family of methods
are iterative methods, where an initial guess is made to the solution, and this guess
improved iteratively until it is sufficiently good. By sufficiently good, we usually
mean that Au b < for some prescribed , where v represents the norm of
a vector v. Iterative methods are often used to solve the sparse linear systems that
arise from the finite element method when the number of unknowns is too large for
a direct method, such as that described in Sect. A.1.1, to be applied.
In the absence of specialist knowledge, some basic advice for using iterative meth-
ods to solve the sparse linear system Au = b may be expressed very simply. If the
matrix A is symmetric and positive definitethat is, A = A and v Av > 0 for all
nonzero vectors vthen the conjugate gradient methodshould be used. If not the
Generalised Minimal RESiduals (GMRES) technique should be used. We present
the algorithm for both of these techniques to allow the reader to understand the
computations underpin these techniques and their consequences in terms of com-
putational memory and operations required. This is particularly important for the
use of GMRES, as this technique requires some input from the user that can have a
significant effect on the efficiency and computational memory requirements. Writing
down the algorithms also allows us to outline how convergence may be accelerated
by preconditioning techniques in Sect. A.1.3.
We also include a summary of two other iterative techniques: GaussSeidel itera-
tion and multigrid. GaussSeidel iteration is very rarely used as an iterative technique.
It is, however, often used as part of a multigrid technique. Multigrid techniques are
a family of iterative techniques for solving linear systems. It is not possible, in a
short appendix, to fully explain how these techniques may be applied as an effective
iterative solver. Instead, we give an overview of the principles that underpin this tech-
nique. Although we would not suggest that a novice uses a basic multigrid technique
as an iterative solver, we will claim, when discussing preconditioning in Sect. A.1.3,
that a basic multigrid technique can be an effective preconditioner.
The conjugate gradient method may be used for solving linear systems Au = b
when the matrix A is symmetric and positive definite. Care should be taken to avoid
216 Appendix A: Methods for Solving Linear and Nonlinear
We saw in Sect. A.1.2.1 that the conjugate gradient algorithm required only the
evaluation of algebraic expressions that were straightforward to execute and did not
require substantial computational memory to store the results of these computations.
This makes the conjugate gradient technique a very attractive iterative method for
solving linear systems. However, this method may only be used for matrices that
are both symmetric definite and positive definite. A popular iterative technique for
matrices that do not have these properties is the GMRES method.
The steps required for the GMRES method are given in Algorithm 2. In contrast to
the conjugate gradient algorithm, there are two additional complexities. First, we see
that a dense matrix H is generated as part of this algorithm. On iteration j, this matrix
has j + 1 rows and j columns. If the number of iterations required is sufficiently small,
this will not cause a problem. However, if a large number of iterations are required,
this matrix will require substantial storage space in the computers memory, which
Appendix A: Methods for Solving Linear and Nonlinear 217
may not be possible. Furthermore, in line 15 of the algorithm, we see that we have
to solve a least squares problem during each iteration of the algorithm which, in
contrast to the operations required for the conjugate gradient method, is not a simple
algebraic operation.
1 An orthogonal matrix is a square matrix that satisfies QQ = I where I is the identity matrix.
218 Appendix A: Methods for Solving Linear and Nonlinear
(D + L)u + Uu = b.
Noting that D + L is a lower triangular matrix, we see that the linear system
that is solved in line 5 of the GaussSeidel algorithm may be solved very easily
using the method described for solving the lower triangular system in Sect. A.1.1.
The computational memory requirements are also very lowthe vectors xk and rk
that are generated on each iteration only require preservation for at most one more
Appendix A: Methods for Solving Linear and Nonlinear 219
iteration and can then be deleted. The drawback is that there is no guarantee that this
algorithm will converge, and if it does converge, then convergence is usually slower
than that for GMRES or the conjugate gradient method.
The final iterative techniques that we discuss are the family of techniques known as
multigrid techniques. These techniques can be used as iterative solvers for linear sys-
tems: this was the initial purpose for developing them. We should emphasise that the
discussion that follows focuses only on a rudimentary implementation of multigrid
techniques and does not provide sufficient discussion to allow the implementation of
multigrid as an efficient iterative solver. The purpose of this discussion will become
clear in Sect. A.1.3, when we explain that a basic implementation of multigrid may be
used to accelerate convergence of the GMRES algorithm presented in Sect. A.1.2.2.
As the name suggests, multigrid techniques use several computational meshes
or grids. Suppose a finite element solution is required on a computational mesh,
M1 , with many nodes, and that the finite element solution on this mesh satisfies
A1 u1 = b1 , where both A1 and b1 are evaluated from the mesh M1 . Suppose further
that M1 , M2 , . . . , MJ are a sequence of successively coarser meshes and that, were
we to calculate the finite element solution on the mesh Mj , j = 1, 2, . . . , J, we would
obtain the linear system Aj uj = bj . We assume that, for j = 1, 2, . . . , J 1, we may
restrict vectors on mesh Mj to the coarser mesh Mj+1 using
uj+1 = Rj uj ,
uj = Pj uj+1 ,
Our final assumption is that the coarsest mesh, MJ , contains sufficiently few nodes
that the resulting linear system can easily be solved using a direct method.
The ideas behind the basic multigrid techniques are simple. Let uj be the solution
of Aj uj = bj for j = 1, 2, . . . , J, and let vj be an approximation to uj . We define
rj = Aj vj bj , ej = vj uj , j = 1, 2, . . . , J.
Aj ej = rj . (A.6)
220 Appendix A: Methods for Solving Linear and Nonlinear
Given an initial guess on the finest mesh M1 , we first perform a small number of
GaussSeidel iterations on the equation A1 u1 = b1 using this initial guess, before
computing the residual r1 on this fine mesh. We then restrict this residual onto the
next mesh M2 using r2 = R1 r1 , before performing a small number of GaussSeidel
iterations on Eq. (A.6) to update the residual r2 . This is repeated on the successively
coarser meshes until we restrict the residual onto the coarsest mesh, MJ , where we
solve Eq. (A.6) exactly. We then proceed back through the meshes, prolongating the
solution onto successively finer meshes and performing a small number of Gauss
Seidel iterations until we reach the finest mesh, M1 , where we update our initial
guess. We complete the multigrid cycle by performing a small number of Gauss
Seidel iterations of the equation A1 u1 = b1 .
The multigrid method described above is presented in Algorithm 4. This multigrid
cycle is repeated until the residual is sufficiently small. Note that the operations
required are all algebraic operations that can be evaluated efficiently and require
minimal computational storage when the algorithm is being performed.
There is clearly much flexibility when using this techniqueusing either a dif-
ferent number of grids or a different number of GaussSeidel iterations are obvious
candidates for improving convergence properties. Many other options also exist for
accelerating convergence, of which we briefly mention only a few. GaussSeidel iter-
ations were used in Algorithm 4 to smooth the error ej on mesh Mj . Other smoothers
exist and may enhance the convergence properties. We also used the same number
of GaussSeidel iterations on all meshes and on both the restricted and prolongated
solutionswe may allow these to vary if we wish. Furthermore, in Algorithm 4,
we iterated through meshes M1 , M2 to the finest mesh MJ and then back along the
reverse path to the finest mesh M1 . A more flexible technique uses cycles that are
not as uniform as this.
Appendix A: Methods for Solving Linear and Nonlinear 221
A.1.3 Preconditioning
It is now a good time to take stock of the material presented so far in this appendix.
We discussed direct methods for solving linear systems in Sect. A.1.1 and proposed
using these methods when the number of unknowns was sufficiently small that the
memory requirements were not excessive. If the number of unknowns is too large
for a direct method to be used, we proposed, in Sect. A.1.2, that an iterative method
would be more appropriate. Specifically, we propose using the conjugate gradient
method if the matrix is symmetric and positive definite, and the GMRES method
otherwise. We have not discussed the number of iterations taken for either of these
iterative techniques to converge as this requires far more detail than can be given in
a book on the finite element method. Nevertheless, we do think it is appropriate to
give some practical tips on a technique known as preconditioning for reducing both
the number of iterations required andimportantlythe computation time.
When computing finite element solutions, we often need to solve sparse linear
systems Au = b using an iterative technique. If M is a nonsingular matrix, then this
linear system is equivalent to
M 1 Au = M 1 b. (A.7)
This equation is known as the preconditioned system, and the matrix M is known
as a preconditioner. Suppose we choose the preconditioner so that M = A. This
choice of preconditioner would allow us to write Eq. (A.7) as u = M 1 b, and we
would then have solved the linear system. This choice of preconditioner is clearly not
appropriateif we were able to evaluate A1 , then we may as well use a direct method
to solve the original system. This observation motivates us to specify two conditions
that a preconditioning matrix must satisfy. The first condition is that the product M 1 A
should bespeaking very looselysome approximation to the identity matrix. We
deliberately leave this as a very imprecise statement as, in this context, a matrix
with tightly clustered eigenvalues may be considered a suitable approximation. The
second condition is that the action of M 1 on a vector is computationally cheap to
compute. This second condition requires explanation as it has significant practical
implications. Note that we do not need an explicit expression for the matrix M 1 .
Indeed, for most preconditioners that are used in practice, an expression for M 1 is
not available. Suppose we want to compute M 1 v for some given vector v. Let us
write w = M 1 v. Computing w is then equivalent to solving the linear system
Mw = v.
Suppose we are solving a linear system Au = b using either the conjugate gradient
method presented in Algorithm 1 or the GMRES method presented in Algorithm 2.
In both algorithms, we see that the only operations involving the matrix A are matrix
vector multiplications of the form Av. Suppose, instead, we solve the preconditioned
system given by Eq. (A.7), using a preconditioner M that satisfies the conditions
above. As the second of these conditions is that the action of M 1 on any vector is
cheap to compute, we may easily compute the right-hand side of this linear system,
i.e. M 1 b. When using either the conjugate gradient or GMRES algorithm for the
preconditioned system, we then have to evaluate matrixvector multiplications of
the form M 1 Av for any vector v. These may also be evaluated cheaply: writing
w = Av, we see that
M 1 Av = M 1 w,
AM 1 v = b, (A.8)
where u = M 1 v. (A.9)
The solution of the right preconditioned system may be computed by first solving
Eq. (A.8) for v, followed by solving Eq. (A.9) for u. The right preconditioned sys-
tem has similar properties to the left preconditioned system in that it will hopefully
decrease the number of iterations required without significantly adding to the com-
putational cost of each algorithm.
Care should be taken when preconditioning the conjugate gradient method. This
iterative technique is underpinned by the assumption that the matrix A is symmetric
and positive definite, and these properties of A must not be destroyed by precondi-
tioning. This may be achieved by writing the preconditioner as M = CC for some
matrix C and then writing the system Au = b as:
C 1 A C 1 v = b,
1
where u = C v.
L Uw = v,
and we saw in Eqs. (A.2) and (A.3) that systems of this form can be solved very
easily.
ILU preconditioning is available in all major open-source and commercial soft-
ware packages for the iterative solution of linear systems and is a very good default
choice of preconditioner. See [12] for more details on the implementation of this
preconditioner.
R(u) = 0, (A.10)
where u is a vector of N unknowns. The most popular iterative technique for solving
systems of equations such as Eq. (A.10) is known as Newtons method, which we
now describe.
Suppose that u is a solution of this system, so that R(u ) = 0. Note that we say
a solution rather than the solutionthere is no guarantee that this solution is
unique or, indeed, that a solution u exists. Approximating component i of R as a
Taylor series about a general point u, up to and including all linear terms in u u,
gives
N
Ri (u ) Ri (u) + Jij uj uj , i = 1, 2, . . . , N,
j=1
where the solid vertical line with subscript u indicates that entries of J are evaluated
at u. We may write this in vector form as
R(u ) R(u) + J u u .
Noting that u is a solution of Eq. (A.10), we have R(u ) = 0, and assuming the
matrix J is invertible, we may approximate the solution of Eq. (A.10) by
u u J 1 R(u).
will converge to this solution for a given initial guess. This may be illustrated using
a very simple example of a nonlinear equation in one scalar variable u. The function
R(u) = ueu has the unique solution u = 0 to the equation R(u) = 0. It is, however,
fairly easy to show that Newtons method will not converge to this solution for any
initial guess satisfying u0 1. Furthermore, should a nonlinear equation possesses
multiple roots, there is no guarantee which of these roots Newtons method will con-
verge to (if it does indeed converge). In particular, we should not expect Newtons
method to converge to the root closest to the initial guess. An excellent illustration
of this point may be found in Chap. 4 of Sli and Mayers, [10], using the example of
solving the equation ez z 2 = 0 for the complex number z = x + iy. A system
of two nonlinear equations for x and y may be derived by decomposing this equation
into real and imaginary parts. There are an infinite number of roots of this system of
equations, and the root that Newtons method converges to for a given initial guess
possesses some very unexpected properties. See Sli and Mayers, [10], for more
details.
The discussion in the previous paragraph should be viewed as a brief summary
of the negative aspects of Newtons method. This should be balanced by the positive
aspects. Newtons method is simple to implement, applicable to general systems of
equations, and is usually considered the go-to method for solving general nonlinear
systems of algebraic equations. We emphasise that widely available open-source and
commercial implementations of Newtons method are available. Many of these are
reliable, robust and efficient, and so the reader need not implement these algorithms
themselves. Some of these implementations require only specification of the function
R(u), while some require specification of both R(u) and the Jacobian matrix J. The
entries of J are partial derivatives of the entries of R(u), and the reader may prefer to
evaluate these derivatives numerically. If this approach is taken, then for efficiency,
the contributions to the numerical derivatives should be computed on each element
as described in Sect. 5.1.7.
Appendix B
Vector Calculus
In this appendix, we give a very brief summary of the vector calculus that is required
when applying the finite element method to partial differential equations in two
spatial dimensions.
If a function u(x, y) possesses first partial derivatives with respect to x and y, the
gradient of u(x, y) is defined by
u
x
u = u .
y
is such that F1 (x, y) and F2 (x, y) both possess first partial derivatives with respect to
x and y, the divergence of F is defined by
F1 F2
= + .
x y
As a consequence,
u
x x
(u) =
u
y y
u u
2 2
= + 2. (B.1)
x 2 y
Suppose the function u(x, y) possesses all first and second partial derivatives, and
the functions v(x, y) and p(x, y) possess all first partial derivatives with respect to
both x and y. An identity used when deriving the weak solution of partial differential
equations is
Let be a closed, bounded region in two dimensions, with piecewise smooth bound-
ary . Let F(x, y) be continuous, with continuous first partial derivatives on the
region . We then have
F dA = F n ds, (B.3)
Some additional texts that have been cited in earlier chapters have been listed below.
References
1. Elman, H., Silvester, D., Wathen, A.: Finite Elements and Fast Iterative Solvers. Oxford Uni-
versity Press, Oxford (2005)
2. Embree, M.: The tortoise and the hare restart GMRES. SIAM Rev. 45, 259266 (2003)
3. Golub, G.H., Van Loan, C.F.: Matrix Computations, 4th edn. The Johns Hopkins University
Press, Baltimore (2012)
4. Greenbaum, A.: Iterative Methods for Solving Linear Systems. Society for Industrial and
Applied Mathematics, Philadelphia (1997)
5. Murray, J.D.: Mathematical Biology. Springer, Berlin (1993)
6. Oosterlee, C.W., Washio, T.: An evaluation of parallel multigrid as a solver and a preconditioner
for singularly perturbed problems. SIAM J. Sci. Comput. 19, 87110 (1998)
7. Persson, P.-O., Strang, G.: A simple mesh generator in matlab. SIAM Rev. 46, 329345 (2004)
8. Shewchuk, J.R.: Triangle: engineering a 2D quality mesh generator and delaunay triangulator.
Lect. Notes Comput. Sci. 1148, 203222 (1996)
9. Shewchuk, J.R.: Delaunay refinement algorithms for triangular mesh generation. Comput.
Geom. Theory Appl. 22, 2174 (2002)
10. Sli, E., Mayers, D.F.: An Introduction to Numerical Analysis. Cambridge University Press,
Cambridge (2006)
11. Trefethen, L.N., Bau, D.: Numerical Linear Algebra. Society for Industrial and Applied Math-
ematics, Philadelphia (1997)
12. Van der Vorst, H.A.: Iterative Krylov Methods for Large Linear Systems. Cambridge University
Press, Cambridge (2003)
13. Wathen, A.J.: Preconditioning. Acta Numer. 24, 329376 (2015)
D
Dirichlet boundary conditions, see Bound- L
ary conditions Linear systems of algebraic equations
Divergence theorem, 228 solution of, 211, 212
Domain, 6 direct methods, 212
iterative methods, 215
Local contributions, 14, 87
E Lower triangular matrix, 212
Elements, 8, 9, 30, 56, 70, 76, 83 LU decomposition, 213
Springer International Publishing AG 2017 231
J. Whiteley, Finite Element Methods, Mathematical Engineering,
DOI 10.1007/978-3-319-49971-0
232 Index