Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
DummyPreconditioner.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/* DummyPreconditioner.h (C) 2000-2026 */
9/* */
10/* Dummy preconditioner using identity matrix. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_DUMMYPRECONDITIONER_H
13#define ARCCORE_ALINA_DUMMYPRECONDITIONER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16/*
17 * This file is based on the work on AMGCL library (version march 2026)
18 * which can be found at https://github.com/ddemidov/amgcl.
19 *
20 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
21 * SPDX-License-Identifier: MIT
22 */
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26#include <memory>
27#include "arccore/alina/BuiltinBackend.h"
28#include "arccore/alina/AlinaUtils.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane::Alina::preconditioner
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
41template <class Backend>
42class DummyPreconditioner
43{
44 public:
45
46 typedef Backend backend_type;
47
48 typedef typename Backend::matrix matrix;
49 typedef typename Backend::vector vector;
50 typedef typename Backend::value_type value_type;
51 typedef typename Backend::col_type col_type;
52 typedef typename Backend::ptr_type ptr_type;
53 typedef typename BuiltinBackend<value_type, col_type, ptr_type>::matrix build_matrix;
54
55 typedef Alina::detail::empty_params params;
56 typedef typename Backend::params backend_params;
57
58 template <class Matrix>
59 DummyPreconditioner([[maybe_unused]] const AlinaContext& context,
60 const Matrix& M,
61 const params& = params(),
62 const backend_params& bprm = backend_params())
63 : A(Backend::copy_matrix(std::make_shared<build_matrix>(M), bprm))
64 {
65 }
66
67 DummyPreconditioner([[maybe_unused]] const AlinaContext& context,
68 std::shared_ptr<build_matrix> M,
69 const params& = params(),
70 const backend_params& bprm = backend_params())
71 : A(Backend::copy_matrix(M, bprm))
72 {
73 }
74
75 template <class Vec1, class Vec2>
76 void apply(const Vec1& rhs, Vec2&& x) const
77 {
78 backend::copy(rhs, x);
79 }
80
81 std::shared_ptr<matrix> system_matrix_ptr() const
82 {
83 return A;
84 }
85
86 const matrix& system_matrix() const
87 {
88 return *A;
89 }
90
91 size_t bytes() const
92 {
93 return 0;
94 }
95
96 private:
97
98 std::shared_ptr<matrix> A;
99
100 friend std::ostream& operator<<(std::ostream& os, const DummyPreconditioner& p)
101 {
102 os << "identity matrix as preconditioner" << std::endl;
103 os << " unknowns: " << backend::nbRow(p.system_matrix()) << std::endl;
104 os << " nonzeros: " << backend::nonzeros(p.system_matrix()) << std::endl;
105
106 return os;
107 }
108};
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113} // namespace Arcane::Alina::preconditioner
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117#endif
Class to handle empty parameter list.
Definition AlinaUtils.h:94
Matrix class, to be used by user.