Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/body_aerodynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1078,14 +1078,8 @@ function set_va!(body_aero::BodyAerodynamics, va::AbstractVector, omega=zeros(MV

# Update wake elements
frozen_wake!(body_aero, va_distribution)
if all(iszero, omega)
body_aero._va .= va
body_aero.has_distributed_va = false
else
body_aero._va .= _compute_reference_velocity_from_distribution(
va_distribution, n_panels)
body_aero.has_distributed_va = true
end
body_aero._va .= va
body_aero.has_distributed_va = false
Comment on lines +1081 to +1082
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

has_distributed_va is now always set to false in the (va, omega) overload, even when omega induces per-panel velocity variation. Since getproperty(::BodyAerodynamics, :va) uses this flag to decide whether .va is well-defined, it would help to clarify (in the set_va! docstring and/or the :va error message) that has_distributed_va only refers to externally supplied per-panel inflow (matrix input), not rotation-induced variation.

Copilot uses AI. Check for mistakes.
return nothing
end

Expand Down
18 changes: 7 additions & 11 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,9 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, y::Vector{T};
throw(ArgumentError("Cannot use theta_idxs or delta_idxs when wing has no unrefined sections"))
end

init_va = body_aero.cache[1][body_aero.va]
init_va .= body_aero.va
init_va = body_aero.cache[1][body_aero._va]
init_va .= body_aero._va
init_omega = copy(body_aero.omega)
last_theta_ref = Ref{Vector{T}}(Vector{T}(undef, 0))
if !isnothing(theta_idxs)
@views last_theta_ref[] = body_aero.cache[2][y[theta_idxs]]
Expand Down Expand Up @@ -1085,15 +1086,10 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, y::Vector{T};
end
end

if !isnothing(va_idxs) && isnothing(omega_idxs)
set_va!(body_aero, y[va_idxs])
elseif !isnothing(va_idxs) && !isnothing(omega_idxs)
set_va!(body_aero, y[va_idxs], y[omega_idxs])
elseif isnothing(va_idxs) && !isnothing(omega_idxs)
set_va!(body_aero, init_va, y[omega_idxs])
else
set_va!(body_aero, init_va)
end
va = isnothing(va_idxs) ? init_va : y[va_idxs]
om = isnothing(omega_idxs) ? init_omega :
Comment on lines +1089 to +1090
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

In calc_results!, y[va_idxs] / y[omega_idxs] create new arrays each call. Since linearize evaluates this many times during finite-difference Jacobian computation, this can add significant allocation overhead. Consider using @views for these slices (and/or view(y, va_idxs) / view(y, omega_idxs)) so set_va! receives a view instead of an allocated copy.

Suggested change
va = isnothing(va_idxs) ? init_va : y[va_idxs]
om = isnothing(omega_idxs) ? init_omega :
@views va = isnothing(va_idxs) ? init_va : y[va_idxs]
@views om = isnothing(omega_idxs) ? init_omega :

Copilot uses AI. Check for mistakes.
y[omega_idxs]
set_va!(body_aero, va, om)

solve!(solver, body_aero; kwargs...)
if !aero_coeffs
Expand Down
8 changes: 4 additions & 4 deletions test/body_aerodynamics/test_body_aerodynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,15 @@ end
@test panel.va ≈ expected_va atol=1e-12
end
@test body_aero.omega ≈ omega
@test body_aero.has_distributed_va
@test_throws ArgumentError body_aero.va
@test !body_aero.has_distributed_va
@test body_aero.va ≈ va

new_omega = [0.0, 0.0, 2.0]
reference_va = copy(body_aero._va)
@test body_aero._va ≈ va
body_aero.omega = new_omega

for panel in body_aero.panels
expected_va = reference_va .+ (-new_omega × panel.control_point)
expected_va = va .+ (-new_omega × panel.control_point)
@test panel.va ≈ expected_va atol=1e-12
end
@test body_aero.omega ≈ new_omega
Expand Down
16 changes: 8 additions & 8 deletions test/body_aerodynamics/test_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ end

@testset "Nonlinear vs Linear - Comprehensive Input Testing" begin
# Initialize with base parameters
va = [15.0, 0.0, 0.0]
theta = zeros(4)
delta = zeros(4)
omega = zeros(3)
va = [15.0, 1.0, 0.5]
theta = deg2rad.([2.0, 1.0, -1.0, -2.0])
delta = deg2rad.([1.0, 0.5, -0.5, -1.0])
omega = [0.0, 0.1, 0.0]

# Define perturbation magnitudes
dva_magnitudes = [0.01, 0.01, 0.01] # Velocity perturbations (m/s)
Expand Down Expand Up @@ -123,7 +123,7 @@ end
reset_va = copy(va)
reset_theta = copy(theta)
reset_delta = copy(delta)
reset_omega = zeros(3)
reset_omega = copy(omega)

# Apply the perturbation to the nonlinear model
if input_name == "va"
Expand All @@ -133,7 +133,7 @@ end
elseif input_name == "delta"
reset_delta = delta + perturbation[11:14]
elseif input_name == "omega"
reset_omega = perturbation[8:10]
reset_omega = omega + perturbation[8:10]
else
throw(ArgumentError())
end
Expand Down Expand Up @@ -302,8 +302,8 @@ end
@info "$combo_name error metrics" prediction_error baseline_difference error_ratio

# Validate the prediction
@test lin_prediction ≈ nonlin_res rtol=0.01 atol=1e-3
@test error_ratio < 0.005
@test lin_prediction ≈ nonlin_res rtol=0.05 atol=1e-3
@test error_ratio < 0.05
Comment on lines +305 to +306
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The combined-input linearization assertions were loosened substantially (rtol 0.01→0.05 and error_ratio 0.005→0.05). This reduces the test’s ability to catch regressions in linearize. If the failures were due to leaving the linear regime, consider keeping a tighter tolerance by reducing combo_scale / perturbation magnitudes, or assert primarily on error_ratio with a smaller bound for at least one representative combined case.

Copilot uses AI. Check for mistakes.
end
end
end
Expand Down
Loading