Poisson2d Notes
Poisson2d Notes
Our first boundary value problem will be the steady-state heat equation, which in two dimensions has the
form
∂ ∂T ∂ ∂T
− k + k = q 000 (x), plus BCs. (1)
∂x ∂x ∂y ∂y
If the thermal conductivity k > 0 is constant, we can pull it outside of the partial derivatives and divide
both sides by k to yield the 2D Poisson equation
2
∂ u ∂2u
− + = f (x), plus BCs. (2)
∂x2 ∂y 2
with f := q 000 /k and u := T . (We typically use u for scalar fields throughout the course for notational
convenience. Later, it will pair well with the set of test functions, denoted as v.)
We will work with the Poisson equation and extensions throughout the course. At this point we want
to introduce some simple cases in order to understand optimal solution strategies in the 3D case, which is
arguably the most important in terms of compute cycles consumed throughout the world.
The basic idea behind the finite difference approach to solving differential equations is to replace the differ-
ential operator with difference operators at a set of n gridpoints. In 1D, it is natural to order the points
sequentially, as illustrated in Fig. 1. Here, we consider the two-point boundary value problem
d2 u
− = f (x), u(0) = u(1) = 0. (3)
dx2
We use the second-order centered difference approximation to the second derivative, which for uniform grid
spacing h := xj − xj−1 is
!
uj+1 − 2uj + uj−1 d2 u h2 d4 u 4
− = − + + O(h ) (4)
h2 dx2 xj 12 dx4 xj
h2 d4 u
= f (xj ) − − O(h4 ) (5)
12 dx4 xj
≈ f (xj ). (6)
Note that (4)–(6) comprises three steps. First, we use the Taylor series expansion to express our difference
formula in terms of the desired derivative plus higher-order corrections. Second, we replace the desired
derivative by the data (f ), given by the differential equation. Finally, we incur the our truncation error by
dropping the higher-order terms in the Taylor series. We equate the results to arrive at our discete system
for the numerical approximation, uj ,
uj+1 − 2uj + uj−1
− = fj , j = 1, . . . , n. (7)
h2
The set of equations (7) represents our discretization of the original differential equation and is an
algebraic system consisting of n equations in n unknowns, uj , j=1,. . . ,n. Each equation j relates uj−1 , uj ,
and uj+1 to fj . For this reason, the resulting matrix system is tridiagonal,
uj−1 uj
uj+1
2 −1 u1 f1
−1 2 −1 u2 f2
.. ..
1 .. ..
−1 . . . = . , (8)
h2
.. ..
..
..
. . −1 . .
−1 2 un fn
| {z }| {z } | {z }
Ax u f
which has the shorthand Ax u = f , where u is the vector of unknowns and f the vector of data values, as
indicated in (8). We will often simply use A instead of Ax for notational convenience. Here, we explicitly
call out the x-coordinate association in preparation for the 2D development coming in the next section.
Our principal concern at this point is to understand the (typical) matrix structure that arises from the 2D
Poisson equation and, more importantly, its 3D counterpart. The essential features of this structure will
be similar for other discretizations (i.e., FEM, SEM), other PDEs, and other space dimensions, so there is
merit to starting with this relatively simple system.
For constant thermal conductivity k this equation reduces to the standard Poisson equation in Ω := [0, 1]2 ⊂
lR2 , which we usually express in terms of u for notational convenience:
where we have substituted the finite difference approximations, assumed to be about the point xij := (xi , yj ),
for i, j ∈ [1, . . . , N ]2 .
Assuming a lexicographical ordering in which the i- (x-) index advances fastest, the system takes on the
following matrix structure for ∆x = ∆y = h.
4 −1 −1
−1 4 −1 −1 u11 f11
.. .. .. u21 f21
−1 . . .
..
..
.. .. .. . .
. . −1 .
..
..
−1 4 −1
.
.
..
uM 1
fM 1
−1 4 −1 .
u12 f
12
..
u22
f
−1 −1 −1 .
4 22
.. .. .. ..
..
..
. −1 . . .
.
.
.. .. .. ..
.. ..
. .
. . . −1 .
uM 2 fM 2
..
.
1 −1 −1 4 .. ..
.. .. =
h2 . .
. .
−1
.. ..
.. ..
.
.
. . −1
.. ..
.. .. ..
.
.
. . .
.. ..
.. .. ..
. . .
.
.
.. ..
.. ..
.
.
. . −1
u1N f1N
−1 4 −1
u2N f2N
..
.
−1 −1 4 .. ..
. .
.. .. .. ..
. . . .
..
..
.. .. ..
. .
. . . −1 uM N fM N
−1 −1 4 | {z } | {z }
| {z } u f
A2D
Note that A2D can be expressed as the sum of two systems, one associated with Ax coming
2 2
from δδxu2 , and one associated with one associated with Ay coming from δδyu2 . Specifically, we can
write
where we have introduced the Kronecker (or tensor) product, ⊗. For two matrices A and B, their
Kronecker product C = A ⊗ B is defined as the block matrix
a11 B a12 B · · · · · · a1n B
a21 B a22 B · · · · · · a2n B
C := . (14)
.. .. ..
. . .
am1 B am2 B · · · · · · amn B
We will soon explore a few properties of this form, but for now simply note that it allows a clean
expression of the discretized Poisson operator in 2D. Consider the following splitting of A2D .
−1
2
−1 2 −1
.. ..
−1 . .
.. ..
. . −1
−1 2
2 −1
−1 2 −1
.. ..
−1 . .
.. ..
. .
−1
−1 2
..
.
1
A2D =
h2 ..
.
..
.
..
.
..
.
2 −1
..
.
−1 2
.. .. ..
. . .
.. ..
. . −1
−1 2
2 −1
2 −1
.. ..
. .
.. ..
. .
2 −1
..
−1
2 .
..
−1 .
2
.. .. ..
. . .
.. .. ..
. . .
..
−1 .
1 2
+
h2
.. ..
. . −1
.. ..
. . −1
.. .. ..
. . .
.. .. ..
. . .
.. ..
. . −1
−1 2
−1 2
.. ..
. .
.. ..
. .
−1 2
2Ix −Ix
Ax
Ax
..
1 −Ix 2Ix .
A2D = + 2
.. h .. ..
. . .
−Ix
Ax −Ix 2Ix
= (Iy ⊗ Ax ) + (Ay ⊗ Ix )
δ 2
We see that we can express A2D as (Iy ⊗ Ax ) + (Ay ⊗ Ix ). The first term is nothing other than δx 2
δ 2
being applied to each row (j) of uij and the second term amounts to applying δy2 to each column
(i) on the grid.
%
% NOTE: It is important to use SPARSE matrices throughout. 5
%
% Otherwise, your run times will be very long and 10
Lx=2; Ly=1;
nx=15; ny=3; % Number of _interior_ points 20
dx=Lx/(nx+1); dy=Ly/(ny+1); 25
Ix=speye(nx); Iy=speye(ny);
40 Iy ⊗ Ax
45
A = kron(Iy,Ax) + kron(Ay,Ix); %%% FINITE DIFFERENCE STIFFNESS MATRIX 0 5 10 15 20 25 30 35 40 45
nz = 129
nd= 5;
e = ones(nd,1); Ad = spdiags([-e 2*e -e], -1:1, nd, nd);
T = kron(Iy,Ad); full(T) Ay ⊗ Ix
0
nd= 15;
e = ones(nd,1); Ad = spdiags([-e 2*e -e], -1:1, nd, nd);
T = kron(Iy,Ad); spy(T)
title(’I_y \otimes A_x’,’fontsize’,16) 50
set(gcf,’PaperUnits’,’normalized’);set(gcf,’PaperPosition’,[0 0 1 1])
print -dpdf iyax.pdf
nd= 5;
e = ones(nd,1); Ad = spdiags([-e 2*e -e], -1:1, nd, nd);
T = kron(Ad,Ix); full(T)
150
nd= 15;
e = ones(nd,1); Ad = spdiags([-e 2*e -e], -1:1, nd, nd);
T = kron(Ad,Ix); spy(T)
title(’A_y \otimes I_x’,’fontsize’,16)
set(gcf,’PaperUnits’,’normalized’);set(gcf,’PaperPosition’,[0 0 1 1]) 200
Ay ⊗ Ix
print -dpdf ayix.pdf
0 50 100 150 200
nz = 645
A = kron(Iy,Ax) + kron(Ay,Ix)
where Ax and Ay are formed using the matlab spdiags command (help spdiags), and Iy and Ix
are formed using speye.
It is important to use sparse matrices in matlab for these higher-dimensional (2D and 3D)
problems or you will run out of memory and it will take very long to solve these problems.
We now extend the 1D and 2D concepts to the most important 3D case. The short story is that
the 3D stiffness matrix takes the wonderfully symmetric form
and the discrete system is as before A3D u = f . This of course is the form that arises for a finite
difference discretization of −∇2 u = f in Ω = [0, 1]3 , u = 0 on ∂Ω, or, more explicitly,
2
δ2u δ2u
δ u
− + + = f (xi , yj , zk ), (16)
δx2 δy 2 δz 2
with
δ2u uij,k+1 − 2uijk + uij,k−1
:= , (17)
δz 2 ijk ∆z 2
δ2 u δ2 u
and equivalent expressions for δx2
and δy 2
.
Note that, with (15), we really have not restricted ourselves to uniform mesh spacing in each
direction. We could have different grid spacing ∆x, ∆y, and ∆z and number of mesh points Nx ,
Ny , and Nz , in each of the space directions. Then, Ix would be the Nx × Nx identity matrix and
Ax would be the corresponding stiffness matrix, as would also be the case for y and z.