From 1118257a70c05f42832003ac5ad010a6547091d5 Mon Sep 17 00:00:00 2001 From: et31efoj <markus.holzer@fau.de> Date: Thu, 26 Sep 2019 08:47:02 +0200 Subject: [PATCH] Hotfix for creation of wrong index when using generate_boundary in 2D --- lbmpy_walberla/boundary.py | 11 ++++++++++- lbmpy_walberla_tests/test_walberla_codegen.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lbmpy_walberla/boundary.py b/lbmpy_walberla/boundary.py index 865ec33..5f2dc6f 100644 --- a/lbmpy_walberla/boundary.py +++ b/lbmpy_walberla/boundary.py @@ -32,7 +32,16 @@ def generate_boundary(generation_context, class_name, boundary_object, lb_method openmp=generation_context.openmp) kernel.function_name = "boundary_" + boundary_object.name - stencil_info = [(i, ", ".join([str(e) for e in d])) for i, d in enumerate(lb_method.stencil)] + # waLBerla is a 3D framework. Therefore, a zero for the z index has to be added if we work in 2D + if lb_method.dim == 2: + stencil = () + for d in lb_method.stencil: + d = d + (0,) + stencil = stencil + (d,) + else: + stencil = lb_method.stencil + + stencil_info = [(i, ", ".join([str(e) for e in d])) for i, d in enumerate(stencil)] context = { 'class_name': boundary_object.name, diff --git a/lbmpy_walberla_tests/test_walberla_codegen.py b/lbmpy_walberla_tests/test_walberla_codegen.py index 9ec5724..cde21c5 100644 --- a/lbmpy_walberla_tests/test_walberla_codegen.py +++ b/lbmpy_walberla_tests/test_walberla_codegen.py @@ -91,7 +91,13 @@ class WalberlaLbmpyCodegenTest(unittest.TestCase): generate_lattice_model(ctx, 'FluctuatingMRT', collision_rule) @staticmethod - def test_boundary(): + def test_boundary_3D(): with ManualCodeGenerationContext(openmp=True, double_accuracy=True) as ctx: lb_method = create_lb_method(stencil='D3Q19', method='srt') - generate_boundary(ctx, 'Boundary', NoSlip(), lb_method, target='gpu') \ No newline at end of file + generate_boundary(ctx, 'Boundary', NoSlip(), lb_method, target='gpu') + + @staticmethod + def test_boundary_2D(): + with ManualCodeGenerationContext(openmp=True, double_accuracy=True) as ctx: + lb_method = create_lb_method(stencil='D2Q9', method='srt') + generate_boundary(ctx, 'Boundary', NoSlip(), lb_method, target='gpu') -- GitLab