Skip to content

Commit 82ae5a2

Browse files
committed
Add controlplots tests
1 parent ed5db49 commit 82ae5a2

4 files changed

Lines changed: 70 additions & 29 deletions

File tree

.github/workflows/CI.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ jobs:
8686
- uses: julia-actions/julia-runtest@v1
8787
env:
8888
BUILD_IS_PRODUCTION_BUILD: false
89+
- name: Install matplotlib
90+
run: sudo apt-get install -y python3-matplotlib
91+
- name: Build PyCall
92+
run: julia --project=test -e 'ENV["PYTHON"]=""; using Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")'
93+
- name: Test Makie plotting
94+
run: julia --project=test test/plotting/test_plotting.jl Makie
95+
- name: Test ControlPlots plotting
96+
run: julia --project=test --threads=1 test/plotting/test_plotting.jl ControlPlots
8997
- uses: julia-actions/julia-processcoverage@v1
9098
- uses: codecov/codecov-action@v5
9199
with:

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
55
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
66
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
77
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
8+
ControlPlots = "23c2ee80-7a9e-4350-b264-8e670f12517c"
89
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
@@ -22,6 +23,7 @@ CSV = "0.10"
2223
DataFrames = "1.7"
2324
Documenter = "1.8"
2425
CairoMakie = "0"
26+
ControlPlots = "0.2.5"
2527
Interpolations = "0.15, 0.16"
2628
LinearAlgebra = "1"
2729
Logging = "1"

test/plotting/test_plotting.jl

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
backend = length(ARGS) >= 1 ? ARGS[1] : "Makie"
2+
if backend == "Makie"
3+
using CairoMakie
4+
elseif backend == "ControlPlots"
5+
using ControlPlots
6+
else
7+
error("Unknown plotting backend: $backend. Use \"Makie\" or \"ControlPlots\".")
8+
end
9+
110
using VortexStepMethod
2-
using CairoMakie
311
using Test
412

513
# Resolve repo data directory for ram air kite assets
@@ -29,7 +37,9 @@ if !@isdefined ram_wing
2937
foil_src = joinpath(_ram_data_dir, "ram_air_kite_foil.dat")
3038
cp(body_src, body_path; force=true)
3139
cp(foil_src, foil_path; force=true)
32-
ram_wing = ObjWing(body_path, foil_path; alpha_range=deg2rad.(-1:1), delta_range=deg2rad.(-1:1))
40+
ram_wing = ObjWing(body_path, foil_path;
41+
alpha_range=deg2rad.(-1:1),
42+
delta_range=deg2rad.(-1:1))
3343
end
3444

3545
function create_body_aero()
@@ -38,33 +48,31 @@ function create_body_aero()
3848
span = 20.0 # Wing span [m]
3949
chord = 1.0 # Chord length [m]
4050
v_a = 20.0 # Magnitude of inflow velocity [m/s]
41-
density = 1.225 # Air density [kg/m³]
4251
alpha_deg = 30.0 # Angle of attack [degrees]
4352
alpha = deg2rad(alpha_deg)
4453

4554
# Step 2: Create wing geometry with linear panel distribution
4655
wing = Wing(n_panels, spanwise_distribution=LINEAR)
4756

48-
# Add wing sections - defining only tip sections with inviscid airfoil model
49-
add_section!(wing,
50-
[0.0, span/2, 0.0], # Left tip LE
51-
[chord, span/2, 0.0], # Left tip TE
57+
# Add wing sections
58+
add_section!(wing,
59+
[0.0, span/2, 0.0],
60+
[chord, span/2, 0.0],
5261
INVISCID)
53-
add_section!(wing,
54-
[0.0, -span/2, 0.0], # Right tip LE
55-
[chord, -span/2, 0.0], # Right tip TE
62+
add_section!(wing,
63+
[0.0, -span/2, 0.0],
64+
[chord, -span/2, 0.0],
5665
INVISCID)
5766

5867
# Step 3: Initialize aerodynamics
5968
refine!(wing)
6069
body_aero = BodyAerodynamics([wing])
61-
# Set inflow conditions
6270
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
6371
set_va!(body_aero, vel_app)
6472
body_aero
6573
end
6674

67-
@testset "Plotting" begin
75+
@testset "Plotting ($backend)" begin
6876
save_dir = tempdir()
6977
body_aero = create_body_aero()
7078

@@ -75,15 +83,27 @@ end
7583
save_path=save_dir,
7684
is_save=true,
7785
is_show=false)
78-
@test fig isa Figure
79-
@test isfile(joinpath(save_dir, "Rectangular_wing_geometry_angled_view.png"))
80-
safe_rm(joinpath(save_dir, "Rectangular_wing_geometry_angled_view.png"))
81-
@test isfile(joinpath(save_dir, "Rectangular_wing_geometry_front_view.png"))
82-
safe_rm(joinpath(save_dir, "Rectangular_wing_geometry_front_view.png"))
83-
@test isfile(joinpath(save_dir, "Rectangular_wing_geometry_side_view.png"))
84-
safe_rm(joinpath(save_dir, "Rectangular_wing_geometry_side_view.png"))
85-
@test isfile(joinpath(save_dir, "Rectangular_wing_geometry_top_view.png"))
86-
safe_rm(joinpath(save_dir, "Rectangular_wing_geometry_top_view.png"))
86+
if backend == "Makie"
87+
@test fig isa Figure
88+
else
89+
@test fig !== nothing
90+
end
91+
@test isfile(joinpath(save_dir,
92+
"Rectangular_wing_geometry_angled_view.png"))
93+
safe_rm(joinpath(save_dir,
94+
"Rectangular_wing_geometry_angled_view.png"))
95+
@test isfile(joinpath(save_dir,
96+
"Rectangular_wing_geometry_front_view.png"))
97+
safe_rm(joinpath(save_dir,
98+
"Rectangular_wing_geometry_front_view.png"))
99+
@test isfile(joinpath(save_dir,
100+
"Rectangular_wing_geometry_side_view.png"))
101+
safe_rm(joinpath(save_dir,
102+
"Rectangular_wing_geometry_side_view.png"))
103+
@test isfile(joinpath(save_dir,
104+
"Rectangular_wing_geometry_top_view.png"))
105+
safe_rm(joinpath(save_dir,
106+
"Rectangular_wing_geometry_top_view.png"))
87107

88108
# Step 5: Initialize the solvers
89109
vsm_solver = Solver(body_aero; aerodynamic_model_type=VSM)
@@ -94,7 +114,8 @@ end
94114
results_llt = solve(llt_solver, body_aero)
95115

96116
# Step 7: Plot spanwise distributions
97-
y_coordinates = [panel.aero_center[2] for panel in body_aero.panels]
117+
y_coordinates = [panel.aero_center[2]
118+
for panel in body_aero.panels]
98119

99120
fig = plot_distribution(
100121
[y_coordinates, y_coordinates],
@@ -103,10 +124,14 @@ end
103124
title="Spanwise Distributions",
104125
is_show=false
105126
)
106-
@test fig isa Figure
127+
if backend == "Makie"
128+
@test fig isa Figure
129+
else
130+
@test fig !== nothing
131+
end
107132

108133
# Step 8: Plot polar curves
109-
v_a = 20.0 # Magnitude of inflow velocity [m/s]
134+
v_a = 20.0
110135
angle_range = range(0, 20, 20)
111136
fig = plot_polars(
112137
[llt_solver, vsm_solver],
@@ -121,14 +146,21 @@ end
121146
is_save=true,
122147
is_show=false
123148
)
124-
@test fig isa Figure
149+
if backend == "Makie"
150+
@test fig isa Figure
151+
else
152+
@test fig !== nothing
153+
end
125154
@test isfile(joinpath(save_dir, "Rectangular_Wing_Polars.png"))
126155
safe_rm(joinpath(save_dir, "Rectangular_Wing_Polars.png"))
127156

128157
# Step 9: Test polar data plotting
129-
# ram_wing is an ObjWing - no refine! needed
130158
body_aero = BodyAerodynamics([ram_wing])
131159
fig = plot_polar_data(body_aero; is_show=false)
132-
@test fig isa Figure
160+
if backend == "Makie"
161+
@test fig isa Figure
162+
else
163+
@test fig !== nothing
164+
end
133165
end
134-
nothing
166+
nothing

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ end::Bool
4141
should_run_test("filament/test_bound_filament.jl") && include("filament/test_bound_filament.jl")
4242
should_run_test("filament/test_semi_infinite_filament.jl") && include("filament/test_semi_infinite_filament.jl")
4343
should_run_test("panel/test_panel.jl") && include("panel/test_panel.jl")
44-
should_run_test("plotting/test_plotting.jl") && include("plotting/test_plotting.jl")
4544
should_run_test("polars/test_polars.jl") && include("polars/test_polars.jl")
4645
should_run_test("ram_geometry/test_kite_geometry.jl") && include("ram_geometry/test_kite_geometry.jl")
4746
should_run_test("settings/test_settings.jl") && include("settings/test_settings.jl")

0 commit comments

Comments
 (0)