Skip to content

Commit 2a9f577

Browse files
Add ability to load particles from openPMD, through the PICMI interface (#6305)
Do no merge until picmi-standard/picmi#127 is merged and a new PICMI version is released. It also adds a corresponding automated test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d021649 commit 2a9f577

File tree

9 files changed

+128
-4
lines changed

9 files changed

+128
-4
lines changed

Docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ docutils>=0.17.1
1111

1212
# PICMI API docs
1313
# note: keep in sync with version in ../requirements.txt
14-
picmistandard==0.33.0
14+
picmistandard==0.34.0
1515
# for development against an unreleased PICMI version, use:
1616
# picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python
1717

Docs/source/usage/python.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ Particle distributions can be used for to initialize particles in a particle spe
152152

153153
.. autoclass:: pywarpx.picmi.ParticleListDistribution
154154

155+
.. autoclass:: pywarpx.picmi.FromFileDistribution
156+
155157
Particle layouts determine how to microscopically place macro particles in a grid cell.
156158

157159
.. autoclass:: pywarpx.picmi.GriddedLayout

Examples/Tests/gaussian_beam/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ add_warpx_test(
2121
test_3d_focusing_gaussian_beam_from_openpmd_prepare # dependency
2222
)
2323

24+
add_warpx_test(
25+
test_3d_focusing_gaussian_beam_from_openpmd_picmi # name
26+
3 # dims
27+
2 # nprocs
28+
inputs_test_3d_focusing_gaussian_beam_from_openpmd_picmi.py # inputs
29+
"analysis_focusing_beam.py" # analysis
30+
"analysis_default_regression.py --path diags/diag1000000" # checksum
31+
test_3d_focusing_gaussian_beam_from_openpmd_prepare # dependency
32+
)
33+
2434
add_warpx_test(
2535
test_3d_focusing_gaussian_beam_from_openpmd_prepare # name
2636
3 # dims
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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()

Python/pywarpx/picmi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,17 @@ def distribution_initialize_inputs(
905905
)
906906

907907

908+
class FromFileDistribution(picmistandard.PICMI_FromFileDistribution):
909+
def init(self, kw):
910+
pass
911+
912+
def distribution_initialize_inputs(
913+
self, species_number, layout, species, density_scale, source_name
914+
):
915+
species.add_new_group_attr(source_name, "injection_style", "external_file")
916+
species.add_new_group_attr(source_name, "injection_file", self.file_path)
917+
918+
908919
class ParticleDistributionPlanarInjector(
909920
picmistandard.PICMI_ParticleDistributionPlanarInjector
910921
):

Python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
package_dir={"pywarpx": "pywarpx"},
7878
description="""Wrapper of WarpX""",
7979
package_data=package_data,
80-
install_requires=["numpy", "picmistandard==0.33.0", "periodictable"],
80+
install_requires=["numpy", "picmistandard==0.34.0", "periodictable"],
8181
python_requires=">=3.8", # left for CI, truly ">=3.9"
8282
zip_safe=False,
8383
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"beam1": {
3+
"particle_momentum_x": 4.222627241785717e-14,
4+
"particle_momentum_y": 1.131583197131103e-15,
5+
"particle_momentum_z": 1.3360487849541085e-10,
6+
"particle_position_x": 1.1288391053970308,
7+
"particle_position_y": 0.02391393806881765,
8+
"particle_position_z": 478.7122905262462,
9+
"particle_weight": 19999660000.0
10+
},
11+
"lev=0": {}
12+
}

Tools/machines/karolina-it4i/install_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ python -m pip install --user --upgrade matplotlib
5353
#python -m pip install --user --upgrade yt
5454

5555
# install or update WarpX dependencies
56-
python -m pip install --user --upgrade picmistandard==0.33.0
56+
python -m pip install --user --upgrade picmistandard==0.34.0
5757
python -m pip install --user --upgrade lasy
5858

5959
# optional: for optimas (based on libEnsemble & ax->botorch->gpytorch->pytorch)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ periodictable~=1.5
44

55
# PICMI
66
# note: don't forget to update the version in Docs/requirements.txt, too
7-
picmistandard==0.33.0
7+
picmistandard==0.34.0
88
# for development against an unreleased PICMI version, use:
99
#picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python
1010

0 commit comments

Comments
 (0)