23#include "arccore/alina/AMG.h"
24#include "arccore/alina/PreconditionedSolver.h"
25#include "arccore/alina/BuiltinBackend.h"
26#include "arccore/alina/Adapters.h"
27#include "arccore/alina/Coarsening.h"
28#include "arccore/alina/Relaxation.h"
29#include "arccore/alina/ConjugateGradientSolver.h"
30#include "arccore/alina/Profiler.h"
32#include "SampleProblemCommon.h"
35using namespace Arcane::Alina;
40 typedef double val_type;
41 typedef ptrdiff_t col_type;
48 , h2i((n - 1) * (n - 1))
51 size_t rows()
const {
return n * n; }
52 size_t nonzeros()
const {
return 5 * rows(); }
54 void operator()(
size_t row,
55 std::vector<col_type>& col,
56 std::vector<val_type>& val)
const
62 col.push_back(row - n);
67 col.push_back(row - 1);
72 val.push_back(4 * h2i);
75 col.push_back(row + 1);
80 col.push_back(row + n);
89double norm(
const Vec& v)
91 return sqrt(Arcane::Alina::backend::inner_product(v, v));
95int main(
int argc,
char* argv[])
97 auto& prof = Alina::Profiler::globalProfiler();
98 int m = argc > 1 ? atoi(argv[1]) : 1024;
111 Solver solve(Alina::adapter::make_matrix(
poisson_2d(m)));
114 std::cout << solve.precond() << std::endl;
116 std::vector<double> f(n, 1);
117 std::vector<double> x(n, 0);
123 std::cout <<
"Solver:" << std::endl
124 <<
" Iterations: " << r.nbIteration() << std::endl
125 <<
" Error: " << r.residual() << std::endl
138 std::fill(x.begin(), x.end(), 0);
140 prof.tic(
"nested solver");
141 r = S(solve.system_matrix(), solve, f, x);
142 prof.toc(
"nested solver");
144 std::cout <<
"Nested solver:" << std::endl
145 <<
" Iterations: " << r.nbIteration() << std::endl
146 <<
" Error: " << r.residual() << std::endl
149 std::cout << prof << std::endl;
Conjugate Gradients solver.
Convenience class that bundles together a preconditioner and an iterative solver.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Smoothed aggregation coarsening.