Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate events in functions; to avoid non-discrete booleans. #4263

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

HansOlsson
Copy link
Contributor

Closes #4209

I don't know if significant enough to push for release.

@HansOlsson HansOlsson added the L: Media Issue addresses Modelica.Media label Jan 15, 2024
Copy link
Member

@beutlich beutlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model Model1b
  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 Model1b;

still fails in Dymola 2024x - even with the proposed changes. Would be good to have this model as test model.

Are other functions affected as well?

Modelica/Media/R134a.mo Outdated Show resolved Hide resolved
Modelica/Media/R134a.mo Outdated Show resolved Hide resolved
@HansOlsson
Copy link
Contributor Author

model Model1b
  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 Model1b;

still fails in Dymola 2024x - even with the proposed changes. Would be good to have this model as test model.

Are other functions affected as well?

No, but it seems that I messed up the annotations a bit, it should now be resolved.

@HansOlsson
Copy link
Contributor Author

still fails in Dymola 2024x - even with the proposed changes. Would be good to have this model as test model.

I added a test-model, but made it similar to an existing one instead.

ModelicaTest/Media.mo Outdated Show resolved Hide resolved
Copy link
Member

@beutlich beutlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that Model1b now runs in Dymola 2024x (and still in SimulationX 4.4).

@beutlich
Copy link
Member

I don't know if significant enough to push for release.

For me it seems like a MSL bug. What's the opinion of the Media officers?

@beutlich
Copy link
Member

Unfortunately, the new test model ModelicaTest.Media.TestOnly.R134a_setState_phX raises a AssignmentFromNonDiscreteToDiscrete warning in SimulationX 4.4 and fails to simulate with all tested solvers due to a singular system of equations. It does not matter if this PR is applied or not.

@HansOlsson
Copy link
Contributor Author

Unfortunately, the new test model ModelicaTest.Media.TestOnly.R134a_setState_phX raises a AssignmentFromNonDiscreteToDiscrete warning in SimulationX 4.4 and fails to simulate with all tested solvers due to a singular system of equations. It does not matter if this PR is applied or not.

Ok, that is problematic. I assume the failure to simulate and assignment-error are related; indicating that the current version of the function doesn't work, and not some unrelated error in the example model.

I don't know the exact reason - is it related to calling GenerateEvents indirectly (i.e., one function with GenerateEvents calling another one)? If so it might be possible to rewrite it as:

  state := ThermodynamicState(phase=
         if ((h < bubbleEnthalpy(SaturationProperties(psat=p,Tsat=0)) 
          or (h > dewEnthalpy(SaturationProperties(psat=p,Tsat=0))) or (p > R134aData.data.FPCRIT)) then 1
         else 2 , p=p, h=h, d=density_ph(p, h), T=temperature_ph(p, h));

(I cannot test that in SimulationX.)

So what to do:

  • Just add
  • Delay until the next release.
  • Add the changes in MSL - but don't add the test.
  • Use the weird rewriting above - even if horrible copy-pasta. One could argue that this indirect calling isn't fully specified, whereas this rewriting should be ok.

@hubertus65
Copy link
Member

I would be in favor to add the rewrite proposed by Hans. It makes the event generation explicit. Could you add it to the PR?

@HansOlsson
Copy link
Contributor Author

I would be in favor to add the rewrite proposed by Hans. It makes the event generation explicit. Could you add it to the PR?

Should be done now. Please re-test

Copy link
Member

@beutlich beutlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gkurzbach The new test model ModelicaTest.Media.TestOnly.R134a_setState_phX still fails in SimulationX 4.4. Can you please elaborate. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: Media Issue addresses Modelica.Media
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with the function setState_phX
4 participants