From dc00b2d8d2e8eb14b25c9c007860f8f151906a3c Mon Sep 17 00:00:00 2001 From: Michael Kuron <m.kuron@gmx.de> Date: Tue, 30 Jun 2020 16:47:29 +0200 Subject: [PATCH] staggered boundary generation: direction index should point to fluid cell when inner_or_boundary=False In that case, the index vector contains the boundary cells, so the direction should point to the fluid cell. When inner_or_boundary=True, the index vector contains the fluid cells and the direction points to the boundary cell. --- python/lbmpy_walberla/boundary.py | 5 +++++ python/pystencils_walberla/boundary.py | 10 ++++++++++ python/pystencils_walberla/templates/Boundary.tmpl.h | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/python/lbmpy_walberla/boundary.py b/python/lbmpy_walberla/boundary.py index 89c0a7d97..b3fbb8c31 100644 --- a/python/lbmpy_walberla/boundary.py +++ b/python/lbmpy_walberla/boundary.py @@ -41,6 +41,10 @@ def generate_boundary(generation_context, class_name, boundary_object, lb_method stencil = lb_method.stencil stencil_info = [(i, d, ", ".join([str(e) for e in d])) for i, d in enumerate(stencil)] + inv_dirs = [] + for direction in stencil: + inverse_dir = tuple([-i for i in direction]) + inv_dirs.append(stencil.index(inverse_dir)) context = { 'class_name': boundary_object.name, @@ -48,6 +52,7 @@ def generate_boundary(generation_context, class_name, boundary_object, lb_method 'StructDeclaration': struct_from_numpy_dtype(struct_name, index_struct_dtype), 'kernel': KernelInfo(kernel), 'stencil_info': stencil_info, + 'inverse_directions' : inv_dirs, 'dim': lb_method.dim, 'target': target, 'namespace': 'lbm', diff --git a/python/pystencils_walberla/boundary.py b/python/pystencils_walberla/boundary.py index 2df49896e..6a93733e2 100644 --- a/python/pystencils_walberla/boundary.py +++ b/python/pystencils_walberla/boundary.py @@ -41,6 +41,10 @@ def generate_staggered_boundary(generation_context, class_name, boundary_object, stencil = neighbor_stencil stencil_info = [(i, d, ", ".join([str(e) for e in d])) for i, d in enumerate(stencil)] + inv_dirs = [] + for direction in stencil: + inverse_dir = tuple([-i for i in direction]) + inv_dirs.append(stencil.index(inverse_dir)) context = { 'class_name': boundary_object.name, @@ -48,6 +52,7 @@ def generate_staggered_boundary(generation_context, class_name, boundary_object, 'StructDeclaration': struct_from_numpy_dtype(struct_name, index_struct_dtype), 'kernel': KernelInfo(kernel), 'stencil_info': stencil_info, + 'inverse_directions' : inv_dirs, 'dim': dim, 'target': target, 'namespace': 'pystencils', @@ -95,6 +100,10 @@ def generate_staggered_flux_boundary(generation_context, class_name, boundary_ob stencil = neighbor_stencil stencil_info = [(i, d, ", ".join([str(e) for e in d])) for i, d in enumerate(stencil)] + inv_dirs = [] + for direction in stencil: + inverse_dir = tuple([-i for i in direction]) + inv_dirs.append(stencil.index(inverse_dir)) context = { 'class_name': boundary_object.name, @@ -102,6 +111,7 @@ def generate_staggered_flux_boundary(generation_context, class_name, boundary_ob 'StructDeclaration': struct_from_numpy_dtype(struct_name, index_struct_dtype), 'kernel': KernelInfo(kernel), 'stencil_info': stencil_info, + 'inverse_directions' : inv_dirs, 'dim': dim, 'target': target, 'namespace': 'pystencils', diff --git a/python/pystencils_walberla/templates/Boundary.tmpl.h b/python/pystencils_walberla/templates/Boundary.tmpl.h index 1c3d9c0e2..46c8b69d2 100644 --- a/python/pystencils_walberla/templates/Boundary.tmpl.h +++ b/python/pystencils_walberla/templates/Boundary.tmpl.h @@ -164,7 +164,7 @@ public: {% if inner_or_boundary -%} auto element = {{StructName}}(it.x(), it.y(), {%if dim == 3%} it.z(), {%endif %} {{dirIdx}} ); {% else -%} - auto element = {{StructName}}(it.x() + cell_idx_c({{dirVec[0]}}), it.y() + cell_idx_c({{dirVec[1]}}), {%if dim == 3%} it.z() + cell_idx_c({{dirVec[2]}}), {%endif %} {{dirIdx}} ); + auto element = {{StructName}}(it.x() + cell_idx_c({{dirVec[0]}}), it.y() + cell_idx_c({{dirVec[1]}}), {%if dim == 3%} it.z() + cell_idx_c({{dirVec[2]}}), {%endif %} {{inverse_directions[dirIdx]}} ); {% endif -%} indexVectorAll.push_back( element ); if( inner.contains( it.x(), it.y(), it.z() ) ) -- GitLab