A. Implement the missing functions (marked with # TO IMPLEMENT) of the simulator
(CBD.py) to realize the
following:
- The construction of the dependency graph;
- Given an algebraic loop, detection of whether it is linear;
- For each of the blocks, write the computation they
need to perform. In this assignment, you only need to
implement the algebraic blocks and the delay block (not Integrator
and Derivative blocks).
Take note that the simulation kernel supports hierarchy. We expect that the hierarchy works.
B. Use the supplied unit tests to test your implementation. Finally, create different CBD models to further test your implementation with and without hierarchy. Plot the results for your report:
- A non-trivial algebraic model without loop to test sorting;
- An algebraic model with a non-linear loop;
- An algebraic model with a linear loop ;
- An algebraic model with at least two linear loops, and computation in between;
In total you will have 8 test models (one without and one with hierarchy each)!
To plot your results you can use the matplotlib python library:
http://matplotlib.org/1.4.0/faq/installing_faq.html.
Here you can find an example how to plot you results together in a single window. Alternatively, you can dump the results of your simulation and copy-paste them into a spreadsheet program.
C. Model Compilation:
- Create a model compiler for CBD models. The compiler takes a CBD model as input and outputs a C-program that calculates the signal values. Here is an example C-file of a very simple CBD model with four blocks. The code can be used as a template to create your own code with the compiler.
- Use the models created in part B. of the assignment to test your model compiler. Because linear algebraic loops need to be solved, you can immediately integrate a solver into your code: http://rosettacode.org/wiki/Gaussian_elimination#C.
Compilation of the code can be done with the GCC compiler: gcc test.c -o test
Execute: ./test
D. Proper documentation, both of your code, and of your report.
In particular, provide a visual representation of your models, as well as of your output signals (as plots).