From 10aa525a448821b515df1731116b60963238efc5 Mon Sep 17 00:00:00 2001 From: Radu Cristea Date: Sat, 9 May 2026 19:47:52 +0300 Subject: [PATCH] fix: tolerate empty valid_t_root in __handle_impact_event The cubic Hermite root-finder filters with a strict open interval (0, t1). When numerical noise places the ground crossing at a boundary (e.g. a rocket settling under parachute), no candidate survives and valid_t_root[0] raises IndexError. Fall back to t1 in that case -- solution[-1] is at or below ground by then, so it is the correct side of the crossing. --- rocketpy/simulation/flight.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 2293d9706..a65cb9075 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1187,8 +1187,10 @@ def __handle_impact_event(self, phase, phase_index, node_index): ] if len(valid_t_root) > 1: # pragma: no cover raise ValueError("Multiple roots found when solving for impact time.") + # Fall back to t1 when noise places the crossing at the step boundary. + t_root_local = valid_t_root[0] if valid_t_root else t1 # Determine impact state at t_root - self.t = self.t_final = valid_t_root[0] + self.solution[-2][0] + self.t = self.t_final = t_root_local + self.solution[-2][0] interpolator = phase.solver.dense_output() self.y_sol = self.impact_state = interpolator(self.t) # Roll back solution