Skip to content

Fix surface elements lost when several markers are plotted - #3027

Open
rois1995 wants to merge 2 commits into
developfrom
fix_surface_sort_markers
Open

rois1995 wants to merge 2 commits into
developfrom
fix_surface_sort_markers

Conversation

@rois1995

Copy link
Copy Markdown
Contributor

Problem

The surface output can miss elements when MARKER_PLOTTING lists more than one marker.
The surface sorter remembers the last element it visited. The element numbers restart at zero on each marker, but this memory was not reset between markers. So an element of the next marker could be taken as already visited and dropped.

Example: a 2x2x2 box mesh with all 6 faces as plotting markers writes only 1 face instead of 6.

All surface output formats are affected.

Fix

  • Reset the visited flags at the start of each marker, in the counting and in the packing loop of CSurfaceFVMDataSorter::SortSurfaceConnectivity.
  • CPhysicalGeometry already resets these flags per marker in the same kind of loop.

Tests

  • New unit test UnitTests/SU2_CFD/output/CSurfaceFVMDataSorter_tests.cpp. It counts the surface elements of a box mesh for several marker lists.
  • Without the fix, the test fails.

Related

PR Checklist

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

🤖 Generated with Claude Code

The duplicate-visit flags of the surface connectivity sort were kept across
markers, but boundary element indices restart at zero on each marker, so an
element could be taken as already visited and dropped from the surface output.
Reset the flags for each marker, and add a unit test with a box mesh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

if (it != markerList.end()) {
/*--- Element indices restart at zero for each marker. ---*/
std::fill(nElem_Flag, nElem_Flag + size, -1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional simplification: the target rank comes from the lowest global index over all nodes of the element, so it is the same on every jj iteration. Computing it once per element removes the jj loop, and with it the need for nElem_Flag and this per-marker reset.

Counting pass (replaces the ii loop here):

      for (int ii = 0; ii < (int)geometry->GetnElem_Bound(iMarker); ii++) {

        if (geometry->bound[iMarker][ii]->GetVTK_Type() == Elem_Type) {

          /*--- Send the element to the rank owning its lowest global node index. ---*/

          Global_Index = geometry->nodes->GetGlobalIndex(geometry->bound[iMarker][ii]->GetNode(0));
          for (int kk = 1; kk < NODES_PER_ELEMENT; kk++) {
            jPoint = geometry->bound[iMarker][ii]->GetNode(kk);
            unsigned long newID = geometry->nodes->GetGlobalIndex(jPoint);
            if (newID < Global_Index) Global_Index = newID;
          }

          iProcessor = linearPartitioner.GetRankContainingIndex(Global_Index);
          nElem_Send[iProcessor+1]++;
        }
      }

Send pass (replaces the ii loop at line 1265):

      for (int ii = 0; ii < (int)geometry->GetnElem_Bound(iMarker); ii++) {

        if (geometry->bound[iMarker][ii]->GetVTK_Type() == Elem_Type) {

          /*--- Send the element to the rank owning its lowest global node index. ---*/

          Global_Index = geometry->nodes->GetGlobalIndex(geometry->bound[iMarker][ii]->GetNode(0));
          for (int kk = 1; kk < NODES_PER_ELEMENT; kk++) {
            jPoint = geometry->bound[iMarker][ii]->GetNode(kk);
            unsigned long newID = geometry->nodes->GetGlobalIndex(jPoint);
            if (newID < Global_Index) Global_Index = newID;
          }

          iProcessor = linearPartitioner.GetRankContainingIndex(Global_Index);

          /*--- Load connectivity into the buffer for sending ---*/

          unsigned long nn = index[iProcessor];
          unsigned long mm = haloIndex[iProcessor];

          for (int kk = 0; kk < NODES_PER_ELEMENT; kk++) {
            iPoint = geometry->bound[iMarker][ii]->GetNode(kk);
            connSend[nn] = geometry->nodes->GetGlobalIndex(iPoint); nn++;

            /*--- Flag the element as halo if any of its nodes is a halo node. ---*/

            if (volumeSorter->GetHalo(iPoint)) haloSend[mm] = true;
          }

          index[iProcessor] += NODES_PER_ELEMENT;
          haloIndex[iProcessor]++;
        }
      }

With both passes changed, nElem_Flag is unused, so its allocation, the reset loop before the send pass, and its delete can be removed as well.

@bigfooted bigfooted left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, check my comment and see if it makes sense.

This branch has not been deployed

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

2 participants