21 oktober 2010

23
The Finite Element Method Fredrik Berntsson ([email protected]) – Typeset by Foil T E X 1

Transcript of 21 oktober 2010

The Finite Element Method

Fredrik Berntsson ([email protected])

– Typeset by FoilTEX – 1

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 – 2

The Finite Element Method (FEM)

- A general purpose technique for solving boundary value problems for elliptic

PDEs in complicated domains.

- Mostly developed by engineers 1955–1965 (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 – 3

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,

∫ 1

0

(u′′ + 2u)vdx =

∫ 1

0

1 · vdx.

Integrate by parts∫ 1

0

(u′′v+2uv)dx = u′(1)v(1)−u′(0)v(0)+

∫ 1

0

(−u′v′+2uv)dx =

∫ 1

0

vdx.

Restrict test functions to V = v ∈ C1(0, 1) such that v(0) = 0.

– Typeset by FoilTEX – 4

We obtain a new problem: Find u such that

∫ 1

0

(−u′v′ + 2uv)dx =

∫ 1

0

vdx + 1 · v(1) for all v ∈ V. (2)

Remarks:

- The problems are equivalent in the sense that any solution u ∈ C2(0, 1) of(2) also satisfies (1) except possibly the boundary value u(0) = 1. Also (2) iscalled 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) = 1is a natural boundary condition.

– Typeset by FoilTEX – 5

Introduce a grid Sh = xiNi=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 formulationof the problem.

- The natural boundary condition u′(1) = 1 is included in the definition of thefunctional < ℓ, · >.

– Typeset by FoilTEX – 6

A basis for Vh is

x0 x1 x2 xN−1 xN

φ0 φ1 φ2 φN−1 φN

φi(x) =

1, x = xi,

0, x = xj, j 6= i.

The finite element solution can be written as a linear combination

uh(x) =N

i=0

ciφi(x).

Remark: The boundary value uh(0)=c0φ0(0)=1 gives us an equation for c0.

– Typeset by FoilTEX – 7

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

N∑

i=0

cia(φi, φj) =< ℓ, φj >, j = 1, 2 . . . , N.

or

1 0 . . . 0a(φ0, φ1) . . . a(φN , φ1)

... ...a(φ0, φN) . . . a(φN , φN)

c0

c1...

cN

=

1< ℓ, φ1 >

...< ℓ, φN >

Remark This is a system Kc = f where K is the stiffness matrix and f is theload vector.

– Typeset by FoilTEX – 8

Elements are easy to compute

a(φi, φi+1) =

∫ 1

0

(−φ′

iφ′

i+1+2φiφi+1)dx =

∫ h

0

−1

h

1

h+2(1−

x

h)x

hdx = −

1

h+

h

6.

xi xi+1

φi φi+1

h

Remark: Ki,j = 0 unless xi and xj are “neighbours” since othervise φiφj ≡ 0.So typically the matrix K is sparse.

Exercise: Compute Ki,i = a(φi, φi) and fi =< ℓ, φi >. Since φi are simplepolynomials its easy to do this numerically.

– Typeset by FoilTEX – 9

Matlab and Comsol example

Find u such that

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

(3)

Use Comsol Multiphysics to: (module add comsol and comsol matlab onLinux).

• 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 (Green’s Identity, Divergence Theorem).

Ω

v∆udΩ = −

Ω

∇v · ∇udΩ +

∂Ω

v∂u

∂ndΓ

- Introduce proper function spaces for solutions and test functions (Weak deri-vatives, 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 ϕ ∈ C∞

0 (Ω).

Then v is the weak derivative of u.

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

(u, ϕx) =

Z 1

−1

uϕxdx=

Z 0

−1

uϕxdx+

Z 1

0

uϕxdx =

[uϕ]0−1−

Z 0

−1

uxϕdx+[uϕ]−10 −

Z 1

0

uxϕdx =

Z 0

−1

(+1)ϕdx−

Z 1

0

(−1)ϕdx = −(v, ϕ)

u(x)

+1

−1

v(x)

– Typeset by FoilTEX – 12

Definition: The Sobolev space H1(Ω) is the set of functions u ∈ L2(Ω) thathave weak derivatives in L2(Ω).

Remarks:

- The set H1(Ω) consists of piecewise differentiable and continous functions.

- The space H1(Ω) is a Hilbert space with scalar product (u, v)1 and norm

‖u‖1 = (u, u)1/21 .

- Higher order Sobolev spaces Hm(Ω) can be defined similarily.

Example: Suppose Ω ⊂ R2 then

(u, v)1 =

Ω

uvdΩ +

Ω

uxvxdΩ +

Ω

uyvydΩ.

– Typeset by FoilTEX – 13

Weak formulation

Example: Find u ∈ C2(Ω) such that

−∆u = f, in Ω,

u = g, on ΓD,∂u∂n = h, on ΓN , ΓD

ΓN

Ω

Introduce V = v ∈ H1(Ω) and v = 0 on ΓD. Take a test function v ∈ V

and write

Ω

vfdΩ = −

Ω

v∆udΩ =

Ω

∇v · ∇udΩ +

ΓN

∂u

∂nvdΓ +

ΓD

∂u

∂nvdΓ =

Ω

∇v · ∇udΩ +

ΓN

hvdΓ.

– Typeset by FoilTEX – 14

The weak formulation is: Find u ∈ H1(Ω) such that

Ω

∇v · ∇udΩ = −

Ω

fvdΩ +

ΓN

hvdΓ, for all v ∈ V

u = g, on ΓD.

(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 ⊂ H1(Ω) anddiscretize 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 areaand boundary integrals.

– Typeset by FoilTEX – 16

Example:

N1

N2 N3 N4

N5

N6N7

N8

N9T1

T2

T3

T4

T5

T6T7

T8T9

Data structures needed:

- A 2×N matrix Nodes, a 3×M matrix Triangles, and a 2×K 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 subjectto a Neumann boundary condition?

– Typeset by FoilTEX – 17

Linear basis functions

Introduce a space Vh ⊂ H1(Ω) of piecewise linear functions on a given mesh Th.

For each node Nk we obtain a basis function φk. The functions φk are uniqelydetermined by φk(xk, yk) = 1, φk(xj, yj) = 0 for k 6= j, and φk is linear oneach triangle Ti.

Example:

N1

N2 N3 N4

N5

N6N7

N8

N9T1

T2

T3

T4

T5

T6T7

T8T9

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

i=1

cia(φi, φj) =< ℓ, φj >, for all j such that φj = 0 on ΓD,

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 · ∇φjdΩ =∑

Tk

Tk

∇φi · ∇φjdΩ.

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 ( KN1,N1 = a(Tk)(φN1, φN1),. . . )

Compute 3 local contributions to < ℓ, φj > (that is∫

TkfφN1dΩ,. . . ).

end

This is an Element oriented algorithm. Have to fix rows corresponding to nodessubject to Dirichlet conditions and need a loop over all the Edges subject to aNeumann conditions to get final Kc = f .

– Typeset by FoilTEX – 20

Comsol Multiphysics 2D Example

∆u=0

n · ∇u = 0

n · ∇u=0

u = 0

u=10

– Typeset by FoilTEX – 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 ofequations and domains.

- The linear system Kc = f is sparse but usually not very structured. Have touse standard sparse linear equation solvers. Less efficient preconditioners.

- Assuming the mesh is of good quality error estimates are similar for FiniteElements and Finite Differences.

- Can use different types of basis functions, e.g. φj ∈ C1(Ω), without changingthe codes very much.

– Typeset by FoilTEX – 22

MAI0088 Applied Functional Analysis and FEM

Course contents:

• mathematical concepts: weak derivative, weak form of a boundary valueproblem, 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 commercialsoftware package.

• Computational Techniques: Sparse linear equation solvers. Preconditioning.Multi–grid solvers.

Course literature: Braess, Finite elements, Cambridge University press.

– Typeset by FoilTEX – 23