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

Posts

Posts

Nov-01-21 18:13:59
Part of the equations for init are in differnent Modell
Category: Programming

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;

Oct-30-21 07:59:51
Part of the equations for init are in differnent Modell
Category: Programming

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

Oct-28-21 17:43:42
Category: Programming

In programming Unit-testing of the code is highly recommended.
In order to early detect errors in the code, certain test cases shall be written, to test every submodule.

I think this approach shall be used in modelling as well.
So I'm searching for recommendations on how to  apply Unit testing to Modelica modells.

Basically I would need a tool to store lot's of test runs with different models and parameters for batch evaluation.
In each test run one or more acceptance criteria shall be defined. This might need evaluation of simulation data at the end of the run (post processing).

Any recommendations for a tool?

Thanks, Bernd

Oct-28-21 17:35:28
Part of the equations for init are in differnent Modell
Category: Programming

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

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