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

Added boundary kernel creation. Fixed a few other things.

parent bad8c3d1
Pipeline #26900 failed with stage
in 16 minutes and 5 seconds
from .boundaryindexing import AdvancedStreamingBoundaryIndexing
from .boundaryconditions import FlexibleBoundary, FlexibleNoSlip
__all__ = ['AdvancedStreamingBoundaryIndexing']
__all__ = ['AdvancedStreamingBoundaryIndexing', 'FlexibleBoundary', 'FlexibleNoSlip']
import sympy as sp
import pystencils as ps
......@@ -67,6 +66,7 @@ class FlexibleBoundary:
# end class FlexibleBoundary
class FlexibleNoSlip(FlexibleBoundary):
def __init__(self, name=None):
......@@ -89,4 +89,4 @@ class FlexibleNoSlip(FlexibleBoundary):
return False
return self.name == other.name
# end class FlexibleNoSlip
\ No newline at end of file
# end class FlexibleNoSlip
from lbmpy.advanced_streaming import AdvancedStreamingBoundaryIndexing
from pystencils import Assignment, create_indexed_kernel
def create_flexible_lbm_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor,
between_timesteps='both', kernel_type='pull',
target='cpu', openmp=True):
index_dtype = index_field.dtype.numpy_dtype.fields['dir'][0]
offsets_dtype = index_field.dtype.numpy_dtype.fields['x'][0]
indexing = AdvancedStreamingBoundaryIndexing(
pdf_field, lb_method.stencil, between_timesteps, kernel_type, index_dtype, offsets_dtype)
f_out, f_in = indexing.proxy_fields
dir_symbol = indexing.dir_symbol
inv_dir = indexing.inverse_dir_symbol
boundary_assignments = boundary_functor(f_out, f_in, dir_symbol, inv_dir, lb_method, index_field)
boundary_assignments = indexing.substitute_proxies(boundary_assignments)
elements = [indexing.code_node]
elements += [Assignment(dir_symbol, index_field[0]('dir'))]
elements += boundary_functor.additional_code_nodes
elements += boundary_assignments.all_assignments
return create_indexed_kernel(elements, [index_field], target=target, cpu_openmp=openmp)
......@@ -27,7 +27,7 @@ class AdvancedStreamingBoundaryIndexing:
@property
def dir_symbol(self):
return TypedSymbol('dir', create_type(np.int64))
return TypedSymbol('dir', create_type(self._index_dtype))
@property
def inverse_dir_symbol(self):
......@@ -37,7 +37,8 @@ class AdvancedStreamingBoundaryIndexing:
# Constructor and State
# =============================
def __init__(self, pdf_field, stencil, between_timesteps='both', kernel_type='pull'):
def __init__(self, pdf_field, stencil, between_timesteps='both', kernel_type='pull',
index_dtype=np.int32, offsets_dtype=np.int32):
if between_timesteps not in ['both', 'odd_to_even', 'even_to_odd']:
raise ValueError(
"Invalid value of parameter 'between_timesteps'."
......@@ -86,6 +87,9 @@ class AdvancedStreamingBoundaryIndexing:
self._q = len(stencil)
self._coordinate_names = ['x', 'y', 'z'][:self._dim]
self._index_dtype = create_type(index_dtype)
self._offsets_dtype = create_type(offsets_dtype)
self._required_arrays = set()
self._trivial_translations = self._collect_trivial_translations()
......@@ -110,8 +114,9 @@ class AdvancedStreamingBoundaryIndexing:
offset_array_names = self._offset_array_names(f_dir, inverse)
self._required_arrays.add((f_dir, inverse))
return {
'index': sp.IndexedBase(index_array_name)[index],
'offsets': tuple(sp.IndexedBase(n)[index] for n in offset_array_names)
'index': sp.IndexedBase(TypedSymbol(index_array_name, self._index_dtype), shape=(1,))[index],
'offsets': tuple(sp.IndexedBase(TypedSymbol(n, self._index_dtype), shape=(1,))[index]
for n in offset_array_names)
}
# =================================
......@@ -186,6 +191,7 @@ class AdvancedStreamingBoundaryIndexing:
trivials.add((f_dir, inv))
return trivials
@property
def code_node(self):
return AdvancedStreamingBoundaryIndexing.TranslationArraysNode(self)
......@@ -194,20 +200,20 @@ class AdvancedStreamingBoundaryIndexing:
def __init__(self, indexing):
code = '\n'
for f_dir, inv in indexing.required_arrays:
for f_dir, inv in indexing._required_arrays:
indices, offsets = indexing._get_translated_indices_and_offsets(f_dir, inv)
acc_indices = ", ".join([str(i) for i in indices])
code += self._array_pattern(indexing._index_array_name(f_dir, inv), acc_indices)
code += self._array_pattern(indexing._index_dtype, indexing._index_array_name(f_dir, inv), acc_indices)
for d, arrname in enumerate(indexing._offset_array_names(f_dir, inv)):
acc_offsets = ", ".join([str(o) for o in offsets[d]])
code += self._array_pattern(arrname, acc_offsets)
code += self._array_pattern(indexing._offsets_dtype, arrname, acc_offsets)
super(AdvancedStreamingBoundaryIndexing.TranslationArraysNode, self).__init__(
code, symbols_read=set(), symbols_defined=indexing.required_arrays)
code, symbols_read=set(), symbols_defined=indexing._required_arrays)
def _array_pattern(self, name, content):
return f"const int64_t {name} [] = {{ {content} }}; \n"
def _array_pattern(self, dtype, name, content):
return f"const {str(dtype)} {name} [] = {{ {content} }}; \n"
# end class AdvancedStreamingIndexing
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