symplectic
cosmic_warp.core.integrators.symplectic
Symplectic integrator implementation for Hamiltonian systems.
This integrator preserves the symplectic structure of Hamiltonian mechanics, making it ideal for long-term orbital simulations and energy conservation.
SymplecticIntegrator
Bases: Integrator
Symplectic Integrator (second-order, kick-drift-kick).
More accurate and stable for long-term simulations of mechanical systems. Suitable for: - Long-duration orbital simulations - Systems with conserved quantities (e.g., energy, momentum) - Scenarios where stability over many time steps is critical
Accuracy notes: - The scheme is symplectic only for constant mass. While thrusters fire, propellant consumption makes the system non-Hamiltonian and energy is (correctly) not conserved. Each kick solves the constant-force variable-mass flow exactly, so burns stay second-order. - The rotational drift is the explicit midpoint rule on the rotation group: omega is taken at the half-step attitude. Total angular momentum is conserved exactly in the inertial frame; the attitude error is second-order in dt. - Velocity-dependent forces (drag) are evaluated at the start of each kick, which is first-order in their (usually tiny) contribution.
Source code in cosmic_warp/core/integrators/base.py
gravity_vector
Gravitational force [N], zero when gravity is disabled.
kick_momentum
kick_momentum(
mom: vec3d,
m_start: float64,
m_end: float64,
F_grav: vec3d,
F_other: vec3d,
h: float64,
) -> vec3d
Exact momentum kick over time h with forces held fixed and mass falling linearly from m_start to m_end (the burn fraction keeps the flow on for the whole kick, so the mass never sits at a dry clamp within it).
With expelled propellant leaving at the vehicle velocity (Meshchersky), m dv/dt = F. Gravity is proportional to mass (constant acceleration); thrust and drag are not, so they act through the integral of 1/m(t): v1 = v0 + h F_grav/m_start + F_other * int_0^h dt/m(t)