Exemplo n.º 1
0
    def init(self, kw):
        """PICMI relies on C++ WarpX to translate charge & mass strings to
        floats. To get around that we have our own variables sq/sm (species
        charge/mass) that are always floats.

        Automatically adds the species to the simulation
        """

        super(Species, self).init(kw)

        if isinstance(self.charge, str):
            if self.charge == 'q_e':
                self.sq = picmi.constants.q_e
            elif self.charge == '-q_e':
                self.sq = -picmi.constants.q_e
            else:
                raise ValueError("Unrecognized charge {}".format(self.charge))
        else:
            self.sq = self.charge

        if isinstance(self.mass, str):
            if self.mass == 'm_e':
                self.sm = picmi.constants.m_e
            elif self.mass == 'm_p':
                self.sm = picmi.constants.m_p
            else:
                raise ValueError("Unrecognized mass {}".format(self.mass))
        else:
            self.sm = self.mass

        mwxrun.simulation.add_species(self,
                                      layout=picmi.GriddedLayout(
                                          n_macroparticle_per_cell=[0, 0],
                                          grid=mwxrun.grid))
        self.pids_initialized = False
        # Only keys are used; ensures pids are both unique and ordered.
        self.waiting_extra_pids = {}
        # add a callback to initialize the extra PIDs after sim init
        callbacks.installafterinit(self.init_pid_dict)
Exemplo n.º 2
0
                          name='electrons',
                          initial_distribution=uniform_plasma)

grid = picmi.Cartesian2DGrid(
    number_of_cells=[nx, ny],
    lower_bound=[xmin, ymin],
    upper_bound=[xmax, ymax],
    lower_boundary_conditions=['periodic', 'periodic'],
    upper_boundary_conditions=['periodic', 'periodic'],
    moving_window_velocity=[0., 0., 0.],
    warpx_max_grid_size=32)

solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.)

sim = picmi.Simulation(solver=solver,
                       max_steps=40,
                       verbose=1,
                       warpx_plot_int=1,
                       warpx_current_deposition_algo='direct')

sim.add_species(electrons,
                layout=picmi.GriddedLayout(n_macroparticle_per_cell=[2, 2],
                                           grid=grid))

# write_inputs will create an inputs file that can be used to run
# with the compiled version.
sim.write_input_file(file_name='inputs2d_from_PICMI')

# Alternatively, sim.step will run WarpX, controlling it from Python
#sim.step()
Exemplo n.º 3
0
                     name='beam',
                     initial_distribution=beam_distribution)
plasma = picmi.Species(particle_type='electron',
                       name='plasma',
                       initial_distribution=plasma_distribution)

sim = picmi.Simulation(solver=solver,
                       max_steps=1000,
                       verbose=1,
                       warpx_plot_int=2,
                       warpx_current_deposition_algo=3,
                       warpx_charge_deposition_algo=0,
                       warpx_field_gathering_algo=0,
                       warpx_particle_pusher_algo=0)

sim.add_species(beam,
                layout=picmi.GriddedLayout(
                    grid=grid,
                    n_macroparticle_per_cell=number_per_cell_each_dim))
sim.add_species(plasma,
                layout=picmi.GriddedLayout(
                    grid=grid,
                    n_macroparticle_per_cell=number_per_cell_each_dim))

# write_inputs will create an inputs file that can be used to run
# with the compiled version.
sim.write_input_file(file_name='inputs_from_PICMI')

# Alternatively, sim.step will run WarpX, controlling it from Python
#sim.step()
                                              directed_velocity = [0., 0., 1.e9])

plasma_distribution = picmi.UniformDistribution(density = 1.e22,
                                                lower_bound = [-200.e-6, -200.e-6, 0.],
                                                upper_bound = [+200.e-6, +200.e-6, None],
                                                fill_in = True)

beam = picmi.Species(particle_type='electron', name='beam', initial_distribution=beam_distribution)
plasma = picmi.Species(particle_type='electron', name='plasma', initial_distribution=plasma_distribution)

sim = picmi.Simulation(solver = solver,
                       max_steps = max_steps,
                       verbose = 1,
                       warpx_current_deposition_algo = 'esirkepov')

sim.add_species(beam, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))
sim.add_species(plasma, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))

field_diag = picmi.FieldDiagnostic(name = 'diag1',
                                   grid = grid,
                                   period = max_steps,
                                   data_list = ['Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz', 'part_per_cell'],
                                   write_dir = '.',
                                   warpx_file_prefix = 'Python_PlasmaAcceleration_plt')

part_diag = picmi.ParticleDiagnostic(name = 'diag1',
                                     period = max_steps,
                                     species = [beam, plasma],
                                     data_list = ['ux', 'uy', 'uz', 'weighting'])

sim.add_diagnostic(field_diag)
Exemplo n.º 5
0
electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=uniform_plasma)

grid = picmi.Cartesian3DGrid(number_of_cells = [nx, ny, nz],
                             lower_bound = [xmin, ymin, zmin],
                             upper_bound = [xmax, ymax, zmax],
                             lower_boundary_conditions = ['periodic', 'periodic', 'periodic'],
                             upper_boundary_conditions = ['periodic', 'periodic', 'periodic'],
                             moving_window_velocity = [0., 0., 0.],
                             warpx_max_grid_size=32, warpx_coord_sys=0)

solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.)

sim = picmi.Simulation(solver = solver,
                       max_steps = 40,
                       verbose = 1,
                       warpx_plot_int = 40,
                       warpx_current_deposition_algo = 3,
                       warpx_charge_deposition_algo = 0,
                       warpx_field_gathering_algo = 0,
                       warpx_particle_pusher_algo = 0)

sim.add_species(electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[2,2,2], grid=grid))

# write_inputs will create an inputs file that can be used to run
# with the compiled version.
sim.write_input_file(file_name='inputs_from_PICMI')

# Alternatively, sim.step will run WarpX, controlling it from Python
sim.step()

Exemplo n.º 6
0
    period=200,
    data_list=diag_field_list,
    write_dir='.',
    warpx_file_prefix='Python_LaserAccelerationMR_plt')

# Set up simulation
sim = picmi.Simulation(solver=solver,
                       max_steps=max_steps,
                       verbose=1,
                       particle_shape='cubic',
                       warpx_use_filter=1,
                       warpx_serialize_ics=1)

# Add plasma electrons
sim.add_species(electrons,
                layout=picmi.GriddedLayout(grid=grid,
                                           n_macroparticle_per_cell=[1, 1, 1]))

# Add beam electrons
sim.add_species(beam,
                layout=picmi.PseudoRandomLayout(grid=grid,
                                                n_macroparticles=100))

# Add laser
sim.add_laser(laser, injection_method=laser_antenna)

# Add diagnostics
sim.add_diagnostic(field_diag)

# Write input file that can be used to run with the compiled version
sim.write_input_file(file_name='inputs_2d_picmi')
Exemplo n.º 7
0
    def setup_run(self):
        """Setup simulation components."""

        #######################################################################
        # Set geometry and boundary conditions                                #
        #######################################################################

        self.grid = picmi.Cartesian1DGrid(
            number_of_cells=[self.nz],
            warpx_max_grid_size=128,
            lower_bound=[0],
            upper_bound=[self.gap],
            lower_boundary_conditions=['dirichlet'],
            upper_boundary_conditions=['dirichlet'],
            lower_boundary_conditions_particles=['absorbing'],
            upper_boundary_conditions_particles=['absorbing'],
            warpx_potential_hi_z=self.voltage,
        )

        #######################################################################
        # Field solver                                                        #
        #######################################################################

        self.solver = picmi.ElectrostaticSolver(grid=self.grid,
                                                method='Multigrid',
                                                required_precision=1e-12,
                                                warpx_self_fields_verbosity=0)

        #######################################################################
        # Particle types setup                                                #
        #######################################################################

        self.electrons = picmi.Species(
            particle_type='electron',
            name='electrons',
            initial_distribution=picmi.UniformDistribution(
                density=self.plasma_density,
                rms_velocity=[
                    np.sqrt(constants.kb * self.elec_temp / constants.m_e)
                ] * 3,
            ))
        self.ions = picmi.Species(
            particle_type='He',
            name='he_ions',
            charge='q_e',
            mass=self.m_ion,
            initial_distribution=picmi.UniformDistribution(
                density=self.plasma_density,
                rms_velocity=[
                    np.sqrt(constants.kb * self.gas_temp / self.m_ion)
                ] * 3,
            ))

        #######################################################################
        # Collision  initialization                                           #
        #######################################################################

        cross_sec_direc = '../../../../warpx-data/MCC_cross_sections/He/'
        mcc_electrons = picmi.MCCCollisions(
            name='coll_elec',
            species=self.electrons,
            background_density=self.gas_density,
            background_temperature=self.gas_temp,
            background_mass=self.ions.mass,
            scattering_processes={
                'elastic': {
                    'cross_section':
                    cross_sec_direc + 'electron_scattering.dat'
                },
                'excitation1': {
                    'cross_section': cross_sec_direc + 'excitation_1.dat',
                    'energy': 19.82
                },
                'excitation2': {
                    'cross_section': cross_sec_direc + 'excitation_2.dat',
                    'energy': 20.61
                },
                'ionization': {
                    'cross_section': cross_sec_direc + 'ionization.dat',
                    'energy': 24.55,
                    'species': self.ions
                },
            })

        mcc_ions = picmi.MCCCollisions(
            name='coll_ion',
            species=self.ions,
            background_density=self.gas_density,
            background_temperature=self.gas_temp,
            scattering_processes={
                'elastic': {
                    'cross_section': cross_sec_direc + 'ion_scattering.dat'
                },
                'back': {
                    'cross_section': cross_sec_direc + 'ion_back_scatter.dat'
                },
                # 'charge_exchange' : {
                #    'cross_section' : cross_sec_direc+'charge_exchange.dat'
                # }
            })

        #######################################################################
        # Initialize simulation                                               #
        #######################################################################

        self.sim = picmi.Simulation(
            solver=self.solver,
            time_step_size=self.dt,
            max_steps=self.max_steps,
            warpx_collisions=[mcc_electrons, mcc_ions],
            warpx_load_balance_intervals=self.max_steps // 5000,
            verbose=self.test)

        self.sim.add_species(self.electrons,
                             layout=picmi.GriddedLayout(
                                 n_macroparticle_per_cell=[self.seed_nppc],
                                 grid=self.grid))
        self.sim.add_species(self.ions,
                             layout=picmi.GriddedLayout(
                                 n_macroparticle_per_cell=[self.seed_nppc],
                                 grid=self.grid))

        #######################################################################
        # Add diagnostics for the CI test to be happy                         #
        #######################################################################

        field_diag = picmi.FieldDiagnostic(
            name='diag1',
            grid=self.grid,
            period=0,
            data_list=['rho_electrons', 'rho_he_ions'],
            write_dir='.',
            warpx_file_prefix='Python_background_mcc_1d_plt')
        self.sim.add_diagnostic(field_diag)
Exemplo n.º 8
0
                                    data_list = diag_field_list)

part_diag1 = picmi.ParticleDiagnostic(name = 'diag1',
                                      period = 10,
                                      species = [electrons])

##########################
# simulation setup
##########################

sim = picmi.Simulation(solver = solver,
                       max_steps = max_steps,
                       verbose = 1,
                       warpx_current_deposition_algo = 'esirkepov')

sim.add_species(electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))

sim.add_laser(laser, injection_method=laser_antenna)

sim.add_diagnostic(field_diag1)
sim.add_diagnostic(part_diag1)

##########################
# simulation run
##########################

# write_inputs will create an inputs file that can be used to run
# with the compiled version.
#sim.write_input_file(file_name = 'inputs_from_PICMI')

# Alternatively, sim.step will run WarpX, controlling it from Python