Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
0
from SymbolicCollisions.core.printers import print_as_vector
from SymbolicCollisions.core.ContinuousCMTransforms import \
    ContinuousCMTransforms, get_mom_vector_from_continuous_def
from SymbolicCollisions.core.cm_symbols import \
    F3D, dzeta3D, u3D, rho
from SymbolicCollisions.core.MatrixGenerator import get_m_order_as_in_r

from SymbolicCollisions.core.DiscreteCMTransforms import \
    DiscreteCMTransforms, get_mom_vector_from_discrete_def, get_mom_vector_from_shift_mat

from SymbolicCollisions.core.cm_symbols import e_D2Q9, u2D, F2D, rho, moments_dict, NrawD2Q9, Mraw_D2Q9

ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)
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')
Пример #6
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
Пример #7
0
from SymbolicCollisions.core.printers import print_as_vector
from sympy.matrices import Matrix
from sympy import Symbol
from SymbolicCollisions.core.DiscreteCMTransforms import DiscreteCMTransforms, get_mom_vector_from_discrete_def
from SymbolicCollisions.core.ContinuousCMTransforms import ContinuousCMTransforms, get_mom_vector_from_continuous_def
from SymbolicCollisions.core.cm_symbols import \
    F3D, dzeta3D, u3D, rho

from SymbolicCollisions.core.cm_symbols import \
    F2D, dzeta2D, u2D, rho

from SymbolicCollisions.core.cm_symbols import rho, moments_dict
import time

lattice = 'D3Q27'
ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)
# ccmt = ContinuousCMTransforms(dzeta2D, u2D, F2D, rho)
start = time.process_time()

print('\n\n// === discrete m === \n ')

from SymbolicCollisions.core.cm_symbols import e_D3Q7

print("moments: first order (linear) velocity expansion.")

dcmt = DiscreteCMTransforms(e_D3Q7, u3D, F3D, rho)
pop_eq = get_mom_vector_from_discrete_def(
    lambda i: dcmt.get_gamma_first_order_cht(i),
    discrete_transform=dcmt.get_m,
    moments_order=moments_dict['D3Q7'],
    serial_run=True)
Пример #8
0
#
# 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', raw_output=True)
# # print_as_vector(cm_eq_tot_e, 'cm_eq_tot_e', raw_output=False)  # TODO: implement printer for these kind of terms
#
# cm_eq_internal_e = get_mom_vector_from_continuous_def(ccmt.get_internal_energy_Maxwellian_DF,
#                                            continuous_transformation=ccmt.get_cm,
#                                            moments_order=moments_dict[lattice])
# print_as_vector(cm_eq_internal_e, 'cm_eq_internal_e')

ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho, cs2=Sigma2asSymbol)
# ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho, cs2=Sigma2, enthalpy=rho*cp*Temperature)
cm_cht_eq = get_mom_vector_from_continuous_def(
    ccmt.get_cht_DF,
    continuous_transformation=ccmt.get_cm,
    moments_order=moments_dict[lattice],
    serial_run=False)
print_as_vector(cm_cht_eq, 'm_cht_eq', raw_output=False)
print("--------------------------------------------------")
print_as_vector(cm_cht_eq, 'm_cht_eq', raw_output=True)

print('\n\n Done in %s [s].' % str(time.process_time() - start))
Пример #9
0
    F3D, dzeta3D, u3D, rho

from SymbolicCollisions.core.ContinuousCMTransforms import ContinuousCMTransforms, get_mom_vector_from_continuous_def

from sympy import Symbol
from sympy import Matrix
from SymbolicCollisions.core.cm_symbols import dzeta2D, e_D2Q9, u2D, F2D, rho, moments_dict, NrawD2Q9, Mraw_D2Q9, M_ortho_GS
from SymbolicCollisions.core.printers import print_as_vector

import time

start = time.process_time()

lattice = 'D2Q9'
dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho)
ccmt = ContinuousCMTransforms(dzeta2D, u2D, F2D, rho)
# # ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho)
# print('\n\n// === discrete moments === \n ')
# print('\n//moments from definition: k_mn = sum( (e_ix)^m (e_iy)^n * fun_i)')
# print('\n\n// === BOUNDARY CONDITIONS === \n ')
# print("discrete raw moments: velocity bc")
# mom_bc = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_velocity_bc(i),
#                                           discrete_transform=dcmt.get_m,
#                                           moments_order=moments_dict[lattice])
# print_as_vector(mom_bc, 'drm_velocity_bc')
# print("-------  ----------")
# mom_bc = get_mom_vector_from_discrete_def(lambda i: Symbol('m00') * dcmt.get_velocity_bc(i),
#                                           discrete_transform=dcmt.get_cm,
#                                           moments_order=moments_dict[lattice])
# print_as_vector(mom_bc, 'dcm_velocity_bc')
# print("\n\n discrete raw moments: pressure bc")
Пример #10
0
from SymbolicCollisions.core.printers import print_as_vector
from sympy.matrices import Matrix
from sympy import Symbol
from SymbolicCollisions.core.ContinuousCMTransforms import ContinuousCMTransforms, get_mom_vector_from_continuous_def
from SymbolicCollisions.core.cm_symbols import \
    F3D, dzeta3D, u3D, rho

from SymbolicCollisions.core.cm_symbols import rho, moments_dict
import time

lattice = 'D2Q9'
ccmt = ContinuousCMTransforms(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')