CBD Assignment
|
Practical Information
GoalsIn this assignment, you will learn how to use Causal-Block Diagrams (CBD) for modeling and simulation. You will take a closer look at specific simulation techniques (mainly numerical analysis, accuracy and stability) in order to get a better understanding about how tools like OpenModelica and MatLab Simulink work behind the scenes. Problem Statement
This assignment is to be made using this Python-based CBD framework.
The ZIP-file contains a full framework to allow CBD modelling in Python. To build the documentation, use the ATTENTION!Python does not enforce the usage of the CBD framework! Instead, it is perfectly possible to bypass its functionality and still yield a valid result. These results will not be seen as a valid CBD modelling and therefore not grant you any points for that part of the solution.
Once the simulator is installed, it works with any IDE, including Jupyter Notebooks. For creating plots, Bokeh, MatPlotLib and SeaBorn are supported. DrawioConvert is an additional tool that allows the creation, visualization and code generation of coupled CBDs. The tool may still have small bugs, and its use is optional, however incredibly useful. It uses DrawIO as a front-end. A small tutorial on how to use the tool is provided. Please contact the TA if you experience any problems.
Assignment Overview
This assignment consists of three main parts:
Harmonic OscillatorA simple harmonic oscillator with no friction exhibits behaviour that can be modelled by the following second-order ODE: $$\dfrac{d^2(x)}{dt^2} = -x$$ where $x(0) = 0$ and $\dfrac{d(x)}{dt}(0) = 1$. This system can be modeled in CBDs using IntegratorBlocks and/or DerivatorBlocks. The real (analytical) solution of this system equals $\sin(t)$. Tasks
Your job is to find the best approach to model the above harmonic oscillator. This is done as described below. Make sure to include all your source code
and everything you believe required for your solution.
Integration MethodsComputing the integral of a function is a common practice in simulation systems. It can be used for specifying time-dependent simulations, constructing (PID) controllers and even identifying accumulative errors. Any complex Cyber-Physical process that happens over a certain period of time makes use of integrators, however their computation is always a numerical approximation. This task will take a look at multiple integration methods and their accuracy. Table 1 shows the four integration methods we will concern ourselves with for this assignment (note: there exist many, many more).
TasksYour job is to compare the given integration methods.
Inline Integration (and Cosimulation)
Note: This task assumes you know the C programming language. A simple tutorial can be found on the
W3 Schools Website. Even though you have a CBD simulator, its execution in Python is slow and does a lot of things behind the scenes (feel free to take a look at the source code). Sometimes, models need to be executed on hardware that may not have the computational power (and storage requirements) to run the model you have built. Remember how Modelica solved this problem: it first flattens all models, next it converts it into executable C-code and finally, it compiles and executes the model. The executable C-code is created by doing a topological sort for all blocks and iteratively turning each block into their corresponding equation(s). This also takes the internal connections into account. This method is called "Inline Integration" This paper (see especially table 2) somewhat explains the process for inline integration of CBDs (mainly focusing on LaTeX generation). Notice that the dependency graph at iteration 0 will differ from the graph at all other times, so the inline integration needs to happen twice. For the purposes of this assignment, we will ignore how algebraic loops can/should be solved. Another reason for doing this is that we might want to combine multiple formalisms together. For instance, when you have a causal controller in CBDs and an acausal plant in Modelica. Combining these purely on a code level is an easy way to allow multi-formalisms. However, sometimes there may be algebraic loops between multiple formalisms, causing complicated code and a lot of headaches. Luckily, there is another way of doing this: cosimulation, in which an orchestrator manages interaction between multiple formalisms. The industrial standard for cosimulation is the Functional Mock-up Interface (FMI). A single instance is called a Functional Mock-up Unit (FMU). For this assignment, we will use FMI standard 2.0. For this task, you will use inline integration to create your own FMU that will be used in cosimulation. Because understanding FMIs is way too out of scope for this course, we have provided you with a template FMU that you can fill with your own code. In short, an FMU is a zipped package of a specifically structured set of files. The template file can thus be uncompressed and you can browse the internal files. For your convenience, the only files you need to edit are:
|
Maintained by Hans Vangheluwe. | Last Modified: 2024/09/27 13:38:18. |