Validate("Temporal profile " + name, thisJz, 0.01) # Verify that "time_fields_frozen" works Late_Ez = S.Field.Field0.Ez(timesteps=190).getData()[0] Validate("Ez field at late time", Late_Ez, 0.01) # Verify that "time_frozen" works Late_density = S.Field.Field0.Rho_trapezoidal(timesteps=190).getData()[0] Validate("Density of a species at a late time", Late_density, 0.01) # Maxwell-Juttner initialization i = -1 drift = ["no", "px", "py", "pz"] for eon in S.namelist.mj_species: i += 1 p = S.ParticleDiagnostic(i).get() p_distr = p["data"][0] p = p[drift[i]] if i > 0 else p["px"] # # theory # g0 = S.namelist.g0 if i>0 else 1. # Te = S.namelist.Te # fth = (g0 * np.sqrt(1.+p**2)+Te) * np.exp( -g0/Te* (np.sqrt(1.+p**2) - np.sqrt(1.-g0**-2)*p) ) # itg = (p[1]-p[0])*np.sum(fth) # fth = fth/itg # plt.plot(px, p_distr, 'o', markeredgecolor=c[i], markerfacecolor="none") # plt.plot(px, fth, '-', color=c[i]) b, a = butter(8, 0.15, btype='low', analog=False) p_filt = filtfilt(b, a, p_distr) Validate("Maxwell-Juttner Momentum distribution (" + drift[i] + " drift)", p_filt, p_filt.max() * 1e-2)
import matplotlib.pyplot as plt from scipy.special import erf as erf plt.ion() path = "Maxwellianization1" sim = Smilei(path) coulomb_log = np.double(sim.namelist.Collisions[0].coulomb_log) dt = np.double(sim.namelist.Main.timestep) / (2 * np.pi) re_ = 2.8179403267e-15 # meters wavelength = 1e-6 # meters c = 3e8 times = sim.ParticleDiagnostic(0).getAvailableTimesteps() electrons = sim.ParticleDiagnostic(0, slice={"x": "all"}).get() vx = electrons["vx"] fig = None fig = plt.figure(1) if fig: fig.clf() if fig: ax = fig.add_subplot(1, 1, 1) for i, t in enumerate(times): if i % 3 > 0: continue A = electrons["data"][i] if fig: #ax.cla() ax.plot(vx, A, 'b') plt.draw() plt.pause(0.0001)
sim = Smilei(path) mass_ion = np.double(sim.namelist.Species["ion1"].mass) charge_ion = np.double(sim.namelist.Species["ion1"].charge) density_ion = np.double(sim.namelist.Species["ion1"].charge_density) temperature_ion = np.double(sim.namelist.Species["ion1"].temperature) velocity_electron = np.double(sim.namelist.Species["electron1"].mean_velocity)[0] temperature_electron = np.double(sim.namelist.Species["electron1"].temperature) coulomb_log = np.double(sim.namelist.Collisions[0].coulomb_log) dt = np.double(sim.namelist.Main.timestep)/(2*np.pi) re = 2.8179403267e-15 # meters wavelength = 1e-6 # meters c = 3e8 coeff = (2.*np.pi/wavelength)**2*re*c times = sim.ParticleDiagnostic(diagNumber=0).getAvailableTimesteps() e_vx_mean = np.zeros(len(times)) e_vperp2 = np.zeros(len(times)) i_vx_mean = np.zeros(len(times)) Ti = np.zeros(len(times)) electrons0 = sim.ParticleDiagnostic(0, slice={"x":"all"}).get() electrons1 = sim.ParticleDiagnostic(1, slice={"x":"all"}).get() ions = sim.ParticleDiagnostic(2, slice={"x":"all"}).get() fig = None #fig = plt.figure(1) if fig: fig.clf() if fig: ax = fig.add_subplot(1,1,1) for i,t in enumerate(times):
return y for path in ["Stopping_power1","Stopping_power2","Stopping_power3"]: sim = Smilei(path) temperature_electron = np.double(sim.namelist.Species["backgroundelectron"].temperature) density_electron = np.double(sim.namelist.Species["backgroundelectron"].charge_density) coulomb_log = np.double(sim.namelist.Collisions[0].coulomb_log) dt = np.double(sim.namelist.Main.timestep)/(2*np.pi) re = 2.8179403267e-15 # meters wavelength = 1e-6 # meters c = 3e8 times = sim.ParticleDiagnostic(diagNumber=0).getAvailableTimesteps() nx = sim.ParticleDiagnostic(diagNumber=0,timesteps=0).get()["x"].size Ekin = np.zeros((nx,len(times))) electrons = sim.ParticleDiagnostic(0).get() ekin = electrons["ekin"]*0.511 dekin = np.diff(ekin) dekin = np.hstack((dekin, dekin[-1])) fig = None #fig = plt.figure(1) if fig: fig.clf() if fig: ax = fig.add_subplot(1,1,1) for i,t in enumerate(times): A = electrons["data"][i] A = A*dekin
import numpy as np import matplotlib.pyplot as plt ln = np.log plt.ion() D = [] colors = ["k", "r", "g", "b", "m"] for elm in ["C", "Al", "Zn", "Sn", "Au"]: S1=Smilei("ionization_multiple"+elm+"1") S2=Smilei("ionization_multiple"+elm+"2") color = colors.pop() timestep1 = np.round(np.double(S1.namelist.Main.timestep), decimals=1) D.append( S1.ParticleDiagnostic(0,slice={"ekin":[0,1]}, linestyle="-", color=color, label=elm) ) timestep2 = int(np.double(S2.namelist.Main.timestep)) D.append( S2.ParticleDiagnostic(0,slice={"ekin":[0,1]}, linestyle="", marker=".", color=color ) ) # Plot simulation result plt.figure(1, figsize=(6,3.5)) multiPlot(*D) fig =plt.gcf() ax = plt.gca() # Make nicer plot legend = plt.legend( loc=2, prop={'size':10}) ax.add_artist(legend)
import os, re, numpy as np from scipy.special import erf from Smilei import * S = Smilei(".", verbose=False) for i in range(3): ion = "ion" + str(i) eon = "eon" + str(i) ion_mass = S.namelist.Species[ion].mass times = np.double(S.ParticleDiagnostic(0).getAvailableTimesteps()) ones = np.ones_like(times) eon_vx = S.ParticleDiagnostic(i * 3 + 0, slice={"x": "all"}).get() eon_mean_vx = np.array(eon_vx["data"]) eon_mean_vx = (np.outer(ones, eon_vx["vx"]) * eon_mean_vx).sum(axis=1) / eon_mean_vx.sum(axis=1) eon_vp2 = S.ParticleDiagnostic(i * 3 + 1, slice={"x": "all"}).get() eon_mean_vp2 = np.array(eon_vp2["data"]) eon_mean_vp2 = (np.outer(ones, eon_vp2["vperp2"]) * eon_mean_vp2).sum(axis=1) / eon_mean_vp2.sum(axis=1) ion_vx = S.ParticleDiagnostic(i * 3 + 2, slice={"x": "all"}).get() ion_vxd = np.array(ion_vx["data"]) ion_mean_vx = (np.outer(ones, ion_vx["vx"]) * ion_vxd).sum(axis=1) / ion_vxd.sum(axis=1) ion_T = (np.outer(ones, ion_vx["vx"]) - np.outer(ion_mean_vx, np.ones_like(ion_vx["vx"])))**2 * ion_vxd ion_T = ion_T.sum(axis=1) / ion_vxd.sum(axis=1) * ion_mass
'font.size': 20 }) mpl.rcParams['xtick.major.size'] = 10 mpl.rcParams['ytick.major.size'] = 10 mpl.rcParams['xtick.minor.size'] = 5 mpl.rcParams['ytick.minor.size'] = 5 S = Smilei('/Users/mica/RESULTS/SMILEI/thermalPlasmaPyDrift/') T = S.namelist.Te mu = 1. / T print mu v0 = S.namelist.v0 g0 = 1. / m.sqrt(1. - v0**2) # read p-distribution fct fp = np.array(S.ParticleDiagnostic(1).getData())[0] p = np.array(S.ParticleDiagnostic(1).get()['py']) print 'int over all py:', (p[1] - p[0]) * np.sum(fp) # compute theoretical distribution fct fth = np.zeros(p.shape) fth = (g0 * np.sqrt(1. + p**2) + T) * np.exp(-g0 * mu * (np.sqrt(1. + p**2) - v0 * p)) itg = (p[1] - p[0]) * np.sum(fth) fth = fth / itg # plot plt.figure(1) plt.semilogy(p, fp, 'b') plt.hold('on') plt.semilogy(p, fth, 'r')
'font.serif': 'Times', 'font.size': 20 }) mpl.rcParams['xtick.major.size'] = 10 mpl.rcParams['ytick.major.size'] = 10 mpl.rcParams['xtick.minor.size'] = 5 mpl.rcParams['ytick.minor.size'] = 5 S = Smilei('/Users/mica/RESULTS/SMILEI/thermalPlasmaNoDrift/') T = S.namelist.Te mu = 1. / T v0 = S.namelist.v0 g0 = 1. / m.sqrt(1. - v0**2) # read gamma-distribution fct fg = np.array(S.ParticleDiagnostic(0).getData())[0] g = np.array(S.ParticleDiagnostic(0).get()['gamma']) print 'int over all g:', (g[1] - g[0]) * np.sum(fg) # compute theoretical distribution fct fth = np.zeros(g.shape) fth = g * np.sqrt(g**2 - 1.) * np.exp(-mu * g) itg = (g[1] - g[0]) * np.sum(fth) fth = fth / itg # read p-distribution fct fp = np.array(S.ParticleDiagnostic(1).getData())[0] p = np.array(S.ParticleDiagnostic(1).get()['px']) print 'int over all px:', (p[1] - p[0]) * np.sum(fp) # compute theoretical distribution fct
# get electron velocity ve = np.double(S1.namelist.Species["electron1"].mean_velocity[0]) Ee = (1. / np.sqrt(1. - ve**2) - 1.) * 511. # energy cse = np.interp(np.log(Ee), np.log(cs[:, 0]), cs[:, 1]) # interpolate cross section # get density ne = np.double(S1.namelist.Species["electron1"].charge_density) # get ion charge q0 = np.double(S1.namelist.Species["ion1"].charge) # Plot simulation result D1 = S1.ParticleDiagnostic("#0/#1", slice={"x": "all"}, linestyle="None", marker=".", label="We=Wi") D2 = S2.ParticleDiagnostic("#0/#1", slice={"x": "all"}, linestyle="None", marker=".", label="We=10. Wi") D3 = S3.ParticleDiagnostic("#0/#1", slice={"x": "all"}, linestyle="None", marker=".", label="We=0.1 Wi") multiPlot(D1, D2, D3, vmin=q0, skipAnimation=True)
print "Analyzing " + element S = Smilei("ionization_equilibrium" + element) npoints = S.namelist.npoints every = S.namelist.DiagParticles[0].every ts = int(t0 * S.namelist.Main.referenceAngularFrequency_SI / S.namelist.Main.timestep / every) # timestep at 1ps Z = [] Zfinal = [] T = [] Tfinal = [] for i in range(npoints): D = S.ParticleDiagnostic("#" + str(4 * i + 2) + "/#" + str(4 * i + 3), slice={"x": "all"}, units=["ps"], marker=".") Z.append(D) Zfinal.append(np.array(D.getData())[ts]) D = S.ParticleDiagnostic("#" + str(4 * i + 0) + "/#" + str(4 * i + 1), slice={"x": "all"}, units=["ps"], marker=".") T.append(D) Tfinal.append(np.array(D.getData())[ts] * (511. * 2. / 3.)) #multiPlot(*Z, figure=1, skipAnimation=True) #multiPlot(*T, figure=2, skipAnimation=True)
plt.figure(1, figsize=(8, 3.5)) # First, slowing down for a few examples ######################################## D = [] sims = ["2", "3", "4"] for sim in sims: S = Smilei("ionization_stopping_power" + sim) D.append( S.ParticleDiagnostic("#0/#1", slice={"x": "all"}, units=["fs"], linestyle="None", marker='o', markersize=4, markeredgewidth=0., skipAnimation=True)) multiPlot(*D) fig = plt.gcf() ax = plt.gca() ax.xaxis.labelpad = 0 ax.yaxis.labelpad = 0 ax.set_xscale("log") ax.set_yscale("log") ax.set_xlim(10., 1e6) ax.set_ylim(1e-2, 3.) ax.set_position([0.1, 0.19, 0.35, 0.77]) # Theory
temperature = [] density = [] for path in ["conductivity1", "conductivity2", "conductivity3"]: sim = Smilei(path) ncases = 0 while sim.namelist.DiagParticles[ncases].output == "jx_density": ncases += 1 if ncases == 0: continue coulomb_log = np.double(sim.namelist.Collisions[0].coulomb_log) dt = np.double(sim.namelist.Main.timestep) / (2 * np.pi) times = sim.ParticleDiagnostic(diagNumber=0).getAvailableTimesteps() vx_mean = np.zeros((ncases, len(times))) fig = None #fig = plt.figure(1) if fig: fig.clf() if fig: ax = fig.add_subplot(1, 1, 1) for k in range(ncases): evx_density = -np.array(sim.ParticleDiagnostic(k).getData()) edensity = np.array(sim.ParticleDiagnostic(k + ncases).getData()) vx_mean[k, :] = evx_density / edensity times *= 3.33 * dt # fs fig = plt.figure(2)
# [0.132194,0.008498],[0.155568,0.024568],[0.183074,0.042322],[0.215444,0.059764],[0.253537,0.074867],[0.298365,0.087020],[0.351120,0.096034],[0.413202,0.101988],[0.486261,0.105125],[0.572238,0.105786], # [0.673416,0.104358],[0.792484,0.101245],[0.932605,0.096836],[1.097501,0.091491],[1.291552,0.085529],[1.519914,0.079223],[1.788653,0.072813],[2.104908,0.066472],[2.477081,0.060321],[2.915059,0.054454], # [3.430476,0.048935],[4.037025,0.043802],[4.750819,0.039074],[5.590821,0.034755],[6.579345,0.030837],[7.742651,0.027303],[9.111645,0.024132],[10.72269,0.021300],[12.61859,0.018779],[14.84971,0.016545], # [17.47531,0.014570],[20.56516,0.012829],[24.20132,0.011297],[28.48041,0.009954],[33.51608,0.008778],[39.44213,0.007751],[46.41597,0.006855],[54.62287,0.006075],[64.28084,0.005398],[75.64647,0.004811], # [89.02167,0.004303],[104.7617,0.003865],[123.2848,0.003488],[145.0831,0.003164],[170.7355,0.002888],[200.9236,0.002653],[236.4493,0.002454],[278.2564,0.002288],[327.4554,0.002149],[385.3535,0.002035], # [453.4886,0.001944],[533.6708,0.001871],[628.0302,0.001815],[739.0734,0.001774],[869.7505,0.001746],[1023.532,0.001730],[1204.505,0.001723],[1417.476,0.001725],[1668.103,0.001735],[1963.044,0.001751], # [2310.133,0.001772],[2718.592,0.001798],[3199.272,0.001827],[3764.942,0.001860],[4430.628,0.001895],[5214.017,0.001932],[6135.917,0.001971],[7220.821,0.002012],[8497.548,0.002053],[10000.01,0.002096] #]) for i in range(3): ion = "ion" + str(i) eon = "eon" + str(i) ion_mean_charge = S.ParticleDiagnostic("#" + str(2 * i) + "/#" + str(2 * i + 1), slice={ "x": "all" }).get() times = ion_mean_charge["times"] * S.namelist.Main.timestep ion_mean_charge = np.array(ion_mean_charge["data"]) # # theory # ion_charge = S.namelist.Species[ion].charge # eon_density = S.namelist.Species[eon].charge_density # eon_velocity = S.namelist.Species[eon].mean_velocity[0] # eon_energy = ((1.-eon_velocity**2)**-.5-1.)*511. # energy in keV # eon_cs = np.interp(np.log(eon_energy), np.log(cs[:,0]), cs[:,1]) # interpolate cross section # t = np.linspace(0., S.namelist.Main.sim_time, 1000) # q = ion_charge + 1. - np.exp(-eon_velocity*eon_density*eon_cs*t) # plt.plot(t,q,'--k') # plt.plot(times, ion_mean_charge)