import os, re, numpy as np from Smilei import * S = Smilei(".", verbose=False) Ntot_charges = S.Scalar.Ntot_charges(timesteps=0).getData()[0] Validate("Initial number of particles", Ntot_charges ) momentum_distribution = S.ParticleDiagnostic.Diag0(timesteps=0).getData()[0] Validate("Initial momentum distribution", momentum_distribution, 0.001 ) max_ubal = np.max( np.abs(S.Scalar.Ubal().getData()) ) Validate("Max Ubal is below 2%", max_ubal<0.02 ) Validate("List of fields in Field0", S.Field.Field0().getFields() )
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
dp = (pmax-pmin)/1000000. y[k] = quad(lambda p: tot1(p,v1[k],a), 0. ,pmin ,epsrel=3.e-14)[0] y[k]+= quad(lambda p: tot1(p,v1[k],a), pmin ,pmax-dp,epsrel=3.e-14)[0] y[k]+= quad(lambda p: tot1(p,v1[k],a), pmax ,np.inf ,epsrel=3.e-14)[0] y[k]+= quad(lambda p: tot (p,v1[k],a), 0. ,np.inf ,epsrel=3.e-14)[0] else: y[k] = quad(lambda p: tot (p,v1[k],a), 0. ,np.inf ,epsrel=3.e-14)[0] y[k]+= quad(lambda p: tot1(p,v1[k],a), 0. ,np.inf ,epsrel=3.e-14)[0] y *= (a/(4.*np.pi*kv(2,a)))/v1 y *= 3.204e-24 # 8*pi^2*me*c^2*re^2 in MeV*cm^2 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
import math as m import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt mpl.rcParams['text.usetex'] = True plt.matplotlib.rcParams.update({ 'font.family': 'serif', '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
from Smilei import * 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
import numpy as np from matplotlib.colors import LogNorm from mpl_toolkits.mplot3d import Axes3D import math as m mpl.rcParams['font.size'] = 20 mpl.rcParams['legend.fontsize'] = 20 mpl.rcParams['figure.facecolor'] = 'white' # ________________________________________________ # Functions # ________________________________________________ # Open results res = Smilei("./tst1d_cir_plane_wave_rela", verbose=False) # ________________________________________________ # Parameters #a0 = res_Boris.namelist.LaserGaussian3D[0].a0 a0 = 5. step = 10 # ____________________________________________ # Fields if False: Ey = res_Boris.Field(0, "Ey", timesteps=1300, slice={"z": [5.]}).get()
import os, re, numpy as np from Smilei import * S = Smilei(".", verbose=False) ## Ionization cross section (code units) for Al3+ vs energy (keV) #cs=np.array([ # [0.001000,0.000000],[0.001177,0.000000],[0.001385,0.000000],[0.001630,0.000000],[0.001918,0.000000],[0.002257,0.000000],[0.002656,0.000000],[0.003126,0.000000],[0.003678,0.000000],[0.004329,0.000000], # [0.005094,0.000000],[0.005995,0.000000],[0.007055,0.000000],[0.008302,0.000000],[0.009770,0.000000],[0.011498,0.000000],[0.013531,0.000000],[0.015923,0.000000],[0.018738,0.000000],[0.022051,0.000000], # [0.025950,0.000000],[0.030539,0.000000],[0.035938,0.000000],[0.042293,0.000000],[0.049770,0.000000],[0.058570,0.000000],[0.068926,0.000000],[0.081113,0.000000],[0.095455,0.000000],[0.112333,0.000000], # [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"])
import os, re, numpy as np, math from Smilei import * S = Smilei(".", verbose=False) ncel = [int(i) for i in S._ncels] # SCALARS RELATED TO MIN/MAX OF FIELDS for field in [ "Ex", "Ey", "Ez", "Bx_m", "By_m", "Bz_m", "Jx", "Jy", "Jz", "Rho" ]: if field in ["Ex", "Rho"]: precision = 0.25 else: precision = 0.025 Validate("Minimum of scalar " + field, S.Scalar(field + "Min").getData()[-1], precision) Validate("Maximum of scalar " + field, S.Scalar(field + "Max").getData()[-1], precision) MinLoc = np.unravel_index(int(S.Scalar(field + "MinCell").getData()[-1]), ncel) MaxLoc = np.unravel_index(int(S.Scalar(field + "MaxCell").getData()[-1]), ncel) Validate("Location of minimum of scalar " + field, MinLoc, 10) Validate("Location of maximum of scalar " + field, MaxLoc, 10) # FIELD DIAGNOSTICS fields = [ "Ex", "Ey", "Ez", "Bx", "By", "Bz", "Bx_m", "By_m", "Bz_m", "Jx", "Jy", "Jz", "Rho", "Jx_test0", "Jy_test0", "Jz_test0", "Rho_test0"
11.91873264, 13.84057796, 16.11965772, 18.80418339, 21.9305915, 25.51153958, 29.52473287, 33.90815976, 38.56573939, 43.38130946, 48.23275232, 52.99823957, 57.55375982, 61.76990959, 65.52021161, 68.70651127, 71.28856372, 73.29422978, 74.80222575, 75.91222479, 76.72040917, 77.30714207 ]), } colors = ["b", "k", "r", "g"] fig = plt.figure(3, figsize=(6, 3.5)) for element in ["H", "Al", "Zn", "Au"]: 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=".")
g = E / 511. + 1. v2 = 1. - g**-2 I0 = (9.76 * Z + 58.8 * Z**-0.19) / 1000. return 2.55e-25 * Z / (1. - g**-2) * (ln( (g + 1.) / 2. * (E / I0)**2) + (1. - (2. * g - 1.) * ln(2.) + (g - 1.)**2 / 8.) / g**2) 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
import os, re, numpy as np, math from Smilei import * S = Smilei(".", verbose=False) # 3D SCREEN DIAGS precision = [0.02, 0.06, 0.01, 0.06, 0.03, 0.1, 0.02, 0.1] for i, d in enumerate(S.namelist.DiagScreen): last_data = S.Screen(i, timesteps=160).getData()[-1] Validate("Screen " + d.shape + " diag with " + d.direction + " direction", last_data, precision[i])
dv0 = { "conductivity1": [0.000018, 0., 0], "conductivity2": [-0.00001, -0.000015, -0.00002], "conductivity3": [-0.00003, -0.00001] } style = {"conductivity1": 'b', "conductivity2": 'g', "conductivity3": 'r'} velocity = [] 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)
import numpy as np from matplotlib.colors import LogNorm from mpl_toolkits.mplot3d import Axes3D import math as m mpl.rcParams['font.size'] = 20 mpl.rcParams['legend.fontsize'] = 20 mpl.rcParams['figure.facecolor'] = 'white' # ________________________________________________ # Functions # ________________________________________________ # Open results res_Boris = Smilei("./tst3d_cir_plane_wave_Boris") res_Vay = Smilei("./tst3d_cir_plane_wave_Vay") res_HC = Smilei("./tst3d_cir_plane_wave_HC") # ________________________________________________ # Parameters #a0 = res_Boris.namelist.LaserGaussian3D[0].a0 a0 = 2. # _________________________________________ # Scalar Ukin = res_Boris.Scalar("Ukin").get() Ukin_Vay = res_Vay.Scalar("Ukin").get() Ukin_HC = res_HC.Scalar("Ukin").get()
import os, re, numpy as np, h5py from Smilei import * S = Smilei(".", verbose=False) # FIELD DIAG Validate("List of fields in Field0", S.Field.Field0().getFields()) timesteps = list(S.Field.Field0().getAvailableTimesteps()) Validate("List of timesteps in Field0", timesteps) Ez = S.Field.Field0("Ez", timesteps=timesteps[-1]).getData()[0] Validate("Last Ez profile in Field0", Ez, 1e-7) # 0-D PROBE Ez = S.Probe(0, "Ez").getData() Validate("Ez vs time in Probe0", Ez, 1e-7) # 1-D PROBE Validate("List of fields in Probe1", S.Probe(1).getFields()) timesteps = S.Probe(1, "Ez").getAvailableTimesteps() Validate("List of timesteps in Probe1", timesteps) Ez = S.Probe(1, "Ez", timesteps=timesteps[-1]).getData()[0] Validate("Last Ez profile in Probe1", Ez, 1e-7) # UBAL SCALAR max_ubal = np.max(np.abs(S.Scalar.Ubal().getData())) Validate("Max Ubal is below 2%", max_ubal < 0.02)
import os, re, numpy as np from scipy.signal import butter, filtfilt from Smilei import * S = Smilei(".", verbose=False) c = ["b", "r", "g", "c", "m", "y"] # Spatial profiles for i, (name, profile) in enumerate(S.namelist.profiles.items()): A = S.Field.Field0("Rho_" + name) data = A.get() values = data["data"][0] # x = data["x"] # v = [profile(xx) for xx in x] # plt.plot(x, values, color=c[i]) # plt.plot(x, v, "o", markeredgecolor=c[i], markerfacecolor="none") Validate("Profile " + name, values, 0.01) # Temporal profiles Jz = S.Field.Field0("Jz").get() x = Jz["x"] #t = Jz["times"] Jz = np.array(Jz["data"]) w = S.namelist.antenna_width for i, (name, tprofile) in enumerate(S.namelist.tprofiles): x0 = i * w + 0.1 * w x1 = x0 + 0.8 * w thisJz = Jz[:, (x > x0) * (x < x1)].mean(axis=1) # v = [tprofile(tt) for tt in t*S.namelist.Main.timestep] # plt.plot(t, thisJz, color=c[i])
[17.475316, 0.014570], [20.565161, 0.012829], [24.201327, 0.011297], [28.480411, 0.009954], [33.516088, 0.008778], [39.442133, 0.007751], [46.415973, 0.006855], [54.622872, 0.006075], [64.280848, 0.005398], [75.646470, 0.004811], [89.021670, 0.004303], [104.761764, 0.003865], [123.284896, 0.003488], [145.083138, 0.003164], [170.735570, 0.002888], [200.923659, 0.002653], [236.449362, 0.002454], [278.256434, 0.002288], [327.455496, 0.002149], [385.353540, 0.002035], [453.488650, 0.001944], [533.670861, 0.001871], [628.030244, 0.001815], [739.073494, 0.001774], [869.750518, 0.001746], [1023.532800, 0.001730], [1204.505627, 0.001723], [1417.476611, 0.001725], [1668.103410, 0.001735], [1963.044021, 0.001751], [2310.133656, 0.001772], [2718.592885, 0.001798], [3199.272585, 0.001827], [3764.942199, 0.001860], [4430.628958, 0.001895], [5214.017089, 0.001932], [6135.917601, 0.001971], [7220.821137, 0.002012], [8497.548578, 0.002053], [10000.016685, 0.002096]]) S1 = Smilei("ionization_rate1") S2 = Smilei("ionization_rate2") S3 = Smilei("ionization_rate3") # 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)
from Smilei import * import numpy as np 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')
import math as m import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt mpl.rcParams['text.usetex'] = True plt.matplotlib.rcParams.update({ 'font.family': 'serif', '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/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))
# ____________________________________________________________________________ # # This script validates the relativist pushers in 1d by analyzing # the trajectory of a particle in a circular Gaussian plane wave. # # _____________________________________________________________________________ import os, re, numpy as np, h5py from Smilei import * S = Smilei(".", verbose=False) # Step represents the step between trajectory points what we consider # This enables to reduce the size of the array step = 2 # List of relativistic pushers pusher_list = ["borisnr", "norm", "vay", "higueracary"] # We load successively the particle track associated to each pusher for pusher in pusher_list: # Data from the Track diagnostic Track = S.TrackParticles("electron_" + pusher, axes=["x", "px", "py", "pz"]).get() # We extract x,px,py,pz from the first particle x = np.array(Track['x'][::step, 0]) px = np.array(Track['px'][::step, 0]) py = np.array(Track['py'][::step, 0]) pz = np.array(Track['pz'][::step, 0])
from Smilei import * import numpy as np import matplotlib.pyplot as plt from scipy.special import erf as erf plt.ion() for path in ["beam_relaxation1", "beam_relaxation2", "beam_relaxation3"]: 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"].nb_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 = np.double( 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))