diff --git a/apps/tutorials/codegen/02_LBMLatticeModelGeneration.dox b/apps/tutorials/codegen/02_LBMLatticeModelGeneration.dox index 06271369fefe50f08836b2dd1ea91ec3f5bfeede..3166cc5001965b1586ec3622f6dea04c7454cb65 100644 --- a/apps/tutorials/codegen/02_LBMLatticeModelGeneration.dox +++ b/apps/tutorials/codegen/02_LBMLatticeModelGeneration.dox @@ -31,7 +31,7 @@ from pystencils_walberla import CodeGeneration, generate_pack_info_from_kernel from lbmpy_walberla import generate_lattice_model \endcode -First, we define a few general parameters. These include the stencil (D2Q9) and the memory layout (`fzyx`, see \ref tutorial_codegen01 ). We define a SymPy symbol for the relaxation rate \f$ \omega \f$. This means we can later set it to a specific value from the waLBerla code. A dictionary with optimization parameters is also set up. Here, we define the compilation target, enable global common subexpression elimination (`cse_global`) and set the PDF field's memory layout. In general, the target could be set to `gpu` to create a CUDA implementation, but this is currently not possible for creating a `LatticeModel` class. +First, we define a few general parameters. These include the stencil (D2Q9) and the memory layout (`fzyx`, see \ref tutorial_codegen01 ). We define a SymPy symbol for the relaxation rate \f$ \omega \f$. This means we can later set it to a specific value from the waLBerla code. A dictionary with optimization parameters is also set up. Here, we enable global common subexpression elimination (`cse_global`) and set the PDF field's memory layout. \code stencil = 'D2Q9' omega = sp.Symbol('omega') diff --git a/apps/tutorials/codegen/02_LBMLatticeModelGeneration.py b/apps/tutorials/codegen/02_LBMLatticeModelGeneration.py index 97dd55b3781279564770b7dbd25c93e9e29eee96..39deba33e739693965d7bc8119e013265342dbdf 100644 --- a/apps/tutorials/codegen/02_LBMLatticeModelGeneration.py +++ b/apps/tutorials/codegen/02_LBMLatticeModelGeneration.py @@ -14,7 +14,7 @@ omega = sp.Symbol('omega') layout = 'fzyx' # Optimizations to be used by the code generator -optimizations = {'target': 'cpu', 'cse_global': True, 'field_layout': layout} +optimizations = {'cse_global': True, 'field_layout': layout} # =========================== # SRT Method Definition diff --git a/apps/tutorials/codegen/03_AdvancedLBMCodegen.py b/apps/tutorials/codegen/03_AdvancedLBMCodegen.py index 400237e63697473e2e28d4713a3536129a341635..a397909805f5fb18f1f1d3a9235717219d7bdc7d 100644 --- a/apps/tutorials/codegen/03_AdvancedLBMCodegen.py +++ b/apps/tutorials/codegen/03_AdvancedLBMCodegen.py @@ -9,70 +9,64 @@ from pystencils_walberla import CodeGeneration, generate_sweep, generate_pack_in from lbmpy_walberla import generate_boundary -with CodeGeneration() as ctx: - - # ======================== - # Target Selection - # ======================== - - if ctx.cuda: - target = 'gpu' - else: - target = 'cpu' +# ======================== +# General Parameters +# ======================== - # ======================== - # General Parameters - # ======================== +stencil = 'D2Q9' +omega = sp.Symbol('omega') +layout = 'fzyx' - stencil = 'D2Q9' - omega = sp.Symbol('omega') - layout = 'fzyx' +# PDF Fields +pdfs, pdfs_tmp = ps.fields('pdfs(9), pdfs_tmp(9): [2D]', layout=layout) - # PDF Fields - pdfs, pdfs_tmp = ps.fields('pdfs(9), pdfs_tmp(9): [2D]', layout=layout) +# Velocity Output Field +velocity = ps.fields("velocity(2): [2D]", layout=layout) +output = {'velocity': velocity} - # Velocity Output Field - velocity = ps.fields("velocity(2): [2D]", layout=layout) - output = {'velocity': velocity} +# Optimization +optimization = {'cse_global': True, + 'symbolic_field': pdfs, + 'symbolic_temporary_field': pdfs_tmp, + 'field_layout': layout} - # Optimization - optimization = {'target': target, - 'cse_global': True, - 'symbolic_field': pdfs, - 'symbolic_temporary_field': pdfs_tmp, - 'field_layout': layout} +# ================== +# Method Setup +# ================== - # ================== - # Method Setup - # ================== +lbm_params = {'stencil': stencil, + 'method': 'mrt_raw', + 'relaxation_rates': [0, 0, 0, omega, omega, omega, 1, 1, 1], + 'cumulant': True, + 'compressible': True} - lbm_params = {'stencil': stencil, - 'method': 'mrt_raw', - 'relaxation_rates': [0, 0, 0, omega, omega, omega, 1, 1, 1], - 'cumulant': True, - 'compressible': True} +lbm_update_rule = create_lb_update_rule(optimization=optimization, + output=output, + **lbm_params) - lbm_update_rule = create_lb_update_rule(optimization=optimization, - output=output, - **lbm_params) +lbm_method = lbm_update_rule.method - lbm_method = lbm_update_rule.method +# ======================== +# PDF Initialization +# ======================== - # ======================== - # PDF Initialization - # ======================== +initial_rho = sp.Symbol('rho_0') - initial_rho = sp.Symbol('rho_0') +pdfs_setter = macroscopic_values_setter(lbm_method, + initial_rho, + velocity.center_vector, + pdfs.center_vector) - pdfs_setter = macroscopic_values_setter(lbm_method, - initial_rho, - velocity.center_vector, - pdfs.center_vector) +# ===================== +# Code Generation +# ===================== - # ===================== - # Code Generation - # ===================== +with CodeGeneration() as ctx: + if ctx.cuda: + target = 'gpu' + else: + target = 'cpu' # LBM Sweep generate_sweep(ctx, "CumulantMRTSweep", lbm_update_rule, field_swaps=[(pdfs, pdfs_tmp)], target=target)