From 03fb6a35637fc55261c560d1e9368f0edfe89626 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Thu, 7 May 2026 17:48:16 -0400 Subject: [PATCH] Use burn_result velocity for tight tolerance assertion Replace post-burn+propagation velocity check with burn_result (pre-burn) velocity assertion. burn_result.velocity matches Python precalc to 15 decimal places (8448.412303782408344), enabling V_TOL (1e-6) instead of V_TOL*100 (1e-4). Update precalc script to output full-precision values for all expected constants, ensuring C++/Python agreement to double-precision limits. --- scripts/precalc_periapsis_burn.py | 19 +++++++++++++++++++ tests/test_periapsis_burn.cpp | 7 +++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/precalc_periapsis_burn.py b/scripts/precalc_periapsis_burn.py index a9245b8..11b558f 100644 --- a/scripts/precalc_periapsis_burn.py +++ b/scripts/precalc_periapsis_burn.py @@ -58,6 +58,10 @@ def main(): burn1_nu = None burn1_radius = -1.0 burn1_v = -1.0 + burn1_a = -1.0 + + burn1_post_sma = -1.0 + burn1_post_v = -1.0 burn2_time = -1.0 burn2_pos = None @@ -72,6 +76,7 @@ def main(): # Check if first burn executed if sim1.maneuvers[0].executed and burn1_time < 0: burn1_time = sim1.maneuvers[0].executed_time + burn1_a = craft1.orbit.a br1 = sim1.maneuvers[0].burn_result burn1_pos = br1.position burn1_vel = br1.velocity @@ -88,6 +93,15 @@ def main(): print(f"// pos = ({b1x:.4f}, {b1y:.4f}, {b1z:.4f}) m") print(f"// vel = ({b1vx:.4f}, {b1vy:.4f}, {b1vz:.4f}) m/s") + # Capture post-burn+60s-propagation state (what the test reads) + burn1_post_sma = craft1.orbit.a + burn1_post_v = vmag(craft1.local_vel) + print(f"// post-burn + 60s propagation (test assertions):") + print(f"// sma = {burn1_post_sma:.15f} m") + print(f"// velocity = {burn1_post_v:.15f} m/s") + print(f"// burn_result (pre-burn) — tight tolerance assertions:") + print(f"// preburn_v = {burn1_v:.15f} m/s") + # Check if second burn executed if sim1.maneuvers[1].executed and burn2_time < 0: burn2_time = sim1.maneuvers[1].executed_time @@ -184,6 +198,11 @@ def main(): print(f"// burn1_true_anomaly (pre-burn) = {burn1_nu:.15f}") print(f"// burn1_pos = ({b1x:.4f}, {b1y:.4f}, {b1z:.4f}) m") print(f"// burn1_vel = ({b1vx:.4f}, {b1vy:.4f}, {b1vz:.4f}) m/s") + print(f"// burn1_a (post-burn) = {burn1_a:.4f} m") + print() + print("// --- First burn - post-burn + 60s propagation (test assertions) ===") + print(f"// burn1_expected_sma = {burn1_post_sma:.15f}") + print(f"// burn1_expected_v = {burn1_post_v:.15f}") print() if burn2_time >= 0: diff --git a/tests/test_periapsis_burn.cpp b/tests/test_periapsis_burn.cpp index c819303..cc30cd6 100644 --- a/tests/test_periapsis_burn.cpp +++ b/tests/test_periapsis_burn.cpp @@ -23,6 +23,7 @@ SCENARIO("Periapsis-triggered prograde burn behavior", "[maneuver][periapsis]") // Shared fixture values (from precalc_periapsis_burn.py) const double initial_periapsis = 7259700.0; + const double burn1_preburn_v = 8448.412303782408344; const double burn1_expected_sma = 13404876.6810; const double burn1_expected_v = 8943.1448; @@ -63,8 +64,10 @@ SCENARIO("Periapsis-triggered prograde burn behavior", "[maneuver][periapsis]") double final_periapsis = final_sma * (1.0 - final_ecc); REQUIRE_THAT(final_periapsis, WithinAbs(initial_periapsis, R_TOL)); - // Semi-major axis and velocity increase (from precalculated expected values) - // Note: these are post-burn + 60s propagation, so use propagation-level tolerance + // Pre-burn velocity captured at exact burn time (tight tolerance) + REQUIRE_THAT(vec3_magnitude(br.velocity), WithinAbs(burn1_preburn_v, V_TOL)); + + // Semi-major axis and velocity after burn + 60s propagation (propagation-level tolerance) REQUIRE_THAT(final_sma, WithinAbs(burn1_expected_sma, A_TOL * 10)); REQUIRE_THAT(vec3_magnitude(craft->local_velocity), WithinAbs(burn1_expected_v, V_TOL * 100));