-
Notifications
You must be signed in to change notification settings - Fork 0
Add stability_derivatives (angle of attack, sideslip) and trim_angle, built on linearize #346
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
Merged
1-Bart-1
merged 10 commits into
main
from
agent/330-add-rigid-body-stability-derivatives-and
Sep 21, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56e7dcc
Add stability_derivatives and trim_angle on linearize
1-Bort-1 7227529
Bisect the trim bracket with a generic sign-change helper
1-Bort-1 d5becc0
Merge origin/main into agent/330-add-rigid-body-stability-derivatives…
1-Bort-1 ba3f07d
Merge origin/main into agent/330-add-rigid-body-stability-derivatives…
1-Bort-1 b50a2b5
trim_angle throws on an unconverged solve and takes backend, not kwargs
1-Bort-1 99cddc4
Merge origin/main into agent/330-add-rigid-body-stability-derivatives…
1-Bort-1 4eb714a
Merge origin/main into agent/330-add-rigid-body-stability-derivatives…
1-Bort-1 0da60e3
Size the stability test solvers from the wing's panel counts
1-Bort-1 3f49fc9
Merge branch 'main' into agent/330-add-rigid-body-stability-derivativ…
1-Bort-1 c8264df
Export apparent_wind and build the examples' inflow with it
1-Bort-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """ | ||
| stability_derivatives(solver, body_aero, alpha, beta, wind_speed; kwargs...) | ||
|
|
||
| Aerodynamic coefficients `[CFx, CFy, CFz, CMx, CMy, CMz]` of `body_aero` at angle of attack | ||
| `alpha` [rad], sideslip `beta` [rad] and `wind_speed` [m/s], and their derivatives with | ||
| respect to `alpha` and `beta` [1/rad], at the rotation rate `body_aero.omega` and with | ||
| moments about `solver.reference_point`. `kwargs` go to [`linearize`](@ref), which leaves | ||
| `body_aero` at this inflow. | ||
|
|
||
| Returns `(coeffs, dalpha, dbeta, converged)`. | ||
| """ | ||
| function stability_derivatives(solver::Solver, body_aero::BodyAerodynamics, alpha, beta, | ||
| wind_speed; kwargs...) | ||
| va_vec = apparent_wind(alpha, beta, wind_speed) | ||
| jac, results, converged = linearize(solver, body_aero, va_vec; | ||
| theta_idxs=nothing, va_idxs=1:3, aero_coeffs=true, kwargs...) | ||
| dva_dalpha = ForwardDiff.derivative( | ||
| angle -> apparent_wind(angle, beta, wind_speed), alpha) | ||
| dva_dbeta = ForwardDiff.derivative( | ||
| angle -> apparent_wind(alpha, angle, wind_speed), beta) | ||
| coeff_jac = jac[1:6, :] | ||
| return (coeffs=results[1:6], dalpha=coeff_jac * dva_dalpha, | ||
| dbeta=coeff_jac * dva_dbeta, converged) | ||
| end | ||
|
|
||
| """ | ||
| trim_angle(solver, body_aero, beta, wind_speed; alpha_range=deg2rad.(-5:2:15), | ||
| alpha_tol=1e-5, backend=AutoForwardDiff()) | ||
|
|
||
| Angles of attack [rad] at which `CMy` of `body_aero` about `solver.reference_point` changes | ||
| sign between neighbouring entries of `alpha_range`, bisected to `alpha_tol` [rad], at | ||
| sideslip `beta` [rad] and `wind_speed` [m/s]. Returns one `(alpha, dCMy_dalpha)` per trim, | ||
| the slope [1/rad] from [`stability_derivatives`](@ref) with `backend`; a trim is statically | ||
| stable where `dCMy_dalpha < 0`. Throws a [`SolveFailure`](@ref) if a solve misses the | ||
| solver's tolerances. | ||
| """ | ||
| function trim_angle(solver::Solver, body_aero::BodyAerodynamics, beta, wind_speed; | ||
| alpha_range=deg2rad.(-5:2:15), alpha_tol=1e-5, backend=AutoForwardDiff()) | ||
| is_nose_down = alpha -> nose_down(solver, body_aero, alpha, beta, wind_speed) | ||
| nose_down_range = is_nose_down.(alpha_range) | ||
| trims = @NamedTuple{alpha::Float64, dCMy_dalpha::Float64}[] | ||
| for i in 1:length(alpha_range)-1 | ||
| nose_down_range[i] == nose_down_range[i+1] && continue | ||
| alpha = bisect_sign_change(is_nose_down, alpha_range[i], alpha_range[i+1], | ||
| alpha_tol) | ||
| derivatives = stability_derivatives(solver, body_aero, alpha, beta, wind_speed; | ||
| backend, throw_on_fail=true) | ||
| push!(trims, (alpha=alpha, dCMy_dalpha=derivatives.dalpha[5])) | ||
| end | ||
| return trims | ||
| end | ||
|
|
||
| """ | ||
| coeffs_at_angles(solver, body_aero, alpha, beta, wind_speed) | ||
|
|
||
| Aerodynamic coefficients `[CFx, CFy, CFz, CMx, CMy, CMz]` of `body_aero` solved at angle of | ||
| attack `alpha` [rad], sideslip `beta` [rad] and `wind_speed` [m/s], at the rotation rate | ||
| `body_aero.omega`. Throws a [`SolveFailure`](@ref) if the solve misses the solver's | ||
| tolerances. | ||
| """ | ||
| function coeffs_at_angles(solver, body_aero, alpha, beta, wind_speed) | ||
| set_va!(body_aero, apparent_wind(alpha, beta, wind_speed), body_aero.omega) | ||
| sol = solve!(solver, body_aero; throw_on_fail=true) | ||
| return [sol.force_coeffs; sol.moment_coeffs] | ||
| end | ||
|
|
||
| """ | ||
| nose_down(solver, body_aero, alpha, beta, wind_speed) | ||
|
|
||
| Whether `CMy` from [`coeffs_at_angles`](@ref) is negative. | ||
| """ | ||
| nose_down(solver, body_aero, alpha, beta, wind_speed) = | ||
| coeffs_at_angles(solver, body_aero, alpha, beta, wind_speed)[5] < 0 | ||
|
|
||
| """ | ||
| bisect_sign_change(predicate, low, high, tol) | ||
|
|
||
| Bisect `[low, high]`, across which the boolean `predicate` flips, to a width of `tol` and | ||
| return the midpoint. | ||
| """ | ||
| function bisect_sign_change(predicate, low, high, tol) | ||
| predicate_low = predicate(low) | ||
| while high - low > tol | ||
| middle = (low + high) / 2 | ||
| if predicate(middle) == predicate_low | ||
| low = middle | ||
| else | ||
| high = middle | ||
| end | ||
| end | ||
| return (low + high) / 2 | ||
| end | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.