From 40f894e997d6c8f67c1ff52b342427980524412b Mon Sep 17 00:00:00 2001 From: Zakariya Ghazzol <214604256+zakariyaghazzol@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:52:31 -0400 Subject: [PATCH 1/2] BUG: fix branch-local center-of-mass derivatives --- rocketpy/rocket/rocket.py | 189 ++++++++++++++++-- rocketpy/simulation/flight.py | 8 +- tests/acceptance/test_defiance_rocket.py | 15 +- .../simulation/test_ignition_cm_rates.py | 127 ++++++++++++ tests/unit/rocket/test_com_to_cdm_rates.py | 174 ++++++++++++++++ tests/unit/rocket/test_rocket.py | 15 +- 6 files changed, 497 insertions(+), 31 deletions(-) create mode 100644 tests/integration/simulation/test_ignition_cm_rates.py create mode 100644 tests/unit/rocket/test_com_to_cdm_rates.py diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index f973677fd..cb7f2238f 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -1024,36 +1024,185 @@ def evaluate_nozzle_gyration_tensor(self): return self.nozzle_gyration_tensor def evaluate_com_to_cdm_function(self): - """Evaluates the z-coordinate of the center of mass (COM) relative to - the center of dry mass (CDM). + """Calculate the signed COM-to-CDM offset used by the flight equations. - Notes - ----- - 1. The `com_to_cdm_function` plus `center_of_mass` should be equal - to `center_of_dry_mass_position` at every time step. - 2. The `com_to_cdm_function` is a function of time and will usually - already be discretized. + Keep the mass-fraction formula as a callable. Sampling the quotient + and then linearly interpolating it would remove its curvature. Returns ------- - self.com_to_cdm_function : Function - Function of time expressing the z-coordinate of the center of mass - relative to the center of dry mass. + Function + Axial offset in meters, including the rocket's coordinate-system + sign factor. """ - self.com_to_cdm_function = ( - -1 - * ( - (self.center_of_propellant_position - self.center_of_dry_mass_position) - * self._csys + + def source(t): + propellant_mass = self.motor.propellant_mass(t) + if np.isscalar(propellant_mass) and propellant_mass == 0: + return 0.0 + return ( + -self._csys + * ( + self.center_of_propellant_position(t) + - self.center_of_dry_mass_position + ) + * propellant_mass + / self.total_mass(t) ) - * self.motor.propellant_mass - / self.total_mass + + self.com_to_cdm_function = Function( + source, + inputs="Time (s)", + outputs="Z Coordinate COM to CDM (m)", ) - self.com_to_cdm_function.set_inputs("Time (s)") - self.com_to_cdm_function.set_outputs("Z Coordinate COM to CDM (m)") self.com_to_cdm_function.set_title("Z Coordinate COM to CDM") + + # A hybrid or cluster combines other motors. Include their data points + # so derivative samples cannot cross an underlying interpolation knot. + motors = [self.motor] + functions = [self.center_of_propellant_position] + boundaries = list(self.motor.burn_time) + visited = set() + for motor in motors: + if id(motor) in visited: + continue + visited.add(id(motor)) + functions.extend((motor.propellant_mass, motor.center_of_propellant_mass)) + for name in ("solid", "liquid", "motor"): + component = getattr(motor, name, None) + if component is not None: + motors.append(component) + for positioned_tank in getattr(motor, "positioned_tanks", ()): + tank = positioned_tank["tank"] + boundaries.extend(tank.flux_time) + functions.extend((tank.fluid_mass, tank.center_of_mass)) + + for function in functions: + grid = getattr(function, "x_array", None) + if grid is not None: + boundaries.extend(grid) + + boundaries = np.asarray(boundaries, dtype=float) + self._com_to_cdm_rate_boundaries = np.unique( + boundaries[np.isfinite(boundaries)] + ) return self.com_to_cdm_function + def _get_com_to_cdm_rates(self, t, dx=1e-4): + """Calculate the CM offset and its first two time derivatives. + + Use samples from a single smooth time interval. At an exact boundary, + select the interval just after it; this gives a finite one-sided rate, + not the impulse associated with an abrupt change in slope. + + Callable mass and position inputs must accept complex perturbations + and be smooth between known boundaries. Their internal discontinuities + cannot be discovered automatically. After changing these inputs, call + ``evaluate_com_to_cdm_function`` to rebuild the boundary list. + + Parameters + ---------- + t : float + Time in seconds. + dx : float, optional + Maximum time spacing for derivative samples, in seconds. + + Returns + ------- + tuple of float + Signed offset and its first two time derivatives, in m, m/s and m/s². + """ + if not math.isfinite(t) or not math.isfinite(dx) or dx <= 0: + raise ValueError("Time must be finite and dx must be positive and finite.") + + boundaries = self._com_to_cdm_rate_boundaries + index = np.searchsorted(boundaries, t, side="right") + left = boundaries[index - 1] if index else -math.inf + right = boundaries[index] if index < len(boundaries) else math.inf + h = min(dx, (right - left) / 4) + # Move the smallest possible step past a knot so the interpolator + # evaluates the segment after it, not the segment before it. + anchor = math.nextafter(t, right) if t == left else t + + # Use centered samples when possible. Near an edge, take both samples + # inward instead of shrinking the spacing until roundoff dominates. + if left < t - h and t + h < right: + sample_times = (t - h, t + h) + direction = 0 + elif t + 2 * h < right: + sample_times = (t + h, t + 2 * h) + direction = 1 + else: + sample_times = (t - h, t - 2 * h) + direction = -1 + + def input_rates(function): + # Interpolated inputs already know their polynomial derivatives. + # Use those directly; only callable inputs need extra samples. + if getattr(function, "x_array", None) is not None: + return ( + function(t), + function.differentiate(anchor, order=1), + function.differentiate(anchor, order=2), + ) + if isinstance(function.source, numbers.Number): + return function(t), 0.0, 0.0 + if ( + not left < anchor < right + or not all(left < sample < right for sample in sample_times) + or len({anchor, *sample_times}) != 3 + ): + raise ValueError( + "CM branch is too narrow for distinct derivative samples." + ) + # Differentiate the first rate within this interval. A second + # difference of values across an ignition kink would create 1/dx. + derivative = function.differentiate_complex_step + first = derivative(anchor) + first_sample, second_sample = ( + derivative(sample) for sample in sample_times + ) + if direction: + second = ( + direction + * (-3 * first + 4 * first_sample - second_sample) + / (2 * h) + ) + else: + second = (second_sample - first_sample) / (2 * h) + return function(t), first, second + + mass, mass_rate, mass_second = input_rates(self.motor.propellant_mass) + total_mass = self.dry_mass + mass + if total_mass <= 0: + raise ValueError("Total rocket mass must be positive.") + # With no propellant and no mass change, its center position is + # irrelevant and may be undefined (for example, in an empty tank). + if mass == 0 and mass_rate == 0 and mass_second == 0: + return 0.0, 0.0, 0.0 + + position, position_rate, position_second = input_rates( + self.center_of_propellant_position + ) + distance = -self._csys * (position - self.center_of_dry_mass_position) + distance_rate = -self._csys * position_rate + distance_second = -self._csys * position_second + + # The offset is distance * mass_fraction. Apply the quotient rule to + # that fraction, then the product rule to the complete offset. + fraction = mass / total_mass + fraction_rate = self.dry_mass * mass_rate / total_mass**2 + fraction_second = self.dry_mass * ( + mass_second / total_mass**2 - 2 * mass_rate**2 / total_mass**3 + ) + return ( + distance * fraction, + distance_rate * fraction + distance * fraction_rate, + distance_second * fraction + + 2 * distance_rate * fraction_rate + + distance * fraction_second, + ) + def get_inertia_tensor_at_time(self, t): """Returns a Matrix representing the inertia tensor of the rocket with respect to the rocket's center of dry mass at a given time. It evaluates diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 43790110c..a39bc565e 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -2769,11 +2769,11 @@ def u_dot_generalized(self, t, u, post_processing=False): # pylint: disable=too total_mass_dot = self.rocket.total_mass_flow_rate.get_value_opt(t) total_mass_ddot = self.rocket.total_mass_flow_rate.differentiate_complex_step(t) ## CM position vector and time derivatives relative to CDM in body frame - r_CM_z = self.rocket.com_to_cdm_function - r_CM_t = r_CM_z.get_value_opt(t) + # Keep the CM derivatives on one side of ignition and other data knots. + r_CM_t, r_CM_rate, r_CM_second = self.rocket._get_com_to_cdm_rates(t) r_CM = Vector([0, 0, r_CM_t]) - r_CM_dot = Vector([0, 0, r_CM_z.differentiate_complex_step(t)]) - r_CM_ddot = Vector([0, 0, r_CM_z.differentiate(t, order=2)]) + r_CM_dot = Vector([0, 0, r_CM_rate]) + r_CM_ddot = Vector([0, 0, r_CM_second]) ## Nozzle position vector r_NOZ = Vector([0, 0, self.rocket.nozzle_to_cdm]) ## Nozzle gyration tensor diff --git a/tests/acceptance/test_defiance_rocket.py b/tests/acceptance/test_defiance_rocket.py index 47d96359b..51190999b 100644 --- a/tests/acceptance/test_defiance_rocket.py +++ b/tests/acceptance/test_defiance_rocket.py @@ -10,7 +10,9 @@ MEASURED_APOGEE_AGL = 9308.32 MAX_RELATIVE_APOGEE_ERROR = 0.01 REFERENCE_MAX_SPEED = 444.24 -REFERENCE_MAX_ACCELERATION = 10400.76 +# The old 10400.76 m/s² reference was a numerical CM-derivative spike at +# burnout, not a measured acceleration. Keep the finite powered-flight peak. +REFERENCE_MAX_ACCELERATION = 88.89 REFERENCE_IMPACT_X = 1609.40 REFERENCE_IMPACT_Y = 87.03 REFERENCE_METRIC_RELATIVE_TOLERANCE = 0.01 @@ -140,3 +142,14 @@ def test_defiance_rocket_matches_reference_flight_metrics(defiance_flight): assert defiance_flight.y_impact == pytest.approx( REFERENCE_IMPACT_Y, **impact_tolerance ) + + +@pytest.mark.parametrize("dx", [1e-3, 1e-4, 1e-5]) +def test_defiance_burnout_cm_rates(defiance_flight, dx): + """Burnout must not create a CM-acceleration spike as spacing shrinks.""" + rocket = defiance_flight.rocket + + _, first, second = rocket._get_com_to_cdm_rates(rocket.motor.burn_out_time, dx=dx) + + assert (first, second) == pytest.approx((0.0, 0.0), abs=1e-12) + assert defiance_flight.max_acceleration_time < rocket.motor.burn_out_time diff --git a/tests/integration/simulation/test_ignition_cm_rates.py b/tests/integration/simulation/test_ignition_cm_rates.py new file mode 100644 index 000000000..c4a6d2856 --- /dev/null +++ b/tests/integration/simulation/test_ignition_cm_rates.py @@ -0,0 +1,127 @@ +import numpy as np +import pytest + +from rocketpy import Flight, HybridMotor + + +@pytest.mark.parametrize("step", [1e-6, 2e-6, 4e-6]) +def test_ignition_rhs_uses_branch_local_cm_rates( + calisto_hybrid_modded, example_plain_env, monkeypatch, step +): + """Use production CM rates in the real flight RHS at ignition.""" + rocket = calisto_hybrid_modded + ignition = rocket.motor.burn_start_time + end = float(rocket.motor.solid.propellant_mass.x_array[1]) + offset = rocket.com_to_cdm_function + mass = rocket.total_mass + + # Here, mass and offset * mass each vary linearly. Differentiating their + # ratio gives reference rates without using the production rate helper. + width = end - ignition + mass_start = mass(ignition) + mass_slope = (mass(end) - mass_start) / width + moment_start = offset(ignition) * mass_start + moment_slope = (offset(end) * mass(end) - moment_start) / width + expected_rate = ( + moment_slope / mass_start - moment_start * mass_slope / mass_start**2 + ) + expected_second = ( + -2 * moment_slope * mass_slope / mass_start**2 + + 2 * moment_start * mass_slope**2 / mass_start**3 + ) + + state = [0, 0, 100, 0, 0, 30, 1, 0, 0, 0, 0.1, 0.2, 0.3] + flight = Flight( + rocket=rocket, + environment=example_plain_env, + rail_length=1, + initial_solution=[ignition + 0.01, *state], + max_time=ignition + 0.0101, + max_time_step=1e-4, + verbose=False, + ) + + reference_calls = [] + + def reference_rates(t): + reference_calls.append(t) + return offset(t), expected_rate, expected_second + + # Reference: substitute independently calculated analytical rates. + with monkeypatch.context() as patch: + patch.setattr( + rocket, + "_get_com_to_cdm_rates", + reference_rates, + ) + expected = np.asarray(flight.u_dot_generalized(ignition, state), dtype=float) + + # If Flight ignored the replacement, both paths could call the old code + # and falsely agree. Check that it really requested these reference rates. + assert reference_calls == [ignition] + + # Exercise the real production method at several sample spacings. + production_rates = rocket._get_com_to_cdm_rates + production_calls = [] + + def checked_production_rates(t): + production_calls.append(t) + return production_rates(t, dx=step) + + with monkeypatch.context() as patch: + patch.setattr( + rocket, + "_get_com_to_cdm_rates", + checked_production_rates, + ) + actual = np.asarray(flight.u_dot_generalized(ignition, state), dtype=float) + + assert production_calls == [ignition] + assert np.all(np.isfinite(actual)) + np.testing.assert_allclose(actual, expected, rtol=1e-6, atol=1e-8) + + +@pytest.mark.parametrize("max_time_step", [1e-3, 5e-4]) +def test_airborne_flight_crosses_delayed_ignition( + calisto_motorless, oxidizer_tank, example_plain_env, max_time_step +): + """Integrate through ignition off the rail without an acceleration spike.""" + motor = HybridMotor( + thrust_source=lambda t: 2000 - 100 * (t - 1), + burn_time=(1, 11), + dry_mass=8, + dry_inertia=(4, 4, 0.1), + center_of_dry_mass_position=0, + grain_density=1700, + grain_number=4, + grain_initial_height=0.1, + grain_separation=0, + grain_initial_inner_radius=0.04, + grain_outer_radius=0.1, + grains_center_of_mass_position=-0.1, + nozzle_position=-0.4, + nozzle_radius=0.07, + ) + motor.add_tank(oxidizer_tank, position=0.3) + rocket = calisto_motorless + rocket.add_motor(motor, position=-1.373) + state = [0, 0, 100, 0, 0, 30, 1, 0, 0, 0, 0, 0, 0] + + flight = Flight( + rocket=rocket, + environment=example_plain_env, + rail_length=1, + initial_solution=[0.99, *state], + max_time=1.02, + max_time_step=max_time_step, + verbose=False, + ) + solution = np.asarray(flight.solution, dtype=float) + + assert np.all(np.isfinite(solution)) + assert np.any(np.isclose(solution[:, 0], 1.0, rtol=0, atol=1e-12)) + assert solution[-1, 0] == pytest.approx(1.02) + assert solution[-1, 6] > state[5] + # Thrust is about 2 kN on a roughly 51 kg rocket. A 100 m/s² bound + # allows normal dynamics but rejects the former ~37000 m/s² spike. + assert flight.max_acceleration < 100 diff --git a/tests/unit/rocket/test_com_to_cdm_rates.py b/tests/unit/rocket/test_com_to_cdm_rates.py new file mode 100644 index 000000000..75c4799fd --- /dev/null +++ b/tests/unit/rocket/test_com_to_cdm_rates.py @@ -0,0 +1,174 @@ +import numpy as np +import pytest + +from rocketpy import Function + + +def _set_mass_fraction_model(rocket, source): + """Use a 6 kg dry rocket with propellant centered 3 m behind it.""" + rocket.dry_mass = 6.0 + rocket.center_of_dry_mass_position = 0.0 + rocket.center_of_propellant_position = Function(-3.0) + rocket.motor.propellant_mass = Function( + source, interpolation="linear", extrapolation="constant" + ) + rocket.total_mass = Function( + lambda t: rocket.dry_mass + rocket.motor.propellant_mass(t) + ) + rocket.evaluate_com_to_cdm_function() + + +@pytest.mark.parametrize("source_kind", ["array", "callable"]) +@pytest.mark.parametrize("dx", [1e-3, 1e-4]) +@pytest.mark.parametrize( + "time, expected", + [ + (-0.1, (1.2, 0.0, 0.0)), + (0.0, (1.2, -0.36, -0.144)), + (np.nextafter(0.0, 1.0), (1.2, -0.36, -0.144)), + (0.5, (1.0, -4 / 9, -16 / 81)), + (np.nextafter(1.0, 0.0), (0.75, -0.5625, -0.28125)), + (1.0, (0.75, 0.0, 0.0)), + (1.1, (0.75, 0.0, 0.0)), + ], +) +def test_com_to_cdm_rates(calisto_motorless, source_kind, dx, time, expected): + """Get the same physical rates from sampled and callable mass inputs.""" + rocket = calisto_motorless + + def mass_source(t): + if t.real < 0: + return 4.0 + if t.real > 1: + return 2.0 + return 4.0 - 2.0 * t + + source = ( + np.array([[0.0, 4.0], [1.0, 2.0]]) if source_kind == "array" else mass_source + ) + _set_mass_fraction_model(rocket, source) + + actual = rocket._get_com_to_cdm_rates(time, dx=dx) + + assert actual == pytest.approx(expected, rel=1e-6, abs=1e-8) + assert actual[0] == pytest.approx( + rocket.com_to_cdm_function(time), rel=1e-12, abs=1e-12 + ) + + +@pytest.mark.parametrize( + "time, dx", + [(np.nan, 1e-4), (0.0, 0.0), (0.0, -1.0), (0.0, np.inf)], +) +def test_com_to_cdm_rates_invalid_inputs(calisto_motorless, time, dx): + """Reject nonfinite times and invalid sample spacings.""" + with pytest.raises(ValueError): + calisto_motorless._get_com_to_cdm_rates(time, dx=dx) + + +@pytest.mark.parametrize("dx", [1e-6, 1e-4, 1.0]) +def test_com_to_cdm_rates_internal_knot(calisto_motorless, dx): + """At an internal knot, use the mass slope from the segment after it.""" + rocket = calisto_motorless + _set_mass_fraction_model(rocket, np.array([[0.0, 4.0], [0.5, 3.0], [1.0, 2.5]])) + + actual = rocket._get_com_to_cdm_rates(0.5, dx=dx) + + assert actual == pytest.approx((1.0, -2 / 9, -4 / 81), rel=1e-6) + + +def test_com_to_cdm_rates_delayed_ignition(calisto_motorless): + """Find a nonzero ignition time without a manually supplied interval.""" + rocket = calisto_motorless + rocket.motor.burn_time = (2.0, 3.0) + rocket.motor.burn_start_time = 2.0 + rocket.motor.burn_out_time = 3.0 + _set_mass_fraction_model(rocket, np.array([[2.0, 4.0], [3.0, 2.0]])) + + assert rocket._get_com_to_cdm_rates(1.9) == pytest.approx((1.2, 0.0, 0.0)) + assert rocket._get_com_to_cdm_rates(2.0) == pytest.approx( + (1.2, -0.36, -0.144), rel=1e-6 + ) + + +@pytest.mark.parametrize("dx", [1e-6, 1e-4, 1e-3]) +def test_com_to_cdm_rates_moving_propellant_center(calisto_motorless, dx): + """Include the center's velocity, acceleration and product-rule term.""" + rocket = calisto_motorless + _set_mass_fraction_model(rocket, np.array([[0.0, 4.0], [1.0, 2.0]])) + rocket.center_of_propellant_position = Function( + lambda t: -(3.0 + 0.1 * t + 0.25 * t**2) + ) + rocket.evaluate_com_to_cdm_function() + + assert rocket._get_com_to_cdm_rates(0.0, dx=dx) == pytest.approx( + (1.2, -0.32, 0.032), rel=1e-6, abs=1e-8 + ) + + +@pytest.mark.parametrize("dx", [1e-6, 1e-4, 1e-3]) +@pytest.mark.parametrize("source_kind", ["array", "callable"]) +def test_com_to_cdm_rates_curved_mass(calisto_motorless, dx, source_kind): + """Include the mass's second time derivative in the quotient rule.""" + rocket = calisto_motorless + _set_mass_fraction_model(rocket, lambda t: 4.0 - 2.0 * t + t**2) + if source_kind == "array": + rocket.motor.propellant_mass = Function( + [[0.0, 4.0], [0.5, 3.25], [1.0, 3.0]], interpolation="polynomial" + ) + rocket.evaluate_com_to_cdm_function() + + assert rocket._get_com_to_cdm_rates(0.0, dx=dx) == pytest.approx( + (1.2, -0.36, 0.216), rel=1e-6, abs=1e-8 + ) + + +def test_com_to_cdm_rates_empty_propellant_center(calisto_motorless): + """An undefined empty-tank center must not produce a NaN rocket offset.""" + rocket = calisto_motorless + _set_mass_fraction_model(rocket, 0.0) + rocket.center_of_propellant_position = Function(lambda t: np.nan + 0 * t) + rocket.evaluate_com_to_cdm_function() + + assert rocket._get_com_to_cdm_rates(0.0) == (0.0, 0.0, 0.0) + assert rocket.com_to_cdm_function(0.0) == 0.0 + np.testing.assert_array_equal(rocket.com_to_cdm_function([0.0, 1.0]), [0.0, 0.0]) + + +@pytest.mark.parametrize("time", [0.0, 0.5, 3.9, 4.1]) +def test_com_to_cdm_rates_orientation(calisto, calisto_nose_to_tail, time): + """Mirroring user coordinates must preserve the body-frame offset rates.""" + assert calisto._get_com_to_cdm_rates(time) == pytest.approx( + calisto_nose_to_tail._get_com_to_cdm_rates(time), rel=1e-10, abs=1e-12 + ) + + +@pytest.mark.parametrize("boundary", ["grain_depletion", "tank_data_end"]) +def test_hybrid_com_to_cdm_rates_constant_boundaries(calisto_hybrid_modded, boundary): + """Stop CM motion when the stored mass and center become constant.""" + rocket = calisto_hybrid_modded + if boundary == "grain_depletion": + time = float(rocket.motor.solid.propellant_mass.x_array[-1]) + else: + time = float(rocket.motor.liquid.propellant_mass.x_array[-1]) + + _, first, second = rocket._get_com_to_cdm_rates(time) + + assert (first, second) == pytest.approx((0.0, 0.0), abs=1e-12) + + +def test_hybrid_com_to_cdm_rates_not_clamped_at_thrust_burnout(calisto_hybrid_modded): + """Follow tank data that still changes after the nominal thrust cutoff.""" + rocket = calisto_hybrid_modded + time = rocket.motor.burn_out_time + offset = rocket.com_to_cdm_function + h = 1e-3 + expected_first = (offset(time + h) - offset(time - h)) / (2 * h) + expected_second = (offset(time + h) - 2 * offset(time) + offset(time - h)) / h**2 + + _, first, second = rocket._get_com_to_cdm_rates(time) + + assert abs(first) > 1e-6 + assert (first, second) == pytest.approx( + (expected_first, expected_second), rel=1e-5, abs=1e-9 + ) diff --git a/tests/unit/rocket/test_rocket.py b/tests/unit/rocket/test_rocket.py index 5ac011a8d..9dbffe4d4 100644 --- a/tests/unit/rocket/test_rocket.py +++ b/tests/unit/rocket/test_rocket.py @@ -558,12 +558,15 @@ def test_evaluate_nozzle_gyration_tensor_parallel_axis_term(calisto): def test_evaluate_com_to_cdm_function(calisto): - atol = 1e-3 # Equivalent to 1mm - assert np.allclose( - (calisto.center_of_dry_mass_position - calisto.center_of_mass).source, - calisto.com_to_cdm_function.source, - atol=atol, - ) + """Compare values without requiring a particular source representation.""" + times = np.linspace(0, calisto.motor.burn_out_time, 101) + expected = [ + calisto._csys + * (calisto.center_of_dry_mass_position - calisto.center_of_mass(t)) + for t in times + ] + actual = [calisto.com_to_cdm_function(t) for t in times] + np.testing.assert_allclose(actual, expected, rtol=0, atol=1e-3) def test_get_inertia_tensor_at_time(calisto): From 4e79d51c59318f4beeee7fcc80791b610f8823b5 Mon Sep 17 00:00:00 2001 From: Zakariya Ghazzol <214604256+zakariyaghazzol@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:08:21 -0500 Subject: [PATCH 2/2] TST: account for interpolation roundoff in tip-off report --- tests/unit/simulation/test_udot_rail2_feature.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/simulation/test_udot_rail2_feature.py b/tests/unit/simulation/test_udot_rail2_feature.py index c52252f5a..a8b46efa3 100644 --- a/tests/unit/simulation/test_udot_rail2_feature.py +++ b/tests/unit/simulation/test_udot_rail2_feature.py @@ -321,7 +321,9 @@ def test_udot_rail2_reports_the_accelerations_it_integrates(): assert abs(u_dot[10]) > 0.1 assert flight.alpha1(time) == pytest.approx(u_dot[10], rel=1e-9) assert flight.alpha2(time) == pytest.approx(u_dot[11], rel=1e-9) - assert flight.alpha3(time) == 0 + assert u_dot[12] == 0 + # Interpolation may leave roundoff even at a stored zero sample. + assert flight.alpha3(time) == pytest.approx(u_dot[12], abs=1e-12) assert flight.ax(time) == pytest.approx(u_dot[3], abs=1e-9) assert flight.ay(time) == pytest.approx(u_dot[4], rel=1e-9) assert flight.az(time) == pytest.approx(u_dot[5], rel=1e-9)