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

Initialisation - equations partly in submodel

Initialisation - equations partly in submodel

Hi!

I want to model a thermodynamic system.

This is what I have tried:

Code:

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;

Somehow I do not get the  initialization right.
It is mandatory that 'H' is set to a proper start value in 'OpenGasVolume'. Part of the equations are captured in the Model 'media'.
My desired result would be media.T == T0 and media.p=p0 over the whole simulation time.

However I get:

Code:

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.

How to init the model correctly?

Thanks, Bernd

Edited by: BerndTA - Oct-30-21 16:35:27

Re: Initialisation - equations partly in submodel

Question also posted at: https://stackoverflow.com/questions/697 … n-submodel
Answer on Stackoverflow prefered. Thanks.

Re: Initialisation - equations partly in submodel

I could solve it. Now I understand the meaning of 'fixed=true'.

Solution is:

Code:

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;

There are 0 guests and 0 other users also viewing this topic
You are here: