Skip to content

Commit 7a0a093

Browse files
committed
three non-allocating functions
1 parent 9bdea5e commit 7a0a093

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

examples/code_bench.jl

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using Revise
22
using LinearAlgebra
33
using ControlPlots
44
using VortexStepMethod
5+
using StaticArrays
6+
using BenchmarkTools
57

68
# Step 1: Define wing parameters
79
n_panels = 20 # Number of panels
@@ -36,20 +38,19 @@ set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
3638
vsm_solver = Solver(aerodynamic_model_type="VSM")
3739

3840
# Benchmark setup
39-
velocity_induced = zeros(3)
40-
tempvel = zeros(3)
41+
velocity_induced = @MVector zeros(3) # StaticArraysCore.MVector{3, Float64}
42+
tempvel = @MVector zeros(3) # StaticArraysCore.MVector{3, Float64}
4143
panel = wa.panels[1]
42-
ep = [0.25, 9.5, 0.0]
43-
evaluation_point_on_bound = true
44-
va_norm = 20.0
45-
va_unit = [0.8660254037844387, 0.0, 0.4999999999999999]
46-
core_radius_fraction = 1.0e-20
47-
gamma = 1.0
44+
ep = @MVector [0.25, 9.5, 0.0] # StaticArraysCore.MVector{3, Float64}
45+
evaluation_point_on_bound = true # Bool
46+
va_norm = 20.0 # Float64
47+
va_unit = @MVector [0.8660254037844387, 0.0, 0.4999999999999999] # StaticArraysCore.MVector{3, Float64}
48+
core_radius_fraction = 1.0e-20 # Float64
49+
gamma = 1.0 # Float64
4850

49-
# Create work vectors tuple
50-
work_vectors = ntuple(_ -> zeros(3), 10)
51+
# Create work vectors tuple of MVector{3, Float64}
52+
work_vectors = ntuple(_ -> @MVector(zeros(3)), 10) # NTuple{10, StaticArraysCore.MVector{3, Float64}}
5153

52-
using BenchmarkTools
5354
@btime VortexStepMethod.calculate_velocity_induced_single_ring_semiinfinite!(
5455
$velocity_induced,
5556
$tempvel,
@@ -63,7 +64,20 @@ using BenchmarkTools
6364
$work_vectors
6465
)
6566

66-
U_2D = zeros(3)
67+
@btime VortexStepMethod.calculate_velocity_induced_single_ring_semiinfinite!(
68+
velocity_induced,
69+
tempvel,
70+
panel.filaments,
71+
ep,
72+
evaluation_point_on_bound,
73+
va_norm,
74+
va_unit,
75+
gamma,
76+
core_radius_fraction,
77+
work_vectors
78+
)
79+
80+
U_2D = @MVector zeros(3) # StaticArraysCore.MVector{3, Float64}
6781

6882
@btime VortexStepMethod.calculate_velocity_induced_bound_2D!(
6983
$U_2D,
@@ -72,4 +86,12 @@ U_2D = zeros(3)
7286
$work_vectors
7387
)
7488

75-
nothing
89+
# model = "VSM"
90+
# va_norm_array = zeros(wa.n_panels)
91+
# va_unit_array = zeros(wa.n_panels, 3)
92+
# @time VortexStepMethod.calculate_AIC_matrices!(wa, model,
93+
# core_radius_fraction,
94+
# va_norm_array,
95+
# va_unit_array)
96+
97+
nothing

src/panel.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,16 @@ Calculate the velocity induced by a vortex ring at a control point.
364364
- nothing
365365
"""
366366
@inline function calculate_velocity_induced_single_ring_semiinfinite!(
367-
velind,
368-
tempvel,
369-
filaments,
370-
evaluation_point,
371-
evaluation_point_on_bound,
372-
va_norm,
373-
va_unit,
374-
gamma,
375-
core_radius_fraction,
376-
work_vectors
367+
velind::MVector{3, Float64},
368+
tempvel::MVector{3, Float64},
369+
filaments::Vector{Union{VortexStepMethod.BoundFilament, VortexStepMethod.SemiInfiniteFilament}},
370+
evaluation_point::MVector{3, Float64},
371+
evaluation_point_on_bound::Bool,
372+
va_norm::Float64,
373+
va_unit::MVector{3, Float64},
374+
gamma::Float64,
375+
core_radius_fraction::Float64,
376+
work_vectors::NTuple{10, MVector{3, Float64}}
377377
)
378378
velind .= 0.0
379379
tempvel .= 0.0

src/wing_aerodynamics.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,12 @@ function calculate_AIC_matrices!(wa::WingAerodynamics, model,
229229
evaluation_point_on_bound = model == "LLT"
230230

231231
# Initialize AIC matrices
232-
AIC = @views wa.AIC
233232
velocity_induced, tempvel, va_unit, U_2D = zeros(MVec3), zeros(MVec3), zeros(MVec3), zeros(MVec3)
234233

235234
# Calculate influence coefficients
236235
for icp in 1:wa.n_panels
237236
ep = getproperty(wa.panels[icp], evaluation_point)
238237
for jring in 1:wa.n_panels
239-
velocity_induced .= 0.0
240-
tempvel .= 0.0
241238
va_unit .= @views va_unit_array[jring, :]
242239
filaments = wa.panels[jring].filaments
243240
va_norm = va_norm_array[jring]
@@ -253,13 +250,12 @@ function calculate_AIC_matrices!(wa::WingAerodynamics, model,
253250
core_radius_fraction,
254251
wa.work_vectors
255252
)
256-
257-
AIC[:, icp, jring] .= velocity_induced
253+
wa.AIC[:, icp, jring] .= velocity_induced
258254

259255
# Subtract 2D induced velocity for VSM
260256
if icp == jring && model == "VSM"
261257
calculate_velocity_induced_bound_2D!(U_2D, wa.panels[jring], ep, wa.work_vectors)
262-
AIC[:, icp, jring] .-= U_2D
258+
wa.AIC[:, icp, jring] .-= U_2D
263259
end
264260
end
265261
end

0 commit comments

Comments
 (0)