Skip to content

Commit cb18276

Browse files
committed
Non-allocating smooth deform
1 parent a92da48 commit cb18276

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/kite_geometry.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ mutable struct RamAirWing <: AbstractWing
407407
area_interp::Extrapolation
408408
theta_dist::Vector{Float64}
409409
delta_dist::Vector{Float64}
410+
cache::Vector{PreallocationTools.LazyBufferCache{typeof(identity), typeof(identity)}}
410411
end
411412

412413
"""
@@ -505,11 +506,12 @@ function RamAirWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10
505506
end
506507

507508
panel_props = PanelProperties{n_panels}()
509+
cache = [LazyBufferCache()]
508510

509511
RamAirWing(n_panels, spanwise_distribution, panel_props, spanwise_direction, sections,
510512
refined_sections, remove_nan, non_deformed_sections,
511513
mass, gamma_tip, inertia_tensor, center_of_mass, radius,
512-
le_interp, te_interp, area_interp, zeros(n_panels), zeros(n_panels))
514+
le_interp, te_interp, area_interp, zeros(n_panels), zeros(n_panels), cache)
513515

514516
catch e
515517
if e isa BoundsError
@@ -557,7 +559,7 @@ function smooth_deform!(wing::RamAirWing, theta_angles::AbstractVector, delta_an
557559

558560
window_size = wing.n_panels ÷ length(theta_angles)
559561
if n_panels > window_size
560-
smoothed = copy(theta_dist)
562+
smoothed = wing.cache[1][theta_dist]
561563
for i in (window_size÷2 + 1):(n_panels - window_size÷2)
562564
@views smoothed[i] = mean(theta_dist[(i - window_size÷2):(i + window_size÷2)])
563565
end

src/solver.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,14 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, wing::RamAirWing
632632

633633
init_va = copy(body_aero.va)
634634
init_alpha_beta = copy(y[alpha_idxs])
635+
zero_delta = zeros(alpha_idxs)
635636

636637
# Function to compute forces for given control inputs
637638
function calc_results!(results, y)
638639
if !isnothing(alpha_idxs) && isnothing(delta_idxs)
639-
VortexStepMethod.smooth_deform!(wing, y[alpha_idxs], zeros(alpha_idxs))
640+
@views VortexStepMethod.smooth_deform!(wing, y[alpha_idxs], zero_delta)
640641
elseif !isnothing(alpha_idxs) && !isnothing(delta_idxs)
641-
VortexStepMethod.smooth_deform!(wing, y[alpha_idxs], y[delta_idxs])
642+
@views VortexStepMethod.smooth_deform!(wing, y[alpha_idxs], y[delta_idxs])
642643
end
643644

644645
VortexStepMethod.init!(body_aero; init_aero=false)

0 commit comments

Comments
 (0)