Skip to content

Commit ee19a46

Browse files
committed
Add bench_solve.jl
1 parent e4c4157 commit ee19a46

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/bench_solve.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# DO NOT DELETE, DO NOT MODIFY!
2+
# This script will not be included in run_tests.jl
3+
# It shall only be executed on one and the same machine for benchmarking the solve functions
4+
using LinearAlgebra
5+
using VortexStepMethod
6+
using BenchmarkTools
7+
using Test
8+
9+
using Pkg
10+
11+
if !("CSV" keys(Pkg.project().dependencies))
12+
using TestEnv
13+
TestEnv.activate()
14+
end
15+
16+
# Step 1: 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+
# Step 2: Create wing geometry with linear panel distribution
26+
wing = Wing(n_panels, spanwise_distribution=LINEAR)
27+
28+
# Add wing sections - defining only tip sections with inviscid airfoil model
29+
add_section!(wing,
30+
[0.0, span/2, 0.0], # Left tip LE
31+
[chord, span/2, 0.0], # Left tip TE
32+
INVISCID)
33+
add_section!(wing,
34+
[0.0, -span/2, 0.0], # Right tip LE
35+
[chord, -span/2, 0.0], # Right tip TE
36+
INVISCID)
37+
38+
# Step 3: Initialize aerodynamics
39+
wa = BodyAerodynamics([wing])
40+
41+
# Set inflow conditions
42+
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
43+
set_va!(wa, vel_app)
44+
45+
# Step 4: Initialize solvers for both LLT and VSM methods
46+
vsm_solver = Solver(wa; aerodynamic_model_type=VSM)
47+
48+
# Step 5: Solve using both methods
49+
result = @benchmark solve_base!($vsm_solver, $wa, nothing) # 34 allocations
50+
println("solve_base():")
51+
println("Allocations: ", result.allocs, ", Mean time: ", round(mean(result.times)/1000), " µs")
52+
# time Python: 32.0 ms Ryzen 7950x
53+
# time Julia: 0.45 ms Ryzen 7950x
54+
result = @benchmark sol = solve!($vsm_solver, $wa, nothing) # 68 allocations
55+
println("solve!()")
56+
println("Allocations: ", result.allocs, ", Mean time: ", round(mean(result.times)/1000), " µs")
57+
nothing

0 commit comments

Comments
 (0)