# Assignment 5: Laplace solver

**Ouvert le :**vendredi 16 février 2024, 00:00

**À remettre :**vendredi 1 mars 2024, 23:59

For this assignment, you should write a modular code that solves the two-dimensional Laplace equation

$$\frac{\partial^2V}{\partial x^2} + \frac{\partial^2V}{\partial y^2} = 0$$

for the field *V* in a domain consisting of the area between an outer square [-1,1]×[-1,1] and an inner square [-0.1, 0.1]×[-0 1, 0.1] . The boundary conditions are *V=0* on the outer square and *V=1* on the inner square.

A physical realization of this would be the electric potential inside a square coaxial cable

Elliptical PDEs such as this one are often solved numerically using an iterative approach. After discretizing the domain as an N x N matrix (of which are internal submatrix here is filled with 1s), at each step, each interior element is replaced by the average of its direct neigbours in all directions, i.e.

$$V_{i,j} \leftarrow (V_{i,j+1}+V_{i,j-1}+V_{i+1,j}+V_{i-1,j})/4$$

This should be repeated for all points until convergence, I.e until the maximum change in the new and old value of all \(V_{ij}\) is less than a given threshold. At each iteration, the boundary conditions must be imposed.

By the way, this update rule is that of the diffusion equation with the maximal time step that is still stable.

Your program should take the number N and the threshold as command line arguments, solve the problem using rarrays, and write the result to a file. It should be modular in much the same way as the modular gameof1d:

- one initialization module with header file (you can start with an array of all zeros for the interior points);
- one iteration module with header file;
- one output module with header file;
- and a main program to drive the whole computation.

You do not have to create tests for this assignment, but your Makefile should have a 'run' target that performs the calculation with N=500 and epsilon=1e-6.

As always, use best practicse like makefiles, version control and commenting your code.

Submit your repo as a zip file in the usual way by March 1 2024.