Passer au contenu principal
SciNet
  • Accueil
  • Tous les cours
  • Calendrier
  • Certificats
  • SciNet
    Site principal Documentation my.SciNet
  • CCDB
  • Plus
Fermer
Activer/désactiver la saisie de recherche
Français
English Français
Vous êtes connecté anonymement
Connexion
SciNet
Accueil Tous les cours Calendrier Certificats SciNet Replier Déplier
Site principal Documentation my.SciNet
CCDB
Tout déplier Tout replier
  1. Tableau de bord
  2. PHY1610 - Winter 2022
  3. 1. Modularization

1. Modularization

Conditions d’achèvement
Ouvert le : jeudi 20 janvier 2022, 00:00
À rendre : lundi 31 janvier 2022, 23:59
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 janvier 2022, 23:32
  • wave1d.cpp wave1d.cpp
    20 janvier 2022, 23:32
  • waveparams.txt waveparams.txt
    20 janvier 2022, 23:32
Contacter l’assistance du site
Vous êtes connecté anonymement (Connexion)
Résumé de conservation de données


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.
Fourni par Moodle