Skip to content

Commit eaa9181

Browse files
authored
MNT: net thrust addition to 3 dof in flight class (#907)
* MNT: updated flight.py 3dof for net_thrust - MNT: added net_thrust to u_dot_generalized_3dof in flight.py * TST: net_thrust availability test on 3 dof flight * MNT: docstring adjustment in net_thrust test in test_flight_3dof.py * MNT: lint check update * DOC: changelog.md update * DOC: bug changelog update
1 parent 6eaf99d commit eaa9181

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 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+
- MNT: net thrust addition to 3 dof in flight class [#907] (https://github.com/RocketPy-Team/RocketPy/pull/907)
3536
- ENH: 3-dof lateral motion improvement [#883](https://github.com/RocketPy-Team/RocketPy/pull/883)
3637
- ENH: Add multi-dimensional drag coefficient support (Cd as function of M, Re, α) [#875](https://github.com/RocketPy-Team/RocketPy/pull/875)
3738
- ENH: Add save functionality to `_MonteCarloPlots.all` method [#848](https://github.com/RocketPy-Team/RocketPy/pull/848)
@@ -52,6 +53,7 @@ Attention: The newest changes should be on top -->
5253

5354
### Fixed
5455

56+
- BUG: energy_data plot not working for 3 dof sims [[#906](https://github.com/RocketPy-Team/RocketPy/issues/906)]
5557
- BUG: Fix CSV column header spacing in FlightDataExporter [#864](https://github.com/RocketPy-Team/RocketPy/issues/864)
5658
- BUG: Fix parallel Monte Carlo simulation showing incorrect iteration count [#806](https://github.com/RocketPy-Team/RocketPy/pull/806)
5759

rocketpy/simulation/flight.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,11 +2041,20 @@ def u_dot_generalized_3dof(self, t, u, post_processing=False):
20412041
R3 += fz
20422042

20432043
# Thrust and weight
2044-
thrust = self.rocket.motor.thrust.get_value_opt(t)
2044+
# Calculate net thrust including pressure thrust correction if motor is burning
2045+
if self.rocket.motor.burn_start_time < t < self.rocket.motor.burn_out_time:
2046+
pressure = self.env.pressure.get_value_opt(z)
2047+
net_thrust = max(
2048+
self.rocket.motor.thrust.get_value_opt(t)
2049+
+ self.rocket.motor.pressure_thrust(pressure),
2050+
0,
2051+
)
2052+
else:
2053+
net_thrust = 0
20452054
gravity = self.env.gravity.get_value_opt(z)
20462055
weight_body = Kt @ Vector([0, 0, -total_mass * gravity])
20472056

2048-
total_force = Vector([0, 0, thrust]) + weight_body + Vector([R1, R2, R3])
2057+
total_force = Vector([0, 0, net_thrust]) + weight_body + Vector([R1, R2, R3])
20492058

20502059
# Dynamics
20512060
v_dot = K @ (total_force / total_mass)
@@ -2133,7 +2142,7 @@ def u_dot_generalized_3dof(self, t, u, post_processing=False):
21332142

21342143
if post_processing:
21352144
self.__post_processed_variables.append(
2136-
[t, *v_dot, *w_dot, R1, R2, R3, 0, 0, 0]
2145+
[t, *v_dot, *w_dot, R1, R2, R3, 0, 0, 0, net_thrust]
21372146
)
21382147

21392148
return u_dot

tests/integration/simulation/test_flight_3dof.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,26 @@ def test_weathercock_anti_aligned_uses_perp_axis_and_evolves(flight_weathercock_
301301
assert e_dot_magnitude > 1e-6, (
302302
"Quaternion derivatives should be non-zero for anti-aligned"
303303
)
304+
305+
306+
def test_3dof_net_thrust_available(flight_3dof):
307+
"""Tests that net_thrust property is available in 3 DOF mode.
308+
The net_thrust property is required for energy plots and should be
309+
available in both 3 DOF and 6 DOF modes.
310+
311+
Parameters
312+
----------
313+
flight_3dof : rocketpy.simulation.flight.Flight
314+
A Flight object configured for 3-DOF simulation.
315+
"""
316+
# Check that net_thrust can be accessed
317+
assert hasattr(flight_3dof, "net_thrust"), "net_thrust attribute not found"
318+
319+
# Check that it returns a Function object with data
320+
net_thrust = flight_3dof.net_thrust
321+
assert len(net_thrust) > 0, "net_thrust should have data points"
322+
323+
# Verify that thrust_power can be computed (uses net_thrust internally)
324+
assert hasattr(flight_3dof, "thrust_power"), "thrust_power attribute not found"
325+
thrust_power = flight_3dof.thrust_power
326+
assert len(thrust_power) > 0, "thrust_power should have data points"

0 commit comments

Comments
 (0)