44import numpy as np
55import pytest
66
7- from rocketpy import Flight
7+ from rocketpy import Flight , Parachute
88
99plt .rcParams .update ({"figure.max_open_warning" : 0 })
1010
@@ -69,7 +69,9 @@ def test_all_info_different_solvers(
6969
7070
7171@patch ("matplotlib.pyplot.show" )
72- def test_hybrid_motor_flight (mock_show , flight_calisto_hybrid_modded ): # pylint: disable=unused-argument
72+ def test_hybrid_motor_flight (
73+ mock_show , flight_calisto_hybrid_modded
74+ ): # pylint: disable=unused-argument
7375 """Test the flight of a rocket with a hybrid motor. This test only validates
7476 that a flight simulation can be performed with a hybrid motor; it does not
7577 validate the results.
@@ -85,7 +87,9 @@ def test_hybrid_motor_flight(mock_show, flight_calisto_hybrid_modded): # pylint
8587
8688
8789@patch ("matplotlib.pyplot.show" )
88- def test_liquid_motor_flight (mock_show , flight_calisto_liquid_modded ): # pylint: disable=unused-argument
90+ def test_liquid_motor_flight (
91+ mock_show , flight_calisto_liquid_modded
92+ ): # pylint: disable=unused-argument
8993 """Test the flight of a rocket with a liquid motor. This test only validates
9094 that a flight simulation can be performed with a liquid motor; it does not
9195 validate the results.
@@ -102,7 +106,9 @@ def test_liquid_motor_flight(mock_show, flight_calisto_liquid_modded): # pylint
102106
103107@pytest .mark .slow
104108@patch ("matplotlib.pyplot.show" )
105- def test_time_overshoot (mock_show , calisto_robust , example_spaceport_env ): # pylint: disable=unused-argument
109+ def test_time_overshoot (
110+ mock_show , calisto_robust , example_spaceport_env
111+ ): # pylint: disable=unused-argument
106112 """Test the time_overshoot parameter of the Flight class. This basically
107113 calls the all_info() method for a simulation without time_overshoot and
108114 checks if it returns None. It is not testing if the values are correct,
@@ -131,7 +137,9 @@ def test_time_overshoot(mock_show, calisto_robust, example_spaceport_env): # py
131137
132138
133139@patch ("matplotlib.pyplot.show" )
134- def test_simpler_parachute_triggers (mock_show , example_plain_env , calisto_robust ): # pylint: disable=unused-argument
140+ def test_simpler_parachute_triggers (
141+ mock_show , example_plain_env , calisto_robust
142+ ): # pylint: disable=unused-argument
135143 """Tests different types of parachute triggers. This is important to ensure
136144 the code is working as intended, since the parachute triggers can have very
137145 different format definitions. It will add 3 parachutes using different
@@ -273,7 +281,9 @@ def test_eccentricity_on_flight( # pylint: disable=unused-argument
273281
274282
275283@patch ("matplotlib.pyplot.show" )
276- def test_air_brakes_flight (mock_show , flight_calisto_air_brakes ): # pylint: disable=unused-argument
284+ def test_air_brakes_flight (
285+ mock_show , flight_calisto_air_brakes
286+ ): # pylint: disable=unused-argument
277287 """Test the flight of a rocket with air brakes. This test only validates
278288 that a flight simulation can be performed with air brakes; it does not
279289 validate the results.
@@ -294,7 +304,9 @@ def test_air_brakes_flight(mock_show, flight_calisto_air_brakes): # pylint: dis
294304
295305
296306@patch ("matplotlib.pyplot.show" )
297- def test_initial_solution (mock_show , example_plain_env , calisto_robust ): # pylint: disable=unused-argument
307+ def test_initial_solution (
308+ mock_show , example_plain_env , calisto_robust
309+ ): # pylint: disable=unused-argument
298310 """Tests the initial_solution option of the Flight class. This test simply
299311 simulates the flight using the initial_solution option and checks if the
300312 all_info method returns None.
@@ -339,7 +351,9 @@ def test_initial_solution(mock_show, example_plain_env, calisto_robust): # pyli
339351
340352
341353@patch ("matplotlib.pyplot.show" )
342- def test_empty_motor_flight (mock_show , example_plain_env , calisto_motorless ): # pylint: disable=unused-argument
354+ def test_empty_motor_flight (
355+ mock_show , example_plain_env , calisto_motorless
356+ ): # pylint: disable=unused-argument
343357 flight = Flight (
344358 rocket = calisto_motorless ,
345359 environment = example_plain_env ,
@@ -438,3 +452,42 @@ def test_rocket_csys_equivalence(
438452 flight_calisto_robust .initial_solution ,
439453 flight_calisto_nose_to_tail_robust .initial_solution ,
440454 )
455+
456+
457+ # TODO: fix the issues on this test and debug shock analysis
458+ def test_opening_shock_recorded_during_flight (calisto , example_plain_env ):
459+ """
460+ Testing if the opening shock is being saved correctly during simulations.
461+ """
462+ # Defining test parachute
463+ calisto .parachutes = []
464+
465+ target_coeff = 1.75
466+ main_chute = Parachute (
467+ name = "Main Test" ,
468+ cd_s = 5.0 ,
469+ trigger = "apogee" ,
470+ sampling_rate = 100 ,
471+ opening_shock_coefficient = target_coeff ,
472+ )
473+
474+ calisto .parachutes .append (main_chute )
475+
476+ # Simulating
477+ flight = Flight (
478+ rocket = calisto ,
479+ environment = example_plain_env ,
480+ rail_length = 5 ,
481+ inclination = 85 ,
482+ heading = 0 ,
483+ terminate_on_apogee = False ,
484+ )
485+
486+ # Analysing results
487+ assert len (flight .parachute_events ) > 0 , "No parachute event registered!"
488+
489+ event_time , flown_chute = flight .parachute_events [0 ]
490+
491+ assert flown_chute .opening_shock_force is not None
492+ assert flown_chute .opening_shock_force > 0
493+ assert flown_chute .opening_shock_coefficient == target_coeff
0 commit comments