RocketPy icon indicating copy to clipboard operation
RocketPy copied to clipboard

ENH: Add the Coriolis Force to the Flight class

Open kevin-alcaniz opened this issue 9 months ago • 5 comments

Pull request type

  • [x] Code changes (bugfix, features)

Checklist

  • [ ] Tests for the changes have been added (if needed)
  • [ ] Docs have been reviewed and added / updated
  • [ ] Lint (black rocketpy/ tests/) has passed locally
  • [ ] All tests (pytest tests -m slow --runslow) have passed locally
  • [ ] CHANGELOG.md has been updated (if relevant)

Current behavior

Currently, RocketPy doesn't account for the Coriolis force, even though the Flight Coordinate System is not truly an inertial reference frame.

New behavior

  • Environment class: A new attribute has been added: the Earth's angular velocity vector. Additionally, a new function has been implemented to compute it.

  • Flight class: The Coriolis acceleration has been added to the vdot vector in the u_dot_generalized function. A theoretical explanation justifying this implementation is attached below.

Breaking change

  • [ ] Yes
  • [ ] No

Theory

image image

kevin-alcaniz avatar Mar 31 '25 06:03 kevin-alcaniz

@Gui-FernandesBR All good on my side!!

kevin-alcaniz avatar Apr 07 '25 10:04 kevin-alcaniz

Thank you, @Gui-FernandesBR , I appreciate it!

Sure. I'm looking forward to the third check. If you have any doubts or suggestions, please, let me know.

kevin-alcaniz avatar Apr 07 '25 14:04 kevin-alcaniz

Before we start working on updating the tests, does any of you have anything to say regarding this PR, @phmbressan @MateusStano ? another review would be appreciated here.

Gui-FernandesBR avatar Apr 23 '25 02:04 Gui-FernandesBR

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.11%. Comparing base (4df0b38) to head (5ca314d). Report is 22 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #799      +/-   ##
===========================================
+ Coverage    79.11%   80.11%   +0.99%     
===========================================
  Files           96       98       +2     
  Lines        11575    12057     +482     
===========================================
+ Hits          9158     9659     +501     
+ Misses        2417     2398      -19     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jun 13 '25 18:06 codecov[bot]

Really awesome @kevin-alcaniz!

I took the liberty to add everything that was missing here since it had been so long.

From you implementation though, there was only one mistake: you were applying an extra unnecessary rotation to the earth_rotation_vector. Taking that out made the simulation behavior make more sense.

I also added the coriolis effect to the parachute udot.

For documentation purposes here is a few plots exemplifying the correct expected behavior with the Coriolis acceleration. The simulation here has no wind, no parachutes, and no aerodynamic forces (0 drag and no aero surfaces)

  • Environment at Latitude 0, Inclination = 90, Heading = 0. There is no North-South drift, only westward drift:

image

  • Same conditions, this time showing the effect of increasing latitude. As expected, drift decreases as it gets closer to the poles

image

Now some cases showing the effect of north vs south hemisphere. The expected behavior can be seen from analyzing the added acceleration from the Coriolis effect (written in the Flight Coord System):

$$ a_c = -2 \omega_E \times v = 2 \begin{bmatrix} - v_z \omega \cos{\phi} + v_y \omega \sin{\phi} \\ - v_x \omega \sin{\phi} \\ v_x \omega \cos{\phi} \end{bmatrix} $$

Wherever the $\sin$ terms appear, a difference due to hemisphere is expected. With $v_x$ positive, we expect the northern hemisphere launch to drift southwards, while the southern hemisphere drifts northwards. Opposite should happen for $v_x$ negative

For $v_y$ positive, the northern hemisphere launch should drift further eastwards than the southern hemisphere launch. Opposite for the negative case

  • Free falling rocket beginning at 80000 m. Zero initial velocity.

image

  • Free falling rocket beginning at 80000 m. Positive X (eastwards) velocity.

image

  • Free falling rocket beginning at 80000 m. Negative X (westwards) velocity.

image

  • Free falling rocket beginning at 80000 m. Positive Y (northwards) velocity.

image

  • Free falling rocket beginning at 80000 m. Negative Y (southwards) velocity.

image

Now we just a need a final approve and we can merge this! @Gui-FernandesBR @phmbressan

MateusStano avatar Jun 13 '25 19:06 MateusStano