Skip to content

Optimization of multigrid settings#2772

Open
bigfooted wants to merge 34 commits intodevelopfrom
feature_MG_adapt
Open

Optimization of multigrid settings#2772
bigfooted wants to merge 34 commits intodevelopfrom
feature_MG_adapt

Conversation

@bigfooted
Copy link
Copy Markdown
Contributor

@bigfooted bigfooted commented Mar 29, 2026

Proposed Changes

Give a brief overview of your contribution here in a few sentences.

This PR is an improvement of the multigrid method. The goal is to make it more robust and less sensitive to user-defined settings.
It introduces the following:

  1. When the smoother converges sufficiently, we stop the smoothing and exit the smoother.
    This means that the option:
MG_PRE_SMOOTH= ( 5, 5, 5, 5, 5 )
MG_POST_SMOOTH= ( 5, 5, 5, 5, 5 )

effectively becomes the maximum number of iterations that are being performed. The smoothing threshold is given by:
MG_SMOOTH_RES_THRESHOLD=0.5
You can still turn it off using:
MG_SMOOTH_EARLY_EXIT= YES

  1. The damping factors are adaptive. When the smoother converges (exits) within the given number of maximum iterations, the damping factors are increased. When the smoother residuals are larger than the starting residuals, we decrease the damping factor. This means that the option:
MG_DAMP_RESTRICTION= 0.5
MG_DAMP_PROLONGATION= 0.5

effectively becomes a starting damping factor.

  1. Limit the number of MG meshes such that the smallest and coarsest mesh always has more than MG_MIN_MESHSIZE points. This means that the option
    MGLEVEL=4
    effectively becomes a maximum number of MG levels.

  2. We also expose the smoothing coefficient for correction smoothing to the user:
    MG_SMOOTH_COEFF=1.25

  3. fixes multigrid restarts for turbulence problems.

Related Work

Resolve any issues (bug fix or feature request), note any related PRs, or mention interactions with the work of others, if any.
A follow-up to #2712

Will fix #1549

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@bigfooted bigfooted marked this pull request as draft March 29, 2026 20:13
@bigfooted bigfooted changed the title Optimization of multigrid settings [WIP] Optimization of multigrid settings Mar 29, 2026
@bigfooted bigfooted marked this pull request as ready for review April 1, 2026 20:40
@bigfooted bigfooted changed the title [WIP] Optimization of multigrid settings Optimization of multigrid settings Apr 1, 2026
Comment on lines +1344 to +1349
su2double vec[MAXNDIM] = {0.0};
su2double len2 = 0.0;
for (unsigned short d = 0; d < nDim; ++d) {
vec[d] = fine_grid->nodes->GetCoord(jPoint, d) - fine_grid->nodes->GetCoord(current, d);
len2 += vec[d] * vec[d];
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a distance function

Comment on lines +1355 to +1356
su2double dot = 0.0;
for (unsigned short d = 0; d < nDim; ++d) dot += vec[d] * prev_dir[d];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell Claude about GeometryToolbox please


int global_any_stagnant = local_any_stagnant;
int global_all_early = local_all_early;
#ifdef HAVE_MPI
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Comment on lines +397 to +428
{
if (SU2_MPI::GetRank() == MASTER_NODE) {
const unsigned short nMGLevels = config[iZone]->GetnMGLevels();
auto printRow = [&](const char* label,
const unsigned short (&actual)[MAX_MG_LEVELS+1],
auto getMax,
const su2double (&rms)[MAX_MG_LEVELS+1][2],
unsigned short nLevels) {
cout << label;
for (unsigned short i = 0; i <= nLevels; ++i) {
cout << (i == 0 ? "(" : ", ")
<< actual[i] << "/" << getMax(i)
<< " [" << scientific << setprecision(2)
<< rms[i][0] << "->" << rms[i][1]
<< defaultfloat << setprecision(6) << "]";
}
cout << ")\n";
};
printRow("Pre-smooth : ", lastPreSmoothIters,
[&](unsigned short i){ return config[iZone]->GetMG_PreSmooth(i); },
lastPreSmoothRMS, nMGLevels);
printRow("Post-smooth : ", lastPostSmoothIters,
[&](unsigned short i){ return config[iZone]->GetMG_PostSmooth(i); },
lastPostSmoothRMS, nMGLevels - 1);
printRow("Corr.-smooth: ", lastCorrecSmoothIters,
[&](unsigned short i){ return config[iZone]->GetMG_CorrecSmooth(i); },
lastCorrecSmoothRMS, nMGLevels - 1);
cout << fixed << setprecision(4)
<< "Damp. (restr/prolong): " << config[iZone]->GetDamp_Res_Restric()
<< " / " << config[iZone]->GetDamp_Correc_Prolong() << "\n";
cout << defaultfloat << setprecision(6);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the table writer please?

if (iPreSmooth == 0 && iRKStep == 0) {
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
{
lastPreSmoothRMS[iMesh][0] = ComputeLinSysResRMS(solver_fine, geometry_fine);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't compute residuals without threads

if (early_exit && mg_early_exit_flag) {
/*--- Early exit: RMS threshold was met; the RMS that triggered exit is current_rms
* but we don't store it — just do a final read for the output. ---*/
lastPreSmoothRMS[iMesh][1] = ComputeLinSysResRMS(solver_fine, geometry_fine);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why do you need to recompute residuals? Aren't the solvers computing them already?

bigfooted and others added 2 commits April 4, 2026 08:46
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants