diff --git a/apps/benchmarks/FlowAroundSphereCodeGen/FlowAroundSphereCodeGen.py b/apps/benchmarks/FlowAroundSphereCodeGen/FlowAroundSphereCodeGen.py index 675a3766ef0e46bec0581e830f12b77b27394219..8d3b556bb31e77eec8cb8daf5937a66766cee0a8 100644 --- a/apps/benchmarks/FlowAroundSphereCodeGen/FlowAroundSphereCodeGen.py +++ b/apps/benchmarks/FlowAroundSphereCodeGen/FlowAroundSphereCodeGen.py @@ -73,14 +73,17 @@ with CodeGeneration() as ctx: generate_alternating_lbm_boundary(ctx, 'FlowAroundSphereCodeGen_UBB', ubb, lb_method, target=target, streaming_pattern=streaming_pattern, - additional_data_handler=ubb_data_handler) + additional_data_handler=ubb_data_handler, + layout='fzyx') generate_alternating_lbm_boundary(ctx, 'FlowAroundSphereCodeGen_NoSlip', NoSlip(), lb_method, - target=target, streaming_pattern=streaming_pattern) + target=target, streaming_pattern=streaming_pattern, + layout='fzyx') generate_alternating_lbm_boundary(ctx, 'FlowAroundSphereCodeGen_Outflow', outflow, lb_method, target=target, streaming_pattern=streaming_pattern, - additional_data_handler=outflow_data_handler) + additional_data_handler=outflow_data_handler, + layout='fzyx') # communication generate_lb_pack_info(ctx, 'FlowAroundSphereCodeGen_PackInfo', stencil, pdfs, diff --git a/python/pystencils_walberla/additional_data_handler.py b/python/pystencils_walberla/additional_data_handler.py index 4d4d82d5256e48b4eb6a8c284dabc9b512311c70..2c4efcc65bdd60451e32e7cefa88f9baf8d6c03e 100644 --- a/python/pystencils_walberla/additional_data_handler.py +++ b/python/pystencils_walberla/additional_data_handler.py @@ -47,6 +47,10 @@ class AdditionalDataHandler: def stencil_info(self): return [(i, d, ", ".join([str(e) for e in d])) for i, d in enumerate(self._walberla_stencil)] + @property + def walberla_stencil(self): + return self._walberla_stencil + @property def inverse_directions(self): inv_dirs = [] diff --git a/python/pystencils_walberla/boundary.py b/python/pystencils_walberla/boundary.py index c8bf214def82c5dcaf531208f114ea2cb9601077..5cf8f1fe5d5db86ccb6375147d401012638add30 100644 --- a/python/pystencils_walberla/boundary.py +++ b/python/pystencils_walberla/boundary.py @@ -6,6 +6,8 @@ from pystencils.boundaries.createindexlist import ( boundary_index_array_coordinate_names, direction_member_name, numpy_data_type_for_boundary_object) from pystencils.data_types import TypedSymbol, create_type +from pystencils.stencil import inverse_direction + from pystencils_walberla.codegen import config_from_context from pystencils_walberla.jinja_filters import add_pystencils_filters_to_jinja_env from pystencils_walberla.additional_data_handler import AdditionalDataHandler @@ -29,6 +31,7 @@ def generate_boundary(generation_context, additional_data_handler=None, interface_mappings=(), generate_functor=True, + layout='fzyx', **create_kernel_params): if boundary_object.additional_data and additional_data_handler is None: @@ -50,7 +53,7 @@ def generate_boundary(generation_context, field = Field.create_generic(field_name, dim, field_data_type, - index_dimensions=len(index_shape), layout='fzyx', index_shape=index_shape, + index_dimensions=len(index_shape), layout=layout, index_shape=index_shape, field_type=field_type) index_field = Field('indexVector', FieldType.INDEXED, index_struct_dtype, layout=[0], @@ -88,7 +91,8 @@ def generate_boundary(generation_context, 'namespace': namespace, 'inner_or_boundary': boundary_object.inner_or_boundary, 'single_link': boundary_object.single_link, - 'additional_data_handler': additional_data_handler + 'additional_data_handler': additional_data_handler, + 'layout': layout } env = Environment(loader=PackageLoader('pystencils_walberla'), undefined=StrictUndefined) diff --git a/python/pystencils_walberla/templates/Boundary.tmpl.h b/python/pystencils_walberla/templates/Boundary.tmpl.h index cc5351d519cc46b618d100dba1460aeaaf8ea434..daf3e0c9668e82c271f0c65368c1331633e9c022 100644 --- a/python/pystencils_walberla/templates/Boundary.tmpl.h +++ b/python/pystencils_walberla/templates/Boundary.tmpl.h @@ -198,7 +198,27 @@ public: indexVectorOuter.clear(); {% if inner_or_boundary -%} - for( auto it = flagField->begin(); it != flagField->end(); ++it ) + {% if layout == "fzyx" -%} + {%- for dirIdx, dirVec, offset in additional_data_handler.stencil_info %} + for( auto it = flagField->beginWithGhostLayerXYZ( cell_idx_c( flagField->nrOfGhostLayers() - 1 ) ); it != flagField->end(); ++it ) + { + if( ! isFlagSet(it, domainFlag) ) + continue; + + if ( isFlagSet( it.neighbor({{offset}} {%if dim == 3%}, 0 {%endif %}), boundaryFlag ) ) + { + auto element = {{StructName}}(it.x(), it.y(), {%if dim == 3%} it.z(), {%endif %} {{dirIdx}} ); + {{additional_data_handler.data_initialisation(dirIdx)|indent(16)}} + indexVectorAll.push_back( element ); + if( inner.contains( it.x(), it.y(), it.z() ) ) + indexVectorInner.push_back( element ); + else + indexVectorOuter.push_back( element ); + } + } + {% endfor %} + {%else%} + for( auto it = flagField->beginWithGhostLayerXYZ( cell_idx_c( flagField->nrOfGhostLayers() - 1 ) ); it != flagField->end(); ++it ) { if( ! isFlagSet(it, domainFlag) ) continue; @@ -215,6 +235,7 @@ public: } {% endfor %} } + {%endif%} {%else%} auto flagWithGLayers = flagField->xyzSizeWithGhostLayer(); real_t dot = 0.0; real_t maxn = 0.0;