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

Implemented LBStep - works for basic scenarios

parent d30c5f73
Branches
Tags
No related merge requests found
from .serial_datahandling import SerialDataHandling
from pystencils.datahandling.serial_datahandling import SerialDataHandling
try:
import waLBerla
if waLBerla.cpp_available:
from .parallel_datahandling import ParallelDataHandling
from pystencils.datahandling.parallel_datahandling import ParallelDataHandling
else:
waLBerla = None
except ImportError:
......@@ -31,7 +31,7 @@ def createDataHandling(parallel, domainSize, periodicity, defaultLayout='SoA', d
else:
dim = 3
blockStorage = waLBerla.createUniformBlockGrid(cells=domainSize, periodicity=periodicity)
blockStorage = waLBerla.createUniformBlockGrid(cells=domainSize, periodic=periodicity)
return ParallelDataHandling(blocks=blockStorage, dim=dim,
defaultLayout=defaultLayout, defaultGhostLayers=defaultGhostLayers)
else:
......
......@@ -127,22 +127,23 @@ class ParallelDataHandling(DataHandling):
ghostLayers = 0
prefix = self.GPU_DATA_PREFIX if gpu else ""
if sliceObj is None:
if sliceObj is not None:
yield from slicedBlockIteration(self.blocks, sliceObj, ghostLayers, ghostLayers,
self.dim, prefix)
else:
yield from blockIteration(self.blocks, ghostLayers, self.dim, prefix)
def gatherArray(self, name, sliceObj=None, allGather=False):
with self.accessWrapper(name):
if sliceObj is None:
sliceObj = makeSlice[:, :, :]
for array in wlb.field.gatherGenerator(self.blocks, name, sliceObj, allGather):
if self.fields[name].indexDimensions == 0:
array = array[..., 0]
if self.dim == 2:
array = array[:, :, 0]
yield array
if sliceObj is None:
sliceObj = makeSlice[:, :, :]
if self.dim == 2:
sliceObj += (0.5,)
for array in wlb.field.gatherGenerator(self.blocks, name, sliceObj, allGather):
if self.fields[name].indexDimensions == 0:
array = array[..., 0]
if self.dim == 2:
array = array[:, :, 0]
yield array
def _normalizeArrShape(self, arr, indexDimensions):
if indexDimensions == 0:
......@@ -159,7 +160,7 @@ class ParallelDataHandling(DataHandling):
nameMap = self._fieldNameToCpuDataName
toArray = wlb.field.toArray
dataUsedInKernel = [(nameMap[p.fieldName], self.fields[p.fieldName])
for p in kernelFunc.ast.parameters if p.isFieldPtrArgument]
for p in kernelFunc.parameters if p.isFieldPtrArgument]
for block in self.blocks:
fieldArgs = {}
for dataName, f in dataUsedInKernel:
......
......@@ -9,6 +9,7 @@ from pystencils.datahandling.datahandling_interface import DataHandling
try:
import pycuda.gpuarray as gpuarray
import pycuda.autoinit
except ImportError:
gpuarray = None
......@@ -159,7 +160,8 @@ class SerialDataHandling(DataHandling):
arr = removeGhostLayers(arr, indexDimensions=indDimensions, ghostLayers=gls)
if sliceObj is not None:
sliceObj = normalizeSlice(sliceObj, arr.shape[:-indDimensions])
sliceObj = normalizeSlice(sliceObj, arr.shape[:-indDimensions] if indDimensions > 0 else arr.shape)
sliceObj = tuple(s if type(s) is slice else slice(s, s + 1, None) for s in sliceObj)
arr = arr[sliceObj]
yield arr
......@@ -208,6 +210,8 @@ class SerialDataHandling(DataHandling):
def _synchronizationFunctor(self, names, stencil, target):
if stencil is None:
stencil = 'D3Q27' if self.dim == 3 else 'D2Q9'
if stencil == 'D3Q15' or stencil == 'D3Q19':
stencil = 'D3Q27'
assert stencil in ("D2Q9", 'D3Q27'), "Serial scenario support only D2Q9 or D3Q27 for periodicity sync"
......
......@@ -24,7 +24,7 @@ def blockIteration(blocks, ghostLayers, dim=3, accessPrefix=''):
localSlice = [slice(0, w, None) for w in cellInterval.size]
if dim == 2:
localSlice[2] = ghostLayers
yield ParallelBlock(block, cellInterval.min, localSlice, ghostLayers, accessPrefix)
yield ParallelBlock(block, cellInterval.min, tuple(localSlice), ghostLayers, accessPrefix)
def slicedBlockIteration(blocks, sliceObj=None, innerGhostLayers=1, outerGhostLayers=1, dim=3, accessPrefix=''):
......@@ -48,7 +48,9 @@ def slicedBlockIteration(blocks, sliceObj=None, innerGhostLayers=1, outerGhostLa
included
"""
if sliceObj is None:
sliceObj = [slice(None, None, None)] * 3
sliceObj = tuple([slice(None, None, None)] * dim)
if dim == 2:
sliceObj += (innerGhostLayers, )
domainCellBB = blocks.getDomainCellBB()
domainExtent = [s + 2 * outerGhostLayers for s in domainCellBB.size]
......
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