Skip to content

Fix multigrid agglomeration#2712

Open
bigfooted wants to merge 62 commits intodevelopfrom
fix_MG_part_1
Open

Fix multigrid agglomeration#2712
bigfooted wants to merge 62 commits intodevelopfrom
fix_MG_part_1

Conversation

@bigfooted
Copy link
Contributor

@bigfooted bigfooted commented Jan 18, 2026

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

Comment on lines +60 to +64
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
Copy link
Contributor Author

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.

Comment on lines 179 to 183
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

If-statement with an empty then-branch and no else-branch.

Copilot Autofix

AI 4 days ago

In general, to fix a futile conditional you either (a) implement the intended behavior in the if body, or (b) remove the conditional entirely if the behavior is intentionally unused. Both approaches ensure that any if expression has a meaningful effect or is not present at all.

For this code, the 2D block currently does nothing, while 3D has active logic. Implementing the 2D behavior would change the current program semantics, which may not be safe without more context. The safest fix that does not change existing functionality is to remove the empty if (nDim == 2) along with its commented‑out body, and keep the surrounding comments indicating that 2D corners are treated differently. This keeps the runtime behavior identical (no 2D agglomeration here) but removes the futile conditional and clarifies that only the nDim == 3 case is active at this point.

Concretely, in Common/src/geometry/CMultiGridGeometry.cpp, in the block starting at if (counter == 2) {, remove the lines:

          /*--- 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));
          }

and leave the if (nDim == 3) ... branch unchanged. No new methods, imports, or definitions are required.

Suggested changeset 1
Common/src/geometry/CMultiGridGeometry.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp
--- a/Common/src/geometry/CMultiGridGeometry.cpp
+++ b/Common/src/geometry/CMultiGridGeometry.cpp
@@ -174,12 +174,7 @@
         /*--- 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 both markers are the same. ---*/
+          /*--- agglomerate if both markers are the same (3D case). ---*/
           if (nDim == 3) agglomerate_seed = (copy_marker[0] == copy_marker[1]);
 
           /*--- Euler walls: check curvature-based agglomeration criterion for both markers ---*/
EOF
@@ -174,12 +174,7 @@
/*--- 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 both markers are the same. ---*/
/*--- agglomerate if both markers are the same (3D case). ---*/
if (nDim == 3) agglomerate_seed = (copy_marker[0] == copy_marker[1]);

/*--- Euler walls: check curvature-based agglomeration criterion for both markers ---*/
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +848 to +858
// /*--- 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

This comment appears to contain commented-out code.

Copilot Autofix

AI 4 days ago

In general, to fix commented‑out code you either (a) delete it entirely if it is no longer needed, or (b) reinstate it as active code if it reflects current intended behavior. Here, we lack evidence that the SEND_RECEIVE special handling should be active, and enabling it would change the agglomeration logic. To avoid unintended behavioral changes, the best fix is to remove the commented‑out C++ statements while keeping or improving any natural‑language explanation.

Concretely, in Common/src/geometry/CMultiGridGeometry.cpp, inside the if (counter == 1) block around lines 836–856, delete the commented‑out if statements (lines 842–852) that contain full C++ code. Optionally, we can replace them with a brief explanatory English comment if desired, but we should not introduce new logic. No new methods, imports, or definitions are required.

Suggested changeset 1
Common/src/geometry/CMultiGridGeometry.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp
--- a/Common/src/geometry/CMultiGridGeometry.cpp
+++ b/Common/src/geometry/CMultiGridGeometry.cpp
@@ -839,18 +839,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.  ---*/
       }
EOF
@@ -839,18 +839,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. ---*/
}
Copilot is powered by AI and may make mistakes. Always verify output.
bigfooted and others added 4 commits January 28, 2026 17:06
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>
@bigfooted bigfooted changed the title [WIP] Fix multigrid agglomeration Fix multigrid agglomeration Jan 28, 2026
*/
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);
Copy link
Member

Choose a reason for hiding this comment

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

why the magic 999?

Comment on lines +179 to +180
// agglomerate_seed = ((config->GetMarker_All_KindBC(copy_marker[0]) == SEND_RECEIVE) ||
// (config->GetMarker_All_KindBC(copy_marker[1]) == SEND_RECEIVE));
Copy link
Member

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?

bigfooted and others added 12 commits February 3, 2026 19:37
Co-authored-by: Johannes Blühdorn <55186095+jblueh@users.noreply.github.com>
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Comment on lines +563 to +565
// nijso: check if this can be removed now.
//solver_fine->InitiateComms(geometry_fine, config, MPI_QUANTITIES::SOLUTION);
//solver_fine->CompleteComms(geometry_fine, config, MPI_QUANTITIES::SOLUTION);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 4 days ago

In general, to fix commented-out code you either (a) reinstate it as active code where it is actually needed and fully tested, or (b) remove it altogether if it is obsolete or no longer required. If you still want to describe former behavior, use a short natural-language comment instead of code-like text.

For this instance in SU2_CFD/src/integration/CMultiGridIntegration.cpp, the best fix without changing existing functionality is to remove the two commented-out communication calls on lines 564–565 and keep, at most, a concise explanatory comment about MPI sync behavior. The behavior is already “no sync” because the calls are commented out; deleting them preserves runtime behavior but removes the technical debt. Concretely:

  • In the loop over iPostSmooth, under the “MPI sync after RK stage...” comment, delete the two commented-out solver_fine->InitiateComms(...) and solver_fine->CompleteComms(...) lines.
  • Optionally trim the “check if this can be removed now” note to a neutral statement about current behavior (no code snippets), but this is not strictly necessary for the CodeQL issue as long as code-like lines are gone.
    No new methods, imports, or definitions are required.
Suggested changeset 1
SU2_CFD/src/integration/CMultiGridIntegration.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp
--- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp
+++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp
@@ -559,11 +559,10 @@
 
       }
 
-      /*--- MPI sync after RK stage to ensure halos have updated solution for next smoothing iteration ---*/
-      // nijso: check if this can be removed now.
-      //solver_fine->InitiateComms(geometry_fine, config, MPI_QUANTITIES::SOLUTION);
-      //solver_fine->CompleteComms(geometry_fine, config, MPI_QUANTITIES::SOLUTION);
+      /*--- MPI sync after RK stage is currently not performed here; halos are assumed up-to-date for next smoothing iteration. ---*/
 
+
+
     }
   }
 
EOF
@@ -559,11 +559,10 @@

}

/*--- MPI sync after RK stage to ensure halos have updated solution for next smoothing iteration ---*/
// nijso: check if this can be removed now.
//solver_fine->InitiateComms(geometry_fine, config, MPI_QUANTITIES::SOLUTION);
//solver_fine->CompleteComms(geometry_fine, config, MPI_QUANTITIES::SOLUTION);
/*--- MPI sync after RK stage is currently not performed here; halos are assumed up-to-date for next smoothing iteration. ---*/



}
}

Copilot is powered by AI and may make mistakes. Always verify output.
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