Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
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 Matrix& A,
49 const params& prm = params(),
50 const backend_params& bprm = backend_params())
51 {
52 S = std::make_shared<Solver>(adapter::block_matrix<value_type>(A), prm, bprm);
53 }
54
55 template <class Matrix, class Vec1, class Vec2>
56 SolverResult operator()(const Matrix& A, const Vec1& rhs, Vec2&& x) const
57 {
58 auto F = backend::reinterpret_as_rhs<value_type>(rhs);
59 auto X = backend::reinterpret_as_rhs<value_type>(x);
60
61 return (*S)(A, F, X);
62 }
63
64 template <class Vec1, class Vec2>
65 SolverResult operator()(const Vec1& rhs, Vec2&& x) const
66 {
67 auto F = backend::reinterpret_as_rhs<value_type>(rhs);
68 auto X = backend::reinterpret_as_rhs<value_type>(x);
69
70 return (*S)(F, X);
71 }
72
73 std::shared_ptr<typename Precond::matrix> system_matrix_ptr() const
74 {
75 return S->system_matrix_ptr();
76 }
77
78 typename Precond::matrix const& system_matrix() const
79 {
80 return S->system_matrix();
81 }
82
83 friend std::ostream& operator<<(std::ostream& os, const make_block_solver& p)
84 {
85 return os << *p.S << std::endl;
86 }
87
88 size_t bytes() const
89 {
90 return backend::bytes(*S);
91 }
92
93 private:
94
96 std::shared_ptr<Solver> S;
97};
98
99} // namespace Arcane::Alina
100
101#endif
Convenience class that bundles together a preconditioner and an iterative solver.
Result of a solving.
Definition AlinaUtils.h:52
Matrix class, to be used by user.
Combined parameters of the bundled preconditioner and the iterative solver.