ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Problem with the function setState_phX

Open congtoantran opened this issue 2 years ago • 5 comments

I have a library which works well on Modelica 3.3.2, but when converted to Modelica 4.0.0, it doesn't work anymore, and the message error is "Non-real equation in continuous time are not legal:".

I'm trying to understand the problem by using a very simple example (see below):

model model1a
  replaceable package Medium = Modelica.Media.R134a.R134a_ph "Medium model" 
    annotation (choicesAllMatching=true);
  Medium.ThermodynamicState state_a ;
  Modelica.Units.SI.AbsolutePressure p=Medium.p_default;
  Modelica.Units.SI.SpecificEnthalpy h=Medium.h_default;

equation 
  state_a = Medium.setState_phX(Medium.p_default, Medium.h_default);
  //     state_a = Medium.setState_phX(p, h);
end model1a;

The above model runs sucessfully. But when I redefine the variable state_a by using the second line in the equation part, the model does not work and the error is :

  Non-real equation in continuous time are not legal:
  state_a.phase = Modelica.Media.R134a.R134a_ph.getPhase_ph(p, h);

Any help to understand the error? Many thanks. I use Dymola 2021, Modelica 4.0.0

congtoantran avatar Oct 20 '23 12:10 congtoantran

@HansOlsson I can reproduce in Dymola 2024x, but not in SimulationX 4.4. Is it a tool-issue (of one of the tools)?

It works though (in both tools) if the variability is changed to parameter.

model Model1b
  replaceable package Medium = Modelica.Media.R134a.R134a_ph "Medium model"
    annotation (choicesAllMatching=true);
  Medium.ThermodynamicState state_a;
  parameter Modelica.Units.SI.AbsolutePressure p=Medium.p_default;
  parameter Modelica.Units.SI.SpecificEnthalpy h=Medium.h_default;

equation 
  //state_a = Medium.setState_phX(Medium.p_default, Medium.h_default);
  state_a = Medium.setState_phX(p, h);
end Model1b;

beutlich avatar Jan 13 '24 18:01 beutlich

I would say it is a library issue that can be corrected.

The issue is that this record has a Boolean member (phase), and a Boolean equation requires that both sides are discrete-time valued, section 3.8.4.

The correction would be that the phase-functions get inlined with events.

HansOlsson avatar Jan 15 '24 10:01 HansOlsson

I checked @HansOlsson's pull request PR #4263 and it looks good to me.

@arunkumar-narasimhan please back-port this to maint/4.1.0

casella avatar Jul 02 '24 12:07 casella

This issue is actually a regression from v.4.0.0 but I also marked it with the 4.1.0-dev label so we don't forget about it

casella avatar Jul 02 '24 12:07 casella

@Esther-Devakirubai please back-port this to maint/4.1.x, then you can close this ticket. Thanks!

casella avatar Sep 10 '24 11:09 casella

@Esther-Devakirubai ping, please back-port this to maint/v4.1.x

casella avatar Feb 11 '25 11:02 casella

Done by #4541

Esther-Devakirubai avatar Feb 24 '25 17:02 Esther-Devakirubai

Once we get a second review on #4541 this will be closed.

casella avatar Feb 24 '25 21:02 casella

This introduces a new model in ModelicaTest, so this issue should only be closed once we have new reference results for that model.

maltelenz avatar Feb 25 '25 08:02 maltelenz

LTX needs to add reference results for this test. @MatthiasBSchaefer will take care of that.

casella avatar Feb 25 '25 11:02 casella

This introduces a new model in ModelicaTest, so this issue should only be closed once we have new reference results for that model.

Here they are: https://github.com/modelica/MAP-LIB_ReferenceResults/tree/v4.1.0/ModelicaTest/Media/TestOnly/R134a_setState_phX

casella avatar Mar 08 '25 18:03 casella