Skip to content

Commit c312ff5

Browse files
committed
Non-allocating init pos
1 parent d449398 commit c312ff5

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

examples/ram_air_kite.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ DEFORM = true
99
# Create wing geometry
1010
wing = RamAirWing("data/ram_air_kite_body.obj", "data/ram_air_kite_foil.dat")
1111
body_aero = BodyAerodynamics([wing];)
12+
println("First init")
13+
@time VortexStepMethod.init!(body_aero)
1214

1315
if DEFORM
1416
# Linear interpolation of alpha from 10° at one tip to 0° at the other
@@ -19,8 +21,10 @@ if DEFORM
1921
delta_end = deg2rad(0)
2022
theta_dist = [theta_start - i * (theta_start - theta_end)/(n_panels-1) for i in 0:(n_panels-1)]
2123
delta_dist = [delta_start - i * (delta_start - delta_end)/(n_panels-1) for i in 0:(n_panels-1)]
24+
println("Deform")
2225
@time VortexStepMethod.deform!(wing, theta_dist, delta_dist)
23-
@time VortexStepMethod.init!(body_aero)
26+
println("Deform init")
27+
@time VortexStepMethod.init!(body_aero; init_aero=false)
2428
end
2529

2630
# Create solvers

src/body_aerodynamics.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ Initialize a BodyAerodynamics struct in-place by setting up panels and coefficie
8989
# Arguments
9090
- `body_aero::BodyAerodynamics`: The structure to initialize
9191
92+
# Keyword Arguments
93+
- `init_aero::Bool`: Wether to initialize the aero data or not
94+
9295
# Returns
9396
nothing
9497
"""
95-
function init!(body_aero::BodyAerodynamics)
96-
98+
function init!(body_aero::BodyAerodynamics; init_aero=true)
9799
idx = 1
100+
vec = zeros(MVec3)
98101
for wing in body_aero.wings
99-
println("init wing")
100102
init!(wing)
101103
panel_props = wing.panel_props
102104

@@ -118,8 +120,10 @@ function init!(body_aero::BodyAerodynamics)
118120
panel_props.x_airf[i, :],
119121
panel_props.y_airf[i, :],
120122
panel_props.z_airf[i, :],
121-
delta;
122-
remove_nan=wing.remove_nan
123+
delta,
124+
vec;
125+
remove_nan=wing.remove_nan,
126+
init_aero
123127
)
124128
idx += 1
125129
end

src/filament.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ 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)
31+
function init!(filament::BoundFilament, x1::PosVector, x2::PosVector, vec=zeros(MVec3))
3232
filament.x1 .= x1
3333
filament.x2 .= x2
34-
filament.length = norm(x2 - x1)
34+
vec .= x2 .- x1
35+
filament.length = norm(vec)
3536
filament.r0 .= x2 .- x1
3637
filament.initialized = true
3738
return nothing

src/panel.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ function init_pos!(
8484
x_airf::PosVector,
8585
y_airf::PosVector,
8686
z_airf::PosVector,
87-
delta
87+
delta,
88+
vec::MVec3
8889
)
8990
# Initialize basic geometry
9091
panel.TE_point_1 .= section_1.TE_point
@@ -95,11 +96,15 @@ function init_pos!(
9596
norm(panel.TE_point_1 - panel.LE_point_1) +
9697
norm(panel.TE_point_2 - panel.LE_point_2)
9798
) / 2
98-
panel.corner_points .= hcat(panel.LE_point_1, panel.TE_point_1, panel.TE_point_2, panel.LE_point_2)
99-
panel.width = norm(bound_point_2 - bound_point_1)
100-
init!(panel.filaments[1], bound_point_2, bound_point_1)
101-
init!(panel.filaments[2], bound_point_1, panel.TE_point_1)
102-
init!(panel.filaments[3], panel.TE_point_2, bound_point_2)
99+
panel.corner_points[:, 1] = panel.LE_point_1
100+
panel.corner_points[:, 2] = panel.TE_point_1
101+
panel.corner_points[:, 3] = panel.TE_point_2
102+
panel.corner_points[:, 4] = panel.LE_point_2
103+
vec .= bound_point_2 .- bound_point_1
104+
panel.width = norm(vec)
105+
init!(panel.filaments[1], bound_point_2, bound_point_1, vec)
106+
init!(panel.filaments[2], bound_point_1, panel.TE_point_1, vec)
107+
init!(panel.filaments[3], panel.TE_point_2, bound_point_2, vec)
103108

104109
panel.bound_point_1 .= bound_point_1
105110
panel.bound_point_2 .= bound_point_2
@@ -190,12 +195,13 @@ function init!(
190195
x_airf::PosVector,
191196
y_airf::PosVector,
192197
z_airf::PosVector,
193-
delta;
198+
delta,
199+
vec::MVec3;
194200
init_aero = true,
195201
remove_nan = true
196202
)
197-
init_pos!(panel, section_1, section_2, aero_center, control_point, bound_point_1, bound_point_2,
198-
x_airf, y_airf, z_airf, delta)
203+
@time init_pos!(panel, section_1, section_2, aero_center, control_point, bound_point_1, bound_point_2,
204+
x_airf, y_airf, z_airf, delta, vec)
199205
init_aero && init_aero!(panel, section_1, section_2; remove_nan)
200206
return nothing
201207
end

src/wing_geometry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function init!(wing::AbstractWing)
233233
refine_aerodynamic_mesh!(wing)
234234

235235
# Calculate panel properties
236-
@time update_panel_properties!(
236+
update_panel_properties!(
237237
wing.panel_props,
238238
wing.refined_sections,
239239
wing.n_panels

0 commit comments

Comments
 (0)