16#include <Matrice_Morse_Sym.h>
17#include <Matrice_Morse.h>
18#include <Matrice_Bloc.h>
19#include <Matrix_tools.h>
20#include <TRUSTArrays.h>
22#include <Matrice_Nulle.h>
36 os << blocs_[i] << finl;
69 for(
int i=0; i<
N_; ++i )
80 for(
int i=0; i<
M_; ++i )
82 sum +=
get_bloc(0,i).valeur( ).nb_colonnes();
90 const double * const_x_addr = x.
addr( );
91 double * x_addr = (
double * ) const_x_addr;
92 double * r_addr = r.
addr( );
99 for (
int i_ligne = 0; i_ligne <
N_; ++i_ligne )
101 const int r_bloc_size =
get_bloc( i_ligne, 0 ).valeur( ).nb_lignes( );
102 r_bloc.
ref_data( r_addr + r_bloc_debut, r_bloc_size );
103 assert( r_bloc_debut+r_bloc_size <= r.
size_array( ) );
104 int x_bloc_debut = 0;
106 for (
int i_colonne = 0; i_colonne <
M_; ++i_colonne )
109 const int x_bloc_size = sub_bloc.valeur( ).nb_colonnes( );
110 x_bloc.
ref_data( x_addr + x_bloc_debut, x_bloc_size );
111 assert( x_bloc_debut+x_bloc_size <= x.
size_array( ) );
112 sub_bloc.valeur( ).ajouter_multvect_( x_bloc, r_bloc );
113 x_bloc_debut += x_bloc_size;
115 r_bloc_debut += r_bloc_size;
123 const double * const_x_addr = x.
addr( );
124 double * x_addr = (
double * ) const_x_addr;
125 double * r_addr = r.
addr( );
130 int r_bloc_debut = 0;
132 for (
int i_ligne = 0; i_ligne <
M_; ++i_ligne )
134 const int r_bloc_size =
get_bloc( 0, i_ligne ).valeur( ).nb_colonnes( );
135 r_bloc.
ref_data( r_addr + r_bloc_debut, r_bloc_size );
136 assert( r_bloc_debut+r_bloc_size <= r.
size_array( ) );
137 int x_bloc_debut = 0;
139 for (
int i_colonne = 0; i_colonne <
N_; ++i_colonne )
142 const int x_bloc_size = sub_bloc.valeur( ).nb_lignes( );
143 x_bloc.
ref_data( x_addr + x_bloc_debut, x_bloc_size );
144 assert( x_bloc_debut+x_bloc_size <= x.
size_array( ) );
145 sub_bloc.valeur( ).ajouter_multvectT_( x_bloc, r_bloc );
146 x_bloc_debut += x_bloc_size;
148 r_bloc_debut += r_bloc_size;
156 Cerr <<
"Error in 'Matrice_Bloc::ajouter_multTab_()':" << finl;
157 Cerr <<
" Not yet implemented" << finl;
168 for (
int i=0; i<nb_line_blocks; i++)
170 for (
int j=0; j<nb_column_blocks; j++)
210 const int nb_stencils = nb_line_blocks * nb_column_blocks;
212 VECT( Stencil ) local_stencils;
213 local_stencils.dimensionner( nb_stencils );
220 for (
int i=0; i<nb_line_blocks; ++i )
222 for (
int j=0; j<nb_column_blocks; ++j )
229 Stencil& local_stencil = local_stencils[ i * nb_column_blocks + j ];
232 const int size = local_stencil.
dimension( 0 );
233 for (
int k=0; k<size; ++k )
235 local_stencil( k, 0 ) += imin;
236 local_stencil( k, 1 ) += jmin;
245 ArrOfInt offsets( nb_lines + 1 );
248 for (
int i=0; i<nb_stencils; ++i )
250 const Stencil& local_stencil = local_stencils[ i ];
251 const int size = local_stencil.
dimension( 0 );
253 for (
int k=0; k<size; ++k )
255 const int line = local_stencil( k, 0 );
256 offsets[ line + 1 ] += 1;
260 for (
int i=0; i<nb_lines; ++i )
262 offsets[ i + 1 ] += offsets[ i ];
265 const int stencil_size = offsets[ nb_lines ];
266 stencil.
resize( stencil_size, 2 );
270 for (
int i=0; i<nb_stencils; ++i )
272 const Stencil& local_stencil = local_stencils[ i ];
273 const int size = local_stencil.
dimension( 0 );
275 for (
int k=0; k<size; ++k )
277 const int line = local_stencil( k, 0 );
278 const int column = local_stencil( k, 1 );
279 const int index = offsets[ line ];
281 assert( stencil( index, 0 ) < 0 );
282 assert( stencil( index, 1 ) < 0 );
283 assert( index < offsets[ line + 1 ] );
285 stencil( index, 0 ) = line;
286 stencil( index, 1 ) = column;
287 offsets[ line ] += 1;
302 const int nb_stencils = nb_line_blocks * nb_column_blocks;
305 VECT( Stencil ) local_stencils;
306 local_stencils.dimensionner( nb_stencils );
313 for (
int i=0; i<nb_line_blocks; ++i )
315 for (
int j=0; j<nb_column_blocks; ++j )
328 Stencil& local_stencil = local_stencils[ i * nb_column_blocks + j ];
331 const int size = local_stencil.
dimension( 0 );
332 for (
int k=0; k<size; ++k )
334 local_stencil( k, 0 ) += imin;
335 local_stencil( k, 1 ) += jmin;
344 ArrOfInt offsets( nb_lines + 1 );
347 for (
int i=0; i<nb_stencils; ++i )
349 const Stencil& local_stencil = local_stencils[ i ];
350 const int size = local_stencil.
dimension( 0 );
352 for (
int k=0; k<size; ++k )
354 const int line = local_stencil( k, 0 );
355 offsets[ line + 1 ] += 1;
359 for (
int i=0; i<nb_lines; ++i )
361 offsets[ i + 1 ] += offsets[ i ];
366 const int stencil_size = offsets[ nb_lines ];
371 for (
int i=0; i<nb_stencils; ++i )
373 const Stencil& local_stencil = local_stencils[ i ];
374 const int size = local_stencil.
dimension( 0 );
376 for (
int k=0; k<size; ++k )
378 const int line = local_stencil( k, 0 );
379 const int column = local_stencil( k, 1 );
380 const int index = offsets[ line ];
384 assert( index < offsets[ line + 1 ] );
388 offsets[ line ] += 1;
398template<
typename _TAB_T_>
static inline void _get_sub_stencil_coeff(
const Matrice_Base& mat, Stencil& sten, _TAB_T_& coeff);
400template<>
inline void _get_sub_stencil_coeff<StencilCoeffs>(
const Matrice_Base& mat, Stencil& sten, StencilCoeffs& coeff)
405template<>
inline void _get_sub_stencil_coeff<std::vector<const double*>>(
const Matrice_Base& mat, Stencil& sten, std::vector<const double*>& coeff)
411template<
typename _TAB_T_,
typename _VAL_T_>
428 Stencil local_stencil;
441 _get_sub_stencil_coeff<_TAB_T_>(local_matrix, local_stencil, local_coeff);
443 const int size = local_stencil.
dimension( 0 );
445 for (
int k=0; k<size; ++k )
447 const int line = local_stencil( k, 0 ) + imin;
448 const int index = offsets[ line ];
450 coeff_sp[index] = local_coeff[ k ];
452 offsets[ line ] += 1;
457 const int nb_stencils = nb_line_blocks * nb_column_blocks;
459 std::vector<Stencil> vect_local_stencils(nb_stencils);
460 std::vector<_TAB_T_> vect_local_coefficients(nb_stencils);
462 for (
int i=0; i<nb_line_blocks; ++i )
464 for (
int j=0; j<nb_column_blocks; ++j )
471 Stencil& local_stencil = vect_local_stencils[ i * nb_column_blocks + j ];
472 _TAB_T_& local_coefficients = vect_local_coefficients[i * nb_column_blocks + j ];
474 _get_sub_stencil_coeff<_TAB_T_>(local_matrix, local_stencil, local_coefficients);
476 const int size = local_stencil.
dimension( 0 );
477 for (
int k=0; k<size; ++k )
479 local_stencil( k, 0 ) += imin;
480 local_stencil( k, 1 ) += jmin;
489 ArrOfInt offsets( nb_lines + 1 );
492 for (
int i=0; i<nb_stencils; ++i )
494 const Stencil& local_stencil = vect_local_stencils[ i ];
495 const int size = local_stencil.
dimension( 0 );
497 for (
int k=0; k<size; ++k )
499 const int line = local_stencil( k, 0 );
500 offsets[ line + 1 ] += 1;
504 for (
int i=0; i<nb_lines; ++i )
506 offsets[ i + 1 ] += offsets[ i ];
509 const int stencil_size = offsets[ nb_lines ];
510 stencil.
resize( stencil_size, 2 );
511 coeff_sp.resize(stencil_size);
515 for (
int i=0; i<nb_stencils; ++i )
517 const Stencil& local_stencil= vect_local_stencils[ i ];
518 const _TAB_T_& local_coefficients = vect_local_coefficients[ i ];
520 const int size = local_stencil.
dimension( 0 );
522 for (
int k=0; k<size; ++k )
524 const int line = local_stencil( k, 0 );
525 const int column = local_stencil( k, 1 );
526 const int index = offsets[ line ];
528 assert( stencil( index, 0 ) < 0 );
529 assert( stencil( index, 1 ) < 0 );
530 assert( index < offsets[ line + 1 ] );
532 stencil( index, 0 ) = line;
533 stencil( index, 1 ) = column;
535 coeff_sp[index] = local_coefficients[ k ];
537 offsets[ line ] += 1;
546 Cerr <<
"Error in Matrice_Morse::get_stencil_and_coeff_ptrs( )"<<finl;
547 Cerr <<
" stencil up to date - function not impl. in this case."<<finl;
548 Cerr <<
" Aborting..." << finl;
560 const int stencil_size =
stencil_.dimension(0);
569 for (
int i=0; i<
N_; ++i )
571 for (
int j=0; j<
M_; ++j )
573 os <<
"Bloc (" << i <<
"," << j <<
")" << finl;
574 get_bloc( i, j ).valeur( ).imprimer( os );
582 for (
int i=0; i<
N_; ++i )
584 for (
int j=0; j<
M_; ++j )
586 os <<
"Bloc (" << i <<
"," << j <<
")" << finl;
587 get_bloc( i, j ).valeur( ).imprimer_formatte( os );
603 if ( ( i<0 ) || ( i>=
N_ ) )
605 Cerr <<
"Error in 'Matrice_Bloc::get_bloc()': " << finl;
606 Cerr <<
" Line index is out of range" << finl;
610 if ( ( j<0 ) || ( j>=
M_ ) )
612 Cerr <<
"Error in 'Matrice_Bloc::get_bloc()': " << finl;
613 Cerr <<
" Column index is out of range" << finl;
617 return blocs_[i *
M_ + j];
622 if ( ( i<0 ) || ( i>=
N_ ) )
624 Cerr <<
"Error in 'Matrice_Bloc::get_bloc()': " << finl;
625 Cerr <<
" Line index is out of range" << finl;
629 if ( ( j<0 ) || ( j>=
M_ ) )
631 Cerr <<
"Error in 'Matrice_Bloc::get_bloc()': " << finl;
632 Cerr <<
" Column index is out of range" << finl;
636 return blocs_[i *
M_ + j];
693void Matrice_Bloc::remplir(
const IntLists& voisins,
const DoubleLists& valeurs,
const DoubleVect& terme_diag,
const int i,
const int n)
696 get_bloc(0,0).typer(
"Matrice_Morse_Sym");
697 get_bloc(0,1).typer(
"Matrice_Morse");
698 get_bloc(1,0).typer(
"Matrice_Morse");
699 get_bloc(1,1).typer(
"Matrice_Morse");
700 remplir(voisins, valeurs, terme_diag, i, n, i, n);
707void Matrice_Bloc::remplir(
const IntLists& voisins,
const DoubleLists& valeurs,
const int i,
const int n,
const int j,
const int m)
710 get_bloc(0,0).typer(
"Matrice_Morse");
711 get_bloc(0,1).typer(
"Matrice_Morse");
712 get_bloc(1,0).typer(
"Matrice_Morse");
713 get_bloc(1,1).typer(
"Matrice_Morse");
714 DoubleVect diagonale_vide;
715 remplir(voisins, valeurs, diagonale_vide, i, n, j, m);
722void Matrice_Bloc::remplir(
const IntLists& voisins,
const DoubleLists& valeurs,
const DoubleVect& terme_diag,
const int i,
const int n,
const int j,
const int m)
740 for (num_elem=0; num_elem<n; num_elem++)
742 IntList_Curseur liste_vois(voisins[num_elem]);
743 DoubleList_Curseur liste_val(valeurs[num_elem]);
761 int colonne = liste_vois.
valeur();
779 RR_rang += RR_compteur;
780 RV_rang += RV_compteur;
781 VR_rang += VR_compteur;
782 VV_rang += VV_compteur;
800 int* RR_tab2_ptr = RR_tab2;
806 int* RV_tab2_ptr = RV_tab2;
812 int* VR_tab2_ptr = VR_tab2;
818 int* VV_tab2_ptr = VV_tab2;
824 for (num_elem=0; num_elem<n; num_elem++)
826 IntList_Curseur liste_vois(voisins[num_elem]);
827 DoubleList_Curseur liste_val(valeurs[num_elem]);
835 *RR_tab1++ = RR_rang;
836 *RV_tab1++ = RV_rang;
840 *VR_tab1++ = VR_rang;
841 *VV_tab1++ = VV_rang;
848 *RR_tab2_ptr++ = num_elem;
849 *RR_coeff++ = terme_diag[num_elem];
854 *VV_tab2_ptr++ = num_elem-i;
855 *VV_coeff++ = terme_diag[num_elem];
861 int colonne = liste_vois.
valeur();
862 double coeff = liste_val.
valeur();
867 *RR_tab2_ptr++ = colonne;
873 *VR_tab2_ptr++ = colonne;
882 *RV_tab2_ptr++ = colonne-j;
888 *VV_tab2_ptr++ = colonne-j;
896 RR_rang += RR_compteur;
897 RV_rang += RV_compteur;
898 VR_rang += VR_compteur;
899 VV_rang += VV_compteur;
930 for (
int i=0; i<nb_line_blocks; ++i )
932 int nb_lines =
get_bloc( i, 0 ).valeur( ).nb_lignes( );
934 for (
int j=0; j<nb_column_blocks; ++j )
938 Cerr <<
"Invalid number of lines in bloc ( " << i <<
", " << j <<
" )" << finl;
944 for (
int j=0; j<nb_column_blocks; ++j )
946 int nb_columns =
get_bloc( 0, j ).valeur( ).nb_colonnes( );
948 for (
int i=0; i<nb_line_blocks; ++i )
952 Cerr <<
"Invalid number of columns in bloc ( " << i <<
", " << j <<
" )" << finl;
966 Cerr <<
"Error in 'Matrice_Bloc::assert_check_block_matrix_structure( )':" << finl;
967 Cerr <<
" Exiting..." << finl;
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.
virtual void get_stencil(Stencil &stencil) const
bool is_stencil_up_to_date_
virtual int nb_lignes() const =0
Return local number of lines (=size on the current proc).
virtual int nb_colonnes() const =0
Return local number of columns (=size on the current proc).
virtual void get_stencil_and_coeff_ptrs(Stencil &stencil, std::vector< const double * > &coeff_ptr) const
virtual void get_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const
virtual void scale(const double x)=0
void block_to_morse_with_ptr(Matrice_Morse &result, std::vector< const double * > &coeffs) const
void get_stencil_coeff_templ(Stencil &stencil, _TAB_T_ &coeff_sp) const
Sortie & imprimer_formatte(Sortie &s) const override
Matrice_Bloc(int N=0, int M=0)
virtual void dimensionner(int N, int M)
int nb_bloc_lignes() const
int ordre() const override
If square matrix, returns number of lines, otherwise 0.
DoubleVect & ajouter_multvect_(const DoubleVect &x, DoubleVect &r) const override
void scale(const double x) override
DoubleTab & ajouter_multTab_(const DoubleTab &x, DoubleTab &r) const override
int nb_bloc_colonnes(void) const
void block_to_morse(Matrice_Morse &matrix) const
bool check_block_matrix_structure() const
void BlocToMatMorse(Matrice_Morse &matrix) const
void get_stencil_and_coeff_ptrs(Stencil &stencil, std::vector< const double * > &coeff_ptr) const override
DoubleVect & ajouter_multvectT_(const DoubleVect &x, DoubleVect &r) const override
virtual const Matrice & get_bloc(int i, int j) const
void remplir(const IntLists &voisins, const DoubleLists &valeurs, const DoubleVect &terme_diag, const int i, const int n)
int nb_lignes() const override
Return local number of lines (=size on the current proc).
void build_stencil() override
void get_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const override
std::vector< Matrice_Base * > blocs_non_nuls_
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
Sortie & imprimer(Sortie &s) const override
std::vector< int > line_offsets_
void get_stencil(Stencil &stencil) const override
std::vector< int > column_offsets_
void assert_check_block_matrix_structure() const
Matrice_Bloc & operator*=(double x)
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.
void compacte(int elim_coeff_nul=0)
Method to check/clean the Matrice_Morse matrix: -Suppress coefficient defined several times.
Classe Matrice Classe generique de la hierarchie des matrices.
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_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_SIZE_ dimension(int d) const
void ref_data(_TYPE_ *ptr, _SIZE_ new_size) override