def add_to_Cfunction_dict__driver_function(): outC_function_master_list.append(outC_function_element("empty", "empty", "empty", "empty", "GiRaFFE_NRPy_RHSs", "empty", "empty", "empty", "empty", "empty", "empty", "empty")) outC_function_outdir_dict["GiRaFFE_NRPy_RHSs"] = "default" outC_function_dict["GiRaFFE_NRPy_RHSs"] = main_evolution_func outC_function_prototype_dict["GiRaFFE_NRPy_RHSs"] = main_evolution_prototype outC_function_master_list.append(outC_function_element("empty", "empty", "empty", "empty", "GiRaFFE_NRPy_post_step", "empty", "empty", "empty", "empty", "empty", "empty", "empty")) outC_function_outdir_dict["GiRaFFE_NRPy_post_step"] = "default" outC_function_dict["GiRaFFE_NRPy_post_step"] = post_step_func outC_function_prototype_dict["GiRaFFE_NRPy_post_step"] = post_step_prototype
def add_to_Cfunction_dict__GiRaFFE_NRPy_BCs(): outC_function_master_list.append(outC_function_element("empty", "empty", "empty", "empty", potential_name, "empty", "empty", "empty", "empty", "empty", "empty", "empty")) outC_function_outdir_dict[potential_name] = "default" outC_function_dict[potential_name] = includes+potential_body.replace("../set_Cparameters.h","set_Cparameters.h") outC_function_prototype_dict[potential_name] = potential_prototype outC_function_master_list.append(outC_function_element("empty", "empty", "empty", "empty", velocity_name, "empty", "empty", "empty", "empty", "empty", "empty", "empty")) outC_function_outdir_dict[velocity_name] = "default" outC_function_dict[velocity_name] = includes+velocity_body.replace("../set_Cparameters.h","set_Cparameters.h") outC_function_prototype_dict[velocity_name] = velocity_prototype
def add_to_Cfunction_dict__GiRaFFE_NRPy_Afield_flux(gammaDD, betaU, alpha, outdir): for flux_dirn in range(3): chsp.find_cmax_cmin(flux_dirn, gammaDD, betaU, alpha) Ccode_kernel = outputC([chsp.cmax, chsp.cmin], ["cmax", "cmin"], "returnstring", params="outCverbose=False,CSE_sorting=none") Ccode_kernel = Ccode_kernel.replace("cmax", "*cmax").replace("cmin", "*cmin") Ccode_kernel = Ccode_kernel.replace("betaU0", "betaUi").replace( "betaU1", "betaUi").replace("betaU2", "betaUi") with open( os.path.join(outdir, "compute_cmax_cmin_dirn" + str(flux_dirn) + ".h"), "w") as file: file.write(Ccode_kernel) outC_function_master_list.append( outC_function_element("empty", "empty", "empty", "empty", name, "empty", "empty", "empty", "empty", "empty", "empty", "empty")) outC_function_outdir_dict[name] = "default" outC_function_dict[name] = includes + body.replace("../set_Cparameters.h", "set_Cparameters.h") outC_function_prototype_dict[name] = prototype
def add_to_Cfunction_dict__GiRaFFE_NRPy_staggered_Afield_flux(): outC_function_master_list.append( outC_function_element("empty", "empty", "empty", "empty", name, "empty", "empty", "empty", "empty", "empty", "empty", "empty")) outC_function_outdir_dict[name] = "default" outC_function_dict[name] = includes + body.replace("../set_Cparameters.h", "set_Cparameters.h") outC_function_prototype_dict[name] = prototype
def unpickle_NRPy_env(NRPyEnvVars): import pickle # https://www.pythonforthelab.com/blog/storing-binary-data-and-serializing/ grfcs_list = [] param_list = [] Cparm_list = [] outCfunc_dict = {} outCfuncproto_dict = {} outCfuncoutdir_dict = {} outCfunc_master_list = [] for WhichParamSet in NRPyEnvVars[0]: # gridfunctions i = 0 num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): grfcs_list.append( gri.glb_gridfc(gftype=pickle.loads(WhichParamSet[i + 0]), name=pickle.loads(WhichParamSet[i + 1]), rank=pickle.loads(WhichParamSet[i + 2]), DIM=pickle.loads(WhichParamSet[i + 3]), f_infinity=pickle.loads(WhichParamSet[i + 4]), wavespeed=pickle.loads(WhichParamSet[i + 5]))) i += 6 # parameters num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): param_list.append( par.glb_param(type=pickle.loads(WhichParamSet[i + 0]), module=pickle.loads(WhichParamSet[i + 1]), parname=pickle.loads(WhichParamSet[i + 2]), defaultval=pickle.loads(WhichParamSet[i + 3]))) i += 4 # Cparameters num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): Cparm_list.append( par.glb_Cparam(type=pickle.loads(WhichParamSet[i + 0]), module=pickle.loads(WhichParamSet[i + 1]), parname=pickle.loads(WhichParamSet[i + 2]), defaultval=pickle.loads(WhichParamSet[i + 3]))) i += 4 # outC_func_dict num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): funcname = pickle.loads(WhichParamSet[i + 0]) funcbody = pickle.loads(WhichParamSet[i + 1]) i += 2 outCfunc_dict[funcname] = funcbody # outC.outC_function_prototype_dict num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): funcname = pickle.loads(WhichParamSet[i + 0]) funcproto = pickle.loads(WhichParamSet[i + 1]) i += 2 outCfuncproto_dict[funcname] = funcproto # outC.outC_function_outdir_dict num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): funcname = pickle.loads(WhichParamSet[i + 0]) funcoutdir = pickle.loads(WhichParamSet[i + 1]) i += 2 outCfuncoutdir_dict[funcname] = funcoutdir # outC.outC_function_master_list num_elements = pickle.loads(WhichParamSet[i]) i += 1 for lst in range(num_elements): includes = pickle.loads(WhichParamSet[i + 0]) i += 1 prefunc = pickle.loads(WhichParamSet[i + 0]) i += 1 desc = pickle.loads(WhichParamSet[i + 0]) i += 1 c_type = pickle.loads(WhichParamSet[i + 0]) i += 1 name = pickle.loads(WhichParamSet[i + 0]) i += 1 params = pickle.loads(WhichParamSet[i + 0]) i += 1 preloop = pickle.loads(WhichParamSet[i + 0]) i += 1 body = pickle.loads(WhichParamSet[i + 0]) i += 1 loopopts = pickle.loads(WhichParamSet[i + 0]) i += 1 postloop = pickle.loads(WhichParamSet[i + 0]) i += 1 enableCparameters = pickle.loads(WhichParamSet[i + 0]) i += 1 rel_path_to_Cparams = pickle.loads(WhichParamSet[i + 0]) i += 1 # 'includes prefunc desc c_type name params preloop body loopopts postloop enableCparameters rel_path_to_Cparams append_coordsuffix' outCfunc_master_list += [ outC.outC_function_element( includes=includes, prefunc=prefunc, desc=desc, c_type=c_type, name=name, params=params, preloop=preloop, body=body, loopopts=loopopts, postloop=postloop, enableCparameters=enableCparameters, rel_path_to_Cparams=rel_path_to_Cparams) ] grfcs_list_uniq = [] for gf_ntuple_stored in grfcs_list: found_gf = False for gf_ntuple_new in grfcs_list_uniq: if gf_ntuple_new == gf_ntuple_stored: found_gf = True if found_gf == False: grfcs_list_uniq.append(gf_ntuple_stored) param_list_uniq = [] for pr_ntuple_stored in param_list: found_pr = False for pr_ntuple_new in param_list_uniq: if pr_ntuple_new == pr_ntuple_stored: found_pr = True if found_pr == False: param_list_uniq.append(pr_ntuple_stored) # Set glb_paramsvals_list: # Step 1: Reset all paramsvals to their defaults # BAD IDEA: OVERWRITTEN DEFAULTS SHOULD BE KEPT. # par.glb_paramsvals_list = [] # for parm in param_list_uniq: # par.glb_paramsvals_list.append(parm.defaultval) Cparm_list_uniq = [] for Cp_ntuple_stored in Cparm_list: found_Cp = False for Cp_ntuple_new in Cparm_list_uniq: if Cp_ntuple_new == Cp_ntuple_stored: found_Cp = True if found_Cp == False: Cparm_list_uniq.append(Cp_ntuple_stored) gri.glb_gridfcs_list = [] par.glb_params_list = [] par.glb_Cparams_list = [] gri.glb_gridfcs_list = grfcs_list_uniq par.glb_params_list = param_list_uniq par.glb_Cparams_list = Cparm_list_uniq for key, item in outCfunc_dict.items(): outC.outC_function_dict[key] = item for key, item in outCfuncproto_dict.items(): outC.outC_function_prototype_dict[key] = item for key, item in outCfuncoutdir_dict.items(): outC.outC_function_outdir_dict[key] = item return outCfunc_master_list