OpenModelica/C3/Component-oriented-modeling/English
Visual Cue | Narration |
Slide:
Title Slide |
Welcome to the spoken tutorial on Component oriented modeling as a part of the series on OpenModelica. |
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 practise this tutorial, you need
|
Slide:
Class Instantiation |
Modelica classes can be instantiated.
For example, an individual can be considered an instance of human being class.
|
Slide:
Syntax |
Here is the syntax for class instantiation. |
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, simpleCircuit. Double click on classInstantiationExample. Let us discuss this class now. | |
/* classInstantiationExample */
bouncingBall Ball1(h(start = 40), h(start = 50)); |
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 variable h. Please refer prerequisite tutorials for more information on bouncingBall model. Let me shift OMEdit window to the left. |
Click on Simulate button. | Let us simulate this class now.
Click on Simulate button in the toolbar. The class didn’t simulate and throws up an error. This is because bouncingBall class is not open in OMEdit. |
Load and Simulate | Open bouncingBall file which you downloaded from the website.
Now, simulate classInstantiationExample once again. |
Click on the + button beside Ball1 in variables browser. | The class simulates successfully this time around.
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. |
Note that the variables of Ball1 are listed here.
These are variables declared in bouncingBall class. These variables are also part of Ball1 since it is an instance of bouncingBall class. Let us 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. component models can be instantiated and connected to produce desired effect. For example, an RLC circuit could be developed from resistor, capacitor and inductor 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. They contain across and flow variables. We will learn about across and flow variables while discussing the example. Connectors cannot contain equations. |
Slide:
Circuit Diagram |
Now, let us simulate this Electric Circuit shown in slide.
The voltage of battery is 10 Volt and the resistance is 5 ohm. |
Slide:
Solution Methodology |
Here is 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 aleady been programmed.
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. | |
Let me switch to OMEdit.
Go back to Modeling perspective. | |
Click on the plus button beside simpleElectricCircuit in Libraries Browser. | Let me shift OMEdit window to the right.
Expand the package in Libraries Browser. Note that this package has five classes named pin, Ground, Resistor, Voltage Source and circuit. Double-click on simpleElectricCircuit to view this package. |
Open it in Text View if the file opens in either Icon or Diagram Views. | |
//
import Modelica.SIunits.* // |
Modelica.SIunits package has been imported.
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 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. |
// flow Current i; // | Voltage across a component causes current to flow through it.
Hence, current is a flow variable and, is defined using flow keyword. |
// annotation(....); // | pin connector has Icon view specified by annotations. |
Scroll down to Resistor class | 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. | |
Drag and Drop pin icon in Libraries Browser. | 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. |
Let’s see how the class is instantiated in 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 class in Diagram View automatically reflects in Text View. |
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. It is ready to be simulated. | |
Let us build the same circuit in a new file.
We shall use drag and drop functionality that we’ve 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.
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 Resistor.
Hover over the left pin of Voltage Source. The text that appears indicates 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.
It has simulated successfully. Shift OMEdit window to the left. |
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. |
Hence, we have created model from its component parts and simulated it.
We shall learn more about the Resistor and Voltage Source classes in the next tutorial. | |
Let me switch back 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 VoltageSource and Resistor. |
Slide:
About the Spoken Tutorial project |
Watch the video available at the link shown below:
http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial It summarises the Spoken Tutorial project. If you do not have good bandwidth, you can download and watch it. |
Slide:
Spoken Tutorial Workshops |
We conduct workshops using spoken tutorials.
Give certificates. 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 from 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. |