-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
d01b6cb
commit 67e6be9
Showing
5 changed files
with
196 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,134 @@ | ||
import numpy as np | ||
from scipy.constants import c, e, m_e, m_p, k | ||
|
||
# Import the relevant structures from fbpic | ||
from fbpic.main import Simulation | ||
from fbpic.lpa_utils.laser import add_laser, add_laser_pulse | ||
from fbpic.lpa_utils.laser.laser_profiles import FlattenedGaussianLaser, GaussianLaser | ||
from fbpic.openpmd_diag import FieldDiagnostic, ParticleDiagnostic, \ | ||
set_periodic_checkpoint, restart_from_checkpoint, BoostedFieldDiagnostic, BoostedParticleDiagnostic | ||
from fbpic.openpmd_diag import ( | ||
FieldDiagnostic, | ||
ParticleDiagnostic, | ||
set_periodic_checkpoint, | ||
restart_from_checkpoint, | ||
BoostedFieldDiagnostic, | ||
BoostedParticleDiagnostic, | ||
) | ||
from fbpic.lpa_utils.boosted_frame import BoostConverter | ||
from fbpic.lpa_utils.laser import add_laser_pulse, FromLasyFileLaser | ||
|
||
import os | ||
from mpi4py.MPI import COMM_WORLD as comm | ||
|
||
|
||
# Whether to use the GPU | ||
use_cuda = True | ||
|
||
# The simulation box | ||
Nz = 6000 #4000 #3200 # Number of gridpoints along z | ||
zmax = 0.e-6 # Right end of the simulation box (meters) | ||
#equal to the size of LASY box for the laser to be centered | ||
zmin = -2*90.e-15*c # Left end of the simulation box (meters) | ||
Nr = 500 #405 #270 # Number of gridpoints along r | ||
rmax = 200.e-6 # Length of the box along r (meters) | ||
Nm = 2 # Number of modes used | ||
Nz = 6000 # 4000 #3200 # Number of gridpoints along z | ||
zmax = 0.0e-6 # Right end of the simulation box (meters) | ||
# equal to the size of LASY box for the laser to be centered | ||
zmin = -2 * 90.0e-15 * c # Left end of the simulation box (meters) | ||
Nr = 500 # 405 #270 # Number of gridpoints along r | ||
rmax = 200.0e-6 # Length of the box along r (meters) | ||
Nm = 2 # Number of modes used | ||
# Boost factor | ||
gamma_boost = 5. | ||
gamma_boost = 5.0 | ||
# Maximum simulation length | ||
Lmax = 5.e-3 #LASY propagation distance of a pulse | ||
Lmax = 5.0e-3 # LASY propagation distance of a pulse | ||
# The simulation timestep | ||
dt = min( rmax/(2*gamma_boost*Nr), (zmax-zmin)/Nz/c ) # Timestep (seconds) | ||
dt = min(rmax / (2 * gamma_boost * Nr), (zmax - zmin) / Nz / c) # Timestep (seconds) | ||
|
||
n_order = 16 | ||
|
||
boost = BoostConverter(gamma_boost) | ||
|
||
|
||
|
||
# The moving window | ||
v_window = c | ||
|
||
# Velocity of the Galilean frame (for suppression of the NCI) | ||
v_comoving = -np.sqrt(gamma_boost**2-1.)/gamma_boost * c | ||
v_comoving = -np.sqrt(gamma_boost**2 - 1.0) / gamma_boost * c | ||
|
||
# The diagnostics | ||
diag_period = 500 # Period of the diagnostics in number of timesteps | ||
diag_period = 500 # Period of the diagnostics in number of timesteps | ||
|
||
# Whether to write the fields in the lab frame | ||
Ntot_snapshot_lab = 40 | ||
Ntot_snapshot_lab = 40 | ||
dt_snapshot_lab = (Lmax) / v_window / (Ntot_snapshot_lab - 1) | ||
|
||
track_bunch = False # Whether to tag and track the particles of the bunch | ||
|
||
# The interaction length of the simulation (meters) | ||
L_interact = Lmax # the plasma length | ||
L_interact = Lmax # the plasma length | ||
# Interaction time (seconds) (to calculate number of PIC iterations) | ||
T_interact = boost.interaction_time( L_interact, (zmax-zmin), v_window ) | ||
T_interact = boost.interaction_time(L_interact, (zmax - zmin), v_window) | ||
# (i.e. the time it takes for the moving window to slide across the plasma) | ||
|
||
#take the first file | ||
PathToTheLasyFile = './DiagLASYforFBPIC/laser00000001_00001.h5' | ||
laser_profile = FromLasyFileLaser(PathToTheLasyFile) | ||
# take the first file | ||
PathToTheLasyFile = "./DiagLASYforFBPIC/laser00000001_00001.h5" | ||
laser_profile = FromLasyFileLaser(PathToTheLasyFile) | ||
|
||
|
||
# --------------------------- | ||
# Carrying out the simulation | ||
# --------------------------- | ||
|
||
if __name__ == '__main__': | ||
|
||
if __name__ == "__main__": | ||
# Initialize the simulation object | ||
sim = Simulation( Nz, zmax, Nr, rmax, Nm, dt, | ||
zmin=zmin, boundaries={'z':'open', 'r':'open'}, initialize_ions=False, | ||
n_order=n_order, use_cuda=use_cuda, v_comoving=v_comoving, | ||
gamma_boost=gamma_boost, verbose_level=2, particle_shape='cubic', | ||
use_galilean=True) | ||
sim = Simulation( | ||
Nz, | ||
zmax, | ||
Nr, | ||
rmax, | ||
Nm, | ||
dt, | ||
zmin=zmin, | ||
boundaries={"z": "open", "r": "open"}, | ||
initialize_ions=False, | ||
n_order=n_order, | ||
use_cuda=use_cuda, | ||
v_comoving=v_comoving, | ||
gamma_boost=gamma_boost, | ||
verbose_level=2, | ||
particle_shape="cubic", | ||
use_galilean=True, | ||
) | ||
# By default the simulation initializes an electron species (sim.ptcl[0]) | ||
# Because we did not pass the arguments `n`, `p_nz`, `p_nr`, `p_nz`, | ||
# this electron species does not contain any macroparticles. | ||
# It is okay to just remove it from the list of species. | ||
sim.ptcl = [] | ||
|
||
|
||
add_laser_pulse( sim, laser_profile, gamma_boost=gamma_boost, | ||
method='antenna', z0_antenna=0.e-6, v_antenna=0.) | ||
add_laser_pulse( | ||
sim, | ||
laser_profile, | ||
gamma_boost=gamma_boost, | ||
method="antenna", | ||
z0_antenna=0.0e-6, | ||
v_antenna=0.0, | ||
) | ||
# Convert parameter to boosted frame | ||
v_window, = boost.velocity( [ v_window ] ) | ||
(v_window,) = boost.velocity([v_window]) | ||
# Configure the moving window | ||
sim.set_moving_window( v=v_window ) | ||
sim.set_moving_window(v=v_window) | ||
|
||
# Add a diagnostics | ||
write_dir = 'DiagsFBPIC' | ||
write_dir = "DiagsFBPIC" | ||
sim.diags = [ | ||
BoostedFieldDiagnostic( zmin, zmax, c, | ||
dt_snapshot_lab, Ntot_snapshot_lab, gamma_boost, | ||
period=diag_period, fldobject=sim.fld, comm=sim.comm, | ||
fieldtypes=["E", "B", "rho"], write_dir=write_dir) | ||
] | ||
|
||
N_step = int(T_interact/sim.dt) | ||
BoostedFieldDiagnostic( | ||
zmin, | ||
zmax, | ||
c, | ||
dt_snapshot_lab, | ||
Ntot_snapshot_lab, | ||
gamma_boost, | ||
period=diag_period, | ||
fldobject=sim.fld, | ||
comm=sim.comm, | ||
fieldtypes=["E", "B", "rho"], | ||
write_dir=write_dir, | ||
) | ||
] | ||
|
||
N_step = int(T_interact / sim.dt) | ||
### Run the simulation | ||
sim.step( N_step ) | ||
sim.step(N_step) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.