12#ifndef ARCCORE_ALINA_PRECONDITIONEDSOLVER_H
13#define ARCCORE_ALINA_PRECONDITIONEDSOLVER_H
26#include "arccore/alina/BuiltinBackend.h"
27#include "arccore/alina/AlinaUtils.h"
32namespace Arcane::Alina
40template <
class Precond,
class IterativeSolver>
45 typename IterativeSolver::backend_type,
46 typename Precond::backend_type>::value,
47 "Backends for preconditioner and iterative solver should be compatible");
51 typedef typename IterativeSolver::backend_type backend_type;
52 typedef typename backend_type::matrix matrix;
54 typedef typename backend_type::value_type value_type;
55 typedef typename backend_type::col_type col_type;
56 typedef typename backend_type::ptr_type ptr_type;
57 typedef typename backend_type::params backend_params;
58 typedef typename BuiltinBackend<value_type, col_type, ptr_type>::matrix build_matrix;
60 typedef typename math::scalar_of<value_type>::type scalar_type;
68 typename IterativeSolver::params
solver;
73 : ARCCORE_ALINA_PARAMS_IMPORT_CHILD(p,
precond)
74 , ARCCORE_ALINA_PARAMS_IMPORT_CHILD(p,
solver)
76 p.check_params( {
"precond",
"solver" });
79 void get(PropertyTree& p,
const std::string& path =
"")
const
81 ARCCORE_ALINA_PARAMS_EXPORT_CHILD(p, path,
precond);
82 ARCCORE_ALINA_PARAMS_EXPORT_CHILD(p, path,
solver);
89 template <
class Matrix>
91 const params& prm = params(),
92 const backend_params& bprm = backend_params())
94 , n(backend::nbRow(A))
96 , S(backend::nbRow(A), prm.
solver, bprm)
103 const backend_params& bprm = backend_params())
105 , n(backend::nbRow(*A))
107 , S(backend::nbRow(*A), prm.solver, bprm)
124 template <
class Matrix,
class Vec1,
class Vec2>
127 return S(A, P, rhs, x);
135 template <
class Vec1,
class Vec2>
166 template <
class Vec1,
class Vec2>
167 void apply(
const Vec1& rhs, Vec2&& x)
const
200 return P.system_matrix_ptr();
203 typename Precond::matrix
const& system_matrix()
const
205 return P.system_matrix();
222 return backend::bytes(S) + backend::bytes(P);
227 return os <<
"Solver\n======\n"
229 <<
"Preconditioner\n==============\n"
PreconditionedSolver(const Matrix &A, const params &prm=params(), const backend_params &bprm=backend_params())
Sets up the preconditioner and creates the iterative solver.
IterativeSolver & solver()
Returns reference to the constructed iterative solver.
SolverResult operator()(const Vec1 &rhs, Vec2 &&x) const
const Precond & precond() const
Returns reference to the constructed preconditioner.
std::shared_ptr< typename Precond::matrix > system_matrix_ptr() const
Returns the system matrix in the backend format.
Precond & precond()
Returns reference to the constructed preconditioner.
void get_params(Alina::PropertyTree &p) const
Stores the parameters used during construction into the property tree p.
size_t size() const
Returns the size of the system matrix.
const IterativeSolver & solver() const
Returns reference to the constructed iterative solver.
void apply(const Vec1 &rhs, Vec2 &&x) const
SolverResult operator()(const Matrix &A, const Vec1 &rhs, Vec2 &&x) const
Matrix class, to be used by user.
Combined parameters of the bundled preconditioner and the iterative solver.
Precond::params precond
Preconditioner parameters.
IterativeSolver::params solver
Iterative solver parameters.
Metafunction that checks if two backends are compatible.