Skip to content

Commit f54d819

Browse files
authored
Add kwarg aero_coeffs to linearization (#197)
* Add kwarg aero_coeffs and test * Update news for latest version
1 parent 9a5a669 commit f54d819

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## VortexStepMethod v2.2.0 2025-08-28
2+
### Added
3+
- The kwarg `aero_coeffs` to the function `linearize`: if true the linearization will output
4+
normalized coefficients instead of moments and forces.
5+
16
## VortexStepMethod v2.1.0 2025-08-11
27
### Changed
38
#### 1. Core New Functionality: YAML Geometry Support

src/solver.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, y::Vector{T};
694694
delta_idxs=nothing,
695695
va_idxs=nothing,
696696
omega_idxs=nothing,
697+
aero_coeffs=false,
697698
kwargs...) where T
698699

699700
!(length(body_aero.wings) == 1) && throw(ArgumentError("Linearization only works for a body_aero with one wing"))
@@ -745,9 +746,15 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, y::Vector{T};
745746
end
746747

747748
solve!(solver, body_aero; kwargs...)
748-
results[1:3] .= solver.sol.force
749-
results[4:6] .= solver.sol.moment
750-
results[7:end] .= solver.sol.group_moment_dist
749+
if !aero_coeffs
750+
results[1:3] .= solver.sol.force
751+
results[4:6] .= solver.sol.moment
752+
results[7:end] .= solver.sol.group_moment_dist
753+
else
754+
results[1:3] .= solver.sol.force_coeffs
755+
results[4:6] .= solver.sol.moment_coeffs
756+
results[7:end] .= solver.sol.group_moment_coeff_dist
757+
end
751758
return nothing
752759
end
753760

test/body_aerodynamics/test_results.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,25 @@ end
7070
delta_idxs=11:14,
7171
moment_frac=0.1
7272
)
73+
74+
coeff_jac, coeff_lin_res = VortexStepMethod.linearize(
75+
solver,
76+
body_aero,
77+
base_inputs;
78+
theta_idxs=1:4,
79+
va_idxs=5:7,
80+
omega_idxs=8:10,
81+
delta_idxs=11:14,
82+
moment_frac=0.1,
83+
aero_coeffs=true
84+
)
7385

7486
# Verify that linearization results match nonlinear results at operating point
7587
baseline_res = VortexStepMethod.solve!(solver, body_aero; log=false)
7688
baseline_res = [solver.sol.force; solver.sol.moment; solver.sol.group_moment_dist]
89+
coeff_baseline_res = [solver.sol.force_coeffs; solver.sol.moment_coeffs; solver.sol.group_moment_coeff_dist]
7790
@test baseline_res lin_res
91+
@test coeff_baseline_res coeff_lin_res
7892

7993
# Define test cases
8094
test_cases = [
@@ -88,6 +102,7 @@ end
88102
for (input_name, indices, magnitudes) in test_cases
89103
@testset "Input: $input_name" begin
90104
max_error_ratio = 0.0
105+
coeff_max_error_ratio = 0.0
91106

92107
# Select one index at a time for focused testing
93108
for idx in indices
@@ -128,18 +143,25 @@ end
128143
# Get nonlinear solution
129144
nonlin_res = VortexStepMethod.solve!(solver, body_aero, nothing; log=false)
130145
nonlin_res = [solver.sol.force; solver.sol.moment; solver.sol.group_moment_dist]
146+
coeff_nonlin_res = [solver.sol.force_coeffs; solver.sol.moment_coeffs; solver.sol.group_moment_coeff_dist]
131147
@test nonlin_res baseline_res
148+
@test coeff_nonlin_res baseline_res
132149

133150
# Compute linearized prediction
134151
lin_prediction = lin_res + jac * perturbation
152+
coeff_lin_prediction = coeff_lin_res + coeff_jac * perturbation
135153

136154
# Calculate error ratio for this case
137155
prediction_error = norm(lin_prediction - nonlin_res)
138156
baseline_difference = norm(baseline_res - nonlin_res)
139157
error_ratio = prediction_error / baseline_difference
158+
coeff_prediction_error = norm(coeff_lin_prediction - coeff_nonlin_res)
159+
coeff_baseline_difference = norm(coeff_baseline_res - coeff_nonlin_res)
160+
coeff_error_ratio = coeff_prediction_error / coeff_baseline_difference
140161

141162
# Update max error ratio
142163
max_error_ratio = max(max_error_ratio, error_ratio)
164+
coeff_max_error_ratio = max(coeff_max_error_ratio, coeff_error_ratio)
143165

144166
# For small perturbations, test that error ratio is small
145167
if idx == first(indices) && mag == first(magnitudes)
@@ -149,6 +171,7 @@ end
149171
end
150172

151173
@info "Max error ratio for $input_name: $max_error_ratio"
174+
@info "Max coeff error ratio for $input_name: $coeff_max_error_ratio"
152175
end
153176
end
154177

@@ -275,4 +298,4 @@ end
275298
end
276299
end
277300
end
278-
end
301+
end

0 commit comments

Comments
 (0)