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

HOTFIX: Tanks Overfill not Being Detected #479

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

phmbressan
Copy link
Collaborator

Pull request type

  • Code changes (bugfix, features)
  • Code maintenance (refactoring, formatting, tests)
  • ReadMe, Docs and GitHub updates
  • Other (please describe):

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest --runslow) have passed locally

Current behavior

The MassBasedTank did not compute correctly overfills or underfills due to some code checks that were not working properly, including:

  • The Function.compose extrapolation check was not being applied correctly;
  • The overfill check was only being done regarding the computed gas_height, however it is more accurate to check before computations in fluid_volume.

New behavior

The main changes this hotfix introduces:

  • The Function.compose extrapolation was corrected;
  • An overfill validation was added in MassBasedTank.fluid_volume;
  • An assertion in test_mass_based_tank regarding the fluid_volume so as to prevent this kind of error in the near future;

Breaking change

  • Yes
  • No

@phmbressan phmbressan added Bug Something isn't working Motors Every propulsion related issue or PR labels Nov 21, 2023
@phmbressan phmbressan self-assigned this Nov 21, 2023
Comment on lines -153 to +154
(0.0559, 0.7139): lambda y: 0.0744,
(0.7139, 0.7698): top_endcap,
(0.0559, 0.8039): lambda y: 0.0744,
(0.8039, 0.8698): top_endcap,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on these changes: after making the assertion from lines 192-195, the tests failed due to the fact that the defined geometry volume is too low. Therefore the tank ended up being overfilled and had to be increased in size.

Copy link

codecov bot commented Nov 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (hotfix/v1.1.1@3d3d982). Click here to learn what that means.

Additional details and impacted files
@@               Coverage Diff                @@
##             hotfix/v1.1.1     #479   +/-   ##
================================================
  Coverage                 ?   70.83%           
================================================
  Files                    ?       55           
  Lines                    ?     9240           
  Branches                 ?        0           
================================================
  Hits                     ?     6545           
  Misses                   ?     2695           
  Partials                 ?        0           
Flag Coverage Δ
unittests 70.83% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"The `fluid_volume`, defined as the sum of `gas_volume` and "
+ "`liquid_volume`, is not equal to the total volume of the tank."
+ "\n\t\tThe difference is more than 1e-6 m^3 at "
+ f"{diff.x_array[np.argmin(diff.y_array)]} s."
Copy link
Member

@giovaniceotto giovaniceotto Nov 22, 2023

Choose a reason for hiding this comment

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

Just checking: we need to guarantee, for now, that fluid_volume does not exceed self.geometry.total_volume, but we don't really care yet if fluid_volume is much less then self.geometry.total_volume?

If this is the case, shouldn't we use np.argmax instead of np.argmin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do think you are right regarding np.argmax, but, just to make sure we are on the same page, this would need to be changed in all error messages of this class, right?

Copy link
Collaborator Author

@phmbressan phmbressan Nov 22, 2023

Choose a reason for hiding this comment

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

Actually, I correct myself: the computation should be np.argmin since we are looking for the smallest of the differences between the fluid volume and the tank volume to determine exactly where it overfilled.

Copy link
Member

@giovaniceotto giovaniceotto Nov 23, 2023

Choose a reason for hiding this comment

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

@phmbressan with np.argmin, don't you have the risk of getting a negative value, in which case the tank is underfilled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The check here is made following these assumptions:

  1. The diff pointed out that the Tank is, at some time, overfilled;
  2. There is a value of time that the fluid volume surpassed the total volume of the Tank;
  3. In general, this specific point in time is not part of the time samples so the minimum value of the diff is used to select it. I do think it is possible that this value may be a bit before the overfill crossing or a bit after, so there is a certain margin of error.

Perhaps I should mention that the time is approximate or, likely a better solution, use Function.find_input. I favored the implemented way due the fact this is a hotfix and the np.argmin was already being used in the other exceptions of this class.

Let me know if I made it clearer now or if there is any mistake in my reasoning.

Comment on lines 1301 to 1305
raise ValueError(
"The `fluid_volume`, defined as the sum of `gas_volume` and "
+ "`liquid_volume`, is not equal to the total volume of the tank."
+ "\n\t\tThe difference is more than 1e-6 m^3 at "
+ f"{diff.x_array[np.argmin(diff.y_array)]} s."
Copy link
Member

Choose a reason for hiding this comment

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

I think this error message could be improved a bit

This is a MassBasedTank, meaning the user will have given mass curves to the tank. If this error pops up warning about volume issues, the user might get confused and the correction to this error will not be clear.

I would suggest telling the user that the masses, the densities or the tank geometry might be wrong

@MateusStano MateusStano merged commit 527fe89 into hotfix/v1.1.1 Nov 23, 2023
@MateusStano MateusStano deleted the bug/tanks-overfill branch November 23, 2023 13:20
@MateusStano MateusStano mentioned this pull request Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Motors Every propulsion related issue or PR
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants