From bb81feae51153b88674295ef8cc1b162ffd61507 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Fri, 11 Jul 2025 08:34:03 +0200
Subject: [PATCH] Add code reminders for entities tag to physical tag
 management

---
 src/mesh/GmshReader.cpp | 46 +++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/src/mesh/GmshReader.cpp b/src/mesh/GmshReader.cpp
index c89836dad..5479b9b47 100644
--- a/src/mesh/GmshReader.cpp
+++ b/src/mesh/GmshReader.cpp
@@ -39,8 +39,7 @@ GmshConnectivityBuilder<1>::GmshConnectivityBuilder(const GmshReader::GmshData&
   Array<int> cell_number_vector(nb_cells);
 
   Array<unsigned int> cell_to_node_row(nb_cells + 1);
-  parallel_for(
-    cell_to_node_row.size(), PUGS_LAMBDA(const CellId cell_id) { cell_to_node_row[cell_id] = 2 * cell_id; });
+  parallel_for(cell_to_node_row.size(), PUGS_LAMBDA(const CellId cell_id) { cell_to_node_row[cell_id] = 2 * cell_id; });
 
   Array<unsigned int> cell_to_node_list(cell_to_node_row[cell_to_node_row.size() - 1]);
   for (CellId cell_id = 0; cell_id < nb_cells; ++cell_id) {
@@ -58,7 +57,9 @@ GmshConnectivityBuilder<1>::GmshConnectivityBuilder(const GmshReader::GmshData&
   }
   descriptor.setCellNumberVector(cell_number_vector);
 
+  auto& point_to_physical_tag = gmsh_data.entity_to_physical_tag_map[0];
   std::map<unsigned int, std::vector<unsigned int>> ref_points_map;
+
   for (unsigned int r = 0; r < gmsh_data.point_entity.size(); ++r) {
     const unsigned int point_number = gmsh_data.point_entity[r];
     ref_points_map[gmsh_data.point_entity_ref[r]].push_back(point_number);
@@ -119,7 +120,9 @@ GmshConnectivityBuilder<1>::GmshConnectivityBuilder(const GmshReader::GmshData&
     descriptor.addRefItemList(RefNodeList(ref_id, point_list, list_type));
   }
 
+  auto& cell_to_physical_tag = gmsh_data.entity_to_physical_tag_map[1];
   std::map<unsigned int, std::vector<unsigned int>> ref_cells_map;
+
   for (unsigned int j = 0; j < gmsh_data.edge_entity_ref.size(); ++j) {
     const unsigned int elem_number = j;
     ref_cells_map[gmsh_data.edge_entity_ref[j]].push_back(elem_number);
@@ -215,6 +218,7 @@ GmshConnectivityBuilder<2>::GmshConnectivityBuilder(const GmshReader::GmshData&
 
   auto& cell_to_physical_tag = gmsh_data.entity_to_physical_tag_map[2];
   std::map<unsigned int, std::vector<unsigned int>> ref_cells_map;
+
   for (unsigned int j = 0; j < gmsh_data.triangle_entity_ref.size(); ++j) {
     const unsigned int elem_number = j;
     auto ref_range                 = cell_to_physical_tag.equal_range(gmsh_data.triangle_entity_ref[j]);
@@ -225,7 +229,10 @@ GmshConnectivityBuilder<2>::GmshConnectivityBuilder(const GmshReader::GmshData&
 
   for (unsigned int j = 0; j < gmsh_data.quadrangle_entity_ref.size(); ++j) {
     const size_t elem_number = nb_triangles + j;
-    ref_cells_map[gmsh_data.quadrangle_entity_ref[j]].push_back(elem_number);
+    auto ref_range           = cell_to_physical_tag.equal_range(gmsh_data.quadrangle_entity_ref[j]);
+    for (auto i_ref = ref_range.first; i_ref != ref_range.second; ++i_ref) {
+      ref_cells_map[i_ref->second].push_back(elem_number);
+    }
   }
 
   for (const auto& ref_cell_list : ref_cells_map) {
@@ -281,7 +288,10 @@ GmshConnectivityBuilder<2>::GmshConnectivityBuilder(const GmshReader::GmshData&
   };
 
   Array<int> face_number_vector = copy(descriptor.faceNumberVector());
+
+  auto& face_to_physical_tag = gmsh_data.entity_to_physical_tag_map[1];
   std::map<unsigned int, std::vector<unsigned int>> ref_faces_map;
+
   for (unsigned int e = 0; e < gmsh_data.edge_entity.size(); ++e) {
     const unsigned int edge_id = find_face(gmsh_data.edge_entity[e][0], gmsh_data.edge_entity[e][1]);
 
@@ -373,7 +383,9 @@ GmshConnectivityBuilder<2>::GmshConnectivityBuilder(const GmshReader::GmshData&
     }
   }
 
+  auto& point_to_physical_tag = gmsh_data.entity_to_physical_tag_map[0];
   std::map<unsigned int, std::vector<unsigned int>> ref_points_map;
+
   for (unsigned int r = 0; r < gmsh_data.point_entity.size(); ++r) {
     const unsigned int point_number = gmsh_data.point_entity[r];
     ref_points_map[gmsh_data.point_entity_ref[r]].push_back(point_number);
@@ -531,7 +543,9 @@ GmshConnectivityBuilder<3>::GmshConnectivityBuilder(const GmshReader::GmshData&
   descriptor.setCellTypeVector(cell_type_vector);
   descriptor.setCellToNodeMatrix(ConnectivityMatrix(cell_to_node_row, cell_to_node_list));
 
+  auto& cell_to_physical_tag = gmsh_data.entity_to_physical_tag_map[3];
   std::map<unsigned int, std::vector<unsigned int>> ref_cells_map;
+
   for (unsigned int j = 0; j < gmsh_data.tetrahedron_entity_ref.size(); ++j) {
     const unsigned int elem_number = j;
     ref_cells_map[gmsh_data.tetrahedron_entity_ref[j]].push_back(elem_number);
@@ -654,7 +668,10 @@ GmshConnectivityBuilder<3>::GmshConnectivityBuilder(const GmshReader::GmshData&
     };
 
     Array<int> face_number_vector = copy(descriptor.faceNumberVector());
+
+    auto& face_to_physical_tag = gmsh_data.entity_to_physical_tag_map[2];
     std::map<unsigned int, std::vector<unsigned int>> ref_faces_map;
+
     for (unsigned int f = 0; f < gmsh_data.triangle_entity.size(); ++f) {
       const unsigned int face_id =
         find_face({gmsh_data.triangle_entity[f][0], gmsh_data.triangle_entity[f][1], gmsh_data.triangle_entity[f][2]});
@@ -800,7 +817,10 @@ GmshConnectivityBuilder<3>::GmshConnectivityBuilder(const GmshReader::GmshData&
     }();
 
     Array<int> edge_number_vector = copy(descriptor.edgeNumberVector());
+
+    auto& edge_to_physical_tag = gmsh_data.entity_to_physical_tag_map[1];
     std::map<unsigned int, std::vector<unsigned int>> ref_edges_map;
+
     for (unsigned int e = 0; e < gmsh_data.edge_entity.size(); ++e) {
       const unsigned int edge_id = find_edge(gmsh_data.edge_entity[e][0], gmsh_data.edge_entity[e][1]);
 
@@ -874,7 +894,9 @@ GmshConnectivityBuilder<3>::GmshConnectivityBuilder(const GmshReader::GmshData&
     }
   }
 
+  auto& point_to_physical_tag = gmsh_data.entity_to_physical_tag_map[0];
   std::map<unsigned int, std::vector<unsigned int>> ref_points_map;
+
   for (unsigned int r = 0; r < gmsh_data.point_entity.size(); ++r) {
     const unsigned int point_number = gmsh_data.point_entity[r];
     ref_points_map[gmsh_data.point_entity_ref[r]].push_back(point_number);
@@ -1058,8 +1080,7 @@ inline auto remove_embedding_spaces = [](std::string_view line) -> std::string_v
 
 inline constexpr int number_of_gmsh_entities = 93;
 
-inline constexpr auto primitive_number_of_nodes = []() constexpr
-{
+inline constexpr auto primitive_number_of_nodes = []() constexpr {
   std::array<short, number_of_gmsh_entities> number_of_nodes;
   number_of_nodes.fill(-1);
 
@@ -1098,11 +1119,9 @@ inline constexpr auto primitive_number_of_nodes = []() constexpr
   number_of_nodes[92] = 125;   // 125-node fourth order hexahedron
 
   return number_of_nodes;
-}
-();
+}();
 
-inline constexpr auto entity_name = []() constexpr
-{
+inline constexpr auto entity_name = []() constexpr {
   std::array<std::string_view, number_of_gmsh_entities> name;
   name.fill("unknown");
   name[0]  = "edges";
@@ -1140,11 +1159,9 @@ inline constexpr auto entity_name = []() constexpr
   name[92] = "125-node fourth order hexahedron";
 
   return name;
-}
-();
+}();
 
-inline constexpr auto supported_entity = []() constexpr
-{
+inline constexpr auto supported_entity = []() constexpr {
   std::array<bool, number_of_gmsh_entities> supported;
   supported.fill(false);
   supported[0]  = true;   // edge
@@ -1157,8 +1174,7 @@ inline constexpr auto supported_entity = []() constexpr
   supported[14] = true;   // point
 
   return supported;
-}
-();
+}();
 
 inline auto tokenize = [](std::string_view& line, auto& tokens) {
   size_t token_idx = 0;
-- 
GitLab