当方程的一部分在子模型中时,Openmodelica 初始化

Openmodelica initialisation when part of equation is in submodel

我想为热力学系统建模。

这是我试过的:

model IdealGas
  // Natural Constants
  parameter Real R(unit="J/molK") = 8.31446261815324 "Gas Constant J/molK";
  // Values of Air used
  parameter Real f = 5 "Degrees of Freedom";
  parameter Modelica.Units.SI.MolarMass MG = 28.949e-3 "kg/mol";
  // Variables
  Modelica.Units.SI.Temperature T(start=273.15) "Temperature (K)";
  Modelica.Units.SI.AbsolutePressure p(start=1.015e5) "Absolut Pressure (Pa)";
  Modelica.Units.SI.SpecificEnthalpy u "spezific energy (J/mol)";
  Modelica.Units.SI.SpecificEnthalpy h "spezific Enthalpy (J/mol)";
  Modelica.Units.SI.Density rho "Density (kg/m3)";
  Modelica.Units.SI.Concentration c "mol/m3";
equation
  rho = MG * p / (R * T);
  c = p / (R * T);
  u = 0.5 * f * R * T;
  h = u + R * T;
end IdealGas;

model OpenGasVolume
    import Modelica.Units.SI;
    parameter  SI.Temperature T0=273.15+55 "Start Temperature (K)";
    parameter  SI.Pressure p0=5e5  "Start pressure (Pa)";
    parameter  SI.Volume V=1  "Volume (m3)";
    SI.Mass m(min = 0.0, start = 1) "Mass in Volume (kg)";
    SI.Energy H(min = 0.0) "Enthalpie in Volume (J)";
       
    IdealGas media;   
   

initial equation
  media.T = T0;
  media.p = p0;
  H = media.h * media.c * V;  // <--- Somehow this initialization does not work as i intend

equation
  H = media.h * media.c * V;
  media.rho = m / V;
  der(m) = 0;    // No Mass transfer
  der(H) =  0;   // No energy transfer
   
end OpenGasVolume;

不知怎么的,我没有得到正确的初始化。 必须将 'H' 设置为 'OpenGasVolume' 中的正确起始值。模型 'media' 中捕获了部分方程式。 在整个模拟时间内,我想要的结果是 media.T == T0 和 media.p=p0。

但是我得到: 代码:

Simulation process failed. Exited with code 255.
Matrix singular!
The initialization problem is inconsistent due to the following equation: 0 != 55 = T0 - media.T
Error in initialization. Storing results and exiting.
Use -lv=LOG_INIT -w for more information.

如何正确初始化模型?

谢谢伯恩德

我可以解决。现在我明白了`fixed=true'的意思了。

解决方法是:

model OpenGasVolume
    import Modelica.Units.SI;
    parameter  SI.Temperature T0=273.15+55 "Start Temperature (K)";
    parameter  SI.Pressure p0=5e5  "Start pressure (Pa)";
    parameter  SI.Volume V=1  "Volume (m3)";
    SI.Mass m(min = 0.0, start = 1) "Mass in Volume (kg)";
    SI.Energy H(min = 0.0) "Enthalpie in Volume (J)";
       
    IdealGas media(T(start = T0, fixed=true), p(start=p0, fixed=true));   <<<=== Correction done here.
   

initial equation

  H = media.h * media.c * V;  
does not work as i intend

equation
  H = media.h * media.c * V;
  media.rho = m / V;
  der(m) = 0;    // No Mass transfer
  der(H) =  0;   // No energy transfer
   
end OpenGasVolume;