lecture-slides-week3
lecture-slides-week3
76
The mesh and the finite element space
Vh = span{φi , i = 1, . . . , N}
for some numbering of the interior nodes of the triangulation, with N their
cardinality.
78
A finite element method
Method
Find uh ∈ Vh , such that
! !
∇uh · ∇vh dx = f vh dx ∀vh ∈ Vh
Ω Ω
79
A finite element method
i.e., solve the N × N-linear system
AU = F
with A = [aij ]N T T
i,j=1 , U = (U1 , . . . , UN ) and F = (F1 , . . . , FN ) , whereby
! !
aij = ∇φj · ∇φi dx, and Fi = f φi dx.
Ω Ω
As we shall see below, computing aij and Fi for general meshes is a non-trivial, yet
well defined, process.
Example
Use FEM to approximate u : Ω → R, such that
80
Example
1.5
0.5
−0.5
−1
0.6
0.4
0.2
−0.2
−0.4
0.6
0.4
0.2
0
−0.2
−0.4
−0.6
81
Calculation of the FEM system for a simple problem
We shall calculate the FEM linear system for Ω = (0, 1) × (0, 1), which we
subdivide into triangles, with nodes (xi , yj ) such that
(0, 1) • • • • • •
y
• • • • • •
• • • • • •
• • • • • •
• • • • • •
• • • • • •
(0, 0) x (1, 0)
82
Calculation of the FEM system for a simple problem
To each node (xi , yj ), we associate a basis (pyramid) function φi,j which is linear
on every element and continuous, with
83
Pyramid function φi,j
xi,j
84
Calculation of the FEM system for a simple problem
We calculate ∇φi,j = ((φi,j )x , (φi,j )y ):
1 1
− h , if (x, y) ∈ T1 ;
−h, if (x, y) ∈ T1 ;
1
0, if (x, y) ∈ T2 ;
− h , if (x, y) ∈ T2 ;
h1 ,
if (x, y) ∈ T3 ; 0,
if (x, y) ∈ T3 ;
1 1
(φi,j )x (x, y) = h, if (x, y) ∈ T4 ; , (φi,j )y (x, y) = h, if (x, y) ∈ T4 ;
1
0, if (x, y) ∈ T5 ;
h, if (x, y) ∈ T5 ;
1
− h , if (x, y) ∈ T6 ;
0, if (x, y) ∈ T6 ;
0, otherwise. 0, otherwise.
It is now not too hard to see, that the resulting matrix
B −I 0 0 ... 0 4 −1 0 0 ... 0
−I B −I 0 ... 0 −1 4 −1 0 ... 0
0 −I B
1 −I . . . 0 0 −1 4 −1 ... 0
A=− . .. .. .. .. .. , B = .. .. .. .. .. . (3
h .. . . . . . . . . . . ...
0 ... 0 −I B −I 0 ... 0 −1 4 −1
0 ... 0 0 −I B 0 ... 0 0 −1 4
where 0 is N × N zero matrix, I is N × N identity matrix, and B ∈ RN×N .
85
Calculation of the FEM system for a simple problem
The corresponding linear system for this case reads (after multiplication by −h):
−hAU = −hF, viz.,
U1,1 F1,1
U2,1 F2,1
.. ..
.
.
B −I 0 0 . . . 0 UN,1 FN,1
−I B −I 0 . . . 0
U1,2
F 1,2
0 −I B −I . . . 0 . .
. .
.. .. . . . . . = h .
,
. . . . . . . . .
.
UN,2
FN,2
0 ... 0 −I B −I . ..
.
0 −I B .
.
0 ... 0
U1,N F1,N
. .. ..
where Fi,j = Ω fφi,j dx . .
UN,N FN,N
Remark
The stiffness matrix A coincides with the finite difference matrix of the five point
scheme: −ui−1,j − ui+1,j + 4ui,j − ui,j−1 − ui,j−1 = h2 f(xi,j ), i, j = 1, . . . , N
86
Assembly
The assembly of the stiffness matrix and the load vector for a general
mesh/triangulation is an involved, yet quite streamlined procedure.
Triangle: https://www.cs.cmu.edu/~quake/triangle.html
Gmsh: https://gmsh.info/
Mesh generators output (among other things) two key data structures:
87
Data structures: node
1
4 6 2 3
0.5 0
0.8 6 0.5 0.5 7
6 7
6 0 0.5 7
6 7
0.6 6 0.5 1 7
node = 6 7
6 1 0.5 7
3 2 5 6 1 1 7
0.4 6 7
4 0 0 5
0.2 1 0
7 1 8
0
Figure 8.9: Example 8.8. Position of nodes and respective node array.
where Z
88
Fi,j = f i,j dV. (8.22)
Data structures: connectivity
1
4 6
0.8 ○
4 2 3
1 3 7
6 8 5 1 7
○
5 6 7
0.6 6 2 1 5 7
connectivity = 6 7
6 4 2 6 7
0.4 3 2 5 4 2 5 6 5
○
6 ○
3
3 1 2
0.2 ○
1 ○
2
7 1 8
0
For given node and connectivity arrays, we can compute the stiffness matrix
Figure 8.10: Example 8.8. Elements and respective connectivity array.
and load vector.
te the reference element (or, reference simplex, as is also known). Then, each element T 2 T can be
sented as the image of an affine map FT : Rd ! Rd mapping the reference element T̂ into T , viz.,
89
Reference element
T̂ := {x ∈ Rd : 0 ≤ x1 + · · · + xd ≤ 1}
(1, 0) x̂ x
90
Reference map
We want (1, 0) of T̂ to be mapped to x1 of T, (0, 1) of T̂ to be mapped to x2 ,
and (0, 0) of T̂ to be mapped to x3 .
(1, 0) x̂ x
ψ1 (x̂, ŷ) := x̂, ψ2 (x̂, ŷ) := ŷ, and ψ3 (x̂, ŷ) := 1 − x̂ − ŷ,
Therefore,
92
Basis functions under map
If ∇
ˆ denotes the gradient w.r.t. x̂ variables, we have
/ 0
wx xx̂ + wy yx̂
ˆ
∇v = = BT ∇w,
wx xŷ + wy yŷ
∂(x, y)
since the Jacobian = BT .
∂(x̂, ŷ)
93
Assembly
We seek to compute each component
#!
aij = ∇φj · ∇φi dx dy,
T∈T T
The final step in the assembly is to transfer the entries of each AT to the global
stiffness matrix A,
with k the column number of the node i, on the row corresponding to T in the
connectivity, and ! the column number of the node j on the row corresponding
to T in the connectivity .
95
Implementation of boundary conditions: Dirichlet type
Split the total number of nodes Ntotal into total number of interior nodes, Nint ,
and of boundary nodes, N∂ , with N∂ := Ntotal − Nint .
Rearrange the numbering so that the nodes xj , j = 1, . . . , Nint are interior, while
xj , j = Nint + 1, . . . , Ntotal are the boundary nodes.
For a boundary condition u(x) = g(x) for x ∈ ∂Ω, the FE solution is of the form
Nint
# N
# total
uh = Uj φ j + g(xj )φj
j=1 j=Nint +1
So, a FEM: find uh ∈ Ṽh , with uh (xj ) = g(xj ), j = Nint + 1, . . . , Ntotal , s.t.
96
Implementation of boundary conditions: Dirichlet type
We now discuss a popular, practical way, (albeit not optimal computationally,) of
implementing the Dirichlet boundary condition.
Starting from the assembled stiffness matrix, say, A and load vector, say, F
inclusive of the boundary basis functions, perform the following:
Remark:
A compatibility condition may be required: let v = 1 (it is allowed!); then
! !
f dx = − g dS.
Ω ∂Ω
99