Skip to content

Commit 262a087

Browse files
1-Bart-1ufechner7
andauthored
reduce allocations more (#44)
* reduce allocations more * add dat file * add bench file * improve test * rename Umag to v_a * cant remove calculate_velocity_induced_single_ring_semiinfinite! allocs * two non-allocating functions in code_bench * add simple script for alloc testing * fix calculations * three non-allocating functions * make tests pass again * non-allocating gamma loop * more efficient polars * use symbols instead of strings * switch to Symbol * tests pass again * working test bench * make tests and examples work * remove unused dependency * add bench.jl * add bench to the menu * less output * fix comment * add plot option to example --------- Co-authored-by: Uwe Fechner <[email protected]>
1 parent aaa9159 commit 262a087

20 files changed

+703
-387
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ results/TUDELFT_V3_LEI_KITE/polars/$C_L$ vs $C_D$.pdf
55
*.bin
66
results/TUDELFT_V3_LEI_KITE/polars/tutorial_testing_stall_model_n_panels_54_distribution_split_provided.pdf
77
docs/build/
8-

examples/bench.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using LinearAlgebra
2+
using ControlPlots
3+
using VortexStepMethod
4+
5+
plot = true
6+
7+
# Step 1: Define wing parameters
8+
n_panels = 20 # Number of panels
9+
span = 20.0 # Wing span [m]
10+
chord = 1.0 # Chord length [m]
11+
v_a = 20.0 # Magnitude of inflow velocity [m/s]
12+
density = 1.225 # Air density [kg/m³]
13+
alpha_deg = 30.0 # Angle of attack [degrees]
14+
alpha = deg2rad(alpha_deg)
15+
16+
# Step 2: Create wing geometry with linear panel distribution
17+
wing = Wing(n_panels, spanwise_panel_distribution=:linear)
18+
19+
# Add wing sections - defining only tip sections with inviscid airfoil model
20+
add_section!(wing,
21+
[0.0, span/2, 0.0], # Left tip LE
22+
[chord, span/2, 0.0], # Left tip TE
23+
:inviscid)
24+
add_section!(wing,
25+
[0.0, -span/2, 0.0], # Right tip LE
26+
[chord, -span/2, 0.0], # Right tip TE
27+
:inviscid)
28+
29+
# Step 3: Initialize aerodynamics
30+
wa = BodyAerodynamics([wing])
31+
32+
# Set inflow conditions
33+
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
34+
set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
35+
36+
# Step 4: Initialize solvers for both LLT and VSM methods
37+
llt_solver = Solver(aerodynamic_model_type=:LLT)
38+
vsm_solver = Solver(aerodynamic_model_type=:VSM)
39+
40+
# Step 5: Solve using both methods
41+
results_vsm = solve(vsm_solver, wa)
42+
@time results_vsm = solve(vsm_solver, wa)
43+
# time Python: 32.0 ms
44+
# time Julia: 0.7 ms
45+
46+
nothing

examples/menu.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using REPL.TerminalMenus
33
options = ["rectangular_wing = include(\"rectangular_wing.jl\")",
44
"ram_air_kite = include(\"ram_air_kite.jl\")",
55
"stall_model = include(\"stall_model.jl\")",
6+
"bench = include(\"bench.jl\")",
67
"quit"]
78

89
function example_menu()

examples/ram_air_kite.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ end
88
using CSV
99
using DataFrames
1010

11+
plot = true
12+
1113
# Create wing geometry
1214
wing = KiteWing("data/ram_air_kite_body.obj", "data/ram_air_kite_foil.dat")
1315
body_aero = BodyAerodynamics([wing])
1416

1517
# Create solvers
1618
VSM = Solver(
17-
aerodynamic_model_type="VSM",
19+
aerodynamic_model_type=:VSM,
1820
is_with_artificial_damping=false
1921
)
2022
VSM_with_stall_correction = Solver(
21-
aerodynamic_model_type="VSM",
23+
aerodynamic_model_type=:VSM,
2224
is_with_artificial_damping=true
2325
)
2426

@@ -36,7 +38,7 @@ vel_app = [
3638
body_aero.va = vel_app
3739

3840
# Plotting geometry
39-
plot_geometry(
41+
plot && plot_geometry(
4042
body_aero,
4143
"";
4244
data_type=".svg",
@@ -53,7 +55,7 @@ plot_geometry(
5355

5456
CAD_y_coordinates = [panel.aerodynamic_center[2] for panel in body_aero.panels]
5557

56-
plot_distribution(
58+
plot && plot_distribution(
5759
[CAD_y_coordinates],
5860
[results],
5961
["VSM"];
@@ -63,7 +65,7 @@ plot_distribution(
6365
is_show=true
6466
)
6567

66-
plot_polars(
68+
plot && plot_polars(
6769
[VSM],
6870
[body_aero],
6971
[

examples/rectangular_wing.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using LinearAlgebra
22
using ControlPlots
33
using VortexStepMethod
44

5+
plot = true
6+
57
# Step 1: Define wing parameters
68
n_panels = 20 # Number of panels
79
span = 20.0 # Wing span [m]
@@ -12,17 +14,17 @@ alpha_deg = 30.0 # Angle of attack [degrees]
1214
alpha = deg2rad(alpha_deg)
1315

1416
# Step 2: Create wing geometry with linear panel distribution
15-
wing = Wing(n_panels, spanwise_panel_distribution="linear")
17+
wing = Wing(n_panels, spanwise_panel_distribution=:linear)
1618

1719
# Add wing sections - defining only tip sections with inviscid airfoil model
1820
add_section!(wing,
1921
[0.0, span/2, 0.0], # Left tip LE
2022
[chord, span/2, 0.0], # Left tip TE
21-
"inviscid")
23+
:inviscid)
2224
add_section!(wing,
2325
[0.0, -span/2, 0.0], # Right tip LE
2426
[chord, -span/2, 0.0], # Right tip TE
25-
"inviscid")
27+
:inviscid)
2628

2729
# Step 3: Initialize aerodynamics
2830
wa = BodyAerodynamics([wing])
@@ -32,16 +34,16 @@ vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
3234
set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
3335

3436
# Step 4: Initialize solvers for both LLT and VSM methods
35-
llt_solver = Solver(aerodynamic_model_type="LLT")
36-
vsm_solver = Solver(aerodynamic_model_type="VSM")
37+
llt_solver = Solver(aerodynamic_model_type=:LLT)
38+
vsm_solver = Solver(aerodynamic_model_type=:VSM)
3739

3840
# Step 5: Solve using both methods
41+
results_llt = solve(llt_solver, wa)
3942
@time results_llt = solve(llt_solver, wa)
40-
@time results_llt = solve(llt_solver, wa)
41-
@time results_vsm = solve(vsm_solver, wa)
43+
results_vsm = solve(vsm_solver, wa)
4244
@time results_vsm = solve(vsm_solver, wa)
4345
# time Python: 32.0ms
44-
# time Julia: 1.5ms
46+
# time Julia: 0.7ms
4547

4648
# Print results comparison
4749
println("\nLifting Line Theory Results:")
@@ -53,20 +55,19 @@ println("CD = $(round(results_vsm["cd"], digits=4))")
5355
println("Projected area = $(round(results_vsm["projected_area"], digits=4))")
5456

5557
# Step 6: Plot geometry
56-
plot_geometry(
58+
plot && plot_geometry(
5759
wa,
5860
"Rectangular_wing_geometry";
5961
data_type=".pdf",
6062
save_path=".",
6163
is_save=false,
6264
is_show=true,
6365
)
64-
nothing
6566

6667
# Step 7: Plot spanwise distributions
6768
y_coordinates = [panel.aerodynamic_center[2] for panel in wa.panels]
6869

69-
plot_distribution(
70+
plot && plot_distribution(
7071
[y_coordinates, y_coordinates],
7172
[results_vsm, results_llt],
7273
["VSM", "LLT"],
@@ -75,7 +76,7 @@ plot_distribution(
7576

7677
# Step 8: Plot polar curves
7778
angle_range = range(0, 20, 20)
78-
plot_polars(
79+
plot && plot_polars(
7980
[llt_solver, vsm_solver],
8081
[wa, wa],
8182
["LLT", "VSM"];

examples/stall_model.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ end
88
using CSV
99
using DataFrames
1010

11+
plot = true
12+
1113
# Find root directory
1214
root_dir = dirname(@__DIR__)
1315
save_folder = joinpath(root_dir, "results", "TUDELFT_V3_LEI_KITE")
1416
mkpath(save_folder)
1517

1618
# Defining discretisation
1719
n_panels = 54
18-
spanwise_panel_distribution = "split_provided"
20+
spanwise_panel_distribution = :split_provided
1921

2022
# Load rib data from CSV
2123
csv_file_path = joinpath(
@@ -30,7 +32,7 @@ rib_list = []
3032
for row in eachrow(df)
3133
LE = [row.LE_x, row.LE_y, row.LE_z]
3234
TE = [row.TE_x, row.TE_y, row.TE_z]
33-
push!(rib_list, (LE, TE, ("lei_airfoil_breukels", [row.d_tube, row.camber])))
35+
push!(rib_list, (LE, TE, (:lei_airfoil_breukels, [row.d_tube, row.camber])))
3436
end
3537

3638
# Create wing geometry
@@ -42,11 +44,11 @@ body_aero_CAD_19ribs = BodyAerodynamics([CAD_wing])
4244

4345
# Create solvers
4446
VSM = Solver(
45-
aerodynamic_model_type="VSM",
47+
aerodynamic_model_type=:VSM,
4648
is_with_artificial_damping=false
4749
)
4850
VSM_with_stall_correction = Solver(
49-
aerodynamic_model_type="VSM",
51+
aerodynamic_model_type=:VSM,
5052
is_with_artificial_damping=true
5153
)
5254

@@ -63,17 +65,17 @@ vel_app = [
6365
] * v_a
6466
body_aero_CAD_19ribs.va = vel_app
6567

66-
# # Plotting geometry
67-
# plot_geometry(
68-
# body_aero_CAD_19ribs,
69-
# "";
70-
# data_type=".svg",
71-
# save_path="",
72-
# is_save=false,
73-
# is_show=true,
74-
# view_elevation=15,
75-
# view_azimuth=-120
76-
# )
68+
# Plotting geometry
69+
plot && plot_geometry(
70+
body_aero_CAD_19ribs,
71+
"";
72+
data_type=".svg",
73+
save_path="",
74+
is_save=false,
75+
is_show=true,
76+
view_elevation=15,
77+
view_azimuth=-120
78+
)
7779

7880
# Solving and plotting distributions
7981
results = solve(VSM, body_aero_CAD_19ribs)
@@ -82,7 +84,7 @@ results = solve(VSM, body_aero_CAD_19ribs)
8284

8385
CAD_y_coordinates = [panel.aerodynamic_center[2] for panel in body_aero_CAD_19ribs.panels]
8486

85-
plot_distribution(
87+
plot && plot_distribution(
8688
[CAD_y_coordinates, CAD_y_coordinates],
8789
[results, results_with_stall],
8890
["VSM", "VSM with stall correction"];
@@ -103,7 +105,7 @@ path_cfd_lebesque = joinpath(
103105
"V3_CL_CD_RANS_Lebesque_2024_Rey_300e4.csv"
104106
)
105107

106-
plot_polars(
108+
plot && plot_polars(
107109
[VSM, VSM_with_stall_correction],
108110
[body_aero_CAD_19ribs, body_aero_CAD_19ribs],
109111
[

0 commit comments

Comments
 (0)