Skip to content

Commit 0ab5152

Browse files
committed
cant remove calculate_velocity_induced_single_ring_semiinfinite! allocs
1 parent 650bf72 commit 0ab5152

File tree

6 files changed

+66
-63
lines changed

6 files changed

+66
-63
lines changed

src/filament.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ end
3131
Calculate induced velocity by a bound vortex filament at a point in space.
3232
"""
3333
function velocity_3D_bound_vortex!(
34-
vel::VelVector,
34+
vel,
3535
filament::BoundFilament,
36-
XVP::PosVector,
37-
gamma::Float64,
38-
core_radius_fraction::Float64,
39-
work_vectors::NTuple{10, Vector{Float64}}
36+
XVP,
37+
gamma,
38+
core_radius_fraction,
39+
work_vectors
4040
)
4141
r1, r2, r1Xr2, r1Xr0, r2Xr0, r1r2norm, r1_proj, r2_proj, r1_projXr2_proj, vel_ind_proj = work_vectors
4242
r0 = filament.r0
@@ -93,12 +93,12 @@ Reference: Rick Damiani et al. "A vortex step method for nonlinear airfoil polar
9393
as implemented in KiteAeroDyn".
9494
"""
9595
function velocity_3D_trailing_vortex!(
96-
vel::VelVector,
96+
vel,
9797
filament::BoundFilament,
98-
XVP::PosVector,
99-
gamma::Float64,
100-
Uinf::Float64,
101-
work_vectors::NTuple{10,Vector{Float64}}
98+
XVP,
99+
gamma,
100+
Uinf,
101+
work_vectors
102102
)
103103
r0, r1, r2, r_perp, r1Xr2, r1Xr0, r2Xr0, normr1r2 = work_vectors[1:8]
104104
r0 .= filament.x2 .- filament.x1 # Vortex filament
@@ -160,13 +160,13 @@ end
160160
Calculate induced velocity by a semi-infinite trailing vortex filament.
161161
"""
162162
function velocity_3D_trailing_vortex_semiinfinite!(
163-
vel::VelVector,
163+
vel,
164164
filament::SemiInfiniteFilament,
165-
Vf::VelVector,
166-
XVP::PosVector,
167-
GAMMA::Float64,
168-
Uinf::Float64,
169-
work_vectors::NTuple{10,Vector{Float64}}
165+
Vf,
166+
XVP,
167+
GAMMA,
168+
Uinf,
169+
work_vectors
170170
)
171171
r1, r_perp, r1XVf = work_vectors[1:3]
172172
GAMMA = -GAMMA * filament.filament_direction

src/panel.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ function calculate_filaments_for_plotting(panel::Panel)
338338
end
339339

340340
"""
341-
calculate_velocity_induced_single_ring_semiinfinite(
341+
calculate_velocity_induced_single_ring_semiinfinite!(
342+
velind::Matrix{Float64},
343+
tempvel::Vector{Float64},
342344
panel::Panel,
343345
evaluation_point::Vector{Float64},
344346
evaluation_point_on_bound::Bool,
@@ -359,26 +361,25 @@ Calculate the velocity induced by a vortex ring at a control point.
359361
- `core_radius_fraction`: Vortex core radius as fraction of panel width
360362
361363
# Returns
362-
- `Vector{Float64}`: Induced velocity vector
364+
- nothing
363365
"""
364-
function calculate_velocity_induced_single_ring_semiinfinite(
366+
function calculate_velocity_induced_single_ring_semiinfinite!(
367+
velind,
368+
tempvel,
365369
panel::Panel,
366-
evaluation_point::PosVector,
367-
evaluation_point_on_bound::Bool,
368-
va_norm::Float64,
369-
va_unit::VelVector,
370-
gamma::Float64,
371-
core_radius_fraction::Float64,
372-
work_vectors::NTuple{10,Vector{Float64}}
370+
evaluation_point,
371+
evaluation_point_on_bound,
372+
va_norm,
373+
va_unit,
374+
gamma,
375+
core_radius_fraction,
376+
work_vectors
373377
)
374-
velind = zeros(Float64, 3)
375-
tempvel = zeros(3)
376-
377378
# Process each filament
378379
for (i, filament) in enumerate(panel.filaments)
379380
if i == 1 # bound filament
380381
if evaluation_point_on_bound
381-
tempvel .= zeros(Float64, 3)
382+
tempvel .= 0.0
382383
else
383384
velocity_3D_bound_vortex!(
384385
tempvel,
@@ -413,8 +414,7 @@ function calculate_velocity_induced_single_ring_semiinfinite(
413414
end
414415
velind .+= tempvel
415416
end
416-
417-
return velind
417+
return nothing
418418
end
419419

420420
"""

src/solver.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function solve(solver::Solver, wing_aero::WingAerodynamics, gamma_distribution=n
8989
va_unit_array = va_array ./ va_norm_array
9090

9191
# Calculate AIC matrices
92-
AIC_x, AIC_y, AIC_z = calculate_AIC_matrices(
92+
calculate_AIC_matrices!(
9393
wing_aero,
9494
solver.aerodynamic_model_type,
9595
solver.core_radius_fraction,
@@ -116,9 +116,6 @@ function solve(solver::Solver, wing_aero::WingAerodynamics, gamma_distribution=n
116116
solver,
117117
wing_aero,
118118
gamma_initial,
119-
AIC_x,
120-
AIC_y,
121-
AIC_z,
122119
va_array,
123120
chord_array,
124121
x_airf_array,
@@ -134,9 +131,6 @@ function solve(solver::Solver, wing_aero::WingAerodynamics, gamma_distribution=n
134131
solver,
135132
wing_aero,
136133
gamma_initial,
137-
AIC_x,
138-
AIC_y,
139-
AIC_z,
140134
va_array,
141135
chord_array,
142136
x_airf_array,
@@ -185,9 +179,6 @@ function gamma_loop(
185179
solver::Solver,
186180
wing_aero::WingAerodynamics,
187181
gamma_new::Vector{Float64},
188-
AIC_x::Matrix{Float64},
189-
AIC_y::Matrix{Float64},
190-
AIC_z::Matrix{Float64},
191182
va_array::Matrix{Float64},
192183
chord_array::Vector{Float64},
193184
x_airf_array::Matrix{Float64},
@@ -204,14 +195,16 @@ function gamma_loop(
204195

205196
gamma = copy(gamma_new)
206197
abs_gamma_new = copy(gamma_new)
207-
induced_velocity_all = zeros(size(AIC_x, 1), 3)
198+
induced_velocity_all = zeros(n_panels, 3)
208199
relative_velocity_array = similar(va_array)
209200
relative_velocity_crossz = similar(relative_velocity_array)
210201
Uinfcrossz_array = similar(va_array)
211202
cl_array = zeros(n_panels)
212203
damp = zeros(length(gamma))
213204
v_normal_array = zeros(n_panels)
214205
v_tangential_array = zeros(n_panels)
206+
207+
AIC_x, AIC_y, AIC_z = @views wing_aero.AIC[1, :, :], wing_aero.AIC[2, :, :], wing_aero.AIC[3, :, :]
215208

216209
iters = 0
217210
for i in 1:solver.max_iterations

src/wing_aerodynamics.jl

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ mutable struct WingAerodynamics
1616

1717
alpha_array::Vector{Float64}
1818
v_a_array::Vector{Float64}
19-
work_vectors::NTuple{10,Vector{Float64}}
19+
work_vectors::NTuple{10,MVec3}
20+
AIC::Array{Float64, 3}
2021

2122
function WingAerodynamics(
2223
wings::Vector{T};
@@ -60,7 +61,8 @@ mutable struct WingAerodynamics
6061
alpha_array = zeros(n_panels)
6162
v_a_array = zeros(n_panels)
6263
work_vectors = ntuple(_ -> Vector{Float64}(undef, 3), 10)
63-
64+
AIC = zeros(3, n_panels, n_panels)
65+
6466
new(
6567
panels,
6668
n_panels,
@@ -72,7 +74,8 @@ mutable struct WingAerodynamics
7274
stall_angle_list,
7375
alpha_array,
7476
v_a_array,
75-
work_vectors
77+
work_vectors,
78+
AIC
7679
)
7780
end
7881
end
@@ -206,7 +209,7 @@ function calculate_panel_properties(section_list::Vector{Section}, n_panels::Int
206209
end
207210

208211
"""
209-
calculate_AIC_matrices(wa::WingAerodynamics, model::String,
212+
calculate_AIC_matrices!(wa::WingAerodynamics, model::String,
210213
core_radius_fraction::Float64,
211214
va_norm_array::Vector{Float64},
212215
va_unit_array::Matrix{Float64})
@@ -216,35 +219,41 @@ Calculate Aerodynamic Influence Coefficient matrices.
216219
Returns:
217220
Tuple of (AIC_x, AIC_y, AIC_z) matrices
218221
"""
219-
function calculate_AIC_matrices(wa::WingAerodynamics, model::String,
220-
core_radius_fraction::Float64,
221-
va_norm_array::Vector{Float64},
222-
va_unit_array::Matrix{Float64})
222+
function calculate_AIC_matrices!(wa::WingAerodynamics, model,
223+
core_radius_fraction,
224+
va_norm_array,
225+
va_unit_array)
223226
model in ["VSM", "LLT"] || throw(ArgumentError("Model must be VSM or LLT"))
224-
225227
# Determine evaluation point based on model
226228
evaluation_point = model == "VSM" ? :control_point : :aerodynamic_center
227229
evaluation_point_on_bound = model == "LLT"
228230

229231
# Initialize AIC matrices
230-
AIC = zeros(3, wa.n_panels, wa.n_panels)
232+
AIC = @views wa.AIC
233+
velocity_induced, tempvel, va_unit = zeros(MVec3), zeros(MVec3), zeros(MVec3)
231234

232235
# Calculate influence coefficients
233236
for icp in 1:wa.n_panels
234237
ep = getproperty(wa.panels[icp], evaluation_point)
235238
for jring in 1:wa.n_panels
236-
velocity_induced = calculate_velocity_induced_single_ring_semiinfinite(
239+
velocity_induced .= 0.0
240+
tempvel .= 0.0
241+
va_unit .= @views va_unit_array[jring, :]
242+
wa.panels[jring]
243+
calculate_velocity_induced_single_ring_semiinfinite!(
244+
velocity_induced,
245+
tempvel,
237246
wa.panels[jring],
238247
ep,
239248
evaluation_point_on_bound,
240249
va_norm_array[jring],
241-
va_unit_array[jring, :],
250+
va_unit,
242251
1.0,
243252
core_radius_fraction,
244253
wa.work_vectors
245254
)
246255

247-
AIC[:, icp, jring] = velocity_induced
256+
AIC[:, icp, jring] .= velocity_induced
248257

249258
# Subtract 2D induced velocity for VSM
250259
if icp == jring && model == "VSM"
@@ -253,8 +262,7 @@ function calculate_AIC_matrices(wa::WingAerodynamics, model::String,
253262
end
254263
end
255264
end
256-
257-
return AIC[1, :, :], AIC[2, :, :], AIC[3, :, :]
265+
return nothing
258266
end
259267

260268
"""
@@ -352,9 +360,10 @@ function update_effective_angle_of_attack_if_VSM(wa::WingAerodynamics,
352360
va_unit_array::Matrix{Float64})
353361

354362
# Calculate AIC matrices at aerodynamic center using LLT method
355-
AIC_x, AIC_y, AIC_z = calculate_AIC_matrices(
363+
calculate_AIC_matrices!(
356364
wa, "LLT", core_radius_fraction, va_norm_array, va_unit_array
357365
)
366+
AIC_x, AIC_y, AIC_z = @views wa.AIC[1, :, :], wa.AIC[2, :, :], wa.AIC[3, :, :]
358367

359368
# Calculate induced velocities
360369
induced_velocity = [

test/bench.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BenchmarkTools
22
using VortexStepMethod
3-
using VortexStepMethod: calculate_AIC_matrices, gamma_loop, calculate_results,
3+
using VortexStepMethod: calculate_AIC_matrices!, gamma_loop, calculate_results,
44
update_effective_angle_of_attack_if_VSM, calculate_projected_area,
55
calculate_cl, calculate_cd_cm,
66
calculate_velocity_induced_single_ring_semiinfinite,
@@ -60,7 +60,7 @@ using LinearAlgebra
6060
for model in models
6161
for frac in core_radius_fractions
6262
@testset "Model $model Core Radius Fraction $frac" begin
63-
result = @benchmark calculate_AIC_matrices($wing_aero, $model, $frac, $va_norm_array, $va_unit_array)
63+
result = @benchmark calculate_AIC_matrices!($wing_aero, $model, $frac, $va_norm_array, $va_unit_array)
6464
@test result.allocs 100 # Allow some allocations for matrix setup
6565
end
6666
end

test/test_wing_aerodynamics.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# using VortexStepMethod: Wing, WingAerodynamics, BoundFilament, SemiInfiniteFilament, add_section!, set_va!, solve, calculate_cl
22
using VortexStepMethod
3-
using VortexStepMethod: calculate_cl, calculate_cd_cm, calculate_projected_area, calculate_AIC_matrices
3+
using VortexStepMethod: calculate_cl, calculate_cd_cm, calculate_projected_area, calculate_AIC_matrices!
44
using LinearAlgebra
55
using Test
66
using Logging
@@ -159,13 +159,14 @@ end
159159
# Calculate new matrices
160160
va_norm_array = fill(norm(Uinf), length(coord))
161161
va_unit_array = repeat(reshape(Uinf ./ norm(Uinf), 1, 3), length(coord))
162-
AIC_x, AIC_y, AIC_z = calculate_AIC_matrices(
162+
calculate_AIC_matrices!(
163163
wing_aero,
164164
"LLT",
165165
core_radius_fraction,
166166
va_norm_array,
167167
va_unit_array
168168
)
169+
AIC_x, AIC_y, AIC_z = @views wing_aero.AIC[1, :, :], wing_aero.AIC[2, :, :], wing_aero.AIC[3, :, :]
169170

170171
# Compare matrices
171172
@test isapprox(MatrixU, AIC_x, atol=1e-5)

0 commit comments

Comments
 (0)