OpenModelica/C3/Component-oriented-modeling/English
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:
|
Slide:
System Requirements |
To record this tutorial, I am using:
|
Slide:
Prerequisites |
To understand and practice this tutorial, you need to know
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:
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
|
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.
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.
| |
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.
|
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.
|
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.
Note that this package has five classes named:
Double-click on simpleElectricCircuit. Close ClassinstantiationExample.
|
//
import Modelica.SIunits.* // |
Modelica.SIunits package has been imported in the package simpleElectricCircuit.
|
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.
|
// 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.
|
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.
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.
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.
| |
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.
|
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.
|
The class has simulated successfully.
| |
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. |