def temp(): '''Stores ion and electron total temperatures vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_temperatures_%s.txt" % (r), 'a') for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) Ti, Te, _, _ = angle.tmp(i, i) file.write(str(Ang) + "\t" + str(Ti) + "\t" + str(Te) + "\n") file.close()
def temp_i(): '''Stores perpendicular and parallel ion temperatures vs. poloidal angle.''' angle.angle_mesh() file = open("ti255_ion_temperatures_%s.txt" % (r), 'a') for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) _, _, Tperp, Ei = angle.tmp(i, i) file.write(str(Ang) + "\t" + str(Tperp) + "\t" + str(2 * Ei) + "\n") file.close()
def den(): '''Stores density vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_densities_%s.txt" % (r), 'a') for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) n = angle.density(i, i) file.write(str(Ang) + "\t" + str(n) + "\n") file.close()
def mag(): '''Stores magnitude of total and poloidal magnetic field vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_magnetic_field_vs.angle_%s.txt" % (r), 'a') file.write("Angle" + "\t" + "Bp" + "\t" + "B" + "\n") for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) Bp, B = angle.magnetic_field(i, i) file.write(str(Ang) + "\t" + str(Bp) + "\t" + str(B) + "\n") file.close()
def dn(): angle.angle_mesh() for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) dn = angle.density_perturbation(i, i) for t in range(2): for p in range(core.Nplanes): file = open("ti255_dn_%s_t_%s_pl_%s.txt" % (r, t, p), 'a') file.write(str(Ang) + "\t" + str(dn[t, p]) + "\n") file.close()
def dPe_strength(): '''Stores strength of electron pressure perturbation vs. poloidal angle.''' angle.angle_mesh() file = open("ti255_Pe_perturbation_strength_vs.angle_%s.txt" % (r), 'a') #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) dPe = angle.e_pressure_perturbation_strength(i, i) file.write(str(Ang) + "\t" + str(dPe) + "\n") file.close()
def dphi_strength(): '''Stores strength of electrostatic fluctuation vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_turbulence_strength_vs.angle_%s.txt" % (r), 'a') #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) _, _, tur = angle.turbulence_strength(i, i) file.write(str(Ang) + "\t" + str(tur) + "\n") file.close()
def check(): '''Simple check to see if the values are stored correctly. Useful to see (with verbose option of angle.spline_creation set to true), if the angular grid covers faithfully the separatrix. ''' angle.angle_mesh() file = open("Check_%s.txt" % (r), 'a') for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) file.write(str(Ang) + "\t" + str(R_val) + "\t" + str(Z_val) + "\n") file.close()
def phis(): '''Stores values potential and electrostatic fluctuation vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_phis_vs.angle_%s.txt" % (r), 'a') file.write("Angle" + "\t" + "Phi" + "\t" + "dPhi" + "\n") #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) phi, dphi, _ = angle.turbulence_strength(i, i) file.write(str(Ang) + "\t" + str(phi) + "\t" + str(dphi) + "\n") file.close()
def dn_strength(): '''Stores strength of density perturbation vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_density_perturbation_strength_vs.angle_%s.txt" % (r), 'a') #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) dn = angle.density_perturbation_strength(i, i) file.write(str(Ang) + "\t" + str(dn) + "\n") file.close()
def mag_component(): '''Stores components of magnetic field vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_magnetic_field_comp_vs.angle_%s.txt" % (r), 'a') file.write("Angle" + "\t" + "Br" + "\t" + "Bz" + "\t" + "Bzeta" + "\n") for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) Br, Bz, Bzeta = angle.mag_comp(i, i) file.write( str(Ang) + "\t" + str(Br) + "\t" + str(Bz) + "\t" + str(Bzeta) + "\n") file.close()
def main_Tot(Rmin): angle.angle_mesh() file = open("ti255_Total_fluxes_vs.angle.txt", 'a') #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) Eq_Gamma_time_avg, Tur_Gamma_time_avg = angle.two_fluxes_angle( i, i, Ang, 0, Rmin, 3) file.write( str(Ang) + "\t" + str(Eq_Gamma_time_avg) + "\t" + str(Tur_Gamma_time_avg) + "\t" + str(R_val) + "\t" + str(Z_val) + "\n") file.close()
def diamagnetic_flux(): '''Stores ion diamagnetic drift fluxes vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_diamag_fluxes_vs.angle_%s.txt" % (r), 'a') file.write("Angle" + "\t" + "D.Flux" + "\t" + "R" + "\t" + "Z" + "\n") #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 2): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) dMag = angle.diamagnetic_drifts_angle(i, i) file.write( str(Ang) + "\t" + str(dMag) + "\t" + str(R_val) + "\t" + str(Z_val) + "\n") file.close()
def ion_heat_flux(): '''Stores ion exb heat fluxes vs. poloidal angle.''' angle.angle_mesh() file = open("ti255_ion_heat_%s.txt" % (r), 'a') file.write("Angle" + "\t" + "Eq.Flux" + "\t" + "Tur.Flux" + "\t" + "R" + "\t" + "Z" + "\n") for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) Eq, Tur = angle.ion_heat_flux_angle(i, i, True) file.write( str(Ang) + "\t" + str(Eq) + "\t" + str(Tur) + "\t" + str(R_val) + "\t" + str(Z_val) + "\n") print("Flux point %s done." % (i)) file.close()
def sl(): '''Stores inverse scale lengths vs. poloidal angle.''' angle.angle_mesh() file = open("ti262_Scale_lengths_%s.txt" % (r), 'a') #calls flux function on diagonal points of the mesh for i in range(2, len(angle.R_fp) - 2): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) LTe = angle.LTeinv(i, i) Ln = angle.Lninv(i, i) LTi = angle.LTiinv(i, i) file.write( str(Ang) + "\t" + str(LTe) + "\t" + str(LTi) + "\t" + str(Ln) + "\t" + str(R_val) + "\t" + str(Z_val) + "\n") file.close()
def exb_flux(): '''Stores the particle, exb, equilibrium and turbulent fluxes vs. poloidal angle.''' angle.angle_mesh() file = open("ti255_particle_fluxes_vs.angle_%s.txt" % (r), 'a') file.write("Angle" + "\t" + "Eq.Flux" + "\t" + "Tur.Flux" + "\t" + "Ring" + "\t" + "R" + "\t" + "Z" + "\n") #calls flux function on diagonal points of the mesh for i in range(1, len(angle.R_fp) - 1): R_val = angle.R_fp[i] Z_val = angle.Z_fp[i] Ang = angle.norm_atan(Z_val, R_val) Eq, Tur, Ring = angle.exb_fluxes_angle(i, i, False) file.write( str(Ang) + "\t" + str(Eq) + "\t" + str(Tur) + "\t" + str(Ring) + "\t" + str(R_val) + "\t" + str(Z_val) + "\n") file.close()
def Re_on_sep(r): #reading the matrices Rpol = np.load( "/global/homes/g/giannos/xgc_python_dir/ti255_analysis/sep_mat/Rsep_%s.npy" % (r)) Zpol = np.load( "/global/homes/g/giannos/xgc_python_dir/ti255_analysis/sep_mat/Zsep_%s.npy" % (r)) arr = np.load( "/global/homes/g/giannos/xgc_python_dir/ti255_analysis/Reynolds/Re_tur_pol_f_%s.npy" % (r)) #finding min/max of R,Z. if ((r * 20) < (len(Rsep) - 1)) and (((r + 1) * 20) < (len(Rsep) - 1)): Rmin = float(Rsep[r * 20]) #2.14# Rmax = float(Rsep[(r + 1) * 20]) #2.26# Zmin = float(Zsep[r * 20]) #-0.38# Zmax = float(Zsep[(r + 1) * 20]) #0.45# Rmin, Rmax, Zmin, Zmax = loading_checks(Rmin, Rmax, Zmin, Zmax) elif ((r * 20) < (len(Rsep) - 1)) and (((r + 1) * 20) > (len(Rsep) - 1)): Rmin = float(Rsep[r * 20]) Rmax = float(Rsep[-1]) Zmin = float(Zsep[r * 20]) Zmax = float(Zsep[-1]) else: pass unitR = (Rmax - Rmin) / 100 unitZ = (Zmax - Zmin) / 100 Zs = np.array([x for x in range(0, arr.shape[0])]) Rs = np.array([x for x in range(0, arr.shape[1])]) file = open( "/global/homes/g/giannos/xgc_python_dir/ti255_analysis/Reynolds/Re_tur_pol_files_%s.txt" % (r), 'a') #file = open("Reynolds_turpf_mid.txt",'a') #file = open("Reynolds_force_midplane.txt",'a') #file = open("pol_flow_mid.txt",'a') #file = open("Re_rad_f_mid.txt",'a') #file = open("Re_rad_f_mid.txt",'a') Septrix = list(zip(Rpol, Zpol)) Z_coord = [] Z_loc = [] R_loc = [] R_coord = [] for Z in Zpol: diff = [] for zeta in Zs: diff.append(abs(Z - (zeta * unitZ + Zmin))) #find units and min/max from parallel. tmp = np.amin(diff) Sep_loc_z = diff.index(tmp) Z_loc.append(Sep_loc_z) Z_coord.append(Zs[Sep_loc_z] * unitZ + Zmin) for R in Rpol: diff = [] for rho in Rs: diff.append(abs(R - (rho * unitR + Rmin))) Sep_loc_r = np.argmin(diff) R_loc.append(Sep_loc_r) R_coord.append(Rs[Sep_loc_r] * unitR + Rmin - core.Rmaj) #plt.plot(R_coord,Z_coord,'r--',Rpol,Zpol,'b*') #plt.show() #file.write("R"+"\t"+"Z"+"\t"+"Shear"+"\n") #file.write("R"+"\t"+"Z"+"\t"+"Re_S"+"\n") file.write("angle" + "\t" + "R" + "\t" + "Z" + "\t" + "Re_rad" + "\n") coordinates = list(zip(R_coord, Z_coord)) ANG = [] for i in range(0, len(coordinates)): angie = angle.norm_atan(Z_coord[i], R_coord[i]) ANG.append(angie) for i in range(0, len(coordinates)): if arr[Z_loc[i], R_loc[i]] > 0: file.write( str(ANG[i]) + "\t" + str(coordinates[i][0]) + "\t" + str(coordinates[i][1]) + "\t" + str(arr[Z_loc[i], R_loc[i]]) + "\n") else: pass file.close()
def sh_on_sep(r): '''For a particular process number, reads in the matrices of R,Z separatrix points, the respective shear matrix and writes out a file that contains the R,Z,shear information.''' #reading the matrices Rpol = np.load("Rsep_%s.npy" % (r)) Zpol = np.load("Zsep_%s.npy" % (r)) arr = np.load("shear_%s.npy" % (r)) #finding min/max of R,Z. if ((r * 20) < (len(Rsep) - 1)) and (((r + 1) * 20) < (len(Rsep) - 1)): Rmin = float(Rsep[r * 20]) #2.14# Rmax = float(Rsep[(r + 1) * 20]) #2.26# Zmin = float(Zsep[r * 20]) #-0.38# Zmax = float(Zsep[(r + 1) * 20]) #0.45# Rmin, Rmax, Zmin, Zmax = loading_checks(Rmin, Rmax, Zmin, Zmax) elif ((r * 20) < (len(Rsep) - 1)) and (((r + 1) * 20) > (len(Rsep) - 1)): Rmin = float(Rsep[r * 20]) Rmax = float(Rsep[-1]) Zmin = float(Zsep[r * 20]) Zmax = float(Zsep[-1]) else: pass unitR = (Rmax - Rmin) / 100 unitZ = (Zmax - Zmin) / 100 Zs = np.array([x for x in range(0, arr.shape[0])]) Rs = np.array([x for x in range(0, arr.shape[1])]) file = open("shear_files_%s.txt" % (r), 'a') #file = open("Reynolds_turpf_mid.txt",'a') #file = open("Reynolds_force_midplane.txt",'a') #file = open("pol_flow_mid.txt",'a') #file = open("Re_rad_f_mid.txt",'a') #file = open("Re_rad_f_mid.txt",'a') Septrix = list(zip(Rpol, Zpol)) Z_coord = [] Z_loc = [] R_loc = [] R_coord = [] for Z in Zpol: diff = [] for zeta in Zs: diff.append(abs(Z - (zeta * unitZ + Zmin))) #find units and min/max from parallel. tmp = np.amin(diff) Sep_loc_z = diff.index(tmp) Z_loc.append(Sep_loc_z) Z_coord.append(Zs[Sep_loc_z] * unitZ + Zmin) for R in Rpol: diff = [] for rho in Rs: diff.append(abs(R - (rho * unitR + Rmin))) Sep_loc_r = np.argmin(diff) R_loc.append(Sep_loc_r) R_coord.append(Rs[Sep_loc_r] * unitR + Rmin - core.Rmaj) #plt.plot(R_coord,Z_coord,'r--',Rpol,Zpol,'b*') #plt.show() #file.write("R"+"\t"+"Z"+"\t"+"Shear"+"\n") #file.write("R"+"\t"+"Z"+"\t"+"Re_S"+"\n") file.write("angle" + "\t" + "R" + "\t" + "Z" + "\t" + "shear" + "\n") coordinates = list(zip(R_coord, Z_coord)) ANG = [] for i in range(0, len(coordinates)): angie = angle.norm_atan(Z_coord[i], R_coord[i]) ANG.append(angie) for i in range(0, len(coordinates)): if arr[Z_loc[i], R_loc[i]] > 0: file.write( str(ANG[i]) + "\t" + str(coordinates[i][0]) + "\t" + str(coordinates[i][1]) + "\t" + str(arr[Z_loc[i], R_loc[i]]) + "\n") else: pass file.close()