You are on page 1of 23

The Finite Element Method

Fredrik Berntsson (fredrik.berntsson@liu.se)

Typeset by FoilTEX

The Finite Element Method


Contents:
- Introduction. History. Simple 1D Example.
- Weak Derivatives. Sobolev spaces. Weak formulation.
- Finite Element method. Mesh. Stiffness Matrix.
- Example: Simple boundary value problem in 2D.
- Summary. Course Contents MAI0088.

Typeset by FoilTEX

The Finite Element Method (FEM)


- A general purpose technique for solving boundary value problems for elliptic
PDEs in complicated domains.
- Mostly developed by engineers 19551965 (Ray W. Clough, John Argyris,. . . )
but building on earlier work by Courant, Rayleigh, Ritz, and Galerkin.
- Rigurous mathematical analysis in Strang and Fix, An Analysis of The Finite
Element Method, 1973.

Typeset by FoilTEX

The Finite Element Method


Example: Find u such that

u + 2u = 1,
x (0, 1),
u(0) = 1, and, u(1) = 1.

(1)

Solution: Multiply by a test function and integrate,


Z 1
Z 1
(u + 2u)vdx =
1 vdx.
0

Integrate by parts
Z 1
Z 1
Z
(uv +2uv)dx = u(1)v(1)u (0)v(0)+ (uv +2uv)dx =
0

vdx.
0

Restrict test functions to V = {v C 1(0, 1) such that v(0) = 0}.


Typeset by FoilTEX

We obtain a new problem: Find u such that


Z

(u v + 2uv)dx =

vdx + 1 v(1) for all v V.

(2)

Remarks:
- The problems are equivalent in the sense that any solution u C 2(0, 1) of
(2) also satisfies (1) except possibly the boundary value u(0) = 1. Also (2) is
called the weak form of (1).
- We have a(u, v) =< , v > for all v V , where a(, ) is a bilinear operator
and < , > is a linear functional.
- The condition u(0) = 1 is called an essential boundary condition and u(1) = 1
is a natural boundary condition.
Typeset by FoilTEX

Introduce a grid Sh = {xi }N


i=0 and a space Vh = {v(x) piecewise linear on Sh}.
The discetized problem is: Find uh Vh such that


a(uh, v) =< , v > for all v Vh such that v(0) = 0,


uh(0) = 1.

Remarks:
- The solution uh Vh is called the finite element solution.
- The essential boundary condition u(0) = 1 appear explicitly in the formulation
of the problem.
- The natural boundary condition u(1) = 1 is included in the definition of the
functional < , >.
Typeset by FoilTEX

A basis for Vh is
0

N1 N

i(x) =

x0 x1

1, x = xi,
0, x = xj , j 6= i.

xN1 xN

x2

The finite element solution can be written as a linear combination


uh(x) =

N
X

cii(x).

i=0

Remark: The boundary value uh(0) = c00(0) = 1 gives us an equation for c0.
Typeset by FoilTEX

The relation a(uh, v) =< , v >, for v = j , gives us a system of linear


equations,
N
X
cia(i, j ) =< , j >, j = 1, 2 . . . , N.
i=0

or

1
c0
1
0 ...
0
c1 < , 1 >
a(0, 1)
. . . a(N , 1)

. =

.
.
.

.
.
.
< , N >
cN
a(0, N )
. . . a(N , N )
Remark This is a system Kc = f where K is the stiffness matrix and f is the
load vector.

Typeset by FoilTEX

Elements are easy to compute


a(i, i+1) =

1
0

(ii+1+2ii+1)dx

h
0

i+1

xi h

xi+1

11
x x
1 h
{ +2(1 ) }dx = + .
hh
h h
h 6

Remark: Ki,j = 0 unless xi and xj are neighbours since othervise ij 0.


So typically the matrix K is sparse.
Exercise: Compute Ki,i = a(i, i) and fi =< , i >. Since i are simple
polynomials its easy to do this numerically.
Typeset by FoilTEX

Matlab and Comsol example


Find u such that

u + 2u = 1,
x (0, 1),
(3)

u(0) = 1, and, u (1) = 1.


Use Comsol Multiphysics to: (module add comsol and comsol matlab on
Linux).
Create the computational grid {xi}.
Speficy the equation and boundary conditions.
Assemble the stiffness matrix and load vector.
Solve the problem and visualize the result.
Typeset by FoilTEX

10

The Finite Element Method


What do we need to make the FEM work in 2D (or 3D)?
- Generalize integration by parts (Greens Identity, Divergence Theorem).
Z

u
vud = v ud +
v d

- Introduce proper function spaces for solutions and test functions (Weak derivatives, Sobolev spaces).
- Discretize the domain (Mesh of Triangles) and introduce a set of basis functions.
- Efficiently compute the stiffness matrix and load vector for a given problem.
Typeset by FoilTEX

11

Weak Derivatives and Sobolev Spaces


Definition: Let u L2() and suppose u L2() satisfies
(v, ) = (u, x),

for all C0().

Then v is the weak derivative of u.


Example: = (1, 1) and u = 1 |x|.
(u, x) =
0

ux dx =
1

ux dx+

u(x)
Z

ux dx =
0

ux dx =
uxdx+[u]0
[u]1
0
1
Z 0
Z 1

(+1)dx
(1)dx = (v, )
1

Typeset by FoilTEX

v(x)

+1

1
12

Definition: The Sobolev space H 1() is the set of functions u L2() that
have weak derivatives in L2().
Remarks:
- The set H 1() consists of piecewise differentiable and continous functions.
- The space H 1() is a Hilbert space with scalar product (u, v)1 and norm
1/2
kuk1 = (u, u)1 .
- Higher order Sobolev spaces H m() can be defined similarily.
Example: Suppose R2 then
Z
Z
Z
(u, v)1 =
uvd +
uxvxd +
uy vy d.

Typeset by FoilTEX

13

Weak formulation
Example: Find u C 2 () such that

u = f,
u = g,
u
n = h,

in ,
on D ,
on N ,

Introduce V = {v H 1() and v = 0 on D }. Take a test function v V


and write
Z
Z
Z
Z
Z
u
u
vf d = vud =
vd +
vd =
v ud +
n
n

N
Z
Typeset by FoilTEX

v ud +

hvd.

14

The weak formulation is: Find u H 1() such that


Z
Z
Z

hvd,
v ud = f vd +

N

u = g, on D .

for all v V

(4)

Remarks
- Can introduce a bilinear operator a(u, v) and a linear functional < , v >.
- The next step is to pick a finite dimensional subspace Sh H 1() and
discretize the problem (4).

Typeset by FoilTEX

15

Domain discretization
Introduce a discretization parameter h and a triangular mesh Th =
{T1, T2, . . . , TM } on .

Need to represent the mesh in an efficient way. Want to be able to compute area
and boundary integrals.

Typeset by FoilTEX

16

Example:
N2

N3
T9

T8
T1

N9

T7
T3

T2
N1

N4

N7

T6
N5
N8
T4

T5

N6

Data structures needed:


- A 2N matrix Nodes, a 3M matrix Triangles, and a 2K matrix Edges.
Here we have Triangles(:,3)= (7 , 8 , 9)T .
- Is a node Nk subject to a Dirichlet boundary condition? Is an edge Ek subject
to a Neumann boundary condition?
Typeset by FoilTEX

17

Linear basis functions


Introduce a space Vh H 1() of piecewise linear functions on a given mesh Th.
For each node Nk we obtain a basis function k . The functions k are uniqely
determined by k (xk , yk ) = 1, k (xj , yj ) = 0 for k 6= j, and k is linear on
each triangle Ti.
N2

N3

Example:

T9

T8
T1

N9

T7
T3

T2
N1

N4

N7

T6
N5
N8
T4

T5

N6

The basis function 8 is non-zero on the triangles T3, T4, T5, T6, and T7.
Typeset by FoilTEX

18

Assembly of Stiffness matrix and load vector


The discretized problem is: Find uh Vh such that
a(uh, j ) =

N
X

cia(i, j ) =< , j >,

for all j such that j = 0 on D ,

i=1

and,
uh(xj , yj ) = g(xj , yj ), for nodes Nj = (xj , yj )T on D .
Remarks:
- Most elements Ki,j are integrals a(j , i). How to compute them?
- The linear system Kc = f is (very) sparse.

Typeset by FoilTEX

19

Note that
a(i, j ) =

i j d =

XZ
Tk

i j d.

Tk

and only 3 basis functions are non-zero on each triangle Tk .


K=sparse(N,N), f=zeros(N,1)
for k = 1 : M
[N1,N2,N3]=Triangles(:,k);
Compute 9 local contributions ( KN 1,N 1 = a(Tk )(NR 1, N 1),. . . )
Compute 3 local contributions to < , j > (that is T f N 1d,. . . ).
k
end
This is an Element oriented algorithm. Have to fix rows corresponding to nodes
subject to Dirichlet conditions and need a loop over all the Edges subject to a
Neumann conditions to get final Kc = f .
Typeset by FoilTEX

20

Comsol Multiphysics 2D Example


u=0
n u = 0

u = 0
u = 10

Typeset by FoilTEX

n u = 0

21

Summary
The Finite Element Method compared to Finite Differences
- A general purpose technique for solving (elliptic) PDEs in complex domains.
- Relatively easy to make good software that can handle many different types of
equations and domains.
- The linear system Kc = f is sparse but usually not very structured. Have to
use standard sparse linear equation solvers. Less efficient preconditioners.
- Assuming the mesh is of good quality error estimates are similar for Finite
Elements and Finite Differences.
- Can use different types of basis functions, e.g. j C 1(), without changing
the codes very much.
Typeset by FoilTEX

22

MAI0088 Applied Functional Analysis and FEM


Course contents:
mathematical concepts: weak derivative, weak form of a boundary value
problem, and Sobolev spaces.
Use tools from functional analysis to analyze the finite element method:
Existance and Uniqueness. Various error estimates.
Implement the core of a realistic finite element solver. Try a commercial
software package.
Computational Techniques: Sparse linear equation solvers. Preconditioning.
Multigrid solvers.
Course literature: Braess, Finite elements, Cambridge University press.
Typeset by FoilTEX

23

You might also like