Skip to content

Commit 660a2df

Browse files
committed
feat: add axial_acceleration with tests
1 parent 793e5f6 commit 660a2df

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

rocketpy/simulation/flight.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,15 @@ def max_acceleration(self):
26192619
"""Maximum acceleration reached by the rocket."""
26202620
max_acceleration_time_index = np.argmax(self.acceleration[:, 1])
26212621
return self.acceleration[max_acceleration_time_index, 1]
2622+
2623+
@cached_property
2624+
def axial_acceleration(self):
2625+
"""Axial acceleration magnitude as a function of time."""
2626+
return (
2627+
self.ax * self.attitude_vector_x
2628+
+ self.ay * self.attitude_vector_y
2629+
+ self.az * self.attitude_vector_z
2630+
)
26222631

26232632
@funcify_method("Time (s)", "Horizontal Speed (m/s)")
26242633
def horizontal_speed(self):

tests/unit/simulation/test_flight.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,37 @@ def test_max_values(flight_calisto_robust):
413413
assert pytest.approx(285.94948, rel=rtol) == test.max_speed
414414

415415

416+
@pytest.mark.parametrize(
417+
"flight_time_attr",
418+
["t_initial", "out_of_rail_time", "apogee_time", "t_final"],
419+
)
420+
def test_axial_acceleration(flight_calisto_custom_wind, flight_time_attr):
421+
"""Tests the axial_acceleration property by manually calculating the
422+
dot product of the acceleration vector and the attitude vector at
423+
specific time steps.
424+
425+
Parameters
426+
----------
427+
flight_calisto_custom_wind : rocketpy.Flight
428+
Flight object to be tested.
429+
flight_time_attr : str
430+
The name of the attribute of the flight object that contains the time
431+
of the point to be tested.
432+
"""
433+
flight = flight_calisto_custom_wind
434+
t = getattr(flight, flight_time_attr)
435+
436+
calculated_axial_acc = flight.axial_acceleration(t)
437+
438+
expected_axial_acc = (
439+
flight.ax(t) * flight.attitude_vector_x(t)
440+
+ flight.ay(t) * flight.attitude_vector_y(t)
441+
+ flight.az(t) * flight.attitude_vector_z(t)
442+
)
443+
444+
assert pytest.approx(expected_axial_acc, abs=1e-9) == calculated_axial_acc
445+
446+
416447
def test_effective_rail_length(flight_calisto_robust, flight_calisto_nose_to_tail):
417448
"""Tests the effective rail length of the flight simulation. The expected
418449
values are calculated by hand, and should be valid as long as the rail

0 commit comments

Comments
 (0)