deltaFlow
LoggingSolverObserver.H
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Saud Zahir
3 *
4 * This file is part of deltaFlow.
5 *
6 * deltaFlow is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * deltaFlow is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with deltaFlow. If not, see
18 * <https://www.gnu.org/licenses/>.
19 */
20
35#ifndef LOGGING_SOLVER_OBSERVER_H
36#define LOGGING_SOLVER_OBSERVER_H
37
38#include "ISolver.H"
39#include "Logger.H"
40#include "Progress.H"
41
47 public:
48 void onIteration(const char* solverName, int iter, int maxIter, double error, double tolerance) override {
49 printIterationProgress(solverName, iter, maxIter, error, tolerance);
50 LOG_DEBUG("{} iteration {}: error = {:.16e}", solverName, iter, error);
51 }
52
53 void onFinished(const char* solverName, bool converged, int iter, int maxIter, double error, double tolerance) override {
54 printConvergenceStatus(solverName, converged, iter, maxIter, error, tolerance);
55 if (converged) {
56 LOG_DEBUG("{} converged in {} iterations with error {:.6e}.", solverName, iter, error);
57 } else {
58 LOG_WARN("{} did not converge within {} iterations.", solverName, maxIter);
59 LOG_DEBUG("Final error was {:.6e}, tolerance is {:.6e}.", error, tolerance);
60 }
61 }
62
63 void onMessage(const char* solverName, const char* message) override {
64 (void)solverName;
65 LOG_DEBUG("{}", message);
66 }
67};
68
69#endif
Abstraction over power-flow solvers (Open/Closed Principle).
Logger utilities for deltaFlow, providing logging macros and a singleton Logger class.
#define LOG_WARN(msg,...)
Macro for logging a warning-level message.
Definition Logger.H:87
#define LOG_DEBUG(msg,...)
Macro for logging a debug-level message.
Definition Logger.H:85
Progress bar for iterative solvers.
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.
Definition Progress.H:50
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.
Definition Progress.H:100
Sink for solver progress/diagnostics (Dependency Inversion / SRP).
Definition ISolver.H:93
Reports solver progress to the Logger singleton and terminal progress bar.
void onFinished(const char *solverName, bool converged, int iter, int maxIter, double error, double tolerance) override
Called once after the iteration loop ends (converged or not).
void onMessage(const char *solverName, const char *message) override
Called for solver-specific diagnostic/warning messages (e.g.
void onIteration(const char *solverName, int iter, int maxIter, double error, double tolerance) override
Called after every iteration with the current error/tolerance.