-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only print mid-timestep estTimeStep outputs if relevant (#3023)
Output from estTimeStep is occurring for the pre- and post-timestep validity checks, but on most timesteps this clutters the output because the validity check passes. This PR creates a class that temporarily redirects std::cout and then uses that to capture the estTimeStep output and only print it if needed.
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |