Solution of Non-Homogeneous Dirichlet Problems with FEM

68
Master Thesis Solution of Non-Homogeneous Dirichlet Problems with FEM Francesco Z¨ uger Institut f¨ ur Mathematik Written under the supervision of Prof. Dr. Stefan Sauter and Dr. Alexander Veit August 27, 2013

Transcript of Solution of Non-Homogeneous Dirichlet Problems with FEM

Page 1: Solution of Non-Homogeneous Dirichlet Problems with FEM

Master Thesis

Solution of Non-Homogeneous Dirichlet Problems

with FEM

Francesco Zuger

Institut fur Mathematik

Written under the supervision ofProf. Dr. Stefan Sauter

andDr. Alexander Veit

August 27, 2013

Page 2: Solution of Non-Homogeneous Dirichlet Problems with FEM
Page 3: Solution of Non-Homogeneous Dirichlet Problems with FEM

Acknowledgment

I would like to thank Prof. Dr. S. Sauter for giving me the opportunity to write a master thesisabout this very interesting topic. He, together with Dr. A. Veit, helped me with very usefulhints along the way. I would also like to thank C. Lehrenfeld (developer of NetGen/NGSolve)for the (very prompt and exhaustive) explanations about the many features of the FEMsolver. Lots of thanks also to Simona Trefalt and Marco Bernasocchi, who transformed mypoor English into a readable text.

I would like to thank Noam Arnold as well: we attended many classes together and weworked in the same field for our master theses, which resulted in many discussions aboutFEM and NetGen/NGsolve that were very helpful.

Lastly I would like to thank my family who has supported me until now without pressure:I really appreciate their trust!

I

Page 4: Solution of Non-Homogeneous Dirichlet Problems with FEM

II

Page 5: Solution of Non-Homogeneous Dirichlet Problems with FEM

Contents

1 Preface 1

1.1 Introduction and Goal Setting . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 NetGen - NGSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.3 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Mathematical Framework 3

2.1 Partial Differential Equation (PDE) . . . . . . . . . . . . . . . . . . . . . . . 3

2.1.1 Classification of Second Order PDE . . . . . . . . . . . . . . . . . . . 4

2.1.2 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.1.3 Solution of Partial Differential Equations . . . . . . . . . . . . . . . . 5

2.2 Sobolev Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.3 Variational Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.4 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.4.1 Ritz-Galerkin Discretization . . . . . . . . . . . . . . . . . . . . . . . . 10

2.4.2 Finite Element Space . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.5 Convergence and Error Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 Non-Homogeneous Dirichlet Boundary Conditions 17

3.1 Solution Split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.1.1 Convergence and Error Estimator . . . . . . . . . . . . . . . . . . . . 20

3.1.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.1.3 Implementation in NGSolve . . . . . . . . . . . . . . . . . . . . . . . . 23

3.1.4 Model Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3.2 Approximation using Robin Boundary Conditions . . . . . . . . . . . . . . . . 29

3.2.1 Convergence and Error Estimate . . . . . . . . . . . . . . . . . . . . . 30

3.2.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.2.3 Implementation in NGSolve . . . . . . . . . . . . . . . . . . . . . . . . 32

3.2.4 Model Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3.3 Time Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3.3.1 CG Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3.3.2 Solution Split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3.3.3 Approximation with Robin Boundary Conditions . . . . . . . . . . . . 38

3.3.4 Numerical Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

III

Page 6: Solution of Non-Homogeneous Dirichlet Problems with FEM

IV CONTENTS

4 Model Problem 2 414.1 Setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.1.1 Periodic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414.1.2 Coefficient functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.2 Full Space Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424.3 Numerical Solution of the Unit Cell Problem . . . . . . . . . . . . . . . . . . 434.4 Dirichlet Problem on a Finite Domain . . . . . . . . . . . . . . . . . . . . . . 444.5 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

4.5.1 Unit Cell Problem Using Matlab . . . . . . . . . . . . . . . . . . . . . 454.5.2 Implementation Using NetGen/NGSolve . . . . . . . . . . . . . . . . . 46

4.6 Numerical Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474.6.1 Error Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474.6.2 Time Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

5 Conclusion 55

Bibliography 57

Appendix 59

Page 7: Solution of Non-Homogeneous Dirichlet Problems with FEM

Chapter 1

Preface

1.1 Introduction and Goal Setting

Many physical phenomena (heat, electrodynamics, fluid dynamics, · · ·) can be representedusing partial differential equations (PDEs). This is why many efforts have been made tofind appropriate tools to solve or approximate a given PDE. Thanks to its flexibility, thefinite element method (FEM) is nowadays one of the most commonly employed mathematicalmethod to approximate the solution of various problems.

In the current work we focus on the resolution of elliptic PDEs with non-homogeneousDirichlet boundary conditions, also referred to as non-homogeneous Dirichlet problems, whichindicate a problem where the searched solution has to coincide with a given function g onthe boundary of the domain. The “standard” FEM only allows to solve Dirichlet problemswith homogeneous boundary conditions, and some approaches were developed to also handlenon-homogeneous cases.

The goal of this work is to present possible ways to deal with non-homogeneous Dirichletproblems using FEM and to give the appropriate mathematical background. Central is thestudy of the convergence and error bounds for these methods. Moreover we performed somenumerical tests to investigate the convergence rate and the time performance of the possiblealgorithms, comparing these results with the statements from the theoretical part.

1.2 NetGen - NGSolve

For the computational part of the study we use NetGen and NGSolve. These are two opensource programs created by J. Schoberl and his team which work in a coupled way to solvePDEs with the FEM.

NetGen, the first of the two programs employed, is a mesh generator. For a given 2Dor 3D geometry it generates the regular triangulation needed to implement a finite elementspace and it can refine a given mesh using a bisection algorithm. Moreover, it is possible toimpose some a-priori refinement in particular areas of the domain along some edges or closeto a particular point, and also implement adaptive refinement algorithms.

NGSolve, the second of the programs used, is the coupled FEM-solver. It can solve varioustypes of PDEs and it is possible to implement additional features by modifying the sourcecode. It is for example possible to implement the resolution of time dependent problems.

1

Page 8: Solution of Non-Homogeneous Dirichlet Problems with FEM

2 CHAPTER 1. PREFACE

Both programs (and source-codes as well) can be downloaded from [Sch13a, Sch13b]. Onthe same websites it is also possible to consult a forum and a short “wiki”.

The official manual can be found in the documentation included in the installation files(ng4.pdf ). A more detailed manual, written by Noam Arnold can be found in [Arn12]: inparticular the author explains how to modify the source code to implement non-stationaryproblems.

1.3 Structure

The second chapter of this thesis is devoted to the introduction of the mathematical frame-work. The fundamentals of the FEM are summarized and the most useful error bounds arederived.

The third chapter covers the main topic of this thesis: possible methods to solve non-homogeneous Dirichlet problems are introduced and their convergence is analyzed. To testthe reliability of the error bounds and the time performance of the algorithm some test for afirst model problem are presented.

The fourth chapter is dedicated to the second model problem. Using this slightly morecomplex problem we verify the behavior of the methods to solve non-homogeneous Dirichletproblems.

The last chapter is a resume of the most important results and a short outlook on possiblefurther research in the area is given.

Page 9: Solution of Non-Homogeneous Dirichlet Problems with FEM

Chapter 2

Mathematical Framework

In this chapter the most important state-of-the-art results from the theory of the FEM aresummarized. In particular practical error bounds that will be tested in empirical applicationsin the next chapter are derived. For more details about the FEM, Braess [Bra07], Brennerand Scott [BS94] as well as other authors, provide self contained expositions.

2.1 Partial Differential Equation (PDE)

A differential equation is an equation whose unknown is a function depending on one or morevariables. We speak of PDE when the function depends on many variables and the probleminvolves partial derivatives.

The unknown function is noted by u and depends on the spatial variables x1, x2, · · · , xd.In case of a non-stationary problem, a time variable t is added. Within this master thesis wewill however only focus on stationary problems. For a shorter notation the spatial variablesare collected in the vector x ∈ Rd.

We denote the partial derivate by

∂iu(x) := ∂xiu(x) :=∂u(x)

∂xi1 ≤ i ≤ d.

We then define a general PDE by using a functional F as:

F (x1, · · · , xd, u, ∂1u, · · · , ∂du, ∂1∂1u, · · · , ∂1∂du, · · · ) = f.

The order of the highest derivative defines the order of the equation. Moreover, if F is alinear function of u and its derivatives, the PDE is called linear.

Example 2.1.1:Using the Laplace Operator ∆ given by

∆u(x) :=

d∑i=1

∂2

∂x2iu(x)

we can define the Potential or Laplace Equation as:

∆u = 0 in Ω ⊂ Rd.

This is a second order, linear PDE.

3

Page 10: Solution of Non-Homogeneous Dirichlet Problems with FEM

4 CHAPTER 2. MATHEMATICAL FRAMEWORK

2.1.1 Classification of Second Order PDE

The general, linear second order PDE can be described as follows:

−div(A gradu) + b · gradu+ cu = f in Ω ⊂ Rd, (2.1)

where

gradu(x) = ∇u(x) :=(∂u(x)

∂xi

)d

i=1

,

divv(x) :=

d∑i=1

∂vi(x)

∂xi.

The coefficient A : Ω → Rd×d is a matrix of real-valued functions, b : Ω → Rd is a vector ofreal-valued functions and c : Ω → R is a real valued function. Since for u ∈ C2 : ∂i∂ju = ∂j∂iu,the matrix A can be chosen w.l.o.g. to be symmetric.

The general second order PDE (2.1) can also be described as

−∇ · (A∇u) + b · ∇u+ cu = f (2.2)

Definition 2.1.2:The equation (2.1) is said to be:

1. elliptic in x ∈ Rd, if A(x) is positive definite or negative definite.

2. hyperbolic in x ∈ Rd, if d − 1 eigenvalue of A(x) are of the same sign and one is ofthe opposite sign.

3. parabolic in x ∈ Rd, if d− 1 eigenvalue of A(x) are of the same sign, one equals nulland Rang(A,b) = d.

4. elliptic in Ω ⊂ Rd, if A(x) for all x ∈ Ω is positive definite or if for all x ∈ Ω isnegative definite.

Such a classification is needed, since for every type of second order PDE, different ap-proaches have to be used to find the solution u. In the current thesis we only focus on thefourth case, i.e. elliptic equations.

Remark 2.1.3:Not every PDE can be classified via Definition 2.1.2.

Example 2.1.4:For the Laplace equation of Example 2.1.1, A is the identity matrix (always positive definite)and thus the Laplace equation is elliptic.

2.1.2 Boundary Conditions

Definition 2.1.5:A problem is said well-posed, if exactly one solution exists and it continuously depends onthe coefficients A,b, c and on the boundary condition [Bra07, p. 8].

Page 11: Solution of Non-Homogeneous Dirichlet Problems with FEM

2.1. PARTIAL DIFFERENTIAL EQUATION (PDE) 5

Typically, PDEs, if not provided with additional information, are not well-posed becausethe solution is not unique. Consider again the Laplace equation (which is linear): if u1 isa possible solution, then every scalar multiplication ku1, k ∈ R is also a solution (∆(ku1) =k∆(u1) = 0). Moreover if u2 is another possible solution, then every linear combinationku1 + ju2 for k, j ∈ R is a further solution of the same problem.

In order to have a unique solution we add further informations to the problem. In caseof an ordinary differential equation (ODE) we impose some initial conditions. Similarly weadd boundary condition for PDEs such that the problem has a unique solution. Since manyPDEs arise from physical problems, where the behaviour of the unknown function can beimposed or measured on the boundary, the corresponding PDE will be accordingly equippedwith some boundary conditions.

The most commonly used boundary conditions, defined over the boundary ∂Ω, are thefollowing ones:

• Dirichlet (or Essential) Boundary Conditions, defined as

u = g on ∂Ω.

In particular, if g = 0 we speak of homogeneous boundary conditions.

• Neumann (or Natural) Boundary Conditions, defined as

∂u

∂n= g on ∂Ω,

where n is the outward pointing unit normal vector on ∂Ω.

• Robin Boundary Conditions, defined as

γu+ α∂u

∂n= g on ∂Ω.

Even though in the literature this particular type of boundary conditions is not widelypresented, it allows us to approximate a non-homogeneous Dirichlet boundary condi-tions. This particular case will be discussed in the next chapter.

If the boundary can be divided in more disjoint parts ∂Ω = ∂Ω1 ∪ ∂Ω2 ∪ · · ·, differentboundary conditions can be imposed on each of the parts ∂Ωi. In this case, we speak of mixedboundary conditions.

Definition 2.1.6:A function, which satisfies a PDE as well as the boundary conditions is said classical solu-tion.

2.1.3 Solution of Partial Differential Equations

Even if PDEs, with suitable boundary conditions are well-defined, the solution of these prob-lems is far from being obvious. In some case it may also be proven that it is in fact impossibleto find an exact solution. Since many PDEs correspond to problems from the “real world”that need to be solved, many efforts were made to find possible methods to approximate theirsolution and to prove that the approximate solution converges to the exact one.

Page 12: Solution of Non-Homogeneous Dirichlet Problems with FEM

6 CHAPTER 2. MATHEMATICAL FRAMEWORK

In the 20th century two classes of approximation methods became popular: the finitedifference method and the finite element method (FEM). The former replaces the deriva-tives with a difference quotient, for example for one dimensional problems this correspondsto u′(x) ≈ u(x+h/2)−u(x−h/2)

h . Using this approximation one can derive a linear system ofequations and easily find an approximate solution ([Bra07, p. 15] and [SF08, p. 16]). Unfor-tunately it is not possible to derive sharp existence and uniqueness theorems and the methodis restricted to polygonal domains with only right angles (π2 or 3

2π).In this master thesis we focus on the FEM, which is much more flexible allowing us to

handle very complex problems. This method is based on the variational form: consider forexample the homogeneous Poisson problem −∆u = f in Ω, u = 0on ∂Ω. Multiplying the firstequation by some suitable function v vanishing at the boundary, taking the integral and usingthe Gaussian Theorem, we derive the variational form: find an admissible u (thus vanishingat the boundary) such that∫

Ω〈∇u,∇v〉 =

∫Ωfv for all test functions v.

Applying an ansatz u ≈∑

j qjϕj , where ϕj are basis functions for a finite dimensional sub-space of the admissible function space, the Galerkin discretization leads to a linear system ofequations

Mq = r

where (m)j,i =∫Ω ϕjϕi and (r)i =

∫Ω fϕi. The key point of the FEM is the choice of

the basis functions: each basis function ϕj (also referred to as “hat”-functions) is a piece-wise polynomial vanishing outside some “finite elements” (triangles or quadrilateral in 2D,polyhedral in 3D). With this choice the system matrix becomes sparse and iterative solverscan be applied efficiently.

2.2 Sobolev Space

In this section some notions and result from functional analysis that allow us to investigatethe mathematical background of the FEM are introduced. Assume Ω ⊂ Rd (d ≥ 2) is anopen, bounded domain. Let us introduce the notation for derivatives with multi-index; forα ∈ Nd

0 with |α| = α1 + · · ·+ αd:

Dαϕ :=∂|α|

∂xα11 ∂xα2

2 . . . ∂xαdd

ϕ.

Definition 2.2.1:Assume φ, ψ ∈ L2(Ω) and α is a multi-index. Then ψ is the (α-) weak derivative of φ(ψ = Dαφ), if ∫

Ωvψ = (−1)|α|

∫ΩDαvφ ∀v ∈ C∞

0 (Ω).

Remark 2.2.2: • If the α-weak derivative exists, then it is unique.

• If u ∈ C |α|, then the weak and the classical derivative coincide, which is why the samesymbol Dα is used.

Page 13: Solution of Non-Homogeneous Dirichlet Problems with FEM

2.2. SOBOLEV SPACE 7

• With the notion of weak derivatives we can define the derivative of some functions inL2 whose classical (point-wise) derivatives do not exist.

Example 2.2.3:Let Ω = [−1, 1]. The weak derivative of the function φ = 1− |x| is given by

D1φ(x) =

1 −1 ≤ x < 0,−1 0 < x ≤ 1.

The proof can be found in [BS94, p. 26].

Definition 2.2.4:For k ∈ N and p ∈ [1,∞), we define the Sobolev Space W k,p as

W k,p(Ω) := ϕ ∈ Lp(Ω) | ∀|α| ≤ k : Dαϕ ∈ Lp(Ω).

These spaces are equipped with the following norm:

‖ϕ‖Wk,p(Ω) :=

∑|α|≤k

‖Dαϕ‖pLp(Ω)

1p

and seminorm:

|ϕ|Wk,p(Ω) :=

∑|α|=k

‖Dαϕ‖pLp(Ω)

1p

.

The standard setting for our application will be p = 2 and for simplicity we write shortHk(Ω) := W k,2(Ω). If the domain is clear from the context we skip it in the notation of ourfunction spaces. We have H0 = L2 and the associated norms coincide. The H1-norm can bewritten according to

‖φ‖2H1 = ‖φ‖2L2 + |φ|2H1 =

∫φ2 +

∫(∇φ)2.

Lemma 2.2.5: • The Sobolev space W k,p, with the norm ‖ · ‖Wk,p is a complete normedvector space and thus a Banach space.

• Hk, provided with the scalar product (φ, ψ)Hk :=∑

|α|≤k(Dαφ,Dαψ)L2(Ω) is a Hilbert

space.

Proof: See [BS94, p.28].

Before discussing the variational form, we employ the trace theorem, which will enable usto define essential boundary conditions.

Definition 2.2.6:The domain Ω has a Lipschitz-boundary (or Ω is a Lipschitz-domain), if for N ∈ Nthere exists some open sets U1, · · · , UN ⊂ Rd such that

(1) ∂Ω ⊂ ∪Ni=1Ui,

Page 14: Solution of Non-Homogeneous Dirichlet Problems with FEM

8 CHAPTER 2. MATHEMATICAL FRAMEWORK

(2) ∂Ω∩Ui can be described as graph of a Lipschitz-continuous function for every 1 ≤ i ≤ N .

Trace Theorem 2.2.7:Let Ω be a Lipschitz-domain, k ∈ N, l ∈ 0, 1, · · · , k − 1 and n be the outward pointingnormal vector on ∂Ω. Then there exists a linear continuous map γl : W

k,p(Ω) → Lp(∂Ω) withthe following property

γl(ϕ) =∂

∂nlϕ ∀ϕ ∈ Ck(Ω). (2.3)

Proof: See [Alt12, S. 265].

From the trace theorem we can derive a very useful definition when dealing with homo-geneous Dirichlet boundary conditions.

Definition 2.2.8:Assume γl as in Theorem 2.2.7, then we define the Sobolev space with function vanishing atthe boundary as

W k,p0 (Ω) := ϕ ∈W k,p(Ω) | 0 ≤ l ≤ k − 1 : γl(ϕ) = 0.

In particular, for k = 1 and p = 2 it follows that:

W 1,20 =: H1

0 = u ∈ H1 : u|∂Ω = 0.

2.3 Variational Form

For the formulation of sharp existence and uniqueness theorems as well as to derive thenumerical discretization we have to convert the problem from the classical formulation to thevariational form. After analyzing the well-posedness, we will discuss under which assumptionsthe strong and the variational formulation coincide.

Definition 2.3.1:Let H be a Hilbert space (with norm ‖ · ‖). A bilinear form a : H ×H → R is

• bounded (or continuous) if there exists a constant C > 0 such that:

|a(u, v)| ≤ C‖u‖‖v‖ ∀u, v ∈ H,

• symmetric if:

a(u, v) = a(v, u) ∀u, v ∈ H.

A bounded bilinear form a is coercive (or elliptic) if there exists an α > 0 such that:

a(v, v) ≥ α‖v‖2 ∀v ∈ H.

Remark 2.3.2:For a bilinear form a(·, ·) we can define the energy norm as ‖v‖a =

√a(v, v).

With these assumptions at hand, we can state a key result for the FEM that ensuresexistence and uniqueness of the solution.

Page 15: Solution of Non-Homogeneous Dirichlet Problems with FEM

2.3. VARIATIONAL FORM 9

Lax-Milgram Theorem 2.3.3:Given a Hilbert space H, a bounded, coercive bilinear form a : H ×H → R and a linear forml : H → R, then the functional

I(u) :=1

2a(u, u)− l(u)

has a unique minimum u∗ ∈ H. This is the unique solution of the variational problem

a(u∗, v) = l(v) ∀v ∈ H. (2.4)

Proof: See [Bra07, p. 37].

The variational formulation is related to a minimization problem for the functional. Braess[Bra07, Charakterisierungssatz p.34] shows that if and only if u solves (2.4) then u is theunique minimum of I(v) and thus the two formulations are equivalent.

Definition 2.3.4:Consider an elliptic PDE given by (2.1) with smooth coefficients A,b and c such that

0 < λ := infx∈Ω

infz∈Rd\0

zTA(x)z

zT z≤ sup

x∈Ωsup

z∈Rd\0

zTA(x)z

zTz=: Λ <∞

holds for some λ,Λ. Then

• u ∈ H10 (Ω) is a weak solution of (2.1) with homogeneous Dirichlet boundary conditions

if: ∫Ω(A∇u) · ∇v + (b · ∇u) v + cuv =

∫Ωfv ∀v ∈ H1

0 (Ω), (2.5)

• u ∈ H1(Ω) is a weak solution of (2.1) with Neumann boundary conditions if:∫Ω(A∇u) · ∇v + (b · ∇u) v + cuv =

∫Ωfv +

∫∂Ωgv ∀v ∈ H1(Ω). (2.6)

By setting a(u, v) =∫Ω (A∇u) · ∇v + (b · ∇u) v + cuv and l(v) =

∫Ω fv, respectively

l(v) =∫Ω fv +

∫∂Ω gv we see that (2.5) and (2.6) are of the form (2.4).

Remark 2.3.5:The Dirichlet boundary conditions are also called “essential” because they are “build” directlyin the space H1(Ω); on the other hand Neumann boundary conditions are called “natural”because the solution of the corresponding variational form satisfies the condition in a weakform (2.6).

Lemma 2.3.6:Consider an elliptic PDE given by (2.1) with homogeneous Dirichlet Boundary conditions andthe corresponding weak formulation from Definition 2.3.4. Assume that A ∈ L∞(Ω,Rd×d) andsymmetric, b = 0 and c ∈ L∞(Ω) with c ≥ 0. Then:

(1) every classical solution is also a weak solution. Every weak solution which lies in C2(Ω)∩C0(Ω) is also a classical solution.

Page 16: Solution of Non-Homogeneous Dirichlet Problems with FEM

10 CHAPTER 2. MATHEMATICAL FRAMEWORK

(2) For every f ∈ L2(Ω) there exists a unique weak solution in H10 .

Proof: (1) see [Bra07, Minimaleigenschaft p. 35].

(2) After proving that a(·, ·) is a bounded, coercive bilinear form we can apply the Lax-Milgram Theorem (see [Bra07, Existenzsatz p. 39]).

For PDEs with Neumann boundary conditions (or mixed boundary conditions) we canderive existence and uniqueness in a similar way (see [Bra07, p. 43]).

2.4 Discretization

For a given Hilbert space H, bounded, coercive bilinear form a : H × H → R and a linearform l : H → R, let us consider the problem in the variational form: find u ∈ H such thata(u, v) = l(v) for every v ∈ H, where Ω is a polyhedral domain with Lipschitz-boundary ∂Ω.Note that for the FEM it is standard to use H1(Ω) (or a proper subspace) as solution spaceand, for shorter notation, the domain Ω is sometimes omitted.

2.4.1 Ritz-Galerkin Discretization

To approximate the solution u we construct a finite dimensional space Sh ⊂ H1 (respectivelySh0 ⊂ H1

0 for homogeneous Dirichlet boundary conditions) such that Sh has a basis denotedby (ϕ)Nj=1 so that N = dim(Sh). To approximate the solution u ∈ H1 we employ the ansatz:

u ≈ uh =

N∑j=1

qjϕj ∈ Sh. (2.7)

Using (2.7) we can rewrite the variational form as:

a(uh, vh) = l(vh) ∀vh ∈ Sh,

since (ϕ)Nj=1 is a basis for Sh. This is equivalent to

a(uh, ϕi) = l(ϕi) ∀i = 1, 2, · · · , N. (2.8)

a(·, ·) is a bilinear form, which means that employing the ansatz (2.7), we get

N∑j=1

qja(ϕj , ϕi) = l(ϕi) ∀i = 1, 2, · · · , N.

This is a linear system of equations which we write in the compact formulation

Mq = r (2.9)

where (m)j,i = a(ϕj , ϕi) and (r)i = l(ϕi).

Page 17: Solution of Non-Homogeneous Dirichlet Problems with FEM

2.4. DISCRETIZATION 11

2.4.2 Finite Element Space

At this point the central issue is to find an appropriate finite element space Sh as the spanof some basis functions ϕj . In this section finite element spaces on polygonal domain in 2Dare introduced. For higher spatial dimension the approach is conceptually similar and can befound in the literature (for example see [BS94, Chapter 5]).

Definition 2.4.1: (1) A subdivision of a domain Ω is a finite collection of open sets τi,such that:

(i) τi ∩ τj = ∅ if i 6= j,

(ii)∪τi = Ω.

(2) A subdivision T = τi : 1 ≤ i ≤ mT (where τi are triangles) is a triangulation if novertex of any triangle lies in the interior of some edges of another triangle (see Figure2.1 (a)-(b)).

Moreover, if we define for every triangle τ ∈ T : hτ := supx,y∈τ ‖x − y‖ and ρτ as thediameter of the largest circle fitting in τ then

(3) T is regular triangulation if there exists a constant cT such that

hτρτ

≤ cT ∀τ ∈ T . (2.10)

For a regular triangulation, we define the maximal mesh width h (also referred to as meshsize) as follows:

h := maxτ∈T

hτ .

Remark 2.4.2: • The condition defined in (2.10) is equivalent to a minimal angle condi-tion (see Figure 2.1 (c)).

• For the subdivision for the FEM not only triangles, but also quadrilateral element canbe used [BS94, p. 82]. In higher dimensions higher dimensional simplices are employedto define a “triangulation”.

After subdividing the domain Ω by a regular triangulation (mesh) we now define the finiteelement spaces Sh ⊂ H1 and Sh

0 ⊂ H10 .

Definition 2.4.3:The finite element space of degree k is given by

Sh :=v ∈ C0(Ω)|∀τ ∈ T : v|τ ∈ Pk

, respectively (2.11)

Sh0 :=

v ∈ C0(Ω)|∀τ ∈ T : v|τ ∈ Pk

∩H1

0 (Ω), (2.12)

where Pk is the set of all polynomial in two variables of degree ≤ k.

For simplicity let us consider the linear case (k = 1). Let us denote by xl for l = 1, · · · , NTthe vertices of the triangles of the triangulation. As we will show, in the linear case, the verticescoincide with the nodal points needed to define the finite element space. The vertices (or in

Page 18: Solution of Non-Homogeneous Dirichlet Problems with FEM

12 CHAPTER 2. MATHEMATICAL FRAMEWORK

(a) Admissible triangula-tion

(b) Non-admissible trian-gulation

(c) Regular triangulation

Figure 2.1: Examples of triangulations. (a) shows an admissible triangulation while (b) showsa triangulation with a “hanging node”. (c) illustrates the definition of shape-regularity for atriangle.

general the nodal points) not lying on the boundary are numbered from 1 to NT (internalnodes), while the vertices from NT + 1 to NT lie on the boundary.

The restriction of every function v ∈ Sh in a triangle τ is an affine function. This functionon τ is uniquely determined by three linearly independent points, thus every polynomialp ∈ P1 is uniquely determined by the value at the three vertices. Consider now two trianglesτ1, τ2 having a common edge E; for p1, p2 ∈ P1 we define

ϕ :=

p1 in τ1,p2 in τ2.

Since the restriction of pi to an edge E is a linear function in one variable, then ϕ is continuousif and only if the value of p1 and p2 coincide on the vertices of E.

We can conclude that every function v ∈ Sh can be uniquely determined by the values atthe vertices xl and thus

dimSh = NT ,

where NT is also referred to as number of degrees of freedom. For homogeneous Dirichletboundary condition the value at vertices lying on the boundary has to be zero, thus dimSh

0 =NT .

The last issue is to find an appropriate basis for the finite element space. For some τ ∈ Tand i = 1, 2, 3 we define the following function:

λτ,i(x) :=det(xτi+1 − x,xτ

i−1 − xτi+1

)det(xτi+1 − xτ

i ,xτi−1 − xτ

i+1

)

Page 19: Solution of Non-Homogeneous Dirichlet Problems with FEM

2.5. CONVERGENCE AND ERROR BOUNDS 13

where xτi are the coordinates of the i-th vertex of τ (vertex numbered counter clockwise) and

the indices are to be interpreted in modulo 3. λτ,i has the property:

λτ,i ∈ P1, λτ,i(xτj ) =

1 i = j,0 i 6= j.

For any node xl we denote by ωl the union of the elements, i.e., triangles having xl as vertex:ωl :=

∪τ∈T ,xl∈τ τ .

We now define the basis functions for the finite element space as:

ϕl(x) :=

0 x /∈ ωl,λτ,j(x) x ∈ τ ⊂ ωl and xl = xτ

j .

This function is hat-shaped (continuous, piece-wise linear and vanishing outside ωl), ithas value 1 at xl and 0 for all other nodes. From the construction of ϕl we conclude that thefunctions ϕl is a basis for Sh:

Sh = span ϕl : 1 ≤ l ≤ NT .

Remark 2.4.4:Consider an elliptic PDE with homogeneous Dirichlet boundary conditions or with Neumannboundary conditions and the corresponding linear system of equations Mq = r resulting from(2.8), (2.9) using the finite element spaces described above.

(1) The system matrix M is symmetric and positive definite (see [Bra07, p. 51]).

(2) The unique solution of the basis representation (2.7) corresponds to the solution of thevariational form by means.

(3) The system matrix M is sparse: the entry mj,i = a(ϕj , ϕi) is non-zero only when themesh points xi and xj belongs to the same edge of the mesh.

Remark 2.4.5:For homogeneous Dirichlet boundary conditions, the value of the solution at the vertices lyingon the boundary must equal to zero, thus qj = 0 for all NT < j ≤ NT . Therefore:

Sh0 = v ∈ C0(Ω)|∀τ ∈ T : v|τ ∈ Pk and v(xl) = 0 for all nodes xl on the boundary.

When increasing the degree of the polynomials it is obvious that the values at the trianglevertices no longer allow to uniquely determine the polynomials pi ∈ Pk (see Table 2.1): itfollows that more constraints are needed. Using Lagrange elements we define a unisolventset of points on the edges between vertices or inside every triangle that allow us to uniquelyidentify each polynomial [BS94, p. 70]. More complex elements involving derivatives at thevertices of triangles are possible as well (Hermite elements, Argyris elements; see [BS94, p.73]).

2.5 Convergence and Error Bounds

In this section, we will prove that the approximate solution uh given by the FEM convergesto the weak solution u. For this, it is important to derive some bounds for the error ‖u−uh‖.

Page 20: Solution of Non-Homogeneous Dirichlet Problems with FEM

14 CHAPTER 2. MATHEMATICAL FRAMEWORK

k dimPk

1 32 63 10...

...k 1

2(k + 1)(k + 2)

Table 2.1: Dimension of Pk in two dimensions (from [BS94, p. 70]).

Cea’s Lemma 2.5.1:Let H be a Hilbert space and Sh ⊂ H a finite dimensional subspace. Let a bounded, coercivebilinear form a : H×H → R and a linear form l : H → R be given. Let u be the weak solutionof problem (2.4) and uh be the corresponding weak solution in the finite dimensional subspaceSh. Then

‖u− uh‖H ≤ C

αinf

vh∈Sh‖u− vh‖H , (2.13)

where C and α are the constants given in Definition 2.3.1.

Proof: See [BS94, p. 62].

We observe that the approximate solution is quasi-optimal, i.e. that the error is propor-tional to the best approximation in Sh.

We investigate the right hand-side of (2.13) in order to give a more useful error bounds.For this we define the interpolation operator Ik,h : Hk+1 → Sh, where Sh is a finite elementspace of degree k, as:

Ik,h(u) :=

NT∑j=1

u(xj)ϕj ,

where ϕj and xj again denote the basis functions and the nodes. For the interpolation errorwe derive the following bound.

Lemma 2.5.2:Given a regular triangulation T of Ω (see Definition 2.4.1) with maximal mesh width h andthe corresponding finite element space Sh with polynomials of maximal degree k; then, foru ∈ Hk+1, it holds

‖u− Ik,h(u)‖L2(Ω) ≤ C1hk+1‖u‖Hk+1(Ω),

‖u− Ik,h(u)‖H1(Ω) ≤ C2hk‖u‖Hk+1(Ω).

The constant C1, C2 depend on Ω, k and the regularity constant cT .

Proof: See [WM85, p. 189].

Since the error is quasi-optimal, in the finite dimensional space we can combine this resultwith (2.13) and derive the error bounds for conforming finite elements.

Page 21: Solution of Non-Homogeneous Dirichlet Problems with FEM

2.5. CONVERGENCE AND ERROR BOUNDS 15

Corollary 2.5.3:Let assume the same condition as in the Cea’s Lemma 2.5.1 and the condition of Lemma2.5.2. Then there exist constants C3, C4 such that

‖u− uh‖L2(Ω) ≤ C3hk+1‖u‖Hk+1(Ω),

‖u− uh‖H1(Ω) ≤ C4hk‖u‖Hk+1(Ω). (2.14)

Proof: See [WM85, p. 189].

Page 22: Solution of Non-Homogeneous Dirichlet Problems with FEM

16 CHAPTER 2. MATHEMATICAL FRAMEWORK

Page 23: Solution of Non-Homogeneous Dirichlet Problems with FEM

Chapter 3

Non-Homogeneous DirichletBoundary Conditions

In this chapter we explain how to handle non-homogeneous Dirichlet boundary conditions,i.e. when, at the boundary, the solution u must coincide with a function g not necessarilyequal to 0.

Assume Ω is a bounded domain in Rd (in our model problems we restrict to d = 2 butalso higher dimensional cases can be handled similarly) with a Lipschitz boundary ∂Ω. Thenconsider the following elliptic PDE:

Lu := −∇ · (α∇u) + cu = f in Ω,

u = g on ∂Ω. (3.1)

for some coefficient functions α, c sufficiently smooth such that:

0 < α0 ≤ α(x) ≤ α1

0 ≤ c0 ≤ c(x) ≤ c1

with α0, α1, c0, c1 ∈ R. For some p ≥ 2 and given f ∈ Lp(Ω) and g ∈ H2(Ω) the correspondingweak formulation [BE86, p. 344] is given by: find u ∈ H1

E(Ω) := w ∈ H1(Ω) : w = g on ∂Ωsuch that:

a(u, v) = l(v) ∀v ∈ H10 := w ∈ H1(Ω) : w = 0 on ∂Ω, (3.2)

where

a(w, v) := (α∇w,∇v)Ω + (cw, v)Ω,

l(v) := (f, v)Ω

and

(w, v)G :=

∫Gwv for some domain G.

If we use the same approach as in the homogeneous case the non-homogeneous boundaryconditions, being essential, must be imposed on the admissible functions, i.e. that everyadmissible function u must coincide with g on the boundary. With this assumption the set

17

Page 24: Solution of Non-Homogeneous Dirichlet Problems with FEM

18 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

of admissible functions, here H1E i.e. the set of functions in H1 which coincide with g on

the boundary, is no longer a linear but an affine space: the sum of two admissible functionsequals 2g on the boundary and thus do not coincide with the boundary conditions (see[SF08]). Clearly we cannot apply the same methods used in the homogeneous case to solvethis particular problem, but we need to develop additional tools.

[SF08, WM85, Fai78] describe two possible approaches to solve PDEs provided with non-homogeneous boundary conditions. The first option is to split the solution in two partsu = ug + u0. The first function coincides with the boundary conditions and the second oneis the solution of a modified elliptic PDE equipped with homogeneous boundary conditions(thus solvable using standard procedures). The second option is to approximate the boundaryconditions using appropriately chosen Robin boundary conditions with a penalty factor. Inthis case the test functions must not coincide with a function g on the boundary but we ensurethat the boundary conditions hold by adding suitable integrants in the linear and bilinearform.

One central issue is to investigate if the error estimates given at the end of the last chapterfor the homogeneous case still holds for non-homogeneous cases or if they need to be adapted.Moreover it is of interest to test the numerical efficiency of the possible methods.

3.1 Solution Split

Let us consider again the problem (3.2). The solution u lies in the set of admissible functionsH1

E , which in general is clearly not a subset of H10 . To describe this set we can choose any

member ug ∈ H1E (in particular ug takes the value g on the boundary), then every function

v ∈ H1E is determined by ug + v0 with v0 ∈ H1

0 (the difference between two functions in H1E

lies in H10 ). Thus [SF08, p. 70]:

H1E = ug ⊕H1

0 . (3.3)

Applying the Ritz-Galerkin discretization process we define the admissible functions vh(x) =ug(x) +

∑qjϕj(x) where ϕj are the basis functions for the finite element space. The admis-

sible class is then given by Sh = ug ⊕Sh0 for the finite dimensional space Sh

0 ⊂ H10 containing

functions vanishing at the boundary.To actually solve the non-homogeneous problem we can make the assumption u = u0+ug

and reformulate the weak formulation (3.2) as follows: find u0 ∈ H10 (respectively uh0 ∈ Sh

0 ),such that

a(u0, v) = l0(v) ∀v ∈ H10 ,

a(uh0 , vh) = l0(v

h) ∀v ∈ Sh0 , (3.4)

where

l0(v) = l(v)− a(ug, v) respectively l0 = l(vh)− a(ug, vh).

The problem (3.4) fullfils the assumptions of the Lax-Milgram Theorem, thus existence anduniqueness of the solution follow (see [Bra07, p. 40] or [WM85, p. 78]).

Remark 3.1.1:We define ug = g on ∂Ω with ug ∈ H1

E but g may not lie in H1E. One remedy is to project

Page 25: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.1. SOLUTION SPLIT 19

(e.g. via interpolation) the function g to the set H1E, then we can denote this approximation by

uhg ≈ ug. How to choose the function approximating the boundary conditions is an importantissue and various solutions are possible, some of which are given in the next example.

Example 3.1.2:The following example (from [WM85, Section 4.2.3]) shows how the function ug (or uhg ) areconstructed. For a parameter γ > 0, let us consider the following elliptic PDE:

∆u+ 2γ∂u

∂y= 0 in Ω =

(−π2,π

2

)2, (3.5)

subject to the boundary conditions:

u(±π2, y) = 0 |y| ≤ π

2,

u(x,−π2) = 0 |x| ≤ π

2,

u(x,π

2) =

(π2

)2− x2 |x| ≤ π

2.

On three edges, the boundary conditions are homogeneous, while on the upper edge (y = π2 )

they are given by the function g = (π/2)2 − x2.In this case, it is possible to find explicitly a function that matches exactly the boundary

conditions. For example consider

u(1)g (x, y) :=

((π2

)2− x2

)(π2+ y) 1

π,

clearly u(1)g satisfies the boundary conditions and thus we can modify (3.5) to a problem with

homogeneous Dirichlet boundary conditions:

∆u0 + 2γ∂u0∂y

= −∆u(1)g − 2γ∂u

(1)g

∂y= 2

(π2+ y)− 2γ

((π2

)2− x2

)in Ω =

(−π2,π

2

)2u0 = 0 on ∂Ω.

A different approach is to project the boundary conditions into the finite element space Sh.This can be done, for example, by interpolating the function g at the boundary nodes (andsetting the function at all other nodes to zero). In this case, we employ the ansatz:

uh =

NT∑j=1

qjϕj +

NT∑j=NT +1

qjϕj

for the approximation of (3.5). Recall that ϕj for j = 1, 2, · · · , NT are the basis functionsvanishing at the boundary, while ϕj for j = NT + 1, · · · , NT are those having non-vanishingat the boundary. In this case

uh,(2)g :=

NT∑j=NT +1

qjϕj

Page 26: Solution of Non-Homogeneous Dirichlet Problems with FEM

20 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

will have the values of g at the boundary nodes and will be equal to zero for all nodes insideΩ.

A third possibility, if there exists a smooth continuation of g inside the domain Ω, isto interpolate the extended function g using all basis functions, i.e. not just those on theboundary. In this case we define:

uh,(3)g :=

NT∑j=1

qjϕj .

In Figure 3.1 on page 24, uh,(2)g and u

h,(3)g are depicted for the numerical example (3.20).

3.1.1 Convergence and Error Estimator

After introducing the various methods to split the solution in a particular solution matching(approximately) the boundary condition and a part with homogeneous boundary condition,it is of interest to verify if the error bounds (2.14) given in the last chapter still hold. Inparticular it is of interest to investigate if the interpolation at the boundary of the functionug affects the convergence rate or if they are dominated by the interpolation error.

Let us again consider a general elliptic problem as in (3.1). In this case the followingtheorem holds.

Theorem 3.1.3:Assume that u minimizes the variational form I(v) = a(v, v)− 2(f, v) over H1

E and uh overSh (where a is a bounded, coercive, symmetric bilinear form). Then the vanishing of the firstvariation is expressed by:

a(u, v0) = l(v0) ∀v0 ∈ H10 , (3.6)

a(uh, vh0 ) = l(vh0 ) ∀vh0 ∈ Sh0 . (3.7)

Moreover uh has the additional property:

a(u− uh, u− uh) = minvh∈Sh

a(u− vh, u− vh) (3.8)

Proof: This proof follows [SF08, p. 200] and some argument are sketched. Since u minimizesthe functional I(v) = a(v, v)− 2(f, v), any perturbation εv0 must increase I:

I(u) ≤ I(u+ εv0) = a(u+ εv0, u+ εv0)− 2(f, u+ εv0) =

= a(u, u)− 2(f, u) + 2ε (a(u, v0)− (f, v0)) + ε2a(v0, v0) =

= I(u) + 2ε (a(u, v0)− (f, v0)) + ε2a(v0, v0)

and therefore

0 ≤ 2ε (a(u, v0)− (f, v0)) + ε2a(v0, v0).

Since this is true for small positive and negative ε, the first term must vanish and this proves(3.6). Analogously (3.7) is proved.

Page 27: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.1. SOLUTION SPLIT 21

To prove (3.8) consider that

a(u− vh, u− vh) = a(u− uh + uh − vh, u− uh + uh − vh) =

= a(u− uh, u− uh) + 2a(u− uh, uh − vh) + a(uh − vh, uh − vh). (3.9)

The second term vanishes; this follows by subtracting (3.7) from (3.6) and choosing v0 =vh0 = uh − vh to get:

a(u, v0)− a(uh, vh0 ) = a(u− uh, uh − vh) = (f, v0)− (f, vh0 ) = (f, 0) = 0.

The last term of (3.9) is strictly positive unless vh equals uh, in which case the minimumoccurs at this point. The property (3.8) is therefore proven.

Corollary 3.1.4:Consider the same assumptions as in Theorem 3.1.3, suppose that Ω is a polygon and thenon-homogeneous Dirichlet boundary conditions u = g on ∂Ω are interpolated in the finiteelement space: at all boundary nodes, the trial functions satisfy vh(xj) = g(xj). Then:

a(u− uh, u− uh) ≤ a(u− Ik,h(u), u− Ik,h(u)

), (3.10)

where Ik,h(u) is the interpolation of the solution in the finite element space.

Proof: See [SF08, p. 200]

Similarly we can also give an estimate for alternative norms. In particular let us considerthe following elliptic problem:

−∇ · (α∇u) = f in Ω

u = g on ∂Ω, (3.11)

where α(x) is a function satisfying

0 < α0 ≤ α(x) ≤ α1 ∀x ∈ Ω (3.12)

for some constants α0, α1.

Theorem 3.1.5:Let u and uh be defined as in Corollary 3.1.4, then

|u− uh|H1 ≤ C infu∈Sh

E

|u− u|H1 (3.13)

where C is a constant not depending on u and ShE := vh ∈ Sh : vh(xj) = g(xj) ∀xj nodes on

the boundary ∂Ω .

Proof: This proof follows the proof in [Fai78, p. 91]. Recall, from Theorem (3.1.3), that thefollowing holds true for the exact solution u of (3.11) and the corresponding weak solutionuh:

(α∇u,∇v0) = (f, v0) ∀v0 ∈ H10 , (3.14)

(α∇uh,∇vh0 ) = (f, vh0 ) ∀vh0 ∈ Sh0 , (3.15)

Page 28: Solution of Non-Homogeneous Dirichlet Problems with FEM

22 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

where (·, ·) is the L2-scalar product. Since Sh0 is a subspace of H1

0 we can subtract (3.15) from(3.14) and setting v0 = vh0 , we get(

α∇(u− uh),∇vh0)= 0 ∀vh0 ∈ H1

0 . (3.16)

For some u ∈ ShE we can write:(

α∇(u− uh),∇(u− uh))=(α∇(u− uh),∇(u− u+ u− uh)

)=

=(α∇(u− uh),∇(u− u)

)+(α∇(u− uh),∇(u− uh)

).

Moreover, since u−uh ∈ H10 , from (3.16) it follows that

(α∇(u− uh),∇(u− uh)

)= 0. Then,

using the Cauchy-Schwarz inequality and (3.12) we can derive:(α∇(u− uh),∇(u− uh)

)=(α∇(u− uh),∇(u− u)

)≤

≤ ‖α∇(u− uh)‖L2 · |u− u|H1 ≤ α1|u− uh|H1 |u− u|H1 . (3.17)

From (3.12) we can also derive:(α∇(u− uh),∇(u− uh)

)≥ α0|u− uh|2H1 . (3.18)

Then combining (3.17) and (3.18):

α0|u− uh|2H1 ≤(α∇(u− uh),∇(u− uh)

)≤ α1|u− uh|H1 |u− u|H1

and thus

|u− uh|H1 ≤ α1

α0|u− u|H1 .

Since u is an arbitrary element of ShE this concludes the proof.

Until now we have defined the approximation uhg ≈ ug just by using the basis functionscorresponding to the boundary nodes. If we now assume that there exists a smooth continu-ation of g into Ω (and at least one exists: u itself) we can then interpolate this function overΩ and derive a very effective error estimate.

Theorem 3.1.6:Let u be the solution (3.11) and let w ∈ H1 be any smooth continuation of g into Ω. We canwrite the finite element approximation as uh = uh0 + wh, where wh ∈ Sh is the interpolationIk,h(w) in the finite element space and uh0 ∈ Sh

0 . Then:

‖u− uh‖H1 ≤ C(‖u− (vh0 + wh)‖H1 + ‖w − wh‖H1

)∀vh0 ∈ Sh

0 . (3.19)

Proof: See [WM85, p. 183].

Since (u− (vh0 +wh)) ∈ H1

0 , the error bound is given by the sum of the interpolation errorof w : ‖w−wh‖ together with the usual interpolation error. Therefore the usual error boundsfor the interpolation error is applicable.

In order to have an optimal order L2-estimate we can use the Aubin-Nitsche Lemma, thatadds the additional h-factor to the error estimator [WM85, Section 6.2.2]. To achieve thesame result, in [Fai78, p. 92], the problem is investigated from another point of view and thequalitative same estimator is derived.

We can also conclude that the error bounds (2.14) still hold.

Page 29: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.1. SOLUTION SPLIT 23

3.1.2 Implementation

The splitting method can be implemented and integrated in a standard FEM solver. Consideragain the problem (3.2) and again split the solution into two parts uh = uh0 + uhg .

Then the solver must be modified as follows:

• Construction of the function ug and the corresponding projection uhg in the finite elementspace: ug can be projected by interpolating over the boundary-nodes (solution split over

boundary - uh,(2)g in Example 3.1.2) or interpolating a smooth continuation in the domain

(solution split over the domain - uh,(3)g in Example 3.1.2).

• Adaptation of the linear form by adding −a(uhg , vh) to the right-hand side vector r. Thesystem matrix M remains unchanged.

• Solution of the linear system of equation Mx = r.

• Reconstruction of the solution of the original problem by adding the solution uh0 ofthe homogeneous problem to the function representing the boundary conditions: uh =uh0 + uhg

Remark 3.1.7:After the projection, the function uhg can be described as a linear combination of the basis

functions ϕj: uhg =

∑j qjϕj with qj ∈ R. If a(·, ·) is the bilinear form for the operator L, the

second step of the algorithm is performed as follows:

−a(uhg , ϕi) = −a

∑j

qjϕj , ϕi

= −∑j

qja(ϕj , ϕi) ∀ϕi basis function.

This operation is easily performed by a computer with a matrix-vector multiplication. Let usconsider for example L = −∆, then −a(uhg , vh) corresponds to:∫

Ω∇uhg∇vh =

∑j

qj

∫Ω∇ϕj∇ϕi ∀ϕi basis function.

This is calculated as the multiplication Mq where M is the system matrix given by (m)ji =∫Ω∇ϕj∇ϕi and q the vector containing the coefficients (q)j determining uhg .

3.1.3 Implementation in NGSolve

In NGSolve this method is already implemented in the procedure “setvalues”: with few linesof code we can adapt the file defining a homogeneous Dirichlet PDE (homogeneous.pde) intoa file defining a PDE with non-homogeneous Dirichlet boundary conditions (nonhomoge-neous solsplit.pde)1

The modification that must be done are the following:

• we still declare the finite element space having homogeneous Dirichlet boundary condi-tions using the command:

1The mentioned files can be found in the appendix.

Page 30: Solution of Non-Homogeneous Dirichlet Problems with FEM

24 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

define fespace v -order=1 -dirichlet=[1]

where [1] corresponds to the part of the boundary, where the boundary conditions areapplied.

• Then we have to define the coefficient function determining to the boundary conditions:2

define coefficient dirichlet_bc

(1/(x+y+1)),

• Before executing the actual solver (bvp), we have to call the procedure “setvalues” thatcalculates the projection uhg and upload the linear form (right-hand side).

numproc setvalues [name] -gridfunction=u -coefficient=dirichlet_bc

• The sum u0+ug will be automatically performed after the resolution of the linear systemof equations.

Remark 3.1.8:The procedure “setvalue” projects the smooth continuation of g over the whole domain Ω tothe finite element space ( solution split over domain).

If we want to define the function uhg only using the boundary nodes ( solution split overboundary) we have to modify the procedure “setvalues” by adding a “boundary”-flag:

numproc setvalues [name] -gridfunction=u -coefficient=dirichlet_bc -boundary

(a) Solution split over domain (without -boundaryflag)

(b) Solution split over boundary (with -boundary flag)

Figure 3.1: The function uhg using the “setvalues” procedure for (3.20) using the two possibleprojections.

2This example refers to the problem (3.20)

Page 31: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.1. SOLUTION SPLIT 25

Remark 3.1.9:Instead of a simple interpolation NGsolve uses a L2-projection to project ug to the finiteelement space. This means that we search for a function uhg = PL2(ug) such that:∫

Ωuhgvh =

∫Ωugvh ∀vh ∈ Sh

and is equivalent to the minimization of the L2 error:

‖uhg − ug‖L2(Ω) → min.

When projecting over the boundary (procedure “setvalues” with “boundary”-flag) the integralsgiven above are calculated over the boundary ∂Ω instead of the domain Ω.

3.1.4 Model Problem

Let us consider a non-homogeneous elliptic PDE given by:

−∆u = − 4

(x+ y + 1)3+ 2π2 sin(πx) sin(πy) in Ω = (0, 1)2

u =1

x+ y + 1on ∂Ω. (3.20)

It is straightforward to prove that the function

u =1

x+ y + 1+ sin(πx) sin(πy)

solves problem (3.20) and can thus be used as a reference solution to compute the error inthe L2 norm. Moreover the gradient of u (needed to compute the error in the H1 seminorm)reads

∇u =

(π cos(πx) sin(πy)− 1

(x+y+1)2

π sin(πx) cos(πy)− 1(x+y+1)2

).

Using the file nonhomog solsplit.pde we can define problem (3.20) for NGSolve. The samefile allows us to calculate the error in the L2 norm and the H1 seminorm (see figure 3.2).

Remark 3.1.10:The theoretical error bounds are derived for the H1-norm, while we calculate the H1-seminorm.Since the H1-seminorm is majorized by the H1-norm the error bound still holds.

To investigate the behavior of the error we can solve the same problem for multiple, says, steps and at each step we refine the mesh using a bisection algorithm. Because of theparticular mesh used for the domain Ω = (0, 1)2 (see Figure 3.3), this algorithm will halve thesize h = maxτ hτ of the mesh at every step. According to the error bounds given by (2.14),we expect that, at each step s, the error esL2 = ‖u − uh‖L2 (for the L2-norm) will decreasewith a factor hk+1 = 1

2k+1 or, in logarithmic scale, with a factor −(k + 1), where k is the

degree of the elements (maximal polynomial degree). Similarly we expect a factor hk = 12k

(or −k in logarithmic scale) for the H1-seminorm.

Page 32: Solution of Non-Homogeneous Dirichlet Problems with FEM

26 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

(a) Solution uh with linear elements (b) Error ‖u− uh‖L2

Figure 3.2: Solution and error of problem (3.20) using solution split over boundary method.

(a) Mesh at step s with a size h = 1/2 (b) Mesh at step s+ 1 with a size h = 1/4

Figure 3.3: Refining the mesh with a bisection algorithm

In Tables 3.1, 3.2, 3.3, and 3.4 the ratio between each refinement step is depicted: thisratio coincides with the factor given by 2k+1 (L2 norm) and 2k (H1 seminorm). The errorsare very similar for both projections (over boundary or over domain). This is because thebound for the error is dominated in both cases by the interpolation error (for the same finiteelement space).

Page 33: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.1. SOLUTION SPLIT 27

k=1 k=2 k=3

step 1h error ratio error ratio error ratio

1 2 0.00531 - 0.00062 - 3.66e-05 -2 4 0.00124 4.283 8.71e-05 7.058 2.61e-06 14.0203 8 0.00030 4.153 1.14e-05 7.656 1.76e-07 14.7884 16 7.47e-05 3.996 1.46e-06 7.775 1.14e-08 15.4955 32 1.90e-05 3.927 1.87e-07 7.812 7.25e-10 15.6986 64 4.84e-06 3.931 2.38e-08 7.865 4.61e-11 15.7377 128 1.22e-06 3.954 3.01e-09 7.916 1.28e-12 15.491

Table 3.1: Error ‖u− uh‖L2 for the L2 norm using the solution split over domain

k=1 k=2 k=3

step 1h error ratio error ratio error ratio

1 2 0.07527 - 0.01006 - 0.00123 -2 4 0.03843 1.959 0.00262 3.834 0.00016 7.6603 8 0.01945 1.976 0.00067 3.916 2.03e-05 7.9164 16 0.00978 1.988 0.00016 3.943 2.56e-06 7.9345 32 0.00490 1.996 4.28e-05 3.966 3.22e-07 7.9606 64 0.00245 1.999 1.08e-05 3.962 4.04e-08 7.9807 128 0.00123 2.000 2.70e-06 3.990 5.05e-09 7.990

Table 3.2: Error |u− uh|H1 for the H1 seminorm using the solution split over domain

k=1 k=2 k=3

step 1h error ratio error ratio error ratio

1 2 0.00472 - 0.00064 - 4.96e-05 -2 4 0.00112 4.214 8.23e-05 7.829 3.12e-06 15.8863 8 0.00028 4.058 1.01e-05 8.188 1.89e-07 16.5394 16 6.90e-05 4.001 1.23e-06 8.141 1.16e-08 16.2145 32 1.73e-05 3.996 1.53e-07 8.061 7.25e-10 16.0566 64 4.32e-06 3.998 1.91e-08 8.020 4.52e-11 16.0147 128 1.08e-06 3.999 2.39e-09 8.006 2.85e-12 15.898

Table 3.3: Error ‖u− uh‖L2 for the L2 norm using the solution split over boundary

k=1 k=2 k=3

step 1h error ratio error ratio error ratio

1 2 0.07748 - 0.01095 - 0.00133 -2 4 0.03907 1.983 0.00279 3.922 0.00017 7.7913 8 0.01959 1.995 0.00070 4.017 2.10e-05 8.1304 16 0.00981 1.998 0.00017 4.012 2.60e-06 8.0655 32 0.00491 1.999 4.33e-05 4.004 3.24e-07 8.0196 64 0.00245 2.000 1.08e-05 4.001 4.05e-08 8.0057 128 0.00123 2.000 2.70e-06 4.000 5.06e-09 8.001

Table 3.4: Error |u− uh|H1 for the H1 seminorm using the solution split over boundary

Page 34: Solution of Non-Homogeneous Dirichlet Problems with FEM

28 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

Figures 3.4 and 3.5 display the error (in logarithmic scale) for the two (semi)-norms: theexpected behavior given by the slope −k + 1 respectively −k are respected. The errors fromthe two projections are very similar and the graphs almost coincide.

1 3 5 7 9 11

−20

−18

−16

−14

−12

−10

−8

Step s

lb(e

rror

)

Solution split over ΩSolution split over ∂ΩExpected behaviour

(a) k=1

1 3 5 7 9 11

−28

−26

−24

−22

−20

−18

−16

−14

−12

−10

Step s

lb(e

rror

)

(b) k=2

1 3 5 7 9 11

−35

−30

−25

−20

−15

Step s

lb(e

rror

)

(c) k=3

Figure 3.4: Logarithm of the error for the L2 norm for some degrees k.

1 3 5 7 9

−10

−9

−8

−7

−6

−5

−4

−3

Step s

lb(e

rror

)

Solution split over ΩSolution split over ∂ΩExpected behaviour

(a) k=1

1 3 5 7 9

−18

−16

−14

−12

−10

−8

−6

Step s

lb(e

rror

)

(b) k=2

1 3 5 7 9

−28

−26

−24

−22

−20

−18

−16

−14

−12

−10

Step s

lb(e

rror

)

(c) k=3

Figure 3.5: Logarithm of the error for the H1 seminorm for some degrees k.

Page 35: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.2. APPROXIMATION USING ROBIN BOUNDARY CONDITIONS 29

3.2 Approximation using Robin Boundary Conditions

In this section we will present a different approach to deal with non-homogeneous Dirichletboundary conditions. Instead of imposing the boundary conditions and thus modifying theset of admissible functions, we approximate the Dirichlet boundary conditions with boundaryconditions of Robin type. In this case we will add some terms in the linear and bilinear-formcorresponding to the boundary conditions, without imposing any condition (u = g on ∂Ω) tothe admissible functions.

Remark 3.2.1:Sometimes this method is called penalty-method [WM85, Bak73, BE86] and it may alsobe used to approximate homogeneous boundary conditions [Bab73]. The advantage of thisapproach is that, without imposing the boundary conditions, we must not ensure that all thebasis functions vanish on the boundary.

The key idea of this method is to replace the boundary conditions u = g on ∂Ω of (3.1)by boundary conditions of Robin type with a penalty factor ε > 0:

α∂uε∂n

+ ε−1(uε − g) = 0 on ∂Ω,

where n denotes the outward pointing unit normal vector on ∂Ω.Let us consider the following penalized problem:

Luε = f in Ω,

α∂uε∂n

+ ε−1(uε − g) = 0 on ∂Ω. (3.21)

The weak formulation is [BE86, p. 345]: find uε ∈ H1(Ω) such that:

aε(uε, v) = lε(v) ∀v ∈ H1(Ω), (3.22)

where

aε(w, v) := a(w, v) + ε−1 〈w, v〉∂Ω ,lε(v) := l(v) + ε−1 〈g, v〉∂Ω

and

〈w, v〉∂G :=

∫∂Gwv.

Since ε > 0, it follows that aε(·, ·) is continuous and coercive; therefore the problem iswell-posed.

As previously stated, the boundary conditions are not imposed as essential condition forthe admissible space H1, but they are naturally satisfied by the weak formulation (3.22)(exactly as in the case of Neumann boundary conditions). In particular by the additionalterms ε−1 〈w, v〉∂Ω for the bilinear-form and ε−1 〈g, v〉∂Ω for the linear-form.

For ε → 0, the equation determining the boundary conditions in (3.21) is dominatedby the part (uε − g), so we expect that this assumption approximates the usual Dirichletboundary conditions. A proof that this approximate solution converges to the exact one isgiven in the next section.

Page 36: Solution of Non-Homogeneous Dirichlet Problems with FEM

30 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

3.2.1 Convergence and Error Estimate

Before discussing the error bound of the finite element approximation, we have to show thatthe approximation using Robin boundary conditions converges to the original problem whenε→ 0.

Theorem 3.2.2:Consider problem (3.1), (3.21) and assume that the corresponding bilinear forms a and aε arebounded and coercive. Then the solution u of the original problem (3.1) and the solution uεof the penalized problem (3.21) satisfy:

‖u− uε‖L2(Ω) ≤ Cε‖u‖H2(Ω), (3.23)

for some constant C not depending on ε.

Proof: The proof follows [BE86, p. 348].Subtracting (3.22) from (3.2) and using the definition of the Robin boundary conditions

we get:

aε(u− uε, v) = ε−1 〈g − uε, v〉∂Ω =

⟨α∂u

∂n, v

⟩∂Ω

∀v ∈ H1(Ω). (3.24)

Choosing v = u− uε, we obtain

ε−1‖u− uε‖2L2(∂Ω) = ε−1 〈u− uε, u− uε〉∂Ω ≤ a(u− uε, u− uε) + ε−1 〈u− uε, u− uε〉∂Ω =

= aε(u− uε, u− uε) =

⟨α∂u

∂n, u− uε

⟩∂Ω

(3.25)

Consider now the trace inequality (see [BE86, p. 347]):∥∥∥∥∂w∂n∥∥∥∥Hm−1(∂Ω)

≤ C‖w‖Hm+1(Ω) ∀w ∈ Hm+1(Ω) (3.26)

for some constant C and some m ∈ N. Using (3.26) and (3.25) we derive:⟨α∂u

∂n, u− uε

⟩∂Ω

≤ Cα

∥∥∥∥∂u∂n∥∥∥∥L2(∂Ω)

‖u− uε‖L2(∂Ω) ≤ ‖u‖H2(Ω)‖u− uε‖L2(∂Ω)

and thus

‖u− uε‖L2(∂Ω) ≤ Cε‖u‖H2(Ω). (3.27)

Using the Cauchy-Schwarz inequality, we observe that

‖u− uε‖L2(∂Ω) = supη∈L2(Ω)

|(u− uε, η)Ω|‖η‖L2(Ω)

. (3.28)

Recalling that L is the symmetric operator, for any η ∈ L2(Ω), we define z such that

Lz = η in Ω z = 0 on ∂Ω, (3.29)

Page 37: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.2. APPROXIMATION USING ROBIN BOUNDARY CONDITIONS 31

then it follows from elliptic regularity, for either ∂Ω smooth or Ω convex polyhedral, that

‖z‖H2(Ω) ≤ C‖η‖L2(Ω). (3.30)

Note that as z ∈ H10 (Ω) we have

|(u− uε, Lz)Ω| =∣∣∣∣a(u− uε, z)−

⟨u− uε, α

∂z

∂n

⟩∂Ω

∣∣∣∣ ≤ Cε‖u‖H2(Ω)‖z‖H2Ω (3.31)

where we have noted (3.24) and applied the bound (3.27) and the trace inequality (3.26).Combining (3.28),(3.29),(3.30) and (3.31) we get:

‖u− uε‖L2(Ω) ≤ Cε‖u‖H2(Ω),

and thus the theorem is proven.

The next issue is to determine wherever the error bound using finite elements is stillgoverned by the interpolation error and thus the convergence rate is optimal. Let us defineuhε ∈ Sh such that:

aε(uhε , v

h) = lε(vh) ∀vh ∈ Sh. (3.32)

Considering that

‖u−uhε‖L2 = ‖u−uε+uε−uhε‖L2 ≤ ‖u−uε‖L2+‖uε−uhε‖L2 ≤ C1ε‖u‖H2+C2hk+1‖u‖Hk+1 ,

one can assume that for ε ≤ hk+1 the usual convergence rate is valid.The following theorem ensures that the usual convergence rate holds for the case where

Ω is a convex polygon. For more complex cases regarding variational crimes one can finddetailed explanations in [BE86].

Theorem 3.2.3:Assume ε = hλ with λ > 0, then the solution u of (3.1) and the solution uhε of (3.32) satisfy:

‖u− uhε‖L2(∂Ω) ≤Chµ2‖u‖Hk+1(Ω)

Chµ∗2‖u‖Hk+2(Ω)

(3.33)

and for i = 0, 1 (thus L2-norm and H1-seminorm):

|u− uhε |Hi(Ω) ≤Chµi‖u‖Hk+1(Ω)

Chµ∗i ‖u‖Hk+2(Ω)

(3.34)

where

µ2 = min[λ, k +1

2, k +

1

2λ],

µ∗2 = min[λ, k + 1, k +1

2λ],

µ(∗)1 = min[k, µ

(∗)2 ],

µ(∗)0 = min[µ

(∗)1 + 1, µ

(∗)2 ];

assuming u sufficiently smooth. Here k denotes the local polynomial degree.

Page 38: Solution of Non-Homogeneous Dirichlet Problems with FEM

32 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

Proof: See [BE86, p. 356]

It follows that λ ≥ k + 1 yields optimal H1 and L2 convergence rate.

Remark 3.2.4:Babuska [Bab73, p. 221] also shows that the approximate solution behaves quite robust withrespect to the choice of the penalty parameter.

3.2.2 Implementation

We can adapt the finite element solver to handle Robin boundary conditions and, providingan appropriate penalty factor, to approximate Dirichlet boundary conditions.

• If we start from a finite element space for homogeneous boundary conditions (Sh0 ) we

need to incorporate the basis functions with value on the boundary nodes in the finiteelement space Sh. Thus each function v ∈ Sh can be defined as:

vh =

NT∑j=0

qjϕj +

NT∑j=NT +1

qjϕj ,

where the basis functions ϕj are defined as:

ϕj ∈ Sh0 j = 0, 1, · · · , NT ,

ϕj ∈ Sh = Sh\Sh0 j = NT + 1, ..., NT .

• We have to choose the penalty factor ε. In the previous section we have shown that forε ≤ hk+1 the solution converges and the error is dominated by the interpolation error.Moreover, the solution behave quite robust with respect to the penalty parameter (seeRemark 3.2.4). This is why, for our computations we use a fixed factor (for exampleε = 10−15) that is smaller than the one needed for very fine mesh (size of order 10−3).

We have to remark that the penalty factor is only applied for the nodes that lie on theboundary and this affect the condition number of the system matrix. To prevent thatthis matrix become ill-conditioned (affecting the accurateness of the iterative solver),very small penalty factors are to avoid.

• Lastly we have to adapt the bilinear and linear form by adding the correspondingintegrals as in (3.22).

3.2.3 Implementation in NGSolve

We start from the file implemented to solve an elliptic problem provided with homogeneousDirichlet boundary conditions (homogeneous.pde) and we adapt it to Robin boundary condi-tions (the adapted file is named nonhomogeneous robin.pde).

Consider that the Robin boundary conditions are defined in NGSolve as

∂ur∂n

= γ(g − ur)

for a factor γ, that clearly correspond to 1/ε. To implement the Robin boundary conditionsmethod we modify the following code lines:

Page 39: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.2. APPROXIMATION USING ROBIN BOUNDARY CONDITIONS 33

• We define a constant encompassing the penalty factor γ = 1/ε:

define constant penal = 1e15

• We define the coefficient functions that define γ to implement∫∂Ω γuv (in this case

named lhs) and γg to implement∫∂Ω γgv (here rhs)3:

define coefficient lhs

(penal),

define coefficient rhs

(penal*((1/(x+y+1)))),

• Once we define the finite element space used to solve the problem we remove the flagimposing the homogeneous boundary conditions (-dirichlet=[1]):

define fespace v -order=1

• To define the bilinear form (left-hand side) we have to include the additional integral:

define bilinearform a -fespace=v -symmetric

laplace one

robin lhs

In this case one is the coefficient function for the Laplace operator (for problem (3.20)one = 1), while robin lhs will add

∫∂Ω γuv to the bilinear-form.

• Similarly we modify the linear form:

define linearform l -fespace=v

source f

neumann rhs

where source f stands for the integral∫Ω fv and neumann rhs corresponds to

∫∂Ω γgv.

The remaining lines of code remain unchanged.4

3.2.4 Model Problem

Consider the model problem given by (3.20).The Robin boundary conditions approximation can be implemented in NGSolve using the

file nonhomogeneous robin.pde. We again solve this problem for various degrees k and werefine the mesh for multiple steps s.

The results, listed in Tables 3.5 and 3.6, agree with the error bounds proven: the errordecreases with a factor hk+1 for the L2 norm and with a factor hk for the H1 seminorm.Moreover, the error is very similar to the error which results when using the solution splitalgorithm: clearly this is a consequence of the dominance of the interpolation error.

The same behaviour is displayed in the Figures 3.6 and 3.7: the error decreases at theexpected rate.

3In this case we refer to the boundary conditions for problem (3.20)4The file nonhomogeneous robin.pde used to solve the problem (3.20) can be found in the appendix.

Page 40: Solution of Non-Homogeneous Dirichlet Problems with FEM

34 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

k=1 k=2 k=3

step 1h error ratio error ratio error ratio

1 2 0.00442 - 0.00052 - 4.53e-05 -2 4 0.00114 3.857 7.37e-05 7.084 3.00e-06 15.1203 8 0.00029 3.972 9.67e-06 7.624 1.88e-07 15.9734 16 7.18e-05 4.016 1.23e-06 7.888 1.17e-08 16.0555 32 1.78e-05 4.022 1.54e-07 7.945 7.28e-10 16.0516 64 4.44e-06 4.017 1.92e-08 8.055 4.54e-11 16.0387 128 1.10e-06 4.021 2.39e-09 8.013 2.83e-12 16.020

Table 3.5: Error ‖u − uh‖L2 for the L2 norm using the Robin boundary conditions approxi-mation

k=1 k=2 k=3

step 1h error ratio error ratio error ratio

1 2 0.08294 - 0.01068 - 0.00143 -2 4 0.04101 2.022 0.00276 3.866 0.00018 7.7293 8 0.02013 2.037 0.00069 3.962 2.23e-05 8.2834 16 0.00994 2.025 0.00017 3.996 2.70e-06 8.2715 32 0.00494 2.013 4.35e-05 4.009 3.31e-07 8.1616 64 0.00246 2.006 1.09e-05 4.007 4.09e-08 8.0847 128 0.00123 2.003 2.74e-06 3.967 5.09e-09 8.043

Table 3.6: Error |u − uh|H1 for the H1 seminorm using the Robin boundary conditions ap-proximation

1 3 5 7 9 11

−20

−18

−16

−14

−12

−10

−8

Step s

lb(e

rror

)

Robin boundary conditionExpected behaviour

(a) k=1

1 3 5 7 9 11

−28

−26

−24

−22

−20

−18

−16

−14

−12

−10

Step s

lb(e

rror

)

(b) k=2

1 3 5 7 9 11

−35

−30

−25

−20

−15

Step s

lb(e

rror

)

(c) k=3

Figure 3.6: Logarithm of the error for the L2 norm for some degrees k.

Page 41: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.2. APPROXIMATION USING ROBIN BOUNDARY CONDITIONS 35

1 3 5 7 9

−10

−9

−8

−7

−6

−5

−4

−3

Step s

lb(e

rror

)

Robin boundary conditionExpected behaviour

(a) k=1

1 3 5 7 9

−18

−16

−14

−12

−10

−8

−6

Step s

lb(e

rror

)

(b) k=2

1 3 5 7 9

−28

−26

−24

−22

−20

−18

−16

−14

−12

−10

Step s

lb(e

rror

)

(c) k=3

Figure 3.7: Logarithm of the error for the H1 seminorm for some degrees k.

Page 42: Solution of Non-Homogeneous Dirichlet Problems with FEM

36 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

3.3 Time Performance

After investigating the two possible methods and proving that the error is still bounded bythe interpolation error, it is of great interest to investigate whether there is a difference interms of the time performance between the two methods.

Note that N is the amount of nodes in the mesh (amount of degrees of freedom). Thetime performance (or time complexity) of an algorithm is given as the amount of elementaryoperations required with respect to N .

Note that in the FEM every function v ∈ Sh is uniquely determined by its coefficient qj(the basis functions ϕj are fixed) and thus it can be stored in a vector of length N .

3.3.1 CG Algorithm

To solve a PDE using the standard finite element method few steps are needed: once thelinear and bilinear forms are defined, the solver assembles the (sparse) system matrix and thevector containing the data from the right-hand side. The most expensive part is, however, thesolution of the linear system of equations. NGSolve manages this part in multiple ways; forour computations we employ the well-known Conjugate Gradient algorithm (CG-algorithm).

In [Zul11, Chapter 8] the entire algorithm is presented, together with a convergence anal-ysis. In the current section we restrict to briefly summarize the time complexity of thisalgorithm.

For a given symmetric, positive definite matrix M ∈ RN×N and a vector r ∈ RN we wantto solve a linear system of equations given by:

Mx = r. (3.35)

Let us define the following norm:

‖x‖M =√xTMx.

The CG-method is an iterative solver and at each iteration step s we have the followingerror estimate [Zul11, S. 108]:

‖xs − x‖M ≤ 2qs‖x0 − x‖M with q =

√κ(M)− 1√κ(M) + 1

, (3.36)

where κ(M) is the condition number for the system matrix M .

(3.36) gives an estimation with regard to the error at the first step ‖xo − x‖M and we areinterested to verify how many steps S are needed to reduce this error by a factor ε. This canbe guaranteed for

2qS ≤ ε,

and this means that we need

S ≥ ln(ε/2)

ln(q)(3.37)

iterations.

Page 43: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.3. TIME PERFORMANCE 37

Note that:

q =

√κ(M)− 1√κ(M) + 1

=

√κ(M) + 1− 2√κ(M) + 1

= 1− 2√κ(M) + 1

(3.38)

and

ln(ε/2)

ln(q)=

− ln(ε/2)

− ln(1− 2√κ(M)+1

)≤(−1

2ln(ε/2)

)(√κ(M) + 1

). (3.39)

Thus we can conclude that we need

S = O(− ln(ε/2)

√κ(M)

)(3.40)

iterations to achieve the needed accuracy. It is to remark that the accuracy factor ε mustdecrease according to the mesh size, so that the solver can guarantee the needed accuracywith respect to the FEM error.

The system matrix M is, in the case of the FEM, a sparse matrix where the number ofnon-zero entries is of order N , so that every iteration can be performed with linear order ofelementary operation. It follows that to achieve the target accuracy we need

O(− ln(ε/2)

√κ (M)N

)(3.41)

elementary operations. Moreover for the discretization of a d-dimensional problem we know[Zul11, p. 110]: κ(M) = O(h−2) and N = O(h−d). Therefore for 2D problems, we need:

O(− ln(ε/2)

√κ (M)N

)= O(− ln(ε/2)

√N ·N) = O(− ln(ε/2)N

32 ) (3.42)

elementary operations.Since the solution of the linear system is the most expensive operation within the FEM,

the time complexity for the whole algorithm is of order O(− ln(ε/2)N32 ).

At this point it is of interest to know if the modification introduced in the Sections 3.1.2and 3.2.2 used to solve non-homogeneous problems affect significantly the time complexity.

3.3.2 Solution Split

To analyse the cost of the solution split method, we have to consider every step introducedin Section 3.1.2.

• Interpolation of uhg : To interpolate ug in Sh we compute the corresponding value

uhg (xj) = ug(xj) for every node xj . If we interpolate the function by a function withdegrees of freedom located only at the boundary (solution split over the boundary), thiswill be done just for the nodes that lie on the boundary. On the other hand, if we usethe smooth continuation of g (solution split over the domain), then this interpolationmust be carried out for every node.

In both cases the order of elementary operation needed is given by O(N) but clearlythe operations needed are significantly less when interpolating only on the boundarybecause the amount of nodes lying on the boundary is significantly less then the totalamount of nodes.

Page 44: Solution of Non-Homogeneous Dirichlet Problems with FEM

38 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

• Adaptation of the right-hand side: From Remark 3.1.7 we know that the adaptationof the right-hand side is done by a matrix-vector multiplication (Mq where q is the vectordetermining uhg ) followed by the sum of the resulting vector (with negative sign) withthe original vector r. Clearly the sum of two vectors of size N needs O(N) elementaryoperations.

Since the system matrixM is a sparse matrix with a number of non-zero entries of orderN the matrix-vector multiplication also needs O(N) elementary operations.

• Reconstruction of the solution of the original problem: In this step we sum thetwo vectors that define uhg and uh0 (the solution of the homogeneous problem): this stepneeds O(N) operations.

In conclusion we see that the time complexity of the solution split method is still dominatedby the cost of the solution of the linear system of equations.

3.3.3 Approximation with Robin Boundary Conditions

For the approximation of Dirichlet boundary condition by Robin boundary conditions onlythe last step from Section 3.2.2 adds some elementary operations to the time complexity ofthe algorithm.

Let us first consider the left-hand side. The matrix Mε is assembled as follows:

(mε)j,i = aε(ϕj , ϕi) = a(ϕj , ϕi) + ε−1 〈ϕj , ϕi〉∂Ω .

and this matrix takes non-zero values only for O(N) entries. Therefore, in an analogous wayas the assembling of the usual system matrix M , the whole process needs O(N) elementaryoperations.

To assemble the right-hand side vector (rε)i = l(εi)+ε−1 〈g, ϕi〉∂Ω we calculate numerically

O(2N) times an integral. Using a quadrature rule (for example the Gaussian-quadrature),the amount of elementary operations needed is constant, which means that the whole processrequires O(N) elementary operations. For the additional integrals due to the Robin boundaryconditions, they must only be calculated for the basis functions not vanishing at the boundary.

In conclusion we find that the time complexity of the Robin boundary conditions ap-proximation is again dominated by the solution of the linear system Mεx = rε and thus therequired linear operation are of order O(− ln(ε/2)N3/2).

3.3.4 Numerical Results

The introduced methods are tested using the server “Asprey” from the Mathematics Instituteof the University of Zurich. This server is provided with two Intel Xeon E5-2643 QuadcoreCPU of 3.3 GHz and it runs the operating system “Ubuntu 12.04.1 LTS” with kernel version3.2.0-35-generic.

In particular we solved the model problem (3.20) refining the mesh at each step. Thebisection algorithm used to refine the mesh increases the number of nodes by a factor ofabout 4 (N → 4N) for two dimensional problem (not depending on k). We therefore expectthat the elapsed time grows with a factor of 43/2 = 8 (the accuracy factor ε is fixed by theiterative solver).

From Tables 3.7, 3.8 and 3.9 we can observe this factor for all our methods: the timeelapsed increases by a factor between 4 and 6, thus less than the “worst case-factor” 8. The

Page 45: Solution of Non-Homogeneous Dirichlet Problems with FEM

3.3. TIME PERFORMANCE 39

solver of NGSolve is refined to handle sparse matrices and uses a preconditioner, that is whythe solution is faster than expected. More information about preconditioning in NGSolvecan be found in the official manual (see Section 1.2). The elapsed time for the first steps isomitted in the following tables because it is to small to be meaningful compared.

Sol-split Domain Sol-split Boundary Robin boundary c.

step N Time (s) factor Time (s) factor Time (s) factor

3 289 0.02 - 0.04 2.000 0.04 -4 1089 0.07 3.500 0.05 1.250 0.07 1.7505 4225 0.19 2.714 0.17 3.400 0.18 2.5716 16641 0.86 4.526 0.59 3.471 0.6 3.3337 66049 3.34 3.884 3.04 5.153 3.06 5.1008 263169 14.14 4.234 13.06 4.296 13.01 4.2529 1050625 61.87 4.376 56.77 4.347 61.02 4.690

Table 3.7: Elapsed time for k = 1

Sol-split Domain Sol-split Boundary Robin boundary c.

step N Time (s) factor Time (s) factor Time (s) factor

3 1089 0.04 - 0.03 1.000 0.05 -4 4225 0.1 2.500 0.09 3.000 0.08 1.6005 16641 0.43 4.300 0.37 4.111 0.38 4.7506 66049 1.64 3.814 1.49 4.027 1.5 3.9477 263169 7.85 4.787 7.33 4.919 7.54 5.0278 1050625 42.92 5.468 40.65 5.546 41.92 5.5609 4198401 215.13 5.012 211.95 5.214 218.06 5.202

Table 3.8: Elapsed time for k = 2

Sol-split Domain Sol-split Boundary Robin boundary c.

step N Time (s) factor Time (s) factor Time (s) factor

3 2401 0.05 - 0.05 2.500 0.05 -4 9409 0.15 3.000 0.12 2.400 0.13 2.6005 37249 0.59 3.933 0.54 4.500 0.56 4.3086 148225 2.73 4.627 2.48 4.593 2.61 4.6617 591361 15.06 5.516 14.21 5.730 14.56 5.5798 2362369 101.5 6.740 95.95 6.752 97.45 6.6939 9443329 641.88 6.324 612.07 6.379 643.65 6.605

Table 3.9: Elapsed time for k = 3

Page 46: Solution of Non-Homogeneous Dirichlet Problems with FEM

40 CHAPTER 3. NON-HOMOGENEOUS DIRICHLET BOUNDARY CONDITIONS

The same results can be observed in Figures 3.8, 3.9 and 3.10: the time complexity growsless than the expected factor 3/2 (calculated in logarithm scale).

1 2 3 4 5 6 7 8 9 10−4

−2

0

2

4

6

8

10

Refinement step s

log(

time)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

Figure 3.8: Logarithm of the elapsed time for k = 1.

1 2 3 4 5 6 7 8 9 10−4

−2

0

2

4

6

8

10

Refinement step s

log(

time)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

Figure 3.9: Logarithm of the elapsed time for k = 2.

1 2 3 4 5 6 7 8 9−4

−2

0

2

4

6

8

Refinement step s

log(

time)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

Figure 3.10: Logarithm of the elapsed time for k = 3.

Page 47: Solution of Non-Homogeneous Dirichlet Problems with FEM

Chapter 4

Model Problem 2

To test the reliability and efficiency of the methods introduced in the previous chapters, letus consider a more complex example. This example was introduced by S. Sauter and used in[BN11] to test the performance of hp-adaptive Finite Elements.

4.1 Setting

4.1.1 Periodic Functions

Let Q = (0, 1)2 be the master cell. For ε = 1N (N ∈ N≥1) andµ = (µ1, µ2)

T ∈ Z2, we define

the ε-scaled and µ-shifted version of Q by

Qε,µ := ((µ1 − 1)ε, µ1ε)× ((µ2 − 1)ε, µ2ε).

We can describe the change of coordinates (χε,µ : Q→ Q) as:

χε,µ(x) = ε(µ+ x) with x ∈ Q ⊂ R2.

Clearly χε,µ is an affine map whose inverse is given by: χ−1ε,µ(x) =

xε − µ.

Definition 4.1.1:A function g : Q→ C is called Q-periodic if ∀ (x1, x2)T ∈ Q

g(0, x2) = g(1, x2) and g(x1, 0) = g(x1, 1)

Furthermore, we can define the periodic, ε-scaled and µ-shifted version of g as:

gperε,µ |Qε,µ= g χ−1ε,µ, gperε,µ : Q→ C.

For shorter notation we omit to write the vector µ (gperε instead of gperε,µ ) and we just talkabout ε-scaled periodic functions.

4.1.2 Coefficient functions

For some real valued constants γ,Γ, β let a, b ∈ C∞(Q) be any Q-periodic functions suchthat:

0 < γ ≤ infx∈Q

a(x) ≤ supx∈Q

a(x) ≤ Γ and

0 < β ≤ infx∈Q

b(x). (4.1)

41

Page 48: Solution of Non-Homogeneous Dirichlet Problems with FEM

42 CHAPTER 4. MODEL PROBLEM 2

Further let aperε , bperε be the ε-scaled (periodic) version of a and b (see Definition 4.1.1).For a small and fixed p ∈ N0 consider the finite subset Tp :=

κ = (k1, k2) ∈ Z2 : −p ≤ k1, k2 ≤ p

Z2 and the following (diffusion and reaction coefficient) functions

a(x) =∑κ∈Tp

aκe2πi〈κ,x〉 and b(x) =

∑κ∈Tp

bκe2πi〈κ,x〉

with real coefficients aκ, bκ such that (4.1) is satisfied. Here < ·, · > is the standard scalarproduct without complex conjugation.

Remark 4.1.2:One can easily verify that if aκ = a−κ and bκ = −b−κ, then a(x), b(x) are real-valued functionsand they can also be described as:

a(x) =∑κ∈Tp

aκcos (2π〈κ,x〉) and b(x) =∑κ∈Tp

bκcos (2π〈κ,x〉) .

Furthermore the ε-scaled periodic versions read:

aε(x) =∑κ∈Z2

aκcos(2π⟨κ,

x

ε

⟩)and bε(x) =

∑κ∈Z2

bκcos(2π⟨κ,

x

ε

⟩). (4.2)

4.2 Full Space Problem

Let us consider the following PDE:

−∇ · (aperε ∇u) + bperε u = f (4.3)

We can rewrite (4.3) in the weak-formulation as follows: Find uε ∈ V (where V is a suitablesubspace of H1(R2)) such that:∫

R2

(aperε 〈∇uε,∇v〉+ bperε uv) =

∫R2

fv ∀v ∈ V. (4.4)

The exact solution can be written in the form

uε(x) =1

∫R2

f(t)ψ(x, ε, t)dt ∀x ∈ R2, (4.5)

where ψ(x, ε, t) = ei〈t,x〉φperε (x, ε, t) and f is the Fourier transform of f . The function φperε isthe ε-scaled periodic version of the solution of the following unit cell problem: Find φ(·, ε, t) ∈H1(Q)such that:

Φ(φ, v) :=

∫Qa⟨(i · t+ ε−1∇)φ, (i · t+ ε−1∇)v

⟩+ bφv =

∫Qv ∀v ∈ H1

(Q). (4.6)

Here 〈x, y〉 =∑2

i=1 xiyi, without complex conjugation.For some vector ξ ∈ R2 we can define the right-hand side of (4.4) using the function

f(x) = e2πi〈ξ,x〉, whose Fourier transform is given by: f(t) = 2πδ(t − 2πξ), where δ is theDirac delta function. Hence (4.5) is:

uε(x) = e2πi〈ξ,x〉φperε (x, ε, 2πξ). (4.7)

Remark 4.2.1:For the computational part we just consider the real-valued case (f : R2 → R) (see Remark4.1.2), and we therefore define the right-hand side as f(x) = cos2π〈ξ,x〉.

Page 49: Solution of Non-Homogeneous Dirichlet Problems with FEM

4.3. NUMERICAL SOLUTION OF THE UNIT CELL PROBLEM 43

4.3 Numerical Solution of the Unit Cell Problem

To solve (4.6) we employ a Galerkin discretization: we approximate the solution with a linearcombination of basis functions:

φ ≈ φp =∑κ∈Tp

φκ,pϕκ. (4.8)

For this purpose, let us define again Tp :=κ = (k1, k2) ∈ Z2 : −p ≤ k1, k2 ≤ p

⊂ Z2, for a

small, fixed p ∈ N0. As basis functions we use the plane waves ϕκ(x) := e2πi〈κ,x〉 and we getthe space

Tp := span ϕκ : κ ∈ Tp . (4.9)

Using (4.8) we can approximate (4.6) over (4.9). It follows that the approximate problem is:

Find φp(·, ε, t) ∈ Tp such that: Φε (φp, v) =

∫Qv ∀v ∈ Tp (4.10)

Recall that we only have to solve this equation for t = 2πξ.Applying the representation (4.8) for problem (4.10) we get a linear system of equations

(Cpφ = r) for the unknown coefficient vector (φκ,p)κ∈Tp. To determine the right-hand side

r = (rλ)λ∈Tp , observe that

rλ =

∫Qe−2π〈λ,x〉dx = δ(0,0),λ.

The stiffness Matrix Cp = (cλ,κ)λ,κ∈Tp can be calculated as follows

cλ,κ = 4π2aλ−κ

⟨ξ +

κ

ε, ξ +

λ

ε

⟩+ bλ−κ

Consequently the coefficient vector φκ,p is then determined as the solution of∑κ∈Tp

cλ,κφκ,p = rλ ∀λ ∈ Tp. (4.11)

Finally we can approximate the solution of the full space problem (4.4) with

uε(x) ≈ uε,p(x) = e2πi〈ξ,x〉

∑κ∈Tp

φκ,pe2πi〈κ,x〉

per

ε︸ ︷︷ ︸(φp)

perε

=∑

κ∈Tp

φκ,pe2πi〈ξ+κ

ε,x〉

(4.12)

Remark 4.3.1:Representation (4.12) shows clearly the two scale behavior of the solution: while the terme2πi〈ξ,x〉 (for moderate ξ) slowly varies, the derivatives of the function (φp)

perε oscillate because

of the composition of φp with the affine transformation χε,µ.

Remark 4.3.2:The parameter p is said to be small and fixed, but from the theory of Galerkin discretizationit is clear that limp→∞ uε,p = uε.

Page 50: Solution of Non-Homogeneous Dirichlet Problems with FEM

44 CHAPTER 4. MODEL PROBLEM 2

Remark 4.3.3:For our computation, we again consider the real-valued case, so the plane waves are given by:ϕκ(x) = cos2π〈κ,x〉 and thus the solution reads:

uε,p(x) =∑κ∈Tp

φκ,pcos(2π⟨ξ +

κ

ε,x⟩)

. (4.13)

4.4 Dirichlet Problem on a Finite Domain

In this section we formulate the analogous problem on a finite domain. With this assumptionwe get a PDE provided with non-homogeneous Dirichlet boundary conditions and thus wecan test the different methods introduced in the last chapter.

Let us choose the parameter ξ ∈ R2, p ∈ N0 and ε = 1N for N ∈ N>0. Recall that

Tp :=κ = (k1, k2) ∈ Z2 : −p ≤ k1, k2 ≤ p

⊂ Z2.

Now consider the non-homogeneous Dirichlet problem: Find u ∈ H1(Ω) such that:

−∇ · (aperε ∇u) + bperε u = f in Ω = (0, 1)2,

u = uε,p on ∂Ω, (4.14)

where

f(x) := cos(2π〈ξ,x〉), uε,p :=∑κ∈Tp

φκ,pcos(2π⟨ξ +

κ

ε,x⟩)

.

The coefficient vector φp = (φκ,p)κ∈Tp is calculated as the solution of the following linearsystem of equations (unit cell problem from (4.10)):∑

κ∈Tp

cλ,κφκ,p = rλ ∀λ ∈ Tp, (4.15)

where

cλ,κ = 4π2aλ−κ

⟨ξ +

κ

ε, ξ +

λ

ε

⟩+ bλ−κ, rλ = δ(0,0),λ.

The parameter determining the coefficients aκ, bκ can be fixed; for this computation we use:

aκ =

10 if κ = (0, 0)1 if max|κ1|, |κ2| = 10 otherwise

bκ =

1 if κ = (0, 0)0 otherwise

i.e.:

aperε (x) = 2

(5 + cos

2πx1ε

+ cos2πx2ε

+ cos2π(x1 + x2)

ε+ cos

2π(x1 − x2)

ε

)and bperε (x) = 1. (4.16)

Remark 4.4.1:Clearly aperε and bperε are bounded according to (4.1), thus the problem has a unique solution(Lax-Milgram Theorem).

Page 51: Solution of Non-Homogeneous Dirichlet Problems with FEM

4.5. IMPLEMENTATION 45

4.5 Implementation

In this particular model problem, two combined implementations are involved: first we haveto solve the Unit Cell Problem for a given p, then we can use the information gained toconstruct the PDE with non-homogeneous Dirichlet boundary conditions and solve the finitespace problem (4.14) using FEM. To perform these tasks we employ two separate tools:first we implement an algorithm (using Matlab) to approximate the solution of the unit cellproblem, then we import the calculated coefficient vector φκ,p into NGsolve and solve thefinite space problem using the algorithms for non-homogeneous problems introduced in thelast chapter. Note that it is not possible to directly solve both parts using NGsolve, which iswhy we use an additional program.

4.5.1 Unit Cell Problem Using Matlab

To solve the Unit Cell Problem we can use the following code files:

1 f unc t i on [ PHI ] = phi func ( E, eps , P )format long ;

3 p=−P:P;

5 %Creat ing the 2D−array with the va lue s o f kappa and lambda[X,Y]=ndgrid (p , p) ;

7 k=ze ro s ( (2∗P+1) ˆ2 ,2) ;f o r i =1:(2∗P+1)ˆ2

9 k ( i , 1 )=X( f l o o r ( ( i −1) . / ( 2∗P+1) )+1,mod( i −1 ,2∗P+1)+1) ;k ( i , 2 )=Y( f l o o r ( ( i −1) . / ( 2∗P+1) )+1,mod( i −1 ,2∗P+1)+1) ;

11 endlambda=k ;

13 l=s i z e (k , 1 ) ;

15 %Evaluat ing the c o e f f i c i e n t o f the matrix CC=ze ro s ( l ) ;

17 f o r i =1: lC( i , : )=c o e f f i c i e n t (E, eps , lambda ( i , : ) , k ) ;

19 end

21 %Creat ing the vec to r r ( r i ght−hand s i d e o f the equat ion )r=ze ro s ( (2∗P+1) ˆ2 ,1) ;

23 r ( f l o o r ( ( ( 2∗P+1)ˆ2) /2)+1 ,1)=1;

25 %Solv ing the l i n e a r problem with the bui ld−in a lgor i thmPHI=C\ r ;

Listing 4.1: function phifunc.m

f unc t i on [ c ] = c o e f f i c i e n t (E, eps , lambda , k )2 l=s i z e (k , 1 ) ;

c=ze ro s (1 , l ) ;4 f o r i =1: l

c ( i )=4∗pi ∗ pi ∗ f c t a ( lambda−k ( i , : ) , eps ) ∗dot (E+k( i , : ) / eps ,E+lambda/ eps ) ;6 i f lambda−k ( i , : ) == [0 0 ]

c ( i )=c ( i )+1;8 end

end10 end

Listing 4.2: function coefficient.m

f unc t i on [ out ] = f c t a ( in , eps )2 out=0;

Page 52: Solution of Non-Homogeneous Dirichlet Problems with FEM

46 CHAPTER 4. MODEL PROBLEM 2

i f in == [ 0 , 0 ]4 out=10;

re turn ;6 end

i f max( abs ( in ) ) == 18 out = 1 ;

re turn ;10 end

end

Listing 4.3: function fcta.m

The function phifunc.m in listing 4.1 returns the coefficient vector φκ,p for given coefficientsξ, ε, p (E, eps and P in the code). To complete this task, the function calls the additionalfunctions coefficient.m (listing 4.2) that calculates the values of the vector Cλ (part of thesystem matrix) and the function fcta.m (listing 4.3), that returns the value of the coefficientaκ.

Choice of p

One of the first issue relative to this computation is the choice of p. As previously mentionedin Remark 4.3.2, by increasing p we decrease the offset between the solution uε and uε,p:for a larger p, the PDE determining uε,p has refined non-homogeneous Dirichlet boundaryconditions that lead to a solution uε,p closer to the original solution uε.

On the other hand a large p is disadvantageous: the cost of inverting the Matrix Cp ofsize (2p + 1)2 × (2p + 1)2 grows very fast, as well as the size of the vector determining theboundary condition (|φp| = (2p+ 1)2). That is why p is chosen to be small.

In conclusion, since we are specifically interested in the performance of the FEM solver,we just need to fix p as small as possible, but providing an appropriate approximation of theboundary conditions (and thus of the exact solution) such that the behavior of the FEM erroris still dominant. In other terms: we can describe the error e for a given norm ‖ · ‖ as:

e = ‖uε,p,h − uε‖ = ‖uε,p,h − uε,p + uε,p − uε‖ ≤≤ ‖uε,p,h − uε,p‖+ ‖uε,p − uε‖ =: eFEM + ep. (4.17)

where uε is the exact solution of (4.14), uε,p is the approximate solution for a given p usingthe Galerkin discretization introduced in Section 4.3 and uε,p,h is the approximated solutionusing the FEM. Since we can only calculate the error eFEM , we need ep to be negligible (suchthat e ≈ eFEM ).

One method to investigate the error ep is to calculate at each step p→ p+1 by how muchthe solution is improved: ‖uε,p+1 − uε,p‖. In Figure 4.1 the difference δ = ‖uε,p+1 − uε,p‖L2

using the L2-norm (in linear and logarithmic scale) is displayed. It can be seen that fromfrom p = 4 to p = 5 the solution only changes by a magnitude of about 10−8. In most of ourFEM approximations we reach a refinement of up to 10−10. It follows that by using p = 10we can ensure that the error ep is negligible.

4.5.2 Implementation Using NetGen/NGSolve

Once the appropriate p is determined, the unit cell problem is solved and the coefficient φκ,pare calculated, we can write the NGSolve file describing problem (4.14). Again we imple-ment the two methods described in the last chapter: solution split (over domain/boundary)

Page 53: Solution of Non-Homogeneous Dirichlet Problems with FEM

4.6. NUMERICAL RESULTS 47

0 1 2 3 40

0.5

1

1.5

2

2.5

3

3.5

4x 10

−5

p

Diff

eren

ce: δ

(a) Linear scale

0 1 2 3 4−8

−7.5

−7

−6.5

−6

−5.5

−5

−4.5

−4

p

Diff

eren

ce: l

og(δ

)

(b) log10 scale

Figure 4.1: Evolution of the solution from p to p+ 1: δ = ‖uε,p+1 − uε,p‖L2

and approximation using the Robin boundary conditions. The file describing these PDEs(sauter10.pde) can be found in the internet page of the University of Zurich’s Institute ofMathematics1.

4.6 Numerical Results

In this section we present the results found with the numerical computations. In particular,we are interested in investigations of the error behavior and the time performance.

As previously mentioned we set p = 10. We moreover set ε = 1N = 1

10 and ξ = [1, 1]T .The solutions found by the three possible approaches nearly coincide and they converge

to the reference solution uε,p for h→ 0. One example of the solution is given in Figure 4.2.

4.6.1 Error Behavior

Within the theoretical part, it was highlighted how the error estimation is dominated by theerror given by the interpolation in the finite element space, in particular it was proven that,for r = 0, 1:

‖u− uh‖Hr ≤ Chk+1−r‖u‖Hk+1 (4.18)

where u is the exact solution and uh is the finite element approximation.In the last chapter we found that this estimate holds for simple examples and it is now of

interest to check if it also holds for a more complex example. Again we can solve the PDE forconsecutive refinement steps s and at each step we refine the mesh using a bisection algorithm.Using the particular mesh for the domain Ω = (0, 1)2 depicted in Figure 3.3, the bisectionalgorithm halve the size h = maxτ hτ of the mesh at each refinement step. According to (4.18)we expect that the error esHr = ‖uε,p,h − uε,p‖L2 will decrease with a factor hk+1−r = 1

2k+1−r

1http://www.math.uzh.ch/compmath/index.php?id=dipl

Page 54: Solution of Non-Homogeneous Dirichlet Problems with FEM

48 CHAPTER 4. MODEL PROBLEM 2

(a) Solution uε,p,h (b) Flux of the solution

Figure 4.2: Solution and flux of the solution of problem (4.14) using linear elements andSolution Split over Domain. The behavior is as stated in Remark 4.3.1

or, in logarithmic scale, with a slope of −(k + 1− r), where k is the polynomial order of theelements.

Remark 4.6.1:As stated in section 4.5.1, we cannot use the exact solution uε as reference solution. Usinga large enough p (in this case p = 10) we can still use uε,p as reference solution, ensuringenough accuracy.

From Tables 4.1-4.6 we can clearly see that, after some iteration steps, the behavior ofthe error follows what stated in (4.18) for both methods: solution split (just on the boundaryand also with smooth continuation) and approximation with the Robin boundary conditions.

For our particular case (with ε = 110), we notice that the different algorithms need some

refinement steps to reach the expected convergence rate: which is achieved once the mesh sizeis of order 10−2 and can thus ensure the appropriate approximation of the rapid oscillation ofthe solution’s derivative: this oscillation is determined by the factor ε defining the problem(see Remark 4.3.1). It could be interesting to investigate how the choice of ε affects theminimal mesh-size needed to ensure the expected convergence rate.

Page 55: Solution of Non-Homogeneous Dirichlet Problems with FEM

4.6. NUMERICAL RESULTS 49

k=1 k=2 k=3

step s√2/h error factor error factor error factor

1 2 0.001293 - 0.000225 - 0.000174 -2 4 0.000152 8.508 0.000120 1.860 6.46E-05 2.6903 8 1.55e-04 0.981 6.51e-05 1.854 2.21e-05 2.9244 16 6.96e-05 2.224 1.63e-05 4.008 4.23e-06 5.2175 32 1.95e-05 3.563 3.48e-06 4.667 4.54e-07 9.3266 64 5.21e-06 3.750 3.65e-07 9.537 3.98e-08 11.4177 128 1.23e-06 4.221 4.90e-08 7.445 2.29e-09 17.3588 256 3.07e-07 4.018 6.18e-09 7.930 1.42e-10 16.1499 512 7.66e-08 4.010 7.78e-10 7.946 9.16e-12 15.488

Table 4.1: Error ‖uε,h,p − uε,p‖L2 using the solution split method over domain

k=1 k=2 k=3

step s√2/h error factor error factor error factor

1 2 0.001591 - 0.000402 - 0.000229 -2 4 0.000150 10.579 0.000111 3.618 6.76e-05 3.3853 8 1.76e-04 0.857 5.22e-05 2.131 2.06e-05 3.2814 16 6.66e-05 2.636 1.67e-05 3.123 4.42e-06 4.6665 32 1.89e-05 3.520 3.54e-06 4.717 4.41e-07 10.0196 64 5.08e-06 3.725 3.76e-07 9.407 3.94e-08 11.2027 128 1.22e-06 4.174 4.98e-08 7.560 2.29e-09 17.2168 256 3.05e-07 3.997 6.21e-09 8.023 1.42e-10 16.1239 512 7.62e-08 3.999 7.76e-10 7.996 9.15e-12 15.501

Table 4.2: Error ‖uε,h,p − uε,p‖L2 using the solution split method over boundary

k=1 k=2 k=3

step s√2/h error factor error factor error factor

1 2 0.001591 - 0.000402 - 0.000229 -2 4 0.000158 10.097 0.000112 3.583 5.29e-05 4.3313 8 1.75e-04 0.901 5.00e-05 2.247 2.01e-05 2.6254 16 6.65e-05 2.630 1.67e-05 2.985 4.39e-06 4.5865 32 1.89e-05 3.518 3.54e-06 4.725 4.41e-07 9.9636 64 5.08e-06 3.722 3.78e-07 9.382 3.94e-08 11.1827 128 1.22e-06 4.174 4.98e-08 7.580 2.29e-09 17.2308 256 3.05e-07 3.996 6.21e-09 8.027 1.42e-10 16.1269 512 7.62e-08 3.999 7.76e-10 7.998 9.14e-12 15.506

Table 4.3: Error ‖uε,h,p−uε,p‖L2 using the Robin boundary conditions approximation method

Page 56: Solution of Non-Homogeneous Dirichlet Problems with FEM

50 CHAPTER 4. MODEL PROBLEM 2

k=1 k=2 k=3

step s√2/h error factor error factor error factor

1 2 0.010392 - 0.00574 - 0.00462 -2 4 0.00405 2.568 0.00275 2.085 2.18e-03 2.1203 8 3.58e-03 1.129 2.10e-03 1.313 1.38e-03 1.5764 16 1.97e-03 1.819 1.27e-03 1.655 5.80e-04 2.3855 32 1.35e-03 1.456 4.78e-04 2.646 1.30e-04 4.4696 64 7.37e-04 1.836 1.30e-04 3.677 2.31e-05 5.6277 128 3.70e-04 1.992 3.59e-05 3.628 2.77e-06 8.3248 256 1.86e-04 1.991 9.10e-06 3.943 3.49e-07 7.9369 512 9.30e-05 1.998 2.25e-06 4.041 4.43e-08 7.876

Table 4.4: Error |uε,h,p − uε,p|H1 using the solution split method over domain

k=1 k=2 k=3

step s√2/h error factor error factor error factor

1 2 0.01141 - 0.00562 - 0.00456 -2 4 0.00397 2.875 0.00281 1.999 2.09e-03 2.1813 8 3.63e-03 1.092 2.04e-03 1.377 1.39e-03 1.5064 16 1.97e-03 1.845 1.26e-03 1.620 5.83e-04 2.3785 32 1.36e-03 1.447 4.79e-04 2.631 1.29e-04 4.5166 64 7.40e-04 1.838 1.30e-04 3.678 2.31e-05 5.5957 128 3.70e-04 1.999 3.59e-05 3.628 2.77e-06 8.3258 256 1.86e-04 1.992 9.16e-06 3.919 3.49e-07 7.9449 512 9.30e-05 1.998 2.26e-06 4.047 4.41e-08 7.914

Table 4.5: Error |uε,h,p − uε,p|H1 using the solution split method over boundary

k=1 k=2 k=3

step s√2/h error factor error factor error factor

1 2 0.01141 - 0.00562 - 0.00456 -2 4 0.00401 2.843 0.00282 1.992 2.09e-03 2.1813 8 3.65e-03 1.100 1.97e-03 1.433 1.39e-03 1.5064 16 1.97e-03 1.853 1.26e-03 1.557 5.83e-04 2.3785 32 1.37e-03 1.437 4.78e-04 2.649 1.29e-04 4.5166 64 7.41e-04 1.846 1.30e-04 3.663 2.31e-05 5.5957 128 3.70e-04 2.002 3.59e-05 3.631 2.77e-06 8.3258 256 1.86e-04 1.992 9.10e-06 3.944 3.49e-07 7.9449 512 9.30e-05 1.998 2.25e-06 4.053 4.41e-08 7.914

Table 4.6: Error |uε,h,p − uε,p|H1 using the Robin boundary conditions approximation

Page 57: Solution of Non-Homogeneous Dirichlet Problems with FEM

4.6. NUMERICAL RESULTS 51

1 3 5 7 9 11 13

−24

−22

−20

−18

−16

−14

−12

−10

Step s

lb(e

rror

)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

(a) k=1

1 3 5 7 9 11

−30

−28

−26

−24

−22

−20

−18

−16

−14

−12

Step s

lb(e

rror

)

(b) k=2

1 3 5 7 9 11

−35

−30

−25

−20

−15

Step s

lb(e

rror

)

(c) k=3

Figure 4.3: Logarithm of the error for the L2 norm for some degrees k.

1 3 5 7 9

−14

−13

−12

−11

−10

−9

−8

−7

−6

Step s

lb(e

rror

)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

(a) k=1

1 3 5 7 9

−18

−16

−14

−12

−10

−8

Step s

lb(e

rror

)

(b) k=2

1 3 5 7 9

−24

−22

−20

−18

−16

−14

−12

−10

−8

Step s

lb(e

rror

)

(c) k=3

Figure 4.4: Logarithm of the error for the H1 seminorm for some degrees k.

Page 58: Solution of Non-Homogeneous Dirichlet Problems with FEM

52 CHAPTER 4. MODEL PROBLEM 2

4.6.2 Time Performance

As in the last chapter it is of interest to verify the time needed by each approach to solve thenon-homogeneous problem at each refinement step. We expect, as proven in theory and asshown in the simpler examples, that the performance evolves with order O(N3/2). Since atevery refinement step the amount of unknowns or degrees of freedom (N) quadruplicate, theexpected time cost should evolve with a factor 43/2 = 8.

In Tables (4.7), (4.8) and (4.9) the expected order is visible: again we see that NGSolveis faster than expected because its solver is specifically built for sparse matrices and exploitsa preconditioner.

The computing times for small N are not significant because the time elapsed is too smallto be meaningful in comparison.

Robin approximation Solution Split over ∂Ω Solution split over Ω

step s N time factor time factor time factor

1 25 0.02 - 0.02 - 0.02 -2 81 0.03 1.500 0.03 1.500 0.06 3.0003 289 0.04 1.333 0.05 1.667 0.2 3.3334 1089 0.1 2.500 0.1 2.000 0.66 3.3005 4225 0.24 2.400 0.22 2.200 2.49 3.7736 16641 0.99 4.125 0.95 4.318 9.63 3.8677 66049 3.59 3.626 3.52 3.705 38.11 3.9578 263169 14.73 4.103 14.58 4.142 154.75 4.0619 1050625 63.4 4.304 61.16 4.195 617.39 3.990

Table 4.7: Elapsed time (in seconds) for the three methods for k = 1

Robin approximation Solution Split over ∂Ω Solution split over Ω

step s N time factor time factor time factor

1 81 0.03 - 0.02 - 0.03 -2 289 0.03 1.000 0.02 1.000 0.1 3.3333 1089 0.06 2.000 0.06 3.000 0.33 3.3004 4225 0.18 3.000 0.17 2.833 1.22 3.6975 16641 0.5 2.778 0.49 2.882 4.78 3.9186 66049 1.88 3.760 1.83 3.735 19.12 4.0007 263169 8.67 4.612 8.4 4.590 77.52 4.0548 1050625 45.95 5.300 44.47 5.294 327.8 4.2299 4198401 220.37 4.796 231.37 5.203 1322.96 4.036

Table 4.8: Elapsed time (in seconds) for the three methods for k = 2

One interesting point is the behavior of the algorithm using the solution split over domainmethod: even if the evolution is still of order O(N3/2) (or even less), this approach is upto ten times slower than the other two methods. This can be explained by considering theconstruction of the algorithm: while the other two approaches only evaluate integrals overthe boundary nodes to deal with the non-homogeneous Dirichlet boundary conditions, thesolution split over domain evaluate the L2-projection over every node in the mesh, clearlyslowing down the process. This behavior is also apparent in Figure 4.5.

Page 59: Solution of Non-Homogeneous Dirichlet Problems with FEM

4.6. NUMERICAL RESULTS 53

Robin approximation Solution Split over ∂Ω Solution split over Ω

step s N time factor time factor time factor

1 169 0.01 - 0.03 - 0.05 -2 625 0.04 4.000 0.03 1.000 0.19 3.8003 2401 0.08 2.000 0.07 2.333 0.63 3.3164 9409 0.22 2.750 0.21 3.000 2.33 3.6985 37249 0.72 3.273 0.71 3.381 9.25 3.9706 148225 3.1 4.306 2.96 4.169 37.54 4.0587 591361 16.2 5.226 15.84 5.351 154.01 4.1038 2362369 103.18 6.369 101.75 6.424 662.82 4.3049 9443329 670.35 6.497 619.7 6.090 2857.2 4.311

Table 4.9: Elapsed time (in seconds) for the three methods for k = 3

1 2 3 4 5 6 7−2

−1

0

1

2

3

4

5

6

7

log(N)

log(

time)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

(a) k = 1

1 2 3 4 5 6 7 8−2

−1

0

1

2

3

4

5

6

log(N)

log(

time)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

(b) k = 2

2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7−2

−1

0

1

2

3

4

5

log(N)

log(

time)

Solution split over ΩSolution split over ∂ΩRobin boundary conditionExpected behaviour

(c) k = 3

Figure 4.5: Logarithm of the elapsed time with respect to the degrees of freedom N (also inlogarithmic scale)

Page 60: Solution of Non-Homogeneous Dirichlet Problems with FEM

54 CHAPTER 4. MODEL PROBLEM 2

Page 61: Solution of Non-Homogeneous Dirichlet Problems with FEM

Chapter 5

Conclusion

In the current work we introduced two methods to solve elliptic PDE with non-homogeneousDirichlet boundary conditions: the Solution Split method (Solution Split over domain or overboundary) and the approximation by Robin boundary conditions. We were able to prove thefollowing properties mathematically and their sharpness by numerical tests.

(1) Error bounds: the approximation error of both methods is dominated by the interpo-lation error in the finite element space. Since this space is the same for both methodswe can conclude that the error bounds given by

‖u− uh‖Hr(Ω) ≤ Chk+1−r‖u‖Hk+1(Ω)

for r = 0, 1 hold for both methods. For the Robin boundary conditions approximation(penalty method) we have to select a penalty factor ε ≤ hk+1 to ensure this rate ofconvergence.

(2) Time complexity: it is not straightforward to distinguish the two methods sincethe time complexity is dominated by the resolution of the linear system of equationsand it evolves with order O(N3/2) with respect to the amount of nodes N (using theCG-algorithm).

The only major difference is that the Solution Split over Domain method is significantlyslower than the other methods. This is because further integrations over the wholedomain are needed. Despite this the order remains unchanged.

There are further interesting points which could be investigated in new studies. Forexample the behavior of the same methods in higher dimensional problems could be tested:this could be done, for three dimensional problems, using NetGen/NGSolve.

Another interesting point are the time-dependent problems: the reliability of the methodswhen the problem is of the non-stationary type and the boundary conditions are given asfunctions with respect to the time variable could be investigated.

A third possible research could be the introduction of variational crimes: for this thesiswe just considered polyhedral domains and thus the triangulation coincided exactly with theoriginal domain. In more general problems the boundary can be given by a smooth curve,which requires curved elements at the boundary or the domain with the triangulation Ωh ≈ Ωwould need to be appropriately approximated. In [BE86, SF08] such techniques are discussedand it could be of interest to test those methods.

55

Page 62: Solution of Non-Homogeneous Dirichlet Problems with FEM

56 CHAPTER 5. CONCLUSION

Page 63: Solution of Non-Homogeneous Dirichlet Problems with FEM

Bibliography

[Alt12] H. W. Alt. Lineare Funktionalanalysis. Springer, Berlin, 2012.

[Arn12] N. Arnold. Netgen/ngsolve manual, 2012. https://www.math.uzh.ch/compmath/

index.php?id=arnold; last visit 07.06.2013.

[Bab73] Ivo Babuska. The finite element method with penalty. Math. Comp., 27:221–228,1973.

[Bak73] Garth A. Baker. Simplified proofs of error estimates for the least squares methodfor dirichlet’s problem. Math. Comp., 27:229–235, 1973.

[BE86] J. Barrett and C. Elliott. Finite element approximation of the dirichlet problemusing the boundary penalty method. Numerische Mathematik, 49:343–366, 1986.

[BN11] R Bank and H. Nguyen. hp adaptive finite elements based on derivative recoveryand superconvergence. Computing and Visualization in Science, 14:287–299, 2011.

[Bra07] D. Braess. Finite Elemente. Theorie, schnelle Loser und Anwendungen in der Elas-tizitatstheorie. Springer, 2007.

[BS94] S. C. Brenner and L. R. Scott. The mathematical theory of finite element methods.Texts in Applied Mathematics. Springer-Verlag, New York, 1994.

[Fai78] Graeme Fairweather. Finite element Galerkin methods for differential equations. M.Dekker New York, NY, 1978.

[Sch13a] J. Schoberl. Netgen, 2013. http://sourceforge.net/projects/netgen-mesher/;last visit 07.06.2013.

[Sch13b] J. Schoberl. Ngsolve, 2013. http://sourceforge.net/projects/ngsolve/; lastvisit 07.06.2013.

[SF08] G. Strang and G.J. Fix. An Analysis of the Finite Element Method, 2ed. Prentice-Hall series in automatic computation. Wellesley-Cambridge Press, 2008.

[WM85] R. Wait and A.R. Mitchell. Finite element analysis and applications. A Wiley-Interscience publication. J. Wiley, 1985.

[Zul11] Walter Zulehner. Numerische Mathematik: eine Einfuehrung anhand von Differen-tialgleichungsproblemen. Birkhaeuser, 2011.

57

Page 64: Solution of Non-Homogeneous Dirichlet Problems with FEM

58 BIBLIOGRAPHY

Page 65: Solution of Non-Homogeneous Dirichlet Problems with FEM

Appendix

#Solv ing − l a p l a c e (u)=f and homogeneous D i r i c h l e t boundary cond i t i on2 #So lut i on u=s in ( p i x ) s i n ( p i y )

4 #Loading geometry and meshgeometry = square . in2d

6 mesh = square . vo l

8 ######### Reso lut ion o f the problem #########de f i n e constant p i = 3.1415926535897932384626

10 #Laplace c o e f f i c i e n td e f i n e c o e f f i c i e n t one

12 1 ,#Source i n t e g r a l ( f )

14 de f i n e c o e f f i c i e n t f(2 ∗ pi ∗ pi ∗ s i n ( p i ∗x ) ∗ s i n ( p i ∗y ) ) ,

16

#Creat ing FE−space18 de f i n e f e spac e v −order=1 −d i r i c h l e t =[1 ]

d e f i n e g r i d f un c t i on u −f e spac e=v −nested20

#Bi l i n e a r form22 de f i n e b i l i n e a r f o rm a −f e spac e=v −symmetric

l a p l a c e one24 #Linearform

de f i n e l i n ea r f o rm l −f e spac e=v26 source f

28 #Numerical s o l u t i o nde f i n e p r e cond i t i on e r c −type=d i r e c t −b i l i n e a r f o rm=a

30 numproc bvp so l v e d i r i c h l e t bc −b i l i n e a r f o rm=a −l i n ea r f o rm=l −g r i d f un c t i on=u −pr e cond i t i on e r=c −maxsteps=100

32 ######### Error eva lua t i on ##########FE−space f o r e r ro r−g r i d f un c t i o n s

34 de f i n e f e spac e ve r r −l 2 −order=0

36 #Coe f f i c i e n t f o r u r e f and gradure fd e f i n e c o e f f i c i e n t u r e f

38 ( s i n ( p i ∗x ) ∗ s i n ( p i ∗y ) ) ,d e f i n e c o e f f i c i e n t g radure f

40 ( p i ∗ cos ( p i ∗x ) ∗ s i n ( p i ∗y ) , p i ∗ s i n ( p i ∗x ) ∗ cos ( p i ∗y ) ) ,

42 #Sca larproduct f o r L2−normde f i n e b i l i n e a r f o rm a l2 −f e spac e=v −nonassemble

44 mass one#Sca larproduct f o r H1−seminorm

46 de f i n e b i l i n e a r f o rm ah1 −f e spac e=v −nonassemblel a p l a c e one

48

#Grid funct i ons f o r e r r o r50 de f i n e g r i d f un c t i on e r r l 2 −f e spac e=ver r

d e f i n e g r i d f un c t i on errh1 −f e spac e=ver r

59

Page 66: Solution of Non-Homogeneous Dirichlet Problems with FEM

60 APPENDIX

52

#Evaluat ing the e r r o r s54 numproc d i f f e r e n c e l 2 e r r o r −b i l i n e a r f o rm1=a l2 −s o l u t i o n=u −f unc t i on=ur e f −d i f f=e r r l 2

numproc d i f f e r e n c e h1er ro r −b i l i n e a r f o rm1=ah1 −s o l u t i o n=u −f unc t i on=gradure f −d i f f=errh1

Listing 1: homogeneous.pde

1 #Model problem 1 us ing So lu t i on Sp l i t

3 #Loading geometry and meshgeometry = square . in2d

5 mesh = square . vo l

7 ######### Reso lut ion o f the problem #########de f i n e constant p i = 3.1415926535897932384626

9 #Laplace c o e f f i c i e n td e f i n e c o e f f i c i e n t one

11 1 ,#Source i n t e g r a l ( f )

13 de f i n e c o e f f i c i e n t f((−4)/ ( ( x+y+1)∗ ( x+y+1)∗ ( x+y+1) )+2∗ pi ∗ pi ∗ s i n ( p i ∗x ) ∗ s i n ( p i ∗y ) ) ,

15 #Di r i c h l e t boundary cond i t i ond e f i n e c o e f f i c i e n t d i r i c h l e t bc

17 (1 / (x+y+1) ) , (1 / (x+y+1) ) , (1 / (x+y+1) ) , (1 / (x+y+1) ) ,

19 #Creat ing FE−spaced e f i n e f e spac e v −order=1 −d i r i c h l e t =[1 ]

21 de f i n e g r i d f un c t i on u −f e spac e=v −nested

23 #Bi l i n e a r formde f i n e b i l i n e a r f o rm a −f e spac e=v −symmetric

25 l a p l a c e one#Linearform

27 de f i n e l i n ea r f o rm l −f e spac e=vsource f

29

#So lut i on Sp l i t procedure31 numproc s e t v a l u e s upload d i r i c −g r i d f un c t i on=u −c o e f f i c i e n t=d i r i c h l e t bc −boundary

33 #Numerical s o l u t i o nde f i n e p r e cond i t i on e r c −type=d i r e c t −b i l i n e a r f o rm=a

35 numproc bvp so l v e d i r i c h l e t bc −b i l i n e a r f o rm=a −l i n ea r f o rm=l −g r i d f un c t i on=u −pr e cond i t i on e r=c −maxsteps=100

37 ######### Error eva lua t i on ##########FE−space f o r e r ro r−g r i d f un c t i o n s

39 de f i n e f e spac e ve r r −l 2 −order=0

41 #Coe f f i c i e n t f o r u r e f and gradure fd e f i n e c o e f f i c i e n t u r e f

43 ( s i n ( p i ∗x ) ∗ s i n ( p i ∗y )+1/ (x+y+1) ) ,d e f i n e c o e f f i c i e n t g radure f

45 ( p i ∗ cos ( p i ∗x ) ∗ s i n ( p i ∗y )−1/ ( ( x+y+1)∗ ( x+y+1) ) , p i ∗ s i n ( p i ∗x ) ∗ cos ( p i ∗y )−1/ ( ( x+y+1)∗ ( x+y+1) )) ,

47 #Sca larproduct f o r L2−normde f i n e b i l i n e a r f o rm a l2 −f e spac e=v −nonassemble

49 mass one#Sca larproduct f o r H1−seminorm

51 de f i n e b i l i n e a r f o rm ah1 −f e spac e=v −nonassemblel a p l a c e one

53

#Grid funct i ons f o r e r r o r55 de f i n e g r i d f un c t i on e r r l 2 −f e spac e=ver r

d e f i n e g r i d f un c t i on errh1 −f e spac e=ver r

Page 67: Solution of Non-Homogeneous Dirichlet Problems with FEM

APPENDIX 61

57

#Evaluat ing e r r o r s59 numproc d i f f e r e n c e l 2 e r r o r −b i l i n e a r f o rm1=a l2 −s o l u t i o n=u −f unc t i on=ur e f −d i f f=e r r l 2

numproc d i f f e r e n c e h1er ro r −b i l i n e a r f o rm1=ah1 −s o l u t i o n=u −f unc t i on=gradure f −d i f f=errh1

Listing 2: nonhomogeneous solsplit.pde

#Model problem 1 us ing So lu t i on Sp l i t2

#Loading geometry and mesh4 geometry = square . in2d

mesh = square . vo l6

de f i n e constant p i = 3.14159265358979323846268 de f i n e constant penal = 1e15

10 ######### Reso lut ion o f the problem ##########Laplace c o e f f i c i e n t

12 de f i n e c o e f f i c i e n t one1 ,

14 #Source i n t e g r a l ( f )d e f i n e c o e f f i c i e n t f

16 ((−4)/ ( ( x+y+1)∗ ( x+y+1)∗ ( x+y+1) )+2∗ pi ∗ pi ∗ s i n ( p i ∗x ) ∗ s i n ( p i ∗y ) ) ,#Co e f f i c i e n t f o r the Robin boundary cond i t i on approximation

18 de f i n e c o e f f i c i e n t l h s( penal ) ,

20 de f i n e c o e f f i c i e n t rhs( penal ∗ ( (1 / (x+y+1) ) ) ) ,

22

#Creat ing FE−space24 de f i n e f e spac e v −order=1

de f i n e g r i d f un c t i on u −f e spac e=v −nested26

#Bi l i n e a r form28 de f i n e b i l i n e a r f o rm a −f e spac e=v −symmetric

l a p l a c e one30 rob in l h s

#Linearform32 de f i n e l i n ea r f o rm l −f e spac e=v

source f34 neumann rhs

36 #Numerical s o l u t i o nde f i n e p r e cond i t i on e r c −type=d i r e c t −b i l i n e a r f o rm=a

38 numproc bvp so l v e d i r i c h l e t bc −b i l i n e a r f o rm=a −l i n ea r f o rm=l −g r i d f un c t i on=u −pr e cond i t i on e r=c −maxsteps=100

40 ######### Error eva lua t i on ##########FE−space f o r e r ro r−g r i d f un c t i o n s

42 de f i n e f e spac e ve r r −l 2 −order=0

44 #Coe f f i c i e n t f o r u r e f and gradure fd e f i n e c o e f f i c i e n t u r e f

46 ( s i n ( p i ∗x ) ∗ s i n ( p i ∗y )+1/ (x+y+1) ) ,d e f i n e c o e f f i c i e n t g radure f

48 ( p i ∗ cos ( p i ∗x ) ∗ s i n ( p i ∗y )−1/ ( ( x+y+1)∗ ( x+y+1) ) , p i ∗ s i n ( p i ∗x ) ∗ cos ( p i ∗y )−1/ ( ( x+y+1)∗ ( x+y+1) )) ,

50 #Sca larproduct f o r L2−normde f i n e b i l i n e a r f o rm a l2 −f e spac e=v −nonassemble

52 mass one#Sca larproduct f o r H1−seminorm

54 de f i n e b i l i n e a r f o rm ah1 −f e spac e=v −nonassemblel a p l a c e one

56

Page 68: Solution of Non-Homogeneous Dirichlet Problems with FEM

62 APPENDIX

#Grid funct i ons f o r e r r o r58 de f i n e g r i d f un c t i on e r r l 2 −f e spac e=ver r

d e f i n e g r i d f un c t i on errh1 −f e spac e=ver r60

#Evaluat ing e r r o r s62 numproc d i f f e r e n c e l 2 e r r o r −b i l i n e a r f o rm1=a l2 −s o l u t i o n=u −f unc t i on=ur e f −d i f f=e r r l 2

numproc d i f f e r e n c e h1er ro r −b i l i n e a r f o rm1=ah1 −s o l u t i o n=u −f unc t i on=gradure f −d i f f=errh1

Listing 3: nonhomogeneous robin.pde