Skip to content

Commit

Permalink
make LWFA example script charge neutral
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMarre committed Sep 11, 2024
1 parent becf6fa commit 8a462fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
13 changes: 10 additions & 3 deletions lib/python/picongpu/picmi/interaction/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@ def fill_in_ionization_electron_species(
for species, ionization_model_conversion in ionization_model_conversion_by_type_and_species.items():
if ionization_model_conversion is not None:
for picmi_ionization_model, pypicongpu_ionization_model in ionization_model_conversion.items():
pypicongpu_ionization_electron_species = pypicongpu_by_picmi_species[
picmi_ionization_model.ionization_electron_species
]
try:
pypicongpu_ionization_electron_species = pypicongpu_by_picmi_species[
picmi_ionization_model.ionization_electron_species
]
except KeyError:
raise ValueError(
f"Ionization electron species of {picmi_ionization_model} not known to simulation."
+ f"Please add species {picmi_ionization_model.ionization_electron_species.name} to"
+ "the simulation"
)
pypicongpu_ionization_model.ionization_electron_species = pypicongpu_ionization_electron_species

def __has_ground_state_ionization(self, species) -> bool:
Expand Down
54 changes: 29 additions & 25 deletions share/picongpu/pypicongpu/examples/laser_wakefield/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
This Python script is example PICMI user script reproducing the LaserWakefield example setup, based on 8.cfg.
"""


# generation modifiers
ENABLE_IONS = True
ENABLE_IONIZATION = True
ADD_CUSTOM_INPUT = True
OUTPUT_DIRECTORY_PATH = "LWFA"


numberCells = np.array([192, 2048, 192])
cellSize = np.array([0.1772e-6, 0.4430e-7, 0.1772e-6]) # unit: meter)

Expand All @@ -47,17 +45,6 @@
vacuum_cells_front=50,
)

# for particle type see https://github.com/openPMD/openPMD-standard/blob/upcoming-2.0.0/EXT_SpeciesType.md
electrons = picmi.Species(particle_type="electron", name="electron", initial_distribution=gaussianProfile)

hydrogen_ionization = picmi.Species(
particle_type="H", name="hydrogen", charge_state=0, initial_distribution=gaussianProfile
)

hydrogen_fully_ionized = picmi.Species(
particle_type="H", name="hydrogen", picongpu_fixed_charge=True, initial_distribution=gaussianProfile
)

solver = picmi.ElectromagneticSolver(
grid=grid,
method="Yee",
Expand All @@ -76,27 +63,47 @@
picongpu_phase=0.0,
)

randomLayout = picmi.PseudoRandomLayout(n_macroparticles_per_cell=2)
random_layout = picmi.PseudoRandomLayout(n_macroparticles_per_cell=2)

# Initialize particles based on speciesInitialization.param
# simulation schema : https://github.com/BrianMarre/picongpu/blob/2ddcdab4c1aca70e1fc0ba02dbda8bd5e29d98eb/share/picongpu/pypicongpu/schema/simulation.Simulation.json

# for particle type see https://github.com/openPMD/openPMD-standard/blob/upcoming-2.0.0/EXT_SpeciesType.md
species_list = []
if not ENABLE_IONIZATION:
hydrogen = hydrogen_fully_ionized
interaction = None

electron_placed = picmi.Species(particle_type="electron", name="electron", initial_distribution=gaussianProfile)
species_list.append((electron_placed, random_layout))

if ENABLE_IONS:
hydrogen_fully_ionized = picmi.Species(
particle_type="H", name="hydrogen", picongpu_fixed_charge=True, initial_distribution=gaussianProfile
)
species_list.append((hydrogen_fully_ionized, random_layout))
else:
hydrogen = hydrogen_ionization
if not ENABLE_IONS:
raise ValueError("Ions species required for ionization")

hydrogen_with_ionization = picmi.Species(
particle_type="H", name="hydrogen", charge_state=0, initial_distribution=gaussianProfile
)
species_list.append((hydrogen_with_ionization, random_layout))

electron_not_placed = picmi.Species(particle_type="electron", name="electron", initial_distribution=None)
species_list.append((electron_not_placed, None))

adk_ionization_model = picmi.ADK(
ADK_variant=picmi.ADKVariant.CircularPolarization,
ion_species=hydrogen_ionization,
ionization_electron_species=electrons,
ion_species=hydrogen_with_ionization,
ionization_electron_species=electron_not_placed,
ionization_current=None,
)

bsi_effectiveZ_ionization_model = picmi.BSI(
BSI_extensions=[picmi.BSIExtension.EffectiveZ],
ion_species=hydrogen_ionization,
ionization_electron_species=electrons,
ion_species=hydrogen_with_ionization,
ionization_electron_species=electron_not_placed,
ionization_current=None,
)

Expand All @@ -111,11 +118,8 @@
picongpu_moving_window_move_point=0.9,
picongpu_interaction=interaction,
)

sim.add_species(electrons, layout=randomLayout)

if ENABLE_IONS:
sim.add_species(hydrogen, layout=randomLayout)
for species, layout in species_list:
sim.add_species(species, layout=layout)

sim.add_laser(laser, None)

Expand Down

0 comments on commit 8a462fd

Please sign in to comment.