Skip to content

Commit 1ee0731

Browse files
committed
Refactor update_effective_angle_of_attack_if_VSM()
1 parent 02cb714 commit 1ee0731

1 file changed

Lines changed: 62 additions & 13 deletions

File tree

src/body_aerodynamics.jl

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -436,28 +436,77 @@ function update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics,
436436
va_norm_array::Vector{Float64},
437437
va_unit_array::Matrix{Float64})
438438

439-
# Calculate AIC matrices at aerodynamic center using LLT method
439+
# Calculate AIC matrices (keep existing optimized view)
440440
calculate_AIC_matrices!(
441441
body_aero, LLT, core_radius_fraction, va_norm_array, va_unit_array
442442
)
443443
AIC_x, AIC_y, AIC_z = @views body_aero.AIC[1, :, :], body_aero.AIC[2, :, :], body_aero.AIC[3, :, :]
444444

445-
# Calculate induced velocities
446-
induced_velocity = [
447-
AIC_x * gamma,
448-
AIC_y * gamma,
449-
AIC_z * gamma
450-
]
451-
induced_velocity = hcat(induced_velocity...)
445+
# Preallocate and calculate induced velocity directly
446+
induced_velocity = similar(va_array)
447+
induced_velocity[:, 1] .= AIC_x * gamma
448+
induced_velocity[:, 2] .= AIC_y * gamma
449+
induced_velocity[:, 3] .= AIC_z * gamma
450+
451+
# In-place relative velocity calculation
452+
relative_velocity = va_array .+ induced_velocity
453+
454+
# Preallocate and compute dot products manually
455+
n = size(relative_velocity, 1)
456+
v_normal = Vector{Float64}(undef, n)
457+
v_tangential = Vector{Float64}(undef, n)
452458

453-
# Calculate relative velocities and angles
454-
relative_velocity = va_array + induced_velocity
455-
v_normal = sum(z_airf_array .* relative_velocity, dims=2)
456-
v_tangential = sum(x_airf_array .* relative_velocity, dims=2)
457-
alpha_array = atan.(v_normal ./ v_tangential)
459+
@inbounds for i in 1:n
460+
vn = 0.0
461+
vt = 0.0
462+
for j in 1:3
463+
vn += z_airf_array[i, j] * relative_velocity[i, j]
464+
vt += x_airf_array[i, j] * relative_velocity[i, j]
465+
end
466+
v_normal[i] = vn
467+
v_tangential[i] = vt
468+
end
469+
470+
# Direct angle calculation without temporary arrays
471+
alpha_array = Vector{Float64}(undef, n)
472+
@inbounds for i in 1:n
473+
alpha_array[i] = atan(v_normal[i], v_tangential[i])
474+
end
475+
458476
return alpha_array
459477
end
460478

479+
# function update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics,
480+
# gamma::Vector{Float64},
481+
# core_radius_fraction::Float64,
482+
# z_airf_array::Matrix{Float64},
483+
# x_airf_array::Matrix{Float64},
484+
# va_array::Matrix{Float64},
485+
# va_norm_array::Vector{Float64},
486+
# va_unit_array::Matrix{Float64})
487+
488+
# # Calculate AIC matrices at aerodynamic center using LLT method
489+
# calculate_AIC_matrices!(
490+
# body_aero, LLT, core_radius_fraction, va_norm_array, va_unit_array
491+
# )
492+
# AIC_x, AIC_y, AIC_z = @views body_aero.AIC[1, :, :], body_aero.AIC[2, :, :], body_aero.AIC[3, :, :]
493+
494+
# # Calculate induced velocities
495+
# induced_velocity = [
496+
# AIC_x * gamma,
497+
# AIC_y * gamma,
498+
# AIC_z * gamma
499+
# ]
500+
# induced_velocity = hcat(induced_velocity...)
501+
502+
# # Calculate relative velocities and angles
503+
# relative_velocity = va_array + induced_velocity
504+
# v_normal = sum(z_airf_array .* relative_velocity, dims=2)
505+
# v_tangential = sum(x_airf_array .* relative_velocity, dims=2)
506+
# alpha_array = atan.(v_normal ./ v_tangential)
507+
# return alpha_array
508+
# end
509+
461510
"""
462511
calculate_results(body_aero::BodyAerodynamics, gamma_new::Vector{Float64},
463512
density::Float64, aerodynamic_model_type::Model,

0 commit comments

Comments
 (0)