From 540268f2c05d46b90ac8f33718efa63b47687cae Mon Sep 17 00:00:00 2001 From: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:55:18 -0800 Subject: [PATCH] Add `verbosity` flag for diagnostic output print statements (#5503) 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 --- Source/Diagnostics/BTDiagnostics.cpp | 2 +- .../BoundaryScrapingDiagnostics.cpp | 2 +- Source/Diagnostics/Diagnostics.H | 2 ++ Source/Diagnostics/Diagnostics.cpp | 3 +++ Source/Diagnostics/FlushFormats/FlushFormat.H | 1 + .../FlushFormats/FlushFormatAscent.H | 3 ++- .../FlushFormats/FlushFormatAscent.cpp | 7 ++++-- .../FlushFormats/FlushFormatCatalyst.H | 1 + .../FlushFormats/FlushFormatCatalyst.cpp | 1 + .../FlushFormats/FlushFormatCheckpoint.H | 1 + .../FlushFormats/FlushFormatCheckpoint.cpp | 7 ++++-- .../FlushFormats/FlushFormatOpenPMD.H | 3 ++- .../FlushFormats/FlushFormatOpenPMD.cpp | 21 +++++++++------- .../FlushFormats/FlushFormatPlotfile.H | 1 + .../FlushFormats/FlushFormatPlotfile.cpp | 25 +++++++++++-------- .../FlushFormats/FlushFormatSensei.H | 1 + .../FlushFormats/FlushFormatSensei.cpp | 8 +++--- Source/Diagnostics/FullDiagnostics.cpp | 8 +++--- 18 files changed, 63 insertions(+), 34 deletions(-) diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index 4939e2fb207..09167452c1a 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -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); diff --git a/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp b/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp index 8df58b6fb28..bcccda48c18 100644 --- a/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp +++ b/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp @@ -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); diff --git a/Source/Diagnostics/Diagnostics.H b/Source/Diagnostics/Diagnostics.H index d0c70e76c1f..a078bab3597 100644 --- a/Source/Diagnostics/Diagnostics.H +++ b/Source/Diagnostics/Diagnostics.H @@ -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 diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index a60aea40242..2b3b6d7df61 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -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){ diff --git a/Source/Diagnostics/FlushFormats/FlushFormat.H b/Source/Diagnostics/FlushFormats/FlushFormat.H index be1322bd61b..f0a83f7a24b 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormat.H +++ b/Source/Diagnostics/FlushFormats/FlushFormat.H @@ -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, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatAscent.H b/Source/Diagnostics/FlushFormats/FlushFormatAscent.H index a5a10d77bdc..86ad4b09cfb 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatAscent.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatAscent.H @@ -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; diff --git a/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp b/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp index 36f0ef05faa..5a405568aa7 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp @@ -18,6 +18,7 @@ FlushFormatAscent::WriteToFile ( const amrex::Vector& 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*/, @@ -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); @@ -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); } diff --git a/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H index 6974bf731a6..c5f3b9148c1 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H @@ -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, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp index 425c13de6a4..3e542f9f871 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp @@ -127,6 +127,7 @@ FlushFormatCatalyst::WriteToFile ( const amrex::Vector& 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*/, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.H b/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.H index 5c26ac97f61..cb0a6c4b6c7 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.H @@ -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, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp b/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp index 4d721dd6abe..788e040b0ee 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp @@ -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*/, @@ -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); diff --git a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.H b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.H index 141760ac2a3..5666d85bf3a 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.H @@ -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; diff --git a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp index e0c8c4ef2d6..aeb26656b46 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp @@ -123,6 +123,7 @@ FlushFormatOpenPMD::WriteToFile ( const amrex::Vector& 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, @@ -130,16 +131,18 @@ FlushFormatOpenPMD::WriteToFile ( { 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); + } } } diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H index c62056b8907..18648c07e69 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H @@ -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, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp index 0f05496e4c0..879a5986434 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp @@ -66,6 +66,7 @@ FlushFormatPlotfile::WriteToFile ( const amrex::Vector& 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*/, @@ -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 rfs; diff --git a/Source/Diagnostics/FlushFormats/FlushFormatSensei.H b/Source/Diagnostics/FlushFormats/FlushFormatSensei.H index 45ea40077e4..87ed00e539e 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatSensei.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatSensei.H @@ -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, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp b/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp index 468ed81ce18..b96c6d76f91 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp @@ -51,7 +51,7 @@ FlushFormatSensei::WriteToFile ( const amrex::Vector& 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 { @@ -63,7 +63,7 @@ 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, @@ -71,7 +71,9 @@ FlushFormatSensei::WriteToFile ( 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 *mf_ptr = const_cast*>(&mf); diff --git a/Source/Diagnostics/FullDiagnostics.cpp b/Source/Diagnostics/FullDiagnostics.cpp index 7a8f376cd21..946178fd1b5 100644 --- a/Source/Diagnostics/FullDiagnostics.cpp +++ b/Source/Diagnostics/FullDiagnostics.cpp @@ -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) { @@ -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(); @@ -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 "