https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
39void
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}
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
registerMooseObjectAliased("MooseApp", ProgressOutput, "Progress")
void ErrorVector unsigned int
A MultiMooseEnum object to hold "execute_on" flags.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::string getFileName(bool stripLeadingPath=true) const
Return the primary (first) filename that was parsed Note: When stripLeadingPath is false,...
Definition MooseApp.C:2403
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
Based class for output objects.
Definition Output.h:52
static InputParameters validParams()
Definition Output.C:32
ExecFlagType _current_execute_flag
Current execute on flag.
Definition Output.h:211
Output a simulation time progress bar on the console.
const bool _use_filename
display input file name in the progress bar title
const unsigned int _length
total length of the progress bar
ProgressOutput(const InputParameters &parameters)
static InputParameters validParams()
const TransientBase *const _transient_executioner
void output() override
Overload this function with the desired output activities.
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
Real getStartTime() const
Return the start time.
virtual Real getTime() const
Get the current time.
Real getEndTime() const
Get the end time.