|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from pywarpx import picmi |
| 4 | + |
| 5 | +constants = picmi.constants |
| 6 | + |
| 7 | +# Constants from the focusing beam example |
| 8 | +nano = 1.0e-9 |
| 9 | +micro = 1.0e-6 |
| 10 | + |
| 11 | +sigmax = 516.0 * nano |
| 12 | +sigmay = 7.7 * nano |
| 13 | +sigmaz = 300.0 * micro |
| 14 | + |
| 15 | +# Box dimensions |
| 16 | +Lx = 20 * sigmax |
| 17 | +Ly = 20 * sigmay |
| 18 | +Lz = 20 * sigmaz |
| 19 | + |
| 20 | +nx = 256 |
| 21 | +ny = 256 |
| 22 | +nz = 256 |
| 23 | + |
| 24 | +xmin = -0.5 * Lx |
| 25 | +xmax = 0.5 * Lx |
| 26 | +ymin = -0.5 * Ly |
| 27 | +ymax = 0.5 * Ly |
| 28 | +zmin = -0.5 * Lz |
| 29 | +zmax = 0.5 * Lz |
| 30 | + |
| 31 | +em_order = 3 |
| 32 | + |
| 33 | +grid = picmi.Cartesian3DGrid( |
| 34 | + number_of_cells=[nx, ny, nz], |
| 35 | + lower_bound=[xmin, ymin, zmin], |
| 36 | + upper_bound=[xmax, ymax, zmax], |
| 37 | + lower_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], |
| 38 | + upper_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], |
| 39 | + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], |
| 40 | + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], |
| 41 | + warpx_max_grid_size=256, |
| 42 | +) |
| 43 | + |
| 44 | +solver = picmi.ElectromagneticSolver(grid=grid) |
| 45 | + |
| 46 | +# Create species with external file injection |
| 47 | + |
| 48 | +beam1_distribution = picmi.FromFileDistribution( |
| 49 | + file_path="../test_3d_focusing_gaussian_beam_from_openpmd_prepare/openpmd_generated_particles.h5", |
| 50 | +) |
| 51 | + |
| 52 | +beam1 = picmi.Species( |
| 53 | + particle_type="electron", |
| 54 | + name="beam1", |
| 55 | + initial_distribution=beam1_distribution, |
| 56 | +) |
| 57 | + |
| 58 | +diag1 = picmi.ParticleDiagnostic( |
| 59 | + name="diag1", |
| 60 | + period=1, |
| 61 | + warpx_dump_last_timestep=1, |
| 62 | +) |
| 63 | + |
| 64 | +openpmd = picmi.ParticleDiagnostic( |
| 65 | + name="openpmd", |
| 66 | + period=1, |
| 67 | + species=[beam1], |
| 68 | + data_list=["weighting", "x", "y", "z"], |
| 69 | + warpx_format="openpmd", |
| 70 | + warpx_dump_last_timestep=1, |
| 71 | +) |
| 72 | + |
| 73 | +sim = picmi.Simulation( |
| 74 | + solver=solver, |
| 75 | + max_steps=0, |
| 76 | + verbose=1, |
| 77 | +) |
| 78 | + |
| 79 | +sim.add_species(beam1, layout=None) |
| 80 | + |
| 81 | +sim.add_diagnostic(diag1) |
| 82 | +sim.add_diagnostic(openpmd) |
| 83 | + |
| 84 | +# write_inputs will create an inputs file that can be used to run |
| 85 | +# with the compiled version. |
| 86 | +# sim.write_input_file(file_name = 'inputs_from_PICMI') |
| 87 | + |
| 88 | +# Alternatively, sim.step will run WarpX, controlling it from Python |
| 89 | +sim.step() |
0 commit comments