Assignment 4 - Solving a finite element system#
This assignment makes up 30% of the overall marks for the course. The deadline for submitting this assignment is 5pm on Thursday 15 December 2022.
Coursework is to be submitted using the link on Moodle. You should submit a single pdf file containing your code, the output when you run your code, and your answers to any text questions included in the assessment. The easiest ways to create this file are:
Write your code and answers in a Jupyter notebook, then select File -> Download as -> PDF via LaTeX (.pdf).
Write your code and answers on Google Colab, then select File -> Print, and print it as a pdf.
Tasks you are required to carry out and questions you are required to answer are shown in bold below.
The assignment#
Mathematical background#
In this assignment, we are going to solve a Helmholtz wave problem:
As our domain we will use the unit square, ie
The finite element method is a method that can approximately solve problems like this. We first split the square
As shown in the diagram, we let
The (degree 1) finite element method looks for an approximate solution by placing an unknown value/variable at each point, and approximating the solution as some
linear combination of the functions
(We do not need to go into details of how this method is derived, but if you’re curious, the first chapter of Numerical Solution of Partial Differential Equations by the Finite Element Method by Claes Johnson gives a good introduction to this method.)
Let
The entries
You could alternatively write this as
For example (using
For
As as second example, when
In this second example, I have numbered the points not on the boundary like this:
Part 1: creating the matrix and vector#
Write a function that takes
You can find example matrices and vectors for
Part 2: solving the system#
Solving the matrix-vector problem will lead to an approximate solution to the Helmholtz problem:
we call this approximate solution
Using any matrix-vector solver, solve the matrix-vector problem for
An example of 3D plotting in matplotlib can be found in the sparse PDE example from earlier in the course.
Part 3: comparing solvers and preconditioners#
In this section, your task is to evaluate the performance of various matrix-vector solvers.
To do this, solve the matrix-vector problem with small to medium sized value of
You should compare at least five matrix-vector solvers: at least two of these should be iterative solvers, and at least one should be a direct solver. You can use solvers from the Scipy library. (You may optionally use additional solvers from other linear algebra libraries such as PETSc, but you do not need to do this to achieve high marks. You should use solvers from these libraries and do not need to implement your own solvers.) For two of the iterative solvers you have chosen to use, repeat the comparisons with three different choices of preconditioner.
Based on your experiments, pick a solver (and a preconditioner if it improves the solver) that you think is most appropriate to solve this matrix-vector problem. Explain, making use of the data from your experiments, why this is the best solver for this problem.
Part 4: increasing #
In this section, you are going to use the solver you picked in part 3 to compute the solution
for larger values of
The problem we have been solving in this assignment has the exact solution
where
For a range of values of
Using your plots, estimate the complexity of the solver you are using (ie is it
Part 5: parallelisation#
In this section, we will consider how your solution method could be parallelised; you do not need, however, to implement a parallel version of your solution method.
Comment on how your solution method could be parallelised. Which parts (if any) would be trivial to parallelise? Which parts (if any) would be difficult to parallelise? By how much would you expect parallelisation to speed up your solution method?
If in part 4 you used a solver that we have not studied in lectures, you can discuss different solvers in parts 4 and 5.