Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » knkc
  • » Profile

Posts

Posts

Nov-24-17 04:59:38
Please help me correct the errors in my code. Thanks.

I've been trying to learn to use the media library in Modelica. When I try to use the function setState_pTX and the run the model below it throws an error that says
" Function Modelica.Media.Interfaces.PartialMedium.setState_pTX is neither external nor has an algorithm. It should have been redeclared."
Please tell me how to properly declare the function. Thanks.

model Media
  import Modelica.SIunits.*;
    replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
                         "Medium model" annotation (__Dymola_choicesAllMatching = true);
                        Medium.ThermodynamicState state;
                        parameter Pressure Pair = 1e5;
                        parameter Temperature Tair = 25+273.15;


equation
  state = Modelica.Media.Interfaces.PartialMedium.setState_pTX(Pair, Tair,Medium.reference_X);
end Media;








Feb-07-17 03:48:52
How can the 'x' variable be defined independently of time ? (x=from 0 to 10 for example)

Yes, modelica can solve linear equations. But to solve linear equations, the number of unknowns should be equal to the number of equations. In your model x and y are the unknown variables. And "y = a*x +b" is the only equation. So there are two unknowns and only one equation. You should either define one of the two unknown variables or give another equation.
for eg:


model Linear

parameter Real a=2;
parameter Real b=1;

parameter Real y = 9;                 
Real x;

equation

y=a*x + b;


end Linear;
or


model Linear

parameter Real a=2;
parameter Real b=1;

Real y;
Real x;

equation

y=a*x + b;
y = b*x + a;


end Linear;

Feb-02-17 06:04:38
My model works fine in Dymola but when I run in OM it throws an error.

I've got a model that works fine in Dymola but when I try to run the same thing in open Modelica it throws this error message at me.

assert | debug | <p>Invalid root: (-7.41609)^(0.62)</p>
assert | info | <p>simulation terminated by an assertion at initialization</p>

The equation that has such a root doesn't have any negative values, i.e. all the R.H.S values in the equations given below are inputs and none of them are negative. I'm not sure why there would be such an invalid root as what is mentioned in the error message. 

   Refp[j] = if j == 1 then mdot * D / (A * Mu_hc) else mdot * D / (A * Mu_l[j - 1]);
   f_fp[j]  = 17.24 / Refp[j] ^ 0.62;

Any suggestions on how to debug this error are welcome. Thanks in advance.

Jan-23-17 12:10:33
Category: Workshops
Jan-23-17 11:43:09
I'm looking for paid consultants to create mechanical or hydraulic and electric models in...

Please check your mail I've sent you the file.

The user interface of Dymola is much better indeed. But the latest version of OM is much better than its older versions and is more stable. Yeah, openmodelica throws far more events and simulation failures that Dymola does.

I'm an electrical engineer.I  use Modelica to build system models for motors, Heat exchangers, for system design etc.
I'm currently developing a library for simulating the thermodynamic performance of a domestic refrigerator. It has components such as heat exchangers, capillary tubes, motor, compressor etc.

Jan-23-17 10:11:19
I'm looking for paid consultants to create mechanical or hydraulic and electric models in...

I used to work on Dymola before since a past couple of months I'm working on OM. I'll send you the file in a while.

Jan-23-17 09:54:21
I'm looking for paid consultants to create mechanical or hydraulic and electric models in...

I've never tried running that model in openmodelica but I'm sure it would work fine. Like I said, the only issue I had when I import the models in Openmodelica is the ports.

Jan-23-17 09:45:28
I'm looking for paid consultants to create mechanical or hydraulic and electric models in...

I've had some issues with the connectors when I tried to import the models that were created in Dymola into openmodelica. Besides that, I've seen no major issues with the models so far. The example that is shown looks like a simple circuit. I've so far modeled only thermodynamic and electrical circuits.

https://openmodelica.org/images/agorapro/attachments/5496/mini_Picture1.png

https://openmodelica.org/images/agorapro/attachments/5496/mini_Inverter.jpg

Jan-23-17 07:02:40
I'm looking for paid consultants to create mechanical or hydraulic and electric models in...

Hi, I do the same kind of a job,
I am currently working on creating heat exchanger models for domestic refrigeration.
I am interested in creating electric models.
If you can give me more details, I can tell you for sure if I'd be able to take it up.
You can email me at chaitanya.kancherla@hotmail.com

Thanks, jez
When I run the model on Open modelica and it still shows me the error for the code given above. Anyway, I found a fix for it.


model Test
parameter Real a[2] = {16,14};
parameter Real b = 15, c =2 ;
Real x,y;
algorithm
for i in 1:2 loop
x := if a[i] < b and a[i] > c then (a[i] - c)/(b-c) else 0;
y := noEvent(if x > 0 then ((1-x)/x)^0.5 else 0);
end for;
end Test;

This works just fine now.

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;

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

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.

When I try to run the simulation for individual values of 'a' (i.e. a[1] = 16 and 1[2] = 14) seperately the program works fine. But when I try to loop the same with using the program below it shows an error that says "division by zero (1-x)/x". Please tell me what I'm doing wrong. Thanks.

model Test
parameter Real a[2] = {16,14};
parameter Real b = 15, c =2 ;
Real x,y;
algorithm
for i in 1:2 loop
x := if a[i] < b and a[i] > c then (a[i] - c)/(b-c) else 0;
y := if x > 0 then ((1-x)/x)^0.5 else 0;
end for;
end Test;

  • Index
  • » Users
  • » knkc
  • » Profile
You are here: