From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:01 Welcome to the spoken tutorial on Developing an equation based model.
00:06 In this tutorial, we are going to learn:

how to create a textual model in OMEdit and simulate it,

00:14 how to declare variables and equations,
00:17 how to use Simulation Setup toolbox.
00:21 To record this tutorial, I am using OpenModelica 1.9.2 and Ubuntu Linux Operating System 14.04.
00:32 But, this process is identical in Windows, Mac OS X or FOSSEE OS on ARM.
00:40 To understand this tutorial, you need to know equation-based modeling of physical systems.
00:48 Let us simulate the motion of a ball of mass 'm' which is under free fall due to gravity.
00:54 The height of the ball from the surface of Earth is represented by variable h.
00:59 The velocity of the ball is represented by variable v.
01:04 Acceleration due to gravity is represented by g and is assumed to be constant.
01:10 Variables directed away from the surface of earth are considered positive.
01:16 The equations of motion for a freely falling body are as follows:

dh/dt = v, dv/dt = g

01:27 The value of h at time t = 0 is 30 meters and the value of v at time t = 0 is 0.
01:37 Now, let me go to OMEdit. I have already launched it on my system.
01:43 To open OMEdit on Ubuntu Linux Operating System, click on Dash Home icon which appears at the top left, in launcher.
01:53 Type OMEdit in the search bar.
01:56 Click on the OMEdit icon.
01:59 On clicking OMEdit icon, you see a window such as this.
02:06 This window is known as "Welcome perspective".
02:09 OMEdit by default, opens in the "Welcome perspective".
02:14 At the bottom right-hand corner, you can locate buttons for ‘Welcome’, ‘Modeling’ and ‘Plotting’ perspectives.
02:23 click on ‘Modeling’ perspective.
02:26 ‘Modeling’ perspective has now opened.
02:29 I will be referring to the area between Libraries Browser on the left, Messages Browser at the bottom and Toolbar on the top, as the modeling area.
02:41 The toolbar has buttons related to file operations, graphical view and simulation.
02:51 We will learn more about these buttons as we go along.
02:55 Now, we shall use ‘freeFall’ class file provided in the Code Files link on our Spoken Tutorial webpage.
03:02 Please download this file and save it on your system.
03:07 To open this class, go to the File menu in Menu bar.
03:13 Click on Open Model/Library File
03:17 Locate freeFall file that you downloaded and saved on your system and open it.
03:24 You may also use the tool named Open Model/Library File that my cursor is pointing to, for opening a file.
03:34 Note that freeFall icon appears in the Libraries Browser.
03:39 Libraries Browser shows all classes that are loaded in a session of OMEdit.
03:45 Right click on freeFall icon and select View Class.
03:52 The class has now opened in Diagram view.
03:56 Do not worry if the class does not open in Diagram view.
04:00 I shall show you how to switch between different views.
04:04 Go to the top of Modeling area.
04:07 Note that the second button stands for Diagram view.
04:10 Third button is Text View.
04:13 Click on it to switch to Text View.
04:17 The class has now opened in Text view.
04:20 Note that the first button stands for Icon View.
04:24 We will learn more about Icon view and Diagram view later on.
04:29 You may also create a new class named freeFall and type the required information.
04:36 To create a new class, go to File menu.
04:40 Select New Modelica Class.
04:43 A dialog box pops up as shown.
04:46 In the Name field of this dialog box, type: freeFall.
04:51 I am using a different name freeFall1 since freeFall class is already open in OMEdit.
04:58 Note that two classes cannot have the same name.
05:03 Click on Specialization drop-down menu. Select Class. Click on Ok.
05:10 A new class has been created.
05:13 You may also use the tool named New Modelica class to open a new class.
05:20 Let me delete annotation section.
05:23 Now, you may type the required information here and save this class.
05:29 To save this class, go to File menu in Menu bar and click on Save.
05:36 Choose an appropriate location for this file and save it.
05:41 Now, let us understand the syntax of Modelica using freeFall class.
05:47 So, switch to freeFall class.
05:49 Go to top of Modelling area. Click on freeFall tab.
05:54 Programs in Modelica are arranged in the form of classes.
05:58 The first line of a class defines its name.
06:02 The name of this class is freeFall.
06:05 Every class must have an end statement to indicate where the class ends.
06:11 This class has variable declarations and equations.
06:15 Let me show you how to declare variables.
06:18 Real represents data-type.
06:21 h represents height of ball from surface of Earth.
06:25 start is an attribute of Real variable.
06:29 Every data-type has certain attributes which specify useful information related to variables.
06:36 start attribute specifies the initial value of a variable.
06:41 The initial value of h is 30 units.
06:45 unit attribute specifies the unit of a variable.
06:49 The unit of h is metre.
06:52 Every variable declaration must end with a semi-colon.
06:57 v represents velocity of ball. It is of Real data-type.
07:02 The initial value of v is zero. Its unit is meter per second.
07:09 g represents acceleration due to gravity. It is of Real data-type. And its unit is meter per second square.
07:18 parameter is a quantity that remains constant in a simulation run.
07:24 The value of g remains constant throughout the simulation run, with a value of 9.81.
07:32 The negative sign is due to sign convention used.
07:36 The text in double quotes is a comment written with the declaration of g.
07:42 Comments provide useful information about the program. They are also useful for documentation.
07:49 Now, let me go back to the slides.
07:52 parameter is a quantity that remains constant in a simulation run.
07:57 Real, Integer, Boolean and String data-types are supported in Modelica.
08:03 start and unit attributes have already been defined.
08:07 min attribute specifies the minimum value of a variable.
08:10 Similarly, max attribute specifies the maximum value of a variable.
08:16 Let me go back to OMEdit.
08:19 ‘equation’ signifies the beginning of equation section of a class.
08:25 This is an alternative way of inserting comments.
08:30 The two equations of motion for a freely falling body, as we have already discussed, have been included here.
08:38 der() is Modelica function for time derivative.
08:43 Hence, der(h) represents dh/dt.
08:48 And der(v) represents dv/dt.
08:52 Every equation must end with a semi-colon.
08:57 Let me show you how to simulate this class.
09:00 Click on simulate button in the toolbar.
09:04 Close the pop-up window.
09:07 This window is known as the Plotting perspective.
09:11 On successful simulation of a class, Plotting perspective opens automatically.
09:17 Variables browser displays information related to variables and parameters of a class.
09:24 Note that there are columns named Unit and Description.
09:29 Unit column specifies units of variables as defined using Unit attribute.
09:37 Description column displays comments written in double quotes with variable declarations.
09:45 Let me show you how to generate a plot. Select h.
09:51 This generates the plot of h with respect to time -with h on y-axis and time on the x-axis
10:01 By default, the simulation is run from 0 to 1 unit of time.
10:07 The unit of time depends on the system of units used for other variables.
10:13 Let me de-select h.
10:17 It is always a good practice to delete the results, once the necessary plots have been generated.
10:25 To delete this result, right-click on freeFall and select Delete result.
10:33 The result has now been deleted.
10:36 Let me go back to Modeling perspective.
10:39 Click on Modeling button at bottom-right.
10:43 class is used synonymously with model, in Modelica.
10:48 One may use model instead of class here, to produce the same effect.
10:54 Now, let me show you how to change the time interval for simulation.
11:01 Click on Simulation Setup button present in the toolbar.
11:06 Under General tab, locate Stop time field. Change it to 5 units.
11:14 Click on Simulate. Close the pop-up window which appears.
11:21 Let me select h once again, in the Variables browser.
11:26 This generates h v/s time plot.
11:29 Notice that the time interval has increased to 5 units.
11:33 But, the value of h has gone below zero which is unacceptable.
11:40 We will learn how to rectify this issue in the later tutorials.
11:45 Let me delete this result by right-clicking on freeFall and selecting Delete result.
11:53 Go back to Modeling perspective by clicking on Modeling perspective at bottom-right.
11:59 It is necessary to ensure that the number of equations is equal to the number of variables.
12:07 This class has two variables and two equations.
12:11 Now, let me delete the first equation and simulate this class to see what happens.
12:18 I have deleted the first equation.
12:21 Notice that a star appears beside the name of the class, in freeFall tab.
12:28 This indicates unsaved changes in the class.
12:31 Hence it is a good practice to save a class after a change has been made.
12:38 To save this class, go to the File menu and click on Save.
12:44 You may also use the Save button in toolbar which my cursor points to, to save a file.
12:53 Now, let me simulate this class by clicking on Simulate button.
12:59 Note that an error message pops up in the Messages browser.
13:04 It says: there are too few equations and the model has 1 equation and 2 variables. Hence this cannot be simulated.
13:14 Let me insert the equation back in its place and click on Save button in the toolbar.
13:24 Click on Simulate button once again to simulate this class.
13:29 Note that the class simulates successfully, since the number of equations is equal to the number of variables.
13:37 Close the pop-up window.
13:40 Let me go back to the slides.
13:43 “der()” is Modelica function for time derivative.
13:48 There is no data flow direction for equations.
13:52 For example, der(h) = v may also be written as v = der(h).
14:00 Initial equations section is used to enter initial conditions.
14:05 We shall learn more about Initial equation later on.
14:10 As an assignment, write a model to simulate the differential equation, dx/dt = -a into x , where a = 1, x belongs to R and the value of x at time t=0 is 5.
14:28 This brings us to the end of this tutorial.
14:31 Watch the video at the following link. It summarizes the Spoken Tutorial project.
14:37 We conduct workshops using spoken tutorials; give certificates. Please contact us.
14:43 Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
14:49 We thank the development team of OpenModelica for their support.
14:53 Thank you.

Contributors and Content Editors

Jyotisolanki, Sandhya.np14