@@ -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