Skip to content

Commit 8100534

Browse files
authored
KiteWing should be centered at center of mass (#108)
* fix tests * remove com as it is zero now * fix tests * improve warning
1 parent 0ff83ec commit 8100534

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/kite_geometry.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ function create_interpolations(vertices, circle_center_z, radius, gamma_tip)
155155
return (le_interp, te_interp, area_interp)
156156
end
157157

158-
# Calculate center of mass for a triangular surface mesh
159-
function calculate_com(vertices, faces)
158+
# Makes the zero coordinates lie on the com
159+
function center_to_com!(vertices, faces)
160160
area_total = 0.0
161161
com = zeros(3)
162162

@@ -174,7 +174,13 @@ function calculate_com(vertices, faces)
174174
com += area * centroid
175175
end
176176

177-
return com / area_total
177+
com = com / area_total
178+
!(abs(com[2]) < 0.01) && @warn "Center of mass $com has to lie on the xz-plane."
179+
@info "Centering vertices of .obj file to the center of mass: $com"
180+
for v in vertices
181+
v .-= com
182+
end
183+
return com
178184
end
179185

180186
"""
@@ -304,7 +310,6 @@ Represents a curved wing that inherits from Wing with additional geometric prope
304310
- refined_sections::Vector{Section}
305311
- `remove_nan::Bool`: Wether to remove the NaNs from interpolations or not
306312
- Additional fields:
307-
- `center_of_mass::Vector{Float64}`: Center of mass coordinates
308313
- `circle_center_z::Vector{Float64}`: Center of circle coordinates
309314
- gamma_tip::Float64: Angle between the body frame z axis and the vector going from the kite circular shape center to the wing tip.
310315
- `inertia_tensor`::Matrix{Float64}: see: [`calculate_inertia_tensor`](@ref)
@@ -325,7 +330,6 @@ mutable struct KiteWing <: AbstractWing
325330
# Additional fields for KiteWing
326331
non_deformed_sections::Vector{Section}
327332
mass::Float64
328-
center_of_mass::Vector{Float64}
329333
circle_center_z::Float64
330334
gamma_tip::Float64
331335
inertia_tensor::Matrix{Float64}
@@ -378,14 +382,13 @@ function KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10.,
378382
if !ispath(polar_path) || !ispath(info_path)
379383
@info "Reading $obj_path"
380384
vertices, faces = read_faces(obj_path)
381-
center_of_mass = calculate_com(vertices, faces)
382-
!(abs(center_of_mass[2]) < 0.01) && @error "Center of mass $center_of_mass has to lie on x-axis."
383-
inertia_tensor = calculate_inertia_tensor(vertices, faces, mass, center_of_mass)
385+
center_to_com!(vertices, faces)
386+
inertia_tensor = calculate_inertia_tensor(vertices, faces, mass, zeros(3))
384387

385388
circle_center_z, radius, gamma_tip = find_circle_center_and_radius(vertices)
386389
le_interp, te_interp, area_interp = create_interpolations(vertices, circle_center_z, radius, gamma_tip)
387390
@info "Writing $info_path"
388-
serialize(info_path, (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
391+
serialize(info_path, (inertia_tensor, circle_center_z, radius, gamma_tip,
389392
le_interp, te_interp, area_interp))
390393

391394
width = 2gamma_tip * radius
@@ -405,7 +408,7 @@ function KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10.,
405408
interpolate_matrix_nans!(cm_matrix)
406409
end
407410

408-
(center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
411+
(inertia_tensor, circle_center_z, radius, gamma_tip,
409412
le_interp, te_interp, area_interp) = deserialize(info_path)
410413

411414
# Create sections
@@ -418,7 +421,7 @@ function KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10.,
418421
end
419422

420423
KiteWing(n_panels, spanwise_panel_distribution, spanwise_direction, sections, sections, remove_nan, sections,
421-
mass, center_of_mass, circle_center_z, gamma_tip, inertia_tensor, radius,
424+
mass, circle_center_z, gamma_tip, inertia_tensor, radius,
422425
le_interp, te_interp, area_interp, zeros(n_panels), zeros(n_panels))
423426
end
424427

test/test_kite_geometry.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
using Test
33
using VortexStepMethod
4-
using VortexStepMethod: create_interpolations, find_circle_center_and_radius, calculate_inertia_tensor, calculate_com, read_faces
4+
using VortexStepMethod: create_interpolations, find_circle_center_and_radius, calculate_inertia_tensor, center_to_com!, read_faces
55
using LinearAlgebra
66
using Interpolations
77
using Serialization
@@ -35,7 +35,7 @@ using Serialization
3535
vertices = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
3636
faces = [[1, 2, 3]]
3737

38-
com = calculate_com(vertices, faces)
38+
com = center_to_com!(vertices, faces)
3939
expected_com = [1/3, 1/3, 0.0]
4040

4141
@test isapprox(com, expected_com, rtol=1e-5)
@@ -121,11 +121,10 @@ using Serialization
121121
# Create info file
122122
info_path = test_obj_path[1:end-4] * "_info.bin"
123123
le_interp, te_interp, area_interp = create_interpolations(vertices, z_center, r, π/4)
124-
center_of_mass = calculate_com(vertices, faces)
125-
inertia_tensor = calculate_inertia_tensor(vertices, faces, 1.0, center_of_mass)
124+
center_of_mass = center_to_com!(vertices, faces)
125+
inertia_tensor = calculate_inertia_tensor(vertices, faces, 1.0, zeros(3))
126126

127127
serialize(info_path, (
128-
center_of_mass,
129128
inertia_tensor,
130129
z_center,
131130
r,
@@ -150,7 +149,6 @@ using Serialization
150149
@test wing.spanwise_direction [0.0, 1.0, 0.0]
151150
@test length(wing.sections) > 0 # Should have sections now
152151
@test wing.mass 1.0
153-
@test length(wing.center_of_mass) == 3
154152
@test wing.radius r rtol=1e-2
155153
@test wing.gamma_tip π/4 rtol=1e-2
156154
@test !isnan(wing.sections[1].aero_data[3][end])

0 commit comments

Comments
 (0)