1- """
2- @with_kw mutable struct AirfoilSettings
3-
4- Configuration settings for airfoils loaded from YAML files.
5-
6- This struct stores the mapping between airfoil IDs and their aerodynamic data sources,
7- typically CSV files containing polar data. It preserves the original YAML configuration
8- for reference and enables reconstruction of the wing geometry from YAML specifications.
9-
10- # Fields
11- - `airfoil_id::Int64`: Unique identifier for the airfoil section
12- - `type::String`: Type of aerodynamic data (e.g., "polars", "inviscid")
13- - `info_dict::Dict{String, Any}`: Additional configuration data, typically containing
14- file paths to CSV polar data files and other airfoil-specific parameters
15-
16- # Example
17- ```julia
18- # Typical usage when parsing YAML wing configuration
19- settings = AirfoilSettings(
20- airfoil_id = 1,
21- type = "polars",
22- info_dict = Dict("csv_file_path" => "polars/airfoil_1.csv")
23- )
24- ```
25- """
26- @with_kw mutable struct AirfoilSettings
27- airfoil_id:: Int64
28- type:: String
29- info_dict:: Dict{String, Any}
30- end
311
32- """
33- YamlWing <: AbstractWing
34-
35- A wing model created from YAML configuration files with CSV polar data.
36-
37- ## Core Features
38- - Wing geometry defined through YAML section coordinates
39- - Aerodynamic properties based on CSV polar data files
40- - Support for multiple airfoil types per wing
41- - Configurable panel distribution and geometry parameters
42-
43- ## Notable Fields
44- - `n_panels::Int16`: Number of panels in aerodynamic mesh
45- - `n_groups::Int16`: Number of control groups
46- - `spanwise_distribution::PanelDistribution`: Panel distribution type
47- - `sections::Vector{Section}`: Wing cross-sections with aerodynamic data
48- - `airfoil_settings::Vector{AirfoilSettings}`: Airfoil configuration data
49-
50- See constructor `YamlWing(yaml_path; kwargs...)` for usage details.
51- """
52- mutable struct YamlWing <: AbstractWing
53- n_panels:: Int16
54- n_groups:: Int16
55- spanwise_distribution:: PanelDistribution
56- panel_props:: PanelProperties
57- spanwise_direction:: MVec3
58- sections:: Vector{Section}
59- refined_sections:: Vector{Section}
60- remove_nan:: Bool
61-
62- # Essential YAML-specific fields
63- airfoil_settings:: Vector{AirfoilSettings}
64- end
652
663"""
674 load_polar_data(csv_file_path)
12461
12562
12663"""
127- YamlWing(yaml_path ; kwargs...)
64+ YamlWing(geometry_file ; kwargs...)
12865
12966Create a wing model from YAML configuration file with CSV polar data.
13067
@@ -135,7 +72,7 @@ This constructor builds a complete aerodynamic model by:
135724. Setting up panel distribution and geometric properties
13673
13774# Arguments
138- - `yaml_path `: Path to YAML file containing wing geometry and airfoil specifications
75+ - `geometry_file `: Path to YAML file containing wing geometry and airfoil specifications
13976
14077# Keyword Arguments
14178- `n_panels=20`: Number of aerodynamic panels across wingspan
@@ -146,7 +83,7 @@ This constructor builds a complete aerodynamic model by:
14683- `prn=true`: Print info messages during construction
14784
14885# Returns
149- A fully initialized `YamlWing ` instance ready for aerodynamic simulation.
86+ A fully initialized `Wing ` instance ready for aerodynamic simulation.
15087
15188# Example YAML format
15289```yaml
@@ -176,7 +113,7 @@ wing = YamlWing(
176113```
177114"""
178115function YamlWing (
179- yaml_path ;
116+ geometry_file ;
180117 n_panels= 20 ,
181118 n_groups= 1 ,
182119 spanwise_distribution= LINEAR,
@@ -187,27 +124,30 @@ function YamlWing(
187124 ! (n_panels % n_groups == 0 ) && throw (ArgumentError (" Number of panels should be divisible by number of groups" ))
188125 ! isapprox (spanwise_direction, [0.0 , 1.0 , 0.0 ]) && throw (ArgumentError (" Spanwise direction has to be [0.0, 1.0, 0.0], not $spanwise_direction " ))
189126
190- prn && @info " Reading YAML wing configuration from $yaml_path "
127+ prn && @info " Reading YAML wing configuration from $geometry_file "
191128
192129 # Read and parse YAML file
193- yaml_data = YAML. load_file (yaml_path )
130+ yaml_data = YAML. load_file (geometry_file )
194131
195132 # Parse airfoils and create CSV file mapping
196133 airfoil_csv_map = Dict {Int64, String} ()
197- airfoil_settings = AirfoilSettings[]
198134
199135 for row in yaml_data[" wing_airfoils" ][" data" ]
200136 airfoil_dict = Dict (zip (yaml_data[" wing_airfoils" ][" headers" ], row))
201137 airfoil_id, airfoil_type, info_dict = airfoil_dict[" airfoil_id" ], airfoil_dict[" type" ], airfoil_dict[" info_dict" ]
202138
203- push! (airfoil_settings, AirfoilSettings (airfoil_id, airfoil_type, info_dict))
204139 haskey (info_dict, " csv_file_path" ) && (airfoil_csv_map[airfoil_id] = info_dict[" csv_file_path" ])
205140 end
206141
207- # Parse sections and create wing sections
208- sections = Section[]
209- refined_sections = Section[]
142+ # Create Wing using the standard constructor
143+ wing = Wing (n_panels;
144+ n_groups= n_groups,
145+ spanwise_distribution= spanwise_distribution,
146+ spanwise_direction= MVec3 (spanwise_direction),
147+ remove_nan= remove_nan
148+ )
210149
150+ # Parse sections and populate wing
211151 for row in yaml_data[" wing_sections" ][" data" ]
212152 section_dict = Dict (zip (yaml_data[" wing_sections" ][" headers" ], row))
213153 airfoil_id = section_dict[" airfoil_id" ]
@@ -220,21 +160,17 @@ function YamlWing(
220160 csv_file_path = get (airfoil_csv_map, airfoil_id, " " )
221161 if ! isempty (csv_file_path) && ! isabspath (csv_file_path)
222162 # Make relative paths relative to YAML file directory
223- csv_file_path = joinpath (dirname (yaml_path ), csv_file_path)
163+ csv_file_path = joinpath (dirname (geometry_file ), csv_file_path)
224164 end
225165 aero_data, aero_model = load_polar_data (csv_file_path)
226166
227167 prn && println (" Section airfoil_id $airfoil_id : Using $aero_model model" )
228168
229- section = Section (le_coord, te_coord, aero_model, aero_data)
230- push! (sections, section)
231- push! (refined_sections, Section (le_coord, te_coord, aero_model, aero_data))
169+ add_section! (wing, le_coord, te_coord, aero_model, aero_data)
232170 end
233171
234- # Create YamlWing
235- YamlWing (
236- n_panels, n_groups, spanwise_distribution, PanelProperties {n_panels} (),
237- MVec3 (spanwise_direction), sections, refined_sections, remove_nan,
238- airfoil_settings
239- )
172+ # Initialize the wing after adding all sections
173+ reinit! (wing)
174+
175+ return wing
240176end
0 commit comments