Skip to content

Optimization of multigrid settings#2772

Open
bigfooted wants to merge 45 commits intodevelopfrom
feature_MG_adapt
Open

Optimization of multigrid settings#2772
bigfooted wants to merge 45 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

Copy link
Copy Markdown
Contributor Author

@bigfooted bigfooted Apr 4, 2026

Choose a reason for hiding this comment

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

this one? GeometryToolbox::Distance

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, so computelinsysres outside of the omp loop?

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

getRes_RMS only has the fine grid values, this one computes it on all grid levels.

Comment on lines 3888 to 3891
bool GetMG_Smooth_EarlyExit() const { return MG_Smooth_EarlyExit; }
bool GetMG_Smooth_EarlyExit() const { return MGOptions.MG_Smooth_EarlyExit; }

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.

So the idea is to return a reference to the struct as well, replacing the individual accessors, so that there is just one clean interface for all MG settings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, so we get rid of the individual GetMG_* functions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pcarruscag mmm, like this?
const CMGOptions& GetMGOptions() const { return MGOptions; }
and then we can do this for example:
config[iZone]->GetMGOptions().MG_Smooth_EarlyExit)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked at sstparsedoptions, and copying that instead, it then looks like this:
const auto& mgOptsZone = config[iZone]->GetMGOptions();
if (mgOptsZone.MG_Smooth_EarlyExit) {

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