Skip to content

Commit fbafa0d

Browse files
committed
Reduce proj area allocs
1 parent c312ff5 commit fbafa0d

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

src/body_aerodynamics.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ function BodyAerodynamics(
8181
return body_aero
8282
end
8383

84+
function Base.getproperty(obj::BodyAerodynamics, sym::Symbol)
85+
if sym === :va
86+
return getfield(obj, :_va)
87+
end
88+
return getfield(obj, sym)
89+
end
90+
91+
function Base.setproperty!(obj::BodyAerodynamics, sym::Symbol, val)
92+
if sym === :va || sym === :omega
93+
set_va!(obj, val)
94+
else
95+
setfield!(obj, sym, val)
96+
end
97+
end
98+
8499
"""
85100
init!(body_aero::BodyAerodynamics)
86101
@@ -98,7 +113,7 @@ nothing
98113
function init!(body_aero::BodyAerodynamics; init_aero=true)
99114
idx = 1
100115
vec = zeros(MVec3)
101-
for wing in body_aero.wings
116+
@time for wing in body_aero.wings
102117
init!(wing)
103118
panel_props = wing.panel_props
104119

@@ -109,7 +124,7 @@ function init!(body_aero::BodyAerodynamics; init_aero=true)
109124
else
110125
delta = 0.0
111126
end
112-
init!(
127+
@views init!(
113128
body_aero.panels[idx],
114129
wing.refined_sections[i],
115130
wing.refined_sections[i+1],
@@ -130,29 +145,14 @@ function init!(body_aero::BodyAerodynamics; init_aero=true)
130145
end
131146

132147
# Initialize rest of the struct
133-
body_aero.projected_area = sum(wing -> calculate_projected_area(wing), body_aero.wings)
134-
body_aero.stall_angle_list .= calculate_stall_angle_list(body_aero.panels)
135-
body_aero.alpha_array .= 0.0
136-
body_aero.v_a_array .= 0.0
137-
body_aero.AIC .= 0.0
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
138153
return nothing
139154
end
140155

141-
function Base.getproperty(obj::BodyAerodynamics, sym::Symbol)
142-
if sym === :va
143-
return getfield(obj, :_va)
144-
end
145-
return getfield(obj, sym)
146-
end
147-
148-
function Base.setproperty!(obj::BodyAerodynamics, sym::Symbol, val)
149-
if sym === :va || sym === :omega
150-
set_va!(obj, val)
151-
else
152-
setfield!(obj, sym, val)
153-
end
154-
end
155-
156156
"""
157157
calculate_AIC_matrices!(body_aero::BodyAerodynamics, model::Model,
158158
core_radius_fraction::Float64,

src/filament.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Represents a bound vortex filament defined by two points.
2828
initialized::Bool = false
2929
end
3030

31-
function init!(filament::BoundFilament, x1::PosVector, x2::PosVector, vec=zeros(MVec3))
31+
function init!(filament::BoundFilament, x1, x2, vec=zeros(MVec3))
3232
filament.x1 .= x1
3333
filament.x2 .= x2
3434
vec .= x2 .- x1

src/panel.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ function init_pos!(
7777
panel::Panel,
7878
section_1::Section,
7979
section_2::Section,
80-
aero_center::PosVector,
81-
control_point::PosVector,
82-
bound_point_1::PosVector,
83-
bound_point_2::PosVector,
84-
x_airf::PosVector,
85-
y_airf::PosVector,
86-
z_airf::PosVector,
80+
aero_center,
81+
control_point,
82+
bound_point_1,
83+
bound_point_2,
84+
x_airf,
85+
y_airf,
86+
z_airf,
8787
delta,
8888
vec::MVec3
8989
)
@@ -188,19 +188,19 @@ function init!(
188188
panel::Panel,
189189
section_1::Section,
190190
section_2::Section,
191-
aero_center::PosVector,
192-
control_point::PosVector,
193-
bound_point_1::PosVector,
194-
bound_point_2::PosVector,
195-
x_airf::PosVector,
196-
y_airf::PosVector,
197-
z_airf::PosVector,
191+
aero_center,
192+
control_point,
193+
bound_point_1,
194+
bound_point_2,
195+
x_airf,
196+
y_airf,
197+
z_airf,
198198
delta,
199-
vec::MVec3;
199+
vec;
200200
init_aero = true,
201201
remove_nan = true
202202
)
203-
@time init_pos!(panel, section_1, section_2, aero_center, control_point, bound_point_1, bound_point_2,
203+
init_pos!(panel, section_1, section_2, aero_center, control_point, bound_point_1, bound_point_2,
204204
x_airf, y_airf, z_airf, delta, vec)
205205
init_aero && init_aero!(panel, section_1, section_2; remove_nan)
206206
return nothing

src/wing_geometry.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,11 @@ function calculate_span(wing::AbstractWing)
767767
return maximum(projections) - minimum(projections)
768768
end
769769

770+
# Project point onto plane
771+
function project_onto_plane(point::PosVector, normal::Vector{Float64})
772+
return point .- dot(point, normal) .* normal
773+
end
774+
770775
"""
771776
calculate_projected_area(wing::AbstractWing, z_plane_vector::Vector{Float64}=[0.0, 0.0, 1.0])
772777
@@ -780,11 +785,6 @@ function calculate_projected_area(wing::AbstractWing,
780785
# Normalize plane normal vector
781786
z_plane_vector = z_plane_vector ./ norm(z_plane_vector)
782787

783-
# Project point onto plane
784-
function project_onto_plane(point::PosVector, normal::Vector{Float64})
785-
return point .- dot(point, normal) .* normal
786-
end
787-
788788
# Calculate area by summing trapezoid areas
789789
projected_area = 0.0
790790
for i in 1:(length(wing.sections)-1)

0 commit comments

Comments
 (0)