From d52d78ebcf1f207dca5f10efdf7403049094ac77 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 29 Nov 2022 15:29:44 +0100
Subject: [PATCH] [MeL] Implement function getBulkIDString()

Using the function avoids the distribution of the magic names 'bulk_node_ids',
'bulk_element_ids', and 'bulk_face_ids' to several places in OGS.
---
 MeshLib/Properties.cpp | 30 ++++++++++++++++++++++++++++++
 MeshLib/Properties.h   |  6 ++++++
 2 files changed, 36 insertions(+)

diff --git a/MeshLib/Properties.cpp b/MeshLib/Properties.cpp
index 7b3d9de170c..ab46c0179f1 100644
--- a/MeshLib/Properties.cpp
+++ b/MeshLib/Properties.cpp
@@ -174,4 +174,34 @@ std::map<std::string, PropertyVectorBase*>::size_type Properties::size(
                     [&](auto const p)
                     { return p.second->getMeshItemType() == mesh_item_type; });
 }
+
+std::string getBulkIDString(MeshItemType mesh_item_type)
+{
+    switch (mesh_item_type)
+    {
+        case MeshItemType::Node:
+            return "bulk_node_ids";
+            break;
+        case MeshItemType::Cell:
+            return "bulk_element_ids";
+            break;
+        case MeshItemType::Edge:
+            return "bulk_edge_ids";
+            break;
+        case MeshItemType::Face:
+            return "bulk_face_ids";
+            break;
+        case MeshItemType::IntegrationPoint:
+            OGS_FATAL("MeshItemType::IntegrationPoint is not handled.");
+            return "";
+            break;
+        default:
+            OGS_FATAL(
+                "Unknown mesh item type. At the moment only for mesh item "
+                "types 'Node', 'Cell', and 'Face' mapping names are "
+                "specified.");
+            return "";
+    }
+}
+
 }  // end namespace MeshLib
diff --git a/MeshLib/Properties.h b/MeshLib/Properties.h
index 51d1155bd1a..1e4b0ca46a7 100644
--- a/MeshLib/Properties.h
+++ b/MeshLib/Properties.h
@@ -173,6 +173,12 @@ private:
 template <typename Function>
 void applyToPropertyVectors(Properties const& properties, Function f);
 
+/// Returns the mapping MeshItemType -> bulk ID property name, i.e.
+/// MeshItemType::Node -> bulk_node_ids
+/// MeshItemType::Cell -> bulk_element_ids
+/// MeshItemType::Face -> bulk_face_ids
+std::string getBulkIDString(MeshItemType mesh_item_type);
+
 #include "Properties-impl.h"
 
 } // end namespace MeshLib
-- 
GitLab