2
votes

The Modelica fluid library attempts to have the useful attribute of being able to initialize either from temperature or enthalpy. However, in the Simulation log several errors show up that are a bit mysterious.

The logged errors don't seem to impact the simulation but they should not be appearing because:

  1. The values passed to temperature_phX should be valid
  2. use_T_start = true so the "else" option causing the errors should not be run

Below is a code that reproduces the error when you run "RunMe" along with an option that will not produce the error. The representative error is at the bottom.

Any insight to how to solve this issue would be greatly appreciated.

model InitialValuesSimplified

  outer Modelica.Fluid.System system "System wide properties";

  replaceable package Medium =
      Modelica.Media.Water.StandardWater "Medium in the component";

  parameter Medium.AbsolutePressure p_a_start=system.p_start
      "Pressure at port a";

  parameter Boolean use_T_start=true "Use T_start if true, otherwise h_start";

  // Creates error log
  parameter Medium.Temperature T_a_start=
    if use_T_start then 
      system.T_start
    else 
      Medium.temperature_phX(p_a_start,h_a_start,X_start)
      "Temperature at port a";

  // No error log
  // parameter Medium.Temperature T_a_start=
  //   if use_T_start then 
  //     system.T_start
  //   else 
  //     system.T_start
  //     "Temperature at port a";

  parameter Modelica.Media.Interfaces.Types.MassFraction X_start[Medium.nX]=
      Medium.X_default "Mass fractions m_i/m";

  parameter Medium.SpecificEnthalpy h_a_start=
    if use_T_start then 
      Medium.specificEnthalpy_pTX(p_a_start,T_a_start,X_start)
    else 
      1e5 "Specific enthalpy at port a";


end InitialValuesSimplified;

Code to run snippet:

model RunMe

  InitialValuesSimplified initialValuesSimplified;
  inner Modelica.Fluid.System system;

end RunMe;

Error code sample:

Log-file of program ./dymosim
(generated: Mon Sep 12 17:15:19 2016)

dymosim started
... "dsin.txt" loading (dymosim input file)
T >= 273.15
The following error was detected at time: 0
IF97 medium function g1: the temperature (= 86.3 K) is lower than 273.15 K!
The stack of functions is:
Modelica.Media.Water.IF97_Utilities.BaseIF97.Basic.g1
Modelica.Media.Water.IF97_Utilities.waterBaseProp_pT
Modelica.Media.Water.IF97_Utilities.h_props_pT(
initialValuesSimplified.p_a_start, 
initialValuesSimplified.T_a_start, 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_pT(initialValuesSimplified.p_a_start, initialValuesSimplified.T_a_start, 0))
Non-linear solver will attempt to handle this problem.
1

1 Answers

1
votes

The problem is that the combination:

parameter Real T_start=if use_T then system.T_start else foo(3,h_start);
parameter Real h_start=if use_T then bar(4,T_start) else 2;

isn't handled symbolically as two different cases (use_T and not use_T), since that could lead to a combinatorial explosion. Instead it is seen as non-linear equation - and h_start is computed, but doesn't influence the resulting T_start.

If you don't intend to change these parameters you could make them final and in the first equation replace h_start by a suitable default. Otherwise a solution is to give a better start-value for T_a_start:

parameter Real T_start(start=300)=if use_T then system.T_start else foo(3,h_start);

Note that the problem isn't lack of start-value, but that the default start-value (500K) is too far off, the solver over-compensates and goes to 86K before converging on 293.15K. (The non-linear solver will likely be improved to avoid over-compensating this much.)