- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Connect two differential equations in...
Connect two differential equations in model - How?
Connect two differential equations in model - How?
Hello!
Can someone show me how to connect two differential equation? Let's say I got two classes, mass with the differential equation F = m*a and the other class, spring with the differential equation F = k*x. k = spring stiffness and x = the length. m = mass in Kg and a = acceleration in m/s^2.
So i got two classes. Now I want to connect thoose two in a model so it will become a mass-spring system. How do I do that?
The purpose with this question is that I want to modleing with differential equation from classes into a model.
Re: Connect two differential equations in model - How?
To connect classes or models, you should use ports.
- Ports will exchange information between the two classes you've defined based on how you've connected them.
- You can define your own ports or use the ports existing in the Standard library.
- knkc
- 14 Posts
Re: Connect two differential equations in model - How?
You can see some examples here:
http://spoken-tutorial.org/tutorial-sea … ge=English (also linked from our first www.openmodelica.org) page.
- adrpo
- 885 Posts
Re: Connect two differential equations in model - How?
knkc wrote:
To connect classes or models, you should use ports.
- Ports will exchange information between the two classes you've defined based on how you've connected them.
- You can define your own ports or use the ports existing in the Standard library.
Can you show me an exemple?
Let say that you do a RLC-circuit and every component has its own dynamic system.
Re: Connect two differential equations in model - How?
adrpo wrote:
You can see some examples here:
http://spoken-tutorial.org/tutorial-sea … ge=English (also linked from our first www.openmodelica.org) page.
Thank you. But that Indian didin't show compleatly how to develop classes, who contain an ODE, and then connect them all.
Re: Connect two differential equations in model - How?
For examples look into the Modelica Standard Libraries (MSL).
Have a look in Modelica.Mecanics.Translational.
Look inside:
- Modelica.Mecanics.Translational.Interfaces for connectors
- Modelica.Mecanics.Components for components (have a look how they extend the Interfaces)
- Modelica.Mecanics.Examples.Damper on how for example Mass and Spring are are connected together
You can read a bit more about Modelica, for example:
http://book.xogeny.com/
- adrpo
- 885 Posts
Re: Connect two differential equations in model - How?
This is how you define a port
connector Electrical_port
import Modelica.SIunits.*;
Voltage v "Potential at the pin" ;
flow Current i ;
end Electrical_port;
After you've defined a port. drag and drop this port in the resistor model. And you can code a simple resistor model with the equation V = I*R as shown below
model Resistor
import Modelica.SIunits.*;
Voltage v ;
Current i "Current flowing from pin p to pin n";
parameter Resistance R (start=1)
"Resistance at temperature T_ref";
Electrical_port p annotation(
Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Electrical_port n annotation(
Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
v = p.v - n.v;
0 = p.i + n.i;
i = p.i;
v = R*i;
end Resistor;
Likewise, you can create a similar model for inductor and capacitor. Once the ports are in place you can drag and drop all these classes in a model and connect them as you want and you can run the simulation.
Hope this helps for more information you can refer the link given by adrpo
- knkc
- 14 Posts
Re: Connect two differential equations in model - How?
knkc wrote:
This is how you define a port
connector Electrical_port
import Modelica.SIunits.*;
Voltage v "Potential at the pin" ;
flow Current i ;
end Electrical_port;
After you've defined a port. drag and drop this port in the resistor model. And you can code a simple resistor model with the equation V = I*R as shown below
model Resistor
import Modelica.SIunits.*;
Voltage v ;
Current i "Current flowing from pin p to pin n";
parameter Resistance R (start=1)
"Resistance at temperature T_ref";
Electrical_port p annotation(
Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Electrical_port n annotation(
Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
v = p.v - n.v;
0 = p.i + n.i;
i = p.i;
v = R*i;
end Resistor;
Likewise, you can create a similar model for inductor and capacitor. Once the ports are in place you can drag and drop all these classes in a model and connect them as you want and you can run the simulation.
Hope this helps for more information you can refer the link given by adrpo
So I need to use openmodelica SI-units and packages If I want to connect ODE's ? Or else it won't work?
Re: Connect two differential equations in model - How?
No. import Modelica.SIunits.*; only imports the units of the variables that I use.
->If you expand the standard Modelica library you'll find in the end SI units package.
-> In the SI units package all the commonly used units are defined.
-> So instead of defining the units of the variables that I would use every time, I import the same as most of them are already defined in the SI units package.
If you want to define your own units for a variable you can do it like this
parameter Real v (unit = "m/s");
alternately
parameter Modelica.SIunits.Velocity v;
or
import Modelica.SIunits.*;
parameter Velocity v;
or
import SI = Modelica.SIunits;
parameter SI.Velocity v;
- knkc
- 14 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Connect two differential equations in...