Skip to content

Commit 3502599

Browse files
committed
Add kwarg to sort sections
1 parent a6a8337 commit 3502599

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/body_aerodynamics.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function Base.setproperty!(obj::BodyAerodynamics, sym::Symbol, val)
114114
end
115115

116116
"""
117-
reinit!(body_aero::BodyAerodynamics; init_aero, va, omega, refine_mesh, recompute_mapping)
117+
reinit!(body_aero::BodyAerodynamics; init_aero, va, omega, refine_mesh, recompute_mapping, sort_sections)
118118
119119
Initialize a BodyAerodynamics struct in-place by setting up panels and coefficients.
120120
@@ -129,6 +129,8 @@ Initialize a BodyAerodynamics struct in-place by setting up panels and coefficie
129129
`deform!()` to preserve deformed geometry.
130130
- `recompute_mapping=true`: Whether to recompute the refined panel mapping.
131131
Set to `false` to skip mapping computation when it hasn't changed.
132+
- `sort_sections=true`: Whether to sort sections by spanwise position.
133+
Set to `false` for REFINE wings where section order is determined by structural connectivity.
132134
133135
# Returns
134136
nothing
@@ -138,12 +140,13 @@ function reinit!(body_aero::BodyAerodynamics;
138140
va=[15.0, 0.0, 0.0],
139141
omega=zeros(MVec3),
140142
refine_mesh=true,
141-
recompute_mapping=true
143+
recompute_mapping=true,
144+
sort_sections=true
142145
)
143146
idx = 1
144147
vec = @MVector zeros(3)
145148
for wing in body_aero.wings
146-
reinit!(wing; refine_mesh, recompute_mapping)
149+
reinit!(wing; refine_mesh, recompute_mapping, sort_sections)
147150
panel_props = wing.panel_props
148151

149152
# Create panels

src/wing_geometry.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function Wing(n_panels::Int;
302302
end
303303

304304
"""
305-
reinit!(wing::AbstractWing; refine_mesh=true, recompute_mapping=true)
305+
reinit!(wing::AbstractWing; refine_mesh=true, recompute_mapping=true, sort_sections=true)
306306
307307
Reinitialize wing geometry and panel properties.
308308
@@ -311,11 +311,13 @@ Reinitialize wing geometry and panel properties.
311311
`deform!()` to preserve deformed geometry while updating panel properties.
312312
- `recompute_mapping::Bool=true`: Whether to recompute the refined panel mapping.
313313
Set to `false` to skip mapping computation when it hasn't changed.
314+
- `sort_sections::Bool=true`: Whether to sort sections by spanwise position.
315+
Set to `false` for REFINE wings where section order is determined by structural connectivity.
314316
"""
315-
function reinit!(wing::AbstractWing; refine_mesh=true, recompute_mapping=true)
317+
function reinit!(wing::AbstractWing; refine_mesh=true, recompute_mapping=true, sort_sections=true)
316318
# Refine mesh unless explicitly disabled (e.g., to preserve deformation)
317319
if refine_mesh
318-
refine_aerodynamic_mesh!(wing; recompute_mapping)
320+
refine_aerodynamic_mesh!(wing; recompute_mapping, sort_sections)
319321
end
320322

321323
# Calculate panel properties
@@ -589,19 +591,22 @@ function update_non_deformed_sections!(wing::AbstractWing)
589591
end
590592

591593
"""
592-
refine_aerodynamic_mesh!(wing::AbstractWing; recompute_mapping=true)
594+
refine_aerodynamic_mesh!(wing::AbstractWing; recompute_mapping=true, sort_sections=true)
593595
594596
Refine the aerodynamic mesh of the wing based on spanwise panel distribution.
595597
596598
# Keyword Arguments
597599
- `recompute_mapping::Bool=true`: Whether to recompute the refined panel mapping.
598600
Set to `false` to skip mapping computation when it hasn't changed.
601+
- `sort_sections::Bool=true`: Whether to sort sections by spanwise position (y-coordinate).
602+
Set to `false` for REFINE wings where section order is determined by structural connectivity.
599603
600604
Returns:
601605
Vector{Section}: List of refined sections
602606
"""
603-
function refine_aerodynamic_mesh!(wing::AbstractWing; recompute_mapping=true)
604-
sort!(wing.sections, by=s -> s.LE_point[2], rev=true)
607+
function refine_aerodynamic_mesh!(wing::AbstractWing; recompute_mapping=true, sort_sections=true)
608+
# Only sort sections if requested (skip for REFINE wings with fixed structural order)
609+
sort_sections && sort!(wing.sections, by=s -> s.LE_point[2], rev=true)
605610
n_sections = wing.n_panels + 1
606611
if length(wing.refined_sections) == 0
607612
if wing.spanwise_distribution == UNCHANGED || length(wing.sections) == n_sections

0 commit comments

Comments
 (0)