Difference between revisions of "OpenModelica/C3/Block-Component-Modeling/English"
(One intermediate revision by the same user not shown) | |||
Line 17: | Line 17: | ||
How to define a '''block'''. | How to define a '''block'''. | ||
− | How to connect | + | How to connect '''blocks'''. |
How to use blocks from '''Modelica Library'''. | How to use blocks from '''Modelica Library'''. | ||
Line 47: | Line 47: | ||
|| Let us now learn more about '''blocks'''. | || Let us now learn more about '''blocks'''. | ||
− | '''block''' is a specialized class in '''Modelica'''. | + | *'''block''' is a specialized class in '''Modelica'''. |
− | + | ||
* It is useful in control applications. | * It is useful in control applications. | ||
* For example, '''Modelica Library''' has blocks for '''PI''' and '''PID''' controllers which are frequently seen in chemical engineering control applications. | * For example, '''Modelica Library''' has blocks for '''PI''' and '''PID''' controllers which are frequently seen in chemical engineering control applications. | ||
Line 62: | Line 61: | ||
They are used to model '''input''' and '''output''' signals. | They are used to model '''input''' and '''output''' signals. | ||
− | |||
For example, this is declaration for a '''block connector''' that models '''real''' input signals. | For example, this is declaration for a '''block connector''' that models '''real''' input signals. | ||
Line 341: | Line 339: | ||
Assignment | Assignment | ||
− | || As an assignment, look into the codes for '''RealInput, RealOutput, SI, SO''' and ''' | + | || As an assignment, look into the codes for '''RealInput, RealOutput, SI, SO''' and '''MIMO''' blocks. |
You can find them in '''Modelica.Blocks.Interfaces''' package. | You can find them in '''Modelica.Blocks.Interfaces''' package. |
Latest revision as of 15:23, 15 January 2018
Visual Cue | Narration |
Slide:
Title Slide |
Welcome to the spoken tutorial on Block component modeling. |
Slide:
Learning Objectives |
In this tutorial, we are going to learn:
How to define a block. How to connect blocks. How to use blocks from Modelica Library. |
Slide:
System Requirements |
To record this tutorial, I am using:
You may use any of the following operating systems. |
Slide:
Prerequisites |
To understand and practice this tutorial, you need
|
Slide:
block |
Let us now learn more about blocks.
|
Slide:
block connectors |
Connectors acts as interface between blocks.
They are used to model input and output signals. For example, this is declaration for a block connector that models real input signals. |
Slide:
Problem Statement |
Let us now try to understand block component modeling through an example.
Let us write a class that uses blocks to perform the following operations:
Let us define this problem statement in detail using schematics. |
Slide:
Sum of signals |
This 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 a 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 i.e. signal 2 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 the Sum of signals and amplification require a block with 2 inputs and 1 output.
Modelica library already has a block named MISO that stands for Multiple Input Single Output. It is available in Modelica.Interfaces.Block 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 block 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 corresponds to the Sum of signals whereas Product corresponds to the amplification of signal. |
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 now switch to OMEdit.
I shall first demonstrate the package arithmeticOperationsUsingBlocks and then demonstrate the syntax of MISO block. | |
/* Libraries Browser */ | I have already opened the package arithmeticOperationsUsingBlocks in OMEdit.
Let me expand it in the Libraries Browser. Note that the package has blocks named Sum, 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. | |
Now 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 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 now take a step back for a moment and demonstrate MISO block.
Go to MISO tab. Switch to Text 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; // |
It 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 now 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. |
Let me switch to Product block.
Switch to Text View. | |
/* Product */
// extends …. // |
This block inherits 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 its elements. |
Let me now switch to main class.
Switch to Text View. | |
/* main */
Sum ..; Product ..; |
These statements indicate the instantiation of Sum and Product blocks.
These instances can also be created using the drag and drop functionality of OMEdit. We discussed this feature in previous tutorials. |
// nin = 2 // | nin is a parameter for dimension of input vector u 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 now simulate this class.
Click on Simulate button. Close the pop up window. | |
/* Variables Browser */ | Expand mySum in Libraries Browser.
Select y. Note that this generates a plot that is in accordance with the values of signal provided. |
This brings us to the end of this tutorial. | |
Slide:
Assignment |
As an assignment, look into the codes for RealInput, RealOutput, SI, SO and MIMO blocks.
You can find them in Modelica.Blocks.Interfaces package. RealInputand RealOutput are connectors which are used quite frequently. Hence it is necessary to understand them. |
Slide:
About the Spoken Tutorial project |
Watch the video available at the following link:
http://spoken-tutorial.org/What\_is\_a\_Spoken\_Tutorial It summarises the Spoken Tutorial project. |
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 spoken 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 the development team of OpenModelica for their support. |
I would like to thank you for joining me in this tutorial.
Good bye. |