Skip to content

Commit b941732

Browse files
committed
Fix warnings
1 parent f8d3d55 commit b941732

4 files changed

Lines changed: 151 additions & 105 deletions

File tree

bin/jetls

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: 2025 Uwe Fechner
3+
# SPDX-License-Identifier: MIT
4+
5+
cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
6+
if [[ $(basename $(pwd)) == "bin" ]]; then
7+
cd ..
8+
fi
9+
10+
jetls check --root=. src/

src/VortexStepMethod.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ using StructMapping
2424
using Xfoil
2525

2626
# Export public interface
27-
export VSMSettings, WingSettings, SolverSettings
28-
export Wing, Section, ObjWing, reinit!, refine!
27+
export SolverSettings, VSMSettings, WingSettings
28+
export ObjWing, Section, Wing, refine!, reinit!
2929
export BodyAerodynamics
30-
export Solver, solve, solve_base!, solve!, VSMSolution, linearize
30+
export Solver, VSMSolution, linearize, solve, solve!, solve_base!
3131
export calculate_results
3232
export add_section!, set_va!
33-
export calculate_span, calculate_projected_area
33+
export calculate_projected_area, calculate_span
3434
export MVec3
35-
export Model, VSM, LLT
36-
export AeroModel, LEI_AIRFOIL_BREUKELS, POLAR_VECTORS, POLAR_MATRICES, INVISCID
37-
export PanelDistribution, LINEAR, COSINE, SPLIT_PROVIDED, UNCHANGED
38-
export InitialGammaDistribution, ELLIPTIC, ZEROS
39-
export SolverStatus, FEASIBLE, INFEASIBLE, FAILURE
40-
export SolverType, LOOP, NONLIN
35+
export LLT, Model, VSM
36+
export AeroModel, INVISCID, LEI_AIRFOIL_BREUKELS, POLAR_MATRICES, POLAR_VECTORS
37+
export COSINE, LINEAR, PanelDistribution, SPLIT_PROVIDED, UNCHANGED
38+
export ELLIPTIC, InitialGammaDistribution, ZEROS
39+
export FAILURE, FEASIBLE, INFEASIBLE, SolverStatus
40+
export LOOP, NONLIN, SolverType
4141
export load_polar_data
4242

43-
export plot_geometry, plot_distribution, plot_circulation_distribution, plot_polars,
44-
save_plot, show_plot, plot_polar_data, plot_combined_analysis
43+
export plot_combined_analysis, plot_circulation_distribution, plot_distribution, plot_geometry,
44+
plot_polar_data, plot_polars, save_plot, show_plot
4545

4646
# the following functions are defined in ext/VortexStepMethodExt.jl
4747
function plot_geometry end

src/body_aerodynamics.jl

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,67 @@ end
159159
return true
160160
end
161161

162+
"""
163+
calculate_stall_angle_list(panels::Vector{Panel};
164+
begin_aoa=9.0,
165+
end_aoa=22.0,
166+
step_aoa=1.0,
167+
stall_angle_if_none_detected=50.0,
168+
cl_initial=-10.0)
169+
170+
Calculate stall angles for each panel.
171+
172+
Returns:
173+
Vector{Float64}: Stall angles in radians
174+
"""
175+
function calculate_stall_angle_list(panels::Vector{Panel};
176+
begin_aoa=9.0,
177+
end_aoa=22.0,
178+
step_aoa=1.0,
179+
stall_angle_if_none_detected=50.0,
180+
cl_initial=-10.0)
181+
stall_angles = Vector{Float64}(undef, length(panels))
182+
calculate_stall_angle_list!(stall_angles, panels;
183+
begin_aoa, end_aoa, step_aoa,
184+
stall_angle_if_none_detected, cl_initial)
185+
return stall_angles
186+
end
187+
188+
function calculate_stall_angle_list!(stall_angles::AbstractVector{Float64},
189+
panels::Vector{Panel};
190+
begin_aoa=9.0,
191+
end_aoa=22.0,
192+
step_aoa=1.0,
193+
stall_angle_if_none_detected=50.0,
194+
cl_initial=-10.0)
195+
196+
# Pre-compute range values to avoid allocation
197+
n_steps = Int(floor((end_aoa - begin_aoa) / step_aoa)) + 1
198+
199+
for (idx, panel) in enumerate(panels)
200+
# Default stall angle if none found
201+
panel_stall = stall_angle_if_none_detected
202+
203+
# Start with minimum cl
204+
cl_old = cl_initial
205+
206+
# Find stall angle
207+
for i in 0:(n_steps-1)
208+
aoa = deg2rad(begin_aoa + i * step_aoa)
209+
cl = calculate_cl(panel, aoa)
210+
if cl < cl_old
211+
panel_stall = aoa
212+
break
213+
end
214+
cl_old = cl
215+
end
216+
217+
stall_angles[idx] = panel_stall
218+
end
219+
220+
return nothing
221+
end
222+
162223
"""
163224
reinit!(body_aero::BodyAerodynamics; init_aero, va, omega, refine_mesh, recompute_mapping, sort_sections)
164225
@@ -381,67 +442,6 @@ function calculate_circulation_distribution_elliptical_wing(gamma_i, body_aero::
381442
nothing
382443
end
383444

384-
"""
385-
calculate_stall_angle_list(panels::Vector{Panel};
386-
begin_aoa=9.0,
387-
end_aoa=22.0,
388-
step_aoa=1.0,
389-
stall_angle_if_none_detected=50.0,
390-
cl_initial=-10.0)
391-
392-
Calculate stall angles for each panel.
393-
394-
Returns:
395-
Vector{Float64}: Stall angles in radians
396-
"""
397-
function calculate_stall_angle_list(panels::Vector{Panel};
398-
begin_aoa=9.0,
399-
end_aoa=22.0,
400-
step_aoa=1.0,
401-
stall_angle_if_none_detected=50.0,
402-
cl_initial=-10.0)
403-
stall_angles = Vector{Float64}(undef, length(panels))
404-
calculate_stall_angle_list!(stall_angles, panels;
405-
begin_aoa, end_aoa, step_aoa,
406-
stall_angle_if_none_detected, cl_initial)
407-
return stall_angles
408-
end
409-
410-
function calculate_stall_angle_list!(stall_angles::AbstractVector{Float64},
411-
panels::Vector{Panel};
412-
begin_aoa=9.0,
413-
end_aoa=22.0,
414-
step_aoa=1.0,
415-
stall_angle_if_none_detected=50.0,
416-
cl_initial=-10.0)
417-
418-
# Pre-compute range values to avoid allocation
419-
n_steps = Int(floor((end_aoa - begin_aoa) / step_aoa)) + 1
420-
421-
for (idx, panel) in enumerate(panels)
422-
# Default stall angle if none found
423-
panel_stall = stall_angle_if_none_detected
424-
425-
# Start with minimum cl
426-
cl_old = cl_initial
427-
428-
# Find stall angle
429-
for i in 0:(n_steps-1)
430-
aoa = deg2rad(begin_aoa + i * step_aoa)
431-
cl = calculate_cl(panel, aoa)
432-
if cl < cl_old
433-
panel_stall = aoa
434-
break
435-
end
436-
cl_old = cl
437-
end
438-
439-
stall_angles[idx] = panel_stall
440-
end
441-
442-
return nothing
443-
end
444-
445445
"""
446446
update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics, gamma,
447447
core_radius_fraction,

src/panel.jl

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -261,9 +281,14 @@ end
261281
Compute lift, drag and moment coefficients for Lei airfoil using Breukels model.
262282
"""
263283
function 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
"""
348373
function 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
366394
end
367395

368396

@@ -373,23 +401,31 @@ Calculate drag and moment coefficients for given angle of attack.
373401
"""
374402
function 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
393429
end
394430

395431
"""

0 commit comments

Comments
 (0)