Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
IInternalLinearAlgebraT.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#pragma once
8
9#include <alien/utils/Precomp.h>
10#include <string>
11
12/*---------------------------------------------------------------------------*/
13/*---------------------------------------------------------------------------*/
14
15namespace Alien
16{
17
18class Space;
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23/*!
24 * \ingroup core
25 * \brief Internal linear algebra interface
26 *
27 * Internal interface for all linear algebra package
28 *
29 * \tparam M The type of matrix used
30 * \tparam V The type of vector used
31 */
32template <class M, class V>
34{
35 public:
36 //! Type of the matrix used
37 typedef M Matrix;
38 //! Type of the vector used
39 typedef V Vector;
40 //! Type of the the linear algebra
42
43 using MatrixType = Matrix ;
44 using VectorType = Vector ;
45 using ValueType = Real ;
46
47 public:
48 //! Free resources
50
51 public:
52 /*!
53 * \brief Compute L0 norm of a vector
54 * \param[in] x The vector on which norm0 is computed
55 * \returns The norm0 of the vector
56 */
57 virtual Real norm0(const Vector& x) const = 0;
58
59 /*!
60 * \brief Compute L1 norm of a vector
61 * \param[in] x The vector on which norm0 is computed
62 * \returns The norm1 of the vector
63 */
64 virtual Real norm1(const Vector& x) const = 0;
65
66 /*!
67 * \brief Compute L2 norm of a vector
68 * \param[in] x The vector on which norm2 is computed
69 * \returns The norm2 of the vector
70 */
71 virtual Real norm2(const Vector& x) const = 0;
72
73
74 /*!
75 * \brief Compute LInf norm of a vector
76 * \param[in] x The vector on which normInf is computed
77 * \returns The normInf of the vector
78 */
79 virtual Real normInf(const Vector& x) const = 0;
80
81 /*!
82 * \brief Compute a matrix vector product
83 *
84 * Compute the matrix-vector product a by x and store it in r : r = a * x
85 *
86 * \param[in] a The matrix to be multiplied
87 * \param[in] x The vector to be multipled
88 * \param[in,out] r The resulting vector
89 */
90 virtual void mult(const Matrix& a, const Vector& x, Vector& r) const = 0;
91
92 /*!
93 * \brief Scale a vector by a factor and adds the result to another vector
94 *
95 * Scale the vector x by the real value alpha and add the result to the vector y : y +=
96 * alpha * x
97 *
98 * \param[in] alpha The real value to scale with
99 * \param[in] x The vector to be scaled
100 * \param[in,out] y The resulting vector
101 */
102 virtual void axpy(Real alpha, const Vector& x, Vector& y) const = 0;
103
104 /*!
105 * \brief Scale a vector by a factor and adds the result to another vector
106 *
107 * Scale the vector y by the real value alpha and add the values of x : alpha * y += x
108 *
109 * \param[in] alpha The real value to scale with
110 * \param[in,out] y The vector to be scaled
111 * \param[in] x The vector to add
112 */
113 virtual void aypx(Real alpha, Vector& y, const Vector& x) const = 0;
114
115 /*!
116 * \brief Copy a vector in another one
117 *
118 * \param[in] x The vector to copy
119 * \param[in,out] r The copied vector
120 */
121 virtual void copy(const Vector& x, Vector& r) const = 0;
122
123 /*!
124 * \brief Compute the dot product of two vectors
125 * \param[in] x The first vector
126 * \param[in] y The second vector
127 * \returns The dot product of x * y
128 */
129 virtual Real dot(const Vector& x, const Vector& y) const = 0;
130
131 /*!
132 * \brief Scale a vector by a factor
133 * \param[in] alpha The real value to scale with
134 * \param[in,out] x The vector to be scaled
135 */
136 virtual void scal(Real alpha, Vector& x) const = 0;
137
138 /*!
139 * \brief Extract the diagonal of a matrix in a vector
140 * \param[in] a The matrix to extract the diagonal
141 * \param[in,out] x The diagonal elements of the matrix stored in a vector
142 */
143 virtual void diagonal(const Matrix& a, Vector& x) const = 0;
144
145 /*!
146 * \brief Compute the reciprocal of a vector
147 * \param[in,out] x The vector to be processed
148 */
149 virtual void reciprocal(Vector& x) const = 0;
150
151 /*!
152 * \brief Compute the point wise multiplication of two vectors and store the result in
153 * another one
154 * \param[in] x The first vector
155 * \param[in] y The second vector
156 * \param[in,out] w The resulting vector
157 */
158 virtual void pointwiseMult(const Vector& x, const Vector& y, Vector& w) const = 0;
159
160 /*!
161 * \brief Dumps a matrix to a file
162 * \param[in] a The matrix to dump
163 * \param[in] filename The name of the file
164 * \todo Implement this method
165 */
166 virtual void dump([[maybe_unused]] Matrix const& a, [[maybe_unused]] std::string const& filename) const
167 {
168 throw NotImplementedException(
169 A_FUNCINFO, "IInternalLinearAlgebra::dump not implemented");
170 }
171
172 /*!
173 * \brief Dumps a vector to a file
174 * \param[in] x The vector to dump
175 * \param[in] filename The name of the file
176 * \todo Implement this method
177 */
178 virtual void dump([[maybe_unused]] Vector const& x, [[maybe_unused]] std::string const& filename) const
179 {
180 throw NotImplementedException(
181 A_FUNCINFO, "IInternalLinearAlgebra::dump not implemented");
182 }
183};
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188} // namespace Alien
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
Internal linear algebra interface.
virtual void dump(Matrix const &a, std::string const &filename) const
Dumps a matrix to a file.
virtual Real normInf(const Vector &x) const =0
Compute LInf norm of a vector.
virtual Real dot(const Vector &x, const Vector &y) const =0
Compute the dot product of two vectors.
virtual void axpy(Real alpha, const Vector &x, Vector &y) const =0
Scale a vector by a factor and adds the result to another vector.
virtual Real norm0(const Vector &x) const =0
Compute L0 norm of a vector.
virtual void mult(const Matrix &a, const Vector &x, Vector &r) const =0
Compute a matrix vector product.
virtual void scal(Real alpha, Vector &x) const =0
Scale a vector by a factor.
virtual void reciprocal(Vector &x) const =0
Compute the reciprocal of a vector.
virtual ~IInternalLinearAlgebra()
Free resources.
virtual void pointwiseMult(const Vector &x, const Vector &y, Vector &w) const =0
Compute the point wise multiplication of two vectors and store the result in another one.
virtual Real norm1(const Vector &x) const =0
Compute L1 norm of a vector.
virtual void dump(Vector const &x, std::string const &filename) const
Dumps a vector to a file.
virtual Real norm2(const Vector &x) const =0
Compute L2 norm of a vector.
virtual void aypx(Real alpha, Vector &y, const Vector &x) const =0
Scale a vector by a factor and adds the result to another vector.
virtual void diagonal(const Matrix &a, Vector &x) const =0
Extract the diagonal of a matrix in a vector.
virtual void copy(const Vector &x, Vector &r) const =0
Copy a vector in another one.
Implementation of an algebraic space.
Definition Space.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17