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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
568 changes: 280 additions & 288 deletions docs/examples/SEB_liquid_motor.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2715,7 +2715,7 @@ def compose(self, func, extrapolate=False):
if isinstance(self.source, np.ndarray) and isinstance(func.source, np.ndarray):
# Perform bounds check for composition
if not extrapolate:
if func.min < self.x_initial and func.max > self.x_final:
if func.min < self.x_initial or func.max > self.x_final:
raise ValueError(
f"Input Function image {func.min, func.max} must be within "
f"the domain of the Function {self.x_initial, self.x_final}."
Expand Down
16 changes: 15 additions & 1 deletion rocketpy/motors/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,21 @@ def fluid_volume(self):
Function
Volume of the fluid as a function of time.
"""
return self.liquid_volume + self.gas_volume
fluid_volume = self.liquid_volume + self.gas_volume

# Check if within bounds
diff = fluid_volume - self.geometry.total_volume

if (diff > 1e-6).any():
raise ValueError(
f"The tank {self.name} was overfilled. The input fluid masses "
+ "produce a volume that surpasses the tank total volume by more "
+ f"than 1e-6 m^3 at {diff.x_array[np.argmax(diff.y_array)]} s."
+ "\n\t\tCheck out the input masses, fluid densities or raise the "
+ "tank height so as to increase its total volume."
)

return fluid_volume

@funcify_method("Time (s)", "Volume (m³)")
def gas_volume(self):
Expand Down
11 changes: 7 additions & 4 deletions tests/test_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_mass_based_tank():
) # density value may be estimate

top_endcap = lambda y: np.sqrt(
0.0775**2 - (y - 0.6924) ** 2
0.0775**2 - (y - 0.7924) ** 2
) # Hemisphere equation creating top endcap
bottom_endcap = lambda y: np.sqrt(
0.0775**2 - (0.0775 - y) ** 2
Expand All @@ -150,8 +150,8 @@ def test_mass_based_tank():
real_geometry = TankGeometry(
{
(0, 0.0559): bottom_endcap,
(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,
Comment on lines -153 to +154
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.

}
)

Expand All @@ -172,7 +172,6 @@ def test_mass_based_tank():
gas_mass=gas_masses,
liquid=lox,
gas=n2,
discretize=None,
)

# Generate tank geometry {radius: height, ...}
Expand All @@ -190,6 +189,10 @@ def test_mass_based_tank():
discretize=None,
)

# Assert volume bounds
assert (real_tank_lox.gas_height <= real_tank_lox.geometry.total_volume).all
assert (example_tank_lox.gas_height <= example_tank_lox.geometry.total_volume).all

initial_liquid_mass = 5
initial_gas_mass = 0
liquid_mass_flow_rate_in = 0.1
Expand Down