TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Matrice_Bloc.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Matrice_Bloc_included
17#define Matrice_Bloc_included
18
19#include <TRUSTTabs_forward.h>
20#include <Matrice_Base.h>
21#include <Matrice.h>
22#include <TRUSTLists.h>
23#include <vector>
24#include <TRUST_Vector.h>
25
26/*----------------------------------------------------------------------------*/
27/* */
28/* class Matrice_Bloc: storage of the blocks of a block matrix A(N,M) */
29/* */
30/* storage is done row by row */
31/* in a vector of type VECT(Matrice). */
32/* Uses: */
33/* blocs_ = vector of matrices Aij */
34/* N_ = 1st dim of blocs_ */
35/* M_ = 2nd dim of blocs_ */
36/* nb_blocs_ = total number of blocks (= N_ * M_) */
37/* */
38/* Matrix form: */
39/* */
40/* [A11 A12 ... A1M] */
41/* [A21 A22 ... A2M] */
42/* A = [... ... ... ...] blocs_=[A11,A12,...,A1M,A21,A22,...,A2M, */
43/* [AN1 AN2 ... ANM] ,...,AN1,AN2,...,ANM] */
44/* */
45/* */
46/*----------------------------------------------------------------------------*/
47
48class Matrice_Morse;
49
51{
52 Declare_instanciable_sans_constructeur(Matrice_Bloc);
53
54public :
55 int ordre() const override;
56 int nb_lignes() const override;
57 int nb_colonnes() const override;
58
59 // Methods for computing r+=Ax, implemented in derived classes
60 DoubleVect& ajouter_multvect_( const DoubleVect& x, DoubleVect& r ) const override;
61 DoubleVect& ajouter_multvectT_( const DoubleVect& x, DoubleVect& r ) const override;
62 DoubleTab& ajouter_multTab_( const DoubleTab& x, DoubleTab& r ) const override;
63
64 // multiplication by a scalar
65 void scale( const double x ) override;
66 // zero out the matrix values
67 void clean() override;
68
69 void get_stencil( Stencil& stencil ) const override;
70 void get_stencil_and_coefficients(Stencil& stencil, StencilCoeffs& coefficients) const override;
71 void get_stencil_and_coeff_ptrs(Stencil& stencil, std::vector<const double *>& coeff_ptr) const override;
72
73
74 // Printing
75 Sortie& imprimer( Sortie& s ) const override;
76 Sortie& imprimer_formatte( Sortie& s ) const override;
77
78 // Sizing
79 virtual void dimensionner( int N, int M );
80
81 // Block access
82 virtual const Matrice& get_bloc( int i, int j ) const;
83 virtual Matrice& get_bloc( int i, int j );
84
85 void build_stencil() override;
86
87public :
88 // Constructeurs :
89 Matrice_Bloc( int N=0, int M=0 );
90
91 // Access to the blocs_ vector characteristics
92 int dim( int d ) const; // if d=0 => N_ if d=1 => M_
93 int nb_bloc_lignes() const; // returns N_
94 int nb_bloc_colonnes(void ) const; // returns M_
95
96 // Fill from a symmetric Morse matrix
97 void remplir(const IntLists& voisins, const DoubleLists& valeurs, const DoubleVect& terme_diag, const int i, const int n);
98
99 // Fill from a Morse matrix
100 void remplir(const IntLists& voisins, const DoubleLists& valeurs, const int i, const int n, const int j, const int m);
101
102 // Fill from a symmetric or non-symmetric Morse matrix
103 void remplir(const IntLists& voisins, const DoubleLists& valeurs, const DoubleVect& terme_diag, const int i, const int n, const int j, const int m);
104
105 // Conversion to a Matrice_Morse
106 void block_to_morse( Matrice_Morse& matrix ) const;
107 void block_to_morse_with_ptr( Matrice_Morse& result, std::vector<const double *>& coeffs) const;
108
109 void BlocToMatMorse( Matrice_Morse& matrix ) const;
110
111
112 Matrice_Bloc& operator *=( double x);
113
114 bool check_block_matrix_structure() const;
115
117
118protected :
119 VECT(Matrice) blocs_; // les blocs de la matrices source A
120 std::vector<Matrice_Base*> blocs_non_nuls_; // les blocs non nuls
121 int N_; // 1ere dim de A
122 int M_; // 2eme dim de A
123 int nb_blocs_; // nb total des blocs de A (= N_ * M_)
124
125 ArrOfInt offsets_;
126 std::vector<int> line_offsets_;
127 std::vector<int> column_offsets_;
128
129 template<typename _TAB_T_, typename _VAL_T_>
130 void get_stencil_coeff_templ( Stencil& stencil, _TAB_T_& coeff_sp) const;
131};
132
133#endif
Matrice_Base class - Base class of the matrix hierarchy.
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
VECT(Matrice) blocs_
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
int dim(int d) const
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
ArrOfInt offsets_
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 clean() override
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)
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
Matrice class - Generic class in the matrix hierarchy.
Definition Matrice.h:34
friend class Sortie
Definition Objet_U.h:70