Difference between revisions of "OpenModelica/C2/Developing-an-equation-based-model/English"
Nancyvarkey (Talk | contribs) |
|||
(One intermediate revision by one other user not shown) | |||
Line 12: | Line 12: | ||
'''Learning Objectives''' | '''Learning Objectives''' | ||
− | || In this tutorial, we | + | || In this tutorial, we are going to learn: |
− | * | + | * How to create a textual model in '''OMEdit''' and simulate it. |
+ | * How to declare variables and equations | ||
+ | * How to use '''Simulation Setup''' toolbox. | ||
− | |||
− | |||
− | |||
|- | |- | ||
|| Slide: | || Slide: | ||
Line 24: | Line 23: | ||
'''System Requirements'''. | '''System Requirements'''. | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | |||
* '''OpenModelica 1.9.2 ''' and | * '''OpenModelica 1.9.2 ''' and | ||
+ | * '''Ubuntu Linux Operating System 14.04''' | ||
− | |||
But, this process is identical in '''Windows, Mac OS X '''or''' FOSSEE OS on ARM'''. | But, this process is identical in '''Windows, Mac OS X '''or''' FOSSEE OS on ARM'''. | ||
Line 35: | Line 33: | ||
Pre-requisites | Pre-requisites | ||
− | || To understand this tutorial, you | + | || To understand this tutorial, you need to know |
− | + | ||
* equation-based modeling of physical systems. | * equation-based modeling of physical systems. | ||
Line 43: | Line 40: | ||
'''Problem Statement''' | '''Problem Statement''' | ||
− | || Let us simulate the motion of a ball of mass ''' | + | || Let us simulate the motion of a ball of mass ''''m'''', which is under '''free fall due to gravity'''. |
− | The height of the ball from the surface of Earth is represented by variable ''' | + | The height of the ball from the surface of Earth is represented by variable '''h'''. |
− | The velocity of the ball is represented by variable ''' | + | The velocity of the ball is represented by variable '''v'''. |
− | + | '''Acceleration due to gravity''' is represented by '''g''' and is assumed to be constant. | |
Line 61: | Line 58: | ||
'''Freefall equations''' | '''Freefall equations''' | ||
− | || The equations of motion for a freely falling body, are as follows: | + | || The '''equations of motion''' for a freely falling body, are as follows: |
− | ''' | + | '''dh/dt = v''' |
+ | '''dv/dt = g''' | ||
− | The value of h at time '''t = 0''' is '''30''' m and the value of v at time '''t = 0''' is '''0'''. | + | |
+ | The value of '''h''' at time '''t = 0''' is '''30''' m and the value of '''v''' at time '''t = 0''' is '''0'''. | ||
|- | |- | ||
Line 74: | Line 73: | ||
|- | |- | ||
− | || | + | || Click on '''Dash Home''' |
− | || To open '''OMEdit '''on '''Ubuntu Linux | + | || 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'''. | ||
− | |||
+ | Click on the '''OMEdit''' icon. | ||
− | + | |- | |
+ | || | ||
+ | ||On clicking '''OMEdit''' icon, you see a window such as this. | ||
− | + | This window is known as '''"Welcome perspective"'''. | |
− | + | ||
− | + | '''OMEdit''' by default, opens in the '''"Welcome perspective"''' | |
− | + | ||
|- | |- | ||
Line 94: | Line 97: | ||
− | Click on | + | Click on '''Modeling perspective''' button at the bottom right |
− | || ''' | + | || At the bottom right-hand corner, you can locate buttons for '''‘Welcome’, ‘Modeling’''' and '''‘Plotting’ perspectives'''. |
− | |||
+ | Let me click on''' ‘Modeling perspective’'''. | ||
− | + | |- | |
− | + | || | |
− | + | ||'''‘Modeling perspective’''' has now opened. | |
− | '''‘Modeling''' | + | |
|- | |- | ||
− | || Move cursor over the area enclosed between Libraries Browser on the left | + | || 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 | || I will be referring to the area between | ||
− | * Libraries Browser on the left, | + | * '''Libraries Browser''' on the left, |
− | * Messages Browser at the bottom and | + | * '''Messages Browser''' at the bottom and |
− | * Toolbar on the top, as the '''modeling area'''. | + | * '''Toolbar''' on the top, as the '''modeling area'''. |
|- | |- | ||
− | || Move cursor over the toolbar present above modeling area | + | || Move cursor over the '''toolbar''' present above modeling area |
− | || The toolbar has buttons related to '''file operations, graphical view''' and '''simulation'''. | + | || The '''toolbar''' has buttons related to '''file operations, graphical view''' and '''simulation'''. |
− | We will learn about | + | We will learn more about these buttons, as we go along. |
|- | |- | ||
|| | || | ||
− | || Now, we shall use''' ‘freeFall’ class''' file provided in the '''Code Files''' link on | + | || Now, we shall use''' ‘freeFall’ class''' file provided in the '''Code Files''' link on our '''Spoken Tutorial webpage'''. |
− | Please download | + | Please download this file and save it on your system. |
|- | |- | ||
|| /* Opening a new class file and switching views */ | || /* Opening a new class file and switching views */ | ||
− | Go to File | + | Go to '''File''' >> '''Open Model/Library File''' |
− | || To open this '''class''', go to the ''' | + | || To open this '''class''', go to the '''File''' menu in '''Menu bar'''. |
− | ''' | + | Click on '''Open Model/Library File''' |
+ | |- | ||
+ | || 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'''. |
+ | |||
+ | |||
+ | '''Libraries Browser''' shows all '''classes''' that are loaded in a session of '''OMEdit'''. | ||
|- | |- | ||
− | || | + | || 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. |
− | + | Do not worry if the '''class''' does not open in '''Diagram''' view. | |
− | + | ||
− | + | I shall show you how to switch between different views. | |
− | + | ||
|- | |- | ||
− | || Go to the top of | + | ||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 | + | || Click on '''Text View''' button at the top of modeling area. |
− | || | + | || Third button is '''Text View'''. |
− | + | Click on it to switch to '''Text View'''. | |
− | We | + | The '''class''' has now opened in '''Text''' view. |
+ | |||
+ | |- | ||
+ | ||Point to the first button | ||
+ | ||Note that the first button stands for '''Icon View'''. | ||
+ | |||
+ | |||
+ | We will learn more about '''Icon view '''and '''Diagram view '''later on. | ||
|- | |- | ||
|| | || | ||
− | || You may also create a new class named ''' | + | || You may also create a new '''class''' named '''freeFall''' and type the required information. |
|- | |- | ||
− | || File | + | || Click on File >> New Modelica Class. |
− | || | + | || To create a new '''class''', go to '''File''' menu. |
+ | |||
+ | |||
+ | Select '''New Modelica Class'''. | ||
|- | |- | ||
− | || | + | || |
− | || A dialog box | + | || A dialog box pops up, as shown. |
+ | |||
+ | |- | ||
+ | || Type '''freeFall1''' | ||
+ | In the '''Name''' field of this dialog box, type '''freeFall'''. | ||
+ | |||
− | I am using a different name since | + | I am using a different name '''freeFall1''' since '''freeFall class''' is already open in '''OMEdit'''. |
|- | |- | ||
− | || Click on | + | || |
− | || Click on ''' | + | ||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'''. | ||
− | |||
− | + | Click on '''Ok'''. | |
− | |||
|- | |- | ||
− | || | + | || 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'''. | ||
|- | |- | ||
− | || File | + | || Click on '''File'''>> '''Save''' |
− | || To save | + | || Now, you may type the required information here and save this '''class'''. |
+ | |||
+ | |||
+ | To save this '''class''', go to '''File''' menu in '''Menu bar''' and click on '''Save'''. | ||
|- | |- | ||
− | || | + | || Choose location |
− | || Choose | + | || 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'''. | + | |- |
+ | || | ||
+ | ||Programs in '''Modelica''' are arranged in the form of '''classes'''. | ||
|- | |- | ||
|| Highlight '''class freeFall''' | || Highlight '''class freeFall''' | ||
+ | |||
+ | || The first line of a '''class''' defines its name. | ||
− | + | The name of this '''class '''is '''freeFall'''. | |
− | + | ||
|- | |- | ||
|| Highlight '''end freeFall;''' | || Highlight '''end freeFall;''' | ||
− | || Every '''class''' must have an ''' | + | || Every '''class''' must have an '''end statement''' to indicate where the '''class''' ends. |
|- | |- | ||
|| | || | ||
− | || This '''class '''has '''variable declarations '''and '''equations'''. Let | + | || This '''class '''has '''variable declarations '''and '''equations'''. |
+ | |||
+ | |||
+ | Let me show you how to declare '''variables'''. | ||
|- | |- | ||
|| '''Real''' h(start = 30, unit = “m”) | || '''Real''' h(start = 30, unit = “m”) | ||
− | || | + | || '''Real''' represents '''data-type'''. |
|- | |- | ||
|| Highlight '''h''' (start = 30, unit = “m”) | || 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”); | || Real h ('''start = 30''', unit = “m”); | ||
− | || | + | || '''start''' attribute specifies the initial value of a '''variable'''. |
− | + | The initial value of '''h''' is 30 units. | |
− | + | ||
− | + | ||
− | The | + | |
|- | |- | ||
|| Real h ( start = 30, '''unit = “m”'''); | || Real h ( start = 30, '''unit = “m”'''); | ||
− | || ''' | + | || '''unit attribute''' specifies the unit of a '''variable'''. |
− | ''' | + | The unit of '''h''' is '''metre'''. |
|- | |- | ||
− | || Real h(start = 30, unit = “m”) | + | || Real h(start = 30, unit = “m”); ''' |
|| Every '''variable declaration''' must end with a '''semi-colon.''' | || Every '''variable declaration''' must end with a '''semi-colon.''' | ||
|- | |- | ||
|| '''Real v''' (start = 0, unit = “m/s”); | || '''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”);''' | || Real v '''(start = 0, unit = “m/s”);''' | ||
− | || The initial value of | + | || The initial value of '''v''' is zero. Its unit is '''meter per second.''' |
|- | |- | ||
|| parameter '''Real g''' (unit = m/s2) = -9.81; | || parameter '''Real g''' (unit = m/s2) = -9.81; | ||
− | || ''' | + | || '''g'''represents '''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; | || 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;''' | || parameter Real g(unit = m/s2) = '''-9.81;''' | ||
− | || The value of ''' | + | || The value of '''g''' remains constant throughout the simulation run, with a value of 9.81. |
+ | |||
+ | |||
+ | The negative sign is due to sign convention used. | ||
|- | |- | ||
|| parameter Real g(unit = m/s2) = -9.81 '''“Acceleration due to gravity”''' | || parameter Real g(unit = m/s2) = -9.81 '''“Acceleration due to gravity”''' | ||
− | || The text in double quotes is a '''comment'''. | + | || The text in double quotes is a '''comment''' written with the declaration of '''g'''. |
− | '''Comments '''provide information about the program. They are also useful for documentation. | + | '''Comments '''provide useful information about the program. They are also useful for documentation. |
|- | |- | ||
|| | || | ||
− | || | + | || Now, let me go back to the slides. |
|- | |- | ||
Line 315: | Line 357: | ||
Variable and Parameter declaration | Variable and Parameter declaration | ||
− | || ''' | + | || '''parameter''' is a quantity that remains constant in a simulation run. |
− | ''' | + | '''Real, Integer, Boolean''' and''' String data-types''' are supported in '''Modelica'''. |
+ | |- | ||
+ | ||Highlight | ||
+ | ||'''start''' and '''unit attributes''' have already been defined. | ||
− | |||
+ | '''min attribute''' specifies the minimum value of a '''variable'''. | ||
− | |||
− | + | Similarly, '''max attribute''' specifies the maximum value of a '''variable'''. | |
− | ''' | + | |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | || | + | || Go back to '''OMEdit''' |
− | || Let | + | || Let me go back to '''OMEdit.''' |
|- | |- | ||
Line 340: | Line 380: | ||
'''equation''' | '''equation''' | ||
− | || '''‘equation’ '''signifies the beginning of equation section of a '''class'''. | + | || '''‘equation’ '''signifies the beginning of '''equation section''' of a '''class'''. |
|- | |- | ||
− | || / | + | || /* Equations of motion */ |
− | || This is | + | || This is an alternative way of inserting '''comments'''. |
|- | |- | ||
Line 350: | Line 390: | ||
'''der(v) = g;''' | '''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(h)''' = '''v'''; | ||
− | || ''' | + | || '''der()''' is '''Modelica function''' for '''time derivative'''. |
Line 361: | Line 401: | ||
|- | |- | ||
|| '''der(v)''' = '''g'''; | || '''der(v)''' = '''g'''; | ||
− | || '''der(v)''' represents '''dv/dt.''' | + | || And '''der(v)''' represents '''dv/dt.''' |
|- | |- | ||
− | || '''der(v) = g''' | + | || '''der(v) = g'''; |
− | || Every equation | + | || Every '''equation''' must end with a '''semi-colon'''. |
|- | |- | ||
− | || Click on | + | || Click on '''simulate''' button |
− | || Let | + | || Let me show you how to simulate this '''class'''. |
− | + | Click on '''simulate''' button in the '''toolbar'''. | |
|- | |- | ||
− | || | + | || Close the pop-up |
− | || Close the | + | || Close the pop-up window. |
|- | |- | ||
|| Plotting perspective | || Plotting perspective | ||
− | || This window is known as | + | || This window is known as the '''Plotting perspective'''. |
− | |||
− | + | On successful simulation of a '''class, Plotting perspective''' opens automatically. | |
− | + | ||
|- | |- | ||
|| Variables browser | || 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'''. | ||
− | |||
+ | '''Unit''' column specifies '''units''' of '''variables,''' as defined using '''Unit''' attribute. | ||
− | + | |- | |
+ | || | ||
+ | ||'''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'''. | ||
− | |||
+ | Select '''h'''. | ||
− | + | |- | |
+ | || | ||
+ | ||This generates the plot of '''h with respect to time''' - | ||
+ | * with '''h''' on '''y-axis''' | ||
+ | * and '''time''' on the '''x-axis''' | ||
|- | |- | ||
− | || | + | || |
− | || | + | ||By default, the simulation is run from 0 to 1 unit of time. |
− | + | The unit of '''time''' depends on the system of '''units''' used for other variables. | |
+ | |- | ||
+ | || 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'''. | ||
− | |||
− | + | The result has now been deleted. | |
− | + | ||
− | + | ||
− | + | ||
− | The | + | |
|- | |- | ||
− | || | + | || Click on '''Modeling perspective''' button at bottom right. |
− | || Let me | + | || Let me go back to '''Modeling perspective'''. |
− | |||
− | |||
− | |||
− | Click on Modeling | + | Click on '''Modeling''' button at bottom-right. |
|- | |- | ||
|| '''class''' freeFall | || '''class''' freeFall | ||
− | || | + | || '''class''' is used synonymously with '''model,''' in '''Modelica'''. |
− | + | One may use '''model''' instead of '''class''' here, to produce the same effect. | |
|- | |- | ||
− | || | + | || |
− | || | + | || 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'''. | ||
− | + | This generates '''h''' v/s '''time''' plot. | |
|- | |- | ||
− | || | + | || |
− | || | + | ||Notice that the time interval has increased to 5 units. |
− | + | But, the value of '''h''' has gone below zero, which is unacceptable. | |
+ | |- | ||
+ | || | ||
+ | ||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. |
− | + | This '''class''' has two variables and two equations. | |
|- | |- | ||
Line 483: | Line 549: | ||
and delete it. | and delete it. | ||
− | || | + | ||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'''. | ||
− | |||
+ | Notice that a star appears beside the name of the '''class''' in '''freeFall''' tab. | ||
− | + | This indicates unsaved changes in the '''class'''. | |
− | + | Hence it is a good practice to save a '''class''' after a change has been made. | |
+ | |- | ||
+ | || | ||
+ | ||To save this '''class, ''' go to the '''File menu''' and click on '''Save'''. | ||
− | |||
+ | You may also use the '''Save''' button in '''toolbar''', which my cursor points to, to save a file. | ||
− | + | |- | |
+ | ||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'''. | ||
− | |||
− | + | It says, there are too few equations and the model has 1 '''equation''' and 2 '''variables'''. Hence this cannot be simulated. | |
− | + | ||
|- | |- | ||
|| | || | ||
− | || Let me insert the equation back in its place and click on '''Save'''. | + | || 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. | ||
|- | |- | ||
|| | || | ||
Line 517: | Line 602: | ||
Equations in Modelica | Equations in Modelica | ||
− | || '''“der()”''' | + | || '''“der()”''' is '''Modelica''' function for '''time derivative'''. |
− | There is no data flow direction for equations. | + | There is no data flow direction for '''equations'''. |
− | For example, '''der(h) = v''' may be written as '''v = der(h)'''. | + | For example, '''der(h) = v''' may also be written as '''v = der(h)'''. |
− | + | '''Initial equations section''' is used to enter initial conditions. | |
− | We shall learn more about''' | + | |
+ | We shall learn more about '''Initial equation''' later on. | ||
|- | |- | ||
Line 534: | Line 620: | ||
Assignment | Assignment | ||
− | || As an assignment, write a model to simulate the differential equation | + | || As an assignment, write a '''model''' to simulate the '''differential equation''' |
* '''dx/dt = -a*x ''' | * '''dx/dt = -a*x ''' | ||
* where '''a = 1''', | * where '''a = 1''', | ||
− | * '''x''' | + | * '''x''' belongs to '''R''' |
− | * and the value of x at time '''t=0''' is '''5''' | + | * and the value of x at time '''t=0''' is '''5''' |
|- | |- | ||
Line 549: | Line 635: | ||
About the Spoken Tutorial project | About the Spoken Tutorial project | ||
− | || | + | || Watch the video at the following link. It summarizes the Spoken Tutorial project. |
− | |||
|- | |- | ||
|| Slide: | || Slide: | ||
Spoken Tutorial Workshops | Spoken Tutorial Workshops | ||
− | || We conduct workshops using spoken tutorials | + | || We conduct workshops using spoken tutorials; give certificates. |
Line 565: | Line 650: | ||
Acknowledgements | Acknowledgements | ||
− | || Spoken Tutorial project is funded by NMEICT, MHRD, Government of India. | + | || '''Spoken Tutorial project''' is funded by NMEICT, MHRD, Government of India. |
|- | |- | ||
Line 571: | Line 656: | ||
Thanks | Thanks | ||
− | || We thank | + | || We thank the development team of '''OpenModelica''' for their support. |
+ | |||
|- | |- | ||
|| | || | ||
− | || Thank you | + | || Thank you. |
|- | |- | ||
|} | |} |
Latest revision as of 18:00, 24 February 2016
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. |