Skip to content

BUG: Flight.potential_energy uses a different gravity model than the simulation #1216

Done

Description

@Gui-FernandesBR

Reproduction

from rocketpy import Environment
mu = 3.986004418e14  # hard-coded in Flight.potential_energy
env = Environment()
print(env.gravity(0), mu / env.earth_radius**2)  # 9.7803 vs 9.7983 (+0.18%)
env = Environment(gravity=9.81)
print(env.gravity(0), mu / env.earth_radius**2)  # 9.81 vs 9.7983

Mechanism

Flight.potential_energy uses a fixed mu with an inverse-square law, while the flight is integrated with env.gravity (Somigliana by default, or whatever the user passes). The two gravity models differ, so Flight.total_energy drifts even without drag: about 0.18% of m * g * dz on the default Calisto flight, roughly 700 J over a 398 kJ coast. With a user-defined gravity the potential energy is not tied to the simulated model at all. The code already carries # TODO: this constant should come from Environment.

Hypothesis (not verified): deriving the potential energy from env.gravity would make total_energy consistent with the integrated dynamics.

Found while reviewing #1204 (follow-up to #1202).

Activity

  1. MateusStano commented on Nov 28, 2026

    @MateusStano
    Member

    Fixed by #1224, merged into develop: Flight.potential_energy is now computed from Environment.gravity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions