Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
PreconditionerOnlySolver.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/* solver_preonly.h (C) 2000-2026 */
9/* */
10/* Solver which only apply preconditioner once. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_PRECONDITIONERONLYSOLVER_H
13#define ARCCORE_ALINA_PRECONDITIONERONLYSOLVER_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 "arccore/alina/SolverUtils.h"
27#include "arccore/alina/AlinaUtils.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane::Alina
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
40template <class Backend, class InnerProduct = detail::default_inner_product>
42: public SolverBase
43{
44 public:
45
46 typedef Backend backend_type;
47
48 typedef typename Backend::vector vector;
49 typedef typename Backend::value_type value_type;
50 typedef typename Backend::params backend_params;
51
52 typedef typename math::scalar_of<value_type>::type scalar_type;
53
54 typedef typename math::inner_product_impl<
55 typename math::rhs_of<value_type>::type>::return_type coef_type;
56
59
62 size_t n,
63 const params& = params(),
64 const backend_params& = backend_params(),
65 const InnerProduct& inner_product = InnerProduct())
66 : SolverBase(context)
67 , n(n)
68 , inner_product(inner_product)
69 {}
70
86 template <class Matrix, class Precond, class Vec1, class Vec2>
87 SolverResult operator()(const Matrix&, const Precond& P, const Vec1& rhs, Vec2&& x) const
88 {
89 P.apply(rhs, x);
90 return SolverResult{};
91 }
92
103 template <class Precond, class Vec1, class Vec2>
104 SolverResult operator()(const Precond& P, const Vec1& rhs, Vec2&& x) const
105 {
106 return (*this)(P.system_matrix(), P, rhs, x);
107 }
108
109 size_t bytes() const
110 {
111 return 0;
112 }
113
114 friend std::ostream& operator<<(std::ostream& os, const PreconditionerOnlySolver& s)
115 {
116 return os
117 << "Type: PreOnly"
118 << "\nUnknowns: " << s.n
119 << "\nMemory footprint: " << human_readable_memory(s.bytes())
120 << std::endl;
121 }
122
123 private:
124
125 size_t n;
126
127 InnerProduct inner_product;
128
129 template <class Vec>
130 scalar_type norm(const Vec& x) const
131 {
132 return sqrt(math::norm(inner_product(x, x)));
133 }
134};
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139} // namespace Arcane::Alina
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144#endif
Solver which only apply preconditioner once.
SolverResult operator()(const Precond &P, const Vec1 &rhs, Vec2 &&x) const
Computes the solution for the given right-hand side.
SolverResult operator()(const Matrix &, const Precond &P, const Vec1 &rhs, Vec2 &&x) const
Computes the solution for the given system matrix.
PreconditionerOnlySolver(const AlinaContext &context, size_t n, const params &=params(), const backend_params &=backend_params(), const InnerProduct &inner_product=InnerProduct())
Preallocates necessary data structures for the system of size n.
size_t bytes() const
Memory used in bytes.
Result of a solution.
Definition AlinaUtils.h:56
Class to handle empty parameter list.
Definition AlinaUtils.h:94
Matrix class, to be used by user.
Default implementation for inner product.