Commit a943e632 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

comm slices and docstrings

parent 97032f3d
Pipeline #27056 failed with stage
in 23 minutes and 38 seconds
......@@ -15,21 +15,20 @@ class FlexibleBoundary:
This function defines the boundary behavior and must therefore be implemented by all boundaries.
The boundary is defined through a list of sympy equations from which a boundary kernel is generated.
Args:
f_out: a pystencils field acting as a proxy to access the populations streaming out of the current
cell, i.e. the post-collision PDFs of the previous LBM step
f_in: a pystencils field acting as a proxy to access the populations streaming into the current
cell, i.e. the pre-collision PDFs for the next LBM step
dir_symbol: a sympy symbol that can be used as an index to f_out and f_in. It describes the direction
pointing from the fluid to the boundary cell.
inv_dir: an indexed sympy symbol which describes the inversion of a direction index. It can be used in
the indices of f_out and f_in for retrieving the PDF of the inverse direction.
lb_method: an instance of the LB method used. Use this to adapt the boundary to the method
(e.g. compressibility)
index_field: the boundary index field that can be used to retrieve and update boundary data
Returns:
:return: list of pystencils assignments, or pystencils.AssignmentCollection
:param f_out: a pystencils field acting as a proxy to access the populations streaming out of the current
cell, i.e. the post-collision PDFs of the previous LBM step
:param f_in: a pystencils field acting as a proxy to access the populations streaming into the current
cell, i.e. the pre-collision PDFs for the next LBM step
:param dir_symbol: a sympy symbol that can be used as an index to f_out and f_in. It describes the direction
pointing from the fluid to the boundary cell.
:param inv_dir: an indexed sympy symbol which describes the inversion of a direction index. It can be used in
the indices of f_out and f_in for retrieving the PDF of the inverse direction.
:param lb_method: an instance of the LB method used. Use this to adapt the boundary to the method
(e.g. compressibility)
:param index_field: the boundary index field that can be used to retrieve and update boundary data
:return: list of pystencils assignments, or pystencils.AssignmentCollection
"""
raise NotImplementedError("Boundary class has to overwrite __call__")
......
......@@ -6,6 +6,7 @@ from pystencils.slicing import make_slice, shift_slice, get_slice_before_ghost_l
from lbmpy.stencils import get_stencil
from lbmpy.advanced_streaming.utility import get_accessor
def cut_slice_in_direction(slices, direction):
assert len(slices) == len(dir)
......@@ -17,33 +18,57 @@ def cut_slice_in_direction(slices, direction):
return tuple(result)
class CommunicationSlices:
def __init__(self, lb_method, kernel_type='pull', after_timestep='both',
pdf_field=None, ghost_layers=1):
self.stencil = lb_method.stencil
self.dim = lb_method.dim
self.q = len(self.stencil)
self.ghost_layers = ghost_layers
def extend_dir(direction):
if len(direction) == 0:
yield tuple()
elif direction[0] == 0:
for d in [-1, 0, 1]:
for rest in extend_dir(direction[1:]):
yield (d, ) + rest
else:
for rest in extend_dir(direction[1:]):
yield (direction[0], ) + rest
def _get_neighbour_transform(direction, ghost_layers):
return tuple(d * (ghost_layers + 1) for d in direction)
def communication_slices(lb_method, kernel_type='pull', after_timestep='both', ghost_layers=1):
"""
Return the source and destination slices for periodicity handling or communication between
blocks. This function returns a dictionary which contains a list of tuples
(idx, src_slice, dst_slice) for each stencil direction. Here, idx is an index to the pdf field,
src_slice the source region of the current block, and dst_slice the destination region in the
adjacent block.
:param lb_method: The lattice boltzmann method to be used.
:param kernel_type: The streaming pattern.
:param after_timestep: Timestep after which communication is run; either 'even', 'odd' or 'both'.
:param ghost_layers: Number of ghost layers in each direction.
"""
stencil = lb_method.stencil
write_accesses = get_accessor(kernel_type, after_timestep).write()
all_slices = dict()
for comm_dir in stencil:
slices_for_dir = set()
if pdf_field is None:
pdf_field = ps.Field.create_generic(
'pdfs', spatial_dimensions=self.dim, index_shape=(self.q, ))
self.pdf_field = pdf_field
for streaming_dir in set(extend_dir(comm_dir)) & set(stencil):
d = stencil.index(streaming_dir)
write_offsets = write_accesses[d].offsets
write_index = write_accesses[d].index[0]
self.write_accesses = get_accessor(kernel_type, after_timestep).write()
tangential_dir = tuple(s - c for s, c in zip(streaming_dir, comm_dir))
origin_slice = get_slice_before_ghost_layer(comm_dir, ghost_layers=ghost_layers, thickness=1)
src_slice = shift_slice(cut_slice_in_direction(origin_slice, tangential_dir), write_offsets)
def copy_slices(self, copy_dir, streaming_dir):
d = self.stencil.index(streaming_dir)
write_offsets = self.write_accesses[d].offsets
write_index = self.write_accesses[d].index[0]
tangential_dir = tuple(s - c for s, c in zip(streaming_dir, copy_dir))
origin_slice = get_slice_before_ghost_layer(copy_dir, ghost_layers=self.ghost_layers, thickness=1)
src_slice = shift_slice(cut_slice_in_direction(origin_slice, tangential_dir), write_offsets)
neighbour_transform = _get_neighbour_transform(comm_dir, ghost_layers)
dst_slice = shift_slice(src_slice, neighbour_transform)
# TODO: Calculate neighbour anchor point and transform src_slice to obtain dst_slice
raise NotImplementedError()
slices_for_dir.add((write_index, src_slice, dst_slice))
def copy_slices_for_comm_direction(self, copy_dir):
dim = len(copy_dir[0])
raise NotImplementedError()
all_slices[comm_dir] = slices_for_dir
return all_slices
\ No newline at end of file
Markdown is supported
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