Skip to content

Commit

Permalink
Add verbosity flag for diagnostic output print statements (#5503)
Browse files Browse the repository at this point in the history
This PR passes the `warpx.verbose` value to diagnostics to set whether a
message is output when the diagnostic is active. Specifically, this
helps with the time-averaged diagnostic where currently a message is
print at every step that averaging is done (commonly every step).

---------

Signed-off-by: roelof-groenewald <[email protected]>
  • Loading branch information
roelof-groenewald authored Dec 11, 2024
1 parent 66204fe commit 540268f
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Source/Diagnostics/BTDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ BTDiagnostics::Flush (int i_buffer, bool force_flush)
m_varnames, m_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
labtime,
m_output_species.at(i_buffer), nlev_output, file_name, m_file_min_digits,
m_plot_raw_fields, m_plot_raw_fields_guards,
m_plot_raw_fields, m_plot_raw_fields_guards, m_verbose,
use_pinned_pc, isBTD, i_buffer, m_buffer_flush_counter.at(i_buffer),
m_max_buffer_multifabs.at(i_buffer), m_geom_snapshot.at(i_buffer).at(0), isLastBTDFlush);

Expand Down
2 changes: 1 addition & 1 deletion Source/Diagnostics/BoundaryScrapingDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ BoundaryScrapingDiagnostics::Flush (int i_buffer, bool /* force_flush */)
warpx.gett_new(0),
m_output_species.at(i_buffer),
nlev_output, file_prefix,
m_file_min_digits, false, false, use_pinned_pc, isBTD,
m_file_min_digits, false, false, m_verbose, use_pinned_pc, isBTD,
warpx.getistep(0), bufferID, numBTDBuffers, geom,
isLastBTD);

Expand Down
2 changes: 2 additions & 0 deletions Source/Diagnostics/Diagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public:
protected:
/** Read Parameters of the base Diagnostics class */
bool BaseReadParameters ();
/** Whether to output a message when diagnostics are output */
int m_verbose = 2;
/** Initialize member variables of the base Diagnostics class. */
void InitBaseData ();
/** Initialize m_mf_output vectors and data required to construct the buffers
Expand Down
3 changes: 3 additions & 0 deletions Source/Diagnostics/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Diagnostics::BaseReadParameters ()
std::string dims;
pp_geometry.get("dims", dims);

const amrex::ParmParse pp_warpx("warpx");
pp_warpx.query("verbose", m_verbose);

// Query list of grid fields to write to output
const bool varnames_specified = pp_diag_name.queryarr("fields_to_plot", m_varnames_fields);
if (!varnames_specified){
Expand Down
1 change: 1 addition & 0 deletions Source/Diagnostics/FlushFormats/FlushFormat.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public:
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose = 2,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatAscent.H
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public:
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose = 2,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
const amrex::Geometry& full_BTD_snapshot = amrex::Geometry(),
bool isLastBTDFlush = false ) const override;
bool isLastBTDFlush = false) const override;

FlushFormatAscent () = default;
~FlushFormatAscent() override = default;
Expand Down
7 changes: 5 additions & 2 deletions Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ FlushFormatAscent::WriteToFile (
const amrex::Vector<ParticleDiag>& particle_diags, int nlev,
const std::string prefix, int file_min_digits, bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose,
const bool /*use_pinned_pc*/,
bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/,
Expand All @@ -32,7 +33,9 @@ FlushFormatAscent::WriteToFile (
"In-situ visualization is not currently supported for back-transformed diagnostics.");

const std::string& filename = amrex::Concatenate(prefix, iteration[0], file_min_digits);
amrex::Print() << Utils::TextMsg::Info("Writing Ascent file " + filename);
if (verbose > 0) {
amrex::Print() << Utils::TextMsg::Info("Writing Ascent file " + filename);
}

// wrap mesh data
WARPX_PROFILE_VAR("FlushFormatAscent::WriteToFile::MultiLevelToBlueprint", prof_ascent_mesh_blueprint);
Expand Down Expand Up @@ -67,7 +70,7 @@ FlushFormatAscent::WriteToFile (

#else
amrex::ignore_unused(varnames, mf, geom, iteration, time,
particle_diags, nlev, file_min_digits, isBTD);
particle_diags, nlev, file_min_digits, verbose, isBTD);
#endif // AMREX_USE_ASCENT
amrex::ignore_unused(prefix, plot_raw_fields, plot_raw_fields_guards);
}
1 change: 1 addition & 0 deletions Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public:
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose = 2,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
Expand Down
1 change: 1 addition & 0 deletions Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ FlushFormatCatalyst::WriteToFile (
const amrex::Vector<ParticleDiag>& particle_diags, int nlev,
const std::string prefix, int file_min_digits, bool plot_raw_fields,
bool plot_raw_fields_guards,
int /*verbose*/,
bool /*use_pinned_pc*/,
bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/,
Expand Down
1 change: 1 addition & 0 deletions Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.H
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FlushFormatCheckpoint final : public FlushFormatPlotfile
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose = 2,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
Expand Down
7 changes: 5 additions & 2 deletions Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ FlushFormatCheckpoint::WriteToFile (
const std::string prefix, int file_min_digits,
bool /*plot_raw_fields*/,
bool /*plot_raw_fields_guards*/,
int verbose,
const bool /*use_pinned_pc*/,
bool /*isBTD*/, int /*snapshotID*/,
int /*bufferID*/, int /*numBuffers*/,
Expand All @@ -56,8 +57,10 @@ FlushFormatCheckpoint::WriteToFile (

const std::string& checkpointname = amrex::Concatenate(prefix, iteration[0], file_min_digits);

amrex::Print() << Utils::TextMsg::Info(
"Writing checkpoint " + checkpointname);
if (verbose > 0) {
amrex::Print() << Utils::TextMsg::Info(
"Writing checkpoint " + checkpointname);
}

// const int nlevels = finestLevel()+1;
amrex::PreBuildDirectorHierarchy(checkpointname, default_level_prefix, nlev, true);
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public:
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
const amrex::Geometry& full_BTD_snapshot = amrex::Geometry(),
bool isLastBTDFlush = false ) const override;
bool isLastBTDFlush = false) const override;

~FlushFormatOpenPMD () override = default;

Expand Down
21 changes: 12 additions & 9 deletions Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,26 @@ FlushFormatOpenPMD::WriteToFile (
const amrex::Vector<ParticleDiag>& particle_diags, int output_levels,
const std::string prefix, int file_min_digits, bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose,
const bool use_pinned_pc,
bool isBTD, int snapshotID, int bufferID, int numBuffers,
const amrex::Geometry& full_BTD_snapshot,
bool isLastBTDFlush) const
{
WARPX_PROFILE("FlushFormatOpenPMD::WriteToFile()");
const std::string& filename = amrex::Concatenate(prefix, iteration[0], file_min_digits);
if (!isBTD)
{
amrex::Print() << Utils::TextMsg::Info("Writing openPMD file " + filename);
} else
{
amrex::Print() << Utils::TextMsg::Info("Writing buffer " + std::to_string(bufferID+1) + " of " + std::to_string(numBuffers)
+ " to snapshot " + std::to_string(snapshotID) + " to openPMD BTD " + prefix);
if (isLastBTDFlush)
if (verbose > 0) {
if (!isBTD)
{
amrex::Print() << Utils::TextMsg::Info("Writing openPMD file " + filename);
} else
{
amrex::Print() << Utils::TextMsg::Info("Finished writing snapshot " + std::to_string(snapshotID) + " in openPMD BTD " + prefix);
amrex::Print() << Utils::TextMsg::Info("Writing buffer " + std::to_string(bufferID+1) + " of " + std::to_string(numBuffers)
+ " to snapshot " + std::to_string(snapshotID) + " to openPMD BTD " + prefix);
if (isLastBTDFlush)
{
amrex::Print() << Utils::TextMsg::Info("Finished writing snapshot " + std::to_string(snapshotID) + " in openPMD BTD " + prefix);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public:
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose = 2,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
Expand Down
25 changes: 14 additions & 11 deletions Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ FlushFormatPlotfile::WriteToFile (
const amrex::Vector<ParticleDiag>& particle_diags, int nlev,
const std::string prefix, int file_min_digits, bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose,
const bool /*use_pinned_pc*/,
bool isBTD, int snapshotID, int bufferID, int numBuffers,
const amrex::Geometry& /*full_BTD_snapshot*/,
Expand All @@ -74,17 +75,19 @@ FlushFormatPlotfile::WriteToFile (
WARPX_PROFILE("FlushFormatPlotfile::WriteToFile()");
auto & warpx = WarpX::GetInstance();
const std::string& filename = amrex::Concatenate(prefix, iteration[0], file_min_digits);
if (!isBTD)
{
amrex::Print() << Utils::TextMsg::Info("Writing plotfile " + filename);
} else
{
amrex::Print() << Utils::TextMsg::Info("Writing buffer " + std::to_string(bufferID+1) + " of " + std::to_string(numBuffers)
+ " to snapshot " + std::to_string(snapshotID) + " in plotfile BTD " + prefix );
if (isLastBTDFlush)
{
amrex::Print() << Utils::TextMsg::Info("Finished writing snapshot " + std::to_string(snapshotID) + " in plotfile BTD " + filename);
}
if (verbose > 0) {
if (!isBTD)
{
amrex::Print() << Utils::TextMsg::Info("Writing plotfile " + filename);
} else
{
amrex::Print() << Utils::TextMsg::Info("Writing buffer " + std::to_string(bufferID+1) + " of " + std::to_string(numBuffers)
+ " to snapshot " + std::to_string(snapshotID) + " in plotfile BTD " + prefix );
if (isLastBTDFlush)
{
amrex::Print() << Utils::TextMsg::Info("Finished writing snapshot " + std::to_string(snapshotID) + " in plotfile BTD " + filename);
}
}
}

Vector<std::string> rfs;
Expand Down
1 change: 1 addition & 0 deletions Source/Diagnostics/FlushFormats/FlushFormatSensei.H
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public:
std::string prefix, int file_min_digits,
bool plot_raw_fields,
bool plot_raw_fields_guards,
int verbose = 2,
bool use_pinned_pc = false,
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
Expand Down
8 changes: 5 additions & 3 deletions Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ FlushFormatSensei::WriteToFile (
const amrex::Vector<ParticleDiag>& particle_diags,
int nlev, const std::string prefix, int file_min_digits,
bool plot_raw_fields, bool plot_raw_fields_guards,
const bool use_pinned_pc,
int verbose, const bool use_pinned_pc,
bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/, bool /*isLastBTDFlush*/) const
{
Expand All @@ -63,15 +63,17 @@ FlushFormatSensei::WriteToFile (

#ifndef AMREX_USE_SENSEI_INSITU
amrex::ignore_unused(varnames, mf, iteration, time, particle_diags,
isBTD);
verbose, isBTD);
#else
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
!isBTD,
"In-situ visualization is not currently supported for back-transformed diagnostics.");

WARPX_PROFILE("FlushFormatSensei::WriteToFile()");
const std::string& filename = amrex::Concatenate(prefix, iteration[0], file_min_digits);
amrex::Print() << Utils::TextMsg::Info("Writing Sensei file " + filename);
if (verbose > 0) {
amrex::Print() << Utils::TextMsg::Info("Writing Sensei file " + filename);
}

amrex::Vector<amrex::MultiFab> *mf_ptr =
const_cast<amrex::Vector<amrex::MultiFab>*>(&mf);
Expand Down
8 changes: 5 additions & 3 deletions Source/Diagnostics/FullDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ FullDiagnostics::Flush ( int i_buffer, bool /* force_flush */ )
m_varnames, m_sum_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
warpx.gett_new(0),
m_output_species.at(i_buffer), nlev_output, m_file_prefix,
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards);
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards,
m_verbose);

// Reset the values in the dynamic start time-averaged diagnostics after flush
if (m_time_average_mode == TimeAverageType::Dynamic) {
Expand All @@ -281,7 +282,8 @@ FullDiagnostics::Flush ( int i_buffer, bool /* force_flush */ )
m_varnames, m_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
warpx.gett_new(0),
m_output_species.at(i_buffer), nlev_output, m_file_prefix,
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards);
m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards,
m_verbose);
}

FlushRaw();
Expand Down Expand Up @@ -340,7 +342,7 @@ FullDiagnostics::DoComputeAndPack (int step, bool force_flush)
}
}
// Print information on when time-averaging is active
if (in_averaging_period) {
if ((m_verbose > 1) && in_averaging_period) {
if (step == m_average_start_step) {
amrex::Print() << Utils::TextMsg::Info(
"Begin time averaging for " + m_diag_name + " and output at step "
Expand Down

0 comments on commit 540268f

Please sign in to comment.