Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
0
    ez_new = dynamic_import("SymbolicCollisions.core.cm_symbols", f"ez_D{d}Q{q}")
else:
    ez_new = None

e_new = dynamic_import("SymbolicCollisions.core.cm_symbols", f"e_D{d}Q{q}")


moments_order = np.array(moments_dict[f'D{d}Q{q}'])
print(f"order of moments | rmoments: \n "
      f"{pd.concat([pd.DataFrame.from_records(moments_order),pd.DataFrame.from_records(rmoments_order)], axis=1)}")


hardcoded_cm_eq = dynamic_import("SymbolicCollisions.core.hardcoded_results", f"hardcoded_cm_eq_cht_D{d}Q{q}")

# ARRANGE STUFF
matrixGenerator = MatrixGenerator(ex_new, ey_new, ez_new, moments_order)
Mraw = matrixGenerator.get_raw_moments_matrix()
Nraw = matrixGenerator.get_shift_matrix()

# from sympy import pprint
# pprint(Mraw)
# pprint(Nraw)

pop_in_str = 'h'  # symbol defining populations
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()
Пример #6
0

    # hardcoded_F_cm = dynamic_import(*which_F_cm)
    return hardcoded_m_eq, hardcoded_F_m


hardcoded_m_eq, hardcoded_F_m = get_m_eq_and_F_m_switcher(model)
# hardcoded_cm_eq = dynamic_import("SymbolicCollisions.core.hardcoded_results", f"hardcoded_cm_eq_compressible_D{d}Q{q}")
# hardcoded_F_cm = dynamic_import("SymbolicCollisions.core.hardcoded_results", f"hardcoded_F_cm_pf_D{d}Q{q}")

# hardcoded_cm_eq = dynamic_import("SymbolicCollisions.core.hardcoded_results", f"hardcoded_cm_eq_incompressible_D{d}Q{q}")
# hardcoded_F_cm = dynamic_import("SymbolicCollisions.core.hardcoded_results", f"hardcoded_F_cm_He_hydro_LB_incompressible_D{d}Q{q}")


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

# from sympy import pprint
# pprint(Mraw)  # see what you have done
# pprint(Nraw)

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


# GENERATE CODE
def make_header(choice):
    model_switcher = {
Пример #7
0
from sympy import Symbol
from sympy.matrices import Matrix, eye, zeros, ones, diag
from sympy import pretty_print

from SymbolicCollisions.core.cm_symbols import *
from SymbolicCollisions.core.MatrixGenerator import MatrixGenerator
from SymbolicCollisions.core.printers import *

matrixGenerator = MatrixGenerator(ex_D2Q9, ey_D2Q9, None, moments_dict[f'D2Q9'])
Mraw = matrixGenerator.get_raw_moments_matrix()

Nraw = matrixGenerator.get_shift_matrix()

Traw = matrixGenerator.get_raw_x_shift_moments_matrix()

Nraw_alternative = Traw * Mraw.inv()
Nraw_alternative_simplified = Matrix([round_and_simplify(Nraw_alternative[i, :]) for i in range(len(ex_D2Q9))])
# print_as_vector(f1, 'f1')

pretty_print(Mraw)
pretty_print(Nraw)
pretty_print(Nraw_alternative)

Пример #8
0
                                          moments_order=rmoments_order)
# print_as_vector(m_eq, 'm_raw_eq', raw_output=False, output_order_of_moments=rmoments_order)
print_as_vector_latex(m_eq, 'k^{H,eq}', output_order_of_moments=rmoments_order)

cm_eq = get_mom_vector_from_continuous_def(
    ccmt.get_Maxwellian_DF,
    continuous_transformation=ccmt.get_cm,
    moments_order=rmoments_order)
# print_as_vector(cm_eq, 'cm_eq', raw_output=False, output_order_of_moments=rmoments_order)
print_as_vector_latex(cm_eq,
                      '\\tilde{k}^{H,eq}',
                      output_order_of_moments=rmoments_order)

print("--------------------------------------------------")

matrixGenerator = MatrixGenerator(ex, ey, ez, rmoments_order)
Mraw = matrixGenerator.get_raw_moments_matrix()
Nraw = matrixGenerator.get_shift_matrix()

feq = Mraw.inv() * m_eq.transpose()
print_as_vector(feq,
                outprint_symbol='f_eq_from_anal_mom',
                output_order_of_moments=rmoments_order)
# print_as_vector_latex(feq, 'h^{eq}', output_order_of_moments=rmoments_order)

print("--------------------------------------------------")

dcmt = DiscreteCMTransforms(e_D2Q9, u3D, None, None)
# 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=rmoments_order)
Пример #9
0
from sympy import Symbol
from sympy.matrices import Matrix, eye, zeros, ones, diag
from sympy import pretty_print

from SymbolicCollisions.core.cm_symbols import *
from SymbolicCollisions.core.MatrixGenerator import MatrixGenerator
from SymbolicCollisions.core.printers import *

matrixGenerator = MatrixGenerator(ex_D2Q9, ey_D2Q9, None,
                                  moments_dict[f'D2Q9'])
Mraw = matrixGenerator.get_raw_moments_matrix()
ShiftMat = matrixGenerator.get_shift_matrix(M_ortho_GS)

# cm = get_populations('cm')
cm = Matrix([0.123, 0.234, 0.345, 0.456, 0.567, 0.678, 0.789, 0.890, 0.901])

ShiftMat = ShiftMat.subs({'u.x': 0.0123, 'u.y': 0.0234})

# pretty_print(ShiftMat)
f1 = M_ortho_GS * ShiftMat.inv() * cm
print_as_vector(f1, 'f1')

print('another approach')
Nraw = NrawD2Q9.subs({'u.x': 0.0123, 'u.y': 0.0234})

f2 = Mraw_D2Q9.inv() * Nraw.inv() * cm
print_as_vector(f2, 'f2')

from numpy.testing import assert_almost_equal
for i in range(0):
    assert_almost_equal(f1[i], f2[i])
Пример #10
0
import pandas as pd


m_seed = [0, 1, 2]
rmoments_order = get_m_order_as_in_r(m_seed, m_seed, m_seed)
q, d = rmoments_order.shape

moments_order = np.array(moments_dict[f'D{d}Q{q}'])
# print(f"order of moments | rmoments: \n "
#       f"{pd.concat([pd.DataFrame.from_records(moments_order),pd.DataFrame.from_records(rmoments_order)], axis=1)}")

e_seed = [0, 1, -1]
ex_D3Q27new, ey_D3Q27new, ez_D3Q27new, e_D3Q27new = get_e_as_in_r(e_seed, e_seed, e_seed)
# print(f"lattice velocities - e: \n {np.array(e_D3Q27new)}")

matrixGenerator = MatrixGenerator(ex_D3Q27new, ey_D3Q27new, ez_D3Q27new, moments_order)
# Mraw = matrixGenerator.get_raw_moments_matrix()
# Nraw = matrixGenerator.get_shift_matrix()

# from sympy import pprint
# pprint(Mraw)  # see what you have done
# pprint(Nraw)

pop_in_str = 'CS_'  # symbol defining populations
temp_pop_str = 'C_'  # symbol defining populations

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)

#  const real_t CS_000 = C_000 ;
print(f"\treal_t H = {sum(populations)};")