numerical methods for pdes fem – implementation: … · fem – implementation: element stiffness...

17
Platzhalter für Bild, Bild auf Titelfolie hinter das Logo einsetzen Dr. Noemi Friedman Numerical methods for PDEs FEM – implementation: element stiffness matrix, isoparametric mapping, assembling global stiffness matrix

Upload: voxuyen

Post on 07-Sep-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

Platzhalter für Bild, Bild auf Titelfolie hinter das Logo einsetzen

Dr. Noemi Friedman

Numerical methods for PDEs FEM – implementation: element stiffness matrix, isoparametric mapping, assembling global stiffness matrix

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 2

Contents of the course

• Fundamentals of functional analysis • Abstract formulation FEM • Application to conrete formulations • Convergence, regularity • Variational crimes • Implementation • Mixed formulations (e.g. Stokes) • Stabilisation for flow problems • Error indicators/estimation • Adaptivity

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 3

Implementation

• Piecewise polynomials and the FEM • Sparsity of the stiffness matrix • Calculating the stiffnes matrix elementwisely • Isoparametric mapping • Condition number of the stiffness matrix • Sparsity of the stiffness matrix • Numerical integration • …

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 4

1D Example with linear nodal basis

𝑢 𝐱 ≈�𝑢𝑖

4

𝑖=1

𝜓𝑖(𝐱)

𝑝 𝑥 = 𝑎𝑥

Strong form:

𝑝(𝑥)

𝑙

𝑙/5 𝑙/5 𝑙/5 𝑢 0 = 𝑢 𝑙 = 0

Weak form:

� 𝐸𝐸𝑑𝑢𝑑𝑥

𝑑𝜓𝑑𝑥 𝑑𝑥

𝑙

0= � 𝑝 𝑥 𝜓 𝑥 𝑑𝑥

𝑙

0

Discretisation of the weak form:

�𝑢𝑗

4

𝑖=1

𝐸𝐸�𝜕𝜓𝑖(𝑥)𝜕𝑥

𝜕𝜓𝑗(𝑥)𝜕𝑥

𝑑𝑥

𝑙 = �𝑝(𝑥)𝜓𝑗(𝑥)𝑑𝑥

𝑙

𝐾𝑖𝑗 𝑓𝑗

𝑙/5 𝑙/5

Not efficient to calculate all the elements of the stiffness matrix one by one!

Calculate element stiffness matrices and assemble

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 5

1D Example with linear nodal basis

𝑝(𝑥)

𝑙

𝑙/5 𝑙/5 𝑙/5 𝑙/5 𝑙/5

instead: Compute stiffness matrix elementwisely and then assemble

𝐊 𝐟 𝐮

Global stiffness matrix

1 2 3 4 5 6

𝐾4𝑒 =

1 2 3 4 5 6

1 2 3 4 5 6

𝑢1 𝑢2

𝑢3

𝑢4

𝑢5

𝑢6

0 𝑓2

𝑓3

𝑓4

𝑓5

0

=

4 5 4 5

𝐾4𝑒 1,1 = 𝐸𝐸�𝜕𝜓4(𝑥)𝜕𝑥

𝜕𝜓4(𝑥)𝜕𝑥

𝑑𝑥

Ω4

𝐾4𝑒(1,1) 𝐾4𝑒(1,2)

𝐾4𝑒(2,1) 𝐾4𝑒(2,2)

𝜓4 𝜓5 𝜓3 𝜓2

𝐾4𝑒 1,2 = 𝐸𝐸�𝜕𝜓4(𝑥)𝜕𝑥

𝜕𝜓5(𝑥)𝜕𝑥

𝑑𝑥

Ω4

𝐾4𝑒 2,1 = 𝐸𝐸�𝜕𝜓5(𝑥)𝜕𝑥

𝜕𝜓4(𝑥)𝜕𝑥

𝑑𝑥

Ω4

𝐾4𝑒 2,2 = 𝐸𝐸�𝜕𝜓5(𝑥)𝜕𝑥

𝜕𝜓5(𝑥)𝜕𝑥

𝑑𝑥

Ω4

𝐾4𝑒(1,2) 𝐾4𝑒(1,1)

𝐾4𝑒(2,1) 𝐾4𝑒(2,2) 𝐾5𝑒(1,1)

𝐾3𝑒(2,2)

𝐾3𝑒 1,1 𝐾2𝑒(2,2)

𝐾2𝑒 1,1 𝐾1𝑒(2,2)

1

1

𝐾3𝑒(1,2)

𝐾2𝑒(1,2)

𝐾3𝑒(2,1)

𝐾2𝑒(2,1)

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 6

1D Example with linear nodal basis

𝑝(𝑥)

𝑙

𝑙/5 𝑙/5 𝑙/5 𝑙/5 𝑙/5

instead: Compute stiffness matrix elementwisely and then assemble

𝐊 𝐟 𝐮

1 2 3 4 5 6

𝑓4𝑒 =

1 2 3 4 5 6

1 2 3 4 5 6

𝑢1 𝑢2

𝑢3

𝑢4

𝑢5

𝑢6

0 0

=

4 5

𝑓4𝑒 1 = � 𝑝(𝑥)𝜓4(𝑥)𝑑𝑥

Ω4

𝑓4𝑒 1

𝑓4𝑒 2

𝜓4 𝜓5 𝜓3 𝜓2

𝑓4𝑒 2 = � 𝑝(𝑥)𝜓5(𝑥)𝑑𝑥

Ω4

𝐾4𝑒(1,2) 𝐾4𝑒(1,1)

𝐾4𝑒(2,1) 𝐾4𝑒(2,2) 𝐾5𝑒(1,1)

𝐾3𝑒(2,2)

𝐾3𝑒 1,1 𝐾2𝑒(2,2)

𝐾2𝑒 1,1 𝐾1𝑒(2,2)

1

1

𝐾3𝑒(1,2)

𝐾2𝑒(1,2)

𝐾3𝑒(2,1)

𝐾2𝑒(2,1)

𝑓4𝑒 1

𝑓4𝑒 2

𝑓2𝑒 1

𝑓1𝑒 2

𝑓3𝑒 1

𝑓2𝑒 2

𝑓3𝑒 2

𝑓5𝑒 1

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 7

Local/global coordinate system 1D

𝐾4𝑒 𝑘, 𝑙 = 𝐸𝐸�𝜕𝑁𝑘(𝜉)𝜕𝜉

𝜕𝜉𝜕𝑥

𝜕𝑁𝑙(𝜉)𝜕𝜉

𝜕𝜉𝜕𝑥

𝑑𝑥

Ω4=

𝐸𝐸𝑙4𝑒 2 �

𝜕𝑁𝑘(𝜉)𝜕𝜉

𝜕𝑁𝑙(𝜉)𝜕𝜉

𝑑𝑥

Ω4

𝜉 = [0,1]

1

𝑙 𝑒

1

𝑙 𝑒

𝐾4𝑒 𝑘, 𝑙 =𝐸𝐸𝑙 𝑒 2 �

𝜕𝑁𝑘(𝜉)𝜕𝜉

𝜕𝑁𝑙(𝜉)𝜕𝜉

𝑑𝑥(𝜉)𝑑𝜉

𝑑𝜉1

0=𝐸𝐸𝑙 𝑒 �

𝜕𝑁𝑘(𝜉)𝜕𝜉

𝜕𝑁𝑙(𝜉)𝜕𝜉

𝑑𝜉1

0

𝑙 𝑒

Idea: coordinate transformation to have unit length elements element stiffnes matrix is the same for each element

𝜕𝜉𝜕𝜕

= 1𝑙 𝑒

𝐾4𝑒 𝑘, 𝑙 = 𝐸𝐸�𝜕𝜓4(𝑥)

𝑥𝜕𝜓5(𝑥)𝜕𝑥

𝑑𝑥

Ω4

𝑘, 𝑙 ∈ [1,2] 𝑖, 𝑗 ∈ [4,5]

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 8

Local/global coordinate system 1D

𝑓4𝑒 𝑙 =

� 𝑝(𝑥)𝜓4(𝑥)𝑑𝑥

Ω4

� 𝑝(𝑥)𝜓5(𝑥)𝑑𝑥

Ω4

= � 𝑝(𝜉)𝑁𝑙(𝜉)𝑑𝑥(𝜉)𝑑𝜉

𝑑𝜉1

0=

1𝑙 𝑒 � 𝑝(𝜉)𝑁𝑙(𝜉)𝑑𝜉

1

0

𝑙 ∈ [1,2]

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 9

Local/ coordinate system, isoparametric mapping 1D

coordinate transformation using the ansatzfunctions isoparametric mapping

functions of lower order: subparametric functions of higher order: superparametric

𝑥 𝜉 = 𝑥𝑖𝑁1 𝜉 + 𝑥𝑖+1𝑁2 𝜉 = 𝑁1 𝜉 𝑁2 𝜉𝑥𝑖𝑥𝑖+1

local coordinate

global coordinate

𝜉 = 0 𝜉 = 1

𝑥𝑖 𝑥2

Shape functions:

Transformation from local to global coordinates:

Stiffness matrix with isoparametric elements:

𝜉 = [0,1] 𝑥

𝑁1 𝜉 = 1 − 𝜉

𝑁2 𝜉 = 𝜉

𝐾4𝑒 𝑘, 𝑙 = 𝐸𝐸�𝜕𝜓𝑖(𝑥)𝑥

𝜕𝜓𝑗(𝑥)𝜕𝑥

𝑑𝑥 = 𝐸𝐸�𝜕𝑁𝑘(𝜉)𝜕𝜉

𝜕𝜉𝜕𝑥

𝜕𝑁𝑙(𝜉)𝜕𝜉

𝜕𝜉𝜕𝑥

𝑑𝑥

Ω4

Ω4

𝑘, 𝑙 ∈ [1,2] 𝑖, 𝑗 ∈ [4,5]

𝐾4𝑒 𝑘, 𝑙 = 𝐸𝐸�𝜕𝑁𝑘(𝜉)𝜕𝜉

𝑑𝑥𝑑𝜉

−1 𝜕𝑁𝑙(𝜉)𝜕𝜉

𝑑𝑥𝑑𝜉

−1 𝑑𝑥(𝜉)𝑑𝜉

𝑑𝜉1

0

𝑑𝑥𝑑𝜉 = 𝑥𝑖

𝑑𝑁1 𝜉𝑑𝜉 + 𝑥𝑖+1

𝑑𝑁2 𝜉𝑑𝜉

𝑑𝑥𝑑𝜉 =

𝑑𝑁1 𝜉𝑑𝜉

𝑑𝑁2 𝜉𝑑𝜉

𝑥𝑖𝑥𝑖+1

𝑑𝑥𝑑𝜉

−1

𝑑𝑥𝑑𝜉

−1

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 10

Isoparametric linear mapping 2D triangular elements

Basis functions:

Transformation from local to global coordinates:

Stiffness matrix:

1

𝑖, 𝑗 ∈ [1,2,3]

𝑥𝑔𝑙𝑔𝑔 𝜉, 𝜂𝑦𝑔𝑙𝑔𝑔 𝜉, 𝜂 = 𝑁1 𝜉, 𝜂 𝑁2 𝜉, 𝜂

𝑁1 𝜉, 𝜂 𝑁3 𝜉, 𝜂

𝑁2 𝜉, 𝜂 𝑁3 𝜉, 𝜂

𝑥1𝑦1𝑥2𝑦2𝑥3𝑦3

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 11

Isoparametric linear mapping 2D triangular elements

Stiffness matrix:

Stiffness matrix with local coordinates:

where:

substitution rule determinant should not be negative or zero!

𝐉 =

�𝜕𝑁𝑖 𝜉, 𝜂

𝜕𝜉 𝑥𝑖

3

𝑖=1

�𝜕𝑁𝑖 𝜉, 𝜂

𝜕𝜂 𝑥𝑖

3

𝑖=1

�𝜕𝑁𝑖 𝜉, 𝜂

𝜕𝜉 𝑦𝑖

3

𝑖=1

�𝜕𝑁𝑖 𝜉, 𝜂

𝜕𝜂 𝑦𝑖

3

𝑖=1

𝑖, 𝑗 ∈ [1,2,3]

𝑖, 𝑗 ∈ [1,2,3] 𝑲𝑖𝑗 = � � 𝑱−𝑻

𝜕𝑁𝑗𝜕𝜉𝜕𝑁𝑗𝜕𝜂

∙1−𝜂

0

1

0𝑱−𝑻

𝜕𝑁𝑖𝜕𝜉𝜕𝑁𝑖𝜕𝜂

𝑱 𝑑𝜉𝑑𝜂

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 12

Isoparametric linear mapping 2D triangular elements, example

𝑥 𝜉, 𝜂𝑦 𝜉, 𝜂 = 1 − 𝜉 − 𝜂 𝜉

1 − 𝜉 − 𝜂 𝜂 𝜉 𝜂

237197

Transformation from local to global coordinates (isoparametric mapping):

𝑥𝑔𝑙𝑔𝑔 𝜉, 𝜂𝑦𝑔𝑙𝑔𝑔 𝜉, 𝜂 = 𝑁1 𝜉, 𝜂 𝑁2 𝜉, 𝜂

𝑁1 𝜉, 𝜂 𝑁3 𝜉, 𝜂

𝑁2 𝜉, 𝜂 𝑁3 𝜉, 𝜂

𝑥1𝑦1𝑥2𝑦2𝑥3𝑦3

1 2

3

4

5 6

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 13

Local/ coordinate system, isoparametric mapping 2D triangular elements, example

Stiffness matrix with local coordinates:

𝑖, 𝑗 ∈ [1,2,3] 𝑲𝑖𝑗 = � � 𝑱−𝑻

𝜕𝑁𝑗𝜕𝜉𝜕𝑁𝑗𝜕𝜂

∙1−𝜂

0

1

0𝑱−𝑻

𝜕𝑁𝑖𝜕𝜉𝜕𝑁𝑖𝜕𝜂

𝑱 𝑑𝜉𝑑𝜂

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 14

Local/ coordinate system, isoparametric mapping 2D triangular elements, example

𝑱𝑻 = 𝑱𝑻 = 𝑱 = 34 𝑱 = 𝟓 𝟕−𝟐 𝟒

𝑱−𝑻 =𝟏𝑱𝑻

𝟒 𝟐−𝟕 𝟓

𝑲𝑖𝑗𝑒 = � �

134

4 2−7 5

𝜕𝑁𝑗𝜕𝜉𝜕𝑁𝑗𝜕𝜂

∙1−𝜂

0

1

0

134

4 2−7 5

𝜕𝑁𝑖𝜕𝜉𝜕𝑁𝑖𝜕𝜂

34𝑑𝜉𝑑𝜂

𝑲21𝑒 = ∫ ∫ 1

344 2−7 5

−1−1 ∙1−𝜂

010

134

4 2−7 5

10 34𝑑𝜉𝑑𝜂 ==∫ ∫ 1

34−62 ∙1−𝜂

−110

4−7 𝑑𝜉𝑑𝜂

𝑲21𝑒 ==−1.118∫ ∫ 𝑑𝜉𝑑𝜂1−𝜂

010 = −1.118 ⋅ 1

2= −0.559

𝑲𝑖𝑗𝑒 = � � 𝑱−𝑻

𝜕𝑁𝑗𝜕𝜉𝜕𝑁𝑗𝜕𝜂

∙1−𝜂

0

1

0𝑱−𝑻

𝜕𝑁𝑖𝜕𝜉𝜕𝑁𝑖𝜕𝜂

𝑱 𝑑𝜉𝑑𝜂

𝑲11𝑒 𝑲12

𝑒 𝑲13𝑒

𝑲21𝑒 𝑲22

𝑒 𝑲23𝑒

𝑲13𝑒 𝑲23

𝑒 𝑲33𝑒

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 15

Local/ coordinate system, isoparametric mapping 2D triangular elements, example

𝑱𝑻 = 𝑱 = 34 𝑲11𝑒 𝑲12

𝑒 𝑲13𝑒

𝑲21𝑒 𝑲22

𝑒 𝑲23𝑒

𝑲13𝑒 𝑲23

𝑒 𝑲33𝑒

𝑓𝑒 =

� 𝑝(𝑥)𝑁1(𝑥,𝑦)𝑑𝑥

Ω𝑒

� 𝑝(𝑥)𝑁2(𝑥, 𝑦)𝑑𝑥

Ω𝑒

� 𝑝(𝑥)𝑁3(𝑥, 𝑦)𝑑𝑥

Ω𝑒

=

� � 𝑝(𝜉)𝑁1(𝜉, 𝜂) 1−𝜂

0𝑱 𝑑𝜉𝑑𝜂

1

0

� � 𝑝(𝜉)𝑁2(𝜉, 𝜂) 1−𝜂

0𝑱 𝑑𝜉𝑑𝜂

1

0

� � 𝑝(𝜉)𝑁3(𝜉, 𝜂) 1−𝜂

0𝑱 𝑑𝜉𝑑𝜂

1

0

𝑢1𝑒

𝑢2𝑒

𝑢3𝑒

𝑓1𝑒

𝑓2𝑒

𝑓3𝑒

=

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 16

Local/ coordinate system, isoparametric mapping 2D triangular elements, example

𝑲11𝑒 𝑲12

𝑒 𝑲13𝑒

𝑲21𝑒 𝑲22

𝑒 𝑲23𝑒

𝑲31𝑒 𝑲32

𝑒 𝑲33𝑒

𝑢1𝑒

𝑢2𝑒

𝑢3𝑒

𝑓1𝑒

𝑓2𝑒

𝑓3𝑒

=

1 2

3

4

5

local 1 2 3 global 4 3 6

6

𝑲22𝑒 𝑲21

𝑒 𝑲23𝑒

𝑲12𝑒 𝑲11

𝑒 𝑲13𝑒

𝑲32𝑒 𝑲31

𝑒 𝑲33𝑒

𝑢1

𝑢2

𝑢3

𝑢4

𝑢5

𝑢6

𝑓2𝑒

𝑓1𝑒

𝑓3𝑒

4 3 6

1

2

3

4

5

6

1

2

3

1 2 3 4 5 6 =

4

3

6

Implementation | Dr. Noemi Friedman | PDE2 tutorial | Seite 17

Condition number of the stiffness matrix [Chapter 4.4.1]

Condition number

What happens with the roundoff errors in 𝐊� = 𝐋𝐋 = 𝐊 + 𝛅𝐊 ≠ 𝐊

𝐊𝐮 = 𝐟 𝐊 + 𝛅𝑲 𝐮� = 𝐟 + 𝛅𝐟 𝐮� − 𝐮𝐮 ≤

𝝀𝒎𝒎𝒎𝝀𝒎𝒎𝒎

𝛅𝐟 𝐟

𝝀𝒎𝒎𝒎𝝀𝒎𝒎𝒎

= 𝜅(𝐊)

Condition number of 𝐊 with nodal bases with 2D triangular mesh: For the Poisson equation

�𝑐𝑖

𝑁

𝑖=1

�𝛻Ψ𝑖(𝐱) ∙ 𝛻Ψ𝑗 𝐱 𝑑Ω

Ω = �𝑓 𝐱 Ψ𝑗 𝐱 𝑑Ω

Ω

𝐾𝑖𝑗

turns il-conditioned for refined mesh!!!