Practical Information
- Due Date: 10 November before 23:55.
- Team Size: 2 (pair design/programming)!
Note that as of the 2017-2018 Academic Year, each International student should team up with "local"
(i.e., whose Bachelor degree was obtained at the University of Antwerp).
- Submission Information:
Only one member of each team submits a full solution. This must be a compressed archive (ZIP, RAR, TAR.GZ...) that includes your report and all models, images, code and other sources that you have used to crate your solution. The report must be called index.html. Make sure to mention the names and student IDs of all the team members.
The other team member must submit a single HTML file containing only the coordinates of both team members. This will allow us to put in grades for both team members in BlackBoard.
- Submission Medium:
BlackBoard. Beware that BlackBoard's clock may differ slightly from yours. If BlackBoard is not reachable due to an (unpredicted) maintenance, you submit your solution via e-mail to the TA. Make sure all group members are in CC.
- Contact / TA:
Randy Paredis.
Goals
In this assignment, you will learn how to use Causal-Block Diagrams (CBD) for modeling and simulation. You will take a closer look at numerical analysis and simulation techniques in order to get a better understanding about how tools like OpenModelica and MatLab Simulink work.
Problem Statement
You are given a CBD simulator and tasked to implement a set of missing functionalities, before using it to model more complex systems. The code for this simuator can be found here, as well as at the bottom of this page. Note that this simulator is incomplete. Also, you will have to re-install the simulator every time you have changed something in its source. If something is not clear, or if you have found a bug, please contact the TA.
The documentation can be found in the doc/ folder. It is highly encouraged to read the provided information about the given functions and classes. If you use a function or a class in a way that disregards the "warning", "danger", "attention"... labels, you will not receive any points on the entire task, even if it produces the correct results. Additionally, the documentation provides a set of examples which may help you in completing this assignment. Especially the "Sine Generator" example.
Once the simulator is installed, it works with any IDE, including Jupyter Notebooks. For creating plots, MatPlotLib and SeaBorn are supported. While Bokeh is also available, live plotting (i.e., plotting during the (scaled) real-time simulation) still has some issues.
DrawioConvert, a tool that can help you create and visualize coupled CBDs (and generate code) is available. The tool is experimental, and its use is optional. A small tutorial on how to use the tool is provided. Please contact the TA if you experience any problems.
Tasks
You will need to perform the following tasks step by step:
-
In the CBD.lib.std module, the standard library of CBD building blocks is listed. However, some are missing part of their implementation, as indicated with the "# TO IMPLEMENT" comment. Implement the missing functionalities for the NegatorBlock, the InverterBlock, the AdderBlock, the ProductBlock, the ModuloBlock, the RootBlock, the PowerBlock, the AbsBlock, the GenericBlock, the MaxBlock, the MinBlock and the DelayBlock. Use the implementation of the other blocks and the documentation to help you finishing this task. To verify your code, you can run the tests with following command from the src/ directory (do not worry about the failing tests for the IntegratorBlock and the DerivatorBlock, for now):
python -m unittest discover -v test "*.py"
-
The CBD.solver.LinearSolver class is a class that is able to solve linear systems of equations. Provide a valid implementation for the __isLinear method, as indicated with the "# TO IMPLEMENT" comment.
-
Use the blocks from the standard library to implement the DerivatorBlock and the IntegratorBlock (using the backwards Euler rule) as a coupled CBD model. Check their validity by running the tests.
Prove the correctness of the used formulas by generating the $\LaTeX$ representation for the model. Generate the $\LaTeX$ representation of your model, with all intermediary steps and describe what goes wrong in the generation (according to you). Take a look at CBD.converters > "Generate LaTeX from CBD Models" in the documentation for more details. Describe all steps in this generation, using your own words.
-
Create a coupled CBD model that outputs $i!$ (i.e., the factorial of $i$) at time $i$. Use this model to plot the first $10$ values: $\{0!, 1!, ..., 9!\}$.
Prove the model's validity by generating the $\LaTeX$ representation for the model. Generate the $\LaTeX$ representation of your model, with all intermediary steps and describe what goes wrong in the generation (according to you).
-
Implement variations of the IntegratorBlock using the forwards Euler rule, trapezoid rule and Simpson's 1/3 rule in a different file. For the latter, the trapezoid rule should be used if you have but two data points. Copy the test for the IntegratorBlock into an experiment file and use that to prove the correctness of your implementation.
Use the $\LaTeX$ representation for the model to prove the validity of the used formulas. Generate the $\LaTeX$ representation of your model, with all intermediary steps and describe what goes wrong in the generation (according to you).
-
Recreate the PRT system from previous assignment as a CBD model. You can ignore the passenger behaviour. In short:
-
Create a Look-Up CBD model w.r.t. the table given in the previous assignment. You are free to choose whether this is a coupled model or not.
-
Implement a PID-controller as a coupled CBD model. Use the ($K_p$, $K_i$, $K_d$)-values that gave you the best solution in the previous assignment. Prove the model's validity by generating the $\LaTeX$ representation for the model.
-
Implement the following ODE as a coupled CBD model:
$$\begin{cases}
\dfrac{dv_{trolley}}{dt} &=& \dfrac{F_{traction} - \dfrac{1}{2}\cdot p\cdot v_{trolley}^2\cdot C_D\cdot A}{m_{trolley} + m_{psgr}}\\
\dfrac{dx_{trolley}}{dt} &=& v_{trolley}
\end{cases}$$
Prove the model's validity by generating the $\LaTeX$ representation for the model. Describe all steps in this generation, using your own words. You do not need to generate the $\LaTeX$ representation for this task anymore.
-
Combine the model and compare the results to those you obtained from the previous assignment. What happens if you alter the $\delta t$ (see also the "Sine Generator" example in the CBD simulator's documentation)? Can you use other integration methods? Why (not)?
-
Up to this point, you have simulated using a fixed stepsize. If a signal is slowly changing over time, it is best to use a large $\delta t$. But, if that signal suddenly contains a lot of variation, a small $\delta t$ is preferred. Using this small $\delta t$ for the full time-interval is computationally expensive, thus an adaptive stepsize is introduced. Without going too much into detail, the CBD simulator is built to allow adaptive stepsize simulation using the Runge-Kutta method. Take a look at the "Continuous Time Simulation" example and
simulate the PRT system using the Runge-Kutta-Fehlberg method for 4th and 5th order (RKF45), as shown in the example (also use the same atol, hmin and safety). Create a plot that shows the trolley's velocity and highlights the computation points, both for fixed stepsize (as is shown in the example as well), as for RKF45. describe how your plot should look like if it were simulated using adaptive stepsize.
Can Would you see a difference compared to fixed stepsize? Why (not)?
-
Write a report that explains your solution for this assigment. Include and discuss your plots and models. Also clearly indicate which models and experiments can be found in which files. Include graphical representations for all your coupled CBD models. If you did not use DrawioConvert, you can take a look at CBD.converters > "Generate GraphViz from CBD Models". Make sure to mention all your hypotheses, assumptions and conclusions. See also the "submission information" at the top of this page.
Take pride in your work. Make sure your report and all models and images are clearly readable. Additionally, produce clean and (preferrably) well documented code. If a plot or figure is difficult to read, also include the corresponding source files (*.py, *.drawio, *.xml...). You will not lose points for doing too much, but you will lose points if you do too little.
Practical Issues
- All parts of this assignment use Python 3.6+. Do not use features from Python 3.10 (current alpha version), nor from Python 2.7 (discontinued as of January 1, 2020).
- $\LaTeX$ rendering in HTML can be done via MathJax. Alternatively, it is allowed to refer to *.tex and/or *.pdf files in your report.
- The CBD simulator can be found here.
- The files for DrawioConvert can be found here:
- Useful links:
|