From dd542beb1daabc33434073695aca3687629f356f Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Fri, 22 Mar 2019 11:00:26 +0100
Subject: [PATCH] walberla coupling modules are tested as well

---
 pystencils/boundaries/createindexlist.py      | 23 ++++++++-----------
 .../boundaries/createindexlistcython.pyx      |  4 ++--
 2 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/pystencils/boundaries/createindexlist.py b/pystencils/boundaries/createindexlist.py
index 6fcedea..d039e16 100644
--- a/pystencils/boundaries/createindexlist.py
+++ b/pystencils/boundaries/createindexlist.py
@@ -47,28 +47,24 @@ def _create_boundary_neighbor_index_list_python(flag_field_arr, nr_of_ghost_laye
     return np.array(result, dtype=index_arr_dtype)
 
 
-def _create_boundary_cell_index_list_python(flag_field_arr, nr_of_ghost_layers, boundary_mask,
+def _create_boundary_cell_index_list_python(flag_field_arr, boundary_mask,
                                             fluid_mask, stencil, single_link):
     coordinate_names = boundary_index_array_coordinate_names[:len(flag_field_arr.shape)]
     index_arr_dtype = np.dtype([(name, np.int32) for name in coordinate_names] + [(direction_member_name, np.int32)])
 
     result = []
-    gl = nr_of_ghost_layers
-    for cell in itertools.product(*reversed([range(gl, i - gl) for i in flag_field_arr.shape])):
+    for cell in itertools.product(*reversed([range(0, i) for i in flag_field_arr.shape])):
         cell = cell[::-1]
         if not flag_field_arr[cell] & boundary_mask:
             continue
         for dir_idx, direction in enumerate(stencil):
             neighbor_cell = tuple([cell_i + dir_i for cell_i, dir_i in zip(cell, direction)])
-            neighbor_is_fluid = False
-            try:
-                neighbor_is_fluid = flag_field_arr[neighbor_cell] & fluid_mask
-            except IndexError:
-                pass
-            if neighbor_is_fluid:
+            if any(not 0 <= e < upper for e, upper in zip(neighbor_cell, flag_field_arr.shape)):
+                continue
+            if flag_field_arr[neighbor_cell] & fluid_mask:
                 result.append(cell + (dir_idx,))
                 if single_link:
-                    continue
+                    break
 
     return np.array(result, dtype=index_arr_dtype)
 
@@ -95,18 +91,19 @@ def create_boundary_index_list(flag_field, stencil, boundary_mask, fluid_mask,
 
     stencil = np.array(stencil, dtype=np.int32)
     args = (flag_field, nr_of_ghost_layers, boundary_mask, fluid_mask, stencil, single_link)
+    args_no_gl = (flag_field, boundary_mask, fluid_mask, stencil, single_link)
 
     if cython_funcs_available:
         if dim == 2:
             if inner_or_boundary:
                 idx_list = create_boundary_neighbor_index_list_2d(*args)
             else:
-                idx_list = create_boundary_cell_index_list_2d(*args)
+                idx_list = create_boundary_cell_index_list_2d(*args_no_gl)
         elif dim == 3:
             if inner_or_boundary:
                 idx_list = create_boundary_neighbor_index_list_3d(*args)
             else:
-                idx_list = create_boundary_cell_index_list_3d(*args)
+                idx_list = create_boundary_cell_index_list_3d(*args_no_gl)
         else:
             raise ValueError("Flag field has to be a 2 or 3 dimensional numpy array")
         return np.array(idx_list, dtype=index_arr_dtype)
@@ -116,7 +113,7 @@ def create_boundary_index_list(flag_field, stencil, boundary_mask, fluid_mask,
         if inner_or_boundary:
             return _create_boundary_neighbor_index_list_python(*args)
         else:
-            return _create_boundary_cell_index_list_python(*args)
+            return _create_boundary_cell_index_list_python(*args_no_gl)
 
 
 def create_boundary_index_array(flag_field, stencil, boundary_mask, fluid_mask, boundary_object,
diff --git a/pystencils/boundaries/createindexlistcython.pyx b/pystencils/boundaries/createindexlistcython.pyx
index 90a0b1d..b196f26 100644
--- a/pystencils/boundaries/createindexlistcython.pyx
+++ b/pystencils/boundaries/createindexlistcython.pyx
@@ -69,7 +69,7 @@ def create_boundary_neighbor_index_list_3d(object[IntegerType, ndim=3] flag_fiel
 @cython.boundscheck(False) # turn off bounds-checking for entire function
 @cython.wraparound(False)  # turn off negative index wrapping for entire function
 def create_boundary_cell_index_list_2d(object[IntegerType, ndim=2] flag_field,
-                                       int nr_of_ghost_layers, IntegerType boundary_mask, IntegerType fluid_mask,
+                                       IntegerType boundary_mask, IntegerType fluid_mask,
                                        object[int, ndim=2] stencil, int single_link):
     cdef int xs, ys, x, y
     cdef int dirIdx, num_directions, dx, dy
@@ -95,7 +95,7 @@ def create_boundary_cell_index_list_2d(object[IntegerType, ndim=2] flag_field,
 @cython.boundscheck(False) # turn off bounds-checking for entire function
 @cython.wraparound(False)  # turn off negative index wrapping for entire function
 def create_boundary_cell_index_list_3d(object[IntegerType, ndim=3] flag_field,
-                                       int nr_of_ghost_layers, IntegerType boundary_mask, IntegerType fluid_mask,
+                                       IntegerType boundary_mask, IntegerType fluid_mask,
                                        object[int, ndim=2] stencil, int single_link):
     cdef int xs, ys, zs, x, y, z
     cdef int dirIdx, num_directions, dx, dy, dz
-- 
GitLab