My program solves a simple 2D Poisson problem, specifically the homogeneous equation,
with Dirichlet boundary conditions given as,
which has analytic solutions given by,
The numerical solution is computed using linear finite elements (FEM) on a regular triangular mesh. The script defines a simple mesh class which is used to generate and store such a mesh for a given number of grid divisions. The program then loops over the elements to compute and assemble the FEM stiffness matrix and uses some sparse linear algebra routines from scipy to compute the numerical solution for the given mesh.
A loop over the number of grid divisions is performed, doubling each time, such that the convergence of the numerical solution towards the expected analytic result can be observed. A figure is produced showing the final numeric solution side by side with the analytic solution for visual comparison, as well as plots of the error norms and observed order of convergence to validate the expected 2nd order spatial accuracy of the method.