TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Matrix_tools.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 Matrix_tools_included
17#define Matrix_tools_included
18
19#include <TRUSTTabs_forward.h>
20#include <vector>
21
22class Matrice;
23class Matrice_Morse;
25class Matrice_Base;
26// Define Stencil type:
27#ifdef TRUST_USE_GPU
28using Stencil = BigIntTab; // We need trustIdType indices on GPU (large memory available)
29using StencilCoeffs = BigArrOfDouble;
30#else
31using Stencil = IntTab;
32using StencilCoeffs = ArrOfDouble;
33#endif
34
36{
37public :
38 // conversion to morse format
39 static void convert_to_morse_matrix(const Matrice_Base& in, Matrice_Morse& out);
40
41 // conversion to Morse format keeping pointers to initial coefficients to later more efficiently update them
43 std::vector<const double *>& coeffs);
44
45 // conversion to symetric morse format
47
48 // checking stencil
49 template <typename _TYPE_, typename _SIZE_>
50 static bool is_normalized_stencil(const TRUSTTab<_TYPE_, _SIZE_>& stencil);
51
52 // checking symmetric stencil
53 static bool is_normalized_symmetric_stencil(const Stencil& stencil);
54
55 // Fill the two arrays tab1, tab2 of the CSR morse structure. This is used in the 32b (int) version in allocate_morse_matrix
56 // but also in some of the partitionners. Those two arrays must have been resized correctly already.
57 template <typename _SIZE_>
58 static void fill_csr_arrays(const _SIZE_ nb_lines, const _SIZE_ nb_columns, const TRUSTTab<_SIZE_,_SIZE_>& stencil,
60
61 // building morse matrices by creating new matrix (from given stencil)
62 // so we need to specify is the stencil is to attach or not to the matrix
63 static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil& stencil, Matrice_Morse& matrix, const bool& attach_stencil_to_matrix = false);
64
65 static void build_morse_matrix(const int nb_lines, const int nb_columns, const Stencil& stencil, const StencilCoeffs& coefficients, Matrice_Morse& matrix);
66
67// building symmetric morse matrices
68 static void allocate_symmetric_morse_matrix(const int order, const Stencil& stencil, Matrice_Morse_Sym& matrix);
69
70 static void build_symmetric_morse_matrix(const int order, const Stencil& stencil, const StencilCoeffs& coefficients, Matrice_Morse_Sym& matrix);
71
72 // allocation for scaled addition
73 static void allocate_for_scaled_addition(const Matrice& A, const Matrice& B, Matrice& C);
74
75 static void allocate_for_symmetric_scaled_addition(const Matrice& A, const Matrice& B, Matrice& C);
76
77 // scaled addition
78 static void add_scaled_matrices(const Matrice& A, const double alpha, const Matrice& B, const double beta, Matrice& C);
79
80 static void add_symmetric_scaled_matrices(const Matrice& A, const double alpha, const Matrice& B, const double beta, Matrice& C);
81
82 // stencil analysis
83 static bool is_null_stencil(const Stencil& stencil);
84
85 static bool is_diagonal_stencil(const int nb_lines, const int nb_columns, const Stencil& stencil);
86
87 // allocation from stencil specification
88 static void allocate_from_stencil(const int nb_lines, const int nb_columns, const Stencil& stencil, Matrice& matrix, const bool& attach_stencil_to_matrix = false);
89
90 // extending a matrix's stencil
91 static void extend_matrix_stencil(const Stencil& stencil, Matrice& matrix, const bool& attach_stencil_to_matrix = false);
92
93 // diagonal matrix times a square morse matrix 'mat'
94 // if inverse then the 1/diag is used
95 // this can be seen as a left multiplication
96 static void matdiag_mult_matmorse(const DoubleTab& diag, Matrice_Morse& mat, const bool& inverse);
97
98 //right multiplication version of matdiag_mult_matmorse
99 static void matmorse_mult_matdiag(const DoubleTab& diag, Matrice_Morse& mat, const bool& inverse);
100
101 // uniform diagonal matrix (i.e. same coefficient on the diag) times a square morse matrix 'mat'
102 // if inverse then the 1/diag is used
103 // this can be seen as a left multiplication
104 static void uniform_matdiag_mult_matmorse(const double diag, Matrice_Morse& mat, const bool& inverse);
105
106 //right multiplication version of uniform_matdiag_mult_matmorse
107 static void matmorse_mult_uniform_matdiag(const double diag, Matrice_Morse& mat, const bool& inverse);
108
109 //add empty rows/columns to matrix
110 static void extend_matrix(Matrice_Morse& mat, int nl, int nc);
111};
112
113#endif /* Matrix_tools_included */
Classe Matrice_Base Classe de base de la hierarchie des matrices.
Classe Matrice_Morse_Sym Represente une matrice M (creuse) symetrique stockee au format Morse.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
Classe Matrice Classe generique de la hierarchie des matrices.
Definition Matrice.h:34
static bool is_null_stencil(const Stencil &stencil)
static void fill_csr_arrays(const _SIZE_ nb_lines, const _SIZE_ nb_columns, const TRUSTTab< _SIZE_, _SIZE_ > &stencil, TRUSTVect< _SIZE_, _SIZE_ > &tab1, TRUSTVect< _SIZE_, _SIZE_ > &tab2)
static void add_symmetric_scaled_matrices(const Matrice &A, const double alpha, const Matrice &B, const double beta, Matrice &C)
static bool is_normalized_symmetric_stencil(const Stencil &stencil)
static bool is_normalized_stencil(const TRUSTTab< _TYPE_, _SIZE_ > &stencil)
static void allocate_for_symmetric_scaled_addition(const Matrice &A, const Matrice &B, Matrice &C)
static void extend_matrix(Matrice_Morse &mat, int nl, int nc)
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
static void convert_to_morse_matrix_with_ptrs(const Matrice_Base &in, Matrice_Morse &out, std::vector< const double * > &coeffs)
static void allocate_from_stencil(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice &matrix, const bool &attach_stencil_to_matrix=false)
static bool is_diagonal_stencil(const int nb_lines, const int nb_columns, const Stencil &stencil)
static void build_symmetric_morse_matrix(const int order, const Stencil &stencil, const StencilCoeffs &coefficients, Matrice_Morse_Sym &matrix)
static void build_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, const StencilCoeffs &coefficients, Matrice_Morse &matrix)
static void extend_matrix_stencil(const Stencil &stencil, Matrice &matrix, const bool &attach_stencil_to_matrix=false)
static void allocate_symmetric_morse_matrix(const int order, const Stencil &stencil, Matrice_Morse_Sym &matrix)
static void matmorse_mult_matdiag(const DoubleTab &diag, Matrice_Morse &mat, const bool &inverse)
static void convert_to_morse_matrix(const Matrice_Base &in, Matrice_Morse &out)
static void uniform_matdiag_mult_matmorse(const double diag, Matrice_Morse &mat, const bool &inverse)
static void matdiag_mult_matmorse(const DoubleTab &diag, Matrice_Morse &mat, const bool &inverse)
static void add_scaled_matrices(const Matrice &A, const double alpha, const Matrice &B, const double beta, Matrice &C)
static void matmorse_mult_uniform_matdiag(const double diag, Matrice_Morse &mat, const bool &inverse)
static void convert_to_symmetric_morse_matrix(const Matrice_Base &in, Matrice_Morse_Sym &out)
static void allocate_for_scaled_addition(const Matrice &A, const Matrice &B, Matrice &C)
: Tableau a n entrees pour n<= 4.
Definition TRUSTTab.h:31