Difference between revisions of "OpenModelica/C3/Component-oriented-modeling/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border=1 ||'''Visual Cue''' ||'''Narration''' |- || Slide: '''Title Slide''' || Welcome to the spoken tutorial on '''Component oriented modeling''' as a part of the serie...")
 
Line 7: Line 7:
  
 
'''Title Slide'''
 
'''Title Slide'''
|| Welcome to the spoken tutorial on '''Component oriented modeling''' as a part of the series on '''OpenModelica'''.
+
|| Welcome to the spoken tutorial on '''Component oriented modeling'''.
  
 
|-
 
|-
Line 16: Line 16:
  
 
* How to instantiate a '''model'''.
 
* How to instantiate a '''model'''.
* How to define a '''connector class'''.
+
* How to define '''connector class''' and
 
* How to develop model of a '''simple electric circuit''' using '''component models'''.
 
* How to develop model of a '''simple electric circuit''' using '''component models'''.
  
Line 26: Line 26:
  
 
* '''OpenModelica 1.9.2'''.
 
* '''OpenModelica 1.9.2'''.
* '''Ubuntu Linux''' Operating System version '''14.04'''.
+
* '''Ubuntu''' Operating System version '''14.04'''.
* But this process is identical in '''Windows, Mac OS X''' or '''FOSSEE OS''' on '''ARM'''.
+
* But this process is identical to any of the following operating systems.
  
 
|-
 
|-
Line 33: Line 33:
  
 
'''Prerequisites'''
 
'''Prerequisites'''
|| To understand and practise this tutorial, you need
+
|| To understand and practice this tutorial, you need to know
  
* knowledge of class definition in '''Modelica'''.
+
* how to define a class in '''Modelica'''.
* knowledge of how to define a '''package''' and '''Icon and Diagram Views'''.
+
* you need to know how to define a '''package''' and '''Icon and Diagram Views'''.
* Prerequisite tutorials are mentioned on our website.
+
 
 +
Prerequisite tutorials are mentioned on our website.
 +
 
 +
Please go through them.
  
 
|-
 
|-
Line 43: Line 46:
  
 
'''Class Instantiation'''
 
'''Class Instantiation'''
|| '''Modelica classes''' can be instantiated.
+
|| Now let us learn more about '''Class Instantiation'''.
 +
 +
'''Modelica classes''' can be instantiated.
  
 
For example, an individual can be considered an instance of human being '''class'''.
 
For example, an individual can be considered an instance of human being '''class'''.
  
 
+
'''Instance''' of a class has the same variables and equations as the class itself.
'''Instance''' of a class has the same variables equations and variables as the class.
+
  
 
|-
 
|-
Line 54: Line 58:
  
 
'''Syntax'''
 
'''Syntax'''
|| Here is the '''syntax''' for class instantiation.
+
|| The syntax for '''Class Instantiation''' is as shown.
  
 
|-
 
|-
Line 64: Line 68:
 
|-
 
|-
 
||  
 
||  
|| Let me switch to OMEdit.  
+
|| Let me switch to '''OMEdit'''.  
  
The following files are already open in OMEdit: '''classInstantiationExample''', '''simpleCircuit'''.
+
The following files are already open in '''OMEdit''':  
 +
 
 +
* '''classInstantiationExample''' and
 +
*'''simpleCircuit'''.
  
 
Double click on '''classInstantiationExample'''.  
 
Double click on '''classInstantiationExample'''.  
  
Let us discuss this class now.
+
Let us discuss more about this class now.
  
 
|-
 
|-
Line 76: Line 83:
  
 
'''bouncingBall Ball1(h(start = 40), h(start = 50));'''
 
'''bouncingBall Ball1(h(start = 40), h(start = 50));'''
|| Here, I have instantiated the '''bouncingBall''' class to create two objects named '''object1''' and '''object2'''.
+
|| Let me shift '''OMEdit''' window to the left for better visibility.
 +
 
 +
Here, I have instantiated the '''bouncingBall''' class to create two objects named  
  
Note that each instance has different start values for the variable '''h'''.  
+
* '''object1''' and
 +
* '''object2'''.  
  
Please refer prerequisite tutorials for more information on '''bouncingBall''' model.  
+
Note that each instance has different start values for the height variable '''h'''.  
  
Let me shift '''OMEdit''' window to the left.
+
Please refer prerequisite tutorials for more information on the '''bouncingBall''' model.  
  
 
|-
 
|-
Line 90: Line 100:
 
Click on '''Simulate''' button in the toolbar.  
 
Click on '''Simulate''' button in the toolbar.  
  
The class didn’t simulate and throws up an error.  
+
The class did not simulate and it threw up an error.  
  
 
This is because '''bouncingBall''' class is not open in '''OMEdit'''.
 
This is because '''bouncingBall''' class is not open in '''OMEdit'''.
Line 96: Line 106:
 
|-
 
|-
 
|| Load and Simulate
 
|| Load and Simulate
|| Open '''bouncingBall''' file which you downloaded from the website.  
+
|| Open '''bouncingBall''' class which you downloaded from the website.  
  
Now, simulate '''classInstantiationExample''' once again.  
+
Now, simulate this class once again.
 +
 
 +
Close the pop up window.
  
 
|-
 
|-
 
|| Click on the '''+''' button beside '''Ball1''' in '''variables browser'''.
 
|| Click on the '''+''' button beside '''Ball1''' in '''variables browser'''.
|| The class simulates successfully this time around.  
+
|| Note that the class simulates successfully this time around.  
  
 
This exercise demonstrates that a class should be open in '''OMEdit''' to be instantiated.
 
This exercise demonstrates that a class should be open in '''OMEdit''' to be instantiated.
  
Expand '''Ball1''' variables by clicking on '''+''' button beside '''Ball1''' in '''variables browser'''.
+
Expand '''object1''' variables in the '''variables browser'''.
  
 
|-
 
|-
 
||  
 
||  
|| Note that the variables of '''Ball1''' are listed here.
+
|| Note that the variables listed here are declared in '''bouncingBall''' class.  
 
+
These are variables declared in '''bouncingBall''' class.  
+
  
These variables are also part of '''Ball1''' since it is an instance of '''bouncingBall''' class.
+
These variables are also a part of '''object1''' and '''object2''' since the adjust instances of the '''bouncingBall''' class.
  
Let us delete the result and go back to the slides.
+
Now delete the result and go back to the slides.
  
 
|-
 
|-
Line 128: Line 138:
 
'''component''' models represent single physical phenomenon.
 
'''component''' models represent single physical phenomenon.
  
'''component''' models can be instantiated and connected to produce desired effect.
+
They can be instantiated and connected to produce desired effect.
  
For example, an '''RLC circuit''' could be developed from '''resistor, capacitor''' and '''inductor''' models.
+
For example, an '''RLC circuit''' could be developed from '''resistor, inductor''' and '''capacitor''' models.
  
 
|-
 
|-
Line 142: Line 152:
 
For example, '''pins''' can be used as connectors for electrical components.
 
For example, '''pins''' can be used as connectors for electrical components.
  
They contain '''across''' and '''flow''' variables.
+
We will learn more about this when we try to simulate the example for an electric circuit.
  
We will learn about '''across''' and '''flow''' variables while discussing the example.
+
'''Connectors''' content across and flow variables and
  
'''Connectors''' cannot contain equations.
+
they cannot contain equations.
  
 
|-
 
|-
Line 152: Line 162:
  
 
'''Circuit Diagram'''
 
'''Circuit Diagram'''
|| Now, let us simulate this Electric Circuit shown in slide.  
+
|| Now, let us simulate this Electric Circuit shown in the slide.  
  
The voltage of battery is '''10''' Volt and the resistance is '''5''' ohm.  
+
The voltage of battery is given by '''{Vo*Sin(2*pi*f*t)}''', where '''Vo''' is '''10''' Volts, '''f''' is '''1''' Hz and the resistance is '''5''' ohm.  
  
 
|-
 
|-
Line 160: Line 170:
  
 
'''Solution Methodology'''
 
'''Solution Methodology'''
|| Here is the solution methodology to model the electric circuit shown in previous slide:
+
|| Let us take a look at the '''Solution Methodology''' to model the electric circuit shown in previous slide:
  
 
Note that any Resistor and Voltage Source have two pins: '''Positive''' and '''Negative'''.
 
Note that any Resistor and Voltage Source have two pins: '''Positive''' and '''Negative'''.
  
 
* Hence, define a connector named '''pin'''.
 
* Hence, define a connector named '''pin'''.
 +
* Define a class named '''Ground''' with one instance of pin connector.
 
* Define a class named '''Resistor'''.
 
* Define a class named '''Resistor'''.
* Define a class named '''Ground'''.
+
* The '''Resistor''' class should have two instances of the pin connector: '''Positive''' pin and the '''Negative''' pin.
* '''Resistor''' class should have two instances of pin: '''Positive''' and '''Negative'''.
+
* Define a class named '''VoltageSource''' with two instances of '''pin''' connector as we have seen in the case of resistor class.
* Similarly, define a class named '''VoltageSource''' with two instances of '''pin''' connector.
+
 
* Define a class named '''simpleCircuit'''.  
 
* Define a class named '''simpleCircuit'''.  
* Create instances of '''Resistor''' and '''VoltageSource''' and connect them.
+
* '''simpleCircuit''' should have instances of '''Resistor''' and '''VoltageSource'''.
 
+
* Connect the respective pins of '''Resistor''', '''ground''' and the '''VoltageSource'''.
 
|-
 
|-
 
||  
 
||  
|| The component models required have aleady been programmed.  
+
|| The component models required have already been programmed.  
  
Hence, I shall demonstrate only the last two steps of Solution Methodology.
+
Hence, I shall demonstrate only the last two steps of '''Solution Methodology'''.  
 
+
A detailed explanation of '''Resistor''', '''VoltageSource''' and '''Ground''' models will be given in the next tutorial.
+
  
 
|-
 
|-
Line 184: Line 192:
 
|| Let me switch to '''OMEdit'''.  
 
|| Let me switch to '''OMEdit'''.  
  
Go back to '''Modeling perspective'''.
+
Go back to the '''Modeling perspective'''.
  
 
|-
 
|-
Line 190: Line 198:
 
|| Let me shift '''OMEdit''' window to the right.  
 
|| Let me shift '''OMEdit''' window to the right.  
  
Expand the package in '''Libraries Browser'''.  
+
Expand '''simpleElectricCircuit'''package in the '''Libraries Browser'''.  
  
Note that this package has five classes named '''pin''', '''Ground''', '''Resistor''', '''Voltage Source''' and '''circuit'''.
+
Note that this package has five classes named:
  
Double-click on '''simpleElectricCircuit''' to view this package.
+
* '''pin''',
 +
* '''Ground''',
 +
* '''Resistor''',
 +
* '''Voltage Source''' and
 +
* '''circuit'''.  
  
|-
+
Double-click on '''simpleElectricCircuit'''.
||
+
 
|| Open it in '''Text View''' if the file opens in either '''Icon or Diagram Views'''.
+
Close '''ClassinstantiationExample'''.
 +
 
 +
Let me shift '''OMEdit''' window to the left once again for better visibility.
  
 
|-
 
|-
Line 206: Line 220:
  
 
//
 
//
|| '''Modelica.SIunits''' package has been imported.
+
|| '''Modelica.SIunits''' package has been imported in the package '''simpleElectricCircuit'''.
  
 
Hence, type definitions in that package can be used without reference to their full names.
 
Hence, type definitions in that package can be used without reference to their full names.
Line 214: Line 228:
 
|| Let us try to understand '''pin''' connector.  
 
|| Let us try to understand '''pin''' connector.  
  
Scroll down a bit.
+
Scroll down a little bit.
  
 
|-
 
|-
Line 228: Line 242:
 
|| Potential at the pin is defined by '''v'''.  
 
|| Potential at the pin is defined by '''v'''.  
  
'''Voltage''' and '''Current''' are types defined in SIunits package.
+
'''Voltage''' and '''Current''' are types defined in '''SIunits''' package of modelica library.
  
 
|-
 
|-
 
|| // flow Current i; //
 
|| // flow Current i; //
|| '''Voltage''' across a component causes current to flow through it.
+
|| '''Voltage''' across a component causes a current to flow through it.
  
Hence, current is a '''flow''' variable and, is defined using '''flow''' keyword.
+
Hence, current is a '''flow''' variable and is defined using '''flow''' keyword.
  
 
|-
 
|-
 
|| // annotation(....); //
 
|| // annotation(....); //
|| '''pin''' connector has Icon view specified by annotations.
+
|| '''pin''' connector also has an '''Icon view''' specified by '''annotations''' as shown.
  
 
|-
 
|-
 
|| Scroll down to '''Resistor''' class
 
|| Scroll down to '''Resistor''' class
|| Let us discuss a little about '''Resistor''' class.  
+
|| Now let us discuss a little about '''Resistor''' class.  
  
 
Scroll down a little more.
 
Scroll down a little more.
Line 251: Line 265:
 
pin n ann(...); //
 
pin n ann(...); //
 
|| As discussed in the '''Solution Methodology''', '''Resistor''' class has two instances of '''pin''' connector.
 
|| As discussed in the '''Solution Methodology''', '''Resistor''' class has two instances of '''pin''' connector.
 +
 +
'''p''' stands for positive pin and
 +
 +
'''n''' stands for negative pin.
  
 
|-
 
|-
Line 268: Line 286:
 
|-
 
|-
 
||  
 
||  
|| Go to '''Diagram View'''.
+
|| Go to '''Diagram View''' if the class opens in '''Text View'''.
  
 
|-
 
|-
 
|| Drag and Drop '''pin''' icon in '''Libraries Browser'''.
 
|| Drag and Drop '''pin''' icon in '''Libraries Browser'''.
|| Left click on '''pin''' icon in '''Libraries Browser'''.  
+
|| Now let me instantiate '''pin''' class.
 +
 
 +
Left click on '''pin''' icon in '''Libraries Browser'''.  
  
 
Hold and drag the icon to the diagram layer.  
 
Hold and drag the icon to the diagram layer.  
Line 284: Line 304:
 
|-
 
|-
 
||  
 
||  
|| Let’s see how the class is instantiated in '''Text View'''.
+
|| Now let us see how this class is instantiated in '''Text View'''.
 +
 
 +
Go to '''Text View'''.
  
 
|-
 
|-
 
|| // simpleElectricCircuit //
 
|| // simpleElectricCircuit //
|| Notice the command for instantiation of class '''pin''' and an annotation based on its placement in '''Diagram View'''.  
+
|| Notice the command for instantiation of class '''pin''' and an '''annotation''' based on its placement in '''Diagram View'''.
 +
 
 +
Hence, creating an instance of a class in '''Diagram View''' automatically reflects in the '''Text View'''.
 +
 
 +
Now let me close '''example1''' tab.
  
Hence, creating an instance of class in '''Diagram View''' automatically reflects in '''Text View'''.
+
Let us learn  how to model electric circuit that we saw in the slides.
  
 
|-
 
|-
Line 296: Line 322:
 
|| Double click on '''Circuit''' icon which is also a part of '''simpleElectricCircuit''' package.  
 
|| Double click on '''Circuit''' icon which is also a part of '''simpleElectricCircuit''' package.  
  
This class already has our circuit of interest assembled as seen in the '''Diagram View'''.  
+
This class already has our circuit of interest assembled as can be seen in its '''Diagram View'''.  
  
 
It is ready to be simulated.
 
It is ready to be simulated.
Line 302: Line 328:
 
|-
 
|-
 
||  
 
||  
|| Let us build the same circuit in a new file.  
+
|| But let us build the same circuit in a new file.  
  
We shall use '''drag and drop''' functionality that we’ve learnt about.  
+
We shall use '''drag and drop''' functionality that we have just learnt about.  
  
 
|-
 
|-
Line 311: Line 337:
  
 
Name this file '''circuit(underscore)construction'''.  
 
Name this file '''circuit(underscore)construction'''.  
 +
 +
Press '''OK'''.
  
 
|-
 
|-
Line 320: Line 348:
 
|| Select, drag and drop the '''VoltageSource''' icon from '''Libraries Browser'''.  
 
|| Select, drag and drop the '''VoltageSource''' icon from '''Libraries Browser'''.  
  
Change its dimensions as you wish.
+
You may change its dimensions as you wish.
  
 
|-
 
|-
Line 336: Line 364:
 
|-
 
|-
 
|| Hover over the left pin of Voltage Source.
 
|| Hover over the left pin of Voltage Source.
|| Let us first connect the positive pin of Voltage Source to Resistor.  
+
|| Let us first connect the positive pin of Voltage Source to the positive pin of Resistor.  
  
 
Hover over the left pin of '''Voltage Source'''.  
 
Hover over the left pin of '''Voltage Source'''.  
  
The text that appears indicates this is the positive pin '''p'''.  
+
The text that appears indicates that, this is the positive pin '''p'''.  
  
 
|-
 
|-
Line 354: Line 382:
 
|-
 
|-
 
|| Connections to Ground
 
|| Connections to Ground
|| We have not mentioned the connections with Ground in the circuit diagram.  
+
|| We have not mentioned the connections with '''Ground''' in the circuit diagram.  
  
 
But, we need to connect the negative pins of resistor and voltage source to ground individually.  
 
But, we need to connect the negative pins of resistor and voltage source to ground individually.  
Line 370: Line 398:
 
|| Click on '''Simulate''' button.  
 
|| Click on '''Simulate''' button.  
  
It has simulated successfully.  
+
Close the pop up window.
  
Shift '''OMEdit''' window to the left.
+
The class has simulated successfully.
 +
 
 +
Let me shift '''OMEdit''' window to the left for better visibility of '''variables browser'''.
  
 
|-
 
|-
Line 379: Line 409:
  
 
Note that the profile is sinusoidal as expected.
 
Note that the profile is sinusoidal as expected.
 +
 +
Since the voltage source is an '''AC''' source instead of '''DC'''.
  
 
|-
 
|-
 
||  
 
||  
|| Hence, we have created model from its component parts and simulated it.  
+
|| Hence, we have created a model from its component parts and simulated it.  
  
We shall learn more about the Resistor and Voltage Source classes in the next tutorial.
+
We shall learn more about the Resistor and Voltage Source classes that we used here in the next tutorial.
  
 
|-
 
|-
 
||  
 
||  
|| Let me switch back to the slides.  
+
|| Let me switch to the slides.  
  
 
This brings us to the end of this tutorial.
 
This brings us to the end of this tutorial.
Line 398: Line 430:
 
|| As an assignment, construct an electric circuit with two resistors in series with one voltage source.  
 
|| As an assignment, construct an electric circuit with two resistors in series with one voltage source.  
  
Use the component models for VoltageSource and Resistor.
+
Use the component models for Voltage source and Resistor provided in simple electric circuit package.
  
 
|-
 
|-
Line 404: Line 436:
  
 
About the '''Spoken Tutorial project'''
 
About the '''Spoken Tutorial project'''
|| Watch the video available at the link shown below:
+
|| Watch the video available at the following link:
  
 
[http://spoken-tutorial.org/ http][http://spoken-tutorial.org/ ://][http://spoken-tutorial.org/ spoken][http://spoken-tutorial.org/ -][http://spoken-tutorial.org/ tutorial][http://spoken-tutorial.org/ .][http://spoken-tutorial.org/ org] /What\_is\_a\_Spoken\_Tutorial
 
[http://spoken-tutorial.org/ http][http://spoken-tutorial.org/ ://][http://spoken-tutorial.org/ spoken][http://spoken-tutorial.org/ -][http://spoken-tutorial.org/ tutorial][http://spoken-tutorial.org/ .][http://spoken-tutorial.org/ org] /What\_is\_a\_Spoken\_Tutorial
  
It summarises the '''Spoken Tutorial project'''.
+
It summarises '''Spoken Tutorial project'''.
 
+
If you do not have good bandwidth, you can download and watch it.
+
  
 
|-
 
|-
Line 417: Line 447:
 
'''Spoken Tutorial''' Workshops
 
'''Spoken Tutorial''' Workshops
 
|| We conduct workshops using spoken tutorials.
 
|| We conduct workshops using spoken tutorials.
 
Give certificates.
 
  
 
Please contact us.
 
Please contact us.
Line 432: Line 460:
  
 
'''Textbook Companion Project'''
 
'''Textbook Companion Project'''
|| We coordinate coding of solved examples from popular books. Please visit our website.
+
|| We coordinate coding of solved examples of popular books.  
 +
 
 +
Please visit our website.
  
 
|-
 
|-
Line 454: Line 484:
 
|| We thank the development team of '''OpenModelica''' for their support.
 
|| We thank the development team of '''OpenModelica''' for their support.
  
|-
+
Thank you.
||
+
|| Thank you.
+

Revision as of 12:28, 22 March 2016

Visual Cue Narration
Slide:

Title Slide

Welcome to the spoken tutorial on Component oriented modeling.
Slide:

Learning Objectives

In this tutorial, we are going to learn:
  • How to instantiate a model.
  • How to define connector class and
  • How to develop model of a simple electric circuit using component models.
Slide:

System Requirements

To record this tutorial, I am using:
  • OpenModelica 1.9.2.
  • Ubuntu Operating System version 14.04.
  • But this process is identical to any of the following operating systems.
Slide:

Prerequisites

To understand and practice this tutorial, you need to know
  • how to define a class in Modelica.
  • you need to know how to define a package and Icon and Diagram Views.

Prerequisite tutorials are mentioned on our website.

Please go through them.

Slide:

Class Instantiation

Now let us learn more about Class Instantiation.

Modelica classes can be instantiated.

For example, an individual can be considered an instance of human being class.

Instance of a class has the same variables and equations as the class itself.

Slide:

Syntax

The syntax for Class Instantiation is as shown.
Now, let us understand this through an example.

Please download and save all the files available on our website.

Let me switch to OMEdit.

The following files are already open in OMEdit:

  • classInstantiationExample and
  • simpleCircuit.

Double click on classInstantiationExample.

Let us discuss more about this class now.

/* classInstantiationExample */

bouncingBall Ball1(h(start = 40), h(start = 50));

Let me shift OMEdit window to the left for better visibility.

Here, I have instantiated the bouncingBall class to create two objects named

  • object1 and
  • object2.

Note that each instance has different start values for the height variable h.

Please refer prerequisite tutorials for more information on the bouncingBall model.

Click on Simulate button. Let us simulate this class now.

Click on Simulate button in the toolbar.

The class did not simulate and it threw up an error.

This is because bouncingBall class is not open in OMEdit.

Load and Simulate Open bouncingBall class which you downloaded from the website.

Now, simulate this class once again.

Close the pop up window.

Click on the + button beside Ball1 in variables browser. Note that the class simulates successfully this time around.

This exercise demonstrates that a class should be open in OMEdit to be instantiated.

Expand object1 variables in the variables browser.

Note that the variables listed here are declared in bouncingBall class.

These variables are also a part of object1 and object2 since the adjust instances of the bouncingBall class.

Now delete the result and go back to the slides.

Slide:

Component orientation

Component orientation sets Modelica apart from other modeling and simulation softwares.

It is the single most important feature of Modelica.

component models represent single physical phenomenon.

They can be instantiated and connected to produce desired effect.

For example, an RLC circuit could be developed from resistor, inductor and capacitor models.

Slide:

Acausal connectors

Acausal connectors serve as the interface between component instances.

They are defined using connector class.

For example, pins can be used as connectors for electrical components.

We will learn more about this when we try to simulate the example for an electric circuit.

Connectors content across and flow variables and

they cannot contain equations.

Slide:

Circuit Diagram

Now, let us simulate this Electric Circuit shown in the slide.

The voltage of battery is given by {Vo*Sin(2*pi*f*t)}, where Vo is 10 Volts, f is 1 Hz and the resistance is 5 ohm.

Slide:

Solution Methodology

Let us take a look at the Solution Methodology to model the electric circuit shown in previous slide:

Note that any Resistor and Voltage Source have two pins: Positive and Negative.

  • Hence, define a connector named pin.
  • Define a class named Ground with one instance of pin connector.
  • Define a class named Resistor.
  • The Resistor class should have two instances of the pin connector: Positive pin and the Negative pin.
  • Define a class named VoltageSource with two instances of pin connector as we have seen in the case of resistor class.
  • Define a class named simpleCircuit.
  • simpleCircuit should have instances of Resistor and VoltageSource.
  • Connect the respective pins of Resistor, ground and the VoltageSource.
The component models required have already been programmed.

Hence, I shall demonstrate only the last two steps of Solution Methodology.

Let me switch to OMEdit.

Go back to the Modeling perspective.

Click on the plus button beside simpleElectricCircuit in Libraries Browser. Let me shift OMEdit window to the right.

Expand simpleElectricCircuitpackage in the Libraries Browser.

Note that this package has five classes named:

  • pin,
  • Ground,
  • Resistor,
  • Voltage Source and
  • circuit.

Double-click on simpleElectricCircuit.

Close ClassinstantiationExample.

Let me shift OMEdit window to the left once again for better visibility.

//

import Modelica.SIunits.*

//

Modelica.SIunits package has been imported in the package simpleElectricCircuit.

Hence, type definitions in that package can be used without reference to their full names.

Scroll down Let us try to understand pin connector.

Scroll down a little bit.

// connector pin // Pin is defined using connector class.
Voltage and current are the variables that a pin exchanges with its surroundings.
// Voltage v; // Potential at the pin is defined by v.

Voltage and Current are types defined in SIunits package of modelica library.

// flow Current i; // Voltage across a component causes a current to flow through it.

Hence, current is a flow variable and is defined using flow keyword.

// annotation(....); // pin connector also has an Icon view specified by annotations as shown.
Scroll down to Resistor class Now let us discuss a little about Resistor class.

Scroll down a little more.

// pin p ann(...);

pin n ann(...); //

As discussed in the Solution Methodology, Resistor class has two instances of pin connector.

p stands for positive pin and

n stands for negative pin.

Now, let me show you how to instantiate a class using the drag and drop functionality of OMEdit.
Press Ctrl + N To demonstrate that, let me open a new class using Ctrl + N.
Type example in the name field. Name this class example1 and press Ok.

Shift OMEdit window to the right.

Go to Diagram View if the class opens in Text View.
Drag and Drop pin icon in Libraries Browser. Now let me instantiate pin class.

Left click on pin icon in Libraries Browser.

Hold and drag the icon to the diagram layer.

Drop it at any location on the canvas.

We have now created an instance of pin class.

You may also change the dimensions and location after dropping it as shown.

Now let us see how this class is instantiated in Text View.

Go to Text View.

// simpleElectricCircuit // Notice the command for instantiation of class pin and an annotation based on its placement in Diagram View.

Hence, creating an instance of a class in Diagram View automatically reflects in the Text View.

Now let me close example1 tab.

Let us learn how to model electric circuit that we saw in the slides.

Double click on Circuit icon which is also a part of simpleElectricCircuit package.

This class already has our circuit of interest assembled as can be seen in its Diagram View.

It is ready to be simulated.

But let us build the same circuit in a new file.

We shall use drag and drop functionality that we have just learnt about.

Press Ctrl + N.

Name this file circuit(underscore)construction.

Press OK.

Click on Diagram View. Switch to Diagram View if it opens in Text View.
Select, drag and drop Voltage Source Select, drag and drop the VoltageSource icon from Libraries Browser.

You may change its dimensions as you wish.

Select, drag and drop Resistor. Similarly, select, drag and drop the Resistor icon from Libraries Browser.
Select, drag and drop Ground. Do the same with Ground class.
Now, we need to connect the respective pins of each component.
Hover over the left pin of Voltage Source. Let us first connect the positive pin of Voltage Source to the positive pin of Resistor.

Hover over the left pin of Voltage Source.

The text that appears indicates that, this is the positive pin p.

Connect the positive pin of voltage source to positive pin of resistor. Left click on this pin and drag the cursor closer to the left pin of Resistor.

Leave the mouse when the appearance of cursor changes to cross from an arrow.

Connect the negative pin of voltage source to negative pin of resistor. Similarly, connect the negative pin of resistor to the negative pin of voltage source.
Connections to Ground We have not mentioned the connections with Ground in the circuit diagram.

But, we need to connect the negative pins of resistor and voltage source to ground individually.

This ensures a reference point for potential in the circuit.

Press Ctrl + S Now, this class is complete.

Save the class by pressing Ctrl + S.

Click on Simulate button. Click on Simulate button.

Close the pop up window.

The class has simulated successfully.

Let me shift OMEdit window to the left for better visibility of variables browser.

Expand Resistor column in Variables Browser and select Ir. Expand Resistor column in the Variables Browser and select Ir.

Note that the profile is sinusoidal as expected.

Since the voltage source is an AC source instead of DC.

Hence, we have created a model from its component parts and simulated it.

We shall learn more about the Resistor and Voltage Source classes that we used here in the next tutorial.

Let me switch to the slides.

This brings us to the end of this tutorial.

Slide:

Assignment

As an assignment, construct an electric circuit with two resistors in series with one voltage source.

Use the component models for Voltage source and Resistor provided in simple electric circuit package.

Slide:

About the Spoken Tutorial project

Watch the video available at the following link:

http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial

It summarises Spoken Tutorial project.

Slide:

Spoken Tutorial Workshops

We conduct workshops using spoken tutorials.

Please contact us.

Slide:

Forum to answer questions

If you have questions from this tutorial, please visit the website mentioned below.
Slide:

Textbook Companion Project

We coordinate coding of solved examples of popular books.

Please visit our website.

Slide:

Lab Migration Project

We help migrate commercial simulator labs to OpenModelica.

Please visit the following website for more information.

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.

Contributors and Content Editors

Kaushik Datta, Nancyvarkey