Skip to content

Commit f992279

Browse files
committed
Remove duplicate code
1 parent 475b48e commit f992279

1 file changed

Lines changed: 37 additions & 33 deletions

File tree

src/wing_geometry.jl

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,40 @@ end
665665
return all(_has_initialized_section_aero_data, wing.refined_sections)
666666
end
667667

668+
"""
669+
copy_sections_to_refined!(wing; reuse_aero_data=false)
670+
671+
Copy unrefined sections to refined sections 1:1 (no interpolation).
672+
If `refined_sections` is empty, allocates via `copy`; otherwise
673+
reinitialises in-place. Warns if billowing was requested but there
674+
are no intermediate sections to billow.
675+
"""
676+
function copy_sections_to_refined!(
677+
wing::AbstractWing; reuse_aero_data::Bool=false
678+
)
679+
if wing.spanwise_distribution == BILLOWING &&
680+
wing.billowing_percentage > 0
681+
@warn "Billowing requested but n_panels " *
682+
"($(wing.n_panels)) == n_provided; no " *
683+
"intermediate sections to billow. " *
684+
"Increase n_panels."
685+
end
686+
if length(wing.refined_sections) == 0
687+
wing.refined_sections = copy(wing.unrefined_sections)
688+
else
689+
for (refined, unrefined) in zip(
690+
wing.refined_sections, wing.unrefined_sections)
691+
if reuse_aero_data
692+
reinit!(refined, unrefined.LE_point,
693+
unrefined.TE_point, unrefined.aero_model)
694+
else
695+
reinit!(refined, unrefined)
696+
end
697+
end
698+
end
699+
return nothing
700+
end
701+
668702
"""
669703
refine!(wing::AbstractWing; recompute_mapping=true, sort_sections=true)
670704
@@ -728,14 +762,7 @@ function refine!(wing::AbstractWing; recompute_mapping=true, sort_sections=true)
728762
if length(wing.refined_sections) == 0
729763
if wing.spanwise_distribution == UNCHANGED ||
730764
length(wing.unrefined_sections) == n_sections
731-
if wing.spanwise_distribution == BILLOWING &&
732-
wing.billowing_percentage > 0
733-
@warn "Billowing requested but n_panels " *
734-
"($(wing.n_panels)) == n_provided; no " *
735-
"intermediate sections to billow. " *
736-
"Increase n_panels."
737-
end
738-
wing.refined_sections = copy(wing.unrefined_sections)
765+
copy_sections_to_refined!(wing; reuse_aero_data)
739766
recompute_mapping && compute_refined_panel_mapping!(wing)
740767
update_non_deformed_sections!(wing)
741768
return nothing
@@ -765,22 +792,7 @@ function refine!(wing::AbstractWing; recompute_mapping=true, sort_sections=true)
765792

766793
# Handle special cases
767794
if wing.spanwise_distribution == UNCHANGED || length(wing.unrefined_sections) == n_sections
768-
for i in eachindex(wing.unrefined_sections)
769-
if reuse_aero_data
770-
section = wing.unrefined_sections[i]
771-
reinit!(
772-
wing.refined_sections[i],
773-
section.LE_point,
774-
section.TE_point,
775-
section.aero_model
776-
)
777-
else
778-
reinit!(wing.refined_sections[i], wing.unrefined_sections[i])
779-
end
780-
end
781-
if wing.spanwise_distribution == BILLOWING && wing.billowing_percentage > 0
782-
@warn "Billowing requested but n_panels ($(wing.n_panels)) == n_provided; no intermediate sections to billow. Increase n_panels."
783-
end
795+
copy_sections_to_refined!(wing; reuse_aero_data)
784796
recompute_mapping && compute_refined_panel_mapping!(wing)
785797
update_non_deformed_sections!(wing)
786798
return nothing
@@ -1146,15 +1158,7 @@ function refine_mesh_by_splitting_provided_sections!(
11461158

11471159
# Check if refinement is needed
11481160
if n_panels_provided == n_panels_desired
1149-
for (refined_section, section) in zip(
1150-
wing.refined_sections, wing.unrefined_sections)
1151-
if reuse_aero_data
1152-
reinit!(refined_section, section.LE_point,
1153-
section.TE_point, section.aero_model)
1154-
else
1155-
reinit!(refined_section, section)
1156-
end
1157-
end
1161+
copy_sections_to_refined!(wing; reuse_aero_data)
11581162
return nothing
11591163
end
11601164

0 commit comments

Comments
 (0)