def trackEnergy(root, finstep): simulation_variables = define_variables(root) code_downsampling = simulation_variables['code_downsampling'] skin_depth = simulation_variables['skin_depth'] ppc0 = simulation_variables['ppc0'] speed_of_light = simulation_variables['speed_of_light'] output_period = simulation_variables['output_period'] stride = simulation_variables['stride'] root += 'output/' m_el = (speed_of_light / skin_depth)**2 * (1. / ppc0) magnetic_energy = [] particle_energy = [] pairs_energy = [] photons_energy = [] npart = [] realnpart = [] for step in range(0, finstep): print((int)(100. * step / finstep), '%') # B-field data = h5py.File(root + 'flds.tot.{}'.format(str(step).zfill(3)), 'r') bx = data['bx'].value by = data['by'].value bz = data['bz'].value ex = data['ex'].value ey = data['ey'].value ez = data['ez'].value b_en = np.sum(bx**2 + by**2 + bz**2 + ex**2 + ey**3 + ez**2) * code_downsampling**2 / (2. * m_el * speed_of_light**2) # particles parts = getPlasma(root, step) data = h5py.File(root + 'prtl.tot.{}'.format(str(step).zfill(3)), 'r') gammae = (data['gammae'].value)[data['inde'].value > 0] gammae_prs = (data['gammae'].value)[data['inde'].value < 0] prtl_en = 2. * np.sum(gammae - 1.) * stride pair_en = 2. * np.sum(gammae_prs - 1.) * stride # photons data = h5py.File(root + 'phot.tot.{}'.format(str(step).zfill(3)), 'r') u = data['up'].value v = data['vp'].value w = data['wp'].value ch = data['chp'].value phot_en = np.sqrt(u**2 + v**2 + w**2) * ch phot_en = np.sum(phot_en) * stride npart.append(len(data['up'].value) * stride) realnpart.append(np.sum(data['chp'].value) * stride) magnetic_energy.append(b_en) particle_energy.append(prtl_en) pairs_energy.append(pair_en) photons_energy.append(phot_en) return (np.array(magnetic_energy), np.array(particle_energy), np.array(pairs_energy), np.array(photons_energy), np.array(npart), np.array(realnpart))
import matplotlib as mpl from aux_11 import * from plotter import * from parser import define_variables import helper as hlp # from matplotlib import rc # # rc('font', **{'family': 'serif', 'serif': ['Computer Modern']}) # rc('text', usetex=True) root = '/u/hhakoby1/outputs/cool_ic/' output_dir = root + 'pics/' simulation_variables = define_variables(root) import os if not os.path.exists(output_dir): os.makedirs(output_dir) max_number = int(getNumberOfFiles(root)) code_downsampling = simulation_variables['code_downsampling'] skin_depth = 0.25 ppc0 = simulation_variables['ppc0'] speed_of_light = simulation_variables['speed_of_light'] stride = simulation_variables['stride'] start = 82 end = max_number
def track_energy(root, step, x_lim=200): simulation_variables = define_variables(root) code_downsampling = simulation_variables['code_downsampling'] skin_depth = simulation_variables['skin_depth'] ppc0 = simulation_variables['ppc0'] speed_of_light = simulation_variables['speed_of_light'] output_period = simulation_variables['output_period'] stride = simulation_variables['stride'] root += 'output/' sim_vals = h5py.File(root + 'param.000', 'r') mx0 = sim_vals['mx0'].value[0] my0 = sim_vals['my0'].value[0] def x_to_sd(x): return (x - mx0 * 0.5) / skin_depth def y_to_sd(y): return (y - my0 * 0.5) / skin_depth m_el = (speed_of_light / skin_depth)**2 * (1. / ppc0) # B-field bx = getField(root, step, 'bx', getSizes(root, step), ymin=0, ymax=-1) by = getField(root, step, 'by', getSizes(root, step), ymin=0, ymax=-1) bz = getField(root, step, 'bz', getSizes(root, step), ymin=0, ymax=-1) ex = getField(root, step, 'ex', getSizes(root, step), ymin=0, ymax=-1) ey = getField(root, step, 'ey', getSizes(root, step), ymin=0, ymax=-1) ez = getField(root, step, 'ez', getSizes(root, step), ymin=0, ymax=-1) x = (np.arange(len(bx[0])) - max(np.arange(len(bx[0]))) * 0.5) * code_downsampling / skin_depth y = (np.arange(len(bx)) - max(np.arange(len(bx))) * 0.5) * code_downsampling / skin_depth x, y = np.meshgrid(x, y) bx = np.where(np.abs(y) < x_lim, bx, 0) by = np.where(np.abs(y) < x_lim, by, 0) bz = np.where(np.abs(y) < x_lim, bz, 0) ex = np.where(np.abs(y) < x_lim, ex, 0) ey = np.where(np.abs(y) < x_lim, ey, 0) ez = np.where(np.abs(y) < x_lim, ez, 0) b_en = np.sum(bx**2 + by**2 + bz**2 + ex**2 + ey**3 + ez**2) * code_downsampling**2 / (2. * m_el * speed_of_light**2) # particles # data = h5py.File(root + 'prtl.tot.{}'.format(str(step).zfill(3)), 'r') prtls = getPlasma(root, step) prtls = prtls[x_to_sd(prtls.x) < x_lim] prs = prtls[prtls.ind < 0] prtls = prtls[prtls.ind > 0] prtl_en = np.sum(prtls.g) * stride prs_en = np.sum(prs.g) * stride # photons import os.path if os.path.isfile(root + 'phot.tot.{}'.format(str(step).zfill(3))): data = h5py.File(root + 'phot.tot.{}'.format(str(step).zfill(3)), 'r') u = data['up'].value v = data['vp'].value w = data['wp'].value ch = data['chp'].value phot_en = np.sum(np.sqrt(u**2 + v**2 + w**2) * ch) * stride else: phot_en = 0 return (b_en, prtl_en, prs_en, phot_en)