Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
core/matvec/Matrix.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* Matrix.h (C) 2000-2022 */
9/* */
10/* Matrix d'algèbre linéraire. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MATVEC_MATRIX_H
13#define ARCANE_MATVEC_MATRIX_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArcanePrecomp.h"
18
19#include "arcane/utils/Array.h"
20#include "arcane/utils/Numeric.h"
21
22#include "arcane/matvec/Vector.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::MatVec
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33class Vector;
34class MatrixImpl;
35class IPreconditioner;
36class AMG;
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
45class ARCANE_CORE_EXPORT Matrix
46{
47 public:
48
49 Matrix()
50 : m_impl(0)
51 {}
52 Matrix(Integer nb_row, Integer nb_column);
53 Matrix(const Matrix& rhs);
54 ~Matrix();
55 void operator=(const Matrix& rhs);
56
57 private:
58
59 Matrix(MatrixImpl* impl);
60
61 public:
62
64 Matrix clone() const;
65
66 public:
67
68 // Nombre de lignes de la matrice
69 Integer nbRow() const;
70 // Nombre de colonnes de la matrice
71 Integer nbColumn() const;
73 void setRowsSize(IntegerConstArrayView rows_size);
75 void setValues(IntegerConstArrayView columns, RealConstArrayView values);
77 void dump(std::ostream& o) const;
79 RealConstArrayView values() const;
81 RealArrayView values();
83 IntegerConstArrayView rowsIndex() const;
85 IntegerConstArrayView columns() const;
87 IntegerArrayView rowsIndex();
89 IntegerArrayView columns();
91 void setValue(Integer row, Integer column, Real value);
93 Real value(Integer row, Integer column) const;
95 void sortDiagonale();
97 static Matrix read(const String& filename);
99 static Matrix readHypre(const String& filename);
100
101 private:
102
105};
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
117class ARCANE_CORE_EXPORT IPreconditioner
118{
119 public:
120
121 virtual ~IPreconditioner() {}
122
123 public:
124
125 virtual void apply(Vector& out_vec, const Vector& vec) = 0;
126};
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131class ARCANE_CORE_EXPORT ConjugateGradientSolver
132{
133 public:
134
136 : m_nb_iteration(0)
137 , m_residual_norm(0.0)
138 , m_max_iteration(5000)
139 {}
140 bool solve(const Matrix& a, const Vector& b, Vector& x, Real epsilon, IPreconditioner* p = 0);
141 Integer nbIteration() const { return m_nb_iteration; }
142 Real residualNorm() const { return m_residual_norm; }
143 void setMaxIteration(Integer max_iteration)
144 {
145 m_max_iteration = max_iteration;
146 }
147
148 private:
149
150 Integer m_nb_iteration;
151 Real m_residual_norm;
152 Integer m_max_iteration;
153
154 private:
155
156 void _applySolver(const Matrix& a, const Vector& b, Vector& x, Real epsilon, IPreconditioner* p);
157 void _applySolver2(const Matrix& a, const Vector& b, Vector& x, Real epsilon, IPreconditioner* precond);
158 void _applySolverAsHypre(const Matrix& a, const Vector& b, Vector& x, Real tol, IPreconditioner* precond);
159};
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
169class ARCANE_CORE_EXPORT DiagonalPreconditioner
170: public IPreconditioner
171{
172 public:
173
174 DiagonalPreconditioner(const Matrix& matrix);
175
176 public:
177
178 virtual void apply(Vector& out_vec, const Vector& vec);
179
180 private:
181
182 Vector m_inverse_diagonal;
183};
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188class ARCANE_CORE_EXPORT MatrixOperation
189{
190 public:
191
192 void matrixVectorProduct(const Matrix& mat, const Vector& vec, Vector& out_vec);
193 void matrixVectorProduct2(const Matrix& mat, const Vector& vec, Vector& out_vec);
194 Real dot(const Vector& vec);
195 Real dot(const Vector& vec1, const Vector& vec2);
196 void negateVector(Vector& vec);
197 void scaleVector(Vector& vec, Real mul);
198 void addVector(Vector& out_vec, const Vector& vec);
199};
200
201class ARCANE_CORE_EXPORT MatrixOperation2
202{
203 public:
204
205 Matrix matrixMatrixProduct(const Matrix& left_matrix, const Matrix& right_matrix);
206 Matrix matrixMatrixProductFast(const Matrix& left_matrix, const Matrix& right_matrix);
207 Matrix transpose(const Matrix& matrix);
208 Matrix transposeFast(const Matrix& matrix);
209 // Applique le produit de matrice L * M * R avec L = transpose(R)
210 Matrix applyGalerkinOperator(const Matrix& left_matrix, const Matrix& matrix, const Matrix& right_matrix);
211 Matrix applyGalerkinOperator2(const Matrix& left_matrix, const Matrix& matrix,
212 const Matrix& right_matrix);
213
214 private:
215
216 void _dumpColumnMatrix(std::ostream& o, IntegerConstArrayView columns_index,
218 RealConstArrayView values);
219};
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224class ARCANE_CORE_EXPORT AMGPreconditioner
225: public IPreconditioner
226{
227 public:
228
230 : m_trace_mng(tm)
231 , m_amg(0)
232 {}
233 virtual ~AMGPreconditioner();
234
235 public:
236
237 virtual void build(const Matrix& matrix);
238
239 public:
240
241 virtual void apply(Vector& out_vec, const Vector& vec);
242
243 private:
244
245 ITraceMng* m_trace_mng;
246 AMG* m_amg;
247};
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252class ARCANE_CORE_EXPORT AMGSolver
253{
254 public:
255
257 : m_trace_mng(tm)
258 , m_amg(0)
259 {}
260 virtual ~AMGSolver();
261
262 public:
263
264 virtual void build(const Matrix& matrix);
265
266 public:
267
268 virtual void solve(const Vector& vector_b, Vector& vector_x);
269
270 private:
271
272 ITraceMng* m_trace_mng;
273 AMG* m_amg;
274};
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
284class ARCANE_CORE_EXPORT DirectSolver
285{
286 public:
287
288 void solve(const Matrix& matrix, const Vector& vector_b, Vector& vector_x);
289
290 private:
291
292 void _solve(RealArrayView mat_values, RealArrayView vec_values, Integer size);
293};
294
295/*---------------------------------------------------------------------------*/
296/*---------------------------------------------------------------------------*/
297
298} // namespace Arcane::MatVec
299
300/*---------------------------------------------------------------------------*/
301/*---------------------------------------------------------------------------*/
302
303#endif
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Solveur direct utilisant le pivot de gauss.
Interface d'un préconditionneur.
Matrice avec stockage CSR.
Definition Matrix.cc:40
Matrice avec stockage CSR.
MatrixImpl * m_impl
Implémentation.
Vecteur d'algèbre linéraire.
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
Interface du gestionnaire de traces.
Chaîne de caractères unicode.