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 will learn to:
|
| Slide:
System Requirements. |
To record this tutorial, I am using
But, this process is identical in Windows, Mac OS X or FOSSEE OS on ARM. |
| Slide:
Pre-requisites |
To understand this tutorial, you should 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:
|
| /* Switch to OMEdit */ | Let me go to OMEdit. I have already launched it on my system. |
| To open OMEdit on Ubuntu Linux OS, click on Dash Home icon at the top left in the launcher.
| |
| Let me go back to OMEdit. | |
| /* Switch to modeling perspective */
|
‘OMEdit’ by default, opens in the ‘Welcome’ perspective.
At the bottom right-hand corner, you can locate buttons for ‘Welcome’, ‘Modeling’ and ‘Plotting’ perspectives.
|
| 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 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 present in menu bar.
|
| Locate ‘freeFall’ file that you downloaded and saved in your system and open it. | |
| Hover over ‘Open model/library file’ | You may also use the ‘Open Model/Library File’ button that my cursor points to, for opening a file. |
| Hover over ‘freeFall’ icon in ‘Libraries Browser’ | Note that ‘freeFall’ icon has now appeared in ‘Libraries Browser’.
|
| Right click on ‘freeFall’ icon and select ‘View Class’ | Right click on ‘freeFall’ and select ‘View Class’. |
| Go to the top of the modeling area | The class has now opened in Diagram view.
Go to the top of the modeling area. |
| Click on ‘Text View’ button at the top of modeling area. | Click on the third button which is the ‘Text View’.
You may see buttons for ‘Icon View’ and ‘Diagram View’ as well.
|
| You may also create a new class named ‘freeFall’ and type the required information. Let me show you how it is done. | |
| File → New Modelica Class. | Go to File menu. Click on ‘New Modelica Class’ |
| Type // freeFall | A dialog box opens as shown. Type ‘freeFall’ in the ‘Name’ field of dialog box.
I am using a different name since ‘freeFall’ class is already open in ‘OMEdit’. |
| Click on ‘Specialization’ drop-down menu. Choose ‘Model’ | Click on ‘Specialization’ drop-down menu.
Choose ‘Class’. We shall learn more about class specialization later on. Click on ‘Ok’. |
| Delete // annotation | New class has now opened.
Delete annotation section. We shall learn about annotation later on. Type the required information and save the class. |
| File → Save | To save the class, go to ‘File’ menu and click on ‘Save’. |
| Choose a location for your file and click on ‘Save’. The file is now saved. | |
| At the top of modeling area, click on ‘freeFall’ tab. | |
| Let us understand the syntax of Modelica using ‘freeFall’ example.
| |
| Highlight class freeFall
|
The first line of a class defines its name. The name of this class is ‘freeFall’. |
| Highlight end freeFall; | Every class must have an ‘end’ statement to indicate where the class ends. |
| This class has variable declarations and equations. Let us see how to declare variables. | |
| Real h(start = 30, unit = “m”) | ‘Real’ signifies a data-type. |
| Highlight h (start = 30, unit = “m”) | ‘h’ stands for the height of ball from surface of Earth. |
| Every data-type has certain attributes.
| |
| Real h (start = 30, unit = “m”); | Initial conditions are required to simulate differential equations with respect to time.
|
| Real h ( start = 30, unit = “m”); | ‘unit’ attribute specifies the unit of the variable. The unit of ‘h’ is ‘metre’.
|
| Real h(start = 30, unit = “m”) ; | Every variable declaration must end with a semi-colon. |
| Real v (start = 0, unit = “m/s”); | ‘v’ represents the velocity of the ball. It is a real variable. |
| 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; | ‘g’ signifies acceleration due to gravity. It is of real data-type. |
| parameter Real g (unit = m/s2) // = -9.81; | The unit of ‘g’ is meter per second square. |
| Highlight parameter Real g(unit = m/s2) = -9.81; | A ‘parameter’ remains constant throughout a simulation run. |
| parameter Real g(unit = m/s2) = -9.81; | The value of ‘g’ is equal to 9.81. Negative sign is due to sign convention. |
| parameter Real g(unit = m/s2) = -9.81 “Acceleration due to gravity” | The text in double quotes is a comment.
|
| Let me go back to the slides. | |
| Slide:
Variable and Parameter declaration |
‘parameter’ is a quantity that remains constant in a simulation run.
|
| Let us go back to OMEdit. | |
| /* freeFall */
equation |
‘equation’ signifies the beginning of equation section of a class. |
| /* Equations of motion */ | This is another way of inserting comments. |
| der(h) = v;
der(v) = g; |
Note that the two equations of motion have been included here. |
| der(h) = v; | ‘der()’ represents the time derivative of a variable.
|
| der(v) = g; | der(v) represents dv/dt. |
| der(v) = g ; | Every equation ends with a semi-colon. |
| Click on ‘simulate’ button | Let us simulate this class.
So click on ‘simulate’ button in the toolbar. |
| Close the dialog box which pops up. | |
| Plotting perspective | This window is known as plotting perspective.
Plotting perspective opens on simulation of a class.
|
| Variables browser | The ‘variables browser’ shows all variables and parameters of a class.
|
| Click on ‘h’ in the ‘variables browser’ | Let me scroll left.
|
| Let me deselect ‘h’. | |
| Click on Modeling perspective button at bottom right. | Let us go back to Modeling perspective.
Click on Modeling perspective button at bottom right. |
| class freeFall | In Modelica, ‘class’ is used synonymously with ‘model’.
|
| Click on ‘Simulation Setup’ button in the toolbar | Let us change the default simulation settings.
|
| ‘Simulation Setup’ toolbox | Under the General tab, locate ‘stop time’ field and change it to 5 units.
|
| Plotting Perspective | Close the dialog box. Click on ‘h’ in the ‘variables browser’.
|
| Click on ‘Modeling’ button | Let me deselect ‘h’ and go back to Modeling perspective.
|
| Select
|
Ensure that the number of variables is equal to the number of equations.
|
| Let me insert the equation back in its place and click on Save. | |
| Let me go back to the slides. | |
| Slide:
Equations in Modelica |
“der()” represents time derivative in Modelica
We shall learn more about ‘initial equation’ section later on. |
| 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 |
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
| Slide:
Spoken Tutorial Workshops |
We conduct workshops using spoken tutorials and give certificates to those who pass an online test.
|
| Slide:
Acknowledgements |
Spoken Tutorial project is funded by NMEICT, MHRD, Government of India. |
| Slide:
Thanks |
We thank OpenModelica team for their support. |
| Thank you! This is Bhargava signing off. |