16#include <Matrice_Dense.h>
20#include <Matrice_Morse.h>
29 for(
int i=0; i<nb_lines; i++)
31 for(
int j=0; j<nb_cols; j++)
33 s << Matrix_( i , j )<<
" ";
51 s << nb_cols <<
"\n\n";
52 for(
int i=0; i<nb_lines; i++)
54 for(
int j=0; j<nb_cols; j++)
56 s << Matrix_( i , j )<<
" ";
84 std::ifstream file(filename, ios::in);
85 int nb_lines, nb_cols;
92 for(
int i=0; i<nb_lines; i++)
94 for(
int j=0; j<nb_cols; j++)
96 file >> Matrix_( i , j );
102 Cerr<<
"Error in Matrice_Dense::read_from_file"<<finl;
103 Cerr<<
"The file "<<filename<<
" was not found or a problem occured while opening the file"<<finl;
104 Cerr<<
"Aborting..."<<finl;
119 assert( coefficients.
size( ) == nb_lines * nb_cols );
122 for(
int i=0; i<nb_lines; i++)
124 for(
int j=0; j<nb_cols; j++)
126 Matrix_( i , j ) = coefficients( counter );
136 assert( coefficients.
size( ) == nb_lines * nb_cols );
139 for(
int j=0; j<nb_cols; j++)
141 for(
int i=0; i<nb_lines; i++)
143 Matrix_( i , j ) = coefficients( counter );
154 int nnz = nb_lines * nb_cols ;
158 int size_tab1 = nb_lines + 1 ;
159 int size_tab2 = nnz ;
164 for(
int i=0; i<size_tab1; i++)
169 for(
int i=0 ; i<nb_lines ; i++)
171 for(
int j=0; j<nb_cols; j++)
183 Matrix_.resize( nb_lines , nb_cols );
188 return Matrix_.dimension( 0 );
193 return Matrix_.dimension( 1 );
200 if( nb_lines == nb_cols )
221 assert( resu.
size_array( ) == nb_lines || resu.
size( ) == nb_lines );
226 for(
int i=0; i<nb_lines; i++)
228 double old_resu = resu( i );
229 double prod_mat_vect = 0;
230 for(
int j=0; j<nb_cols; j++)
232 prod_mat_vect += Matrix_( i , j ) * x( j );
234 resu( i ) = old_resu + prod_mat_vect ;
245 Matrix_( i , j ) = value;
253 for(
int j=0; j<nb_cols; j++)
255 for(
int i=0; i<nb_lines; i++)
257 double value = Matrix_( i , j );
272 if( other_matrix.
nb_lignes( ) != nb_lines )
281 for(
int i=0; i<nb_lines; i++)
283 for(
int j=0; j<nb_cols; j++)
285 if( std::fabs( other_matrix( i , j ) - Matrix_( i , j )) >= tol )
306 assert( resu.
size_array( ) == nb_cols || resu.
size( ) == nb_cols );
311 for(
int i=0; i<nb_cols; i++)
313 double old_resu = resu( i );
314 double prod_mat_vect = 0;
315 for(
int j=0; j<nb_lines; j++)
317 prod_mat_vect += Matrix_( j , i ) * x( j );
319 resu( i ) = old_resu + prod_mat_vect ;
329 for(
int i=0; i<nb_lines; i++)
331 for(
int j=0; j<nb_cols; j++)
333 Matrix_( i , j ) *= x ;
343 for(
int i=0; i<nb_lines; i++)
345 for(
int j=0; j<nb_cols; j++)
347 Matrix_( i , j ) = 0. ;
360 for(
int i=0; i<nb_lines; i++)
362 for(
int j=0; j<nb_cols; j++)
368 const int new_size = stencil.
dimension( 0 );
369 stencil.
resize( new_size, 2 );
376 Cerr<<
"Error in Matrice_Dense::ajouter_multTab_ ."<<finl;
377 Cerr<<
"This function is virtual pure in Matrice_Base but seems never used."<<finl;
378 Cerr<<
"One should get rid off it."<<finl;
379 Cerr<<
"Aborting..."<<finl;
391 if (ipiv.size_array()!=nbLines)
393 ipiv.resize(nbLines);
394 work.resize(nbLines);
397 if (nbLines != nbCols)
399 Cerr <<
"Error in Matrice_Dense::inverse" << finl;
400 Cerr <<
"The matrix is not a square matrix !" << finl;
404 F77NAME(DGETRF)(&nbLines, &nbLines, Matrix_.addr(), &nbLines, ipiv.addr(), &infoerr);
405 assert(infoerr == 0);
406 F77NAME(DGETRI)(&nbLines, Matrix_.addr(), &nbLines, ipiv.addr(), work.addr(), &nbLines, &infoerr);
407 assert(infoerr == 0);
431 if (ipiv.size_array()!=nbLines)
433 ipiv.resize(nbLines);
434 work.resize(nbLines);
437 if (nbLines != nbCols)
439 Cerr <<
"Error in Matrice_Dense::inverse" << finl;
440 Cerr <<
"The matrix is not a square matrix !" << finl;
443 F77NAME(DGETRF)(&nbLines, &nbLines, Matrix_.addr(), &nbLines, ipiv.addr(), &infoerr);
444 if (infoerr != 0)
Process::exit(
"Error DGETRF in Matrice_Dense::solve");
448 F77NAME(DGETRS)(&trans, &nbLines, &nb_rhs, Matrix_.addr(), &nbLines, ipiv.addr(), x.
addr(), &nbLines, &infoerr);
449 if (infoerr != 0)
Process::exit(
"Error DGETRS in Matrice_Dense::solve");
Class defining operators and methods for all reading operation in an input flow (file,...
Classe Matrice_Base Classe de base de la hierarchie des matrices.
void scale(const double x) override
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
void read_from_file(const Nom &filename)
int ordre() const override
If square matrix, returns number of lines, otherwise 0.
void build_matrix_from_coefficients_line_by_line(const DoubleVect &coefficients)
DoubleVect & ajouter_multvectT_(const DoubleVect &x, DoubleVect &r) const override
Operation de multiplication-accumulation (saxpy) matrice vecteur, par la matrice transposee.
void dimensionner(const int nb_lines, const int nb_cols)
void solve(const ArrOfDouble &b, ArrOfDouble &x)
Solves the linear system A*x = b using LU factorization.
void build_the_transposed(Matrice_Dense &transposed) const
void build_matrix_from_coefficients_column_by_column(const DoubleVect &coefficients)
int nb_lignes() const override
Return local number of lines (=size on the current proc).
friend Matrice_Dense operator+(const Matrice_Dense &A, const Matrice_Dense &B)
Sortie & imprimer_formatte(Sortie &s) const override
void convert_to_morse_matrix(Matrice_Morse &morse_matrix) const
friend Matrice_Dense operator*(const double &a, const Matrice_Dense &B)
bool is_the_same(const Matrice_Dense &other_matrix, const double tol=1e-14) const
void set_coefficient(const int i, const int j, const double value)
void multiplyToRight(const Matrice_Dense &B, Matrice_Dense &RES) const
DoubleTab & ajouter_multTab_(const DoubleTab &x, DoubleTab &r) const override
DoubleVect & ajouter_multvect_(const DoubleVect &x, DoubleVect &r) const override
Operation de multiplication-accumulation (saxpy) matrice vecteur.
void get_stencil(Stencil &stencil) const override
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
void dimensionner(int n, _SIZE_ nnz)
Size the matrix with n lines and n columns and nnz zero-values coefficients.
class Nom Une chaine de caractere pour nommer les objets de TRUST
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Classe de base des flux de sortie.
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_SIZE_ dimension(int d) const