Skip to content

Commit eb2af0e

Browse files
authored
Add deform! test (#124)
* add deform tests * fix typo
1 parent 3b13209 commit eb2af0e

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

src/kite_geometry.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,19 @@ function RamAirWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10
413413

414414
# Create sections
415415
sections = Section[]
416+
refined_sections = Section[]
417+
non_deformed_sections = Section[]
416418
for gamma in range(-gamma_tip, gamma_tip, n_sections)
417419
aero_data = (collect(alpha_range), collect(delta_range), cl_matrix, cd_matrix, cm_matrix)
418420
LE_point = [le_interp[i](gamma) for i in 1:3]
419421
TE_point = [te_interp[i](gamma) for i in 1:3]
420422
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))
421425
end
422426

423-
RamAirWing(n_panels, spanwise_panel_distribution, spanwise_direction, sections, sections, remove_nan, sections,
427+
RamAirWing(n_panels, spanwise_panel_distribution, spanwise_direction, sections,
428+
refined_sections, remove_nan, non_deformed_sections,
424429
mass, circle_center_z, gamma_tip, inertia_tensor, radius,
425430
le_interp, te_interp, area_interp, zeros(n_panels), zeros(n_panels))
426431
end

src/solver.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
105105
log=false, reference_point=zeros(MVec3), moment_frac=0.1)
106106

107107
# calculate intermediate result
108-
(converged,
109-
body_aero, gamma_new, reference_point, density, aerodynamic_model_type, core_radius_fraction,
110-
mu, alpha_array, v_a_array, chord_array, x_airf_array, y_airf_array, z_airf_array,
111-
va_array, va_norm_array, va_unit_array, panels,
112-
is_only_f_and_gamma_output) = solve_base(solver, body_aero, gamma_distribution; log, reference_point)
108+
(converged, body_aero, gamma_new, reference_point, density, aerodynamic_model_type, core_radius_fraction,
109+
mu, alpha_array, v_a_array, chord_array, x_airf_array, y_airf_array, z_airf_array,
110+
va_array, va_norm_array, va_unit_array, panels,
111+
is_only_f_and_gamma_output) = solve_base(solver, body_aero, gamma_distribution; log, reference_point)
113112
if !isnothing(solver.sol.gamma_distribution)
114113
solver.sol.gamma_distribution .= gamma_new
115114
else
@@ -242,7 +241,7 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
242241
# Calculate the moment distribution (moment on each panel)
243242
arm = (moment_frac - 0.25) * panel.chord
244243
moment_distribution[i] = dot(ftotal_induced_va, panel.z_airf) * arm
245-
moment_coefficient_distribution[i] = moment_distribution[i] ./ (q_inf * projected_area)
244+
moment_coefficient_distribution[i] = moment_distribution[i] / (q_inf * projected_area)
246245
end
247246

248247
# update the result struct

test/test_kite_geometry.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,42 @@ using Serialization
166166
@test isnan(wing.sections[1].aero_data[4][end])
167167
@test isnan(wing.sections[1].aero_data[5][end])
168168
end
169+
170+
@testset "Wing Deformation" begin
171+
# Create a RamAirWing for testing
172+
wing = RamAirWing(test_obj_path, test_dat_path; remove_nan=true)
173+
body_aero = BodyAerodynamics([wing])
174+
175+
# Store original TE point for comparison
176+
i = length(body_aero.panels) ÷ 2
177+
original_te_point = copy(body_aero.panels[i].TE_point_1)
178+
179+
# Apply deformation with non-zero angles
180+
theta_dist = fill(deg2rad(30.0), wing.n_panels) # 10 degrees twist
181+
delta_dist = fill(deg2rad(5.0), wing.n_panels) # 5 degrees trailing edge deflection
182+
183+
VortexStepMethod.deform!(wing, theta_dist, delta_dist)
184+
VortexStepMethod.init!(body_aero)
185+
186+
# Check if TE point changed after deformation
187+
deformed_te_point = copy(body_aero.panels[i].TE_point_1)
188+
@test !isapprox(original_te_point, deformed_te_point, atol=1e-2)
189+
@test deformed_te_point[3] < original_te_point[3] # right hand rule
190+
@test deformed_te_point[2] original_te_point[2] atol=1e-2 # right hand rule
191+
@test deformed_te_point[1] < original_te_point[1] # right hand rule
192+
@test body_aero.panels[i].delta deg2rad(5.0)
193+
194+
# Reset deformation with zero angles
195+
zero_theta_dist = zeros(wing.n_panels)
196+
zero_delta_dist = zeros(wing.n_panels)
197+
198+
VortexStepMethod.deform!(wing, zero_theta_dist, zero_delta_dist)
199+
VortexStepMethod.init!(body_aero)
200+
201+
# Check if TE point returned to original position
202+
reset_te_point = copy(body_aero.panels[i].TE_point_1)
203+
@test original_te_point reset_te_point atol=1e-4
204+
end
169205

170206
rm(test_obj_path)
171207
rm(test_dat_path)

0 commit comments

Comments
 (0)