ENERGY 281
Spring Quarter 2007-08
Le ture 11 Notes
Thesenoteswereoriginally written byTara LaFor e.
1 Derivation of the Finite Element Method
Inordertoderivethefundamental on eptsofniteelementmethods(FEM)
we will start by looking at an extremely simple ODE and approximate it
usingFEM.
1.1 The Model Problem
Themodel problemis:
−u ′′ + u = x 0 < x < 1
u (0) = 0 u (1) = 0
(1)andthis problem an be solved analyti ally:
u (x) = x − sinh x/ sinh 1
. Thepurpose of starting with this problem is to demonstrate the fundamental
on epts and pitfalls in FEM in a situation where we know the orre t an-
swer, sothatwe willknowwhere our approximationis goodand where itis
poor. In asesof pra ti alinterestwe willlookat ODEs andPDEsthatare
too omplex to be solved analyti ally.
FEMdoesn'ta tuallyapproximatetheoriginalequation,butrathertheweak
form of the original equation. The purpose of the weak form is to satisfy
the equation in the "average sense," so that we an approximate solutions
thatare dis ontinuous or otherwise poorly behaved. Ifa fun tion
u(x)
is asolutiontotheoriginalformoftheODE, thenitalsosatisesthe weakform
ofthe ODE. The weakform ofEq. 1is
Z 1
0 −u ′′ + u vdx = Z 1
0
xvdx
(2)Thefun tion
v(x)
is alled theweight fun tionor testfun tion.v(x)
an beany fun tion of
x
that issu iently well behaved for the integrals to exist.Theset of all fun tions
v
that also havev(0) = 0
,v(1) = 0
are denoted byH
. (We willput many more onstraintsonv
shortly.)Thenew problemisto nd
u
sothatR 1
0 (−u ′′ + u − x) vdx = 0 for allv ∈ H
u (0) = 0 u (1) = 0
(3)On etheproblemiswritteninthiswaywe ansaythatthesolution
u
belongsto the lass of trial fun tions whi h are denoted
H ˜
. When the problem iswritten in this way the lasses of test fun tions
H
and trial fun tionsH ˜
arenot the same. For example,
u
must be twi edierentiable and have the propertythatR 1
0 u ′′ vdx < ∞, while v
doesn't even have to be
ontinuousas
longastheintegralinEq. 3existsandisnite. Itispossibletoapproximate
u
in this way, but having to work with two dierent lasses of fun tionsunne essarily ompli ates the problem. In order to make sure that
H
andH ˜
arethe same we an observe thatifv
issu iently smooth thenZ 1
0 −u ′′ vdx = Z 1
0
u ′ v ′ dx − u ′ v| 1 0 (4)
Thisformulationmustbevalidsin e
u
mustbetwi edierentiableandv
wasarbitrary. This puts another onstraint on
v
that it must be dierentiable and thatthose derivatives mustbe well-enough behaved to ensure thattheintegral
R 1
0 u ′ v ′ dx exists. Moreover, sin
e we de
ided from the outset that
v(0) = 0
and v(1) = 0
, the se
ond term in Eq. 4 is zero regardless of the
behaviorof
u ′ atthese points. The newproblem is
Z 1
0
u ′ v ′ + uv − xv dx = 0.
(5)Noti ethatbyperformingthe integrationbyparts werestri tedthe lassof
testfun tions
H
byintrodu ingv ′intotheequation. Wehavesimultaneously
expandedthe
lassoftrialfun
tionsH ˜
,sin
e u
isnolongerrequiredto have
ase ondderivativeinEq. 5. TheweakformulationdenedinEq. 5is alled
avariational boundary-valueproblem.
InEq. 5
u
andv
have exa tlythe same onstraints onthem:1.
u
andv
mustbesquare integrable, thatis:R 1
0 uvdx ≈ R 1
0 u 2 dx < ∞
2. The rst derivatives of
u
andv
must be square integrable, that is:R 1
0 u ′ v ′ dx ≈ R 1
0 (u ′ ) 2 dx < ∞ (this a tually guarantees the rst prop-
erty)
3. Wehadalreadyassumedthat
v(0) = 0
andv(1) = 0
andweknowfromthe originalstatement of theproblem that
u(0) = 0
andu(1) = 0
.Now we have that
H = H = H ˜ 0 1. Any fun
tion w
is a member of H 0 1
if
R 1
0 (u ′ ) 2 dx < ∞ and w(0) = w(1) = 0
. H 0 1
is the spa
e of admissible
fun tionsforthe variational boundary-value problem(ie. all admissibletest
and trialfun tionsarein
H 0 1)
Wewill onsiderthevariationalformEq. 5tobetheequationthatwewould
like to approximate, rather than the original statement in Eq. 1. On e we
have found asolution toEq. 5in this waywe an askthe question whether
thisformulation isalsoa solutiontoEq. 1: That is,whetherthissolution is
afun tionsatisfyingEq. 1atevery
x
in0 < x < 1
,orwhetherwehavefoundasolutionthatsatisesonlythe weakformoftheequation. Inthe asethat
we anonly nd asolution to the weakform, no " lassi al" solutionexists.
1.2 Galerkin Approximations
We now have the problemre-stated so thatwe arelooking for
u ∈ H 0 1 su h
that
Z 1 0
u ′ v ′ + uv dx = Z 1
0
xvdx
(6)for all
v ∈ H 0 1. In order to narrow down the number of fun tions we will
onsider in our approximate solutions we will make two more assumptions
about
H 0 1. First,wewill assumethatH 0 1 isalinearspa
eof fun
tions(that
isif
v 1 , v 2 ∈ H 0 1 anda, b
are
onstants then av 1 + bv 2 ∈ H 0 1.)
These ondassumption isthat
H 0 1 isinnite dimensional. For exampleifwe
have the sine seriesψ n (x) = √
2 sin(nπx)
forn = 1, 2, 3, ...
andv ∈ H 0 1 then
v
an be represented byv (x) = P ∞
n=1 a n ψ n (x). The s
alar
oe
ients a n
aregiven by
a n = R 1
0 v (x) ψ n (x) dx, justlike usual. Hen
einnititely many
oe
ients a n
must be found to dene v
exa tly. As in Fourier analysis,many of these oe ients will be zero. We will also trun ate the series in
orderto have managablelength series,justlike in dis rete Fourier analysis.
and osines,mu hlesssmoothfun tions anbeused. Infa tour setofbasis
fun tionsdo not even have to be smooth and an ontain dis ontinuities in
the derivatives,but they mustbe ontinuous. We will assumethatthe in-
niteseries onvergessothatwe an onsideronlytherst
N
basisfun tionsandgeta good approximation
v N ofthe original test (ortrial) fun tion:
v ∼ = v N = X N
i=1 β i φ i (x) (7)
where
φ iareas-yetunspe iedbasisfun tions. Thissubspa eoffun tionsis
denoted
H 0 (N ) andisasubspa
e ofH 0 1. Galerkin'smethod
onsistsofnding
an approximate solution to Eq. 6 in a nite-dimensional subspa e
H 0 (N ) of
H 0 (1 ofadmissible fun
tionsrather thanin the whole spa
e H 0 1. Nowwe are
H 0 1. Nowwe are
looking for
u N = P N
i=1 α i φ i (x). The new approximate problem we have is
to ndu N ∈ H 0 (N )
su
h that
Z 1
0
u ′ N v ′ N + u N v N dx = Z 1
0
xv N dx
(8)for all
v N ∈ H 0 (N ). Sin
e the φ i are known (in prin
iple) u N will be
om-
u N will be om-
pletely determined on e the oe ients
α i havebeen found.
Inorderto ndthat
α n weput P N
i=1 α i φ i (x) andP N
i=1 β i φ i (x) into Eq. 8.
Z 1 0
d dx
h P N
i=1 β i φ i (x) i
d dx
h P N
j=1 α j φ i (x) i + h P N
i=1 β i φ i (x) i h P N
j=1 α j φ i (x) i
− x P N
i=1 β i φ i (x)
dx = 0
(9)forall
N
independent sets ofβ i.
This an be expanded andfa tored to give
X N i=1 β i
X N
j=1
Z 1
0
φ ′ j (x) φ ′ i (x) + φ j (x) φ i (x) dx
α j −
Z 1
0
xφ i (x) dx
= 0
(10)
forall
N
independent setsofβ i. Thestru ture ofEq. 10iseasierto seeifit
isre-written as
X N i=1 β i
X N
j=1 K ij α j − F i
= 0
(11)forall
β i. Where
K ij = R 1 0
h φ ′ j (x) φ ′ i (x) + φ j (x) φ i (x) i
dx F = Z 1
0
xφ i (x) dx
(12)and where
i
,j = 1, ..., N
. TheN × N
matrix ofK ij is alled the stiness
matrixand the ve tor
F
isthe loadve tor. Sin etheβ i areknownK ij and
F
an be al ulated dire tly. But theβ i were arbitrary so we an hoose
ea h element
β i for ea
h equation. For the rst equation
hoose β 1 = 1
and
β n = 0
forn 6= 1
. NowP N
j=1 K 1j α j = F 1
. Similarly for the se ondequation hoose
β 2 = 1
andβ n = 0
forn 6= 2
so thatP N
j=1 K 2j α j = F 2
.In this way we have hosen
N
independent equations that an be used tondthe
N
unknownsα i. Moreover the N
oe
ientsα i
an be found from
α j = P N
j=1 K − 1
ji F i
whereK − 1
ji
arethe elementsof the inverse ofK
.The stiness matrix
K
is symmetri for this simple problem, whi h makesthe omputation of the matrix faster sin e we don't have to ompute all of
the elements, symmetri matri ies arealsomu h faster to invert.
1.3 Finite Elements Basis Fun tions
Now we have done a great deal of work, but it may not seem like we are
mu h loser to nding a solution to the original ODE sin e we still know
nothing about
φ i. The purpose of using su h a general formulation is that any set of linearly independent fun tionswill work to solve the ODE. Now
wearenallygoingto talkaboutwhatkindoffun tionswewillwant touse
as basis fun tions. The nite element method is a general and systemati
te hnique for onstru ting basis fun tions for Galerkin approximations. In
FEMthebasisfun tions
φ i aredened pie
ewiseover subregions. Overany
subdomain the φ i will be
hosen to be polynomials of low degree, though
otherpossibilitiesdoexist.
•
niteelements arethe subregionsofthe domainover whi hea hbasisfun tion is dened. Hen e ea h basis fun tion has ompa t support
over an element. Ea h element has length
h
. The lengths of the ele-mentsdoNOTneed tobethesame(butgenerallywewillassumethat
theyare.)
•
nodes ornodalpointsaredened withinea helement. InFigure1thevenodesarethe endpoints ofea h element (numbered 0to 4).
•
the nite element mesh is the olle tion ofelementsand nodalpointsthat make up the domain and is shown in Figure 1. An element
i
isdenotedby
Ω i.
Now weneed to onstru tthe a tual basisfun tionsusing the three riteria
denedbefore: 1)Thebasisfun tionsaresimple fun tionsdenedpie ewise
overtheniteelementmesh,2)thebasisfun tionsmustbeinthe lassoftest
fun tions
H 0 1, and3) The basisfun
tionsare
hosen sothatthe parameters
α i arethe valuesof u N (x)
at the nodalpoints.
u N (x)
at the nodalpoints.The simplest set of basis fun tionsare the hat fun tions on elements
i = 1, 2, 3
.φ i (x) =
x−x i −1
h i for x i−1 ≤ x ≤ x i
x i+1 − x
h i+1 for x i ≤ x ≤ x i+1
0 for x < x i−1 , x > x i+1
(13)
where
h i = x i − x i−1 isthe length ofelement i
. Thederivativesare
φ ′ i (x) =
1
h i for x i−1 ≤ x ≤ x i
− 1
h i+1 for x i ≤ x ≤ x i+1
0 for x < x i−1 , x > x i+1
(14)
Theequationsfor elements0 and4havebeenleftout sin e wede ided that
u(0) = u(1) = 1
, so no basis fun tions are required. In general the basisfun tionsfor the rstand last elementsare halfofthe fun tions sin ethere
isno
i−1
ori+1
node,respe tively. Thehatfun tionsareshowninFigure2.Themathemati al termfor hatfun tionsispie e-wise linear basis fun tions
Lookingatthethree riteriaabove, learlythefun tionsinEq. 13aresimple
anddened element-wise. Itiseasy to showthattheyarein
H 0 1, sin e they
have square-integrable rst derivatives. They also satisfy the third riteria
sin e
φ i (x j ) = 1
ifi = j
and 0 otherwise. Hen e ea h fun tion ontributes to the value ofu N at exa
tlyone node and α i = u N (x i )
.
It is less lear that the hat fun tions will give a ontinuous representation
of
v N and u N. Let v
be the sine fun
tion with period 2 shown in Figure
v
be the sine fun tion with period 2 shown in Figure3. At the nodes (0, 1, 2, 3, 4) sine has the values (0,0.7071,1,0.7071,0).
The representation
v N on the nite element mesh is v N = 0.7071φ 1 (x) +
0 1 2 3 4
h 1 h
2 h
3 h 4
Ω 1 Ω 2 Ω 3 Ω 4
Figure1: Fourniteelementsontheinterval[01℄.
0 1 2 3 4
−1 0 1
h 1 h 2 h 3 h 4
Ω 1 Ω 2 Ω 3 Ω 4
φ 1 φ 2 φ 3
0 1 2 3 4
−1 0 1
h 1 h 2 h 3 h 4
Ω 1 Ω 2 Ω 3 Ω 4
φ 1 ∗ φ 2 ∗ φ 3 ∗
Figure2: Fourhatfun tions(top)andtheirderivatives(bottom)ontheinterval[01℄.
φ 2 (x) + 0.7071φ 3 (x)
. When the elements are summed up the sine waveis approximated by pie ewise linear fun tions between ea h of the nodes,
and is exa tly represented at ea h node. When more nodes are used the
approximationimprovesand in the limitof
N → ∞
the sinewave wouldbeexa tlyrepresented. In FEMwe willnever pro eedall the wayto the limit,
so the interval size
h
will always have nite sizeh
. This is why the termnite elements is used.
0 0.5 1 1.5 2 2.5 3 3.5 4
−1 0 1
h 1 h 2 h 3 h
4
Ω 1 Ω 2 Ω 3 Ω 4
0.7071φ 1
φ 2
0.7071φ 3
sin(pi x) v
N
Figure3: Theniteelementapproximation of
sin (πx)
using ve nodesontheinterval[01℄.
1.4 The Stiness Matrix
K
and the Load Ve torF
for HatFun tions
Re allfromEq. 12thatea h element of the stinessmatrix
K
is given byK ij = R 1
0
φ ′ i (x) φ ′ j (x) + φ i (x) φ j (x) dx
= P 4 e=1
R
Ω e
φ ′ i (x) φ ′ j (x) + φ i (x) φ j (x) dx
= P 4 e=1 K ij e
(15)
similarly
F i = Z 1
0
xφ i (x)dx = X 4 e=1
Z
Ω e
xφ i (x)dx = X 4
e=1 F i e
(16)where we have used the property that
φ(x)
are dened pie ewise on ea helement 1through 4. Inorder to ompute anapproximation ofthe solution
to the model ODE it is ne essary to ompute nine elements for
K ij from
i, j = 1, 2, 3
and threeelementsfor F
. Butsin
e ea
h of the fun
tions φ(x)
aredenedinthesamewayitispossibleto ompute
K eandF eforageneri
element andthen to onstru t thematrix usingthe sumsabove. Consider a
generi interiorelement
Ω eontheintervalx Atox B. Wewillusea
hange of
x B. Wewillusea hange of
variablesandrewritethisintermsof
ξ
,adummyvariableforx
. Wewillhaveξ = (0, h)
. On this element exa tly two of the hat fun tions are nonzero:ψ A (ξ) = 1 − h ξ and ψ B (ξ) = h ξ. Convin
e yourself that this denition is
equivalent tothe previousdenitionof thehat fun tion,but withthe origin
shifted to the start of one of the interior elements. The two hat fun tions
have derivatives
ψ ′ A (ξ) = − h 1 andψ ′ B (ξ) = h 1.
It is also important to noti e that for the hat fun tions
φ i (x) 6= 0
on onlythe elements
Ω i and Ω i+1. Thisresults ina tridiagonal sparsematrix K
for
K
forany number of elements in the mesh aswill be shownbelow. Using Eq. 15
you an see thatthereare threeintegrals that ontributeto
K ij:
k AA = R h 0
ψ e A ′ (ξ) 2
+ [ψ e A (ξ)] 2 dξ
= R h 0
[1/h] 2 + [1 − ξ/h] 2
dξ = 1/h + h/3 k AB = R h
0 ψ A e ′ (ξ) ψ B e ′ (ξ) + ψ e A (ξ) ψ e B (ξ)dξ
= R h
0 ((−1/h) (1/h) + (1 − ξ/h) (ξ/h))dξ = −1/h + h/6 k BB = R h
0
ψ e B ′ (ξ) 2
+ [ψ e B (ξ)] 2 dξ
= R h 0
[−1/h] 2 + [ξ/h] 2
dξ = 1/h + h/3
(17)
Similarlythe omponentsthat ontributeto the loadve tor are:
F A e = R h
0 (x A + ξ) (1 − ξ/h) dξ = h 6 (2x A + x B ) F B e = R h
0 (x A + ξ) (ξ/h) dξ = h 6 (x A + 2x B ) (18)
wherethe
x Aandx Bterms
omefromevaluatingthefor
ingfun
tionf (x) = x
at the endpoints ofthe generi
element.
f (x) = x
at the endpoints ofthe generi element.Thusea hgeneri interiorelement ontributestothe stinessmatrix a
2 × 2
submatrix
k e =
1/h + h/3 −1/h + h/6
−1/h + h/6 1/h + h/3
(19)
f e = h/6
2x A + x B
x A + 2x B
(20)
For the 4 element mesh we have derived the ontributions to the overall
stinessmatrix
K
from ea hnode isgiven by:K 1 =
1/h + h/3 0 0
0 0 0
0 0 0
K 2 =
1/h + h/3 −1/h + h/6 0
−1/h + h/6 1/h + h/3 0
0 0 0
K 3 =
0 0 0
0 1/h + h/3 −1/h + h/6 0 −1/h + h/6 1/h + h/3
K 4 =
0 0 0
0 0 0
0 0 1/h + h/3
(21)
where the ontributions fromelements 1and 4have only oneentry be ause
only halfof the hat fun tion existson these elements. Similarly the ontri-
butions to theload ve tor are
F 1 = h/6
2h
0 0
F 2 = h/6
2h + 2h h + 4h
0
(22)F 3 = h/6
0 4h + 3h 2h + 6h
F 4 = h/6
0 0 6h + 4h
(23)where
h = 0.25
for the model problem. NowK = K 1 + K 2 + K 3 + K 4
and
F = F 1 + F 2 + F 3 + F 4. The nalsystemof equations hassymmetri
anddiagonallydominant stinessmatrix
K
,whi hisveryni etoworkwithmathemati ally. Thevalues of
u N at ea
h node isgiven by α = K ˜ − 1 F
and
u N = P 3
i=1 α i φ i (x).
Using this we get that the approximation to the model problem is
u = 0.0353φ 1 (x)+0.0569φ 2 (x)+0.0505φ 3 (x)
. Thisisnotaverya urateanswer,sin e only four elements wereused. A more a urate approximation an be
obtainedbyusingmoreelements, butatthe ostofbuildingandinverting a
larger stinessmatrix
K
. The usualwayofestimating the errorof anFEMapproximation using linear basis fun tions (the hat fun tions we derived)
usingthe
L 2 or mean-square norm isthat ||e|| 0 < C 2 h 2. This isan a-priori
substantially smaller.
Referen es
[1℄ Be ker, E. B., G. F. Carey, and J. T. Oden, Finite Elements an In-
trodu tion, Texas Institute for Computational Me hani s, UT Austin,
1981.