@@ -12,6 +12,45 @@ Expected format: header row and columns alpha, cl, cd, cm (case-insensitive, ord
1212
1313Returns (aero_data, POLAR_VECTORS) or (nothing, INVISCID) if missing/invalid.
1414"""
15+
16+ # Structs for YAML parsing using StructMapping.jl
17+ @kwdef struct WingAirfoilInfo
18+ csv_file_path:: String = " "
19+ end
20+
21+ @kwdef struct WingAirfoilData
22+ airfoil_id:: Int64
23+ type:: String
24+ info_dict:: WingAirfoilInfo
25+ end
26+
27+ @kwdef struct WingAirfoils
28+ alpha_range:: Vector{Float64}
29+ reynolds:: Float64
30+ headers:: Vector{String}
31+ data:: Vector{WingAirfoilData}
32+ end
33+
34+ @kwdef struct WingSectionData
35+ airfoil_id:: Int64
36+ LE_x:: Float64
37+ LE_y:: Float64
38+ LE_z:: Float64
39+ TE_x:: Float64
40+ TE_y:: Float64
41+ TE_z:: Float64
42+ end
43+
44+ @kwdef struct WingSections
45+ headers:: Vector{String}
46+ data:: Vector{WingSectionData}
47+ end
48+
49+ @kwdef struct WingGeometry
50+ wing_sections:: WingSections
51+ wing_airfoils:: WingAirfoils
52+ end
53+
1554function load_polar_data (csv_file_path:: String )
1655 if isempty (csv_file_path) || ! isfile (csv_file_path)
1756 @warn " Polar file not found or empty path: $csv_file_path . Using INVISCID model instead."
@@ -126,17 +165,44 @@ function YamlWing(
126165
127166 prn && @info " Reading YAML wing configuration from $geometry_file "
128167
129- # Read and parse YAML file
130- yaml_data = YAML. load_file (geometry_file)
168+ # Load YAML file following Uwe's suggestion
169+ data = YAML. load_file (geometry_file)
131170
132- # Parse airfoils and create CSV file mapping
133- airfoil_csv_map = Dict {Int64, String} ()
171+ # Convert YAML data to our struct format
172+ # Convert wing sections
173+ wing_sections_data = data[" wing_sections" ]
174+ sections = WingSectionData[]
175+ for row in wing_sections_data[" data" ]
176+ section_dict = Dict (zip (wing_sections_data[" headers" ], row))
177+ push! (sections, WingSectionData (
178+ airfoil_id = section_dict[" airfoil_id" ],
179+ LE_x = section_dict[" LE_x" ],
180+ LE_y = section_dict[" LE_y" ],
181+ LE_z = section_dict[" LE_z" ],
182+ TE_x = section_dict[" TE_x" ],
183+ TE_y = section_dict[" TE_y" ],
184+ TE_z = section_dict[" TE_z" ]
185+ ))
186+ end
134187
135- for row in yaml_data[" wing_airfoils" ][" data" ]
136- airfoil_dict = Dict (zip (yaml_data[" wing_airfoils" ][" headers" ], row))
137- airfoil_id, airfoil_type, info_dict = airfoil_dict[" airfoil_id" ], airfoil_dict[" type" ], airfoil_dict[" info_dict" ]
138-
139- haskey (info_dict, " csv_file_path" ) && (airfoil_csv_map[airfoil_id] = info_dict[" csv_file_path" ])
188+ # Convert wing airfoils
189+ wing_airfoils_data = data[" wing_airfoils" ]
190+ airfoils = WingAirfoilData[]
191+ for row in wing_airfoils_data[" data" ]
192+ airfoil_dict = Dict (zip (wing_airfoils_data[" headers" ], row))
193+ push! (airfoils, WingAirfoilData (
194+ airfoil_id = airfoil_dict[" airfoil_id" ],
195+ type = airfoil_dict[" type" ],
196+ info_dict = WingAirfoilInfo (csv_file_path = get (airfoil_dict[" info_dict" ], " csv_file_path" , " " ))
197+ ))
198+ end
199+
200+ # Create CSV file mapping from airfoils
201+ airfoil_csv_map = Dict {Int64, String} ()
202+ for airfoil in airfoils
203+ if ! isempty (airfoil. info_dict. csv_file_path)
204+ airfoil_csv_map[airfoil. airfoil_id] = airfoil. info_dict. csv_file_path
205+ end
140206 end
141207
142208 # Create Wing using the standard constructor
@@ -148,23 +214,20 @@ function YamlWing(
148214 )
149215
150216 # Parse sections and populate wing
151- for row in yaml_data[" wing_sections" ][" data" ]
152- section_dict = Dict (zip (yaml_data[" wing_sections" ][" headers" ], row))
153- airfoil_id = section_dict[" airfoil_id" ]
154-
155- # Get coordinates
156- le_coord = [section_dict[" LE_x" ], section_dict[" LE_y" ], section_dict[" LE_z" ]]
157- te_coord = [section_dict[" TE_x" ], section_dict[" TE_y" ], section_dict[" TE_z" ]]
217+ for section in sections
218+ # Get coordinates directly from struct fields
219+ le_coord = [section. LE_x, section. LE_y, section. LE_z]
220+ te_coord = [section. TE_x, section. TE_y, section. TE_z]
158221
159222 # Load polar data and create section
160- csv_file_path = get (airfoil_csv_map, airfoil_id, " " )
223+ csv_file_path = get (airfoil_csv_map, section . airfoil_id, " " )
161224 if ! isempty (csv_file_path) && ! isabspath (csv_file_path)
162225 # Make relative paths relative to YAML file directory
163226 csv_file_path = joinpath (dirname (geometry_file), csv_file_path)
164227 end
165228 aero_data, aero_model = load_polar_data (csv_file_path)
166229
167- prn && println (" Section airfoil_id $airfoil_id : Using $aero_model model" )
230+ prn && println (" Section airfoil_id $(section . airfoil_id) : Using $aero_model model" )
168231
169232 add_section! (wing, le_coord, te_coord, aero_model, aero_data)
170233 end
0 commit comments