Commit 41ece459 authored by RudolfWeeber's avatar RudolfWeeber
Browse files

Add accessor-agnostic update kernel generation functions

and use them for generating stream-pull kernels
parent d77c86e0
Pipeline #31885 failed with stage
in 10 minutes and 28 seconds
import numpy as np
import sympy as sp
from lbmpy.fieldaccess import StreamPullTwoFieldsAccessor
from lbmpy.fieldaccess import StreamPullTwoFieldsAccessor, StreamPushTwoFieldsAccessor
from lbmpy.methods.abstractlbmethod import LbmCollisionRule
from pystencils import Assignment, AssignmentCollection, Field
from pystencils.field import create_numpy_array_with_layout, layout_string_to_tuple
......@@ -54,9 +54,9 @@ def create_lbm_kernel(collision_rule, input_field, output_field, accessor):
return result
def create_stream_pull_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst_field_name="dst",
generic_layout='numpy', generic_field_type=np.float64):
"""Creates a stream-pull kernel, without collision.
def create_stream_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst_field_name="dst",
generic_layout='numpy', generic_field_type=np.float64, accessor=None):
"""Creates a stream kernel, without collision.
For parameters see function ``create_stream_pull_collide_kernel``
"""
......@@ -71,16 +71,19 @@ def create_stream_pull_only_kernel(stencil, numpy_arr=None, src_field_name="src"
src = Field.create_from_numpy_array(src_field_name, numpy_arr, index_dimensions=1)
dst = Field.create_from_numpy_array(dst_field_name, numpy_arr, index_dimensions=1)
accessor = StreamPullTwoFieldsAccessor()
eqs = [Assignment(a, b) for a, b in zip(accessor.write(dst, stencil), accessor.read(src, stencil))]
return AssignmentCollection(eqs, [])
def create_stream_pull_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst_field_name="dst",
generic_layout='numpy', generic_field_type=np.float64):
return create_stream_only_kernel(stencil, numpy_arr=numpy_arr, src_field_name=src_field_name, dst_field_name=dst_field_name,
generic_layout=generic_layout, generic_field_type=generic_field_type, accessor=StreamPullTwoFieldsAccessor())
def create_stream_pull_with_output_kernel(lb_method, src_field, dst_field, output):
def create_stream_with_output_kernel(lb_method, src_field, dst_field, output, accessor):
stencil = lb_method.stencil
cqc = lb_method.conserved_quantity_computation
streamed = sp.symbols("streamed_:%d" % (len(stencil),))
accessor = StreamPullTwoFieldsAccessor()
stream_assignments = [Assignment(a, b) for a, b in zip(streamed, accessor.read(src_field, stencil))]
output_eq_collection = cqc.output_equations_from_pdfs(streamed, output)
write_eqs = [Assignment(a, b) for a, b in zip(accessor.write(dst_field, stencil), streamed)]
......@@ -90,6 +93,9 @@ def create_stream_pull_with_output_kernel(lb_method, src_field, dst_field, outpu
return LbmCollisionRule(lb_method, main_eqs, subexpressions,
simplification_hints=output_eq_collection.simplification_hints)
def create_stream_pull_with_output_kernel(lb_method, src_field, dst_field, output):
return create_stream_with_output_kernel(lb_method, src_field, dst_field, output, accessor=StreamPullTwoFieldsAccessor())
# ---------------------------------- Pdf array creation for various layouts --------------------------------------------
......
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