You are on page 1of 39

Lecture Notes on The Finite Element Method

(for EMH451 & EME401)


Razi Abdul Rahman
September 26, 2011
Contents
1 Introduction 4
2 Review of PDEs 5
2.1 Classication of PDEs . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 Elliptic PDE: Laplaces and Poissons Equations . . . . 5
2.1.2 Steady-state heat equation . . . . . . . . . . . . . . . . 6
2.2 Strong Form and Weak Form of PDEs . . . . . . . . . . . . . 6
2.2.1 Properties of Test Functions . . . . . . . . . . . . . . . 6
3 Introduction to FEM 7
4 Finite element Formulation in 1-D 9
4.1 Method of Weighted Redisuals . . . . . . . . . . . . . . . . . . 9
4.2 The Galerkin Method on 1-D Problem (ODE) . . . . . . . . . 10
4.2.1 Galerkins Method in discrete domains . . . . . . . . . 13
4.3 1-D Linear Basis Functions in Local Coordinates . . . . . . . . 15
4.4 1-D Integration of Basis Functions . . . . . . . . . . . . . . . . 18
4.5 1-D Element Stiness Matrix and Load Vector . . . . . . . . . 18
4.6 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.7 1-D Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.7.1 Modication of system matrix for essential BC . . . . . 21
4.8 Solution of Ka = b . . . . . . . . . . . . . . . . . . . . . . . . 22
4.9 Post-processing . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.10 Concluding Notes . . . . . . . . . . . . . . . . . . . . . . . . . 22
5 1-D FEM: Applications 23
5.1 Steady-State Heat Conduction Revisited . . . . . . . . . . . . 23
5.1.1 Boundary conditions . . . . . . . . . . . . . . . . . . . 23
5.1.2 Nonconstant source term . . . . . . . . . . . . . . . . . 24
5.1.3 Varying (x) . . . . . . . . . . . . . . . . . . . . . . . 24
5.2 Convergence of solution/discretization error . . . . . . . . . . 25
5.3 Formulations for Elasticity Problems . . . . . . . . . . . . . . 25
5.4 Formulations for Elasticity Problems: Beam bending . . . . . 26
5.5 Beam elements . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5.6 Elastic strain energy . . . . . . . . . . . . . . . . . . . . . . . 27
5.6.1 Review of work by external force . . . . . . . . . . . . 27
5.6.2 Elastic strain energy U due to uniaxial stress . . . . . . 27
5.6.3 Error in energy based on discontinuity of stress . . . . 28
2
CONTENTS 3
6 Formulations for Field Problems in 2D: Heat Conduction 29
6.1 2-D Heat Conduction . . . . . . . . . . . . . . . . . . . . . . 29
6.2 Finite Elements in 2-D . . . . . . . . . . . . . . . . . . . . . . 30
6.2.1 Linear quadrilaterals and triangles . . . . . . . . . . . 30
6.3 2-D Element Stiness Matrix and Load Vector . . . . . . . . . 31
6.4 Boundary Conditions on
A
and
B
. . . . . . . . . . . . . . . 32
7 Linear Solvers 33
7.1 Sparse Matrix Solvers . . . . . . . . . . . . . . . . . . . . . . . 33
7.1.1 Direct Method . . . . . . . . . . . . . . . . . . . . . . 33
7.1.2 Iterative Method . . . . . . . . . . . . . . . . . . . . . 36
8 Post-processing 38
Chapter 1
Introduction
This lecture script is for the courses EMH451 and EME401. It is meant as
lecture notes to help you study the subject. You should always learn the
course materials from any of the textbooks listed on the last page of this
document.
For EME401, the main reference is Logans text book [4]. Another main
reference is in Zienkiewicz and Taylor [5]. Some discussions from the Ansys
Theory Manual are also used [2]. For practical aspect, coding with FEMhub
is discussed [1]. Certain algorithms by Kwon and Bang are also used [3].
4
Chapter 2
Review of PDEs
2.1 Classication of PDEs
A model problem PDE can be written as
a

2
u
x
2
+ b

2
u
xy
+ c

2
u
y
2
+ d
u
.
x
+ f
u
y
+ gu = 0 (2.1)
Depending on the coecients, we will get dierent types of PDE.
Major types of PDE
Elliptic
Parabolic
Hyperbolic
parabolic example: initial-boundary value problem
transient solution
hyperbolic example: convection-diusion problem
2.1.1 Elliptic PDE: Laplaces and Poissons Equations
For steady-state problems commonly found in physics and engineering
Examples of elliptic PDE:
Heat conduction
Static problem in elasticity
velocity potential in incompressible ow
electrostatic potential
etc.
5
6 CHAPTER 2. REVIEW OF PDES
2.1.2 Steady-state heat equation
Heat conduction in higher dimensions is described by PDEs. For example in
2D:

x
_

xx
T
x
_
+

y
_

yy
T
y
_
= Q(x, y) (2.2)
subject to boundary conditions.
xx,yy
is thermal conductivity in the {x, y}.
In a more compact and general form, we can write the above as
u = f (2.3)
or
div ( grad u) = f (2.4)
where u is the temperature T, is the material coecient where here = .
For 1D case, and does not vary, then we can simplify the heat conduction
equation to

d
2
u(x)
dx
2
= f(x) (2.5)
with of course under certain boundary conditions at the end points. We
assume the domain for the PDE is of length L. The domain here refers to
the length of the 1D bar.
2.2 Strong Form and Weak Form of PDEs
The model PDE (2.1) and the example heat equation of Eq. (2.2) above
have the strong form of the PDE. It is called strong because the solution
must be satised at all points in the domain, i.e., strong condition.
Alternatively, we can state the same PDE in its weak form. We turn the
strong form into the weak form by:
multiplying the equation by a test function v(x)
integrating the form over the prescribed (in this case 1D) domain
Using the simple strong form of Eq. (5.1), we get the weak form to be
_
L
0
v
_

d
2
dx
2
u + f(x)
_
dx = 0, 0 x L (2.6)
This is the form where we say the solution may be satised in a weighted or
average sense due to the integral (summation). I.e., the condition is weak
compare to the rst condition.
2.2.1 Properties of Test Functions
The test function v in the weak form must be admissable.
To satisfy this, v must be
smooth, i.e., there is no slope discontinuity along the domain L.
must satisfy boundary conditions
Chapter 3
Introduction to FEM
In physics and engineering, the FEM is a method of solving a problem
in continuum physics/mechanics by describing the problem as a set of
discrete problems.
2 ways of converting continuum to discrete problem:
create a nite number of points, replace derivatives with dier-
ences. This is an approach of FDM and FVM
create a nite number of functions, approximate the exact solution
with these trial functions. This is the approach of FEM.
NOTE: In the FEM, the space of the solution is discretized (and not
only the Euclidean (physical space))
We can also dene the FEM as a numerical method for solving the
PDE
The formulations of the FEM can be summarized as the following:
i) Direct stiness method, and ii) Generalized formulation
in (i) we dene the spring characteristics of a single element
we then assemble these elements into a single stiness matrix
in (ii) we based in mathematical statement of the physical problem
we do this either by functional minimization or Methods of Weighted
residuals
In functional minimization, we base on minimization of the potential
energy of the structure
In weighted residuals, we base on fulllling the weak form in an average
sense
in weigthed residuals, most popular is the Galerkin Method
The FEM is derived from the principle of weighted residuals using
locally-supported basis functions
7
8 CHAPTER 3. INTRODUCTION TO FEM
These basis functions are usually known as shape functions
recast the strong form of the PDE to its weak form counterpart
by way of Galerkin Method, use the basis functions to locally satisfy
the weak problem
for the solutions to be valid, these functions must be in the space of
admissable functions
Chapter 4
Finite element Formulation in
1-D
Recall the methods used in the FEM formulation:
direct stiness method with linear spring elements
for elasticity problem
generalized methods based on the weak form of the DE
energy methods (Principle of Minimum Potential Energy)
potential energy as a function of displacement d
since d is a function, we have a function of function, or func-
tional
this method is a subject of variational calculus (calculus of
variations)
Method of Weighted Residuals: there are many, but more popular
is the Galerkin method (our focus)
There are several approaches that may be used for the FEM formula-
tion.
we use generalized methods based on the weak form of the DE
of these generalized methods, we will focus on the Method of Weighted
Residuals
of these weighted residuals, we will focus on the Galerkin method
4.1 Method of Weighted Redisuals
In approximation methods, we usually use known functions to approximate
the unknown function. Suppose u is the unknown function. Then, an ap-
proximate function u can be written as
u =
N

n=1
a
n
v
n
(4.1)
9
10 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
where a
n
is the coecient of the (known) trial function v
n
. The whole point
is to nd the right a
n
so that u is as close to u as possible.
The dierence between the exact solution u and its approximation u is
the error and is usually termed residual R

:
R

= u u (4.2)
We want to get R

as close to zero as possible. Note that R

is a function
of the coordinates in the domain . To satisfy R

everywhere in the domain


is a strong condition.
Alternatively we can make R to be zero in some average sense: we use
a number of integrals over the area and weighted them to become zero like
this
_

W
i
R

d = 0 (4.3)
where W
i
is a weighing function.
This way we satisfy the zero requirement, but in a weaker sense. This
relates to the strong form and weak form of the Dierential Equations.
This is the basis of the Galerkin Method as follows.
4.2 The Galerkin Method on 1-D Problem
(ODE)
recast the strong form of the PDE to its weak form counterpart
by way of Galerkin Method, use the weighting functions to locally sat-
isfy the weak problem
for the solutions to be valid, these functions must be in the space of
admissable functions
As an example, we apply the Galerkin method on the steady-state 1D heat
equation as before. Recall Eq. (5.1)

d
2
u
dx
2
= f (4.4)
along a bar of length L. u = temperature of bar at x in Kelvin . = thermal
conductivity of bar in W/k/m. f = heat generation per length in W/m.
For simplicity, we let = 1, f = 2.
For completeness, we have to set the boundary conditions at both ends.
There are several possible boundary conditions that we can specify. We
choose the displacement bcs for both ends: u(0) = 0; u(L) = 0.
Note: In this example when u itself is xed, we call it Dirichlet BC.
Now, the problem is completely stated, i.e., solvable.
Recall: This is the strong form of the BVP. We turn the strong form into
the weak form by:
multiplying the equation by a weight function v(x)
4.2. THE GALERKIN METHOD ON 1-D PROBLEM (ODE) 11
integrating the form over the prescribed (1D) domain
_
L
0
v
_
d
2
dx
2
u + f(x)
_
dx = 0, 0 x L (4.5)
Separate the terms:
_
L
0
v
d
2
u
dx
2
dx +
_
L
0
v fdx = 0, 0 x L (4.6)
Eq. (4.6) is still dicult to solve due to the order of rst term being 2. We
reduce the order via integration by parts on the rst term:
_
b
a
g
dh
dx
dx = [gh]
b
a

_
b
a
dg
dx
hdx, (4.7)
where
g = v, h =
du
dx
Applying this, we obtained the form
_
b
a
g
dh
dx
dx =
_
v
du
dx
_
L
0

_
L
0
dv
dx
du
dx
dx (4.8)
Substitute Eq. (4.8) into Eq. (4.6)
_
v
du
dx
_
L
0

_
L
0
dv
dx
du
dx
dx +
_
L
0
vfdx = 0 (4.9)
Rearrange:
_
L
0
dv
dx
du
dx
dx =
_
v
du
dx
_
L
0
+
_
L
0
vfdx (4.10)
NOTE: v(x) may not be any functions, but must be in the class of admiss-
able functions.
At this point, we are still dealing with the unknown eld u as continuous
function.
we now move to discrete or nite approximation of u
To approximate u, we introduce degrees of fredom DOF a
i
and basis
functions
i
which approximates u as
u(x) =
n

i=1

i
(x)a
i
(4.11)
Suppose u varies linearly within the 1-D domain, then we only need 2 basis
functions and correspondingly 2 DOFs.
In terms of a dot product:
u(x) = (x) a (4.12)
12 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
where
(x) =
_

1
(x)
2
(x)

; a =
_
a
1
a
2
_
so that
u(x) =
1
(x)a
1
+
2
(x)a
2
In engineering texts, is more commonly refered to as shape functions
and denoted N.
We want to substitute u in Eq. (4.10). But rst we deal with the deriva-
tive of u:
From the above,
u(x) = (x) a
Since a is constant, then
d u(x)
dx
=
d(x)
dx
a
Introduce B as a vector of the rst derivative of the basis functions, then
d u(x)
dx
= B a (4.13)
Now, using these vector products for u and u

, Eq. (4.10) becomes


_
L
0
dv
dx
B adx = [vB a]
L
0
+
_
L
0
vfdx (4.14)
So, we are left with the trial functions or weighting functions v (notice
the plurals).
Similar to u, we can form v in terms of some nite number of functions
and arbitrary unknowns c
v(x) =
n

i=1
v
i
(x)c
i
(4.15)
Or in dot product terms:
v(x) = V c (4.16)
v can be chosen to any functions. The gist of the Galerkin method is we
simply chose as our basis functions as the test functions v,
v(x) = c (4.17)
Also note that
c = c
T

T
Substituting the chosen v into Eq. (4.14), we nally get
_
L
0
c
T
B
T
B adx = c
T
_

T
B a

L
0
+
_
L
0
c
T

T
fdx (4.18)
Notice here that we can drop c, and since a is a vector of unknowns, we can
bring it out of the integration
_
L
0
_
B
T
B

dx a =
_

T
B a

L
0
+
_
L
0

T
fdx (4.19)
4.2. THE GALERKIN METHOD ON 1-D PROBLEM (ODE) 13
The boundary term
By looking at the rst term of the right hand side (RHS), it refers to the con-
tribution of the boundary conditions. For simplication of discussion, we can
so choose that this term may vanish at the boundaries. For non-vanishing
boundary conditions, well discuss a method to incorporate this in later sec-
tion
Setting the System of Linear equations
If we ignore the boundary term, we may write as
_
L
0
_
B
T
B

dx a =
_
L
0

T
fdx (4.20)
We can write the above as the matrix-vector equation
Ka = b (4.21)
with
K =
_
L
0
_
B
T
B

dx
and
b =
_
L
0

T
fdx
This is the nal form of the solution part of the FEM. We can use any
methods to solve for the unknown vector a, and then use Eq. (4.12) to nd
u(x).
4.2.1 Galerkins Method in discrete domains
the power of the FEM is that the form of Eq. (4.19) is applicable when
the domain is discretized into more elements
we just have to keep track of the indices and then assemble the element
stiness matrices into a global matrix
As an example, suppose the bar of length L is discretized into 4 seg-
ments/elements as in Fig. 4.1.
1
2 3 4
5
1
2
3 4
Figure 4.1: 1D mesh of four elements.
There are now eight basis functions for the whole bar domain. We choose
the basis functions such that they are dened locally as seen in Fig. 4.2.
14 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
Figure 4.2: All the basis functions in the mesh.
4.3. 1-D LINEAR BASIS FUNCTIONS IN LOCAL COORDINATES 15
These basis functions look like a hat function along the bar (Fig. 4.3).
1 2 3 4
5
Figure 4.3: Combination of all the basis functions to become hat function.
NOTE: With these basis functions, integration of these functions over the
whole total length of the domain just yield zero values for the elements not
dened by the local basis functions.
We can instead integrate for each element. This is the reason when you
later get many zero entries in the K matrix.
Now we integrate the basis functions element per element. An element is
labeled as in Fig. 4.4.
i
j
e
Figure 4.4: A single element of length l with local labels.
If we apply the Galerkin method on each nite element, Eq. (4.20) be-
comes
_
x
j
x
i
_
B
(e)
T
B
(e)
_
dx a
(e)
=
_
x
j
x
i

(e)
T
f
(e)
dx (4.22)
4.3 1-D Linear Basis Functions in Local Co-
ordinates
Look at Fig. 4.5. We can dene the basis functions for this element in
terms of the local coordinates :
=
_
1
2
(1 )
1
2
(1 + )

(4.23)
Eq. (4.23) comprised of two independent linear functions described over
the element in local coordinates (Linear element).
With these two functions,
1
and
2
we can described exactly any given
linear variation of u(x) over the element. With
u(x) =
1
a
1
+
2
a
2
(4.24)
we can nd a
1
, a
2
to dene any u
The global-local mapping is given by
x =
l
2
+
1
2
(x
i
+ x
j
) (4.25)
16 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
Figure 4.5: Basis functions dened in local coordinates.
For some examples, consider dierent cases of linear variation of u over
the element as in Fig. 4.6. Linear variation can be described exactly by the
linear basis functions:
For u
1
(), u
1
(1) = 0, u
1
(1) = 10
Using the boundary values to nd a
1
, a
2
,
u
1
() =
1
a
1
+
2
a
2
= 10
2
(4.26)
For u
2
(), u
2
(1) = 7, u
2
(1) = 5
Using the boundary values to nd a
1
, a
2
,
u
2
() =
1
a
1
+
2
a
2
= 7
1
+ 5
2
(4.27)
For u
3
(), u
3
(1) = 2, u
3
(1) = 2
Using the boundary values to nd a
1
, a
2
,
u
3
() =
1
a
1
+
2
a
2
= 2
1
2
2
(4.28)
These examples provide the notion of the degrees of freedom {a
1
, a
2
}
acting as the support points of the basis functions.
4.3. 1-D LINEAR BASIS FUNCTIONS IN LOCAL COORDINATES 17
Figure 4.6: Dierent linear variations of u over the element.
18 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
4.4 1-D Integration of Basis Functions
Recall from the weak form that we need to integrate the basis functions and
their derivatives. From Eq. (4.25)
x =
l
2
+
1
2
(x
i
+ x
j
) (4.29)
Then,
dx =
l
2
d (4.30)
Recalling Eq. (4.23)
=
_
1
2
(1 )
1
2
(1 + )

Then,
B
(e)
=
d
(e)
dx
=
l
2
d
(e)
d
(4.31)
=
_
1 1

1
l
(4.32)
4.5 1-D Element Stiness Matrix and Load
Vector
K
(e)
=
l
2
_
1
1
_
B
(e)
T
B
(e)
_
d (4.33)
K
(e)
=
1
l
_
1 1
1 1
_
(4.34)
b
(e)
=
l
2
_
1
1

(e)
T
f
(e)
d (4.35)
For constant f = p
b
(e)
=
lp
2
_
1
1
_
(4.36)
4.6 Pseudocode
A pseudocode is a compact and informal high-level description of a pro-
gramming language that uses the structural convention of a programming
language but for human reading.
In our lecture, we use the Matlabs structural convention for our pseu-
docode.
Examples:
1. algorithm with the if statement:
if <condition>
do something
else
do something else
4.7. 1-D ASSEMBLY 19
2. algorithm with the for loop statement:
initalize array variable1
for <var> from <initial value>:<final value> (*)
do something with variable1
* here we assume increment by 1
Note:
In pseudocode we do not worry about the correctness of actual syntax as
long as the algorithm is understandable.
4.7 1-D Assembly
Now that we have element matrix and vector for each element in the mesh, we
have to combine them into a single matrix-vector equation as in Eq. (4.21).
Revisit our example mesh in Fig. 4.1. We begin the assembly process as
follows:
1. Create and array of the nodal coordinates:
x = {x
1
, x
2
, x
3
, x
4
, x
5
}
For our example,
x = {0, .25, .5, .75, 1.}
2. Create element connectivity map:
should tell us for example: which node number corresponds to local
node i of element 3
The array would look like
e 1 2
1 1 2
2 2 3
3 3 4
4 4 5
3. Create array for BC information
4. Assemble k and b
For our example problem the algorithm can be followed (although not
ecient)
1 set elementDOF = 2 \% each element has 2 DOF
2 ndof = number of DOFs
3 Intialize: K = zeros(ndof,ndof)
4 Initialize: bb = zeros(ndof)
5 for e from 1 to NumberOfElements
6 fetch b of element e % call a function
7 fetch k of element e % call a function
8 for ir from 1 to 2 \% visit the row of the element matrix
9 irs = elementDOFMap(e,ir)
20 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
10 bb(irs) = b(ir)
11 for ic from 1 to 2 \% visit the column of the element matrix
12 ics = elementDOFMap(e,ic)
13 % Update the system matrix and vector
14 K(irs,ics) = K(irs,ics) + k(ir,ic)
15 end column loop
16 end row loop
17 end element loop
5. The system matrix and vector obtained by this assembly is not
solvable. The matrix is singular due to absence of boundary conditions.
Resulting K
_

_
k
(1)
11
k
(1)
12
0 0 0
k
(1)
21
k
(1)
22
+ k
(2)
11
k
(2)
12
0 0
0 k
(2)
21
k
(2)
22
+ k
(3)
11
k
(3)
12
0
0 0 k
(3)
21
k
(3)
22
+ k
(4)
11
k
(4)
12
0 0 0 k
(4)
21
k
(4)
22
_

_
(4.37)
1
l
_

_
1 1 0 0 0
1 2 1 0 0
0 1 2 1 0
0 0 1 2 1
0 0 0 1 1
_

_
(4.38)
Resulting b
_

_
b
(1)
1
b
(1)
2
+ b
(2)
1
b
(2)
2
+ b
(3)
1
b
(3)
2
+ b
(4)
1
b
(4)
2
_

_
(4.39)
lp
2
_

_
1
2
2
2
1
_

_
(4.40)
Note the conditions about the entries of K and b above:
the material property of each element is the same, = 1
the domain is equally partitioned so the length l of each element is the
same
4.7. 1-D ASSEMBLY 21
4.7.1 Modication of system matrix for essential BC
There are many approaches to incorporating BCs in K. We use a computer
approach that retains favorable property of K when solving the system of
equations.
Basic idea:
we already know the solutions at the end pointswe actually impose
them
hence a
i
relating to u is implied
From our problem, u(0) = u(L) = 0
u(0) is in e1, so
u(0) =
1
()a
1
+
2
()a
2
(4.41)
u(0) =
1
(1)a
1
+
2
(1)a
2
(4.42)
0 = 1a
1
+ 0a
2
(4.43)
So, a
1
must be zero to satisfy the BC. This is local a
1
which corresponds to
global a
1
(Refer to the element connectivity map). We need to force global
a
1
to be zero.
Similarly for u(L), L is in e4, so
u(L) =
1
()a
1
+
2
()a
2
(4.44)
u(L) =
1
(1)a
1
+
2
(1)a
2
(4.45)
0 = 0a
1
+ 1a
2
(4.46)
So, a
2
must be zero to satisfy the BC. This is local a
2
which corresponds to
global a
5
(Refer to the element connectivity map). We need to force global
a
5
to be zero.
We use the following algorithm for modication of the system matrix K
to incorporate essential BC by preserving symmetry in K. (from Kwon, FEM
with Matlab).
1 for ic from 1 to 2; % loop for two ends of constraints (1-D)
2 id = bcdof(ic);
3 val = bcval(ic);
4 for i from 1 to ndof;
5 bb(i) = bb(i) - val*K(i,id);
6 K(id,i) = 0
7 K(i,id) = 0;
8 end
9 K(id,id) = 1;
10 bb(id) = val;
11 end
The resulting equation system would look like this for the given BCs:
_

_
1 0 0 0 0
0 2 1 0 0
0 1 2 1 0
0 0 1 2 0
0 0 0 0 1
_

_
a =
l
2
p
2
_

_
0
2
2
2
0
_

_
(4.47)
22 CHAPTER 4. FINITE ELEMENT FORMULATION IN 1-D
4.8 Solution of Ka = b
To solve the system of equations, we can use the Gaussian elimination method
for this small problem.
For the above equation, a = [0 .1875 .25 .1875 0]
T
4.9 Post-processing
Post-processing concerns with evaluation and visualization of our un-
known eld u
often we also want to see the derived values (like heat ux)
Recall that for 1-D with linear elements:
u(x) = a
1

1
(x) + a
2

2
(x) (4.48)
Observe:
At local Node 1,
1
= 1;
2
= 0. Hence, at Node i u(x
i
) = a
i
By the same observation, for the global node u(x
j
) = a
j
So, the DOF a
i
is the solution to the eld variable u at the node i.
To nd u(x) on the edge of an element, search for which element con-
tains the location x, then use the above equation.
The nite element solution to the example problem (4.4) with the mesh
in Fig. 4.1 is shown in Fig. 4.7.
1
2 3 4
5
1
2
3 4
Figure 4.7: Solution to the example problem with 4 element mesh.
4.10 Concluding Notes
the simple example does not account non-homogenous materials
since k and f are the same for the whole domain L, and each element
has the same length, the element matrix and load vector are the same
in each element. This is an exception.
for general case, you have to include the factors k,L for evaluating the
element matrix
for non-constant f, you have to evaluate the integral for b.
Solution for Ka = b with the Gaussian elimination method is viable
only in small size problems (n in hundreds). For more realisic problems,
various other matrix solution methods must be used
Chapter 5
1-D FEM: Applications
5.1 Steady-State Heat Conduction Revisited
Recall the Poissons equation we used to describe steady-state heat conduc-
tion in 1-D:

d
2
u
dx
2
= f (5.1)
Possible boundary conditions: Given a boundary
Dirichlet/essential BC:
u = p
on , if p zero, then known as homogenous Dirichlet BC (First kind)
Neumann/natural BC:
du
dx
= q
on ,if q zero, then known as homogenous Dirichlet BC (Second kind)
Generalized/Robin BC:
au + b
du
dx
= r
on ,if r zero, then known as homogenous Neumann BC (Third kind)
Application of BC for the Robin BC is a bit more complicated, well skip it.
NOTE: For homogenous Neumann BC, we do not need to do anything
to the system matrix Kone reason why it is called natural BC.
5.1.1 Boundary conditions
Physical interpretations of the BC for heat conduction problem:
Dirichlet BC: temperature is xed
Neumann BC: heat ux q is xed
T
n
= q
If q = 0, we call this insulated/adiabatic boundary.
23
24 CHAPTER 5. 1-D FEM: APPLICATIONS
Robin BC: convective heat transfer coecient is xed
hT
w

dT
dx
= T

h =heat transfer coecient, T


w
=boundary temperature, T

= ambi-
ent temperature.
5.1.2 Nonconstant source term
FiXme: skip
1D numerical integration
FiXme: skip
5.1.3 Varying (x)
If varies, then the element stiness matrix for each element is no longer
the same. must be accounted in the element matrix
K
(e)
=
l
2
_
1
1
_
B
(e)
T
B
(e)
_
d (5.2)
K
(e)
=

l
_
1 1
1 1
_
(5.3)
Examples where may vary:
nonhomogenous materials in the domain
This is quite straight forward. Just use the right k for the material of the
element.
varying cross sectional area
From Fouriers law of heat conduction heat q is dened per unit area A:
q = kA
T
x
(5.4)
For a homogenous material of conductivity k, if A varies with x, then
(x) = kA(x)
The element matrix is then
K
(e)
=
kAl
2
_
1
1
_
B
(e)
T
B
(e)
_
d (5.5)
K
(e)
=
kA
l
_
1 1
1 1
_
(5.6)
5.2. CONVERGENCE OF SOLUTION/DISCRETIZATION ERROR 25
5.2 Convergence of solution/discretization er-
ror
For our linear interpolation functions (basis functions), the order of conver-
gence in terms of the element size h (length) can be predicted. The error
converges in the order
O(h
2
) (5.7)
meaning that, for example if h is reduced by half, the error is reduced by
1/4. approached 0 as h approaches 0. I.e., the more divisions the more
accuracy is obtained.
5.3 Formulations for Elasticity Problems
A problem in elasticity that can be described with a Poisson equation (second
order dierential equation) may be described buy the DE
d
dx
_
EA
du
dx
_
= f(x) (5.8)
which is exactly the second order Poissons equation
d
dx
_
k(x)
du
dx
_
= f(x) (5.9)
BCs:
u(0) = 0;
du(L)
dx
= 0 (5.10)
The cross-sectional area varies linearly
A(x) = A
0
(1 + x/L) (5.11)
This DE describes the axial displacement u(x) due to axially loaded bar given
by the load f(x).
As an exercise, use the previously constructed element stiness matrix
and load vector for the heat problem to construct the corresponding matrix
and vector for this elasticity problem. Take into account that the material
property k = EA is now dierent among the elements.
P
L
x
Figure 5.1: axially loaded rod
26 CHAPTER 5. 1-D FEM: APPLICATIONS
5.4 Formulations for Elasticity Problems: Beam
bending
A problem in elasticity that can be described with a Poisson equation is beam
deection with the moment function (refer to e.g. Hibbelers and Benhams
books):
EI
d
2
v
dx
2
= M(x) (5.12)
where in terms of the general form of equation
k
d
2
u
dx
2
= f (5.13)
k = EI provided EI is constant, u = deection of beam, f = M(x) the
moment function (in negative sense).
But a more common equation to describe the deection of a beam is with
the (physical) load function w(x):
EI
d
4
v
d x
4
= w( x) (5.14)
or
d
2
d x
2
_
EI
d
2
v
d x
2
_
= w(x) (5.15)
This is a fourth-order PDE, which is also solvable with the FEM. The dif-
ference is that we have to use dierent kind of basis functions. To satisfy
the weak form of the above equation, we need basis functions that are also
continuous with their rst derivatives which is not required before like in the
heat conduction problem.
In the FEM, this type of functions is known as C(1)-continous functions.
The previous type is called C(0)-continous.
5.5 Beam elements
FiXme: skip
Basis functions

1
=
1
L
3
(2 x
3
3 x
2
L + L
3
) (5.16)

2
=
1
L
3
( x
3
L 2 x
2
L
2
+ xL
3
) (5.17)

3
=
1
L
3
(2 x
3
+ 3 x
2
L) (5.18)

4
=
1
L
3
( x
3
L x
2
L
2
) (5.19)
Element matrix equation
EI
L
3
_

_
12 6L 12 6L
6L 4L
2
6L 2L
2
12 6L 12 6L
6L 2L
2
6L 4L
2
_

_
_

_
d
1

1
d
2

2
_

_
=
_

_
f
1
m
1
f
2
m
2
_

_
(5.20)
5.6. ELASTIC STRAIN ENERGY 27
5.6 Elastic strain energy
5.6.1 Review of work by external force
A force does work when it undergoes a displacement dx that is in the same
direction as the force.
Denition: dW Fdx
If the total displacement is x:
W =
_
x
0
Fdx (5.21)
In elastic case, and where load gradually increases from 0 to F and total
displacement is , work is then
W =
1
2
F (5.22)
W may be seen seen as area under graph of F x.
5.6.2 Elastic strain energy U due to uniaxial stress
Denition of elastic strain energy: the stored energy released when the ma-
terial returns to its underformed state when the loading is being removed.
Work is done by the applied loading.
Work done = Elastic strain energy U:
W = U (5.23)
U is always a positive scalar value
the general formula is
U =
_
V

2
dV (5.24)
Using Hookes law = E
U =
_
V

2
2E
dV (5.25)
Introduce elasticity matrix (or stress/strain matrix, or constitutive matrix)
D to relate stress and strain in higher dimensions:
= D (5.26)
So, for higher dimensions, the strain energy is
U =
1
2
_
V

T
DdV (5.27)
or in terms of ,
U =
1
2
_
V

T
D
1
dV (5.28)
28 CHAPTER 5. 1-D FEM: APPLICATIONS
Recall that we use the formulation for the stiness matrix K with B (K
is composed of the gradient of ).
Recall also the strain is the gradient of displacement, and the displace-
ment is expressed with the basis functions times the dof vector.
Then U can be found with
U =
1
2
a
T
Ka (5.29)
5.6.3 Error in energy based on discontinuity of stress
In axial displacement, the basis functions enforce continuity of the functions,
but not their gradients.
Hence stress elds can be discontinuous between elements.
We use this fact for estimating our error in FEM.
Let
n
= stress vector at a node.
Then take the dierence between the nodal values and the average:
=
ave

n
(5.30)
Then error in energy for one element is
e
(e)
=
1
2
_
V

T
D
1
dV (5.31)
For the entire domain, we just sum up e
(e)
of all elements.
More often, we deal with the norm of error e:
||e
(e)
|| =
_
1
2
_
V

T
D
1
dV
_
1/2
(5.32)
And also, we prefer the error with respect to the strain energy U above:
e
rel
= ||e||/||U|| (5.33)
Usually in engineering we want e
rel
to be less than 5 %. In Ansys, this
error in energy is obtained by the command PRERR.
Chapter 6
Formulations for Field
Problems in 2D: Heat
Conduction
6.1 2-D Heat Conduction
The PDE:

x
_

xx
T
x
_
+

y
_

yy
T
y
_
= Q(x, y) (6.1)
subject to boudary conditions.
xx,yy
is thermal conductivity in the {x, y}.
In a more compact and general form, we can write the above as
u = f (6.2)
or
div ( grad u) = f (6.3)
For simplicity we only deal with two types of boundary conditions:
1. Specifying temperature T: Dirichlet or essential BC
2. Specifying the gradient of T, i.e, the heat ux q
n
: Neumann or natural
BC.
To get the FEM formulation:
the formulation for the weak form is like in 1-D
the dierence is that to reduce the order of the integral equation of
the weak form, we use Greens theorem instead of integration by parts
(since were now in higher dimension)
the application of Galerkins method proceeds as before
29
30CHAPTER 6. FORMULATIONS FORFIELDPROBLEMS IN2D: HEAT CONDUCTION
6.2 Finite Elements in 2-D
6.2.1 Linear quadrilaterals and triangles
Basis functions for triangles are most commonly expressed in natural coor-
dinates (known as area coordinates in 2-D).

1
+
2
+
3
= 1
A
1
+ A
2
+ A
3
= A

i
=
A
i
A
y
x
0
P
L
2
=0
L
3
=0
L
1
=0
A
2
A
3
A
1
Figure 6.1: Natural coordinate system for triangles (
1
,
2
,
3
).
The linear mapping is given by:
_
_
1
x
y
_
_
=
_
_
1 1 1
x
1
x
2
x
3
y
1
y
2
y
3
_
_
_
_

3
_
_
; (6.4)
and inversely,
_
_

3
_
_
=
1
2A
_
_
a
1
b
1
c
1
a
2
b
2
c
2
a
3
b
3
c
3
_
_
_
_
1
x
y
_
_
, (6.5)
where
a
1
=x
2
y
3
x
3
y
2
b
1
= y
2
y
3
c
1
= x
3
x
2
a
2
=x
3
y
1
x
1
y
3
b
2
= y
3
y
1
c
2
= x
1
x
3
a
3
=x
1
y
2
x
2
y
1
b
3
= y
1
y
2
c
3
= x
2
x
1
and
2A =

1 x
1
y
1
1 x
2
y
2
1 x
3
y
3

= |x
1
y
2
x
1
y
3
+ x
2
y
3
x
2
y
1
x
3
y
1
x
3
y
2
| (6.6)
The linear basis functions are given by:

1
=
1
(6.7)

2
=
2
(6.8)

3
=
3
(6.9)
6.3. 2-D ELEMENT STIFFNESS MATRIX AND LOAD VECTOR 31
6.3 2-D Element Stiness Matrix and Load
Vector
Recall the denition of stiness matrix. In 2-D, the integral is over the area
of the triangle element :
k
(e)
ij
=
_

i

j
d; i, j = 1, 2, 3 (6.10)
Hence
k
(e)
ij
=
_

1
4(A
(e)
)
2
[b
i
b
j
+ c
i
c
j
]d (6.11)

i
is a constant. We can write k
(e)
ij
as
k
(e)
ij
=
1
4(A
(e)
)
[b
i
b
j
+ c
i
c
j
] (6.12)
The complete element stiness matrix is then
K
(e)
=
1
4A
(e)
_
_
b
1
b
1
+ c
1
c
1
b
2
b
1
+ c
2
c
1
b
3
b
1
+ c
3
c
1
b
1
b
2
+ c
1
c
2
b
2
b
2
+ c
2
c
2
b
3
b
2
+ c
3
c
2
b
1
b
3
+ c
1
c
3
b
2
b
3
+ c
2
c
3
b
3
b
3
+ c
3
c
3
_
_
(6.13)
For element load vector, recall
f
(e)
1
=
_

f
1
d (6.14)
f
(e)
2
=
_

f
2
d (6.15)
f
(e)
3
=
_

f
3
d (6.16)
Since we said f is constant, say f(x) = Q, we have
f
(e)
i
= Q
_

i
d (6.17)
To integrate the basis function over the area, recall that
i
=
i
. Also, for
area cooridinates the integration is given by
_

a
i

b
j

b
k
d =
a!b!c!
(a + b + c + 2)!
2 (6.18)
By using the above formula we can now have f
(e)
as
f
(e)
=
Q
3
_
_
1
1
1
_
_
(6.19)
32CHAPTER 6. FORMULATIONS FORFIELDPROBLEMS IN2D: HEAT CONDUCTION
6.4 Boundary Conditions on
A
and
B
3 types of prescribed boundary conditions and their physical meanings in
heat transfer problem.
1. prescribed eld
specify temperature: u = T
A
on
A
if T
A
= 0, i.e., u = 0 on
A
, this is called homogenous BC.
eld specied BC is a.k.a Dirichlet BC, or essential BC
2. prescribed gradient of the eld normal to the surface
recall Fouriers law: q = kT. Here gradient of u is the ux
if gradient is zero:
u
n
= 0,
this BC refers to perfectly insulated BC, since no heat ux is
allowed
zero normal ux is a.k.a Neumann BC, or natural BC
if heat ux is allowed, then
k
u
n
= q
where we assume that the material is isotropic: k
xx
= k
yy
specify ux: u = T
A
on
A
3. prescribed combination of the above
specify convection:
k
u
n
= (u u
a
)
where = heat transfer coecient, u
a
=ambient T
Chapter 7
Linear Solvers
7.1 Sparse Matrix Solvers
Assembly of element matrices and load vectors result in the system of linear
equations:
Ax = b (7.1)
The resulting matrix A (formerly K) is called global or system matrix. The
DOFs are stored in the vector x (formerly a).
The system matrix is sparse: there are many more zero entries than
nonzero entries. Why?
For realistic problems, nding A
1
is impossible with computer (too much
memory usage).
Note here that we have arrived from our PDE problem to linear alge-
bra problem. The problem now is about the solution of simulaneous linear
algebraic equations.
2 approaches to solution of the algebra problem: direct and indirect.
7.1.1 Direct Method
based on Gaussian elimination
complexity of classical Gauss: O(n
3
)
matrix is factorized, e.g., LU decompostion (available in Matlab)
LU also O(n
3
)
in general, memory intensive
Simple Gauss elimination
Consists of forward elimination to make the matrix upper triangle.
Then solve with backward elimination
Example: solve
_
_
1 1 5
1 2 0
5 0 1
_
_
x =
_
_
0
1
2
_
_
(7.2)
33
34 CHAPTER 7. LINEAR SOLVERS
Start with
_
_
1 1 5 |0
1 2 0 |1
5 0 1 |2
_
_
(7.3)
Eliminate Row 2, Column 1: R2 = R2 + R1
_
_
1 1 5 |0
0 1 5 |1
5 0 1 |2
_
_
(7.4)
Eliminate Row 3, Column 1: R3 = R3 5R1
_
_
1 1 5 |0
0 1 5 |1
0 5 24 |2
_
_
(7.5)
Eliminate Row 3, Column 2: R3 = R3 5R2
_
_
1 1 5 |0
0 1 5 |1
0 0 49 | 3
_
_
(7.6)
Now solve with backward substitution to get x
_
_
0.3878
0.6939
0.0612
_
_
(7.7)
LU decomposition
The problems with Gauss elimination:
can have 0 division
to many ll-in entries memory intensive
The LU decomposition can avoid/minimize this problem.
LU stands for Lower and Uupper matrices.
Structure of L:
_
_
l
11
0 0
l
21
l
22
0
l
n1
l
n2
l
nn
_
_
Structure of U:
_
_
u
11
u
12
u
1n
0 u
22
u
2n
0 0 u
nn
_
_
Decompose:
Ax = b
into
(LU)x = b
7.1. SPARSE MATRIX SOLVERS 35
Then solve for x in 2 steps:
1. Solve for intermediate vector y with forward substitution
Ly = b (7.8)
2. Solve for x with backward substitution
Ux = y (7.9)
LU decomposition with Crouts algorithm
The algorithm creates U with unit diagonals:
_
_
1 u
12
u
1n
0 1 u
2n
0 0 1
_
_
Algorithm:
l
i,1
= a
i,1
for i = 1, 2, . . . , n (7.10)
u
1j
=
a
1j
l
11
for j = 2, 3, . . . , n (7.11)
For j = 2, 3, . . . , n 1
l
ij
= a
ij

j1

k=1
l
ik
u
kj
for i = j, j + 1, . . . , n (7.12)
u
jk
=
a
jk

j1
i=1
l
ji
u
ik
l
jj
for k = j + 1, j + 2, . . . , n (7.13)
For the entry l
nn
:
l
nn
= a
nn

n1

k=1
l
nk
u
kn
(7.14)
Example: Using the same matrix problem above:
Apply Eqs. (7.10) and (7.11):
l
i,1
=
_
_
1
5
5
_
_
(7.15)
u
i,1
=
_
u
11
1 5

(7.16)
Apply Eqs. (7.12) and (7.13):
l
22
= 2 l
21
u
12
= 2 (1)(1) = 1
l
32
= 0 l
31
u
12
= 0 (5)(1) = 5
u
22
=
a
22
l
21
u
12
l
22
=
2 (1)(1)
1
= 1
36 CHAPTER 7. LINEAR SOLVERS
u
23
=
a
23
l
21
u
13
l
22
=
0 (1)(5)
1
= 5
Finally use (7.14):
l
33
= a
33
(l
31
u
13
+ l
32
u
23
) = 1 (5)(5) = 49
Since we know that u
33
= 1, we can form L and U:
L =
_
_
1 0 0
1 1 0
5 5 49
_
_
U =
_
_
1 1 5
0 1 5
0 0 1
_
_
To solve, solve for y using Eq. (7.8) rst:
y =
_
_
0.00000
1.00000
0.06122
_
_
Then solve for x using Eq. (7.9):
x =
_
_
0.3878
0.6939
0.0612
_
_
7.1.2 Iterative Method
From Eq. (7.1), if x is not the exact solution, then the dierence between
the LHS and RHS is the residual:
r = b A x (7.17)
In iterative method, we solve the algebra problem repetitively as we im-
prove x after each iteration until the residuals are small enough.
The trick is to nd a fast search direction to achieve this objective.
Further notes:
a simple method is the Gauss-Seidel method (not covered here)
complexity is O(n
2
)
most iterative methods are based on Conjugate Gradient (CG) Method,
more stable
complexity is O(n) for sparse matrix
use less memory
The CG algorithm can be found in many resources, for example at http://en.wikipedia.org/w
7.1. SPARSE MATRIX SOLVERS 37
Example with the Conjugate Gradient algorithm
Using the same Eq. as before:
Start with intial guess:
x
(0)
= [0 0 0]
T
Then inital residual is equal to the RHS:
r
(0)
= [0 1 2]
T
Start iteration: k = 1
x
(1)
= [0 1.8333 3.6667]
T
r
(1)
= [0.8333 1 2]
T
At k = 2:
x
(2)
= [0.56639 0.02570 0.07447]
T
r
(2)
= [0.16833 1.51500 0.75750]
T
At k = 3:
x
(3)
= [0.38776 0.69388 0.06122]
T
we reach the solution!
r
(3)
= [2.2204 10
16
4.4409 10
16
1.2212 10
15
]
T
To see the trend of error reduction by each iteration we work with the
L2-norm of r
(k)
.
k norm of r
(k)
0 2.2361
1 7.5369
2 1.7022
3 1.3183e-15
We see that a problem with n unknowns will converge in n iteration steps
at most.
Exercise: Suppose
A =
_
_
1 1 4
1 2 0
4 0 2
_
_
; b =
_
_
1
2
2
_
_
(7.18)
Chapter 8
Post-processing
Post-processing concerns with evaluation and visualization of our un-
known eld u
often we also want to see the derived values (like heat ux)
Recall that for 1-D with linear elements:
u(x) = a
1

1
(x) + a
2

2
(x) (8.1)
Observe:
At Node 1,
1
= 1;
2
= 0. Hence u(x
i
) = a
i
By the same observation, u(x
j
) = a
j
So, the DOF a
i
is the solution to the eld variable u at the node i.
To nd u(x) on the edge of an element, search for which element contains
x, then use the above equation.
So, we need an algorithm to search for the element (many available).
38
Bibliography
[1] Femhub. Available from: http://femhub.org.
Key: Femhub
[2] Ansys, Inc., 275 Technology Drive, Canonsburg, PA 15317, USA. Ansys
Theory Manual, 2009.
Key: AnsysTM
[3] Y. W. Kwon and H. Bang. The Finite Element Method using MATLAB.
CRC Press LLC, New York, 1997.
Key: Kwon97
[4] D. L. Logan. A First Course in the Finite Element Method. Cengage
Learning, Stamford, PA, fourth edition, 2011.
Key: Loga11
[5] O. C. Zienkiewicz and R. L. Taylor. The Finite Element Method: The
Basis, volume 1. Butterworth-Heinemann, Oxford, 2000.
Key: Zien01
39