diff --git a/framework/include/outputs/Console.h b/framework/include/outputs/Console.h index cef4751dfdea..8801418c8a28 100644 --- a/framework/include/outputs/Console.h +++ b/framework/include/outputs/Console.h @@ -87,6 +87,11 @@ class Console : public TableOutput return _system_info_flags; } + /** + * A reference to the time format to allow callers to set a new format for this console object + */ + MooseEnum & timeFormat() { return _time_format; } + protected: /** * Print the input file at the beginning of the simulation @@ -150,6 +155,9 @@ class Console : public TableOutput */ void writeVariableNorms(); + /// A help function to format a time + std::string formatTime(const Real t) const; + /// The max number of table rows unsigned int _max_rows; @@ -198,6 +206,9 @@ class Console : public TableOutput /// Number of significant digits unsigned int _precision; + /// Time format + MooseEnum _time_format; + private: /** * Add a message to the output streams diff --git a/framework/src/outputs/Console.C b/framework/src/outputs/Console.C index 9b5b423d645d..9221443dc118 100644 --- a/framework/src/outputs/Console.C +++ b/framework/src/outputs/Console.C @@ -66,6 +66,11 @@ Console::validParams() params.addParam( "time_precision", "The number of significant digits that are printed on time related outputs"); + MooseEnum time_format("plain=0 second=1 dtime=2", "plain"); + params.addParam( + "time_format", + time_format, + "The format for the printed times ('dtime' means a format like 1d 01:01:0.1s)"); // Performance Logging params.addDeprecatedParam("perf_log", @@ -181,6 +186,7 @@ Console::Console(const InputParameters & parameters) _outlier_variable_norms(getParam("outlier_variable_norms")), _outlier_multiplier(getParam>("outlier_multiplier")), _precision(isParamValid("time_precision") ? getParam("time_precision") : 0), + _time_format(getParam("time_format")), _console_buffer(_app.getOutputWarehouse().consoleBuffer()), _old_linear_norm(std::numeric_limits::max()), _old_nonlinear_norm(std::numeric_limits::max()), @@ -413,38 +419,30 @@ Console::writeTimestepInformation(bool output_dt) // Write time step and time information oss << "\nTime Step " << timeStep(); - // Set precision - if (_precision > 0) - oss << std::setw(_precision) << std::setprecision(_precision) << std::setfill('0') - << std::showpoint; - - // Show scientific notation - if (_scientific_time) - oss << std::scientific; - // Print the time - oss << ", time = " << time(); + oss << ", time = " << formatTime(time()); if (output_dt) { if (!_verbose) // Show the time delta information - oss << ", dt = " << std::left << dt(); + oss << ", dt = " << std::left << formatTime(dt()); // Show old time information, if desired on separate lines else { oss << '\n' << std::right << std::setw(21) << std::setfill(' ') << "old time = " << std::left - << timeOld() << '\n'; + << formatTime(timeOld()) << '\n'; // Show the time delta information - oss << std::right << std::setw(21) << std::setfill(' ') << "dt = " << std::left << dt() - << '\n'; + oss << std::right << std::setw(21) << std::setfill(' ') << "dt = " << std::left + << formatTime(dt()) << '\n'; // Show the old time delta information, if desired if (_verbose) - oss << std::right << std::setw(21) << std::setfill(' ') << "old dt = " << _dt_old << '\n'; + oss << std::right << std::setw(21) << std::setfill(' ') + << "old dt = " << formatTime(_dt_old) << '\n'; } } @@ -455,6 +453,49 @@ Console::writeTimestepInformation(bool output_dt) } } +std::string +Console::formatTime(const Real t) const +{ + std::ostringstream oss; + if (_time_format == "plain" || _time_format == "second") + { + if (_precision > 0) + oss << std::setw(_precision) << std::setprecision(_precision) << std::setfill('0') + << std::showpoint; + if (_scientific_time) + oss << std::scientific; + oss << t; + if (_time_format == "second") + oss << "s"; + } + else if (_time_format == "dtime") + { + int days = std::floor(t / 24 / 3600); + int hours = std::floor(t / 3600 - days * 24); + int mins = std::floor(t / 60 - days * 24 * 60 - hours * 60); + Real second = t - days * 24 * 3600 - hours * 3600 - mins * 60; + + if (days != 0) + oss << days << "d"; + if (hours != 0 || mins != 0 || second != 0) + { + oss << " "; + oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0') << std::setw(2) + << mins << ":"; + + if (_precision > 0) + oss << std::setw(_precision) << std::setprecision(_precision) << std::setfill('0') + << std::showpoint; + if (_scientific_time) + oss << std::scientific; + else if (second < 10) + oss << "0"; + oss << second; + } + } + return oss.str(); +} + void Console::writeVariableNorms() {