def __init__(self, fd_order=2, vars_at_inf_default = 0., vars_radial_falloff_power_default = 3., vars_speed_default = 1.): evolved_variables_list, _, _ = gri.gridfunction_lists() # set class finite differencing order self.fd_order = fd_order NRPy_FD_order = par.parval_from_str("finite_difference::FD_CENTDERIVS_ORDER") if NRPy_FD_order < fd_order: print("ERROR: The global central finite differencing order within NRPy+ must be greater than or equal to the Sommerfeld boundary condition's finite differencing order") sys.exit(1) # Define class dictionaries to store sommerfeld parameters for each EVOL gridfunction # EVOL gridfunction asymptotic value at infinity self.vars_at_infinity = {} # EVOL gridfunction wave speed at outer boundaries self.vars_speed = {} # EVOL gridfunction radial falloff power self.vars_radial_falloff_power = {} # Set default values for each specific EVOL gridfunction for gf in evolved_variables_list: self.vars_at_infinity[gf.upper() + 'GF'] = vars_at_inf_default self.vars_radial_falloff_power[gf.upper() + 'GF'] = vars_radial_falloff_power_default self.vars_speed[gf.upper() + 'GF'] = vars_speed_default
def __init__(self, vars_at_inf_default=0., vars_radpower_default=3., vars_speed_default=1.): evolved_variables_list, auxiliary_variables_list, auxevol_variables_list = \ gri.gridfunction_lists() # Define class dictionaries to store sommerfeld parameters for each EVOL gridfunction # EVOL gridfunction asymptotic value at infinity self.vars_at_infinity = {} # EVOL gridfunction wave speed at outer boundaries self.vars_speed = {} # EVOL gridfunction radial falloff power self.vars_radpower = {} # Set default values for each specific EVOL gridfunction for gf in evolved_variables_list: self.vars_at_infinity[gf.upper() + 'GF'] = vars_at_inf_default self.vars_radpower[gf.upper() + 'GF'] = vars_radpower_default self.vars_speed[gf.upper() + 'GF'] = vars_speed_default
def NRPy_basic_defines_set_gridfunction_defines_with_parity_types(verbose=True): # First add human-readable gridfunction aliases (grid.py) to NRPy_basic_defines dictionary, evolved_variables_list, auxiliary_variables_list, auxevol_variables_list = gri.gridfunction_lists() # Step 3.b: set the parity conditions on all gridfunctions in gf_list, # based on how many digits are at the end of their names def set_parity_types(list_of_gf_names): parity_type = [] for name in list_of_gf_names: for gf in gri.glb_gridfcs_list: if gf.name == name: parity_type__orig_len = len(parity_type) if gf.DIM < 3 or gf.DIM > 4: print("Error: Cannot currently specify parity conditions on gridfunctions with DIM<3 or >4.") sys.exit(1) if gf.rank == 0: parity_type.append(0) elif gf.rank == 1: if gf.DIM == 3: parity_type.append(int(gf.name[-1]) + 1) # = 1 for e.g., beta^0; = 2 for e.g., beta^1, etc. elif gf.DIM == 4: parity_type.append(int(gf.name[-1])) # = 0 for e.g., b4^0; = 1 for e.g., beta^1, etc. elif gf.rank == 2: if gf.DIM == 3: # element of a list; a[-2] the # second-to-last element, etc. idx0 = gf.name[-2] idx1 = gf.name[-1] if idx0 == "0" and idx1 == "0": parity_type.append(4) elif (idx0 == "0" and idx1 == "1") or (idx0 == "1" and idx1 == "0"): parity_type.append(5) elif (idx0 == "0" and idx1 == "2") or (idx0 == "2" and idx1 == "0"): parity_type.append(6) elif idx0 == "1" and idx1 == "1": parity_type.append(7) elif (idx0 == "1" and idx1 == "2") or (idx0 == "2" and idx1 == "1"): parity_type.append(8) elif idx0 == "2" and idx1 == "2": parity_type.append(9) elif gf.DIM == 4: idx0 = gf.name[-2] idx1 = gf.name[-1] # g4DD00 = g_{tt} : parity type = 0 # g4DD01 = g_{tx} : parity type = 1 # g4DD02 = g_{ty} : parity type = 2 # g4DD0a = g_{ta} : parity type = a if idx0 == "0": parity_type.append(int(idx1)) elif idx1 == "0": parity_type.append(int(idx0)) if idx0 == "1" and idx1 == "1": parity_type.append(4) elif (idx0 == "1" and idx1 == "2") or (idx0 == "2" and idx1 == "1"): parity_type.append(5) elif (idx0 == "1" and idx1 == "3") or (idx0 == "3" and idx1 == "1"): parity_type.append(6) elif idx0 == "2" and idx1 == "2": parity_type.append(7) elif (idx0 == "2" and idx1 == "3") or (idx0 == "3" and idx1 == "2"): parity_type.append(8) elif idx0 == "3" and idx1 == "3": parity_type.append(9) if len(parity_type) == parity_type__orig_len: print("Error: Could not figure out parity type for "+gf.gftype+" gridfunction: " + gf.name,gf.DIM,gf.name[-2],gf.name[-1],gf.rank) sys.exit(1) if len(parity_type) != len(list_of_gf_names): print("Error: For some reason the length of the parity types list did not match the length of the gf list.") sys.exit(1) return parity_type evol_parity_type = set_parity_types(evolved_variables_list) aux_parity_type = set_parity_types(auxiliary_variables_list) auxevol_parity_type = set_parity_types(auxevol_variables_list) # Output all gridfunctions to Ccodesrootdir/gridfunction_defines.h # ... then append to the file the parity type for each gridfunction. outstr = """ /* PARITY TYPES FOR ALL GRIDFUNCTIONS. * SEE \"Tutorial-Start_to_Finish-Curvilinear_BCs.ipynb\" FOR DEFINITIONS. */ """ if len(evolved_variables_list) > 0: outstr += "static const int8_t evol_gf_parity[" + str(len(evolved_variables_list)) + "] = { " for i in range(len(evolved_variables_list) - 1): outstr += str(evol_parity_type[i]) + ", " outstr += str(evol_parity_type[len(evolved_variables_list) - 1]) + " };\n" if len(auxiliary_variables_list) > 0: outstr += "static const int8_t aux_gf_parity[" + str(len(auxiliary_variables_list)) + "] = { " for i in range(len(auxiliary_variables_list) - 1): outstr += str(aux_parity_type[i]) + ", " outstr += str(aux_parity_type[len(auxiliary_variables_list) - 1]) + " };\n" if len(auxevol_variables_list) > 0: outstr += "static const int8_t auxevol_gf_parity[" + str(len(auxevol_variables_list)) + "] = { " for i in range(len(auxevol_variables_list) - 1): outstr += str(auxevol_parity_type[i]) + ", " outstr += str(auxevol_parity_type[len(auxevol_variables_list) - 1]) + " };\n" if verbose == True: for i in range(len(evolved_variables_list)): print("Evolved gridfunction \"" + evolved_variables_list[i] + "\" has parity type " + str( evol_parity_type[i]) + ".") for i in range(len(auxiliary_variables_list)): print("Auxiliary gridfunction \"" + auxiliary_variables_list[i] + "\" has parity type " + str( aux_parity_type[i]) + ".") for i in range(len(auxevol_variables_list)): print("AuxEvol gridfunction \"" + auxevol_variables_list[i] + "\" has parity type " + str( auxevol_parity_type[i]) + ".") return outstr