Sei sulla pagina 1di 67

Finite Element Method

A short Introduction to Principles and Ideas

Kenny Erleben
kenny@diku.dk
Department of Computer Science
University of Copenhagen

2010

What is FEM... A Simple 1D Example

The Basic Steps

The five basic steps in deriving a FEM for a given problem


STEP 1: Write volume integral
STEP 2: Do Integration by parts
STEP 3: Make an Approximation
STEP 4: Choose a Trial Function
STEP 5: Compute a Solution
Now let us try it out

First we need a Problem


We wish to find the unknown function y (x) : R 7 R on some
domain x [x1 ..xn ]. All we know is some differential equation
2 y (x)
= c(x)
x 2
where c(x) : R 7 R is some known function also we are given
some boundary conditions
y (x1 ) = a
y (xn ) = b
Now we will do this using the finite element method (FEM).

STEP 1 Rewrite into a Volume Integral

First we multiply by an arbitrary trial function v (x) defined such


that we always have v (x1 ) = v (xn ) = 0 and then we integrate over
our domain

 2
Z xn
y (x)
c(x) dx = 0
v (x)
x 2
x1
The boundary conditions are a bit trivial for this 1D example since
they are point based1 .

Technically one would do the same to the boundary conditions and add all
up into a single equation.
5

STEP 2 Integration by Parts


So we have
Z xn
x1


2 y (x)
c(x) dx =
v (x)
x 2
Z xn
Z xn
2 y (x)
dx
v (x)
v (x)c(x)dx = 0
x 2
x1
x1


Integration by parts of the first term give us


Z xn
Z xn
h
ix
v (x) y (x)
y (x) 2
dx
v (x)c(x)dx = 0

v (x) x
x
x
x1
x1
x1
Cleaning up
Z

xn

x1
6

v (x) y (x)
dx +
x
x

xn

v (x)c(x)dx = 0
x1

What Happened?
Originally we had the term
Z
v (x)

2 y (x)
dx
x 2

Here y (x) needs to be twice continuously differentiable. Now we


have
Z
v (x) y (x)
dx
x
x
Now y (x) only needs to be continuously differentiable.

Strong Form Weak Form


Downside is that v (x) must be differentiable.

STEP 3 Make an Approximation


Rather than finding y we wish to find a good approximation y
which we write abstractly as
n
X
y (x) y (x) =
Ni (x)
yi
i=1

That is we have broken up our continuous function into a set of n


discrete values (
yi , xi ) that we somehow combine using some
weighting/interpolation scheme given by the global shape functions
Ni .
More elegantly we write compactly

y1 (x)



y
y (x) =
Ni (x)
yi = N1 (x) Nn (x) ... = N
{z
}
|
i=1
yn (x)
N(x)
| {z }
n
X

A Few Notes on the Shape Functions

The shape function should interpolate the points


(
1 x = xi
Ni (x) =
0 x = xj j 6= i
and
X

Ni (x) = 1

The last condition is known as partition of unity2

2
9

What is

R xn
x1

Ndx = 1?.

An Illustration of the Computational Mesh

10

Let us use the Hat-Function


Using linear interpolation yields the so called hat

xi x



1 x
xi x
= 1 xxi
Ni (x) = max 0, 1
x

11

functions
xi1 x xi
xi < x xi+1
otherwise

Using the Approximation


So we have
Z

xn

x1

v (x) y (x)
dx +
x
x

xn

v (x)c(x)dx = 0
x1

Let us insert the approximation into our integrals


Z xn
Z xn
v (x) N(x)
y dx +
v (x)c(x)dx = 0
x
x
x1
x1
This is the main trick of the finite element method (FEM)

FEM is a method of Approximation


12

STEP 4 Choose a Trial Function


We will make the choice
v (x) = N(x)y
T

where y = y1 y2 are completely arbitrary values at the
discrete points. Inserting our choice yields
Z xn
Z xn
(N(x)y) N(x)
y dx
N(x)yc(x)dx = 0
x
x
x1
x1
Rewriting
Z
T
y

xn

x1

13



Z xn
NT (x) N(x)
T
N (x)c(x)dx = 0
dx y +
x
x
x1

Cleaning Up
Now
y

Z

xn

x1



Z xn
NT (x) N(x)
T
dx y +
N (x)c(x)dx = 0
x
x
x1

must hold for all arbitrary values of y so



Z xn
Z xn
NT (x) N(x)
dx y +
NT (x)c(x)dx = 0
x
x
x
x
| 1
{z
}
| 1
{z
}
f

Thus we now have a simple linear system


K
y =f

14

STEP 5 Compute a Solution


Compute (numerically or analytically)
Z

xn

K=
x1

NT (x) N(x)
dx
x
x
xn

f=

NT (x)c(x)dx

x1

then we have
K
y =f
We are almost done, we just need to add the boundary conditions
before we can solve the linear system for our solution y .

15

Remember to Add Boundary Conditions


These are
y1 = a
yn = b
So we make the modifications
fi fi Ki1 a Kin b
and

(
1
K1i
0

i 1, . . . , n

if i = 1
otherwise

similar for Kni . This can be done more elegantly in matrix


notation.
16

Boundary Conditions in Matrix Form


Assume a discrete model
K
y =f
where y , f Rn and K Rnn . Now we wish to apply Dirichlet
boundary conditions
D {i|
yi = di }
then
F {i|i
/ D}
Make partitioning of original system

   
KF F KF D yF
f
= F
KDF KDD yD
fD

17

Inserting the Boundary Condition


Insert Dirichlet boundary conditions
I
yD = d
Into partitioned system

KF F
0

KF D
I

   
yF
f
= F
yD
d

Resulting in the reduced system


KF F yF = fF KF D d
Notice that boundary conditions end up as extra term on right
hand side (extra source term)
18

Where did the Elements go?


Its called finite element method but we have derived an
approximate solution in a global setting.
Z xn
Z xn
NT N
y dx
NT cdx =
x
x
x1
x1
X Z xj (Ne )T Ne
y e dx
x
x
xi
e

Z xj

(Ne )T cdx = 0
xi

where e is the element between two consecutive nodes xi and xj

19

The Local Shape Functions


We have


Ne (x) = Nie (x) Nje (x)
 
y
e
y = i
yj
where the local shape functions are
Nie =

20

x xi
xj xi

and Nje =

xj x
xj xi

The Spatial Derivatives

So assuming equidistant xi s we have x = xj xi and


Nie =
Further

xi x
x

and Nje =

x xj
x

Nje
Nie
1
1
=
and
=
x
x
x
x
which are constants independent of x

21

The Finite Elements


So
Z

xj

xi

 
1
(Ne )T Ne e
1 
1
y dx =
2
1
x
x
x


1 1
1 e
=
y
1 1
x
|
{z
}




y e

xj

dx
xi

Ke

and
e

xj

f =

(Ne )T cdx

xi

Now for this educational example we simply set c(x) = 0 so f e = 0

22

Assembling local Elements into a Global System

So we finally have
K
y=

Ke y e =

Or more algorithmically we have . . .

23

X
e

fe = f

The Computer Scientist at Work

24

The Final Assembly Algorithm


for all e
Ke compute element matrix
f e compute element vector
next e
K zeroes(n, n)
f zeroes(n, 1)
for all e
Kii Kii + Ke11
Kij Kij + Ke12
Kji Kji + Ke21
Kjj Kjj + Ke22
fi fi + f1e
fj fj + f2e
next e
25

The Boundary Condition Algorithm


Given the boundary conditions
D = {i|
yi = di }
Make the modifications
for all i D
fi di
for all j
/D
fj fj Kji di
next j
Ki 0
Ki 0
Kii 1
next i
26

The Final Computation

Since yD is given we only solve the reduced system


KF F yF = fF
where F {j|j
/ D}.

27

Study Group
Make an implementation of the 1D example. Use the values
x1 = 1, xn = 2
x = 0.1
a = 1, b = 2, c = 0
Start by making a sketch on paper showing how you expect
y (x) to look like.
Discuss which parts of the algorithm that is nave parallizable
Consider using an iterative method (like Conjugate Gradient)
for solving the reduced system, can you suggest any
optimizations? (Hint: do not actually assemble the global
matrix)
Make pseudo code algorithms for your optimizations
28

Let us go to 2D

29

Lets do the fast track this time

STEP 1: Define Elements


STEP 2: Choose Trial and Shape Functions
STEP 3: Solve Element wise Integrals
STEP 4: Do Assembly of Elements
STEP 5: Apply Boundary Conditions
STEP 6: Compute Solution

30

The Problem
We wish to find the unknown function u(p) : R2 7 R on some

T
domain p = x y R2 . All we know is some differential
equation
2 u(p) 2 u(p)
+
= c(p)
y 2
x 2
where c(p) : R2 7 R is some known function also we are given
some boundary conditions
u(p) = a(p)
For all p . Now we will do this using the finite element
method (FEM).

31

The 2D Domain

32

The 2D Computational Mesh

33

STEP 1: Define Elements


We have triangle elements

Element e consists of the nodes i, j and k in counter clock wise


order.
34

STEP 2: Choose Trial and Shape Functions


Let p(x, y ) e then we want to find the approximation
e
 e
 uie
e
e
u(p) u(p) = Ni (p) Nj (p) Nk (p) uj = Ne ue
uke
and we choose trial functions to be v e (p) = w e (p) = Ne u e . For
a triangle we will use barycentric coordinates3 .
Nie =
Nje =

Aei
Ae
Aej

Ae
Ae
Nke = ke
A
Here As are triangle areas and Ae = Aei + Aej + Aek total area
3

35

Also known as area weighted coordinates

Barycentric Coords Area Weighted Coords


Geometrically that looks like this

36

The Local Shape Functions


We can use cross products to quickly compute triangle areas
(pk pj ) (p pj )
Ae
(pi pk ) (p pk )
Nje =
Ae
(pj pi ) (p pi )
Nke =
Ae
Nie =

where Ae = (pj pi ) (pk pi ). Observe these are linear


functions in x and y .

37

The Spatial Derivatives

So we find by differentiation
(pk pj )y
Nie
=
x
Ae
e
(pk pj )x
Ni
=
y
Ae
Similar for Nje and Nke . Observe they are constants independent of
x and y .

38

STEP 3: Solve Element wise Integrals


So we have

 2
Z
Z
u 2u
e
+
c d +
v
w e (u a) d = 0
y 2 x 2
e
e
Remember that by design v and w are complementary so we will
ignore the boundary term for now and concentrate of the domain
term. That is,

 2
Z
u 2u
e
+
c d = 0
v
y 2 x 2
e

39

Getting the local Element Matrices


Substitution of our choices and integration by parts etc give us
Ke ue = f e
where
Ke =
e

Ne
y

f =

T

Ne
+
y

Ne
x

T

Ne
x

!
Ae

(Ne )T cd

Now for our example we assume c = 0 and we will have closed


form formulas.

40

STEP 4: Do Assembly of Elements

Same as in 1D

41

STEP 5: Apply Boundary Conditions

Same as in 1D
(If conditions are point wise)

42

STEP 6: Compute Solution

Same as in 1D

43

The Boundary Condition Term


So if boundary conditions are not point wise we have to look at
Z
w e (u a) d = 0
e

Doing the same algebraic manipulations as before we end up with


Z
(Ne )T (Ne ue a) d = 0
e

Why is this different from the 1D example?


The boundary condition is applied along the whole boundary
Observe that the equation will give a result like
ue = de
44

Its really just like point wise conditions

Knowing that we end up with


ue = de
for the element boundary
Compute boundary terms for all elements with a boundary
Assemble all boundary terms into one boundary vector
Apply the assembled boundary vector as point wise boundary
conditions to assembled system.

45

Study Group
Derive the formula for Ke and f e in full detail for the 2D
example
Make an implementation of the 2D example on a rectangular
domain that is 6-by-2 in size.
Set a = 1 on the left edge of the rectangle and a = 2 on the
right size.
Use c = 0
Treat boundary conditions as point wise conditions

Discuss from a computer scientist viewpoint which steps are


the same and which steps that are different compared to the
1D example.

46

Abstracting Mathematician at Work

47

The Strong Form Problem

We have a set of differential equations


A(u) = 0
in a domain and we seek the solution u subject to a set of
boundary conditions,
B(u) = 0
on the boundaries .

48

The Solution

The finite element method seek an approximate solution


X
u u =
Ni ui = N u
where Ni are shape functions and ui s are the unknown parameters
to be solved for.

49

Rewriting to Integral Form


Obviously
Z

v T A(u)d = 0

and

v T B(u)d = 0

where v and v are a set of arbitrary functions.


Called Weighting functions or Trial functions
So

v A(u)d +

v T B(u)d = 0

is equivalent to the satisfaction of the differential equations.

50

The Weighted Residual Method


Substitute u N u, and
v=

Wj uj

v =

j uj
W

then
ujT

Z

WjT A(N u)d

Z
+


T

Wj B(N u)d = 0

Note A(N u) is the residual or error when using the approximating


solution (similar for B(N u)). Since uj is arbitrary
Z
Z
jT B(N)d = 0
WjT A(N u)d + W
j

51

The Galerkin Method

j = Nj we have the Galerkin Method.


When choosing Wj = W
Z
Z
T
Nj A(N u)d + NjT B(N u)d = 0
j

52

The Weak Form

Given
Z

WjT A(N u)d

jT B(N u)d = 0
W

Integration by part
Z
Z
T
j )T F (N u)d = 0
C (Wj ) D(N u)d + E (W

This is called the weak form.

53

Discrete Systems

j )T F (N u) then
Let G C (Wj )T D(N u) and g E (W

Z
Z
Z
X Z
Gd + gd =
Gd +
gd = 0

This is called assembly.

54

2D Elasticity

55

STEPS 1-2 and 4-6

We use the exact same setup as for the previous 2D example


2D domain
Triangle elements
Area weighted coordinates for shape functions
Point wise boundary conditions
Now all that is missing is the problem definition and how to phrase
it as an element integral.

56

The Problem and Element Integral


The weak form integral of Cauchys equation (equivalent of
Newtons 2. Law for continuum) results in
Z
(e )T e d = (e )T f e
e

where
is Cauchy stress tensor written as a 3 dimensional vector
 is the virtual Cauchy strain tensor written as a 3
dimensional vector
ue is the virtual displacement vector of dimension 6
f e is the external body force vector of dimension 6
As usual we treat boundary conditions as point wise and can ignore
them for now.
57

The Virtual Displacements

Given nodal virtual displacements ue we can use our shape


functions
u = Ne ue
where N is a 2-by-6 dimensional matrix given by


Ne = Nie I22 Nje I22 Nke I22
and the Ns are the barycentric coordinates introduced previously.

58

The Virtual Stress


Stress, , is a function of the displacement field thus by definition
e
e
e
 = Su = SN
|{z} u = Bu
B

where S is the differential operator of dimension 3-by-2

0
x


S = 0 y

and so B is of dimension 3-by-6

59

Linear Elasticity
If one imposes the condition that is symmetric then the stress
tensor can be saved in a 3-dimensional vector

T
= 11 22 12
Similar trick can be used for a symmetric strain tensor

T
 = 11 22 12
The stress tensor may be related to the Cauchy strain tensor by
the linear relation
= D = DBue
where D is a 3-by-3 elasticity matrix.

60

Substitution of the Math


If we substitute into our element integrals we have
Z
(ue )T BT DBue d = (e )T f e
e

This must hold for all virtual displacements so


Z
BT DBue d = f e
e

which we can solve


e
T
e e
B
{z } u = f
| DBA
Ke

That is it!

61

A Few Implementation Tips


For steel Young modulus is E = 69 109 Pa and Poisson ratio is
= 0.3 and the Elasticity matrix would be given by

1
0
E
1
0
D=
(1 2 )
(1)
0 0
2
and
e
Ni
x
B=
0 e
Ni
y

62

Nje
0
x
Nie

y 0
e
e
Ni
x

Nj
y

e
Nk
x
e

Nj

0
y
e
e
0

Nj
x

Nk
y

0
Nke

y
e
Nk
x

Study Group

Make an implementation of the 2D elastic assembly process


Discuss from a computer science viewpoint which steps are the
same and which steps that are different in the 2D elastic case
Speculate how to write a general FEM computer program that
could simulate any partial differential equation with point wise
boundary conditions

63

Further Reading
O. C. Zienkiewicz and R. L. Taylor: The Finite Element
Method, volume 1, The Basis, Fifth Edition, Butterworth and
Heinemann, 2002
R. D. Cook, D. S. Malkus, M. E. Plesha and R. J. Witt:
Concepts and applications of finite element analysis, fourth
edition, John Wiley and Sons, 2002.
M
uller and M. Gross: Interactive virtual materials,
Proceedings of Graphics Interface 2004.
R. Schmedding and M. Teschner: Inversion Handling for
Stable Deformable Modeling, The Visual Computer, vol. 24,
no. 7-9 (CGI 2008 Special Issue), pp. 625-633, 2008.
A. W. Bargteil, C. Wojtan, J. K. Hodgins, and G. Turk: A
finite element method for animating large viscoplastic flow,
ACM Trans. Graph. vol 26. no. 3. 2007.
64

Intermediate Programming
Implement a rectangular solid 2D bar of dimension 6-by-2
meters and made of steel like material. Attach the left side of
the bar to a wall (use boundary condition u = 0) and apply a
downward nodal load on the right edge of the bar.
Examine the eigenvalue spectrum of the global stiffness matrix
before applying boundary conditions and after.
Examine the fill pattern of the stiffness matrix.
Investigate what happens to the deformations when you vary
the resolution and load on the bar. Try to find the best
suitable mesh resolution.
From everyday life steel material appears to be noticeable
incompressible. Examine whether your implementation has
volume (area in 2D) conservation.
65

Advanced Programming
Combine your 2D elastic model simulator with a LCP solver
that can solve for non-penetration of nodes against a fixed
completely rigid surface
Make the collision detection between a 2D solid rectangular
bar and a circular surface using an implicit function
: R2 7 R (signed distance field outside positive and inside
negative) of the surface. Let the contact normal and
separation distance be given by
(p)
n(p) =
and d(p) = (p)
k (p) k
The deformed coordinates of the solid can be found as
p = p0 + u

66

where u is the displacement field of the solid (computed using


your FEM simulator) and p0 is the material (initial)
coordinates of the solid.

Advanced Programming (Contd)


The LCP problem is now given by
di (
ui ) 0 i 0
where i is the magnitude of the normal force. The FEM
equation needs to be modified into

n1 1

K
u = f + ...
nn n
Of course you only need to add normal forces for the cases
where di 0.
Observe that results of the LCP solver go into the FEM solver
and vice versa. Thus, they are linked in some nonlinear non
smooth fashion. This is the problem you need to find a
solution for.
67

Potrebbero piacerti anche