Skip to content

Commit d7e4dba

Browse files
MNT: corrections after review, see...
- Fix exhaust velocity calculation for non-zero mass flow rates - remove useless if statement - change if to elif statement. - all the tested passing without warnings.
1 parent ea57768 commit d7e4dba

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

rocketpy/mathutils/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ def _check_user_input(
28632863
extrapolation = "constant"
28642864

28652865
## multiple dimensions
2866-
if source_dim > 2:
2866+
elif source_dim > 2:
28672867
# check for inputs and outputs
28682868
if inputs == ["Scalar"]:
28692869
inputs = [f"Input {i+1}" for i in range(source_dim - 1)]

rocketpy/motors/liquid_motor.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -273,34 +273,18 @@ def exhaust_velocity(self):
273273
mass flow rate. Therefore, this will vary with time if the mass flow
274274
rate varies with time.
275275
"""
276-
if not isinstance(self.thrust.source, np.ndarray):
277-
return self.thrust / (-1 * self.mass_flow_rate)
278-
279276
times, thrusts = self.thrust.source[:, 0], self.thrust.source[:, 1]
280277
mass_flow_rates = self.mass_flow_rate(times)
281278

282-
# Avoid division by zero by replacing 0 with NaN
283-
mass_flow_rates_nonzero = np.where(
284-
np.isclose(mass_flow_rates, 0), np.nan, mass_flow_rates
285-
)
286-
ext_vel = -thrusts / mass_flow_rates_nonzero
287-
288-
if np.any(np.isnan(ext_vel)):
289-
warnings.warn(
290-
"Exhaust velocity is NaN for some values of time, probably due to a"
291-
"division by zero. Check if the mass flow rate curve isn't zero for "
292-
"some values of time. The times used to calculate the exhaust "
293-
"velocity are the same as the computed thrust curve."
294-
)
279+
# Compute exhaust velocity only for non-zero mass flow rates
280+
valid_indices = mass_flow_rates != 0
281+
valid_times = times[valid_indices]
282+
valid_thrusts = thrusts[valid_indices]
283+
valid_mass_flow_rates = mass_flow_rates[valid_indices]
295284

296-
return Function(
297-
np.column_stack([times, ext_vel]),
298-
title="Exhaust Velocity",
299-
inputs=["Time (s)"],
300-
outputs="Exhaust Velocity [m/s]",
301-
interpolation="linear",
302-
extrapolation="zero",
303-
)
285+
ext_vel = -valid_thrusts / valid_mass_flow_rates
286+
287+
return np.column_stack([valid_times, ext_vel])
304288

305289
@funcify_method("Time (s)", "Propellant Mass (kg)")
306290
def propellant_mass(self):

0 commit comments

Comments
 (0)