LCOV - code coverage report
Current view: top level - src/outputs - ProgressOutput.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 29 32 90.6 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      15             : InputParameters
      16       14305 : ProgressOutput::validParams()
      17             : {
      18       14305 :   auto params = Output::validParams();
      19       14305 :   params.addClassDescription("Output a simulation time progress bar on the console.");
      20       28610 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END};
      21       42915 :   params.addParam<bool>(
      22       28610 :       "use_filename", true, "Put the input filename into the title of the progress bar");
      23       14305 :   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       14305 :   return params;
      28       14305 : }
      29             : 
      30          20 : ProgressOutput::ProgressOutput(const InputParameters & parameters)
      31             :   : Output(parameters),
      32          20 :     _transient_executioner(dynamic_cast<TransientBase *>(_app.getExecutioner())),
      33          20 :     _use_filename(getParam<bool>("use_filename")),
      34          30 :     _length(isParamValid("progress_bar_width") ? getParam<unsigned int>("progress_bar_width")
      35          30 :                                                : MooseUtils::getTermWidth(true) - 2)
      36             : {
      37          20 : }
      38             : 
      39             : void
      40          40 : ProgressOutput::output()
      41             : {
      42          40 :   if (_transient_executioner == nullptr || _current_execute_flag != EXEC_TIMESTEP_END)
      43           0 :     return;
      44             : 
      45          40 :   const auto passed = _transient_executioner->getTime() - _transient_executioner->getStartTime();
      46          40 :   const auto total = _transient_executioner->getEndTime() - _transient_executioner->getStartTime();
      47          40 :   if (total == 0)
      48           0 :     return;
      49             : 
      50             :   // length of filled portion
      51          40 :   const auto progress = std::round((passed * _length) / total);
      52             : 
      53             :   // title string
      54          40 :   std::string title = name();
      55          40 :   if (_use_filename)
      56          40 :     title += " (" + getMooseApp().getFileName() + ')';
      57          40 :   if (title.length() >= _length - 1)
      58           0 :     title = title.substr(0, _length - 4) + "...";
      59             : 
      60             :   // top line
      61          40 :   Moose::out << "+-" << title << std::string(_length - 1 - title.length(), '-') << "+\n";
      62             : 
      63             :   // bar
      64          40 :   Moose::out << '|' << std::string(progress, '#') << std::string(_length - progress, '.') << "|\n";
      65             : 
      66             :   // bottom line
      67          40 :   Moose::out << '+' << std::string(_length, '-') << "+\n";
      68          40 : }

Generated by: LCOV version 1.14