@@ -137,12 +137,6 @@ function init_aero!(
137137 panel. cl_coeffs, panel. cd_coeffs, panel. cm_coeffs = compute_lei_coeffs (section_1, section_2)
138138
139139 elseif panel. aero_model in (POLAR_VECTORS, POLAR_MATRICES)
140- aero_1 = section_1. aero_data
141- aero_2 = section_2. aero_data
142- if ! all (size .(aero_1) .== size .(aero_2))
143- throw (ArgumentError (" Polar data must have same shape" ))
144- end
145-
146140 if remove_nan
147141 extrap_flat = Flat ()
148142 extrap_line = Line ()
@@ -152,17 +146,30 @@ function init_aero!(
152146 end
153147
154148 if panel. aero_model == POLAR_VECTORS
155- alphas_1 = aero_1[1 ]
156- alphas_2 = aero_2[1 ]
149+ aero_1 = section_1. aero_data
150+ aero_2 = section_2. aero_data
151+ aero_1 isa Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}} ||
152+ throw (ArgumentError (" POLAR_VECTORS requires aero_data = (alpha, cl, cd, cm) vectors." ))
153+ aero_2 isa Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}} ||
154+ throw (ArgumentError (" POLAR_VECTORS requires aero_data = (alpha, cl, cd, cm) vectors." ))
155+ aero_1_t = aero_1:: Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}}
156+ aero_2_t = aero_2:: Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}}
157+
158+ if ! all (size .(aero_1_t) .== size .(aero_2_t))
159+ throw (ArgumentError (" Polar data must have same shape" ))
160+ end
161+
162+ alphas_1 = aero_1_t[1 ]
163+ alphas_2 = aero_2_t[1 ]
157164 (
158165 length (alphas_1) == length (alphas_2) &&
159166 all (isapprox .(diff (alphas_1), diff (alphas_2)))
160167 ) || throw (ArgumentError (" Alpha steps must be identical." ))
161168
162169 polar_data = (
163- Vector {Float64} ((aero_1 [2 ] + aero_2 [2 ]) / 2 ),
164- Vector {Float64} ((aero_1 [3 ] + aero_2 [3 ]) / 2 ),
165- Vector {Float64} ((aero_1 [4 ] + aero_2 [4 ]) / 2 )
170+ Vector {Float64} ((aero_1_t [2 ] + aero_2_t [2 ]) / 2 ),
171+ Vector {Float64} ((aero_1_t [3 ] + aero_2_t [3 ]) / 2 ),
172+ Vector {Float64} ((aero_1_t [4 ] + aero_2_t [4 ]) / 2 )
166173 )
167174 alphas = Vector {Float64} (alphas_1)
168175
@@ -171,10 +178,23 @@ function init_aero!(
171178 panel. cm_interp = linear_interpolation (alphas, polar_data[3 ]; extrapolation_bc= extrap_flat)
172179
173180 elseif panel. aero_model == POLAR_MATRICES
174- alphas_1 = aero_1[1 ]
175- alphas_2 = aero_2[1 ]
176- deltas_1 = aero_1[2 ]
177- deltas_2 = aero_2[2 ]
181+ aero_1 = section_1. aero_data
182+ aero_2 = section_2. aero_data
183+ aero_1 isa Tuple{Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}} ||
184+ throw (ArgumentError (" POLAR_MATRICES requires aero_data = (alpha, delta, cl, cd, cm)." ))
185+ aero_2 isa Tuple{Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}} ||
186+ throw (ArgumentError (" POLAR_MATRICES requires aero_data = (alpha, delta, cl, cd, cm)." ))
187+ aero_1_t = aero_1:: Tuple{Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}
188+ aero_2_t = aero_2:: Tuple{Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}
189+
190+ if ! all (size .(aero_1_t) .== size .(aero_2_t))
191+ throw (ArgumentError (" Polar data must have same shape" ))
192+ end
193+
194+ alphas_1 = aero_1_t[1 ]
195+ alphas_2 = aero_2_t[1 ]
196+ deltas_1 = aero_1_t[2 ]
197+ deltas_2 = aero_2_t[2 ]
178198 (
179199 length (alphas_1) == length (alphas_2) &&
180200 all (isapprox .(diff (alphas_1), diff (alphas_2)))
@@ -185,9 +205,9 @@ function init_aero!(
185205 ) || throw (ArgumentError (" Delta steps must be identical." ))
186206
187207 polar_data = (
188- Matrix {Float64} ((aero_1 [3 ] + aero_2 [3 ]) / 2 ),
189- Matrix {Float64} ((aero_1 [4 ] + aero_2 [4 ]) / 2 ),
190- Matrix {Float64} ((aero_1 [5 ] + aero_2 [5 ]) / 2 )
208+ Matrix {Float64} ((aero_1_t [3 ] + aero_2_t [3 ]) / 2 ),
209+ Matrix {Float64} ((aero_1_t [4 ] + aero_2_t [4 ]) / 2 ),
210+ Matrix {Float64} ((aero_1_t [5 ] + aero_2_t [5 ]) / 2 )
191211 )
192212 alphas = Vector {Float64} (alphas_1)
193213 deltas = Vector {Float64} (deltas_1)
@@ -196,7 +216,7 @@ function init_aero!(
196216 panel. cd_interp = linear_interpolation ((alphas, deltas), polar_data[2 ]; extrapolation_bc= extrap_line)
197217 panel. cm_interp = linear_interpolation ((alphas, deltas), polar_data[3 ]; extrapolation_bc= extrap_flat)
198218 else
199- throw (ArgumentError (" Polar data in wrong format: $aero_1 " ))
219+ throw (ArgumentError (" Polar data in wrong format for model $(panel . aero_model) . " ))
200220 end
201221
202222 elseif ! (panel. aero_model == INVISCID)
261281Compute lift, drag and moment coefficients for Lei airfoil using Breukels model.
262282"""
263283function compute_lei_coeffs (section_1:: Section , section_2:: Section )
284+ section_1. aero_data isa NTuple{2 , Float64} ||
285+ throw (ArgumentError (" LEI_AIRFOIL_BREUKELS requires aero_data = (tube_diameter, camber)." ))
286+ section_2. aero_data isa NTuple{2 , Float64} ||
287+ throw (ArgumentError (" LEI_AIRFOIL_BREUKELS requires aero_data = (tube_diameter, camber)." ))
288+
264289 # Average tube diameter and camber from both sections
265- t1, k1 = section_1. aero_data
266- t2, k2 = section_2. aero_data
290+ t1, k1 = section_1. aero_data:: NTuple{2, Float64}
291+ t2, k2 = section_2. aero_data:: NTuple{2, Float64}
267292 t = (t1 + t2) / 2
268293 k = (k1 + k2) / 2
269294
@@ -347,22 +372,25 @@ Calculate lift coefficient for given angle of attack.
347372"""
348373function calculate_cl (panel:: Panel , alpha:: Float64 ):: Float64
349374 isnan (alpha) && return NaN
350- cl = 0.0
351375 if panel. aero_model == LEI_AIRFOIL_BREUKELS
352376 cl = evalpoly (rad2deg (alpha), reverse (panel. cl_coeffs))
353377 if abs (alpha) > (π/ 9 )
354378 cl = 2 * cos (alpha) * sin (alpha)^ 2
355379 end
380+ return cl
356381 elseif panel. aero_model == INVISCID
357- cl = 2 π * alpha
382+ return 2 π * alpha
358383 elseif panel. aero_model == POLAR_VECTORS
359- cl = panel. cl_interp (alpha):: Float64
384+ interp = panel. cl_interp
385+ interp isa Union{I1, I2} || throw (ArgumentError (" cl_interp is not initialized for POLAR_VECTORS." ))
386+ return (interp:: Union{I1, I2} )(alpha):: Float64
360387 elseif panel. aero_model == POLAR_MATRICES
361- cl = panel. cl_interp (alpha, panel. delta):: Float64
388+ interp = panel. cl_interp
389+ interp isa Union{I3, I4} || throw (ArgumentError (" cl_interp is not initialized for POLAR_MATRICES." ))
390+ return (interp:: Union{I3, I4} )(alpha, panel. delta):: Float64
362391 else
363392 throw (ArgumentError (" Unsupported aero model: $(panel. aero_model) " ))
364393 end
365- return cl
366394end
367395
368396
@@ -373,23 +401,31 @@ Calculate drag and moment coefficients for given angle of attack.
373401"""
374402function calculate_cd_cm (panel:: Panel , alpha:: Float64 )
375403 isnan (alpha) && return NaN , NaN
376- cd, cm = 0.0 , 0.0
377404 if panel. aero_model == LEI_AIRFOIL_BREUKELS
378405 cd = evalpoly (rad2deg (alpha), reverse (panel. cd_coeffs))
379406 cm = evalpoly (rad2deg (alpha), reverse (panel. cm_coeffs))
380407 if abs (alpha) > (π/ 9 ) # Outside ±20 degrees
381408 cd = 2 * sin (alpha)^ 3
382409 end
410+ return cd, cm
383411 elseif panel. aero_model == POLAR_VECTORS
384- cd = panel. cd_interp (alpha):: Float64
385- cm = panel. cm_interp (alpha):: Float64
412+ cd_interp = panel. cd_interp
413+ cm_interp = panel. cm_interp
414+ cd_interp isa Union{I1, I2, I5} || throw (ArgumentError (" cd_interp is not initialized for POLAR_VECTORS." ))
415+ cm_interp isa Union{I1, I2} || throw (ArgumentError (" cm_interp is not initialized for POLAR_VECTORS." ))
416+ return (cd_interp:: Union{I1, I2, I5} )(alpha):: Float64 ,
417+ (cm_interp:: Union{I1, I2} )(alpha):: Float64
386418 elseif panel. aero_model == POLAR_MATRICES
387- cd = panel. cd_interp (alpha, panel. delta):: Float64
388- cm = panel. cm_interp (alpha, panel. delta):: Float64
419+ cd_interp = panel. cd_interp
420+ cm_interp = panel. cm_interp
421+ cd_interp isa Union{I3, I4, I6} || throw (ArgumentError (" cd_interp is not initialized for POLAR_MATRICES." ))
422+ cm_interp isa Union{I3, I4} || throw (ArgumentError (" cm_interp is not initialized for POLAR_MATRICES." ))
423+ return (cd_interp:: Union{I3, I4, I6} )(alpha, panel. delta):: Float64 ,
424+ (cm_interp:: Union{I3, I4} )(alpha, panel. delta):: Float64
389425 elseif ! (panel. aero_model == INVISCID)
390426 throw (ArgumentError (" Unsupported aero model: $(panel. aero_model) " ))
391427 end
392- return cd, cm
428+ return 0.0 , 0.0
393429end
394430
395431"""
0 commit comments