Skip to content

Conversation

kevin-alcaniz
Copy link
Collaborator

@kevin-alcaniz kevin-alcaniz commented Mar 31, 2025

Pull request type

  • 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 and others added 30 commits March 14, 2025 18:46
the wind factor wasn't applied to the env.wind_velocity properties
It showed the nominal and the standard deviation values and it doesn't make sense in a uniform distribution. In a np.random.uniform the 'nominal value' is the lower bound of the distribution, and the 'standard deviation' value is the upper bound. Now, a new condition has been added for the uniform distributions where the mean and semi range are calculated and showed. This way the visualize_attribute function will show the whole range where the random values are uniformly taken in
Added the ability to multiply functions with 2D domains in the __mul__ function
The StochasticAirBrakes class has been created. The __init__.py files in the stochastic and rocketpy folders have also been modified accordingly to incorporate this new class
This functions appends an airbrake and controller objects previuosly created to the rocket
Some functions has been modified and other has been created in order to include the new StochasticAirBrakes feature into the StochasticRocket class. A new function named 'add_air_brakes' has been created to append a StochasticAirBrakes and Controller objects to the StochasticRocket object. A new function '_create_air_brake' has been introduced to create a sample of an AirBrake object through a StochasticAirBrake object. Enventually, the 'create_object' function has been modified to add the sampled AirBrakes to the sampled Rocket
When defining the _Controller object a StochasticAirBrake was input. This is already corrected and a AirBrake object is now introduced
…ontroller

BUG: StochasticAirBrake object input in _Controller
Since the new StochasticAirBrake class is defined, we need the 'time_overshoot' option in the Flight class to ensure that the time step defined in the simulation is the controller sampling rate. The MonteCarlo class has had to be modified as well to include this option.
Documentation related to the StochasticAirBrakes implementation has been added in StochasticAirBrakes, StochasticRocket and Rocket classes.
Unnecessary comment

Co-authored-by: Gui-FernandesBR <[email protected]>
@kevin-alcaniz
Copy link
Collaborator Author

@Gui-FernandesBR All good on my side!!

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @kevin-alcaniz !

From my point of view, this PR adds great value to RocketPy.
@MateusStano would like to review this PR before we proceed to merging it onto develop.

Tests are failing, this happens because some tests have values that were made by running flight and capturing the results. Since the flight simulation has changed with this PR, we have to update the values.
@kevin-alcaniz I know you've been busy, so don't worry, I believe we can work on this problem from our side.

image

@Gui-FernandesBR Gui-FernandesBR requested a review from Copilot April 7, 2025 13:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

rocketpy/simulation/flight.py:1696

  • [nitpick] Consider explicitly indicating the discarded x component (perhaps with a named placeholder like '_x') for clarity. This would help ensure that the component order is immediately clear to readers and maintainers.
_, w_earth_y, w_earth_z = self.env.earth_rotation_vector

rocketpy/simulation/flight.py:1921

  • [nitpick] Verify that the coordinate transformation via Kt applied here produces results consistent with the manual component handling in the u_dot method. Ensuring consistency in handling the Earth's rotation vector across methods is crucial for correct Coriolis force computation.
w_earth = Kt @ Vector(self.env.earth_rotation_vector)

@kevin-alcaniz
Copy link
Collaborator Author

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.

@Gui-FernandesBR
Copy link
Member

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.

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@MateusStano
Copy link
Member

MateusStano commented Jun 13, 2025

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

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update changelog

@MateusStano MateusStano merged commit e428604 into develop Jul 4, 2025
7 of 29 checks passed
@MateusStano MateusStano deleted the enh/add-coriolis-force branch July 4, 2025 15:06
@github-project-automation github-project-automation bot moved this from Next Version to Closed in LibDev Roadmap Jul 4, 2025
aZira371 pushed a commit to aZira371/RocketPy that referenced this pull request Sep 9, 2025
* wind factor bug corrected

the wind factor wasn't applied to the env.wind_velocity properties

* BUG: StochasticModel visualize attributes of a uniform distribution

It showed the nominal and the standard deviation values and it doesn't make sense in a uniform distribution. In a np.random.uniform the 'nominal value' is the lower bound of the distribution, and the 'standard deviation' value is the upper bound. Now, a new condition has been added for the uniform distributions where the mean and semi range are calculated and showed. This way the visualize_attribute function will show the whole range where the random values are uniformly taken in

* variable names corrections

* Corrections requested by the pylint test

* ENH: add multiplication for 2D functions in rocketpy.function

Added the ability to multiply functions with 2D domains in the __mul__ function

* ENH: StochasticAirBrakes class created

The StochasticAirBrakes class has been created. The __init__.py files in the stochastic and rocketpy folders have also been modified accordingly to incorporate this new class

* ENH: set_air_brakes function created

This functions appends an airbrake and controller objects previuosly created to the rocket

* ENH: add StochasticAirBrake to rocketpy.stochastic_rocket

Some functions has been modified and other has been created in order to include the new StochasticAirBrakes feature into the StochasticRocket class. A new function named 'add_air_brakes' has been created to append a StochasticAirBrakes and Controller objects to the StochasticRocket object. A new function '_create_air_brake' has been introduced to create a sample of an AirBrake object through a StochasticAirBrake object. Enventually, the 'create_object' function has been modified to add the sampled AirBrakes to the sampled Rocket

* BUG: StochasticAirBrake object input in _Controller

When defining the _Controller object a StochasticAirBrake was input. This is already corrected and a AirBrake object is now introduced

* ENH: add time_overshoot option to rocketpy.stochastic_flight

Since the new StochasticAirBrake class is defined, we need the 'time_overshoot' option in the Flight class to ensure that the time step defined in the simulation is the controller sampling rate. The MonteCarlo class has had to be modified as well to include this option.

* DOC: StochasticAirBrakes related documentation added

Documentation related to the StochasticAirBrakes implementation has been added in StochasticAirBrakes, StochasticRocket and Rocket classes.

* ENH: pylint recommendations done

* ENH: Reformatted files to pass Ruff linting checks

* ENH: Update rocketpy/stochastic/stochastic_rocket.py

Unnecessary comment

Co-authored-by: Gui-FernandesBR <[email protected]>

* ENH: more intuitive uniform distribution display in StochasticModel

Co-authored-by: MateusStano <[email protected]>

* DOC: improve drag curve factor definition in StochasticAirBrakes

* ENH: Change assert statement to if

Co-authored-by: Gui-FernandesBR <[email protected]>

* DOC: better explanation of __mul__ function

Co-authored-by: MateusStano <[email protected]>

* ENH: delete set_air_brakes function for simplicity

* ENH: inertial foreces added to u_dot_generalized

* ENH: define Earth's angular velocity vector in Environment

* ENH: some corrections to the Flight class

* ENH: modifications in the Flight class

* DOC: improving Environment documentation

* DOC: more improvements in the Environment class

* ENH: format changes done

* DOC: env.earth_rotation_vector improved

Co-authored-by: Gui-FernandesBR <[email protected]>

* ENH: Coriolis acceleration added to u_dot

* BUG: print left

* ENH: ruff changes

* ENH: CHANGELOG updated

* ENH: remove unecessary frame rotation

* ENH: remove rotation from solid prop udot

* ENH: add coriolis to parachute

* TST: fix tests values

* MNT: remove debug functions

* DEV: changelog

---------

Co-authored-by: Gui-FernandesBR <[email protected]>
Co-authored-by: MateusStano <[email protected]>
Co-authored-by: MateusStano <[email protected]>
Co-authored-by: MateusStano <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

ENH: Add the Coriolis Acceleration

3 participants