@@ -51,6 +51,9 @@ Struct for storing the solution of the [solve!](@ref) function. Must contain all
5151 moment_coeff_dist:: MVector{P, Float64} = zeros (P)
5252 group_moment_dist:: MVector{G, Float64} = zeros (G)
5353 group_moment_coeff_dist:: MVector{G, Float64} = zeros (G)
54+ cl_group_array:: MVector{G, Float64} = zeros (G)
55+ cd_group_array:: MVector{G, Float64} = zeros (G)
56+ cm_group_array:: MVector{G, Float64} = zeros (G)
5457 solver_status:: SolverStatus = FAILURE
5558end
5659
@@ -296,8 +299,14 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
296299 if length (solver. sol. group_moment_dist) > 0
297300 group_moment_dist = solver. sol. group_moment_dist
298301 group_moment_coeff_dist = solver. sol. group_moment_coeff_dist
302+ cl_group_array = solver. sol. cl_group_array
303+ cd_group_array = solver. sol. cd_group_array
304+ cm_group_array = solver. sol. cm_group_array
299305 group_moment_dist .= 0.0
300306 group_moment_coeff_dist .= 0.0
307+ cl_group_array .= 0.0
308+ cd_group_array .= 0.0
309+ cm_group_array .= 0.0
301310 panel_idx = 1
302311 group_idx = 1
303312 for wing in body_aero. wings
@@ -306,21 +315,46 @@ function solve!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribution=
306315 # Original method: divide panels into equally-sized sequential groups
307316 panels_per_group = wing. n_panels ÷ wing. n_groups
308317 for _ in 1 : wing. n_groups
318+ panel_count = 0
309319 for _ in 1 : panels_per_group
310320 group_moment_dist[group_idx] += moment_dist[panel_idx]
311321 group_moment_coeff_dist[group_idx] += moment_coeff_dist[panel_idx]
322+ cl_group_array[group_idx] += solver. sol. cl_array[panel_idx]
323+ cd_group_array[group_idx] += solver. sol. cd_array[panel_idx]
324+ cm_group_array[group_idx] += solver. sol. cm_array[panel_idx]
312325 panel_idx += 1
326+ panel_count += 1
313327 end
328+ # Average the coefficients over panels in the group
329+ cl_group_array[group_idx] /= panel_count
330+ cd_group_array[group_idx] /= panel_count
331+ cm_group_array[group_idx] /= panel_count
314332 group_idx += 1
315333 end
316334 elseif wing. grouping_method == REFINE
317335 # REFINE method: group refined panels by their original unrefined section
336+ # First pass: accumulate values
337+ group_panel_counts = zeros (Int, wing. n_groups)
318338 for local_panel_idx in 1 : wing. n_panels
319339 original_section_idx = wing. refined_panel_mapping[local_panel_idx]
320- group_moment_dist[group_idx + original_section_idx - 1 ] += moment_dist[panel_idx]
321- group_moment_coeff_dist[group_idx + original_section_idx - 1 ] += moment_coeff_dist[panel_idx]
340+ target_group_idx = group_idx + original_section_idx - 1
341+ group_moment_dist[target_group_idx] += moment_dist[panel_idx]
342+ group_moment_coeff_dist[target_group_idx] += moment_coeff_dist[panel_idx]
343+ cl_group_array[target_group_idx] += solver. sol. cl_array[panel_idx]
344+ cd_group_array[target_group_idx] += solver. sol. cd_array[panel_idx]
345+ cm_group_array[target_group_idx] += solver. sol. cm_array[panel_idx]
346+ group_panel_counts[original_section_idx] += 1
322347 panel_idx += 1
323348 end
349+ # Second pass: average coefficients
350+ for i in 1 : wing. n_groups
351+ target_group_idx = group_idx + i - 1
352+ if group_panel_counts[i] > 0
353+ cl_group_array[target_group_idx] /= group_panel_counts[i]
354+ cd_group_array[target_group_idx] /= group_panel_counts[i]
355+ cm_group_array[target_group_idx] /= group_panel_counts[i]
356+ end
357+ end
324358 group_idx += wing. n_groups
325359 end
326360 else
0 commit comments