An Introduction to the

Dr. Erich Gaertig BU Central / Simulation Hilite Germany GmbH

Tübingen, 17.12.2019 Outline

• Introduction to FEM - Motivation

• Mathematical Description/Numerical Implementation for Linear

Elements on Triangular Meshes

• Solving a Simple PDE on an Irregular Domain in 2D/3D - Demo Introduction

• Complex problems necessitate the need for a flexible and powerful computational technique

• Most real problems are defined on domains that are geometrically complex and may have different boundary conditions on different portions of the boundary

• It is therefore impossible to find an analytical solution; also Finite Differences (FD) are difficult to adapt for arbitrary geometries

• Solution of problems in structural mechanics by known functions with unknown coefficients (Ritz [1909]), later refined by using nodal shape functions (Courant [1943])

• FEM originally developed mainly by engineers in the aerospace environment (The finite element method in plane stress analysis (1960), Turner, Clough, Martin, Topp [1950 - 1960])

• Thorough mathematical investigations and extensions during the 1960s (variational formulation, Argyris, Zienkiewicz, Turner, Reissner)

• First commercial codes showed up in the 1970s (NASAs Nastran commercialized in 1971) Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction

• Instead of satisfying the PDE point-by-point in the computational domain (FD approach), FEM (and other methods as well) uses an weighted integral formulation with test functions, that average the PDE globally

• Consider as an example d du x + u =0, 0

• We seek a solution of the form 2 UN = cj j (x)+0(x) j=1 X

• Here, all three functions satisfy the homogeneous boundary conditions UNLESS there are non-homogeneous ones; then 0 ( x ) has to obey them as well

• Since in this case, there’s only one non-homogeneous BC for the left boundary point, we can make the ansatz U = c + c + with =1, (x)=x 2 2x, (x)=x 3 3x 2 1 1 2 2 0 0 1 2 Introduction

• For U 2 ( x ) to satisfy the PDE, we need to have dU d 2U 2 x 2 + U = 2c (x 1) 3c (x 2 1) 2c x 6c x 2 dx dx 2 1 2 1 2 +c (x 2 2x)+c (x 3 3x)+1=0 1 2

• This relation has to hold for all x , comparing powers leads to

1+2c1 +3c2 =0 6c 3c =0 1 2 c 9c =0 1 2 c2 =0

• These relations are inconsistent; there is no solution to this linear system at all!!

• Instead, multiply both sides of the PDE with a weight function and integrate over the domain 1 dU d 2U w(x)R(x)dx = 0 with R(x)= 2 x + U dx dx2 2 Z0

• From this, we obtain as many linearly independent equations as there are linear independent weight functions. Since here we have N =2 , let’s choose w =1 and w = x Introduction

• This leads to

1 1 1 1 0= 1 R(x)dx =(1+2c +3c )+ ( 6c 3c )+ (c 9c )+ c · 1 2 2 1 2 3 1 2 4 2 Z0 1 1 1 1 1 0= x R(x)dx = (1 + 2c +3c )+ ( 6c 3c )+ (c 9c )+ c · 2 1 2 3 1 2 4 1 2 5 2 Z0

• These are two linear equations for two unknowns with the solution 222 100 c = ,c = 1 23 2 23

• This is the heart of FEM; if anything, take this from the lecture: By transforming the system of PDEs into an averaged, weighted integral statement, derive a linear system of equations for the unknown expansion coefficients of your global solution

• Even for moderately sized problems in 2D, it’s very easy to get systems with ~ 100.000 unknowns; need for accessible and efficient framework for assembling and solving these systems (2nd part of the talk) Introduction

• This leads to

1 1 1 1 0= 1 R(x)dx =(1+2c +3c )+ ( 6c 3c )+ (c 9c )+ c · 1 2 2 1 2 3 1 2 4 2 Z0 1 1 1 1 1 0= x R(x)dx = (1 + 2c +3c )+ ( 6c 3c )+ (c 9c )+ c · 2 1 2 3 1 2 4 1 2 5 2 Z0

• These are two linear equations for two unknowns with the solution 222 100 c = ,c = 1 23 2 23

• This is the heart of FEM; if anything, take this from the lecture: By transforming the system of PDEs into an averaged, weighted integral statement, derive a linear system of equations for the unknown expansion coefficients of your global solution

• Even for moderately sized problems in 2D, it’s very easy to get systems with ~ 100.000 unknowns; need for accessible and efficient framework for assembling and solving these systems (2nd part of the talk) Introduction

• This leads to

1 1 1 1 0= 1 R(x)dx =(1+2c +3c )+ ( 6c 3c )+ (c 9c )+ c · 1 2 2 1 2 3 1 2 4 2 Z0 1 1 1 1 1 0= x R(x)dx = (1 + 2c +3c )+ ( 6c 3c )+ (c 9c )+ c · 2 1 2 3 1 2 4 1 2 5 2 Z0

• These are two linear equations for two unknowns with the solution 222 100 c = ,c = 1 23 2 23

• This is the heart of FEM; if anything, take this from the lecture: By transforming the system of PDEs into an averaged, weighted integral statement, derive a linear system of equations for the unknown expansion coefficients of your global solution

• Even for moderately sized problems in 2D, it’s very easy to get systems with ~ 100.000 unknowns; need for accessible and efficient framework for assembling and solving these systems (2nd part of the talk) Introduction

• Note:

• There are (at least) three problems with this approach (Ritz method, 1908)

• The matrix one needs to solve for the unknown expansion coefficients c i typically is dense, so computations will be slow; even more so, if high accuracies are needed

• For complicated PDEs, it might be very difficult to find basis functions that automatically satisfy the imposed boundary conditions

• It is not clear, how to choose the weighting functions for the integration; different

choices will naturally lead to different coefficients c i (you need ALL of them in a sense)

• All these issues are remedied by a proper formulation of the Finite Element Method; in particular

• it will lead to a linear system with sparse matrices (so very efficient algorithms for solving these type of systems can be employed)

• very simple basis functions are used; boundary conditions are transparently encoded in the integral statements as well

• the very same functions are used as basis for the weights in the FE-formulation Introduction

• Note:

• There are (at least) three problems with this approach (Ritz method, 1908)

• The matrix one needs to solve for the unknown expansion coefficients c i typically is dense, so computations will be slow; even more so, if high accuracies are needed

• For complicated PDEs, it might be very difficult to find basis functions that automatically satisfy the imposed boundary conditions

• It is not clear, how to choose the weighting functions for the integration; different

choices will naturally lead to different coefficients c i (you need ALL of them in a sense)

• All these issues are remedied by a proper formulation of the Finite Element Method; in particular

• it will lead to a linear system with sparse matrices (so very efficient algorithms for solving these type of systems can be employed)

• very simple basis functions are used; boundary conditions are transparently encoded in the integral statements as well

• the very same functions are used as basis for the weights in the FE-formulation Introduction

• Note:

• There are (at least) three problems with this approach (Ritz method, 1908)

• The matrix one needs to solve for the unknown expansion coefficients c i typically is dense, so computations will be slow; even more so, if high accuracies are needed

• For complicated PDEs, it might be very difficult to find basis functions that automatically satisfy the imposed boundary conditions

• It is not clear, how to choose the weighting functions for the integration; different

choices will naturally lead to different coefficients c i (you need ALL of them in a sense)

• All these issues are remedied by a proper formulation of the Finite Element Method; in particular

• it will lead to a linear system with sparse matrices (so very efficient algorithms for solving these type of systems can be employed)

• very simple basis functions are used; boundary conditions are transparently encoded in the integral statements as well

• the very same functions are used as basis for the weights in the FE-formulation Introduction

• There are various reasons for using an integral version of the PDE

• even for smooth initial data, PDEs may exhibit discontinuous behaviour

• discontinuous source functions or irregular domains also lead to non-classical solutions

• Consider as prototype example the Poisson equation 2 u = f in an open domain ⌦ r • a classical solution has continuous second derivatives in the interior ( u C 2 ( ⌦ ) ) and is 2 continuous up to the boundary (u C 0 ( ⌦ ) ) 2

• If the source function is discontinuous (e.g. weight placed on parts of a membrane), then u/C2(⌦) 2

• The same happens for so-called re-entrant corners in a non-convex domain 2✓ + ⇡ ⌦ =[ 1, 1]2 [ 1, 0]2 , = , f =0, g = u , u = r 2/3 sin \ D | 3 (null) ✓ ◆ Lesson 1

Linear triangular elements

1 The model problem

All along this course we will be working with a simple model boundary value problem, which will allow us to put the emphasis on the numerical method rather than on the intricacies of the problem itself. For some of the exercises and in forthcoming lessons we will complicate things a little bit. In this initial section there is going to be a lot of new stuÆ. Take your time to read it carefully, because we will be using this material during the entire course.

1.1 The physical domain TheMathematical first thing we haveDescription/Numerical to describe is the geometry Implementation (the physical setting of the problem). You have a sketch of it in Figure 1.1. • Our model problem is

ΓD Γ u + cu = f in ⌦ N Ω u = g0 on D

@nu = g1 on N

• Multiply with test function, integrate and use Green’s Figureidentity 1.1: The domain ≠ and the Dirichlet and Neumann boundaries We are thus given a polygon in the plane R2. We call this polygon ≠. Its boundary is a closed polygonal curve °. (There is not much diÆerence if we suppose that there is (u)v + u v = (@nu)v = (@nu)v + (@nu)v ⌦ ⌦ r r D N Z Z Z Z Z 3

1 • Impose v =0 on D and search for solutions u H ( ⌦ ) such that 2 u = g0 on D

1 u v + c uv = fv+ g1v v H (⌦) r r 8 2 D Z⌦ Z⌦ Z⌦ ZN (weak formulation)

1 2 @u @u 2 1 1 H (⌦) = u L (⌦) , L (⌦) H (⌦) = v H (⌦) v = 0 on D 2 @x @x 2 D 2 ⇢ 1 2 Lesson 1

Linear triangular elements

1 The model problem

All along this course we will be working with a simple model boundary value problem, which will allow us to put the emphasis on the numerical method rather than on the intricacies of the problem itself. For some of the exercises and in forthcoming lessons we will complicate things a little bit. In this initial section there is going to be a lot of new stuÆ. Take your time to read it carefully, because we will be using this material during the entire course.

1.1 The physical domain TheMathematical first thing we haveDescription/Numerical to describe is the geometry Implementation (the physical setting of the problem). You have a sketch of it in Figure 1.1. • Our model problem is

ΓD Γ u + cu = f in ⌦ N Ω u = g0 on D essential BC

@nu = g1 on N natural BC

• Multiply with test function, integrate and use Green’s Figureidentity 1.1: The domain ≠ and the Dirichlet and Neumann boundaries We are thus given a polygon in the plane R2. We call this polygon ≠. Its boundary is a closed polygonal curve °. (There is not much diÆerence if we suppose that there is (u)v + u v = (@nu)v = (@nu)v + (@nu)v ⌦ ⌦ r r D N Z Z Z Z Z 3

1 • Impose v =0 on D and search for solutions u H ( ⌦ ) such that 2 u = g0 on D

1 u v + c uv = fv+ g1v v H (⌦) r r 8 2 D Z⌦ Z⌦ Z⌦ ZN (weak formulation)

1 2 @u @u 2 1 1 H (⌦) = u L (⌦) , L (⌦) H (⌦) = v H (⌦) v = 0 on D 2 @x @x 2 D 2 ⇢ 1 2 Mathematical Description/Numerical Implementation

• By reducing the smoothness of the solution variable required by the weak formulation 2 (i.e. C 1 ( ⌦ ) instead of C ( ⌦ ) ), we can get a weak solution, that is not smooth enough to be a classical solution

• One even extends the admissible function space to include C 0 ( ⌦ ) - functions as well via so- called weak derivatives:

• for v C 01 ( ⌦ ) , the partial integration relation in 1D reads 2

u0v = uv0 Z⌦ Z⌦ • idea: use this as the definition for the weak derivative of u

• we call @ x u w the weak derivative of u , if |

@ u v = uv0 v C1(⌦) x |w 8 2 0 Z⌦ Z⌦

• This means, differentiation is also defined via integration over test functions

• Advantage: functions, that are classically not differentiable nevertheless are weakly differentiable, e.g. u(x)= x | | Mathematical Description/Numerical Implementation

• Similar definitions for weak derivatives exist for all differential operators, e.g. div, rot etc.; these are used for computational electrodynamics for example

2 2 • example: a function u w L ( ⌦ ) is called weak divergence of u L ( ⌦ ) , if for any r · | 2 2 function v C1(⌦) 2 0 u v = u v r · |w · r Z⌦ Z⌦

(hint: use Gauss’ theorem)

1 1 • The test space H ( ⌦ ) = v H ( ⌦ ) v = 0 on D with weak derivatives and equipped with D 2 u,v := (uv + u v) dx h i r · r Z⌦ is a special , a so-called

AAADeXicjVLbTttAED2Je+HSC7R964sLQkorFNnBKPCGVFrxgqAqAaRAq7Wzca34Jq8TNSA+g1f4rn5L+9Czi4OUh5SutZ7ZMzNnZmfHz+NIlY7zq1a3Hj1+8nRufmHx2fMXL5eWXx2rbFgEshNkcVac+kLJOEplp4zKWJ7mhRSJH8sTf/BR209GslBRlh6V41yeJyJMo34UiJJQd++b2zg7SGQo3n9fWnWajtd2NrdtKq22t+lScbecje2W7TYds1Z33vTNOsyWa+s4Qw8ZAgyRQCJFST2GgOLXhQsHObFzXBIrqEXGLnGFBcYO6SXpIYgO+A956lZoyrPmVCY6YJaYu2CkjTXuz4bRp7fOKqkryj/cFwYLZ2a4NMy6wjGlT8Z5w7hPvMQPejwUmVSek1r+J1Khfx+3zogUX6v8+mb/6kcPI/Ytp226Jz+nujI7c86MY1p079UDnS9Z5ZZhj5gtN4h+i+D+rru0FMQGxmLjk/EMyeGb84j1pJQdVqonYcJgm1fpUQojpWFJK0ZBvoJSTwjr4SxOBs6erRy3mq7X9L5wKD3crTm8xQoanLw2drCHQ9ahu3SNG9zWf1vvrIb14c61XqtiXmNqWRt/AYL1tLQ= AAADhnicjVLbbtNAED2puaTllhaJF3iwqJCKVFl2cJT0LRIF+oIogrSVmhKtna2x4ptsJ2oI/Zm+gsSX8AH8BR/AA2e3TqU8hLLWembPzJyZnR0vi8KitO1ftRXjxs1bt+ura3fu3rv/oLG+cVCk49yXPT+N0vzIE4WMwkT2yrCM5FGWSxF7kTz0Ri+V/XAi8yJMk4/lNJMnsQiS8DT0RUlo0Hi098kZzPpvRByLwe75Vv9dLAPxfNDYtC3bbdutHZNKs+22HCpOx36x0zQdy9Zrs/uk89P8cfF7P12vbaOPIVL4GCOGRIKSegSBgt8xHNjIiJ1gRiynFmq7xDnWGDuml6SHIDriP+DpuEITnhVnoaN9Zom4c0aaeMb9WjN69FZZJfWC8g/3F40FSzPMNLOqcErpkXFVM74lXuIzPa6LjCvPeS3/E1ng9CpumxEJPlT51c3+1Y8hJuxbRttiT84WurI8c8aMU1pU74trOl+yyo5mD5kt04h6C//qrru05MRG2mLilfYMyOHp84T1JJQ9VqomYc5g6lcZUgotpWZJKkZBvpxSTQjr4SzOB85crhw0Lce13PccSheXq47HeIotTl4bXexhn3X4+IoLfMN3o25YRstoX7qu1KqYh1hYRvcvwAG5lw== Mathematical Description/Numerical Implementation

• 1 1 Now keep in mind that the so defined function- and test-spaces H ⌦ and H D ⌦ are infinite-

dimensional vector spaces (the latter being a proper sub-vectorspace( )of the former)( )

• This makes it difficult for a direct numerical implementation of the weak formulation (computers can’t handle infinities very well…)

• We need to restrict ourselves (and set up) a convenient, finite-dimensional version of the two different Sobolev-spaces involved here

• These surrogates, being finite-dimensional vector-spaces, therefore feature a finite basis as well

• The weak formulation can then be recast in terms of a cleverly chosen basis („hat-functions“)

• This leads to a linear system of equations for the approximate solution of the PDE within the particular function space

• An obvious question then is: How well does this approximation represent the true solution of the original problem (existence and uniqueness, convergence behavior, refinement, etc.)

• We’re not going to delve into this; see literature list at the end of this talk Mathematical Description/Numerical Implementation

• In order to solve our test problem numerically, we need to discretize the physical domain (triangulation), the function space (finite elements) and the weak formulation (assembly)

• A triangulation h of ⌦ is a subdivision of this domain into triangles, so that T • if two triangles have some intersection, it is either on a common vertex or a common full edge. In particular, two triangles do not overlap

• the triangulation has to respect the partition of the boundary into Dirichlet and Neumann boundary

Γ N

Γ D

Figure 1.4: A forbidden transition of Dirichlet to Neumann boundary conditions happen- valid triangulation hanging nodes improper partitioning Figure 1.5: A triangulationFigure of ≠ 1.3: Situations not admitted in triangulations.ing inside In an edge.the second Graphical one notation we see for the Dirichlet a Neumann boundaries as shown in appearance of what is called a hanging node. many Mechanics books are give in the graph x2 Because of what we have explained above, if we fix one node (vertex) and associate 2.3 Piecewise linear functions on athe triangulation value one to this node and zero to all others, there exists a unique function 'i Vh K K’ that has these values, that is, 2 We now turn our attention to functions defined on the whole of the polygon ≠ that has 1,j= i, x been triangulated as shown before. ' (p )=± = 1 i j ij 0,j= i. Consider first two triangles sharing a common edge, say K and K0 (see Figure 1.6).Ω 6 We take values at the four vertices of this figure andThe aspectbuild aof function one of these that functions belongs is shown to P1 in Figure 1.8. Figure 1.6: Two triangles withon a common each of edge the triangles and has the required valuesNotice on the that vertices. if a triangle ObviouslyK has not wepi canas one of its vertices, 'i vanishes all over K, define a unique function with this property. Moreover,since the since value ofthe'i valueon the on three the vertices common of K is zero. Therefore, the support of 'i (the closure of the set of points where 'i is not zero) is the same as the union of triangles that There is a particularly interesting aspect of this basisedge of dependsVh that makes only on it especial. the values In on the two common vertices, the resulting function is share pi as vertex. In Figure 1.9 you can see the type of supports you can find. general if you have a basis of Vh you know that youcontinuous. can decompose elements of Vh as a There is even more. Take uh Vh. It is simple to see that unique linear combination of the elements of the basis,We that can is, do this triangle by triangle. We end up with a function that is linear2 on each N N triangle and globally continuous. The space of such functions is u = u (p )' . u = u ' h h j j h j j j=1 j=1 V = u (≠) u , K . X X h h h K P1 h N 2 C | 2 Why?8 Let me2 T explain. Take the function j=1 uh(pj)'j and evaluate it in pi: you obtain is a general element of Vh. With this basis, the coe±cients are precisely the valuesn of uh Ø o on the nodes, that is, u = u (p ). Hence, the coe±Ifcients we fixof u valuesin this on basis the are set something of vertices of theØ triangulation , there existsN a unique u PVN j h j h Ø Th h 2 h more than coe±cients: there are values of the functionwith on those points. values on the vertices. Therefore an element of Vh is uniquelyuh determined(pj)'j(pi)= by uh(pj)±ji = uh(pi). j=1 j=1 its values on the set of vertices of the triangulation. The values onX the vertices of theX An important result. As you can see, when defining the space V we have just glued whole triangulationh are the degrees of freedom thatTherefore, determine this function an element has exactly of Vh. the In same this nodal values as uh and must be uh. The together functions on triangles. Thanks to the way we have made the triangulation P1 context we will call nodes to the vertices in theirfact role that as two points functions where of V weh with take the values. same nodal values are the same function is the and to the way we chose the local degrees of freedom, what we obtained was a continuous linear independence of the nodal functions ' . What we have proved is the fact that (Note that in forthcoming lessons there will be other nodes in addition to vertices). { i} function. One can think, is this so important? Could I take something discontinuous? At 'i i =1,...,N is a basis of Vh and therefore this level, the answer is a very load and clear NO! TheElements reason is the of following the space resultVh are that called linear finite{ element| functions} or simply P1 finite elements.1 dim V = N =# vertices . allows us to know whether certain functions are in H (≠) or not. h { } Let us take now a numbering of the set of nodes (that is, vertices) of the triangulation. Theorem. Let uh be a function defined onAt a triangulation this moment of any≠ such numbering that goes2. In Figure 1.7 we have a numbering of the nodes13 of the triangulation of our model domain. The vertices will be generically denoted pi with 14 i varying from one to the number of vertices, which we call N.

2And in many instances this will be so to the end of the discretization process. Using one numbering or another has a great influence on the shape of the linear section we will obtain in Section 3, but this shape is relevant only for some choices of the method to solve the corresponding linear system

12 AAADeXicjVLbTttAED2Je+HSC7R964sLQkorFNnBKPCGVFrxgqAqAaRAq7Wzca34Jq8TNSA+g1f4rn5L+9Czi4OUh5SutZ7ZMzNnZmfHz+NIlY7zq1a3Hj1+8nRufmHx2fMXL5eWXx2rbFgEshNkcVac+kLJOEplp4zKWJ7mhRSJH8sTf/BR209GslBRlh6V41yeJyJMo34UiJJQd++b2zg7SGQo3n9fWnWajtd2NrdtKq22t+lScbecje2W7TYds1Z33vTNOsyWa+s4Qw8ZAgyRQCJFST2GgOLXhQsHObFzXBIrqEXGLnGFBcYO6SXpIYgO+A956lZoyrPmVCY6YJaYu2CkjTXuz4bRp7fOKqkryj/cFwYLZ2a4NMy6wjGlT8Z5w7hPvMQPejwUmVSek1r+J1Khfx+3zogUX6v8+mb/6kcPI/Ytp226Jz+nujI7c86MY1p079UDnS9Z5ZZhj5gtN4h+i+D+rru0FMQGxmLjk/EMyeGb84j1pJQdVqonYcJgm1fpUQojpWFJK0ZBvoJSTwjr4SxOBs6erRy3mq7X9L5wKD3crTm8xQoanLw2drCHQ9ahu3SNG9zWf1vvrIb14c61XqtiXmNqWRt/AYL1tLQ= Mathematical Description/Numerical Implementation

• Consider bi-linear functions on one of these triangles 3

p P1 = a0 + a1x1 + a2x2 a0,a1,a2 R 2 { | 2 } K • They are uniquely determined by 2

• either from its three defining coefficients 1 • or from its values on the three vertices of a triangle K Figure 1.2: A triangle and its three vertices • in particular, the value of p P 1 on any edge of the triangle depends only on the 2 values of p at the two attached vertices or from its values on the three vertices of a triangle K. • Both possibilities state that the space P1 is a of dimension three. While the first choice (coe±cients)Figure gives us 1.5: a simple A triangulation expression of of the≠ function, the second is more • Two piecewise linear functions on triangles sharinguseful fora common many tasks, edge in can particular be continuously for drawing the function. The three values of the function on the vertices will be called the local degrees of freedom. glued together. Do this globally and arrive at the P 1 - finite element space x There is another important property that2 will be extremely useful in the sequel: the 0 value of p P1 on the edge that joins two vertices of the triangle depends only on the Vh = uh (⌦) uh K P1 2K h values of p on this two vertices. In other words, the value of p P1 on an edge is uniquely 2 C | 2 8 2 T K K’ 2 determined by the degrees of freedom associated to the edge, namely, the values of p on the two vertices that lie on that edge.

x1 2.2 Triangulations • Any element of this space is uniquely determined by its values on the nodes of the So far we have functions on a single triangle. Now we go for partitions of the domain into triangulation (here, nodes = vertices) triangles. A triangulationFigure 1.6: of Two≠ is triangles a subdivision with of a this common domain edge into triangles. Triangles • This space will serve as finite-dimensionalmust surrogate cover all for≠ butthe nofunction more and space must H fulfill1 ⌦ the following rule: There is a particularlyIf two triangles interesting have some aspect intersection, of this it basis is either of V onh that common makes vertex it or especial. a In ( ) general if youcommon have a full basis edge. of InVh particular,you know two that diÆerent you cantriangles decompose do not overlap. elements of Vh as a unique linearFigure combination 1.3 shows two forbidden of the elements configurations. of the basis,See Figure that 1.5 is, to see how a triangulation looks like. There is another rule, related to the partition of ° into ° and ° : N D N

The triangulation must respectuh the= partitionuj 'j of the boundary into Dirichlet and Neumann boundaries. j=1 X This means that an edge of a triangle that lies on ° cannot be part Dirichlet and part is a general element of Vh. With this basis, the coe±cients are precisely the values of uh Neumann. Therefore if there is a transition from Dirichlet to Neumann boundaries, there on the nodes, that is, u = u (p ). Hence, the coe±cients of u in this basis are something must be a vertexj of a triangleh j in that transition point. Note thath this situation has to be more thantaken coe into±cients: account there only when are values there is of a the transition function from on Dirichlet points. to Neumann conditions inside a side of the polygon ≠. An importantThe set result. of the trianglesAs you (that can is, see, the when list thereof) defining will the be space generallyVh we denoted have justh. The glued subindex h makes reference to the diameter of the triangulation, defined as theT length together P1 functions on triangles. Thanks to the way we have made the triangulation and to theof the way longest we chose edge the of all local triangles degrees, that of is, freedom, the longest what distance we obtained between was vertices a continuous of the triangulation. function. One can think, is this so important? Could I take something discontinuous? At this level, the answer is a very load and clear11 NO! The reason is the following result that allows us to know whether certain functions are in H1(≠) or not.

Theorem. Let uh be a function defined on a triangulation of ≠ such that

14 Mathematical Description/Numerical Implementation

• Remark: There is a whole ‚zoo‘ of tailor-made elements (Periodic Table of Finite Elements) 14 10 5

15 6 11 2

16 12 18 3 7

1

8 17 4 13

Mathematical Description/Numerical9 Implementation

• Let’s denote the nodes with p j ,j =1 ...N =# vertices . For a fixed node, consider the { } Figure 1.7: Global numbering of nodes unique function 1,j= i 'i (pj )=ij = 0,j= i ( 6

• Now take any u h V h ; it is easy to see (why?) that 2 N Figure 1.8: The graph of a nodal basis function: it looks like a camping tent. uh = uh(pj )'j j=1 X restricted to each triangle it is a polynomial (or smooth) function. Then

1 • Therefore ' i i =1 ...N is a basis of V h and u H (≠) u is continuous. { | } h 2 () h dimThereV = isN certain=# vertices intuition to be had on why this result is true. If you take a derivative of a h { } piecewise smooth function, you obtain Dirac distributions along the lines where there are discontinuities. Dirac distributions are not functions and it does not make sense to see if • It’s even a very special basis, sincethe the are expansion square–integrable coefficients or not. are Therefore,values of the if there function are discontinuities, on the function fails to have a square–integrable gradient. nodes N uh =2.4= c Dirichletj 'j with cj = nodesuh(pj ) j=1 X So far we have taken into account the discrete version of the domain ≠ but not the partition of its boundary ° into Dirichlet and Neumann sides. We first need some terminology. A Dirichlet edge is an edge of a triangle that lies on °D. Similarly a Neumann edge is an edge of a triangle that is contained in °N . The vertices of the Dirichlet edges are called Dirichlet nodes. Notice that the doubt may arise in transitions from the Dirichlet to the Neumann part of the boundary. If a node belongs to both °N and °D it is a Dirichlet node.

15 Mathematical Description/Numerical Implementation

• The boundary needs a separate treatment

• a Dirichlet edge is an edge of a triangle that lies on D ; its vertices are the Dirichlet nodes Figure 1.9: Supports of two nodal basis functions • a Neumann edge is an edge of a triangle that is contained in N

• if a node belongs to D and N , its a Dirichlet node N D

• 1 The finite element representation of H D ( ⌦ ) is

D 1 V = Vh H = vh Vh vh = 0 on D h \ D { 2 | } Figure 1.10: Dirichlet nodes corresponding to the domain as depicted in Figure 1.1

D D • v h V if and only if it vanishes on all Dirichlet nodes (why?). Can we find a basis for V ? 2 h In truth, in parallel to what happens with howh the Dirichlet and Neumann boundary conditions are treated in the weak formulation, we will inherit two diÆerent discrete entities:

Dirichlet nodes, and • • If we separate the number of nodes into free/independent nodesNeumann and edges. Dirichlet nodes, a basis of • D mVh is given by (why?) Let us now recall the space 1 1 H (≠)= v H (≠) v =0 on°D . °D { 2 | } vh = vj 'j , with vj = vWeh( mightpj ) be interested in the space j Ind °D 1 X2 V = Vh H (≠)= vh Vh vh =0, on °D . h \ °D { 2 | } 16 • This proves that

dim V D =# Ind =# nodes # Dirichlet nodes h { } { } { } Mathematical Description/Numerical Implementation

• After all these preliminaries, we’re finally able to derive the FEM-version of our model problem. Recall, that our objective is to

• find u H 1 ( ⌦ ) , such that 2 u = g0 on D

1 u v + c uv = fv+ g1v v H (⌦) r r 8 2 D Z⌦ Z⌦ Z⌦ ZN

• The associated discrete problem is then given by

• find u h V h , such that 2 u (p )=g (p ) j Dir h j 0 j 8 2

u v + c u v = fv + g v v V D r hr h h h h 1 h 8 h 2 h Z⌦ Z⌦ Z⌦ ZN

• This means especially

• we look for solutions in the finite-dimensional FE-space instead of the whole

(infinite-dimensional) Sobolev space ( dim V h = N =# vertices ) { } • the values on Dirichlet nodes are already fixed (only # Ind unknowns) { } • testing space is reduced to V D (and dim V D =# Ind ) h h { } Mathematical Description/Numerical Implementation

• D Since we know a basis for V h , this is equivalent to

u ' + c u ' = f' + g ' i Ind r hr i h i i 1 i 8 2 Z⌦ Z⌦ Z⌦ ZN

• Next, let’s write

uh = uj 'j + uj 'j j Ind j Dir X2 X2

= uj 'j + g0(pj )'j j Ind j Dir X2 X2

• Taking the gradient, inserting and rearranging the Dirichlet-data to the right leads to

' ' + c ' ' u = f' + g ' r j r i j i j i 1 i j Ind ✓ ⌦ ⌦ ◆ ⌦ N X2 Z Z Z Z ' ' + c ' ' g (p ) r j r i j i 0 j j Dir ✓ ⌦ ⌦ ◆ X2 Z Z

• This represents a matrix-vector equation which can be inverted to solve for the # Ind { } unknowns uj

• Of course, the matrix- and righthand side-entries need to be computed numerically (assembly) Ns h v dx = ci i dx ⌦e = ⌦e Z Xi 1 Z

Introduction Applications Weighted Residuals Finite Elements Essential BCs Complex Problems Adaptivity

Mathematical Description/Numerical Implementation An element integral will • Consider for example the matrix contributionshave contributions (RHS works only similar) from the global basis w = ' ' = ' ' = w K ij r i r functionsj correspondingr i r j ij ⌦ K K K Z to itsX2 nodes.Th Z X2Th ΩKe We call these local basisK mij = 'i 'j = 'i 'j = mij functions i, 0 i Ns. ⌦ K K K Z X2Th Z  X2Th

Ns h v = cii h ⌦e T • i=1 In theory, the indices i,j run over all independent X nodes, but • due to the special form of our nodal basis functions, only basis functions corresponding to the nodes of the triangle contribute (why?)

K K • the matrices w ij ,m ij therefore only have 9 entries in total, on positions depending on the global numbering of the nodes

• all these local contributions from the various cells need to be assembled to the global system matrix and righthand-side

• This leads to a sparse linear system, which is the reason why it is possible to solve problems with millions/billions of unknowns (use CG for example) Ns h v dx = ci i dx ⌦e = ⌦e Z Xi 1 Z

Introduction Applications Weighted Residuals Finite Elements Essential BCs Complex Problems Adaptivity

Mathematical Description/Numerical Implementation An element integral will • Consider for example the matrix contributionshave contributions (RHS works only similar) from the global basis w = ' ' = ' ' = w K ij r i r functionsj correspondingr i r j ij ⌦ K K K Z to itsX2 nodes.Th Z X2Th ΩKe We call these local basisK mij = 'i 'j = 'i 'j = mij functions i, 0 i Ns. ⌦ K K K Z X2Th Z  X2Th

Ns h v = cii h ⌦e T • i=1 In theory, the indices i,j run over all independent X nodes, but • due to the special form of our nodal basis functions, only basis functions corresponding to the nodes of the triangle contribute (why?)

K K • the matrices w ij ,m ij therefore only have 9 entries in total, on positions depending on the global numbering of the nodes

• all these local contributions from the various cells need to be assembled to the global system matrix and righthand-side

• This leads to a sparse linear system, which is the reason why it is possible to solve problems with millions/billions of unknowns (use CG for example) Introduction Applications Weighted Residuals Finite Elements Essential BCs Complex Problems Adaptivity

Mathematical Description/Numerical Implementation

• For efficient evaluation of the nodal basis functionsThe and integrals their gradients are performed (and also to on a “reference” element ˆ increase performance and accuracy), all calculations⌦e are performed on a reference cell

x(ξ) • The Jacobian of the map x ( ⇠ ) is J x ξ KΩe ΩKˆe • We then have for example

f'i dx = fˆ(⇠)ˆ'i (⇠) det J d⇠ ˆ The| Jacobian| of the map x(⇠) is J. ZK ZK

'i 'j dx = 'ˆi (⇠)ˆ'j (⇠) det J de⇠ K Kˆ | F| i = f idx = f (x(⇠))i J d⇠ Z Z ˆ | | Z⌦e Z⌦e • The gradients are more tricky…

1 1 'i 'j dx = J ˆ 'ˆi (⇠)J ˆ 'ˆj (⇠) det J d⇠ r r ˆ r r | | ZK ZK

• The integrals are numerically evaluated using Gauss quadrature with quadrature points ⇠ e

and weights w e , e.g. N

fˆ(⇠)ˆ'i (⇠) det J d⇠ = fˆ(⇠e )ˆ'i (⇠e ) det J(⇠e ) we ˆ | | | | K e=1 Z X 14 10 5 19 17 Mathematical Description/Numerical Implementation 20 15 16 6 18 11 2 21 • 15 Want to do it from scratch? How does the assembly process might look like for P 1 - elements?4 16 22 7 12 14 18 1 3 5 7 14 10 13 6 8 23 5 1 19 2 3 17 11 K 20 12 18 15 8 • Take as an example wij = 'i 'j = 'i 'j = wij 16 6 11 17 2 9 ⌦ r r K r r 21 4 10 K h K h 15 Z 2T Z 2T 4 16 22 13 X X 7 12 14 18 1 3 5 7 13 6 23 9 1 8 K K K 2 3 • p , p , p 11 12 For each triangle, assign a number to its vertices 1 2 3 8 17 4 9 10 13 Figure 2.2: A numbering of the triangles

K K K 9 3 • Consider the three functions N 1 ,N 2 ,N 3 P 1 with 2 Figure 2.2: A numbering of the triangles

3 K K K 2 N↵ p = ↵ ↵, =1, 2, 3 local global K 1 1 12 2 2 $ 16 local global • n ↵ K 3 $ 11 Let ↵ be the global node number of the local node with number of1 the triangle . Then1 12 $ 2 $ 16 3 $ 11 $ K Figure 2.3: The 14th triangle and their vertex numberings N↵ = 'n↵ K on Figure 2.3: The 14th triangle and their vertex numberings The assembly process requires then a given numbering of triangles as shown in Figure The assembly process2.2. requires The order then a of given this numbering numbering of triangles is only as used shown to in do Figure the computations but does not modify • This allows us to compute 2.2. The order of thisthe numbering shape is of only the used final to do result. the computations but does not modify the shape of the final result. The process to assembleThe the process mass matrix to assemble is the same. the EÆective mass assembly matrix of is the the mass same. EÆective assembly of the mass and stiÆness matricesand can be sti doneÆness at thematrices same time. can Instead be done of computing at the same separately time. the Instead of computing separately the K K K K matrix KK and a similar one forK the mass matrix, we can directly try to compute the k↵ = N↵ = wn n ↵, =1, 2, 3 matrix K and a similar one for the mass matrix, we can directly try to compute the ↵ 3 3 matrix with elements K r · r £ 3 3 matrix with elements Z £ N K N K + c N K N K , Æ, Ø =1, 2, 3. r Ø · r Æ Ø Æ ZK ZK N K N K + c N K N K , Æ, Ø =1, 2, 3. K r Ø · r Æ Ø Æ • The global matrix is then assembled by all sub-matrices W = W ZK ZK K X2 Th

26

26 1.2 The reference element To compute the elements

N K N K and N K N K r Ø · r Æ Ø Æ ZK ZK K we need: (a) either and eÆective way of evaluating the functions NÆ and their gradients; (b) or a closed form for the resulting integrals. Both possibilities are done usually by moving to the so–called reference element. For triangles, the reference element is the triangle with vertices Mathematical Description/Numerical Implementation p1 =(0, 0), p2 =(1, 0), p3 =(0, 1). To distinguish variables in the reference element and in a general triangle (in this context • As previously described, use reference elements to do the calculations. For triangles,b it isb b

3 pˆ1 =(0, 0) , pˆ2 =(1, 0) , pˆ3 =(0, 1)

• The functions N ˆ ↵ (ˆ p )= ↵ are given by K^

Nˆ1 =1 ⇠ ⌘ , Nˆ2 = ⇠ , Nˆ3 = ⌘ 1 2 K K K • For the triangle K with p 1 =( x 1 ,y 1 ) , p 2 =( x 2 ,y 2 ) , p 3 =( x 3 ,y 3 ) , we have the bijective Figure 2.4: The reference element affine transformation FK :(⇠, ⌘) (x,y) ! we say a physical element) it is customary to use the variables (ª, ¥) in the reference element and (x, y) in the physical element. In the mathematical literature for FEM it is x x2 x1 x3 x1 ⇠ x1 = + also usual to hat variables in the reference element, so that (ˆx, yˆ) would be used to denote y y y y y ⌘ y ✓ ◆  2 1 3 1 ✓ ◆ ✓coordinates1 ◆ in the reference configuration. B K An unimportant detail. Some people prefer to use a diÆerent reference triangle, with • It is easy to show, that | {z } the same shape but with vertices on ( 1, 1), (1, 1) and ( 1, 1). Some details of the forthcoming computations have to be adapted° ° if this° choice is° taken. FK (ˆp↵)=p↵ , ↵ =1, 2, 3 The local nodal functions in the reference triangles are three P1 functions satisfying • Furthermore NÆ(pØ)=±ÆØ, Æ, Ø =1, 2, 3. ˆ K N↵ = N↵ FK , ↵ =1, 2, 3 These functions are precisely b b

N1 =1 ª ¥, N2 = ª, N3 = ¥ K ˆ 1 K ˆ 1 ° ° N↵ = N↵ FK , ↵ =1, 2, 3 i.e. N↵ (x,y)=N↵(FK (x,y)) or, if you prefer hatting variablesb (this is theb last time web will write both expressions)

N1 =1 x y, N2 = x, N3 = y • Since the inverse affine transformation is straightforward to compute, this is a simple° ° way of K b b b 27b b b b evaluating the functions N ↵ needed for the FE-integrals 1.2 The reference element To compute the elements

N K N K and N K N K r Ø · r Æ Ø Æ ZK ZK K we need: (a) either and eÆective way of evaluating the functions NÆ and their gradients; (b) or a closed form for the resulting integrals. Both possibilities are done usually by moving to the so–called reference element. For triangles, the reference element is the triangle with vertices Mathematical Description/Numerical Implementation p1 =(0, 0), p2 =(1, 0), p3 =(0, 1). To distinguish variables in the reference element and in a general triangle (in this context • Evaluating gradients needs more care, since one has to use the chain rule b b b

3

@x @⇠ • For = and ˆ = , it is for an arbitrary function r @y r @⌘ ✓ ◆ ✓ ◆ K^

T ˆ BK ( FK )= ( FK ) r r 1 2 = NK or (with ↵ ) Figure 2.4: The reference element

K T 1 we say a physical element) it is customary to use the variables (ª, ¥) in the reference N = B ( ˆ Nˆ ) F r ↵ K r ↵ K element and (x, y) in the physical element. In the mathematical literature for FEM it is also usual to hat variables in the reference element, so that (ˆx, yˆ) would be used to denote • Here, we have coordinates in the reference configuration. An unimportant detail. Some people prefer to use a diÆerent reference triangle, with 1 y y (y they ) same shape but with vertices on ( 1, 1), (1, 1) and ( 1, 1). Some details of the T 3 1 2 1 ° ° ° ° BK = forthcoming computations have to be adapted if this choice is taken. detBK (x2 x1) x2 x1  The local nodal functions in the reference triangles are three P1 functions satisfying N (p )=± , Æ, Ø =1, 2, 3. with Æ Ø ÆØ These functions are precisely b b detB =(x x )(y y ) (y y )(x x ) N1 =1 ª ¥, N2 = ª, N3 = ¥ K 2 1 3 1 2 1 3 1 ° ° or, if you prefer hatting variablesb (this is theb last time web will write both expressions)

• N1 =1 x y, N2 = x, N3 = y Luckily, for this elementary method here, the gradients are constant vectors ° ° 1 1 0 b b b 27b b b b ˆ Nˆ = , ˆ Nˆ = , ˆ Nˆ = r 1 1 r 2 0 r 3 1 ✓ ◆ ✓ ◆ ✓ ◆ Mathematical Description/Numerical Implementation

• Integration is also performed on the reference element; we therefore have

K K ˆ ˆ N N↵ = detBK NN↵ | | ˆ ZK ZK

• We’re done here since only the determinant is dependent on the current triangle and 211 1 Kˆ 0 = NˆNˆ↵ = 121 ˆ 24 2 3 ZK ↵, 112 4 5

• For the gradients, it is

K K T ˆ ˆ T ˆ ˆ N N↵ = detBK BK N BK N↵ r · r | | ˆ r · r ZK ZK = detBK CK ˆ Nˆ ˆ Nˆ↵ | | ˆ r · r ZK where cK cK C = B 1B T = 11 12 K K K cK cK  12 22

is a symmetric 2x2 matrix that depends only on the triangle Mathematical Description/Numerical Implementation

• If we write

1 10 1 Kˆ ⇠⇠ = @⇠Nˆ @⇠Nˆ↵ = 110 ˆ 2 2 3 ZK ↵, 000 4 5

10 1 1 Kˆ ⌘⌘ = @⌘Nˆ @⌘Nˆ↵ = 000 ˆ 2 2 3 ZK ↵, 10 1 4 5

10 1 1 Kˆ ⇠⌘ = @⇠Nˆ @⌘Nˆ↵ = 10 1 ˆ 2 2 3 ZK ↵, 000 4 5

we finally arrive at

NK NK = detB cK Kˆ + cK Kˆ ++cK (Kˆ + Kˆ T ) r · r ↵ | K | 11 ⇠⇠ 22 ⌘⌘ 22 ⇠⌘ ⇠⌘ ZK ↵,

• Doing this calculations for all elements of the triangulation completes the assembly of the system matrix; the same has to be done for the righthand-sides (and possible boundary integrals due to Neumann - conditions…) Demo

• Most commercially available codes contain sophisticated routines for pre-processing…

• automated meshing with tets, quads or mixed elements

• simple ways of local mesh refinement

• defeaturing

• running the simulation…

• apply boundary conditions, forces, stresses etc.

• implicit and explicit solvers for time-evolution, stationary solver

• and post-processing the results

• visualization of the solution(s)

• animations and arbitrary XY-plots

• We will try to solve a simple Poisson equation with similar OpenSource tools

• Gmsh for meshing, deal.II as FE library, VisIt for visualization Demo

• There are a couple of sophisticated OpenSource FE libraries available:

• MOOSE framework (Multiphysics Object-Oriented Software Environment)

• OpenFOAM (OpenSource Field Operation and Manipulation), mainly used for CFD

• The Fenics Project (uses Python scripting for solving PDEs)

• Agros2D (application package with GUI support for meshing and post-processing)

• libmesh (used by MOOSE under the hood)

• deal.ii (Differential Equations Analysis Library, used by Agros2D under the hood)

• The former four provide an additional abstraction layer to the more low-level APIs found in libmesh and deal.ii Demo

Demo Demo Demo Demo Demo Demo Demo Demo Demo Literature

• Zhangxin Chen Finite Element Methods and Their Applications Springer, 2005

• Susanne C. Brenner, L. Ridgway Scott The Mathematical Theory of Finite Element Methods Springer, 2007

• J. N. Reddy An Introduction to the Finite Element Method McGraw Hill, 2006

• Dietrich Braess Finite Elements: Theory, Fast Solvers and Applications in Solid Mechanics Cambridge University Press, 2007

• Young W. Kwong, Hyochoong Bang The Finite Element Method using MATLAB CRC Press, 1996