Skip to content

Commit a546cad

Browse files
committed
fix polar mixing test
1 parent fca49af commit a546cad

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

test/test_panel.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using VortexStepMethod: Panel, Section, calculate_relative_alpha_and_relative_velocity
1+
using VortexStepMethod: Panel, Section, calculate_relative_alpha_and_relative_velocity, calculate_cl, calculate_cd_cm
2+
using Interpolations: linear_interpolation, Line
23
using LinearAlgebra
34
using Test
45
using BenchmarkTools
@@ -112,48 +113,49 @@ end
112113
end
113114

114115
# Generate mock polar data
115-
alphas = -10:1:25
116+
alphas = deg2rad.(-10:1:25)
116117
n_points = length(alphas)
117118
polar_data = zeros(n_points, 4)
119+
big_polar_data = zeros(n_points, 4)
118120

119121
# Fill polar data with realistic values
120122
for (i, alpha) in enumerate(alphas)
121123
cd = 0.015 + 0.015 * abs(alpha/10)^1.5 # Drag increases with angle
122124
cl = 0.1 * alpha + 0.01 * alpha^2 * exp(-alpha/20) # Lift with stall behavior
123125
cm = -0.02 * alpha # Linear pitching moment
124-
polar_data[i,:] = [alpha, cd, cl, cm]
126+
polar_data[i,:] = [alpha, cl, cd, cm]
127+
big_polar_data[i,:] = [alpha, 1.1cl, 1.1cd, 1.1cm]
125128
end
126-
129+
127130
# Create two sections with slightly different polar data
128131
section1 = Section([0.0, 0.0, 0.0], [1.0, 0.0, 0.0], ("polar_data", polar_data))
129-
section2 = Section([0.0, 10.0, 0.0], [1.0, 10.0, 0.0], ("polar_data", polar_data * 1.1))
132+
section2 = Section([0.0, 10.0, 0.0], [1.0, 10.0, 0.0], ("polar_data", big_polar_data))
130133

131134
# Create panel
132135
panel = create_panel(section1, section2)
133136

134137
@testset "Panel Polar Data Initialization" begin
135138
# Test if panel has polar data
136-
@test hasattr(panel, :panel_polar_data)
139+
@test hasproperty(panel, :panel_polar_data)
137140
@test !isnothing(panel.panel_polar_data)
138141
@test size(panel.panel_polar_data) == size(polar_data)
139142

140143
# Test if panel polar data is correctly averaged
141-
expected_data = (polar_data + polar_data * 1.1) / 2
144+
expected_data = (polar_data + big_polar_data) / 2
142145
@test isapprox(panel.panel_polar_data, expected_data, rtol=1e-5)
143146
end
144147

145148
@testset "Coefficient Interpolation" begin
146-
test_alphas = [-5.0, 0.0, 5.0, 10.0]
149+
test_alphas = deg2rad.([-5.0, 0.0, 5.0, 10.0])
147150
for alpha in test_alphas
148151
# Calculate coefficients using panel methods
149-
alpha_rad = deg2rad(alpha)
150-
cl = panel.calculate_cl(alpha_rad)
151-
cd, cm = panel.calculate_cd_cm(alpha_rad)
152+
cl = calculate_cl(panel, alpha)
153+
cd, cm = calculate_cd_cm(panel, alpha)
152154

153155
# Calculate expected values through interpolation
154-
expected_cl = linear_interpolate(polar_data[:,1], polar_data[:,3], [alpha])[1]
155-
expected_cd = linear_interpolate(polar_data[:,1], polar_data[:,2], [alpha])[1]
156-
expected_cm = linear_interpolate(polar_data[:,1], polar_data[:,4], [alpha])[1]
156+
expected_cl = linear_interpolation(polar_data[:,1], polar_data[:,2], extrapolation_bc=Line())(alpha)
157+
expected_cd = linear_interpolation(polar_data[:,1], polar_data[:,3], extrapolation_bc=Line())(alpha)
158+
expected_cm = linear_interpolation(polar_data[:,1], polar_data[:,4], extrapolation_bc=Line())(alpha)
157159

158160
# Average with slightly different data (1.1 factor)
159161
expected_cl = (expected_cl + 1.1 * expected_cl) / 2

0 commit comments

Comments
 (0)