Version 2, position dependent E/B, kinetic ions, boris mover, terminator

This commit is contained in:
Jonas Kellerer
2022-10-21 10:09:19 +02:00
parent acc55cf003
commit 83fd2e5d7e
869 changed files with 1033204 additions and 3634436 deletions
+302
View File
@@ -0,0 +1,302 @@
#from asyncio import open_unix_connection
import numpy as np
import h5py as h5py
import os
import sys
import matplotlib
import matplotlib.pyplot as plt
import plot_standards as pst
def getSpecies(filename):
file = h5py.File(filename, 'r')
return list(file.keys())
def outputPeriodKey(output_period):
if (output_period == "LastSyncPeriod"):
return "/LastSyncPeriod"
else:
return "/" + output_period
def mass(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_mass = path_to_species + "/Mass"
return np.array(file[path_to_mass])[0]
def charge(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_charge = path_to_species + "/Charge"
return np.array(file[path_to_charge])[0]
def zBinsDensityField(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_border = path_to_species + "/DensityField/BinBorders/longitudinal"
return np.array(file[path_to_border])
def energyBinsDensityfield(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_border = path_to_species + "/DensityField/BinBorders/energy"
return np.array(file[path_to_border])
def binVolumes(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_volumes = path_to_species + "/DensityField/BinVolumes"
return np.array(file[path_to_volumes])
def deletionsMaxInteractions(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path = path_to_species + "/DeletionLogger" + \
outputPeriodKey(output_period) + "/NumDeletions/MaxInteractions"
return np.array(file[path])[0]
def deletionsMaxTimeAlive(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path = path_to_species + "/DeletionLogger" + \
outputPeriodKey(output_period) + "/NumDeletions/MaxTimeAlive"
return np.array(file[path])[0]
def deletionsRecombination(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path = path_to_species + "/DeletionLogger" + \
outputPeriodKey(output_period) + "/NumDeletions/Recombination"
return np.array(file[path])[0]
def deletionsWall(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path = path_to_species + "/DeletionLogger" + \
outputPeriodKey(output_period) + "/NumDeletions/Wall"
return np.array(file[path])[0]
def timeInBin(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_time = path_to_species + "/DensityField/SimulationData" + \
outputPeriodKey(output_period) + "/TimeInBin"
return np.array(file[path_to_time])
def physicalTime(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_time = path_to_species + "/DensityField/SimulationData" + \
outputPeriodKey(output_period) + "/PhysicalTime"
return np.array(file[path_to_time])[0]
def spectrum(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_spectrum = path_to_species + "/DensityField/SimulationData" + \
outputPeriodKey(output_period) + "/Spectrum"
return np.array(file[path_to_spectrum])
def density(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_density = path_to_species + "/DensityField/SimulationData" + \
outputPeriodKey(output_period) + "/Density"
return np.array(file[path_to_density])
def longitudinalCurrent(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
outputPeriodKey(output_period) + "/CurrentInZ"
return np.array(file[path_to_current])
def longitudinalNegativeCrossings(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
outputPeriodKey(output_period) + "/NegativeCrossingsInZ"
return np.array(file[path_to_current])
def longitudinalPositiveCrossings(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
outputPeriodKey(output_period) + "/PositiveCrossingsInZ"
return np.array(file[path_to_current])
def radialCurrent(filename, path_to_species, output_period):
file = h5py.File(filename, 'r')
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
outputPeriodKey(output_period) + "/CurrentInR"
return np.array(file[path_to_current])
def longitudinalAreas(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_areas = path_to_species + "/CurrentCollector/AreaInZ"
return np.array(file[path_to_areas])
def radialAreas(filename, path_to_species):
file = h5py.File(filename, 'r')
path_to_areas = path_to_species + "/CurrentCollector/AreaInR"
return np.array(file[path_to_areas])
def longitudinalCurrentVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
areas_in_z = longitudinalAreas(filename, path_to_species)
current_in_z = longitudinalCurrent(
filename, path_to_species, output_period)
particles = current_in_z * areas_in_z
return np.sum(particles, axis=(0, 1)) / np.sum(areas_in_z, axis=(0, 1))
def longitudinalNegativeCrossingsVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
areas_in_z = longitudinalAreas(filename, path_to_species)
current_in_z = longitudinalCurrent(
filename, path_to_species, output_period)
particles = current_in_z * areas_in_z
return np.sum(particles, axis=(0, 1)) / np.sum(areas_in_z, axis=(0, 1))
def tubeCurrentVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
areas_in_r = radialAreas(filename, path_to_species)
current_in_r = radialCurrent(filename, path_to_species, output_period)
particles = current_in_r * areas_in_r
return (np.sum(particles, axis=(1)) / np.sum(areas_in_r, axis=(1)))[-2, :]
def densityVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
bin_volumes = binVolumes(filename, path_to_species)
densities = density(filename, path_to_species, output_period)
particles = densities*bin_volumes
return np.sum(particles, axis=(0, 1)) / np.sum(bin_volumes, axis=(0, 1))
def findClosestIndex(position, bin_borders):
return (np.abs(bin_borders - position)).argmin()
def spectrumAtZ(filename, path_to_species, z_position, output_period="LastSyncPeriod"):
bin_volumes = binVolumes(filename, path_to_species)
spectrums = spectrum(filename, path_to_species, output_period)
particles = spectrums
for i in np.arange(0, particles.shape[3]):
particles[:, :, :, i] = spectrums[:, :, :, i]*bin_volumes
z_index = findClosestIndex(
z_position, zBinsDensityField(filename, path_to_species))
volume = np.sum(bin_volumes, axis=(0, 1))[z_index]
return np.sum(particles, axis=(0, 1))[z_index, :]/volume
def makeBarPlotData(data, mins, maxs):
plot_bins = np.dstack((mins, maxs)).flatten()
plot_datas = np.dstack((data, data)).flatten()
return plot_bins, plot_datas
def plotSpectrumAtZ(filename, path_to_species, z_position, plot_axis, output_period="LastSyncPeriod"):
spectrum_at_z = spectrumAtZ(
filename, path_to_species, z_position, output_period)
E_bins = energyBinsDensityfield(filename, path_to_species)
plot_bins, plot_datas = makeBarPlotData(
spectrum_at_z[1:-1], E_bins[0:-1], E_bins[1:])
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
plot_axis.set_xscale("log")
plot_axis.set_yscale("log")
plot_axis.set_xlabel(r"Energy $E$ (eV)")
plot_axis.set_ylabel(
r"Diff. Density $\frac{\mathrm{d}n_e}{\mathrm{d}\log_{10}E}$ $\left(\frac{1}{\mathrm{m}^{3} \log_{10}(\mathrm{eV})}\right)$")
def plotAllSpectrumAtZ(filename, z_position, output_period, specie_keys, output_folder):
pst.setRcParams()
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
for key in specie_keys:
plotSpectrumAtZ(filename, key, z_position, ax, output_period)
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
ax.legend()
fig.savefig(output_folder +
"/spectrum_at_z={}_at_period={}.pdf".format(z_position, output_period))
def plotDensityVsZ(filename, path_to_species, plot_axis, output_period="LastSyncPeriod"):
density = densityVsZ(filename, path_to_species, output_period)
z_bins = zBinsDensityField(filename, path_to_species)
plot_bins, plot_datas = makeBarPlotData(
density[1:-1], z_bins[0:-1], z_bins[1:])
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
plot_axis.set_yscale("log")
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
plot_axis.set_ylabel(r"Density $n$ ($m^{-3}$)")
def plotAllDensityVsZ(filename, output_period, specie_keys, output_folder):
pst.setRcParams()
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
for key in specie_keys:
plotDensityVsZ(filename, key, ax, output_period)
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
ax.legend()
fig.savefig(output_folder + "/density_vs_z_at_period={}.pdf".format(output_period),
format='pdf', bbox_inches='tight')
def plotLongitudinalParticleCurrentVsZ(filename, path_to_species, plot_axis, output_period="LastSyncPeriod"):
current_in_z = longitudinalCurrentVsZ(
filename, path_to_species, output_period)
z_bins = zBinsDensityField(filename, path_to_species)
plot_axis.plot(z_bins, current_in_z, label=str(path_to_species))
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
plot_axis.set_ylabel(r"Particle current $j$ ($m^{-3}s^{-1}$)")
def plotAllLongitudinalParticleCurrentVsZ(filename, output_period, specie_keys, output_folder):
pst.setRcParams()
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
for key in specie_keys:
plotLongitudinalParticleCurrentVsZ(filename, key, ax, output_period)
ax.set_facecolor('#e7e7e7ff')
ax.grid(color='white')
ax.legend()
fig.savefig(output_folder + "/longitudinal_particle_current_vs_z_at_period={}.pdf".format(output_period),
format='pdf', bbox_inches='tight')
def plotLongitudinalElectricCurrentVsZ(filename, path_to_species, plot_axis, output_period="LastSyncPeriod"):
current_in_z = longitudinalCurrentVsZ(
filename, path_to_species, output_period)*charge(filename, path_to_species)
z_bins = zBinsDensityField(filename, path_to_species)
plot_axis.plot(z_bins, current_in_z)
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
plot_axis.set_ylabel(r"Electric current $I$ ($A$)")
def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncPeriod"):
max_interactions = deletionsMaxInteractions(
filename, path_to_species, output_period)
max_time_alive = deletionsMaxTimeAlive(
filename, path_to_species, output_period)
recombinations = deletionsRecombination(
filename, path_to_species, output_period)
wall = deletionsWall(filename, path_to_species, output_period)
print("Deletion Logger stats for: " + str(path_to_species))
print("MaxTimeAlive: {}".format(max_time_alive))
print("MaxInteractions: {}".format(max_interactions))
print("Recombinations: {}".format(recombinations))
print("Wall hits: {}".format(wall))
def printAllDeletionLoggerStats(filename, specie_keys, output_period):
for key in specie_keys:
printDeletionLoggerStats(filename, key, output_period)
+89
View File
@@ -0,0 +1,89 @@
import matplotlib
import matplotlib.colors as clr
import matplotlib.pyplot as plt
from cycler import cycler
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
def set_size(width, fraction=1, subplots=(1, 1)):
"""Set figure dimensions to avoid scaling in LaTeX.
Parameters
----------
width: float or string
Document width in points, or string of predined document type
fraction: float, optional
Fraction of the width which you wish the figure to occupy
subplots: array-like, optional
The number of rows and columns of subplots.
Returns
-------
fig_dim: tuple
Dimensions of figure in inches
"""
if width == 'thesis':
width_pt = 426.79135
elif width == 'beamer':
width_pt = 307.28987
else:
width_pt = width
# Width of figure (in pts)
fig_width_pt = width_pt * fraction
# Convert from pt to inches
inches_per_pt = 1 / 72.27
# Golden ratio to set aesthetic figure height
# https://disq.us/p/2940ij3
golden_ratio = (5**.5 - 1) / 2
# Figure width in inches
fig_width_in = fig_width_pt * inches_per_pt
# Figure height in inches
fig_height_in = fig_width_in * golden_ratio * (subplots[0] / subplots[1])
return (fig_width_in, fig_height_in)
def setRcParams():
#matplotlib.rcParams['text.usetex'] = True
#matplotlib.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
#matplotlib.rcParams['pcolor.shading'] = 'auto'
matplotlib.rcParams['font.family'] = "serif"
matplotlib.rcParams['font.size'] = 10
matplotlib.rcParams['axes.labelsize'] = 10
matplotlib.rcParams['legend.fontsize'] = 8
matplotlib.rcParams['xtick.labelsize'] = 8
matplotlib.rcParams['ytick.labelsize'] = 8
matplotlib.rcParams['figure.autolayout'] = True
matplotlib.rcParams['figure.titlesize'] = 4
matplotlib.rcParams['axes.titlesize'] = 4
matplotlib.rcParams['lines.markersize'] = 4
# matplotlib.rcParams['axes.facecolor'] = '#e7e7e7ff'
#matplotlib.rcParams['axes.grid'] = True
#matplotlib.rcParams['grid.color'] = 'white'
#matplotlib.rcParams['figure.dpi'] = 240
# lines for colorblind
colour_blind_cycle = ['#377eb8', '#ff7f00', '#4daf4a',
'#f781bf', '#a65628', '#984ea3',
'#999999', '#e41a1c', '#dede00']
matplotlib.rcParams['axes.prop_cycle'] = cycler(color=colour_blind_cycle)
# colorblind cmap
colorblind_diverging = ['#ca0020', '#f4a582',
'#f7f7f7', '#92c5de', '#0571b0']
Cmap_Name = "mymap"
try:
mymap = plt.get_cmap(name=Cmap_Name)
except:
mymap = LinearSegmentedColormap.from_list(
Cmap_Name, colorblind_diverging)
plt.register_cmap(name=Cmap_Name, cmap=mymap)
matplotlib.rcParams['image.cmap'] = Cmap_Name