You are on page 1of 24

Galerkin finite element method

Boundary value problem

Lu = f

u=g
0

n u = g1

n u + u = g
2

weighted residual formulation

in

partial differential equation

on 0

Dirichlet boundary condition

on 1

Neumann boundary condition

on 2

Robin boundary condition

1. Multiply the residual of the PDE by a weighting function w vanishing


on the Dirichlet boundary 0 and set the integral over equal to zero
2. Integrate by parts using the Neumann and Robin boundary conditions
3. Represent the approximate solution uh u as a linear combination of
polynomial basis functions i defined on a given mesh (triangulation)

4. Substitute the functions uh and i for u and w in the weak formulation


5. Solve the resulting algebraic system for the vector of nodal values ui

Construction of 1D finite elements


1

1. Linear finite elements

2

Consider the barycentric coordinates


x2 x
1 (x) =
,
x2 x1

x x1
2 (x) =
x2 x1

defined on the element e = [x1 , x2 ]


i P1 (e),

Basis functions

x2

'1

'2

2
d
dx

i, j = 1, 2

1 (x) + 2 (x) = 1,
1
x2 x
1

x1

i = 1, 2

i (xj ) = ij ,
d1
dx

x e

x1

x2
u2

constant derivatives

1 |e = 1 ,

uh (x) = u1 1 (x) + u2 2 (x),

u1

2 |e = 2
x e

e
x1

x2

Construction of 1D finite elements


1

2. Quadratic finite elements


{1 (x), 2 (x)}
x1 = {1, 0},
x12 =

x1 +x2
2

barycentric coordinates
e

x2 = {0, 1}
= { 21 , 21 }

Basis functions

2

endpoints

midpoint

x1

x2

'1

'12

1 , 2 , 12 P2 (e)

1 (x) = 1 (x)(21 (x) 1)

e
x12

x1

2 (x) = 2 (x)(22 (x) 1)


12 (x) = 41 (x)2 (x)

x2
u2

u1

Shape function uh |e
uh (x) = u1 1 (x) + u2 2 (x) + u12 12 (x)

'2

u12

e
x1

x12

x2

Construction of 1D finite elements


3. Cubic finite elements
{1 (x), 2 (x)}

1

barycentric coordinates

x1 = {1, 0},

x12 =

2x1 +x2
3

= { 32 , 13 }

x2 = {0, 1},

x21 =

x1 +2x2
3

= { 31 , 23 }

Basis functions

e
x1

x2

1 , 2 , 12 , 21 P3 (e)

1 (x) = 21 1 (x)(31 (x) 2)(31 (x) 1)


2 (x) = 12 2 (x)(32 (x) 2)(32 (x) 1)
12 (x) = 92 1 (x)2 (x)(31 (x) 1)
21 (x) = 92 1 (x)2 (x)(32 (x) 1)
Shape function

2

u2
u12
u1

u21

e
x1

x12 x21 x2

uh (x) = u1 1 (x) + u2 2 (x) + u12 12 (x) + u21 21 (x)

Construction of triangular finite elements


x3

Let x = (x, y) = {1 (x), 2 (x), 3 (x)}

Construct 2D barycentric coordinates


i P1 (e),

i (xj ) = ij ,

i, j = 1, 2, 3

x1
Polynomial fitting: i (x) = ci1 + ci2 x + ci3 y

(x
)
=
c
+
c
x
+
c
y
=

i
1
i1
i2
1
i3
1
i1

c
1
x
y

i1
1
1
1 x2 y2 ci2 =
i (x2 ) = ci1 + ci2 x2 + ci3 y2 = i2

ci3
1 x3 y3
i (x3 ) = ci1 + ci2 x3 + ci3 y3 = i3
{z
}
|

x2

i1
i2
i3

We have 3 systems of 3 equations for 9 unknowns. They can be solved for the
unknown coefficients cij by resorting to Cramers rule.
det A = x2 y3 + x1 y2 + x3 y1 x2 y1 x3 y2 x1 y3
Area of the triangle

|e| = 12 | det A|

(also needed for quadrature rules)

Construction of triangular finite elements


Connect the point x to the vertices
to construct the barycentric splitting

i = 1, 2, 3
3
S
ei
e=
xi ,

x3
e
e2 e1

i=1

Areas of the triangles

1 x y
A1 = 1 x2 y2 ,
1 x3 y3

1
2 | det Ai (x)|

|ei (x)| =

1 x1 y1
A2 = 1 x y ,
1 x3 y3

Solution of the linear systems:

i (x) =

|ei (x)|
|e|

x1

x e

x2

1 x1 y1
A3 = 1 x2 y2
1 x y


det Ai (x)
= det A ,

It is obvious that the barycentric coordinates satisfy


|e1 (x)| + |e2 (x)| + |e3 (x)| = |e|,

e3

i = 1, 2, 3

i (xj ) = ij

1 (x) + 2 (x) + 3 (x) 1


e2

A similar interpretation is possible in one dimension:


x1

e1
e

x2

Construction of triangular finite elements


Nodal barycentric coordinates
x1 = {1, 0, 0},
x12 = { 12 , 21 , 0},

x2 = {0, 1, 0},

1 = 1 ,

midpoint-oriented

12 = 1 23 ,

2. Quadratic elements

3 = 3 (23 1),

x1

x12

x2

2 = 2 ,

3 = 3

(standard)

13 = 1 22 ,

23 = 1 21

uh (x) = c1 + c2 x + c3 y + c4 x2 + c5 xy + c6 y 2 P2 (e)

Standard P2 basis (6 nodes)

2 = 2 (22 1),

x23 = {0, 21 , 21 }

x123 x23

uh (x) = c1 + c2 x + c3 y P1 (e)

vertex-oriented

1 = 1 (21 1),

x13

x3 = {0, 0, 1}

x13 = { 12 , 0, 12 },

1. Linear elements

x3

x123 = { 13 , 31 , 31 }

12 = 41 2
13 = 41 3
23 = 42 3

Extended P2+ basis (7 nodes)


i = i (2i 1) + 31 2 3

ij = 4i j 121 2 3

123 = 271 2 3 ,

i, j = 1, 2, 3

Construction of tetrahedral finite elements


x4

Let x = (x, y, z) = {1 (x), 2 (x), 3 (x), 4 (x)}


Construct

i P1 (e) : i (xj ) = ij ,

Polynomial fitting:

1
1

1
1

x1
x2
x3
x4

y1
y2
y3
y4

x124

i, j = 1, . . . , 4

x134
x234

x3

x123

x1

i (x) = ci1 + ci2 x + ci3 y + ci4 z

i1
ci1
z1

z2
ci2 = i2
z3 ci3 i3
i4
ci4
z4

1. Linear elements

x2

Barycentric splitting

e=

4
S

ei

i=1

i (x) =

|ei (x)|
,
|e|

i = 1, . . . , 4

uh (x) = c1 + c2 x + c3 y + c4 z P1 (e)

vertex-oriented

1 = 1 ,

2 = 2 ,

face-oriented

123 = 1 34 ,

134 = 1 32 ,

3 = 3 ,

124 = 1 33

234 = 1 31

4 = 4

(standard)

xijk =

xi +xj +xk
3

2. Higher-order approximations are possible but rather expensive in 3D

Coordinate and element transformations


Idea: define the basis functions on a geometrically simple reference element
n = 1 n = 2n = 1
y^
y^

n=1

x^ 3
0

e^

x^1

x^2 x^1

x^ 3

x^ 3 x^14

e^0 e^10 e^1 0 1 e^


x^ 1 x^x^21 x^ x^ 2 x^x^12 x^

01 0

y^
Fe
e
x1

Fe

x1

x3Fe

x1

x2 e

e
x2 x x1

Fe y

x2 x1

Linear mapping in Rn

z^

x^ 4

1 1
0

e^

x^

Fey z
e

y^

x3

x1

x2x2

Fe : y e e

x3
x1

xx

x
y

e^

x^ 2 x^

x^x^2 1 x^

y^ Fe 3
Fe x 4 z

x3
x1

01

x^ 2 x^x2^ x^x^ 1
1

x^ 3

x2

xx2 x

e^ e^

n=3

n=3
z^

x^ 4

x^x^21 x^x^1

n=
2 3
n=

n=2
y^ z^

x^ 3

Fe

Fe
x4 z
e
x2

x4
x3
x1

x3

x2

Coordinate and element transformations


Mapping of the reference element e onto an element e with vertices xi
Fe :

e = Fe (
e)

x = Fe (
x) =

n+1
X

xi i (
x),

x e

i=1

where i are the barycentric coordinates. This mapping is of the form


+ be ,
Fe (
x) = Be x

Be Rnn ,

be Rn

It is applicable to arbitrary simplex elements with straight sides


n=1
n=2

n=3

Be = x2 x1 ,

x2 x1
Be =
y2 y1

x2 x1
Be = y2 y1
z2 z1

be = x1

x3 x1
,
y3 y1

be =

x3 x1 x4 x1
y3 y1 y4 y1 ,
z3 z1 z4 z1

x1
y1

x1
be = y1
z1

Coordinate and element transformations


Properties of the linear mapping
vertices are mapped onto vertices

+ be
Fe (
x) = Be x
xi = Fe (
xi )

midpoints of sides are mapped onto midpoints of sides




i +
xi +xj
x
xj
xij = 2 = Fe
= Fe (
xij )
2
barycenters are mapped onto barycenters


i +
xi +xj +xk
x
xj +
xk
= Fe (
xijk )
= Fe
xijk =
3
3
The values of i on the physical element e are defined by the formula
i (x) = i (Fe1 (x)),

x e

i (x) = i (
x),

x = Fe (
x)

Note that i (xj ) = i (


xj ) = ij and the degree of basis functions (linear,

quadratic, cubic etc.) is preserved since x depends linearly on x

Coordinate and element transformations


Derivative transformations

i (x) = i (
x),

i = Ji

Chain rule

x e,

e
x

where J is the Jacobian of the (inverse)

mapping as introduced before in the context of the finite difference method


i
x
i
y

=
=

1
det J
1
det J

h
h

i y
x
y

i x
y x

i y
y x

i x
x
y

J =

x
x

x
y

y
x

y
y

must be nonsingular
for Fe to be invertible

Isoparametric mappings: it is possible to define curved elements e using a


mapping Fe of the same degree as the basis functions on the reference element e
Example. Extended quadratic element P2+
e = Fe (
e)
x = Fe (
x) =

i xi ,
x
3
P

i=1

ij xij ,
x

xi
i (
x) +

P
ij

123 x123
x

xij
ij (
x) + x123
123 (
x)

y^

Fe

e^

1
2

1
2

x^

Construction of quadrilateral finite elements


Idea: construct 2D basis functions as a tensor product of 1D ones defined on e
1. Bilinear finite elements
Let

1 (t) = 1 t,

y^

2 (t) = t,

t [0, 1]

1 (
x) = 1 (
x)1 (
y ),

3 (
x) = 2 (
x)2 (
y)

2 (
x) = 2 (
x)1 (
y ),

4 (
x) = 1 (
x)2 (
y)

y
x^ 4
x^ 1

x^ 3

e^

x^ 2
1

Fe
x1

x^

x3

x4

x2

The space Q1 (
e) spanned by i consists of functions which are P1 for each variable
In general

Qk (
e) = span{xk11 xk22 . . . xknn },

Isoparametric mapping

x = Fe (
x) =

4
P

i=1

0 ki k,

xi i (
x),

i = 1, . . . , n

i (x) = i (Fe1 (x))

The physical element e = Fe (


e) is a quadrilateral with straight sides which must be
convex for Fe to be invertible. It is easy to verify that Fe (
xi ) = xi , i = 1, . . . , 4

Construction of quadrilateral finite elements


2. Nonconforming rotated bilinear elements
Let

1 (
Q
e) = span{1, x
, y, x
2 y2 }
2

x = Fe (
x) =

i xi

4
x

bilinear mapping
1
|Si |

Edge-oriented basis functions:

Si

1
x

uh (x) =

= [1 , 2 , 3 , 4 ]T ,

c = [c1 , c2 , c3 , c4 ]T ,

= [1, x
, y, x
2 y2 ]T ,

T c = T A1 u = T u

x4

x2

e
x1

edge mean values

uj j (
x) =

u = [u1 , u2 , u3 , u4 ]T ,

Ac = u

uh (x(s)) ds uh (xi )
4
P

Fe

2
x

j=1

Coefficients:

x3

i=1

Degrees of freedom: ui =

3
x

uh (x) = c1 + c2 x
+ c3 y + c4 (
x y )
4
P

(Rannacher and Turek, 1992)

4
P

j=1

ui =

cj j (
x), x e
P

aij cj
R
x)ds
aij = |S1i | Si j (

T = T A1

Construction of quadrilateral finite elements


Midpoint rule:

aij j (
xi ),

ui uh (xi )

a
Q
1

{edge mean values}

1
1
1 2 0
3

2
1 1 1

2
3
A=

1 1 1 2
2
3

1 0 12 31

1 (
x) =

3
4

+ 23 x
52 y 32 (
x2 y2 )

2 (
x) = 41 12 x
+ 32 y + 23 (
x2 y2 )

12 y 23 (
x2 y2 )
3 (
x) = 41 + 32 x
4 (
x) =

3
4

25 x
+ 32 y + 32 (
x2 y2 )

exact for linear functions

b
Q
1

{edge midpoint values}

1
1
1 2 0
4

3
1 1 1

2
4
A=

1 1 1 3
2
4

1 0 12 41

1 (
x) =

3
4

+x
2
y (
x2 y2 )

2 (
x) = 41 + y + (
x2 y2 )

(
x2 y2 )
3 (
x) = 41 + x

4 (
x) =

3
4

2
x + y + (
x2 y2 )

Nonparametric version: construct the basis functions directly using a local


coordinate system rather than the transformation to a reference element

Construction of quadrilateral finite elements


3. Biquadratic finite elements
1 (t) = (1 t)(1 2t),

2 (t) = t(1 2t),

3 (t) = 4t(1 t),

t [0, 1]

Products of 1D quadratic basis functions spanning the space Q2 (


e)
1 (
x) = 1 (
x)1 (
y ),

4 (
x) = 1 (
x)2 (
y ),

7 (
x) = 3 (
x)2 (
y)

2 (
x) = 2 (
x)1 (
y ),

5 (
x) = 3 (
x)1 (
y ),

8 (
x) = 1 (
x)3 (
y)

3 (
x) = 2 (
x)2 (
y ),

6 (
x) = 2 (
x)3 (
y ),

9 (
x) = 3 (
x)3 (
y)

i (x) = i (Fe1 (x)),

Basis functions on the physical element

x e

Mapping: subparametric (bilinear) or isoparametric


e

x7

x4
x8
x1
0

x3
x9

x6

Fe1

y^
1

x5 x2

e^

Fe2

x^ 4 x^ 7 x^ 3
x^ 8 x^ x^ 6
9
x^ 1 x^ 5 x^ 2
1

x^

x7 x3
x6
x8 x9
x2
x1 x5

x4

x = Fe (
x) =

9
P

xi i (
x)

i=1

e = Fe (
e) is curved

Construction of hexahedral finite elements


1. Trilinear finite elements

1 (t) = 1 t,

2 (t) = t,

t [0, 1]

Products of 1D linear basis functions spanning the space Q1 (


e)
1 (
x) = 1 (
x)1 (
y )1 (
z ),

5 (
x) = 1 (
x)1 (
y )2 (
z)

2 (
x) = 2 (
x)1 (
y )1 (
z ),

6 (
x) = 2 (
x)1 (
y )2 (
z)

3 (
x) = 2 (
x)2 (
y )1 (
z ),

7 (
x) = 2 (
x)2 (
y )2 (
z)

4 (
x) = 1 (
x)2 (
y )1 (
z ),

8 (
x) = 1 (
x)2 (
y )2 (
z)

Basis functions on the physical element


z^

x^ 4

x^ 8
x^ 5

y^

x^ 1
0
1

e^

x^ 3

Fe

x^ 7
x^ 6

x5

x^ 2
1

x8

x^

x4
x1

i (x) = i (Fe1 (x)),

x e

x3
x7

x2

Isoparametric mapping

x6

x = Fe (
x) =

8
P

xi i (
x)

i=1

2. Rotated trilinear elements (6 nodes, face-oriented degrees of freedom)

Finite element matrix assembly


Example: 1D Poisson equation

d2 u = f in (0, 1)
dx2
u(0) = 0, du (1) = 0

'k

ek

dx

Galerkin discretization:

'k

xk

uh =

N
P

u j j

xk

(linear finite elements)

j=1
N
X

u0 = 0,

uj

j=1

di dj
dx =
dx dx

f i dx,

Decomposition of integrals into element contributions


ak
ij

Au = F,

N
X
j=1

uj

z
N Z
X

k=1

ek

ek = [xk1 , xk ]

Fik

}|
{
z }| {
N Z
X
di dj
f i dx,
dx =
dx dx
k=1 ek
{z
} |
{z
}
aij

i = 1, . . . , N

Fi

i = 1, . . . , N

Example: 1D Poisson equation / linear elements


Idea: evaluate element contributions and insert them into the global matrix
aij =
Fi =

N
P

k=1
N
P

k=1

akij =

Fik =

R1

di dj
0 dx dx

R1
0

f i dx

dx

akij 6= 0 only for i, j {k 1, k}


Fik 6= 0 only for i {k 1, k}

Element stiffness matrix and load vector


ek = [xk1 , xk ]
R
R

R dk1 dk
dk1 dk1
f k1 dx
dx
dx dx
dx
dx dx
ek
ek
k
k
ek

a =
,
f
=
R
R dk dk
R dk dk1
f k dx
dx
ek
dx dx
ek dx dx
ek dx
Coefficients of the global system Au = F

ak1 k1 ak1 k
A=
ak k1
ak k

which are to be augmented

Fk1

F =
Fk

Example: 1D Poisson equation / linear elements


Special case:
k1 (x) =
k (x) =

3 elements,
xk x
xk xk1

xxk1
xk xk1

x = 31 ,

kxx
x ,

x(k1)x
,
x

x ek = [xk1 , xk ]

Hence,

dk1
dx
dk
dx

f 1

'0

'1

1
= x

ak =

1
x
1
x

e1
x0

1 1
1
1

e2
x1

'3

'2

fk =

e3

x3

x2

x
2

1
1

Assembly of the global stiffness matrix and load vector

1 1 0 0
0 0 0 0
0 0 0 0
0 0
1 0 0
1 1 0
1 1
1 0 0
1 0
A = x
0 0 0 0 + x
0 1 1 0 + x
0 0 1 1
0 0 1 1
0 0 0 0
0 0 0 0





1 1 0 0
1
0
0
1
2 1 0
1 x 1 x 0 x 2
1 1
A = x
0 1 2 1 , F = x
2 0 + 2 1 + 2 1 = 2 2
0 0 1 1
1
0
0
1

Example: 1D Poisson equation / linear elements


Recall that u0 = 0 so the first equation drops out and the system shrinks to


1
2
1
0
u
1
u1 = 25 (x)2 , u2 = 4(x)2
1
1 2 1 u2 = 1

2
(x)
1
u3 = 92 (x)2 ,
x = 31
0 1 1
u3
2

Implementation of Dirichlet boundary conditions


1. Row/column elimination: u0 = g0
whereas the second one turns into

the first equation is superfluous


a11 u1 + a12 u2 + a13 u3 = F1 a10 g0

2. Row modification (replacement by a row of the identity matrix)


a00 := 1,

a0j := 0,

j = 1, 2, 3,

F0 := g0

3. Penalty method / addition of a large number to the diagonal


a00 := a00 + ,

F0 := F0 + g0

symmetry is preserved

Implementation of Neumann boundary conditions


R
du
FN = eN f N dx + g1 a surface integral is added
dx (1) = g1

Example: 1D Poisson equation / quadratic elements


N
P

Galerkin FEM:

uj

k=1

j=1/2

ek = [xk1 , xk ],

ek

di dj
dx dx

dx =

N R
P

k=1

x = {1 (x), 2 (x)}

k1 = 1 (21 1),

k = 2 (22 1),
k1/2 = 41 2 ,

N R
P

ek

'k

dk1
41 1
=

dx
x
dk1/2
2 1
= 4x
dx
dk
1 2
dx = 4 x

i = 1, . . . , N

f i dx,
1

1=2

'k

1=2

xk

'k

ek
xk

xk

Element stiffness matrix and load vector

ak =

dk1 dk1
dx
dx
dx
ek
6 R dk1/2 dk1
6
dx
dx
dx
4 ek
R dk dk1
dx
dx
ek dx

2 R

dk1 dk1/2
dx
dx
dx
ek
R dk1/2 dk1/2
dx
dx
dx
ek
R dk dk1/2
dx
dx
ek dx

dx
k1
R ek
k
f = ekR f k1/2 dx =
f k dx
ek

x
6

1
4
1

3
dk1 dk
dx
dx
dx
ek
7
R dk1/2 dk
dx 7
dx
dx
5
ek
R dk dk
dx
ek dx dx
R

1
3x

3
7 8 1
4 8 16 8 5
1 8 7

Global system: Au = F, where


u = [u1/2 u1 u3/2 . . . uN 1/2 uN ]T

Numerical integration for finite elements


R

Change of variables theorem

f (x) dx =

i (x) = i (Fe1 (x)),

f(
x)| det J| d
x

i = Ji

x e

i
i = J 1

For instance, the entries of the element stiffness matrix are given by
Z
Z
j )| det J| d
i ) (J 1
x
aij = i j dx = (J 1
e

Numerical integration

g(
x) d
x

n
P

w
i g(
xi ),

g(
x) = f(
x)| det J|

i=0

Newton-Cotes formulae can be used but Gaussian quadrature is preferable:


R

g(
x) d
x
e

g
(
x1 )+
g (
x2 )
,
2

x
1 =

1
2

1
6

3,

x
2 =

1
2

1
6

3,

e = [0, 1]

exact for g P3 (
e) as compared to P1 (
e) for the trapezoidal rule

Storage of sparse matrices


Banded matrices: store the nonzero diagonals as 1D arrays
Arbitrary matrices: store the nonzero elements as a 1D array
1. Coordinate storage

(inconvenient access)

A(NNZ)

nonzero elements in arbitrary order

IROW(NNZ)

auxiliary array of row numbers

ICOL(NNZ)

auxiliary array of column numbers

2. Compact storage

(convenient access)

A(NNZ)

nonzero elements stored row-by-row

ILD(N+1)

pointers to the beginning of each row

ICOL(NNZ)

auxiliary array of column numbers

Example

1
2
A=
0
7

2
4
3
0

0
3
6
5

7
0
5
8

A = (1, 2, 7, 4, 2, 3, 6, 3, 5, 8, 7, 5)
ICOL = (1, 2, 4, 2, 1, 3, 3, 2, 4, 4, 1, 3)
IROW = (1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)
NNZ = 12, ILD = (1, 4, 7, 10, 13)

You might also like