def __init__(self, hdf5_file, iPlot=1): ''' Constructor ''' self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) if iPlot > 0 and iPlot < self.grid.nt: self.iPlot = iPlot else: self.iPlot = self.grid.nt self.potential = Potential(self.grid, self.hdf5) self.hamiltonian = Hamiltonian(self.grid, hdf5=self.hdf5) self.distribution = DistributionFunction(self.grid, hdf5=self.hdf5) self.potential.read_from_hdf5(iPlot) self.distribution.read_from_hdf5(iPlot) self.hamiltonian.read_from_hdf5(iPlot) self.plot = PlotBGK(self.grid, self.distribution, self.hamiltonian, self.potential, iTime=iPlot, write=True)
class timetraces(object): ''' Plots timetraces of the errors of the total particle number, momentum, energy, entropy, the L1, L2, L3, L4, L6, L8 norms as well as the distribution function at the final timestep. The script is invoked with ``python diag_timetraces.py -f <findex> -l <lindex> -v <vmax> -i <hdf5_file>`` -f <findex> is the index of the first timestep to plot (*default*: 0) -l <lindex> is the index of the last timestep to plot (*default*: nt) -v <vmax> limits the v range to plot in the contour plot of the distribution function -i <hdf5_file> specifies the data file to read ''' def __init__(self, hdf5_file, first=-1, last=-1, vMax=0.): ''' Constructor ''' self.first = first self.last = last self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) self.potential = Potential(self.grid, self.hdf5) self.hamiltonian = Hamiltonian(self.grid, hdf5=self.hdf5) self.distribution = DistributionFunction(self.grid, hdf5=self.hdf5) self.potential.read_from_hdf5(0) self.distribution.read_from_hdf5(0) self.hamiltonian.read_from_hdf5(0) self.plot = PlotTimetraces(self.grid, self.distribution, self.hamiltonian, self.potential, first, last, vMax) def __del__(self): if self.hdf5 != None: self.hdf5.close() def run(self, ptime): if ptime != 0: for itime in range(1, self.last + 1): print("it = %5i" % (itime)) self.potential.read_from_hdf5(itime) self.distribution.read_from_hdf5(itime) self.hamiltonian.read_from_hdf5(itime) self.plot.add_timepoint() if itime == ptime: self.plot.update() break self.plot.save_plots() self.plot.update(final=True)
def __init__(self, hdf5_file, nPlot=1, iStart=0): ''' Constructor ''' self.iStart = iStart self.nPlot = nPlot self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) self.potential = Potential(self.grid, self.hdf5) self.hamiltonian = Hamiltonian(self.grid, hdf5=self.hdf5) self.distribution = DistributionFunction(self.grid, hdf5=self.hdf5) self.potential.read_from_hdf5(iStart) self.distribution.read_from_hdf5(iStart) self.hamiltonian.read_from_hdf5(iStart) self.plot = PlotNoether(self.grid, self.distribution, self.hamiltonian, self.potential, self.grid.nt, iStart, nPlot)
def __init__(self, hdf5_file, first=-1, last=-1, vMax=0.): ''' Constructor ''' self.first = first self.last = last self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) self.potential = Potential(self.grid, self.hdf5) self.hamiltonian = Hamiltonian(self.grid, hdf5=self.hdf5) self.distribution = DistributionFunction(self.grid, hdf5=self.hdf5) self.potential.read_from_hdf5(0) self.distribution.read_from_hdf5(0) self.hamiltonian.read_from_hdf5(0) self.plot = PlotTimetraces(self.grid, self.distribution, self.hamiltonian, self.potential, first, last, vMax)
class movie(object): ''' Creates a movie from HDF5 showing the distribution function and timetraces of the errors in the particle number, energy, entropy and L2 norm. ''' def __init__(self, hdf5_file, iPlot=1): ''' Constructor ''' self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) if iPlot > 0 and iPlot < self.grid.nt: self.iPlot = iPlot else: self.iPlot = self.grid.nt self.potential = Potential(self.grid, self.hdf5) self.hamiltonian = Hamiltonian(self.grid, hdf5=self.hdf5) self.distribution = DistributionFunction(self.grid, hdf5=self.hdf5) self.potential.read_from_hdf5(iPlot) self.distribution.read_from_hdf5(iPlot) self.hamiltonian.read_from_hdf5(iPlot) self.plot = PlotBGK(self.grid, self.distribution, self.hamiltonian, self.potential, iTime=iPlot, write=True) def __del__(self): if self.hdf5 != None: self.hdf5.close()
def __init__(self, hdf5_file, nPlot=1, nmax=0): ''' Constructor ''' self.nPlot = nPlot self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) self.potential = Potential(self.grid, self.hdf5) self.energy = np.zeros(self.grid.nt+1) for itime in range(0, self.grid.nt+1): self.potential.read_from_hdf5(itime) self.energy[itime] = np.sqrt(self.potential.charge * self.potential.E) tMax = [] EMax = [] # find maxima for it in range(0, self.grid.nt+1): itm = (it-1+self.grid.nt+1) % (self.grid.nt+1) itp = (it+1+self.grid.nt+1) % (self.grid.nt+1) if self.energy[it] > self.energy[itm] and self.energy[it] > self.energy[itp]: tMax.append(self.grid.t[it]) EMax.append(self.energy[it]) # fit maxima if nmax == 0: nmax = len(tMax) else: nmax += 1 fit = np.polyfit(tMax[1:nmax], np.log(EMax[1:nmax]), 1) fit_fn = np.poly1d(fit) print("") print("Fit Parameter (m,b):", fit) print("") # set up figure/window size self.figure1 = plt.figure(num=None, figsize=(16,9)) plt.subplots_adjust(left=0.1, right=0.95, bottom=0.09, top=0.94, wspace=0.1, hspace=0.2) # plot plt.semilogy(self.grid.t, self.energy) plt.plot(tMax, EMax, 'ro') plt.plot(self.grid.t, np.exp(fit_fn(self.grid.t)), '--k') # plt.title("Damping of the Electrostatic Field", fontsize=24) plt.xlabel("$t$", labelpad=15, fontsize=22) plt.ylabel("$\parallel E (x,t) \parallel_{2}$", fontsize=22) plt.tight_layout() plt.draw() if hdf5_file.rfind('/') >= 0: filename = hdf5_file[hdf5_file.rfind('/'):] else: filename = hdf5_file filename = filename.replace('.hdf5', '_') filename += 'potential' plt.savefig(filename + '.png', dpi=300) plt.savefig(filename + '.pdf')
class replay(object): ''' Interactive replay plotting the distribution function, the Hamiltonian, density, potential and timetraces of kinetic and potential energy as well as the errors in the particle number, energy, entropy and L2 norm. ''' def __init__(self, hdf5_file, nPlot=1, iStart=0, vMax=0.0): ''' Constructor ''' self.iStart = iStart self.nPlot = nPlot self.hdf5 = h5py.File(hdf5_file, 'r') self.grid = Grid().load_from_hdf5(self.hdf5) self.potential = Potential(self.grid, self.hdf5) self.hamiltonian = Hamiltonian(self.grid, hdf5=self.hdf5) self.distribution = DistributionFunction(self.grid, hdf5=self.hdf5) self.potential.read_from_hdf5(iStart) self.distribution.read_from_hdf5(iStart) self.hamiltonian.read_from_hdf5(iStart) self.plot = PlotReplay(self.grid, self.distribution, self.hamiltonian, self.potential, self.grid.nt, iStart, nPlot, vMax) # self.plot.save_plots() def __del__(self): if self.hdf5 != None: self.hdf5.close() def init(self, iStart=0): self.update(iStart) def update(self, itime, final=False): self.potential.read_from_hdf5(itime) self.distribution.read_from_hdf5(itime) self.hamiltonian.read_from_hdf5(itime) print("it = %5i" % (itime)) if itime > 0: # Ekin = self.hamiltonian.Ekin # Ekin0 = self.hamiltonian.Ekin0 # Epot = self.hamiltonian.Epot - self.potential.E # Epot0 = self.hamiltonian.Epot0 - self.potential.E0 # Epot_f = self.hamiltonian.Epot / 2. # Epot0_f = self.hamiltonian.Epot0 / 2. # Epot_p = self.potential.E # Epot0_p = self.potential.E0 # # dEkin = Ekin - Ekin0 # dEpot = Epot - Epot0 # dEpot_f = Epot_f - Epot0_f # dEpot_p = Epot_p - Epot0_p # # E = Ekin + Epot # E0 = Ekin0 + Epot0 # E_f = Ekin + Epot_f # E0_f = Ekin0 + Epot0_f # E_p = Ekin + Epot_p # E0_p = Ekin0 + Epot0_p # # E_err = (E - E0 ) / E0 # E_err_f = (E_f - E0_f) / E0_f # E_err_p = (E_p - E0_p) / E0_p # # print # print(" dEpot/dEkin = %24.16E, dEpot(f)/dEkin = %24.16E, dEpot(phi)/dEkin = %24.16E" % (dEpot/dEkin, dEpot_f/dEkin, dEpot_p/dEkin)) # print(" E_pot = %24.16E, E_pot(f) = %24.16E, E_pot(phi) = %24.16E" % (Epot, Epot_f, Epot_p)) # print(" E_err = %24.16E, E_err(f) = %24.16E, E_err(phi) = %24.16E" % (E_err, E_err_f, E_err_p)) self.plot.add_timepoint() return self.plot.update(final=final) def run(self): for itime in range(self.iStart + 1, self.grid.nt + 1): self.update(itime, final=(itime == self.grid.nt))