Difference between revisions of "OpenModelica/C3/Modelica-Packages/English-timed"
From Script | Spoken-Tutorial
Jyotisolanki (Talk | contribs) (Created page with "{| border=1 ||''' Time ''' ||'''Narration''' |- || 00:01 || Welcome to the Spoken Tutorial on '''Packages'''. |- ||00:05 || In this tutorial, we are going to learn: How to...") |
Sandhya.np14 (Talk | contribs) |
||
Line 5: | Line 5: | ||
|- | |- | ||
|| 00:01 | || 00:01 | ||
− | || Welcome to the Spoken Tutorial on '''Packages'''. | + | || Welcome to the '''Spoken Tutorial''' on '''Packages'''. |
|- | |- | ||
||00:05 | ||00:05 | ||
− | || In this tutorial, we are going to learn: | + | || In this tutorial, we are going to learn: |
+ | how to create a '''package''' of '''classes''' in '''Modelica''', | ||
|- | |- | ||
||00:12 | ||00:12 | ||
− | || | + | ||how to reference '''classes''' in a '''package''', |
|- | |- | ||
||00:16 | ||00:16 | ||
− | || | + | ||how to '''import''' a '''package''' and |
+ | how to use '''Modelica Library'''. | ||
|- | |- | ||
|| 00:22 | || 00:22 | ||
− | || To record this tutorial, I am using : '''OpenModelica 1.9.2''' and '''Ubuntu''' | + | || To record this tutorial, I am using : '''OpenModelica 1.9.2''' and '''Ubuntu Operating System''' version '''14.04''' and '''gedit'''. |
|- | |- | ||
||00:35 | ||00:35 | ||
− | ||'''Windows''' users may use '''Notepad''' or any other text editor instead of '''gedit'''. | + | ||'''Windows''' users may use '''Notepad''' or any other text-editor instead of '''gedit'''. |
|- | |- | ||
Line 45: | Line 47: | ||
|- | |- | ||
||01:04 | ||01:04 | ||
− | ||It can be stored as a | + | ||It can be stored as a single file or a '''directory'''. |
|- | |- | ||
Line 53: | Line 55: | ||
|- | |- | ||
|| 01:12 | || 01:12 | ||
− | || In '''single file storage''' all '''classes''' belonging to a '''package''' are written in a | + | || In '''single file storage''', all '''classes''' belonging to a '''package''' are written in a single file. |
|- | |- | ||
Line 61: | Line 63: | ||
|- | |- | ||
|| 01:24 | || 01:24 | ||
− | || Now let me switch to '''OMEdit''' to demonstrate '''single file storage''' for a '''package'''. | + | || Now, let me switch to '''OMEdit''' to demonstrate '''single file storage''' for a '''package'''. |
|- | |- | ||
|| 01:31 | || 01:31 | ||
− | || Please download and save all the files available on our website. | + | || Please download and '''save''' all the files available on our website. |
|- | |- | ||
Line 81: | Line 83: | ||
|- | |- | ||
||01:51 | ||01:51 | ||
− | ||''' | + | ||Press '''Ctrl + O'''. |
|- | |- | ||
||01:54 | ||01:54 | ||
− | ||Go to the appropriate location on your system and select '''spokenTutorialExamples.mo''', | + | ||Go to the appropriate location on your system and select '''spokenTutorialExamples.mo''', |
− | + | ||
|- | |- | ||
||02:02 | ||02:02 | ||
Line 113: | Line 114: | ||
|- | |- | ||
|| 02:32 | || 02:32 | ||
− | || Double click on '''spokenTutorialExamples''' icon. | + | || Double-click on '''spokenTutorialExamples''' icon. |
|- | |- | ||
Line 121: | Line 122: | ||
|- | |- | ||
|| 02:42 | || 02:42 | ||
− | || Now let me discuss '''spokenTutorialExamples''' | + | || Now, let me discuss '''spokenTutorialExamples'''. |
|- | |- | ||
Line 133: | Line 134: | ||
|- | |- | ||
||02:56 | ||02:56 | ||
− | || This package consists of '''freefall class''' | + | || This package consists of '''freefall class''', '''bouncingBall''' model and '''bouncingBallWithUserTypes''' models. |
|- | |- | ||
|| 03:08 | || 03:08 | ||
− | || '''end | + | || '''end''' statement defines where the package ends. |
|- | |- | ||
Line 149: | Line 150: | ||
|- | |- | ||
|| 03:24 | || 03:24 | ||
− | || Click on the (+) button besides '''spokenTutorialExamples''' icon in '''Libraries Browser'''. | + | || Click on the plus (+) button besides '''spokenTutorialExamples''' icon, in '''Libraries Browser'''. |
|- | |- | ||
Line 181: | Line 182: | ||
|- | |- | ||
|| 04:06 | || 04:06 | ||
− | || Now let me unload '''spokenTutorialExamples''' from OMEdit. | + | || Now let me '''unload''' '''spokenTutorialExamples''' from OMEdit. |
|- | |- | ||
Line 197: | Line 198: | ||
|- | |- | ||
|| 04:27 | || 04:27 | ||
− | || In '''Directory storage | + | || In '''Directory storage''', classes are stored in separate files. |
|- | |- | ||
Line 205: | Line 206: | ||
|- | |- | ||
|| 04:37 | || 04:37 | ||
− | ||A file named '''package.mo''' is to be included in the directory and | + | ||A file named '''package.mo''' is to be included in the directory and each '''class''' starts with a '''within''' statement. |
|- | |- | ||
Line 229: | Line 230: | ||
|- | |- | ||
|| 05:17 | || 05:17 | ||
− | ||Notice that the folder has following files: | + | ||Notice that the folder has following files: '''package.mo''', '''freeFall.mo''', '''bouncingBallWithUserTypes''' and '''bouncingBall'''. |
|- | |- | ||
Line 277: | Line 278: | ||
|- | |- | ||
|| 06:36 | || 06:36 | ||
− | || The difference between single file and directory storage can only be understood when we open this '''package''' using a text editor like '''gedit'''. | + | || The difference between single file and '''directory storage''' can only be understood when we open this '''package''' using a text editor like '''gedit'''. |
|- | |- | ||
Line 285: | Line 286: | ||
|- | |- | ||
|| 06:53 | || 06:53 | ||
− | || Now let me unload '''spokenTutorialExamples''' package from 'OMEdit'''. | + | || Now, let me unload '''spokenTutorialExamples''' package from 'OMEdit'''. |
|- | |- | ||
Line 301: | Line 302: | ||
|- | |- | ||
|| 07:17 | || 07:17 | ||
− | || '''within | + | || '''within''' statement indicates that this file represents a '''package'''. |
|- | |- | ||
Line 313: | Line 314: | ||
|- | |- | ||
||07:31 | ||07:31 | ||
− | || '''package.mo''' file can only contain the '''within | + | || '''package.mo''' file can only contain the '''within''' statement and '''package''' declaration. |
|- | |- | ||
Line 321: | Line 322: | ||
|- | |- | ||
|| 07:41 | || 07:41 | ||
− | || This '''within | + | || This '''within''' statement indicates that '''freefall''' class belongs to '''spokenTutorialExamples''' package. |
|- | |- | ||
|| 07:49 | || 07:49 | ||
− | ||Rest of this file has information specific to '''freeFall | + | ||Rest of this file has information specific to '''freeFall''' class. |
|- | |- | ||
Line 333: | Line 334: | ||
|- | |- | ||
|| 08:04 | || 08:04 | ||
− | ||But, we didn’t observe '''within | + | ||But, we didn’t observe '''within''' statement when we opened the package in '''OMEdit'''. |
|- | |- | ||
|| 08:11 | || 08:11 | ||
− | ||This indicates that '''within | + | ||This indicates that '''within''' statement helps '''OMEdit''' recognize the file structure. |
|- | |- | ||
Line 357: | Line 358: | ||
|- | |- | ||
|| 08:33 | || 08:33 | ||
− | ||'''OMEdit''' automatically | + | ||'''OMEdit''' automatically '''load'''s it for every session. |
|- | |- | ||
Line 369: | Line 370: | ||
|- | |- | ||
|| 08:46 | || 08:46 | ||
− | ||'''Classes''' of this library can be referenced and used. | + | ||'''Classes''' of this '''library''' can be referenced and used. |
|- | |- | ||
|| 08:51 | || 08:51 | ||
− | || Now let me switch to '''OMEdit''' to demonstrate '''Modelica Library'''. | + | || Now, let me switch to '''OMEdit''' to demonstrate '''Modelica Library'''. |
|- | |- | ||
Line 385: | Line 386: | ||
|- | |- | ||
|| 09:10 | || 09:10 | ||
− | ||You may note that a package may further contain packages as well as is evident here. Of special mention | + | ||You may note that a package may further contain packages as well as is evident here. Of special mention is the '''SIunits''' package. |
|- | |- | ||
Line 397: | Line 398: | ||
|- | |- | ||
|| 09:32 | || 09:32 | ||
− | ||We shall see how to use these type definitions using '''bouncingBallWithImport class'''. | + | ||We shall see how to use these '''type''' definitions using '''bouncingBallWithImport class'''. |
|- | |- | ||
Line 465: | Line 466: | ||
|- | |- | ||
|| 11:10 | || 11:10 | ||
− | ||Close the pop up window. | + | ||Close the pop-up window. |
|- | |- | ||
Line 477: | Line 478: | ||
|- | |- | ||
|| 11:25 | || 11:25 | ||
− | || | + | ||Let me de-select '''h'''. Delete the result. Switch to '''Modeling''' perspective. |
|- | |- | ||
Line 485: | Line 486: | ||
|- | |- | ||
|| 11:38 | || 11:38 | ||
− | ||This can be simplified using '''import | + | ||This can be simplified using '''import''' statement. |
|- | |- | ||
|| 11:42 | || 11:42 | ||
− | ||Now, we shall type a few | + | ||Now, we shall type a few statements that show the use of '''import'''. |
|- | |- | ||
|| 11:48 | || 11:48 | ||
− | ||The | + | ||The statements to be typed are provided in a text file named '''import-statements.txt'''. |
|- | |- | ||
Line 517: | Line 518: | ||
|- | |- | ||
|| 12:23 | || 12:23 | ||
− | ||Paste all the ''' | + | ||Paste all the '''statement'''s at the beginning of the model. |
|- | |- | ||
Line 529: | Line 530: | ||
|- | |- | ||
|| 12:39 | || 12:39 | ||
− | ||Save this model by pressing '''Ctrl + S'''. | + | ||'''Save''' this model by pressing '''Ctrl + S'''. |
|- | |- | ||
Line 541: | Line 542: | ||
|- | |- | ||
|| 12:52 | || 12:52 | ||
− | ||Close the pop up window. | + | ||Close the pop-up window. |
|- | |- | ||
Line 565: | Line 566: | ||
|- | |- | ||
|| 13:15 | || 13:15 | ||
− | ||Using the '''import | + | ||Using the '''import''' statements, '''Modelica''' looks up for '''Length''' and '''Velocity''' '''type definition'''s using the '''path''' mentioned here. |
|- | |- | ||
Line 577: | Line 578: | ||
|- | |- | ||
|| 13:36 | || 13:36 | ||
− | || Now let us see how we can replace these two '''import | + | || Now let us see how we can replace these two '''import''' statements by a single '''import statement'''. Delete the two statements. |
|- | |- | ||
||13:47 | ||13:47 | ||
− | || And type '''import | + | || And type: '''import space Modelica dot SIunits dot asterisk semicolon''' |
|- | |- | ||
|| 13:58 | || 13:58 | ||
− | ||Save this model by pressing '''Ctrl + S''' | + | ||'''Save''' this model by pressing '''Ctrl + S''' |
|- | |- | ||
Line 605: | Line 606: | ||
|- | |- | ||
|| 14:20 | || 14:20 | ||
− | ||Close the pop up window. | + | ||Close the pop- up window. |
|- | |- | ||
Line 613: | Line 614: | ||
|- | |- | ||
|| 14:25 | || 14:25 | ||
− | ||You may notice the similarity of plot once again. | + | ||You may notice the similarity of '''plot''' once again. |
|- | |- | ||
Line 629: | Line 630: | ||
|- | |- | ||
|| 14:38 | || 14:38 | ||
− | ||As an assignment, | + | ||As an assignment, declare variable '''h''' and '''v''' of '''freeFall class''' as '''Length''' and '''Velocity''' '''type'''s respectively. |
|- | |- | ||
Line 641: | Line 642: | ||
|- | |- | ||
||14:58 | ||14:58 | ||
− | || Watch the video available at the link shown below: | + | || Watch the video available at the link shown below: |
+ | http://spoken-tutorial.org/What_is_a_Spoken_Tutorial | ||
|- | |- |
Latest revision as of 17:10, 20 August 2018
Time | Narration |
00:01 | Welcome to the Spoken Tutorial on Packages. |
00:05 | In this tutorial, we are going to learn:
how to create a package of classes in Modelica, |
00:12 | how to reference classes in a package, |
00:16 | how to import a package and
how to use Modelica Library. |
00:22 | To record this tutorial, I am using : OpenModelica 1.9.2 and Ubuntu Operating System version 14.04 and gedit. |
00:35 | Windows users may use Notepad or any other text-editor instead of gedit. |
00:42 | To understand and practice this tutorial, you need Knowledge of class and type definition in Modelica |
00:51 | Prerequisite tutorials are mentioned on our website. Please go through them. |
00:56 | A Package is a specialized class in Modelica. |
01:01 | It is a collection of classes. |
01:04 | It can be stored as a single file or a directory. |
01:08 | We will first learn about single file storage. |
01:12 | In single file storage, all classes belonging to a package are written in a single file. |
01:20 | It is not recommended as it may get lengthy in a few cases. |
01:24 | Now, let me switch to OMEdit to demonstrate single file storage for a package. |
01:31 | Please download and save all the files available on our website. |
01:36 | You may see that there is a file and a folder bearing the name spokenTutorialExamples. |
01:43 | Please download both of them. |
01:46 | Now, let me open the necessary files in OMEdit. |
01:51 | Press Ctrl + O. |
01:54 | Go to the appropriate location on your system and select spokenTutorialExamples.mo, |
02:02 | bouncingBallWithUserTypes.mo and bouncingBallWithImport. |
02:08 | You may also open each of them individually. |
02:12 | Note that I have not selected spokenTutorialExamples folder. |
02:17 | We shall discuss more about it when we look at directory storage. |
02:23 | Click on Open. |
02:25 | You may see that spokenTutorialExamples package is now seen in Libraries Browser. |
02:32 | Double-click on spokenTutorialExamples icon. |
02:37 | Switch to Text View if the file opens in Icon/Diagram View. |
02:42 | Now, let me discuss spokenTutorialExamples. |
02:47 | First line defines the name of a package. |
02:51 | Evidently, name of this package is spokenTutorialExamples. |
02:56 | This package consists of freefall class, bouncingBall model and bouncingBallWithUserTypes models. |
03:08 | end statement defines where the package ends. |
03:13 | We have viewed all classes and models of this package at one place. |
03:19 | Now, let us learn how to view individual classes in a package. |
03:24 | Click on the plus (+) button besides spokenTutorialExamples icon, in Libraries Browser. |
03:31 | This displays the names of classes present in this package. |
03:36 | Double-click on freeFall in Libraries Browser. |
03:40 | freeFall class has now opened. |
03:43 | Individual classes of a package may be simulated. |
03:47 | But the package itself can not be simulated. |
03:52 | Let me go back to spokenTutorialExamples tab. |
03:57 | Note that Simulate button doesn’t appear in the toolbar which indicates that this package cannot be simulated. |
04:06 | Now let me unload spokenTutorialExamples from OMEdit. |
04:12 | Do a right-click and select unload. Select Yes. |
04:18 | This is done so as to avoid conflict when demonstrating directory storage. |
04:24 | Now let me go back to the slides. |
04:27 | In Directory storage, classes are stored in separate files. |
04:32 | Name of directory is same as that of the package. |
04:37 | A file named package.mo is to be included in the directory and each class starts with a within statement. |
04:47 | Now, let me demonstrate the folder spokenTutorialExamples that you’ve downloaded. |
04:54 | Note that this folder represents the same package as that we have already discussed. |
05:02 | Let me demonstrate the file structure of this folder. |
05:06 | Go to the location where you saved the downloaded files on your system. |
05:12 | Double-click on spokenTutorialExamples folder. |
05:17 | Notice that the folder has following files: package.mo, freeFall.mo, bouncingBallWithUserTypes and bouncingBall. |
05:30 | We shall understand more about directory storage using both OMEdit and gedit. |
05:38 | Note that package.mo indicates that this folder represents a package. |
05:45 | Without this file, the folder doesn’t represent a Modelica package. |
05:51 | Now, let me switch to OMEdit to demonstrate directory storage. |
05:57 | Press Ctrl + O. |
05:59 | Navigate to the spokenTutorialExamples folder that you have downloaded. |
06:05 | Select package.mo from this folder and click on Open. |
06:11 | spokenTutorialExamples package can now be seen in Libraries Browser. |
06:17 | Double-click on spokenTutorialExamples icon. |
06:22 | Open the package in Text View if it opens in either Icon/Diagram View. |
06:27 | If you scroll down, you may notice that this package is the same as that we have seen in single file storage. |
06:36 | The difference between single file and directory storage can only be understood when we open this package using a text editor like gedit. |
06:47 | You may use Notepad or any other text editor if you are using Windows. |
06:53 | Now, let me unload spokenTutorialExamples package from 'OMEdit. |
06:59 | Switch to spokenTutorialExamples folder and open all the files using gedit. |
07:08 | Now all the files are open in gedit. |
07:13 | Let us take a look at package.mo first. |
07:17 | within statement indicates that this file represents a package. |
07:21 | Name of this package is spokenTutorialExamples. |
07:25 | Note that the name of folder was spokenTutorialExamples as well. |
07:31 | package.mo file can only contain the within statement and package declaration. |
07:38 | Let me switch to freeFall tab. |
07:41 | This within statement indicates that freefall class belongs to spokenTutorialExamples package. |
07:49 | Rest of this file has information specific to freeFall class. |
07:54 | You may see that other models in this package namely bouncingBallWithUserTypes and bouncingBall follow a similar syntax as well. |
08:04 | But, we didn’t observe within statement when we opened the package in OMEdit. |
08:11 | This indicates that within statement helps OMEdit recognize the file structure. |
08:17 | Hence, it is omitted by OMEdit while displaying the package. |
08:22 | Let me go back to the slides. |
08:25 | We shall now understand more about Modelica Library. |
08:29 | Modelica Library is an open-source package. |
08:33 | OMEdit automatically loads it for every session. |
08:38 | It can be seen in Libraries Browser. |
08:41 | It has classes from mechanical, electrical and thermal domains. |
08:46 | Classes of this library can be referenced and used. |
08:51 | Now, let me switch to OMEdit to demonstrate Modelica Library. |
08:57 | Locate Modelica icon in Libraries Browser and expand it. |
09:03 | Note that Modelica Library has packages named Blocks, Complex Blocks etc. |
09:10 | You may note that a package may further contain packages as well as is evident here. Of special mention is the SIunits package. |
09:22 | Expand it. |
09:25 | This package has type definitions for physical quantities like Angle, Length, Position etc. |
09:32 | We shall see how to use these type definitions using bouncingBallWithImport class. |
09:39 | Compress SIunits. |
09:42 | And double-click on bouncingBallWithImport and bouncingBallWithUserTypes. |
09:49 | Let me shift OMEdit window to the left for better visibility. |
09:55 | We shall first look at bouncingBallWithUserTypes. |
09:59 | We have learnt about this model in the prerequisite tutorials. |
10:03 | This model has type definitions named Length and Velocity. |
10:09 | We can instead use the type definition in SIunits instead of defining them explicitly in every model. |
10:18 | We shall see how to do that using bouncingBallWithImport model. |
10:23 | Let me switch to bouncingBallWithImport. |
10:27 | A class in a package is referenced to using dot. |
10:32 | Modelica.SIunits refers to SIunits package which belongs to Modelica library. |
10:39 | Variable h is declared to be of Length type which is defined in SIunits package. |
10:47 | Similarly, variable v is declared to be of Velocity type which is defined in SIunits package. |
10:56 | Note that parameters radius and g are declared in a similar fashion. |
11:03 | Now let me Simulate this model. |
11:07 | Click on Simulate button in the toolbar. |
11:10 | Close the pop-up window. |
11:13 | Select h in the Variables Browser. |
11:17 | Note that the plot obtained is similar to the one seen in the case ofbouncingBallWithUserTypes. |
11:25 | Let me de-select h. Delete the result. Switch to Modeling perspective. |
11:33 | It is tedious to use the full name of a class every time. |
11:38 | This can be simplified using import statement. |
11:42 | Now, we shall type a few statements that show the use of import. |
11:48 | The statements to be typed are provided in a text file named import-statements.txt. |
11:56 | Go to the location where you saved it on your system. |
12:01 | Double-click on import-statements.txt. Windows users may use Notepad to open this file. |
12:11 | The file is now open in gedit. |
12:14 | Copy all the statements using Ctrl+C or by doing right-click. |
12:21 | Switch to OMEdit. |
12:23 | Paste all the statements at the beginning of the model. |
12:28 | Delete the declaration statements for Length and Velocity, which have been defined before. |
12:36 | Delete the extra spaces. |
12:39 | Save this model by pressing Ctrl + S. |
12:43 | Now the model is complete and ready for simulation. |
12:48 | Click on Simulate button to simulate it. |
12:52 | Close the pop-up window. |
12:54 | Select h in the Variables Browser. |
12:58 | Note that the plot is same as in previous case. |
13:03 | De-select h and delete the result. |
13:07 | Switch to Modeling perspective. |
13:10 | Now let us now try to understand the import statements. |
13:15 | Using the import statements, Modelica looks up for Length and Velocity type definitions using the path mentioned here. |
13:25 | This saves the trouble of referring to the package every time. |
13:30 | A detailed discussion of lookup rules is beyond the scope of this tutorial. |
13:36 | Now let us see how we can replace these two import statements by a single import statement. Delete the two statements. |
13:47 | And type: import space Modelica dot SIunits dot asterisk semicolon |
13:58 | Save this model by pressing Ctrl + S |
14:02 | This statement is known as a wild-card import. |
14:06 | This way, any class from SIunits may be accessed without explicitly mentioning it. |
14:14 | Now let me Simulate this model. |
14:17 | Click on Simulate button. |
14:20 | Close the pop- up window. |
14:22 | Select h in the Variables Browser. |
14:25 | You may notice the similarity of plot once again. |
14:29 | De-select h and delete the result. |
14:32 | Go back to Modeling perspective. |
14:35 | Now let me switch to the slides. |
14:38 | As an assignment, declare variable h and v of freeFall class as Length and Velocity types respectively. |
14:47 | These type definitions can be found in SIunits package of Modelica library. |
14:54 | This brings us to the end of this tutorial. |
14:58 | Watch the video available at the link shown below: |
15:02 | It summarises the Spoken Tutorial project. |
15:05 | If you have questions in this Spoken Tutorial, please visit the website shown. |
15:11 | We coordinate coding of solved examples from popular books. |
15:15 | We give honorarium to contributors. Please visit our website. |
15:21 | We help migrate labs from commercial simulators to OpenModelica. |
15:26 | Please visit the following website. |
15:29 | Spoken Tutorial Project is supported by NMEICT, MHRD Government of India. |
15:36 | We thank the development team of OpenModelica for their support. |
15:41 | I would like to thank you for joining me in this tutorial.
Good bye. |