diff --git a/CHANGELOG.md b/CHANGELOG.md index a91a671ec..17b654414 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Attention: The newest changes should be on top --> ### Added + +- ENH: Add axial_acceleration attribute to the Flight class [#876](https://github.com/RocketPy-Team/RocketPy/pull/876) - ENH: Rail button bending moments calculation in Flight class [#893](https://github.com/RocketPy-Team/RocketPy/pull/893) - ENH: Built-in flight comparison tool (`FlightComparator`) to validate simulations against external data [#888](https://github.com/RocketPy-Team/RocketPy/pull/888) - ENH: Add persistent caching for ThrustCurve API [#881](https://github.com/RocketPy-Team/RocketPy/pull/881) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index daa8719f8..05d746b20 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2583,6 +2583,15 @@ def acceleration(self): """Rocket acceleration magnitude as a Function of time.""" return (self.ax**2 + self.ay**2 + self.az**2) ** 0.5 + @funcify_method("Time (s)", "Axial Acceleration (m/s²)", "spline", "zero") + def axial_acceleration(self): + """Axial acceleration magnitude as a Function of time.""" + return ( + self.ax * self.attitude_vector_x + + self.ay * self.attitude_vector_y + + self.az * self.attitude_vector_z + ) + @cached_property def max_acceleration_power_on_time(self): """Time at which the rocket reaches its maximum acceleration during diff --git a/tests/unit/simulation/test_flight.py b/tests/unit/simulation/test_flight.py index 1bd9384e2..a54c5afdb 100644 --- a/tests/unit/simulation/test_flight.py +++ b/tests/unit/simulation/test_flight.py @@ -413,6 +413,37 @@ def test_max_values(flight_calisto_robust): assert pytest.approx(285.94948, rel=rtol) == test.max_speed +@pytest.mark.parametrize( + "flight_time_attr", + ["t_initial", "out_of_rail_time", "apogee_time", "t_final"], +) +def test_axial_acceleration(flight_calisto_custom_wind, flight_time_attr): + """Tests the axial_acceleration property by manually calculating the + dot product of the acceleration vector and the attitude vector at + specific time steps. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. + flight_time_attr : str + The name of the attribute of the flight object that contains the time + of the point to be tested. + """ + flight = flight_calisto_custom_wind + t = getattr(flight, flight_time_attr) + + calculated_axial_acc = flight.axial_acceleration(t) + + expected_axial_acc = ( + flight.ax(t) * flight.attitude_vector_x(t) + + flight.ay(t) * flight.attitude_vector_y(t) + + flight.az(t) * flight.attitude_vector_z(t) + ) + + assert pytest.approx(expected_axial_acc, abs=1e-9) == calculated_axial_acc + + def test_effective_rail_length(flight_calisto_robust, flight_calisto_nose_to_tail): """Tests the effective rail length of the flight simulation. The expected values are calculated by hand, and should be valid as long as the rail