|
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 |
2 | 3 | using LinearAlgebra |
3 | 4 | using Test |
4 | 5 | using BenchmarkTools |
@@ -112,48 +113,49 @@ end |
112 | 113 | end |
113 | 114 |
|
114 | 115 | # Generate mock polar data |
115 | | - alphas = -10:1:25 |
| 116 | + alphas = deg2rad.(-10:1:25) |
116 | 117 | n_points = length(alphas) |
117 | 118 | polar_data = zeros(n_points, 4) |
| 119 | + big_polar_data = zeros(n_points, 4) |
118 | 120 |
|
119 | 121 | # Fill polar data with realistic values |
120 | 122 | for (i, alpha) in enumerate(alphas) |
121 | 123 | cd = 0.015 + 0.015 * abs(alpha/10)^1.5 # Drag increases with angle |
122 | 124 | cl = 0.1 * alpha + 0.01 * alpha^2 * exp(-alpha/20) # Lift with stall behavior |
123 | 125 | 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] |
125 | 128 | end |
126 | | - |
| 129 | + |
127 | 130 | # Create two sections with slightly different polar data |
128 | 131 | 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)) |
130 | 133 |
|
131 | 134 | # Create panel |
132 | 135 | panel = create_panel(section1, section2) |
133 | 136 |
|
134 | 137 | @testset "Panel Polar Data Initialization" begin |
135 | 138 | # Test if panel has polar data |
136 | | - @test hasattr(panel, :panel_polar_data) |
| 139 | + @test hasproperty(panel, :panel_polar_data) |
137 | 140 | @test !isnothing(panel.panel_polar_data) |
138 | 141 | @test size(panel.panel_polar_data) == size(polar_data) |
139 | 142 |
|
140 | 143 | # 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 |
142 | 145 | @test isapprox(panel.panel_polar_data, expected_data, rtol=1e-5) |
143 | 146 | end |
144 | 147 |
|
145 | 148 | @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]) |
147 | 150 | for alpha in test_alphas |
148 | 151 | # 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) |
152 | 154 |
|
153 | 155 | # 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) |
157 | 159 |
|
158 | 160 | # Average with slightly different data (1.1 factor) |
159 | 161 | expected_cl = (expected_cl + 1.1 * expected_cl) / 2 |
|
0 commit comments