Difference between revisions of "OpenModelica/C3/Block-Component-Modeling/English"
(Created page with "{| border=1 ||'''Visual Cue''' ||'''Narration''' |- || Slide: '''Title Slide''' || Welcome to the spoken tutorial on '''Block component modeling'''. |- || Slide: Learning...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
|| Slide: | || Slide: | ||
− | Learning Objectives | + | '''Learning Objectives''' |
− | || In this tutorial, | + | || In this tutorial, we are going to learn: |
− | + | ||
How to define a '''block'''. | How to define a '''block'''. | ||
− | How to connect blocks. | + | How to connect '''blocks'''. |
− | How to use blocks from '''Modelica | + | How to use blocks from '''Modelica Library'''. |
|- | |- | ||
|| Slide: | || Slide: | ||
− | System Requirements | + | '''System Requirements''' |
|| To record this tutorial, I am using: | || To record this tutorial, I am using: | ||
+ | * '''OpenModelica version 1.9.2''' | ||
− | + | You may use any of the following operating systems. | |
− | + | ||
− | + | ||
|- | |- | ||
|| Slide: | || Slide: | ||
− | Prerequisites | + | '''Prerequisites''' |
|| To understand and practice this tutorial, you need | || To understand and practice this tutorial, you need | ||
− | |||
− | |||
* Knowledge of '''component oriented modeling''' in '''Modelica'''. | * Knowledge of '''component oriented modeling''' in '''Modelica'''. | ||
− | * Prerequisite tutorials are mentioned on our website | + | * Prerequisite tutorials are mentioned on our website. |
+ | * Please go through them. | ||
|- | |- | ||
Line 48: | Line 45: | ||
'''block''' | '''block''' | ||
− | || '''block''' is a specialized class in '''Modelica'''. | + | || Let us now learn more about '''blocks'''. |
+ | |||
+ | *'''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 applications. | + | * For example, '''Modelica Library''' has blocks for '''PI''' and '''PID''' controllers which are frequently seen in chemical engineering control applications. |
− | * variables | + | * variables of a block class must have fixed causality: either '''input''' or '''output'''. |
* '''blocks''' can be connected using '''connect''' statements. | * '''blocks''' can be connected using '''connect''' statements. | ||
+ | * We have learnt about '''connect''' statements in previous tutorials. | ||
|- | |- | ||
Line 58: | Line 58: | ||
'''block connectors''' | '''block connectors''' | ||
− | || ''' | + | || '''Connectors''' acts as interface between '''blocks'''. |
+ | They are used to model '''input''' and '''output''' signals. | ||
− | For example, this is | + | For example, this is declaration for a '''block connector''' that models '''real''' input signals. |
|- | |- | ||
Line 67: | Line 68: | ||
'''Problem Statement''' | '''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 | + | Let us write a class that uses blocks to perform the following operations: |
− | * Take two time varying signals as input and | + | * Take two time varying signals as '''input''' and '''output''' their sum. |
− | * Take a time varying signal and | + | * Take a time varying signal as input and amplify it by a constant. |
− | Let us define this problem in detail using schematics. | + | Let us define this problem statement in detail using schematics. |
|- | |- | ||
|| Slide: | || Slide: | ||
− | Sum of signals | + | '''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. | To make things simpler, let us choose signal '''1''' to be '''t''' which represents time. | ||
Line 90: | Line 91: | ||
'''Amplification of signal''' | '''Amplification of signal''' | ||
− | || This is schematic for amplification of signal. | + | || This is schematic for amplification of a '''signal'''. |
− | It is similar to the previous case with two inputs and one output. | + | It is similar to the previous case with two '''inputs''' and one '''output'''. |
− | Let us choose one input to be our signal. | + | Let us choose one '''input''' to be our '''signal'''. |
− | Let the other input be a constant '''K''' by which to amplify the 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. | + | The product of these two '''inputs''' is the '''output''' required. |
− | We have chosen the | + | We have chosen the '''signal 2''' i.e. '''K''' to be '''5''' units. |
|- | |- | ||
Line 106: | Line 107: | ||
'''MISO''' | '''MISO''' | ||
− | || Notice that both Sum of signals and amplification require a block with '''2''' inputs and '''1''' output. | + | || Notice that both the 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'''. | + | '''Modelica library''' already has a block named '''MISO''' that stands for '''Multiple Input Single Output'''. |
− | It is available in '''Modelica.Interfaces. | + | 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. | The input to this block '''u''' is a vector since it can accept multiple signals as input. | ||
Line 122: | Line 123: | ||
|| Let us now discuss how to solve our problem using '''OMEdit'''. | || Let us now discuss how to solve our problem using '''OMEdit'''. | ||
− | Extend '''MISO''' to create a block named '''Sum'''. | + | Extend '''MISO''' block to create a block named '''Sum'''. |
We have learnt about extending a class in previous tutorials. | We have learnt about extending a class in previous tutorials. | ||
Line 132: | Line 133: | ||
Create instances of '''Sum''' and '''Product''' blocks in the '''main''' class. | Create instances of '''Sum''' and '''Product''' blocks in the '''main''' class. | ||
− | Lastly, program the necessary equations related to input and output variables. | + | Lastly, program the necessary equations related to '''input''' and '''output''' variables. |
− | Note that '''Sum''' | + | 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'''. | + | || 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. | You may locate this file on our website and download it. | ||
Line 144: | Line 145: | ||
|- | |- | ||
|| | || | ||
− | || Let me switch to '''OMEdit'''. | + | || Let me now switch to '''OMEdit'''. |
I shall first demonstrate the package '''arithmeticOperationsUsingBlocks''' and then demonstrate the syntax of '''MISO''' block. | I shall first demonstrate the package '''arithmeticOperationsUsingBlocks''' and then demonstrate the syntax of '''MISO''' block. | ||
Line 150: | Line 151: | ||
|- | |- | ||
|| /* Libraries Browser */ | || /* Libraries Browser */ | ||
− | || I have already opened | + | || I have already opened the package '''arithmeticOperationsUsingBlocks''' in '''OMEdit'''. |
Let me expand it in the '''Libraries Browser'''. | Let me expand it in the '''Libraries Browser'''. | ||
− | Note that the package has blocks named '''Sum''' | + | Note that the package has blocks named '''Sum''', '''Product''' and a '''main''' class. |
|- | |- | ||
Line 170: | Line 171: | ||
Scroll down a bit. | Scroll down a bit. | ||
− | Double Click on '''MISO | + | 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. | Let us first look into '''Sum''' block. | ||
Line 180: | Line 183: | ||
|- | |- | ||
|| /* arithmeticOperationsUsingBlocks.Sum */ | || /* arithmeticOperationsUsingBlocks.Sum */ | ||
− | || Switch to '''Text View''' if it opens in | + | || Switch to '''Text View''' if it opens in '''Diagram View'''. |
|- | |- | ||
Line 194: | Line 197: | ||
|- | |- | ||
|| | || | ||
− | || Let me take a step back for a moment and demonstrate '''MISO block'''. | + | || Let me now take a step back for a moment and demonstrate '''MISO block'''. |
Go to '''MISO tab'''. | Go to '''MISO tab'''. | ||
− | Switch to | + | Switch to '''Text View'''. |
|- | |- | ||
Line 208: | Line 211: | ||
// extends Modelica.Blocks.Icons.Block; // | // extends Modelica.Blocks.Icons.Block; // | ||
− | || | + | || It inherits '''Block class'''. |
You may locate this in '''Modelica library''' using the path shown. | You may locate this in '''Modelica library''' using the path shown. | ||
Line 250: | Line 253: | ||
|- | |- | ||
|| | || | ||
− | || Let us go back to '''Sum''' block and continue from where we left off. | + | || Let us now go back to '''Sum''' block and continue from where we left off. |
|- | |- | ||
Line 256: | Line 259: | ||
// y = Sum(u) // | // y = Sum(u) // | ||
− | || Variables '''y''' and '''u''' are a part of this block since it inherits MISO. | + | || 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. | As we have learnt in previous tutorials, '''Sum''' is an '''array''' function. | ||
Line 264: | Line 267: | ||
|- | |- | ||
|| | || | ||
− | || | + | || Let me switch to '''Product''' block. |
− | + | Switch to '''Text View'''. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 280: | Line 275: | ||
// extends …. // | // extends …. // | ||
− | || This block | + | || This block inherits '''MISO''' as well. |
|- | |- | ||
|| y = Product(u) | || y = Product(u) | ||
− | || As we have seen in previous tutorials, '''Product''' is an array function that takes an array as input. | + | || As we have seen in previous tutorials, '''Product''' is an array function that takes an array as '''input'''. |
− | It returns the product of elements. | + | It returns the product of its elements. |
|- | |- | ||
|| | || | ||
− | || Let me now switch to main class. | + | || Let me now switch to '''main''' class. |
Switch to '''Text View'''. | Switch to '''Text View'''. | ||
Line 300: | Line 295: | ||
Product ..; | Product ..; | ||
− | || | + | || These statements indicate the instantiation of '''Sum''' and '''Product''' blocks. |
− | These | + | These instances can also be created using the drag and drop functionality of '''OMEdit'''. |
We discussed this feature in previous tutorials. | We discussed this feature in previous tutorials. | ||
Line 308: | Line 303: | ||
|- | |- | ||
|| // nin = 2 // | || // nin = 2 // | ||
− | || '''nin''' is | + | || '''nin''' is a parameter for dimension of '''input''' vector '''u''' in '''MISO'''. |
We assign a value of '''2''' to this parameter. | We assign a value of '''2''' to this parameter. | ||
Line 314: | Line 309: | ||
|- | |- | ||
|| // mySum.u = {time, 2*time} // | || // 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 | + | || This equation indicates the values of '''signal 1''' and '''signal 2''' for '''Sum''' of signals which we discussed in slides. |
|- | |- | ||
Line 322: | Line 317: | ||
|- | |- | ||
|| | || | ||
− | || Let me simulate this class. | + | || Let me now simulate this class. |
− | Click on '''Simulate'''. | + | Click on '''Simulate''' button. |
+ | |||
+ | Close the pop up window. | ||
|- | |- | ||
|| /* Variables Browser */ | || /* Variables Browser */ | ||
− | || Expand '''mySum'''. | + | || 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. | || This brings us to the end of this tutorial. | ||
− | |||
− | |||
|- | |- | ||
Line 344: | 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. | ||
+ | |||
+ | '''RealInput'''and '''RealOutput''' are connectors which are used quite frequently. | ||
+ | |||
+ | Hence it is necessary to understand them. | ||
|- | |- | ||
Line 352: | Line 351: | ||
About the '''Spoken Tutorial project''' | About the '''Spoken Tutorial project''' | ||
− | || Watch the video available at the link | + | || Watch the video available at the following link: |
http://spoken-tutorial.org/What\_is\_a\_Spoken\_Tutorial | http://spoken-tutorial.org/What\_is\_a\_Spoken\_Tutorial | ||
+ | |||
+ | It summarises the '''Spoken Tutorial''' project. | ||
|- | |- | ||
Line 369: | Line 370: | ||
|| Slide: | || Slide: | ||
− | Forum to answer questions | + | '''Forum to answer questions''' |
− | || If you have questions in this tutorial, please visit the webpage mentioned. | + | || If you have questions in this spoken tutorial, please visit the webpage mentioned. |
|- | |- | ||
Line 398: | Line 399: | ||
'''Thanks''' | '''Thanks''' | ||
− | || We thank '''OpenModelica''' | + | || We thank the development team of '''OpenModelica''' for their support. |
|- | |- | ||
|| | || | ||
− | || I would like to thank you | + | || I would like to thank you for joining me in this tutorial. |
+ | |||
+ | Good bye. |
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. |