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
  • » Roumaenien
  • » Profile

Posts

Posts

Apr-25-22 14:54:49
Category: Programming

Hi there,

when working with OM, i often have to use the media models of the MSL in combination with the models of the fluid library. For a simple simulation, where i need to "pump" water from one tank to another, i tried to build a simple pump-like model. This is where i seem to make an error, that i often make, when it comes to using components of Modelica.Media and Modelica.Fluid - most of the time i get the message stating that the number of equations doesn't match the number of variables when trying to run the simulation (when i check the model itself, the number of variables and equations match).

If someone could tell me, where the the error in my code or within my method in general is, that would be really great. I tried finding literature on how to make balanced models or papers etc. on how to setup up those modelica models but unfortunately i can't find something like a checklist or a receipt. There seem to be some basic concepts i still don't understand.

Below is my code of the pump-model, the model i test it in and attached is the error message i get, when trying to simulate.

I know, this is not a problem of the software rather than my abilities to create models...i just can't get my head around this and you would help me a lot. Thank you very much!

model SimplePump
"Simple, pump-like model that induces a mass flow between ports a and b"

  replaceable package Medium = Modelica.Media.Water.StandardWaterOnePhase;
  parameter Real m_flow = 2;

  Modelica.Fluid.Interfaces.FluidPort_a port_a(redeclare package Medium = Medium) 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)));
  Modelica.Fluid.Interfaces.FluidPort_b port_b(redeclare package Medium = Medium) 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

  //pressures at ports
  0 = port_a.p - port_b.p;

  //mass balance
  0 = port_a.m_flow + port_b.m_flow;
 
  //Induced mass flow
  m_flow = port_a.m_flow;
 
  //energy balance
  port_a.h_outflow = port_b.h_outflow;

annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Ellipse(origin = {-0.26, 0.42}, lineThickness = 0.75, extent = {{39.63, 40.09}, {-39.63, -40.09}}, endAngle = 360), Line(origin = {-45, 0}, points = {{45, 0}, {-45, 0}, {-45, 0}}, thickness = 0.75), Line(origin = {39.79, 40.62}, points = {{-40, 0}, {40, 0}, {40, 0}}, thickness = 0.75), Line(origin = {-0.02, -38.8}, points = {{-27.9787, 8.79835}, {-39.9787, -9.20165}, {40.0213, -9.20165}, {26.0213, 8.79835}, {26.0213, 8.79835}}, thickness = 0.75), Rectangle(extent = {{-100, 100}, {100, -100}})}));
end SimplePump;

model TestCase

replaceable package Medium = Modelica.Media.Water.StandardWater;

  SimplePump simplePump(redeclare package Medium = Medium, m_flow = 2) annotation(
    Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  inner Modelica.Fluid.System system annotation(
    Placement(visible = true, transformation(origin = {-90, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Fluid.Sources.FixedBoundary Sink(nPorts = 1, redeclare package Medium = Medium)  annotation(
    Placement(visible = true, transformation(origin = {80, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
  Modelica.Fluid.Sources.FixedBoundary Source(nPorts = 1, redeclare package Medium = Medium) annotation(
    Placement(visible = true, transformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

equation

  connect(simplePump.port_b, Sink.ports[1]) annotation(
    Line(points = {{10, 0}, {70, 0}}, color = {0, 127, 255}));
  connect(Source.ports[1], simplePump.port_a) annotation(
    Line(points = {{-70, 0}, {-10, 0}}, color = {0, 127, 255}));

  annotation(
    uses(Modelica(version = "3.2.3")));
end TestCase;

ErrorMessageTestCase.txt

Apr-17-22 16:12:38
An independent subset of the model has imbalanced number of equations (14) and variables (15).

Hi,

i didn't get any reply to my post so far but i think the fault in my method desribed above is that i didn't test the System with a boundary for the Medium to flow into. So try connecting the port to FixedBoundary or pT_Boundary for example current/wink

Apr-29-20 22:20:52
An independent subset of the model has imbalanced number of equations (14) and variables (15).

Hi,

could someone maby try to rebuild my model to check if the same error appears?! It only consists of 3 models of the modelica standard library - you would help me a lot. I don't know where to start with this.

Thank you!

Apr-28-20 13:01:27
An independent subset of the model has imbalanced number of equations (14) and variables (15).

Hi,

i am fairly new to (open)modelica and really love to work with it. Unfortunately i am having troubles understanding the Error-messages i am getting. I try to utilize the modelica.fluid library for a small project and already read the fluid.userguid and the media.userguide.

I'd like to build a simple model, that provides a mass flow to / via a fluid_port_b. The model is getting checked succesfully but whenever i try to simulate it, i get two errors stating, that "An independent subset of the model has imbalanced number of equations (14) and variables (15)." and "pre-optimization module clockPartitioning (simulation) failed.".

I tried it by enabling the old frontend for code generation but that didn't help. Do i understand it right, that i have too much equations / not enough variables?
I would be really thankfull for a hint on how to set this up right, since i am totally in the dark with this. Thank you very much for your efforts in advance!

P.S.: I would have liked to upload pictures but get an "The requested page can't be found"-message.

Code:
model Test
  Modelica.Fluid.Sources.MassFlowSource_T boundary(redeclare package Medium = Modelica.Media.IdealGases.SingleGases.H2, nPorts = 1, use_m_flow_in = true) annotation(
    Placement(visible = true, transformation(origin = {2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)))
;
  Modelica.Blocks.Sources.RealExpression realExpression(y = 2.4)  annotation(
    Placement(visible = true, transformation(origin = {-4, 34}, extent = {{10, -10}, {-10, 10}}, rotation = 0)))
;
  inner Modelica.Fluid.System system annotation(
    Placement(visible = true, transformation(origin = {-90, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)))
;
  Modelica.Fluid.Interfaces.FluidPort_b port_b(redeclare package Medium = Modelica.Media.IdealGases.SingleGases.H2) 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
  connect(realExpression.y, boundary.m_flow_in) annotation(
    Line(points = {{-15, 34}, {-24, 34}, {-24, 8}, {-8, 8}}, color = {0, 0, 127}))
;
  connect(boundary.ports[1], port_b) annotation(
    Line(points = {{12, 0}, {100, 0}, {100, 0}, {100, 0}}, color = {0, 127, 255}))
;

annotation(
    uses(Modelica(version = "3.2.3")))
;
end Test;

Error:
[1] 14:33:03 Symbolic Error
An independent subset of the model has imbalanced number of equations (14) and variables (15).
variables:
port_b.h_outflow
port_b.p
boundary.T_in_internal
boundary.ports[1].h_outflow
boundary.ports[1].p
boundary.medium.p_bar
boundary.medium.T_degC
boundary.medium.state.T
boundary.medium.state.p
boundary.medium.R
boundary.medium.u
boundary.medium.T
boundary.medium.d
boundary.medium.h
boundary.medium.p
equations:
1 : boundary.medium.T_degC = -273.15 + boundary.medium.T
2 : boundary.medium.p_bar = 1e-005 * boundary.medium.p
3 : boundary.medium.R = 4124.487568704486
4 : boundary.medium.h = Modelica.Media.IdealGases.Common.Functions.h_T(Modelica.Media.IdealGases.Common.DataRecord("H2", 0.00201588, 0, 4200697.462150524, 1000, {40783.2321, -800.918604, 8.21470201, -0.01269714457, 1.753605076e-005, -1.20286027e-008, 3.36809349e-012}, {2682.484665, -30.43788844}, {560812.801, -837.150474, 2.975364532, 0.001252249124, -3.74071619e-007, 5.936625200000001e-011, -3.6069941e-015}, {5339.82441, -2.202774769}, 4124.487568704486), boundary.medium.T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.ZeroAt0K, 0.0)
5 : boundary.medium.u = boundary.medium.h - boundary.medium.R * boundary.medium.T
6 : boundary.medium.d = boundary.medium.p / (boundary.medium.T * boundary.medium.R)
7 : boundary.medium.state.T = boundary.medium.T
8 : boundary.medium.state.p = boundary.medium.p
9 : boundary.T_in_internal = boundary.T
10 : boundary.medium.T = boundary.T_in_internal
11 : boundary.ports[1].p = boundary.medium.p
12 : boundary.ports[1].h_outflow = boundary.medium.h
13 : boundary.ports[1].h_outflow = port_b.h_outflow
14 : boundary.ports[1].p = port_b.p

[2] 14:33:03 Translation Error
pre-optimization module clockPartitioning (simulation) failed.

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