Skip to content

Commit f7b041e

Browse files
committed
Fix warnings
1 parent 21ebe19 commit f7b041e

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

src/obj_geometry.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ function ObjWing(
528528
# Load or create polars
529529
(!endswith(dat_path, ".dat")) && (dat_path *= ".dat")
530530
(!isfile(dat_path)) && error("DAT file not found: $dat_path")
531-
cl_polar_path = dat_path[1:end-4] * "_cl_polar.csv"
532-
cd_polar_path = dat_path[1:end-4] * "_cd_polar.csv"
533-
cm_polar_path = dat_path[1:end-4] * "_cm_polar.csv"
531+
cl_polar_path = string(dat_path[1:end-4], "_cl_polar.csv")
532+
cd_polar_path = string(dat_path[1:end-4], "_cd_polar.csv")
533+
cm_polar_path = string(dat_path[1:end-4], "_cm_polar.csv")
534534

535535
(!endswith(obj_path, ".obj")) && (obj_path *= ".obj")
536536
(!isfile(obj_path)) && error("OBJ file not found: $obj_path")
@@ -557,9 +557,9 @@ function ObjWing(
557557
area, width, crease_frac, alpha_range, delta_range, remove_nan)
558558
end
559559

560-
cl_matrix, _, _ = read_aero_matrix(cl_polar_path)
561-
cd_matrix, _, _ = read_aero_matrix(cd_polar_path)
562-
cm_matrix, alpha_range, delta_range = read_aero_matrix(cm_polar_path)
560+
cl_matrix, _, _ = read_aero_matrix(String(cl_polar_path))
561+
cd_matrix, _, _ = read_aero_matrix(String(cd_polar_path))
562+
cm_matrix, alpha_range, delta_range = read_aero_matrix(String(cm_polar_path))
563563

564564
if remove_nan
565565
any(isnan.(cl_matrix)) && interpolate_matrix_nans!(cl_matrix; prn)

src/polars.jl

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@ function solve_alpha!(cls, cds, cms, alpha_range, alpha_idxs, delta, re, x_, y_,
7272
y = deepcopy(y_)
7373
turn_trailing_edge!(delta, x, y, lower, upper, crease_frac)
7474
Xfoil.set_coordinates(x, y)
75-
x, y = Xfoil.pane(npan=140)
75+
Xfoil.pane(npan=140)
7676
reinit = true
7777
for (alpha, alpha_idx) in zip(alpha_range, alpha_idxs)
78-
converged = false
79-
cl = 0.0
80-
cd = 0.0
8178
# Solve for the given angle of attack
8279
cl, cd, _, cm, converged = Xfoil.solve_alpha(rad2deg(alpha), re; iter=50, reinit=reinit, mach=kite_speed/speed_of_sound, xtrip=(0.05, 0.05))
8380
reinit = false
@@ -308,23 +305,29 @@ The first row contains flap deflection angles, first column contains angles of a
308305
- `delta_range`: Vector of flap deflection angles in radians
309306
- `label`: Coefficient label for the header
310307
"""
311-
function write_aero_matrix(filepath::String, matrix::Matrix{Float64},
308+
function write_aero_matrix(filepath::AbstractString, matrix::Matrix{Float64},
312309
alpha_range::Vector{Float64}, delta_range::Vector{Float64},
313-
label::String)
314-
open(filepath, "w") do io
310+
label::AbstractString)
311+
open(String(filepath), "w") do io
315312
# Write header with delta values
316-
println(io, "$label/delta," * join(["δ=$(round(rad2deg(δ), digits=1))°" for δ in delta_range], ","))
313+
delta_labels = ["δ=$(round(rad2deg(δ), digits=1))°" for δ in delta_range]
314+
deltas_str = join(delta_labels, ",")
315+
deltas_str isa String || throw(ArgumentError("Failed to serialize delta header labels."))
316+
header = string(label, "/delta,", deltas_str)
317+
println(io, header)
317318

318319
# Write data rows with alpha values and coefficients
319320
for i in eachindex(alpha_range)
320-
row = "α=$(round(rad2deg(alpha_range[i]), digits=1))°," * join(matrix[i,:], ",")
321+
coeffs_str = join(matrix[i,:], ",")
322+
coeffs_str isa String || throw(ArgumentError("Failed to serialize coefficient row."))
323+
row = string("α=$(round(rad2deg(alpha_range[i]), digits=1))°,", coeffs_str)
321324
println(io, row)
322325
end
323326
end
324327
end
325328

326329
"""
327-
read_aero_matrix(filepath::String) -> (Matrix{Float64}, Vector{Float64}, Vector{Float64})
330+
read_aero_matrix(filepath::AbstractString) -> (Matrix{Float64}, Vector{Float64}, Vector{Float64})
328331
329332
Read an aerodynamic coefficient matrix from CSV with angle labels.
330333
Returns the coefficient matrix and corresponding angle ranges.
@@ -334,15 +337,18 @@ Returns the coefficient matrix and corresponding angle ranges.
334337
- `alpha_range`: Vector of angle of attack values in radians
335338
- `delta_range`: Vector of flap deflection angles in radians
336339
"""
337-
function read_aero_matrix(filepath::String)
338-
lines = readlines(filepath)
340+
function read_aero_matrix(filepath::AbstractString)
341+
lines = readlines(String(filepath))
339342

340343
# Parse header to get delta values
341344
header = split(lines[1], ',')
342345
delta_values = map(header[2:end]) do δ_str
343346
# Extract number between "δ=" and "°"
344347
m = match(r"δ=(-?\d+\.?\d*)°", δ_str)
345-
deg2rad(parse(Float64, m.captures[1]))
348+
m === nothing && throw(ArgumentError("Invalid delta header entry: $δ_str"))
349+
δ_cap = m.captures[1]
350+
(δ_cap isa AbstractString) || throw(ArgumentError("Missing delta value in header entry: $δ_str"))
351+
deg2rad(parse(Float64, String(δ_cap)))
346352
end
347353

348354
# Initialize matrix
@@ -356,7 +362,10 @@ function read_aero_matrix(filepath::String)
356362
entries = split(line, ',')
357363
# Extract alpha value
358364
m = match(r"α=(-?\d+\.?\d*)°", entries[1])
359-
alpha_values[i] = deg2rad(parse(Float64, m.captures[1]))
365+
m === nothing && throw(ArgumentError("Invalid alpha row entry: $(entries[1])"))
366+
α_cap = m.captures[1]
367+
(α_cap isa AbstractString) || throw(ArgumentError("Missing alpha value in row entry: $(entries[1])"))
368+
alpha_values[i] = deg2rad(parse(Float64, String(α_cap)))
360369
# Parse coefficient values
361370
matrix[i,:] .= parse.(Float64, entries[2:end])
362371
end

0 commit comments

Comments
 (0)