Skip to content

Commit 043ad9c

Browse files
Fix incorrect indexing in max_acceleration_power_off_time
Co-authored-by: Gui-FernandesBR <[email protected]>
1 parent 6e238a7 commit 043ad9c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

rocketpy/simulation/flight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,7 @@ def max_acceleration_power_off_time(self):
26012601
max_acceleration_time_index = np.argmax(
26022602
self.acceleration[burn_out_time_index:, 1]
26032603
)
2604-
return self.acceleration[max_acceleration_time_index, 0]
2604+
return self.acceleration[burn_out_time_index + max_acceleration_time_index, 0]
26052605

26062606
@cached_property
26072607
def max_acceleration_power_off(self):

tests/unit/simulation/test_flight.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,35 @@ def test_stability_static_margins(
628628
assert np.all(moments / wind_sign <= 0)
629629
else: # static_margin == 0
630630
assert np.all(np.abs(moments) <= 1e-10)
631+
632+
633+
def test_max_acceleration_power_off_time_with_controllers(
634+
flight_calisto_air_brakes,
635+
):
636+
"""Test that max_acceleration_power_off_time returns a valid time when
637+
controllers are present (e.g., air brakes). This is a regression test for
638+
a bug where the time was always returned as 0.0.
639+
640+
Parameters
641+
----------
642+
flight_calisto_air_brakes : rocketpy.Flight
643+
Flight object with air brakes. See the conftest.py file for more info
644+
regarding this pytest fixture.
645+
"""
646+
test = flight_calisto_air_brakes
647+
burn_out_time = test.rocket.motor.burn_out_time
648+
649+
# The max_acceleration_power_off_time should be at or after motor burn out
650+
# It should NOT be 0.0, which was the bug behavior
651+
assert test.max_acceleration_power_off_time > 0, (
652+
"max_acceleration_power_off_time should not be zero"
653+
)
654+
assert test.max_acceleration_power_off_time >= burn_out_time - 0.01, (
655+
f"max_acceleration_power_off_time ({test.max_acceleration_power_off_time}) "
656+
f"should be at or after burn_out_time ({burn_out_time})"
657+
)
658+
659+
# Also verify max_acceleration_power_off is positive
660+
assert test.max_acceleration_power_off > 0, (
661+
"max_acceleration_power_off should be greater than zero"
662+
)

0 commit comments

Comments
 (0)