def test_get_force_He_discrete(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        F_in_cm = get_mom_vector_from_discrete_def(dcmt.get_force_He,
                                                   discrete_transform=dcmt.get_cm,
                                                   moments_order=moments_dict['D2Q9'],
                                                   serial_run=True)
        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(F_in_cm, 'F_in_cm')
        out = f.getvalue()

        expected_result = '\tF_in_cm[0] = 0;\n' \
                          '\tF_in_cm[1] = Fhydro.x*m00/rho;\n' \
                          '\tF_in_cm[2] = Fhydro.y*m00/rho;\n' \
                          '\tF_in_cm[3] = -3.*m00*ux2*(Fhydro.x*u.x + Fhydro.y*u.y)/rho;\n' \
                          '\tF_in_cm[4] = -3.*m00*uy2*(Fhydro.x*u.x + Fhydro.y*u.y)/rho;\n' \
                          '\tF_in_cm[5] = -3.*m00*uxuy*(Fhydro.x*u.x + Fhydro.y*u.y)/rho;\n' \
                          '\tF_in_cm[6] = m00*(9.*Fhydro.x*ux3*u.y + 9.*Fhydro.y*ux2*uy2 + 1/3.*Fhydro.y)/rho;\n' \
                          '\tF_in_cm[7] = m00*(9.*Fhydro.x*ux2*uy2 + 1/3.*Fhydro.x + 9.*Fhydro.y*u.x*uy3)/rho;\n' \
                          '\tF_in_cm[8] = -m00*(18.*Fhydro.x*ux3*uy2 + Fhydro.x*ux3 + 3.*Fhydro.x*u.x*uy2 + 18.*Fhydro.y*ux2*uy3 + 3.*Fhydro.y*ux2*u.y + Fhydro.y*uy3)/rho;\n'  # noqa

        assert 'F_in_cm[0] = 0;' in out
        assert 'F_in_cm[1] = Fhydro.x*m00/rho;' in out
        assert 'F_in_cm[2] = Fhydro.y*m00/rho;' in out
        assert 'F_in_cm[3] = -3.*m00*ux2*(Fhydro.x*u.x + Fhydro.y*u.y)/rho;\n' in out
        assert 'F_in_cm[4] = -3.*m00*uy2*(Fhydro.x*u.x + Fhydro.y*u.y)/rho;\n' in out
        assert 'F_in_cm[5] = -3.*m00*uxuy*(Fhydro.x*u.x + Fhydro.y*u.y)/rho;\n' in out
        assert 'F_in_cm[6] = m00*(9.*Fhydro.x*ux3*u.y + 9.*Fhydro.y*ux2*uy2 + 1/3.*Fhydro.y)/rho;\n' in out
        assert 'F_in_cm[7] = m00*(9.*Fhydro.x*ux2*uy2 + 1/3.*Fhydro.x + 9.*Fhydro.y*u.x*uy3)/rho;\n' in out
        assert 'F_in_cm[8] = -m00*(18.*Fhydro.x*ux3*uy2 + Fhydro.x*ux3 + 3.*Fhydro.x*u.x*uy2 + 18.*Fhydro.y*ux2*uy3 + 3.*Fhydro.y*ux2*u.y + Fhydro.y*uy3)/rho;\n' in out  # noqa

        assert expected_result == out
예제 #2
0
    def test_get_cm_eq_incompressible_continuous(self):
        # population_eq -> cm_eq - from continous definition: '
        # k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) '
        # where fun = fM(rho,u,x,y) *(x-ux)^m *(y-uy)^n * (z-uz)^o ')

        cm_i = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)
        cm_eq = get_mom_vector_from_continuous_def(
            cm_i.get_incompressible_DF,
            continuous_transformation=cm_i.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        # TODO: can't use hardcoded_cm_eq_incompressible_D2Q9,
        #  because sympy switches hardcoded 'u.x*(-m00 + 1)' to '-u.x*(m00 - 1') and test fails.
        #  thank you sympy...

        assert f'cm_eq[0] = {m00};' in out
        assert f'cm_eq[1] = u.x*(1 - {m00});' in out or f'cm_eq[1] = u.x*(-{m00} + 1);' in out
        assert f'cm_eq[2] = u.y*(1 - {m00});' in out or f'cm_eq[2] = u.y*(-{m00} + 1);' in out
        assert f'cm_eq[3] = {m00}*ux2 + 1/3.*{m00} - ux2;\n' in out
        assert f'cm_eq[4] = {m00}*uy2 + 1/3.*{m00} - uy2;\n' in out
        assert f'cm_eq[5] = uxuy*({m00} - 1.);\n' in out
        assert f'cm_eq[6] = u.y*(-{m00}*ux2 - 1/3.*{m00} + ux2 + 1/3.);\n' in out
        assert f'cm_eq[7] = u.x*(-{m00}*uy2 - 1/3.*{m00} + uy2 + 1/3.);\n' in out
        assert f'cm_eq[8] = {m00}*ux2*uy2 + 1/3.*{m00}*ux2 + 1/3.*{m00}*uy2 + 1/9.*{m00} - ux2*uy2 - 1/3.*ux2 - 1/3.*uy2;\n' in out  # noqa
    def test_get_F_cm_Guo_continuous_and_discrete(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        F_cm_Guo_disc = get_mom_vector_from_discrete_def(dcmt.get_force_Guo,
                                                         discrete_transform=dcmt.get_cm,
                                                         moments_order=moments_dict['D2Q9'],
                                                         serial_run=True)

        from SymbolicCollisions.core.ContinousCMTransforms import \
            ContinousCMTransforms, get_mom_vector_from_continuous_def

        from SymbolicCollisions.core.cm_symbols import \
            F3D, dzeta3D, u3D

        ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)
        F_cm_Guo_cont = get_mom_vector_from_continuous_def(ccmt.get_force_Guo,
                                                           continuous_transformation=ccmt.get_cm,
                                                           moments_order=moments_dict['D2Q9'],
                                                           serial_run=True)

        # print_as_vector(F_cm_Guo_cont, 'F_cm')
        results = [F_cm_Guo_disc, F_cm_Guo_cont]

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(hardcoded_F_cm_Guo_hydro_LB_velocity_based_D2Q9, 'F_cm')
        expected_result = f.getvalue()

        for result in results:
            f = io.StringIO()
            with redirect_stdout(f):
                print_as_vector(result, 'F_cm')
            out = f.getvalue()

            assert out == expected_result
    def test_get_cm_eq_hydro_discrete(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        cm_eq = get_mom_vector_from_discrete_def(dcmt.get_EDF_hydro,
                                                 discrete_transform=dcmt.get_cm,
                                                 moments_order=moments_dict['D2Q9'],
                                                 serial_run=True)
        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        expected_result = '\tcm_eq[0] = m00;\n' \
                          '\tcm_eq[1] = u.x*(-m00 + 1);\n' \
                          '\tcm_eq[2] = u.y*(-m00 + 1);\n' \
                          '\tcm_eq[3] = m00*ux2 + 1/3.*m00 - ux2;\n' \
                          '\tcm_eq[4] = m00*uy2 + 1/3.*m00 - uy2;\n' \
                          '\tcm_eq[5] = uxuy*(m00 - 1.);\n' \
                          '\tcm_eq[6] = u.y*(-m00*ux2 - 1/3.*m00 + 1/3.);\n' \
                          '\tcm_eq[7] = u.x*(-m00*uy2 - 1/3.*m00 + 1/3.);\n' \
                          '\tcm_eq[8] = m00*ux2*uy2 + 1/3.*m00*ux2 + 1/3.*m00*uy2 + 1/9.*m00 + 2.*ux2*uy2 - 1/3.*ux2 - 1/3.*uy2;\n'  # noqa

        assert 'cm_eq[0] = m00;' in out
        assert 'cm_eq[1] = u.x*(-m00 + 1)' in out
        assert 'cm_eq[2] = u.y*(-m00 + 1);' in out
        assert 'cm_eq[3] = m00*ux2 + 1/3.*m00 - ux2;\n' in out
        assert 'cm_eq[4] = m00*uy2 + 1/3.*m00 - uy2;\n' in out
        assert 'cm_eq[5] = uxuy*(m00 - 1.);\n' in out
        assert 'cm_eq[6] = u.y*(-m00*ux2 - 1/3.*m00 + 1/3.);\n' in out
        assert 'cm_eq[7] = u.x*(-m00*uy2 - 1/3.*m00 + 1/3.);\n' in out
        assert 'cm_eq[8] = m00*ux2*uy2 + 1/3.*m00*ux2 + 1/3.*m00*uy2 + 1/9.*m00 + 2.*ux2*uy2 - 1/3.*ux2 - 1/3.*uy2;\n' in out  # noqa

        assert expected_result == out
예제 #5
0
    def test_get_F_cm_using_He_scheme_and_continuous_Maxwellian_DF(self):
        cm_i = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)
        F_cm = get_mom_vector_from_continuous_def(
            cm_i.get_force_He_hydro_DF,
            continuous_transformation=cm_i.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(F_cm, 'F_cm')
        out = f.getvalue()

        # TODO: can't use hardcoded_cm_eq_incompressible_D2Q9,
        #  because sympy switches hardcoded terms like 'u.x*(-m00 + 1)' to '-u.x*(m00 - 1') and test fails.
        #  thank you sympy...

        assert f'\tF_cm[0] = 0;\n' in out
        assert f'\tF_cm[1] = {Force_str}.x*{m00}/rho;\n' in out
        assert f'\tF_cm[2] = {Force_str}.y*{m00}/rho;\n' in out
        assert f'\tF_cm[3] = -2.*{Force_str}.x*u.x*({m00} - 1.)/rho;\n' in out
        assert f'\tF_cm[4] = -2.*{Force_str}.y*u.y*({m00} - 1.)/rho;\n' in out
        assert f'\tF_cm[5] = (-{Force_str}.x*{m00}*u.y + {Force_str}.x*u.y - {Force_str}.y*{m00}*u.x + {Force_str}.y*u.x)/rho;\n' in out
        assert f'\tF_cm[6] = (2.*{Force_str}.x*{m00}*uxuy - 2.*{Force_str}.x*uxuy + {Force_str}.y*{m00}*ux2 + 1/3.*{Force_str}.y*{m00} - {Force_str}.y*ux2)/rho;\n' in out
        assert f'\tF_cm[7] = ({Force_str}.x*{m00}*uy2 + 1/3.*{Force_str}.x*{m00} - {Force_str}.x*uy2 + 2.*{Force_str}.y*{m00}*uxuy - 2.*{Force_str}.y*uxuy)/rho;\n' in out
        assert f'\tF_cm[8] = (-2.*{Force_str}.x*{m00}*u.x*uy2 - 2/3.*{Force_str}.x*{m00}*u.x + 2.*{Force_str}.x*u.x*uy2 + 2/3.*{Force_str}.x*u.x - 2.*{Force_str}.y*{m00}*ux2*u.y - 2/3.*{Force_str}.y*{m00}*u.y + 2.*{Force_str}.y*ux2*u.y + 2/3.*{Force_str}.y*u.y)/rho;\n' in out
예제 #6
0
    def test_get_cumulants(self):
        from SymbolicCollisions.core.cumulants import get_cumulant
        from SymbolicCollisions.core.printers import print_as_vector
        from sympy.matrices import Matrix

        order = [
            (1, 0, 0),
            (0, 1, 0),
            (0, 0, 1),
            (2, 0, 0),
            (0, 2, 0),
            (0, 0, 2),
            (1, 1, 0)]

        result = [
            '= m100;',
            '= m010;',
            '= m001;',
            '= m200 - m100*m100/m000;',
            '= m020 - m010*m010/m000',
            '= m002 - m001*m001/m000;',
            '= m110 - m010*m100/m000;']

        for o, r in zip(order, result):
            cumulant, _ = get_cumulant(*o)

            f = io.StringIO()
            with redirect_stdout(f):
                mc = Matrix([cumulant])  # printer works using Matrix format
                print_as_vector(mc, 'c')
            out = f.getvalue()

            assert r in out
    def test_get_F_cm_using_He_scheme_and_continuous_Maxwellian_DF(self):
        cm_i = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)
        F_cm = get_mom_vector_from_continuous_def(cm_i.get_force_He_hydro_DF,
                                                  continuous_transformation=cm_i.get_cm,
                                                  moments_order=moments_dict['D2Q9'],
                                                  serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(F_cm, 'F_cm')
        out = f.getvalue()

        # TODO: can't use hardcoded_cm_eq_incompressible_D2Q9,
        #  because sympy switches hardcoded terms like 'u.x*(-m00 + 1)' to '-u.x*(m00 - 1') and test fails.
        #  thank you sympy...

        expected_result = \
            '\tF_cm[0] = 0;\n' \
            '\tF_cm[1] = Fhydro.x*m00/rho;\n' \
            '\tF_cm[2] = Fhydro.y*m00/rho;\n' \
            '\tF_cm[3] = -2.*Fhydro.x*u.x*(m00 - 1.)/rho;\n' \
            '\tF_cm[4] = -2.*Fhydro.y*u.y*(m00 - 1.)/rho;\n' \
            '\tF_cm[5] = (-Fhydro.x*m00*u.y + Fhydro.x*u.y - Fhydro.y*m00*u.x + Fhydro.y*u.x)/rho;\n' \
            '\tF_cm[6] = (2.*Fhydro.x*m00*uxuy - 2.*Fhydro.x*uxuy + Fhydro.y*m00*ux2 + 1/3.*Fhydro.y*m00 - Fhydro.y*ux2)/rho;\n' \
            '\tF_cm[7] = (Fhydro.x*m00*uy2 + 1/3.*Fhydro.x*m00 - Fhydro.x*uy2 + 2.*Fhydro.y*m00*uxuy - 2.*Fhydro.y*uxuy)/rho;\n' \
            '\tF_cm[8] = (-2.*Fhydro.x*m00*u.x*uy2 - 2/3.*Fhydro.x*m00*u.x + 2.*Fhydro.x*u.x*uy2 + 2/3.*Fhydro.x*u.x - 2.*Fhydro.y*m00*ux2*u.y - 2/3.*Fhydro.y*m00*u.y + 2.*Fhydro.y*ux2*u.y + 2/3.*Fhydro.y*u.y)/rho;\n'

        assert expected_result == out
def make_collision(choice):
    model_switcher = {
        # Relax 2nd moments for hydro, SOI
        'hydro_compressible': (eye(q) - S_Relax) * temp_populations
                              + S_Relax * hardcoded_cm_eq
                              + (eye(q) - S_Relax / 2) * hardcoded_F_cm,

        'hydro_incompressible': (eye(q) - S_Relax) * temp_populations
                                + S_Relax * hardcoded_cm_eq
                                + (eye(q) - S_Relax / 2) * hardcoded_F_cm,
        # Relax 1st moments for ADE, SOI
        'ade_with_f': (eye(q) - S_Relax) * temp_populations
                      + S_Relax * hardcoded_cm_eq
                      + (eye(q) - S_Relax / 2) * hardcoded_F_cm,
        # Relax 1st moments for ADE, SOI without force
        'ade': (eye(q) - S_Relax) * temp_populations
               + S_Relax * hardcoded_cm_eq,
        # Relax 1,3,5 moments for ADE, SOI without force
        'cht': (eye(q) - S_Relax) * temp_populations
               + S_Relax * hardcoded_cm_eq,
    }
    # Get the function from switcher dictionary
    cm_after_collision = model_switcher.get(choice, lambda: "Invalid argument")

    print_as_vector(cm_after_collision, outprint_symbol=pop_in_str)
예제 #9
0
    def test_get_cumulants(self):
        from SymbolicCollisions.core.cumulants import get_cumulant
        from SymbolicCollisions.core.printers import print_as_vector
        from sympy.matrices import Matrix

        order = [
            (1, 0, 0),
            (0, 1, 0),
            (0, 0, 1),
            (2, 0, 0),
            (0, 2, 0),
            (0, 0, 2),
            (1, 1, 0)]

        result = [
            '= m100;',
            '= m010;',
            '= m001;',
            '= m200 - m100**2/m000;',
            '= m020 - m010**2/m000',
            '= m002 - m001**2/m000;',
            '= m110 - m010*m100/m000;']

        for o, r in zip(order, result):
            cumulant, _ = get_cumulant(*o)

            f = io.StringIO()
            with redirect_stdout(f):
                mc = Matrix([cumulant])  # printer works using Matrix format
                print_as_vector(mc, 'c')
            out = f.getvalue()

            assert r in out
예제 #10
0
    def test_shift_vs_def_cm(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

        functions = [
            lambda i: w_D2Q9[i], dcmt.get_force_He, dcmt.get_force_Guo
        ]
        from SymbolicCollisions.core.cm_symbols import Mraw_D2Q9, NrawD2Q9

        for fun in functions:
            F_in_cm = get_mom_vector_from_discrete_def(
                fun,
                discrete_transform=dcmt.get_cm,
                moments_order=moments_dict['D2Q9'],
                serial_run=True)  # calculate from definition of cm
            NMF_cm = get_mom_vector_from_shift_mat(
                fun,
                mat=NrawD2Q9 * Mraw_D2Q9)  # calculate using shift matrices

            f = io.StringIO()
            with redirect_stdout(f):
                print_as_vector(F_in_cm, 'F_in_cm')
            out = f.getvalue()

            f2 = io.StringIO()
            with redirect_stdout(f2):
                print_as_vector(NMF_cm, 'F_in_cm')
            out2 = f2.getvalue()

            assert out == out2
예제 #11
0
    def test_get_force_He_discrete(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        F_in_cm = get_mom_vector_from_discrete_def(
            dcmt.get_force_He,
            discrete_transform=dcmt.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)
        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(F_in_cm, f'F_in_cm')
        out = f.getvalue()

        assert f'F_in_cm[0] = 0;' in out
        assert f'F_in_cm[1] = {Force_str}.x*{m00}/rho;' in out
        assert f'F_in_cm[2] = {Force_str}.y*{m00}/rho;' in out
        assert f'F_in_cm[3] = -3.*{m00}*ux2*({Force_str}.x*u.x + {Force_str}.y*u.y)/rho;\n' in out
        assert f'F_in_cm[4] = -3.*{m00}*uy2*({Force_str}.x*u.x + {Force_str}.y*u.y)/rho;\n' in out
        assert f'F_in_cm[5] = -3.*{m00}*uxuy*({Force_str}.x*u.x + {Force_str}.y*u.y)/rho;\n' in out
        assert f'F_in_cm[6] = {m00}*(9.*{Force_str}.x*ux3*u.y + 9.*{Force_str}.y*ux2*uy2 + 1/3.*{Force_str}.y)/rho;\n' in out
        assert f'F_in_cm[7] = {m00}*(9.*{Force_str}.x*ux2*uy2 + 1/3.*{Force_str}.x + 9.*{Force_str}.y*u.x*uy3)/rho;\n' in out
        assert f'F_in_cm[8] = -{m00}*(18.*{Force_str}.x*ux3*uy2 + {Force_str}.x*ux3 + 3.*{Force_str}.x*u.x*uy2 + 18.*{Force_str}.y*ux2*uy3 + 3.*{Force_str}.y*ux2*u.y + {Force_str}.y*uy3)/rho;\n' in out  # noqa

        expected_result = f'\tF_in_cm[0] = 0;\n' \
                          f'\tF_in_cm[1] = {Force_str}.x*{m00}/rho;\n' \
                          f'\tF_in_cm[2] = {Force_str}.y*{m00}/rho;\n' \
                          f'\tF_in_cm[3] = -3.*{m00}*ux2*({Force_str}.x*u.x + {Force_str}.y*u.y)/rho;\n' \
                          f'\tF_in_cm[4] = -3.*{m00}*uy2*({Force_str}.x*u.x + {Force_str}.y*u.y)/rho;\n' \
                          f'\tF_in_cm[5] = -3.*{m00}*uxuy*({Force_str}.x*u.x + {Force_str}.y*u.y)/rho;\n' \
                          f'\tF_in_cm[6] = {m00}*(9.*{Force_str}.x*ux3*u.y + 9.*{Force_str}.y*ux2*uy2 + 1/3.*{Force_str}.y)/rho;\n' \
                          f'\tF_in_cm[7] = {m00}*(9.*{Force_str}.x*ux2*uy2 + 1/3.*{Force_str}.x + 9.*{Force_str}.y*u.x*uy3)/rho;\n' \
                          f'\tF_in_cm[8] = -{m00}*(18.*{Force_str}.x*ux3*uy2 + {Force_str}.x*ux3 + 3.*{Force_str}.x*u.x*uy2 + 18.*{Force_str}.y*ux2*uy3 + 3.*{Force_str}.y*ux2*u.y + {Force_str}.y*uy3)/rho;\n'  # noqa

        assert expected_result == out
예제 #12
0
def make_collision(choice):
    model_switcher = {
        # Relax 2nd moments for hydro, SOI
        'hydro': (eye(q) - S_Relax) * temp_populations
                 + S_Relax * hardcoded_cm_eq
                 + (eye(q) - S_Relax / 2) * hardcoded_F_cm,
        # Relax 1st moments for ADE, SOI without force
        'ade': None  # TODO: write the collision for advection-diffusion equation
    }
    # Get the function from switcher dictionary
    cm_after_collision = model_switcher.get(choice, lambda: "Invalid argument")
    print_as_vector(cm_after_collision, outprint_symbol=pop_in_str)
예제 #13
0
def make_collision(choice):
    model_switcher = {
        # Relax 2nd moments for hydro, SOI
        'hydro': (eye(q) - S_Relax) * temp_populations
                 + S_Relax * hardcoded_cm_eq
                 + (eye(q) - S_Relax / 2) * hardcoded_F_cm,
        # Relax 1st moments for ADE, SOI without force
        'ade': None  # TODO: write the collision for advection-diffusion equation
    }
    # Get the function from switcher dictionary
    cm_after_collision = model_switcher.get(choice, lambda: "Invalid argument")
    print_as_vector(cm_after_collision, print_symbol=pop_in_str)
    def test_cm_vector_from_continuous_def(self):
        # this test runs long without output and CI may consider it as a timeout :/
        ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)

        lattices = [
            'D2Q9',
            'D3Q19',
            'D2Q9',
            'D2Q9',
            'D3Q19',
            ]

        functions = [
            ccmt.get_Maxwellian_DF,
            ccmt.get_Maxwellian_DF,
            ccmt.get_force_Guo,
            ccmt.get_force_He_MB,
            ccmt.get_force_He_MB,
        ]

        expected_results = [
            hardcoded_cm_eq_compressible_D2Q9,
            hardcoded_cm_eq_compressible_D3Q19,
            hardcoded_F_cm_Guo_hydro_LB_velocity_based_D2Q9,
            hardcoded_F_cm_hydro_density_based_D2Q9,
            hardcoded_F_cm_hydro_density_based_D3Q19,
        ]

        for fun, lattice, expected_result in zip(functions, lattices, expected_results):
            cm_eq = get_mom_vector_from_continuous_def(fun,
                                                       continuous_transformation=ccmt.get_cm,
                                                       moments_order=moments_dict[lattice],
                                                       serial_run=True
                                                       )
            # print("------------\n\n")
            # print_as_vector(cm_eq, 'CM')
            # print_as_vector(expected_result, 'CM_expected')
            # print("------------\n\n")

            f = io.StringIO()
            with redirect_stdout(f):
                print_as_vector(cm_eq, 'cm_eq')
            out = f.getvalue()

            f2 = io.StringIO()
            with redirect_stdout(f2):
                print_as_vector(expected_result, 'cm_eq')
            ccode_expected_result = f2.getvalue()

            assert ccode_expected_result == out
예제 #15
0
    def test_Shift_ortho_Geier_d2q9(self):
        from SymbolicCollisions.core.MatrixGenerator import get_shift_matrix
        from SymbolicCollisions.core.cm_symbols import Shift_ortho_Geier, K_ortho_Geier, ex_Geier, ey_Geier

        Smat = get_shift_matrix(K_ortho_Geier, ex_Geier, ey_Geier)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(Shift_ortho_Geier, 's')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            print_as_vector(Smat[3:, 3:], 's')
        out2 = f2.getvalue()

        assert out == out2
예제 #16
0
    def test_get_raw_matrix_d2q9(self):
        from SymbolicCollisions.core.MatrixGenerator import get_raw_moments_matrix
        from SymbolicCollisions.core.cm_symbols import ex_D2Q9, ey_D2Q9, Mraw_D2Q9

        M = get_raw_moments_matrix(ex_=ex_D2Q9, ey_=ey_D2Q9)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(Mraw_D2Q9, 's')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            print_as_vector(M, 's')
        out2 = f2.getvalue()

        assert out == out2
예제 #17
0
    def test_Shift_ortho_Straka_d2q5(self):
        from SymbolicCollisions.core.MatrixGenerator import get_shift_matrix
        from SymbolicCollisions.core.cm_symbols import Shift_ortho_Straka_d2q5, K_ortho_Straka_d2q5, ex_Straka_d2_q5, \
            ey_Straka_d2_q5

        Smat = get_shift_matrix(K_ortho_Straka_d2q5, ex_Straka_d2_q5, ey_Straka_d2_q5)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(Shift_ortho_Straka_d2q5, 's')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            print_as_vector(Smat[1:, 1:], 's')
        out2 = f2.getvalue()

        assert out == out2
예제 #18
0
    def test_df_to_m(self):
        # SETUP
        d = 2
        q = 9

        # DYNAMIC IMPORTS
        ex = dynamic_import("SymbolicCollisions.core.cm_symbols",
                            f"ex_D{d}Q{q}")
        ey = dynamic_import("SymbolicCollisions.core.cm_symbols",
                            f"ey_D{d}Q{q}")
        if d == 3:
            ez = dynamic_import("SymbolicCollisions.core.cm_symbols",
                                f"ez_D{d}Q{q}")
        else:
            ez = None

        pop_in_str = 'x_in'  # symbol defining populations
        temp_pop_str = 'temp'  # symbol defining populations

        temp_populations = get_print_symbols_in_indx_notation(q, temp_pop_str)

        matrixGenerator = MatrixGenerator(ex, ey, ez,
                                          moments_dict[f'D{d}Q{q}'])
        Mraw = matrixGenerator.get_raw_moments_matrix()

        m = Mraw * temp_populations

        expected_results = "\tx_in[0] = temp[0] + temp[1] + temp[2] + temp[3] + temp[4] + temp[5] + temp[6] + temp[7] + temp[8];\n" \
                           "\tx_in[1] = temp[1] - temp[3] + temp[5] - temp[6] - temp[7] + temp[8];\n" \
                           "\tx_in[2] = temp[2] - temp[4] + temp[5] + temp[6] - temp[7] - temp[8];\n" \
                           "\tx_in[3] = temp[1] + temp[3] + temp[5] + temp[6] + temp[7] + temp[8];\n" \
                           "\tx_in[4] = temp[2] + temp[4] + temp[5] + temp[6] + temp[7] + temp[8];\n" \
                           "\tx_in[5] = temp[5] - temp[6] + temp[7] - temp[8];\n" \
                           "\tx_in[6] = temp[5] + temp[6] - temp[7] - temp[8];\n" \
                           "\tx_in[7] = temp[5] - temp[6] - temp[7] + temp[8];\n" \
                           "\tx_in[8] = temp[5] + temp[6] + temp[7] + temp[8];\n"

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(m, outprint_symbol=pop_in_str)
        out = f.getvalue()

        assert out == expected_results
    def test_get_cm_eq_incompressible_continuous(self):
        # population_eq -> cm_eq - from continous definition: '
        # k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) '
        # where fun = fM(rho,u,x,y) *(x-ux)^m *(y-uy)^n * (z-uz)^o ')

        cm_i = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)
        cm_eq = get_mom_vector_from_continuous_def(cm_i.get_hydro_DF,
                                                   continuous_transformation=cm_i.get_cm,
                                                   moments_order=moments_dict['D2Q9'],
                                                   serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        # TODO: can't use hardcoded_cm_eq_incompressible_D2Q9,
        #  because sympy switches hardcoded 'u.x*(-m00 + 1)' to '-u.x*(m00 - 1') and test fails.
        #  thank you sympy...

        expected_result = '\tcm_eq[0] = m00;\n' \
                          '\tcm_eq[1] = u.x*(-m00 + 1);\n' \
                          '\tcm_eq[2] = u.y*(-m00 + 1);\n' \
                          '\tcm_eq[3] = m00*ux2 + 1/3.*m00 - ux2;\n' \
                          '\tcm_eq[4] = m00*uy2 + 1/3.*m00 - uy2;\n' \
                          '\tcm_eq[5] = uxuy*(m00 - 1.);\n' \
                          '\tcm_eq[6] = u.y*(-m00*ux2 - 1/3.*m00 + ux2 + 1/3.);\n' \
                          '\tcm_eq[7] = u.x*(-m00*uy2 - 1/3.*m00 + uy2 + 1/3.);\n' \
                          '\tcm_eq[8] = m00*ux2*uy2 + 1/3.*m00*ux2 + 1/3.*m00*uy2 + 1/9.*m00 - ux2*uy2 - 1/3.*ux2 - 1/3.*uy2;\n'  # noqa

        assert 'cm_eq[0] = m00;' in out
        assert 'cm_eq[1] = u.x*(-m00 + 1)' in out
        assert 'cm_eq[2] = u.y*(-m00 + 1);' in out
        assert 'cm_eq[3] = m00*ux2 + 1/3.*m00 - ux2;\n' in out
        assert 'cm_eq[4] = m00*uy2 + 1/3.*m00 - uy2;\n' in out
        assert 'cm_eq[5] = uxuy*(m00 - 1.);\n' in out
        assert 'cm_eq[6] = u.y*(-m00*ux2 - 1/3.*m00 + ux2 + 1/3.);\n' in out
        assert 'cm_eq[7] = u.x*(-m00*uy2 - 1/3.*m00 + uy2 + 1/3.);\n' in out
        assert 'cm_eq[8] = m00*ux2*uy2 + 1/3.*m00*ux2 + 1/3.*m00*uy2 + 1/9.*m00 - ux2*uy2 - 1/3.*ux2 - 1/3.*uy2;\n' in out  # noqa

        assert expected_result == out
예제 #20
0
    def test_Shift_ortho_Geier_d2q9(self):

        from SymbolicCollisions.core.cm_symbols import Shift_ortho_Geier, K_ortho_Geier, ex_Geier, ey_Geier
        matrix_generator = MatrixGenerator(
            ex=ex_Geier,
            ey=ey_Geier,
            ez=None,
            order_of_moments=moments_dict['D2Q9'])
        Smat = matrix_generator.get_shift_matrix(K_ortho_Geier)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(Shift_ortho_Geier, 's')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            print_as_vector(Smat[3:, 3:], 's')
        out2 = f2.getvalue()

        assert out == out2
예제 #21
0
    def test_cm_eq_compressible_discrete(self):
        """
        test eq 10 from
        'Modeling incompressible thermal flows using a central-moment-based lattice Boltzmann method'
        Linlin Fei, Kai Hong Luo, Chuandong Lin, Qing Li
        2017
        """
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        cm_eq = get_mom_vector_from_discrete_def(
            lambda i: m00 * dcmt.get_gamma(i),
            discrete_transform=dcmt.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        assert f'cm_eq[0] = {m00};' in out
        assert f'cm_eq[2] = 0;' in out
        assert f'cm_eq[2] = 0;' in out
        assert f'cm_eq[3] = 1/3.*{m00};\n' in out
        assert f'cm_eq[4] = 1/3.*{m00};\n' in out
        assert f'cm_eq[5] = 0;\n' in out
        assert f'cm_eq[6] = -{m00}*ux2*u.y;\n' in out
        assert f'cm_eq[7] = -{m00}*u.x*uy2;\n' in out
        assert f'cm_eq[8] = {m00}*(3.*ux2*uy2 + 1/9.);\n' in out

        expected_result = f'\tcm_eq[0] = {m00};\n' \
                          f'\tcm_eq[1] = 0;\n' \
                          f'\tcm_eq[2] = 0;\n' \
                          f'\tcm_eq[3] = 1/3.*{m00};\n' \
                          f'\tcm_eq[4] = 1/3.*{m00};\n' \
                          f'\tcm_eq[5] = 0;\n' \
                          f'\tcm_eq[6] = -{m00}*ux2*u.y;\n' \
                          f'\tcm_eq[7] = -{m00}*u.x*uy2;\n' \
                          f'\tcm_eq[8] = {m00}*(3.*ux2*uy2 + 1/9.);\n'

        assert expected_result == out
예제 #22
0
    def test_Shift_ortho_Straka_d2q5(self):
        from SymbolicCollisions.core.cm_symbols import Shift_ortho_Straka_d2q5, K_ortho_Straka_d2q5, \
            ex_Straka_d2_q5, ey_Straka_d2_q5

        matrix_generator = MatrixGenerator(
            ex=ex_Straka_d2_q5,
            ey=ey_Straka_d2_q5,
            ez=None,
            order_of_moments=moments_dict['D2Q5'])
        Smat = matrix_generator.get_shift_matrix(K_ortho_Straka_d2q5)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(Shift_ortho_Straka_d2q5, 's')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            print_as_vector(Smat[1:, 1:], 's')
        out2 = f2.getvalue()

        assert out == out2
예제 #23
0
    def test_cm_eq_compressible_discrete(self):
        """
        test eq 10 from
        'Modeling incompressible thermal flows using a central-moment-based lattice Boltzmann method'
        Linlin Fei, Kai Hong Luo, Chuandong Lin, Qing Li
        2017
        """
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        cm_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma(i),
                                                 discrete_transform=dcmt.get_cm,
                                                 moments_order=moments_dict['D2Q9'],
                                                 serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        expected_result = '\tcm_eq[0] = m00;\n' \
                          '\tcm_eq[1] = 0;\n' \
                          '\tcm_eq[2] = 0;\n' \
                          '\tcm_eq[3] = 1/3.*m00;\n' \
                          '\tcm_eq[4] = 1/3.*m00;\n' \
                          '\tcm_eq[5] = 0;\n' \
                          '\tcm_eq[6] = -m00*ux2*u.y;\n' \
                          '\tcm_eq[7] = -m00*u.x*uy2;\n' \
                          '\tcm_eq[8] = m00*(3.*ux2*uy2 + 1/9.);\n'

        assert 'cm_eq[0] = m00;' in out
        assert 'cm_eq[2] = 0;' in out
        assert 'cm_eq[2] = 0;' in out
        assert 'cm_eq[3] = 1/3.*m00;\n' in out
        assert 'cm_eq[4] = 1/3.*m00;\n' in out
        assert 'cm_eq[5] = 0;\n' in out
        assert 'cm_eq[6] = -m00*ux2*u.y;\n' in out
        assert 'cm_eq[7] = -m00*u.x*uy2;\n' in out
        assert 'cm_eq[8] = m00*(3.*ux2*uy2 + 1/9.);\n' in out

        assert expected_result == out
예제 #24
0
    def test_get_raw_matrix_d2q9(self):

        from SymbolicCollisions.core.cm_symbols import ex_D2Q9, ey_D2Q9, Mraw_D2Q9

        matrix_generator = MatrixGenerator(
            ex=ex_D2Q9,
            ey=ey_D2Q9,
            ez=None,
            order_of_moments=moments_dict['D2Q9'])
        M = matrix_generator.get_raw_moments_matrix()

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(Mraw_D2Q9, 's')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            print_as_vector(M, 's')
        out2 = f2.getvalue()

        assert out == out2
예제 #25
0
    def test_notation_ijk(self):
        q = 27
        populations = get_print_symbols_in_indx_notation(q, print_symbol='b')
        expected_results = "\ta000 = b[0];\n" \
                           "\ta100 = b[1];\n" \
                           "\ta200 = b[2];\n" \
                           "\ta010 = b[3];\n" \
                           "\ta020 = b[4];\n" \
                           "\ta001 = b[5];\n" \
                           "\ta002 = b[6];\n" \
                           "\ta111 = b[7];\n" \
                           "\ta211 = b[8];\n" \
                           "\ta121 = b[9];\n" \
                           "\ta221 = b[10];\n" \
                           "\ta112 = b[11];\n" \
                           "\ta212 = b[12];\n" \
                           "\ta122 = b[13];\n" \
                           "\ta222 = b[14];\n" \
                           "\ta110 = b[15];\n" \
                           "\ta210 = b[16];\n" \
                           "\ta120 = b[17];\n" \
                           "\ta220 = b[18];\n" \
                           "\ta101 = b[19];\n" \
                           "\ta201 = b[20];\n" \
                           "\ta102 = b[21];\n" \
                           "\ta202 = b[22];\n" \
                           "\ta011 = b[23];\n" \
                           "\ta021 = b[24];\n" \
                           "\ta012 = b[25];\n" \
                           "\ta022 = b[26];\n"

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(populations,
                            outprint_symbol='a',
                            output_order_of_moments=e_D3Q27)
        out = f.getvalue()

        assert out == expected_results
    def test_thermal_cm_eq_vector_from_continuous_def(self):
        ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho, cs2=cs2_thermal)
        import warnings
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            cm_eq = get_mom_vector_from_continuous_def(ccmt.get_Maxwellian_DF,
                                                      continuous_transformation=ccmt.get_cm,
                                                      moments_order=moments_dict['D2Q9'],
                                                      serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            expected_result = hardcoded_cm_eq_compressible_D2Q9_thermal
            print_as_vector(expected_result, 'cm_eq')

        ccode_expected_result = f2.getvalue()

        assert ccode_expected_result == out
예제 #27
0
    def test_notation_i(self):
        q = 27
        populations = get_print_symbols_in_indx_notation(q, print_symbol='b')
        expected_results = "\ta[0] = b[0];\n" \
                           "\ta[1] = b[1];\n" \
                           "\ta[2] = b[2];\n" \
                           "\ta[3] = b[3];\n" \
                           "\ta[4] = b[4];\n" \
                           "\ta[5] = b[5];\n" \
                           "\ta[6] = b[6];\n" \
                           "\ta[7] = b[7];\n" \
                           "\ta[8] = b[8];\n" \
                           "\ta[9] = b[9];\n" \
                           "\ta[10] = b[10];\n" \
                           "\ta[11] = b[11];\n" \
                           "\ta[12] = b[12];\n" \
                           "\ta[13] = b[13];\n" \
                           "\ta[14] = b[14];\n" \
                           "\ta[15] = b[15];\n" \
                           "\ta[16] = b[16];\n" \
                           "\ta[17] = b[17];\n" \
                           "\ta[18] = b[18];\n" \
                           "\ta[19] = b[19];\n" \
                           "\ta[20] = b[20];\n" \
                           "\ta[21] = b[21];\n" \
                           "\ta[22] = b[22];\n" \
                           "\ta[23] = b[23];\n" \
                           "\ta[24] = b[24];\n" \
                           "\ta[25] = b[25];\n" \
                           "\ta[26] = b[26];\n" \

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(populations, outprint_symbol='a')
        out = f.getvalue()

        assert out == expected_results
예제 #28
0
    def test_get_F_cm_Guo_continuous_and_discrete(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        F_cm_Guo_disc = get_mom_vector_from_discrete_def(
            dcmt.get_force_Guo,
            discrete_transform=dcmt.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)

        from SymbolicCollisions.core.ContinuousCMTransforms import \
            ContinuousCMTransforms, get_mom_vector_from_continuous_def

        from SymbolicCollisions.core.cm_symbols import \
            F3D, dzeta3D, u3D

        ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)
        F_cm_Guo_cont = get_mom_vector_from_continuous_def(
            ccmt.get_force_Guo,
            continuous_transformation=ccmt.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)

        # print_as_vector(F_cm_Guo_cont, 'F_cm')
        results = [F_cm_Guo_disc, F_cm_Guo_cont]

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(hardcoded_F_cm_Guo_hydro_incompressible_D2Q9,
                            'F_cm')
        expected_result = f.getvalue()

        for result in results:
            f = io.StringIO()
            with redirect_stdout(f):
                print_as_vector(result, 'F_cm')
            out = f.getvalue()

            assert out == expected_result
예제 #29
0
    def test_get_cm_eq_hydro_discrete(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
        cm_eq = get_mom_vector_from_discrete_def(
            dcmt.get_EDF_incompressible,
            discrete_transform=dcmt.get_cm,
            moments_order=moments_dict['D2Q9'],
            serial_run=True)
        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        # TODO: be aware that sympy may switch hardcoded terms like 'u.x*(-m00 + 1)' to '-u.x*(m00 - 1')
        #  thank you sympy...

        assert f'cm_eq[0] = {m00};' in out
        assert f'cm_eq[1] = u.x*(1 - {m00});' in out or f'cm_eq[1] = u.x*(-{m00} + 1);' in out
        assert f'cm_eq[2] = u.y*(1 - {m00});' in out or f'cm_eq[2] = u.y*(-{m00} + 1);' in out
        assert f'cm_eq[3] = {m00}*ux2 + 1/3.*{m00} - ux2;\n' in out
        assert f'cm_eq[4] = {m00}*uy2 + 1/3.*{m00} - uy2;\n' in out
        assert f'cm_eq[5] = uxuy*({m00} - 1.);\n' in out
        assert f'cm_eq[6] = u.y*(-{m00}*ux2 - 1/3.*{m00} + 1/3.);\n' in out
        assert f'cm_eq[7] = u.x*(-{m00}*uy2 - 1/3.*{m00} + 1/3.);\n' in out
        assert f'cm_eq[8] = {m00}*ux2*uy2 + 1/3.*{m00}*ux2 + 1/3.*{m00}*uy2 + 1/9.*{m00} + 2.*ux2*uy2 - 1/3.*ux2 - 1/3.*uy2;\n' in out  # noqa
예제 #30
0
    def test_shift_vs_def_cm(self):
        dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

        functions = [lambda i: w_D2Q9[i], dcmt.get_force_He, dcmt.get_force_Guo]
        from SymbolicCollisions.core.cm_symbols import Mraw_D2Q9, NrawD2Q9

        for fun in functions:
            F_in_cm = get_mom_vector_from_discrete_def(fun,
                                                       discrete_transform=dcmt.get_cm,
                                                       moments_order=moments_dict['D2Q9'],
                                                       serial_run=True)  # calculate from definition of cm
            NMF_cm = get_mom_vector_from_shift_mat(fun, mat=NrawD2Q9 * Mraw_D2Q9)  # calculate using shift matrices

            f = io.StringIO()
            with redirect_stdout(f):
                print_as_vector(F_in_cm, 'F_in_cm')
            out = f.getvalue()

            f2 = io.StringIO()
            with redirect_stdout(f2):
                print_as_vector(NMF_cm, 'F_in_cm')
            out2 = f2.getvalue()

            assert out == out2
예제 #31
0
    def test_thermal_cm_eq_vector_from_continuous_def(self):
        ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho, cs2=cs2_thermal)
        import warnings
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            cm_eq = get_mom_vector_from_continuous_def(
                ccmt.get_Maxwellian_DF,
                continuous_transformation=ccmt.get_cm,
                moments_order=moments_dict['D2Q9'],
                serial_run=True)

        f = io.StringIO()
        with redirect_stdout(f):
            print_as_vector(cm_eq, 'cm_eq')
        out = f.getvalue()

        f2 = io.StringIO()
        with redirect_stdout(f2):
            expected_result = hardcoded_cm_eq_compressible_D2Q9_thermal
            print_as_vector(expected_result, 'cm_eq')

        ccode_expected_result = f2.getvalue()

        assert ccode_expected_result == out
예제 #32
0
    def test_cm_vector_from_continuous_def(self):
        # this test runs long without output and CI may consider it as a timeout :/
        ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)

        from SymbolicCollisions.core.cm_symbols import Sigma2asSymbol
        ccmt_cht = ContinuousCMTransforms(dzeta3D,
                                          u3D,
                                          F3D,
                                          rho,
                                          cs2=Sigma2asSymbol)

        ccmts = [
            ccmt,
            ccmt,
            ccmt,
            ccmt,
            ccmt,
            ccmt_cht,
        ]

        lattices = ['D2Q9', 'D3Q19', 'D2Q9', 'D2Q9', 'D3Q19', 'D2Q9']

        functions = [
            ccmt.get_Maxwellian_DF,
            ccmt.get_Maxwellian_DF,
            ccmt.get_force_Guo,
            ccmt.get_force_He_MB,
            ccmt.get_force_He_MB,
            ccmt_cht.get_cht_DF,
        ]

        expected_results = [
            hardcoded_cm_eq_compressible_D2Q9,
            hardcoded_cm_eq_compressible_D3Q19,
            hardcoded_F_cm_Guo_hydro_incompressible_D2Q9,
            hardcoded_F_cm_hydro_compressible_D2Q9,
            hardcoded_F_cm_hydro_compressible_D3Q19,
            hardcoded_cm_eq_cht_D2Q9,
        ]

        for fun, lattice, _ccmt, expected_result in zip(
                functions, lattices, ccmts, expected_results):
            cm_eq = get_mom_vector_from_continuous_def(
                fun,
                continuous_transformation=_ccmt.get_cm,
                moments_order=moments_dict[lattice],
                serial_run=True)
            # print("------------\n\n")
            # print_as_vector(cm_eq, 'CM')
            # print_as_vector(expected_result, 'CM_expected')
            # print("------------\n\n")

            f = io.StringIO()
            with redirect_stdout(f):
                print_as_vector(cm_eq, 'cm_eq')
            out = f.getvalue()

            f2 = io.StringIO()
            with redirect_stdout(f2):
                print_as_vector(expected_result, 'cm_eq')
            ccode_expected_result = f2.getvalue()

            assert ccode_expected_result == out
예제 #33
0
import time

start = time.process_time()

lattice = 'D2Q9'
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

print("\n--- FORCES ---")
print('// === welcome to central moments space! === \n ')
print('// === discrete central moments ===\n ')

print('\n//F_cm_He_discrete')
F_cm_He = get_mom_vector_from_discrete_def(dcmt.get_force_He,
                                           discrete_transform=dcmt.get_cm,
                                           moments_order=moments_dict[lattice])
print_as_vector(F_cm_He, 'F_cm')

print('\n//N*M*F_He')
NMF_cm_He = get_mom_vector_from_shift_mat(dcmt.get_force_He,
                                          mat=NrawD2Q9 * Mraw_D2Q9)
print_as_vector(NMF_cm_He, 'F_cm')

print('\n//F_cm_Guo')
F_cm_Guo = get_mom_vector_from_discrete_def(
    dcmt.get_force_Guo,
    discrete_transform=dcmt.get_cm,
    moments_order=moments_dict[lattice])
print_as_vector(F_cm_Guo, 'F_cm')

print('\n//N*M*F_cm_Guo_second_order ')
NMF_cm_Guo = get_mom_vector_from_shift_mat(dcmt.get_force_Guo,
start = time.process_time()

print('// === welcome to cm! === \n ')

print('\n//population_eq -> (central) m_eq - from continous definition: \n'
      'k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) \n'
      'where fun = fM(rho,u,x,y) *(x-ux)^m *(y-uy)^n *(z-uz)^o ')

print('The raw moments for the pressure part')
m_eq_p = get_mom_vector_from_continuous_def(
    ccmt.get_incompressible_DF_part_p,
    continuous_transformation=ccmt.get_m,
    moments_order=moments_dict[lattice])

print_as_vector(m_eq_p,
                'm_eq_p',
                output_order_of_moments=moments_dict[lattice])

print('The central moments for the velocity part')
cm_eq_gamma = get_mom_vector_from_continuous_def(
    ccmt.get_incompressible_DF_part_gamma,
    continuous_transformation=ccmt.get_cm,
    moments_order=moments_dict[lattice])

print_as_vector(cm_eq_gamma,
                'cm_eq_gamma',
                output_order_of_moments=moments_dict[lattice])

print('\n\n\n// let us relax the pressure part')
print('\n// pressure part - raw moments after relaxation')
print_as_vector(S_relax_hydro_D2Q9 * m_eq_p.transpose(),
예제 #35
0
"Coupling lattice Boltzmann model for simulation of thermal flows on stanard lattices" \
"by Q. Li, K. H. Luo, Y.L.He., Y.J. Gao, W.Q Tao, 2012"

phi_x = Symbol("phi_x")
phi_y = Symbol("phi_y")
C_D2Q9 = Matrix([-1 / 9 * phi_x,
                 -phi_x / 36 + phi_y / 4,
                 -phi_x / 36 - phi_y / 4,  # suprisingly the article applies asymmetric correction in x and y direction
                 -phi_x / 36 + phi_y / 4,
                 -phi_x / 36 - phi_y / 4,
                 phi_x / 18,
                 phi_x / 18,
                 phi_x / 18,
                 phi_x / 18, ])

print_as_vector(C_D2Q9.transpose() * Mraw_D2Q9, print_symbol="pop_in_str")

#
# print('\n//population_eq -> cm_eq - from continous definition: \n'
#       'k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) \n'
#       'where fun = fM(rho,u,x,y) *(x-ux)^m (y-uy)^n')
# cm_eq = get_mom_vector_from_continuous_def(get_continuous_Maxwellian_DF, continuous_transformation=get_continuous_cm)
# # cm_eq = get_mom_vector_from_continuous_def(get_continuous_hydro_DF, continuous_transformation=get_continuous_cm)
# print_as_vector(cm_eq, 'cm_eq')


# import re
# re.findall(r'\d+', 'hello 42 I\'m a 32 string 30')
# ['42', '32', '30']
# # This would also match 42 from bla42bla. If you only want numbers delimited by word boundaries (space, period, comma), you can use \b :
#
예제 #36
0
)
print(
    f"\treal_t {I} = {sum(get_print_symbols_in_m_notation(moments_order, i))};"
)
print(
    f"\treal_t {R} = {sum(get_print_symbols_in_m_notation(moments_order, r))};"
)

print(f"\treal_t {s} = {S/rho};")
print(f"\treal_t {i} = {I/rho};")
print(f"\treal_t {r} = {R/rho};")

r0 = Symbol('infectious_radius', real=True)
cross_diffusivity = Symbol('cross_diffusivity', real=True)
# print(f"\treal_t {omega_cross} = {S*(beta*r0*r0/8)};")
print_as_vector(Matrix([s * (beta * r0 * r0 / 8)]),
                f"real_t {cross_diffusivity}")
print_as_vector(
    Matrix([
        1 / (3 * cross_diffusivity /
             Symbol('stability_enhancement', positive=True) + 0.5)
    ]), f"real_t {omega_cross}")

for t in temp_populations:
    print(f"\treal_t {t};")

# for m_eq, source, pop_in_str in zip([s_m_eq, i_m_eq, r_m_eq], [s_m_source, i_m_source, r_m_source], ['s', 'i', 'r']):
for source, pop_in_str, relaxation_matrix in zip(
    [s_m_source, i_m_source, r_m_source], ['i', 's', 'r'],
    [relaxation_matrix_s, relaxation_matrix_i, relaxation_matrix_r]):
    print(f"\t //--- processing {pop_in_str} ---")
예제 #37
0

# print("\n\n=== normalize matrix  ===\n")
# from sklearn.preprocessing import normalize
# Column_Normalized = normalize(M_ortho_GS)#, norm='l1', axis=0)
# """axis = 0 indicates, normalize by column and if you are
# interested in row normalization just give axis = 1"""
# pretty_print(Column_Normalized*Column_Normalized.transpose())

print("\n\n=== CM ===\n")

# N_ortho = T_raw_to_ortho*N
# pretty_print(N_ortho)
XXX_ortho = T_raw_to_ortho * Mraw_D2Q9
pretty_print(XXX_ortho * XXX_ortho.transpose())
print_as_vector(XXX_ortho * XXX_ortho.transpose(), print_symbol='xxx')



# print("\n\n=== MRT ===\n")


# momencik = get_discrete_cm(2, 0, lambda i: Symbol('f[%d]' % i))
# momencik = get_discrete_m(2, 0, lambda i: Symbol('f[%d]' % i))
# print_as_vector_raw(Matrix([momencik]), print_symbol='momencik')




L = [Matrix([2,3,5]), Matrix([3,6,2]), Matrix([8,3,2])]
예제 #38
0
lattice = 'D2Q9'
ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho, cs2=cs2_thermal)
# ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)
# ccmt = ContinousCMTransforms(dzeta2D, u2D, F2D, rho, cs2=cs2_thermal)

print('\n\n// === continous cm === \n ')
print("\n--- EQUILIBRIA ---")

print("\n----------------------- calculate particular moment -------------------------------")

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    # row = moments_dict['D3Q15'][14]
    row = moments_dict['D2Q9'][8]
    moment = ccmt.get_cm(row, ccmt.get_Maxwellian_DF)
    print_as_vector(Matrix([moment]), 'particular_moment')


print("\n----------------------- calculate all moments -------------------------------")
cm_eq = get_mom_vector_from_continuous_def(ccmt.get_Maxwellian_DF,
                                           continuous_transformation=ccmt.get_cm,
                                           moments_order=moments_dict[lattice])
print_as_vector(cm_eq, 'cm_eq')

cm_eq_tot_e = get_mom_vector_from_continuous_def(ccmt.get_total_energy_Maxwellian_DF,
                                           continuous_transformation=ccmt.get_cm,
                                           moments_order=moments_dict[lattice])
print_as_vector(cm_eq_tot_e, 'cm_eq_tot_e')

cm_eq_internal_e = get_mom_vector_from_continuous_def(ccmt.get_internal_energy_Maxwellian_DF,
                                           continuous_transformation=ccmt.get_cm,
예제 #39
0
pop_eq_str = 'heq'  # symbol defining populations
temp_pop_str = 'temp'  # symbol defining populations

# GENERATE CODE
print(f"CudaDeviceFunction void relax_and_collide_ADE_SRT_from_cm_eq(real_t rho, real_t {omega_ade},  vector_t u) \n{{")
print("\t//=== THIS IS AUTOMATICALLY GENERATED CODE ===")
print_sigma_cht()
print_u2(d)


populations = get_print_symbols_in_m_notation(moments_order, pop_in_str)
temp_populations = get_print_symbols_in_m_notation(moments_order, temp_pop_str)
eq_populations = get_print_symbols_in_m_notation(moments_order, pop_eq_str)

print(f"\treal_t H = {sum(populations)};")
print("\n\t//equilibrium in central moments space")
print_as_vector(hardcoded_cm_eq, outprint_symbol=f"real_t {pop_eq_str}", output_order_of_moments=moments_order)

print("\n\t//back to raw moments")
print_as_vector(Nraw.inv() * eq_populations, outprint_symbol=f"real_t {temp_pop_str}", output_order_of_moments=moments_order)
# print_as_vector(Nraw.inv() * hardcoded_cm_eq, outprint_symbol=temp_pop_str, moments_order=moments_order)  # shortcut

print("\n\t//back to density-probability functions")
print_as_vector(Mraw.inv() * temp_populations, outprint_symbol=pop_eq_str, output_order_of_moments=rmoments_order)

print("\n\t//SRT collision")
for p, p_eq in zip(populations, eq_populations):
    print(f"\t{p} = {p} + {omega_ade}*({p_eq}-{p});")

print("\n}\n")
예제 #40
0
from SymbolicCollisions.core.cumulants import get_cumulant
from SymbolicCollisions.core.printers import print_as_vector
from sympy.matrices import Matrix
from sympy import pprint

cumulant, trunc_cumulant = get_cumulant(2, 0, 0)


pprint(cumulant)
# preview(cumulant, output='dvi')  # open preview in new window

# pprint(trunc_cumulant)
# preview(trunc_cumulant, output='dvi')  # open preview in new window
#


mc = Matrix([cumulant])
print_as_vector(mc, 'c')
예제 #41
0
from SymbolicCollisions.core.hardcoded_results import hardcoded_F_cm_hydro_density_based_D3Q19, \
    hardcoded_F_cm_Guo_hydro_LB_incompressible_D2Q9, \
    hardcoded_F_cm_hydro_density_based_D2Q9, \
    hardcoded_cm_eq_compressible_D2Q9,    hardcoded_cm_eq_compressible_D3Q19, \
    hardcoded_cm_eq_incompressible_D2Q9, \
    hardcoded_cm_eq_compressible_D2Q9_thermal
"""
Here are samples to facilitate debugging regex-printers ;)
"""

gamma = Symbol('gamma', positive=True)
RT = Symbol('RT', positive=True)
# example= Matrix([1.*rho])
# example= Matrix([1.0 * T * cp ** 1.0 * rho ** 1.0])
# example = Matrix([0.1111111111 * T * gamma ** 2 / (cp * rho)])
# example = Matrix([1.0 * m00 * (RT * uy ** 2 - RT ** 1.0 * uy ** 2 + RT ** 2.0)])

example = Matrix([1.0 * m00 * uy * (RT**1.0 - RT)])

# example = hardcoded_cm_eq_compressible_D2Q9_thermal

print_as_vector(example, 'abc', raw_output=False)

# TODO:
#  1.0*m00*(RT*u.y**2 - RT**1.0*u.y**2 + RT**2.0);
#  reduces to:
#  m00*(RT*uy2 - RT**uy2 + RT**2.);
#  and
#  1.0*m00*u.y*(RT**1.0 - RT);
#  reduces to:
#  m00 * u.y * (RT ** 1. - RT);
예제 #42
0
import time

start = time.process_time()

lattice = 'D2Q9'
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

print("\n--- FORCES ---")
print('// === welcome to central moments space! === \n ')
print('// === discrete central moments ===\n ')

print('\n//F_cm_He_discrete')
F_cm_He = get_mom_vector_from_discrete_def(dcmt.get_force_He,
                                           discrete_transform=dcmt.get_cm,
                                           moments_order=moments_dict[lattice])
print_as_vector(F_cm_He, 'F_cm')

print('\n//N*M*F_He')
NMF_cm_He = get_mom_vector_from_shift_mat(dcmt.get_force_He, mat=NrawD2Q9 * Mraw_D2Q9)
print_as_vector(NMF_cm_He, 'F_cm')

print('\n//F_cm_Guo')
F_cm_Guo = get_mom_vector_from_discrete_def(dcmt.get_force_Guo,
                                            discrete_transform=dcmt.get_cm,
                                            moments_order=moments_dict[lattice])
print_as_vector(F_cm_Guo, 'F_cm')

print('\n//N*M*F_cm_Guo_second_order ')
NMF_cm_Guo = get_mom_vector_from_shift_mat(dcmt.get_force_Guo, mat=NrawD2Q9 * Mraw_D2Q9)
print_as_vector(NMF_cm_Guo, 'F_cm')
예제 #43
0
for source, pop_in_str in zip([source_term], ['f']):
    print(f"\t //--- processing {pop_in_str} ---")

    m_eq = get_vector_of_eq_central_moments(tilde_phi, Sigma2asSymbol)
    populations = get_print_symbols_in_m_notation(moments_order, pop_in_str)
    collided_populations_str = pop_in_str + "_star_"
    collided_populations = get_print_symbols_in_m_notation(
        moments_order, collided_populations_str)

    for t, p in zip(temp_populations, populations):
        print(f"\t{t} = {p};")

    print("\n\t//raw moments from density-probability functions")

    print_as_vector(Mraw * rtemp_populations,
                    outprint_symbol=pop_in_str,
                    output_order_of_moments=moments_order)

    print("\n\t//collide")
    # Relax 1,3,5 moments for ADE, FOI without force

    # print("\n\t//collide-FOI")  # it look the same as SOI, only the values of omega_ade differs by 1/2
    # m_after_collision = (eye(q) - Relaxation_matrix) * populations + Relaxation_matrix * m_eq + source
    # print_as_vector(m_after_collision, outprint_symbol="real_t " + collided_populations_str, output_order_of_moments=moments_order)
    #
    # Relax 1,3,5 moments for ADE, SOI without force
    # print("\n\t//collide-SOI")
    m_after_collision = (
        eye(q) - Relaxation_matrix) * populations + Relaxation_matrix * (
            m_eq + source / 2.) + (eye(q) - Relaxation_matrix / 2.) * source
    # m_after_collision = (eye(q) - Relaxation_matrix) * populations + Relaxation_matrix * m_eq + source
예제 #44
0
from SymbolicCollisions.core.cm_symbols import rho, moments_dict
import time


lattice = 'D2Q9'
ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)

start = time.process_time()

print('\n\n// === continous cm === \n ')

# to calculate particular moment
row = moments_dict['D2Q9'][0]
moment = ccmt.get_cm(row, ccmt.get_Maxwellian_DF)
print_as_vector(Matrix([moment]), 'particular_moment')


print('\n//Force -> Force_cm - from continous definition: \n'
      'k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) \n'
      'where fun = forceM(rho,u,x,y) *(x-ux)^m *(y-uy)^n *(z-uz)^o ')
F_cm = get_mom_vector_from_continuous_def(ccmt.get_force_He_MB,
                                          continuous_transformation=ccmt.get_cm,
                                          moments_order=moments_dict[lattice])
print_as_vector(F_cm, 'F_cm')


print('\n//population_eq -> cm_eq - from continous definition: \n'
      'k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) \n'
      'where fun = fM(rho,u,x,y) *(x-ux)^m *(y-uy)^n *(z-uz)^o ')
cm_eq = get_mom_vector_from_continuous_def(ccmt.get_Maxwellian_DF,
예제 #45
0

make_variables(model)

print(f"\tfor (int i = 0; i < {q}; i++) {{\n\t"
      f"\t{temp_pop_str}[i] = {pop_in_str}[i];}}")

populations = get_DF(q, pop_in_str)
temp_populations = get_DF(q, temp_pop_str)
cm_eq = get_DF(q, cm_eq_pop_str)
F_cm = get_DF(q, F_str)
m = Mraw * temp_populations

print("\n\t//raw moments from density-probability functions")
# print("\t//[m00, m10, m01, m20, m02, m11, m21, m12, m22]")
print_as_vector(m, print_symbol=pop_in_str)

print("\n\t//central moments from raw moments")
cm = Nraw * populations
print_as_vector(cm, print_symbol=temp_pop_str)

print("\n\t//collision in central moments space")
# print("//calculate equilibrium distributions in cm space")
# print("real_t {cm_eq_pop_str}[{q}];\n")
# print_as_vector(hardcoded_cm_eq, cm_eq_pop_str)  # save time, verbosity
# print("//calculate forces in cm space")
# print("real_t {F_cm_str}[{q}];")
# print_as_vector(hardcoded_F_cm, F_cm_str)  # save time, verbosity
print("\t//collide")

print_ccode(get_m00(q, pop_in_str), assign_to='real_t m00')

print("\nreal_t %s[9]; real_t %s[9]; real_t %s[9];\n" %
      (temp_pop_str, cm_eq_pop_str, F_cm_str))
print("for (int i = 0; i < 9; i++) {\n\t"
      "%s[i] = %s[i];}" % (temp_pop_str, pop_in_str))

populations = get_print_symbols_in_indx_notation(q, pop_in_str)
temp_populations = get_print_symbols_in_indx_notation(q, temp_pop_str)
cm_eq = get_print_symbols_in_indx_notation(q, cm_eq_pop_str)
F_cm = get_print_symbols_in_indx_notation(q, F_cm_str)
m = Mraw_D2Q9 * temp_populations

print("\n//raw moments from density-probability functions")
print("//[m00, m10, m01, m20, m02, m11, m21, m12, m22]")
print_as_vector(m, outprint_symbol=pop_in_str)

print("\n//central moments from raw moments")
cm = NrawD2Q9 * populations
print_as_vector(cm, outprint_symbol=temp_pop_str)

print("\n//collision in central moments space")
print("//calculate equilibrium distributions in cm space")
# print_as_vector_re(get_cm_vector_from_discrete_def(lambda i: m00 * get_gamma(i)), cm_eq_pop_str)
print_as_vector(hardcoded_cm_eq_compressible_D2Q9, cm_eq_pop_str)  # save time

print("//calculate forces in cm space")
# print_as_vector(get_cm_vector_from_discrete_def(get_discrete_force_Guo_second_order), F_cm_str)
# print_as_vector(get_cm_vector_from_continuous_def(get_continuous_force_He_MB), F_cm_str)
print_as_vector(hardcoded_F_cm_pf_D2Q9, F_cm_str)  # save time
print("//collide")
mom_relaxed_DF_str = 'm_relaxed'

print("CudaDeviceFunction void relax_MRT_relax_raw_mom_into_ortho("
      "real_t %s[9], "
      "real_t tau, "
      "\n{"
      % DF_in_str)


print("\nreal_t %s = 1./tau;" % omega_v)
print("\nreal_t %s[9]; real_t %s[9]; \n" % (mom_DF_str, mom_relaxed_DF_str))

populations = get_DF(print_symbol=DF_in_str)
m_DF = get_DF(print_symbol=mom_DF_str)
m_relaxed_DF = get_DF(print_symbol=mom_relaxed_DF_str)
m = Mraw_D2Q9 * populations

print("\n//raw moments from density-probability functions")
print("//[m00, m10, m01, m20, m02, m11, m21, m12, m22]")
print_as_vector(m, print_symbol=mom_DF_str)


print("\n//collision in orthogonal moments space")
print_as_vector(S_relax2 * m_DF, print_symbol=mom_relaxed_DF_str)

print("\n//back to density-probability functions")
populations = Mraw_D2Q9.inv() * m_relaxed_DF
print_as_vector(populations, print_symbol=DF_in_str)

print("\n}\n")
예제 #48
0

make_variables(model)

print(f"\tfor (int i = 0; i < {q}; i++) {{\n\t"
      f"\t{temp_pop_str}[i] = {pop_in_str}[i];}}")

populations = get_print_symbols_in_indx_notation(q, pop_in_str)
temp_populations = get_print_symbols_in_indx_notation(q, temp_pop_str)
cm_eq = get_print_symbols_in_indx_notation(q, m_eq_pop_str)
F_cm = get_print_symbols_in_indx_notation(q, F_str)
m = Mraw * temp_populations

print("\n\t//raw moments from density-probability functions")
# print("\t//[m00, m10, m01, m20, m02, m11, m21, m12, m22]")
print_as_vector(m, outprint_symbol=pop_in_str)


print("\n\t//collision in moments space")
# print("//calculate equilibrium distributions in cm space")
# print("real_t {cm_eq_pop_str}[{q}];\n")
# print_as_vector(hardcoded_cm_eq, cm_eq_pop_str)  # save time, verbosity
# print("//calculate forces in cm space")
# print("real_t {F_cm_str}[{q}];")
# print_as_vector(hardcoded_F_cm, F_cm_str)  # save time, verbosity
print("\t//collide")


def make_collision(choice):
    model_switcher = {
        # Relax 2nd moments for hydro, SOI
예제 #49
0
mf_str = 'm_f_'
cmf_str = 'cm_f_'
cmf_eq_str = 'cm_f_eq_'
cmq_eq_str = 'cm_q_eq_'
collided_populations_str = "cm_star_"

mf = get_print_symbols_in_m_notation(moments_order, mf_str)
cmf = get_print_symbols_in_m_notation(moments_order, cmf_str)
cmf_eq = get_print_symbols_in_m_notation(moments_order, cmf_eq_str)
cmq_eq = get_print_symbols_in_m_notation(moments_order, cmq_eq_str)
cm_star = get_print_symbols_in_m_notation(moments_order,
                                          collided_populations_str)

print("\n\t//raw moments from density-probability functions")
print_as_vector(Mraw * rf_populations,
                outprint_symbol="real_t " + mf_str,
                output_order_of_moments=moments_order)

# same but in different order ...
# rmatrixGenerator = MatrixGenerator(ex_D3Q27new, ey_D3Q27new, ez_D3Q27new, rmoments_order)
# rMraw = rmatrixGenerator.get_raw_moments_matrix()
# print_as_vector(rMraw * rf_populations, outprint_symbol="real_t " + 'rm', output_order_of_moments=rmoments_order)
print("\n\t//central moments from raw moments")
print_as_vector(Nraw * mf,
                outprint_symbol="real_t " + cmf_str,
                output_order_of_moments=moments_order)

print("\n\t//cm equilibrium moments ")

print_as_vector(get_vector_of_eq_central_moments(tilde_phi, Sigma2asSymbol),
                outprint_symbol="real_t " + cmf_eq_str,
예제 #50
0
from SymbolicCollisions.core.cumulants import get_cumulant
from SymbolicCollisions.core.printers import print_as_vector
from sympy.matrices import Matrix
from sympy import pprint

cumulant, trunc_cumulant = get_cumulant(2, 1, 0)


pprint(cumulant)
# preview(cumulant, output='dvi')  # open preview in new window

# pprint(trunc_cumulant)
# preview(trunc_cumulant, output='dvi')  # open preview in new window
#


mc = Matrix([cumulant])
print_as_vector(mc, 'c')
DF_in_str = 'f_in'  # symbol defining DF
mom_DF_str = 'm'
mom_relaxed_DF_str = 'm_relaxed'

print("CudaDeviceFunction void relax_MRT_relax_raw_mom_into_ortho("
      "real_t %s[9], "
      "real_t tau, "
      "\n{" % DF_in_str)

print("\nreal_t %s = 1./tau;" % omega_v)
print("\nreal_t %s[9]; real_t %s[9]; \n" % (mom_DF_str, mom_relaxed_DF_str))

populations = get_print_symbols_in_indx_notation(print_symbol=DF_in_str)
m_DF = get_print_symbols_in_indx_notation(print_symbol=mom_DF_str)
m_relaxed_DF = get_print_symbols_in_indx_notation(
    print_symbol=mom_relaxed_DF_str)
m = Mraw_D2Q9 * populations

print("\n//raw moments from density-probability functions")
print("//[m00, m10, m01, m20, m02, m11, m21, m12, m22]")
print_as_vector(m, outprint_symbol=mom_DF_str)

print("\n//collision in orthogonal moments space")
print_as_vector(S_relax2 * m_DF, outprint_symbol=mom_relaxed_DF_str)

print("\n//back to density-probability functions")
populations = Mraw_D2Q9.inv() * m_relaxed_DF
print_as_vector(populations, outprint_symbol=DF_in_str)

print("\n}\n")
예제 #52
0
    DiscreteCMTransforms, get_mom_vector_from_discrete_def

from SymbolicCollisions.core.MatrixGenerator import get_m_order_as_in_r, get_e_as_in_r, MatrixGenerator, get_reverse_direction_idx, get_reverse_indices

lattice = 'D2Q9'
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

start = time.process_time()
print('// === discrete (central) moments ===\n ')
print('// === welcome to TRT! === \n ')

print("moments: second order (quadratic) velocity expansion.")
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma(i),
                                          discrete_transform=dcmt.get_m,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'm_eq', output_order_of_moments=moments_dict[lattice])

print("TRT m antisymmetric - moments: second order (quadratic) velocity expansion.")
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma_TRT_antisymmetric(i),
                                          discrete_transform=dcmt.get_m,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'm_eq_antisymmetric', output_order_of_moments=moments_dict[lattice])

print("TRT m symmetric - moments: second order (quadratic) velocity expansion.")
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma_TRT_symmetric(i),
                                          discrete_transform=dcmt.get_m,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'm_eq_symmetric', output_order_of_moments=moments_dict[lattice])

print("=================================================================")
# yet another way of doing the same
print_ccode(get_m00(q, pop_in_str), assign_to='real_t m00')

print("\nreal_t %s[9]; real_t %s[9]; real_t %s[9];\n" % (temp_pop_str, cm_eq_pop_str, F_cm_str))
print("for (int i = 0; i < 9; i++) {\n\t"
      "%s[i] = %s[i];}" % (temp_pop_str, pop_in_str))

populations = get_DF(print_symbol=pop_in_str)
temp_populations = get_DF(print_symbol=temp_pop_str)
cm_eq = get_DF(print_symbol=cm_eq_pop_str)
F_cm = get_DF(print_symbol=F_cm_str)
m = Mraw_D2Q9 * temp_populations

print("\n//raw moments from density-probability functions")
print("//[m00, m10, m01, m20, m02, m11, m21, m12, m22]")
print_as_vector(m, print_symbol=pop_in_str)

print("\n//central moments from raw moments")
cm = NrawD2Q9 * populations
print_as_vector(cm, print_symbol=temp_pop_str)

print("\n//collision in central moments space")
print("//calculate equilibrium distributions in cm space")
# print_as_vector_re(get_cm_vector_from_discrete_def(get_pop_eq_hydro), cm_eq_pop_str)
print_as_vector(hardcoded_cm_eq_incompressible_D2Q9, cm_eq_pop_str)  # save time
print("//calculate forces in cm space")
# print_as_vector(get_cm_vector_from_discrete_def(get_force_Guo_second_order), F_cm_str)
# print_as_vector(get_cm_vector_from_continuous_def(get_continuous_force_He_MB), F_cm_str)
print_as_vector(hardcoded_F_cm_He_hydro_LB_velocity_based_D2Q9, F_cm_str)  # save time

print("//collide eq: (eye(9)-S)*cm + S*cm_eq + (eye(9)-S/2.)*force_in_cm_space")
예제 #54
0
start = time.process_time()

lattice = 'D2Q9'
ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

T_raw_to_ortho = M_ortho_GS * Mraw_D2Q9.inv()

print('// === welcome to moments space! === \n ')
print('// === discrete moments ===\n ')

print('\n//F_m_Guo_extended')
F_m_Guo = get_mom_vector_from_discrete_def(dcmt.get_force_Guo,
                                           discrete_transform=dcmt.get_m,
                                           moments_order=moments_dict[lattice])
print_as_vector(F_m_Guo, 'F_cm')
print_as_vector(T_raw_to_ortho * F_m_Guo, 'F_GS_m')

print('\n//M*F_m_Guo_extended ')
MF_m_Guo = get_mom_vector_from_shift_mat(dcmt.get_force_Guo, mat=Mraw_D2Q9)
print_as_vector(MF_m_Guo, 'F_raw_m')
print_as_vector(T_raw_to_ortho * MF_m_Guo, 'F_GS_m')

print('\n//M_ortho_GS*F_m_Guo_extended ')
MF_m_Guo = get_mom_vector_from_shift_mat(dcmt.get_force_Guo, mat=M_ortho_GS)
print_as_vector(MF_m_Guo, 'F_GS_m')

print('\n\n// === continuous moments === \n ')

print('\n//Gou`s forcing -> Force_m - from continous definition: \n'
      'k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) \n'
예제 #55
0
# from sympy import pprint
# pprint(Mraw)
# pprint(Nraw)

pop_in_str = 'x_in'  # symbol defining populations
temp_pop_str = 'temp'  # symbol defining populations
cm_eq_pop_str = 'cm_eq'  # symbol defining populations

# GENERATE CODE
print(f"CudaDeviceFunction void set_eq(real_t {pop_in_str}[{q}], real_t Xeq, vector_t u) \n{{")
print("\t//=== THIS IS AUTOMATICALLY GENERATED CODE ===")
print_u2(d)
print(f"\treal_t {m00} = Xeq;")
print(f"\treal_t {temp_pop_str}[{q}];\n")

populations = get_DF(q, pop_in_str)
temp_populations = get_DF(q, temp_pop_str)

print("\n\t//equilibrium in central moments space")
print_as_vector(hardcoded_cm_eq, print_symbol=pop_in_str)

print("\n\t//back to raw moments")
print_as_vector(Nraw.inv() * populations, print_symbol=temp_pop_str)
# print_as_vector(Nraw.inv() * hardcoded_cm_eq, print_symbol=temp_pop_str)  # shortcut

print("\n\t//back to density-probability functions")
populations = Mraw.inv() * temp_populations
print_as_vector(populations, print_symbol=pop_in_str)

print("\n}\n")
예제 #56
0
파일: eq_cm.py 프로젝트: CFD-GO/TCLB_tools
lattice = 'D2Q9'
ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)

start = time.process_time()

print('// === welcome to cm! === \n ')
print('// === discrete cm ===\n ')


print('\n//population_eq -> cm_eq - by definition: k_mn = sum( (e_ix-ux)^m (e_iy-uy)^n * population_eq_i)')
print("moments: first order (linear) velocity expansion.")
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma_first_order(i),
                                          discrete_transform=dcmt.get_cm,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'pop_eq_first_order')

print("moments: second order (quadratic) velocity expansion.")
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma(i),
                                          discrete_transform=dcmt.get_cm,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'pop_eq')


print('\n//population -> cm - by definition: k_mn = sum( (e_ix-ux)^m (e_iy-uy)^n * population_i)')
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('%s[%d]' % ('pop', i)),
                                          discrete_transform=dcmt.get_cm,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'pop_cm')

print('\n//phase-field hydrodynamic model: population_eq_pf -> cm_eq_pf - by definition: '
예제 #57
0
파일: eq_m.py 프로젝트: CFD-GO/TCLB_tools
from SymbolicCollisions.core.printers import print_as_vector

import time

start = time.process_time()

lattice = 'D2Q9'
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
ccmt = ContinousCMTransforms(dzeta3D, u3D, F3D, rho)

print('\n\n// === discrete moments === \n ')
print("moments: first order (linear) velocity expansion.")
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma_first_order(i),
                                          discrete_transform=dcmt.get_m,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'pop_eq_first_order')

print("moments: second order (quadratic) velocity expansion.")
print('\n//population_eq -> m_eq - by definition: k_mn = sum( (e_ix)^m (e_iy)^n * population_eq_i)')
pop_eq = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_gamma(i),
                                          discrete_transform=dcmt.get_m,
                                          moments_order=moments_dict[lattice])
print_as_vector(pop_eq, 'pop_eq')

print('\n\n// === continuous moments === \n ')
print('\n//population_eq -> m_eq - from continuous definition: \n'
      'k_mn = integrate(fun, (x, -oo, oo), (y, -oo, oo)) \n'
      'where fun = fMB(rho,u,x,y) *(x)^m (y)^n ')

m_eq = get_mom_vector_from_continuous_def(ccmt.get_Maxwellian_DF,
                                          continuous_transformation=ccmt.get_m,