From 014e633aae170219da41e9b2156b917fcafafde3 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:37:08 -0500 Subject: [PATCH 01/11] ENH: Add new stability margin properties to Flight class --- rocketpy/simulation/flight.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 326b5db04..c642d1123 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2426,6 +2426,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(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): From 6779a3e191430ee1491d598af80184eb3c4de791 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:37:20 -0500 Subject: [PATCH 02/11] TST: Add tests for initial and out-of-rail stability margins in Flight class --- tests/unit/test_flight.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/test_flight.py b/tests/unit/test_flight.py index 87249cf44..e6ab6b8b8 100644 --- a/tests/unit/test_flight.py +++ b/tests/unit/test_flight.py @@ -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) From 55e5cc25cd70c367ea62898fe1fc0e198cb2a4e5 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:38:42 -0500 Subject: [PATCH 03/11] MNT: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ff32bd8d..6345de19f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From c8b26b63f28271d415e79b9e566ed7ee01af1d47 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:43:22 -0500 Subject: [PATCH 04/11] DOC: Add initial and out-of-rail stability margins to Flight class documentation --- rocketpy/simulation/flight.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index c642d1123..ff0ee1840 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -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. @@ -2429,7 +2433,7 @@ def min_stability_margin(self): @property def initial_stability_margin(self): """Stability margin at time 0. - + Returns ------- float @@ -2439,7 +2443,7 @@ def initial_stability_margin(self): @property def out_of_rail_stability_margin(self): """Stability margin at the time the rocket leaves the rail. - + Returns ------- float From 1aecd491ddc1f455046567164b23fe1c8bd9a0be Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:37:08 -0500 Subject: [PATCH 05/11] ENH: Add new stability margin properties to Flight class --- rocketpy/simulation/flight.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 326b5db04..c642d1123 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2426,6 +2426,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(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): From c36d27f9e3d1cd3c0487d1f68d39ade8fa39572a Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:37:20 -0500 Subject: [PATCH 06/11] TST: Add tests for initial and out-of-rail stability margins in Flight class --- tests/unit/test_flight.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/test_flight.py b/tests/unit/test_flight.py index 87249cf44..e6ab6b8b8 100644 --- a/tests/unit/test_flight.py +++ b/tests/unit/test_flight.py @@ -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) From 36fb6b5dca9343dbb9d3483546ade4ec9a8709f7 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:38:42 -0500 Subject: [PATCH 07/11] MNT: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a8476ad6..3586d54e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 1264a67b8f5e7386f650132ccef67406dd2446a0 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 7 Mar 2024 18:43:22 -0500 Subject: [PATCH 08/11] DOC: Add initial and out-of-rail stability margins to Flight class documentation --- rocketpy/simulation/flight.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index c642d1123..ff0ee1840 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -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. @@ -2429,7 +2433,7 @@ def min_stability_margin(self): @property def initial_stability_margin(self): """Stability margin at time 0. - + Returns ------- float @@ -2439,7 +2443,7 @@ def initial_stability_margin(self): @property def out_of_rail_stability_margin(self): """Stability margin at the time the rocket leaves the rail. - + Returns ------- float From ee01e9dd9f159d463e642465244ebe08f4038565 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 21 Mar 2024 15:29:08 -0400 Subject: [PATCH 09/11] MNT: Fix initial stability margin calculation in Flight class --- rocketpy/simulation/flight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index ff0ee1840..344a831fb 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2438,7 +2438,7 @@ def initial_stability_margin(self): ------- float """ - return self.stability_margin(0) + return self.stability_margin(self.time[0]) @property def out_of_rail_stability_margin(self): From c9cc0deb6393ed38b3dc18b9d0c8dc59ee840e42 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 22 Mar 2024 06:12:41 -0400 Subject: [PATCH 10/11] ENH: add new stability Flight properties to flight prints --- rocketpy/prints/flight_prints.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/rocketpy/prints/flight_prints.py b/rocketpy/prints/flight_prints.py index 5b1f9b914..ec702a12c 100644 --- a/rocketpy/prints/flight_prints.py +++ b/rocketpy/prints/flight_prints.py @@ -67,8 +67,7 @@ def initial_conditions(self): self.flight.w1(0), self.flight.w2(0), self.flight.w3(0) ) ) - - return None + print(f"Initial Stability Margin: {self.flight.initial_stability_margin:.3f} c") def numerical_integration_settings(self): """Prints out the Numerical Integration settings available about the @@ -150,9 +149,8 @@ def out_of_rail_conditions(self): print("\nRail Departure State\n") print("Rail Departure Time: {:.3f} s".format(self.flight.out_of_rail_time)) print( - "Rail Departure Velocity: {:.3f} m/s".format( - self.flight.out_of_rail_velocity - ) + "Rail Departure Stability Margin: " + f"{self.flight.out_of_rail_stability_margin:.3f} c" ) print( "Rail Departure Stability Margin: {:.3f} c".format( @@ -408,9 +406,13 @@ def stability_margin(self): about the flight.""" print("\nStability Margin\n") print( - "Maximum Stability Margin: {:.3f} c at {:.2f} s".format( - self.flight.max_stability_margin, self.flight.max_stability_margin_time - ) + f"Initial Stability Margin: {self.flight.initial_stability_margin:.3f} c " + f"at {self.flight.time[0]:.2f} s" + ) + print( + "Out of Rail Stability Margin: " + f"{self.flight.out_of_rail_stability_margin:.3f} c " + f"at {self.flight.out_of_rail_time:.2f} s" ) print( "Minimum Stability Margin: {:.3f} c at {:.2f} s".format( From 2456b119baccafff2df4fcea5a9a37fa0b8d55d4 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 22 Mar 2024 06:14:47 -0400 Subject: [PATCH 11/11] BUG: refactor the initial_conditions _FlightPrints.method to use correct initial time - This also adopts f-string interpolation for the initial_conditions prints --- rocketpy/prints/flight_prints.py | 41 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/rocketpy/prints/flight_prints.py b/rocketpy/prints/flight_prints.py index ec702a12c..b9be3f6ee 100644 --- a/rocketpy/prints/flight_prints.py +++ b/rocketpy/prints/flight_prints.py @@ -33,39 +33,36 @@ def initial_conditions(self): ------- None """ - print("\nInitial Conditions\n") - # Post-process results - if self.flight.post_processed is False: - self.flight.post_process() + t_init = self.flight.time[0] + + print(f"Initial time: {t_init:.3f} s") print( - "Position - x: {:.2f} m | y: {:.2f} m | z: {:.2f} m".format( - self.flight.x(0), self.flight.y(0), self.flight.z(0) - ) + f"Position - x: {self.flight.x(t_init):.2f} m | " + f"y: {self.flight.y(t_init):.2f} m | " + f"z: {self.flight.z(t_init):.2f} m" ) print( - "Velocity - Vx: {:.2f} m/s | Vy: {:.2f} m/s | Vz: {:.2f} m/s".format( - self.flight.vx(0), self.flight.vy(0), self.flight.vz(0) - ) + f"Velocity - Vx: {self.flight.vx(t_init):.2f} m/s | " + f"Vy: {self.flight.vy(t_init):.2f} m/s | " + f"Vz: {self.flight.vz(t_init):.2f} m/s" ) print( - "Attitude - e0: {:.3f} | e1: {:.3f} | e2: {:.3f} | e3: {:.3f}".format( - self.flight.e0(0), - self.flight.e1(0), - self.flight.e2(0), - self.flight.e3(0), - ) + f"Attitude (quaternions) - e0: {self.flight.e0(t_init):.3f} | " + f"e1: {self.flight.e1(t_init):.3f} | " + f"e2: {self.flight.e2(t_init):.3f} | " + f"e3: {self.flight.e3(t_init):.3f}" ) print( - "Euler Angles - Spin φ : {:.2f}° | Nutation θ: {:.2f}° | Precession ψ: {:.2f}°".format( - self.flight.phi(0), self.flight.theta(0), self.flight.psi(0) - ) + f"Euler Angles - Spin φ : {self.flight.phi(t_init):.2f}° | " + f"Nutation θ: {self.flight.theta(t_init):.2f}° | " + f"Precession ψ: {self.flight.psi(t_init):.2f}°" ) print( - "Angular Velocity - ω1: {:.2f} rad/s | ω2: {:.2f} rad/s| ω3: {:.2f} rad/s".format( - self.flight.w1(0), self.flight.w2(0), self.flight.w3(0) - ) + f"Angular Velocity - ω1: {self.flight.w1(t_init):.2f} rad/s | " + f"ω2: {self.flight.w2(t_init):.2f} rad/s | " + f"ω3: {self.flight.w3(t_init):.2f} rad/s" ) print(f"Initial Stability Margin: {self.flight.initial_stability_margin:.3f} c")