16#ifndef Matrice_Morse_included
17#define Matrice_Morse_included
19#include <TRUSTTabs_forward.h>
20#include <Matrice_Base.h>
21#include <TRUSTLists.h>
25#include <TRUSTArray_kokkos.tpp>
63 template<
typename _SIZE_>
Matrice_Morse(
int n,
int m, _SIZE_ nnz) ;
67 Matrice_Morse(
int ,
int ,
const IntLists& ,
const DoubleLists& ,
const DoubleVect& );
76 void remplir(
const IntLists& ,
const DoubleLists& ,
const DoubleVect& );
77 void remplir(
const IntLists& ,
const DoubleLists&);
80 template<
typename _SIZE_>
void dimensionner(
int n, _SIZE_ nnz);
81 template<
typename _SIZE_>
void dimensionner(
int n,
int m, _SIZE_ nnz);
88 int ordre()
const override;
120 void clean()
override;
136 void scale(
const double x )
override;
138 void get_stencil( Stencil& stencil )
const override;
147 virtual int inverse(
const DoubleVect&, DoubleVect&,
double )
const ;
148 virtual int inverse(
const DoubleVect&, DoubleVect&,
double,
int )
const ;
151 void compacte(
int elim_coeff_nul=0);
155 ArrOfDouble&
ajouter_multvect_(
const ArrOfDouble& ,ArrOfDouble&, ArrOfInt& )
const;
196 if (
tab1_.size_array()>std::numeric_limits<int>::max())
Process::exit(
"Can't convert this huge matrix to int32 indices !");
197 int size =
tab1_.size_array();
198 if (tab1_int32_.size_array()!=size) tab1_int32_.resize(size);
199 for (
int i=0; i<size; i++) tab1_int32_(i) = (int)
tab1_(i);
214 for (
int i = 0; i < size; i++)
tab1_(i) = (trustIdType)tab1_int32(i);
223 mutable IntVect tab1_int32_;
234 template<
typename _TAB_T_,
typename _VALUE_T_>
239 mutable bool constant_stencil_=
false;
242int Matrice_Morse_test();
251 auto k2=
tab1_[i+1]-1;
255 auto k = std::lower_bound(
tab2_.addr() + k1,
tab2_.addr() + k2, j + 1) -
tab2_.addr();
257 auto k = (int)(std::lower_bound(
tab2_.addr() + k1,
tab2_.addr() + k2, j + 1) -
tab2_.addr());
259 if (k < k2 &&
tab2_[k] == j + 1)
263 for (
auto k=k1; k<k2; k++)
277 auto k2=
tab1_[i+1]-1;
281 auto k = std::lower_bound(
tab2_.addr() + k1,
tab2_.addr() + k2, j + 1) -
tab2_.addr();
283 auto k = (int)(std::lower_bound(
tab2_.addr() + k1,
tab2_.addr() + k2, j + 1) -
tab2_.addr());
285 if (k < k2 &&
tab2_[k] == j + 1)
289 for (
auto k=k1; k<k2; k++)
294 Cerr <<
"i or j are not suitable " << finl;
295 Cerr <<
"i=" << i << finl;
296 Cerr <<
"j=" << j << finl;
297 Cerr <<
"n_lignes=" <<
nb_lignes() << finl;
303 Cerr <<
"Error Matrice_Morse::operator("<< i <<
"," << j <<
") not defined!" << finl;
311struct Matrice_Morse_View
320 mutable DoubleArrView coeff_;
326 tab1_ = matrice.
get_tab1().view_ro();
327 tab2_ = matrice.
get_tab2().view_ro();
338 KOKKOS_INLINE_FUNCTION
339 double& diag(
int i)
const
342 return coeff_(tab1_(i)-1);
345 KOKKOS_INLINE_FUNCTION
346 const double& operator()(
int i,
int j)
const
349 if ((symetrique_==1) && ((j-i)<0))
358 auto k2=tab1_(i+1)-1;
365 for (
auto k=k1; k<k2; k++)
368 printf(
"Error Matrice_Morse_View(%d, %d) not defined!\n", (
int)i, (
int)j);
373 KOKKOS_INLINE_FUNCTION
374 void store(
int i,
int j,
double coeff,
bool atomic=
false)
const
376 if ((symetrique_==1) && ((j-i)<0))
385 auto k2=tab1_(i+1)-1;
392 for (
auto k=k1; k<k2; k++)
395 if (atomic) Kokkos::atomic_store(&coeff_(k), coeff);
396 else coeff_(k) = coeff;
399 printf(
"Error Matrice_Morse_View::store(%d, %d, value) not defined!\n", (
int)i, (
int)j);
403 KOKKOS_INLINE_FUNCTION
404 void atomic_store(
int i,
int j,
double coeff)
const { store(i,j,coeff,
true); }
406 KOKKOS_INLINE_FUNCTION
407 void atomic_add(
int i,
int j,
double coeff)
const { add(i,j,coeff,
true); }
409 KOKKOS_INLINE_FUNCTION
410 void add(
int i,
int j,
double coeff,
bool atomic=
false)
const
412 if (symetrique_==2 && i!=j)
414 else if ((symetrique_==1) && ((j-i)<0))
423 auto k2=tab1_(i+1)-1;
432 for (
auto k=k1; k<k2; k++)
435 if (atomic) Kokkos::atomic_add(&coeff_(k), coeff);
436 else coeff_(k) += coeff;
439 printf(
"Error Matrice_Morse_View::add(%d, %d, value) not defined!\n", (
int)i, (
int)j);
Classe Matrice_Base Classe de base de la hierarchie des matrices.
bool is_stencil_up_to_date_
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
void clean() override
Remplit la matrice avec des zeros.
friend Matrice_Morse operator*(double, const Matrice_Morse &)
Fonction (hors classe) amie de la classe Matrice_Morse Scaling de la matrice par un scalaire: multipl...
friend Matrice_Morse operator+(const Matrice_Morse &, const Matrice_Morse &)
Fonction (hors classe) amie de la classe Matrice_Morse Addition de 2 matrices au format Morse.
int largeur_de_bande() const
Calcule la largeur de bande d'une matrice morse.
int morse_matrix_structure_has_changed_
Matrice_Morse & affecte_prod(const Matrice_Morse &A, const Matrice_Morse &B)
Affecte le produit de 2 matrices Morse A et B a l'objet (this).
void get_stencil_and_coeff_ptrs(Stencil &stencil, std::vector< const double * > &coeff_ptr) const override
void get_stencil(Stencil &stencil) const override
bool check_morse_matrix_structure() const
Sortie & imprimer_image(Sortie &s) const
Matrice_Morse & operator*=(double)
Operateur de multiplication (de tous les elements) d'une matrice par un scalaire.
void WriteFileMTX(const Nom &) const
bool check_sorted_morse_matrix_structure() const
Matrice_Morse & operator=(const Matrice_Morse &)
Operateur d'affectation d'une Matrice_Morse dans une autre Matrice_Morse.
void assert_check_morse_matrix_structure() const
void scale(const double x) override
virtual Matrice_Morse & diagmulmat(const DoubleVect &x)
Matrice_Morse & operator/=(double)
Operateur de division (de tous les elements) d'une matrice par un scalaire.
void get_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const override
const auto & get_tab2() const
int ordre() const override
Renvoie l'ordre de la matrice: - le nombre de lignes si la matrice est carree.
bool is_sorted_stencil() const
void set_tab1(const IntVect &tab1_int32)
Sortie & imprimer_formatte(Sortie &s) const override
virtual int inverse(const DoubleVect &, DoubleVect &, double) const
Calcule la solution du systeme lineaire: A * solution = secmem.
virtual Matrice_Morse & transpose(const Matrice_Morse &a)
*this = a transposee.
const IntVect & get_tab1_int32() const
Sortie & imprimer(Sortie &s) const override
bool & constant_stencil() const
void dimensionner(int n, _SIZE_ nnz)
Size the matrix with n lines and n columns and nnz zero-values coefficients.
const auto & get_tab1() const
void set_nb_columns(const int)
DoubleVect & ajouter_multvect_(const DoubleVect &, DoubleVect &) const override
Operation de multiplication-accumulation (saxpy) matrice vecteur.
DoubleVect & ajouter_multvectT_(const DoubleVect &, DoubleVect &) const override
Operation de multiplication-accumulation (saxpy) matrice vecteur, par la matrice transposee.
void get_stencil_coeff_templ(Stencil &stencil, _TAB_T_ &coeffs_span) const
void assert_check_sorted_morse_matrix_structure() const
Matrice_Morse & operator+=(const Matrice_Morse &)
NE FAIT RIEN.
int get_symmetric() const
double coef(int i, int j) const
double & operator()(int i, int j)
double & coef(int i, int j)
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
bool has_same_morse_matrix_structure(const Matrice_Morse &) const
Matrice_Morse operator-() const
Operateur de negation unaire, renvoie l'opposee de la matrice: - A Appelle operator*(double,...
const auto & get_coeff() const
void set_symmetric(const int)
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 construire_sous_bloc(int nl0, int nc0, int nl1, int nc1, Matrice_Morse &result) const
void unite()
Initialisation a la matrice unite (modif MT).
void set_tab1_int32() const
DoubleTab & ajouter_multTab_(const DoubleTab &, DoubleTab &) const override
Operation de multiplication-accumulation (saxpy) matrice matrice (matrice X representee par un tablea...
class Nom Une chaine de caractere pour nommer les objets de TRUST
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
static KOKKOS_INLINE_FUNCTION void Kokkos_exit(const char *)
Routine de sortie de TRUST dans une region Kokkos.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
_SIZE_ size_array() const