Skip to content

Commit

Permalink
Merge pull request #479 from RocketPy-Team/bug/tanks-overfill
Browse files Browse the repository at this point in the history
HOTFIX: Tanks Overfill not Being Detected
  • Loading branch information
MateusStano authored Nov 23, 2023
2 parents e18ca22 + 6894dd4 commit 527fe89
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 294 deletions.
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 warning on line 1295 in rocketpy/motors/tank.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/tank.py#L1295

Added line #L1295 was not covered by tests

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

Check warning on line 1298 in rocketpy/motors/tank.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/tank.py#L1298

Added line #L1298 was not covered by tests

if (diff > 1e-6).any():
raise ValueError(

Check warning on line 1301 in rocketpy/motors/tank.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/tank.py#L1300-L1301

Added lines #L1300 - L1301 were not covered by tests
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

Check warning on line 1309 in rocketpy/motors/tank.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/tank.py#L1309

Added line #L1309 was not covered by tests

@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,
}
)

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

0 comments on commit 527fe89

Please sign in to comment.