forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add progress output (idaholab#22906)
- Loading branch information
Showing
11 changed files
with
260 additions
and
61 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 an 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/DOFMap | ||
|
||
!syntax inputs /Outputs/DOFMap | ||
|
||
!syntax children /Outputs/DOFMap |
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,33 @@ | ||
//* 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; | ||
|
||
class ProgressOutput : public Output | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ProgressOutput(const InputParameters & parameters); | ||
|
||
protected: | ||
void output() override; | ||
|
||
Transient * _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,70 @@ | ||
//* 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 "ProgressOutput.h" | ||
#include "Transient.h" | ||
|
||
registerMooseObjectAliased("MooseApp", ProgressOutput, "Progress"); | ||
|
||
InputParameters | ||
ProgressOutput::validParams() | ||
{ | ||
auto params = Output::validParams(); | ||
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 are 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 || | ||
!_transient) | ||
return; | ||
|
||
auto passed = _transient_executioner->getTime() - _transient_executioner->getStartTime(); | ||
auto total = _transient_executioner->endTime() - _transient_executioner->getStartTime(); | ||
if (total == 0) | ||
return; | ||
|
||
// length of filled portion | ||
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 | ||
[] |
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,30 @@ | ||
[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] | ||
type = Progress | ||
progress_bar_width = 50 | ||
[] | ||
[] |
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 @@ | ||
[Tests] | ||
issues = '#22906' | ||
design = ProgressOutput.md | ||
[full] | ||
type = RunApp | ||
input = 'full.i' | ||
expect_out = "\+-Progress \(.*\)-*\+\n\|#########################.........................\|\n\+--------------------------------------------------\+" | ||
requirement = "The system shall support printing a progress bar that indicates the fraction of total simulation time passed." | ||
[] | ||
[common] | ||
type = RunApp | ||
input = 'common.i' | ||
expect_out = '\+-progress \(.*\)-*\+' | ||
requirement = "The system shall support using a shortcut to set up a progress bar output." | ||
[] | ||
[] | ||
|
||
|
||
|