Skip to content

Commit dab4dbe

Browse files
authored
Add center of mass field to RamWing (#128)
* Components used for non-dim * Fix bug * Test fails correctly * Add com field * Reset to main
1 parent eb2af0e commit dab4dbe

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

src/kite_geometry.jl

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ mutable struct RamAirWing <: AbstractWing
333333
circle_center_z::Float64
334334
gamma_tip::Float64
335335
inertia_tensor::Matrix{Float64}
336+
center_of_mass::Vector{Float64}
336337
radius::Float64
337338
le_interp::NTuple{3, Extrapolation}
338339
te_interp::NTuple{3, Extrapolation}
@@ -382,13 +383,13 @@ function RamAirWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10
382383
if !ispath(polar_path) || !ispath(info_path)
383384
@info "Reading $obj_path"
384385
vertices, faces = read_faces(obj_path)
385-
center_to_com!(vertices, faces)
386+
center_of_mass = center_to_com!(vertices, faces)
386387
inertia_tensor = calculate_inertia_tensor(vertices, faces, mass, zeros(3))
387388

388389
circle_center_z, radius, gamma_tip = find_circle_center_and_radius(vertices)
389390
le_interp, te_interp, area_interp = create_interpolations(vertices, circle_center_z, radius, gamma_tip)
390391
@info "Writing $info_path"
391-
serialize(info_path, (inertia_tensor, circle_center_z, radius, gamma_tip,
392+
serialize(info_path, (inertia_tensor, center_of_mass, circle_center_z, radius, gamma_tip,
392393
le_interp, te_interp, area_interp))
393394

394395
width = 2gamma_tip * radius
@@ -401,33 +402,39 @@ function RamAirWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10
401402
end
402403

403404
@info "Loading polars and kite info from $polar_path and $info_path"
404-
(alpha_range, delta_range, cl_matrix::Matrix, cd_matrix::Matrix, cm_matrix::Matrix) = deserialize(polar_path)
405-
if remove_nan
406-
interpolate_matrix_nans!(cl_matrix)
407-
interpolate_matrix_nans!(cd_matrix)
408-
interpolate_matrix_nans!(cm_matrix)
409-
end
410-
411-
(inertia_tensor, circle_center_z, radius, gamma_tip,
412-
le_interp, te_interp, area_interp) = deserialize(info_path)
413-
414-
# Create sections
415-
sections = Section[]
416-
refined_sections = Section[]
417-
non_deformed_sections = Section[]
418-
for gamma in range(-gamma_tip, gamma_tip, n_sections)
419-
aero_data = (collect(alpha_range), collect(delta_range), cl_matrix, cd_matrix, cm_matrix)
420-
LE_point = [le_interp[i](gamma) for i in 1:3]
421-
TE_point = [te_interp[i](gamma) for i in 1:3]
422-
push!(sections, Section(LE_point, TE_point, POLAR_MATRICES, aero_data))
423-
push!(refined_sections, Section(LE_point, TE_point, POLAR_MATRICES, aero_data))
424-
push!(non_deformed_sections, Section(LE_point, TE_point, POLAR_MATRICES, aero_data))
405+
try
406+
(alpha_range, delta_range, cl_matrix::Matrix, cd_matrix::Matrix, cm_matrix::Matrix) = deserialize(polar_path)
407+
if remove_nan
408+
interpolate_matrix_nans!(cl_matrix)
409+
interpolate_matrix_nans!(cd_matrix)
410+
interpolate_matrix_nans!(cm_matrix)
411+
end
412+
(inertia_tensor::Matrix, center_of_mass::Vector, circle_center_z::Real,
413+
radius::Real, gamma_tip::Real, le_interp, te_interp, area_interp) = deserialize(info_path)
414+
415+
# Create sections
416+
sections = Section[]
417+
refined_sections = Section[]
418+
non_deformed_sections = Section[]
419+
for gamma in range(-gamma_tip, gamma_tip, n_sections)
420+
aero_data = (collect(alpha_range), collect(delta_range), cl_matrix, cd_matrix, cm_matrix)
421+
LE_point = [le_interp[i](gamma) for i in 1:3]
422+
TE_point = [te_interp[i](gamma) for i in 1:3]
423+
push!(sections, Section(LE_point, TE_point, POLAR_MATRICES, aero_data))
424+
push!(refined_sections, Section(LE_point, TE_point, POLAR_MATRICES, aero_data))
425+
push!(non_deformed_sections, Section(LE_point, TE_point, POLAR_MATRICES, aero_data))
426+
end
427+
428+
RamAirWing(n_panels, spanwise_panel_distribution, spanwise_direction, sections,
429+
refined_sections, remove_nan, non_deformed_sections,
430+
mass, circle_center_z, gamma_tip, inertia_tensor, center_of_mass, radius,
431+
le_interp, te_interp, area_interp, zeros(n_panels), zeros(n_panels))
432+
catch e
433+
if e isa BoundsError
434+
@error "Delete $polar_path and $info_path and try again."
435+
end
436+
rethrow(e)
425437
end
426-
427-
RamAirWing(n_panels, spanwise_panel_distribution, spanwise_direction, sections,
428-
refined_sections, remove_nan, non_deformed_sections,
429-
mass, circle_center_z, gamma_tip, inertia_tensor, radius,
430-
le_interp, te_interp, area_interp, zeros(n_panels), zeros(n_panels))
431438
end
432439

433440
"""
28 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

test/test_kite_geometry.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ using Serialization
131131
inertia_tensor = calculate_inertia_tensor(vertices, faces, 1.0, zeros(3))
132132

133133
serialize(info_path, (
134-
inertia_tensor,
134+
inertia_tensor,
135+
center_of_mass,
135136
z_center,
136137
r,
137138
π/4,

0 commit comments

Comments
 (0)