TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Matrice_Base.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_Base_included
17#define Matrice_Base_included
18
19#include <TRUSTTab.h>
20#include <Matrix_tools.h>
21
22/*! @brief Matrice_Base class - Base class of the matrix hierarchy.
23 *
24 * This class defines the generic interface of a matrix as used in Trio-U.
25 * Consequently it is not instantiable. All matrix types must derive from
26 * this base class and implement its abstract methods.
27 *
28 * In the method comments, A represents a Matrice_base object.
29 *
30 * @sa Abstract class, Abstract methods:, DoubleVect& multvect_(const DoubleVect&, DoubleVect& ) const, int ordre() const
31 */
32
33class Matrice_Base : public Objet_U
34{
35
36 Declare_base(Matrice_Base);
37
38public :
39 /// If square matrix, returns number of lines, otherwise 0
40 virtual int ordre() const=0;
41 /// Return local number of lines (=size on the current proc)
42 virtual int nb_lignes() const=0;
43 /// Return local number of columns (=size on the current proc)
44 virtual int nb_colonnes() const=0;
45
46 // Methods for computing r+=Ax, implemented in derived classes
47 virtual DoubleVect& ajouter_multvect_(const DoubleVect& x, DoubleVect& r) const =0;
48 virtual DoubleVect& ajouter_multvectT_(const DoubleVect& x, DoubleVect& r) const =0;
49 virtual DoubleTab& ajouter_multTab_(const DoubleTab& x, DoubleTab& r) const =0;
50 // Methods for computing r+=Ax with echange_espace_virtuel(), implemented in Matrice_Base
51 virtual inline DoubleVect& ajouter_multvect(const DoubleVect& x, DoubleVect& r) const;
52 virtual inline DoubleVect& ajouter_multvectT(const DoubleVect& x, DoubleVect& r) const;
53 virtual inline DoubleTab& ajouter_multTab(const DoubleTab& , DoubleTab& r) const;
54 // Methods for computing r=Ax, implemented in Matrice_Base
55 virtual inline DoubleVect& multvect_(const DoubleVect&, DoubleVect& ) const;
56 virtual inline DoubleVect& multvect(const DoubleVect&, DoubleVect& ) const;
57 virtual inline DoubleVect& multvectT_(const DoubleVect&, DoubleVect& ) const;
58 virtual inline DoubleVect& multvectT(const DoubleVect&, DoubleVect& ) const;
59 virtual inline DoubleTab& multTab(const DoubleTab& , DoubleTab& r) const;
60 // Matrix printing methods
61 virtual inline Sortie& imprimer(Sortie&) const;
62 virtual inline Sortie& imprimer_formatte(Sortie& s) const;
63
64 friend DoubleVect operator*(const Matrice_Base&, const DoubleVect&);
65
66 virtual void scale(const double x) =0;
67
68 // Zero out the matrix values
69 virtual void clean() { Process::exit("Matrice_base::clean() not implemented.");};
70
71 virtual void get_stencil(Stencil& stencil) const;
72
73 virtual void get_symmetric_stencil(Stencil& stencil) const;
74
75 virtual void get_stencil_and_coefficients(Stencil& stencil, StencilCoeffs& coefficients) const;
76 virtual void get_stencil_and_coeff_ptrs(Stencil& stencil, std::vector<const double *>& coeff_ptr) const;
77
78 virtual void get_symmetric_stencil_and_coefficients(Stencil& stencil, StencilCoeffs& coefficients) const;
79
80 int get_stencil_size() const ;
81 virtual void build_stencil();
82
83 void set_stencil( const Stencil& stencil );
84
85 bool is_stencil_up_to_date() const ;
86
87protected:
89 Stencil stencil_ ;
90};
91
92
93
94/*! @brief Multiplication of a vector by the matrix.
95 *
96 * Operation: r = A*x
97 *
98 * @param (DoubleVect& x) the vector to multiply
99 * @param (DoubleVect& r) the result vector of the operation
100 * @return (DoubleVect&) the result vector of the operation
101 */
102inline DoubleVect& Matrice_Base::
103multvect(const DoubleVect& x, DoubleVect& r) const
104{
105 multvect_(x,r);
107 return r;
108}
109
110inline DoubleVect& Matrice_Base::
111multvect_(const DoubleVect& x, DoubleVect& r) const
112{
113 r=0;
115 return r;
116}
117
118/*! @brief Multiplication of a vector by the transposed matrix.
119 *
120 * Operation: r = AT*x
121 *
122 * @param (DoubleVect& x) the vector to multiply
123 * @param (DoubleVect& r) the result vector of the operation
124 * @return (DoubleVect&) the result vector of the operation
125 */
126inline DoubleVect& Matrice_Base::
127multvectT(const DoubleVect& x, DoubleVect& r) const
128{
129 multvectT_(x,r);
131 return r;
132}
133
134inline DoubleVect& Matrice_Base::
135multvectT_(const DoubleVect& x, DoubleVect& r) const
136{
137 r=0;
139 return r;
140}
141
142/*! @brief NOT IMPLEMENTED Multiplication of a matrix represented by an array by the matrix.
143 *
144 * Operation: R = A*X
145 *
146 * @param (DoubleTab&) the matrix to multiply
147 * @param (DoubleTab& r) the result matrix of the operation
148 * @return (DoubleTab&) the result matrix of the operation
149 * @throws NOT IMPLEMENTED
150 */
151inline DoubleTab& Matrice_Base::
152multTab(const DoubleTab& x, DoubleTab& r) const
153{
154 r=0;
155 ajouter_multTab_(x,r);
157 return r;
158}
159
160
161/*! @brief Matrix-vector multiply-accumulate operation (saxpy).
162 *
163 * Operation: r = r + A*x
164 *
165 * @param (DoubleVect& x) the vector to multiply
166 * @param (DoubleVect& r) the result vector of the operation
167 * @return (DoubleVect&) the result vector of the operation
168 */
169inline DoubleVect& Matrice_Base::
170ajouter_multvect(const DoubleVect& x, DoubleVect& r) const
171{
174 return r;
175}
176
177/*! @brief Matrix-vector multiply-accumulate operation (saxpy).
178 *
179 * Operation: r = r + A*x
180 *
181 * @param (DoubleVect& x) the vector to multiply
182 * @param (DoubleVect& r) the result vector of the operation
183 * @return (DoubleVect&) the result vector of the operation
184 */
185inline DoubleVect& Matrice_Base::
186ajouter_multvectT(const DoubleVect& x, DoubleVect& r) const
187{
190 return r;
191}
192
193/*! @brief NOT IMPLEMENTED Matrix-matrix multiply-accumulate operation (saxpy)
194 *
195 * (matrix represented by an array)
196 * Operation: R = R + A*X
197 *
198 * @param (DoubleTab&) the matrix to multiply
199 * @param (DoubleTab& r) the result matrix of the operation
200 * @return (DoubleTab&) the result matrix of the operation
201 * @throws NOT IMPLEMENTED
202 */
203inline DoubleTab& Matrice_Base::
204ajouter_multTab(const DoubleTab& x, DoubleTab& r) const
205{
206 ajouter_multTab_(x,r);
208 return r;
209}
210
211
212/*! @brief Friend function (outside the class) of the Matrice_Base class.
213 *
214 * Multiplication operator: returns (A*vect)
215 *
216 * @param (Matrice_Base& A) the multiplying matrix
217 * @param (DoubleVect& vect) the vector to multiply
218 * @return (DoubleVect) the result vector of the operation
219 */
220DoubleVect operator * (const Matrice_Base& A, const DoubleVect& vect);
221
222
224{
225 return os<<*this;
226}
227
229{
230 return os<<*this;
231}
232
233#endif
Matrice_Base class - Base class of the matrix hierarchy.
int get_stencil_size() const
virtual DoubleTab & ajouter_multTab(const DoubleTab &, DoubleTab &r) const
NOT IMPLEMENTED Matrix-matrix multiply-accumulate operation (saxpy).
void set_stencil(const Stencil &stencil)
virtual void get_symmetric_stencil(Stencil &stencil) const
virtual DoubleVect & multvectT(const DoubleVect &, DoubleVect &) const
Multiplication of a vector by the transposed matrix.
virtual DoubleVect & ajouter_multvectT(const DoubleVect &x, DoubleVect &r) const
Matrix-vector multiply-accumulate operation (saxpy).
virtual void get_stencil(Stencil &stencil) const
bool is_stencil_up_to_date_
virtual DoubleVect & multvect_(const DoubleVect &, DoubleVect &) const
virtual DoubleVect & ajouter_multvect_(const DoubleVect &x, DoubleVect &r) const =0
virtual DoubleTab & ajouter_multTab_(const DoubleTab &x, DoubleTab &r) const =0
friend DoubleVect operator*(const Matrice_Base &, const DoubleVect &)
Friend function (outside the class) of the Matrice_Base class.
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 DoubleVect & multvectT_(const DoubleVect &, DoubleVect &) const
virtual DoubleVect & multvect(const DoubleVect &, DoubleVect &) const
Multiplication of a vector by the matrix.
Stencil stencil_
virtual void get_symmetric_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const
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 int ordre() const =0
If square matrix, returns number of lines, otherwise 0.
virtual void build_stencil()
virtual DoubleTab & multTab(const DoubleTab &, DoubleTab &r) const
NOT IMPLEMENTED Multiplication of a matrix represented by an array by the matrix.
virtual void scale(const double x)=0
virtual Sortie & imprimer_formatte(Sortie &s) const
virtual DoubleVect & ajouter_multvect(const DoubleVect &x, DoubleVect &r) const
Matrix-vector multiply-accumulate operation (saxpy).
virtual DoubleVect & ajouter_multvectT_(const DoubleVect &x, DoubleVect &r) const =0
virtual void clean()
virtual Sortie & imprimer(Sortie &) const
bool is_stencil_up_to_date() const
friend class Sortie
Definition Objet_U.h:70
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")