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
8 changed files
with
158 additions
and
63 deletions.
There are no files selected for viewing
Submodule wasp
updated
from b3c222 to 827479
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//* 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" | ||
|
||
registerMooseObject("PolarBearApp", ProgressOutput); | ||
|
||
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"); | ||
return params; | ||
} | ||
|
||
ProgressOutput::ProgressOutput(const InputParameters & parameters) | ||
: Output(parameters), | ||
_transient_executioner(dynamic_cast<Transient *>(_app.getExecutioner())), | ||
_use_filename(getParam<bool>("use_filename")), | ||
_length(MooseUtils::getTermWidth(true)) | ||
{ | ||
} | ||
|
||
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