1. Mandatory assignment due 11/10-2024#
Please organize you project in a fork of the repository at: MATMEK-4270/mandatory1. You should start by changing the badge in the README to reflect your own work.
Collaboration/discussion among students is encouraged, but each student need an individual fork of the repository. Please send me an email about your github username if it is not obvious who you are from this username. I can see all the forks, but I cannot necessarily understand who is who.
You need a green badge in order to pass the mandatory assignment. You also need to answer a few questions in a report and to place a movie (see Section 1.2.6) where I can easily see it on github.com (without downloading).
1.1. Poisson’s equation#
Consider Poisson’s equation
for the two-dimensional domain \(\Omega = [0, L]^2\). Use a uniform mesh of equal length for both directions, such that the mesh can be described as \(\boldsymbol{x} \times \boldsymbol{y}\), where
and \(h = L/N\). There is already the start of an implementation of a solver in Poisson2D. The solver is created such that it takes a Sympy function ue
as input when creating the solver class (see Poisson2D.__init__
). This manufactured solution ue
is used to create the right hand side function \(f(x, y)\), such that when you solve the Poisson problem numerically the resulting mesh function \(u_{ij}\) should converge towards ue
.
1.1.1. Implement the Poisson solver#
Modify the solver class Poisson2D such that the two tests test_convergence_poisson2d and test_interpolation passes.
1.2. Stationary waves#
Consider the wave equation
in a two-dimensional spatial domain \(\Omega = [0, 1]^2\) and in time \(t \in [0, T]\). Use a uniform mesh for the finite difference method in both space and time. Use the same spatial discretization in both \(x\) and \(y\)-directions, such that the mesh can be described as in Section 1.1 for \(L=1\). Time is discretized as \(t_n = n \Delta t\) for \(n \in 0, 1, \ldots, N_t\), and \(\Delta t = T/N_t\). The CFL number \(C\) is defined as
A mesh function will be denoted as
and for a given timestep \(n\) it is useful to use matrix notation for the mesh function:
All internal points in the computational domain can be discretized using central differences in both time and space
The wave equation admits two real stationary waves as solutions:
The Dirichlet problem:
The Neumann problem:
Here \(k_x=m_x\pi\) and \(k_y=m_y\pi\), where \(m_x\) and \(m_y\) are arbitrary integers, and \(\omega\) is the dispersion coefficient.
1.2.1. The Dirichlet problem#
There is the beginning of a solver class Wave2D for the homogeneous Dirichlet problem using the standing wave in Eq. (1.4) as initial condition.
Hint
A solver for the Dirichlet problem was implemented in lecture 7.
Complete the implementation of the Wave2D solver and verify the implementation using the analytical solution in (1.4). Compute the error using the \(\ell^{2}\) norm
where \(e^n = U^n - U^n_e\), \(U^n\) is the solution at time \(n \Delta t\) and \(U^n_e\) here is the analytical solution Eq. (1.4) at the mesh at the same time. The solver is verified when test_convergence_wave2d passes.
1.2.2. The Neumann problem#
There is also the beginning of a solver for the wave equation with Neumann boundary conditions in Wave2D_Neumann. This solver should use the standing wave in Eq. (1.5) as initial condition and exact solution. Modify the three class methods that are included in order to make test_convergence_wave2d_neumann pass.
For the remaining questions, please answer in a report placed in the report folder. You can use a notebook or a PDF.
1.2.3. Exact solution#
The two stationary solutions to the wave equations are real and imaginary components of the waves
where the imaginary unit \(\imath = \sqrt{-1}\). Show that Eq. (1.6) satisfies the wave equation.
1.2.4. Dispersion coefficient#
Assume that \(m_x=m_y\) such that \(k_x=k_y=k\). A discrete version of Eq. (1.6) will then read
where \(\tilde{\omega}\) is a numerical dispersion coefficient, i.e., the numerical approximation of the exact \(\omega\). Insert Eq. (1.7) into the discretized Eq. (1.3) and show that for CFL number \(C=1/\sqrt{2}\) we get \(\tilde{\omega} = \omega\).
1.2.5. Test for exact solution#
Modify the test test_exact_wave2d such that it verifies that \(m_x=m_y\) and \(C=1/\sqrt{2}\) leads to l2-errors less than \(10^{-12}\) for both the Dirichlet problem and the Neumann problem.
1.2.6. Create movie#
Create a movie of the Neumann problem using \(m_x=m_y=2\) and \(C = 1/\sqrt{2}\). Call the move neumannwave.gif
and save it to the report folder of your forked repository. Make sure that the movie is not larger than 1 MB.
Hint
See Lecture 7 about how to create an animation and a movie in Python.