Skip to content

Commit 605f8f3

Browse files
committed
add bench file
1 parent 3ff8bc3 commit 605f8f3

File tree

3 files changed

+118
-4
lines changed

3 files changed

+118
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Manifest.toml
33
venv
44
results/TUDELFT_V3_LEI_KITE/polars/tutorial_testing_stall_model_n_panels_54_distribution_split_provided.pdf
55
docs/build/
6+
*.bin

src/filament.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function velocity_3D_bound_vortex!(
5757
elseif norm(r1Xr0) / norm(r0) == 0
5858
vel .= zeros(3)
5959
else
60-
@info "inside core radius"
61-
@info "distance from control point to filament: $(norm(r1Xr0) / norm(r0))"
60+
@debug "inside core radius"
61+
@debug "distance from control point to filament: $(norm(r1Xr0) / norm(r0))"
6262

6363
# Project onto core radius
6464
cross3!(r2Xr0, r2, r0)
@@ -71,8 +71,6 @@ function velocity_3D_bound_vortex!(
7171
vel_ind_proj .= (gamma / (4π)) .* r1_projXr2_proj ./ (norm(r1_projXr2_proj)^2) .*
7272
dot(r0, r1_proj/norm(r1_proj) .- r2_proj/norm(r2_proj))
7373

74-
@show vel_ind_proj r1_projXr2_proj
75-
7674
vel .= norm(r1Xr0) ./ (norm(r0) * epsilon) .* vel_ind_proj
7775
end
7876
nothing

test/bench.jl

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using BenchmarkTools
2+
using VortexStepMethod
3+
using VortexStepMethod: calculate_AIC_matrices, gamma_loop, calculate_results,
4+
update_effective_angle_of_attack_if_VSM, calculate_projected_area,
5+
calculate_cl, calculate_cd_cm,
6+
calculate_velocity_induced_single_ring_semiinfinite,
7+
calculate_velocity_induced_bound_2D,
8+
velocity_3D_bound_vortex!,
9+
velocity_3D_trailing_vortex!,
10+
velocity_3D_trailing_vortex_semiinfinite!,
11+
Panel
12+
using Test
13+
using LinearAlgebra
14+
15+
@testset "Function Allocation Tests" begin
16+
# Define wing parameters
17+
n_panels = 20 # Number of panels
18+
span = 20.0 # Wing span [m]
19+
chord = 1.0 # Chord length [m]
20+
v_a = 20.0 # Magnitude of inflow velocity [m/s]
21+
density = 1.225 # Air density [kg/m³]
22+
alpha_deg = 30.0 # Angle of attack [degrees]
23+
alpha = deg2rad(alpha_deg)
24+
25+
# Create test panels
26+
panels = []
27+
wing = Wing(n_panels, spanwise_panel_distribution="linear")
28+
add_section!(wing,
29+
[0.0, span/2, 0.0], # Left tip LE
30+
[chord, span/2, 0.0], # Left tip TE
31+
"inviscid")
32+
add_section!(wing,
33+
[0.0, -span/2, 0.0], # Right tip LE
34+
[chord, -span/2, 0.0], # Right tip TE
35+
"inviscid")
36+
37+
wing_aero = WingAerodynamics([wing])
38+
39+
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
40+
set_va!(wing_aero, (vel_app, 0.0)) # Second parameter is yaw rate
41+
42+
# Initialize solvers for both LLT and VSM methods
43+
solver = Solver()
44+
45+
# Pre-allocate arrays
46+
gamma = rand(n_panels)
47+
gamma_new = similar(gamma)
48+
AIC_x = rand(n_panels, n_panels)
49+
AIC_y = similar(AIC_x)
50+
AIC_z = similar(AIC_x)
51+
v_ind = zeros(3)
52+
point = rand(3)
53+
va_norm_array = ones(n_panels)
54+
va_unit_array = ones(n_panels, 3)
55+
56+
models = ["VSM", "LLT"]
57+
core_radius_fractions = [0.001, 10.0]
58+
59+
@testset "AIC Matrix Calculation" begin
60+
for model in models
61+
for frac in core_radius_fractions
62+
result = @benchmark calculate_AIC_matrices($wing_aero, $model, $frac, $va_norm_array, $va_unit_array)
63+
@test result.allocs 100 # Allow some allocations for matrix setup
64+
end
65+
end
66+
end
67+
68+
@testset "Gamma Loop" begin
69+
result = @benchmark gamma_loop($solver, $wing, $gamma_new, $AIC_x, $AIC_y, $AIC_z)
70+
@test result.allocs 50 # Main iteration should be mostly allocation-free
71+
end
72+
73+
@testset "Results Calculation" begin
74+
result = @benchmark calculate_results($wing, $gamma)
75+
@test result.allocs 20 # Allow minimal allocations for results
76+
end
77+
78+
@testset "Angle of Attack Update" begin
79+
result = @benchmark update_effective_angle_of_attack_if_VSM($wing, $gamma)
80+
@test result.allocs == 0 # Should be allocation-free
81+
end
82+
83+
@testset "Area Calculations" begin
84+
result = @benchmark calculate_projected_area($wing)
85+
@test result.allocs 10 # Geometric calculations may need some allocations
86+
end
87+
88+
@testset "Aerodynamic Coefficients" begin
89+
panel = panels[1]
90+
alpha = 0.1
91+
92+
@test (@ballocated calculate_cl($panel, $alpha)) == 0
93+
@test (@ballocated calculate_cd_cm($panel, $alpha)) == 0
94+
end
95+
96+
@testset "Induced Velocity Calculations" begin
97+
# Test single ring velocity calculation
98+
@test (@ballocated calculate_velocity_induced_single_ring_semiinfinite(
99+
$point, $panels[1], $gamma[1])) == 0
100+
101+
# Test 2D bound vortex
102+
@test (@ballocated calculate_velocity_induced_bound_2D(
103+
$point, $panels[1], $gamma[1])) == 0
104+
105+
# Test 3D velocity components
106+
@test (@ballocated velocity_3D_bound_vortex!(
107+
$v_ind, $point, $panels[1], $gamma[1])) == 0
108+
109+
@test (@ballocated velocity_3D_trailing_vortex!(
110+
$v_ind, $point, $panels[1], $gamma[1])) == 0
111+
112+
@test (@ballocated velocity_3D_trailing_vortex_semiinfinite!(
113+
$v_ind, $point, $panels[1], $gamma[1])) == 0
114+
end
115+
end

0 commit comments

Comments
 (0)