Skip to content

Commit e191857

Browse files
committed
add induction matrix test
1 parent df2baca commit e191857

File tree

4 files changed

+588
-428
lines changed

4 files changed

+588
-428
lines changed

test/test_wing_aerodynamics.jl

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# using VortexStepMethod: Wing, WingAerodynamics, BoundFilament, SemiInfiniteFilament, add_section!, set_va!, solve, calculate_cl
22
using VortexStepMethod
3-
using VortexStepMethod: calculate_cl, calculate_cd_cm, calculate_projected_area
3+
using VortexStepMethod: calculate_cl, calculate_cd_cm, calculate_projected_area, calculate_AIC_matrices
44
using LinearAlgebra
55
using Test
66
using Logging
77

8+
# ENV["JULIA_DEBUG"] = "all"
9+
# global_logger(ConsoleLogger(stderr, Logging.Debug))
10+
811
include("utils.jl")
912

1013
@testset "Calculate results against output results" begin
@@ -100,3 +103,109 @@ include("utils.jl")
100103
@test length(results_NEW["cl_distribution"]) == length(wing_aero.panels)
101104
@test length(results_NEW["cd_distribution"]) == length(wing_aero.panels)
102105
end
106+
107+
108+
@testset "Induction Matrix Creation" begin
109+
# Setup
110+
n_panels = 3
111+
N = n_panels + 1 # number of SECTIONS
112+
max_chord = 1.0
113+
span = 2.36
114+
AR = span^2 /* span * max_chord / 4)
115+
dist = "cos"
116+
coord = generate_coordinates_el_wing(max_chord, span, N, dist)
117+
118+
Atot = max_chord / 2 * span / 2 * π
119+
@debug "N: $N"
120+
@debug "size(coord): $(size(coord))"
121+
122+
Umag = 20.0
123+
aoa = 5.7106 * π / 180
124+
Uinf = [cos(aoa), 0.0, sin(aoa)] .* Umag
125+
126+
# Create wing geometry
127+
core_radius_fraction = 1e-20
128+
coord_left_to_right = flip_created_coord_in_pairs(deepcopy(coord))
129+
wing = Wing(n_panels; spanwise_panel_distribution="unchanged")
130+
for idx in 1:2:size(coord_left_to_right, 1)
131+
add_section!(
132+
wing,
133+
coord_left_to_right[idx,:],
134+
coord_left_to_right[idx+1,:],
135+
"inviscid"
136+
)
137+
end
138+
139+
wing_aero = WingAerodynamics([wing])
140+
set_va!(wing_aero, (Uinf, 0.0))
141+
142+
# Calculate reference matrices using thesis functions
143+
controlpoints, rings, bladepanels, ringvec, coord_L =
144+
create_geometry_general(coord, Uinf, N, "5fil", "LLT")
145+
146+
# Test LLT matrices
147+
@testset "LLT Matrices" begin
148+
# Calculate reference matrices
149+
MatrixU, MatrixV, MatrixW = thesis_induction_matrix_creation(
150+
deepcopy(ringvec),
151+
deepcopy(controlpoints),
152+
deepcopy(rings),
153+
deepcopy(Uinf),
154+
zeros(N-1),
155+
nothing, # data_airf not needed
156+
nothing, # conv_crit not needed
157+
"LLT"
158+
)
159+
160+
# Calculate new matrices
161+
va_norm_array = fill(norm(Uinf), length(coord))
162+
va_unit_array = repeat(reshape(Uinf ./ norm(Uinf), 1, 3), length(coord))
163+
AIC_x, AIC_y, AIC_z = calculate_AIC_matrices(
164+
wing_aero,
165+
"LLT",
166+
core_radius_fraction,
167+
va_norm_array,
168+
va_unit_array
169+
)
170+
171+
# Compare matrices
172+
@test isapprox(MatrixU, AIC_x, atol=1e-5)
173+
@test isapprox(MatrixV, -AIC_y, atol=1e-5)
174+
@test isapprox(MatrixW, AIC_z, atol=1e-5)
175+
end
176+
177+
# Test VSM matrices
178+
@testset "VSM Matrices" begin
179+
# Calculate reference matrices for VSM
180+
controlpoints, rings, bladepanels, ringvec, coord_L =
181+
create_geometry_general(coord, Uinf, N, "5fil", "VSM")
182+
183+
MatrixU, MatrixV, MatrixW = thesis_induction_matrix_creation(
184+
deepcopy(ringvec),
185+
deepcopy(controlpoints),
186+
deepcopy(rings),
187+
deepcopy(Uinf),
188+
zeros(N-1),
189+
nothing,
190+
nothing,
191+
"VSM"
192+
)
193+
194+
# Calculate new matrices
195+
va_norm_array = fill(norm(Uinf), length(coord))
196+
va_unit_array = repeat(reshape(Uinf ./ norm(Uinf), 1, 3), length(coord))
197+
AIC_x, AIC_y, AIC_z = calculate_AIC_matrices(
198+
wing_aero,
199+
"VSM",
200+
core_radius_fraction,
201+
va_norm_array,
202+
va_unit_array
203+
)
204+
205+
# Compare matrices with higher precision for VSM
206+
@test isapprox(MatrixU, AIC_x, atol=1e-8)
207+
@test isapprox(MatrixV, -AIC_y, atol=1e-8)
208+
@test isapprox(MatrixW, AIC_z, atol=1e-8)
209+
@show MatrixU MatrixV MatrixW
210+
end
211+
end

0 commit comments

Comments
 (0)