From Script | Spoken-Tutorial
Jump to: navigation, search
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,
02:02 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 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:,, bouncingBallWithUserTypes and bouncingBall.
05:30 We shall understand more about directory storage using both OMEdit and gedit.
05:38 Note that 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 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 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 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.

Contributors and Content Editors

Jyotisolanki, Sandhya.np14