From e2cab92997dbe862d249c9546fc09d3652f04b9d Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Fri, 21 Apr 2017 10:02:46 +0200 Subject: [PATCH] lbmpy: Fix bug when using non-standard field layout in scenarios --- field.py | 9 ++++++--- slicing.py | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/field.py b/field.py index 20d5c77ed..79984f373 100644 --- a/field.py +++ b/field.py @@ -114,13 +114,13 @@ class Field(object): @staticmethod def createFixedSize(fieldName, shape, indexDimensions=0, dtype=np.float64, layout='numpy'): """ - Creates a field with fixed sizes i.e. can be called only wity arrays of the same size and layout + Creates a field with fixed sizes i.e. can be called only with arrays of the same size and layout :param fieldName: symbolic name for the field :param shape: overall shape of the array :param indexDimensions: how many of the trailing dimensions are interpreted as index (as opposed to spatial) :param dtype: numpy data type of the array the kernel is called with later - :param layout: see createGeneric + :param layout: full layout of array, not only spatial dimensions """ spatialDimensions = len(shape) - indexDimensions assert spatialDimensions >= 1 @@ -140,7 +140,10 @@ class Field(object): shape += (1,) strides += (1,) - return Field(fieldName, dtype, layout[:spatialDimensions], shape, strides) + spatialLayout = list(layout) + for i in range(spatialDimensions, len(layout)): + spatialLayout.remove(i) + return Field(fieldName, dtype, tuple(spatialLayout), shape, strides) def __init__(self, fieldName, dtype, layout, shape, strides): """Do not use directly. Use static create* methods""" diff --git a/slicing.py b/slicing.py index 6a12b3d57..15060b69d 100644 --- a/slicing.py +++ b/slicing.py @@ -1,5 +1,6 @@ import sympy as sp import numpy as np +from pystencils.field import createNumpyArrayWithLayout, getLayoutOfArray class SliceMaker(object): @@ -95,11 +96,14 @@ def removeGhostLayers(arr, indexDimensions=0, ghostLayers=1): return arr[indexing] -def addGhostLayers(arr, indexDimensions=0, ghostLayers=1): +def addGhostLayers(arr, indexDimensions=0, ghostLayers=1, layout=None): dimensions = len(arr.shape) spatialDimensions = dimensions - indexDimensions newShape = [e + 2 * ghostLayers for e in arr.shape[:spatialDimensions]] + list(arr.shape[spatialDimensions:]) - result = np.zeros(newShape) + if layout is None: + layout = getLayoutOfArray(arr) + result = createNumpyArrayWithLayout(newShape, layout) + result.fill(0.0) indexing = [slice(ghostLayers, -ghostLayers, None), ] * spatialDimensions indexing += [slice(None, None, None)] * indexDimensions result[indexing] = arr -- GitLab