23 #include "../config/config.hpp"
28 #ifdef MFEM_USE_GINKGO
29 #include <ginkgo/ginkgo.hpp>
34 namespace GinkgoWrappers
38 template <
typename ValueType=
double>
39 double get_norm(
const gko::matrix::Dense<ValueType> *norm)
42 auto cpu_norm = clone(norm->get_executor()->get_master(), norm);
44 return cpu_norm->at(0, 0);
49 template <
typename ValueType=
double>
53 auto exec = b->get_executor();
55 auto b_norm = gko::initialize<gko::matrix::Dense<ValueType>>({0.0}, exec);
57 b->compute_norm2(lend(b_norm));
59 return std::pow(
get_norm(lend(b_norm)),2);
73 template <
typename ValueType=
double>
80 mfem::out <<
"Iteration log with real residual norms:" << std::endl;
81 mfem::out <<
'|' << std::setw(10) <<
"Iteration" <<
'|' << std::setw(25)
82 <<
"Real Residual Norm" <<
'|' << std::endl;
85 mfem::out <<
'|' << std::setfill(
'-') << std::setw(11) <<
'|' <<
86 std::setw(26) <<
'|' << std::setfill(
' ') << std::endl;
89 for (std::size_t i = 0; i < iterations.size(); i++)
91 mfem::out <<
'|' << std::setw(10) << iterations[i] <<
'|'
92 << std::setw(25) << real_norms[i] <<
'|' << std::endl;
96 mfem::out.unsetf(std::ios_base::floatfield);
98 mfem::out <<
'|' << std::setfill(
'-') << std::setw(11) <<
'|' <<
99 std::setw(26) <<
'|' << std::setfill(
' ') << std::endl;
107 const gko::size_type &iteration,
108 const gko::LinOp *residual,
109 const gko::LinOp *solution,
110 const gko::LinOp *residual_norm)
const override
133 auto exec = matrix->get_executor();
135 auto one = gko::initialize<gko_dense>({1.0}, exec);
137 auto neg_one = gko::initialize<gko_dense>({-1.0}, exec);
139 auto res = gko::clone(b);
142 matrix->apply(gko::lend(one), gko::lend(solution),
143 gko::lend(neg_one), gko::lend(res));
153 real_norms.push_back(-1.0);
157 iterations.push_back(iteration);
162 const gko::LinOp *matrix,
const gko_dense *b)
163 : gko::log::Logger(exec,
164 gko::log::Logger::iteration_complete_mask),
171 const gko::LinOp *matrix;
175 mutable std::vector<ValueType> recurrent_norms{};
177 mutable std::vector<ValueType> real_norms{};
179 mutable std::vector<std::size_t> iterations{};
244 int max_num_iter,
double RTOLERANCE,
double ATOLERANCE);
292 std::shared_ptr<gko::stop::ResidualNormReduction<>::Factory>
326 initialize_ginkgo_log(gko::matrix::Dense<double>*
b);
335 std::shared_ptr<gko::matrix::Csr<>> system_matrix;
342 const std::string exec_type;
364 const std::string & exec_type,
382 const std::string & exec_type,
387 const gko::LinOpFactory* preconditioner
410 const std::string & exec_type,
428 const std::string & exec_type,
433 const gko::LinOpFactory* preconditioner
459 const std::string & exec_type,
477 const std::string & exec_type,
482 const gko::LinOpFactory* preconditioner
515 const std::string & exec_type,
533 const std::string & exec_type,
538 const gko::LinOpFactory* preconditioner
563 const std::string & exec_type,
581 const std::string & exec_type,
586 const gko::LinOpFactory* preconditioner
615 const std::string & exec_type,
633 const std::string & exec_type,
638 const gko::LinOpFactory *inner_solver
647 #endif // MFEM_GINKGO
CGSSolver(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
ResidualLogger(std::shared_ptr< const gko::Executor > exec, const gko::LinOp *matrix, const gko_dense *b)
FCGSolver(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
std::shared_ptr< ResidualLogger<> > residual_logger
void solve(const SparseMatrix *matrix, Vector &solution, const Vector &rhs)
GMRESSolver(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
std::shared_ptr< gko::LinOpFactory > solver_gen
std::shared_ptr< gko::stop::Combined::Factory > combined_factory
double get_norm(const gko::matrix::Dense< ValueType > *norm)
CGSolver(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
void on_iteration_complete(const gko::LinOp *, const gko::size_type &iteration, const gko::LinOp *residual, const gko::LinOp *solution, const gko::LinOp *residual_norm) const override
std::shared_ptr< gko::stop::ResidualNormReduction<>::Factory > residual_criterion
void initialize(const SparseMatrix *matrix)
void apply(Vector &solution, const Vector &rhs)
virtual ~GinkgoIterativeSolverBase()=default
BICGSTABSolver(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
double compute_norm(const gko::matrix::Dense< ValueType > *b)
std::shared_ptr< gko::log::Convergence<> > convergence_logger
std::shared_ptr< gko::Executor > executor
IRSolver(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
gko::matrix::Dense< ValueType > gko_dense
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
GinkgoIterativeSolverBase(const std::string &exec_type, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)