40struct RichardsonSolverParams
42 using params = RichardsonSolverParams;
54 double abstol = std::numeric_limits<double>::min();
63 RichardsonSolverParams() =
default;
66 : ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p,
damping)
67 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p,
maxiter)
68 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p,
tol)
69 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p,
abstol)
70 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p,
ns_search)
71 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p,
verbose)
73 p.check_params({
"damping",
"maxiter",
"tol",
"abstol",
"ns_search",
"verbose" });
78 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path,
damping);
79 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path,
maxiter);
80 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path,
tol);
81 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path,
abstol);
82 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path,
ns_search);
83 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path,
verbose);
98 typedef Backend backend_type;
100 typedef typename Backend::vector vector;
101 typedef typename Backend::value_type value_type;
104 typedef typename math::scalar_of<value_type>::type scalar_type;
107 typename math::rhs_of<value_type>::type>::return_type coef_type;
115 const params& prm = params(),
116 const backend_params& backend_prm = backend_params(),
117 const InnerProduct& inner_product = InnerProduct())
120 , r(Backend::create_vector(n, backend_prm))
121 , s(Backend::create_vector(n, backend_prm))
122 , inner_product(inner_product)
140 template <
class Matrix,
class Precond,
class Vec1,
class Vec2>
143 static const coef_type one = math::identity<coef_type>();
147 scalar_type norm_rhs = norm(rhs);
148 if (norm_rhs < Alina::detail::eps<scalar_type>(1)) {
150 norm_rhs = math::identity<scalar_type>();
158 scalar_type eps = std::max(prm.tol * norm_rhs, prm.abstol);
160 backend::residual(rhs, A, x, *r);
161 scalar_type res_norm = norm(*r);
164 for (; iter < prm.maxiter && math::norm(res_norm) > eps; ++iter) {
166 backend::axpby(prm.damping, *s, one, x);
167 backend::residual(rhs, A, x, *r);
170 if (prm.verbose && iter % 5 == 0)
171 std::cout << iter <<
"\t" << std::scientific << res_norm / norm_rhs << std::endl;
187 template <
class Precond,
class Vec1,
class Vec2>
190 return (*
this)(P.system_matrix(), P, rhs, x);
195 return backend::bytes(*r) +
199 friend std::ostream& operator<<(std::ostream& os,
const RichardsonSolver& s)
201 return os <<
"Type: Richardson"
202 <<
"\nUnknowns: " << s.n
203 <<
"\nMemory footprint: " << human_readable_memory(s.
bytes())
215 std::shared_ptr<vector> r;
216 std::shared_ptr<vector> s;
218 InnerProduct inner_product;
221 scalar_type norm(
const Vec& x)
const
223 return sqrt(math::norm(inner_product(x, x)));
RichardsonSolver(size_t n, const params &prm=params(), const backend_params &backend_prm=backend_params(), const InnerProduct &inner_product=InnerProduct())
Preallocates necessary data structures for the system of size n.