# from sympy import pprint # pprint(Mraw) # see what you have done # pprint(Nraw) temp_pop_str = 'temp' # symbol defining populations ### GENERATE CODE ### print( f"CudaDeviceFunction void relax_and_collide_cross_SIR_M(real_t rho, real_t {omega_ade}) \n{{" ) print("\t//=== THIS IS AUTOMATICALLY GENERATED CODE ===") print_sigma_sir() rtemp_populations = get_print_symbols_in_m_notation(rmoments_order, temp_pop_str) temp_populations = get_print_symbols_in_m_notation(moments_order, temp_pop_str) print( f"\treal_t {S} = {sum(get_print_symbols_in_m_notation(moments_order, s))};" ) 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};")
# 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() 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")
) print("\t//=== THIS IS AUTOMATICALLY GENERATED CODE ===") f = Symbol('f', positive=True) # fraction print( "\t// \"Optimal Stability of Advection-Diffusion Lattice Boltzmann Models \n" "\t// with Two Relaxation Times for Positive/Negative Equilibrium\" \n" "\t// by I. Ginzburg, D. d’Humières, A. Kuzmin, 2010\n" "\t// real_t omega_even = (-1.0 + 2.0/omega_ade)/(2.0*magic_parameter + 1.0);\n" "\t// real_t omega_even = 2. - omega_ade;\n" "\treal_t omega_even = 1.;\n") print_u2(d) print(f"\treal_t {Sigma2asSymbol} = {cs2};") print(f"\treal_t {Q} = getQ();") rf_populations = get_print_symbols_in_m_notation(rmoments_order, f) print( f"\treal_t {tilde_phi} = {sum(get_print_symbols_in_m_notation(moments_order, f))};" ) 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)
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) # print_as_vector(pop_eq, 'dcm_eq_antisymmetric', output_order_of_moments=rmoments_order) # print("TRT cm antisymmetric - moments: full velocity expansion.") # notice that the moments of non-eq DF is splited into sym and antisymmetric moments in the same way. feq = get_print_symbols_in_m_notation(rmoments_order, "h") feq_symm = lambda i: (feq[i] + feq[rev_i[i]]) / 2 feq_antisymm = lambda i: (feq[i] - feq[rev_i[i]]) / 2 pop_eq_full = get_mom_vector_from_discrete_def(feq_symm, discrete_transform=dcmt.get_m, moments_order=rmoments_order) # print_as_vector(pop_eq_full, 'm_eq_full_symmetric', output_order_of_moments=rmoments_order) print_as_vector_latex(pop_eq_full, 'k^{H,seq}', output_order_of_moments=rmoments_order) # print_as_vector_latex(pop_eq_full, 'm_s', output_order_of_moments=rmoments_order) pop_eq_full = get_mom_vector_from_discrete_def(feq_antisymm, discrete_transform=dcmt.get_m,
make_header(model) print("\t//=== THIS IS AUTOMATICALLY GENERATED CODE ===") # print(f"real_t {sv} = omega;") # print("real_t bulk_visc = 1./6. ;") # print("real_t {sb} = 1./(3*bulk_visc + 0.5);") # print(f"real_t {sb} = omega_bulk;\n") # s_b = 1./(3*bulk_visc + 0.5) if 'cht' in model: print_sigma_cht() print_u2(d) rtemp_populations = get_print_symbols_in_m_notation(rmoments_order, temp_pop_str) 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) cm_eq = get_print_symbols_in_m_notation(moments_order, cm_eq_pop_str) F_cm = get_print_symbols_in_m_notation(moments_order, F_str) if 'hydro_compressible' in model or 'hydro_incompressible' in model: print(f"\treal_t {omega_b} = 1.0;") if 'cht' in model: print(f"\treal_t {Enthalpy} = {sum(populations)};") else: print(f"\treal_t {m00} = {sum(populations)};") for t, p in zip(temp_populations, populations):
from SymbolicCollisions.core.printers import get_print_symbols_in_indx_notation, get_print_symbols_in_m_notation from SymbolicCollisions.core.DiscreteCMTransforms import \ DiscreteCMTransforms, get_mom_vector_from_discrete_def, get_mom_vector_from_shift_mat lattice = 'D2Q9' ccmt = ContinuousCMTransforms(dzeta3D, u3D, F3D, rho) dcmt = DiscreteCMTransforms(e_D2Q9, u2D, F2D, rho) start = time.process_time() pop_in_str = 'f' md = moments_dict['D2Q9'] mmd = Matrix(moments_dict['D2Q9']) # populations_m = get_print_symbols_in_m_notation(e_D2Q9, pop_in_str) populations_m = get_print_symbols_in_m_notation(mmd, pop_in_str) populations_inx = get_print_symbols_in_indx_notation(e_D2Q9.shape[0], pop_in_str) md = moments_dict['D2Q9'] mmd = Matrix(moments_dict['D2Q9']) ed = [e_D2Q9[i, :] for i in range(e_D2Q9.shape[0])] ed2 = get_print_symbols_in_m_notation(e_D2Q9, 'cantbempty') print_as_vector(populations_m, outprint_symbol='g') print() print_as_vector(populations_m, outprint_symbol='g', output_order_of_moments=e_D2Q9) # this is wrong! print() print_as_vector(populations_m,
# from sympy import pprint # pprint(Mraw) # pprint(Nraw) pop_in_str = 'h' # symbol defining populations temp_pop_str = 'temp' # symbol defining populations # GENERATE CODE print( f"CudaDeviceFunction void SetEquilibriumHeat(real_t H, real_t rho, 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_dict[f'D{d}Q{q}'], pop_in_str) temp_populations = get_print_symbols_in_m_notation(moments_dict[f'D{d}Q{q}'], temp_pop_str) # if 'cht' in model: # print(f"\treal_t {Enthalpy} = {sum(populations)};") # else: # print(f"\treal_t {m00} = {sum(populations)};") print("\n\t//equilibrium in central moments space") hardcoded_cm_eq = dynamic_import("SymbolicCollisions.core.hardcoded_results", f"hardcoded_cm_eq_cht_D{d}Q{q}") print_as_vector(hardcoded_cm_eq, outprint_symbol=pop_in_str, output_order_of_moments=moments_order)