@@ -8,16 +8,19 @@ Represents a wing section with leading edge, trailing edge, and aerodynamic prop
88- `LE_point::Vector{Float64}`: Leading edge point coordinates
99- `TE_point::Vector{Float64}`: Trailing edge point coordinates
1010- `aero_input::Vector{Any}`: Aerodynamic input data for the section:
11- - `[ "inviscid"] `: Inviscid aerodynamics
12- - `[ "polar_data", [alpha,CL,CD,CM]] `: Polar data aerodynamics
13- - `[ "lei_airfoil_breukels", [d_tube,camber]] `: LEI airfoil with Breukels parameters
11+ - `( "inviscid") `: Inviscid aerodynamics
12+ - `( "polar_data", [alpha_column,CL_column,CD_column,CM_column]) `: Polar data aerodynamics
13+ - `( "lei_airfoil_breukels", [d_tube,camber]) `: LEI airfoil with Breukels parameters
1414"""
1515struct Section
1616 LE_point:: Vector{Float64}
1717 TE_point:: Vector{Float64}
18- aero_input:: Union{String, Tuple{String, Vector{Float64}}}
18+ aero_input:: Union{String, Tuple{String, Vector{Float64}}, Tuple{String, Matrix{Float64}} }
1919
20- function Section (LE_point:: Vector{Float64} , TE_point:: Vector{Float64} , aero_input:: Union{String, Tuple{String, Vector{Float64}}} )
20+ function Section (
21+ LE_point:: Vector{Float64} ,
22+ TE_point:: Vector{Float64} ,
23+ aero_input:: Union{String, Tuple{String, Vector{Float64}}, Tuple{String, Matrix{Float64}}} )
2124 new (LE_point, TE_point, aero_input)
2225 end
2326
@@ -45,7 +48,7 @@ Represents a wing composed of multiple sections with aerodynamic properties.
4548- "split_provided": Split provided sections
4649- "unchanged": Keep original sections
4750"""
48- mutable struct Wing
51+ mutable struct Wing <: AbstractWing
4952 n_panels:: Int
5053 spanwise_panel_distribution:: String
5154 spanwise_direction:: Vector{Float64}
6871Add a new section to the wing.
6972"""
7073function add_section! (wing:: Wing , LE_point:: Vector{Float64} ,
71- TE_point:: Vector{Float64} , aero_input:: Union{String, Tuple{String, Vector{Float64}}} )
74+ TE_point:: Vector{Float64} , aero_input)
7275 push! (wing. sections, Section (LE_point, TE_point, aero_input))
7376end
7477
9295
9396
9497"""
95- refine_aerodynamic_mesh(wing::Wing )
98+ refine_aerodynamic_mesh(wing::AbstractWing )
9699
97100Refine the aerodynamic mesh of the wing based on spanwise panel distribution.
98101
99102Returns:
100103 Vector{Section}: List of refined sections
101104"""
102- function refine_aerodynamic_mesh (wing:: Wing )
105+ function refine_aerodynamic_mesh (wing:: AbstractWing )
103106 # Sort sections from left to right
104107 sort! (wing. sections, by= s -> s. LE_point[2 ], rev= true )
105108
@@ -163,14 +166,22 @@ end
163166
164167Interpolate aerodynamic coefficients to a common alpha range.
165168"""
166- function interpolate_to_common_alpha (alpha_common:: Vector{Float64} ,
167- alpha_orig:: Vector{Float64} ,
168- CL_orig:: Vector{Float64} ,
169- CD_orig:: Vector{Float64} ,
170- CM_orig:: Vector{Float64} )
171- CL_common = interpolate (alpha_orig, CL_orig, alpha_common)
172- CD_common = interpolate (alpha_orig, CD_orig, alpha_common)
173- CM_common = interpolate (alpha_orig, CM_orig, alpha_common)
169+ function interpolate_to_common_alpha (alpha_common,
170+ alpha_orig,
171+ CL_orig,
172+ CD_orig,
173+ CM_orig)
174+
175+ # Create interpolation objects
176+ itp_CL = linear_interpolation (alpha_orig, CL_orig)
177+ itp_CD = linear_interpolation (alpha_orig, CD_orig)
178+ itp_CM = linear_interpolation (alpha_orig, CM_orig)
179+
180+ # Evaluate at common alpha points
181+ CL_common = itp_CL .(alpha_common)
182+ CD_common = itp_CD .(alpha_common)
183+ CM_common = itp_CM .(alpha_common)
184+
174185 return CL_common, CD_common, CM_common
175186end
176187
182193
183194Interpolate aerodynamic input between two sections.
184195"""
185- function calculate_new_aero_input (aero_input:: Union {Vector{String}, Vector{Tuple{String, Vector{Float64}}}} ,
196+ function calculate_new_aero_input (aero_input,
186197 section_index:: Int ,
187198 left_weight:: Float64 ,
188199 right_weight:: Float64 )
@@ -201,8 +212,14 @@ function calculate_new_aero_input(aero_input::Union{Vector{String}, Vector{Tuple
201212 polar_right = aero_input[section_index + 1 ][2 ]
202213
203214 # Unpack polar data
204- alpha_left, CL_left, CD_left, CM_left = polar_left
205- alpha_right, CL_right, CD_right, CM_right = polar_right
215+ @views begin
216+ alpha_left, CL_left, CD_left, CM_left = (
217+ polar_left[:, i] for i in 1 : 4
218+ )
219+ alpha_right, CL_right, CD_right, CM_right = (
220+ polar_right[:, i] for i in 1 : 4
221+ )
222+ end
206223
207224 # Create common alpha array
208225 alpha_common = sort (unique (vcat (alpha_left, alpha_right)))
@@ -220,7 +237,7 @@ function calculate_new_aero_input(aero_input::Union{Vector{String}, Vector{Tuple
220237 CD_interp = CD_left_common .* left_weight .+ CD_right_common .* right_weight
221238 CM_interp = CM_left_common .* left_weight .+ CM_right_common .* right_weight
222239
223- return (" polar_data" , [ alpha_common, CL_interp, CD_interp , CM_interp] )
240+ return (" polar_data" , hcat ( alpha_common, CD_interp, CL_interp , CM_interp) )
224241
225242 elseif model_type == " lei_airfoil_breukels"
226243 tube_diameter_left = aero_input[section_index][2 ][1 ]
@@ -263,9 +280,9 @@ Returns:
263280function refine_mesh_for_linear_cosine_distribution (
264281 spanwise_panel_distribution:: String ,
265282 n_sections:: Int ,
266- LE:: Union{Matrix{Float64}, Adjoint{Float64, Matrix{Float64}}} ,
267- TE:: Union{Matrix{Float64}, Adjoint{Float64, Matrix{Float64}}} ,
268- aero_input:: Union {Vector{String}, Vector{Tuple{String, Vector{Float64}}}} )
283+ LE,
284+ TE,
285+ aero_input)
269286
270287 # 1. Compute quarter chord line
271288 quarter_chord = LE .+ 0.25 .* (TE .- LE)
@@ -408,14 +425,14 @@ end
408425
409426
410427"""
411- refine_mesh_by_splitting_provided_sections(wing::Wing )
428+ refine_mesh_by_splitting_provided_sections(wing::AbstractWing )
412429
413430Refine mesh by splitting provided sections into desired number of panels.
414431
415432Returns:
416433 Vector{Section}: Refined sections
417434"""
418- function refine_mesh_by_splitting_provided_sections (wing:: Wing )
435+ function refine_mesh_by_splitting_provided_sections (wing:: AbstractWing )
419436 n_sections_provided = length (wing. sections)
420437 n_panels_provided = n_sections_provided - 1
421438 n_panels_desired = wing. n_panels
@@ -491,14 +508,14 @@ function refine_mesh_by_splitting_provided_sections(wing::Wing)
491508end
492509
493510"""
494- calculate_span(wing::Wing )
511+ calculate_span(wing::AbstractWing )
495512
496513Calculate wing span along spanwise direction.
497514
498515Returns:
499516 Float64: Wing span
500517"""
501- function calculate_span (wing:: Wing )
518+ function calculate_span (wing:: AbstractWing )
502519 # Normalize spanwise direction
503520 vector_axis = wing. spanwise_direction ./ norm (wing. spanwise_direction)
504521
@@ -512,14 +529,14 @@ function calculate_span(wing::Wing)
512529end
513530
514531"""
515- calculate_projected_area(wing::Wing , z_plane_vector::Vector{Float64}=[0.0, 0.0, 1.0])
532+ calculate_projected_area(wing::AbstractWing , z_plane_vector::Vector{Float64}=[0.0, 0.0, 1.0])
516533
517534Calculate projected wing area onto plane defined by normal vector.
518535
519536Returns:
520537 Float64: Projected area
521538"""
522- function calculate_projected_area (wing:: Wing ,
539+ function calculate_projected_area (wing:: AbstractWing ,
523540 z_plane_vector:: Vector{Float64} = [0.0 , 0.0 , 1.0 ])
524541 # Normalize plane normal vector
525542 z_plane_vector = z_plane_vector ./ norm (z_plane_vector)
@@ -557,8 +574,8 @@ function calculate_projected_area(wing::Wing,
557574end
558575
559576# Add span property to Wing struct
560- Base. propertynames (w:: Wing ) = (fieldnames (typeof (w))... , :span )
561- function Base. getproperty (w:: Wing , s:: Symbol )
577+ Base. propertynames (w:: AbstractWing ) = (fieldnames (typeof (w))... , :span )
578+ function Base. getproperty (w:: AbstractWing , s:: Symbol )
562579 if s === :span
563580 return calculate_span (w)
564581 else
0 commit comments