1. Modularization
$$\frac{\partial^2u}{\partial t^2} - c^2 \frac{\partial^2u}{\partial x^2} + \frac{1}{\tau} \frac{\partial u}{\partial t} = 0$$
with boundary conditions
$$u=0$$
and initial conditions of a triangle form:
$$u(x,0)=\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$$.
Compilation of the code can be done with the command
g++ -std=c++17 -O2 wave1d.cpp -o wave1d
or using the make command, which requires this Makefile. On the Teach cluster, this code requires loading the "gcc/9" module.
Running the code should be done with the command
./wave1d waveparams.txt
which will run the simulation with the parameters in the file waveparams.txt.
The source code (wave1d.cpp), makefile (Makefile) and parameter file (waveparams.txt) should all be in the same folder.
ASSIGNMENT:Modify this code into a new, modularized version:
- Create as many functions (headers and implementation files, do not forget preprocessor guards) as you find reasonable/necessary (e.g., input,output,parameters,single-step solver, driver, etc. -- you should at least have three modules!)
- Update the Makefile to compile this modular project. Remember to include rules for each module, compilation and optimization flags, a clean rule, etc...
- Use your favourite plotting tool or file comparison tool to check that the results match those from before the modularization.
The original file should become just a 'driver', containing main, that solves the same problem as the original code.
Please submit:
- All source and header files and the makefile for the modularized program.
- The output file generated after running your implemented modular version of the code.
- A brief report, explaining what you did (i.e. what functions and modules you created and why), as well as the logic of the makefile, and how you checked that your code matches the results generated by the original code.
Deadline: January 27, 2022, at 11:59pm.
Late penalty policy: you can submit up to seven days late, but you will get a half point 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.
- 20 January 2022, 11:32 PM
- 20 January 2022, 11:32 PM
- 20 January 2022, 11:32 PM