Jacobi solver for boundary value problems

Content

We are looking for a numerical approximation of the function \(u(x,y)\) f where \(u_{xx} + u_{yy} = 0\) with the boundary equation \(u(x,y) = g(x,y)\) for \(x, y \in \delta\Omega\). The image above presents a numerical approximation for the boundary conditions \(u(x,0) = sin(\pi x)\), \(u(x,1) = sin(\pi x) e^{-\pi}\) und \(u(0, y) = u(1, y) = 0\).

The problem can be solved numerically by dividing the domain \(\Omega\) uniformely by using a \(N \times N\) grid. Then \(u(x,y)\) can be represented on the points of the grid using a matrix \(A\) where \(A_{i,j} = u\left(\frac{i}{N}, \frac{j}{N}\right)\) for \(i,j = 0 \dots N\):

\[ \left( \begin{array}{ccccc} A_{0,N-1} & A_{1,N-1} & \dots & A_{N-2, N-1} & A_{N-1,N-1} \\ A_{0,N-2} & A_{1,N-2} & \dots & A_{N-2, N-2} & A_{N-1,N-2} \\ \vdots & \vdots & & \vdots & \vdots \\ A_{0,1} & A_{1,1} & \dots & A_{N-2, 1} & A_{N-1, 1} \\ A_{0,0} & A_{1,0} & \dots & A_{N-2, 0} & A_{N-1, 0} \end{array} \right)\]

A stepwise approximation of \(A\) can be done by computing a sequence of \(A_0\), \(A_1 \dots\) where the border of \(A_0\) is defined by \(g(x,y)\) and otherwise initialized to zeroes.

Multiple iterative solvers are possible. The simplest is the Jacobi solver that works with a 5-point difference star:

\[ A_{{k+1}_{i,j}} = \frac{1}{4} \left( A_{k_{i-1,j}} + A_{k_{i,j-1}} + A_{k_{i,j+1}} + A_{k_{i+1,j}} \right)\]

for \(i, j \in 1 \dots N-1, k = 1, 2, \dots\). (See Alefeld et al, Parallele numerische Verfahren, pp. 18.)

The iterations are repeated until

\[ \max_{i,j = 1 \dots N-1} \left| A_{{k+1}_{i,j}} - A_{{k}_{i,j}} \right| \le \epsilon\]

for some given value of \(\epsilon\).

Exercise

Compilation and execution

theon$ mpic++ -g -O3 -std=c++17 \
>    -Istep03 -I/home/numerik/pub/pp/ss19/lib \
>    $(pkg-config --cflags gdk-pixbuf-2.0) \
>    -o jacobi jacobi.cpp $(pkg-config --libs gdk-pixbuf-2.0)
theon$ mpirun -np 4 ./jacobi
5090 iterations
theon$