Skip to content

Commit

Permalink
ENH: Insert apogee state into solution list during flight simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-FernandesBR committed Jul 13, 2024
1 parent 45971e9 commit fdb1791
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Attention: The newest changes should be on top -->

### Changed

- ENH: Insert apogee state into solution list during flight simulation [#638](https://github.com/RocketPy-Team/RocketPy/pull/638)
- ENH: Environment class major refactor may 2024 [#605](https://github.com/RocketPy-Team/RocketPy/pull/605)
- MNT: Refactors the code to adopt pylint [#621](https://github.com/RocketPy-Team/RocketPy/pull/621)
- MNT: Refactor AeroSurfaces [#634](https://github.com/RocketPy-Team/RocketPy/pull/634)
Expand Down
5 changes: 5 additions & 0 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ def __simulate(self, verbose):
phase.solver.status = "finished"

# Check for apogee event
# TODO: negative vz doesn't really mean apogee. Improve this.
if len(self.apogee_state) == 1 and self.y_sol[5] < 0:
# Assume linear vz(t) to detect when vz = 0
t0, vz0 = self.solution[-2][0], self.solution[-2][6]
Expand All @@ -863,6 +864,10 @@ def __simulate(self, verbose):
phase.time_nodes.flush_after(node_index)
phase.time_nodes.add_node(self.t, [], [])
phase.solver.status = "finished"
elif len(self.solution) > 2:
# adding the apogee state to solution increases accuracy
# we can only do this if the apogee is not the first state
self.solution.insert(-1, [t_root, *self.apogee_state])
# Check for impact event
if self.y_sol[2] < self.env.elevation:
# Check exactly when it happened using root finding
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,37 @@ def test_empty_motor_flight(
],
)
assert flight.all_info() is None


def test_freestream_speed_at_apogee(example_plain_env, calisto):
"""
Asserts that a rocket at apogee has a free stream speed of 0.0 m/s in all
directions given that the environment doesn't have any wind.
"""
# NOTE: this rocket doesn't move in x or z direction. There's no wind.
hard_atol = 1e-12
soft_atol = 1e-6
test_flight = Flight(
environment=example_plain_env,
rocket=calisto,
rail_length=5.2,
inclination=90,
heading=0,
terminate_on_apogee=False,
atol=13 * [hard_atol],
)

assert np.isclose(
test_flight.stream_velocity_x(test_flight.apogee_time), 0.0, atol=hard_atol
)
assert np.isclose(
test_flight.stream_velocity_y(test_flight.apogee_time), 0.0, atol=hard_atol
)
# NOTE: stream_velocity_z has a higher error due to apogee detection estimation
assert np.isclose(
test_flight.stream_velocity_z(test_flight.apogee_time), 0.0, atol=soft_atol
)
assert np.isclose(
test_flight.free_stream_speed(test_flight.apogee_time), 0.0, atol=soft_atol
)
assert np.isclose(test_flight.apogee_freestream_speed, 0.0, atol=soft_atol)

0 comments on commit fdb1791

Please sign in to comment.