Skip to content

Commit 3a41c22

Browse files
committed
feat: add axial_acceleration with tests
1 parent 793e5f6 commit 3a41c22

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Attention: The newest changes should be on top -->
3232

3333
### Added
3434

35+
- ENH: Add axial_acceleration attribute to the Flight class [#876](https://github.com/RocketPy-Team/RocketPy/pull/876)
3536
- ENH: Add save functionality to `_MonteCarloPlots.all` method [#848](https://github.com/RocketPy-Team/RocketPy/pull/848)
3637
- ENH: Add persistent caching for ThrustCurve API [#881](https://github.com/RocketPy-Team/RocketPy/pull/881)
3738
- ENH: Compatibility with MERRA-2 atmosphere reanalysis files [#825](https://github.com/RocketPy-Team/RocketPy/pull/825)

rocketpy/simulation/flight.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,15 @@ def max_acceleration(self):
26202620
max_acceleration_time_index = np.argmax(self.acceleration[:, 1])
26212621
return self.acceleration[max_acceleration_time_index, 1]
26222622

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+
)
2631+
26232632
@funcify_method("Time (s)", "Horizontal Speed (m/s)")
26242633
def horizontal_speed(self):
26252634
"""Rocket horizontal speed as a Function of time."""

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import matplotlib
12
import netCDF4
23
import numpy as np
3-
import matplotlib
44
import pytest
55

66
# Configure matplotlib to use non-interactive backend for tests

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)