Assignment 3: Modularize with make and git
The program wave1d.cpp (available below) solves the damped 1-dim wave equation:
$$\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(x_1)=0 $$ $$u(x_2)=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 the Makefile supplied below. On the Teach cluster, this code requires loading the "gcc/12" module.
Running the code should be done with the command
./wave1d waveparams.txt
or with the command "make run", which will run the simulation with the parameters in the file waveparams.txt (also available below).
The source code (wave1d.cpp), makefile (Makefile) and parameter file (waveparams.txt) should all be saved in the same folder.
ASSIGNMENT:Modify this code into a new, modularized version:
- First, create a local git repository and put in the existing code, Makefile, and input file.
- Ensure the program runs and then save its output under a new name. You will be modifying the code and this saved output will be your check that the program's output has not changed.
- 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...
- You can do this step by step.
- We expect you to have detailed git commits during this refactoring exercise, with meaning full comments.
The original file should in the end only contain the main function, which solves the same problem as the original code by calling functions in the modules.
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 implemented modular version of the code.
Deadline: Friday February 3, 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.
- 27 janvier 2023, 11:19
- 27 janvier 2023, 11:19
- 27 janvier 2023, 11:19