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)
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()
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))