OpenModelica/C3/Block-Component-Modeling/English
Visual Cue | Narration |
Slide:
Title Slide |
Welcome to the spoken tutorial on Block component modeling. |
Slide:
Learning Objectives |
In this tutorial, you are going to learn:
How to connect blocks. How to use blocks from Modelica Standard Library. |
Slide:
System Requirements |
To record this tutorial, I am using:
|
Slide:
Prerequisites |
To understand and practice this tutorial, you need
|
Slide:
block |
block is a specialized class in Modelica.
|
Slide:
block connectors |
block connectors are used to model input and output signals.
|
Slide:
Problem Statement |
Now, let us try to understand block component modeling through an example.
Let us write a class that uses blocks to perform the following two operations:
Let us define this problem in detail using schematics. |
Slide:
Sum of signals |
The figure shows a schematic for block that takes two signals as input and returns their sum.
To make things simpler, let us choose signal 1 to be t which represents time. Let signal 2 be 2 (times) t (squared) |
Slide:
Amplification of signal |
This is schematic for amplification of signal.
It is similar to the previous case with two inputs and one output. Let us choose one input to be our signal. Let the other input be a constant K by which to amplify the signal. The product of these two inputs is the output required. We have chosen the signal 2 i.e. K to be 5 units. |
Slide:
MISO |
Notice that both Sum of signals and amplification require a block with 2 inputs and 1 output.
Modelica library has a block named MISO that stands for Multiple Input Single Output. It is available in Modelica.Interfaces.Blocks package. The input to this block u is a vector since it can accept multiple signals as input. y is the output which is a scalar. |
Slide:
Solution Methodology |
Let us now discuss how to solve our problem using OMEdit.
Extend MISO to create a block named Sum. We have learnt about extending a class in previous tutorials. Extend MISO to create a block named Product. Create a class named main. Create instances of Sum and Product blocks in the main class. Lastly, program the necessary equations related to input and output variables. Note that Sum block corresponds to the Sum of signals and Product to amplification. |
I have already created the necessary blocks and packaged them into a file named arithmeticOperationsUsingBlocks.
You may locate this file on our website and download it. | |
Let me switch to OMEdit.
I shall first demonstrate the package arithmeticOperationsUsingBlocks and then demonstrate the syntax of MISO block. | |
/* Libraries Browser */ | I have already opened this package in OMEdit.
Let me expand it in the Libraries Browser. Note that the package has blocks named Sum and Product and a main class. |
Double-click on all three of them.
Let me also open MISO block from Modelica Library. | |
Expand Modelica library.
Go to Blocks → Interfaces. Scroll down a bit. Double Click on MISO Interfaces package also has several other blocks which are similar to MISO in functionality. | |
Let me shift OMEdit window to the left for better visibility.
Let us first look into Sum block. | |
/* arithmeticOperationsUsingBlocks.Sum */ | Switch to Text View if it opens in either Icon or Diagram View. |
/* block Sum */ | This is the syntax for declaring a block. |
/* extends Modelica…. */ | This statement is used to inherit MISO block from its location in Modelica library.
We have learnt about Class inheritance or Class extension in previous tutorials. |
Let me take a step back for a moment and demonstrate MISO block.
Go to MISO tab. Switch to vText View. | |
partial block MISO; | MISO is a partial block which means that it can only be inherited but not instantiated. |
/* MISO */
// extends Modelica.Blocks.Icons.Block; // |
MISO inherits Block class.
You may locate this in Modelica library using the path shown. This class is used here only for the sake of its Diagram View and hence need not be discussed. |
/* MISO */
// parameter Integer nin=1 "Number of inputs"; // |
nin represents the number of inputs.
This parameter may be changed when the block is inherited. |
/* MISO */
RealInput u[nin]; |
RealInput is a connector which evidently represents a real input signal.
In this case, the input is a vector u as we already discussed. |
/* MISO */
RealOutput y; |
Similarly, RealOutput is a connector which represents a real output signal.
Here, y is the real-valued output signal. |
RealInput and RealOutput are present in the same package of Modelica Library as MISO.
Please look into them. | |
/* MISO Diagram View */ | Now, let me show you how the Diagram View of MISO block looks like. |
Let us go back to Sum block and continue from where we left off. | |
/* Sum */
// y = Sum(u) // |
Variables y and u are a part of this block since it inherits MISO.
As we have learnt in previous tutorials, Sum is an array function. It takes an array as input and returns the sum of its elements. |
Now, let me show you the Diagram View of Sum block. | |
/* Diagram View of Sum */ | This Diagram looks like that of MISO.
This is because Sum is an inherited class of MISO. |
Let me now switch to Product block. | |
/* Product */
// extends …. // |
This block extends MISO as well. |
y = Product(u) | As we have seen in previous tutorials, Product is an array function that takes an array as input.
It returns the product of elements. |
Let me now switch to main class.
Switch to Text View. | |
/* main */
Sum ..; Product ..; |
This indicates instantiation of Sum and Product blocks.
These instance can also be created using the drag and drop functionality of OMEdit. We discussed this feature in previous tutorials. |
// nin = 2 // | nin is the parameter for number of input vectors in MISO.
We assign a value of 2 to this parameter. |
// mySum.u = {time, 2*time} // | This equation indicates the values of signal 1 and signal 2 for Sum of signals which we discussed in slides |
// myProduct.u = {..} // | Similarly, this indicates the values of Signal 1 and Signal 2 for amplification of signal as we already discussed. |
Let me simulate this class.
Click on Simulate. | |
/* Variables Browser */ | Expand mySum.
Click on y. This generates a plot that is in accordance with the values provided. |
This brings us to the end of this tutorial.
Let me switch to slides. | |
Slide:
Assignment |
As an assignment, look into the codes for RealInput, RealOutput, SI, SO and MO blocks.
You can find them in Modelica.Blocks.Interfaces package. |
Slide:
About the Spoken Tutorial project |
Watch the video available at the link shown below |
Slide:
Spoken Tutorial Workshops |
We conducts workshops using spoken tutorials.
Give certificates. Please contact us. |
Slide:
Forum to answer questions |
If you have questions in this tutorial, please visit the webpage mentioned. |
Slide:
Textbook Companion Project |
We coordinate coding of solved examples from popular books.
We give honorarium to contributors. Please visit our website. |
Slide:
Lab Migration Project |
We help migrate labs from commercial simulators to OpenModelica. |
Slide:
Acknowledgements |
Spoken Tutorial Project is supported by NMEICT, MHRD, Government of India. |
Slide:
Thanks |
We thank OpenModelica development team for their support. |
I would like to thank you the listener for joining me in this tutorial. |