|
| 1 | +from pywarpx import picmi |
| 2 | + |
| 3 | +# Physical constants |
| 4 | +c = picmi.constants.c |
| 5 | +q_e = picmi.constants.q_e |
| 6 | + |
| 7 | +# Number of time steps |
| 8 | +max_steps = 1000 |
| 9 | + |
| 10 | +# Number of cells |
| 11 | +nx = 64 |
| 12 | +nz = 512 |
| 13 | + |
| 14 | +# Physical domain |
| 15 | +xmin = -30e-06 |
| 16 | +xmax = 30e-06 |
| 17 | +zmin = -56e-06 |
| 18 | +zmax = 12e-06 |
| 19 | + |
| 20 | +# Domain decomposition |
| 21 | +max_grid_size = 64 |
| 22 | +blocking_factor = 32 |
| 23 | + |
| 24 | +# Create grid |
| 25 | +grid = picmi.Cartesian2DGrid( |
| 26 | + number_of_cells = [nx, nz], |
| 27 | + lower_bound = [xmin, zmin], |
| 28 | + upper_bound = [xmax, zmax], |
| 29 | + lower_boundary_conditions = ['open', 'open'], |
| 30 | + upper_boundary_conditions = ['open', 'open'], |
| 31 | + moving_window_velocity = [0., c], |
| 32 | + warpx_max_grid_size = max_grid_size, |
| 33 | + warpx_blocking_factor = blocking_factor) |
| 34 | + |
| 35 | +# Particles: plasma electrons |
| 36 | +plasma_density = 2e23 |
| 37 | +plasma_xmin = -20e-06 |
| 38 | +plasma_ymin = None |
| 39 | +plasma_zmin = 10e-06 |
| 40 | +plasma_xmax = 20e-06 |
| 41 | +plasma_ymax = None |
| 42 | +plasma_zmax = None |
| 43 | +uniform_distribution = picmi.UniformDistribution( |
| 44 | + density = plasma_density, |
| 45 | + lower_bound = [plasma_xmin, plasma_ymin, plasma_zmin], |
| 46 | + upper_bound = [plasma_xmax, plasma_ymax, plasma_zmax], |
| 47 | + fill_in = True) |
| 48 | +electrons = picmi.Species( |
| 49 | + particle_type = 'electron', |
| 50 | + name = 'electrons', |
| 51 | + initial_distribution = uniform_distribution) |
| 52 | + |
| 53 | +# Particles: beam electrons |
| 54 | +q_tot = 1e-12 |
| 55 | +x_m = 0. |
| 56 | +y_m = 0. |
| 57 | +z_m = -28e-06 |
| 58 | +x_rms = 0.5e-06 |
| 59 | +y_rms = 0.5e-06 |
| 60 | +z_rms = 0.5e-06 |
| 61 | +ux_m = 0. |
| 62 | +uy_m = 0. |
| 63 | +uz_m = 500. |
| 64 | +ux_th = 2. |
| 65 | +uy_th = 2. |
| 66 | +uz_th = 50. |
| 67 | +gaussian_bunch_distribution = picmi.GaussianBunchDistribution( |
| 68 | + n_physical_particles = q_tot / q_e, |
| 69 | + rms_bunch_size = [x_rms, y_rms, z_rms], |
| 70 | + rms_velocity = [c*ux_th, c*uy_th, c*uz_th], |
| 71 | + centroid_position = [x_m, y_m, z_m], |
| 72 | + centroid_velocity = [c*ux_m, c*uy_m, c*uz_m]) |
| 73 | +beam = picmi.Species( |
| 74 | + particle_type = 'electron', |
| 75 | + name = 'beam', |
| 76 | + initial_distribution = gaussian_bunch_distribution) |
| 77 | + |
| 78 | +# Laser |
| 79 | +e_max = 16e12 |
| 80 | +position_z = 9e-06 |
| 81 | +profile_t_peak = 30.e-15 |
| 82 | +profile_focal_distance = 100e-06 |
| 83 | +laser = picmi.GaussianLaser( |
| 84 | + wavelength = 0.8e-06, |
| 85 | + waist = 5e-06, |
| 86 | + duration = 15e-15, |
| 87 | + focal_position = [0, 0, profile_focal_distance + position_z], |
| 88 | + centroid_position = [0, 0, position_z - c*profile_t_peak], |
| 89 | + propagation_direction = [0, 0, 1], |
| 90 | + polarization_direction = [0, 1, 0], |
| 91 | + E0 = e_max, |
| 92 | + fill_in = False) |
| 93 | +laser_antenna = picmi.LaserAntenna( |
| 94 | + position = [0., 0., position_z], |
| 95 | + normal_vector = [0, 0, 1]) |
| 96 | + |
| 97 | +# Electromagnetic solver |
| 98 | +solver = picmi.ElectromagneticSolver( |
| 99 | + grid = grid, |
| 100 | + method = 'Yee', |
| 101 | + cfl = 1., |
| 102 | + divE_cleaning = 0) |
| 103 | + |
| 104 | +# Diagnostics |
| 105 | +diag_field_list = ["B", "E", "J", "rho"] |
| 106 | +field_diag = picmi.FieldDiagnostic( |
| 107 | + name = 'diag1', |
| 108 | + grid = grid, |
| 109 | + period = 200, |
| 110 | + data_list = diag_field_list) |
| 111 | + |
| 112 | +# Set up simulation |
| 113 | +sim = picmi.Simulation( |
| 114 | + solver = solver, |
| 115 | + max_steps = max_steps, |
| 116 | + verbose = 1, |
| 117 | + particle_shape = 'cubic', |
| 118 | + warpx_use_filter = 1) |
| 119 | + |
| 120 | +# Add plasma electrons |
| 121 | +sim.add_species( |
| 122 | + electrons, |
| 123 | + layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [1, 1, 1])) |
| 124 | + |
| 125 | +# Add beam electrons |
| 126 | +sim.add_species( |
| 127 | + beam, |
| 128 | + layout = picmi.PseudoRandomLayout(grid = grid, n_macroparticles = 100)) |
| 129 | + |
| 130 | +# Add laser |
| 131 | +sim.add_laser( |
| 132 | + laser, |
| 133 | + injection_method = laser_antenna) |
| 134 | + |
| 135 | +# Add diagnostics |
| 136 | +sim.add_diagnostic(field_diag) |
| 137 | + |
| 138 | +# Write input file that can be used to run with the compiled version |
| 139 | +sim.write_input_file(file_name = 'inputs_2d_picmi') |
| 140 | + |
| 141 | +# Initialize inputs and WarpX instance |
| 142 | +sim.initialize_inputs() |
| 143 | +sim.initialize_warpx() |
| 144 | + |
| 145 | +# Advance simulation until last time step |
| 146 | +sim.step(max_steps) |
0 commit comments