Skip to content

Commit

Permalink
Add reduced_diags general input (ECP-WarpX#5479)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dpgrote and pre-commit-ci[bot] authored Dec 4, 2024
1 parent 99a90a4 commit 9e5346e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 27 deletions.
21 changes: 13 additions & 8 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3589,22 +3589,27 @@ This shifts analysis from post-processing to runtime calculation of reduction op
* ``Timestep``
This type outputs the simulation's physical timestep (in seconds) at each mesh refinement level.

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

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

* ``<reduced_diags_name>.extension`` (`string`) optional (default `txt`)
The extension of the output file.
* ``reduced_diags.extension`` (`string`) optional (default `txt`)
The extension of the output file (the suffix).
This can also be specified for the specific diagnostic by setting ``<reduced_diags_name>.extension``.

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

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

Lookup tables and other settings for QED modules
------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@
histuH_rdiag = picmi.ReducedDiagnostic(
diag_type="ParticleHistogram",
name="histuH",
period=100,
species=hydrogen,
bin_number=1000,
bin_min=0.0,
Expand All @@ -208,7 +207,6 @@
histue_rdiag = picmi.ReducedDiagnostic(
diag_type="ParticleHistogram",
name="histue",
period=100,
species=electrons,
bin_number=1000,
bin_min=0.0,
Expand All @@ -222,7 +220,6 @@
histuzAll_rdiag = picmi.ReducedDiagnostic(
diag_type="ParticleHistogram",
name="histuzAll",
period=100,
species=hydrogen,
bin_number=1000,
bin_min=-0.474,
Expand All @@ -233,7 +230,6 @@
field_probe_z_rdiag = picmi.ReducedDiagnostic(
diag_type="FieldProbe",
name="FieldProbe_Z",
period=100,
integrate=0,
probe_geometry="Line",
x_probe=0.0,
Expand All @@ -246,7 +242,6 @@
field_probe_scat_point_rdiag = picmi.ReducedDiagnostic(
diag_type="FieldProbe",
name="FieldProbe_ScatPoint",
period=1,
integrate=0,
probe_geometry="Point",
x_probe=0.0,
Expand All @@ -256,7 +251,6 @@
field_probe_scat_line_rdiag = picmi.ReducedDiagnostic(
diag_type="FieldProbe",
name="FieldProbe_ScatLine",
period=100,
integrate=1,
probe_geometry="Line",
x_probe=-2.5e-6,
Expand All @@ -267,7 +261,8 @@
)

load_balance_costs_rdiag = picmi.ReducedDiagnostic(
diag_type="LoadBalanceCosts", name="LBC", period=100
diag_type="LoadBalanceCosts",
name="LBC",
)

# Set up simulation
Expand All @@ -278,6 +273,7 @@
particle_shape="cubic",
warpx_numprocs=[1, 2], # deactivate `numprocs` for dynamic load balancing
warpx_use_filter=1,
warpx_reduced_diags_intervals=100,
warpx_load_balance_intervals=100,
warpx_load_balance_costs_update="heuristic",
)
Expand Down
3 changes: 1 addition & 2 deletions Examples/Tests/implicit/inputs_test_1d_semi_implicit_picard
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ diag1.electrons.variables = z w ux uy uz
diag1.protons.variables = z w ux uy uz

warpx.reduced_diags_names = particle_energy field_energy
reduced_diags.intervals = 1
particle_energy.type = ParticleEnergy
particle_energy.intervals = 1
field_energy.type = FieldEnergy
field_energy.intervals = 1
3 changes: 1 addition & 2 deletions Examples/Tests/implicit/inputs_test_1d_theta_implicit_picard
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ diag1.electrons.variables = z w ux uy uz
diag1.protons.variables = z w ux uy uz

warpx.reduced_diags_names = particle_energy field_energy
reduced_diags.intervals = 1
particle_energy.type = ParticleEnergy
particle_energy.intervals = 1
field_energy.type = FieldEnergy
field_energy.intervals = 1
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ diag1.electrons.variables = x z w ux uy uz
diag1.protons.variables = x z w ux uy uz

warpx.reduced_diags_names = particle_energy field_energy
reduced_diags.intervals = 1
particle_energy.type = ParticleEnergy
particle_energy.intervals = 1
field_energy.type = FieldEnergy
field_energy.intervals = 1
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ diag1.electrons.variables = x z w ux uy uz
diag1.protons.variables = x z w ux uy uz

warpx.reduced_diags_names = particle_energy field_energy
reduced_diags.intervals = 1
particle_energy.type = ParticleEnergy
particle_energy.intervals = 1
field_energy.type = FieldEnergy
field_energy.intervals = 1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ diag1.electrons.variables = x z w ux uy uz
diag1.protons.variables = x z w ux uy uz

warpx.reduced_diags_names = particle_energy field_energy
reduced_diags.intervals = 1
particle_energy.type = ParticleEnergy
particle_energy.intervals = 1
field_energy.type = FieldEnergy
field_energy.intervals = 1
30 changes: 29 additions & 1 deletion Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2770,6 +2770,21 @@ class Simulation(picmistandard.PICMI_Simulation):
warpx_used_inputs_file: string, optional
The name of the text file that the used input parameters is written to,
warpx_reduced_diags_path: string, optional
Sets the default path for reduced diagnostic output files
warpx_reduced_diags_extension: string, optional
Sets the default extension for reduced diagnostic output files
warpx_reduced_diags_intervals: string, optional
Sets the default intervals for reduced diagnostic output files
warpx_reduced_diags_separator: string, optional
Sets the default separator for reduced diagnostic output files
warpx_reduced_diags_precision: integer, optional
Sets the default precision for reduced diagnostic output files
"""

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

self.reduced_diags_path = kw.pop("warpx_reduced_diags_path", None)
self.reduced_diags_extension = kw.pop("warpx_reduced_diags_extension", None)
self.reduced_diags_intervals = kw.pop("warpx_reduced_diags_intervals", None)
self.reduced_diags_separator = kw.pop("warpx_reduced_diags_separator", None)
self.reduced_diags_precision = kw.pop("warpx_reduced_diags_precision", None)

self.inputs_initialized = False
self.warpx_initialized = False

Expand Down Expand Up @@ -2902,6 +2923,13 @@ def initialize_inputs(self):

pywarpx.warpx.numprocs = self.numprocs

reduced_diags = pywarpx.warpx.get_bucket("reduced_diags")
reduced_diags.path = self.reduced_diags_path
reduced_diags.extension = self.reduced_diags_extension
reduced_diags.intervals = self.reduced_diags_intervals
reduced_diags.separator = self.reduced_diags_separator
reduced_diags.precision = self.reduced_diags_precision

particle_shape = self.particle_shape
for s in self.species:
if s.particle_shape is not None:
Expand Down Expand Up @@ -3943,7 +3971,7 @@ def __init__(
self,
diag_type,
name=None,
period=1,
period=None,
path=None,
extension=None,
separator=None,
Expand Down
8 changes: 7 additions & 1 deletion Source/Diagnostics/ReducedDiags/ReducedDiags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ m_rd_name{rd_name}
{
BackwardCompatibility();

const ParmParse pp_rd("reduced_diags");
const ParmParse pp_rd_name(m_rd_name);

// read path
pp_rd.query("path", m_path);
pp_rd_name.query("path", m_path);

// read extension
pp_rd.query("extension", m_extension);
pp_rd_name.query("extension", m_extension);

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

// read reduced diags intervals
std::vector<std::string> intervals_string_vec = {"1"};
pp_rd_name.getarr("intervals", intervals_string_vec);
pp_rd.queryarr("intervals", intervals_string_vec);
pp_rd_name.queryarr("intervals", intervals_string_vec);
m_intervals = utils::parser::IntervalsParser(intervals_string_vec);

// read separator
pp_rd.query("separator", m_sep);
pp_rd_name.query("separator", m_sep);

// precision of data in the output file
utils::parser::queryWithParser(pp_rd, "precision", m_precision);
utils::parser::queryWithParser(pp_rd_name, "precision", m_precision);
}
// end constructor
Expand Down

0 comments on commit 9e5346e

Please sign in to comment.