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

ENH: adds new stability margin methods to flight #572

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- ENH: Add new stability margin properties to Flight class [#572](https://github.com/RocketPy-Team/RocketPy/pull/572)
- ENH: adds `Function.remove_outliers` method [#554](https://github.com/RocketPy-Team/RocketPy/pull/554)

### Changed
Expand Down
24 changes: 24 additions & 0 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ class Flight:
Rocket's static margin during flight in calibers.
Flight.stability_margin : Function
Rocket's stability margin during flight, in calibers.
Flight.initial_stability_margin : float
Rocket's initial stability margin in calibers.
Flight.out_of_rail_stability_margin : float
Rocket's stability margin in calibers when it leaves the rail.
Flight.stream_velocity_x : Function
Freestream velocity x (East) component, in m/s, as a function of
time. Can be called or accessed as array.
Expand Down Expand Up @@ -2426,6 +2430,26 @@ def min_stability_margin(self):
"""Minimum stability margin."""
return self.stability_margin(self.min_stability_margin_time)

@property
def initial_stability_margin(self):
"""Stability margin at time 0.

Returns
-------
float
"""
return self.stability_margin(self.time[0])

@property
def out_of_rail_stability_margin(self):
"""Stability margin at the time the rocket leaves the rail.

Returns
-------
float
"""
return self.stability_margin(self.out_of_rail_time)

# Reynolds Number
@funcify_method("Time (s)", "Reynolds Number", "spline", "zero")
def reynolds_number(self):
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,31 @@ def test_get_controller_observed_variables(flight_calisto_air_brakes):
obs_vars = flight_calisto_air_brakes.get_controller_observed_variables()
assert isinstance(obs_vars, list)
assert len(obs_vars) == 0


def test_initial_stability_margin(flight_calisto_custom_wind):
"""Test the initial_stability_margin method of the Flight class.

Parameters
----------
flight_calisto_custom_wind : rocketpy.Flight
"""
res = flight_calisto_custom_wind.initial_stability_margin
assert isinstance(res, float)
assert res == flight_calisto_custom_wind.stability_margin(0)
assert np.isclose(res, 2.05, atol=0.1)


def test_out_of_rail_stability_margin(flight_calisto_custom_wind):
"""Test the out_of_rail_stability_margin method of the Flight class.

Parameters
----------
flight_calisto_custom_wind : rocketpy.Flight
"""
res = flight_calisto_custom_wind.out_of_rail_stability_margin
assert isinstance(res, float)
assert res == flight_calisto_custom_wind.stability_margin(
flight_calisto_custom_wind.out_of_rail_time
)
assert np.isclose(res, 2.14, atol=0.1)
Loading