-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25503 from dschwen/progress_output_22906
Add progress bar output
- Loading branch information
Showing
12 changed files
with
269 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Progress | ||
|
||
!syntax description /Outputs/Progress | ||
|
||
## Overview | ||
|
||
The Progress output displays an ASCII art progress bar at the end of each timestep, visualizing the amount of simulation time that has passed vs. the total simulation time. It requires the use of a transient executioner along with predetermined start and end times. The width of the bar widget can be specified using the [!param](/Outputs/Progress/progress_bar_width) parameter. If omitted the value of the `MOOSE_PPS_WIDTH` environment variable is queried. If that variable is not set the terminal window width is queried (with a fallback value of 132 chars). | ||
|
||
``` | ||
+-Progress (full.i)--------------------------------+ | ||
|#########################.........................| | ||
+--------------------------------------------------+ | ||
``` | ||
|
||
!syntax parameters /Outputs/Progress | ||
|
||
!syntax inputs /Outputs/Progress | ||
|
||
!syntax children /Outputs/Progress |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "Output.h" | ||
|
||
class Transient; | ||
|
||
/** | ||
* Output a simulation time progress bar on the console | ||
*/ | ||
class ProgressOutput : public Output | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ProgressOutput(const InputParameters & parameters); | ||
|
||
protected: | ||
void output() override; | ||
|
||
const Transient * const _transient_executioner; | ||
|
||
/// display input file name in the progress bar title | ||
const bool _use_filename; | ||
|
||
/// total length of the progress bar | ||
const unsigned int _length; | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "ProgressOutput.h" | ||
#include "Transient.h" | ||
|
||
registerMooseObjectAliased("MooseApp", ProgressOutput, "Progress"); | ||
|
||
InputParameters | ||
ProgressOutput::validParams() | ||
{ | ||
auto params = Output::validParams(); | ||
params.addClassDescription("Output a simulation time progress bar on the console."); | ||
params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END}; | ||
params.addParam<bool>( | ||
"use_filename", true, "Put the input filename into the title of the progress bar"); | ||
params.addParam<unsigned int>( | ||
"progress_bar_width", | ||
"Explicitly specify the bar width. If omitted the MOOSE_PPS_WIDTH environment variable or, " | ||
"if not set, the terminal width is queried."); | ||
return params; | ||
} | ||
|
||
ProgressOutput::ProgressOutput(const InputParameters & parameters) | ||
: Output(parameters), | ||
_transient_executioner(dynamic_cast<Transient *>(_app.getExecutioner())), | ||
_use_filename(getParam<bool>("use_filename")), | ||
_length(isParamValid("progress_bar_width") ? getParam<unsigned int>("progress_bar_width") | ||
: MooseUtils::getTermWidth(true) - 2) | ||
{ | ||
} | ||
|
||
void | ||
ProgressOutput::output() | ||
{ | ||
if (_transient_executioner == nullptr || _current_execute_flag != EXEC_TIMESTEP_END) | ||
return; | ||
|
||
const auto passed = _transient_executioner->getTime() - _transient_executioner->getStartTime(); | ||
const auto total = _transient_executioner->getEndTime() - _transient_executioner->getStartTime(); | ||
if (total == 0) | ||
return; | ||
|
||
// length of filled portion | ||
const auto progress = std::round((passed * _length) / total); | ||
|
||
// title string | ||
std::string title = name(); | ||
if (_use_filename) | ||
title += " (" + getMooseApp().getFileName() + ')'; | ||
if (title.length() >= _length - 1) | ||
title = title.substr(0, _length - 4) + "..."; | ||
|
||
// top line | ||
Moose::out << "+-" << title << std::string(_length - 1 - title.length(), '-') << "+\n"; | ||
|
||
// bar | ||
Moose::out << '|' << std::string(progress, '#') << std::string(_length - progress, '.') << "|\n"; | ||
|
||
// bottom line | ||
Moose::out << '+' << std::string(_length, '-') << "+\n"; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[Mesh] | ||
[gen] | ||
type = GeneratedMeshGenerator | ||
dim = 1 | ||
[] | ||
[] | ||
|
||
[Variables] | ||
[u] | ||
[] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
kernel_coverage_check = false | ||
[] | ||
|
||
[Executioner] | ||
type = Transient | ||
start_time = 10 | ||
end_time = 20 | ||
dt = 5 | ||
[] | ||
|
||
[Outputs] | ||
progress = true | ||
[] |
Oops, something went wrong.