Skip to content

Commit afb3e3e

Browse files
Env/flight axial acceleration (#876)
* feat: add axial_acceleration with tests * Update axial_acceleration. * Update CHANGELOG * Update CHANGELOG * Refine docstring for axial_acceleration method Updated docstring for axial_acceleration method to improve clarity. --------- Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com>
1 parent 4ef7e77 commit afb3e3e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3131
Attention: The newest changes should be on top -->
3232

3333
### Added
34+
35+
- ENH: Add axial_acceleration attribute to the Flight class [#876](https://github.com/RocketPy-Team/RocketPy/pull/876)
3436
- ENH: Rail button bending moments calculation in Flight class [#893](https://github.com/RocketPy-Team/RocketPy/pull/893)
3537
- ENH: Built-in flight comparison tool (`FlightComparator`) to validate simulations against external data [#888](https://github.com/RocketPy-Team/RocketPy/pull/888)
3638
- ENH: Add persistent caching for ThrustCurve API [#881](https://github.com/RocketPy-Team/RocketPy/pull/881)

rocketpy/simulation/flight.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,15 @@ def acceleration(self):
25832583
"""Rocket acceleration magnitude as a Function of time."""
25842584
return (self.ax**2 + self.ay**2 + self.az**2) ** 0.5
25852585

2586+
@funcify_method("Time (s)", "Axial Acceleration (m/s²)", "spline", "zero")
2587+
def axial_acceleration(self):
2588+
"""Axial acceleration magnitude as a Function of time."""
2589+
return (
2590+
self.ax * self.attitude_vector_x
2591+
+ self.ay * self.attitude_vector_y
2592+
+ self.az * self.attitude_vector_z
2593+
)
2594+
25862595
@cached_property
25872596
def max_acceleration_power_on_time(self):
25882597
"""Time at which the rocket reaches its maximum acceleration during

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)