Commit 66f97df1 authored by Michael Kuron's avatar Michael Kuron
Browse files

Merge branch 'FIX_Boundary_kwargs' into 'master'

Fix boundary kwargs

See merge request pycodegen/lbmpy!46
parents ba9b9d1a f2f3bca5
...@@ -260,16 +260,3 @@ class StreamInConstant(LbBoundary): ...@@ -260,16 +260,3 @@ class StreamInConstant(LbBoundary):
def __eq__(self, other): def __eq__(self, other):
return type(other) == StreamInConstant return type(other) == StreamInConstant
# end class StreamInConstant # end class StreamInConstant
# ------------------------- Old, Deprecated Implementation -------------------------
class Boundary(LbBoundary):
def __init__(self, name=None):
from lbmpy.boundaries.boundaryhandling import deprecation_message
deprecation_message()
self._name = name
def __call__(self, pdf_field, direction_symbol, lb_method, index_field):
raise NotImplementedError("Boundary class has to overwrite __call__")
...@@ -65,7 +65,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling): ...@@ -65,7 +65,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
return create_lattice_boltzmann_boundary_kernel( return create_lattice_boltzmann_boundary_kernel(
symbolic_field, symbolic_index_field, self._lb_method, boundary_obj, symbolic_field, symbolic_index_field, self._lb_method, boundary_obj,
prev_timestep=prev_timestep, streaming_pattern=self._streaming_pattern, prev_timestep=prev_timestep, streaming_pattern=self._streaming_pattern,
target=self._target, openmp=self._openmp) target=self._target, cpu_openmp=self._openmp)
class InplaceStreamingBoundaryInfo(object): class InplaceStreamingBoundaryInfo(object):
...@@ -175,11 +175,7 @@ class LbmWeightInfo(CustomCodeNode): ...@@ -175,11 +175,7 @@ class LbmWeightInfo(CustomCodeNode):
def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor, def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor,
prev_timestep=Timestep.BOTH, streaming_pattern='pull', prev_timestep=Timestep.BOTH, streaming_pattern='pull',
target='cpu', openmp=True, **kernel_creation_args): target='cpu', **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] index_dtype = index_field.dtype.numpy_dtype.fields['dir'][0]
offsets_dtype = index_field.dtype.numpy_dtype.fields['x'][0] offsets_dtype = index_field.dtype.numpy_dtype.fields['x'][0]
...@@ -197,7 +193,7 @@ def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, ...@@ -197,7 +193,7 @@ def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method,
elements = [Assignment(dir_symbol, index_field[0]('dir'))] elements = [Assignment(dir_symbol, index_field[0]('dir'))]
elements += boundary_assignments.all_assignments elements += boundary_assignments.all_assignments
kernel = create_indexed_kernel(elements, [index_field], target=target, cpu_openmp=openmp, **kernel_creation_args) kernel = create_indexed_kernel(elements, [index_field], target=target, **kernel_creation_args)
# Code Elements ahead of the loop # Code Elements ahead of the loop
index_arrs_node = indexing.create_code_node() index_arrs_node = indexing.create_code_node()
...@@ -205,28 +201,3 @@ def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, ...@@ -205,28 +201,3 @@ def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method,
kernel.body.insert_front(node) kernel.body.insert_front(node)
kernel.body.insert_front(index_arrs_node) kernel.body.insert_front(index_arrs_node)
return kernel 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):
deprecation_message()
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)
...@@ -453,10 +453,10 @@ def extract_monomials(sequence_of_polynomials, dim=3): ...@@ -453,10 +453,10 @@ def extract_monomials(sequence_of_polynomials, dim=3):
dim: length of returned exponent tuples dim: length of returned exponent tuples
>>> x, y, z = MOMENT_SYMBOLS >>> x, y, z = MOMENT_SYMBOLS
>>> extract_monomials([x**2 + y**2 + y, y + y**2]) >>> extract_monomials([x**2 + y**2 + y, y + y**2]) == {(0, 1, 0),(0, 2, 0),(2, 0, 0)}
{(0, 2, 0), (0, 1, 0), (2, 0, 0)} True
>>> extract_monomials([x**2 + y**2 + y, y + y**2], dim=2) >>> extract_monomials([x**2 + y**2 + y, y + y**2], dim=2) == {(0, 1), (0, 2), (2, 0)}
{(0, 1), (0, 2), (2, 0)} True
""" """
monomials = set() monomials = set()
for polynomial in sequence_of_polynomials: for polynomial in sequence_of_polynomials:
...@@ -477,10 +477,11 @@ def monomial_to_polynomial_transformation_matrix(monomials, polynomials): ...@@ -477,10 +477,11 @@ def monomial_to_polynomial_transformation_matrix(monomials, polynomials):
>>> polys = [7 * x**2 + 3 * x + 2 * y **2, \ >>> polys = [7 * x**2 + 3 * x + 2 * y **2, \
9 * x**2 - 5 * x] 9 * x**2 - 5 * x]
>>> mons = list(extract_monomials(polys, dim=2)) >>> mons = list(extract_monomials(polys, dim=2))
>>> mons.sort()
>>> monomial_to_polynomial_transformation_matrix(mons, polys) >>> monomial_to_polynomial_transformation_matrix(mons, polys)
Matrix([ Matrix([
[ 3, 2, 7], [2, 3, 7],
[-5, 0, 9]]) [0, -5, 9]])
""" """
dim = len(monomials[0]) dim = len(monomials[0])
......
...@@ -117,7 +117,7 @@ def test_modes(stencil, force_model): ...@@ -117,7 +117,7 @@ def test_modes(stencil, force_model):
# The stress moments should match eq. 47 from https://doi.org/10.1023/A:1010414013942 # The stress moments should match eq. 47 from https://doi.org/10.1023/A:1010414013942
u = method.first_order_equilibrium_moment_symbols u = method.first_order_equilibrium_moment_symbols
def traceless(m): def traceless(m):
tr = sp.simplify(sp.Trace(m)) tr = sp.simplify(sum([m[i,i] for i in range(dim)]))
return m - tr/m.shape[0]*sp.eye(m.shape[0]) return m - tr/m.shape[0]*sp.eye(m.shape[0])
C = sp.Rational(1,2) * (2 + lambda_s) * (traceless(sp.Matrix(u) * sp.Matrix(F).transpose()) + \ C = sp.Rational(1,2) * (2 + lambda_s) * (traceless(sp.Matrix(u) * sp.Matrix(F).transpose()) + \
traceless(sp.Matrix(F) * sp.Matrix(u).transpose())) + \ traceless(sp.Matrix(F) * sp.Matrix(u).transpose())) + \
......
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