test_srt_trt_simplifications.py 2.67 KB
Newer Older
1
2
3
4
5
6
7
8
"""
This unittest checks the simplification quality of SRT and TRT (compressible and incompressible) against
known acceptable values.
"""
import sympy as sp

from lbmpy.forcemodels import Guo
from lbmpy.methods import create_srt, create_trt, create_trt_with_magic_number
Martin Bauer's avatar
Martin Bauer committed
9
from lbmpy.methods.momentbasedsimplifications import cse_in_opposing_directions
Martin Bauer's avatar
Martin Bauer committed
10
from lbmpy.simplificationfactory import create_simplification_strategy
11
12
13
14
from lbmpy.stencils import get_stencil


def check_method(method, limits_default, limits_cse):
Martin Bauer's avatar
Martin Bauer committed
15
16
    strategy = create_simplification_strategy(method)
    strategy_with_cse = create_simplification_strategy(method)
Martin Bauer's avatar
Martin Bauer committed
17
    strategy_with_cse.add(cse_in_opposing_directions)
18
19
20
21
22
23
24
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
55
56
57
58
59
60
61
62
63
64
65
66
    collision_rule = method.get_collision_rule()

    ops_default = strategy(collision_rule).operation_count
    ops_cse = strategy_with_cse(collision_rule).operation_count

    assert ops_default['adds'] <= limits_default[0]
    assert ops_default['muls'] <= limits_default[1]
    assert ops_default['divs'] <= limits_default[2]

    assert ops_cse['adds'] <= limits_cse[0]
    assert ops_cse['muls'] <= limits_cse[1]
    assert ops_cse['divs'] <= limits_cse[2]


def test_simplifications_srt_d2q9_incompressible():
    omega = sp.symbols('omega')
    method = create_srt(get_stencil("D2Q9"), omega, compressible=False, equilibrium_order=2)
    check_method(method, [53, 46, 0], [49, 30, 0])


def test_simplifications_srt_d2q9_compressible():
    omega = sp.symbols('omega')
    method = create_srt(get_stencil("D2Q9"), omega, compressible=True, equilibrium_order=2)
    check_method(method, [53, 57, 1], [53, 41, 1])


def test_simplifications_trt_d2q9_incompressible():
    o1, o2 = sp.symbols("omega_1 omega_2")
    method = create_trt(get_stencil("D2Q9"), o1, o2, compressible=False)
    check_method(method, [77, 86, 0], [65, 38, 0])


def test_simplifications_trt_d2q9_compressible():
    o1, o2 = sp.symbols("omega_1 omega_2")
    method = create_trt(get_stencil("D2Q9"), o1, o2, compressible=True)
    check_method(method, [77, 105, 1], [65, 55, 1])


def test_simplifications_trt_d3q19_force_incompressible():
    o1, o2 = sp.symbols("omega_1 omega_2")
    force_model = Guo([sp.Rational(1, 3), sp.Rational(1, 2), sp.Rational(1, 5)])
    method = create_trt(get_stencil("D3Q19"), o1, o2, compressible=False, force_model=force_model)
    check_method(method, [268, 281, 0], [241, 175, 1])


def test_simplifications_trt_d3q19_force_compressible():
    o1, o2 = sp.symbols("omega_1 omega_2")
    force_model = Guo([sp.Rational(1, 3), sp.Rational(1, 2), sp.Rational(1, 5)])
    method = create_trt_with_magic_number(get_stencil("D3Q19"), o1, compressible=False, force_model=force_model)
Martin Bauer's avatar
Martin Bauer committed
67
    check_method(method, [270, 283, 1], [243, 177, 1])