In the final week of the unit, we will use finite differences to solve PDEs in two dimensions. Particular focus will be placed on solving Poisson's equation. For 2D problems, the number of unknowns and hence the size of the linear systems quickly grow as the number of grid points is increased. Hence, sparse matrices can lead to substantial reductions in the memory that needed to numerically solve the PDE.
On Blackboard you can find a Python file that solves
on the rectangular domain , with on all of the boundaries. This code uses NumPy to solve the linear system. The matrix for the discretised Laplacian is stored as a dense NumPy array.
The exercises below can be completed in any order.
Write your own 2D Poisson solver that uses SciPy's root
function.
Extend the code on Blackboard so that sparse matrices are used.
Use memory profiling to determine how much memory is required to solve the 2D Poisson equation. How does the memory usage depend on the number of grid points?
Write a solver for the 2D diffusion equation
with at the boundaries and . Beware, the time-step restrictions for 2D problems are different than for 1D problems!