normalization, elastic center move, density calc.

This commit is contained in:
Jonas Kellerer
2021-04-22 10:59:48 +02:00
parent bb8fa25117
commit 64437af0ad
17 changed files with 299 additions and 169 deletions
@@ -12,39 +12,44 @@ def plotTubeCurrentVsZ(filename_current, filename_density, output_folder):
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e"}
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T3+"}
dicts = [e_dict, T3_dict]
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e$^-$", "charge": -1.602E-19}
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T$_3^+$", "charge": 1.602E-19}
T2_dict = {"key" : "/T2+", "linestyle": '--', "label": "T$_2^+$", "charge": 1.602E-19}
T_dict = {"key" : "/T+", "linestyle": '--', "label": "T$^+$", "charge": 1.602E-19}
dicts = [e_dict, T3_dict, T2_dict, T_dict]
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
for d in dicts:
j_total = cc.particleCurrentR(filename_current, filename_density, d["key"])
j_total = cc.absoluteCurrentR(filename_current, filename_density, d["key"])
z_bins = cc.binBordersZ(filename_current, d["key"])
plot_data = np.sum(j_total,2)[-1,:]
plot_data = np.sum(j_total,2)[-1,:] * np.abs(d["charge"])
x_mins = z_bins[:-1]
x_maxs = z_bins[1:]
plot_bins, plot_datas = cc.makeBarPlotData(plot_data, x_mins, x_maxs)
ax.plot(plot_bins, plot_datas, linestyle=d["linestyle"], label=d["label"])
ax.plot(plot_bins - plot_bins[0], plot_datas, linestyle=d["linestyle"], label=d["label"])
ax.set_xlabel(r"Position $z$ [m]")
ax.set_ylabel(r"Particle Current $j_r$ [$m^{-2}s^{-1}$]")
ax.set_xlabel(r"Distance to rear wall $z$ [m]")
ax.set_ylabel(r"Current $I_r$ [A]")
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
ax.set_yscale("log")
ax.legend(loc="upper right")
ax.legend(loc="lower right")
filename_output = output_folder + 'tube_current_vs_z.pdf'
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
def plotLongitudinalCurrentVsZ(filename_current, filename_density, output_folder):
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e"}
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T3+"}
dicts = [e_dict, T3_dict]
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e$^-$", "charge": -1.602E-19}
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T$_3^+$", "charge": 1.602E-19}
T2_dict = {"key" : "/T2+", "linestyle": '--', "label": "T$_2^+$", "charge": 1.602E-19}
T_dict = {"key" : "/T+", "linestyle": '--', "label": "T$^+$", "charge": 1.602E-19}
dicts = [e_dict, T3_dict, T2_dict, T_dict]
pst.setRcParams()
prop_cycle = plt.rcParams['axes.prop_cycle']
@@ -53,19 +58,19 @@ def plotLongitudinalCurrentVsZ(filename_current, filename_density, output_folder
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
for d in dicts:
j_total = cc.particleCurrentZ(filename_current, filename_density, d["key"])
j_total = cc.absoluteCurrentZ(filename_current, filename_density, d["key"])
z_bins = cc.binBordersZ(filename_current, d["key"])
plot_data = np.sum(np.sum(j_total,2),0)
ax.plot(z_bins, plot_data, linestyle=d["linestyle"], label=d["label"])
plot_data = np.sum(np.sum(j_total,2),0) * d["charge"]
ax.plot(z_bins- z_bins[0], plot_data, linestyle=d["linestyle"], label=d["label"])
ax.set_xlabel(r"Position $z$ [m]")
ax.set_ylabel(r"Particle Current $j_z$ [$m^{-2}s^{-1}$]")
ax.set_xlabel(r"Distance to rear wall $z$ [m]")
ax.set_ylabel(r"Current $I_z$ [A]")
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
ax.legend(loc="lower right")
filename_output = output_folder + 'jz_vs_z.pdf'
filename_output = output_folder + 'Iz_vs_z.pdf'
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
@@ -16,41 +16,20 @@ def makeBarPlotData(data, mins, maxs):
def plotAllDensityVsZ(filename, filename_output):
keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"]
print("Get Density: e-")
density_e = getDensities(filename, keys[0])
print("Get Density: T+")
density_T = getDensities(filename, keys[1])
print("Get Density: T2+")
density_T2 = getDensities(filename, keys[2])
print("Get Density: T3+")
density_T3 = getDensities(filename, keys[3])
zmins = getZBinsMin(filename, keys[0])
zmaxs = getZBinsMax(filename, keys[0])
Emins = getEBinsMin(filename, keys[0])
Emaxs = getEBinsMax(filename, keys[0])
total_density_e = np.sum(density_e,3)
total_density_e = np.sum(total_density_e,2)
total_density_e = np.sum(total_density_e,1)
print("Get Density: e-")
total_density_e = longitudinalDensity(filename, keys[0])
print("Get Density: T+")
total_density_T = longitudinalDensity(filename, keys[1])
print("Get Density: T2+")
total_density_T2 = longitudinalDensity(filename, keys[2])
print("Get Density: T3+")
total_density_T3 = longitudinalDensity(filename, keys[3])
print("Total density e-: ")
print(total_density_e)
total_density_T = np.sum(density_T,3)
total_density_T = np.sum(total_density_T,2)
total_density_T = np.sum(total_density_T,1)
total_density_T2 = np.sum(density_T2,3)
total_density_T2 = np.sum(total_density_T2,2)
total_density_T2 = np.sum(total_density_T2,1)
total_density_T3 = np.sum(density_T3,3)
total_density_T3 = np.sum(total_density_T3,2)
total_density_T3 = np.sum(total_density_T3,1)
print("Total density T3+: ")
print(total_density_T3)
pst.setRcParams()
prop_cycle = plt.rcParams['axes.prop_cycle']
@@ -59,24 +38,26 @@ def plotAllDensityVsZ(filename, filename_output):
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
plot_bins, plot_data = makeBarPlotData(total_density_e, zmins, zmaxs)
ax.plot(plot_bins, plot_data,'-', label="e-")
ax.plot(plot_bins - plot_bins[0], plot_data/1E6,'-', label="e-")
plot_bins, plot_data = makeBarPlotData(total_density_T3, zmins, zmaxs)
ax.plot(plot_bins, plot_data, '--', label=r'T$^+_3$')
ax.plot(plot_bins - plot_bins[0], plot_data/1E6, '--', label=r'T$^+_3$')
plot_bins, plot_data = makeBarPlotData(total_density_T, zmins, zmaxs)
ax.plot(plot_bins, plot_data, '-.', label=r'T$^+_2$')
ax.plot(plot_bins - plot_bins[0], plot_data/1E6, '-.', label=r'T$^+_2$')
plot_bins, plot_data = makeBarPlotData(total_density_T2, zmins, zmaxs)
ax.plot(plot_bins, plot_data, ':', label=r'T$^+$')
ax.plot(plot_bins - plot_bins[0], plot_data/1E6, ':', label=r'T$^+$')
ax.set_yscale("log")
ax.set_xlabel(r"Position $z$ [m]")
ax.set_ylabel(r"Density $n$ [$m^{-3}$]")
ax.set_xlabel(r"Distance to rear wall $z$ [m]")
ax.set_ylabel(r"Density $n$ [$cm^{-3}$]")
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
ax.legend(loc="lower right")
ax.legend(loc=(0.85, 0.15))
#ax.legend(loc="lower right")
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
plt.show()
@@ -62,4 +62,5 @@ def plotElectronDensityVsE(filename, z_rearwall, z_mid, z_dps, filename_output):
ax.legend()
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
plt.show()
@@ -18,38 +18,38 @@ def plotElectronDensityVsZ(filename, E_th_max, E_beta_min, filename_output):
keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"]
k = keys[0]
density = getDensities(filename, k)
particles = getParticlesPerBin(filename, k)
volumes = getVolumes(filename, k)
zmins = getZBinsMin(filename, k)
zmaxs = getZBinsMax(filename, k)
Emins = getEBinsMin(filename, k)
Emaxs = getEBinsMax(filename, k)
volumes_longitudinal = np.sum(volumes, axis=(1,2))
print("thermal density: ")
thermal_energy = E_th_max
thermal_energy_index = np.where(Emins <= thermal_energy)[-1][-1]
thermal_density = np.sum(density[:,:,:,0:thermal_energy_index],3)
thermal_density = np.sum(thermal_density,2)
thermal_density = np.sum(thermal_density,1)
print("thermal density: ")
print(thermal_density)
beta_energy = E_beta_min
beta_energy_index = np.where(Emins >= beta_energy)[-1][-1]
beta_density = np.sum(density[:,:,:,beta_energy_index:],3)
beta_density = np.sum(beta_density, 2)
beta_density = np.sum(beta_density, 1)
thermal_particles = particles[:,:,:,0:thermal_energy_index]
thermal_particles_longitudinal = np.sum(thermal_particles, axis=(1,2,3))
n_thermal = thermal_particles_longitudinal / volumes_longitudinal
print("beta density: ")
print(beta_density)
beta_energy = E_beta_min
beta_energy_index = np.where(Emins >= beta_energy)[-1][-1]
beta_particles = particles[:,:,:,beta_energy_index:]
beta_particles_longitudinal = np.sum(beta_particles, axis=(1,2,3))
n_beta = beta_particles_longitudinal / volumes_longitudinal
secondary_density = np.sum(density[:,:,:,thermal_energy_index+1:beta_energy_index-1],3)
secondary_density = np.sum(secondary_density, 2)
secondary_density = np.sum(secondary_density, 1)
total_density = np.sum(density,3)
total_density = np.sum(total_density,2)
total_density = np.sum(total_density, 1)
secondary_particles = particles[:,:,:,thermal_energy_index+1:beta_energy_index-1]
secondary_particles_longitudinal = np.sum(secondary_particles, axis=(1,2,3))
n_secondary = secondary_particles_longitudinal / volumes_longitudinal
n_total = n_thermal + n_beta + n_secondary
pst.setRcParams()
prop_cycle = plt.rcParams['axes.prop_cycle']
@@ -61,18 +61,21 @@ def plotElectronDensityVsZ(filename, E_th_max, E_beta_min, filename_output):
#plot_bins, plot_data = makeBarPlotData(total_density, zmins, zmaxs)
#plt.plot(plot_bins, plot_data)
plot_bins, plot_data = makeBarPlotData(thermal_density, zmins, zmaxs)
ax.plot(plot_bins, plot_data,'-', label="thermal")
plot_bins, plot_data = makeBarPlotData(n_thermal, zmins, zmaxs)
ax.plot(plot_bins - plot_bins[0], plot_data/1E6,'-', label="thermal")
plot_bins, plot_data = makeBarPlotData(beta_density, zmins, zmaxs)
ax.plot(plot_bins, plot_data, '--', label="beta")
plot_bins, plot_data = makeBarPlotData(n_beta, zmins, zmaxs)
ax.plot(plot_bins - plot_bins[0], plot_data/1E6, '--', label="beta")
plot_bins, plot_data = makeBarPlotData(secondary_density, zmins, zmaxs)
ax.plot(plot_bins, plot_data, '-.', label="secondary")
plot_bins, plot_data = makeBarPlotData(n_secondary, zmins, zmaxs)
ax.plot(plot_bins - plot_bins[0], plot_data/1E6, '-.', label="secondary")
ax.set_ylim((5E-3, 1E6))
ax.set_yscale("log")
ax.set_xlabel(r"Position $z$ [m]")
ax.set_ylabel(r"Density $n_e$ [$m^{-3}$]")
ax.set_xlabel(r"Distance to rear wall $z$ [m]")
ax.set_ylabel(r"Density $n_e$ [$cm^{-3}$]")
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
@@ -95,15 +95,18 @@ def particleCurrentR(filename_current, filename_densities, key):
bin_borders_r = binBordersR(filename_current, key)
bin_borders_z = binBordersZ(filename_current, key)
bin_areas_r = binAreasR(bin_borders_r, bin_borders_z)
for iz in np.arange(0, particle_current.shape[2], 1):
particle_current[:,:,iz] = particle_current[:,:,iz]/bin_areas_r
for ir in np.arange(0, particle_current.shape[0],1):
for iz in np.arange(0, particle_current.shape[1],1):
for iE in np.arange(0, particle_current.shape[2], 1):
particle_current[ir,iz,iE] = particle_current[ir,iz,iE]/bin_areas_r[ir, iz]
return particle_current
def particleCurrentZ(filename_current, filename_densities, key):
n_pos = NPosZ(filename_current, key)
n_neg = NNegZ(filename_current, key)
n_total = totalCurrentZ(n_pos, n_neg)[1:, :, :]
n_total = totalCurrentZ(n_pos, n_neg)[:-1, :, :]
delta_t = lastOutputTime(filename_densities)
particle_current = n_total/delta_t
@@ -111,11 +114,57 @@ def particleCurrentZ(filename_current, filename_densities, key):
bin_borders_r = binBordersR(filename_current, key)
bin_borders_z = binBordersZ(filename_current, key)
bin_areas_z = binAreasZ(bin_borders_r, bin_borders_z)
for iz in np.arange(0, particle_current.shape[2], 1):
particle_current[:,:,iz] = particle_current[:,:,iz]/bin_areas_z
for ir in np.arange(0, particle_current.shape[0],1):
for iz in np.arange(0, particle_current.shape[1],1):
for iE in np.arange(0, particle_current.shape[2], 1):
particle_current[ir,iz,iE] = particle_current[ir,iz,iE]/bin_areas_z[ir, iz]
return particle_current
def absoluteCurrentZ(filename_current, filename_densities, key):
n_pos = NPosZ(filename_current, key)
n_neg = NNegZ(filename_current, key)
n_total = totalCurrentZ(n_pos, n_neg)[:-1, :, :]
delta_t = lastOutputTime(filename_densities)
particle_current = n_total/delta_t
return particle_current
def absoluteCurrentR(filename_current, filename_densities, key):
n_pos = NPosR(filename_current, key)
n_neg = NNegR(filename_current, key)
n_total = totalCurrentR(n_pos, n_neg)[:,:-1,:]
delta_t = lastOutputTime(filename_densities)
particle_current = n_total/delta_t
return particle_current
def totalCurrentRearwall(filename_current, filename_densities, key):
n_pos = NPosZ(filename_current, key)
n_neg = NNegZ(filename_current, key)
n_total = totalCurrentZ(n_pos, n_neg)[:-1, :, :]
delta_t = lastOutputTime(filename_densities)
R = 0.045
A_rw = R**2 * np.pi
I_rw = np.sum(np.sum(n_total[:,0, :],1),0) /delta_t * 1.602E-19
return I_rw
def totalCurrentTube(filename_current, filename_densities, key):
n_pos = NPosR(filename_current, key)
n_neg = NNegR(filename_current, key)
n_total = totalCurrentR(n_pos, n_neg)[:,1:,:]
delta_t = lastOutputTime(filename_densities)
R = 0.045
H = 13
I_tube = np.sum(np.sum(n_total[4,:,:],1),0) / delta_t * 1.602E-19
return I_tube
def makeBarPlotData(data, mins, maxs):
plot_bins = np.dstack((mins,maxs)).flatten()
plot_datas = np.dstack((data,data)).flatten()
@@ -51,7 +51,7 @@ def getOffset(filename, key):
return offsets
def getDensities(filename, key):
def getParticlesPerBin(filename, key):
f = h5py.File(filename, 'r')
data = np.array([f[key]])
f.close()
@@ -60,6 +60,40 @@ def getDensities(filename, key):
last_output_time = np.unique(data[:,0])[-1]
data_last = data[data[:,0] == last_output_time]
print("Get Cum times")
cum_times = getCumTimes(filename, key)
print("Get Offsets")
offsets = getOffset(filename, key)
particles = cum_times/last_output_time - offsets
return particles
def getDensities(filename, key):
particles = getParticlesPerBin(filename, key)
volumes = getVolumes(filename, key)
[zbins, rbins, phi_bins, E_bins] = getNumBins(filename, key)
density = np.empty_like(particles)
for iE in np.arange(0,E_bins,1):
density[:,:,:,iE] = particles/volumes
return density
def longitudinalDensity(filename, key):
particles = getParticlesPerBin(filename, key)
volumes = getVolumes(filename, key)
particles_longitudinal = np.sum(particles, axis=(1,2,3))
volumes_longitudinal = np.sum(volumes, axis=(1,2))
density = particles_longitudinal / volumes_longitudinal
return density
def getVolumes(filename, key):
[zbins, rbins, phi_bins, E_bins] = getNumBins(filename, key)
zbins_min = getZBinsMin(filename, key)
zbins_max = getZBinsMax(filename, key)
@@ -68,31 +102,19 @@ def getDensities(filename, key):
phibins_min = getPhiBinsMin(filename, key)
phibins_max = getPhiBinsMax(filename, key)
print("Get Cum times")
cum_times = getCumTimes(filename, key)
print("Get Offsets")
offsets = getOffset(filename, key)
volumes = np.empty((zbins, rbins, phi_bins))
densities = np.zeros((zbins, rbins, phi_bins, E_bins))
print("Calculate densities")
for iz in np.arange(0,zbins,1):
print("iz: " + str(iz))
for ir in np.arange(0,rbins,1):
for iphi in np.arange(0,phi_bins,1):
for iE in np.arange(0,E_bins,1):
z_bin_min = zbins_min[iz]
z_bin_max = zbins_max[iz]
r_bin_min = rbins_min[ir]
r_bin_max = rbins_max[ir]
phi_bin_min = phibins_min[iphi]
phi_bin_max = phibins_max[iphi]
volume = getVolume(z_bin_min, z_bin_max, r_bin_min, r_bin_max, phi_bin_min, phi_bin_max)
densities[iz,ir,iphi,iE] = cum_times[iz, ir, iphi, iE]/(last_output_time*volume) - offsets[iz, ir, iphi, iE]/volume
return densities
z_bin_min = zbins_min[iz]
z_bin_max = zbins_max[iz]
r_bin_min = rbins_min[ir]
r_bin_max = rbins_max[ir]
phi_bin_min = phibins_min[iphi]
phi_bin_max = phibins_max[iphi]
volumes[iz, ir, iphi] = getVolume(z_bin_min, z_bin_max, r_bin_min, r_bin_max, phi_bin_min, phi_bin_max)
return volumes
def getZBinsMin(filename, key):
meta_key = key + "_meta_data"