Skip to content
Snippets Groups Projects
Commit 340819af authored by Martin Bauer's avatar Martin Bauer
Browse files

lbmpy: Removed unnecessary conversion of boundary index list

parent 04d4d09c
Branches
Tags
No related merge requests found
...@@ -72,7 +72,6 @@ class BoundaryHandling(object): ...@@ -72,7 +72,6 @@ class BoundaryHandling(object):
for boundaryIdx, boundaryFunc in enumerate(self._boundaryFunctions): for boundaryIdx, boundaryFunc in enumerate(self._boundaryFunctions):
idxField = createBoundaryIndexList(self.flagField, self._lbMethod.stencil, idxField = createBoundaryIndexList(self.flagField, self._lbMethod.stencil,
2 ** boundaryIdx, self._fluidFlag, self._ghostLayers) 2 ** boundaryIdx, self._fluidFlag, self._ghostLayers)
idxField = transformIndexListToStruct(idxField)
ast = generateBoundaryHandling(self._symbolicPdfField, idxField, self._lbMethod, boundaryFunc) ast = generateBoundaryHandling(self._symbolicPdfField, idxField, self._lbMethod, boundaryFunc)
if self._target == 'cpu': if self._target == 'cpu':
...@@ -134,23 +133,13 @@ class LbmMethodInfo(CustomCppCode): ...@@ -134,23 +133,13 @@ class LbmMethodInfo(CustomCppCode):
super(LbmMethodInfo, self).__init__(code, symbolsRead=set(), symbolsDefined=symbolsDefined) super(LbmMethodInfo, self).__init__(code, symbolsRead=set(), symbolsDefined=symbolsDefined)
def transformIndexListToStruct(arr):
#TODO create in correct form right away
dim = arr.shape[-1] -1
coordinateNames = ['x', 'y', 'z'][:dim]
dataTypeInfo = [(name, np.int) for name in coordinateNames] + [('dir', np.int)]
indexArrStruct = np.empty((arr.shape[0]), dtype=np.dtype(dataTypeInfo))
for idx, name in enumerate(coordinateNames):
indexArrStruct[name] = arr[:, idx]
indexArrStruct['dir'] = arr[:, -1]
return indexArrStruct
def generateBoundaryHandling(pdfField, indexArr, lbMethod, boundaryFunctor): def generateBoundaryHandling(pdfField, indexArr, lbMethod, boundaryFunctor):
indexField = Field.createFromNumpyArray("indexField", indexArr) indexField = Field.createFromNumpyArray("indexField", indexArr)
elements = [LbmMethodInfo(lbMethod)] elements = [LbmMethodInfo(lbMethod)]
boundaryEqList = boundaryFunctor(pdfField, indexField[0]('dir'), lbMethod) dirSymbol = TypedSymbol("dir", indexArr.dtype.fields['dir'][0])
boundaryEqList = [sp.Eq(dirSymbol, indexField[0]('dir'))]
boundaryEqList += boundaryFunctor(pdfField, dirSymbol, lbMethod)
if type(boundaryEqList) is tuple: if type(boundaryEqList) is tuple:
boundaryEqList, additionalNodes = boundaryEqList boundaryEqList, additionalNodes = boundaryEqList
elements += boundaryEqList elements += boundaryEqList
......
...@@ -13,6 +13,9 @@ except Exception: ...@@ -13,6 +13,9 @@ except Exception:
def _createBoundaryIndexListPython(flagFieldArr, nrOfGhostLayers, boundaryMask, fluidMask, stencil): def _createBoundaryIndexListPython(flagFieldArr, nrOfGhostLayers, boundaryMask, fluidMask, stencil):
coordinateNames = ("x", "y", "z")[:len(flagFieldArr.shape)]
indexArrDtype = np.dtype([(name, np.int32) for name in coordinateNames] + [('dir', np.int32)])
result = [] result = []
gl = nrOfGhostLayers gl = nrOfGhostLayers
for cell in itertools.product(*[range(gl, i-gl) for i in flagFieldArr.shape]): for cell in itertools.product(*[range(gl, i-gl) for i in flagFieldArr.shape]):
...@@ -21,20 +24,24 @@ def _createBoundaryIndexListPython(flagFieldArr, nrOfGhostLayers, boundaryMask, ...@@ -21,20 +24,24 @@ def _createBoundaryIndexListPython(flagFieldArr, nrOfGhostLayers, boundaryMask,
for dirIdx, direction in enumerate(stencil): for dirIdx, direction in enumerate(stencil):
neighborCell = tuple([cell_i + dir_i for cell_i, dir_i in zip(cell, direction)]) neighborCell = tuple([cell_i + dir_i for cell_i, dir_i in zip(cell, direction)])
if flagFieldArr[neighborCell] & boundaryMask: if flagFieldArr[neighborCell] & boundaryMask:
result.append(list(cell) + [dirIdx]) result.append(cell + (dirIdx,))
return np.array(result, dtype=np.int32) return np.array(result, dtype=indexArrDtype)
def createBoundaryIndexList(flagField, stencil, boundaryMask, fluidMask, nrOfGhostLayers=1): def createBoundaryIndexList(flagField, stencil, boundaryMask, fluidMask, nrOfGhostLayers=1):
dim = len(flagField.shape)
coordinateNames = ("x", "y", "z")[:dim]
indexArrDtype = np.dtype([(name, np.int32) for name in coordinateNames] + [('dir', np.int32)])
if cythonFuncsAvailable: if cythonFuncsAvailable:
stencil = np.array(stencil, dtype=np.int32) stencil = np.array(stencil, dtype=np.int32)
if len(flagField.shape) == 2: if dim == 2:
idxList = createBoundaryIndexList2D(flagField, nrOfGhostLayers, boundaryMask, fluidMask, stencil) idxList = createBoundaryIndexList2D(flagField, nrOfGhostLayers, boundaryMask, fluidMask, stencil)
elif len(flagField.shape) == 3: elif dim == 3:
idxList = createBoundaryIndexList3D(flagField, nrOfGhostLayers, boundaryMask, fluidMask, stencil) idxList = createBoundaryIndexList3D(flagField, nrOfGhostLayers, boundaryMask, fluidMask, stencil)
else: else:
raise ValueError("Flag field has to be a 2 or 3 dimensional numpy array") raise ValueError("Flag field has to be a 2 or 3 dimensional numpy array")
return np.array(idxList, dtype=np.int32) return np.array(idxList, dtype=indexArrDtype)
else: else:
return _createBoundaryIndexListPython(flagField, nrOfGhostLayers, boundaryMask, fluidMask, stencil) return _createBoundaryIndexListPython(flagField, nrOfGhostLayers, boundaryMask, fluidMask, stencil)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment