Skip to content

Commit 04e9f1f

Browse files
committed
Read file better
1 parent 971c198 commit 04e9f1f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/kite_geometry.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ Create interpolation functions for leading/trailing edges and area.
111111
- Tuple of (le_interp, te_interp, area_interp) interpolation functions
112112
- Where le_interp and te_interp are tuples themselves, containing the x, y and z interpolations
113113
"""
114-
function create_interpolations(vertices, circle_center_z, radius, gamma_tip)
115-
gamma_range = range(-gamma_tip+1e-6, gamma_tip-1e-6, 100)
114+
function create_interpolations(vertices, circle_center_z, radius, gamma_tip; interp_steps=40)
115+
gamma_range = range(-gamma_tip+1e-6, gamma_tip-1e-6, interp_steps)
116+
stepsize = gamma_range.step.hi
116117
vz_centered = [v[3] - circle_center_z for v in vertices]
117118

119+
te_gammas = zeros(length(gamma_range))
120+
le_gammas = zeros(length(gamma_range))
118121
trailing_edges = zeros(3, length(gamma_range))
119122
leading_edges = zeros(3, length(gamma_range))
120123
areas = zeros(length(gamma_range))
@@ -124,31 +127,36 @@ function create_interpolations(vertices, circle_center_z, radius, gamma_tip)
124127
leading_edges[1, j] = Inf
125128
for (i, v) in enumerate(vertices)
126129
# Rotate y coordinate to check box containment
127-
rotated_y = v[2] * cos(-gamma) - vz_centered[i] * sin(-gamma)
128-
if gamma 0.0 && 0.0 rotated_y 0.5
130+
# rotated_y = v[2] * cos(-gamma) - vz_centered[i] * sin(-gamma)
131+
gamma_v = atan(-v[2], vz_centered[i])
132+
if gamma < 0 && gamma - stepsize gamma_v gamma
129133
if v[1] > trailing_edges[1, j]
130134
trailing_edges[:, j] .= v
135+
te_gammas[j] = gamma_v
131136
end
132137
if v[1] < leading_edges[1, j]
133138
leading_edges[:, j] .= v
139+
le_gammas[j] = gamma_v
134140
end
135-
elseif gamma > 0.0 && -0.5 rotated_y 0.0
141+
elseif gamma > 0 && gamma gamma_v gamma + stepsize
136142
if v[1] > trailing_edges[1, j]
137143
trailing_edges[:, j] .= v
144+
te_gammas[j] = gamma_v
138145
end
139146
if v[1] < leading_edges[1, j]
140147
leading_edges[:, j] .= v
148+
le_gammas[j] = gamma_v
141149
end
142150
end
143151
end
144-
area = norm(leading_edges[:, j] - trailing_edges[:, j]) * gamma_range.step * radius
152+
area = norm(leading_edges[:, j] - trailing_edges[:, j]) * stepsize * radius
145153
last_area = j > 1 ? areas[j-1] : 0.0
146154
areas[j] = last_area + area
147155
end
148156

149-
le_interp = ntuple(i -> linear_interpolation(gamma_range, leading_edges[i, :],
157+
le_interp = ntuple(i -> linear_interpolation(te_gammas, leading_edges[i, :],
150158
extrapolation_bc=Line()), 3)
151-
te_interp = ntuple(i -> linear_interpolation(gamma_range, trailing_edges[i, :],
159+
te_interp = ntuple(i -> linear_interpolation(le_gammas, trailing_edges[i, :],
152160
extrapolation_bc=Line()), 3)
153161
area_interp = linear_interpolation(gamma_range, areas, extrapolation_bc=Line())
154162

@@ -446,7 +454,7 @@ Constructor for a [RamAirWing](@ref) that allows to use an `.obj` and a `.dat` f
446454
function RamAirWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10., mass=1.0,
447455
n_panels=54, n_sections=n_panels+1, spanwise_panel_distribution=UNCHANGED,
448456
spanwise_direction=[0.0, 1.0, 0.0], remove_nan=true, align_to_principal=false,
449-
alpha_range=deg2rad.(-5:1:20), delta_range=deg2rad.(-5:1:20)
457+
alpha_range=deg2rad.(-5:1:20), delta_range=deg2rad.(-5:1:20), interp_steps=40
450458
)
451459

452460
!isapprox(spanwise_direction, [0.0, 1.0, 0.0]) && throw(ArgumentError("Spanwise direction has to be [0.0, 1.0, 0.0], not $spanwise_direction"))
@@ -468,7 +476,7 @@ function RamAirWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10
468476
align_to_principal && align_to_principal!(vertices, inertia_tensor)
469477

470478
circle_center_z, radius, gamma_tip = find_circle_center_and_radius(vertices)
471-
le_interp, te_interp, area_interp = create_interpolations(vertices, circle_center_z, radius, gamma_tip)
479+
le_interp, te_interp, area_interp = create_interpolations(vertices, circle_center_z, radius, gamma_tip; interp_steps)
472480
@info "Writing $info_path"
473481
serialize(info_path, (inertia_tensor, center_of_mass, circle_center_z, radius, gamma_tip,
474482
le_interp, te_interp, area_interp))

0 commit comments

Comments
 (0)