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() 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")
pop_in_str = 'f_in' # symbol defining populations temp_pop_str = 'temp' # symbol defining populations cm_eq_pop_str = 'cm_eq' # symbol defining populations F_cm_str = 'F_cm' # eq : (eye(9)-S)*cm + S*cm_eq + (eye(9)-S/2.)*force_in_cm_space print("CudaDeviceFunction void relax_and_collide_CM_hydro(" f"real_t {pop_in_str}[{q}], " "real_t tau, " "vector_t u, " "vector_t Fhydro, " f"real_t {rho}) " "\n {") print_u2() print("real_t %s = 1./tau;" % omega_v) # print("real_t bulk_visc = 1./6. ;") # print("real_t %s = 1./(3*bulk_visc + 0.5);" % sb) print("real_t %s = omega_bulk;" % omega_b) # s_b = 1./(3*bulk_visc + 0.5) print("") 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)
pop_in_str = 'f_in' # symbol defining populations temp_pop_str = 'temp' # symbol defining populations cm_eq_pop_str = 'cm_eq' # symbol defining populations F_cm_str = 'F_phi_cm' # "Modelling incompressible thermal flows using a central-moments-based lattice Boltzmann method" L. Fei et al. 2017 # eq8 : (eye(9)-S)*cm + S*cm_eq + (eye(9)-S/2.)*force_in_cm_space print("CudaDeviceFunction void relax_and_collide_CM_phase_field(" "real_t %s[9], " "real_t tau, " "vector_t u, " "vector_t F_phi" ") \n{" % pop_in_str) print_u2() print("real_t %s = 1./tau;" % omega_v) # print("real_t bulk_visc = 1./6. ;") # print("real_t %s = 1./(3*bulk_visc + 0.5);" % sb) print("real_t %s = omega_bulk;" % omega_b) # s_b = 1./(3*bulk_visc + 0.5) print("") 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)
'hydro': f"CudaDeviceFunction void relax_and_collide_hydro_with_F(real_t {pop_in_str}[{q}], real_t {omega_v}, vector_t u, vector_t {F_str}) \n{{", 'ade_with_f': f"CudaDeviceFunction void relax_and_collide_ADE_with_F(real_t {pop_in_str}[{q}], real_t {omega_ade}, vector_t u, vector_t {F_str}) \n{{", 'ade': f"CudaDeviceFunction void relax_and_collide_ADE(real_t {pop_in_str}[{q}], real_t {omega_ade}, vector_t u) \n{{", } result = model_switcher.get(choice, lambda: "Invalid argument") print(result) 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) print_u2(d) print_ccode(get_m00(q, pop_in_str), assign_to=f'\treal_t {m00}') def make_variables(choice): model_switcher = { 'hydro': f"\n\treal_t {temp_pop_str}[{q}];\n", 'ade_with_f': f"\n\treal_t {temp_pop_str}[{q}];\n", 'ade': f"\n\treal_t {temp_pop_str}[{q}];\n", } # Get the function from switcher dictionary result = model_switcher.get(choice, lambda: "Invalid argument") print(result) make_variables(model)