From 8d278092f0685e4420eb370ce03d0d1f1c7bea62 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Sat, 17 Jun 2017 21:30:17 +0200
Subject: [PATCH] Started implementation of parallel waLBerla based scenarios

---
 field.py   | 24 ++++++++++++++++++------
 slicing.py |  2 ++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/field.py b/field.py
index 79984f373..6a00e61f5 100644
--- a/field.py
+++ b/field.py
@@ -61,12 +61,8 @@ class Field(object):
                        the outer loop loops over dimension 2, the second outer over dimension 1, and the inner loop
                        over dimension 0. Also allowed: the strings 'numpy' (0,1,..d) or 'reverseNumpy' (d, ..., 1, 0)
         """
-        if isinstance(layout, str) and (layout == 'numpy' or layout.lower() == 'c'):
-            layout = tuple(range(spatialDimensions))
-        elif isinstance(layout, str) and (layout == 'reverseNumpy' or layout.lower() == 'f'):
-            layout = tuple(reversed(range(spatialDimensions)))
-        if len(layout) != spatialDimensions:
-            raise ValueError("Layout")
+        if isinstance(layout, str):
+            layout = layoutStringToTuple(layout, dim=spatialDimensions)
         shapeSymbol = IndexedBase(TypedSymbol(Field.SHAPE_PREFIX + fieldName, Field.SHAPE_DTYPE), shape=(1,))
         strideSymbol = IndexedBase(TypedSymbol(Field.STRIDE_PREFIX + fieldName, Field.STRIDE_DTYPE), shape=(1,))
         totalDimensions = spatialDimensions + indexDimensions
@@ -409,6 +405,22 @@ def createNumpyArrayWithLayout(shape, layout):
     return res
 
 
+def layoutStringToTuple(layoutStr, dim):
+    if layoutStr in ('fzyx', 'zyxf') and dim != 4:
+        if dim == 3:
+            return tuple(reversed(range(dim)))
+        else:
+            raise ValueError("Layout descriptor " + layoutStr + " only valid for dimension 4, not %d" % (dim,))
+
+    if layoutStr == "fzyx" or layoutStr == 'f' or layoutStr == 'reverseNumpy':
+        return tuple(reversed(range(dim)))
+    elif layoutStr == 'c' or layoutStr == 'numpy':
+        return tuple(range(dim))
+    elif layoutStr == 'zyxf':
+        return tuple(reversed(range(dim-1))) + (dim,)
+    raise ValueError("Unknown layout descriptor " + layoutStr)
+
+
 def normalizeLayout(layout):
     """Takes a layout tuple and subtracts the minimum from all entries"""
     minEntry = min(layout)
diff --git a/slicing.py b/slicing.py
index 15060b69d..6af0ab685 100644
--- a/slicing.py
+++ b/slicing.py
@@ -19,6 +19,8 @@ def normalizeSlice(slices, sizes):
 
     for s, size in zip(slices, sizes):
         if type(s) is int:
+            if s < 0:
+                s = size + s
             result.append(s)
             continue
         if type(s) is float:
-- 
GitLab