@@ -209,70 +209,93 @@ mutable struct KiteWing <: AbstractWing
209209 te_interp:: Extrapolation
210210 area_interp:: Extrapolation
211211
212- function KiteWing (obj_path, dat_path; alpha= 0.0 , crease_frac= 0.75 , wind_vel= 10. , mass= 1.0 ,
213- n_panels= 54 , n_sections= n_panels+ 1 , spanwise_panel_distribution= UNCHANGED, spanwise_direction= [0.0 , 1.0 , 0.0 ])
214-
215- ! isapprox (spanwise_direction, [0.0 , 1.0 , 0.0 ]) && @error " Spanwise direction has to be [0.0, 1.0, 0.0]"
216-
217- # Load or create polars
218- (! endswith (dat_path, " .dat" )) && (dat_path *= " .dat" )
219- (! isfile (dat_path)) && error (" DAT file not found: $dat_path " )
220- polar_path = dat_path[1 : end - 4 ] * " _polar.bin"
221-
222- (! endswith (obj_path, " .obj" )) && (obj_path *= " .obj" )
223- (! isfile (obj_path)) && error (" OBJ file not found: $obj_path " )
224- info_path = obj_path[1 : end - 4 ] * " _info.bin"
225-
226- if ! ispath (polar_path) || ! ispath (info_path)
227- @info " Reading $obj_path "
228- vertices, faces = read_faces (obj_path)
229- center_of_mass = calculate_com (vertices, faces)
230- ! (abs (center_of_mass[2 ]) < 0.01 ) && @error " Center of mass $center_of_mass has to lie on x-axis."
231- inertia_tensor = calculate_inertia_tensor (vertices, faces, mass, center_of_mass)
232-
233- circle_center_z, radius, gamma_tip = find_circle_center_and_radius (vertices)
234- le_interp, te_interp, area_interp = create_interpolations (vertices, circle_center_z, radius, gamma_tip)
235- @info " Writing $info_path "
236- serialize (info_path, (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
237- le_interp, te_interp, area_interp))
238-
239- width = 2 gamma_tip * radius
240- area = area_interp (gamma_tip)
241- @eval Main begin
242- foil_path, polar_path, v_wind, area, width, x_turn =
243- $ dat_path, $ polar_path, $ wind_vel, $ gamma_tip, $ width, $ crease_frac
244- include (" ../scripts/polars.jl" )
245- end
246- end
212+ end
247213
248- @info " Loading polars and kite info from $polar_path and $info_path "
249- (alpha_range, beta_range, cl_matrix:: Matrix , cd_matrix:: Matrix , cm_matrix:: Matrix ) = deserialize (polar_path)
250-
251- (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
252- le_interp, te_interp, area_interp) = deserialize (info_path)
253-
254- # Create sections
255- sections = Section[]
256- for gamma in range (- gamma_tip, gamma_tip, n_sections)
257- aero_data = (collect (alpha_range), collect (beta_range), cl_matrix, cd_matrix, cm_matrix)
258- LE_point = [0.0 , 0.0 , circle_center_z] .+ [le_interp (gamma), sin (gamma) * radius, cos (gamma) * radius]
259- if ! isapprox (alpha, 0.0 )
260- local_y_vec = [0.0 , sin (- gamma), cos (gamma)] × [1.0 , 0.0 , 0.0 ]
261- TE_point = LE_point .+ rotate_v_around_k ([te_interp (gamma) - le_interp (gamma), 0.0 , 0.0 ], local_y_vec, alpha)
262- else
263- TE_point = LE_point .+ [te_interp (gamma) - le_interp (gamma), 0.0 , 0.0 ]
264- end
265- push! (sections, Section (LE_point, TE_point, POLAR_DATA, aero_data))
214+ """
215+ KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10., mass=1.0,
216+ n_panels=54, n_sections=n_panels+1, spanwise_panel_distribution=UNCHANGED,
217+ spanwise_direction=[0.0, 1.0, 0.0])
218+
219+ Constructor for a [KiteWing](@ref) that allows to use an `.obj` and a `.dat` file as input.
220+
221+ # Parameters
222+ - obj_path: Path to the `.obj` file used for creating the geometry
223+ - dat_path: Path to the `.dat` file, a standard format for 2d foil geometry
224+
225+ # Keyword Parameters
226+ - alpha=0.0: Angle of attack of each segment relative to the x axis [rad]
227+ - crease_frac=0.75: The x coordinate around which the trailing edge rotates on a normalized 2d foil,
228+ used in the xfoil polar generation
229+ - wind_vel=10.0: Apparent wind speed in m/s, used in the xfoil polar generation
230+ - mass=1.0: Mass of the wing in kg, used for the inertia calculations
231+ - `n_panels`=54: Number of panels.
232+ - `n_sections`=n_panels+1: Number of sections (there is a section on each side of each panel.)
233+ - `spanwise_panel_distribution`=UNCHANGED: see: [PanelDistribution](@ref)
234+ - `spanwise_direction`=[0.0, 1.0, 0.0]
235+ """
236+ function KiteWing (obj_path, dat_path; alpha= 0.0 , crease_frac= 0.75 , wind_vel= 10. , mass= 1.0 ,
237+ n_panels= 54 , n_sections= n_panels+ 1 , spanwise_panel_distribution= UNCHANGED,
238+ spanwise_direction= [0.0 , 1.0 , 0.0 ])
239+
240+ ! isapprox (spanwise_direction, [0.0 , 1.0 , 0.0 ]) && @error " Spanwise direction has to be [0.0, 1.0, 0.0]"
241+
242+ # Load or create polars
243+ (! endswith (dat_path, " .dat" )) && (dat_path *= " .dat" )
244+ (! isfile (dat_path)) && error (" DAT file not found: $dat_path " )
245+ polar_path = dat_path[1 : end - 4 ] * " _polar.bin"
246+
247+ (! endswith (obj_path, " .obj" )) && (obj_path *= " .obj" )
248+ (! isfile (obj_path)) && error (" OBJ file not found: $obj_path " )
249+ info_path = obj_path[1 : end - 4 ] * " _info.bin"
250+
251+ if ! ispath (polar_path) || ! ispath (info_path)
252+ @info " Reading $obj_path "
253+ vertices, faces = read_faces (obj_path)
254+ center_of_mass = calculate_com (vertices, faces)
255+ ! (abs (center_of_mass[2 ]) < 0.01 ) && @error " Center of mass $center_of_mass has to lie on x-axis."
256+ inertia_tensor = calculate_inertia_tensor (vertices, faces, mass, center_of_mass)
257+
258+ circle_center_z, radius, gamma_tip = find_circle_center_and_radius (vertices)
259+ le_interp, te_interp, area_interp = create_interpolations (vertices, circle_center_z, radius, gamma_tip)
260+ @info " Writing $info_path "
261+ serialize (info_path, (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
262+ le_interp, te_interp, area_interp))
263+
264+ width = 2 gamma_tip * radius
265+ area = area_interp (gamma_tip)
266+ @eval Main begin
267+ foil_path, polar_path, v_wind, area, width, x_turn =
268+ $ dat_path, $ polar_path, $ wind_vel, $ gamma_tip, $ width, $ crease_frac
269+ include (" ../scripts/polars.jl" )
266270 end
271+ end
272+
273+ @info " Loading polars and kite info from $polar_path and $info_path "
274+ (alpha_range, beta_range, cl_matrix:: Matrix , cd_matrix:: Matrix , cm_matrix:: Matrix ) = deserialize (polar_path)
275+
276+ (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
277+ le_interp, te_interp, area_interp) = deserialize (info_path)
267278
268- new (
269- n_panels, spanwise_panel_distribution, spanwise_direction, sections, sections,
270- mass, center_of_mass, circle_center_z, gamma_tip, inertia_tensor, radius,
271- le_interp, te_interp, area_interp
272- )
279+ # Create sections
280+ sections = Section[]
281+ for gamma in range (- gamma_tip, gamma_tip, n_sections)
282+ aero_data = (collect (alpha_range), collect (beta_range), cl_matrix, cd_matrix, cm_matrix)
283+ LE_point = [0.0 , 0.0 , circle_center_z] .+ [le_interp (gamma), sin (gamma) * radius, cos (gamma) * radius]
284+ if ! isapprox (alpha, 0.0 )
285+ local_y_vec = [0.0 , sin (- gamma), cos (gamma)] × [1.0 , 0.0 , 0.0 ]
286+ TE_point = LE_point .+ rotate_v_around_k ([te_interp (gamma) - le_interp (gamma), 0.0 , 0.0 ], local_y_vec, alpha)
287+ else
288+ TE_point = LE_point .+ [te_interp (gamma) - le_interp (gamma), 0.0 , 0.0 ]
289+ end
290+ push! (sections, Section (LE_point, TE_point, POLAR_DATA, aero_data))
273291 end
292+
293+ KiteWing (n_panels, spanwise_panel_distribution, spanwise_direction, sections, sections,
294+ mass, center_of_mass, circle_center_z, gamma_tip, inertia_tensor, radius,
295+ le_interp, te_interp, area_interp)
274296end
275297
298+
276299function rotate_v_around_k (v, k, θ)
277300 k = normalize (k)
278301 v_rot = v * cos (θ) + (k × v) * sin (θ) + k * (k ⋅ v) * (1 - cos (θ))
0 commit comments