Skip to content

Commit 8c5ebbd

Browse files
committed
Refactoring
1 parent 8466643 commit 8c5ebbd

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/body_aerodynamics.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ Update angle of attack at aerodynamic center for VSM method.
428428
Returns:
429429
Vector{Float64}: Updated angles of attack
430430
"""
431-
function update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics,
431+
function update_effective_angle_of_attack!(alpha_corrected,
432+
body_aero::BodyAerodynamics,
432433
gamma::Vector{Float64},
433434
core_radius_fraction::Float64,
434435
z_airf_array::Matrix{Float64},
@@ -467,12 +468,11 @@ function update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics,
467468
end
468469

469470
# Direct angle calculation without temporary arrays
470-
alpha_array = cache_body[4][relative_velocity]
471471
@inbounds for i in 1:n
472-
alpha_array[i] = atan(v_normal[i], v_tangential[i])
472+
alpha_corrected[i] = atan(v_normal[i], v_tangential[i])
473473
end
474474

475-
return alpha_array
475+
nothing
476476
end
477477

478478
"""
@@ -518,6 +518,7 @@ function calculate_results(
518518
cd_array = zeros(n_panels)
519519
cm_array = zeros(n_panels)
520520
panel_width_array = zeros(n_panels)
521+
alpha_corrected = zeros(n_panels)
521522

522523
# Calculate coefficients for each panel
523524
for (i, panel) in enumerate(panels)
@@ -532,8 +533,9 @@ function calculate_results(
532533
moment = reshape((cm_array .* 0.5 .* density .* v_a_array.^2 .* chord_array), :, 1)
533534

534535
# Calculate alpha corrections based on model type
535-
alpha_corrected = if aerodynamic_model_type === VSM
536-
update_effective_angle_of_attack_if_VSM(
536+
if aerodynamic_model_type === VSM
537+
update_effective_angle_of_attack!(
538+
alpha_corrected,
537539
body_aero,
538540
gamma_new,
539541
core_radius_fraction,
@@ -543,10 +545,8 @@ function calculate_results(
543545
va_norm_array,
544546
va_unit_array
545547
)
546-
elseif aerodynamic_model_type === LLT
547-
alpha_array
548-
else
549-
throw(ArgumentError("Unknown aerodynamic model type, should be LLT or VSM"))
548+
elseif aerodynamic_model_type == LLT
549+
alpha_corrected .= alpha_array
550550
end
551551

552552
# Verify va is not distributed

src/solver.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ const cache = [LazyBufferCache(), LazyBufferCache(), LazyBufferCache(), LazyBuff
121121
LazyBufferCache(), LazyBufferCache(), LazyBufferCache(), LazyBufferCache(),
122122
LazyBufferCache(), LazyBufferCache(), LazyBufferCache()]
123123

124-
const cache_base = [LazyBufferCache()]
124+
const cache_base = [LazyBufferCache()]
125+
const cache_solve = [LazyBufferCache()]
125126

126127
"""
127128
solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=solver.sol.gamma_distribution;
@@ -162,6 +163,7 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
162163
cm_array = solver.sol.cm_array
163164
converged = solver.lr.converged
164165
alpha_array = solver.lr.alpha_array
166+
alpha_corrected = cache_solve[1][alpha_array]
165167
v_a_array = solver.lr.v_a_array
166168
panels = body_aero.panels
167169

@@ -190,11 +192,10 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
190192
@. drag = cd_array * 0.5 * density * v_a_array^2 * solver.sol.chord_array
191193
@. moment = cm_array * 0.5 * density * v_a_array^2 * solver.sol.chord_array
192194

193-
194195
# Calculate alpha corrections based on model type
195-
# TODO: this vector needs to be pre-allocated !!!
196-
alpha_corrected = if aerodynamic_model_type == VSM # 4188 bytes
197-
update_effective_angle_of_attack_if_VSM(
196+
if aerodynamic_model_type == VSM # 1568 bytes
197+
update_effective_angle_of_attack!(
198+
alpha_corrected,
198199
body_aero,
199200
gamma_new,
200201
solver.core_radius_fraction,
@@ -204,10 +205,8 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
204205
solver.br.va_norm_array,
205206
solver.br.va_unit_array
206207
)
207-
elseif aerodynamic_model_type === LLT
208-
alpha_array
209-
else
210-
throw(ArgumentError("Unknown aerodynamic model type, should be LLT or VSM"))
208+
elseif aerodynamic_model_type == LLT
209+
alpha_corrected .= alpha_array
211210
end
212211

213212
# Initialize result arrays

0 commit comments

Comments
 (0)