SU2 icon indicating copy to clipboard operation
SU2 copied to clipboard

Output the location of the maximum residual to the history file (MAX_RES_LOC)

Open Syphonicc opened this issue 2 months ago • 0 comments

Is your feature request related to a problem? Please describe.

When a case stalls or diverges, the history file tells you that something is wrong (MAX_*, RMS_*) but not where. The usual workflow is to wait for the crash (or stop the run), write volume output, and hunt for the bad cells in ParaView.

SU2 already computes this information every iteration. CSolver::ResidualReductions_FromAllThreads records the global index and coordinates of the point with the maximum residual for each variable (AddRes_Max), and CSolver::SetResidual_RMS reduces them across ranks when COMM_LEVEL=FULL (the default). Getters exist (GetPoint_Max, GetPoint_Max_Coord), but the data is not exposed to any output, so we pay three Allreduce calls per solver per iteration for values that are discarded.

Describe the solution you'd like

A new opt-in history group, MAX_RES_LOC, that writes the global point index and coordinates of the maximum residual of each solution variable:

  • MAXLOC_ID-<SOLVER>_<iVar>, MAXLOC_X-<SOLVER>_<iVar>, MAXLOC_Y-..., MAXLOC_Z-... (Z in 3D only), where the variable ordering follows the existing MAX_RES fields.
  • Implemented as one generic register/load helper pair in CFlowOutput that loops over nVar of a given solver, called for the flow solver (comp/inc/NEMO) and the turbulence solver, so no per-variable code is duplicated.
  • Off by default: existing history output and regression results are unchanged unless MAX_RES_LOC is added to HISTORY_OUTPUT.
  • If COMM_LEVEL is not FULL, the fields are written as NaN with a one-time warning (the location is not globally reduced in that case).

While going through this code I also noticed that, if two ranks hold the exact same maximum residual, the MPI_MAX reduction of Point_Max_Coord in SetResidual_RMS can mix coordinate components from both ranks. I'd fix that in the same PR by keeping the coordinates only on the rank that owns the winning global index.

Use cases:

  • Seeing live whether a stalled residual is pinned to a fixed region (e.g. a bad cell at a trailing edge or a far-field corner) or moves with the flow.
  • After a divergence, knowing where it started, with a point ID to jump to directly in ParaView.
  • Enabling external monitoring tools to report the location live. I maintain a small terminal monitor for SU2 history files (su2live) and would add support for this group.

Describe alternatives you've considered

  • Writing volume output more often and inspecting the residual fields: expensive on large meshes and only gives snapshots.
  • A field per named variable (MAXLOC_X_DENSITY, …): more readable, but it would duplicate the per-solver variable mapping already spread across CFlowCompOutput, CFlowIncOutput and CNEMOCompOutput. Index-based naming keeps it to one generic helper. Happy to go the other way if you prefer.
  • Printing the location to screen only (as older versions did for some solvers): not machine-readable and not available for post-processing.

Additional context

I'd like to take this on myself and open a PR against develop (new history group, the helper functions, the tie fix, a config_template.cfg entry, and a regression test on TestCases/euler/naca0012 checking that serial and parallel runs report the same location). Before I start, is this something you'd accept, and do you have any preference on field naming or scope (e.g. flow + turbulence first, other solvers later)?

Syphonicc avatar Sep 26 '26 17:09 Syphonicc