deltaFlow
Progress.H File Reference

Progress bar for iterative solvers. More...

#include <fmt/color.h>
#include <fmt/core.h>
#include <string>
Include dependency graph for Progress.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void printIterationProgress (const std::string &solver, int iter, int maxIter, double error, double tol, int barWidth=50)
 Print an iteration progress line for a solver.
 
void printConvergenceStatus (const std::string &solver, bool converged, int iter, int maxIter, double error, double tol, int barWidth=50)
 Print the final convergence status line.
 

Detailed Description

Progress bar for iterative solvers.

Provides a colored terminal progress bar that shows solver convergence status in real-time. Green fill indicates progress; red indicates failure.

Definition in file Progress.H.

Function Documentation

◆ printConvergenceStatus()

void printConvergenceStatus ( const std::string &  solver,
bool  converged,
int  iter,
int  maxIter,
double  error,
double  tol,
int  barWidth = 50 
)
inline

Print the final convergence status line.

Overwrites the progress bar with a final status:

  • Green bar (partial) + "CONVERGED" if converged
  • Red bar at failure point + "FAILED" if not converged
Parameters
solverSolver name
convergedWhether the solver converged
iterFinal iteration count
maxIterMaximum allowed iterations
errorFinal mismatch/error value
tolConvergence tolerance
barWidthWidth of the progress bar in characters (default: 50)

Definition at line 100 of file Progress.H.

108 {
109 // Overwrite the last progress line
110 fmt::print("\033[1F\033[2K");
111
112 float ratio = maxIter == 0 ? 0.0f : static_cast<float>(iter) / maxIter;
113 int filled = static_cast<int>(ratio * barWidth);
114
115 fmt::print(fg(fmt::color::cyan) | fmt::emphasis::bold, "{:<16}", solver);
116
117 if (converged) {
118 // Green bar up to convergence point, gray for the rest
119 for (int i = 0; i < filled; ++i)
120 fmt::print(bg(fmt::color::green), " ");
121 for (int i = filled; i < barWidth; ++i)
122 fmt::print(bg(fmt::color::dark_gray), " ");
123 fmt::print("\033[0m");
124
125 fmt::print(" ");
126 fmt::print(fg(fmt::color::green) | fmt::emphasis::bold, "CONVERGED");
127 fmt::print(fg(fmt::color::white), " in ");
128 fmt::print(fg(fmt::color::yellow) | fmt::emphasis::bold, "{}", iter);
129 fmt::print(fg(fmt::color::white), " iterations");
130 fmt::print(fg(fmt::color::white), " error {:.6e}\n", error);
131 } else {
132 // Red bar up to failure point, dark gray for the rest
133 for (int i = 0; i < filled; ++i)
134 fmt::print(bg(fmt::color::red), " ");
135 for (int i = filled; i < barWidth; ++i)
136 fmt::print(bg(fmt::color::dark_gray), " ");
137 fmt::print("\033[0m");
138
139 fmt::print(" ");
140 fmt::print(fg(fmt::color::red) | fmt::emphasis::bold, "FAILED");
141 fmt::print(fg(fmt::color::white), " after ");
142 fmt::print(fg(fmt::color::yellow) | fmt::emphasis::bold, "{}", iter);
143 fmt::print(fg(fmt::color::white), " iterations");
144 fmt::print(fg(fmt::color::white), " error {:.6e}\n", error);
145 }
146}
Here is the caller graph for this function:

◆ printIterationProgress()

void printIterationProgress ( const std::string &  solver,
int  iter,
int  maxIter,
double  error,
double  tol,
int  barWidth = 50 
)
inline

Print an iteration progress line for a solver.

Displays a colored progress bar with iteration count and error magnitude.

  • Green bar: proportional to iterations completed out of maxIter
  • Red bar at failure point when solver diverges
Parameters
solverSolver name (e.g. "Newton-Raphson", "Gauss-Seidel")
iterCurrent iteration number (1-based)
maxIterMaximum allowed iterations
errorCurrent mismatch/error value
tolConvergence tolerance
barWidthWidth of the progress bar in characters (default: 50)

Definition at line 50 of file Progress.H.

57 {
58 float ratio = maxIter == 0 ? 0.0f : static_cast<float>(iter) / maxIter;
59 int filled = static_cast<int>(ratio * barWidth);
60
61 // Move cursor up to overwrite previous line (except on first iteration)
62 if (iter > 1)
63 fmt::print("\033[1F\033[2K");
64
65 fmt::print(fg(fmt::color::cyan) | fmt::emphasis::bold, "{:<16}", solver);
66
67 // Progress bar
68 for (int i = 0; i < filled; ++i)
69 fmt::print(bg(fmt::color::green), " ");
70 for (int i = filled; i < barWidth; ++i)
71 fmt::print(bg(fmt::color::dark_gray), " ");
72
73 // Reset colors
74 fmt::print("\033[0m");
75
76 // Stats
77 fmt::print(" iter ");
78 fmt::print(fg(fmt::color::yellow) | fmt::emphasis::bold, "{:>4}", iter);
79 fmt::print(fg(fmt::color::white), "/{:<4}", maxIter);
80 fmt::print(" error ");
81 fmt::print(fg(fmt::color::yellow), "{:.6e}", error);
82 fmt::print(fg(fmt::color::white), " tol {:.0e}\n", tol);
83}
Here is the caller graph for this function: