16#include <Matrice_Morse_Sym.h>
17#include <TRUSTArrays.h>
18#include <Array_tools.h>
64 const DoubleLists& valeurs,
65 const DoubleVect& terme_diag)
69 remplir(voisins, valeurs, terme_diag);
155 double* t=
new double[nb_com];
159 for(comp=0; comp<nb_com; comp++)
165 for(comp=0; comp<nb_com; comp++)
167 t[comp] += aij*x(j,comp);
168 resu(j,comp) += aij*x(i,comp);
171 for(comp=0; comp<nb_com; comp++)
172 resu(i,comp) += t[comp] ;
186 double prod_scal_local = 0.;
187 operator_egal(resu, 0.);
191 const double * thecoef =
get_coeff().addr() - 1;
192 const double * xx = x.
addr() - 1;
193 double * res = resu.
addr() - 1;
194 const auto * index1 =
get_tab1().addr() - 1;
195 const int * index2 =
get_tab2().addr() - 1;
196#ifdef COMPILER_BLRTS_XLC
197#pragma disjoint (*coef, *xx, *res)
200 for (i = 1; i < fin; i++)
203 auto j_next= index1[i+1];
205 assert(i==index2[j]);
207 double resu_tmp = res[i] + thecoef[j] * xi;
209 for (; j < j_next; j++)
212 double coef_j = thecoef[j];
214 resu_tmp += coef_j * xn;
215 res[nj] += coef_j * xi;
218 prod_scal_local += resu_tmp * xi;
222 return prod_scal_local;
245 const double * thecoef =
get_coeff().addr() - 1;
246 const double * xx = x.
addr() - 1;
247 double * res = resu.
addr() - 1;
248 const auto * index1 =
get_tab1().addr() - 1;
249 const int * index2 =
get_tab2().addr() - 1;
250#ifdef COMPILER_BLRTS_XLC
251#pragma disjoint (*coef, *xx, *res)
254 for (i = 1; i < fin; i++)
257 auto j_next= index1[i+1];
258 assert(i==index2[j]);
261 int ncoeffs = j_next - j;
264 int n2 = index2[j+1];
265 int n3 = index2[j+2];
266 int n4 = index2[j+3];
268 double res_i = res[i];
269 double res_n2 = res[n2];
270 double res_n3 = res[n3];
271 double res_n4 = res[n4];
272 double a1 = thecoef[j];
273 double a2 = thecoef[j+1];
274 double a3 = thecoef[j+2];
275 double a4 = thecoef[j+3];
276 res[i] = res_i + a1 * xi + a2 * xx[n2] + a3 * xx[n3] + a4 * xx[n4];
277 res[n2] = res_n2 + a2 * xi;
278 res[n3] = res_n3 + a3 * xi;
279 res[n4] = res_n4 + a4 * xi;
285 double resu_tmp = res[i] + thecoef[j] * xi;
287 for (; j < j_next; j++)
290 double coef_j = thecoef[j];
292 resu_tmp += coef_j * xn;
293 res[nj] += coef_j * xi;
302 for(i=debut; i<n; i++)
308 assert(i==tab2(l-1)-1);
311 for (k=l; k<fin2; k++)
336 Cerr <<
"Matrice_Morse_Sym::ajouter_multvectT_ is not coded" << finl;
353 Cerr <<
"Error in Matrice_Morse_Sym::operator+" << finl;
354 Cerr <<
"The 2 matrices must have the same dimension" << finl;
355 Cerr <<
"The first matrix is of dimension: " << A.
nb_lignes()<< finl;
356 Cerr <<
"The second matrix is of dimension: " << B.
nb_lignes()<< finl;
361 IntList colonnes_A_ligne_i,colonnes_B_ligne_i;
362 int min_colonnes_A,min_colonnes_B,non_nuls_ligne_i;
363 DoubleList coeffs_A_ligne_i,coeffs_B_ligne_i;
364 double coeff_A,coeff_B;
367 for (
auto i=0; i<somme.
get_coeff().size(); i++)
375 if (!colonnes_A_ligne_i.
est_vide()) colonnes_A_ligne_i.
vide();
376 if (!colonnes_B_ligne_i.
est_vide()) colonnes_B_ligne_i.
vide();
393 non_nuls_ligne_i = 0;
402 colonnes_B_ligne_i[0];
405 coeffs_B_ligne_i[0] ;
407 colonnes_B_ligne_i.
suppr(colonnes_B_ligne_i[0]);
408 coeffs_B_ligne_i.
suppr(coeffs_B_ligne_i[0]);
415 colonnes_A_ligne_i[0];
420 colonnes_A_ligne_i.
suppr(colonnes_A_ligne_i[0]);
421 coeffs_A_ligne_i.
suppr(coeffs_A_ligne_i[0]);
426 min_colonnes_A = colonnes_A_ligne_i[0];
427 min_colonnes_B = colonnes_B_ligne_i[0];
428 coeff_A = coeffs_A_ligne_i[0];
429 coeff_B = coeffs_B_ligne_i[0];
431 if (min_colonnes_A < min_colonnes_B)
436 colonnes_A_ligne_i.
suppr(min_colonnes_A);
437 coeffs_A_ligne_i.
suppr(coeff_A);
441 if (min_colonnes_B < min_colonnes_A)
446 colonnes_B_ligne_i.
suppr(min_colonnes_B);
447 coeffs_B_ligne_i.
suppr(coeff_B);
451 if (min_colonnes_A == min_colonnes_B)
456 colonnes_A_ligne_i.
suppr(min_colonnes_A);
457 colonnes_B_ligne_i.
suppr(min_colonnes_B);
458 coeffs_A_ligne_i.
suppr(coeff_A);
459 coeffs_B_ligne_i.
suppr(coeff_B);
523 Stencil symmetric_stencil;
542 for (
int i=0; i<nb_lines; ++i )
544 auto k0 =
tab1_( i ) - 1;
545 auto k1 =
tab1_( i + 1 ) - 1;
546 int size = (int)(k1 - k0);
551 for (
int k=0; k<size; ++k )
553 tmp[ k ] =
tab2_( k + k0 ) - 1;
558 for (
int k=0; k<size; ++k )
564 const int new_size = stencil.
dimension( 0 );
566 stencil.
resize( new_size, 2 );
570 StencilCoeffs& coefficients )
const
574 Stencil symmetric_stencil;
575 StencilCoeffs symmetric_coefficients;
580 symmetric_coefficients,
587 StencilCoeffs& coefficients )
const
607 for (
int i=0; i<nb_lines; ++i )
609 auto k0 =
tab1_( i ) - 1;
610 auto k1 =
tab1_( i + 1 ) - 1;
611 int size = (int)(k1 - k0);
621 for (
int k=0; k<size; ++k )
623 tmp1( k ) =
tab2_( k + k0 ) - 1;
624 tmp2[ k ] =
coeff_( k + k0 );
626 tri_lexicographique_tableau_indirect( tmp1, index );
628 for (
int k=0; k<size; ++k )
636 const int new_size = stencil.
dimension( 0 );
637 assert( coefficients.
size_array( ) == new_size );
640 stencil.
resize( new_size, 2 );
653 return((*
this)*(-1));
705int Matrice_Morse_Sym_test()
712 double coeff_seuil)
const
714 Cerr <<
"Not coded." << finl;
720 double coeff_seuil,
int max_iter)
const
722 Cerr <<
"Not coded." << finl;
742 int elements_diagonaux_non_stockes=0;
743 auto size_tab2_ =
tab2_.size_array();
744 for (
int i=0; i<n; i++)
747 if (k>=size_tab2_ || i!=
tab2_(k)-1)
749 elements_diagonaux_non_stockes++;
755 if (elements_diagonaux_non_stockes)
758 auto nnz=size_tab2_+elements_diagonaux_non_stockes;
762 for (
int i=n-1; i>=0; i--)
766 auto k2=
tab1_(i+1)-1;
767 for (
auto j=k2-1; j>=k1; j--)
769 tab2_(j+elements_diagonaux_non_stockes)=
tab2_(j);
772 tab1_(i+1)+=elements_diagonaux_non_stockes;
774 if (k1>=size_tab2_ || i!=
tab2_(k1)-1)
777 elements_diagonaux_non_stockes--;
778 tab2_(k1+elements_diagonaux_non_stockes)=i+1;
779 coeff_(k1+elements_diagonaux_non_stockes)=0.;
782 assert(elements_diagonaux_non_stockes==0);
793 Cerr <<
"Renumbering the matrix ..." << finl;
801 int mon_ordre = matrice.
ordre();
803 for (
int i=0; i<mon_ordre; i++) matrice2(i, i) = 0.;
804 matrice2 += matrice ;
807 const int n = mon_ordre;
810 const int* tab2tmp = matrice2.
get_tab2().addr();
815 int* masktmp =
new int[n];
816 for (
int i=0 ; i<n; i++) masktmp[i] = 1;
817 const int* mask = (
const int*) masktmp;
818 const int maskval = 1;
820 int* level =
new int[n+1];
826 F77NAME(PERPHN)(&n, tab2tmp, tab1tmp, &init, mask, &maskval,
827 &nlev, tab_iperm.
addr(), level);
832 ArrOfInt tab_perm(n);
833 for (
int i=0 ; i<n; i++ ) tab_perm[tab_iperm[i] - 1] = i + 1;
837 const double* a = matrice.
get_coeff().addr();
838 const int* ja = matrice.
get_tab2().addr();
841 const double* tao = matrice2.
get_coeff().addr();
842 double* ao = (
double*)tao;
843 const int* tjao = matrice2.
get_tab2().addr();
844 int* jao = (
int*)tjao;
847 int* iao = (
int*)tiao;
849 const int* perm = tab_perm.
addr();
850 const int* perm_inv = tab_iperm.
addr();
858 F77NAME(DPERM) (&n, a, ja, ia, ao, jao, iao, perm, perm_inv, &job);
862 for (
int i=0; i<mon_ordre; i++) matrice2(i, i) = 0.;
865 matrice_renumerotee_.typer(
"Matrice_Morse_Sym");
871 for(
int i=0; i<size; i++)
873 Cerr <<
"Bandwidth of the renumbered matrix : " << ref_cast(
Matrice_Morse,matrice_renumerotee_.valeur()).largeur_de_bande() << finl;
881 Cerr <<
"Invalid morse structure" << finl;
886 for (
int i=0; i<nb_lines; ++i )
888 auto k0 =
tab1_( i ) - 1;
889 auto k1 =
tab1_( i + 1 ) - 1;
891 for (
auto k=k0; k<k1; ++k )
893 int j =
tab2_( k ) - 1;
896 Cerr <<
"( j < i ) : line index : " << i <<
" and column index " << j << finl;
912 for (
int i=0; i<nb_lines; ++i )
914 auto k0 =
tab1_( i ) - 1;
915 auto k1 =
tab1_( i + 1 ) - 1;
917 for (
auto k=k0; k<k1; ++k )
919 int j =
tab2_( k ) - 1;
922 Cerr <<
"( j < i ) : line index : " << i <<
" and column index " << j << finl;
937 Cerr <<
"Error in 'Matrice_Morse_Sym::assert_check_symmetric_morse_matrix_structure( )':" << finl;
938 Cerr <<
" Exiting..." << finl;
952 Cerr <<
"Error in 'Matrice_Morse_Sym::assert_check_sorted_symmetric_morse_matrix_structure( )':" << finl;
953 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.
bool is_stencil_up_to_date_
virtual DoubleVect & ajouter_multvect(const DoubleVect &x, DoubleVect &r) const
Operation de multiplication-accumulation (saxpy) matrice vecteur.
bool is_stencil_up_to_date() const
Classe Matrice_Morse_Sym Represente une matrice M (creuse) symetrique stockee au format Morse.
void assert_check_sorted_symmetric_morse_matrix_structure() const
void compacte(int elim_coeff_nul=0)
Suppression des doublons on ordonne tab2;.
DoubleVect & ajouter_multvectT_(const DoubleVect &, DoubleVect &) const override
Operation de multiplication-accumulation (saxpy) matrice vecteur, par la matrice transposee.
Matrice_Morse_Sym & operator*=(double)
NE FAIT RIEN : NON CODE.
bool check_symmetric_morse_matrix_structure() const
void get_symmetric_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const override
void get_stencil(Stencil &stencil) const override
Matrice_Morse_Sym(int n1=1, int n2=1)
void renumerote() const
Renumerotation d'une matrice afin de reduire la largeur de bande.
bool check_sorted_symmetric_morse_matrix_structure() const
DoubleVect & ajouter_multvect_(const DoubleVect &, DoubleVect &) const override
Operation de multiplication-accumulation (saxpy) matrice vecteur.
friend Matrice_Morse_Sym operator+(const Matrice_Morse_Sym &, const Matrice_Morse_Sym &)
Fonction (hors classe) amie de la classe Matrice_Morse_Sym NE FAIT RIEN : NON CODE.
int inverse(const DoubleVect &, DoubleVect &, double) const override
Calcule la solution du systeme lineaire: A * solution = secmem.
void assert_check_symmetric_morse_matrix_structure() const
void get_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const override
Matrice_Morse_Sym & operator=(const Matrice_Morse_Sym &)
Operateur d'affectatiob d'une Matrice_Morse_Sym dans une Matrice_Morse_Sym.
ArrOfInt & permutation_inverse()
Matrice_Morse_Sym operator-() const
Operateur de negation unaire, renvoie l'opposee de la matrice: - A.
Sortie & imprimer_formatte(Sortie &s) const override
DoubleTab & ajouter_multTab_(const DoubleTab &, DoubleTab &) const override
Operation de multiplication-accumulation (saxpy) matrice matrice (matrice represente par un tableau).
void scale(const double x) override
virtual double multvect_et_prodscal(const DoubleVect &, DoubleVect &) const
void get_symmetric_stencil(Stencil &stencil) const override
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
int largeur_de_bande() const
Calcule la largeur de bande d'une matrice morse.
int morse_matrix_structure_has_changed_
bool check_morse_matrix_structure() const
bool check_sorted_morse_matrix_structure() const
const auto & get_tab2() const
int ordre() const override
Renvoie l'ordre de la matrice: - le nombre de lignes si la matrice est carree.
void set_tab1(const IntVect &tab1_int32)
Sortie & imprimer_formatte(Sortie &s) const override
virtual Matrice_Morse & transpose(const Matrice_Morse &a)
*this = a transposee.
const IntVect & get_tab1_int32() const
const auto & get_tab1() const
int get_symmetric() const
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
const auto & get_coeff() const
void remplir(const IntLists &, const DoubleLists &, const DoubleVect &)
virtual Matrice_Morse & partie_sup(const Matrice_Morse &a)
int nb_lignes() const override
Return local number of lines (=size on the current proc).
void compacte(int elim_coeff_nul=0)
Method to check/clean the Matrice_Morse matrix: -Suppress coefficient defined several times.
void set_tab1_int32() const
void set_est_definie(int)
int get_est_definie() const
void unsymmetrize_stencil_and_coefficients(const int nb_lines, const Stencil &symmetric_stencil, const StencilCoeffs &symmetric_coefficients, Stencil &stencil, StencilCoeffs &coefficients) const
void unsymmetrize_stencil(const int nb_lines, const Stencil &symmetric_stencil, Stencil &stencil) const
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 exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Classe de base des flux de sortie.
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
TRUSTList & add(_TYPE_)
insertion en queue
TRUSTList & add_if_not(_TYPE_)
Ajout d'un element a la liste ssi il n'existe pas deja.
void suppr(_TYPE_)
Supprime un element contenu dans la liste.
void vide()
Vide la liste.
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_SIZE_ dimension(int d) const
_SIZE_ size_totale() const