Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
make_block_solver.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/*---------------------------------------------------------------------------*/
9/*
10 * This file is based on the work on AMGCL library (version march 2026)
11 * which can be found at https://github.com/ddemidov/amgcl.
12 *
13 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
14 * SPDX-License-Identifier: MIT
15 */
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#ifndef ARCCORE_ALINA_MAKE_BLOCK_SOLVER_HPP
20#define ARCCORE_ALINA_MAKE_BLOCK_SOLVER_HPP
21
22#include "arccore/alina/BackendInterface.h"
23#include "arccore/alina/Adapters.h"
24#include "arccore/alina/StaticMatrix.h"
25#include "arccore/alina/PreconditionedSolver.h"
26#include "arccore/alina/AlinaUtils.h"
27
28namespace Arcane::Alina
29{
30
31/* Creates solver that operates in non-scalar domain but may take scalar inputs
32 * for the system matrix and the rhs/solution vectors.
33 */
34template <class Precond, class IterativeSolver>
35class make_block_solver
36{
37 public:
38
39 typedef typename Precond::backend_type backend_type;
40 typedef typename backend_type::value_type value_type;
41 typedef typename backend_type::params backend_params;
42 typedef typename backend_type::vector vector;
43 typedef typename math::scalar_of<value_type>::type scalar_type;
44
46
47 template <class Matrix>
48 make_block_solver(const AlinaContext& context,
49 const Matrix& A,
50 const params& prm = params(),
51 const backend_params& bprm = backend_params())
52 {
53 S = std::make_shared<Solver>(context, adapter::block_matrix<value_type>(A), prm, bprm);
54 }
55
56 template <class Matrix, class Vec1, class Vec2>
57 SolverResult operator()(const Matrix& A, const Vec1& rhs, Vec2&& x) const
58 {
59 auto F = backend::reinterpret_as_rhs<value_type>(rhs);
60 auto X = backend::reinterpret_as_rhs<value_type>(x);
61
62 return (*S)(A, F, X);
63 }
64
65 template <class Vec1, class Vec2>
66 SolverResult operator()(const Vec1& rhs, Vec2&& x) const
67 {
68 auto F = backend::reinterpret_as_rhs<value_type>(rhs);
69 auto X = backend::reinterpret_as_rhs<value_type>(x);
70
71 return (*S)(F, X);
72 }
73
74 std::shared_ptr<typename Precond::matrix> system_matrix_ptr() const
75 {
76 return S->system_matrix_ptr();
77 }
78
79 typename Precond::matrix const& system_matrix() const
80 {
81 return S->system_matrix();
82 }
83
84 friend std::ostream& operator<<(std::ostream& os, const make_block_solver& p)
85 {
86 return os << *p.S << std::endl;
87 }
88
89 size_t bytes() const
90 {
91 return backend::bytes(*S);
92 }
93
94 private:
95
97 std::shared_ptr<Solver> S;
98};
99
100} // namespace Arcane::Alina
101
102#endif
Convenience class that bundles together a preconditioner and an iterative solver.
Result of a solution.
Definition AlinaUtils.h:56
Matrix class, to be used by user.
Combined parameters of the bundled preconditioner and the iterative solver.