Skip to content

Commit

Permalink
Only print mid-timestep estDt outputs if relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpkatz committed Jan 20, 2025
1 parent 046cf07 commit 8488fff
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
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
26 changes: 26 additions & 0 deletions Source/driver/Castro_io.H
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#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);
}

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

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

};

#endif

0 comments on commit 8488fff

Please sign in to comment.