Skip to content

Commit 527fe89

Browse files
authored
Merge pull request #479 from RocketPy-Team/bug/tanks-overfill
HOTFIX: Tanks Overfill not Being Detected
2 parents e18ca22 + 6894dd4 commit 527fe89

File tree

4 files changed

+303
-294
lines changed

4 files changed

+303
-294
lines changed

docs/examples/SEB_liquid_motor.ipynb

Lines changed: 280 additions & 288 deletions
Large diffs are not rendered by default.

rocketpy/mathutils/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@ def compose(self, func, extrapolate=False):
27152715
if isinstance(self.source, np.ndarray) and isinstance(func.source, np.ndarray):
27162716
# Perform bounds check for composition
27172717
if not extrapolate:
2718-
if func.min < self.x_initial and func.max > self.x_final:
2718+
if func.min < self.x_initial or func.max > self.x_final:
27192719
raise ValueError(
27202720
f"Input Function image {func.min, func.max} must be within "
27212721
f"the domain of the Function {self.x_initial, self.x_final}."

rocketpy/motors/tank.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,21 @@ def fluid_volume(self):
12921292
Function
12931293
Volume of the fluid as a function of time.
12941294
"""
1295-
return self.liquid_volume + self.gas_volume
1295+
fluid_volume = self.liquid_volume + self.gas_volume
1296+
1297+
# Check if within bounds
1298+
diff = fluid_volume - self.geometry.total_volume
1299+
1300+
if (diff > 1e-6).any():
1301+
raise ValueError(
1302+
f"The tank {self.name} was overfilled. The input fluid masses "
1303+
+ "produce a volume that surpasses the tank total volume by more "
1304+
+ f"than 1e-6 m^3 at {diff.x_array[np.argmax(diff.y_array)]} s."
1305+
+ "\n\t\tCheck out the input masses, fluid densities or raise the "
1306+
+ "tank height so as to increase its total volume."
1307+
)
1308+
1309+
return fluid_volume
12961310

12971311
@funcify_method("Time (s)", "Volume (m³)")
12981312
def gas_volume(self):

tests/test_tank.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_mass_based_tank():
140140
) # density value may be estimate
141141

142142
top_endcap = lambda y: np.sqrt(
143-
0.0775**2 - (y - 0.6924) ** 2
143+
0.0775**2 - (y - 0.7924) ** 2
144144
) # Hemisphere equation creating top endcap
145145
bottom_endcap = lambda y: np.sqrt(
146146
0.0775**2 - (0.0775 - y) ** 2
@@ -150,8 +150,8 @@ def test_mass_based_tank():
150150
real_geometry = TankGeometry(
151151
{
152152
(0, 0.0559): bottom_endcap,
153-
(0.0559, 0.7139): lambda y: 0.0744,
154-
(0.7139, 0.7698): top_endcap,
153+
(0.0559, 0.8039): lambda y: 0.0744,
154+
(0.8039, 0.8698): top_endcap,
155155
}
156156
)
157157

@@ -172,7 +172,6 @@ def test_mass_based_tank():
172172
gas_mass=gas_masses,
173173
liquid=lox,
174174
gas=n2,
175-
discretize=None,
176175
)
177176

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

192+
# Assert volume bounds
193+
assert (real_tank_lox.gas_height <= real_tank_lox.geometry.total_volume).all
194+
assert (example_tank_lox.gas_height <= example_tank_lox.geometry.total_volume).all
195+
193196
initial_liquid_mass = 5
194197
initial_gas_mass = 0
195198
liquid_mass_flow_rate_in = 0.1

0 commit comments

Comments
 (0)