OpenModelica/C2/Developing-an-equation-based-model/English
Visual Cue | Narration |
Slide Number 1
Title Slide |
Welcome to the spoken tutorial on Developing an equation based model. |
Slide:
Learning Objectives |
In this tutorial, we are going to learn:
|
Slide:
System Requirements. |
To record this tutorial, I am using
|
Slide:
Pre-requisites |
To understand this tutorial, you need to know
|
Slide:
Problem Statement |
Let us simulate the motion of a ball of mass 'm', which is under free fall due to gravity.
|
Slide:
Freefall equations |
The equations of motion for a freely falling body, are as follows:
dv/dt = g
|
/* Switch to OMEdit */ | Let me go to OMEdit. I have already launched it on my system. |
Click on Dash Home | To open OMEdit on Ubuntu Linux Operating System, click on Dash Home icon, which appears at the top left, in launcher. |
Type OMEdit in the search bar >> click on OMEdit | Type OMEdit in the search bar.
|
On clicking OMEdit icon, you see a window such as this.
| |
/* Switch to modeling perspective */
|
At the bottom right-hand corner, you can locate buttons for ‘Welcome’, ‘Modeling’ and ‘Plotting’ perspectives.
|
‘Modeling perspective’ has now opened. | |
Move cursor over the area enclosed between Libraries Browser on the left >> Messages Browser appears at the bottom >> Model file tabs on the top
|
I will be referring to the area between
|
Move cursor over the toolbar present above modeling area | The toolbar has buttons related to file operations, graphical view and simulation.
|
Now, we shall use ‘freeFall’ class file provided in the Code Files link on our Spoken Tutorial webpage.
| |
/* Opening a new class file and switching views */
Go to File >> Open Model/Library File |
To open this class, go to the File menu in Menu bar.
|
Locate the downloaded freeFall file | Locate freeFall file that you downloaded and saved on your system and open it. |
Hover over Open model/library file | You may also use the tool named Open Model/Library File, that my cursor is pointing to, for opening a file. |
Hover over freeFall icon in Libraries Browser | Note that freeFall icon appears in the Libraries Browser.
|
Right click on freeFall icon >> select View Class | Right click on freeFall icon and select View Class. |
The class has now opened in Diagram view.
I shall show you how to switch between different views. | |
Go to the top of Modeling area >> point to second button | Go to the top of Modeling area.
Note that the second button stands for Diagram view. |
Click on Text View button at the top of modeling area. | Third button is Text View.
Click on it to switch to Text View.
|
Point to the first button | Note that the first button stands for Icon View.
|
You may also create a new class named freeFall and type the required information. | |
Click on File >> New Modelica Class. | To create a new class, go to File menu.
|
A dialog box pops up, as shown. | |
Type freeFall1
In the Name field of this dialog box, type freeFall.
| |
Note that two classes cannot have the same name. | |
Click on Specialization drop-down menu >> choose Class >> click on Ok | Click on Specialization drop-down menu.
Select Class.
|
Point to the tool named New Modelica class | A new class has been created.
You may also use the tool named New Modelica class to open a new class. |
Delete annotation section | Let me delete annotation section. |
Click on File>> Save | Now, you may type the required information here and save this class.
|
Choose location | Choose an appropriate location for this file and save it. |
Now, let us understand the syntax of Modelica using freeFall class.
So switch to freeFall class. | |
Modelling area >> Click on freeFall tab. | Go to top of Modelling area.
Click on freeFall tab. |
Programs in Modelica are arranged in the form of classes. | |
Highlight class freeFall | The first line of a class defines its name.
|
Highlight end freeFall; | Every class must have an end statement to indicate where the class ends. |
This class has variable declarations and equations.
| |
Real h(start = 30, unit = “m”) | Real represents data-type. |
Highlight h (start = 30, unit = “m”) | h represents height of ball from surface of Earth. |
Highlight start | start is an attribute of Real variable. |
Continue highlight | Every data-type has certain attributes, which specify useful information related to variables. |
Real h (start = 30, unit = “m”); | start attribute specifies the initial value of a variable.
|
Real h ( start = 30, unit = “m”); | unit attribute specifies the unit of a variable.
|
Real h(start = 30, unit = “m”); | Every variable declaration must end with a semi-colon. |
Real v (start = 0, unit = “m/s”); | v represents velocity of ball. It is of Real data-type. |
Real v (start = 0, unit = “m/s”); | The initial value of v is zero. Its unit is meter per second. |
parameter Real g (unit = m/s2) = -9.81; | grepresents acceleration due to gravity. It is of Real data-type.
And its unit is meter per second square. |
Highlight parameter Real g(unit = m/s2) = -9.81; | parameter is a quantity that remains constant in a simulation run. |
parameter Real g(unit = m/s2) = -9.81; | The value of g remains constant throughout the simulation run, with a value of 9.81.
|
parameter Real g(unit = m/s2) = -9.81 “Acceleration due to gravity” | The text in double quotes is a comment written with the declaration of g.
|
Now, let me go back to the slides. | |
Slide:
Variable and Parameter declaration |
parameter is a quantity that remains constant in a simulation run.
|
Highlight | start and unit attributes have already been defined.
|
Go back to OMEdit | Let me go back to OMEdit. |
/* freeFall */
equation |
‘equation’ signifies the beginning of equation section of a class. |
/* Equations of motion */ | This is an alternative way of inserting comments. |
der(h) = v;
der(v) = g; |
The two equations of motion for a freely falling body, as we have already discussed, have been included here. |
der(h) = v; | der() is Modelica function for time derivative.
|
der(v) = g; | And der(v) represents dv/dt. |
der(v) = g; | Every equation must end with a semi-colon. |
Click on simulate button | Let me show you how to simulate this class.
Click on simulate button in the toolbar. |
Close the pop-up | Close the pop-up window. |
Plotting perspective | This window is known as the Plotting perspective.
|
Variables browser | Variables browser displays information related to variables and parameters of a class. |
Point to Unit and Description | Note that there are columns named Unit and Description.
|
Description column displays comments written in double quotes with variable declarations. | |
Click on h in the variables browser | Let me show you how to generate a plot.
|
This generates the plot of h with respect to time -
| |
By default, the simulation is run from 0 to 1 unit of time.
| |
De-select h | Let me de-select h. |
It is always a good practice to delete the results, once the necessary plots have been generated. | |
Right-click on freeFall >> select Delete result | To delete this result, right-click on freeFall and select Delete result.
|
Click on Modeling perspective button at bottom right. | Let me go back to Modeling perspective.
|
class freeFall | class is used synonymously with model, in Modelica.
|
Now, let me show you how to change the time interval for simulation. | |
Click on Simulation Setup button in the toolbar | Click on Simulation Setup button present in the toolbar. |
Locate Stop time field >> 5 | Under General tab, locate Stop time field.
Change it to 5 units. |
Click on Simulate >> close the pop-up | Click on Simulate.
Close the pop-up window which appears. |
Select h >> Plot window | Let me select h once again, in the Variables browser.
|
Notice that the time interval has increased to 5 units.
| |
We will learn how to rectify this issue in the later tutorials. | |
Right-click on freeFall >> select Delete result. | Let me delete this result by right-clicking on freeFall and selecting Delete result. |
Click on Modeling button | Go back to Modeling perspective by clicking on Modeling perspective at bottom-right. |
It is necessary to ensure that the number of equations is equal to the number of variables.
| |
Select
|
Now, let me delete the first equation and simulate this class, to see what happens. |
Point to star next to filename. | I have deleted the first equation.
This indicates unsaved changes in the class.
|
To save this class, go to the File menu and click on Save.
| |
Click on Simulate. | Now, let me simulate this class by clicking on Simulate button. |
Error message pops up | Note that an error message pops up in the Messages browser.
|
Let me insert the equation back in its place and click on Save button in the toolbar. | |
Click on Simulate button once again to simulate this class.
Note that the class simulates successfully, since the number of equations is equal to the number of variables. | |
Close the pop-up | Close the pop-up window. |
Let me go back to the slides. | |
Slide:
Equations in Modelica |
“der()” is Modelica function for time derivative.
|
Slide:
Assignment |
As an assignment, write a model to simulate the differential equation
|
This brings us to the end of this tutorial. | |
Slide:
About the Spoken Tutorial project |
Watch the video at the following link. It summarizes the Spoken Tutorial project. |
Slide:
Spoken Tutorial Workshops |
We conduct workshops using spoken tutorials; give certificates.
|
Slide:
Acknowledgements |
Spoken Tutorial project is funded by NMEICT, MHRD, Government of India. |
Slide:
Thanks |
We thank the development team of OpenModelica for their support. |
Thank you. |