Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only print mid-timestep estTimeStep outputs if relevant #3023

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/driver/Castro.H
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// runtime parameters
#include <castro_params.H>
#include <prob_parameters.H>
#include <Castro_io.H>
#include <Castro_util.H>

using namespace castro;
Expand Down
26 changes: 24 additions & 2 deletions Source/driver/Castro_advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,21 @@ Castro::initialize_do_advance (Real time, Real dt)

if (castro::check_dt_before_advance && !is_first_step_on_this_level) {
int is_new = 0;
Real old_dt = estTimeStep(is_new);

// We only display the estTimeStep output if the validity check fails
std::string estTimeStep_output;

Real old_dt;

{
CoutRedirection redirection;
old_dt = estTimeStep(is_new);
estTimeStep_output = redirection.getCapturedOutput();
}

if (castro::change_max * old_dt < dt) {
status.success = false;
std::cout << estTimeStep_output;
status.reason = "pre-advance timestep validity check failed";
}
}
Expand Down Expand Up @@ -276,10 +287,21 @@ Castro::finalize_do_advance (Real time, Real dt)

if (do_validity_check) {
int is_new = 1;
Real new_dt = estTimeStep(is_new);

// We only display the estTimeStep output if the validity check fails
std::string estTimeStep_output;

Real new_dt;

{
CoutRedirection redirection;
new_dt = estTimeStep(is_new);
estTimeStep_output = redirection.getCapturedOutput();
}

if (castro::change_max * new_dt < dt) {
status.success = false;
std::cout << estTimeStep_output;
status.reason = "post-advance timestep validity check failed";
return status;
}
Expand Down
32 changes: 32 additions & 0 deletions Source/driver/Castro_io.H
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#ifndef CASTRO_IO_H
#define CASTRO_IO_H

#include <iostream>
#include <sstream>

extern std::string inputs_name;

// Redirect std::cout to a temporary buffer.

class CoutRedirection {

public:
CoutRedirection () : original_output(std::cout.rdbuf()) {
std::cout.rdbuf(captured_output.rdbuf());
}

~CoutRedirection () {
std::cout.rdbuf(original_output);
}

// Remove copy/move constructors/assignment operators.
CoutRedirection (const CoutRedirection&) = delete;
CoutRedirection (CoutRedirection&&) = delete;
CoutRedirection& operator= (const CoutRedirection&) = delete;
CoutRedirection& operator= (CoutRedirection&&) = delete;

std::string getCapturedOutput () {
return captured_output.str();
}

private:
std::ostringstream captured_output;
std::streambuf* original_output;

};

#endif
Loading