Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
ProgressOutput.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "ProgressOutput.h"
11 #include "TransientBase.h"
12 
13 registerMooseObjectAliased("MooseApp", ProgressOutput, "Progress");
14 
17 {
18  auto params = Output::validParams();
19  params.addClassDescription("Output a simulation time progress bar on the console.");
20  params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END};
21  params.addParam<bool>(
22  "use_filename", true, "Put the input filename into the title of the progress bar");
23  params.addParam<unsigned int>(
24  "progress_bar_width",
25  "Explicitly specify the bar width. If omitted the MOOSE_PPS_WIDTH environment variable or, "
26  "if not set, the terminal width is queried.");
27  return params;
28 }
29 
31  : Output(parameters),
32  _transient_executioner(dynamic_cast<TransientBase *>(_app.getExecutioner())),
33  _use_filename(getParam<bool>("use_filename")),
34  _length(isParamValid("progress_bar_width") ? getParam<unsigned int>("progress_bar_width")
35  : MooseUtils::getTermWidth(true) - 2)
36 {
37 }
38 
39 void
41 {
43  return;
44 
47  if (total == 0)
48  return;
49 
50  // length of filled portion
51  const auto progress = std::round((passed * _length) / total);
52 
53  // title string
54  std::string title = name();
55  if (_use_filename)
56  title += " (" + getMooseApp().getFileName() + ')';
57  if (title.length() >= _length - 1)
58  title = title.substr(0, _length - 4) + "...";
59 
60  // top line
61  Moose::out << "+-" << title << std::string(_length - 1 - title.length(), '-') << "+\n";
62 
63  // bar
64  Moose::out << '|' << std::string(progress, '#') << std::string(_length - progress, '.') << "|\n";
65 
66  // bottom line
67  Moose::out << '+' << std::string(_length, '-') << "+\n";
68 }
registerMooseObjectAliased("MooseApp", ProgressOutput, "Progress")
std::string getFileName(bool stripLeadingPath=true) const
Return the primary (first) filename that was parsed Note: When stripLeadingPath is false...
Definition: MooseApp.C:2244
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
const unsigned int _length
total length of the progress bar
void output() override
Overload this function with the desired output activities.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Real getStartTime() const
Return the start time.
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:33
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
Output a simulation time progress bar on the console.
const TransientBase *const _transient_executioner
Based class for output objects.
Definition: Output.h:43
static InputParameters validParams()
T round(T x)
Definition: MathUtils.h:77
ExecFlagType _current_execute_flag
Current execute on flag.
Definition: Output.h:211
virtual Real getTime() const
Get the current time.
Definition: TransientBase.h:89
ProgressOutput(const InputParameters &parameters)
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
Definition: TransientBase.h:26
Real getEndTime() const
Get the end time.
const bool _use_filename
display input file name in the progress bar title
static InputParameters validParams()
Definition: Output.C:32
void ErrorVector unsigned int
unsigned short getTermWidth(bool use_environment)
Returns the width of the terminal using sys/ioctl.
Definition: MooseUtils.C:646