From d9145a59fce5095160abc0732dcebadf4e51137f Mon Sep 17 00:00:00 2001
From: Julian Heinze <julian.heinze@ufz.de>
Date: Tue, 19 Mar 2024 10:43:19 +0100
Subject: [PATCH] use function to remove bulk ids

---
 ogstools/feflowlib/tools.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/ogstools/feflowlib/tools.py b/ogstools/feflowlib/tools.py
index 6c8c95aea..d2cbfa0b5 100644
--- a/ogstools/feflowlib/tools.py
+++ b/ogstools/feflowlib/tools.py
@@ -48,10 +48,9 @@ def get_specific_surface(surface_mesh: pv.PolyData, filter_condition):
 
 def assign_bulk_ids(mesh: pv.UnstructuredGrid):
     """
-    Add fields bulk_node_ids and bulk_element_ids to the given bulk mesh.
+    Add data arrays for bulk_node_ids and bulk_element_ids to the given bulk mesh.
 
-    :param mesh_name: name of the mesh
-    :type mesh_name: str
+    :param mesh: bulk mesh
     """
     # The format must be unsigned integer, as it is required by OGS
     mesh["bulk_node_ids"] = np.arange(mesh.n_points, dtype=np.uint64)
@@ -60,6 +59,16 @@ def assign_bulk_ids(mesh: pv.UnstructuredGrid):
     )
 
 
+def remove_bulk_ids(mesh: pv.UnstructuredGrid):
+    """
+    Remove data arrays for bulk_node_ids and bulk_element_ids of the given bulk mesh.
+
+    :param mesh: bulk mesh
+    """
+    mesh.point_data.remove("bulk_node_ids")
+    mesh.cell_data.remove("bulk_element_ids")
+
+
 def extract_point_boundary_conditions(
     out_mesh_path: Path, mesh: pv.UnstructuredGrid
 ):
@@ -111,8 +120,7 @@ def extract_point_boundary_conditions(
                 str(out_mesh_path / point_data) + ".vtu"
             ] = filtered_points
     # Remove bulk node/element ids from bulk mesh, as they are not needed anymore.
-    mesh.point_data.remove("bulk_node_ids")
-    mesh.cell_data.remove("bulk_element_ids")
+    remove_bulk_ids(mesh)
     return dict_of_point_boundary_conditions
 
 
@@ -172,8 +180,7 @@ def extract_cell_boundary_conditions(
     # correct unit for P_IOFLOW, in FEFLOW m/d in ogs m/s
     topsurf.cell_data["P_IOFLOW"] = topsurf.cell_data["P_IOFLOW"]
     # Remove bulk node/element ids from bulk mesh, as they are not needed anymore.
-    mesh.point_data.remove("bulk_node_ids")
-    mesh.cell_data.remove("bulk_element_ids")
+    remove_bulk_ids(mesh)
     return (
         bulk_mesh_path.with_stem("topsurface_" + bulk_mesh_path.stem),
         topsurf,
-- 
GitLab