1- #=
1+ using LinearAlgebra
2+ using VortexStepMethod
3+ using ControlPlots
4+ using YAML
5+ using CSV
6+ using DataFrames
27
3- Example script to run the VortexStepMethod on a pyramid model.
48
5- Second commit
9+ function read_yaml (yaml_file_path)
10+ # Read the YAML file to get the sections
11+ yaml_data = YAML. load_file (yaml_file_path)
12+
13+ # Extract headers and data
14+ headers = yaml_data[" wing_sections" ][" headers" ]
15+ data_rows = yaml_data[" wing_sections" ][" data" ]
16+
17+ # Convert YAML data to the expected format
18+ sections = []
19+ for row in data_rows
20+ # Create a dictionary mapping headers to values
21+ section_dict = Dict (zip (headers, row))
22+
23+ # Keep airfoil_id as integer for CSV filename lookup
24+ airfoil_id = section_dict[" airfoil_id" ]
25+
26+ # Extract coordinates
27+ le_coord = [section_dict[" LE_x" ], section_dict[" LE_y" ], section_dict[" LE_z" ]]
28+ te_coord = [section_dict[" TE_x" ], section_dict[" TE_y" ], section_dict[" TE_z" ]]
29+
30+ section = (
31+ airfoil_id = airfoil_id,
32+ le_coord = le_coord,
33+ te_coord = te_coord
34+ )
35+ push! (sections, section)
36+ end
637
7- Third test commit
38+ return sections
39+ end
840
9- =#
41+ function load_polar_data (airfoil_id, polars_dir)
42+ """
43+ Load polar data from CSV file for given airfoil_id.
44+ Expected CSV format: columns named alpha, cl, cd, cm
45+ """
46+ csv_filename = " $(airfoil_id) .csv"
47+ csv_filepath = joinpath (polars_dir, csv_filename)
48+
49+ if ! isfile (csv_filepath)
50+ @warn " Polar file not found: $csv_filepath . Using INVISCID model instead."
51+ return nothing , INVISCID
52+ end
53+
54+ try
55+ df = CSV. read (csv_filepath, DataFrame)
56+
57+ # Verify required columns exist
58+ required_cols = [" alpha" , " cl" , " cd" , " cm" ]
59+ missing_cols = setdiff (required_cols, names (df))
60+ if ! isempty (missing_cols)
61+ @warn " Missing columns $missing_cols in $csv_filepath . Using INVISCID model instead."
62+ return nothing , INVISCID
63+ end
64+
65+ # Create aero_data tuple
66+ aero_data = (df. alpha, df. cl, df. cd, df. cm)
67+ return aero_data, POLAR_VECTORS
68+
69+ catch e
70+ @warn " Error reading polar file $csv_filepath : $e . Using INVISCID model instead."
71+ return nothing , INVISCID
72+ end
73+ end
74+
75+
76+ function instantiate_from_yaml (yaml_file_path, polars_dir; n_panels= 20 , spanwise_distribution= LINEAR)
77+ """
78+ Create a wing geometry from YAML file with polar data loaded from CSV files.
79+
80+ # Arguments
81+ - `yaml_file_path`: Path to YAML file containing wing section definitions
82+ - `polars_dir`: Path to directory containing polar CSV files (named <airfoil_id>.csv)
83+ - `n_panels`: Number of panels for the wing (default: 20)
84+ - `spanwise_distribution`: Panel distribution type (default: LINEAR)
85+
86+ # Returns
87+ - `BodyAerodynamics`: Initialized aerodynamics object containing the wing
88+
89+ # Example
90+ ```julia
91+ yaml_path = "pyramid.yaml"
92+ polars_dir = "/path/to/polars"
93+ body_aero = instantiate_from_yaml(yaml_path, polars_dir; n_panels=30)
94+ ```
95+ """
96+ # Create wing with specified panel distribution
97+ wing = Wing (n_panels, spanwise_distribution= spanwise_distribution)
98+
99+ # Read sections from YAML file
100+ sections = read_yaml (yaml_file_path)
101+
102+ # Add each section to the wing
103+ for section in sections
104+ # Load polar data for this airfoil
105+ aero_data, aero_model = load_polar_data (section. airfoil_id, polars_dir)
106+
107+ println (" Section airfoil_id $(section. airfoil_id) : Using $(aero_model) model" )
108+
109+ add_section! (wing,
110+ section. le_coord, # Leading edge coordinate
111+ section. te_coord, # Trailing edge coordinate
112+ aero_model, # Aerodynamic model (POLAR_VECTORS or INVISCID)
113+ aero_data) # Aerodynamic data tuple or nothing
114+ end
115+
116+ # Initialize and return aerodynamics object
117+ body_aero = BodyAerodynamics ([wing])
118+ return body_aero
119+ end
120+
121+ # getting the project_dir
122+ project_dir = dirname (dirname (pathof (VortexStepMethod))) # Go up one level from src to project root
123+ yaml_file_path = joinpath (project_dir, " data" , " pyramid_model" , " pyramid.yaml" )
124+ polars_dir = joinpath (project_dir, " data" , " pyramid_model" , " polars" )
125+
126+ sections = read_yaml (yaml_file_path)
127+ println (" Read sections from YAML file: $(length (sections)) sections" )
128+ println (" Sections: $(sections) " )
129+
130+ body_aero = instantiate_from_yaml (yaml_file_path, polars_dir; n_panels= 20 )
131+ println (" Created wing geometry with $(length (body_aero. panels)) panels" )
132+
133+ # Plotting Geometrys
134+ PLOT = true
135+ USE_TEX = false
136+ PLOT && plot_geometry (
137+ body_aero,
138+ " " ;
139+ data_type= " .svg" ,
140+ save_path= " " ,
141+ is_save= false ,
142+ is_show= true ,
143+ view_elevation= 15 ,
144+ view_azimuth= - 120 ,
145+ use_tex= USE_TEX
146+ )
0 commit comments