def main(**kwargs): # -------- raw_data_path = "/mnt/c/Users/liaha/scratch/" config = "1.1.1-torus2_b-gz2" specs = "a0beta500torBeta_br32x32x64rl2x2" time = 26 filename = raw_data_path + config + "_" + specs + ".prim.{:05}.athdf".format(time) kwargs['radius'] = 10.0 # --- # fi=kwargs['file'] fi=filename quantities=['rho','vel1','vel2','vel3','Bcc1','Bcc2','Bcc3'] # p=read.athdf(fi,quantities=quantities,x1_min=kwargs['radius'], x1_max=kwargs['radius']) p=read_athdf(fi,quantities=quantities,x1_min=kwargs['radius'], x1_max=kwargs['radius']) print(p['vel1'].shape) r=p['x1v'] print(r.shape) theta=p['x2v'] phi=p['x3v'] R=p['x1f'] nx1=len(r) nx2=len(theta) nx3=len(phi) dp=(2*np.pi/nx3)*np.ones(nx3) dt=(np.pi/nx2)*np.ones(nx2) Dp=dp.reshape(nx3,1, 1) Dt=dt.reshape(1,nx2, 1) dr=np.ones(nx1) for i in range(nx1): dr[i]=R[i+1]-R[i] Dr=dr.reshape(1,1,nx1) rho=p['rho'] ks=kerr(r,theta) f=fourvector(r,theta,p['vel1'],p['vel2'],p['vel3'],p['Bcc1'],p['Bcc2'],p['Bcc3']) print(f.gamma.shape) print("gamma") print(np.max(f.gamma)) k=Dt*Dp*ks.g Mflux=f.u1*k*rho x=open("massflux.txt","a") t=open("Timemassflux.txt","a") print(np.sum(np.sum(Mflux, axis=0), axis=0)) # np.savetxt(x,np.sum(np.sum(Mflux,axis=0),axis=0)) # np.savetxt(t,np.array(p['Time']).reshape(1,)) x.close() t.close()
def get_calculated_data(data_in, calc_q): r = data_in["x1v"] theta = data_in["x2v"] metric = kerr.kerr(r, theta) fourvector = kerr.fourvector(r, theta, data_in['vel1'], data_in['vel2'], data_in['vel3'], data_in['Bcc1'], data_in['Bcc2'], data_in['Bcc3']) if calc_q == 'u1': data_in[calc_q] = fourvector.u1 elif calc_q == 'rhou1': data_in[calc_q] = data_in['rho'] * fourvector.u1 elif calc_q == 'bsq': data_in[calc_q] = fourvector.bsq elif calc_q == 'beta': data_in[calc_q] = data_in['press'] / fourvector.pmag elif calc_q == 'test': data_in[calc_q] = 2.0 * data_in['press'] / (data_in['Bcc3']**2) return data_in
# reshape variables dp = (2 * np.pi / nx3) * np.ones(nx3) dt = (np.pi / nx2) * np.ones(nx2) Dp = dp.reshape(nx3, 1, 1) Dt = dt.reshape(1, nx2, 1) dr = np.ones(nx1) #tbh i don't know what this is for for i in range(nx1): dr[i] = R[i + 1] - R[i] # reshape and load more variables, including GR variables Dr = dr.reshape(1, 1, nx1) rho = p['rho'] ks = kerr(r, theta) f = fourvector(r, theta, p['vel1'], p['vel2'], p['vel3'], p['Bcc1'], p['Bcc2'], p['Bcc3']) # perform mflux calculation k = Dt * Dp * ks.g Mflux = f.u1 * k * rho total_mflux = np.sum(np.sum(Mflux, axis=0), axis=0) code_time = np.array(p['Time']).reshape(1, ) output_data = np.array([code_time, total_mflux]).reshape((1, 2)) # save data to file if not os.path.isfile(mdot_path): header = "time, mdot" with open(mdot_path, "a") as f: np.savetxt(f, output_data, header=header) # Clean up mdot by removing duplicates and sorting
print(np.allclose(metric_AH.G11[0, :, :], metric_MA.G11)) print(np.allclose(metric_AH.G22[0, :, :], metric_MA.G22)) print(np.allclose(metric_AH.G31[0, :, :], metric_MA.G31)) print(np.allclose(metric_AH.G33[0, :, :], metric_MA.G33)) print("Compare gamma (with allclose)") print(vel1.shape) vel1r = vel1[:, :, r10ind].reshape(nx3, nx2, 1) vel2r = vel2[:, :, r10ind].reshape(nx3, nx2, 1) vel3r = vel3[:, :, r10ind].reshape(nx3, nx2, 1) Bcc1r = Bcc1[:, :, r10ind].reshape(nx3, nx2, 1) Bcc2r = Bcc2[:, :, r10ind].reshape(nx3, nx2, 1) Bcc3r = Bcc3[:, :, r10ind].reshape(nx3, nx2, 1) gamma_AH = metric_AH.get_normal_frame_gamma((vel1r, vel2r, vel3r)) four_vel_AH = metric_AH.get_four_velocity_from_output((vel1r, vel2r, vel3r)) # fourvec_MA = fourvector(x1v, x2v, vel1, vel2, vel3, Bcc1, Bcc2, Bcc3) fourvec_MA = fourvector(x1vr, x2v, vel1r, vel2r, vel3r, Bcc1r, Bcc2r, Bcc3r) print("Is usquared the same?") print(np.allclose(metric_AH.usq, fourvec_MA.usq)) print(np.allclose(gamma_AH, fourvec_MA.gamma)) print("Is u0 the same?") print(np.allclose(four_vel_AH[0], fourvec_MA.u0)) print("Is u1 the same?") print(np.allclose(four_vel_AH[1], fourvec_MA.u1)) print("Are the transformed magnetic fields the same?") proj_B_AH = metric_AH.get_proj_bfield_from_outputB_fourV( four_vel_AH, (Bcc1r, Bcc2r, Bcc3r)) print(np.allclose(proj_B_AH[0], fourvec_MA.b0))
# print(data.keys()) # print("Simulation time is {}".format(data["Time"])) # Define variables based on data # "Time" is how that variable is titled in the data, so the capital is important simulation_timeA = dataA["Time"] simulation_timeB = dataB["Time"] pressdataA = dataA['press'] pressdataB = dataB['press'] r = dataA["x1v"] theta = dataA["x2v"] # Define metric variables metric = kerr.kerr(r, theta) fourvectorA = kerr.fourvector(r, theta, dataA['vel1'], dataA['vel2'], dataA['vel3'], dataA['Bcc1'], dataA['Bcc2'], dataA['Bcc3']) pmagdataA = fourvectorA.pmag fourvectorB = kerr.fourvector(r, theta, dataB['vel1'], dataB['vel2'], dataB['vel3'], dataB['Bcc1'], dataB['Bcc2'], dataB['Bcc3']) pmagdataB = fourvectorB.pmag # Define radius radius_in_codeunits = 5 radiusind = (np.abs(dataA['x1v'] - radius_in_codeunits)).argmin() # print(radiusind) # get line out at constant radius phi_index = 0 radius_index = 0
# reshape variables dp = (2 * np.pi / nx3) * np.ones(nx3) dt = (np.pi / nx2) * np.ones(nx2) Dp = dp.reshape(nx3, 1, 1) Dt = dt.reshape(1, nx2, 1) dr = np.ones(nx1) # tbh i don't know what this is for for i in range(nx1): dr[i] = R[i + 1] - R[i] # reshape and load more variables, including GR variables Dr = dr.reshape(1, 1, nx1) rho = data['rho'] ks = kerr(r, theta) f = fourvector(r, theta, data['vel1'], data['vel2'], data['vel3'], data['Bcc1'], data['Bcc2'], data['Bcc3']) # perform mflux calculation k = Dt * Dp * ks.g Mflux = f.u1 * k * rho total_mflux = np.sum(np.sum(Mflux, axis=0), axis=0) output_data = np.array([r, total_mflux]) # save data to file filename = "mdot_over_r_t{}".format(timestep) if not os.path.isfile(mdot_reduced_path): header = "radius, mdot" print(mdot_reduced_path) with open(mdot_reduced_path + filename, "a") as f: np.savetxt(f, output_data, header=header)