Commit e2cab929 authored by Martin Bauer's avatar Martin Bauer
Browse files

lbmpy: Fix bug when using non-standard field layout in scenarios

parent 8065a9d6
......@@ -114,13 +114,13 @@ class Field(object):
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)):
return Field(fieldName, dtype, tuple(spatialLayout), shape, strides)
def __init__(self, fieldName, dtype, layout, shape, strides):
"""Do not use directly. Use static create* methods"""
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)
indexing = [slice(ghostLayers, -ghostLayers, None), ] * spatialDimensions
indexing += [slice(None, None, None)] * indexDimensions
result[indexing] = arr
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment