Skip to content

Commit

Permalink
Merge pull request #24945 from YaqiWang/more_time_units
Browse files Browse the repository at this point in the history
Add more options on outputting time in console
  • Loading branch information
GiudGiud authored Jul 11, 2023
2 parents 51557c3 + 7092b37 commit 2225d85
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
17 changes: 15 additions & 2 deletions framework/include/outputs/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,23 @@ class Console : public TableOutput
return _system_info_flags;
}

/**
* Time formatting options
*/
enum class TimeFormatEnum
{
PLAIN = 0,
SECOND = 1,
MINUTE = 2,
HOUR = 3,
DAY = 4,
DTIME = 5
};

/**
* A reference to the time format to allow callers to set a new format for this console object
*/
MooseEnum & timeFormat() { return _time_format; }
TimeFormatEnum & timeFormat() { return _time_format; }

protected:
/**
Expand Down Expand Up @@ -207,7 +220,7 @@ class Console : public TableOutput
unsigned int _precision;

/// Time format
MooseEnum _time_format;
TimeFormatEnum _time_format;

private:
/**
Expand Down
22 changes: 15 additions & 7 deletions framework/src/outputs/Console.C
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Console::validParams()
params.addParam<unsigned int>(
"time_precision",
"The number of significant digits that are printed on time related outputs");
MooseEnum time_format("plain=0 second=1 dtime=2", "plain");
MooseEnum time_format("plain=0 second=1 minute=2 hour=3 day=4 dtime=5", "plain");
params.addParam<MooseEnum>(
"time_format",
time_format,
Expand Down Expand Up @@ -187,7 +187,7 @@ Console::Console(const InputParameters & parameters)
_outlier_variable_norms(getParam<bool>("outlier_variable_norms")),
_outlier_multiplier(getParam<std::vector<Real>>("outlier_multiplier")),
_precision(isParamValid("time_precision") ? getParam<unsigned int>("time_precision") : 0),
_time_format(getParam<MooseEnum>("time_format")),
_time_format(getParam<MooseEnum>("time_format").getEnum<TimeFormatEnum>()),
_console_buffer(_app.getOutputWarehouse().consoleBuffer()),
_old_linear_norm(std::numeric_limits<Real>::max()),
_old_nonlinear_norm(std::numeric_limits<Real>::max()),
Expand Down Expand Up @@ -460,18 +460,26 @@ std::string
Console::formatTime(const Real t) const
{
std::ostringstream oss;
if (_time_format == "plain" || _time_format == "second")
if (_time_format != TimeFormatEnum::DTIME)
{
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";

if (_time_format == TimeFormatEnum::PLAIN)
oss << t;
else if (_time_format == TimeFormatEnum::SECOND)
oss << t << "s";
else if (_time_format == TimeFormatEnum::MINUTE)
oss << t / 60 << "m";
else if (_time_format == TimeFormatEnum::HOUR)
oss << t / 3600 << "h";
else if (_time_format == TimeFormatEnum::DAY)
oss << t / 86400 << "d";
}
else if (_time_format == "dtime")
else
{
Real abst = t;
if (t < 0)
Expand Down
36 changes: 36 additions & 0 deletions test/tests/outputs/console/tests
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,42 @@
requirement = 'The system shall support writing time information in DTIME format in the console.'
issues = '#24813'
[../]
[./console_minute_format]
type = RunApp
input = 'console_dtime_format.i'
cli_args = 'Outputs/screen/time_format=minute'
expect_out = 'Time Step 1, time = -0\.0116667m[\s\S]*'
'Time Step 6, time = 0\.103333m[\s\S]*'
'Time Step 48, time = 195\.670m[\s\S]*'
'Time Step 59, time = 1666\.67m'

requirement = 'The system shall support writing time information in minutes in the console.'
issues = '#24944'
[../]
[./console_hour_format]
type = RunApp
input = 'console_dtime_format.i'
cli_args = 'Outputs/screen/time_format=hour'
expect_out = 'Time Step 1, time = -0\.000194444h[\s\S]*'
'Time Step 6, time = 0\.00172222h[\s\S]*'
'Time Step 48, time = 3\.26117h[\s\S]*'
'Time Step 59, time = 27\.7778h'

requirement = 'The system shall support writing time information in hours in the console.'
issues = '#24944'
[../]
[./console_day_format]
type = RunApp
input = 'console_dtime_format.i'
cli_args = 'Outputs/screen/time_format=day'
expect_out = 'Time Step 1, time = -8\.10185e-06[\s\S]*'
'Time Step 6, time = 7\.17593e-05d[\s\S]*'
'Time Step 48, time = 0\.135882d[\s\S]*'
'Time Step 59, time = 1\.15741d'

requirement = 'The system shall support writing time information in days in the console.'
issues = '#24944'
[../]
[./_console]
# Test the used of MooseObject::_console method
type = RunApp
Expand Down

0 comments on commit 2225d85

Please sign in to comment.