Skip to content

Commit 9e5346e

Browse files
Add reduced_diags general input (#5479)
This PR adds the `reduced_diags` input parameter group that allows setting of parameters common to all reduced diagnostics. For example 'reduced_diags.intervals` can be set once rather than having to set it for each individual reduced diagnostic. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 99a90a4 commit 9e5346e

File tree

9 files changed

+57
-27
lines changed

9 files changed

+57
-27
lines changed

Docs/source/usage/parameters.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,22 +3589,27 @@ This shifts analysis from post-processing to runtime calculation of reduction op
35893589
* ``Timestep``
35903590
This type outputs the simulation's physical timestep (in seconds) at each mesh refinement level.
35913591

3592-
* ``<reduced_diags_name>.intervals`` (`string`)
3592+
* ``reduced_diags.intervals`` (`string`)
35933593
Using the `Intervals Parser`_ syntax, this string defines the timesteps at which reduced
3594-
diagnostics are written to file.
3594+
diagnostics are written to the file.
3595+
This can also be specified for the specific diagnostic by setting ``<reduced_diags_name>.intervals``.
35953596

3596-
* ``<reduced_diags_name>.path`` (`string`) optional (default `./diags/reducedfiles/`)
3597-
The path that the output file will be stored.
3597+
* ``reduced_diags.path`` (`string`) optional (default `./diags/reducedfiles/`)
3598+
The path where the output file will be stored.
3599+
This can also be specified for the specific diagnostic by setting ``<reduced_diags_name>.path``.
35983600

3599-
* ``<reduced_diags_name>.extension`` (`string`) optional (default `txt`)
3600-
The extension of the output file.
3601+
* ``reduced_diags.extension`` (`string`) optional (default `txt`)
3602+
The extension of the output file (the suffix).
3603+
This can also be specified for the specific diagnostic by setting ``<reduced_diags_name>.extension``.
36013604

3602-
* ``<reduced_diags_name>.separator`` (`string`) optional (default a `whitespace`)
3605+
* ``reduced_diags.separator`` (`string`) optional (default a `whitespace`)
36033606
The separator between row values in the output file.
36043607
The default separator is a whitespace.
3608+
This can also be specified for the specific diagnostic by setting ``<reduced_diags_name>.separator``.
36053609

3606-
* ``<reduced_diags_name>.precision`` (`integer`) optional (default `14`)
3610+
* ``reduced_diags.precision`` (`integer`) optional (default `14`)
36073611
The precision used when writing out the data to the text files.
3612+
This can also be specified for the specific diagnostic by setting ``<reduced_diags_name>.precision``.
36083613

36093614
Lookup tables and other settings for QED modules
36103615
------------------------------------------------

Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc_picmi.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@
196196
histuH_rdiag = picmi.ReducedDiagnostic(
197197
diag_type="ParticleHistogram",
198198
name="histuH",
199-
period=100,
200199
species=hydrogen,
201200
bin_number=1000,
202201
bin_min=0.0,
@@ -208,7 +207,6 @@
208207
histue_rdiag = picmi.ReducedDiagnostic(
209208
diag_type="ParticleHistogram",
210209
name="histue",
211-
period=100,
212210
species=electrons,
213211
bin_number=1000,
214212
bin_min=0.0,
@@ -222,7 +220,6 @@
222220
histuzAll_rdiag = picmi.ReducedDiagnostic(
223221
diag_type="ParticleHistogram",
224222
name="histuzAll",
225-
period=100,
226223
species=hydrogen,
227224
bin_number=1000,
228225
bin_min=-0.474,
@@ -233,7 +230,6 @@
233230
field_probe_z_rdiag = picmi.ReducedDiagnostic(
234231
diag_type="FieldProbe",
235232
name="FieldProbe_Z",
236-
period=100,
237233
integrate=0,
238234
probe_geometry="Line",
239235
x_probe=0.0,
@@ -246,7 +242,6 @@
246242
field_probe_scat_point_rdiag = picmi.ReducedDiagnostic(
247243
diag_type="FieldProbe",
248244
name="FieldProbe_ScatPoint",
249-
period=1,
250245
integrate=0,
251246
probe_geometry="Point",
252247
x_probe=0.0,
@@ -256,7 +251,6 @@
256251
field_probe_scat_line_rdiag = picmi.ReducedDiagnostic(
257252
diag_type="FieldProbe",
258253
name="FieldProbe_ScatLine",
259-
period=100,
260254
integrate=1,
261255
probe_geometry="Line",
262256
x_probe=-2.5e-6,
@@ -267,7 +261,8 @@
267261
)
268262

269263
load_balance_costs_rdiag = picmi.ReducedDiagnostic(
270-
diag_type="LoadBalanceCosts", name="LBC", period=100
264+
diag_type="LoadBalanceCosts",
265+
name="LBC",
271266
)
272267

273268
# Set up simulation
@@ -278,6 +273,7 @@
278273
particle_shape="cubic",
279274
warpx_numprocs=[1, 2], # deactivate `numprocs` for dynamic load balancing
280275
warpx_use_filter=1,
276+
warpx_reduced_diags_intervals=100,
281277
warpx_load_balance_intervals=100,
282278
warpx_load_balance_costs_update="heuristic",
283279
)

Examples/Tests/implicit/inputs_test_1d_semi_implicit_picard

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ diag1.electrons.variables = z w ux uy uz
8585
diag1.protons.variables = z w ux uy uz
8686

8787
warpx.reduced_diags_names = particle_energy field_energy
88+
reduced_diags.intervals = 1
8889
particle_energy.type = ParticleEnergy
89-
particle_energy.intervals = 1
9090
field_energy.type = FieldEnergy
91-
field_energy.intervals = 1

Examples/Tests/implicit/inputs_test_1d_theta_implicit_picard

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ diag1.electrons.variables = z w ux uy uz
8585
diag1.protons.variables = z w ux uy uz
8686

8787
warpx.reduced_diags_names = particle_energy field_energy
88+
reduced_diags.intervals = 1
8889
particle_energy.type = ParticleEnergy
89-
particle_energy.intervals = 1
9090
field_energy.type = FieldEnergy
91-
field_energy.intervals = 1

Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ diag1.electrons.variables = x z w ux uy uz
109109
diag1.protons.variables = x z w ux uy uz
110110

111111
warpx.reduced_diags_names = particle_energy field_energy
112+
reduced_diags.intervals = 1
112113
particle_energy.type = ParticleEnergy
113-
particle_energy.intervals = 1
114114
field_energy.type = FieldEnergy
115-
field_energy.intervals = 1

Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb_filtered

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ diag1.electrons.variables = x z w ux uy uz
109109
diag1.protons.variables = x z w ux uy uz
110110

111111
warpx.reduced_diags_names = particle_energy field_energy
112+
reduced_diags.intervals = 1
112113
particle_energy.type = ParticleEnergy
113-
particle_energy.intervals = 1
114114
field_energy.type = FieldEnergy
115-
field_energy.intervals = 1

Examples/Tests/implicit/inputs_test_2d_theta_implicit_strang_psatd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ diag1.electrons.variables = x z w ux uy uz
9292
diag1.protons.variables = x z w ux uy uz
9393

9494
warpx.reduced_diags_names = particle_energy field_energy
95+
reduced_diags.intervals = 1
9596
particle_energy.type = ParticleEnergy
96-
particle_energy.intervals = 1
9797
field_energy.type = FieldEnergy
98-
field_energy.intervals = 1

Python/pywarpx/picmi.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,21 @@ class Simulation(picmistandard.PICMI_Simulation):
27702770
27712771
warpx_used_inputs_file: string, optional
27722772
The name of the text file that the used input parameters is written to,
2773+
2774+
warpx_reduced_diags_path: string, optional
2775+
Sets the default path for reduced diagnostic output files
2776+
2777+
warpx_reduced_diags_extension: string, optional
2778+
Sets the default extension for reduced diagnostic output files
2779+
2780+
warpx_reduced_diags_intervals: string, optional
2781+
Sets the default intervals for reduced diagnostic output files
2782+
2783+
warpx_reduced_diags_separator: string, optional
2784+
Sets the default separator for reduced diagnostic output files
2785+
2786+
warpx_reduced_diags_precision: integer, optional
2787+
Sets the default precision for reduced diagnostic output files
27732788
"""
27742789

27752790
# Set the C++ WarpX interface (see _libwarpx.LibWarpX) as an extension to
@@ -2836,6 +2851,12 @@ def init(self, kw):
28362851
self.checkpoint_signals = kw.pop("warpx_checkpoint_signals", None)
28372852
self.numprocs = kw.pop("warpx_numprocs", None)
28382853

2854+
self.reduced_diags_path = kw.pop("warpx_reduced_diags_path", None)
2855+
self.reduced_diags_extension = kw.pop("warpx_reduced_diags_extension", None)
2856+
self.reduced_diags_intervals = kw.pop("warpx_reduced_diags_intervals", None)
2857+
self.reduced_diags_separator = kw.pop("warpx_reduced_diags_separator", None)
2858+
self.reduced_diags_precision = kw.pop("warpx_reduced_diags_precision", None)
2859+
28392860
self.inputs_initialized = False
28402861
self.warpx_initialized = False
28412862

@@ -2902,6 +2923,13 @@ def initialize_inputs(self):
29022923

29032924
pywarpx.warpx.numprocs = self.numprocs
29042925

2926+
reduced_diags = pywarpx.warpx.get_bucket("reduced_diags")
2927+
reduced_diags.path = self.reduced_diags_path
2928+
reduced_diags.extension = self.reduced_diags_extension
2929+
reduced_diags.intervals = self.reduced_diags_intervals
2930+
reduced_diags.separator = self.reduced_diags_separator
2931+
reduced_diags.precision = self.reduced_diags_precision
2932+
29052933
particle_shape = self.particle_shape
29062934
for s in self.species:
29072935
if s.particle_shape is not None:
@@ -3943,7 +3971,7 @@ def __init__(
39433971
self,
39443972
diag_type,
39453973
name=None,
3946-
period=1,
3974+
period=None,
39473975
path=None,
39483976
extension=None,
39493977
separator=None,

Source/Diagnostics/ReducedDiags/ReducedDiags.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ m_rd_name{rd_name}
2828
{
2929
BackwardCompatibility();
3030

31+
const ParmParse pp_rd("reduced_diags");
3132
const ParmParse pp_rd_name(m_rd_name);
3233

3334
// read path
35+
pp_rd.query("path", m_path);
3436
pp_rd_name.query("path", m_path);
3537

3638
// read extension
39+
pp_rd.query("extension", m_extension);
3740
pp_rd_name.query("extension", m_extension);
3841

3942
// check if it is a restart run
@@ -61,13 +64,16 @@ m_rd_name{rd_name}
6164

6265
// read reduced diags intervals
6366
std::vector<std::string> intervals_string_vec = {"1"};
64-
pp_rd_name.getarr("intervals", intervals_string_vec);
67+
pp_rd.queryarr("intervals", intervals_string_vec);
68+
pp_rd_name.queryarr("intervals", intervals_string_vec);
6569
m_intervals = utils::parser::IntervalsParser(intervals_string_vec);
6670

6771
// read separator
72+
pp_rd.query("separator", m_sep);
6873
pp_rd_name.query("separator", m_sep);
6974

7075
// precision of data in the output file
76+
utils::parser::queryWithParser(pp_rd, "precision", m_precision);
7177
utils::parser::queryWithParser(pp_rd_name, "precision", m_precision);
7278
}
7379
// end constructor

0 commit comments

Comments
 (0)