Skip to content

Commit e104242

Browse files
committed
Now 328 allocations
1 parent 98a7336 commit e104242

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/body_aerodynamics.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,17 +450,35 @@ function update_effective_angle_of_attack!(alpha_corrected,
450450
# induced_velocity[:, 2] .= AIC_y * gamma
451451
# induced_velocity[:, 3] .= AIC_z * gamma
452452

453-
# Get views of AIC matrices without copying
454-
AIC_views = (@view(body_aero.AIC[1, :, :]),
455-
@view(body_aero.AIC[2, :, :]),
456-
@view(body_aero.AIC[3, :, :]))
453+
# # Get views of AIC matrices without copying
454+
# AIC_views = (@view(body_aero.AIC[1, :, :]),
455+
# @view(body_aero.AIC[2, :, :]),
456+
# @view(body_aero.AIC[3, :, :]))
457+
458+
# # Preallocate induced velocity array
459+
# induced_velocity = cache_body[1][va_array]
460+
461+
# # Calculate induced velocity components in-place
462+
# for (j, aic) in enumerate(AIC_views) # 384 allocated
463+
# mul!(@view(induced_velocity[:, j]), aic, gamma)
464+
# end
465+
466+
# Get dimensions from existing data
467+
n_rows = size(body_aero.AIC, 2)
468+
n_cols = size(body_aero.AIC, 3)
457469

458470
# Preallocate induced velocity array
459471
induced_velocity = cache_body[1][va_array]
460472

461-
# Calculate induced velocity components in-place
462-
for (j, aic) in enumerate(AIC_views) # 384 allocated
463-
mul!(@view(induced_velocity[:, j]), aic, gamma)
473+
# Calculate each component with explicit loops
474+
for j in 1:3 # For each x/y/z component
475+
for i in 1:n_rows
476+
acc = zero(eltype(induced_velocity)) # Type-stable accumulator
477+
for k in 1:n_cols
478+
acc += body_aero.AIC[j, i, k] * gamma[k]
479+
end
480+
induced_velocity[i, j] = acc
481+
end
464482
end
465483

466484
# In-place relative velocity calculation

test/bench2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ println("Rectangular wing, solve_base!:")
4848
# time Python: 32.0 ms Ryzen 7950x
4949
# time Julia: 0.48 ms laptop, performance mode, grid
5050
println("Rectangular wing, solve!:")
51-
@btime sol = solve!($vsm_solver, $wa, nothing) # 337 allocations
51+
@btime sol = solve!($vsm_solver, $wa, nothing) # 328 allocations
5252
nothing

0 commit comments

Comments
 (0)