P. 1
Jcerda Notes FE0

|Views: 2|Likes:

See more
See less

03/06/2012

pdf

text

original

# Simulationsmethoden I WS 09 10

Lecture Notes
Finite element methods applied to solve
PDE
Joan J. Cerdà

December 14, 2009
ICP, Stuttgart
Contents
1 In this lecture we will talk about 2
2 FDM vs FEM 2
3 Perspective: different ways of solving approximately a PDE. 2
4 Basic steps of any FEM intended to solve PDEs. 4
5 FEM in 1-D: heat equation for a cylindrical rod. 5
6 FEM in 2-D: the Poisson equation. 10
7 Sparse Matrixes (band matrixes) and FEM. 17
8 Other tricks for FEM and beyond. 18
9 Bibliography 19

jcerda put here an at symbol icp.uni-stuttgart.de
1
1 In this lecture we will talk about
1. FDM vs FEM.
2. Perspective: different ways of solving approximately a PDE.
3. Basic steps of any FEM intended to solve PDEs.
4. FEM in 1-D: heat equation for a cylindrical rod.
5. FEM in 2-D: the Poisson equation.
6. Sparse Matrixes (band matrixes) and FEM.
7. Other tricks for FEM and beyond.
8. Bibliography.
2 FDM vs FEM
1. With FEM you can handle better boundary problems with odd geometries.
2. With FEM it is easier to make more ﬁner subdivisions of the space in regions where you
need more accuracy. This is not so easy to do with FDM.
A word of caution: FEM as FDM are suitable for linear PDE’s. If you have non-linear PDEs.
You will have ﬁrst to linearize it.
3 Perspective: different ways of solving approximately a
PDE.
I have a PDE with certain bc (boundary conditions) to be solved, which options do I have:
1. Analytical solution: the best, but not always available.
2. Approximate solutions. There is always an error. The difference between the exact value
and the approximate value is called the residual, we will denote it by R. For instance, let’s
suppose I have to solve the following ODE:
d
ˆ
φ
dx
+
ˆ
φ(x) = 0 (1)
if my approximate solution is φ(x) = 1 + a
1
x + a
2
x
2
, where a
1
and a
2
must be
determined to get the φ as close to the exact solution
ˆ
φ as I can. In that example the
residual is
R(x; a
1
, a
2
) ≡

dx
+ φ(x) = 1 + (1 + x) a
1
+ (2x + x
2
) a
2
(2)
2
There are several ways of solving approximately a PDE, the most usual are:
1. Ritz method (aka Goodman’s method): we get a
1
and a
2
_
Domain
R(x; a
1
, a
2
)dx = 0 (3)
2. Variational method (Rayleight-Ritz method): from the PDE we get its variational inte-
gral. The function
ˆ
φ that minimizes that variational integral is the solution to the problem.
[FALTA]
3. Weighted residual methods: in this methods we assume the parameters a
1
, a
2
(, ..., a
n
if we have n in a general case) to be determined by asking the residual to obey a set of
equations:
_
Domain
R(x; a
1
, .., a
n
) ω
i
(x) dx = 0 (4)
where ω
i
(x) with i = 1, ..n are n arbitrary functions called weighting functions. Some
usual choices of ω
i
(x) are
a) Collocation method: we ask the residual R to be zero at n points {x
i
}
i=n
i=1
inside the
domain. which is equivalent to say ω
i
(x) = δ(x − x
i
).
b) Sub-domain method: we split the domain in n regions and we ask the averaged R,
< R >, to be zero inside each region.
c) Least-Squares method: we set ω
i
(x) =
∂R
∂a
i
d) Galerkin method: if we use approximate solutions of the type φ(x) = 1 + a
1
x +
a
2
x
2
, this means that N
i
(x) = x and N
2
(x) = x
2
are a set of basis vectors for all
our possible solutions. We set ω
i
(x) = N
i
(x),i.e., we have to solve n equations (in
our example n = 2) like
_
Domain
R(x; a
1
, .., a
n
) N
i
(x) dx = 0. (5)
4. FDM: Finite Difference Methods.
5. FEM: Finite Element Methods.
6. FVM: Finite Volume Methods. A reﬁned FDM popular in Computational ﬂuid dynamics.
7. MOM:method of moments. You convert your differential equation into an integral equa-
tion. Used specially in electromagnetics.
3
4 Basic steps of any FEM intended to solve PDEs.
In all FEM variants there are always the same sequence of steps to be taken
1. Discretize the continuum: divide the solution into smaller regions that we call elements.
The elements contain inside a certain number of points we call nodes. There are lots of
shapes the elements can have. From segments of lines, triangles, squares, etc, to curved
elements. The one/ones you will use depends on the problem you want to solve. For
instance, for a 1D problem, like a cylindrical rod with radial symmetry, the most simple
is to take the elements as linear segments with two nodes per segment (see Fig.1) and
discretize it is as shown in ﬁgure 2. For a 2D problem, the most simple can be using
triangular elements (see ﬁgure 3).
2. Select the type of trial function to use, and in turn the shape functions: We select
what kind of functions we will take to describe the variation of the function φ inside
each element (the trial function). This is equivalent to say, that we select the basis set of
functions that will describe our solution. One of the usual choices is to take a polynomial
like for instance φ(x) = a
0
+a
1
x (known as linear element) or φ(x) = a
0
+a
1
x+a
2
x
2
(known as quadratic element). If we have n unknown coefﬁcients a
0
, a
1
, ..., a
n−1
we will
need the element to have n nodes to be able to determine them.
Is it easy to show that the value of our trial function φ for a given position x inside an
element can be written as a function of the values of φ at the N nodes the of element
([φ
1
, φ
2
, ..., φ
N
]) , i.e.
φ(x) = [φ] · [N] = [φ
1
, φ
2
, ..., φ
N
] · [N
1
(x), N
2
(x), ..., N
N
(x)] (6)
where the {N
i
(x)}
i=N
i=1
are known as the Shape Functions.
3. The formulation: Given the PDE you want to solve, now you must ﬁnd a system of
algebraic equations for each element "e" such that by solving it you got the values of of
φ at the position of nodes of the element "e" ([φ
1
, φ
2
, ..., φ
N
] ≡ [φ]
e
), i.e., you must ﬁnd
for each element "e" the matrix [K]
e
and the vector [f ]
e
such that,
[K]
e
· [φ]
e
= [f ]
e
. (7)
This is one of the more tricky parts of the FEM. There are different ways of getting the
matrix [K]
e
, we will see it later.
4. Assembling the equations for different elements: one has to assemble the equations for
all elements. The "problem" is that usually contiguous elements have nodes in common
(see for instance ﬁgure 2, and therefore two algebraic equations may refer to the same
node, and that has to be taken into account. At the end, if we have a total of M effective
nodes
1
in the system, then we must build up a global matrix [K] of size M × M and a
1
For instance in ﬁgure 1 we have a total of 5 elements that have each one two nodes, nonetheless due to the nodes
in common, the number of effective nodes we have (the number of unknowns) is just M = 6 and not 10.
4
global vector [f ] of size M such that the FEM problems "reduces" to solve the following
matrix equation:
[K] · [φ] = [f ]. (8)
where [φ] ≡ [φ
1
, φ
2
, ..., φ
M
] is the value of the approximate solution φ at the position
where the effective nodes are.
Notice that once we now [φ
1
, φ
2
, ..., φ
M
] one is able to calculate the value of φ at whatever
point x of the system, just make use of equation 6.
5. Solve the system of equations: In principle you can use whatever method you want, but
the more the number of nodes the use, the better is the quality of the solution, the matrices
we will build up can be very large, i.e. M becomes very large. As we will see, most of
elements of matrix [K] are zero, sparse matrix, so you can save a lot of time and memory
if you use special methods for sparse matrixes, we will see it later.
6. Compute secondary quantities: Once you know the φ values, you can compute other
magnitudes using the values of φ.
Let’s see now two examples about how this works in practice
Figure 1: A single one dimensional element
5 FEM in 1-D: heat equation for a cylindrical rod.
In this section we plan to build up a very simple and basic one-dimensional FEM method.
Let’s consider a cylindrical rod of radius R and length L with one end insulated an the other
held to constant temperature T
tip
, while the surrounding environment has a temperature T
env
(see ﬁgure 2). We assume the cylinder lies along the x-axis, and the insulated tip is located at
x = 0. The lost of heat occurs via the lateral surface of the cylinder at a rate characterized by the
heat transfer coefﬁcient h which units are W/(m
2
K), we assume that the thermal conductivity
5
Figure 2: The 1D system we want to study using Galerkin FEM. The plot corresponds to using
5 one-dimensional linear elements (each element has 2 nodes), i.e. 6 effective nodes
in total.
Figure 3: The most simple 2D element: a triangle.
6
for the bar is k
2
. For such system, we can use the following coordinates
ˆ
θ = (T − T
env
) (10)
η =
x
L
(11)
µ
2
= L
2
2h
kR
(12)
and it can be proved that the governing differential equation of the system is:
d
2
ˆ
θ

2
− µ
2
ˆ
θ = 0 (13)
with the following boundary conditions
d
ˆ
θ

= 0 at η = 0 (14)
ˆ
θ =
ˆ
θ
tip
= (T
tip
− T
env
) at η = 1. (15)
Proof: the heat balance on a differential volume of length dx gives, (P = 2πR,A = πR
2
):
−kA
dT
dx
¸
¸
¸
¸
x
= h P dx (T − T
env
) − k A
dT
dx
¸
¸
¸
¸
x+dx
= h P dx (T − T
env
) − k A
dT
dx
¸
¸
¸
¸
x
− k A
d
2
T
dx
2
dx (16)
We will use a FEM method known as the Galerkin ﬁnite element method. As we will see, the
name comes from the request we do: we want the approximate solution to obey for each element
the Galerkin approach in order to minimize the value of the residual. For our very simple one
dimensional problem we choose the elements as a straight segments with two nodes located at
the two ends of each segment, see ﬁgure 1. Therefore, we will split the rod bar in N elements,
where two adjacent elements have always one node in common. Thus, for instance, in the case
N = 5 elements, we will have a total number of M = 6 effective nodes (see ﬁgure 2). Let’s
call l to the length of each one of the elements. What we have done until now is the ﬁrst step
in any FEM problem, the discretization of the continuum: we divide the solution region into
non-overlapping sub-regions that we call elements.
The second step in any FEM method is to choose which type of function will represent the
variation of the ﬁeld (in our case θ) along each element. This second stage is know as Selection
of the trial functions which will lead us to determine which are the shape functions for our case
2
The thermal conductivity k is the property of a material that indicates its ability to conduct heat. It arises in the
Fourier´s law (aka law of heat conduction): q = −k ∇T, where q is the heat ﬂux, i.e. the ﬂow of energy per unit
of area (units: W/m
2
). The units of k are W/(m K). Recall that the Integral form of the Fourier´s law is:
∂Q
∂t
= −k
I
S
∇T · dS. (9)
7
(recall eq. 6) . The Shape functions are also known as interpolation functions or basis functions.
Here, we will do the most basic assumption, i.e., for a segment with two nodes i and j which
have values for θ function that are θ
i
and θ
j
, respectively, the change from one value to the other
will be given by a linear function. Thus,
θ(x) = a
1
+ a
2
x (17)
where the constants a
1
and a
2
can be obtained via the two conditions
θ
i
= a
1
+ a
2
x
i
(18)
θ
j
= a
1
+ a
2
x
j
(19)
it is simple to show that one can rewrite equation 17 as
θ(x) = N
i
(x) θ
i
+ N
j
(x) θ
j
(20)
where
N
i
(x) =
x
j
− x
l
, (21)
N
j
(x) =
x − x
i
l
, (22)
are the so-called Shape functions for the 1D linear ﬁnite element. You should take into account
that this shape functions, are deﬁned to be strictly zero when we are out of the space assigned to
the element associated to them. One should remark that using a ﬁrst order polynomial like eq.
17 (lineal element) to account for the variation of the temperature θ inside an element is a quite
coarse and rough approach. Thus for instance, one can assume a second degree polynomial like,
θ(x) = a
1
+ a
2
x + a
3
x
2
(23)
but then, in order to calculate the three constants we need a third node to exist in the element
(usually placed at the mid-point of the segment). Such type of element is know as a quadratic
element. The quadratic element (or higher order elements), allow for a better description of what
happens inside the element, but of course, the FEM method becomes more complex. At this
moment we will keep things a simple as possible and we will assume we use a linear element
such that equations 17 and 20 hold.
The third stage in any FEM method is know as the Formulation or the obtaining of the
element characteristics. Basically in this step we determine the matrix equations that will
govern the behavior of one single element. To do that, of course, we need to know which
governing differential equation does the system (and therefore the element) obey, as well as
what are the boundary conditions. In our simple case, the differential equation to obey and the
conditions are given in eq. 13 and expressions 14 and 15. Before starting to derive the matrix
equations for our element, notice that if equation 20 holds for our linear element, then

dx
=
−1
l
θ
i
+
1
l
θ
j
. (24)
8
Because we assume θ within the element to be approached by a expression like eq. 20, we will
always have an error respect what would be the exact solution. What we want is to minimize as
far as possible the error when we compare the exact solution with the solution obtained via FEM.
A nice method to get an approximate solution of the differential equation such that minimizes
errors is known as the Galerkin method (and from there derives the name of the whole FEM
method we are using). The Galerkin method applied to our case says that if our differential
equation is eq. 13, our approximate solution θ will have the minimum possible error respect the
exact solution if it obeys a set of equations:
_
rod
N
k
_
d
2
θ

2
− µ
2
θ
_
dη = 0 (25)
where the number of equations is equal to the number of shape functions N
k
we have (in our
case, two per each element we use). Notice the shape functions N
k
act as weighting functions.
Given N
k
is valid only for the element at which the node k belongs (notice that intermediate
nodes will for one element act as the i-node, and for the neighbor node they will act as a j-
node), we can reduce the integration over the whole rod to the integration over the element
associated to the shape function N
k
we consider.
Let’s deﬁne η
e
≡ l/L. Because we have previously deﬁned η ≡ x/L (where L is the length
of the rod), the following equalities hold for a linear element:

= L

dx
=
−1
η
e
θ
i
+
1
η
e
θ
j
(26)
N
i
(η) = 1 − η/η
e
(27)
N
j
(η) = η/η
e
. (28)
Then, let’s compute eq. 25 for the ﬁrst element using the weighting functions N
i
(η) and N
j
(η)
which are associated to such element. After a little bit of algebra involving the integration by
parts, we get the following equations must be obeyed by the values of θ at nodes i and j of such
element (i.e, θ
i
and θ
j
):
0 =
1
η
e

i
− θ
j
) +

+
µ
2
η
e
6
(2θ
i
+ θ
j
) (29)
0 =
1
η
e
(−θ
i
+ θ
j
) −

+
µ
2
η
e
6

i
+ 2θ
j
). (30)
The ﬁrst equation corresponds to use N
i
as a weighting function and the second equation is
obtained when N
j
is used as a weighting function in eq 25 (applied to the ﬁrst element). Previous
equations can be rewritten together in a matrix-like notation as:
1
η
e
_
1 −1
−1 1
__
θ
i
θ
j
_
+
µ
2
η
e
6
_
2 1
1 2
__
θ
i
θ
j
_
+
_

_
=
_
0
0
_
(31)
which is the element characteristics of the ﬁrst element. Thus for instance, when µ
2
= 3 and
η
e
= 0.2 (i.e., the system is split in 5 elements) the element characteristics becomes:
_
5.2 −4.9
−4.9 5.2
__
θ
i
θ
j
_
+
_

_
=
_
0
0
_
(32)
9
It is possible to show that for the other elements we can get a similar element characteristics.
Now in a fourth stage, we must ensemble all the equations for all the elements. This is
very easily done in our 1D case as follows: if in a element characteristics matrix we have a row
that refers to the same θ
x
than a row in the characteristics matrix of another element, then we
just add the two rows together. At the end we must get a matrix expression with as many rows
as effective nodes we have. For instance, if we consider the ﬁrst two elements (i.e. 3 nodes in
total), the equations we get for the system will be:
_
_
5.2 −4.9 0
−4.9 10.4 −4.9
0 −4.9 5.2
_
_
_
_
_
θ
1
θ
2
θ
3
_
_
_
=
_
_
_
0
0

_
_
_
(33)
and if we consider the ﬁrsts three elements (4 nodes) the expression would be
_
_
_
_
5.2 −4.9 0 0
−4.9 10.4 −4.9 0
0 −4.9 10.4 −4.9
0 0 −4.9 5.2
_
_
_
_
_
¸
¸
_
¸
¸
_
θ
1
θ
2
θ
3
θ
4
_
¸
¸
_
¸
¸
_
=
_
¸
¸
_
¸
¸
_
0
0
0

_
¸
¸
_
¸
¸
_
(34)
and so on so forth. Notice that for the row that corresponds to θ
1
the dθ/dη is set to zero due to
the boundary condition that we have for η = 0 (see eq.14).
Because the other boundary condition we have is that the last node should have θ = θ
tip
, we
can impose this directly in the system of equations to solve. Thus for instance, if we consider
the 5 elements (6 effective nodes):
_
_
_
_
_
_
_
_
5.2 −4.9 0 0 0 0
−4.9 10.4 −4.9 0 0 0
0 −4.9 10.4 −4.9 0 0
0 0 −4.9 10.4 −4.9 0
0 0 0 −4.9 10.4 −4.9
0 0 0 0 0 1
_
_
_
_
_
_
_
_
_
¸
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
¸
_
θ
1
θ
2
θ
3
θ
4
θ
5
θ
6
_
¸
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
¸
_
=
_
¸
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
¸
_
0
0
0
0
0
θ
tip
_
¸
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
¸
_
. (35)
This last expression is the system of equations we have to solve to get the solution via the
Galerkin FEM. The result can be generalized to whatever number of elements we want to have
(but mind to change η
e
). The solution of the system of algebraic equations is the ﬁfth and ﬁnal
stage of the FEM (of course, later, once we know the θ values at each node, we can compute sec-
ondary quantities like for instance heat ﬂuxes, etc.). The resolution of the system of equations,
as in the case of the FDM method is done via one of the several techniques available. Notice
that the matrix is sparse, in fact, band diagonal. The larger is the number of nodes we use, the
more sparser becomes the matrix.
6 FEM in 2-D: the Poisson equation.
Let’s now for a more complex case, a two dimensional problem. In this case, we want to solve
the Poisson equation, namely,

2
ˆ
V
∂x
2
+

2
ˆ
V
∂y
2
= −ρ(x, y). (36)
10
In terms of the shape functions (still to be determined for this case) the trial solution V (x, y)
can be written as:
V (x, y) =

e
V
e
(x, y) =

e

i
v
i,e
N
i,e
(x, y) (37)
where e is the index to denote the different elements, and i is the index to denote the different
nodes inside the element e. V
e
(x, y) represents the trial solution associated to the element e.
N
(i,e)
(x, y) is the shape function associated to the node i of the element e. The v
(i,e)
is the value
of V (the potential) at the node i of the element e, .i.e., the stuff we want to know at the end of
the day.
Let’s take the most simple type of 2D element, i.e., a triangle element with 3 nodes located at
the vertices of the triangular elements (see ﬁgure 3).
Let’s take again linear shape functions, i.e., let’s assume
N
i,e
(x, y) = a
i,e
+ b
i,e
x + c
i,e
y (38)
where i = 1, 2, 3 (we have 3 nodes). As in the 1D problem, we want each shape function to be 1
at the position of one of the nodes and zero on the position of the other nodes of the element. One
can show that this can be obtained deﬁning the Shape functions as the following determinants:
N
1,e
(x, y) =
1
D
e
¸
¸
¸
¸
¸
¸
1 x y
1 x
2
y
2
1 x
3
y
3
¸
¸
¸
¸
¸
¸
, (39)
N
2,e
(x, y) =
1
D
e
¸
¸
¸
¸
¸
¸
1 x
1
y
1
1 x y
1 x
3
y
3
¸
¸
¸
¸
¸
¸
, (40)
N
3,e
(x, y) =
1
D
e
¸
¸
¸
¸
¸
¸
1 x
1
y
1
1 x
2
y
2
1 x y
¸
¸
¸
¸
¸
¸
, (41)
(42)
where
D
e
=
¸
¸
¸
¸
¸
¸
1 x
1
y
1
1 x
2
y
2
1 x
3
y
3
¸
¸
¸
¸
¸
¸
. (43)
and [(x
1
, y
1
), (x
2
, y
2
), (x
3
, y
3
)] are the coordinates of the nodes (located at the vertices of the
triangular element we use). In 3D the determinants will be 4 × 4 instead of 3 × 3 (we add a z
column). Notice that you obtain the 1D linear elements also using the previous systematic way.
Notice that by deﬁnition, the shape functions N
i,e
are zero out of the element e. Notice also that
using the determinants notation, is very easy to check that they will be one at the node we want
and zero at the other nodes.
Thus, once we know the position of the vertices of our triangular elements, using eqs. 39, 40
and 41 we can easily compute the coefﬁcients a
i,e
, b
i,e
, c
i,e
that appear in equation 38. In this
way, given the positions of the vertices of our elements, we know the shape functions.
11
A thing to take into account always is that if our PDE to solve is of order m then the Shape
functions we choose must be at least m−1 times derivable (i.e. different fromzero), because
as we will see later, we need up to the m − 1 derivative of our shape functions to build-up the
algebraic equations. If they were zero, then we would get an undetermined system of equations.
Now it comes the step of the formulation. In our 2D particular case, the residual is
R(x, y; [v]) =

2
V
dx
2
+

2
V
dy
2
+ ρ(x, y). (44)
where V is given by equation 37, and [v] is the set of all the unknowns v
i,e
to be determined
(the values of the potential in all the nodes we have). As in the 1D case, we choose the Galerkin
method to minimize the value of the residual, i.e., we have to solve the set of equations:
_
domain
N
i,e
(x, y) R(x, y; [v]) dx dy = 0. (45)
where we have an equation for each shape function N
i,e
(x, y) associated to an effective node.
These equations can be rewritten as:
_
e element
N
i,e
(x, y)
_

2
V
dx
2
+

2
V
dy
2
_
dx dy +
_
e element
N
i,e
(x, y) ρ(x, y) dx dy = 0. (46)
Let’s go for the ﬁrst integral,
_
e element
N
i,e
(x, y)

2
V
dx
2
dx dy (47)
it can be done by integrating by parts and we reduce the order of the partial derivatives from two
to one because

∂x
_
N
i,e
(x, y)
∂V
∂x
_
=
∂N
i,e
(x, y)
∂x
∂V
∂x
+ N
i,e
(x, y)

2
V
dx
2
(48)
allows us to rewrite the integral with N
i,e
(x, y)

2
V
dx
2
as
_
e element

∂x
_
N
i,e
(x, y)
∂V
∂x
_
dx dy −
_
e element
∂N
i,e
(x, y)
∂x
∂V
∂x
dx dy. (49)
Now, using the divergence theorem in the plane
3
, I can rewrite the ﬁrst integral over the e-
element as an integral over a closed path along the boundary of the element:
_
e element

∂x
_
N
i,e
(x, y)
∂V
∂x
_
dx dy =
_
boundary of e
N
i,e
(x, y)
∂V
∂x
ˆ n
x
dx dy (51)
3
See for instance the book Marsden-Tromba, Vector calculus . 3rd Edition, chap 8.1, ca. page 499.
Z
∂Surface
F · n dl =
Z
Surface
∇· F dA (50)
12
where ˆ n
x
is the x component of the vector normal to the boundary of the element at each point.
[FALTA i en els llocs on tenim el vertex com es deﬁneix la normal ????]. A similar thing can be
done for the y part of the integral and instead of ˆ n
x
we will get a ˆ n
y
.
Despite this dependence with ˆ n
x
and ˆ n
y
looks at ﬁrst sight like it will complicate our life, in
fact it simpliﬁes it a lot because those terms will cancel out among contiguous elements. The
only kind of integrals of the style of eq. 51 that survive are those of those elements located at
the boundary of the system (and therefore without a counter part), see ﬁgure 4.
Figure 4: Suppose the following disposition of the triangular elements. The normals cancel out
except at the boundaries , and so will do the contributions to the line integrals of the
style of eq. 51.
For elements which are not in the boundary of the system (i.e., they are completely sur-
rounded by other elements) it is easy to show that the Galerkin condition applied to our element
e leads to three (i = 1, 2, 3) algebraic equations,
D
e
2

j
v
j,e
(b
i,e
b
j,e
+ c
i,e
c
j,e
) −
_
e element
N
i,e
(x, y) ρ(x, y) dx dy = 0 (52)
where j = 1, 2, 3 represents also an index over the three different nodes we have in the element
e, and
D
e
2
is the area of the triangular element "e". If we write it in a matrix way:
[K]
e
[v]
e
= [f ]
e
, (53)
K
ij
=
D
e
2
(b
i,e
b
j,e
+ c
i,e
c
j,e
) , (54)
f
i
=
_
e element
N
i,e
(x, y) ρ(x, y) dx dy. (55)
(56)
The different coefﬁcients b
i,e
, b
j,e
and c
i,e
, c
j,e
are known quantities once we have deﬁned the
position of our nodes ( use eqs. 39, 40 and 41 ).
13
Figure 5: First step in the discretization of the 2D rectangular domain. We do a rectangular grid,
and we assign a number n to the effective nodes as depicted in the plot.
Figure 6: Second step in the discretization of the 2D rectangular domain. We create the triangle
elements and we label them as depicted in the plot.
14
For elements in the boundary one has to add the terms of the style of eq. 51.
Now we know the equations for our elements (three for element), we have to add the equa-
tions of all elements all together taking into account that contiguous elements have nodes in
common.
The most clean way of doing this is as follows: To give a particular example, let’s suppose
for simplicity we have to solve our Poisson equation onto a square domain. The boundary nodes
those located in the perimeter of our square.
To obtain the global matrix [K] and the global vector [f], we do as follows:
• Discretize the square domain into a rectangular grid of n = N
x
× N
y
points (that will be
our n effective nodes). See ﬁgure 5 .
• Now split the rectangular grid into triangular elements as shown in ﬁgure 6.
• The vertices in each triangle we will label them as 1, 2, 3 in a clock-wise way, starting in
the bottom left for odd elements, and up left for even elements.
• Notice the disposition of the odd and even labeled triangles. The mapping from the ver-
tices of the triangle elements to the effective nodes involved is explained in tables 1 and
2.
• Now that we know the coordinates of the vertices for each element, we can compute the
three shape functions N
i,e
for each element e. Make use of the determinant formulas we
have seen before.
• Initialize the global matrix [K] and the global vector [f] with zeros.
• Now act as the following pseudocode says to build up the global matrix [K] and the global
vector [f]:
For element=1 till element= the last element {
for i=1 till i=3 {
n = map_to_effective_node_the_vertice(i)
Calc f_i of the vector [f]_e see eq.53, store it as f
for j=1 till j=3 {
m = map_to_effective_node_the_vertice(j)
Calc K_ij of the matrix [K]_e see eq.52, store it as K
/
*
K_nm is the (n,m) element of the global matrix [K]
*
/
/
*
f_n is the (n) element of the global vector [f]
*
/
if(n and m are not in the boundary) {
K_nm += K
f_n += f
} else {
if( n is in the boundary) {
set K_nn = 1
f_n = v_n ; /
*
if n is in the boundary, we know v_n
*
/
15
} else if (m is in the boundary) {
f_n = f_n - K
*
v_m ; /
*
if m is in the boundary, we know v_m
*
/
}
}
}
}
}
• Now that you have the global matrix [K] and the global vector [f], just what remains to be
done is to solve the system:
[K][v] = [f ], (57)
in order to obtain the value of the potential V at position of the effective nodes [v].
Notice that in the pseudocode we use for the boundary nodes
if( n is in the boundary) {
set K_nn = 1
f_n = value for such point in the boundary
} else if (m in the boundary) {
g_n = g_n - K
*
v_m
}
The ﬁrst body of the if is to make sure that the values at the boundary nodes are ﬁxed and
are not changed. The second body (the "else if") is to incorporate the contributions from the
line integrals of the nodes located at the boundary. The terms containing non zero line integral
contributions can be easily added to the [f ] vector (mind the minus sign due to the change of
those terms from the left to the right hand side of the equations]. Thus, given a node n that has
neighboring nodes m which are in the boundary, we have
f
n
= f
n
(arising from non bn) −
bn

m
K
n,m
v
m
(58)
where bn stands for "boundary nodes near node n". Notice that because m is a node on the
boundary, we now the value of v
m
, and K
n,m
will contain also the result of the integral lines
which can be easily evaluated.
16
Table 1: Odd labeled triangular elements. Let’s suppose the triangle is in the rectangle of the
α-th column and β-th row (α = 1 and β = 1 is the rectangle at the bottom-left).
vertex num. It has Corresponds to
i coordinates the effective node
1 (x
α−1
, y
β−1
) n
1
≡ (β − 1)N
x
+ α
2 (x
α−1
, y
β
) n
2
≡ n
1
+ N
x
3 (x
α
, y
β−1
) n
3
≡ n
1
+ 1
Table 2: Even labeled triangular elements. Let’s suppose the triangle is in the rectangle of the
α-th column and β-th row (α = 1 and β = 1 is the rectangle at the bottom-left).
vertex num It has Corresponds to
i coordinates the effective node
1 (x
α−1
, y
β
) n
2
2 (x
α
, y
β
) n
2
+ 1
3 (x
α
, y
β−1
) n
3
7 Sparse Matrixes (band matrixes) and FEM.
• A sparse matrix is a matrix with many elements that are zero.
• As we have seen in the 1D case, and is easy to see in 2D and 3D. FEM method leads
to huge sparse matrix. This is because our node has direct connection only with its ﬁrst
neighbor nodes.
• The more the number of nodes, the larger the matrix to solve is. In 3D, this trouble is even
more pronounced and the matrix is even more sparse.
• Storing zeros is a waste of memory. There are ways of storing matrices which have many
zeros with a minimumamount of storage (See for instance Numerical Recipes, ca. Chapter
2.4). (Note: ca = circa (Latin) = around, near).
• If you solve the system
[K][v] = [f ]. (59)
with methods like Gauss-Jordan. In the intermediate stage you will have huge matrices
with non zeros. That’s not nice, because you need to make many operations to solve the
system, and you need huge amounts of memory.
17
• In fact, FEM leads usually to Band Diagonal Matrixes, i.e., the non-zero elements localize
a few elements before, and after the diagonal. There are very efﬁcient techniques to solve
such band diagonal matrixes using minimum storage and minimum number of operations
(fast calculation). (See for instance Numerical Recipes, ca. Chapter 2.4).
8 Other tricks for FEM and beyond.
• Howto avoid the systematic addition of truncation errors by choosing the grid of nodes in a
clever way. In this way, more accuracy without need of increasing the number of effective
nodes in the system. This can be done by alternating the direction of the diagonal cuts.
See plots in ﬁgure 7.
• A proper node labeling scheme can help to have a more narrow bandwidth in the matrixes.
Which is important in order to have a faster solution of the matrix. The troubles with
optimizing the labeling of the nodes is complex when we have complex geometries. There
are programs and algorithms for doing such in an efﬁcient way an reduce as maximum as
possible the bandwidth of the matrixes.
• Notice that if you need to reﬁne adding more elements in a certain zone because is the
zone where you need more accuracy with FEM programs is very easy. An the the changes
to do to the code of the program are minimum.
• The preparation of the FEM, selection of elements, mapping, etc. is very tedious. Nowa-
days there are excellent programs and algorithms intended to generate the meshes even
for complex geometries.
• The use of higher orders than linear elements, is usually nice because with few high order
terms you can save usually quite a lot of elements. The use of higher order elements is
specially rewarding when the gradient of the ﬁeld variable (θ in the 1D case, v in the 2D
case) is expected to vary very rapidly. The use of the Pascal triangle can help to determine
which should be the terms to include in higher orders in the 2D case.
• Notice that we have just worked out the FEM for bounded problems. For problems where
no boundaries exist (e.g. scattering, radiation problems), there are special methods in-
tended to solve such situations: use of inﬁnite element methods, boundary element meth-
ods, or the adsorbing boundary condition.
• Notice also that we have not dealt with time dependent problems, but static ones. There are
also FEM methods intended to solve problems to deal with time-dependent phenomena.
• The FEM method we have reviewed applies t ﬁnite linear equations. If you have a non
linear PDE, you will have ﬁrst to linearize it.
18
Figure 7: (a) All cuts in the same direction. (b) Alternance of the diagonal cuts to make easier
9 Bibliography
Suitable books to become more learned about FDM and FEM methods are:
• Fundamentals of the Finite Element Method for Heat and Fluid Flow, R.W. Lewis, P.
Nithiarasu and K. N. Seetharamu. Wiley Ltd. (2004). ISBN: 0-470-84788-3.
• Computational methods in physics and Engineering, 2nd edition, Samuel S.M. Wong.
World Scientiﬁc, (1997). ISBN:9810230176.
• Numerical Techniques in Electromagnetics, Matthew N. O. Sadiku. CRC Press (2001).
ISBN: 0-8493-1395-3.
• Numerical Recipes in C: The art of Scientiﬁc Computing. Cambridge Univ. Press. (1992).
ISBN: 0-521-43108-5.
There are also some nice web pages devoted to the ﬁnite element methods:
• The Internet ﬁnite element resources page: http://homepage.usask.ca /
˜
ijm451/ﬁnite/ fe_resources/
fe_resources.html
19

With FEM you can handle better boundary problems with odd geometries. Bibliography. A word of caution: FEM as FDM are suitable for linear PDE’s. The difference between the exact value and the approximate value is called the residual.1 In this lecture we will talk about 1. 6. If you have non-linear PDEs. I have a PDE with certain bc (boundary conditions) to be solved. where a1 and a2 must be ˆ determined to get the φ as close to the exact solution φ as I can. 2. You will have ﬁrst to linearize it. 5. FEM in 2-D: the Poisson equation. In that example the residual is R(x. a1 . 2 FDM vs FEM 1. For instance. which options do I have: 1. Sparse Matrixes (band matrixes) and FEM. 3. This is not so easy to do with FDM. but not always available. There is always an error. FEM in 1-D: heat equation for a cylindrical rod. 2. Other tricks for FEM and beyond. 3 Perspective: different ways of solving approximately a PDE. 8. Approximate solutions. we will denote it by R. 7. 2. Perspective: different ways of solving approximately a PDE. With FEM it is easier to make more ﬁner subdivisions of the space in regions where you need more accuracy. FDM vs FEM. 4. Analytical solution: the best. let’s suppose I have to solve the following ODE: ˆ dφ ˆ + φ(x) = 0 dx (1) if my approximate solution is φ(x) = 1 + a1 x + a2 x2 . a2 ) ≡ dφ + φ(x) = 1 + (1 + x) a1 + (2x + x2 ) a2 dx (2) 2 . Basic steps of any FEM intended to solve PDEs.

Domain (5) 4.i. . a1 . Variational method (Rayleight-Ritz method): from the PDE we get its variational inteˆ gral.e. an ) Ni (x) dx = 0. The function φ that minimizes that variational integral is the solution to the problem.There are several ways of solving approximately a PDE. 3 . FDM: Finite Difference Methods.. a1 . .. 6. a2 )dx = 0 Domain (3) 2... b) Sub-domain method: we split the domain in n regions and we ask the averaged R. which is equivalent to say ωi (x) = δ(x − xi ). to be zero inside each region. We set ωi (x) = Ni (x). 5. this means that Ni (x) = x and N2 (x) = x2 are a set of basis vectors for all our possible solutions. FEM: Finite Element Methods. MOM:method of moments. an ) ωi (x) dx = 0 Domain (4) where ωi (x) with i = 1. You convert your differential equation into an integral equation. Some usual choices of ωi (x) are a) Collocation method: we ask the residual R to be zero at n points {xi }i=n inside the i=1 domain. Ritz method (aka Goodman’s method): we get a1 and a2 via asking R(x. Used specially in electromagnetics.. A reﬁned FDM popular in Computational ﬂuid dynamics. we have to solve n equations (in our example n = 2) like R(x.n are n arbitrary functions called weighting functions. a1 . ∂R c) Least-Squares method: we set ωi (x) = ∂ai d) Galerkin method: if we use approximate solutions of the type φ(x) = 1 + a1 x + a2 x2 . the most usual are: 1. an if we have n in a general case) to be determined by asking the residual to obey a set of equations: R(x.. [FALTA] 3. . . 7.. a2 (. Weighted residual methods: in this methods we assume the parameters a1 . < R >. FVM: Finite Volume Methods...

φ2 ..4 Basic steps of any FEM intended to solve PDEs. φ2 . like a cylindrical rod with radial symmetry. . that we select the basis set of functions that will describe our solution. and that has to be taken into account. The "problem" is that usually contiguous elements have nodes in common (see for instance ﬁgure 2. Assembling the equations for different elements: one has to assemble the equations for all elements.. Select the type of trial function to use. .1) and discretize it is as shown in ﬁgure 2. For instance... The one/ones you will use depends on the problem you want to solve. NN (x)] where the {Ni (x)}i=N are known as the Shape Functions. φ2 .. the most simple can be using triangular elements (see ﬁgure 3).. If we have n unknown coefﬁcients a0 . Is it easy to show that the value of our trial function φ for a given position x inside an element can be written as a function of the values of φ at the N nodes the of element ([φ1 .. 4 . At the end. i=1 3. N2 (x). From segments of lines. The formulation: Given the PDE you want to solve. now you must ﬁnd a system of algebraic equations for each element "e" such that by solving it you got the values of of φ at the position of nodes of the element "e" ([φ1 .... In all FEM variants there are always the same sequence of steps to be taken 1. and in turn the shape functions: We select what kind of functions we will take to describe the variation of the function φ inside each element (the trial function). we will see it later.. This is equivalent to say..e. i. (7) (6) This is one of the more tricky parts of the FEM. φN ] ≡ [φ]e ). 4. an−1 we will need the element to have n nodes to be able to determine them. For a 2D problem. . φN ]) . 2. [K]e · [φ]e = [f ]e . if we have a total of M effective nodes1 in the system. then we must build up a global matrix [K] of size M × M and a 1 For instance in ﬁgure 1 we have a total of 5 elements that have each one two nodes.e.. a1 .. . nonetheless due to the nodes in common. One of the usual choices is to take a polynomial like for instance φ(x) = a0 + a1 x (known as linear element) or φ(x) = a0 + a1 x + a2 x2 (known as quadratic element). the number of effective nodes we have (the number of unknowns) is just M = 6 and not 10.. you must ﬁnd for each element "e" the matrix [K]e and the vector [f ]e such that. i. squares. There are different ways of getting the matrix [K]e . the most simple is to take the elements as linear segments with two nodes per segment (see Fig. to curved elements. triangles. The elements contain inside a certain number of points we call nodes. Discretize the continuum: divide the solution into smaller regions that we call elements. φN ] · [N1 (x). φ(x) = [φ] · [N] = [φ1 . for a 1D problem. There are lots of shapes the elements can have. . etc.. and therefore two algebraic equations may refer to the same node.

and the insulated tip is located at x = 0.global vector [f ] of size M such that the FEM problems "reduces" to solve the following matrix equation: [K] · [φ] = [f ]. 6. We assume the cylinder lies along the x-axis. The lost of heat occurs via the lateral surface of the cylinder at a rate characterized by the heat transfer coefﬁcient h which units are W/(m2 K).. just make use of equation 6. φ2 .. In this section we plan to build up a very simple and basic one-dimensional FEM method. As we will see. we will see it later. while the surrounding environment has a temperature Tenv (see ﬁgure 2). the better is the quality of the solution. the matrices we will build up can be very large. but the more the number of nodes the use. Compute secondary quantities: Once you know the φ values. we assume that the thermal conductivity 5 . . so you can save a lot of time and memory if you use special methods for sparse matrixes. (8) where [φ] ≡ [φ1 . you can compute other magnitudes using the values of φ. 5. Let’s see now two examples about how this works in practice Figure 1: A single one dimensional element 5 FEM in 1-D: heat equation for a cylindrical rod. φ2 . φM ] is the value of the approximate solution φ at the position where the effective nodes are. M becomes very large. sparse matrix. i.. Let’s consider a cylindrical rod of radius R and length L with one end insulated an the other held to constant temperature Ttip . Notice that once we now [φ1 .e. φM ] one is able to calculate the value of φ at whatever point x of the system... Solve the system of equations: In principle you can use whatever method you want. .. most of elements of matrix [K] are zero.

i.Figure 2: The 1D system we want to study using Galerkin FEM. 6 effective nodes in total.e. Figure 3: The most simple 2D element: a triangle. 6 . The plot corresponds to using 5 one-dimensional linear elements (each element has 2 nodes).

we will split the rod bar in N elements. Recall that the Integral form of the Fourier´s law is: I ∂Q = −k ∇T · dS. (P = 2πR. What we have done until now is the ﬁrst step in any FEM problem. where q is the heat ﬂux. the name comes from the request we do: we want the approximate solution to obey for each element the Galerkin approach in order to minimize the value of the residual.A = πR2 ): −kA dT dx = h P dx (T − Tenv ) − k A x dT dx dT dx x+dx = h P dx (T − Tenv ) − k A −kA x d2 T dx dx2 (16) We will use a FEM method known as the Galerkin ﬁnite element method. (9) ∂t S 7 . Let’s call l to the length of each one of the elements. i. we can use the following coordinates ˆ θ = (T − Tenv ) x η = L 2h µ2 = L2 kR and it can be proved that the governing differential equation of the system is: ˆ d2 θ ˆ − µ2 θ = 0 dη 2 with the following boundary conditions ˆ dθ = 0 at η = 0 dη ˆ ˆ θ = θtip = (Ttip − Tenv ) (14) at η = 1. For our very simple one dimensional problem we choose the elements as a straight segments with two nodes located at the two ends of each segment. in the case N = 5 elements. for instance. For such system. see ﬁgure 1. Therefore. where two adjacent elements have always one node in common. This second stage is know as Selection of the trial functions which will lead us to determine which are the shape functions for our case 2 The thermal conductivity k is the property of a material that indicates its ability to conduct heat. the ﬂow of energy per unit of area (units: W/m2 ). Thus. It arises in the Fourier´s law (aka law of heat conduction): q = −k ∇T . As we will see. we will have a total number of M = 6 effective nodes (see ﬁgure 2).e.for the bar is k 2 . The second step in any F EM method is to choose which type of function will represent the variation of the ﬁeld (in our case θ) along each element. (15) (13) (10) (11) (12) Proof: the heat balance on a differential volume of length dx gives. the discretization of the continuum: we divide the solution region into non-overlapping sub-regions that we call elements. The units of k are W/(m K).

we need to know which governing differential equation does the system (and therefore the element) obey. Such type of element is know as a quadratic element. of course.e. The third stage in any F EM method is know as the Formulation or the obtaining of the element characteristics. At this moment we will keep things a simple as possible and we will assume we use a linear element such that equations 17 and 20 hold. 13 and expressions 14 and 15. in order to calculate the three constants we need a third node to exist in the element (usually placed at the mid-point of the segment). i. θ(x) = a1 + a2 x + a3 x2 (23) but then. θ(x) = a1 + a2 x where the constants a1 and a2 can be obtained via the two conditions θi = a1 + a2 xi θj = a1 + a2 xj (18) (19) (17) it is simple to show that one can rewrite equation 17 as θ(x) = Ni (x) θi + Nj (x) θj where Ni (x) = Nj (x) = xj − x . the differential equation to obey and the conditions are given in eq. One should remark that using a ﬁrst order polynomial like eq. Here. as well as what are the boundary conditions. The Shape functions are also known as interpolation functions or basis functions. allow for a better description of what happens inside the element. respectively.(recall eq. we will do the most basic assumption. 6) .. for a segment with two nodes i and j which have values for θ function that are θi and θj . Thus for instance. l x − xi . To do that. The quadratic element (or higher order elements). l (21) (22) (20) are the so-called Shape functions for the 1D linear ﬁnite element. Thus. the change from one value to the other will be given by a linear function. You should take into account that this shape functions. but of course. In our simple case. notice that if equation 20 holds for our linear element. Basically in this step we determine the matrix equations that will govern the behavior of one single element. one can assume a second degree polynomial like. dx l l (24) 8 . Before starting to derive the matrix equations for our element. then dθ −1 1 = θi + θj . 17 (lineal element) to account for the variation of the temperature θ inside an element is a quite coarse and rough approach. are deﬁned to be strictly zero when we are out of the space assigned to the element associated to them. the F EM method becomes more complex.

the following equalities hold for a linear element: dθ dθ −1 1 = L = θi + θj dη dx ηe ηe Ni (η) = 1 − η/ηe Nj (η) = η/ηe . and for the neighbor node they will act as a jnode). (26) (27) (28) Then. we get the following equations must be obeyed by the values of θ at nodes i and j of such element (i.2 (i. Thus for instance. two per each element we use). A nice method to get an approximate solution of the differential equation such that minimizes errors is known as the Galerkin method (and from there derives the name of the whole FEM method we are using). Previous equations can be rewritten together in a matrix-like notation as: 0 = 1 ηe 1 −1 −1 1 θi θj + µ2 ηe 6 2 1 1 2 θi θj + dθ dη dθ − dη = 0 0 (31) which is the element characteristics of the ﬁrst element. θi and θj ): 1 dθ µ2 ηe (θi − θj ) + + (2θi + θj ) (29) ηe dη 6 dθ µ2 ηe 1 (−θi + θj ) − + (θi + 2θj ). Because we have previously deﬁned η ≡ x/L (where L is the length of the rod). After a little bit of algebra involving the integration by parts. when µ2 = 3 and ηe = 0.e.e.2 −4. our approximate solution θ will have the minimum possible error respect the exact solution if it obeys a set of equations: Nk rod d2 θ − µ2 θ dη = 0 dη 2 (25) where the number of equations is equal to the number of shape functions Nk we have (in our case. Notice the shape functions Nk act as weighting functions.9 −4. let’s compute eq. What we want is to minimize as far as possible the error when we compare the exact solution with the solution obtained via FEM. 13. Let’s deﬁne ηe ≡ l/L. Given Nk is valid only for the element at which the node k belongs (notice that intermediate nodes will for one element act as the i-node. the system is split in 5 elements) the element characteristics becomes: 5. (30) 0 = ηe dη 6 The ﬁrst equation corresponds to use Ni as a weighting function and the second equation is obtained when Nj is used as a weighting function in eq 25 (applied to the ﬁrst element).9 5.Because we assume θ within the element to be approached by a expression like eq.. 20. The Galerkin method applied to our case says that if our differential equation is eq. we can reduce the integration over the whole rod to the integration over the element associated to the shape function Nk we consider. we will always have an error respect what would be the exact solution.2 θi θj + dθ dη dθ − dη = 0 0 (32) 9 . 25 for the ﬁrst element using the weighting functions Ni (η) and Nj (η) which are associated to such element.

Notice that the matrix is sparse.9 10. band diagonal.4 −4. ˆ ˆ ∂2V ∂2V + = −ρ(x.2 −4.9 0   θ4   0            0     0 0 −4. later. we want to solve the Poisson equation.9 0 0   = .4 −4.). if we consider the ﬁrst two elements (i. if we consider the 5 elements (6 effective nodes):      5.9 10.9 10. 3 nodes in total).9   θ5   0          θ6 θtip 0 0 0 0 0 1 This last expression is the system of equations we have to solve to get the solution via the Galerkin FEM. Thus for instance.9  0 θ2 = (33)   dθ   θ3 0 −4. Because the other boundary condition we have is that the last node should have θ = θtip .2 dη and if we consider the ﬁrsts three elements (4 nodes) the expression would be      5.4 −4. namely. For instance. In this case. Now in a fourth stage.9 10.9 10.4 −4. The larger is the number of nodes we use. etc.4 −4. then we just add the two rows together. (35)  0 0 −4. y).2 dη (34) and so on so forth.14).2 −4.9 10.4 −4. Notice that for the row that corresponds to θ1 the dθ/dη is set to zero due to the boundary condition that we have for η = 0 (see eq. as in the case of the FDM method is done via one of the several techniques available. 6 FEM in 2-D: the Poisson equation. in fact. we can impose this directly in the system of equations to solve. the more sparser becomes the matrix.4 −4. Let’s now for a more complex case.It is possible to show that for the other elements we can get a similar element characteristics.9 0 0  θ1   0       0     −4. The resolution of the system of equations.9 5. The result can be generalized to whatever number of elements we want to have (but mind to change ηe ).9 0  θ1   0   −4. we must ensemble all the equations for all the elements. This is very easily done in our 1D case as follows: if in a element characteristics matrix we have a row that refers to the same θx than a row in the characteristics matrix of another element. the equations we get for the system will be:      5. we can compute secondary quantities like for instance heat ﬂuxes. once we know the θ values at each node. The solution of the system of algebraic equations is the ﬁfth and ﬁnal stage of the FEM (of course.9   θ3   0    dθ       θ4 0 0 −4. At the end we must get a matrix expression with as many rows as effective nodes we have.2 −4.9 5.9 0  θ2   =  0 −4.9 10.9 0 0 0   θ2   0             θ3   0   0 −4. a two dimensional problem.9 0 0 0 0  θ1   0           −4. ∂x2 ∂y 2 (36) 10 .e.

the stuff we want to know at the end of the day.e . 3 (we have 3 nodes). One can show that this can be obtained deﬁning the Shape functions as the following determinants: N1.In terms of the shape functions (still to be determined for this case) the trial solution V (x. y) (37) e e i where e is the index to denote the different elements. y2 ). In this way. . is very easy to check that they will be one at the node we want and zero at the other nodes.e. Let’s take again linear shape functions. y) = . bi. i. and i is the index to denote the different nodes inside the element e. 2.e (x. N(i.e (x. i. 40 and 41 we can easily compute the coefﬁcients ai. Notice that by deﬁnition.e . we know the shape functions. The v(i. Notice also that using the determinants notation. y) represents the trial solution associated to the element e.. using eqs. y) = 1 De 1 De 1 De 1 x y 1 x2 y2 1 x3 y3 1 x1 y1 1 x y 1 x3 y3 1 x1 y1 1 x2 y2 1 x y . y) = . y) = ai. the shape functions Ni.e y (38) where i = 1.e (x.e that appear in equation 38. 39. (x3 . y) is the shape function associated to the node i of the element e. y) = vi. (43) and [(x1 . (x2 .. Notice that you obtain the 1D linear elements also using the previous systematic way. Let’s take the most simple type of 2D element. Thus. ci.e (x. let’s assume Ni. (40) N3.e) (x. As in the 1D problem.e + bi. we want each shape function to be 1 at the position of one of the nodes and zero on the position of the other nodes of the element. y3 )] are the coordinates of the nodes (located at the vertices of the triangular element we use).e.e x + ci. once we know the position of the vertices of our triangular elements.e Ni.i. y1 ). Ve (x.e are zero out of the element e. In 3D the determinants will be 4 × 4 instead of 3 × 3 (we add a z column).e. given the positions of the vertices of our elements. y) = Ve (x.e) is the value of V (the potential) at the node i of the element e.. 11 . (39) N2. (41) (42) where De = 1 x1 y1 1 x2 y2 1 x3 y3 .e (x. a triangle element with 3 nodes located at the vertices of the triangular elements (see ﬁgure 3). y) can be written as: V (x.

the residual is R(x. y). because as we will see later. y. we need up to the m − 1 derivative of our shape functions to build-up the algebraic equations. [v]) dx dy = 0. then we would get an undetermined system of equations. y) e element ∂2V ∂2V + dx2 dy 2 dx dy + e element Ni.1. y) ρ(x. y) dx dy = 0..e (x. y) ∂V dx dy.e (x. y) 2 ∂x ∂x dx 2 (48) allows us to rewrite the integral with Ni. y) ∂V ∂2V + Ni. y) ∂V ∂x dx dy = boundary of e Ni. we have to solve the set of equations: Ni. domain (45) where we have an equation for each shape function Ni. y) ∂V nx dx dy ˆ ∂x (51) See for instance the book Marsden-Tromba.e (x. ca. page 499. dx2 dy 2 (44) where V is given by equation 37. These equations can be rewritten as: Ni. Z Z F · n dl = ∇ · F dA ∂Surf ace Surf ace (50) 12 . using the divergence theorem in the plane3 . Now it comes the step of the formulation. (46) Let’s go for the ﬁrst integral. and [v] is the set of all the unknowns vi.e (x. chap 8. ∂x ∂x (49) Now.e (x.e (x. Vector calculus . y) e element ∂2V dx dy dx2 (47) it can be done by integrating by parts and we reduce the order of the partial derivatives from two to one because ∂ ∂x Ni. i. y) ∂ V as dx2 ∂ ∂x e element Ni. In our 2D particular case. y) associated to an effective node. 3rd Edition.e. If they were zero. [v]) = ∂2V ∂2V + + ρ(x.e (x. As in the 1D case.e (x. y. we choose the Galerkin method to minimize the value of the residual. I can rewrite the ﬁrst integral over the eelement as an integral over a closed path along the boundary of the element: ∂ ∂x e element 3 Ni. y) ∂V ∂x = ∂Ni.e (x.e (x.e (x. Ni. y) ∂V ∂x dx dy − e element ∂Ni.e to be determined (the values of the potential in all the nodes we have).A thing to take into account always is that if our PDE to solve is of order m then the Shape functions we choose must be at least m−1 times derivable (i.e (x. y) R(x.e. different from zero).e (x.

De 2 vj. If we write it in a matrix way: 2 [K]e [v]e = [f ]e .e are known quantities once we have deﬁned the position of our nodes ( use eqs.e + ci.e.e (x. Kij = 2 fi = e element (53) (54) (55) (56) Ni. Figure 4: Suppose the following disposition of the triangular elements.e .e bj. 13 .. ˆ ˆ Despite this dependence with nx and ny looks at ﬁrst sight like it will complicate our life. bj. 51.where nx is the x component of the vector normal to the boundary of the element at each point.e and ci. they are completely surrounded by other elements) it is easy to show that the Galerkin condition applied to our element e leads to three (i = 1. 39. ˆ [FALTA i en els llocs on tenim el vertex com es deﬁneix la normal ????]. 2. cj. The only kind of integrals of the style of eq. 3 represents also an index over the three different nodes we have in the element e. A similar thing can be done for the y part of the integral and instead of nx we will get a ny .e . see ﬁgure 4. in ˆ ˆ fact it simpliﬁes it a lot because those terms will cancel out among contiguous elements. and so will do the contributions to the line integrals of the style of eq. 3) algebraic equations. y) dx dy = 0 (52) where j = 1. The normals cancel out except at the boundaries . 51 that survive are those of those elements located at the boundary of the system (and therefore without a counter part).e cj. The different coefﬁcients bi. y) ρ(x.e cj.e ) .e (bi. 2. y) dx dy. For elements which are not in the boundary of the system (i.e ) − j e element Ni. y) ρ(x.e bj. and De is the area of the triangular element "e".e + ci.e (x. 40 and 41 ). De (bi.

We create the triangle elements and we label them as depicted in the plot. 14 .Figure 5: First step in the discretization of the 2D rectangular domain. We do a rectangular grid. and we assign a number n to the effective nodes as depicted in the plot. Figure 6: Second step in the discretization of the 2D rectangular domain.

3 in a clock-wise way. • Now that we know the coordinates of the vertices for each element. Make use of the determinant formulas we have seen before.For elements in the boundary one has to add the terms of the style of eq.53. • Initialize the global matrix [K] and the global vector [f] with zeros. /* if n is in the boundary.52. we do as follows: • Discretize the square domain into a rectangular grid of n = Nx × Ny points (that will be our n effective nodes). The most clean way of doing this is as follows: To give a particular example. 51. The boundary nodes those located in the perimeter of our square. • Now act as the following pseudocode says to build up the global matrix [K] and the global vector [f]: For element=1 till element= the last element { for i=1 till i=3 { n = map_to_effective_node_the_vertice(i) Calc f_i of the vector [f]_e see eq. 2. See ﬁgure 5 . and up left for even elements.e for each element e. The mapping from the vertices of the triangle elements to the effective nodes involved is explained in tables 1 and 2. we can compute the three shape functions Ni. • Now split the rectangular grid into triangular elements as shown in ﬁgure 6.m) element of the global matrix [K] */ /* f_n is the (n) element of the global vector [f] */ if(n and m are not in the boundary) { K_nm += K f_n += f } else { if( n is in the boundary) { set K_nn = 1 f_n = v_n . starting in the bottom left for odd elements. store it as K /* K_nm is the (n. Now we know the equations for our elements (three for element). • The vertices in each triangle we will label them as 1. we have to add the equations of all elements all together taking into account that contiguous elements have nodes in common. store it as f for j=1 till j=3 { m = map_to_effective_node_the_vertice(j) Calc K_ij of the matrix [K]_e see eq. • Notice the disposition of the odd and even labeled triangles. we know v_n */ 15 . let’s suppose for simplicity we have to solve our Poisson equation onto a square domain. To obtain the global matrix [K] and the global vector [f].

and Kn. we now the value of vm . Notice that because m is a node on the boundary. Notice that in the pseudocode we use for the boundary nodes if( n is in the boundary) { set K_nn = 1 f_n = value for such point in the boundary } else if (m in the boundary) { g_n = g_n . /* if m is in the boundary.K*v_m } The ﬁrst body of the if is to make sure that the values at the boundary nodes are ﬁxed and are not changed. (57) in order to obtain the value of the potential V at position of the effective nodes [v]. Thus. given a node n that has neighboring nodes m which are in the boundary. we know v_m */ } } } } } • Now that you have the global matrix [K] and the global vector [f]. The second body (the "else if") is to incorporate the contributions from the line integrals of the nodes located at the boundary.m vm (58) where bn stands for "boundary nodes near node n". The terms containing non zero line integral contributions can be easily added to the [f ] vector (mind the minus sign due to the change of those terms from the left to the right hand side of the equations].K*v_m .m will contain also the result of the integral lines which can be easily evaluated. just what remains to be done is to solve the system: [K][v] = [f ]. we have bn fn = fn (arising f rom non bn) − m Kn.} else if (m is in the boundary) { f_n = f_n . 16 .

the larger the matrix to solve is.4). yβ−1 ) (xα−1 . vertex num. In 3D. • The more the number of nodes. yβ−1 ) Corresponds to the effective node n2 n2 + 1 n3 7 Sparse Matrixes (band matrixes) and FEM. • Storing zeros is a waste of memory. because you need to make many operations to solve the system.Table 1: Odd labeled triangular elements. i 1 2 3 It has coordinates (xα−1 . vertex num i 1 2 3 It has coordinates (xα−1 . This is because our node has direct connection only with its ﬁrst neighbor nodes. (59) with methods like Gauss-Jordan. That’s not nice. yβ ) (xα . yβ−1 ) Corresponds to the effective node n1 ≡ (β − 1)Nx + α n2 ≡ n 1 + Nx n3 ≡ n 1 + 1 Table 2: Even labeled triangular elements. • A sparse matrix is a matrix with many elements that are zero. 17 . ca. • As we have seen in the 1D case. yβ ) (xα . yβ ) (xα . this trouble is even more pronounced and the matrix is even more sparse. (Note: ca = circa (Latin) = around. • If you solve the system [K][v] = [f ]. and you need huge amounts of memory. and is easy to see in 2D and 3D. In the intermediate stage you will have huge matrices with non zeros. Let’s suppose the triangle is in the rectangle of the α-th column and β-th row (α = 1 and β = 1 is the rectangle at the bottom-left). There are ways of storing matrices which have many zeros with a minimum amount of storage (See for instance Numerical Recipes. near). FEM method leads to huge sparse matrix. Let’s suppose the triangle is in the rectangle of the α-th column and β-th row (α = 1 and β = 1 is the rectangle at the bottom-left). Chapter 2.

v in the 2D case) is expected to vary very rapidly. An the the changes to do to the code of the program are minimum. The use of higher order elements is specially rewarding when the gradient of the ﬁeld variable (θ in the 1D case. The use of the Pascal triangle can help to determine which should be the terms to include in higher orders in the 2D case. or the adsorbing boundary condition. In this way. mapping. There are very efﬁcient techniques to solve such band diagonal matrixes using minimum storage and minimum number of operations (fast calculation). etc. the non-zero elements localize a few elements before. and after the diagonal. If you have a non linear PDE. See plots in ﬁgure 7. FEM leads usually to Band Diagonal Matrixes. radiation problems). This can be done by alternating the direction of the diagonal cuts. The troubles with optimizing the labeling of the nodes is complex when we have complex geometries. ca. is very tedious. For problems where no boundaries exist (e.e. selection of elements. there are special methods intended to solve such situations: use of inﬁnite element methods.g. • The preparation of the FEM. but static ones. • The FEM method we have reviewed applies t ﬁnite linear equations. Chapter 2. 18 . • Notice also that we have not dealt with time dependent problems. (See for instance Numerical Recipes. • A proper node labeling scheme can help to have a more narrow bandwidth in the matrixes. There are also FEM methods intended to solve problems to deal with time-dependent phenomena. boundary element methods. Nowadays there are excellent programs and algorithms intended to generate the meshes even for complex geometries. more accuracy without need of increasing the number of effective nodes in the system. i. • How to avoid the systematic addition of truncation errors by choosing the grid of nodes in a clever way. • Notice that if you need to reﬁne adding more elements in a certain zone because is the zone where you need more accuracy with FEM programs is very easy.. • Notice that we have just worked out the FEM for bounded problems. There are programs and algorithms for doing such in an efﬁcient way an reduce as maximum as possible the bandwidth of the matrixes. scattering.4). you will have ﬁrst to linearize it.• In fact. 8 Other tricks for FEM and beyond. • The use of higher orders than linear elements. is usually nice because with few high order terms you can save usually quite a lot of elements. Which is important in order to have a faster solution of the matrix.

Samuel S.Figure 7: (a) All cuts in the same direction.M. R. ISBN: 0-521-43108-5.W. Press.usask. Seetharamu. There are also some nice web pages devoted to the ﬁnite element methods: ˜ • The Internet ﬁnite element resources page: http://homepage. O.html 19 . Lewis. (1997).ca /ijm451/ﬁnite/ fe_resources/ fe_resources. ISBN:9810230176. Wiley Ltd. World Scientiﬁc. (2004). Nithiarasu and K. • Numerical Techniques in Electromagnetics. (b) Alternance of the diagonal cuts to make easier truncation errors to cancel instead of adding up. ISBN: 0-470-84788-3. P. • Numerical Recipes in C: The art of Scientiﬁc Computing. ISBN: 0-8493-1395-3. N. 2nd edition. Matthew N. Sadiku. • Computational methods in physics and Engineering. Cambridge Univ. Wong. (1992). 9 Bibliography Suitable books to become more learned about FDM and FEM methods are: • Fundamentals of the Finite Element Method for Heat and Fluid Flow. CRC Press (2001).

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->