From c24a7946dab249a9ecc902e5196ce10975de02b5 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Fri, 26 Jan 2018 16:22:05 +0100
Subject: [PATCH] Python Module improvements

- cellIntervalToSlice more flexible
---
 python/waLBerla/core_extension.py  | 9 ++++++---
 python/waLBerla/cuda_extension.py  | 3 +++
 src/blockforest/python/Exports.cpp | 2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/python/waLBerla/core_extension.py b/python/waLBerla/core_extension.py
index 8720e3faf..e25e06d1b 100644
--- a/python/waLBerla/core_extension.py
+++ b/python/waLBerla/core_extension.py
@@ -58,13 +58,16 @@ def sliceToCellInterval( s ):
     
 
 def cellIntervalToSlice(cellInterval, collapseExtentOne=True):
+    if not hasattr(collapseExtentOne, '__len__'):
+        collapseExtentOne = (collapseExtentOne, collapseExtentOne, collapseExtentOne)
+
     slices = []
-    for i in range(3):
-        if collapseExtentOne and cellInterval.min[i] == cellInterval.max[i]:
+    for i, collapseInfo in enumerate(collapseExtentOne):
+        if collapseInfo and cellInterval.min[i] == cellInterval.max[i]:
             slices.append( cellInterval.min[i] )
         else:
             slices.append( slice(cellInterval.min[i], cellInterval.max[i]+1,None ) )
-    return slices
+    return tuple(slices)
 
 
 
diff --git a/python/waLBerla/cuda_extension.py b/python/waLBerla/cuda_extension.py
index aecd783cd..e61612b45 100644
--- a/python/waLBerla/cuda_extension.py
+++ b/python/waLBerla/cuda_extension.py
@@ -10,6 +10,9 @@ def toGpuArray(f, withGhostLayers=True):
     dtype = np.dtype(f.dtypeStr)
     strides = [dtype.itemsize*a for a in f.strides]
     res = GPUArray(f.sizeWithGhostLayers, dtype, gpudata=f.ptr, strides=strides)
+    if withGhostLayers is True:
+        return res
+
     ghostLayers = normalizeGhostlayerInfo(f, withGhostLayers)
     glCutoff = [ f.nrOfGhostLayers - gl for gl in ghostLayers ]
     res = res[ glCutoff[0]:-glCutoff[0] if glCutoff[0] > 0 else None,
diff --git a/src/blockforest/python/Exports.cpp b/src/blockforest/python/Exports.cpp
index 096a9f4a4..66fd6c3d9 100644
--- a/src/blockforest/python/Exports.cpp
+++ b/src/blockforest/python/Exports.cpp
@@ -87,7 +87,7 @@ object python_createUniformBlockGrid(tuple args, dict kw)
            *it != "dx" &&
            *it != "oneBlockPerProcess"  )
       {
-         PyErr_SetString( PyExc_ValueError, (std::string("Unknown Parameter") + (*it) ).c_str() );
+         PyErr_SetString( PyExc_ValueError, (std::string("Unknown Parameter: ") + (*it) ).c_str() );
          throw boost::python::error_already_set();
       }
    }
-- 
GitLab