@@ -129,13 +129,13 @@ Initialize a BodyAerodynamics struct in-place by setting up panels and coefficie
129129# Returns
130130nothing
131131"""
132- function reinit! (body_aero:: BodyAerodynamics ;
132+ function reinit! (body_aero:: BodyAerodynamics ;
133133 init_aero= true ,
134134 va= [15.0 , 0.0 , 0.0 ],
135135 omega= zeros (MVec3)
136136)
137137 idx = 1
138- vec = zeros (MVec3 )
138+ vec = @MVector zeros (3 )
139139 for wing in body_aero. wings
140140 reinit! (wing)
141141 panel_props = wing. panel_props
@@ -168,8 +168,8 @@ function reinit!(body_aero::BodyAerodynamics;
168168 end
169169
170170 # Initialize rest of the struct
171- body_aero. projected_area = sum (wing -> calculate_projected_area (wing) , body_aero. wings)
172- body_aero. stall_angle_list . = calculate_stall_angle_list ( body_aero. panels)
171+ body_aero. projected_area = sum (calculate_projected_area, body_aero. wings)
172+ calculate_stall_angle_list! ( body_aero. stall_angle_list, body_aero. panels)
173173 body_aero. alpha_array .= 0.0
174174 body_aero. v_a_array .= 0.0
175175 body_aero. AIC .= 0.0
@@ -191,21 +191,28 @@ Returns: nothing
191191"""
192192@inline function calculate_AIC_matrices! (body_aero:: BodyAerodynamics , model:: Model ,
193193 core_radius_fraction,
194- va_norm_array,
194+ va_norm_array,
195195 va_unit_array)
196196 # Determine evaluation point based on model
197197 evaluation_point = model == VSM ? :control_point : :aero_center
198198 evaluation_point_on_bound = model == LLT
199-
200- # Initialize AIC matrices
201- velocity_induced, tempvel, va_unit, U_2D = zeros (MVec3), zeros (MVec3), zeros (MVec3), zeros (MVec3)
199+
200+ # Allocate work vectors for this function (separate from those used by child functions)
201+ velocity_induced = @MVector zeros (3 )
202+ tempvel = @MVector zeros (3 )
203+ va_unit = @MVector zeros (3 )
204+ U_2D = @MVector zeros (3 )
202205
203206 # Calculate influence coefficients
204207 for icp in eachindex (body_aero. panels)
205- ep = getproperty (body_aero. panels[icp], evaluation_point)
208+ panel_icp = body_aero. panels[icp]
209+ ep = evaluation_point == :control_point ? panel_icp. control_point : panel_icp. aero_center
206210 for jring in eachindex (body_aero. panels)
207- va_unit .= @views va_unit_array[jring, :]
208- filaments = body_aero. panels[jring]. filaments
211+ panel_jring = body_aero. panels[jring]
212+ @inbounds for k in 1 : 3
213+ va_unit[k] = va_unit_array[jring, k]
214+ end
215+ filaments = panel_jring. filaments
209216 va_norm = va_norm_array[jring]
210217 calculate_velocity_induced_single_ring_semiinfinite! (
211218 velocity_induced,
@@ -222,8 +229,8 @@ Returns: nothing
222229
223230 # Subtract 2D induced velocity for VSM
224231 if icp == jring && model == VSM
225- calculate_velocity_induced_bound_2D! (U_2D, body_aero . panels[jring] , ep, body_aero. work_vectors)
226- velocity_induced .- = U_2D
232+ calculate_velocity_induced_bound_2D! (U_2D, panel_jring , ep, body_aero. work_vectors)
233+ velocity_induced .- = U_2D
227234 end
228235 body_aero. AIC[:, icp, jring] .= velocity_induced
229236 end
@@ -276,31 +283,46 @@ function calculate_stall_angle_list(panels::Vector{Panel};
276283 step_aoa= 1.0 ,
277284 stall_angle_if_none_detected= 50.0 ,
278285 cl_initial= - 10.0 )
279-
280- aoa_range = deg2rad .(range (begin_aoa, end_aoa, step= step_aoa))
281- stall_angles = Float64[]
282-
283- for panel in panels
286+ stall_angles = Vector {Float64} (undef, length (panels))
287+ calculate_stall_angle_list! (stall_angles, panels;
288+ begin_aoa, end_aoa, step_aoa,
289+ stall_angle_if_none_detected, cl_initial)
290+ return stall_angles
291+ end
292+
293+ function calculate_stall_angle_list! (stall_angles:: AbstractVector{Float64} ,
294+ panels:: Vector{Panel} ;
295+ begin_aoa= 9.0 ,
296+ end_aoa= 22.0 ,
297+ step_aoa= 1.0 ,
298+ stall_angle_if_none_detected= 50.0 ,
299+ cl_initial= - 10.0 )
300+
301+ # Pre-compute range values to avoid allocation
302+ n_steps = Int (floor ((end_aoa - begin_aoa) / step_aoa)) + 1
303+
304+ for (idx, panel) in enumerate (panels)
284305 # Default stall angle if none found
285306 panel_stall = stall_angle_if_none_detected
286-
307+
287308 # Start with minimum cl
288309 cl_old = cl_initial
289-
310+
290311 # Find stall angle
291- for aoa in aoa_range
312+ for i in 0 : (n_steps- 1 )
313+ aoa = deg2rad (begin_aoa + i * step_aoa)
292314 cl = calculate_cl (panel, aoa)
293315 if cl < cl_old
294316 panel_stall = aoa
295317 break
296318 end
297319 cl_old = cl
298320 end
299-
300- push! ( stall_angles, panel_stall)
321+
322+ stall_angles[idx] = panel_stall
301323 end
302-
303- return stall_angles
324+
325+ return nothing
304326end
305327
306328"""
0 commit comments