-
Notifications
You must be signed in to change notification settings - Fork 920
Fix multigrid agglomeration #2712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
| MG_PRE_SMOOTH= ( 4, 4, 4, 4 ) | ||
| MG_POST_SMOOTH= ( 4, 4, 4, 4 ) | ||
| MG_CORRECTION_SMOOTH= ( 4, 4, 4, 4 ) | ||
| MG_DAMP_RESTRICTION= 0.5 | ||
| MG_DAMP_PROLONGATION= 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When MG is finalized, these will be initial values and will be adaptively changed.
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
| if (nDim == 2) { | ||
| //agglomerate_seed = ((config->GetMarker_All_KindBC(copy_marker[0]) == SEND_RECEIVE) || | ||
| // (config->GetMarker_All_KindBC(copy_marker[1]) == SEND_RECEIVE)); | ||
|
|
||
| /* --- Euler walls can also not be agglomerated when the point has 2 markers ---*/ | ||
| if ((config->GetMarker_All_KindBC(copy_marker[0]) == EULER_WALL) || | ||
| (config->GetMarker_All_KindBC(copy_marker[1]) == EULER_WALL)) { | ||
| agglomerate_seed = false; | ||
| } |
Check notice
Code scanning / CodeQL
Futile conditional Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 days ago
In general, a futile conditional with an empty then-branch and no else-branch should be removed or rewritten so that the condition is either used meaningfully or not evaluated at all. Any explanatory comments should be kept outside of a non-functional if to avoid confusing tools and readers.
For this case in Common/src/geometry/CMultiGridGeometry.cpp, the if (nDim == 2) on line 178 has its logic entirely commented out. The behavior for nDim == 2 is therefore already "do nothing", and the condition serves only as a disabled skeleton. To fix it without changing existing functionality, we should delete the empty if statement (lines 178–181) and retain the commented-out description (or a short note) as plain comments directly in the counter == 2 block. The rest of the logic—especially the if (nDim == 3) agglomerate_seed = (copy_marker[0] == copy_marker[1]); and the curvature-based checks—must remain unchanged.
No new methods, imports, or definitions are needed. The edit is a local cleanup of the empty if block within the shown region.
-
Copy modified lines R177-R180
| @@ -174,11 +174,10 @@ | ||
| /*--- Note that in 2D, this is a corner and we do not agglomerate unless they both are SEND_RECEIVE. ---*/ | ||
| /*--- In 3D, we agglomerate if the 2 markers are the same. ---*/ | ||
| if (counter == 2) { | ||
| /*--- agglomerate if one of the 2 markers are MPI markers. ---*/ | ||
| if (nDim == 2) { | ||
| // agglomerate_seed = ((config->GetMarker_All_KindBC(copy_marker[0]) == SEND_RECEIVE) || | ||
| // (config->GetMarker_All_KindBC(copy_marker[1]) == SEND_RECEIVE)); | ||
| } | ||
| /*--- agglomerate if one of the 2 markers are MPI markers (2D case, currently disabled). ---*/ | ||
| // agglomerate_seed = ((nDim == 2) && | ||
| // ((config->GetMarker_All_KindBC(copy_marker[0]) == SEND_RECEIVE) || | ||
| // (config->GetMarker_All_KindBC(copy_marker[1]) == SEND_RECEIVE))); | ||
| /*--- agglomerate if both markers are the same. ---*/ | ||
| if (nDim == 3) agglomerate_seed = (copy_marker[0] == copy_marker[1]); | ||
|
|
| // /*--- If seed has 2 markers and one is SEND_RECEIVE, do not agglomerate with physical boundary ---*/ | ||
| // if ((marker_seed.size() == 2) && (config->GetMarker_All_KindBC(marker_seed[0]) == SEND_RECEIVE)) { | ||
| // if (copy_marker[0] == marker_seed[1]) { | ||
| // agglomerate_CV = false; | ||
| // } | ||
| // } | ||
| // if ((marker_seed.size() == 2) && (config->GetMarker_All_KindBC(marker_seed[1]) == SEND_RECEIVE)) { | ||
| // if (copy_marker[0] == marker_seed[0]) { | ||
| // agglomerate_CV = false; | ||
| // } | ||
| // } |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 days ago
To fix the problem, we should remove the commented-out code block and, if necessary, replace it with a brief natural-language comment that does not look like code. This avoids confusion, keeps the file clean, and aligns with the recommendation to remove or reinstate commented-out code.
Concretely, in Common/src/geometry/CMultiGridGeometry.cpp, within the if (counter == 1) branch around line 840, delete the commented-out if statements and their bodies (lines 846–856) while leaving the surrounding logic intact. Since this code was already disabled with //, removing it does not alter existing functionality and requires no additional methods, imports, or definitions. If you want to preserve the intent, you can leave or slightly rephrase the existing explanatory comments that are not code-like; in the snippet given, the descriptive comments at 838–843 and 858–860 are already adequate, so we can simply drop the commented-out logic.
| @@ -843,18 +843,6 @@ | ||
| // note that this should be the same marker id, not just the same marker type. | ||
| if ((marker_seed.size() == 1) && (copy_marker[0] == marker_seed[0])) agglomerate_CV = true; | ||
|
|
||
| // /*--- If seed has 2 markers and one is SEND_RECEIVE, do not agglomerate with physical boundary ---*/ | ||
| // if ((marker_seed.size() == 2) && (config->GetMarker_All_KindBC(marker_seed[0]) == SEND_RECEIVE)) { | ||
| // if (copy_marker[0] == marker_seed[1]) { | ||
| // agglomerate_CV = false; | ||
| // } | ||
| // } | ||
| // if ((marker_seed.size() == 2) && (config->GetMarker_All_KindBC(marker_seed[1]) == SEND_RECEIVE)) { | ||
| // if (copy_marker[0] == marker_seed[0]) { | ||
| // agglomerate_CV = false; | ||
| // } | ||
| // } | ||
|
|
||
| /*--- Note: If there is only one marker, but the marker is the SEND_RECEIVE, then the point is actually an | ||
| interior point and we do not agglomerate. ---*/ | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
| /*--- Force sequential execution of recursive calls for determinism ---*/ | ||
| SU2_OMP_BARRIER | ||
| SU2_OMP_MASTER | ||
| { | ||
| // Empty - just ensures only one thread enters the recursion at a time | ||
| } | ||
| END_SU2_OMP_MASTER | ||
| SU2_OMP_BARRIER | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intent here? Right now, it seems equivalent to a plain SU2_OMP_BARRIER.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Johannes, for looking into this. I was testing some OMP stuff because it was giving me non-deterministic results (different convergence nr of iterations per run). I will clean this up as well.
| /*--- Force sequential execution of recursive calls for determinism ---*/ | ||
| SU2_OMP_BARRIER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the leading comment still up to date then? Maybe something like
| /*--- Force sequential execution of recursive calls for determinism ---*/ | |
| SU2_OMP_BARRIER | |
| /*--- Synchronize prior to recursive calls for determinism ---*/ | |
| SU2_OMP_BARRIER |
| /*! | ||
| * \class CMultiGridGeometry | ||
| * \brief Class for defining the multigrid geometry, the main delicated part is the | ||
| * \brief Class for defining the multigrid geometry, the main delegated part is the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dedicated?
| /*--- Multigrid structures. ---*/ | ||
| if (config->GetnMGLevels() > 0) { | ||
| Parent_CV.resize(npoint) = 0; | ||
| Parent_CV.resize(npoint) = ULONG_MAX; // Initialize to ULONG_MAX to indicate unagglomerated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::numeric_limits::max()
| */ | ||
| void SetRestricted_Solution(unsigned short RunTime_EqSystem, CSolver *sol_fine, CSolver *sol_coarse, | ||
| CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config); | ||
| CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config, unsigned short iMesh = 999); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the magic 999?
| 3rd) One marker ---> Surface (always agglomerate) | ||
| 4th) No marker ---> Internal Volume (always agglomerate) ---*/ | ||
|
|
||
| // note that for MPI, we introduce interfaces and we can choose to have agglomeration over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // note that for MPI, we introduce interfaces and we can choose to have agglomeration over | |
| // Note that for MPI, we introduce interfaces and we can choose to have agglomeration over |
| // agglomerate_seed = ((config->GetMarker_All_KindBC(copy_marker[0]) == SEND_RECEIVE) || | ||
| // (config->GetMarker_All_KindBC(copy_marker[1]) == SEND_RECEIVE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wip? or the comment above if counter == 2 needs to be updated?
|
|
||
| /*--- Reset state at the beginning of a new solve (iter 0 or 1) ---*/ | ||
| /*--- This ensures deterministic behavior across multiple runs ---*/ | ||
| static unsigned long last_reset_iter = ULONG_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this gets a bit out of hand xD
| /*--- Update LocalCFL at each coarse grid point ---*/ | ||
| SU2_OMP_FOR_STAT(roundUpDiv(geometry_coarse->GetnPoint(), omp_get_num_threads())) | ||
| for (auto iPoint = 0ul; iPoint < geometry_coarse->GetnPoint(); iPoint++) { | ||
| solver_coarse->GetNodes()->SetLocalCFL(iPoint, CFL_coarse_new); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make a function for the adaptation, please.
|
|
||
| } | ||
|
|
||
| /*--- MPI sync after RK stage to ensure halos have updated solution for next smoothing iteration ---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why this would be necessary, in the whole code we always communicate everything after it is computed, so this is either missing somewhere else, or masking another issue.
|
|
||
| delete [] Solution; | ||
|
|
||
| /*--- Ensure all threads complete before MPI communication ---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, for loops have an implied barrier at the end.
| /*--- Ensure MPI completion visible to all threads ---*/ | ||
| SU2_OMP_BARRIER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about CompleteComms.
We use funneled communications, so I'm pretty sure we have a barrier somewhere in the comms.
Proposed Changes
Give a brief overview of your contribution here in a few sentences.
Implement multigrid agglomeration according to Nishikawa and Diskin.
euler walls are working correctly.
mpi still needs to be checked.
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 --allto 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.