386
Chapter
8.
Problems
in
multiple
spatial dimensions
Continuing
in
this manner,
we find
We
can now
solve
62
Ku = f to
obtain
The
resulting piecewise linear approximation
is
displayed
in
Figure
8.18.
The
calculations
in the
previous example
are
elementary,
but
extremely time-
consuming,
and are
ideal
for
implementation
in a
computer program. When these
calculations
are
programmed,
the
operations
are not
organized
in the
same
way as
in
the
above hand calculation.
For
example, instead
of
computing
one
entry
in K
at a
time,
it is
common
to
loop over
the
elements
of the
mesh
and to
compute
all
the
contributions
to the
various
entries
in K and f
from
each element
in
turn.
Among
other things, this
simplifies
the
data
structure
for
describing
the
mesh.
(To
automate
the
calculations presented above,
it
would
be
necessary
to
know, given
a
certain node, which nodes
are
adjacent
to it.
This
is
avoided when
one
loops over
the
elements instead
of
over
the
nodes.) Also,
the
various integrations
are
rarely
carried
out
exactly,
but
rather
by
using quadrature rules. These implementation
details
are
discussed
in
Section 10.1.
As
we
have discussed before,
an
important aspect
of the finite
element method
is
the
fact
that
the
linear systems
that
must
be
solved
are
sparse.
In
Figure 8.19,
we
display
the
sparsity
pattern
of the
stiffness
matrix
for
Poisson's equation,
as in
Example 8.10,
but
with
a finer
grid.
The
matrix
K is
banded,
that
is, all of its
entries
are
zero except those
found
in a
band around
the
main diagonal.
Efficient
solution
of
banded
and
other sparse systems
is
discussed
in
Section 10.2.
62
It is
expected that
a
computer program
will
be
used
to
solve
any
linear system large than
2x2
or
3 x 3. We
used
MATLAB
to
solve
Ku = f for
this example.
386
Chapter
8.
Problems in multiple spatial dimensions
Continuing in this manner, we find
h
3
2h
3
3h
3
h
3
f = 2h
3
3h
3
h
3
2h
3
3h
3
We can now solve
62
Ku
= f to obtain
0.015904
0.027344
0.027065
0.020647
u = 0.035156
0.034040
0.015904
0.027344
0.027065
The resulting piecewise linear approximation is displayed in Figure 8.18.
The calculations in
the
previous example are elementary,
but
extremely time-
consuming,
and
are ideal for implementation in a computer program. When these
calculations are programmed,
the
operations are not organized in the same way as
in the above hand calculation. For example, instead of computing one entry in K
at
a time, it
is
common to loop over the elements of the mesh and to compute
all the contributions
to
the various entries in K and f from each element in turn.
Among other things, this simplifies the
data
structure for describing the mesh. (To
automate the calculations presented above, it would be necessary to know, given a
certain node, which nodes are adjacent
to
it. This
is
avoided when one loops over
the
elements instead of over
the
nodes.) Also, the various integrations are rarely
carried out exactly,
but
rather by using quadrature rules. These implementation
details are discussed in Section 10.l.
As
we
have discussed before, an important aspect of
the
finite element method
is
the
fact
that
the linear systems
that
must be solved are sparse. In Figure 8.19,
we
display the sparsity
pattern
of the stiffness matrix for Poisson's equation, as in
Example 8.10,
but
with a finer grid. The matrix K
is
banded,
that
is, all of its
entries are zero except those found in a band around the main diagonal. Efficient
solution of banded and other sparse systems is discussed in Section 10.2.
6
2
It
is expected
that
a
computer
program
will
be
used
to
solve
any
linear system large
than
2 x 2
or
3 X 3. We used MATLAB
to
solve
Ku
= f for
this
example.