Assignment 4: Two dimensional wave
Starting from a modularized form of the wave1d program (which we will give you), you will now generalize this to a program that can solve a two-dimensional damped wave equation, i.e., that can solve the equation:
$$\frac{\partial^2u}{\partial t^2} - c^2 \frac{\partial^2u}{\partial x^2} - c^2 \frac{\partial^2u}{\partial y^2} + \frac{1}{\tau} \frac{\partial u}{\partial t} = 0$$
on a square domain \([x_1,x_2]\times[x_1,x_2]\) with boundary conditions
$$u(x_1,y,t)=0\ {\rm for\ all}\ y \in [x_1,x_2]$$ $$u(x_2,y,t)=0\ {\rm for\ all}\ y \in [x_1,x_2]$$ $$u(x,x_1,t)=0\ {\rm for\ all}\ x \in [x_1,x_2]$$ $$u(x,x_2,t)=0\ {\rm for\ all}\ x \in [x_1,x_2]$$
for all times \(t\), and initial conditions of a pyramid form:
$$u(x,y,t=0) = p(x)p(y)$$
$$p(x)=\begin{cases}0&\mbox{if}\quad{}x<x_1+L/4\\(x-x_1-L/4)/L&\mbox{if}\quad{}x_1+L/4<x<(x_1+x_2)/2\\\frac{1}{2}-(x-x_1-L/4)/L&\mbox{if}\quad{}(x_1+x_2)/2<x<x_2-L/4\\0&\mbox{if}\quad{}x>x_2-L/4\end{cases}$$
where $$L=x_2-x_1$$.
The starting (one-dimensional) code is in a git repo on the Teach cluster, and can be cloned with
git clone /scinet/course/phy1610/a4wave2d
This creates the a42wave2d subdirectory within which there will be a directory .git with a copy of the repository. Usually, you would create a new branch at this point, but since you will not be pushing your changes back to the original repo, you can make commits to the existing branch in the.git repository in this local copy. Do not start a new repo, leave this one, with all its history ("git log") intact.
Compilation of the code can be done with the commands
source teachsetup make
The first line loads the gcc, gdb, and rarray module. If you are working on your own machine, you should download rarray from https://github.com/vanzonr/rarray, and download the code at the bottom of this page (that zip file contains the git directory). The code does not use rarray yet, but this will be part of the assignment.
Running the code is, like before, done with the command
./wave1d waveparams.txt
or with the command "make run".
ASSIGNMENT:Modify this code in the following ways:
- First, run the program as is, and save the output to create an integrated test.
- Change the code to use rarray<double,1> instead of unique_ptr<double[]>. Ensure the program passes the integrated test.
- Next, you will create a 2D version, but before that, copy all of the 1D code and the Makefile to a sub-directory, and add and commit that to git.
- Your next step towards 2D will be to modify the wavetypes.h so it uses 2d rarrays. At this point, the program will no longer work or compile, as the other modules can not handle 2D arrays yet.
- Start modifying the simulation (which will allocate the ngrid x ngrid arrays), initialization (which will fill it), output (which will write it out), and evolve modules, in that order. The last module, evolve, needs to actually solve the equation, for which see below).
- While doing that, for each of these 4 modules, you should create a unit tests for each functions.
- Remember to include rules to compile and run each test in the Makefile (the tests can work before the whole program will), and don't forget to make frequent git commits.
Please submit to this web site:
- A zip file or tar file with the most recently committed working source tree including the .git subdirectory. See https://education.scinet.utoronto.ca/mod/page/view.php?id=2170 for tips on how to do that.
- The output file generated after running your 2D version of the code.
Deadline: Friday February 17, 2023, at 11:59pm.
Late penalty policy: as usual, you can submit up to seven days late, but you will get 5% taken off for each day you submitted late. Also note that if you submit the different parts of your work at different times, the last submission date is taken as the submission of the whole.
How to numerically solve the 2D damped wave equation in the evolve module- 11 February 2023, 3:24 PM