Ejemplo n.º 1
0
    def test_incompressible():
        with ManualCodeGenerationContext() as ctx:
            omega = sp.Symbol("omega")

            cr = create_lb_collision_rule(stencil='D3Q19',
                                          method='srt',
                                          relaxation_rates=[omega],
                                          compressible=False)
            generate_lattice_model(ctx, 'Model', cr)
            assert 'static const bool compressible = false;' in ctx.files[
                'Model.h']
Ejemplo n.º 2
0
 def test_output_field():
     with ManualCodeGenerationContext(openmp=True,
                                      double_accuracy=True) as ctx:
         omega_field = ps.fields("omega_out: [3D]", layout='fzyx')
         parameters = {
             'stencil': 'D3Q27',
             'method': 'trt-kbc-n1',
             'compressible': True,
             'entropic': True,
             'omega_output_field': omega_field,
         }
         cr = create_lb_collision_rule(**parameters)
         generate_lattice_model(ctx, 'Model', cr)
Ejemplo n.º 3
0
    def test_fluctuating():
        with ManualCodeGenerationContext(openmp=True,
                                         double_accuracy=True) as ctx:
            omega_shear = sp.symbols("omega")
            force_field, vel_field = ps.fields("force(3), velocity(3): [3D]",
                                               layout='fzyx')

            # the collision rule of the LB method where the some advanced features
            collision_rule = create_lb_collision_rule(
                stencil='D3Q19',
                compressible=True,
                fluctuating={
                    'seed': 0,
                    'temperature': 1e-6
                },
                method='mrt',
                relaxation_rates=[omega_shear] * 19,
                force_model='guo',
                force=force_field.center_vector,
                optimization={'cse_global': False})
            generate_lattice_model(ctx, 'FluctuatingMRT', collision_rule)
Ejemplo n.º 4
0
    def test_lattice_model():
        with ManualCodeGenerationContext() as ctx:
            force_field = ps.fields("force(3): [3D]", layout='fzyx')
            omega = sp.Symbol("omega")

            cr = create_lb_collision_rule(stencil='D3Q19',
                                          method='srt',
                                          relaxation_rates=[omega],
                                          compressible=True,
                                          force_model='guo',
                                          force=force_field.center_vector)

            scaling = RefinementScaling()
            scaling.add_standard_relaxation_rate_scaling(omega)
            scaling.add_force_scaling(force_field)

            generate_lattice_model(ctx,
                                   'SrtWithForceFieldModel',
                                   cr,
                                   refinement_scaling=scaling)
            generate_boundary(ctx, 'MyUBB', UBB([0.05, 0, 0]), cr.method)
            generate_boundary(ctx, 'MyNoSlip', NoSlip(), cr.method)
            assert 'static const bool compressible = true;' in ctx.files[
                'SrtWithForceFieldModel.h']
Ejemplo n.º 5
0
        ('double', 'omega_6'),
        ('int32_t', 'cudaBlockSize0'),
        ('int32_t', 'cudaBlockSize1'),
    ]
    lb_method = create_lb_method(**options)
    update_rule = create_lb_update_rule(lb_method=lb_method, **options)

    if not noopt:
        update_rule = insert_fast_divisions(update_rule)
        update_rule = insert_fast_sqrts(update_rule)

    # CPU lattice model - required for macroscopic value computation, VTK output etc.
    options_without_opt = options.copy()
    del options_without_opt['optimization']
    generate_lattice_model(ctx,
                           'UniformGridGPU_LatticeModel',
                           lb_method,
                           update_rule_params=options_without_opt)

    # gpu LB sweep & boundaries
    generate_sweep(ctx,
                   'UniformGridGPU_LbKernel',
                   update_rule,
                   field_swaps=[('pdfs', 'pdfs_tmp')],
                   inner_outer_split=True,
                   target='gpu',
                   gpu_indexing_params=sweep_params,
                   varying_parameters=vp)

    generate_boundary(ctx,
                      'UniformGridGPU_NoSlip',
                      NoSlip(),
Ejemplo n.º 6
0
from pystencils_walberla import CodeGeneration, generate_sweep


with CodeGeneration() as ctx:
    # LB options
    options = {
        'method': 'srt',
        'stencil': 'D3Q19',
        'relaxation_rate': sp.Symbol("omega"),
        'field_name': 'pdfs',
        'compressible': False,
        'temporary_field_name': 'pdfs_tmp',
        'optimization': {'cse_global': True,
                         'cse_pdfs': True,
                         'gpu_indexing_params': {'block_size': (128, 1, 1)}}
    }
    lb_method = create_lb_method(**options)
    update_rule = create_lb_update_rule(lb_method=lb_method, **options)

    # CPU lattice model - required for macroscopic value computation, VTK output etc.
    generate_lattice_model(ctx, 'UniformGridGPU_LatticeModel', lb_method)

    # gpu LB sweep & boundaries
    generate_sweep(ctx, 'UniformGridGPU_LbKernel', update_rule, field_swaps=[('pdfs', 'pdfs_tmp')],
                   inner_outer_split=True, target='gpu')
    generate_boundary(ctx, 'UniformGridGPU_NoSlip', NoSlip(), lb_method, target='gpu')
    generate_boundary(ctx, 'UniformGridGPU_UBB', UBB([0.05, 0, 0]), lb_method, target='gpu')

    # communication
    generate_pack_info_from_kernel(ctx, 'UniformGridGPU_PackInfo', update_rule, target='gpu')
Ejemplo n.º 7
0
import sympy as sp
import pystencils as ps
from lbmpy.creationfunctions import create_lb_method
from lbmpy.boundaries import NoSlip, UBB
from pystencils_walberla import CodeGeneration
from lbmpy_walberla import generate_lattice_model, RefinementScaling, generate_boundary


with CodeGeneration() as ctx:
    omega = sp.Symbol("omega")
    force_field = ps.fields("force(3): [3D]", layout='fzyx')

    # lattice Boltzmann method
    lb_method = create_lb_method(stencil='D3Q19', method='srt', relaxation_rates=[omega],
                                 force_model='guo', force=force_field.center_vector)

    scaling = RefinementScaling()
    scaling.add_standard_relaxation_rate_scaling(omega)
    scaling.add_force_scaling(force_field)

    # generate components
    generate_lattice_model(ctx, 'SrtWithForceFieldModel', lb_method, refinement_scaling=scaling)
    generate_boundary(ctx, 'MyUBB', UBB([0.05, 0, 0]), lb_method)
    generate_boundary(ctx, 'MyNoSlip', NoSlip(), lb_method)
Ejemplo n.º 8
0
import sympy as sp
import pystencils as ps
from lbmpy.creationfunctions import create_lb_method
from lbmpy.boundaries import NoSlip, UBB
from pystencils_walberla import CodeGeneration
from lbmpy_walberla import generate_lattice_model, RefinementScaling, generate_boundary

with CodeGeneration() as ctx:
    omega = sp.Symbol("omega")
    force_field = ps.fields("force(3): [3D]", layout='fzyx')

    # lattice Boltzmann method
    lb_method = create_lb_method(stencil='D3Q19',
                                 method='srt',
                                 relaxation_rates=[omega],
                                 force_model='guo',
                                 force=force_field.center_vector)

    scaling = RefinementScaling()
    scaling.add_standard_relaxation_rate_scaling(omega)
    scaling.add_force_scaling(force_field)

    # generate components
    generate_lattice_model(ctx,
                           'SrtWithForceFieldModel',
                           lb_method,
                           refinement_scaling=scaling)
    generate_boundary(ctx, 'MyUBB', UBB([0.05, 0, 0]), lb_method)
    generate_boundary(ctx, 'MyNoSlip', NoSlip(), lb_method)
Ejemplo n.º 9
0
        method='mrt3',
        relaxation_rates=[omega, omega, omega_free],
        entropic=
        True,  # entropic method where second omega is chosen s.t. entropy condition
        omega_output_field=
        omega_out,  # scalar field where automatically chosen omega of entropic or Smagorinsky method is written to
        force=force_field.
        center_vector,  # read forces for each lattice cell from an external force field
        # that is initialized and changed in C++ app
        output={'velocity': vel_field
                },  # write macroscopic velocity to field in every time step
        # useful for coupling multiple LB methods, e.g. hydrodynamic to advection/diffusion LBM
        optimization={'cse_global': True})

    # the refinement scaling object describes how certain parameters are scaled across grid scales
    # there are two default scaling behaviors available for relaxation rates and forces:
    scaling = RefinementScaling()
    scaling.add_standard_relaxation_rate_scaling(omega)
    scaling.add_force_scaling(force_field)

    # generate lattice model and (optionally) boundary conditions
    # for CPU simulations waLBerla's internal boundary handling can be used as well
    generate_lattice_model(ctx,
                           'LbCodeGenerationExample_LatticeModel',
                           collision_rule,
                           refinement_scaling=scaling)
    generate_boundary(ctx, 'LbCodeGenerationExample_UBB', UBB([0.05, 0, 0]),
                      collision_rule.method)
    generate_boundary(ctx, 'LbCodeGenerationExample_NoSlip', NoSlip(),
                      collision_rule.method)
Ejemplo n.º 10
0
import sympy as sp
import pystencils as ps
from lbmpy.creationfunctions import create_lb_collision_rule
from pystencils_walberla import CodeGeneration
from lbmpy_walberla import generate_lattice_model

with CodeGeneration() as ctx:
    omega_shear, omega_bulk = sp.symbols("omega_shear, omega_bulk")
    temperature = sp.symbols("temperature")
    force_field, vel_field = ps.fields("force(3), velocity(3): [3D]",
                                       layout='fzyx')

    collision_rule = create_lb_collision_rule(
        stencil='D3Q19',
        compressible=True,
        fluctuating={
            'temperature': temperature,
            'block_offsets': 'walberla',
        },
        method='mrt3',
        relaxation_rates=[omega_shear, omega_bulk],
        force_model='guo',
        force=force_field.center_vector,
        optimization={'cse_global': True})

    generate_lattice_model(ctx, 'FluctuatingMRT_LatticeModel', collision_rule)