Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
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 const params& = params(),
63 const backend_params& = backend_params(),
64 const InnerProduct& inner_product = InnerProduct())
65 : n(n)
66 , inner_product(inner_product)
67 {}
68
84 template <class Matrix, class Precond, class Vec1, class Vec2>
85 SolverResult operator()(const Matrix&, const Precond& P, const Vec1& rhs, Vec2&& x) const
86 {
87 P.apply(rhs, x);
88 return SolverResult{};
89 }
90
101 template <class Precond, class Vec1, class Vec2>
102 SolverResult operator()(const Precond& P, const Vec1& rhs, Vec2&& x) const
103 {
104 return (*this)(P.system_matrix(), P, rhs, x);
105 }
106
107 size_t bytes() const
108 {
109 return 0;
110 }
111
112 friend std::ostream& operator<<(std::ostream& os, const PreconditionerOnlySolver& s)
113 {
114 return os
115 << "Type: PreOnly"
116 << "\nUnknowns: " << s.n
117 << "\nMemory footprint: " << human_readable_memory(s.bytes())
118 << std::endl;
119 }
120
121 private:
122
123 size_t n;
124
125 InnerProduct inner_product;
126
127 template <class Vec>
128 scalar_type norm(const Vec& x) const
129 {
130 return sqrt(math::norm(inner_product(x, x)));
131 }
132};
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137} // namespace Arcane::Alina
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142#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(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.
Base class for solvers.
Definition SolverBase.h:31
Result of a solving.
Definition AlinaUtils.h:52
Class to handle empty parameters list.
Definition AlinaUtils.h:90
Matrix class, to be used by user.
Default implementation for inner product.