Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SU2_CFD/src/output/filewriter/CSurfaceFVMDataSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,8 @@ void CSurfaceFVMDataSorter::SortSurfaceConnectivity(CConfig *config, CGeometry *
auto it = std::find(markerList.begin(), markerList.end(), markerTag);

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.


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

Expand Down Expand Up @@ -1257,6 +1259,8 @@ void CSurfaceFVMDataSorter::SortSurfaceConnectivity(CConfig *config, CGeometry *
auto it = std::find(markerList.begin(), markerList.end(), markerTag);

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

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

Expand Down
64 changes: 64 additions & 0 deletions UnitTests/SU2_CFD/output/CSurfaceFVMDataSorter_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*!
* \file CSurfaceFVMDataSorter_tests.cpp
* \brief Tests of the surface connectivity sorting of the FVM output.
* \version 8.6.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/

#include "catch.hpp"

#include <string>
#include <vector>

#include "../../UnitQuadTestCase.hpp"
#include "../../../SU2_CFD/include/output/filewriter/CFVMDataSorter.hpp"
#include "../../../SU2_CFD/include/output/filewriter/CSurfaceFVMDataSorter.hpp"

namespace {

/*--- Number of quadrilaterals in the sorted surface connectivity of the given markers of a box mesh. ---*/
unsigned long CountSurfaceQuads(const std::string& boxSize, const std::vector<std::string>& markers) {
UnitQuadTestCase test;
test.SetOption("MESH_BOX_SIZE=" + boxSize);
test.InitConfig();
test.InitGeometry();

CFVMDataSorter volumeSorter(test.config.get(), test.geometry.get(), {"x", "y", "z"});
CSurfaceFVMDataSorter surfaceSorter(test.config.get(), test.geometry.get(), &volumeSorter);
surfaceSorter.SortConnectivity(test.config.get(), test.geometry.get(), markers);

return surfaceSorter.GetnElemGlobal(QUADRILATERAL);
}

const std::vector<std::string> allMarkers = {"x_minus", "x_plus", "y_minus", "y_plus", "z_minus", "z_plus"};

} // namespace

TEST_CASE("Surface sorting keeps the elements of every marker", "[Output]") {
/*--- One element per marker: the element index is 0 on every marker. ---*/
CHECK(CountSurfaceQuads("2,2,2", allMarkers) == 6);
CHECK(CountSurfaceQuads("2,2,2", {"x_minus", "z_plus"}) == 2);
CHECK(CountSurfaceQuads("2,2,2", {"y_plus"}) == 1);

/*--- 4x4 elements per marker. ---*/
CHECK(CountSurfaceQuads("5,5,5", allMarkers) == 6 * 16);
}
1 change: 1 addition & 0 deletions UnitTests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ su2_cfd_tests = files(['Common/CConfig_tests.cpp',
'SU2_CFD/fluid/CFluidModel_tests.cpp',
'SU2_CFD/output/CNEMOCompOutput_tests.cpp',
'SU2_CFD/output/COutput_convergence_tests.cpp',
'SU2_CFD/output/CSurfaceFVMDataSorter_tests.cpp',
'SU2_CFD/gradients.cpp',
'SU2_CFD/adaptive_metric.cpp',
'SU2_CFD/periodic_limiters.cpp',
Expand Down