Skip to main content
SciNet
  • Home
  • All Courses
  • Calendar
  • Certificates
  • SciNet
    Main Site Documentation my.SciNet
  • CCDB
  • More
Close
Toggle search input
English
English Français
You are currently using guest access
Log in
SciNet
Home All Courses Calendar Certificates SciNet Collapse Expand
Main Site Documentation my.SciNet
CCDB
Expand all Collapse all
  1. Dashboard
  2. PHY1610 - Winter 2022
  3. 1. Modularization

1. Modularization

Completion requirements
Opened: Thursday, 20 January 2022, 12:00 AM
Due: Monday, 31 January 2022, 11:59 PM
The program wave1d.cpp 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=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.
You can upload these separately, or combined in a tar or zip file.

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.

Creative Commons License
  • Makefile Makefile
    20 January 2022, 11:32 PM
  • wave1d.cpp wave1d.cpp
    20 January 2022, 11:32 PM
  • waveparams.txt waveparams.txt
    20 January 2022, 11:32 PM
Contact site support
You are currently using guest access (Log in)
Data retention summary


All content on this website is made available under the Creative Commons Attribution 4.0 International licence, with the exception of all videos which are released under the Creative Commons Attribution-NoDerivatives 4.0 International licence.
Powered by Moodle