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

Deprecation of old boundary API

parent fe2b7f9c
Pipeline #27673 waiting for manual action with stage
in 24 minutes and 3 seconds
......@@ -7,8 +7,8 @@ from lbmpy.simplificationfactory import create_simplification_strategy
from lbmpy.advanced_streaming.indexing import NeighbourOffsetArrays
class Boundary:
"""Base class for all boundary classes that use the AdvancedStreamingBoundaryIndexing"""
class LbBoundary:
"""Base class that all boundaries should derive from"""
inner_or_boundary = True
single_link = False
......@@ -69,7 +69,7 @@ class Boundary:
# end class Boundary
class NoSlip(Boundary):
class NoSlip(LbBoundary):
def __init__(self, name=None):
"""Set an optional name here, to mark boundaries, for example for force evaluations"""
......@@ -94,7 +94,7 @@ class NoSlip(Boundary):
# end class NoSlip
class UBB(Boundary):
class UBB(LbBoundary):
"""Velocity bounce back boundary condition, enforcing specified velocity at obstacle"""
def __init__(self, velocity, adapt_velocity_to_force=False, dim=None, name=None):
......@@ -135,7 +135,7 @@ class UBB(Boundary):
direction = dir_symbol
assert self.dim == lb_method.dim, \
f"Dimension of UBB ({self.dim}) does not match dimension of method ({lb_method.dim})"
f"Dimension of UBB ({self.dim}) does not match dimension of method ({lb_method.dim})"
neighbor_offset = NeighbourOffsetArrays.neighbour_offset(direction, lb_method.stencil)
......@@ -174,7 +174,7 @@ class UBB(Boundary):
# end class UBB
class FixedDensity(Boundary):
class FixedDensity(LbBoundary):
def __init__(self, density, name=None):
if name is None:
......@@ -221,7 +221,7 @@ class FixedDensity(Boundary):
# end class FixedDensity
class NeumannByCopy(Boundary):
class NeumannByCopy(LbBoundary):
def get_additional_code_nodes(self, lb_method):
return [NeighbourOffsetArrays(lb_method.stencil)]
......@@ -240,7 +240,7 @@ class NeumannByCopy(Boundary):
# end class NeumannByCopy
class StreamInConstant(Boundary):
class StreamInConstant(LbBoundary):
def __init__(self, constant, name=None):
super(StreamInConstant, self).__init__(name)
self._constant = constant
......@@ -260,3 +260,60 @@ class StreamInConstant(Boundary):
def __eq__(self, other):
return type(other) == StreamInConstant
# end class StreamInConstant
# ------------------------- Old, Deprecated Implementation -------------------------
class Boundary:
inner_or_boundary = True
single_link = False
def __init__(self, name=None):
from lbmpy.boundaries.boundaryhandling import deprecation_message
self._name = name
def __call__(self, pdf_field, direction_symbol, lb_method, index_field):
This function defines the boundary behavior and must therefore be implemented by all boundaries.
Here the boundary is defined as a list of sympy equations, from which a boundary kernel is generated.
pdf_field: pystencils field describing the pdf. The current cell is cell next to the boundary,
which is influenced by the boundary cell i.e. has a link from the boundary cell to
direction_symbol: a sympy symbol that can be used as index to the pdf_field. It describes
the direction pointing from the fluid to the boundary cell
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 sympy equations
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 name(self):
if self._name:
return self._name
return type(self).__name__
def name(self, new_value):
self._name = new_value
......@@ -62,7 +62,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
return self._boundary_object_to_boundary_info[boundary_obj].flag
def _create_boundary_kernel(self, symbolic_field, symbolic_index_field, boundary_obj, prev_timestep=Timestep.BOTH):
return create_advanced_streaming_boundary_kernel(
return create_lattice_boltzmann_boundary_kernel(
symbolic_field, symbolic_index_field, self._lb_method, boundary_obj,
prev_timestep=prev_timestep, streaming_pattern=self._streaming_pattern,
target=self._target, openmp=self._openmp)
......@@ -173,9 +173,14 @@ class LbmWeightInfo(CustomCodeNode):
# end class LbmWeightInfo
def create_advanced_streaming_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor,
prev_timestep=Timestep.BOTH, streaming_pattern='pull',
target='cpu', openmp=True, **kernel_creation_args):
def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor,
prev_timestep=Timestep.BOTH, streaming_pattern='pull',
target='cpu', openmp=True, **kernel_creation_args):
from lbmpy.boundaries.boundaryconditions import Boundary as OldBoundary
if isinstance(boundary_functor, OldBoundary):
return create_lattice_boltzmann_boundary_kernel_old(pdf_field, index_field, lb_method, boundary_functor,
target=target, openmp=openmp, **kernel_creation_args)
index_dtype = index_field.dtype.numpy_dtype.fields['dir'][0]
offsets_dtype = index_field.dtype.numpy_dtype.fields['x'][0]
indexing = BetweenTimestepsIndexing(
......@@ -200,3 +205,28 @@ def create_advanced_streaming_boundary_kernel(pdf_field, index_field, lb_method,
return kernel
# ----------------------------- Old, Deprecated Implementation -----------------------
def deprecation_message():
import warnings
deprecation_message = "The old code generation scheme for LB boundaries has been deprecated. " \
+ "Please update your boundary implementation to derive from ``LbBoundary`` " \
+ "and use the new implementation scheme based on `BetweenTimestepsIndexing`."
warnings.simplefilter('always', DeprecationWarning)
warnings.warn(deprecation_message, DeprecationWarning, stacklevel=2)
warnings.simplefilter('default', DeprecationWarning)
def create_lattice_boltzmann_boundary_kernel_old(pdf_field, index_field, lb_method, boundary_functor,
target='cpu', openmp=True, **kernel_creation_args):
from pystencils.boundaries.boundaryhandling import BoundaryOffsetInfo
elements = [BoundaryOffsetInfo(lb_method.stencil), LbmWeightInfo(lb_method)]
index_arr_dtype = index_field.dtype.numpy_dtype
dir_symbol = TypedSymbol("dir", index_arr_dtype.fields['dir'][0])
elements += [Assignment(dir_symbol, index_field[0]('dir'))]
elements += boundary_functor(pdf_field=pdf_field, direction_symbol=dir_symbol,
lb_method=lb_method, index_field=index_field)
return create_indexed_kernel(elements, [index_field], target=target, cpu_openmp=openmp, **kernel_creation_args)
......@@ -3,7 +3,7 @@ import sympy as sp
from lbmpy.advanced_streaming import Timestep
from lbmpy.boundaries import NoSlip
from lbmpy.boundaries.boundaryhandling import create_advanced_streaming_boundary_kernel
from lbmpy.boundaries.boundaryhandling import create_lattice_boltzmann_boundary_kernel
from lbmpy.advanced_streaming.utility import even_accessors, odd_accessors, streaming_patterns, inverse_dir_index, AccessPdfValues
from lbmpy.creationfunctions import create_lb_method
from lbmpy.stencils import get_stencil
......@@ -48,12 +48,12 @@ def test_advanced_streaming_noslip_single_cell(stencil, streaming_pattern, prev_
shape=(TypedSymbol("indexVectorSize", create_type(np.int64)), 1), strides=(1, 1))
index_vector = np.array([ pos + (d,) for d in range(q) ], dtype=index_struct_dtype)
flex_ast = create_advanced_streaming_boundary_kernel(pdf_field,
ast = create_lattice_boltzmann_boundary_kernel(pdf_field,
index_field, lb_method, noslip,
flex_kernel = flex_ast.compile()
flex_kernel = ast.compile()
flex_kernel(pdfs=pdfs, indexVector=index_vector, indexVectorSize=len(index_vector))
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