Skip to content

Commit

Permalink
add verbosity flag for diagnostic output print statements
Browse files Browse the repository at this point in the history
Signed-off-by: roelof-groenewald <regroenewald@gmail.com>
  • Loading branch information
roelof-groenewald committed Dec 8, 2024
1 parent 3f3c91d commit 03c00a6
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 38 deletions.
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormat.H
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public:
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
const amrex::Geometry& full_BTD_snapshot = amrex::Geometry(),
bool isLastBTDFlush = false) const = 0;
bool isLastBTDFlush = false,
int verbose = 2 ) const = 0;

FlushFormat () = default;
virtual ~FlushFormat() = default;
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 @@ -41,7 +41,8 @@ public:
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,
int verbose = 2 ) const override;

FlushFormatAscent () = default;
~FlushFormatAscent() override = default;
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ FlushFormatAscent::WriteToFile (
const bool /*use_pinned_pc*/,
bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/,
bool /*isLastBTDFlush*/) const
bool /*isLastBTDFlush*/,
int /*verbose*/) const
{
#ifdef AMREX_USE_ASCENT
WARPX_PROFILE("FlushFormatAscent::WriteToFile()");
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public:
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,
int verbose = 2) const override;

#ifdef AMREX_USE_CATALYST
~FlushFormatCatalyst() override;
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ FlushFormatCatalyst::WriteToFile (
bool /*use_pinned_pc*/,
bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/,
bool /*isLastBTDFlush*/) const
bool /*isLastBTDFlush*/,
int /*verbose*/) const
{
#ifdef AMREX_USE_CATALYST
amrex::Print() << Utils::TextMsg::Info("Running Catalyst pipeline scripts...");
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class FlushFormatCheckpoint final : public FlushFormatPlotfile
bool isBTD = false, int snapshotID = -1,
int bufferID = 1, int numBuffers = 1,
const amrex::Geometry& full_BTD_snapshot = amrex::Geometry(),
bool isLastBTDFlush = false) const final;
bool isLastBTDFlush = false,
int verbose = 2) const final;

void CheckpointParticles (const std::string& dir,
const amrex::Vector<ParticleDiag>& particle_diags) const;
Expand Down
9 changes: 6 additions & 3 deletions Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ FlushFormatCheckpoint::WriteToFile (
bool /*isBTD*/, int /*snapshotID*/,
int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/,
bool /*isLastBTDFlush*/) const
bool /*isLastBTDFlush*/,
int verbose) const
{
using ablastr::fields::Direction;

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 @@ -40,7 +40,8 @@ public:
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,
int verbose = 2 ) const override;

~FlushFormatOpenPMD () override = default;

Expand Down
23 changes: 13 additions & 10 deletions Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,23 @@ FlushFormatOpenPMD::WriteToFile (
const bool use_pinned_pc,
bool isBTD, int snapshotID, int bufferID, int numBuffers,
const amrex::Geometry& full_BTD_snapshot,
bool isLastBTDFlush) const
bool isLastBTDFlush,
int verbose) 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
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public:
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,
int verbose = 2 ) const override;

/** Write general info of the run into the plotfile */
void WriteJobInfo(const std::string& dir) const;
Expand Down
27 changes: 15 additions & 12 deletions Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,25 @@ FlushFormatPlotfile::WriteToFile (
const bool /*use_pinned_pc*/,
bool isBTD, int snapshotID, int bufferID, int numBuffers,
const amrex::Geometry& /*full_BTD_snapshot*/,
bool isLastBTDFlush) const
bool isLastBTDFlush,
int verbose) const
{
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
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatSensei.H
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public:
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,
int verbose = 2) const override;

/** \brief Do in-situ visualization for particle data.
* \param[in] particle_diags Each element of this vector handles output of 1 species.
Expand Down
3 changes: 2 additions & 1 deletion Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ FlushFormatSensei::WriteToFile (
bool plot_raw_fields, bool plot_raw_fields_guards,
const bool use_pinned_pc,
bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
const amrex::Geometry& /*full_BTD_snapshot*/, bool /*isLastBTDFlush*/) const
const amrex::Geometry& /*full_BTD_snapshot*/, bool /*isLastBTDFlush*/,
int /*verbose*/ ) const
{
amrex::ignore_unused(
geom, nlev, prefix, file_min_digits,
Expand Down
2 changes: 2 additions & 0 deletions Source/Diagnostics/FullDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private:
amrex::Real m_average_period_time = -1.0;
/** Time step to start averaging */
int m_average_start_step = -1;
/** Whether to output a message when diagnostics are output */
int m_verbose = 2;
/** Flush m_mf_output or m_sum_mf_output and particles to file for the i^th buffer */
void Flush (int i_buffer, bool /* force_flush */) override;
/** Flush raw data */
Expand Down
9 changes: 6 additions & 3 deletions Source/Diagnostics/FullDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ FullDiagnostics::ReadParameters ()
pp_diag_name.get("time_average_mode", m_time_average_mode_str);

const amrex::ParmParse pp_warpx("warpx");
pp_warpx.query("verbose", m_verbose);
std::vector<std::string> dt_interval_vec = {"-1"};
const bool timestep_may_vary = pp_warpx.queryarr("dt_update_interval", dt_interval_vec);
amrex::Print() << Utils::TextMsg::Warn("Time step varies?" + std::to_string(timestep_may_vary));
Expand Down Expand Up @@ -261,7 +262,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 +283,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 +343,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 03c00a6

Please sign in to comment.