Skip to content

Commit d6c3bdf

Browse files
committed
Add docs and scope code in if envs
- added first documentation on time averaged diags - put more operations on summation multifabs into if-environments
1 parent 3ff90c9 commit d6c3bdf

File tree

3 files changed

+90
-39
lines changed

3 files changed

+90
-39
lines changed

Docs/source/usage/parameters.rst

+43-1
Original file line numberDiff line numberDiff line change
@@ -2618,8 +2618,9 @@ Diagnostics and output
26182618
In-situ visualization
26192619
^^^^^^^^^^^^^^^^^^^^^
26202620

2621-
WarpX has four types of diagnostics:
2621+
WarpX has five types of diagnostics:
26222622
``FullDiagnostics`` consist in dumps of fields and particles at given iterations,
2623+
``TimeAveragedDiagnostics`` only allow field data which they output after averaging over a period of time,
26232624
``BackTransformedDiagnostics`` are used when running a simulation in a boosted frame, to reconstruct output data to the lab frame,
26242625
``BoundaryScrapingDiagnostics`` are used to collect the particles that are absorbed at the boundary, throughout the simulation, and
26252626
``ReducedDiags`` allow the user to compute some reduced quantity (particle temperature, max of a field) and write a small amount of data to text files.
@@ -2867,6 +2868,47 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a
28672868
* ``warpx.mffile_nstreams`` (`int`) optional (default `4`)
28682869
Limit the number of concurrent readers per file.
28692870

2871+
2872+
.. _running-cpp-parameters-diagnostics-timeavg:
2873+
2874+
Time-Averaged Diagnostics
2875+
^^^^^^^^^^^^^^^^^^^^^^^^^
2876+
2877+
``TimeAveraged`` diagnostics are a special type of ``FullDiagnostics`` that allows for the output of time-averaged field data.
2878+
This type of diagnostics can be created using ``<diag_name>.diag_type = TimeAveraged``.
2879+
We support only field data and related options from the list at `Full Diagnostics`_.
2880+
2881+
In addition, `TimeAveraged` diagnostic options include:
2882+
2883+
* ``<diag_name>.time_average_mode`` (`string`, default `none`)
2884+
Describes the operating mode for time averaged field output.
2885+
2886+
* ``none`` for no averaging (instantaneous fields)
2887+
2888+
* ``fixed_start`` for a diagnostic that averages all fields between the current output step and a fixed point in time
2889+
2890+
* ``dynamic_start`` for a constant averaging period and output at different points in time (non-overlapping)
2891+
2892+
.. note::
2893+
2894+
To enable time-averaged field output with intervals tightly spaced enough for overlapping averaging periods,
2895+
please create additional instances of ``TimeAveraged`` diagnostics.
2896+
2897+
* ``<diag_name>.average_period_steps`` (`int`)
2898+
Configures the number of time steps in an averaging period.
2899+
Set this only in the ``dynamic_start`` mode and only if ``average_period_time`` has not already been set.
2900+
Will be ignored in the ``fixed_start`` mode (with warning).
2901+
2902+
* ``<diag_name>.average_period_time`` (`float`, in seconds)
2903+
Configures the time (SI units) in an averaging period.
2904+
Set this only in the ``dynamic_start`` mode and only if ``average_period_steps`` has not already been set.
2905+
Will be ignored in the ``fixed_start`` mode (with warning).
2906+
2907+
* ``<diag_name>.average_start_step`` (`int`)
2908+
Configures the time step at which time-averaging begins.
2909+
Set this only in the ``fixed_start`` mode.
2910+
Will be ignored in the ``dynamic_start`` mode (with warning).
2911+
28702912
.. _running-cpp-parameters-diagnostics-btd:
28712913

28722914
BackTransformed Diagnostics

Source/Diagnostics/FullDiagnostics.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private:
4343
amrex::Real m_average_period_time = 0;
4444
/** Time step to start averaging */
4545
int m_average_start_step = 0;
46-
/** Flush m_mf_output and particles to file for the i^th buffer */
46+
/** Flush m_mf_output or m_sum_mf_output and particles to file for the i^th buffer */
4747
void Flush (int i_buffer, bool /* force_flush */) override;
4848
/** Flush raw data */
4949
void FlushRaw ();

Source/Diagnostics/FullDiagnostics.cpp

+46-37
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,26 @@ FullDiagnostics::Flush ( int i_buffer, bool /* force_flush */ )
192192
// is supported for BackTransformed Diagnostics, in BTDiagnostics class.
193193
auto & warpx = WarpX::GetInstance();
194194

195-
m_flush_format->WriteToFile(
196-
m_varnames, m_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
197-
warpx.gett_new(0),
198-
m_output_species.at(i_buffer), nlev_output, m_file_prefix,
199-
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards);
195+
if (m_diag_type == DiagTypes::TimeAveraged) {
196+
if (m_time_average_type == TimeAverageType::Static || m_time_average_type == TimeAverageType::Dynamic) {
197+
// Loop over the output levels and divide by the number of steps in the averaging period
198+
for (int lev = 0; lev < nlev_output; ++lev) {
199+
m_sum_mf_output.at(i_buffer).at(lev).mult(1./m_average_period_steps);
200+
}
200201

201-
if (m_time_average_type == TimeAverageType::Static || m_time_average_type == TimeAverageType::Dynamic) {
202-
// Loop over the output levels and divide by the number of steps in the averaging period
203-
for (int lev = 0; lev < nlev_output; ++lev) {
204-
m_sum_mf_output.at(i_buffer).at(lev).mult(1./m_average_period_steps);
205-
}
202+
m_flush_format->WriteToFile(
203+
m_varnames, m_sum_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
204+
warpx.gett_new(0),
205+
m_output_species.at(i_buffer), nlev_output, m_file_prefix,
206+
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards);
206207

207-
m_flush_format->WriteToFile(
208-
m_varnames, m_sum_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
208+
}
209+
} else {
210+
m_flush_format->WriteToFile(
211+
m_varnames, m_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
209212
warpx.gett_new(0),
210213
m_output_species.at(i_buffer), nlev_output, m_file_prefix,
211214
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards);
212-
213215
}
214216

215217
FlushRaw();
@@ -233,30 +235,33 @@ FullDiagnostics::DoDump (int step, int /*i_buffer*/, bool force_flush)
233235
bool
234236
FullDiagnostics::DoComputeAndPack (int step, bool force_flush)
235237
{
236-
if (m_time_average_type == TimeAverageType::Dynamic) {
237-
m_average_start_step = m_intervals.nextContains(step) - m_average_period_steps;
238-
// check that the periods do not overlap and that the start step is not negative
239-
if (m_average_start_step > 0) {
240-
if (m_average_start_step < m_intervals.previousContains(step)) {
241-
WARPX_ABORT_WITH_MESSAGE(
242-
"Averaging periods may not overlap within a single diagnostic. "
243-
"Please create a second diagnostic for overlapping time averaging periods "
244-
"and account for the increased memory consumption."
245-
);
246-
} else {
247-
WARPX_ABORT_WITH_MESSAGE("The step to begin time averaging may not be a negative number.");
248-
}
249-
}
250-
}
251238

252239
// Start averaging at output step (from diag.intervals) - period + 1
253240
bool in_averaging_period = false;
254-
if (step > m_intervals.nextContains(step) - m_average_start_step && step <= m_intervals.nextContains(step)) {
255-
in_averaging_period = true;
241+
if (m_diag_type == DiagTypes::TimeAveraged) {
242+
if (m_time_average_type == TimeAverageType::Dynamic) {
243+
m_average_start_step = m_intervals.nextContains(step) - m_average_period_steps;
244+
// check that the periods do not overlap and that the start step is not negative
245+
if (m_average_start_step > 0) {
246+
if (m_average_start_step < m_intervals.previousContains(step)) {
247+
WARPX_ABORT_WITH_MESSAGE(
248+
"Averaging periods may not overlap within a single diagnostic. "
249+
"Please create a second diagnostic for overlapping time averaging periods "
250+
"and account for the increased memory consumption."
251+
);
252+
} else {
253+
WARPX_ABORT_WITH_MESSAGE("The step to begin time averaging may not be a negative number.");
254+
}
255+
}
256+
}
256257

257-
if (m_time_average_type == TimeAverageType::Static) {
258-
// Update time averaging period to current step
259-
m_average_period_steps = step - m_average_start_step;
258+
if (step > m_intervals.nextContains(step) - m_average_start_step && step <= m_intervals.nextContains(step)) {
259+
in_averaging_period = true;
260+
261+
if (m_time_average_type == TimeAverageType::Static) {
262+
// Update time averaging period to current step
263+
m_average_period_steps = step - m_average_start_step;
264+
}
260265
}
261266
}
262267

@@ -719,10 +724,14 @@ FullDiagnostics::InitializeBufferData (int i_buffer, int lev, bool restart ) {
719724
const int ngrow = (m_format == "sensei" || m_format == "ascent") ? 1 : 0;
720725
int const ncomp = static_cast<int>(m_varnames.size());
721726
m_mf_output[i_buffer][lev] = amrex::MultiFab(ba, dmap, ncomp, ngrow);
722-
// Allocate MultiFab for cell-centered field output accumulation. The data will be averaged before flushing.
723-
m_sum_mf_output[i_buffer][lev] = amrex::MultiFab(ba, dmap, ncomp, ngrow);
724-
// Initialize to zero because we add data.
725-
m_sum_mf_output[i_buffer][lev].setVal(0.);
727+
728+
if (m_diag_type == DiagTypes::TimeAveraged) {
729+
// Allocate MultiFab for cell-centered field output accumulation. The data will be averaged before flushing.
730+
m_sum_mf_output[i_buffer][lev] = amrex::MultiFab(ba, dmap, ncomp, ngrow);
731+
// Initialize to zero because we add data.
732+
m_sum_mf_output[i_buffer][lev].setVal(0.);
733+
}
734+
726735
if (lev == 0) {
727736
// The extent of the domain covered by the diag multifab, m_mf_output
728737
//default non-periodic geometry for diags

0 commit comments

Comments
 (0)