Skip to content
Snippets Groups Projects

Add a static switch to choose verbosity of PCG/BiCGStab

Merged Stéphane Del Pino requested to merge feature/solvers-verbosity into develop
4 files
+ 38
20
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 18
9
@@ -5,14 +5,19 @@
#include <iomanip>
#include <iostream>
#include <rang.hpp>
template <bool verbose = true>
struct BiCGStab
{
template <typename VectorType, typename MatrixType>
BiCGStab(const VectorType& b, const MatrixType& A, VectorType& x, const size_t max_iter, const double epsilon = 1e-6)
{
std::cout << "- bi-conjugate gradient stabilized\n";
std::cout << " epsilon = " << epsilon << '\n';
std::cout << " maximum number of iterations: " << max_iter << '\n';
if constexpr (verbose) {
std::cout << "- bi-conjugate gradient stabilized\n";
std::cout << " epsilon = " << epsilon << '\n';
std::cout << " maximum number of iterations: " << max_iter << '\n';
}
VectorType r_k_1{b.size()};
@@ -33,10 +38,14 @@ struct BiCGStab
VectorType r_k{x.size()};
std::cout << " initial residu: " << resid0 << '\n';
if constexpr (verbose) {
std::cout << " initial residu: " << resid0 << '\n';
}
for (size_t i = 1; i <= max_iter; ++i) {
std::cout << " - iteration: " << std::setw(6) << i << "\tresidu: " << residu / resid0
<< "\tabsolute: " << residu << '\n';
if constexpr (verbose) {
std::cout << " - iteration: " << std::setw(6) << i << "\tresidu: " << residu / resid0
<< "\tabsolute: " << residu << '\n';
}
Ap_k = A * p_k;
@@ -64,14 +73,14 @@ struct BiCGStab
}
if (residu / resid0 > epsilon) {
std::cout << " bi_conjugate gradient stabilized: *NOT CONVERGED*\n";
std::cout << " bi-conjugate gradient stabilized: " << rang::fgB::red << "*NOT CONVERGED*" << rang::style::reset
<< '\n';
;
std::cout << " - epsilon: " << epsilon << '\n';
std::cout << " - relative residu : " << residu / resid0 << '\n';
std::cout << " - absolute residu : " << residu << '\n';
}
}
std::cout << "- bi-conjugate gradient stabilized: done\n";
}
};
Loading