Skip to content

Commit 9d6e138

Browse files
committed
Add reinit allocation tests
1 parent c7d1bba commit 9d6e138

File tree

4 files changed

+22
-108
lines changed

4 files changed

+22
-108
lines changed

src/body_aerodynamics.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ nothing
113113
function init!(body_aero::BodyAerodynamics; init_aero=true)
114114
idx = 1
115115
vec = zeros(MVec3)
116-
@time for wing in body_aero.wings
116+
for wing in body_aero.wings
117117
init!(wing)
118118
panel_props = wing.panel_props
119119

@@ -145,11 +145,11 @@ function init!(body_aero::BodyAerodynamics; init_aero=true)
145145
end
146146

147147
# Initialize rest of the struct
148-
@time body_aero.projected_area = sum(wing -> calculate_projected_area(wing), body_aero.wings)
149-
@time body_aero.stall_angle_list .= calculate_stall_angle_list(body_aero.panels)
150-
@time body_aero.alpha_array .= 0.0
151-
@time body_aero.v_a_array .= 0.0
152-
@time body_aero.AIC .= 0.0
148+
body_aero.projected_area = sum(wing -> calculate_projected_area(wing), body_aero.wings)
149+
body_aero.stall_angle_list .= calculate_stall_angle_list(body_aero.panels)
150+
body_aero.alpha_array .= 0.0
151+
body_aero.v_a_array .= 0.0
152+
body_aero.AIC .= 0.0
153153
return nothing
154154
end
155155

src/wing_geometry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function init!(refined_section::Section, section::Section)
5353
refined_section.aero_data = section.aero_data
5454
else
5555
for i in eachindex(section.aero_data)
56-
refined_section.aero_data[i] .= section.aero_data[i]
56+
copyto!(refined_section.aero_data[i], section.aero_data[i])
5757
end
5858
end
5959
end

test/bench.jl

Lines changed: 13 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ using VortexStepMethod: calculate_AIC_matrices!, gamma_loop!, calculate_results,
1414
velocity_3D_bound_vortex!,
1515
velocity_3D_trailing_vortex!,
1616
velocity_3D_trailing_vortex_semiinfinite!,
17-
Panel
17+
Panel,
18+
init!
1819
using Test
1920
using LinearAlgebra
2021

@@ -39,6 +40,13 @@ using LinearAlgebra
3940
INVISCID)
4041

4142
body_aero = BodyAerodynamics([wing])
43+
init!(body_aero)
44+
45+
@testset "Re-initialization" begin
46+
result = @benchmark init!(body_aero; init_aero=false) samples=1 evals=1
47+
@info "Re-initializing Allocations: $(result.allocs) \t Memory: $(result.memory)"
48+
@test result.allocs < 100
49+
end
4250

4351
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
4452
set_va!(body_aero, vel_app)
@@ -66,7 +74,7 @@ using LinearAlgebra
6674
for model in models
6775
for frac in core_radius_fractions
6876
@testset "Model $model Core Radius Fraction $frac" begin
69-
result = @benchmark calculate_AIC_matrices!($body_aero, $model, $frac, $va_norm_array, $va_unit_array) samples = 1 evals = 1
77+
result = @benchmark calculate_AIC_matrices!($body_aero, $model, $frac, $va_norm_array, $va_unit_array) samples=1 evals=1
7078
@test result.allocs 100
7179
@info "Model: $(model) \t Core radius fraction: $(frac) \t Allocations: $(result.allocs) \t Memory: $(result.memory)"
7280
end
@@ -129,7 +137,7 @@ using LinearAlgebra
129137
$body_aero.panels,
130138
0.5;
131139
log = false
132-
) samples = 1 evals = 1
140+
) samples=1 evals=1
133141
@test result.allocs 10
134142
@info "Model: $model \t Aero_model: $aero_model \t Allocations: $(result.allocs) Memory: $(result.memory)"
135143
end
@@ -180,103 +188,8 @@ using LinearAlgebra
180188
$va_unit_array,
181189
$body_aero.panels,
182190
false
183-
) samples = 1 evals = 1
184-
@test_broken result.allocs 100
191+
) samples=1 evals=1
192+
@test result.allocs 300
185193
end
186-
187-
188-
# TODO: implement the rest of the benchmarks
189-
# @testset "Angle of Attack Update" begin
190-
# alpha_array = zeros(n_panels)
191-
# result = @benchmark update_effective_angle_of_attack_if_VSM(
192-
# $alpha_array,
193-
# $body_aero,
194-
# $gamma
195-
# ) samples = 1 evals = 1
196-
# @test result.allocs == 0
197-
# end
198-
199-
# @testset "Area Calculations" begin
200-
# area = @MVector zeros(3)
201-
# result = @benchmark calculate_projected_area(
202-
# $area,
203-
# $body_aero
204-
# ) samples = 1 evals = 1
205-
# @test result.allocs == 0
206-
# end
207-
208-
# @testset "Aerodynamic Coefficients" begin
209-
# panel = body_aero.panels[1]
210-
# alpha = 0.1
211-
212-
# result = @benchmark calculate_cl($panel, $alpha) samples = 1 evals = 1
213-
# @test result.allocs == 0
214-
215-
# cd_cm = @MVector zeros(2)
216-
# result = @benchmark calculate_cd_cm($cd_cm, $panel, $alpha) samples = 1 evals = 1
217-
# @test result.allocs == 0
218-
# end
219-
220-
# @testset "Induced Velocity Calculations" begin
221-
# v_ind = @MVector zeros(3)
222-
# point = @MVector [0.25, 9.5, 0.0]
223-
# work_vectors = ntuple(_ -> @MVector(zeros(3)), 10)
224-
225-
# # Test single ring velocity calculation
226-
# result = @benchmark calculate_velocity_induced_single_ring_semiinfinite!(
227-
# $v_ind,
228-
# $(work_vectors[1]),
229-
# $panel.filaments,
230-
# $point,
231-
# true,
232-
# 20.0,
233-
# $(work_vectors[2]),
234-
# 1.0,
235-
# 1e-20,
236-
# $work_vectors
237-
# ) samples = 1 evals = 1
238-
# @test result.allocs == 0
239-
240-
# # Test 2D bound vortex
241-
# result = @benchmark calculate_velocity_induced_bound_2D!(
242-
# $v_ind,
243-
# $panel,
244-
# $point,
245-
# $work_vectors
246-
# ) samples = 1 evals = 1
247-
# @test result.allocs == 0
248-
249-
# # Test 3D velocity components
250-
# result = @benchmark velocity_3D_bound_vortex!(
251-
# $v_ind,
252-
# $point,
253-
# $panel,
254-
# 1.0,
255-
# 1e-20,
256-
# $work_vectors
257-
# ) samples = 1 evals = 1
258-
# @test result.allocs == 0
259-
260-
# result = @benchmark velocity_3D_trailing_vortex!(
261-
# $v_ind,
262-
# $point,
263-
# $panel,
264-
# 1.0,
265-
# 20.0,
266-
# $work_vectors
267-
# ) samples = 1 evals = 1
268-
# @test result.allocs == 0
269-
270-
# result = @benchmark velocity_3D_trailing_vortex_semiinfinite!(
271-
# $v_ind,
272-
# $point,
273-
# $panel,
274-
# 1.0,
275-
# 20.0,
276-
# $(work_vectors[2]),
277-
# $work_vectors
278-
# ) samples = 1 evals = 1
279-
# @test result.allocs == 0
280-
# end
281194
end
282195

test/test_panel.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ function create_panel(section1::Section, section2::Section)
4747
x_airf,
4848
y_airf,
4949
z_airf,
50-
0.0
50+
0.0,
51+
zeros(MVec3)
5152
)
5253
return panel
5354
end

0 commit comments

Comments
 (0)