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

Fix Wb_flows discretization terms for DynamicPipe #3959

Merged

Conversation

mestinso
Copy link
Collaborator

@mestinso mestinso commented Mar 6, 2022

  • Fixes made for all structure cases: av_b, a_vb, a_v_b, and av_vb
  • The updated discretization terms give more accurate derivatives associated with the volumes
  • Energy is now properly conserved (previously av_b, a_vb, and a_v_b had conservation errors)

@mestinso mestinso linked an issue Mar 6, 2022 that may be closed by this pull request
@mestinso mestinso force-pushed the bugfix/dynamic-pipe-discretization-fix branch from fe2dcf3 to f1a8eb6 Compare March 6, 2022 03:18
- Fixes made for all structure cases: av_b, a_vb, a_v_b, and av_vb
- The new discretizations terms give more accurate derivatives associated with the volumes
- Energy is now properly conserved (previously av_b, a_vb, and a_v_b had conservation errors)
@mestinso mestinso force-pushed the bugfix/dynamic-pipe-discretization-fix branch from f1a8eb6 to 59c418e Compare March 13, 2022 15:09
@mestinso mestinso changed the title Fixed Wb_flows dp/dx[1] and dp/dx[end] terms Fixed Wb_flows discretization terms for DynamicPipe Mar 13, 2022
@beutlich
Copy link
Member

@mestinso Thank you for you valuable effort!

What I'd like to have are test models (covering all the branches) where the current imlementation raises an assert, but with your fix results in succeeding models. This way we can easily see what the expected purpose of the changes are. Thanks again.

@beutlich beutlich added bug Critical/severe issue L: Fluid Issue addresses Modelica.Fluid (excl. Dissipation) labels Mar 15, 2022
@beutlich beutlich added this to the MSL4.1.0 milestone Mar 15, 2022
@mestinso
Copy link
Collaborator Author

@mestinso Thank you for you valuable effort!

What I'd like to have are test models (covering all the branches) where the current imlementation raises an assert, but with your fix results in succeeding models. This way we can easily see what the expected purpose of the changes are. Thanks again.

@beutlich Sure. Do you suggest I add these test models into ModelicaTest as part of this PR?

@beutlich
Copy link
Member

Do you suggest I add these test models into ModelicaTest as part of this PR?

Exactly.

@bilderbuchi
Copy link

@mestinso did you ever get around to adding those tests to ModelicaTest?

@mestinso
Copy link
Collaborator Author

@mestinso did you ever get around to adding those tests to ModelicaTest?

@bilderbuchi Unfortunately no, but thanks for the prompt here. I expect to get a little time here in the coming weeks, so, hopefully, I'll push an update soon.

@modelica modelica deleted a comment from arunkumar-narasimhan Feb 24, 2023
@TManikantan
Copy link
Contributor

@mestinso Did you got time to add the test to Modelica Test?

@mestinso
Copy link
Collaborator Author

@bilderbuchi @TManikantan @hubertus65 @beutlich Two new tester models have been added. The first tester checks for energy conservation for water flow without the kinetic energy term and the second tester checks for energy conservation for airflow with the kinetic energy term. Note that for the previous version of the DynamicPipe model, 6/12 asserts passed in the first tester and 1/4 asserts passed in the second tester.

@bilderbuchi
Copy link

Nice work! It's kinda surprising that in DynamicPipeEnergyConservationCheck.mo you don't need an epsilon on the isEqual -- do you think that could be fragile w.r.t. floating-point comparison issues?

Copy link
Member

@hubertus65 hubertus65 left a comment

Choose a reason for hiding this comment

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

I agree with the comment of @bilderbuchi that the choice of eps = 0 (the default 3rd argument in Modelica.Math.isEqual) is risky and likely toto lead to assertion errors on other platforms, or just with other solvers than those you tested: we have seen such cases before. Therefore I suggest the following: Add a third argument to all calls of isEqual to set eps to a value. My suggestion for eps is in the range of 1e-10 to 1e-12: that is several orders of magnitude larger then the numerical eps, and several orders of magnitude smaller than the solver tolerance.

@mestinso
Copy link
Collaborator Author

mestinso commented Mar 7, 2023

@bilderbuchi @hubertus65 I went ahead and adjusted those tolerances as recommended.

@TManikantan TManikantan requested a review from rfranke March 9, 2023 04:44
@TManikantan
Copy link
Contributor

@casella @rfranke a reminder would you please review this fix?

@MartinOtter MartinOtter removed the request for review from rfranke March 28, 2023 15:00
@MartinOtter
Copy link
Member

Had email with Francesco, and he will review

Copy link
Contributor

@casella casella left a comment

Choose a reason for hiding this comment

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

I was also a bit surprised that the tests passed with zero tolerance, but I see those are really round figures (the source is at 3 MJ/kg, and so are the volume enthalpies) so I guess that explains it. I ran Check2 and in that case I see you need indeed a bit of tolerance, around 1 ppm, which makes sense.

I'm currently unable to review the details of the updated model, but given the results of the tests this looks good to me.

@casella casella merged commit 7d2e8d7 into modelica:master Apr 18, 2023
@beutlich beutlich changed the title Fixed Wb_flows discretization terms for DynamicPipe Fix Wb_flows discretization terms for DynamicPipe Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Critical/severe issue L: Fluid Issue addresses Modelica.Fluid (excl. Dissipation)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong enthalpies calculated by DynamicPipe
7 participants