Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element...

66
Lecture notes for Finite Element Methods Autumn Term 2013, Uppsala Universitet Patrick Henning Date: December 2, 2013 (this script is based on the previous lecture by A. M˚ alqvist and the book ’The Finite Element Method: Theory, Implementation, and Practice’ by M.G. Larson and F. Bengzon)

Transcript of Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element...

Page 1: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Lecture notes forFinite Element Methods

Autumn Term 2013, Uppsala Universitet

Patrick Henning

Date: December 2, 2013

(this script is based on the previous lecture by A. Malqvist and the book

’The Finite Element Method: Theory, Implementation, and Practice’ by M.G. Larson and F. Bengzon)

Page 2: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

II

Page 3: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Contents

1 Lecture 1 and 2 31.1 Piecewise polynomial approximations in 1D . . . . . . . . . . . . . 31.2 Continuous Piecewise Linear Polynomials . . . . . . . . . . . . . . . 51.3 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.4 Continuous Piecewise Linear Interpolation . . . . . . . . . . . . . . 81.5 L2-Projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.6 Computation of an L2-Projection Ph(f) . . . . . . . . . . . . . . . . 101.7 Numerical Integration with Quadrature Rules . . . . . . . . . . . . 111.8 Error in Quadrature Rules . . . . . . . . . . . . . . . . . . . . . . . 131.9 Implementation of the L2−Projection . . . . . . . . . . . . . . . . . 131.10 Exercise 4.1 - Cauchy-Schwarz inequality . . . . . . . . . . . . . . . 16

2 Lecture 3 and 4 172.1 Weak formulation of the problem . . . . . . . . . . . . . . . . . . . 172.2 The Finite Element Method . . . . . . . . . . . . . . . . . . . . . . 182.3 Derivation of the discrete system . . . . . . . . . . . . . . . . . . . 182.4 Basic a priori error estimate . . . . . . . . . . . . . . . . . . . . . . 192.5 Mathematical modeling and boundary conditions . . . . . . . . . . 212.6 Model problem with coefficient and general Robin BC . . . . . . . . 232.7 A posteriori error estimate and adaptivity . . . . . . . . . . . . . . 25

3 Lectures 5 and 6 293.1 Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293.2 Data structure for mesh . . . . . . . . . . . . . . . . . . . . . . . . 293.3 Mesh generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313.4 Piecewise polynomial spaces . . . . . . . . . . . . . . . . . . . . . . 313.5 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333.6 L2-projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343.7 Existence and uniqueness of the projection . . . . . . . . . . . . . . 353.8 A priori error estimate . . . . . . . . . . . . . . . . . . . . . . . . . 363.9 Quadrature and numerical integration . . . . . . . . . . . . . . . . . 37

III

Page 4: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1

3.10 Implementation details . . . . . . . . . . . . . . . . . . . . . . . . . 38

4 Lecture 7, 8 and 9 414.1 Weak formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414.2 Finite Element Method . . . . . . . . . . . . . . . . . . . . . . . . . 434.3 The Dirichlet Problem . . . . . . . . . . . . . . . . . . . . . . . . . 464.4 The Neumann Problem . . . . . . . . . . . . . . . . . . . . . . . . . 474.5 Elliptic Problems with a Convection Term . . . . . . . . . . . . . . 484.6 Eigenvalue Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 494.7 Error analysis and adaptivity . . . . . . . . . . . . . . . . . . . . . 50

5 Lecture 10 575.1 Systems of Ordinary Differential Equations . . . . . . . . . . . . . . 575.2 Heat equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595.3 Wave equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Page 5: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

2 CONTENTS

Page 6: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Chapter 1

Lecture 1 and 2

1.1 Piecewise polynomial approximations in 1D

Summary:

• Introduction of a class of functions that can approximate quite arbitraryfunctions and that are easy to implement,

• Introduction of two methods of approximation,

• Discussion of the quality of the approximations.

Let I := [x0, x1] ⊂ R for x0 < x1 and let P1(I) := v| v(x) = c0 + c1x; c0, c1 ∈ R.Every linear function v on I is uniquely defined by c0, c1 via v(x) = c0 + c1x.

-

6

x0 x1

c0

slope c1 = v′(x)

Alternatively, the function v can be also characterized by two values α0, α1 viaα0 = v(x0) and α1 = v(x1).

3

Page 7: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4 CHAPTER 1. LECTURE 1 AND 2

-

6

x0 x1

α0

α1 t t

Note that typically c0, c1 6= α0, α1, however they are related by a linear systemof equations:

c0 + c1x0 = α0

c0 + c1x1 = α1=⇒

(1 x0

1 x1

)(c0

c1

)=

(α0

α1

).

The matrix is invertible since the determinant is positive:∣∣∣∣1 x0

1 x1

∣∣∣∣ = x1 − x0 > 0.

Consequently, every pair c0, c1 corresponds with a pair α0, α1 and vice versa.

Now, let λ0, λ1 ∈ P1(I) such that λ0(x0) = 1, λ0(x1) = 0 and such that λ1(x0) = 0,λ1(x1) = 1. λ0 and λ1 are uniquely determined. Any v ∈ P1(I) can be written asv(x) = α0λ0(x) + α1λ1(x). What are the equations for λ0 and λ1?

-

6

x0 x1

1

λ0

-

6

x0 x1

1

λ1

We obtain

λ0(x) =x1 − xx1 − x0

and λ1(x) =x− x0

x1 − x0

.

The set λ0, λ1 spans P1(I) (i.e. it is a basis).

Page 8: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1.2. CONTINUOUS PIECEWISE LINEAR POLYNOMIALS 5

1.2 Continuous Piecewise Linear Polynomials

Let a = x0 < x1 < ... < xN = b, where xiNi=0 are nodes. Let furthermoreIi := [xi−1, xi], i = 1, 2, .., N and let hi := xi − xi−1 denote the length of Ii. WithI := [a, b] we let Vh := v ∈ C0(I)| v|Ii ∈ P1(Ii). Here, C0(I) defines the space ofcontinuous functions on I.

v ∈ Vh is uniquely defined by v(xi)Ni=0.

v(x0)v(xN)

-

6

x0

=

a

x1 x2 xN

=b

s s s s s s

Let φjNj=0 ⊂ Vh be functions so that for i, j = 0, ..., N :

φj(xi) =

1 i = j

0 i 6= j.

-

6

x0 x1 xj−1 xj xj+1 xN

1

”hat function”

Now φjNj=0 forms a basis of Vh, i.e. any v ∈ Vh can be written as

v(x) =N∑i=0

αiφi(x), where αi = v(xi).

Page 9: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

6 CHAPTER 1. LECTURE 1 AND 2

We have

φi(x) =

x−xi−1

hi, x ∈ Ii,

xi+1−xhi+1

, x ∈ Ii+1,

0, otherwise.

1.3 Interpolation

Let f : I = [x0, x1]→ R be a continuous function. We define the linear interpolantΠ(f) ∈ P1(I) by Π(f) := f(x0)φ0 + f(x1)φ1.

-

6

x0 x1

s sf

Π(f )

We would like to study the error f − Π(f) in the L2−norm. Let therefore

‖w‖L2(I) :=

(∫I

w(x)2 dx

) 12

(the L2-norm)

Why is this a norm? Properties that characterize a norm:

(i) ‖w‖ = 0 ⇔ w = 0

(ii) ‖λw‖ = |λ|‖w‖ for all w ∈ Vh and λ ∈ R

(iii) ‖v + w‖ ≤ ‖v‖+ ‖w‖ for all v, w ∈ Vh.

They are fulfilled by the L2−norm, since:

(i) if w = 0, we obviously have ‖w‖L2(I) = 0,

if ‖w‖2L2(I) =

∫Iw(x)2 dx = 0 ⇒ w = 0, because w2 ≥ 0.

(ii) ‖λw‖L2(I) =(∫

I(λw(x))2 dx

) 12 = (λ2)

12

(∫Iw(x)2 dx

) 12 = |λ|‖w‖L2(I).

Page 10: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1.3. INTERPOLATION 7

(iii) To verify (iii), we require the Cauchy-Schwarz inequality (respectively Holderinequality) which implies∫

I

v(x)w(x) dx ≤ ‖v‖L2(I)‖w‖L2(I). (1.3.1)

Using it we obtain:

‖v + w‖2L2(I) =

∫I

(v(x) + w(x))2 dx =

∫I

v(x)2 + 2v(x)w(x) + w(x)2 dx

≤ ‖v‖2L2(I) + 2‖v‖L2(I)‖w‖L2(I) + ‖w‖2

L2(I) =(‖v‖2

L2(I) + ‖w‖2L2(I)

)2

.

Proposition 1.3.1. Let f ∈ C2(I) (two times continuously differentiable), thenit holds

‖f − Π(f)‖L2(I) ≤ h2‖f ′′‖L2(I),

‖(f − Π(f))′‖L2(I) ≤ h‖f ′′‖L2(I),

where h := x1 − x0.

Proof. Let e := f − Π(f). We have for arbitrary y ∈ I:

e(y) = e(x0) +

∫ y

x0

e′(x) dx.

Since e(x0) = 0 by the definition of Π(f), we get

e(y) =

∫ y

x0

e′(x) dx =

∫ y

x0

1 e′(x) dx(1.3.1)

≤(∫ y

x0

12 dx

) 12(∫ y

x0

(e′(x))2 dx

) 12

≤ h12‖e′‖L2(I).

Therefore we get e(y)2 ≤ h‖e′‖2L2(I) which implies:

‖e‖2L2(I) =

∫I

e(y)2 dy ≤ h‖e′‖2L2(I)

∫I

1 dy = h2‖e′‖2L2(I). (1.3.2)

It remains to estimate ‖e′‖L2(I). We use the mean value theorem (applied to e′)which gives us the existence of a ξ ∈ I such that

e′(ξ) =e(x1)− e(x0)

x1 − x0

= 0 (because of e(x0) = e(x1)). (1.3.3)

Page 11: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

8 CHAPTER 1. LECTURE 1 AND 2

Now let y ∈ I be arbitrary, then we get e′(y) = e′(ξ) +∫ yξe′′(x) dx =

∫ yξe′′(x) dx

which implies

e′(y) =

∫ y

ξ

e′′(x) dx ≤∫I

|e′′(x)| dx ≤ h12

(∫I

|e′′(x)|2 dx) 1

2

= h12

(∫I

|f ′′(x)|2 dx) 1

2

,

where we used Π(f)′′ = 0. We get∫I

|e′(y)|2 dy ≤ h

∫I

∫I

|f ′′(x)|2 dx dy = h2

∫I

|f ′′(x)|2 dx.

Combining the last estimate with (1.3.2), we get

‖e‖L2(I) ≤ h‖e′‖L2(I) ≤ h2‖f ′′‖L2(I).

1.4 Continuous Piecewise Linear Interpolation

Now let Π(f) :=∑N

i=0 f(xi)φi.

Proposition 1.4.1. Let f ∈ C0(I) and f ∈ C2(Ii) for all 1 ≤ i ≤ N , then it holds

‖f − Π(f)‖2L2(I) ≤

N∑i=1

h4i ‖f ′′‖2

L2(Ii),

N∑i=1

‖(f − Π(f))′‖2L2(Ii)

≤N∑i=1

h4i ‖f ′′‖2

L2(Ii),

where hi := xi − xi−1.

Proof. We can use Proposition 1.3.1 and apply it to each of the intervals Ii toobtain

‖f − Π(f)‖2L2(I) =

N∑i=1

‖f − Π(f)‖2L2(Ii)

≤N∑i=1

h4i ‖f ′′‖2

L2(Ii)

and simultaneously

‖(f − Π(f))′‖2L2(I) =

N∑i=1

‖(f − Π(f))′‖2L2(Ii)

≤N∑i=1

h2i ‖f ′′‖2

L2(Ii).

Page 12: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1.5. L2-PROJECTION 9

We make three observations:

1. Π(f)→ f as (max1≤i≤N hi)→ 0.

2. Π(f) is a bad approximation if f ′′ is big.

3. Non-uniform refinements in hi can be used to reduce terms where ‖f ′′‖L2(Ii)

is big.

1.5 L2-Projection

Let I = [a, b]. Notation: in the following we just write∫Iv instead of

∫Iv(x) dx if

the variable of integration is clear from the context.We consider the space L2(I) := v|

∫Iv(x)2 dx < ∞ with the scalar product

(v, w) :=∫Iu · v. Recall the properties of a scalar product:

(i) (v, w) = (w, v) for all v, w ∈ L2(I) (symmetry),

(ii) (αv+βw, z) = α(v, z)+β(w, z) for all v, w, z ∈ L2(I) and α, β ∈ R,

(iii) ∀v ∈ L2(I): (v, v) ≥ 0 and ’(v, v) = 0 ⇔ v=0’.

Each of the properties is obviously fulfilled.

We have already defined the corresponding norm

‖v‖L2(I) =

(∫I

v2

) 12

= (v, v)12 .

The normed vector space L2(I) with the above scalar product (inner product)is a Hilbert space (i.e. every Cauchy sequence converges). The ’L’ comes fromLebesgue who introduced the so called ’Lebesque integral’ that we use nowadays.

We say two L2-functions v and w are orthogonal if (v, w) = 0.

The Cauchy-Schwarz inequality holds for all v, w ∈ L2(I):

(v, w) ≤ ‖v‖L2(I)‖w‖L2(I) (proved later).

The triangle inequality holds for all v, w ∈ L2(I):

‖v + w‖L2(I) ≤ ‖v‖L2(I) + ‖w‖L2(I).

Page 13: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

10 CHAPTER 1. LECTURE 1 AND 2

Proof. Using Cauchy-Schwarz, we get:

‖v + w‖2L2(I) = (v + w, v + w) = (v, v + w) + (w, v + w)

≤ ‖v‖L2(I)‖v + w‖L2(I) + ‖w‖L2(I)‖v + w‖L2(I).

Dividing by ‖v + w‖L2(I) yields the result. If ‖v + w‖L2(I) = 0, the result istrivial.

Let f ∈ L2(I), where I is an interval in R. We define the L2−projection

Ph : L2(I)→ Vh = v ∈ C0(I)| v|Ii ∈ P1(Ii)

by: Ph(f) ∈ Vh fulfills∫I

(f − Ph(f)) · vh = 0 for all vh ∈ Vh.

Note that

‖f − Ph(f)‖2L2(I) = (f − Ph(f), f − Ph(f))

= (f − Ph(f), f − vh) + (f − Ph(f), vh − Ph(f))︸ ︷︷ ︸=0

≤ ‖f − Ph(f)‖L2(I)‖f − vh‖L2(I)

and therefore

‖f − Ph(f)‖L2(I) ≤ ‖f − vh‖L2(I) for all vh ∈ Vh.

Ph(f) is the best approximation of f in Vh with respect to the L2−norm.

1.6 Computation of an L2-Projection Ph(f )

To find Ph(f) ∈ Vh with (f −Ph(f), vh) = 0 for all vh ∈ Vh is equivalent to findingPh(f) ∈ Vh with

(f − Ph(f), φj) = 0 for all j = 0, ..., N,

where Vh = span(φjNj=0) and φj being the hat functions defined in Section 1.2(which form a basis of Vh).

Page 14: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1.7. NUMERICAL INTEGRATION WITH QUADRATURE RULES 11

Since Ph(f) ∈ Vh we can write it as Ph(f) =∑N

j=0 ξjφj with appropriate ξj ∈ R.Therefore

’find Ph(f) ∈ Vh : (Ph(f), vh) = (f, vh) for all vh ∈ Vh’

⇐⇒ ’find ξ0, ..., ξN ∈ R :N∑j=0

ξj(φj, φi) = (f, φi) for all 0 ≤ i ≤ N ’.

The real numbers ξ = (ξ0, ..., ξN) are the coefficients for describing Ph(f) in termsof the hat basis functions: Ph(f) =

∑Nj=0 ξjφj. The problem can be expressed as

a linear system of equations. We define the Matrix M ∈ R(N+1)×(N+1) and thevector b ∈ R(N+1) by

Mij := (φj, φi) =

∫I

φi · φj (computable)

bi := (f, φi) =

∫I

f · φi (computable).

We get bi =∑N

j=0Mijξj for i = 0, ..., N or equivalently b = Mξ. This leads to thefollowing algorithm for the computation of Ph(f):

Algorithm

1. Initiate mesh with N elements x0 < x1 < ... < xN .

2. Compute M and b.

3. Solve Mξ = b.

4. Let Ph(f) =∑N

j=0 ξjφj.

1.7 Numerical Integration with Quadrature Rules

We want to approximate integrals numerically. We denote

J(f) :=

∫I

f(x) dx.

A quadrature rule is formula to approximate an integral. The formula takes valuesat f(xj), multiplies them with so called weights ωj (which represent small volumeunits) and sums up everything, i.e.:

J(f) ≈ QI(f) :=n∑j=1

ωjf(xj), xj ∈ [a, b].

Examples:

Page 15: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

12 CHAPTER 1. LECTURE 1 AND 2

1. Midpoint rule. Let n = 1, x1 = a+b2

, ω1 = b− a.

J(f) ≈ QI(f) := f(x1)(b− a) = f

(a+ b

2

)(b− a).

This rule is exact for linear functions f .

-

6

a b

s f

QI(f )

2. Trapezoidal rule. Let n = 2, x1 = a, x2 = b, ω1 = ω2 = b−a2

.

J(f) ≈ QI(f) :=f(a) + f(b)

2(b− a).

This rule is exact for linear functions f .

-

6

a b

s sf

QI(f )

3. Simpson’s rule. Let g(x) := γx2 + βx + α and I = [0, h]. We wish todetermine α, β and γ such that g(0) = f(0), g(h

2) = f(h

2) and g(h) = f(h),

i.e. g is a quadratic interpolation of f . In particular: if f is a quadraticpolynomial, then f = g. Now, find α, β, γ ∈ R such that

g(0) = α = f(0), g(h

2) = γ

h2

4+ β

h

2+ α and g(h) = γh2 + βh+ α = f(h).

We obtain the following the linear system of equations for α, β and γ:1 0 0

1 h2

h2

4

1 h h2

αβγ

=

f(0)f(h

2)

f(h)

with solution

αβγ

=

f(0)2h

(−1

2f(h)− 3

2f(0) + 2f(h

2))

2h2

(f(h)− 2f(h

2) + f(0)

) .

Page 16: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1.8. ERROR IN QUADRATURE RULES 13

Computing the integral of g over I by using the above values for α, β andγ, we obtain ∫ h

0

g(x) dx =h

6(f(0) + 4f(

h

2) + f(h)).

This means, that the quadrature rule

J(f) ≈ QI(f) :=f(a) + 4f(a+b

2) + f(b)

6(b− a)

is exact for quadratic functions f (because in this case we have f = g).

4. Gauss quadrature rule. So called Gauss quadratures are higher orderquadrature rules which can be exact for arbitrary polynomials.

1.8 Error in Quadrature Rules

Let QI(f) be a quadrature rule which is exact for polynomials of degree ’≤ p’.Then ∣∣∣∣∫

I

f(x) dx−QI(f)

∣∣∣∣ ≤ C|I|p+1 supy∈I

∣∣∣∣ ∂p+1

∂xp+1f(y)

∣∣∣∣ ,where C is a constant independent of I and f .

1.9 Implementation of the L2−Projection

We describe the assembling of the mass matrix M with entries

Mij =

∫I

φj · φi where φi(x) =

x−xi−1

hi, x ∈ Ii,

xi+1−xihi+1

, x ∈ Ii+1,

0, otherwise.

-

6

xi−3 xi−2 xi−1 xi xi+1

1 φiφi−1

Page 17: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

14 CHAPTER 1. LECTURE 1 AND 2

We compute the entries. First, observe that Mij = 0 if |i− j| > 1. For Mii we get

Mii =

∫I

φ2i =

∫Ii−1

(x− xi−1

hi

)2

dx+

∫Ii

(xi+1 − xhi+1

)2

dx

=1

h2i

[(x− xi−1)3

3

]xixi−1

+1

h2i+1

[−(xi+1 − xi)3

3

]xi+1

xi

=hi3

+hi+1

3, i = 1, ..., N − 1.

M00 =hi3

and MNN =hN3.

Sine the matrix M is symmetric, it remains to calculate Mi+1,i.

Mi+1,i =

∫I

φi · φi+1 =

∫Ii

(xi+1 − xhi+1

)·(x− xihi+1

)dx

=1

h2i+1

[−(xi+1 − x)2

2(x− xi)

]xi+1

xi

− 1

h2i+1

∫ xi+1

xi

−(xi+1 − x

2

)2

dx

1

h2i+1

[(xi+1 − x)3

6

]xi+1

xi

=hi+1

6, i = 0, ..., N.

We obtain a tridiagonal matrix:

M =

h13

h16

0 · · · 0h16

h13

+ h23

h26

. . ....

0. . . . . . . . . 0

.... . . . . . hN

6

0 · · · 0 hN6

hN3

.

Observe that M can written in the following localized structure:

M =

h13

h16

h16

h13

+

h23

h26

h26

h23

+ ... +

hN3

hN6

hN6

hN3

.

We can therefore easily identify the local contribution from an element Ii anddenote this contribution by M Ii , i.e.

M Ii :=1

6

(2 11 2

)hi (local mass matrix).

Algorithm:

Page 18: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

1.9. IMPLEMENTATION OF THE L2−PROJECTION 15

1. Allocate memory for a (N + 1)× (N + 1) matrix.

2. For i = 1, ..., N :

Compute M Ii = 16

(2 11 2

)hi.

Add M Ii1,1 to Mi,i

M Ii1,2 to Mi,i+1

M Ii2,1 to Mi+1,i

M Ii2,2 to Mi+1,i+1

end.

Assembly of local vectorWe use the trapezoidal rule for assembling an approximation of the exact right

hand side vector for the L2−projection. An exact entry of the right hand side isgiven by

bi :=

∫I

f · φi =

∫ xi

xi−1

f · φi +

∫ xi+1

xi

f · φi.

Using the trapezoidal rule and φi(xi−1) = φi(xi+1) = 0, we can approximate bi by

bi ≈f(xi−1)φi(xi−1) + f(xi)φi(xi)

2(xi − xi−1) +

f(xi)φi(xi) + f(xi+1)φi(xi+1)

2(xi+1 − xi)

= f(xi)hi + hi+1

2.

The approximate right hand side b is therefore given by:

b :=

f(x0)h1

2

f(x1)h1+h22

...

f(xN−1)hN−1+hN2

f(xN)hN2

=

f(x0)f(x1)

0...0

h1

2

︸ ︷︷ ︸bI1

+

0

f(x1)f(x2)

0...

h2

2

︸ ︷︷ ︸bI2

+ ... +

0...0

f(xN−1)f(xN)

hN2

︸ ︷︷ ︸bIN

.

Algorithm:

Page 19: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

16 CHAPTER 1. LECTURE 1 AND 2

1. Allocate memory for a (N + 1)× 1 vector.

2. For i = 1, ..., N :

Compute bIi = 12

(f(xi−1)f(xi)

)hi.

Add bIi1 to bi−1

bIi2 to bi

end.

1.10 Exercise 4.1 - Cauchy-Schwarz inequality

We prove the estimate ∣∣∣∣∫Ω

u · v∣∣∣∣ ≤ ‖u‖L2(I) · ‖v‖L2(I)

for all u, v ∈ L2(I).

Proof. Assume ‖v‖L2(I) 6= 0 (otherwise trivial). Let λ ∈ R. We get

0 ≤ ‖u− λv‖2L2(I) = ‖u‖2

L2(I) − 2λ

∫Ω

u · v + λ2‖v‖2L2(I). (1.10.1)

Now let

λ :=

∫Ωu · v

‖v‖2L2(I)

(trick!)

which makes (1.10.1) to read

0 ≤ ‖u‖2L2(I) − 2

(∫Ωu · v

)2

‖v‖2L2(I)

+

(∫Ωu · v

)2

‖v‖2L2(I)

.

Multiplying with ‖v‖2L2(I) yields

0 ≤ ‖u‖2L2(I)‖v‖2

L2(I) −(∫

Ω

u · v)2

,

which directly implies ∫Ω

u · v ≤ ‖u‖L2(I)‖v‖L2(I).

Page 20: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Chapter 2

Lecture 3 and 4

Finite Element Method in 1D

Summary:

• derive the Finite Element Method,

• study the error,

• implementation of the method.

Model problem: Find u ∈ C2(0, 1) such that

−u′′(x) = f(x), x ∈ I := (0, 1),

u(0) = u(1) = 0. (2.0.1)

Even in 1D it might be difficult or impossible to solve equations of type (2.0.1).We therefore seek a numerical approximation.

2.1 Weak formulation of the problem

We call a function v ∈ C0(0, 1) weakly differentiable if there exists a function wwith

∫I|w| <∞ and such that∫

I

v · φ′ = −∫I

w · φ

for all φ ∈ C1(0, 1) with φ(0) = φ(1) = 0. We write v′ := w for the weak derivativeof v. Let

V0 := v ∈ C0(0, 1)| ‖v‖L2(I) <∞, ‖v′‖L2(I) <∞ and v(0) = v(1) = 0,

17

Page 21: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

18 CHAPTER 2. LECTURE 3 AND 4

where v′ denote the weak derivative. Multiplying (2.0.1) with a test functionv ∈ V0 and integration over I yields:∫

I

f · v =

∫I

−u′′ · v IP=

∫I

u′ · v′ − u′(1)v(1) + u′(0)v(0) =

∫I

u′ · v′.

The weak form reads: find u ∈ V0 s.t.∫I

u′ · v′ =∫I

f · v for all v ∈ V0. (2.1.1)

Comments:

1. If u is strong solution (i.e. solution of (2.0.1)), then it is also weak solution.

2. If u is a weak solution with u ∈ C2(I), it is also strong solution.

3. Existence and uniqueness of weak solutions is obtained by the Lax-Milgram-Theorem.

4. We can consider solutions with lower regularity using the weak formulation.

5. FEM gives an approximation of the weak solution.

In the following, we use the notation ‖ · ‖L2(I) := ‖ · ‖.

2.2 The Finite Element Method

Let Vh,0 := v ∈ Vh| v(1) = v(0) = 0, where

Vh := c ∈ C0(I)| v|Ii ∈ P1(Ii).

Find uh ∈ Vh,0 s.t. ∫I

u′h · v′ =∫I

f · v for all v ∈ Vh,0. (2.2.1)

We call uh the Finite Element Approximation of u.

2.3 Derivation of the discrete system

Problem (2.2.1) is equivalent to: find uh ∈ Vh,0 s.t.∫I

u′h · φ′i =

∫I

f · φi for 1 ≤ i ≤ N − 1.

Page 22: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

2.4. BASIC A PRIORI ERROR ESTIMATE 19

Note that the index is only from 1 to N−1, because of the zero boundary condition!Now, let uh =

∑N−1j=1 ξjφj. Then∫

I

f · φi =

∫I

(N−1∑j=1

ξjφ′j

)· φ′i =

N−1∑j=1

ξj

∫I

φ′j · φ′i for 1 ≤ i ≤ N − 1.

Let A ∈ R(N−1)×(N−1) and b ∈ RN−1 be given by the entries

Ai,j :=

∫I

φ′j · φ′i for 1 ≤ i, j ≤ N − 1,

bi :=

∫I

f · φi for 1 ≤ i ≤ N − 1.

We have

bi =N−1∑j=1

Ai,jξj for 1 ≤ i ≤ N − 1.

The algebraic problem reads therefore: find ξ ∈ RN−1

b = Aξ.

A is called the stiffness matrix.

Algorithm

1. Initiate a mesh with N elements.

2. Compute A and b.

3. Solve the system Aξ = b.

4. Set uh =∑N−1

j=1 ξjφj.

2.4 Basic a priori error estimate

We study the error e := u− uh.

Theorem 2.4.1.uh ∈ Vh,0 satisfies the Galerkin orthogonality:∫

I

(u− uh)′ · v′h = 0 for all vh ∈ Vh,0. (2.4.1)

Page 23: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

20 CHAPTER 2. LECTURE 3 AND 4

Proof. Since Vh,0 ⊂ V0 we obtain from (2.1.1) and (2.2.1) that∫I

u′ · v′h =

∫I

f · vh for all vh ∈ Vh,0,∫I

u′h · v′h =

∫I

f · vh for all vh ∈ Vh,0.

Subtracting both equations gives the result.

Theorem 2.4.2.It holds

‖(u− uh)′‖L2(I) ≤ ‖(u− vh)′‖L2(I) for all vh ∈ Vh,0.

Proof. With u− uh = u− vh + vh − uh we obtain

‖(u− uh)′‖2L2(I) = ((u− uh)′, (u− uh)′)

= ((u− uh)′, (u− vh)′) + ((u− uh)′, (vh − uh)′)︸ ︷︷ ︸=0, because of (2.4.1).

≤ ‖(u− uh)′‖L2(I)‖(u− vh)′‖L2(I).

Dividing by ‖(u− uh)′‖L2(I) finishes the proof. (If ‖(u− uh)′‖L2(I) = 0, the resultis trivial.)

Theorem 2.4.3 (A priori error estimate).It holds

‖(u− uh)′‖2L2(I) ≤

N∑i=1

h2i ‖u′′‖2

L2(Ii).

Note: even though we do not prove it, the solution u of (2.1.1) has a second weakderivative in the weak sense. Therefore, the above equation is justified.

Page 24: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

2.5. MATHEMATICAL MODELING AND BOUNDARY CONDITIONS 21

Proof. We have by Theorem 2.4.2

‖(u− uh)′‖2L2(I) ≤ ‖(u− Π(u))′‖2

L2(I) ≤N∑i=1

h2i ‖u′′‖2

L2(Ii),

where we used the estimate from Proposition 1.4.1.

The error is expressed in terms in terms of the exact solution. If it is expressedin terms of the computed solution uh it is an a posteriori error estimate (this yieldsa computable error bound). We will return to this.

We note:

1. uh → u in the ‖v′‖-norm as (max1≤i≤N hi)→ 0. If ‖(u− uh)′‖L2(I) = 0 thenuh − u is constant, but since u(0) = uh(0) we also have u − uh = 0 andtherefore uh = u.

2. uh is the best approximation within the space Vh,0 with respect to the ‖v′‖-norm.

3. The error e = u− uh is orthogonal to Vh,0 in the (v′, w′) scalar product.

4. The norm ‖v′‖ is referred to as the energy norm and has often a physicalmeaning.

2.5 Mathematical modeling and boundary con-

ditions

Stationary heat equation:

0 x0

-

x1

-

L

q(x0) q(x1)

Heat source f

Page 25: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

22 CHAPTER 2. LECTURE 3 AND 4

Let q denote the heat flux along the x-axis. The conservation of energy yields:

q(x0)− q(x1) +

∫ x1

x0

f(x) dx = 0.

and therefore ∫ x1

x0

q′(x) dx+

∫ x1

x0

f(x) dx = 0.

The heat flux is proportional to the negative temperature gradient q = −kT ′,where k is the thermal conductivity, i.e. heat flows from hot to cold. This givesus

−∫ x1

x0

(kT ′)′(x) dx =

∫ x1

x0

f(x) dx.

Since the interval [x0, x1] was arbitrary, we get

− (kT ′)′(x) = f(x) for all x ∈ I = (0, L).

Boundary conditions

There are three important types of boundary conditions (BC):

1. Dirichlet: T (0) = α and T (L) = β for two real numbers α and β. This BC isalso known as strong BC or essential BC. The temperature is kept a constantvalue at the boundary points (temperature regulator).

2. Neumann: T ′(0) = α and T ′(L) = β for two real numbers α and β. This BCis also known as natural BC. If T ′(0) = 0 then q(0) = 0, which means thatwe do not have flow over the boundary (no flow in, no flow out).

3. Robin: T ′(0) = αT (0) and T ′(L) = βT (L) for two real numbers α and β. Itsays that the flux is proportional to the heat - the larger the heat the largerthe flow.

Note that any combination is possible at the two boundary points.

Page 26: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

2.6. MODEL PROBLEMWITH COEFFICIENT ANDGENERAL ROBIN BC23

2.6 Model problem with coefficient and general

Robin BC

Model problem:

−(au′)′ = f in I := (0, 1),

a(0)u′(0) = κ0(u(0)− g0),

a(1)u′(1) = κ1(u(1)− g1),

where a = a(x) with a(x) ≥ a0 > 0, f ∈ L2(I), κ0, κ1 ≥ 0. We derive the weakform. Let

V := v ∈ C0(0, 1)| ‖v‖L2(I) <∞ and ‖v′‖L2(I) <∞,

where v′ denotes the weak derivative. Multiplying with v ∈ V and integrationyield: ∫ 1

0

fv =

∫ 1

0

−(au′)′v =

∫ 1

0

au′v′ − a(1)u′(1)v(1) + a(0)u′(0)v(0)

=

∫ 1

0

au′v′ − κ1(u(1)− g1)v(1) + κ0(u(0)− g0)v(0)

for all v ∈ V . We gather all u-independent terms on the left and obtain∫ 1

0

au′v′ + κ0u(0)v(0)− κ1u(1)v(1) =

∫ 1

0

fv + κ0g0v(0)− κ1g1v(1)

for all v ∈ V .

Implementation:Let for simplification a = 1. We need to assemble a stiffness matrix A and a

load vector b. Let therefore uh =∑N

j=0 ξjφj and v = φi for i = 0, ..., N (observethat the sum is from 0 to N !). We get:

Aξ = b

with A ∈ R(N+1)×(N+1) and b ∈ RN+1 given by the entries

Ai,j :=

∫ 1

0

φ′jφ′i + κ0φj(0)φi(0)− κ1φj(1)φi(1),

bi :=

∫ 1

0

fφi + κ0g0φi(0)− κ1g1φi(1),

Page 27: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

24 CHAPTER 2. LECTURE 3 AND 4

where 0 ≤ i, j ≤ N . Since

φi(x) =

x−xi−1

hi, x ∈ Ii,

xi+1−xhi+1

, x ∈ Ii+1,

0, otherwise.

We have

φ′i(x) =

1hi, x ∈ Ii,− 1hi+1

, x ∈ Ii+1,

0, otherwise.

We note that ∫ 1

0

φ′iφ′i =

∫ xi

xi−1

(φ′i)2 +

∫ xi+1

xi

(φ′i)2 =

1

hi+

1

hi+1

for i = 0, ..., N , and∫ 1

0

φ′iφ′i+1 =

∫ 1

0

φ′i+1φ′i =

∫ xi+1

xi

−1

hi+1

1

hi+1

=−1

hi+1

,

for i = 0, ..., N − 1. The terms κ0φj(0)φi(0) are only non-zero entries for i = j = 0and κ1φj(1)φi(1) is non-zero for i = j = N . We therefore get:

A =

κ0 + 1h1

− 1h1

0 · · · 0

− 1h1

1h1

+ 1h2− 1h2

. . ....

0. . . . . . . . . 0

.... . . . . . − 1

hN

0 · · · 0 − 1hN

1hN− κ1

.

If we use the trapezoidal rule for b, we get

b =

f(x0)h1

2+ κ0g0

f(x1)h1+h22

...

f(xN−1)hN−1+hN2

f(xN)hN2− κ1g1.

.

Page 28: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

2.7. A POSTERIORI ERROR ESTIMATE AND ADAPTIVITY 25

We assemble the matrix A in the same way as M : Observe that M can written inthe following localized structure:

A =1

h1

1 −1−1 1

+1

h1

1 −1−1 1

+

... +1

hN

1 −1−1 1

+

κ0

−κ1

.

Algorithm:

1. Allocate memory for a (N + 1)× (N + 1) matrix A.

2. For i = 1, ..., N :

Compute AIi = 1hi

(1 −1−1 1

).

Add AIi1,1 to Ai,i

AIi1,2 to Ai,i+1

AIi2,1 to Ai+1,i

AIi2,2 to Ai+1,i+1

end.

Add κ0 to A0,0 and −κ1 to AN,N .

3. Assemble b as before and solve Aξ = b.

2.7 A posteriori error estimate and adaptivity

We go back to the original model problem to find u (weakly) such that

−u′′ = f, in I := (0, 1),

u(0) = u(1) = 0.

Page 29: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

26 CHAPTER 2. LECTURE 3 AND 4

Proposition 2.7.1. It holds

‖(u− uh)′‖2 ≤N∑i=1

Ri(uh)2,

where the element residual is given by

Ri(uh) := hi · ‖f + u′′h‖L2(Ii).

Note that u′′h = 0 for piecewise linear Vh.

Proof. Let e := u− uh and observe that (e− Π(e))(xi) = 0 for every node xi (weuse that subsequently). We get with Galerkin orthogonality and the estimatesfrom Proposition 1.3.1:

‖e′‖2 =

∫ 1

0

e′e′ =

∫ 1

0

e′(e′ − Π(e)′)

=N∑i=1

∫ xi

xi−1

e′(e− Π(e))′

=N∑i=1

∫ xi

xi−1

(−e′′)︸ ︷︷ ︸=f+u′′h

(e− Π(e)) + [e′ (e− Π(e))︸ ︷︷ ︸=0 in nodes

]xixi−1

≤N∑i=1

‖f + u′′h‖L2(Ii)‖e− Π(e)‖L2(Ii)

≤N∑i=1

‖f + u′′h‖L2(Ii)h2i ‖e′′‖L2(Ii)

=N∑i=1

‖f + u′′h‖2L2(Ii)

h2i .

Adaptive mesh refinement

We want to use the bound to increase the number of nodes on the ’right ares’. Westart from:

‖(u− uh)′‖2 ≤N∑i=1

h2i · ‖f + u′′h‖2

L2(Ii),

Algorithm:

Page 30: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

2.7. A POSTERIORI ERROR ESTIMATE AND ADAPTIVITY 27

1. Given a coarse mesh of N nodes.

2. While N ’not too large’

Compute uh,

Compute Ri := hi · ‖f + u′′h‖L2(Ii),

Select and refine Ii where Ri is big

end.

How to select and refine?

Example: let 0 ≤ α ≤ 1. If Rj > αmaxi=1,...,N Ri then split Ii into two, i.e.Inew,1i := [xi,

xi+xi+1

2] and Inew,2i := [xi+xi+1

2, xi+1].

Original grid

Refined grid

Page 31: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

28 CHAPTER 2. LECTURE 3 AND 4

Page 32: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Chapter 3

Lectures 5 and 6

Piecewise polynomial approximation in 2D

Summary:

• construct mesh,

• construct the space Vh,

• interpolation,

• L2-projection

• implementation.

3.1 Meshes

Let Ω ⊂ R2 bounded with ∂Ω assumed to be polygonal.A triangulation Th of Ω is a set of triangles T such that

Ω =⋃T∈Th

T

and two triangles intersect by either a common triangle edge, or a corner, ornothing. Corners will be referred to as nodes. We let hT :=diam(T ) the length orthe largest edge.

3.2 Data structure for mesh

Let Th have N nodes and M triangles. The data is stored in two matrices. Thematrix P ∈ R2×N describes the nodes, i.e. the nodes (x1, y1), · · · (xN , yN) form the

29

Page 33: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

30 CHAPTER 3. LECTURES 5 AND 6

entries:

P =

(x1 x2 · · · xNy1 y2 · · · yN

)and the matrix K ∈ R3×M describes the triangles, i.e. it describes which nodes(numerated from 1 to N) form a triangle T and how it is orientated:

K =

nα1 nα2 · · · nαMnβ1 nβ2 · · · nβMnγ1 nγ2 · · · nγM

.

This means that triangle Ti is formed by the nodes nαi , nβi and nγi (enumerationin counter-clockwise direction).

@@

@@@

@@@

aTT

Example:

s

s

s

s

s

s

s

s@@@@@@

@@@@@@

@@@@@@

N1 = (0, 0) N2 = (1, 0) N3 = (2, 0)

N4

= (0, 1)

N5 = (1, 1) N6 = (2, 1)

N7 = (0, 2) N8 = (1, 2)

s

s

s

s

s

s

sT1

T2

T3

T4

T5

T6

That implies for our example:

P =

(0 1 2 0 1 2 0 10 0 0 1 1 1 2 2

)and

K =

1 2 2 3 4 52 5 3 6 5 84 4 5 5 7 7

.

Page 34: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

3.3. MESH GENERATION 31

3.3 Mesh generation

In 2D given a set of nodes, the Delaunay algorithm gives a triangulation of quality,(a large smalls angle ’worst element’).

Matlab has a built in toolbox called ’PDE Tool Box’ and includes a mesh genera-tion algorithm.

1. Define geometry:

geom =

2 2 2 2 2 20 2 2 1 1 02 2 1 1 0 00 0 1 1 2 20 1 1 2 2 01 1 1 1 1 10 0 0 0 0 0

←− polygon←− x coordinate 1←− x coordinate 2←− y coordinate 1←− y coordinate 2←− domain to the right←− domain to the left

’domain to the right = 1’ means: to the right of the edge is R2 \ Ω.’domain to the left = 0’ means: to the left of the edge is Ω.

(0, 0) 1 (2, 0)

6 (1, 1)

2

(2, 1)

4

3

(0, 2) 5 (1, 2)

2. [p, e, t] =initmesh(geom, ’hmax’, 0.1 ), where e denotes the edge matrix.

3. pdemesh(p, e, t)

3.4 Piecewise polynomial spaces

Let T be a triangle with nodes

N1 = (x1, y1), N2 = (x2, y2), N3 = (x3, y3).

Page 35: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

32 CHAPTER 3. LECTURES 5 AND 6

@@

@@@

@@@

(x1, y1)

(x2, y2)

(x3, y3)

T

We define

P1(T ) := v ∈ C0(T )| v(x, y) = c1 + c2x+ c3y, c1, c2, c3 ∈ R.

Now let vi = v(Ni) for i = 1, 2, 3. Note that v ∈ P1(T ) is determined by vi3i=1.

Given vi we compute ci by1 x1 y1

1 x2 y2

1 x3 y3

c1

c2

c3

=

v1

v2

v3

.

This is solvable due to

det

1 x1 y1

1 x2 y2

1 x3 y3

= 2|T | 6= 0.

Let λj ∈ P1(T ) be given by the nodal values

λj(Ni) =

1 i = j

0 i 6= j.

This gives us

v(x, y) = α1λ1(x, y) + α2λ2(x, y) + λ3(x, y),

where αiv(Ni) for i = 1, 2, 3.

Example:

@@@@@@

(0, 0) (1, 0)

(0, 1)s

ss T

Page 36: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

3.5. INTERPOLATION 33

The basis functions are λ1(x, y) = 1− x− y, λ2(x, y) = x and λ3(x, y) = y.

Let Th be a triangulation of Ω, then we let

Vh := v ∈ C0(Ω)| ∀T ∈ Th : v|T ∈ P1(T ).

Functions in Vh are piecewise linear and continuous. We know that v ∈ Vh isuniquely determined by v(Ni)| i = 1, · · · , N. We let

φj(Ni) =

1 i = j

0 i 6= j

and let φj| 1 ≤ j ≤ N ⊂ Vh be a basis for Vh (’hat functions’), i.e.:

v(x, y) =N∑i=1

αiφi(x, y), αi = v(Ni), i = 1, · · · , N.

3.5 Interpolation

Given f ∈ C0(T ) on a single triangle with nodes Ni = (xi, yi), i = 1, 2, 3, we let

Π(f) :=3∑i=1

f(Ni)φi

in particular Π(f)(Ni) = f(Ni).

We want to estimate f − Π(f). Wirst we need to measure derivatives in 2D. Let

|Df | :=

(∣∣∣∣∂f∂x∣∣∣∣2 +

∣∣∣∣∂f∂y∣∣∣∣2) 1

2

|D2f | :=

(∣∣∣∣∂2f

∂2x

∣∣∣∣2 + 2

∣∣∣∣ ∂2f

∂x∂y

∣∣∣∣2 +

∣∣∣∣∂2f

∂2y

∣∣∣∣2) 1

2

and let ‖f‖L2(Ω) =(∫

Ω|f(x)|2 dx

) 12 .

Proposition 3.5.1. For f ∈ C2(T ), it holds:

‖f − Π(f)‖L2(T ) ≤ Ch2T‖D2f‖L2(T ),

‖D(f − Π(f))‖L2(T ) ≤ ChT‖D2f‖L2(T ),

where C is a generic constant independent of hT and f , but that depends on theratio between smallest and largest interior angle of the triangle T .

Page 37: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

34 CHAPTER 3. LECTURES 5 AND 6

Proof. Not in this course.

Now, we consider the piecewise continuous interpolant Π(f) =∑N

i=1 f(Ni)φi.

Proposition 3.5.2. For f ∈ C0(Ω), with f ∈ C2(T ) for all T ∈ Th, it holds

‖f − Π(f)‖2L2(Ω) ≤ C

∑T∈Th

h4T‖D2f‖2

L2(T ),∑T∈Th

‖D(f − Π(f))‖2L2(T ) ≤ C

∑T∈Th

h2T‖D2f‖2

L2(T ),

where C is a generic constant independent of h and f , but that depends on theratio between smallest and largest interior angle of the triangles of Th.

Proof. An immediate consequence of Proposition 3.5.1.

3.6 L2-projection

Let Ph : L2(Ω)→ Vh be the L2-projection with Ph(f) ∈ Vh given s.t.∫Ω

(f − Ph(f))vh = 0 for all vh ∈ Vh. (3.6.1)

Linear system:

Problem (3.6.1) is equivalent to∫Ω

(f − Ph(f))φi = 0 for i = 1, · · · , N

and Ph(f) can be expressed as Ph(f) =∑N

i=1 ξiφi, where ξi (for i = 1, · · · , N) aregiven by the equation∫

Ω

fφi =

∫Ω

N∑i=1

ξiφiφj =N∑i=1

ξi

∫Ω

φiφj.

Let M ∈ RN×N and b ∈ RN be given by

Mi,j :=

∫Ω

φjφi for i, j = 1, · · ·N,

bi :=

∫Ω

fφi for i = 1, · · ·N.

Page 38: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

3.7. EXISTENCE AND UNIQUENESS OF THE PROJECTION 35

This gives us∑N

j=1 ξjMi,j = bi for j = 1, · · · , N and leads to

Mξ = b.

Algorithm for L2-projection:

1. generate triangulation and Vh,

2. compute M and b,

3. solve Mξ = b,

4. set Ph(f) =∑N

i=1 ξφi.

3.7 Existence and uniqueness of the projection

Theorem 3.7.1.For any f ∈ L2(Ω) the L2-projection Ph(f) exists and is unique.

Proof. Uniqueness: assume Ph(f)1 and Ph(f)2 be two solutions with the L2-projection property. We obtain:∫

Ω

Ph(f)1vh =

∫Ω

fvh for all vh ∈ Vh,∫Ω

Ph(f)2vh =

∫Ω

fvh for all vh ∈ Vh.

This gives us ∫Ω

(Ph(f)1 − Ph(f)2)vh = 0 for all vh ∈ Vh.

Choosing vh = Ph(f)1 − Ph(f)2 gives us

‖Ph(f)1 − Ph(f)2‖L2(Ω) = 0

and therefore Ph(f)1 = Ph(f)2.

Existence: Ph(f) is given by a N ×N linear system Mx = b. We just saw

Mx = 0 ⇐⇒ x = 0,

but this implies that the kernel is zero and therefore we have existence for arbitraryright hand side b.

Page 39: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

36 CHAPTER 3. LECTURES 5 AND 6

3.8 A priori error estimate

Theorem 3.8.1.Let f ∈ L2(Ω) and let Ph(f) be the L2-projection of f , then

‖f − Ph(f)‖ ≤ ‖f − vh‖ for all vh ∈ Vh.

Proof. As in 1D let f − Ph(f) = f − vh + vh − Ph(f) and observe

‖f − Ph(f)‖2 =

∫Ω

(f − Ph(f))(f − vh + vh − Ph(f))

=

∫Ω

(f − Ph(f))(f − vh) +

∫Ω

(f − Ph(f))(vh − Ph(f))

=

∫Ω

(f − Ph(f))(f − vh)

≤ ‖f − Ph(f)‖‖f − vh‖ for all vh ∈ Vh.

Theorem 3.8.2.For f ∈ C0(Ω), with f ∈ C2(T ) for all T ∈ Th, it holds

‖f − Ph(f)‖2L2(Ω) ≤ C

∑T∈Th

h4T‖D2f‖2

L2(T ),

with a generic constant C.

Proof. Use Theorem 3.8.1 and Proposition 3.5.2 to obtain:

‖f − Ph(f)‖2L2(Ω) ≤

∑T∈Th

‖f − Π(f)‖2L2(T ) ≤ C

∑T∈Th

h4T‖D2f‖2

L2(T ).

Page 40: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

3.9. QUADRATURE AND NUMERICAL INTEGRATION 37

Theorem 3.8.3.The mass matrix M is symmetric and positive definite.

Proof. The symmetry is obvious by Mi,j = Mj,i. The positive definite property,i.e. xTMx > 0 for all x ∈ RN \ 0, can be verified by:

xTMx =N∑

i,j=1

xiMi,jxj =N∑

i,j=1

xixj

∫Ω

φiφj

=

∫Ω

(N∑i=1

xiφi

)(N∑i=j

xjφj

)

= ‖N∑i=1

xiφi‖2L2(Ω) ≥ 0,

where xTMx = 0 only if∑N

i=1 xiφi = 0, which is only the case if xi = 0 fori = 1, · · · , N .

3.9 Quadrature and numerical integration

In general∫Tf(x) dx ≈

∑j ωjf(qj)|T |, where the ωj’s denote the weights, the qj’s

the quadrature points and |T | the area.

Examples:

1. Midpoint rule:∫T

f(x) dx ≈ f(xT )|T |, with midpoint x =N1 +N2 +N3

3.

2. Corner rule:∫T

f(x) dx ≈3∑i

f(Ni)|T |3, with triangle corners Ni.

3. Gauss quadratures: Gauss quadratures are designed with general points andweights so that they are exact for polynomials of a given degree.

Page 41: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

38 CHAPTER 3. LECTURES 5 AND 6

3.10 Implementation details

Assembly of mass matrix M with

Mi,j =

∫Ω

φjφi for i, j = 1, · · ·N.

Useful formula (without proof): let m,n, p ∈ N and let φT,1, φT,2 and φT,3 denotethe three basis functions that belong to the three corners of the triangle T . Thenit holds: ∫

T

φmT,1 φnT,2 φ

pT,3 =

2m!n! p!

(m+ n+ p+ 2)!|T |. (3.10.1)

Example:

sN1 = (0, 0)

sN2 = ( 3

4, 0)

sN3 = (1, 0)

sN4 = (1, 1)N5 = (0, 1)sT1

T2 T3

M =

∫Ω

φ1φ1 φ1φ2 φ1φ3 φ1φ4 φ1φ5

φ2φ1 φ2φ2 φ2φ3 φ2φ4 φ2φ5

φ3φ1 φ3φ2 φ3φ3 φ3φ4 φ3φ5

φ4φ1 φ4φ2 φ4φ3 φ4φ4 φ4φ5

φ5φ1 φ5φ2 φ5φ3 φ5φ4 φ5φ5

=∑T∈Th

∫T

φ1φ1 φ1φ2 φ1φ3 φ1φ4 φ1φ5

φ2φ1 φ2φ2 φ2φ3 φ2φ4 φ2φ5

φ3φ1 φ3φ2 φ3φ3 φ3φ4 φ3φ5

φ4φ1 φ4φ2 φ4φ3 φ4φ4 φ4φ5

φ5φ1 φ5φ2 φ5φ3 φ5φ4 φ5φ5

=

∫T1

φ1φ1 0 0 φ1φ4 φ1φ5

0 0 0 0 00 0 0 0 0

φ4φ1 0 0 φ4φ4 φ4φ5

φ5φ1 0 0 φ5φ4 φ5φ5

+

∫T2

φ1φ1 φ1φ2 0 φ1φ4 0φ2φ1 φ2φ2 0 φ2φ4 0

0 0 0 0 0φ4φ1 φ4φ2 0 φ4φ4 0

0 0 0 0 0

+

∫T3

0 0 0 0 00 φ2φ2 φ2φ3 φ2φ4 00 φ3φ2 φ3φ3 φ3φ4 00 φ4φ2 φ4φ3 φ4φ4 00 0 0 0 0

=: MT1 +MT2 +MT3 .

Page 42: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

3.10. IMPLEMENTATION DETAILS 39

Using formula (3.10.1), we obtain∫T

φiφj =1

12(1 + δij)|T | for i, j = 1, 2, 3,

where δij = 1 for i = j and δij = 0 for i 6= j. This gives us

MTi =1

12

2 1 11 2 11 1 2

|Ti|Algorithm for Mass matrix

• Construct P and K matrices.

• Allocate memory for M (N ×N)

• for T ∈ Th:

MT =1

12

2 1 11 2 11 1 2

|T |M(T (1 : 3), T (1 : 3)) = M(T (1 : 3), T (1 : 3)) +MT .

end

Remark: ’M(T (1 : 3), T (1 : 3)) = M(T (1 : 3), T (1 : 3)) +MT ’ is Matlab notation.

Page 43: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

40 CHAPTER 3. LECTURES 5 AND 6

Page 44: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Chapter 4

Lecture 7, 8 and 9

Finite Element Method in 2D

Summary:

• weak formulation,

• finite element method,

• error estimation,

• implementation,

• adaptivity.

4.1 Weak formulation

First, we derive the so called Green’s formula from the Divergence Theorem (StokesTheorem).

Let d = 1, 2, 3 and Ω ⊂ Rd be a bounded domain with Lipschitz-continuous bound-ary ∂Ω and unit outer normal n. The Divergence Theorem says:∫

Ω

∂f(x)

∂xidx =

∫∂Ω

f(x) · ni dσ(x), i = 1, .., d.

Let f = u · v for two sufficiently regular (i.e. H1(Ω)) functions u and v. Then weobtain:∫

Ω

(∂u

∂xi

)v dx = −

∫Ω

u

(∂v

∂xi

)dx+

∫∂Ω

u · v · ni dσ(x), i = 1, .., d.

41

Page 45: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

42 CHAPTER 4. LECTURE 7, 8 AND 9

Now let u = wi be the components of a vector-valued function. We sum overi =, 1.., d and obtain:∫

Ω

(∇ · w) v dx =d∑i=1

∫Ω

(∂wi∂xi

)v dx

= −d∑i=1

∫Ω

wi

(∂v

∂xi

)dx+

∫∂Ω

wi · v · ni dσ(x)

= −∫

Ω

w · ∇v dx+

∫∂Ω

v w · n dσ(x).

Now let w = −a∇u for given functions a and u. We obtain:

−∫

Ω

(∇ · (a∇u)) v dx =

∫Ω

a∇u · ∇v dx−∫∂Ω

v (a∇u) · n dσ(x). (4.1.1)

For the special case a = 1, this formula is called Green’s formula.

General elliptic equation of second orderFind u s.t.

−∇ · (a∇u) + bu = f in Ω, (4.1.2)

a∇u · n = κ(g − u) on ∂Ω,

where a > 0, b ≥ 0, κ ≥ 0, f ∈ L2(Ω) and g ∈ C0(∂Ω).

We seek a weak solution in

V := H1(Ω) := v ∈ L2(Ω)| v has a weak derivative and ‖v‖L2(Ω) + ‖∇v‖L2(Ω) <∞.

In order to derive the weak formulation we multiply (4.1.2) with v ∈ V , integrateover Ω and use (4.1.1):∫

Ω

fv dx = −∫

Ω

∇ · (a∇u)v dx+

∫Ω

buv dx

=

∫Ω

a∇u∇v dx+

∫Ω

buv dx−∫∂Ω

n · a∇u v dσ(x)

=

∫Ω

a∇u∇v dx+

∫Ω

buv +

∫∂Ω

κ(u− g) v dσ(x).

We obtain the weak form: find u ∈ V s.t.∫Ω

a∇u∇v dx+

∫Ω

buv dx+

∫∂Ω

κu v dσ(x) =

∫Ω

fv dx+

∫∂Ω

κg v dσ(x) ∀v ∈ V.

(4.1.3)

Page 46: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.2. FINITE ELEMENT METHOD 43

4.2 Finite Element Method

We can formulate the method as in the 1D case by using the weak formulation(4.1.3).

Definition 4.2.1 (Finite Element Method in 2D).Find uh ∈ Vh s.t.∫

Ω

a∇uh∇vh dx+

∫Ω

buhvh dx+

∫∂Ω

κuh vh dσ(x) (4.2.1)

=

∫Ω

fvh dx+

∫∂Ω

κg vh dσ(x) ∀vh ∈ Vh.

Implementation

Let a = 1 and b = g = 0. Then we have uh =∑N

i=1 ξiφi. We pick φj in (4.2.1) andobtain:

N∑i=1

ξi

(∫Ω

∇φi · ∇φj dx+

∫∂Ω

κφi φj dσ(x)

)=

∫Ω

fφj for 1 ≤ j ≤ N.

This gives us the system

(A+R) ξ = b, where

A ∈ RN×N , R ∈ RN×N and b ∈ RN are given by the entires

Ai,j :=

∫Ω

∇φj · ∇φi dx, Ri,j :=

∫∂Ω

κφi φj dσ(x),

bj :=

∫Ω

fφj, for 1 ≤ i, j ≤ N.

Assembly of the stiffness matrix

We can again identify the local contributions that come form a particular triangleT :

ATi,j :=

∫T

∇φi · ∇φj, for i, j = 1, 2, 3.

Page 47: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

44 CHAPTER 4. LECTURE 7, 8 AND 9

@@

@@@

@@@

(x1, y1)

(x2, y2)

(x3, y3)

T

We have φi(x, y) = ai + bix + ciy, for i = 1, 2, 3. Let us denote αi := (ai, bi, ci).We know

φi(Nj) =

1 i = j

0 i 6= j,

which gives us

Bαi =

1 x1 y1

1 x2 y2

1 x3 y3

aibici

=

100

= ei.

In general we have Bαi = ei for i = 1, 2, 3. Furthermore, we obviously have

∇φi =

(bici

),

which gives

ATi,j = (bibj + cicj)|T | for i, j = 1, 2, 3.

AlgorithmLet N be the number of nodes and M the number of triangles.

1. Allocate memory for a N ×N matrix A.

2. For K ∈ Th:

Compute ∇φKi = (bi, ci)K for i = 1, 2, 3. Set

AK :=

(b21 + c2

1) (b1b2 + c1c2) (b1b3 + c1c3)(b2b1 + c2c1) (b2

2 + c22) (b2b3 + c2c3)

(b3b1 + c3c1) (b3b2 + c3c2) (b23 + c2

3)

|T |.

Page 48: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.2. FINITE ELEMENT METHOD 45

Add A(T (1 : 3, K), T (1 : 3, K)) = A(T (1 : 3, K), T (1 : 3, K)) + AK .

end.

Assembly of boundary matrix

Let Γouth denote the set of boundary edges of the triangulation, i.e.

Γouth := E|E = T ∩ ∂Ω, for T ∈ Th.

Assume that κ is constant on E. For E ∈ Γouth , we define RE ∈ R2×2 by the entries

REi,j :=

∫E

κφiφj dσ(x) = κ1

6(1 + δi,j)|E|, for i, j = 1, 2,

where δi,j is 1 for i = j and 0 else.

In Matlab structure:

e =

nα1 nα2 nα3 · · · nαJnβ1 nβ2 nβ3 · · · nβJx1

x2

bnd10

|T |.

J denotes the number of boundary edges (boundary segments).

Algorithm

For j = 1, .., J :

Compute |E| given p(:, e(1 : 2, j)).

Evaluate κ in midpoint (if it is not constant).

R(e(1 : 2, j), e(1 : 2, j)) = R(e(1 : 2, j), e(1 : 2, j)) + κ6

(2 11 2

)|E|.

end.

Page 49: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

46 CHAPTER 4. LECTURE 7, 8 AND 9

Assembly of Load Vector

We use a one-point quadrature rule for approximating the integral. We obtain forT ∈ Th:

bTj =

∫T

fφj ≈ f(Nj)|T |3, for j = 1, 2, 3.

Algorithm

For i = 1, ..,M :

Compute |K|.

b(t(1 : 3, i)) = b(t(1 : 3, i)) +

f(N i1)

f(N i2)

f(N i3)

|K|3

.

end.

Given A, R and b, we can solve

(A+R)ξ = b

and write uh =∑N

i=1 ξφi.

4.3 The Dirichlet Problem

Find u s.t.

−4u = f in Ω, (4.3.1)

u = g on ∂Ω.

We seek the (weak) solution in:

Vg := v ∈ V | v|∂Ω = g.

Multiplying (4.5.1) with a test function v ∈ V0 and integrating gives us:∫Ω

fv =

∫Ω

−4uv =

∫Ω

∇u · ∇v −∫∂Ω

(∇u · n)v =

∫Ω

∇u · ∇v.

Page 50: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.4. THE NEUMANN PROBLEM 47

So the weak problem reads: find u ∈ Vg s.t.∫Ω

fv =

∫Ω

∇u · ∇v for all v ∈ V0.

Finite Element Method:

Assume that g is piecewise linear on ∂Ω with respect to the triangulation. Thenour FEM approximation is uh ∈ Vh,g := v ∈ Vh| v|∂Ω = g with∫

Ω

fvh =

∫Ω

∇uh · ∇vh for all v ∈ Vh,0.

Assume that we have N nodes and J boundary nodes, then the matrix formof the FEM problem reads:

A0,0 A0,g

Ag,0 Ag,g

N − J

J

N − J J

A0,0 A0,g

Ag,0 Ag,g

ξ0

ξ1

=

b0

b1

with A0,0 ∈ R(N−J)×(N−J), Ag,g ∈ RJ×J , A0,g ∈ R(N−J)×J and Ag,0 ∈ RJ×(N−J).Note that ξ ∈ RJ is known (it contains the values of g in the boundary nodes).We can therefore solve the simplified problem reading: find ξ0 ∈ R(N−J) with

A0,0ξ0 = b0 − A0,gξg.

In Matlab let int = 1 : N − J , bnd N − J + 1 : N .

A = A(int ,int ).b = b(int )− A(int ,bnd ) ∗ g.U(int )= A \ b, U(bnd )= g.

4.4 The Neumann Problem

Find u s.t.

−4u = f in Ω, (4.4.1)

∇u · n = g on ∂Ω.

Page 51: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

48 CHAPTER 4. LECTURE 7, 8 AND 9

In order to guarantee solvability, we note that∫Ω

f · 1 +

∫∂Ω

g =

∫Ω

−4u · 1 +

∫∂Ω

(∇u · n)1 dσ(x) =

∫Ω

∇u · ∇1 = 0.

We therefore nee to assume the compatibility condition∫Ω

f · 1 +

∫∂Ω

g = 0.

to ensure that a solution can exist. Note that if u exists, it is only determined upto a constant, since u + c is a solution if u is a solution and c ∈ R. We thereforedefine the solution space:

V := v ∈ V |∫

Ω

v(x) dx = 0.

This space guarantees a unique weak solution (with weak formulation as usualwith test functions in V ). Numerically the zero-average can be realized via socalled Lagrange-multipliers.

4.5 Elliptic Problems with a Convection Term

Find u s.t.

−∇ · (a∇u) + b · ∇u+ cu = f in Ω, (4.5.1)

u = 0 on ∂Ω.

Weak formulation: find u ∈ V0 := v ∈ V | v|∂Ω = 0 s.t.∫Ω

a∇u · ∇v +

∫Ω

(b · ∇u)v +

∫Ω

c u · v =

∫Ω

fv for all v ∈ V0.

The FEM approximation is given by uh ∈ Vh,0 := vh ∈ Vh| (vh)|∂Ω = 0 solving∫Ω

a∇uh · ∇vh +

∫Ω

(b · ∇uh)vh +

∫Ω

c uh · vh =

∫Ω

fvh for all vh ∈ Vh,0.

With the ansatz uh =∑N

j=1 ξjφj and v = φi in the weak formulation, we get

N∑j=1

ξj

(∫Ω

a∇φj · ∇φi +

∫Ω

(b · ∇φj)φi +

∫Ω

c φj · φi)

=

∫Ω

fφi for 1 ≤ i ≤ N.

Page 52: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.6. EIGENVALUE PROBLEM 49

Let therefore A,B,C ∈ RN×N , R ∈ RN×N be given by the entires

Ai,j :=

∫Ω

a∇φi · ∇φj dx, Bi,j :=

∫Ω

(b · ∇φi) · φj dx,

Ci,j :=

∫Ω

cφiφj dx, Fj :=

∫Ω

fφj, for 1 ≤ i, j ≤ N.

We solve

(A+B + C)ξ = F.

Note that B is not symmetric, i.e.

Bi,j =

∫Ω

(b · ∇φi) · φj dx 6=∫

Ω

(b · ∇φj) · φi dx = Bj,i.

4.6 Eigenvalue Problem

Find λ ∈ R and u s.t.

−4u = λu in Ω, (4.6.1)

∇u · n = 0 on ∂Ω.

Weak formulation: we multiply the equation with a test function v ∈ V andintegrate over Ω to obtain:

−∫

Ω

∇u · ∇v = λ

∫Ω

uv for all v ∈ V.

The FEM approximation is given by uh ∈ Vh and Λ ∈ R s.t.

−∫

Ω

∇uh · ∇vh = Λ

∫Ω

uhvh for all vh ∈ Vh.

This leads to an algebraic system of the structure

Aξ = ΛMξ,

i.e. an algebraic eigenvalue problem. In Matlab egg or digs can be used.

Page 53: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

50 CHAPTER 4. LECTURE 7, 8 AND 9

4.7 Error analysis and adaptivity

Model problem: find u s.t.

−4u = f in Ω,

u = 0 on ∂Ω.

Weak solution: find u ∈ V0 s.t.∫Ω

∇u · ∇v =

∫Ω

fv for all v ∈ V0.

FEM approximation: find uh ∈ Vh,0 with∫Ω

∇uh · ∇vh =

∫Ω

fvh for all v ∈ Vh,0.

Linear system of equations

We choose v = φi, with i = 1, .., N , where span(φiNi=1) = Vh,0. Now, find

uh =∑N

i=1 ξiφi s.t.:

N∑i=1

ξi

(∫Ω

∇φi · ∇φj dx)

=

∫Ω

fφj for 1 ≤ j ≤ N.

This gives us the system

Aξ = b,

where A ∈ RN×N and b ∈ RN are given by the entires

Ai,j :=

∫Ω

∇φi · ∇φj dx, bj :=

∫Ω

fφj, for 1 ≤ i, j ≤ N.

Theorem 4.7.1.The stiffness matrix A is symmetric and positive definite.

Page 54: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.7. ERROR ANALYSIS AND ADAPTIVITY 51

Proof. The symmetry of A is trivial.

xTAx =N∑i=1

N∑j=1

xiAijxj =N∑i=1

xixj

∫Ω

∇φi · ∇φj

=

∫Ω

(N∑i=1

xi∇φi

(N∑j=1

xj∇φj

)=

∫Ω

(N∑i=1

xiφi

)· ∇

(N∑j=1

xjφj

)

= |∇

(N∑i=1

xiφi

)|2 ≥ 0,

where equality holds only for x = 0, since we are in Vh,0.

A priori error bound

Theorem 4.7.2.Let u ∈ V0 denote the weak solution and uh ∈ Vh,0 the corresponding FEM approx-imation. It holds: ∫

Ω

∇(u− uh) · ∇vh = 0 for all vh ∈ Vh,0. (4.7.1)

Proof. By definition of weak solution and FEM approximation we get∫Ω

∇u · ∇v =

∫Ω

fv for all v ∈ Vh,0 ⊂ V0,∫Ω

∇uh · ∇vh =

∫Ω

fvh for all vh ∈ Vh,0.

Subtracting both equations gives the result.

Now let |||v|||2 :=∫

Ω∇v · ∇v be the energy norm on V0. Note that 0 is the

only constant in V0.

Theorem 4.7.3.Let u ∈ V0 denote the weak solution and uh ∈ Vh,0 the corresponding FEM approx-imation. It holds:

|||u− uh||| ≤ |||u− vh||| for all vh ∈ Vh,0.

Page 55: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

52 CHAPTER 4. LECTURE 7, 8 AND 9

Proof. We get for arbitrary vh ∈ Vh,0:

|||u− uh|||2 =

∫Ω

∇(u− uh) · ∇(u− uh)

(4.7.1)=

∫Ω

∇(u− uh) · ∇(u− vh)C.S.≤ ‖|u− uh‖|‖|u− vh‖|.

Theorem 4.7.4.Let u ∈ V0 denote the weak solution and uh ∈ Vh,0 the corresponding FEM approx-imation. If u ∈ C2(Ω) it holds:

|||u− uh|||2 ≤ C∑T∈Th

h2T‖D2u‖2

L2(T ),

where C is independent of hT and u.

Proof. Let v = Π(u) ∈ Vh,0 in Theorem 4.7.3. By the interpolation estimates forΠ we obtain

|||u− uh||| ≤ |||u− Π(u)||| =∑T∈Th

||D(u− Π(u))||2L2(T ) ≤ C∑T∈Th

h2T‖D2u‖2

L2(T ).

Note that uh → u for h→ 0. This means |||u− uh||| ∼ h.

Adaptive Finite Element Methods

Preliminary results:

There exists an interpolation operator Π (Clement-type interpolation) mapping toVh,0, that fulfills the interpolation bound:

‖v − Π(v)‖L2(T ) ≤ ChT‖Dv‖L2(ωT ),

where ωT :=⋃K ∈ Th|T ∩K 6= ∅ and C is constant that is independent of hT

and v.

Page 56: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.7. ERROR ANALYSIS AND ADAPTIVITY 53

Trace inequality:

‖v − Π(v)‖L2(∂T ) ≤ Ch12T‖Dv‖L2(ωT ),

where C is again a generic constant.

Jump of functions: let vh ∈ Vh be piecewise linear, then

[n · ∇vh]∂T1∩∂T2 := nT1 · (∇vh)|T1 + nT2 · (∇vh)|T2 .

Observe that nT1 = −nT2 on ∂T1 ∩ ∂T2.

@@@@@@@@

@@@

@@@

@@

T1 T2

- nT1

nT2

(∇vh)|T1(∇vh)|T2

Theorem 4.7.5 (A posteriori error estimate).It holds

|||u− uh|||2 ≤ C∑T∈Th

RT (uh)2,

where C is a (computable) constant that is independent of hT and

RT (uh)2 := h2

T‖f +4uh‖2L2(T ) +

1

4hT‖[n · ∇uh]‖2

L2(∂T\∂Ω).

Page 57: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

54 CHAPTER 4. LECTURE 7, 8 AND 9

Proof. Let e := u− uh. We get:

|||e|||2 =

∫Ω

∇e · ∇e =

∫Ω

∇e · ∇(e− Π(e))

=∑T∈Th

∫T

∇e · ∇(e− Π(e))

(4.1.1)=

∑T∈Th

∫T

4e (e− Π(e)) +∑T∈Th

∫∂T\∂Ω

(n · ∇e)(e− Π(e)) dσ(x)

=∑T∈Th

∫T

(f +4uh) (e− Π(e)) +∑T∈Th

∫∂T\∂Ω

(n · ∇e)(e− Π(e)) dσ(x).

Note that ∑T∈Th

∫∂T\∂Ω

(n · ∇u)(e− Π(e)) dσ(x) = 0

since [n · ∇u] = 0 because of u ∈ C2. We conclude

|||e|||2 =∑T∈Th

∫T

(f +4uh) (e− Π(e))︸ ︷︷ ︸=:I

−∑T∈Th

∫∂T\∂Ω

(n · ∇uh)(e− Π(e)) dσ(x)︸ ︷︷ ︸=:II

.

Let Γh denote the set of interior edges, i.e.

Γh := E := T ∩K|T,K ∈ Th, and E contains more than one point.

We start with estimating II:

II = −∑T∈Th

∫∂T\∂Ω

(n · ∇uh)(e− Π(e)) dσ(x)

=∑E∈Γh

∫E

[n · ∇uh](e− Π(e)) dσ(x)

=1

2

∑T∈Th

∫∂T\∂Ω

[n · ∇uh](e− Π(e)) dσ(x)

≤ 1

2

∑T∈Th

‖[n · ∇uh]‖L2(∂T\∂Ω)‖e− Π(e)‖L2(∂T\∂Ω)

≤ C∑T∈Th

1

2‖[n · ∇uh]‖L2(∂T\∂Ω)h

12T‖∇e‖L2(ωT )

≤ C

(∑T∈Th

hT4‖[n · ∇uh]‖2

L2(∂T\∂Ω)

) 12

|||e|||.

Page 58: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

4.7. ERROR ANALYSIS AND ADAPTIVITY 55

Next, we deal with I:

I =∑T∈Th

∫T

(f +4uh) (e− Π(e))

≤ C∑T∈Th

hT‖f +4uh‖L2(T )‖∇e‖L2(T )

≤ C

(∑T∈Th

h2T‖f +4uh‖2

L2(T )

) 12

|||e|||.

Combining both estimates yields

|||e|||2 ≤ C

(∑T∈Th

h2T‖f +4uh‖2

L2(T ) +∑T∈Th

hT4‖[n · ∇uh]‖2

L2(∂T\∂Ω)

).

Adaptive algorithm

We want to refine the mesh where RT (uh) is large. Main difficulties are:

• no hanging nodes,

• ’good quality’ triangulations (e.g. avoid very small angles in the triangles).

There are several algorithms including

∗ Rivara refinement (largest edge),

∗ regular refinment.

A combination is used in Matlab.

Alg.:

1. Construct initial mesh Th.

2. Solve finite element problem for uh.

3. Compute local indicators RT (uh)2.

4. Compute maximum m := maxT∈Th RT (uh)2.

5. Mark elements with error over γ ·m, where 0 < γ < 1 is a fixed parameter.

Page 59: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

56 CHAPTER 4. LECTURE 7, 8 AND 9

6. Refine elements and get new mesh Th.

7. Return to step 2) (stop when N becomes too large or when the error∑T∈Th RT (uh)

2 is small enough)

Matlab syntax

Regard problems of the type

−∇ · (a∇u) + cu = f.

Step 3: indicator =pdejmps(p, t, a, c, f, uh, 1, 1, 1), the last three numbers stand for

the weighting constants c1 and c122 and m in hmT .

Step 6: [p, e, t] =refinemesh(geom, p, e, t, index). Here tol = γ ∗ max(indicator)and index =find(indicator > tol).

Page 60: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

Chapter 5

Lecture 10

Time dependent problems

Summary:

• Numerical methods for ODEs

• Heat equation

– Weak form

– FEM

– Implementation

• Wave equation

– Weak form

– FEM

– Implementation

5.1 Systems of Ordinary Differential Equations

Problem: find ξ(t) ∈ RN so that

M.ξ(t) + A(t)ξ(t) = f(t), t ∈ (0, T ]

ξ(0) = ξ0,

where M is constant and only A and f are time-dependent.

57

Page 61: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

58 CHAPTER 5. LECTURE 10

Let 0 = t0 < t1 < t2 < ... < tL = T be a discretization, let kn := tn − tn−1

for n = 1, ..., L be the time step size and let ξn ≈ ξ(tn) for n = 1, ..., L denotecorresponding approximations. We integrate in time to obtain∫ tn

tn−1

M.ξ(t) dt+

∫ tn

tn−1

A(t)ξ(t) dt =

∫ tn

tn−1

f(t) dt.

This yields

M(ξ(tn)− ξ(tn−1)) +

∫ tn

tn−1

A(t)ξ(t) dt =

∫ tn

tn−1

f(t) dt.

We can approximate this with the Euler scheme:

Backward Euler

M(ξn − ξn−1) + knA(tn)ξn = knf(tn)

or equivalently

Mξn − ξn−1

kn+ Anξ

n = fn

with An := A(tn) and fn := f(tn).

Algorithm

• Set 0 = t0 < t1 < ...tL = T .

• Let ξ0 = ξ(0). For n = 1, ..., L

solve (M + knAn)ξn = Mξn−1 + knfn,

end.

Alternative Schemes

• Backward Euler: (M + knAn)ξn = Mξn−1 + knfn.

• Forward Euler: Mξn = Mξn−1 − knAn−1ξn−1 + knfn−1.

Page 62: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

5.2. HEAT EQUATION 59

• Crank-Nicolson: (M + kn2An)ξn = (M − kn

2An−1)ξn−1 + kn

2(fn + fn−1),

here ∫ tn

tn−1

A(t)ξ(t) dt ≈ Anξnkn2

+ An−1ξn−1kn−1

2,∫ tn

tn−1

f(t) dt ≈ kn2

(fn + fn−1).

5.2 Heat equation

Find u = u(x, t) s.t.

.u−4u = f in Ω ⊂ R2, t ∈ (0, T ),

u(·, t) = 0 on ∂Ω and t ∈ (0, T ],

u(x, 0) = u0 for x ∈ Ω.

Let V0 := v| ‖v‖+‖∇v‖ <∞, v|∂Ω = 0. Multiplying the heat equation withv ∈ V and integrating over Ω yields∫

Ω

fv =

∫Ω

.uv −

∫Ω

4u · v =

∫Ω

.uv +

∫Ω

∇u · ∇v

for 0 < t < T . The weak form therefore reads: find u(t) ∈ V0 s.t. for all t > 0∫Ω

.uv +

∫Ω

∇u · ∇v =

∫Ω

fv for all v ∈ V0.

FEM

Find uh(t) ∈ Vh,0 s.t. for all t > 0∫Ω

.uhvh +

∫Ω

∇uh · ∇vh =

∫Ω

fvh for all vh ∈ Vh,0.

Let uh(t) =∑N

i=1 ξi(t)φi(x). Choosing vh = φj in the FEM formulation, we obtain:

N∑i=1

.ξi

∫Ω

φiφj +N∑i=1

ξi

∫Ω

∇φi · ∇φj =

∫Ω

fφj for 1 ≤ j ≤ N.

Note that

ξ(t) =

ξ1(t)...

ξN(t)

=

uh(x1, t)...

uh(xN , t)

,

Page 63: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

60 CHAPTER 5. LECTURE 10

where xi denotes the node that belongs to the basis function φi.

Let A,M ∈ RN×N and b(t) ∈ RN be given by the entries

Mi,j :=

∫Ω

φjφi, Ai,j :=

∫Ω

∇φj · ∇φi for i, j = 1, · · ·N,

bi :=

∫Ω

fφi for i = 1, · · ·N,

then we obtain the system

M.ξ(t) + Aξ(t) = b(t),

which we can e.g. solve with the Backward Euler method.

Algorithm:

Assume that only b is time-dependent (if it is not time-dependent, move its com-putation outside of the loop over n).

• Construct mesh and Vh,0.

• Compute M and A.

• Let ξ0 = ξ(0).

• For n = 1, ..., L

compute bn,

solve (M + knA)ξn = Mξn−1 + knbn,

(uh)n :=∑N

i=1 ξni φi,

end.

For ξ0 we can either use

ξ0 :=

ξ1(0)...

ξN(0)

=

u0(x1)...

u0(xN)

,

or we can let ξ0 to be the L2-projection of u0. We set (uh)0 :=∑N

i=1 ξ0i φi.

Page 64: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

5.3. WAVE EQUATION 61

Remark 5.2.1 (Stability).There hold continuous and discrete stability estimates:

‖u(·, t)‖ ≤ ‖u(·, 0)‖+

∫ t

0

‖f(·, s)‖ ds,

‖(uh)n‖ ≤ ‖(uh)n−1‖+ kn‖fn‖ ≤ ‖(uh)0‖+n∑i=1

ki‖fi‖.

5.3 Wave equation

Find u = u(x, t) s.t.

..u−∇ · (ε∇u) = f in Ω ⊂ R2, t ∈ (0, T ),

n · ∇u(·, t) = 0 on ∂Ω and t ∈ (0, T ],

u(x, 0) = u0 for x ∈ Ω,.u(x, 0) = v0 for x ∈ Ω,

where ε = ε(x, t) and f = f(x, t).

Weak form

Let V := v| ‖v‖ + ‖∇v‖ < ∞. Multiplying the wave equation with v ∈ V andintegrating over Ω yields with the Green’s formula∫

Ω

fv =

∫Ω

..uv −

∫Ω

∇ · (ε∇u)u · v =

∫Ω

..uv +

∫Ω

ε∇u · ∇v −∫∂Ω

(ε∇u · n)v.

for 0 < t < T . The weak form therefore reads: find u(t) ∈ V s.t. for all t > 0∫Ω

..uv +

∫Ω

ε∇u · ∇v =

∫Ω

fv for all v ∈ V.

FEM - semi-discrete

Find uh(t) ∈ Vh s.t. for all t > 0∫Ω

..uhvh +

∫Ω

ε∇uh · ∇vh =

∫Ω

fvh for all vh ∈ Vh.

Page 65: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

62 CHAPTER 5. LECTURE 10

We let uh(x, t) =∑N

j=1 ξj(t)φj(x), where

ξ(t) =

ξ1(t)...

ξN(t)

=

uh(x1, t)...

uh(xN , t)

.

This leads to

N∑i=1

..ξi

∫Ω

φiφj +N∑i=1

ξi

∫Ω

∇φi · ∇φj =

∫Ω

fφj for 1 ≤ j ≤ N.

We obtain the system

M..ξ(t) + Aξ(t) = b(t) for 0 < t < T,

where M denotes the mass matrix and A the stiffness matrix.

FEM - time discretization

We transform the problem into a first order system. Let therefore η(t) :=.ξ(t) and

consider the new coupled system:

M.ξ(t) = Mη(t), for 0 < t < T,

M.η(t) + A(t)ξ(t) = b(t), for 0 < t < T.

The application of the Crank-Nicholson scheme gives for n > 0:

Mξn − ξn−1

kn= M

ηn + ηn−1

2,

Mηn − ηn−1

kn+Anξ

n + An−1ξn−1

2=bn + bn−1

2.

In matrix form we get:(M −kn

2M

kn2An M

)︸ ︷︷ ︸

=:Wn

(ξn

ηn

)=

(M kn

2M

−kn2An−1 M

)(ξn−1

ηn−1

)+

(0

kn2

(bn + bn−1)

)︸ ︷︷ ︸

=:wn

.

Algorithm: Crank-Nicolson for the wave equation:

• Construct mesh and Vh,0.

• Compute M .

Page 66: Lecture notes for Finite Element Methods Autumn Term … · Lecture notes for Finite Element Methods Autumn Term 2013, ... ’The Finite Element Method: ... Note that typically fc

5.3. WAVE EQUATION 63

• Choose ξ0 = ξ(0) and η0 = η(0)

• For n = 1, ..., L

compute An and bn,

solve

Wn

(ξn

ηn

)= wn.

(uh)n :=∑N

i=1 ξni φi,

end.

Remark 5.3.1 (Conservation of mass).Let f = 0 and ε = 1, then

‖.u(·, t)‖2 + ‖∇u(·, t)‖2 = C,

where C is independent of t