Você está na página 1de 15

Finite Element Methods on a Time-Varying

System
Christopher Lustri
June 16, 2010
1 Introduction
We wish to explore the theory underlying the implementation of nite element
methods in numerical analysis, particularly with reference to solutions of the par-
tial dierential equation

2
u = f in , (1)
u = g
D
on
D
and
u
n
= g
N
on
N
. (2)
where R
2
,
D

N
= and the two boundary regions are distinct with

D
non-empty. Specically, we will consider the key results in the development
of the theory of nite elements, including weak solutions and the structure of the
individual elements, as well as the numerical implementation of the method. We
will subsequently implement a nite element numerical solver in order to solve
this equation in a region of space, with f, g
D
and g
N
prescribed.
We will then extend these concepts in order to consider a time-varying problem
using Euler time-steps, and nally implement a nite element solution to a simple
time-varying analogue of the original spatial partial dierential equation, given as
u
t

2
u = f in , (3)
u = u
0
in at t = 0, (4)
with the same boundary conditions as before. We will consider the problem with
both steady and time-varying boundary conditions.
1
2 Finite Element Methods on a Spatial Problem
2.1 Weak formulation
Many equations of interest in applied mathematics have classical solutions. We
consider the sets of functions
C
0
() = {f : R|f is continuous},
C
2
() =

f : R|f
x
i
x
j
C
0
() i, j

.
If is suciently regular, the solution u to an second-order partial dierential
equation, such as that given in (1, 2) satisfying u C
2
() is known as a classical,
or strong solution [4]. That is, if there exists a solution which has continuous sec-
ond partial derivatives, and is therefore suciently smooth, it is a strong solution
to the problem.
There are numerous numerical techniques that may be applied in order to nd
classical solutions to partial dierential equations [1, 2, 5]. Unfortunately, many
problems of interest do not admit classical solutions. If this is the case, we must
instead search for a variational, or weak formulation of the original problem. This
involves reformulating the original problem such that the smoothness requirement
is relaxed. The resultant expression is known as a weak formulation of the prob-
lem.
In order to obtain a weak formulation, we consider a test function w that lies in
the Sobolev space
H
1
E
0
() = {v H
1
()|v = 0 on
D
},
where
H
1
() = {v : R|u, u
x
, u
y
L
2
()} ,
L
2
() =

v : R|

v
2
<

.
That is, we require that the function w and associated rst-derivatives to be
square-integrable. Now, if we integrate the product of problem given in (1) and
the test function w, we obtain

2
u w =

f w.
Integration by parts and application of the divergence theorem gives

u w =

wf +

w
u
n
.
Substitution of the boundary conditions given in (2), noting that v H
1
E
0
(),
gives the formulation

u w =

wf +

N
wg
N
. (5)
2

k
:
Figure 1: Triangular tesselation of a domain using triangular elements
k
. The domain is
shaded blue, with nodes denoted by bold circles, and the boundary of the domain,
, denoted by bold lines.
This is the weak formulation of the partial dierential equation given in (1). In
order for a solution u to be considered a weak solution of (1, 2), we require that
u H
1
E
() = {v H
1
()|v = g
D
on
D
},
and that u satises the weak formulation of (1), given in (5) [3]. While for strong
solutions we required the second-derivatives to be continuous, we simply require
for weak solutions that the rst-derivatives be square-integrable. It may be demon-
strated that all strong solutions to the problem also satisfy the conditions to be
considered weak solutions. By considering the weak formulation, we are eectively
permitting a broader range of solutions to the original problem by extending the
solution space.
2.2 Galerkin method
The Galerkin approximation method allows us to convert a continuous problem,
such as the weak formulation for the partial dierential equation given in (refweak)
into a discrete problem that may be solved numerically. This method involves
using a nite dimensional subspace S
0
of H
1
E
0
, and therefore obtaining a solution
in a nite dimensional subset of H
1
E
.
The rst stage is to tesselate the domain into non-overlapping regions. Any
polygonal domain may be tesselated using triangles and, as such, triangular tes-
selations are frequently chosen when implementing the Galerkin method. It is,
however, possible to divide the domain up in a variety of fashions, such as quadri-
lateral tesselations, which will be touched upon in a later section. We will assume
that the domain is tesselated with non-overlapping triangles, or elements
k
for
k = 1, . . . , K, such that the vertices of neighbouring elements meet at points called
nodes. An example of this tesselation is included in Figure 1.
3
Node j

j
Figure 2: The right-hand side shows a schematic of a typical
j
, which is nonzero at node j and
zero at all other nodes, with
j
dened in a piecewise fashion such that it is linear
in each triangle. The left-hand side shows
j
on a single triangle. Each triangle will
be nonzero for three dierent values of j, corresponding to each of the three nodes on
the edge of the triangle.
The subspace S
0
is typically dened as the span of a set of basis functions, such
that
S
0
= span{
1
,
2
, . . . ,
n
},
where
j
for j = 1, . . . , n is a set of linearly independent basis functions, and n is
the number of nodes in the tesselation of the domain that are not found on
D
.
The remaining nodes found on
D
are denoted as node j = n+1, n+2, . . . , n+n

.
A common method of constructing S
0
is to select
j
such that
j
is continuous,
equal to one at node j and equal to zero on all elements not touching node j. On
the elements that do touch node j,
j
is linear in the form ax + by + c such that
the previous requirements are satised. A schematic of the function
j
may be
seen in Figure 2. The set {
1
,
2
, . . . ,
n
} forms a basis for the space S
0
= P
1
,
which is the space of continuous piecewise linear functions on the triangulation.
We also dene
n+1
,
n+2
, . . . ,
n+n

in a similar fashion.
There are other methods of constructing the approximation space S
0
such that
it takes dierent forms. It is possible to use quadratic functions of the form
ax
2
+bxy +cy
2
+dx+ey +f, rather than linear functions, on each elements. This
requires nodes to be dened on the sides of each triangle, as well as at the vertices.
In fact, it is possible to select polynomials of any order, although this typically
involves selecting more nodes on the boundary, as well as internal nodes. To
dene cubic basis functions, we require that the triangles contain 10 nodes, with
four on each side and one internal node. While there are some situations where
selecting higher-order basis functions is desirable, they are beyond the scope of
this document, and we will consider only linear basis functions for the purposes of
calculation. For illustrative purposes, Figure 3 contains an example of a triangular
element containing part of a quadratic basis function. Additionally, the elements
may not be triangular, but may instead take dierent shapes, such as quadrilateral
elements. Again, there are some situations where such basis functions may be
4
Node j
Figure 3: A single triangular element containing part of a piecewise quadratic basis function

j
. The element contains six nodes, which is required in order to generate the basis
function.
more useful for computational purposes, however that is also beyond the scope of
this document. Further information on element types and basis functions may be
found in Elman et al. [3].
The Galerkin method involves seeking
u
h
=
n

j=1
u
j

j
+
n+n

j=n+1
u
j

j
H
1
E
, (6)
such that u
h
satises the weak form of the original problem, given in (5). This
gives

u
h
w =

wf +

N
wg
N
, (7)
for all w S
0
. As S
0
= span{
1
,
2
, . . . ,
n
}, this is equivalent to nding u
h
such
that

u
h

i
=

i
f +

i
g
N
,
for i = 1, 2, . . . , n. Using (6), this may be expressed in the form of a linear system
Au = f such that
A = {a
i,j
} where a
i,j
=

j

i
, (8)
u = (u
1
, u
2
, . . . , u
n
)
T
and f = (f
1
, f
2
, . . . , f
n
)
T
, where
f
i
=

i
f +

i
g
N

n+n

j=n+1
u
j

j

i
.
As such, the Galerkin method involves determining A and f, and then solving the
resultant linear system in order to obtain an approximation for u in S
0
. We could
apply this method to problems with dierent governing equations, however this
entails obtaining a new weak formulation for the problem.
5

.
.
.
:

4


y
x
Figure 4: Triangular tesselation of part of the domain , specied in (1) as 0 < x < 1 and
0 < y < 1, using triangular elements
k
. The part of the domain shown is shaded
blue, with nodes denoted by bold circles, and the boundary of the domain, , denoted
by bold lines.
2.3 Implementation
In order to demonstrate the Galerkin nite-element method, we considered the
problem

2
u = f in 0 < x < 1, 0 < y < 1, (9)
with discontinuous Dirichlet conditions on the left boundary, given by
u =

0 x = 0, y < 0.5,
1 x = 0, y 0.5,
(10)
and no-ux Neumann conditions prescribed on the remaining boundaries. The
boundary conditions are discontinous, which means that we will require a weak
solution to the partial dierential equation. We rst considered the problem with
no forcing term, or f = 0, and then with a nonzero forcing term, f = 0.25y. In
order to discretize the domain, the region in question was rst divided into squares,
which were subsequently split into two triangular regions, as seen in Figure 4. The
domain consisted of 30 rows, each containing 60 triangles.
The Galerkin method described in the previous section was implemented according
the the algorithm described Elman et al. [3]. This method involves computing
the stiness matrix A and the load vector f numerically. Calculations on each
element were performed by mapping
k
, with vertecies at (x,y) = (x
1
, y
1
), (x
2
,
y
2
) and (x
3
, y
3
), to a reference element

with verticies at (,) = (0,0), (0,1)


and (1,0), with the mapping given as
x(, ) = x
1

1
(, ) + x
2

2
(, ) + x
3

3
(, ),
y(, ) = y
1

1
(, ) + y
2

2
(, ) + y
3

3
(, ),
6
(a) f = 0 (b) f = 0.25y
Figure 5: Solution to the spatial problem described in (1) with boundary conditions given in
(10) along x = 0 and no-ux conditions on the remaining boundaries, with (a) f = 0
and (b) f = 0.25y.
with

1
= 1 ,

2
= ,

3
= .
This simplied the numerical evaluation of the integrals within the denition of
A and f. Integrals performed over an element were performed using triangular
quadrature such that

h(, ) d d
1
2
h(1/3, 1/3),
while the trapezium rule was applied in order to evaluate line integrals along the
edges of elements. The stiness matrix and load vector were then assembled and
mapped back into the (x,y) domain. The solution u to the equation Au = f was
then computed using MATLAB. The results may be seen in Figure 2.3.
We see that in both cases, the heat ows into the domain where the boundary
is equal to one, and out of the domain where the boundary is equal to zero. In
the gure with a forcing term, we see that the gradient of the heat ow is steeper
in the bottom half of the domain and less steep at the top of the domain, as the
contribution from the forcing term is proportional to y. It is important to note
that the discontinuous boundary condition does not pose a problem in either case,
due to the nature of numerical nite-element methods.
3 Finite-Element Methods on a Time-Varying
Problem
We may now extend the ideas developed in the previous section in order to develop
a scheme for solving the time-varying problem given in (3, 4). To accomplish this,
7
we obtain a weak formulation for the solution in space, and approximate the solu-
tion in space by nite elements as before. This will produce a system of ordinary
dierential equations which may be solved using nite dierence methods. We
will use the Euler method, although other methods are applicable.
3.1 Weak formulation and Finite Element Scheme
The weak formulation for the time-varying problem given in (3) takes the form

u
t
w +

u w =

wf +

wg
N
.
We then discretise the spatial domain as before, and apply the Galerkin approxi-
mation such that we search for u
h
H
1
E
that solves the equation in a nite sub-
space, given by S
0
= span{
1
,
2
, . . . ,
n
}. We therefore nd that the Galerkin
equation takes the form

u
h
t
w +

u
h
w =

wf +

wg
N
. (11)
Aside from the time-derivative, this equation is identical to that given in (7). As
such, each of these terms has been addressed in the previous section. It remains
to be demonstrated how the time-derivative alters the resulting system. In order
to discretise this term in space, we begin with the expression for u
h
given in (6).
From this, we see that
u
h
t
(x, t) =
n

j=1
du
j
dt
(t)
j
(x) +
n+n

j=n+1
du
j
dt
(t)
j
(x) H
1
E
.
We therefore nd that the discrete equation contains

u
h
t
w =
n

j=1
du
j
dt
(t)

j
(x)
i
(x) +
n+n

j=n+1
du
j
dt
(t)

j
(x)
i
(x).
The time-varying discretised system may therefore be expressed using (6) as
n

j=1
u
j

i
+
n

j=1
u
j
(t)

j

i
=

f
i
+

i
g
N

n+n

j=n+1
u
j

j

i

n+n

j=n+1
u
j

i
.
This is a linear system of semi-discrete rst-order ordinary dierential equations
of the form M u(t) + Au(t) = f, with A dened in (8), M is given by
M = {m
i,j
} where m
i,j
=

i
,
8
and f = (f
1
, f
2
, . . . , f
n
)
T
takes the new form
f
i
=

f
i
+

i
g
N

n+n

j=n+1
u
j

j

i

n+n

j=n+1
u
j

i
.
3.2 Euler Method
We now use the Euler method [2] in order to write the semi-discrete system given
by M u(t) + Au(t) = f as a fully discretised system. If we write
u
k
= (u
1
(kt), u
2
(kt), . . . , u
n
(kt))
T
,
for k = 1, 2, . . ., the Euler method involves approximating the time-derivatives as
u(kt)
u
k+1
u
k
t
.
The semi-discrete system at some t = kt therefore becomes
M(u
k+1
u
k
) + tAu
k
= tf,
with some prescribed initial condition u
0
. As such, we can solve a linear system
at each time-step given by
Mu
k+1
= (M tA)u
k
+ f, (12)
where u
0
is known, and each subsequent u
k
may be obtained from u
k1
. As
such, we may now obtain the solution for the system over a number of time-
steps by solving the fully-discretised linear system at each time step (that is, for
k = 1, 2, . . .).
It is possible to show that this method will be unstable for large enough t,
and therefore care must be taken when determining the time-steps that are to
be chosen when solving a problem. If the time-steps are too large, the solution
vectors will tend to innity as k , even if the solution does not behave in
this manner.
3.3 Implementation
In order to demonstrate the Galerkin nite-element method, we considered the
problem
u
t

2
u = f in 0 < x < 1, 0 < y < 1, 0 < t 2, (13)
with the discontinuous Dirichlet conditions given in (10) given on the left bound-
ary and no-ux Neumann conditions prescribed on the remaining boundaries. The
initial condition was prescribed as being zero everywhere within the domain. The
9
discretization and nite-element scheme was identical to that applied to the sta-
tionary problem, with the exception that the domain was divided into 18 rows,
each containing 36 triangles, in order to improve the speed of computation.
The introduction of the time-stepping procedure as described earlier led to insta-
bilities unless the time-steps were set to be extremely small. In order to ensure
stability, the time-steps were chosen as t = 10
5
, although this could be made
larger without a loss of stability in the solution. The linear system described in
(12) was solved at each time-step in order to demonstrate the behaviour of the
system when ow starts at t = 0. Some of the results may be seen in Figure 3.3.
We see that the ow tends towards the steady solution over time, as required.
Additionally, we could easily apply this method to more complicated problems,
such as a problem with time-varying forcing terms or boundary conditions. We
could also adapt the method to other governing equations by obtaining a dierent
weak formulation, as described in the previous section.
4 Conclusions
There are many partial dierential equations that arise in applied mathematics
for which no classical solution exists. In these cases, we must search for weak
solutions to the partial dierential equations by expressing the equation in varia-
tional form, which may be solved in order to obtain weak solutions to the original
problem. We may use nite element methods in order to compute the solution to
the equations in variational form and subsequently obtain weak solutions to the
original equation.
The method of nite elements involved discretising the domain of the problem into
a set of elements, and dening a set of piecewise basis functions on these elements
in order to obtain an approximation space, generated by the basis functions. It
was within this approximation space that the weak solution was sought. We sub-
sequently applied the Galerkin nite element method which entailed constructing
a stiness matrix and load vector in order to express the nite element solution
as the solution to a linear system of equations, which could be solved numerically.
This method was applied in order to solve two simple problems; the heat equation
without a forcing term in the original equation, the same equation with a forcing
term included.
In order to solve time-varying problems, we obtained a variational form for the
equation with a time-derivative included, and applied the nite element method
as before, obtaining a semi-discrete system that was discrete in space but continu-
ous in time. This, however, resulted in a system of ordinary dierential equations,
rather than a fully discrete linear system. To fully discretise the system, we used
the Euler method to discretise the ordinary dierential equations in time. The re-
sultant system was then solved using standard methods for solving linear systems.
This method was applied in order to solve the time-varying heat equation and it
10
(a) t = 0 (b) t = 0.4
(c) t = 0.8 (d) t = 1.2
(e) t = 1.6 (f) t = 2
Figure 6: Solution to the time-dependent spatial problem described in (13) with boundary con-
ditions given in 10 along x = 0 and no-ux conditions on the remaining boundaries,
with u = 0 initially within the domain. The solutions is shown at regular intervals
between t = 0 and t = 2.
11
was observed that the computed solution evolved from the initial conguration
towards the steady solution as time progressed.
A number of extensions to the methods described here were touched upon. We can
consider a range of dierent equations, however doing so involves determining the
variational form for each new equation. It is possible to use elements of dierent
shapes, such as quadrilateral elements. Additionally, it is possible to consider
higher-order piecewise basis functions, such as quadratic or cubic basis functions.
In many cases, these can give greater accuracy, but require more nodes within
each element, increasing computational cost. We could also consider dierent
methods of discretisation in time, such as Runge-Kutta methods, and apply the
current scheme to more demanding time-varying problems, such as problems with
time-varying boundary conditions or forcing terms.
A Example nite-element solver
This code was used to discretise the system in question and apply the Galerkin
nite-element method used on a simple linear basis with triangular elements in
order to solve the system. This code was used to produce the results in the report,
with minor modications depending on the problem in question.
1 clear all
2
3 % Discretisation of domain
4 T = 10; % Triangles per row (even)
5 N = T/2 + 1; % Nodes per row
6 rows = 5; % Number of rows
7 Xt = linspace(0,1,N); % Range in x
8 Yt = linspace(0,1,rows+1); % Range in y
9 X = [];
10 Y = [];
11 for i = 1:rows+1
12 X = [X Xt];
13 Y((i-1)
*
N+1:i
*
N) = Yt(i)
*
ones(1,N);
14 end
15 nodes = length(X); % Number of nodes in system
16 triangles = T
*
rows; % Number of elements in system
17
18 L = Xt(2)-Xt(1); % Distance between nodes
19 Jk = L2; % Twice the area of each element
20
21 % Contiguous list of nodes on boundary
22 B = [1:N:(rows-1)
*
N+1 rows
*
N+1:(rows+1)
*
N ...
23 rows
*
N:-N:N N-1:-1:2];
24
25 % Forming Connectivity Matrix C
26 C = zeros(4,triangles);
27 C(1,:) = 1:triangles;
12
28 for i = 1:rows
29 C(2,(i-1)
*
T+1:i
*
T) = ceil(C(1,1:T)/2)+(i-1)
*
N;
30 end
31 C(3,1:2:triangles-1) = C(2,1:2:triangles-1)+N;
32 C(3,2:2:triangles) = C(2,1:2:triangles)+1;
33 C(4,:) = C(2,:)+N+1;
34
35 % Forming Stiffness Matrix A and Load Vector f
36 dchidxi = [-1 1 0]; % Partial derivatives
37 dchidnu = [-1 0 1];
38 Jstar = 0.5; % Size of reference element
39
40 for k = 1:triangles
41
42 % Finding spatial coordinates of vertices
43 X1 = X(C(2,k));
44 X2 = X(C(3,k));
45 X3 = X(C(4,k));
46 XX = [X1 X2 X2];
47 Y1 = Y(C(2,k));
48 Y2 = Y(C(3,k));
49 Y3 = Y(C(4,k));
50 YY = [Y1 Y2 Y3];
51 CC = [C(2,k) C(3,k) C(4,k)];
52
53
54 for i = 1:3
55 for j = 1:3
56 Aloc(i,j,k) = ((Y3-Y1)
*
dchidxi(i) + ...
57 (Y1-Y2)
*
dchidnu(i))
*
...
58 ((Y3-Y1)
*
dchidxi(j) + ...
59 (Y1-Y2)
*
dchidnu(j))
*
...
60 Jstar/Jk + ((X1-X3)
*
dchidxi(i) + ...
61 (X2-X1)
*
dchidnu(i))
*
...
62 ((X1-X3)
*
dchidxi(j) + ...
63 (X2-X1)
*
dchidnu(j))
*
Jstar/Jk;
64 end
65
66 xstore = 0;
67 ystore = 0;
68 for j = 1:3
69 xstore = xstore + XX(j)/3;
70 ystore = ystore + YY(j)/3;
71 end
72 % Define the function f as ffunc(x,y)
73 floc(k,i) = 0.5
*
ffunc(xstore, ystore)
*
2
*
Jk/3;
74
75 if sum(CC(i) == B) > 0
76 floc(k,i) = floc(k,i) + L/2
*
GN(XX(i),YY(i));
77 end
78
79 end
80 end
81
13
82 Pt = C(2:end,:);
83 P = Pt';
84
85 A = zeros(nodes,nodes);
86 f = zeros(nodes,1);
87 for k = 1:triangles
88 for j = 1:3
89 for i = 1:3
90 A(P(k,i),P(k,j)) = A(P(k,i),P(k,j)) + Aloc(i,j,k);
91 end
92 f(P(k,j)) = f(P(k,j)) + floc(k,j);
93 end
94 end
95
96 UJ = linspace(0,1,rows+1);
97
98 % Setting Dirichlet condition edge of domain.
99 for i = 1:rows+1
100 A(N
*
(i-1)+1,:) = zeros(1,nodes);
101 A(N
*
(i-1)+1,N
*
(i-1)+1) = 1;
102 end
103
104 % Obtaining the steady-state solution
105 uout = A\f;
106 umapss = reshape(uout, T/2+1, rows+1);
107 umapss = umapss';
108
109
110 % Computing Mass Matrix M
111 for k = 1:triangles
112 for i = 1:3
113 for j = 1:3
114 Mloc(i,j,k) = 0.5
*
(1/3)
*
(1/3)
*
Jk;
115 end
116 end
117 end
118 M = zeros(nodes,nodes);
119 for k = 1:triangles
120 for j = 1:3
121 for i = 1:3
122 M(P(k,i),P(k,j)) = M(P(k,i),P(k,j)) + Mloc(i,j,k);
123 end
124 end
125 end
126
127 % Setting timesteps
128 dt = 0.000001;
129 Nsteps = 100000;
130 usol = zeros(length(f), Nsteps/10000);
131 uk = zeros(length(f),1);
132
133 % Applying Dirichlet conditions
134 for i = 1:rows+1
135 M(N
*
(i-1)+1,:) = zeros(1,nodes);
14
136 M(N
*
(i-1)+1,N
*
(i-1)+1) = 1;
137 end
138
139 for i = 2:Nsteps
140
141 % Creating load vector
142 fnew = (M - dt
*
A)
*
uk + dt
*
f;
143
144 % Performing Euler step
145 for k = 1:rows+1
146 fnew(N
*
(k-1)+1) = round(UJ(k));
147 end
148 uk = M\fnew;
149
150 % Storing solution
151 if i/10000 == round(i/10000)
152 usol(:,i/10000) = uk;
153 end
154 end
155
156 % Preparing solution for visualisation
157 umap = reshape(usol(:,end), T/2+1, rows+1);
158 umap = umap';
References
[1] W F Ames. Numerical Methods for Partial Dierential Equations. Academic
Press, New York, 1992.
[2] B Carnahan, H A Luther, and J O Wilkes. Applied Numerical Methods. John
Wiley and Sons, New York, 1969.
[3] H Elman, D Silvester, and A Watham. Finite Elements and Fast Iterative
Solvers. Oxford University Press, Oxford, 2005.
[4] J Ockendon, S Howison, A Lacey, and A Movchan. Applied Partial Dierential
Equations. Oxford University Press, Oxford, 2003.
[5] Q A Press, B P Flannery, S A Teukolsky, and W T Vetterling. Numerical
recipes: The Art of Scientic Computing. Cambridge University Press, New
York, 1986.
15

Você também pode gostar