Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
profile with a gaussian profile
"""
# Extract the part that has information
if info_in_real_part:
interp1 = interp1_complex.real
zero_part = interp1_complex.imag
else:
interp1 = interp1_complex.imag
zero_part = interp1_complex.real
# Control that the part that has no information is 0
assert np.allclose( 0., zero_part, atol=1.e-6*interp1.max() )
# Get the predicted properties of the laser in the boosted frame
if gamma_b is None:
boost = BoostConverter(1.)
else:
boost = BoostConverter(gamma_b)
ctau_b, lambda0_b, Lprop_b, z0_b = \
boost.copropag_length([ctau, 0.8e-6, Lprop, z0])
# Take into account whether the pulse is propagating forward or backward
if not forward_propagating:
Lprop_b = - Lprop_b
# Fit the on-axis profile to extract a0
def fit_function(z, a0, z0_phase):
return( gaussian_laser( z, r[0], a0, z0_phase,
z0_b+Lprop_b, ctau_b, lambda0_b ) )
fit_result = curve_fit( fit_function, z, interp1[:,0],
p0=np.array([a0, z0_b+Lprop_b]) )
a0_fit, z0_fit = fit_result[0]
Nr = 100 # Number of gridpoints along r
rmax = 100.e-6 # Length of the box along r (meters)
Nm = 2 # Number of modes used
n_order = -1 # The order of the stencil in z
# The simulation timestep
dt = (zmax-zmin)/Nz/c # Timestep (seconds)
N_step = 800 # Number of iterations to perform
N_show = 40 # Number of timestep between every plot
show_fields = False
l_boost = False
if l_boost:
# Boosted frame
gamma_boost = 15.
boost = BoostConverter(gamma_boost)
else:
gamma_boost = 1.
boost = None
# Initialize the simulation object
sim = Simulation( Nz, zmax, Nr, rmax, Nm, dt,
-1.e-6, 0., -1.e-6, 0., 1, 1, 1, 1.e18,
zmin=zmin, n_order=n_order, boundaries='open',
gamma_boost=gamma_boost )
# Configure the moving window
sim.set_moving_window(v=c, gamma_boost=gamma_boost)
# Suppress the particles that were intialized by default and add the bunch
sim.ptcl = [ ]
def run_simulation( gamma_boost, show ):
"""
Run a simulation with a relativistic electron bunch crosses a laser
Parameters
----------
gamma_boost: float
The Lorentz factor of the frame in which the simulation is carried out.
show: bool
Whether to show a plot of the angular distribution
"""
# Boosted frame
boost = BoostConverter(gamma_boost)
# The simulation timestep
diag_period = 100
N_step = 101 # Number of iterations to perform
# Calculate timestep to resolve the interaction with enough points
laser_duration_boosted, = boost.copropag_length(
[laser_duration], beta_object=-1 )
bunch_sigma_z_boosted, = boost.copropag_length(
[bunch_sigma_z], beta_object=1 )
dt = (4*laser_duration_boosted + bunch_sigma_z_boosted/c)/N_step
# Initialize the simulation object
zmax, zmin = boost.copropag_length( [zmax_lab, zmin_lab], beta_object=1. )
sim = Simulation( Nz, zmax, Nr, rmax, Nm, dt,
dens_func=None, zmin=zmin, boundaries='periodic',
use_cuda=use_cuda )
use_cuda = True
# The simulation box
Nz = 100
zmax = 0.e-6
zmin = -20.e-6
Nr = 200
rmax = 20.e-6
Nm = 1
# The simulation timestep
dt = (zmax-zmin)/Nz/c
N_step = 101
# Boosted frame
gamma_boost = 15.
boost = BoostConverter( gamma_boost )
# The bunch
sigma_r = 1.e-6
sigma_z = 3.e-6
Q = 200.e-12
gamma0 = 100.
sigma_gamma = 0.
n_emit = 0.1e-6
z_focus = 2000.e-6
z0 = -10.e-6
N = 40000
# The diagnostics
diag_period = 5
Ntot_snapshot_lab = 21
dt_snapshot_lab = 2*(z_focus-z0)/c/20
rmax = 10.e-6 # Length of the box along r (meters)
Nm = 2 # Number of modes used
# The particles of the plasma
p_zmin = 5.e-6 # Position of the beginning of the plasma (meters)
p_zmax = 15.e-6
p_rmin = 0. # Minimal radial position of the plasma (meters)
p_rmax = 100.e-6 # Maximal radial position of the plasma (meters)
n_atoms = 0.2 # The atomic density is chosen very low,
# to avoid collective effects
p_nz = 2 # Number of particles per cell along z
p_nr = 1 # Number of particles per cell along r
p_nt = 4 # Number of particles per cell along theta
# Boosted frame
boost = BoostConverter(gamma_boost)
# Boost the different quantities
beta_boost = np.sqrt( 1. - 1./gamma_boost**2 )
zmin, zmax = boost.static_length( [zmin_lab, zmax_lab] )
p_zmin, p_zmax = boost.static_length( [p_zmin, p_zmax] )
n_atoms, = boost.static_density( [n_atoms] )
# Increase the number of particles per cell in order to keep sufficient
# statistics for the evaluation of the ionization fraction
if gamma_boost > 1:
p_nz = int( 2 * gamma_boost * (1+beta_boost) * p_nz )
# The laser
a0 = 1.8 # Laser amplitude
lambda0_lab = 0.8e-6 # Laser wavelength
# Boost the laser wavelength before calculating the laser amplitude
lambda0, = boost.copropag_length( [ lambda0_lab ], beta_object=1. )
# Duration and initial position of the laser
# Order of the stencil for z derivatives in the Maxwell solver.
# Use -1 for infinite order, i.e. for exact dispersion relation in
# all direction (adviced for single-GPU/single-CPU simulation).
# Use a positive number (and multiple of 2) for a finite-order stencil
# (required for multi-GPU/multi-CPU with MPI). A large `n_order` leads
# to more overhead in MPI communications, but also to a more accurate
# dispersion relation for electromagnetic waves. (Typically,
# `n_order = 32` is a good trade-off.)
# See https://arxiv.org/abs/1611.05712 for more information.
n_order = -1
# Boosted frame
gamma_boost = 10.
# Boosted frame converter
boost = BoostConverter(gamma_boost)
# The simulation box
Nz = 600 # Number of gridpoints along z
zmax = 0.e-6 # Length of the box along z (meters)
zmin = -30.e-6
Nr = 75 # Number of gridpoints along r
rmax = 150.e-6 # Length of the box along r (meters)
Nm = 2 # Number of modes used
# The simulation timestep
# (See the section Advanced use > Running boosted-frame simulation
# of the FBPIC documentation for an explanation of the calculation of dt)
dt = min( rmax/(2*boost.gamma0*Nr)/c, (zmax-zmin)/Nz/c ) # Timestep (seconds)
# The laser (conversion to boosted frame is done inside 'add_laser')
a0 = 2. # Laser amplitude
# (increase this number for a real simulation)
# Order of the stencil for z derivatives in the Maxwell solver.
# Use -1 for infinite order, i.e. for exact dispersion relation in
# all direction (adviced for single-GPU/single-CPU simulation).
# Use a positive number (and multiple of 2) for a finite-order stencil
# (required for multi-GPU/multi-CPU with MPI). A large `n_order` leads
# to more overhead in MPI communications, but also to a more accurate
# dispersion relation for electromagnetic waves. (Typically,
# `n_order = 32` is a good trade-off.)
# See https://arxiv.org/abs/1611.05712 for more information.
n_order = -1
# Boosted frame
gamma_boost = 15.
boost = BoostConverter(gamma_boost)
# The laser (conversion to boosted frame is done inside 'add_laser')
a0 = 2. # Laser amplitude
w0 = 50.e-6 # Laser waist
ctau = 5.e-6 # Laser duration
z0 = -10.e-6 # Laser centroid
zfoc = 0.e-6 # Focal position
lambda0 = 0.8e-6 # Laser wavelength
# The density profile
w_matched = 50.e-6
ramp_up = 5.e-3
plateau = 8.e-2
ramp_down = 5.e-3
# The particles of the plasma