Skip to content

Commit f55597f

Browse files
committed
Add groups
1 parent 3502599 commit f55597f

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

src/body_aerodynamics.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Main structure for calculating aerodynamic properties of bodies. Use the constru
2424
@with_kw mutable struct BodyAerodynamics{P}
2525
panels::Vector{Panel}
2626
wings::Vector{Wing}
27+
groups::Vector{Panel} = Panel[]
2728
_va::MVec3 = zeros(MVec3)
2829
omega::MVec3 = zeros(MVec3)
2930
gamma_distribution::MVector{P, Float64} = zeros(P)
@@ -73,14 +74,15 @@ function BodyAerodynamics(
7374
) where T <: AbstractWing
7475
# Initialize panels
7576
panels = Panel[]
77+
n_groups = 0
7678
for wing in wings
7779
for section in wing.sections
7880
section.LE_point .-= kite_body_origin
7981
section.TE_point .-= kite_body_origin
8082
end
8183
if wing.spanwise_distribution == UNCHANGED
8284
wing.refined_sections = wing.sections
83-
!(wing.n_panels == length(wing.sections) - 1) &&
85+
!(wing.n_panels == length(wing.sections) - 1) &&
8486
throw(ArgumentError("(wing.n_panels = $(wing.n_panels)) != (length(wing.sections) - 1 = $(length(wing.sections) - 1))"))
8587
else
8688
wing.refined_sections = Section[Section() for _ in 1:wing.n_panels+1]
@@ -91,9 +93,15 @@ function BodyAerodynamics(
9193
panel = Panel()
9294
push!(panels, panel)
9395
end
96+
97+
# Count total groups
98+
n_groups += wing.n_groups
9499
end
95100

96-
body_aero = BodyAerodynamics{length(panels)}(; panels, wings)
101+
# Initialize groups (unrefined panel representatives)
102+
groups = [Panel() for _ in 1:n_groups]
103+
104+
body_aero = BodyAerodynamics{length(panels)}(; panels, wings, groups)
97105
reinit!(body_aero; va, omega)
98106
return body_aero
99107
end

src/solver.jl

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,43 +316,92 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
316316
panels_per_group = wing.n_panels ÷ wing.n_groups
317317
for _ in 1:wing.n_groups
318318
panel_count = 0
319+
group_panel = body_aero.groups[group_idx]
320+
# Zero out accumulated fields
321+
group_panel.x_airf .= 0.0
322+
group_panel.y_airf .= 0.0
323+
group_panel.z_airf .= 0.0
324+
group_panel.va .= 0.0
325+
group_panel.chord = 0.0
326+
group_panel.width = 0.0
319327
for _ in 1:panels_per_group
328+
panel = body_aero.panels[panel_idx]
320329
group_moment_dist[group_idx] += moment_dist[panel_idx]
321330
group_moment_coeff_dist[group_idx] += moment_coeff_dist[panel_idx]
322331
cl_group_array[group_idx] += solver.sol.cl_array[panel_idx]
323332
cd_group_array[group_idx] += solver.sol.cd_array[panel_idx]
324333
cm_group_array[group_idx] += solver.sol.cm_array[panel_idx]
334+
# Accumulate geometry for averaging
335+
group_panel.x_airf .+= panel.x_airf
336+
group_panel.y_airf .+= panel.y_airf
337+
group_panel.z_airf .+= panel.z_airf
338+
group_panel.va .+= panel.va
339+
group_panel.chord += panel.chord
340+
group_panel.width += panel.width
325341
panel_idx += 1
326342
panel_count += 1
327343
end
328-
# Average the coefficients over panels in the group
344+
# Average the coefficients and geometry over panels in the group
329345
cl_group_array[group_idx] /= panel_count
330346
cd_group_array[group_idx] /= panel_count
331347
cm_group_array[group_idx] /= panel_count
348+
group_panel.x_airf ./= panel_count
349+
group_panel.y_airf ./= panel_count
350+
group_panel.z_airf ./= panel_count
351+
group_panel.va ./= panel_count
352+
group_panel.chord /= panel_count
353+
group_panel.width /= panel_count
332354
group_idx += 1
333355
end
334356
elseif wing.grouping_method == REFINE
335357
# REFINE method: group refined panels by their original unrefined section
358+
# Initialize group panels
359+
for i in 1:wing.n_groups
360+
target_group_idx = group_idx + i - 1
361+
group_panel = body_aero.groups[target_group_idx]
362+
group_panel.x_airf .= 0.0
363+
group_panel.y_airf .= 0.0
364+
group_panel.z_airf .= 0.0
365+
group_panel.va .= 0.0
366+
group_panel.chord = 0.0
367+
group_panel.width = 0.0
368+
end
336369
# First pass: accumulate values
337370
group_panel_counts = zeros(Int, wing.n_groups)
338371
for local_panel_idx in 1:wing.n_panels
372+
panel = body_aero.panels[panel_idx]
339373
original_section_idx = wing.refined_panel_mapping[local_panel_idx]
340374
target_group_idx = group_idx + original_section_idx - 1
375+
group_panel = body_aero.groups[target_group_idx]
341376
group_moment_dist[target_group_idx] += moment_dist[panel_idx]
342377
group_moment_coeff_dist[target_group_idx] += moment_coeff_dist[panel_idx]
343378
cl_group_array[target_group_idx] += solver.sol.cl_array[panel_idx]
344379
cd_group_array[target_group_idx] += solver.sol.cd_array[panel_idx]
345380
cm_group_array[target_group_idx] += solver.sol.cm_array[panel_idx]
381+
# Accumulate geometry
382+
group_panel.x_airf .+= panel.x_airf
383+
group_panel.y_airf .+= panel.y_airf
384+
group_panel.z_airf .+= panel.z_airf
385+
group_panel.va .+= panel.va
386+
group_panel.chord += panel.chord
387+
group_panel.width += panel.width
346388
group_panel_counts[original_section_idx] += 1
347389
panel_idx += 1
348390
end
349-
# Second pass: average coefficients
391+
# Second pass: average coefficients and geometry
350392
for i in 1:wing.n_groups
351393
target_group_idx = group_idx + i - 1
352394
if group_panel_counts[i] > 0
395+
group_panel = body_aero.groups[target_group_idx]
353396
cl_group_array[target_group_idx] /= group_panel_counts[i]
354397
cd_group_array[target_group_idx] /= group_panel_counts[i]
355398
cm_group_array[target_group_idx] /= group_panel_counts[i]
399+
group_panel.x_airf ./= group_panel_counts[i]
400+
group_panel.y_airf ./= group_panel_counts[i]
401+
group_panel.z_airf ./= group_panel_counts[i]
402+
group_panel.va ./= group_panel_counts[i]
403+
group_panel.chord /= group_panel_counts[i]
404+
group_panel.width /= group_panel_counts[i]
356405
end
357406
end
358407
group_idx += wing.n_groups

0 commit comments

Comments
 (0)