Repository navigation
Conversation
Flight.potential_energy computed mu * m * (1/(z + R) - 1/R), which is negative for z > 0 and decreases as the rocket climbs. Swap the two terms so the potential energy relative to sea level is positive and grows with altitude. Flight.total_energy inherits the fix. Fixes RocketPy-Team#1202
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Checklist
ruff check/ruff format --check) has passed locallypytest tests/unit tests/integration) have passed locallyCurrent behavior
Flight.potential_energycomputesmu * m * (1 / (z + R) - 1 / R), which is negative forz > 0and gets more negative as the rocket climbs.Flight.total_energyinherits the sign error. Between burn out and apogee the mass is constant, so the change in potential energy should bem * g * dz; with the issue's script it comes out as-398754.6 Jinstead of+398711.0 J. The trajectory itself is not affected.New behavior
The two terms are swapped, so the potential energy relative to sea level is positive and increases with altitude. Added
test_potential_energy_increases_with_altitude, which checks that the burn-out-to-apogee change inpotential_energymatchesm * g * dzon theflight_calistofixture. It fails ondevelop(-398045 Jvs+398623 J) and passes with this change.Breaking change
potential_energyandtotal_energychange sign (they were wrong before); the energy plots inFlight.plotsandCompareFlightswill now show the expected curves.Fixes #1202