Skip to content

Commit da0a1f4

Browse files
authored
Implemented new particle diagnostics in picmi (#984)
* Implemented new particle diagnostics in picmi * Cleaned up picmi adding new particle diagnostics * In PICMI examples, use name option for diagnostics * For travis, update ubuntu version to bionic
1 parent 4a65dd2 commit da0a1f4

File tree

12 files changed

+121
-50
lines changed

12 files changed

+121
-50
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# License: BSD-3-Clause-LBNL
77

8-
dist: xenial
8+
dist: bionic
99
language: c++
1010
sudo: true
1111
cache: pip

Examples/Modules/gaussian_beam/PICMI_inputs_gaussian_beam.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=electron_beam)
4444
protons = picmi.Species(particle_type='proton', name='protons', initial_distribution=proton_beam)
4545

46-
field_diag1 = picmi.FieldDiagnostic(grid = grid,
46+
field_diag1 = picmi.FieldDiagnostic(name = 'diag1',
47+
grid = grid,
4748
period = 10,
4849
data_list = ['E', 'B', 'J', 'part_per_cell'],
4950
warpx_file_prefix = 'plotfiles/plt')
5051

51-
part_diag1 = picmi.ParticleDiagnostic(period = 10,
52+
part_diag1 = picmi.ParticleDiagnostic(name = 'diag1',
53+
period = 10,
5254
species = [electrons, protons],
5355
data_list = ['weighting', 'momentum', 'fields'])
5456

Examples/Physics_applications/laser_acceleration/PICMI_inputs_laser_acceleration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@
100100
# diagnostics
101101
##########################
102102

103-
field_diag1 = picmi.FieldDiagnostic(grid = grid,
103+
field_diag1 = picmi.FieldDiagnostic(name = 'diag1',
104+
grid = grid,
104105
period = 10)
105106

106-
part_diag1 = picmi.ParticleDiagnostic(period = 10,
107+
part_diag1 = picmi.ParticleDiagnostic(name = 'diag1',
108+
period = 10,
107109
species = [electrons])
108110

109111
##########################

Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@
5151
sim.add_species(beam, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))
5252
sim.add_species(plasma, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))
5353

54-
field_diag = picmi.FieldDiagnostic(grid = grid,
54+
field_diag = picmi.FieldDiagnostic(name = 'diag1',
55+
grid = grid,
5556
period = max_steps,
5657
data_list = ['Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz', 'part_per_cell'],
5758
write_dir = 'diags',
5859
warpx_file_prefix = 'plotfiles/plt')
5960

60-
part_diag = picmi.ParticleDiagnostic(period = max_steps,
61+
part_diag = picmi.ParticleDiagnostic(name = 'diag1',
62+
period = max_steps,
6163
species = [beam, plasma],
6264
data_list = ['ux', 'uy', 'uz', 'weighting', 'Ex', 'Ey', 'Ez'],
6365
write_dir = 'diags')

Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_mr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@
5757
sim.add_species(beam, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))
5858
sim.add_species(plasma, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim))
5959

60-
field_diag = picmi.FieldDiagnostic(grid = grid,
60+
field_diag = picmi.FieldDiagnostic(name = 'diag1',
61+
grid = grid,
6162
period = 2,
6263
data_list = ['Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz', 'part_per_cell'],
6364
write_dir = 'diags',
6465
warpx_file_prefix = 'plotfiles/plt')
6566

66-
part_diag = picmi.ParticleDiagnostic(period = 2,
67+
part_diag = picmi.ParticleDiagnostic(name = 'diag1',
68+
period = 2,
6769
species = [beam, plasma],
6870
data_list = ['ux', 'uy', 'uz', 'weighting', 'Ex', 'Ey', 'Ez'],
6971
write_dir = 'diags')

Examples/Tests/Langmuir/PICMI_inputs_langmuir2d.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@
6060
# diagnostics
6161
##########################
6262

63-
field_diag1 = picmi.FieldDiagnostic(grid = grid,
63+
field_diag1 = picmi.FieldDiagnostic(name = 'diag1',
64+
grid = grid,
6465
period = diagnostic_interval,
6566
data_list = ['Ex', 'Jx'],
6667
warpx_file_prefix = 'plotfiles/plt')
6768

68-
part_diag1 = picmi.ParticleDiagnostic(period = diagnostic_interval,
69+
part_diag1 = picmi.ParticleDiagnostic(name = 'diag1',
70+
period = diagnostic_interval,
6971
species = [electrons],
7072
data_list = ['weighting', 'ux', 'Ex'])
7173

@@ -90,7 +92,7 @@
9092

9193
# write_inputs will create an inputs file that can be used to run
9294
# with the compiled version.
93-
#sim.write_input_file(file_name = 'inputs2d_from_PICMI')
95+
sim.write_input_file(file_name = 'inputs2d_from_PICMI')
9496

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

Examples/Tests/Langmuir/PICMI_inputs_langmuir_rt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@
6262
# diagnostics
6363
##########################
6464

65-
field_diag1 = picmi.FieldDiagnostic(grid = grid,
65+
field_diag1 = picmi.FieldDiagnostic(name = 'diag1',
66+
grid = grid,
6667
period = diagnostic_interval,
6768
data_list = ['Ex', 'Jx'],
6869
warpx_file_prefix = 'plotfiles/plt')
6970

70-
part_diag1 = picmi.ParticleDiagnostic(period = diagnostic_interval,
71+
part_diag1 = picmi.ParticleDiagnostic(name = 'diag1',
72+
period = diagnostic_interval,
7173
species = [electrons],
7274
data_list = ['weighting', 'ux', 'Ex'])
7375

Examples/Tests/Langmuir/PICMI_inputs_langmuir_rz_multimode_analyze.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@
9595
# diagnostics
9696
##########################
9797

98-
field_diag1 = picmi.FieldDiagnostic(grid = grid,
98+
field_diag1 = picmi.FieldDiagnostic(name = 'diag1',
99+
grid = grid,
99100
period = diagnostic_interval,
100101
data_list = ['E', 'B', 'J', 'part_per_cell'],
101102
warpx_file_prefix = 'plotfiles/plt')
102103

103-
part_diag1 = picmi.ParticleDiagnostic(period = diagnostic_interval,
104+
part_diag1 = picmi.ParticleDiagnostic(name = 'diag1',
105+
period = diagnostic_interval,
104106
species = [electrons],
105107
data_list = ['weighting', 'momentum', 'fields'])
106108

Python/pywarpx/Bucket.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ class Bucket(object):
1515
def __init__(self, instancename, **defaults):
1616
self._localsetattr('instancename', instancename)
1717
self._localsetattr('argvattrs', {})
18-
self.argvattrs.update(defaults)
18+
for name, value in defaults.items():
19+
self.add_new_attr(name, value)
1920

2021
def _localsetattr(self, name, value):
2122
object.__setattr__(self, name, value)
2223

24+
def add_new_attr(self, name, value):
25+
"""Names starting with "_" are make instance attributes.
26+
Otherwise the attribute is added to the args list.
27+
"""
28+
if name.startswith('_'):
29+
self._localsetattr(name, value)
30+
else:
31+
self.argvattrs[name] = value
32+
2333
def __setattr__(self, name, value):
24-
self.argvattrs[name] = value
34+
self.add_new_attr(name, value)
2535

2636
def __getattr__(self, name):
2737
try:

Python/pywarpx/Diagnostics.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
from .Bucket import Bucket
88

9-
diagnostics = Bucket('diagnostics', diags_names=[])
10-
diagnostics_list = []
9+
diagnostics = Bucket('diagnostics', _diagnostics_dict={})
10+
11+
class Diagnostic(Bucket):
12+
"""
13+
This is the same as a Bucket, but checks that any attributes are always given the same value.
14+
"""
15+
def add_new_attr_with_check(self, name, value):
16+
if name.startswith('_'):
17+
self._localsetattr(name, value)
18+
else:
19+
if name in self.argvattrs:
20+
assert value == self.argvattrs[name], Exception(f'Diagnostic attributes not consistent for {self.instancename}')
21+
self.argvattrs[name] = value
22+
23+
def __setattr__(self, name, value):
24+
self.add_new_attr_with_check(name, value)
1125

0 commit comments

Comments
 (0)