Skip to content

Commit

Permalink
Continue averaging period logic
Browse files Browse the repository at this point in the history
- Implement warnings and errors for certain inputs concerning averaging periods
  • Loading branch information
n01r committed Sep 18, 2024
1 parent 07c707c commit 3ff90c9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Source/Diagnostics/FullDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public:
* Dynamic corresponds to a moving period for averaging where the start step
* is as many steps before the output interval as the averaging period is long.
*/
enum TimeAverageType {None, Static, Dynamic};
enum struct TimeAverageType {None, Static, Dynamic};
private:
/** Read user-requested parameters for full diagnostics */
void ReadParameters ();
Expand Down
53 changes: 42 additions & 11 deletions Source/Diagnostics/FullDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,32 @@ FullDiagnostics::ReadParameters ()
);
}

const bool averaging_period_steps_specified = pp_diag_name.query(
"average_period_steps", m_average_period_steps
);
const bool averaging_period_time_specified = pp_diag_name.queryWithParser(
"average_period_time", m_average_period_time
);

if (m_time_average_type == TimeAverageType::Static) {
// This fails if users do not specify a start.
pp_diag_name.get("average_start_step", m_average_start_step);

if (averaging_period_time_specified || averaging_period_steps_specified) {
const std::string period_spec_warn_msg = "An averaging period was specified for the 'static_start' averaging mode" \
"but will be IGNORED. Averaging will be performed between step" \
+ std::to_string(m_average_start_step) \
+ "and the specified intervals.";
ablastr::warn_manager::WMRecordWarning(
"Diagnostics",
period_spec_warn_msg,
ablastr::warn_manager::WarnPriority::medium
);
}

}

if (m_time_average_type == TimeAverageType::Dynamic) {
const bool averaging_period_steps_specified = pp_diag_name.query(
"average_period_steps", m_average_period_steps
);
const bool averaging_period_time_specified = pp_diag_name.queryWithParser(
"average_period_time", m_average_period_time
);
// one of the two averaging period options must be set but neither none nor both
if (
(averaging_period_steps_specified && averaging_period_time_specified)
Expand Down Expand Up @@ -218,20 +233,36 @@ FullDiagnostics::DoDump (int step, int /*i_buffer*/, bool force_flush)
bool
FullDiagnostics::DoComputeAndPack (int step, bool force_flush)
{
if (m_time_averaging == "dynamic_start") {
if (m_time_average_type == TimeAverageType::Dynamic) {
m_average_start_step = m_intervals.nextContains(step) - m_average_period_steps;
// check that the periods do not overlap and that the start step is not negative
if (m_average_start_step > 0) {
if (m_average_start_step < m_intervals.previousContains(step)) {
WARPX_ABORT_WITH_MESSAGE(
"Averaging periods may not overlap within a single diagnostic. "
"Please create a second diagnostic for overlapping time averaging periods "
"and account for the increased memory consumption."
);
} else {
WARPX_ABORT_WITH_MESSAGE("The step to begin time averaging may not be a negative number.");
}
}
}

// add logic here to do compute and pack if m_intervals.contains (step+1-time_average_period) or if (cur_step>time_average_startstep)
// Start averaging at output step (from diag.intervals) - period + 1
bool in_averaging_period = false;
if (step > m_intervals.nextContains(step) - m_average_start_step && step <= m_intervals.nextContains(step)) {
in_averaging_period = true;

if (m_time_average_type == TimeAverageType::Static) {
// Update time averaging period to current step
m_average_period_steps = step - m_average_start_step;
}
}

// Data must be computed and packed for full diagnostics
// whenever the data needs to be flushed.
return (force_flush || m_intervals.contains(step+1) || in_averaging_period);
//return (force_flush || m_intervals.contains(step+1) );

}

Expand Down Expand Up @@ -666,14 +697,14 @@ FullDiagnostics::InitializeBufferData (int i_buffer, int lev, bool restart ) {

if (m_time_average_type == TimeAverageType::Dynamic) {

// already checked in ReadParameters that only one of them is set
// already checked in ReadParameters that only one of the parameters is set
// calculate the other averaging period parameter from the other one, respectively
if (m_average_period_steps > 0) {
m_average_period_time = m_average_period_steps * warpx.getdt(0);
} else if (m_average_period_time > 0) {
m_average_period_steps = static_cast<int> (std::round(m_average_period_time / warpx.getdt(0)));
}

// CONTINUE HERE
}
}

Expand Down
2 changes: 0 additions & 2 deletions Source/Diagnostics/MultiDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <string>
#include <vector>

/** All types of diagnostics. */
enum struct DiagTypes {Full, BackTransformed, BoundaryScraping, TimeAveraged};

/**
* \brief This class contains a vector of all diagnostics in the simulation.
Expand Down
8 changes: 4 additions & 4 deletions Source/Diagnostics/MultiDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ MultiDiagnostics::MultiDiagnostics ()
alldiags.resize( ndiags );
for (int i=0; i<ndiags; i++){
if ( diags_types[i] == DiagTypes::Full ){
alldiags[i] = std::make_unique<FullDiagnostics>(i, diags_names[i]);
alldiags[i] = std::make_unique<FullDiagnostics>(i, diags_names[i], diags_types[i]);
} else if ( diags_types[i] == DiagTypes::TimeAveraged ){
alldiags[i] = std::make_unique<FullDiagnostics>(i, diags_names[i]);
alldiags[i] = std::make_unique<FullDiagnostics>(i, diags_names[i], diags_types[i]);
} else if ( diags_types[i] == DiagTypes::BackTransformed ){
alldiags[i] = std::make_unique<BTDiagnostics>(i, diags_names[i]);
alldiags[i] = std::make_unique<BTDiagnostics>(i, diags_names[i], diags_types[i]);
} else if ( diags_types[i] == DiagTypes::BoundaryScraping ){
alldiags[i] = std::make_unique<BoundaryScrapingDiagnostics>(i, diags_names[i]);
alldiags[i] = std::make_unique<BoundaryScrapingDiagnostics>(i, diags_names[i], diags_types[i]);
} else {
WARPX_ABORT_WITH_MESSAGE("Unknown diagnostic type");
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Diagnostics/WarpXOpenPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,8 @@ WarpXOpenPMDPlot::SetupFields ( openPMD::Container< openPMD::Mesh >& meshes,
if (WarpX::do_dive_cleaning) {
meshes.setAttribute("chargeCorrectionParameters", "period=1");
}
// TODO set meta-data information for time-averaged quantities
// but we need information of the specific diagnostic in here
}


Expand Down

0 comments on commit 3ff90c9

Please sign in to comment.