Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

- The `VSMSolution` docstring gives `lift_dist`, `drag_dist` and `panel_moment_dist` in
the per-unit-span units they hold, [N/m] and [Nm/m], instead of [N] and [Nm].
- `fit_kulfan_parameters` with `LeastSquaresFit` drops singular values below `1e-4`
times the largest, so a contour whose stations crowd into a narrow band of the chord
fits to an airfoil-sized shape instead of weights that resample it to 1e4 scale.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: The entry says a crowded contour now fits to an airfoil-sized shape, but the card's own table shows the 0.03-band case still comes out 15× too thick. The entry should say the weights are bounded, not that the shape is correct, or users will trust sections that are still wrong.

Fits of well-spread stations are unchanged.

## VortexStepMethod v5.1.1 2026-09-12

Expand Down
10 changes: 6 additions & 4 deletions src/airfoil_aero/kulfan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ function leading_edge_basis(x::AbstractVector{T}, n_weights::Int) where T
return x .* max.(1 .- x, zero(T)).^(n_weights + 0.5)
end

const KULFAN_FIT_RTOL = 1e-4 # [-] singular values dropped below this times the largest

"""
fit_kulfan_parameters(x::Vector, y::Vector, method::KulfanFitMethod)
fit_kulfan_parameters(x::Vector, y::Vector; n_weights=8)
Expand All @@ -128,7 +130,8 @@ end

Least-squares fit matching AeroSandbox's `get_kulfan_parameters`: both surfaces
share a single least-squares system with a shared leading-edge weight and a
trailing-edge thickness.
trailing-edge thickness. Singular values below `1e-4` times the largest are dropped, so
stations crowded into part of the chord give bounded weights.
"""
function fit_kulfan_parameters(x::Vector{T}, y::Vector{T},
method::LeastSquaresFit) where T
Expand All @@ -144,12 +147,11 @@ function fit_kulfan_parameters(x::Vector{T}, y::Vector{T},
te_col = ifelse.(is_upper, xv ./ 2, .-xv ./ 2)

A = hcat((.!is_upper) .* CS, is_upper .* CS, le_col, te_col)
coeffs = A \ y_norm
coeffs = pinv(A; rtol=KULFAN_FIT_RTOL) * y_norm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: Truncation happens silently, so a degenerate contour now gives a plausible-looking but wrong section instead of an obviously broken one, and nothing downstream checks it. Without the resampler or thickness fixes in this branch or a tracked issue for them, the failure gets harder to spot.

TE_thickness = coeffs[end]

if TE_thickness < 0
A = hcat((.!is_upper) .* CS, is_upper .* CS, le_col)
coeffs = A \ y_norm
coeffs = pinv(A[:, 1:end-1]; rtol=KULFAN_FIT_RTOL) * y_norm
TE_thickness = zero(T)
end

Expand Down
12 changes: 12 additions & 0 deletions test/airfoil_aero/test_airfoil_aero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ end
@test params.TE_thickness ≈ 0.0 atol = 1e-12
end

@testset "Fit to stations crowded into a narrow band stays airfoil-sized" begin
spread = (1 .- cos.(range(0, pi, 121))) ./ 2
crowded = vcat(0.0, range(0.30, 0.31, 118), 1.0)
surface(weights, xs) = class_function(xs) .* (bernstein_basis(xs, 7) * weights)
y_upper = surface(fill(0.2, 8), crowded) .+ 0.005 .* sin.(40pi .* crowded)
y_lower = surface(fill(-0.1, 8), spread)
x = vcat(reverse(crowded), spread[2:end])
y = vcat(reverse(y_upper), y_lower[2:end])
_, y_fit = kulfan_to_coordinates(fit_kulfan_parameters(x, y))
@test maximum(abs, y_fit) < 2 * maximum(abs, y)
end

@testset "Shrink-wrap encloses points with clearance" begin
xn, yn, _ = normalize_airfoil(collect(float.(xr)), collect(float.(yr)))
cloud_to_wrap(xw, yw) = minimum(
Expand Down
Loading