Difference between revisions of "OpenModelica/C3/Block-Component-Modeling/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border=1 ||'''Visual Cue''' ||'''Narration''' |- || Slide: '''Title Slide''' || Welcome to the spoken tutorial on '''Block component modeling'''. |- || Slide: Learning...")
 
Line 13: Line 13:
  
 
Learning Objectives
 
Learning Objectives
|| In this tutorial, you are going to learn:
+
|| 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 Standard Library'''.
+
How to use blocks from '''Modelica Library'''.
  
 
|-
 
|-
Line 28: Line 28:
 
|| To record this tutorial, I am using:
 
|| To record this tutorial, I am using:
  
 +
* '''OpenModelica version 1.9.2'''
  
* '''OpenModelica 1.9.2'''
+
You may use any of the following operating systems.
* '''Ubuntu''' Operating System version '''14.04'''
+
* But, this process is identical in '''Windows, Mac OS X''' or '''FOSSEE OS''' on '''ARM'''.
+
  
 
|-
 
|-
Line 39: Line 38:
 
|| To understand and practice this tutorial, you need
 
|| To understand and practice this tutorial, you need
  
 
* Knowledge of class definition in '''Modelica'''.
 
 
* 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 46:
  
 
'''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 in a block class must have fixed causality: either input or output.
+
* 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 60:
  
 
'''block connectors'''
 
'''block connectors'''
|| '''block connectors''' are used to model input and output signals.
+
|| Connectors acts as interface between blocks.
 +
 
 +
They are used to model input and output signals.
  
  
For example, this is a declaration for '''block connector''' that models '''real''' input.
+
For example, this is declaration for a '''block connector''' that models '''real''' input signals.
  
 
|-
 
|-
Line 67: Line 71:
  
 
'''Problem Statement'''
 
'''Problem Statement'''
|| Now, let us try to understand '''block component modeling''' through an example.  
+
|| Let us now 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 write a class that uses blocks to perform the following operations:
  
* Take two time varying signals as input and returning their sum as output.
+
* Take two time varying signals as input and output their sum.
* Take a time varying signal and amplifying it by a constant.
+
* 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.
  
 
|-
 
|-
Line 80: Line 84:
  
 
Sum of signals
 
Sum of signals
|| The figure shows a schematic for block that takes two signals as input and returns their sum.  
+
|| 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 94:
  
 
'''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.  
Line 96: Line 100:
 
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.  
Line 106: Line 110:
  
 
'''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.Blocks''' package.
+
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 126:
 
|| 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 134: Line 138:
 
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''' block corresponds to the Sum of signals and '''Product''' to amplification.
+
Note that '''Sum''' corresponds to the Sum of signals whereas '''Product''' corresponds to the amplification of signal.
  
 
|-
 
|-
Line 144: Line 148:
 
|-
 
|-
 
||  
 
||  
|| 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 154:
 
|-
 
|-
 
|| /* Libraries Browser */
 
|| /* Libraries Browser */
|| I have already opened this package in '''OMEdit'''.  
+
|| 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''' and '''Product''' and a '''main''' class.
+
Note that the package has blocks named '''Sum''', '''Product''' and a '''main''' class.
  
 
|-
 
|-
Line 170: Line 174:
 
Scroll down a bit.  
 
Scroll down a bit.  
  
Double Click on '''MISO Interfaces''' package also has several other blocks which are similar to '''MISO''' in functionality.  
+
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.  
+
|| 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 186:
 
|-
 
|-
 
|| /* arithmeticOperationsUsingBlocks.Sum */
 
|| /* arithmeticOperationsUsingBlocks.Sum */
|| Switch to '''Text View''' if it opens in either '''Icon or Diagram View'''.
+
|| Switch to '''Text View''' if it opens in '''Diagram View'''.
  
 
|-
 
|-
Line 194: Line 200:
 
|-
 
|-
 
||  
 
||  
|| 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 vText View.'''
+
Switch to '''Text View'''.
  
 
|-
 
|-
Line 208: Line 214:
  
 
// extends Modelica.Blocks.Icons.Block; //
 
// extends Modelica.Blocks.Icons.Block; //
|| '''MISO''' inherits '''Block class'''.  
+
|| 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 256:
 
|-
 
|-
 
||  
 
||  
|| 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 264: Line 270:
 
|-
 
|-
 
||  
 
||  
|| Now, let me show you the '''Diagram View''' of '''Sum''' block.  
+
|| Let me switch to '''Product''' block.
  
|-
+
Switch to '''Text View'''.
|| /* 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.
+
  
 
|-
 
|-
Line 280: Line 278:
  
 
// extends …. //
 
// extends …. //
|| This block extends '''MISO''' as well.
+
|| This block inherits '''MISO''' as well.
  
 
|-
 
|-
Line 286: Line 284:
 
|| 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.
  
 
|-
 
|-
Line 300: Line 298:
  
 
Product ..;
 
Product ..;
|| This indicates instantiation of '''Sum''' and '''Product''' blocks.  
+
|| These statements indicate the instantiation of '''Sum''' and '''Product''' blocks.  
  
These instance can also be created using the drag and drop functionality of '''OMEdit'''.
+
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 306:
 
|-
 
|-
 
|| // nin = 2 //
 
|| // nin = 2 //
|| '''nin''' is the parameter for number of input vectors in '''MISO'''.  
+
|| '''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 312:
 
|-
 
|-
 
|| // 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 320:
 
|-
 
|-
 
||  
 
||  
|| 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'''.
  
Click on '''y'''.  
+
Select '''y'''.  
  
This generates a plot that is in accordance with the values provided.
+
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.  
 
Let me switch to slides.
 
  
 
|-
 
|-
Line 347: Line 345:
  
 
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 354:
  
 
About the '''Spoken Tutorial project'''
 
About the '''Spoken Tutorial project'''
|| Watch the video available at the link shown below
+
|| 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 370: Line 374:
  
 
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 402:
  
 
'''Thanks'''
 
'''Thanks'''
|| We thank '''OpenModelica''' development team for their support.
+
|| We thank the development team of '''OpenModelica''' for their support.
  
 
|-
 
|-
 
||  
 
||  
|| I would like to thank you the listener for joining me in this tutorial.
+
|| I would like to thank you for joining me in this tutorial.
 +
 
 +
Good bye.

Revision as of 10:40, 11 April 2016

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:
  • OpenModelica version 1.9.2

You may use any of the following operating systems.

Slide:

Prerequisites

To understand and practice this tutorial, you need
  • Knowledge of component oriented modeling in Modelica.
  • Prerequisite tutorials are mentioned on our website.
  • Please go through them.
Slide:

block

Let us now learn more about blocks.

block is a specialized class in Modelica.

  • 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.
  • variables of a block class must have fixed causality: either input or output.
  • blocks can be connected using connect statements.
  • We have learnt about connect statements in previous tutorials.
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:

  • Take two time varying signals as input and output their sum.
  • Take a time varying signal as input and amplify it by a constant.

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 MO 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.

Contributors and Content Editors

Kaushik Datta