Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
IInternalLinearAlgebraExprT.h
Go to the documentation of this file.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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 * \file IInternalLinearAlgebraExprT.h
9 * \brief IInternalLinearAlgebraExprT.h
10 */
11#pragma once
12
13#include <alien/core/backend/IInternalLinearAlgebraT.h>
14#include <alien/utils/Precomp.h>
15#include <string>
16
17/*---------------------------------------------------------------------------*/
18/*---------------------------------------------------------------------------*/
19
20namespace Alien
21{
22
23class Space;
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \ingroup core
30 * \brief Internal linear algebra interface
31 *
32 * Internal interface for all linear algebra package
33 *
34 * \tparam M The type of matrix used
35 * \tparam V The type of vector used
36 */
37template <class M, class V>
39{
40 public:
41 //! Type of the matrix used
42 typedef M Matrix;
43 //! Type of the vector used
44 typedef V Vector;
45 //! Type of the the linear algebra
47
48 public:
49 //! Free resources
51
52 public:
53 /*!
54 * \brief Compute L0 norm of a vector
55 * \param[in] x The vector on which norm0 is computed
56 * \returns The norm0 of the vector
57 */
58 virtual Real norm0(const Vector& x) const = 0;
59
60 /*!
61 * \brief Compute L1 norm of a vector
62 * \param[in] x The vector on which norm0 is computed
63 * \returns The norm1 of the vector
64 */
65 virtual Real norm1(const Vector& x) const = 0;
66
67 /*!
68 * \brief Compute L2 norm of a vector
69 * \param[in] x The vector on which norm0 is computed
70 * \returns The norm2 of the vector
71 */
72 virtual Real norm2(const Vector& x) const = 0;
73
74 /*!
75 * \brief Compute LInf norm of a vector
76 * \param[in] x The vector on which norm0 is computed
77 * \returns The normInf of the vector
78 */
79 virtual Real normInf(const Vector& x) const = 0;
80
81 /*!
82 * \brief Compute L2 (Frobenous) norm of a matrix
83 * \param[in] x The matrix on which norm2 is computed
84 * \returns The norm2 of the matrix
85 */
86 virtual Real norm2(const Matrix& x) const = 0;
87
88 /*!
89 * \brief Compute a matrix vector product
90 *
91 * Compute the matrix-vector product a by x and store it in r : r = a * x
92 *
93 * \param[in] a The matrix to be multiplied
94 * \param[in] x The vector to be multipled
95 * \param[in,out] r The resulting vector
96 */
97 virtual void mult(const Matrix& a, const Vector& x, Vector& r) const = 0;
98
99 /*!
100 * \brief Scale a vector by a factor and adds the result to another vector
101 *
102 * Scale the vector x by the real value alpha and add the result to the vector y : y +=
103 * alpha * x
104 *
105 * \param[in] alpha The real value to scale with
106 * \param[in] x The vector to be scaled
107 * \param[in,out] y The resulting vector
108 */
109 virtual void axpy(Real alpha, const Vector& x, Vector& y) const = 0;
110
111 /*!
112 * \brief Scale a vector by a factor and adds the result to another vector
113 *
114 * Scale the vector y by the real value alpha and add the values of x : alpha * y += x
115 *
116 * \param[in] alpha The real value to scale with
117 * \param[in,out] y The vector to be scaled
118 * \param[in] x The vector to add
119 */
120 virtual void aypx(Real alpha, Vector& y, const Vector& x) const = 0;
121
122 /*!
123 * \brief Copy a vector in another one
124 *
125 * \param[in] x The vector to copy
126 * \param[in,out] r The copied vector
127 */
128 virtual void copy(const Vector& x, Vector& r) const = 0;
129
130 /*!
131 * \brief Copy a matrix in another one
132 *
133 * \param[in] x The vector to copy
134 * \param[in,out] r The copied vector
135 */
136 virtual void copy(const Matrix& a, Matrix& r) const = 0;
137
138 /*!
139 * \brief Add a matrix to another one
140 *
141 * \param[in] a The matrix to copy
142 *
143 * \param[in,out] r The copied vector
144 */
145 virtual void add(const Matrix& a, Matrix& r) const = 0;
146
147 /*!
148 * \brief Compute the dot product of two vectors
149 * \param[in] x The first vector
150 * \param[in] y The second vector
151 * \returns The dot product of x * y
152 */
153 virtual Real dot(const Vector& x, const Vector& y) const = 0;
154
155 /*!
156 * \brief Scale a vector by a factor
157 * \param[in] alpha The real value to scale with
158 * \param[in,out] x The vector to be scaled
159 */
160 virtual void scal(Real alpha, Vector& x) const = 0;
161
162 /*!
163 * \brief Scale a matrix by a factor
164 * \param[in] alpha The real value to scale with
165 * \param[in,out] x The vector to be scaled
166 */
167 virtual void scal(Real alpha, Matrix& a) const = 0;
168
169 /*!
170 * \brief Extract the diagonal of a matrix in a vector
171 * \param[in] a The matrix to extract the diagonal
172 * \param[in,out] x The diagonal elements of the matrix stored in a vector
173 */
174 virtual void diagonal(const Matrix& a, Vector& x) const = 0;
175
176 /*!
177 * \brief Compute the reciprocal of a vector
178 * \param[in,out] x The vector to be processed
179 */
180 virtual void reciprocal(Vector& x) const = 0;
181
182 /*!
183 * \brief Compute the point wise multiplication of two vectors and store the result in
184 * another one
185 * \param[in] x The first vector
186 * \param[in] y The second vector
187 * \param[in,out] w The resulting vector
188 */
189 virtual void pointwiseMult(const Vector& x, const Vector& y, Vector& w) const = 0;
190
191 /*!
192 * \brief Dumps a matrix to a file
193 * \param[in] a The matrix to dump
194 * \param[in] filename The name of the file
195 * \todo Implement this method
196 */
197 virtual void dump([[maybe_unused]] Matrix const& a, [[maybe_unused]] std::string const& filename) const
198 {
199 throw NotImplementedException(
200 A_FUNCINFO, "IInternalLinearAlgebra::dump not implemented");
201 }
202
203 /*!
204 * \brief Dumps a vector to a file
205 * \param[in] x The vector to dump
206 * \param[in] filename The name of the file
207 * \todo Implement this method
208 */
209 virtual void dump([[maybe_unused]] Vector const& x, [[maybe_unused]] std::string const& filename) const
210 {
211 throw NotImplementedException(
212 A_FUNCINFO, "IInternalLinearAlgebra::dump not implemented");
213 }
214
215 /*!
216 * \brief Compute a matrix vector product
217 *
218 * Compute the matrix-vector product a by x and store it in r : r = a * x
219 *
220 * \param[in] a The matrix to be multiplied
221 * \param[in] x The vector to be multipled
222 * \param[in,out] r The resulting vector
223 */
224 virtual void mult(
225 const Matrix& a, const UniqueArray<Real>& x, UniqueArray<Real>& r) const = 0;
226
227 /*!
228 * \brief Scale a vector by a factor and adds the result to another vector
229 *
230 * Scale the vector x by the real value alpha and add the result to the vector y : y +=
231 * alpha * x
232 *
233 * \param[in] alpha The real value to scale with
234 * \param[in] x The vector to be scaled
235 * \param[in,out] y The resulting vector
236 */
237 virtual void axpy(Real alpha, const UniqueArray<Real>& x, UniqueArray<Real>& y) const = 0;
238
239 /*!
240 * \brief Scale a vector by a factor and adds the result to another vector
241 *
242 * Scale the vector y by the real value alpha and add the values of x : alpha * y += x
243 *
244 * \param[in] alpha The real value to scale with
245 * \param[in,out] y The vector to be scaled
246 * \param[in] x The vector to add
247 */
248 virtual void aypx(Real alpha, UniqueArray<Real>& y, const UniqueArray<Real>& x) const = 0;
249
250 /*!
251 * \brief Copy a vector in another one
252 *
253 * \param[in] x The vector to copy
254 * \param[in,out] r The copied vector
255 */
256 virtual void copy(const UniqueArray<Real>& x, UniqueArray<Real>& r) const = 0;
257
258 /*!
259 * \brief Compute the dot product of two vectors
260 * \param[in] local_size The size of the vectors
261 * \param[in] x The first vector
262 * \param[in] y The second vector
263 * \returns The dot product of x * y
264 */
265 virtual Real dot(Integer local_size, const UniqueArray<Real>& x,
266 const UniqueArray<Real>& y) const = 0;
267
268 /*!
269 * \brief Scale a vector by a factor
270 * \param[in] alpha The real value to scale with
271 * \param[in,out] x The vector to be scaled
272 */
273 virtual void scal(Real alpha, UniqueArray<Real>& x) const = 0;
274};
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
278
279} // namespace Alien
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
Internal linear algebra interface.
virtual Real dot(Integer local_size, const UniqueArray< Real > &x, const UniqueArray< Real > &y) const =0
Compute the dot product of two vectors.
virtual void mult(const Matrix &a, const Vector &x, Vector &r) const =0
Compute a matrix vector product.
virtual ~IInternalLinearAlgebraExpr()
Free resources.
virtual void add(const Matrix &a, Matrix &r) const =0
Add a matrix to another one.
virtual void scal(Real alpha, Matrix &a) const =0
Scale a matrix by a factor.
virtual Real norm1(const Vector &x) const =0
Compute L1 norm of a vector.
virtual void copy(const UniqueArray< Real > &x, UniqueArray< Real > &r) const =0
Copy a vector in another one.
virtual Real dot(const Vector &x, const Vector &y) const =0
Compute the dot product of two vectors.
virtual void scal(Real alpha, Vector &x) const =0
Scale a vector by a factor.
virtual void diagonal(const Matrix &a, Vector &x) const =0
Extract the diagonal of a matrix in a vector.
virtual void axpy(Real alpha, const UniqueArray< Real > &x, UniqueArray< Real > &y) const =0
Scale a vector by a factor and adds the result to another vector.
virtual void dump(Matrix const &a, std::string const &filename) const
Dumps a matrix to a file.
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 norm0(const Vector &x) const =0
Compute L0 norm of a vector.
virtual Real normInf(const Vector &x) const =0
Compute LInf norm of a vector.
virtual void scal(Real alpha, UniqueArray< Real > &x) const =0
Scale a vector by a factor.
virtual void dump(Vector const &x, std::string const &filename) const
Dumps a vector to a file.
virtual Real norm2(const Matrix &x) const =0
Compute L2 (Frobenous) norm of a matrix.
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 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 copy(const Matrix &a, Matrix &r) const =0
Copy a matrix in another one.
virtual void reciprocal(Vector &x) const =0
Compute the reciprocal of a vector.
virtual void copy(const Vector &x, Vector &r) const =0
Copy a vector in another one.
virtual void aypx(Real alpha, UniqueArray< Real > &y, const UniqueArray< Real > &x) const =0
Scale a vector by a factor and adds the result to another vector.
virtual void mult(const Matrix &a, const UniqueArray< Real > &x, UniqueArray< Real > &r) const =0
Compute a matrix vector product.
virtual Real norm2(const Vector &x) const =0
Compute L2 norm of a vector.
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