From 3cf1dc5d03964b87ca1a7793cfdb026dcfcc62ab Mon Sep 17 00:00:00 2001
From: Julian Heinze <julian.heinze@ufz.de>
Date: Tue, 19 Mar 2024 11:06:44 +0100
Subject: [PATCH] code improvements to be more readible and comprehensive

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

diff --git a/ogstools/feflowlib/tools.py b/ogstools/feflowlib/tools.py
index d2cbfa0b5..f9ffd6e8a 100644
--- a/ogstools/feflowlib/tools.py
+++ b/ogstools/feflowlib/tools.py
@@ -84,29 +84,25 @@ def extract_point_boundary_conditions(
     :rtype: dict
     """
     dict_of_point_boundary_conditions = {}
+    # Assigning bulk node ids because format needs to be unsigned integer for OGS.
+    # Otherwise vtkOriginalPointIds would be fine.
     assign_bulk_ids(mesh)
     # extract mesh since boundary condition are on the surface ?! (not safe!)
     surf_mesh = mesh.extract_surface()
     # remove all the point data that are not of interest
     for point_data in surf_mesh.point_data:
-        if not all(["_BC" in point_data]) and point_data != "bulk_node_ids":
+        if "_BC" not in point_data and point_data != "bulk_node_ids":
             surf_mesh.point_data.remove(point_data)
     # remove all points with point data that are of "nan"-value
     for point_data in surf_mesh.point_data:
         if point_data != "bulk_node_ids":
-            dirichlet_bool = "_BC_" not in point_data
-            if "_4TH" in point_data:
-                filtered_points = mesh.extract_points(
-                    [not np.isnan(x) for x in mesh[point_data]],
-                    adjacent_cells=False,
-                    include_cells=False,
-                )
-            else:
-                filtered_points = surf_mesh.extract_points(
-                    [not np.isnan(x) for x in surf_mesh[point_data]],
-                    adjacent_cells=False,
-                    include_cells=dirichlet_bool,
-                )
+            BC_2nd_or_3rd = "2ND" in point_data or "3RD" in point_data
+            filter_mesh = mesh if "_4TH" in point_data else surf_mesh
+            filtered_points = filter_mesh.extract_points(
+                [not np.isnan(x) for x in filter_mesh[point_data]],
+                adjacent_cells=False,
+                include_cells=BC_2nd_or_3rd,
+            )
             # Only selected point data is needed -> clear all cell data instead of the bulk_element_ids
             for cell_data in filtered_points.cell_data:
                 if cell_data != "bulk_element_ids":
-- 
GitLab