Fem Notes
Fem Notes
Per-Olof Persson
[email protected]
1 Introduction to FEM
1.1 A simple example
Consider the model problem
−u00 (x) = 1, for x ∈ (0, 1) (1.1)
u(0) = u(1) = 0 (1.2)
with exact solution u(x) = x(1 − x)/2. Find an approximate solution of the form
û(x) = A sin(πx) = Aϕ(x) (1.3)
Various ways to impose the equation:
Collocation : Impose −û00 (xc ) = 1 for some collocation point xc =⇒ Aπ 2 sin(πxc ) = 1
xc = 1
2 =⇒ A = 1
π2
= 0.1013
√
2
xc = 1
4 =⇒ A = π2
= 0.1433
Average : Impose the average of the equation over the interval:
Z 1 Z 1
00
−û (x) dx = 1 dx (1.4)
0 0
Z 1
2
Aπ 2 sin(πx) dx = Aπ 2 = 2Aπ = 1 (1.5)
0 π
1
A= = 0.159 (1.6)
2π
Galerkin : Impose the weighted average of the equation over the interval:
Z 1 Z 1
00
−û (x)v(x) dx = 1 · v(x) dx (1.7)
0 0
A Galerkin method using the weight functions v(x) from the same space as the solution
space, that is, v(x) = ϕ(x). This gives
Z 1 Z 1
Aπ 2 sin2 (πx) dx = sin(πx) dx (1.8)
0 0
21 2
Aπ · = (1.9)
2 π
4
A = 3 = 0.129 (1.10)
π
1
0.18
0.16 ûAVG (x)
0.14 ûGAL (x)
0.12 u(x)
0.10
0.08 ûCOL (x)
0.06
0.04
0.02
0.00
0.0 0.2 0.4 0.6 0.8 1.0
Figure 1: Solutions of the model problem (1.1)-(1.2) using collocation, average, and
Galerkin.
The three solutions are shown in figure 1.1. The finite element method is based on the
Galerkin formulation, which in this example clearly is superior to collocation or averaging.
To solve for û(x) = Aϕ(x), note that û0 (x) = Aϕ0 (x) and
(
2 x ≤ 12
ϕ0 (x) = (1.16)
−2 x > 12
2
u3
u1
u2
ϕ1 ϕ2 ϕ3
1
x0 x1 x2 x3 x4
Figure 2: A refined piecewise linear function space, same solution and basis functions.
or 4A = 1/2, that is, A = 1/8, and the FEM solution is û(x) = ϕ(x)/8.
where we note that this particular basis has the convenient property that uh (xj ) = uj , for
j = 1, . . . , n.
A Galerkin formulation for (1.1)-(1.2) can now be stated as: Find uh ∈ Vh such that
Z 1 Z 1
0 0
uh (x)v (x) dx = v(x) dx, ∀v ∈ Vh (1.21)
0 0
3
In particular, (1.21) should be satisfied for v = ϕi , i = 1, . . . , n, which leads to n equations
of the form
Z 1 Z 1
0 0
uh (x)ϕi (x) dx = ϕi (x) dx, for i = 1, . . . , n (1.22)
0 0
Pn
Insert the expression (1.20) for the approximate solution and its derivative, u0h (x) = 0
i=1 ui ϕi (x):
Z 1 X n Z 1
0 0
uj ϕj (x) ϕi (x) dx =
ϕx (x) dx, i = 1, . . . , n (1.23)
0 j=1 0
Example : Consider a triangulation of [0, 1] into four elements of width h = 1/4 between
the node points xi = ih, i = 0, . . . , 4. We then get a solution space of dimension
n = 3, and basis functions ϕ1 , ϕ2 , ϕ3 . When calculating the entries of A, note that
A is symmetric, that is, aij = aji
A is tridiagonal, that is, aij = 0 whenever |i − j| > 1
For our equidistant triangulation, aii = ajj and ai,i+1 = aj,j+1
This gives
1 1
a11 = 4 · 4 · + (−4)(−4) = 8 (1.27)
4 4
1
a12 = (−4) · 4 · = −4 (1.28)
4
a22 = a33 = a11 = 8 (1.29)
a21 = a12 = a23 = a32 = −4 (1.30)
a13 = a31 = 0 (1.31)
and
Z 1
1
f1 = f2 = f3 = ϕ1 (x) dx = (1.32)
0 4
and the linear system becomes
8 −4 0 u1 1/4
−4 8 −4 u2 = 1/4 (1.33)
0 −4 8 u3 1/4
4
with solution
u = (u1 , u2 , u3 )T = (3/32, 1/8, 3/32)T (1.34)
Note that the discretization exactly matches the one obtained with finite differences
and the 2nd order 3-point stencil:
2 −1 0 u1 1
1
−1 2 −1 u2 = 1
(1.35)
(1/4)2
0 −1 2 u3 1
0 0 −4 4 u4 9/8
with solution
u = (u1 , u2 , u3 , u4 )T = (15/32, 7/8, 39/32, 3/2)T . (1.47)
5
1.5 Inhomogeneous Dirichlet problems
Use two spaces: Vh , which enforces the inhomogeneous Dirichlet condition, for the solu-
tion uh , and Vh0 , which enforces homogeneous Dirichlet conditions, for the test function v.
Consider for example the model problem
Note that the function space Vh is not a linear vector space, due to the inhomogeneous
constraint. In practice, Dirichlet conditions are implemented by first considering the all-
Neumann problem, and enforcing the Dirichlet conditions directly into the resulting system
of equations.
Example : For the model problem (1.48)-(1.50), first consider the corresponding all-
Neumann problem
In our example with four elements of size h = 1/4, this gives 5 degrees of freedom and
the resulting linear system (with f = 1):
4 −4 0 0 0 u1 1/8
−4 8 −4 0 0 u2 1/4
0 −4 8 −4 0 u3 = 1/4 (1.57)
0 0 −4 8 −4 u4 1/4
0 0 0 −4 4 u5 1/8
This system is singular (since the solution is undetermined up to a constant). We can
now impose the Dirichlet conditions u(0) = 0 and u(1) = 1 directly by replacing the
corresponding equations:
1 0 0 0 0 u1 0
−4 8 −4 0 0 u2 1/4
0 −4 8 −4 0 u3 = 1/4 (1.58)
0 0 −4 8 −4 u4 1/4
0 0 0 0 1 u5 1
6
We can keep the symmetry of the matrix by eliminating the entries below/above the
diagonal of the Dirichlet variables:
1 0 0 0 0 u1 0 0
0 8 −4 0 0 u2 1/4 − (−4) · 0 1/4
0 −4 8 −4 0 u3 = 1/4 = 1/4 (1.59)
0 0 −4 8 0 u4 1/4 − (−4) · 1 17/4
0 0 0 0 1 u5 1 1
with solution u = (u1 , . . . , u5 )T = (0, 11/32, 5/8, 27/32, 1)T . If necessary, the Dirichlet
degress of freedom can be removed from the system, to obtain the smaller system of
equations
8 −4 0 u2 1/4
−4 8 −4 u3 = 1/4 (1.60)
0 −4 8 u4 17/4
In the so-called stamping method, or the assembly process, each element matrix and
load vector are added at the corresponding global position in the global stiffness matrix and
right-hand side vector:
A = 0, b = 0
for all elements k
Calculate Ak , bk
A(t(k, :), t(k, :)) += Ak
b(t(k, :)) += bk
end for
7
Example : Equidistant 1D mesh, element width h, piece-wise linears, f = 1. The elemental
matrix and load vector are
k 1 1 −1 k h 1
A = , b = (1.63)
h −1 1 2 1
The mesh is represented by the arrays
x0 1 2
x1 2 3
p = . , t = . (1.64)
.. ..
xn n n+1
The stamping method gives the global matrices:
1 −1
1 −1 1 −1
−1 2 −1
−1 1 −1 2 −1
−1 2 −1
1 1 −1 1 1
→ → −1 1
h
h
h
1 −1
−1 2 −1
−1 2 −1
1
→
−1 2 −1 =A (1.65)
h
−1 2 −1
−1 2 −1
−1 1
and, similarily, the right-hand side vector
h T
b= 1 2 ··· 2 1 (1.66)
2
Parameterize by adding degrees of freedom at element midpoints. Each element then has
three local nodes: xk1 , xk2 , xk3 , and three local basis functions H1k (x), H2k (x), H3k (x). These
are determined by solving for the polynomial coefficients in
Hik = ai + bi x + ci x2 , i = 1, 2, 3 (1.68)
and requiring that Hik (xj ) = δij , for each i, j = 1, 2, 3. The leads to the linear system of
equations V C = I:
x21
1 x1 a1 a2 a3 1 0 0
1 x2 x22 b1 b2 b3 = 0 1 0 (1.69)
1 x3 x23 c1 c2 c3 0 0 1
8
which gives the coefficients C = V −1 . For example, with x1 = 0, x2 = h/2, x3 = h, we get
2 h
H1 (x) = 2
(x − )(x − h) (1.70)
h 2
4
H2 (x) = − 2 x(x − h) (1.71)
h
2 h
H3 (x) = 2 x(x − ) (1.72)
h 2
The corresponding element matrix and the element load can then be calculated as before:
Z h Z h
k k 0 k 0 k
Aij = Hi (x) Hj (x) dx, bi = f (x)Hik (x) dx (1.73)
0 0
when xi , wi , i = 1, . . . , n are specified points and weights. By choosing xi as the zeros of the
nth Legendre polynomial, and the weights such that the rule exactly integrates polynomials
up to degree n−1, the rule (1.76) gives exact integration for polynomials of degree ≤ 2n−1.
For example, the following rule has n = 2 and degree of precision 2 · 2 − 1 = 3:
Z 1
1 1
f (x) dx ≈ f (− √ ) + f ( √ ) (1.77)
−1 3 3
In our quadratic element example, the integrals for the element matrix were products of
derivatives of quadratics, that is, quadratics. Therefore they can be exactly evaluated using
this rule:
" 2 # Z h
2 3h
Ak11 = Set f (x) = 2 2x − = f (x) dx (1.78)
h 2 0
h h h h h 7
= f( − √ ) + f( + √ ) = · · · = (1.79)
2 2 2 3 2 2 3 3h
9
2 The Poisson Problem in 2-D
Consider the problem
−∇2 u = f in Ω (2.1)
n · ∇u = g on Γ (2.2)
Apply the divergence theorem and use the Neumann condition, to get the Galerkin
form
Z Z I
∇uh · ∇v dx = f v dx + gv ds (2.5)
Ω Ω Γ
Switch order of integration and summation to get the finite element formulation:
n
X
Aij uh,j = bi , or Au = b (2.7)
j=1
where
Z Z I
Aij = ∇ϕi · ∇ϕj dx, bi = f ϕi dx + gϕi ds (2.8)
Ω Ω Γ
2.2 Discretization
Find a tringulation of the domain Ω into triangular elements T k , k = 1, . . . , K and
nodes xi , i = 1, . . . , n
Consider the space Vh of continuous functions that are linear within each element
10
A function v ∈ Vh can then be written
n
X
v= vi ϕi (x) (2.10)
i=1
11
2.5 Assembly, The Stamping Method
Assume a local-to-global mapping t(k, α), giving the global node number for local
node number α in element k
The global linear system is then obtained from the elementary matrices and loads by
the stamping method:
A = 0, b = 0
for k = 1, . . . , K
A(t(k, :), t(k, :)) = A(t(k, :), t(k, :)) + Ak
b(t(k, :)) = b(t(k, :)) + bk
xt(k,2) xt(k,1)
Tk
xt(k,3)
Enforce uh,i = uD for all nodes i on ΓD directly in the linear system of equations:
i
0 · · ·
i 0 1 0 ··· uD
0 uh =
(2.19)
3 FEM Theory
3.1 Variational and minimization formulations
Consider the Dirichlet problem (D)
−∇2 u = f in Ω (3.1)
u = 0 on Γ (3.2)
12
Introduce the notation
Z
a(u, v) = ∇u · ∇v dx (bilinear form) (3.3)
ZΩ
`(v) = f v dx (linear form) (3.4)
Ω
Note that
Also,
Z
a(u, u) = k∇uk22 dx ≥ 0, (3.8)
Ω
and if u = 0 on Γ, then equality only for u = 0. This can then be used to define the energy
norm
p
k|uk| ≡ a(u, u) (3.9)
where d is the number of space dimensions. Let V = H01 . The solution u to (D) then
satisfies a corresponding variational problem (V):
This is also called the weak form of (D), with a weak solution u. Note that a solution u of
(D) is also a solution of (V), since for any v ∈ V :
Z Z
2
−∇ uv dx = f v dx (3.14)
Z I Ω ZΩ
∇u · ∇v dx − n · ∇u v ds = f v dx (3.15)
Ω Z Γ ZΩ
∇u · ∇v dx = f v dx (3.16)
Ω Ω
a(u, v) = `(v) (3.17)
where we used the fact that v = 0 on Γ. The reverse can also be shown, (V) =⇒ (D), if u
is sufficiently regular.
Now consider the minimization problem (M):
1
Find u ∈ V s.t. F (u) ≤ F (v) ∀v ∈ V, where F (v) = a(v, v) − `(v) (3.18)
2
13
Suppose u solves (V). Then it also solves (M), since for any v ∈ V , set w = v − u ∈ V , and
1
F (v) = F (u + w) = a(u + w, u + w) − `(u + w) (3.19)
2
1 1 1 1
= a(u, u) + a(u, w) + a(w, v) + a(w, w) − `(u) − `(w) (3.20)
2 2 2 2
1 1
= a(u, u) − `(u) + a(u, w) − `(w) + a(w, w) ≥ F (u) (3.21)
|2 {z } | {z } |2 {z }
=0 ∀w∈V
F (u) ≥0
The reverse can also easily be shown, that is, (M) =⇒ (V).
for some finite-dimensional subspace Vh of V . Recall that the solution u to (V) satisfies
a(u, v) = `(v) for all v ∈ V , and in particular for all v ∈ Vh , we have
a(u − uh , v) = 0 ∀v ∈ Vh , (3.23)
or a(e, v) = 0 with the error e = u − uh . This means that the error also satisfies a
corresponding minimization problem (M), with `(v) = 0, which leads to the property:
1 1
a(v, v) − 0 = k|vk|2 is minimized by v = u − uh = e (3.24)
2 2
In other words, for any wh ∈ Vh , k|u − wh k| ≥ k|u − uh k|, or the FEM formulation finds the
best possible solution in the energy norm.
More generally, for any Hilbert space V with corresponding norm k · kV , we require that
(ii) a(·, ·) is continuous, i.e., ∃γ > 0 s.t. |a(v, w)| ≤ γkvkV kwkV , ∀v, w ∈ V
The energy norm k| · k| is then equivalent to k · kV , that is, ∃c, C > 0 s.t.
14
3.3 Interpolants
Consider a 1-D function w ∈ V and its linear interpolant wI ∈ Vh , where Vh is a space of
piecewise linear functions, defined by wI (xi ) = w(xi ), or
n
X
wI (x) = w(xi )ϕi (x) (3.27)
i=1
To find a bound on the energy norm of the difference w − wI , we first bound the derivative.
Consider a single element, and note that the difference w − wI is zero at the endpoints. A
point x = z must then exists, such that
For any other point x inside the element, we then have from the fundamental theorem of
calculus,
Z x
[w(x) − wI (x)]0 = [w(y) − wI (y)]00 dy (3.29)
z
A bound for the energy norm of w − wI can then be derived as follows. Note that the
number of elements T can be written as C1 /h, for some constant C1 .
T Z
2
X C1
k|w − wI k| = [(w − wI )0 ]2 dx ≤ · h · h2 · [max |w00 |]2 (3.32)
ek h
k=1
= C1 h2 [max |w00 |]2 (3.33)
or
This implies convergence in the energy norm, at a linear rate w.r.t. the element sizes h.
This result does not imply that the solution itself in, for example, the L2 -norm is
quadratically convergent. However, using other techniques it can be shown that
15
3.5 2-D interpolants
For piecewise interpolant on a triangular mesh in 2-D, it can be shown that
which again leads to the energy norm bound for a finite element solution uh
4 Some extensions
4.1 Higher order elements in 2D
For the piecewise linear case on triangular meshes, we parameterized the space of continuous
functions as:
Representing a solution ui at the global nodes xi
Continuity is enforced since the node values are single-valued, and along an edge
between two elements there is a uniquely defined linear function.
This extends natually to piecewise quadratic elements:
Introduce the edge midpoints as global nodes
Each triangle is now associated with 6 nodes, with determines a unique quadratic
function u(x, y) = a + bx + cy + dx2 + exy + f y 2
16
4.2 Other PDEs
Consider the more general linear parabolic PDE:
∂u
ρ − ∇ · (D∇u + αu) + au = f in Ω (4.1)
∂t
with boundary conditions
Note that the fields rho, D, α, g, and uD in general are time and space dependent.
A standard FEM formulation for (4.1) is: Find uh ∈ Vh s.t.
Z Z Z Z Z
ρu˙h v dx + (D∇uh + αuh ) · ∇v dx + auh v dx = f v dx + gv ds (4.4)
Ω Ω Ω Ω ΓN
for all v ∈ V0,h , where Vh is an appropriate finite dimensional space satisfying the Dirichlet
conditions. Considering the all-Neumann problem, discretization with basis functions ϕi (x)
leads to the linear system of ODEs
Mρ u̇ + Ku + Cu + Ma u = f + g (4.5)
where
Z
Mρ,ij = ρϕi ϕj dx (4.6)
ZΩ
Ma,ij = aϕi ϕj dx (4.7)
ZΩ
Kij = (D∇ϕj ) · ∇ϕi dx (4.8)
ZΩ
Cij = (αϕj ) · (∇ϕi ) dx (4.9)
ZΩ
fi = f ϕi dx (4.10)
IΩ
gi = gϕi ds (4.11)
Γ
This can be integrated in time using method of lines, with e.g. a BDF method or an implicit
Runge-Kutta. Note that explicit methods can be used, but they require inversion of Mρ
and will put stability constrains on the timestep.
17