Professional Documents
Culture Documents
Michael Bader
Lehrstuhl Informatik V
Winter 2021/2022
Part I: Introduction to Finite Element Methods
A Road to Theory
Time-Dependent Problems
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 2
The Model Problem: Poisson Equation
∂2 ∂2
− 2
u(x, y ) − u(x, y) = f (x, y ) in Ω = (0, 1)2
∂x ∂y 2
• Dirichlet boundary conditions:
u(x, y) = g(x, y ) on ∂Ω
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 3
Finite Elements – Main Ingredients
1. solve weak form of PDE to reduce regularity properties
Z Z
00 00
−u = f −→ − vu dx = vf dx for “all” v
Ω Ω
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 4
Weak Form and Weak Solutions
Motivation:
• an approximate solution (i.e., function) will likely not satisfy the PDE
• we thus need to “weaken” the requirements on the approximating function
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 5
Example: Weak Form of the Poisson Equation
• Poisson equation with Dirichlet conditions:
−∆u = f in Ω, u = 0 on δΩ
• weak form: Z Z
− ∆u · v dΩ = f · v dΩ ∀v ∈ V
Ω Ω
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 6
Example: Weak Form of the Poisson Equation (2)
−∆u = f in Ω, u = 0 on δΩ
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 7
A Bit More Motivation for the Weak Form
FEM and the Residual Equation
!
• for the PDE −∆u = f , the residual is defined as r (x) := ∆u(x) + f (x) = 0
• in the weak form (multiply with test function an integrate) we obtain
Z Z
v (x) r (x) = v (x) ∆u(x) + f (x) dx = 0 for all v
Z
• remember that f (x)g(x) dx is the standard scalar product on functions
• hence: the residual of the weak solution has to be orthogonal to all test functions
(and recall all connections between “orthogonal” and “shortest distance”)
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 8
Test and Shape Functions
• search for solution functions uh of the form
X
uh = uj ϕj (x)
j
span{ϕ1 , . . . , ϕJ } = Wh
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 9
Test and Shape Functions (2)
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 10
Example: Nodal Basis
1
1
h (x − xi−1 ) xi−1 < x < xi 0,8
0,6
1
h (xi+1 − x)
ϕi (x) := xi < x < xi+1 0,4
0 otherwise
0,2
0
0 0,2 0,4 0,6 0,8 1
x
f(x)
3 u(x) 3 u(x)=iii(x)
2 2
1 1
0 0
0 xi 1 0 1
h3=2-3
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 11
Assembling the System of Equations
• start from system of equations
Z X Z
∇ uj ϕj (x) · ∇ψi dx = f · ψi dx ∀ψi
j
• ∇ and
R
are linear operators ⇒ rewrite into canonical form:
XZ Z
∇ϕj (x) · ∇ψi (x) dx uj = f · ψi dx ∀ψi
j | {z } | {z }
=:Aij =:fi
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 12
Example Problem: 1D Poisson
• in 1D: −u 00 (x) = f (x) on Ω = (0, 1),
hom. Dirichlet boundary cond.: u(0) = u(1) = 0
• weak form:
Z 1 Z 1
0 0
u (x) · v (x) dx = f (x) · v (x) dx ∀v ∈ V
0 0
• computational grid:
xi = ih, (for i = 1, . . . , n − 1); mesh size h = 1/n
• Vh = Wh : piecewise linear functions (on intervals [xi , xi+1 ])
• insert uh = j uj ϕj (x) into weak form:
P
Z 1X Z 1
0 0
uj ϕj (x) · ϕi (x) dx = f (x) · ϕi (x) dx ∀i = 1, . . . , n − 1
0 j 0
| {z }
= j uj 01 ϕ0j (x)·ϕ0i (x) dx
P R
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 13
Nodal Basis
1
h (x − xi−1 ) xi−1 < x < xi
1
h (xi+1 − x)
ϕi (x) := xi < x < xi+1
0 otherwise
0,8
0,6
0,4
0,2
0
0 0,2 0,4 0,6 0,8 1
x
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 14
Nodal Basis – Derivatives and Integrals
Compute derivative of basis functions:
1
h
xi−1 < x < xi
0
ϕi (x) := − h1 xi < x < xi+1
0 otherwise
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 16
Outlook: A Road to Theory
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 17
Time-Dependent Problems
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 18
Time-Dependent Problems (2)
Solve a system of ordinary differential equations:
• after spatial discretisation (Mh constant):
∂
∂t Mh (uh ) = Ah uh + fh
• uh a vector of time-dependent coefficient functions:
T
uh = (u1 (t), . . . , ui (t), . . . , un (t))
• e.g., with forward Euler: Mh u(n+1)
h − uh
(n) (n)
= Ah uh + fh
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 20
Element Stiffness Matrices
Finite Element methods are often used for complicated meshes:
Questions:
• how to set up the system of equations efficiently?
• is it possible to use stencil notation??
⇒ Switch to element stiffness matrices!
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 21
Element Stiffness Matrices (2)
• for discretisation → domain Ω subdivided into finite elements Ω(k) :
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 22
Element Stiffness Matrices (3)
• leads to local stiffness matrices A(k ) for each element:
Z XZ
∇φj · ∇φi dx = ∇φj · ∇φi dx
Ω k
Ω(k )
| {z } | {z }
=:Aij =:Aij
(k)
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 23
Element Stiffness Matrices (4)
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 24
Example: 1D Poisson
• Ω = [0, 1] splitted into Ω(k) = [xk , xk +1 ]
• nodal basis; leads to element stiffness matrix:
b (k) = 1 1 −1
A h −1 1
• in stencil notation:
1 1 1
h [ −1 1 0] + h[0 1 − 1] → h [ −1 2 − 1]
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 25
Example: 2D Poisson
• −∆u = f on domain Ω = [0, 1]2
• splitted into Ω(i,j) = [xi , xi+1 ] × [xj , xj+1 ]
• bilinear basis functions
ϕij (x, y ) = ϕi (x)ϕj (y )
• “pagoda” functions
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 26
Example: 2D Poisson (2)
• leads to element stiffness matrix:
2 − 12 − 12 −1
−1 2 −1 − 12
Ab (k) =
21
− 12
−2 −1 2
−1 − 12 − 12 2
−1 −1 −1
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 27
Typical Workflow
1. choose grid (essentially the Ω(k) ):
• quadratic or cubic cells
• triangles (structured, unstructured)
• tetrahedra, etc.
2. set up basis functions for each element Ω(k) ;
for example, at all nodes xi ∈ Ω(k )
ϕi (xi ) = 1
ϕi (xj ) = 0 for all j 6= i
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 28
Element-Oriented Computation on Unstructured
Meshes
Recall: FEM often used for complicated meshes:
(k) (k)
where φµ (x) = φi (x) and φν = φj (x) in Ω(k )
• requires a mapping φ(k) (k )
µ → φi (and φν → φj ),
i.e., a function ι(k) with i = ι(k) (µ) and j = ι(k) (ν)
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 30
Accumulation of Global Stiffness Matrix
• note the different dimensions of A(k) and A b (k) :
(k ) (k )
A omits zero rows and columns of A
b
• formulated via a projection matrix:
T (k ) 1 if i = ι(k) (µ)
A(k) = P (k) b (k ) P (k)
A with Pµ,i :=
0 otherwise
• recall computation of global stiffness matrix:
X X T (k ) (k )
A := A(k ) = P (k ) Ab P
k k
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 31
Element Stiffness Matrices and Meshes
Recall our initial question:
g(b) Rb
f (g(t))g 0 (t) dt
R
Compare integration by substitution: f (x) dx =
g(a) a
Z1
b (k) = ∂ (k) (k) ∂ (k ) (k)
A µ,ν φ χ (ξ) φµ χ (ξ) (xk +1 − xk ) dξ.
∂x | ν {z } ∂x | {z }
0 =Φµ (ξ) =Φν (ξ)
Note that:
∂
• ∂ξ χk (ξ) = (xk +1 − xk ) corresponds to the factor g 0 (t) in the substitution
rule
• we still have to deal with the partial derivatives in x
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 34
Simple Example: 1D Poisson (3)
∂f ∂f ∂g
We require the chain rule, ∂x = ∂g ∂x , to obtain:
∂ (k) (k) ∂ ∂ ∂ξ
φµ χ (ξ) = Φµ (ξ) = Φµ (ξ)
∂x ∂x ∂ξ ∂x
x − x k
As x = χ(k) (ξ) := xk + ξ(xk+1 − xk ), we have ξ = and thus:
xk+1 − xk
∂ ∂ξ ∂ 1
Φµ (ξ) = Φµ (ξ)
∂ξ ∂x ∂ξ xk+1 − xk
Finally, we get:
Z1
b (k) = ∂ (k ) (k) ∂ (k) (k )
A µ,ν φ χ (ξ) φ χ (ξ) (xk+1 − xk ) dξ
∂x ν ∂x µ
0
Z1
∂ ∂ 1
= Φν (ξ) Φµ (ξ) (xk+1 − xk ) dξ.
∂ξ ∂ξ (xk +1 − xk )2
0
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 35
Simple Example: 1D Poisson (4)
Altogether, element stiffness matrices are computed as:
Z1
b (k) = 1 ∂ ∂
A µ,ν Φν (ξ) Φµ (ξ) dξ
xk+1 − xk ∂ξ ∂ξ
0
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 37
Outlook: Automatised Finite Element Assembly
Example: FeniCS Project, https://fenicsproject.org/ Numerical Programming 2
Michael Bader | Scientific Computing I | Introduction to Finite Element Methods | Winter 2021/2022 39