UniformGridGPU.py 2.93 KB
Newer Older
Martin Bauer's avatar
Martin Bauer committed
1
import sympy as sp
2
import numpy as np
Martin Bauer's avatar
Martin Bauer committed
3
4
5
6
7
from lbmpy.creationfunctions import create_lb_method, create_lb_update_rule
from lbmpy.boundaries import NoSlip, UBB
from pystencils_walberla import generate_pack_info_from_kernel
from lbmpy_walberla import generate_lattice_model, generate_boundary
from pystencils_walberla import CodeGeneration, generate_sweep
8
9
from pystencils.data_types import TypedSymbol
from pystencils.fast_approximation import insert_fast_sqrts, insert_fast_divisions
Martin Bauer's avatar
Martin Bauer committed
10

11
12
13
14
15
omega = sp.symbols("omega")
# sweep_block_size = (128, 1, 1)
sweep_block_size = (TypedSymbol("cudaBlockSize0", np.int32),
                    TypedSymbol("cudaBlockSize1", np.int32),
                    1)
Martin Bauer's avatar
Martin Bauer committed
16

Martin Bauer's avatar
Martin Bauer committed
17
18
sweep_params = {'block_size': sweep_block_size}

19
20
options = {
    'srt': {
Martin Bauer's avatar
Martin Bauer committed
21
22
        'method': 'srt',
        'stencil': 'D3Q19',
23
        'relaxation_rate': omega,
Martin Bauer's avatar
Martin Bauer committed
24
        'compressible': False,
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    },
    'trt': {
        'method': 'trt',
        'stencil': 'D3Q19',
        'relaxation_rate': omega,
    },
    'mrt': {
        'method': 'mrt',
        'stencil': 'D3Q19',
        'relaxation_rates': [0, omega, 1.3, 1.4, omega, 1.2, 1.1],
    },
    'entropic': {
        'method': 'mrt3',
        'stencil': 'D3Q19',
        'compressible': True,
        'relaxation_rates': [omega, omega, sp.Symbol("omega_free")],
        'entropic': True,
    },
    'smagorinsky': {
        'method': 'srt',
        'stencil': 'D3Q19',
        'smagorinsky': True,
        'relaxation_rate': omega,
    }
}

with CodeGeneration() as ctx:

    common_options = {
        'field_name': 'pdfs',
Martin Bauer's avatar
Martin Bauer committed
55
        'temporary_field_name': 'pdfs_tmp',
56
        #'kernel_type': 'collide_stream_push',
Martin Bauer's avatar
Martin Bauer committed
57
        'optimization': {'cse_global': True,
58
                         'cse_pdfs': False}
Martin Bauer's avatar
Martin Bauer committed
59
    }
60
61
62
63
64
65
66
    options = options[ctx.config]
    options.update(common_options)

    vp = [
        ('int32_t', 'cudaBlockSize0'),
        ('int32_t', 'cudaBlockSize1')
    ]
Martin Bauer's avatar
Martin Bauer committed
67
68
69
    lb_method = create_lb_method(**options)
    update_rule = create_lb_update_rule(lb_method=lb_method, **options)

70
71
72
    update_rule = insert_fast_divisions(update_rule)
    update_rule = insert_fast_sqrts(update_rule)

Martin Bauer's avatar
Martin Bauer committed
73
    # CPU lattice model - required for macroscopic value computation, VTK output etc.
74
75
76
    options_without_opt = options.copy()
    del options_without_opt['optimization']
    generate_lattice_model(ctx, 'UniformGridGPU_LatticeModel', lb_method, update_rule_params=options_without_opt)
Martin Bauer's avatar
Martin Bauer committed
77
78

    # gpu LB sweep & boundaries
79
80
81
82
83
    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)

Martin Bauer's avatar
Martin Bauer committed
84
85
86
87
88
    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')