Skip to content
Open
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
21 changes: 16 additions & 5 deletions rocketpy/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ def fin_flutter_analysis(
considering the variation of the speed of sound with altitude.
safety_factor : rocketpy.Function
The Safety Factor for the fin flutter as a function of time, defined as
the flutter Mach Number divided by the freestream Mach Number.
the flutter Mach Number divided by the freestream Mach Number. The times
at which the freestream Mach Number is zero are left out.
"""
found_fin = False
surface_area = None
Expand Down Expand Up @@ -415,10 +416,20 @@ def _flutter_safety_factor(flight, flutter_mach):
rocketpy.Function
The safety factor for the fin flutter analysis.
"""
safety_factor = flutter_mach / flight.mach_number
safety_factor.set_title("Fin Flutter Safety Factor")
safety_factor.set_outputs("Safety Factor")
return safety_factor
time, mach = flight.mach_number[:, 0], flight.mach_number[:, 1]
# Without wind, Mach is zero until liftoff and the ratio is undefined there
defined = mach > 0
safety_factor = flutter_mach[defined, 1] / mach[defined]
# The ratio is very large just after liftoff, where a spline oscillates and
# can become negative. pchip stays between the neighboring samples.
return Function(
np.column_stack((time[defined], safety_factor)),
inputs="Time (s)",
outputs="Safety Factor",
interpolation="pchip",
extrapolation="constant",
title="Fin Flutter Safety Factor",
)


def _flutter_plots(flight, flutter_mach, safety_factor, *, filename=None):
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,64 @@ def test_fin_flutter_analysis(flight_calisto_custom_wind):
assert np.isclose(safety_factor(np.inf), 61.669562809629035, atol=5e-3)


def test_fin_flutter_analysis_without_wind(flight_calisto_robust):
"""Without wind the Mach number is zero on the pad, where the safety factor
is undefined. Those points are left out, and the rest is the ratio of the
flutter and the freestream Mach numbers.

Parameters
----------
flight_calisto_robust : Flight
A Flight object with a rocket with fins, in an atmosphere without wind.
"""
mach = flight_calisto_robust.mach_number
assert mach[0, 1] == 0

flutter_mach, safety_factor = utilities.fin_flutter_analysis(
fin_thickness=2 / 1000,
shear_modulus=10e9,
flight=flight_calisto_robust,
see_prints=False,
see_graphs=False,
)

time = safety_factor[:, 0]
assert len(time) == np.count_nonzero(mach[:, 1])
assert safety_factor[:, 1] == pytest.approx(
np.array(flutter_mach(time)) / np.array(mach(time)), rel=1e-9
)
assert safety_factor(10) == pytest.approx(flutter_mach(10) / mach(10), rel=5e-3)
# The interpolation should not take the curve below its lowest sample
dense_time = np.linspace(0, time[-1], 20001)
assert min(safety_factor(dense_time)) >= safety_factor[:, 1].min() * (1 - 1e-9)


@patch("matplotlib.pyplot.show")
def test_fin_flutter_analysis_without_wind_output(
mock_show, flight_calisto_robust, capsys
):
"""Tests the prints and graphs for a flight without wind.

Parameters
----------
mock_show : mock
Mock of matplotlib.pyplot.show function.
flight_calisto_robust : Flight
A Flight object with a rocket with fins, in an atmosphere without wind.
"""
_, safety_factor = utilities.fin_flutter_analysis(
fin_thickness=2 / 1000,
shear_modulus=10e9,
flight=flight_calisto_robust,
see_prints=True,
see_graphs=True,
)

min_safety_factor = safety_factor[:, 1].min()
assert f"Min safety factor={min_safety_factor:.3f}" in capsys.readouterr().out
mock_show.assert_called()


def test_calculate_stall_wind_velocity_returns_value(flight_calisto_custom_wind):
"""Regression: the stall wind velocity must be returned (it was previously
only logged at INFO level and the method returned None, losing the value).
Expand Down