Skip to content

Commit 1bc106b

Browse files
committed
Reduce allocs
1 parent b10a779 commit 1bc106b

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

examples/ram_air_kite.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ using ControlPlots
22
using VortexStepMethod
33
using LinearAlgebra
44

5-
PLOT = false
5+
PLOT = true
66
USE_TEX = false
7-
DEFORM = true
7+
DEFORM = false
88

99
# Create wing geometry
1010
wing = RamAirWing("data/ram_air_kite_body.obj", "data/ram_air_kite_foil.dat")
@@ -14,15 +14,8 @@ println("First init")
1414

1515
if DEFORM
1616
# Linear interpolation of alpha from 10° at one tip to 0° at the other
17-
n_panels = wing.n_panels
18-
theta_start = deg2rad(10)
19-
theta_end = deg2rad(0)
20-
delta_start = deg2rad(10)
21-
delta_end = deg2rad(0)
22-
theta_dist = [theta_start - i * (theta_start - theta_end)/(n_panels-1) for i in 0:(n_panels-1)]
23-
delta_dist = [delta_start - i * (delta_start - delta_end)/(n_panels-1) for i in 0:(n_panels-1)]
2417
println("Deform")
25-
@time VortexStepMethod.deform!(wing, theta_dist, delta_dist)
18+
@time VortexStepMethod.smooth_deform!(wing, deg2rad.([10,20,10,0]), deg2rad.([-10,0,-10,0]))
2619
println("Deform init")
2720
@time VortexStepMethod.init!(body_aero; init_aero=false)
2821
end

src/kite_geometry.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,29 +519,29 @@ end
519519

520520
function smooth_deform!(wing::RamAirWing, theta_angles::AbstractVector, delta_angles::AbstractVector)
521521
!(wing.n_panels % length(theta_angles) == 0) && throw(ArgumentError("Number of angles has to be a multiple of number of panels"))
522-
panels = wing.panels
522+
n_panels = wing.n_panels
523523
theta_dist = wing.theta_dist
524524
delta_dist = wing.delta_dist
525525

526-
dist_idx = 1
526+
dist_idx = 0
527527
for angle_idx in eachindex(theta_angles)
528528
for _ in 1:(wing.n_panels ÷ length(theta_angles))
529+
dist_idx += 1
529530
theta_dist[dist_idx] = theta_angles[angle_idx]
530531
delta_dist[dist_idx] = delta_angles[angle_idx]
531-
dist_idx += 1
532532
end
533533
end
534534
@assert (dist_idx == wing.n_panels)
535535

536536
window_size = wing.n_panels ÷ length(theta_angles)
537-
if length(panels) > window_size
537+
if n_panels > window_size
538538
smoothed = copy(theta_dist)
539-
for i in (window_size÷2 + 1):(length(panels) - window_size÷2)
540-
smoothed[i] = mean(theta_dist[(i - window_size÷2):(i + window_size÷2)])
539+
for i in (window_size÷2 + 1):(n_panels - window_size÷2)
540+
@views smoothed[i] = mean(theta_dist[(i - window_size÷2):(i + window_size÷2)])
541541
end
542542
theta_dist .= smoothed
543-
for i in (window_size÷2 + 1):(length(panels) - window_size÷2)
544-
smoothed[i] = mean(delta_dist[(i - window_size÷2):(i + window_size÷2)])
543+
for i in (window_size÷2 + 1):(n_panels - window_size÷2)
544+
@views smoothed[i] = mean(delta_dist[(i - window_size÷2):(i + window_size÷2)])
545545
end
546546
delta_dist .= smoothed
547547
end

0 commit comments

Comments
 (0)