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

Added basic boundary classes

parent dd236fb0
Pipeline #26890 failed with stage
in 21 minutes and 11 seconds
import sympy as sp
import pystencils as ps
class FlexibleBoundary:
"""Base class for all boundary classes that use the AdvancedStreamingBoundaryIndexing"""
inner_or_boundary = True
single_link = False
def __init__(self, name=None):
self._name = name
def __call__(self, f_out, f_in, dir_symbol, inv_dir, lb_method, index_field):
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.
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
:return: list of pystencils assignments, or pystencils.AssignmentCollection
raise NotImplementedError("Boundary class has to overwrite __call__")
def additional_data(self):
"""Return a list of (name, type) tuples for additional data items required in this boundary
These data items can either be initialized in separate kernel see additional_data_kernel_init or by
Python callbacks - see additional_data_callback """
return []
def additional_data_init_callback(self):
"""Return a callback function called with a boundary data setter object and returning a dict of
data-name to data for each element that should be initialized"""
return None
def additional_code_nodes(self):
"""Return a list of code nodes that need to be prepended to the boundary equations
in the generated code. Those can be instances of subclasses of pystencils.astnodes.Node, or
pystencils assignments."""
return []
def name(self):
if self._name:
return self._name
return type(self).__name__
def name(self, new_value):
self._name = new_value
# end class FlexibleBoundary
class FlexibleNoSlip(FlexibleBoundary):
def __init__(self, name=None):
"""Set an optional name here, to mark boundaries, for example for force evaluations"""
super(FlexibleNoSlip, self).__init__(name)
No-Slip, (half-way) simple bounce back boundary condition, enforcing zero velocity at obstacle.
Extended for use with any streaming pattern.
def __call__(self, f_out, f_in, dir_symbol, inv_dir, lb_method, index_field):
return ps.Assignment(f_in(inv_dir[dir_symbol]), f_out(dir_symbol))
def __hash__(self):
return hash(
def __eq__(self, other):
if not isinstance(other, FlexibleNoSlip):
return False
return ==
# end class FlexibleNoSlip
\ No newline at end of file
......@@ -21,12 +21,15 @@ class AdvancedStreamingBoundaryIndexing:
# Symbols for usage in boundaries
# =======================================
def proxy_fields(self):
return ps.fields(f"f_out({self._q}), f_in({self._q}): [{self._dim}D]")
def dir_symbol(self):
return TypedSymbol('dir', create_type(np.int64))
def inverse_dir_symbol(self):
return sp.IndexedBase('invdir')
......@@ -123,8 +126,8 @@ class AdvancedStreamingBoundaryIndexing:
assignments = ps.AssignmentCollection(assignments)
accesses = self._accesses
f_out, f_in = self.proxy_fields()
inv_dir = self.inverse_dir_symbol()
f_out, f_in = self.proxy_fields
inv_dir = self.inverse_dir_symbol
accessor_subs = dict()
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