-
-
Notifications
You must be signed in to change notification settings - Fork 222
ENH: Add multi-dimensional drag coefficient support (Cd as function of M, Re, α) #875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add multi-dimensional drag coefficient support (Cd as function of M, Re, α) #875
Conversation
|
The code implementation is as I planned it to be done. There might be a slight edge case which should be addressed in regular grid interpolator unit tests or with warning: that the grid was not sorted in ascending order as intended. This can happen with repeated values in the grid. Apart from that the changes are okay to be merged! @Gui-FernandesBR @copilot |
356e14a to
b621a16
Compare
|
@Gui-FernandesBR Is there a way to see this branch on VSC? I am unable to access it there. It is not being listed as a remote branch. I think one of the previous lint errors was related to the new grid method being too big in function.py. It should be ideally broken down into helper functions or pylint has to be disabled for it. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #875 +/- ##
===========================================
+ Coverage 80.27% 80.96% +0.68%
===========================================
Files 104 107 +3
Lines 12769 13609 +840
===========================================
+ Hits 10250 11018 +768
- Misses 2519 2591 +72 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The pull request is ready for review now. Pylint is failing due to a problem in .pylintrc, I am not sure if this file should be corrected in this PR or not as this is an unrelated error. Tests did pass locally on my end before merging from develop. @RocketPy-Team/code-owners will need help from you, because different tests are failing at different places - on github test_sensor failed but on local after merging develop test_environment failed. |
Co-authored-by: Gui-FernandesBR <[email protected]>
…tegration tests Co-authored-by: Gui-FernandesBR <[email protected]>
Co-authored-by: Gui-FernandesBR <[email protected]>
- MNT: velocity_body was not being used in get_drag_coefficient, removed it as an input
… test_multidim_drag.py -MNT: removed unused velocity in body frame parameter requirement from all instances of get_drag_coefficient in flight.py - MNT: corrected docstring for get_value_opt_grid in function.py - MNT: shifted import of classes before the definition of functions in test_multidim_drag.py
- MNT: rearranged the docstring of from_grid in function.py to match the expected output of doctest
- MNT: reran make format and lint on function.py to correct after previous changes to from_grid
- MNT: disables pylint unused private member for get_value_opt_grid as it is called upon dynamically by from_grid - MNT: disabled pylint too many statement for from_grid for now and added a to-do to refactor it into smaller methods/helper functions - MNT: updated .pylintrc to record Re as good name
- MNT: Re variable was unused in test_3d_drag_with_varying_alpha thus replaced it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements multi-dimensional drag coefficient support, allowing drag to vary with Mach number, Reynolds number, and angle of attack. This enhancement enables RocketPy users to utilize CFD simulation data that naturally depends on multiple flow parameters, significantly improving aerodynamic modeling accuracy.
Key changes:
- Added
Function.from_grid()class method for creating N-dimensional structured grid interpolators usingscipy.interpolate.RegularGridInterpolator - Modified Flight class to automatically calculate Reynolds number and angle of attack during trajectory integration, passing these to multi-dimensional drag functions
- Updated Rocket class to preserve Function objects when provided directly as drag coefficients (backward compatible with existing 1D usage)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
rocketpy/mathutils/function.py |
Adds from_grid() class method, linear_grid interpolation type, and __get_value_opt_grid() for structured grid evaluation with edge-clamping extrapolation |
rocketpy/simulation/flight.py |
Implements __get_drag_coefficient() helper to detect function dimensionality and calculate Re/α during integration; updates all u_dot methods |
rocketpy/rocket/rocket.py |
Preserves Function objects when passed as drag coefficients instead of wrapping them, enabling multi-dimensional drag |
tests/unit/mathutils/test_function_grid.py |
Comprehensive unit tests for grid interpolation (1D/2D/3D), extrapolation modes, validation, and fallback behavior |
tests/integration/test_multidim_drag.py |
Integration tests verifying 3D drag works in full flight simulations and maintains backward compatibility with 1D drag |
.pylintrc |
Adds 'Re' (Reynolds number) to accepted variable names |
Gui-FernandesBR
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @MateusStano please review changes in the flight.py file
- @phmbressan please review changes in the function.py ile
Everything is looking good, @aZira371 great work here! I'm confortable with what has been done so far. I believe we can include this one on the next release.
@aZira371 could you please update changelog?
|
Thanks for the review @Gui-FernandesBR will soon work on this and update the changelog. |
- TST: Added integration-level check to verify the flight simulation actually uses alpha when evaluating multi dim drag coeff. - TST: utilized pytest fixtures where possible.
- MNT: Function.is_multidimensional property in function.py. It returns True when the function's internal domain dimension is greater than 1 and safely returns False on errors. - MNT: Replaced the ad-hoc hasattr/len check in flight.py with a clearer check: if isinstance and drag_function.is_multidimensional
…or when an unsupported extrapolation value is provided.
ENH: Used shared flight fixtures and simplify multi-drag integration tests in test_multidim_drag.py ENH: Exposes multidimensionality and validated grid extrapolation in function.py
…clature - MNT: added a fallback to reynolds calculation in flight.py to avoid mu is zero case - MNT: updated test_shepard_fallback_warning name and docstring to match implementation in test_function_grid.py
…ueError, OverflowError): in get_drag_coefficient of flight.py
… and the explicit API.
Gui-FernandesBR
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,
I'd like to request @MateusStano 's review here as well
…tibility parameter, and early return guard clause Co-authored-by: aZira371 <[email protected]>
Added warning for unsorted axes in commit 05ebb10. The |
Gui-FernandesBR
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
It is a big change, I can't say everything is correct, but I prefer to deploy it to production so we let users report bugs if any.
Acceptance tests have passed so I'm ok with this.
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
Drag coefficients are limited to 1D functions of Mach number. CFD simulations typically produce drag data varying with Reynolds number and angle of attack, which cannot be properly represented.
New behavior
Drag coefficients now support N-dimensional structured grids via
Function.from_grid(). Flight simulations automatically calculate and pass Reynolds number (from velocity, density, viscosity, rocket diameter) and angle of attack (from freestream velocity vectors in body frame) to multi-dimensional drag functions.Implementation
Function Class (
rocketpy/mathutils/function.py)from_grid()class method usingscipy.interpolate.RegularGridInterpolator'regular_grid'interpolation type with edge clamping (no extrapolation beyond bounds)flatten_for_compatibilityparameter to skip O(n^d) memory overhead for large grids when legacy code compatibility is not requiredFlight Class (
rocketpy/simulation/flight.py)__get_drag_coefficient()helper detecting function dimensionality (uses early return guard clause for cleaner code)udot_rail1(),u_dot(),u_dot_generalized()to use helperRocket Class (
rocketpy/rocket/rocket.py)Usage Example
Testing
Function.from_grid()covering 1D/2D/3D grids, extrapolation, validation, unsorted axis warnings, and memory optimizationBreaking change
Existing 1D drag curves (Mach only) work unchanged. Multi-dimensional support is opt-in via
from_grid().Additional information
Resolves #874
CodeQL security scan: 0 alerts
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.