Skip to content

Commit 1438b55

Browse files
committed
Added tests and settings
1 parent dad4e72 commit 1438b55

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed

data/ram_air_kite/vsm_settings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ PanelDistribution:
1010
InitialGammaDistribution:
1111
ELLIPTIC: Elliptic distribution
1212
ZEROS: Constant distribution
13+
PanelGroupingMethod:
14+
EQUAL_SIZE: Divide panels into equally-sized sequential groups
15+
REFINE: Group refined panels by their original unrefined section
1316

1417
wings:
1518
- name: main_wing
1619
n_panels: 40
1720
n_groups: 40
1821
spanwise_panel_distribution: LINEAR
1922
spanwise_direction: [0.0, 1.0, 0.0]
23+
grouping_method: EQUAL_SIZE
2024
remove_nan: true
2125
solver_settings:
2226
n_panels: 40

src/settings.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ end
1414
n_groups::Int64 = 40
1515
spanwise_panel_distribution::PanelDistribution = LINEAR
1616
spanwise_direction::MVec3 = [0.0, 1.0, 0.0]
17+
grouping_method::PanelGroupingMethod = EQUAL_SIZE
1718
remove_nan = true
1819
end
1920

@@ -80,6 +81,9 @@ function VSMSettings(filename; data_prefix=true)
8081
wing.n_groups = wing_data["n_groups"]
8182
wing.spanwise_panel_distribution = eval(Symbol(wing_data["spanwise_panel_distribution"]))
8283
wing.spanwise_direction = MVec3(wing_data["spanwise_direction"])
84+
if haskey(wing_data, "grouping_method")
85+
wing.grouping_method = eval(Symbol(wing_data["grouping_method"]))
86+
end
8387
wing.remove_nan = wing_data["remove_nan"]
8488

8589
push!(vsm_settings.wings, wing)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ end::Bool
2828
include("ram_geometry/test_kite_geometry.jl")
2929
include("settings/test_settings.jl")
3030
include("solver/test_solver.jl")
31+
include("solver/test_group_coefficients.jl")
3132
include("VortexStepMethod/test_VortexStepMethod.jl")
3233
include("wake/test_wake.jl")
3334
include("wing_geometry/test_wing_geometry.jl")
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
using VortexStepMethod
2+
using LinearAlgebra
3+
using Test
4+
5+
# Load test support
6+
include("../TestSupport.jl")
7+
using .TestSupport
8+
9+
@testset "Group Coefficient Arrays Tests" begin
10+
@testset "Group coefficients with EQUAL_SIZE method" begin
11+
# Create a simple wing with groups
12+
n_panels = 20
13+
n_groups = 4
14+
15+
# Create a test wing settings file
16+
settings_file = create_temp_wing_settings("solver", "solver_test_wing.yaml"; alpha=5.0, beta=0.0, wind_speed=10.0)
17+
18+
try
19+
# Modify settings to use specific panel/group configuration
20+
settings = VSMSettings(settings_file)
21+
settings.wings[1].n_panels = n_panels
22+
settings.wings[1].n_groups = n_groups
23+
settings.wings[1].grouping_method = EQUAL_SIZE
24+
settings.solver_settings.n_panels = n_panels
25+
settings.solver_settings.n_groups = n_groups
26+
27+
# Create wing and solver
28+
wing = Wing(settings)
29+
body_aero = BodyAerodynamics([wing])
30+
solver = Solver(body_aero, settings)
31+
32+
# Set conditions and solve
33+
va = [10.0, 0.0, 0.0]
34+
set_va!(body_aero, va)
35+
sol = solve!(solver, body_aero)
36+
37+
# Test 1: Group arrays exist and have correct size
38+
@test length(sol.cl_group_array) == n_groups
39+
@test length(sol.cd_group_array) == n_groups
40+
@test length(sol.cm_group_array) == n_groups
41+
42+
# Test 2: Group arrays are not all zeros (solver computed them)
43+
@test !all(sol.cl_group_array .== 0.0)
44+
@test !all(sol.cd_group_array .== 0.0)
45+
46+
# Test 3: Verify group coefficients are averages of panel coefficients
47+
panels_per_group = n_panels ÷ n_groups
48+
for group_idx in 1:n_groups
49+
panel_start = (group_idx - 1) * panels_per_group + 1
50+
panel_end = group_idx * panels_per_group
51+
52+
# Calculate expected average from panel coefficients
53+
expected_cl = sum(sol.cl_array[panel_start:panel_end]) / panels_per_group
54+
expected_cd = sum(sol.cd_array[panel_start:panel_end]) / panels_per_group
55+
expected_cm = sum(sol.cm_array[panel_start:panel_end]) / panels_per_group
56+
57+
# Check if group coefficients match expected averages
58+
# Handle NaN values that can occur in INVISCID models
59+
if isnan(expected_cl)
60+
@test isnan(sol.cl_group_array[group_idx])
61+
else
62+
@test isapprox(sol.cl_group_array[group_idx], expected_cl, rtol=1e-10)
63+
end
64+
if isnan(expected_cd)
65+
@test isnan(sol.cd_group_array[group_idx])
66+
else
67+
@test isapprox(sol.cd_group_array[group_idx], expected_cd, rtol=1e-10)
68+
end
69+
if isnan(expected_cm)
70+
@test isnan(sol.cm_group_array[group_idx])
71+
else
72+
@test isapprox(sol.cm_group_array[group_idx], expected_cm, rtol=1e-10)
73+
end
74+
end
75+
76+
# Test 4: Verify physical consistency (lift coefficients should be positive at positive AoA)
77+
# Skip test if values are NaN
78+
if !any(isnan.(sol.cl_group_array))
79+
@test all(sol.cl_group_array .> 0.0)
80+
end
81+
82+
finally
83+
rm(settings_file; force=true)
84+
end
85+
end
86+
87+
@testset "Group coefficients with n_groups=0 (no grouping)" begin
88+
# Create a wing with no groups
89+
n_panels = 20
90+
n_groups = 0
91+
92+
settings_file = create_temp_wing_settings("solver", "solver_test_wing.yaml"; alpha=5.0, beta=0.0, wind_speed=10.0)
93+
94+
try
95+
settings = VSMSettings(settings_file)
96+
settings.wings[1].n_panels = n_panels
97+
settings.wings[1].n_groups = n_groups
98+
settings.solver_settings.n_panels = n_panels
99+
settings.solver_settings.n_groups = n_groups
100+
101+
wing = Wing(settings)
102+
body_aero = BodyAerodynamics([wing])
103+
solver = Solver(body_aero, settings)
104+
105+
va = [10.0, 0.0, 0.0]
106+
set_va!(body_aero, va)
107+
sol = solve!(solver, body_aero)
108+
109+
# Test: Group arrays should be empty when n_groups=0
110+
@test length(sol.cl_group_array) == 0
111+
@test length(sol.cd_group_array) == 0
112+
@test length(sol.cm_group_array) == 0
113+
114+
finally
115+
rm(settings_file; force=true)
116+
end
117+
end
118+
119+
@testset "Group coefficients with different group sizes" begin
120+
# Test with various panel/group combinations
121+
test_cases = [
122+
(n_panels=40, n_groups=8),
123+
(n_panels=30, n_groups=5),
124+
(n_panels=24, n_groups=6),
125+
]
126+
127+
for (n_panels, n_groups) in test_cases
128+
settings_file = create_temp_wing_settings("solver", "solver_test_wing.yaml"; alpha=5.0, beta=0.0, wind_speed=10.0)
129+
130+
try
131+
settings = VSMSettings(settings_file)
132+
settings.wings[1].n_panels = n_panels
133+
settings.wings[1].n_groups = n_groups
134+
settings.wings[1].grouping_method = EQUAL_SIZE
135+
settings.solver_settings.n_panels = n_panels
136+
settings.solver_settings.n_groups = n_groups
137+
138+
wing = Wing(settings)
139+
body_aero = BodyAerodynamics([wing])
140+
solver = Solver(body_aero, settings)
141+
142+
va = [10.0, 0.0, 0.0]
143+
set_va!(body_aero, va)
144+
sol = solve!(solver, body_aero)
145+
146+
# Verify arrays have correct size
147+
@test length(sol.cl_group_array) == n_groups
148+
@test length(sol.cd_group_array) == n_groups
149+
@test length(sol.cm_group_array) == n_groups
150+
151+
# Verify group coefficients are computed correctly
152+
panels_per_group = n_panels ÷ n_groups
153+
for group_idx in 1:n_groups
154+
panel_start = (group_idx - 1) * panels_per_group + 1
155+
panel_end = group_idx * panels_per_group
156+
157+
expected_cl = sum(sol.cl_array[panel_start:panel_end]) / panels_per_group
158+
expected_cd = sum(sol.cd_array[panel_start:panel_end]) / panels_per_group
159+
expected_cm = sum(sol.cm_array[panel_start:panel_end]) / panels_per_group
160+
161+
# Handle NaN for all coefficients
162+
if isnan(expected_cl)
163+
@test isnan(sol.cl_group_array[group_idx])
164+
else
165+
@test isapprox(sol.cl_group_array[group_idx], expected_cl, rtol=1e-10)
166+
end
167+
if isnan(expected_cd)
168+
@test isnan(sol.cd_group_array[group_idx])
169+
else
170+
@test isapprox(sol.cd_group_array[group_idx], expected_cd, rtol=1e-10)
171+
end
172+
if isnan(expected_cm)
173+
@test isnan(sol.cm_group_array[group_idx])
174+
else
175+
@test isapprox(sol.cm_group_array[group_idx], expected_cm, rtol=1e-10)
176+
end
177+
end
178+
179+
finally
180+
rm(settings_file; force=true)
181+
end
182+
end
183+
end
184+
end

0 commit comments

Comments
 (0)