diff --git a/field.py b/field.py index 20d5c77ede672361afe40c1e88522e858f2453b5..79984f373c6dc50a2a7613a1fe27aa69eb3b9e48 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 6a12b3d579a70c9bb4ed0a384b8af68b8fee8c55..15060b69d0781360d644a220f10748be0ccb3a79 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