TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Matrice_Diagonale.cpp
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#include <Matrice_Diagonale.h>
17#include <TRUSTTab.h>
18
19Implemente_instanciable_sans_constructeur(Matrice_Diagonale,"Matrice_Diagonale",Matrice_Base);
20
22{
23 os << coefficients_ << finl;
24 return os;
25}
26
28{
29 is >> coefficients_;
30 return is;
31}
32
34{
35 return coefficients_.size();
36}
37
39{
40 return coefficients_.size( );
41}
42
44{
45 return coefficients_.size( );
46}
47
48DoubleVect& Matrice_Diagonale::ajouter_multvect_( const DoubleVect& x, DoubleVect& r ) const
49{
50 int count = coefficients_.size( );
51
52 assert( x.size( ) ==count );
53 assert( r.size( ) ==count );
54
55 const double* c_ptr = coefficients_.addr( );
56 const double* x_ptr = x.addr( );
57 double* r_ptr = r.addr( );
58
59 for ( ; count; count-- )
60 {
61 const double x_ = *x_ptr;
62 const double c_ = *c_ptr;
63 double& r_ = *( r_ptr++ );
64 r_ += c_ * x_;
65 x_ptr++;
66 }
67
68 return r;
69}
70
71DoubleVect& Matrice_Diagonale::ajouter_multvectT_( const DoubleVect& x, DoubleVect& r ) const
72{
73 return ajouter_multvect_( x, r );
74}
75
76DoubleTab& Matrice_Diagonale::ajouter_multTab_( const DoubleTab& x, DoubleTab& r ) const
77{
78 if ( ( x.nb_dim() == 1 ) && ( r.nb_dim() == 1 ) )
79 {
80 ajouter_multvect_( x, r );
81 return r;
82 }
83
84 assert( x.nb_dim( ) == 2 );
85 assert( r.nb_dim( ) == 2 );
86
87 const int size = coefficients_.size( );
88 assert( x.dimension( 0 ) == size );
89 assert( r.dimension( 0 ) == size );
90
91 const int nb_components = x.dimension( 1 );
92 assert( r.dimension( 1 ) == nb_components );
93
94 for ( int i=0; i<size; ++i )
95 {
96 const double coefficient = coefficients_( i );
97 for ( int j=0; j<nb_components; ++j )
98 {
99 r( i, j ) += x( i, j ) * coefficient;
100 }
101 }
102
103 return r;
104}
105
106void Matrice_Diagonale::scale( const double x )
107{
108 coefficients_ *= x;
109}
110
112{
113 coefficients_ = 0.;
114}
115
116void Matrice_Diagonale::get_stencil( Stencil& stencil ) const
117{
119 {
120 stencil = stencil_;
121 return;
122 }
123
124 const int size = ordre( );
125
126 stencil.resize( size, 2 );
127
128 for ( int i=0; i<size; ++i )
129 {
130 stencil( i, 0 ) = i;
131 stencil( i, 1 ) = i;
132 }
133}
134
135void Matrice_Diagonale::get_symmetric_stencil( Stencil& stencil ) const
136{
137 get_stencil( stencil );
138}
139
141 StencilCoeffs& coefficients ) const
142{
144 {
145 if( coefficients_.size( ) == 0 )
146 {
147 Cerr << "Error in Matrice_Morse::get_stencil_and_coefficients( )"<<finl;
148 Cerr << " The coefficients are not filled."<<finl;
149 Cerr << " Aborting..." << finl;
151 }
152 stencil = stencil_;
153 const int n = coefficients_.size_array();
154 coefficients.resize_array( n );
155 for ( int i=0; i<n; ++i ) coefficients[ i ] = coefficients_( i );
156 return;
157 }
158 const int size = ordre( );
159
160 stencil.resize( size, 2 );
161 coefficients.resize_array( size );
162
163 for ( int i=0; i<size; ++i )
164 {
165 stencil( i, 0 ) = i;
166 stencil( i, 1 ) = i;
167 coefficients[ i ] = coefficients_( i );
168 }
169}
170
172 StencilCoeffs& coefficients ) const
173{
175 coefficients );
176}
177
182
187
188Matrice_Diagonale::Matrice_Diagonale(const DoubleVect& coefficients) : Matrice_Base( ), coefficients_( coefficients )
189{
190 is_stencil_up_to_date_ = false ;
191}
192
194{
195 return coefficients_;
196}
197
198const DoubleVect& Matrice_Diagonale::get_coefficients() const
199{
200 return coefficients_;
201}
202
204{
205 coefficients_.resize( size );
206}
207
208double Matrice_Diagonale::coeff( int i, int j ) const
209{
210 if ( i==j )
211 {
212 return coefficients_[ i ];
213 }
214 else
215 {
216 return 0.0;
217 }
218}
219
220double& Matrice_Diagonale::coeff( int i, int j )
221{
222 if ( i==j )
223 {
224 return coefficients_[ i ];
225 }
226
227 Cerr << "Error in 'Matrice_Diagonale::coeff()':" << finl;
228 Cerr << " non-const access is only allowed for diagonal coefficients" << finl;
229 Process::exit( );
230
231 return coefficients_[ 0];
232}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Classe Matrice_Base Classe de base de la hierarchie des matrices.
bool is_stencil_up_to_date_
Stencil stencil_
Classe Matrice_Diagonale Represente une matrice diagonale.
void dimensionner(int size)
void get_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const override
int ordre() const override
If square matrix, returns number of lines, otherwise 0.
void get_stencil(Stencil &stencil) const override
double coeff(int i, int j) const
void get_symmetric_stencil(Stencil &stencil) const override
int nb_lignes() const override
Return local number of lines (=size on the current proc).
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
DoubleTab & ajouter_multTab_(const DoubleTab &x, DoubleTab &r) const override
DoubleVect & ajouter_multvectT_(const DoubleVect &x, DoubleVect &r) const override
void get_symmetric_stencil_and_coefficients(Stencil &stencil, StencilCoeffs &coefficients) const override
DoubleVect & ajouter_multvect_(const DoubleVect &x, DoubleVect &r) const override
void scale(const double x) override
DoubleVect & get_coefficients()
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
Definition Process.cpp:570
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
_TYPE_ * addr()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
int nb_dim() const
Definition TRUSTTab.h:199
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45