14#include "arccore/alina/RelaxationRuntime.h"
15#include "arccore/alina/CoarseningRuntime.h"
16#include "arccore/alina/SolverRuntime.h"
17#include "arccore/alina/PreconditionedSolver.h"
18#include "arccore/alina/DistributedSolverRuntime.h"
19#include "arccore/alina/DistributedDirectSolverRuntime.h"
20#include "arccore/alina/DistributedSubDomainDeflation.h"
21#include "arccore/alina/AMG.h"
22#include "arccore/alina/BuiltinBackend.h"
23#include "arccore/alina/AlinaLib.h"
54struct AlinaPreconditioner
56 explicit AlinaPreconditioner(PreconditionerType* preconditioner)
57 : m_preconditioner(preconditioner)
59 ~AlinaPreconditioner()
62 delete m_preconditioner;
64 PreconditionerType* m_preconditioner =
nullptr;
70struct AlinaSequentialSolver
72 explicit AlinaSequentialSolver(SequentialSolverType* solver)
75 ~AlinaSequentialSolver()
79 SequentialSolverType* m_solver =
nullptr;
85struct AlinaDistributedSolver
87 explicit AlinaDistributedSolver(DistributedSolverType* solver)
90 ~AlinaDistributedSolver()
94 DistributedSolverType* m_solver =
nullptr;
104 x.iterations = r.nbIteration();
105 x.residual = r.residual();
115 return new AlinaParameters();
124 prm->m_properties.put(name, value);
133 prm->m_properties.put(name, value);
140params_set_string(
AlinaParameters* prm,
const char* name,
const char* value)
142 prm->m_properties.put(name, value);
151 Params& p = prm->m_properties;
168preconditioner_create(
int n,
174 SmallSpan<const int> ptr_range(ptr, n + 1);
175 SmallSpan<const int> col_range(col, ptr[n]);
176 SmallSpan<const double> val_range(val, ptr[n]);
178 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
180 PreconditionerType* amg =
nullptr;
182 amg =
new PreconditionerType(A, prm->m_properties);
184 amg =
new PreconditionerType(A);
185 return new AlinaPreconditioner(amg);
194 PreconditionerType* amg = handle->m_preconditioner;
196 size_t n = Alina::backend::nbRow(amg->system_matrix());
198 SmallSpan<double> x_range(x, n);
199 SmallSpan<const double> rhs_range(rhs, n);
201 amg->apply(rhs_range, x_range);
210 std::cout << *(handle->m_preconditioner) << std::endl;
226solver_create(
int n,
const int* ptr,
231 SmallSpan<const int> ptr_range(ptr, n + 1);
232 SmallSpan<const int> col_range(col, ptr[n]);
233 SmallSpan<const double> val_range(val, ptr[n]);
235 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
237 SequentialSolverType* solver =
new SequentialSolverType(A);
239 solver =
new SequentialSolverType(A, prm->m_properties);
241 solver =
new SequentialSolverType(A);
242 return new AlinaSequentialSolver(solver);
251 SequentialSolverType* slv = handle->m_solver;
253 std::cout << slv->
precond() << std::endl;
273 SequentialSolverType* slv = handle->m_solver;
275 size_t n = slv->
size();
277 SmallSpan<double> x_range(x, n);
278 SmallSpan<const double> rhs_range(rhs, n);
280 Alina::SolverResult r = (*slv)(rhs_range, x_range);
282 return _toConvInfo(r);
296 SequentialSolverType* slv = handle->m_solver;
298 size_t n = slv->
size();
300 SmallSpan<double> x_range(x, n);
301 SmallSpan<const double> rhs_range(rhs, n);
303 SmallSpan<const int> ptr_range(A_ptr, n + 1);
304 SmallSpan<const int> col_range(A_col, A_ptr[n]);
305 SmallSpan<const double> val_range(A_val, A_ptr[n]);
307 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
309 Alina::SolverResult r = (*slv)(A, rhs_range, x_range);
311 return _toConvInfo(r);
317struct deflation_vectors
320 AlinaDefVecFunction user_func;
323 deflation_vectors(
int n, AlinaDefVecFunction user_func,
void* user_data)
325 , user_func(user_func)
326 , user_data(user_data)
329 int dim()
const {
return n; }
331 double operator()(
int i, ptrdiff_t j)
const
333 return user_func(i, j, user_data);
339solver_mpi_create(MPI_Comm comm,
341 const ptrdiff_t* ptr,
342 const ptrdiff_t* col,
345 AlinaDefVecFunction def_vec_func,
349 std::function<double(ptrdiff_t,
unsigned)> dv =
deflation_vectors(n_def_vec, def_vec_func, def_vec_data);
351 prm.put(
"num_def_vec", n_def_vec);
352 prm.put(
"def_vec", &dv);
358 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
360 auto* p =
new DistributedSolverType(mpi_comm, A, prm);
373 DistributedSolverType* solver = handle->m_solver;
375 size_t n = solver->size();
377 SmallSpan<double> x_range(x, n);
378 SmallSpan<const double> rhs_range(rhs, n);
380 AlinaConvergenceInfo cnv;
382 std::tie(cnv.iterations, cnv.residual) = (*solver)(rhs_range, x_range);
Algebraic multigrid method.
Runtime wrapper for distributed direct solvers.
Distributed solver based on subdomain deflation.
Convenience class that bundles together a preconditioner and an iterative solver.
const Precond & precond() const
Returns reference to the constructed preconditioner.
size_t size() const
Returns the size of the system matrix.
Vue d'un tableau d'éléments de type T.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Convenience wrapper around MPI_Comm.