TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Matrix_tools.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 <Matrix_tools.h>
17#include <Matrice.h>
18#include <Matrice_Base.h>
19#include <Matrice_Nulle.h>
20#include <Matrice_Diagonale.h>
21#include <Matrice_Morse.h>
22#include <Matrice_Morse_Sym.h>
23#include <TRUSTTab.h>
24#include <Array_tools.h>
25
26#include <algorithm>
27
28// conversion to morse format
30 Matrice_Morse& out )
31{
32 Stencil stencil;
33 StencilCoeffs coefficients;
34
35 in.get_stencil_and_coefficients( stencil, coefficients );
36
38 in.nb_colonnes( ),
39 stencil,
40 coefficients,
41 out );
42}
43
44// conversion to morse format, storing initial location of coefficients pointers
46 Matrice_Morse& out,
47 std::vector<const double *>& coeffs)
48{
49 Stencil stencil;
50 StencilCoeffs coefficients;
51
52 in.get_stencil_and_coeff_ptrs( stencil, coeffs);
53
54 // Copy coefficients into StencilCoeffs
55 coefficients.resize_array((int)coeffs.size());
56 auto deref_fun = [](const double* src) { return *src; };
57
58 std::transform(coeffs.begin(), coeffs.end(), coefficients.addr(), deref_fun);
59
61 in.nb_colonnes( ),
62 stencil,
63 coefficients,
64 out );
65}
66
67
68// conversion to symetric morse format
71{
72 assert( in.nb_lignes( ) == in.nb_colonnes( ) );
73
74 Stencil stencil;
75 StencilCoeffs coefficients;
76
77 in.get_symmetric_stencil_and_coefficients( stencil, coefficients );
78
80 stencil,
81 coefficients,
82 out );
83}
84
85// checking stencil
86template <typename _TYPE_, typename _SIZE_>
88{
89 const _SIZE_ size = stencil.dimension( 0 );
90 for ( _SIZE_ i=1; i<size; ++i )
91 {
92 _TYPE_ delta1 = stencil( i-1, 0 ) - stencil( i, 0 );
93 _TYPE_ delta2 = stencil( i-1, 1 ) - stencil( i, 1 );
94 _TYPE_ delta = ( delta1 == 0 ) ? delta2 : delta1;
95
96 if ( delta >= 0 )
97 return false;
98 }
99 return true;
100}
101
102// checking symmetric stencil
104{
105 if ( ! ( is_normalized_stencil( stencil ) ) )
106 {
107 Cerr << "non-normalized stencil" << finl;
108 return false;
109 }
110
111 const int size = stencil.dimension( 0 );
112 for ( int i=0; i<size; ++i )
113 {
114 int delta = stencil( i, 0 ) - stencil( i, 1 );
115 if ( delta > 0 )
116 {
117 Cerr << "( " << i << " ) line index > column index : ( " << stencil( i, 0 ) << ", " << stencil( i, 1 ) << " )" << finl;
118 return false;
119 }
120 }
121
122 return true;
123}
124
125template <typename _SIZE_>
126void Matrix_tools::fill_csr_arrays(const _SIZE_ nb_lines, const _SIZE_ nb_columns, const TRUSTTab<_SIZE_,_SIZE_>& stencil,
128{
129 assert( is_normalized_stencil( stencil ) );
130
131 const _SIZE_ nb_coefficients = stencil.dimension( 0 );
132
133 assert(tab1.size_array() == nb_lines+1);
134 assert(tab2.size_array() == nb_coefficients);
135
136 if ( nb_coefficients > 0 )
137 {
138 tab1 = 0 ;
139 tab1[0] = 1;
140 for (_SIZE_ i=0; i<nb_coefficients; ++i )
141 {
142 assert( stencil( i ,0 ) >= 0 );
143 assert( stencil( i ,0 ) < nb_lines );
144 assert( stencil( i ,1 ) >= 0 );
145 assert( stencil( i ,1 ) < nb_columns );
146
147 tab1[stencil(i, 0) + 1] += 1;
148 tab2[i] = stencil(i, 1) + 1;
149 }
150 for ( int i=0; i<nb_lines; ++i )
151 tab1[i + 1] += tab1[i];
152 }
153}
154
155// Explicit instanciation
156template void Matrix_tools::fill_csr_arrays(const int nb_lines, const int nb_columns, const TRUSTTab<int,int>& stencil,
158#if INT_is_64_ == 2
159template void Matrix_tools::fill_csr_arrays(const trustIdType nb_lines, const trustIdType nb_columns, const TRUSTTab<trustIdType,trustIdType>& stencil,
161#endif
162
163// building morse matrices
164void Matrix_tools::allocate_morse_matrix( const int nb_lines,
165 const int nb_columns,
166 const Stencil& stencil,
167 Matrice_Morse& matrix ,
168 const bool& attach_stencil_to_matrix )
169{
170 assert( is_normalized_stencil( stencil ) );
171
172 const int nb_coefficients = stencil.dimension( 0 );
173 matrix.dimensionner( nb_lines, nb_columns, nb_coefficients );
174 {
175 auto& tab1 = matrix.get_set_tab1();
176 auto& tab2 = matrix.get_set_tab2();
177 if ( nb_coefficients > 0 )
178 {
179 tab1 = 0;
180 tab1[0] = 1;
181 for ( int i=0; i<nb_coefficients; ++i )
182 {
183 tab1[stencil(i, 0) + 1] += 1;
184 tab2[i] = stencil(i, 1) + 1;
185 }
186 for ( int i=0; i<nb_lines; ++i )
187 tab1[i + 1] += tab1[i];
188 }
189 }
190 if( attach_stencil_to_matrix )
191 matrix.set_stencil( stencil );
192}
193
194void Matrix_tools::build_morse_matrix( const int nb_lines,
195 const int nb_columns,
196 const Stencil& stencil,
197 const StencilCoeffs& coefficients,
198 Matrice_Morse& matrix )
199{
200 // No : stencil do not rely on sorted columns
201 //assert( is_normalized_stencil( stencil ) );
202
203 const int nb_coefficients = stencil.dimension( 0 );
204 assert( nb_coefficients == coefficients.size_array( ) );
205
206 matrix.dimensionner( nb_lines,
207 nb_columns,
208 nb_coefficients );
209
210 if ( nb_coefficients > 0 )
211 {
212 matrix.get_set_tab1() =0 ;
213 matrix.get_set_tab1()( 0 ) = 1;
214 for ( int i=0; i<nb_coefficients; ++i )
215 {
216 assert( stencil( i ,0 ) >= 0 );
217 assert( stencil( i ,0 ) < nb_lines );
218 assert( stencil( i ,1 ) >= 0 );
219 assert( stencil( i ,1 ) < nb_columns );
220
221 matrix.get_set_tab1()( stencil( i, 0 ) + 1 ) += 1;
222 matrix.get_set_tab2()( i ) = stencil( i, 1 ) + 1;
223 matrix.get_set_coeff()( i ) = coefficients[ i ];
224 }
225 for ( int i=0; i<nb_lines; ++i )
226 {
227 matrix.get_set_tab1()( i + 1 ) += matrix.get_tab1()( i );
228 }
229 }
230}
231
232
233
234// building symmetric morse matrices
236 const Stencil& stencil,
237 Matrice_Morse_Sym& matrix )
238{
239 assert( is_normalized_symmetric_stencil( stencil ) );
240
241 const int nb_coefficients = stencil.dimension( 0 );
242
243 matrix.dimensionner( order,
244 order,
245 nb_coefficients );
246
247 if ( nb_coefficients > 0 )
248 {
249 matrix.get_set_tab1()= 0 ;
250 matrix.get_set_tab1()( 0 ) = 1;
251 for ( int i=0; i<nb_coefficients; ++i )
252 {
253 assert( stencil( i ,0 ) >= 0 );
254 assert( stencil( i ,0 ) < order );
255 assert( stencil( i ,1 ) >= 0 );
256 assert( stencil( i ,1 ) < order );
257 assert( stencil( i, 0 ) <= stencil( i, 1 ) );
258
259 matrix.get_set_tab1()( stencil( i, 0 ) + 1 ) += 1;
260 matrix.get_set_tab2()( i ) = stencil( i, 1 ) + 1;
261 }
262 for ( int i=0; i<order; ++i )
263 {
264 matrix.get_set_tab1()( i + 1 ) += matrix.get_tab1()( i );
265 }
266 }
267 matrix.set_symmetric( 1 );
268}
269
270
272 const Stencil& stencil,
273 const StencilCoeffs& coefficients,
274 Matrice_Morse_Sym& matrix )
275{
276 // No : stencil do not rely on sorted columns
277 // assert( is_normalized_symmetric_stencil( stencil ) );
278
279 const int nb_coefficients = stencil.dimension( 0 );
280 assert( nb_coefficients == coefficients.size_array( ) );
281
282 matrix.dimensionner( order,
283 order,
284 nb_coefficients );
285
286 if ( nb_coefficients > 0 )
287 {
288 matrix.get_set_tab1() = 0 ;
289 matrix.get_set_tab1()( 0 ) = 1;
290 for ( int i=0; i<nb_coefficients; ++i )
291 {
292 assert( stencil( i ,0 ) >= 0 );
293 assert( stencil( i ,0 ) < order );
294 assert( stencil( i ,1 ) >= 0 );
295 assert( stencil( i ,1 ) < order );
296 assert( stencil( i, 0 ) <= stencil( i, 1 ) );
297
298 matrix.get_set_tab1()( stencil( i, 0 ) + 1 ) += 1;
299 matrix.get_set_tab2()( i ) = stencil( i, 1 ) + 1;
300 matrix.get_set_coeff()( i ) = coefficients[ i ];
301 }
302 for ( int i=0; i<order; ++i )
303 {
304 matrix.get_set_tab1()( i + 1 ) += matrix.get_tab1()( i );
305 }
306 }
307 matrix.set_symmetric( 1 );
308}
309
310
311// allocation for scaled addition
313 const Matrice& B,
314 Matrice& C )
315{
316 assert( A.valeur( ).nb_lignes( ) == B.valeur( ).nb_lignes( ) );
317 assert( A.valeur( ).nb_colonnes( ) == B.valeur( ).nb_colonnes( ) );
318
319 Stencil A_stencil;
320 A.valeur( ).get_stencil( A_stencil );
321 const int A_size = (int)A_stencil.dimension( 0 );
322
323 Stencil B_stencil;
324 B.valeur( ).get_stencil( B_stencil );
325 const int B_size = (int)B_stencil.dimension( 0 );
326
327 int size = A_size + B_size;
328 Stencil stencil;
329
330 stencil.resize( size, 2 );
331
332 for ( int i=0; i<A_size; ++i )
333 {
334 stencil( i , 0 ) = A_stencil( i, 0 );
335 stencil( i , 1 ) = A_stencil( i, 1 ) ;
336 }
337
338 for ( int i=0; i<B_size; ++i )
339 {
340 stencil( i+A_size , 0 ) = B_stencil( i, 0 );
341 stencil( i+A_size , 1 ) = B_stencil( i, 1 ) ;
342 }
343
344 tableau_trier_retirer_doublons( stencil );
345
346 C.typer( "Matrice_Morse" );
347 Matrice_Morse& C_ = ref_cast( Matrice_Morse, C.valeur( ) );
348
349 allocate_morse_matrix( A.valeur( ).nb_lignes( ),
350 A.valeur( ).nb_colonnes( ),
351 stencil,
352 C_ );
353}
354
356 const Matrice& B,
357 Matrice& C )
358{
359 assert( A.valeur( ).nb_lignes( ) == A.valeur( ).nb_lignes( ) );
360 assert( A.valeur( ).nb_lignes( ) == B.valeur( ).nb_lignes( ) );
361 assert( A.valeur( ).nb_colonnes( ) == B.valeur( ).nb_colonnes( ) );
362
363 Stencil A_stencil;
364 A.valeur( ).get_symmetric_stencil( A_stencil );
365 const int A_size = (int)A_stencil.dimension( 0 );
366
367 Stencil B_stencil;
368 B.valeur( ).get_symmetric_stencil( B_stencil );
369 const int B_size = (int)B_stencil.dimension( 0 );
370
371 int size = A_size + B_size;
372 Stencil stencil;
373
374 stencil.resize( size, 2 );
375
376 for ( int i=0; i<A_size; ++i )
377 {
378 stencil( i , 0 ) = A_stencil( i, 0 );
379 stencil( i , 1 ) = A_stencil( i, 1 ) ;
380 }
381
382 for ( int i=0; i<B_size; ++i )
383 {
384 stencil( i+A_size , 0 ) = B_stencil( i, 0 );
385 stencil( i+A_size , 1 ) = B_stencil( i, 1 ) ;
386 }
387
388 tableau_trier_retirer_doublons( stencil );
389
390 C.typer( "Matrice_Morse_Sym" );
391 Matrice_Morse_Sym& C_ = ref_cast( Matrice_Morse_Sym, C.valeur( ) );
392
393 allocate_symmetric_morse_matrix( A.valeur( ).nb_lignes( ),
394 stencil,
395 C_ );
396}
397
398
399// scaled addition
401 const double alpha,
402 const Matrice& B,
403 const double beta,
404 Matrice& C )
405{
406 assert( sub_type( Matrice_Morse, C.valeur( ) ) );
407 Matrice_Morse& C_ = ref_cast( Matrice_Morse, C.valeur( ) );
408
410
411 Stencil A_stencil;
412 StencilCoeffs A_coefficients;
413 A.valeur( ).get_stencil_and_coefficients( A_stencil,
414 A_coefficients );
415
416 Stencil B_stencil;
417 StencilCoeffs B_coefficients;
418 B.valeur( ).get_stencil_and_coefficients( B_stencil,
419 B_coefficients );
420
421 int A_k = 0;
422 int B_k = 0;
423
424 C_.get_set_coeff() = 0.0 ;
425
426 const int nb_lines = C_.nb_lignes( );
427 for ( int i=0; i<nb_lines; ++i )
428 {
429 auto k0 = C_.get_tab1()( i ) - 1;
430 auto k1 = C_.get_tab1()( i + 1 ) - 1;
431
432 for ( auto k=k0; k<k1; ++k )
433 {
434 int j = C_.get_tab2()( k ) - 1;
435
436 if ( ( A_k < A_stencil.dimension( 0 ) ) && ( A_stencil( A_k, 0 ) == i ) && ( A_stencil( A_k, 1 ) == j ) )
437 {
438 C_.get_set_coeff()( k ) += alpha * A_coefficients[ A_k ];
439 ++A_k;
440 }
441
442 if ( ( B_k < B_stencil.dimension( 0 ) ) && ( B_stencil( B_k, 0 ) == i ) && ( B_stencil( B_k, 1 ) == j ) )
443 {
444 C_.get_set_coeff()( k ) += beta * B_coefficients[ B_k ];
445 ++B_k;
446 }
447 }
448 }
449
450 assert( A_k == A_coefficients.size_array( ) );
451 assert( B_k == B_coefficients.size_array( ) );
452}
453
455 const double alpha,
456 const Matrice& B,
457 const double beta,
458 Matrice& C )
459{
460 assert( sub_type( Matrice_Morse_Sym, C.valeur( ) ) );
461 Matrice_Morse_Sym& C_ = ref_cast( Matrice_Morse_Sym, C.valeur( ) );
462
464
465 Stencil A_stencil;
466 StencilCoeffs A_coefficients;
467 A.valeur( ).get_symmetric_stencil_and_coefficients( A_stencil,
468 A_coefficients );
469
470 Stencil B_stencil;
471 StencilCoeffs B_coefficients;
472 B.valeur( ).get_symmetric_stencil_and_coefficients( B_stencil,
473 B_coefficients );
474
475 int A_k = 0;
476 int B_k = 0;
477
478 C_.get_set_coeff() = 0.0 ;
479
480 const int nb_lines = C_.nb_lignes( );
481 for ( int i=0; i<nb_lines; ++i )
482 {
483 auto k0 = C_.get_tab1()( i ) - 1;
484 auto k1 = C_.get_tab1()( i + 1 ) - 1;
485
486 for ( auto k=k0; k<k1; ++k )
487 {
488 int j = C_.get_tab2()( k ) - 1;
489
490 if ( ( A_k < A_stencil.dimension( 0 ) ) && ( A_stencil( A_k, 0 ) == i ) && ( A_stencil( A_k, 1 ) == j ) )
491 {
492 C_.get_set_coeff()( k ) += alpha * A_coefficients[ A_k ];
493 ++A_k;
494 }
495
496 if ( ( B_k < B_stencil.dimension( 0 ) ) && ( B_stencil( B_k, 0 ) == i ) && ( B_stencil( B_k, 1 ) == j ) )
497 {
498 C_.get_set_coeff()( k ) += beta * B_coefficients[ B_k ];
499 ++B_k;
500 }
501 }
502 }
503
504 assert( A_k == A_coefficients.size_array( ) );
505 assert( B_k == B_coefficients.size_array( ) );
506}
507
508// stencil analysis
509bool Matrix_tools::is_null_stencil( const Stencil& stencil )
510{
511 return ( stencil.dimension( 0 ) == 0 );
512}
513
514bool Matrix_tools::is_diagonal_stencil( const int nb_lines,
515 const int nb_columns,
516 const Stencil& stencil )
517{
518 if ( nb_lines != nb_columns )
519 {
520 return false;
521 }
522
523 const int size = stencil.dimension( 0 );
524
525 if ( size == 0 )
526 {
527 return false;
528 }
529
530 for ( int i=0; i<size; ++i )
531 {
532 if ( stencil( i, 0 ) != stencil( i, 1 ) )
533 {
534 return false;
535 }
536
537 if ( stencil( i, 0 ) >= nb_lines )
538 {
539 return false;
540 }
541
542 if ( stencil( i, 1 ) >= nb_columns )
543 {
544 return false;
545 }
546 }
547
548 return true;
549}
550
551void Matrix_tools::allocate_from_stencil( const int nb_lines,
552 const int nb_columns,
553 const Stencil& stencil,
554 Matrice& matrix ,
555 const bool& attach_stencil_to_matrix)
556{
557 if ( is_null_stencil( stencil ) )
558 {
559 matrix.typer( "Matrice_Nulle" );
560 Matrice_Nulle& matrix_ = ref_cast( Matrice_Nulle, matrix.valeur( ) );
561 matrix_.dimensionner( nb_lines, nb_columns );
562 }
563 else if ( is_diagonal_stencil( nb_lines,
564 nb_columns,
565 stencil ) )
566 {
567 matrix.typer( "Matrice_Diagonale" );
568 Matrice_Diagonale& matrix_ = ref_cast( Matrice_Diagonale, matrix.valeur( ) );
569 matrix_.dimensionner( nb_lines );
570 if( attach_stencil_to_matrix )
571 {
572 matrix_.set_stencil( stencil );
573 }
574 }
575 else
576 {
577 matrix.typer( "Matrice_Morse" );
578 Matrice_Morse& matrix_ = ref_cast( Matrice_Morse, matrix.valeur( ) );
579 allocate_morse_matrix( nb_lines,
580 nb_columns,
581 stencil,
582 matrix_,
583 attach_stencil_to_matrix );
584 }
585}
586
587// extending a matrix's stencil
588void Matrix_tools::extend_matrix_stencil( const Stencil& stencil,
589 Matrice& matrix ,
590 const bool& attach_stencil_to_matrix )
591{
592 if ( ! ( is_null_stencil( stencil ) ) )
593 {
594 const int nb_lines = matrix.valeur( ).nb_lignes( );
595 const int nb_columns = matrix.valeur( ).nb_colonnes( );
596
597 Stencil full_stencil;
598 matrix.valeur( ).get_stencil( full_stencil );
599
600 const int size = stencil.dimension( 0 );
601
602 const int old_size = full_stencil.size( ) / 2 ;
603
604 full_stencil.resize( old_size + size, 2);
605
606 for ( int i=0; i<size; ++i )
607 {
608 full_stencil( old_size + i , 0 ) = stencil( i, 0 );
609 full_stencil( old_size + i , 1 ) = stencil( i, 1 );
610 }
611
612 tableau_trier_retirer_doublons( full_stencil );
613
614 allocate_from_stencil( nb_lines,
615 nb_columns,
616 full_stencil,
617 matrix ,
618 attach_stencil_to_matrix );
619 }
620}
621
622
623
624void Matrix_tools::matdiag_mult_matmorse( const DoubleTab& diag,
625 Matrice_Morse& mat,
626 const bool& inverse )
627{
628 const int nb_lignes = mat.nb_lignes( );
629 const auto& tab1 = mat.get_tab1( );
630 const auto& tab2 = mat.get_tab2( );
631 auto nnz_tot = 0;
632 for( int i=0; i<nb_lignes; i++ )
633 {
634 const int nnz_i = (int)(tab1[ i+1 ] - tab1[ i ]); // nnz sur la ligne i
635 for(int k=0; k<nnz_i; k++)
636 {
637 const int j = tab2[nnz_tot + k] - 1 ; // indice de la colonne
638 double& coefficient = mat.coef( i, j );
639 if( inverse )
640 coefficient *= 1./diag[ i ] ;
641 else
642 coefficient *= diag[ i ] ;
643 }
644 nnz_tot += nnz_i;
645 }
646}
647
648void Matrix_tools::matmorse_mult_matdiag( const DoubleTab& diag,
649 Matrice_Morse& mat,
650 const bool& inverse )
651{
652 const int nb_lignes = mat.nb_lignes( );
653 const auto& tab1 = mat.get_tab1( );
654 const auto& tab2 = mat.get_tab2( );
655 auto nnz_tot = 0;
656 for( int i=0; i<nb_lignes; i++ )
657 {
658 const int nnz_i = (int)(tab1[ i+1 ] - tab1[ i ]); // nnz sur la ligne i
659 for(int k=0; k<nnz_i; k++)
660 {
661 const int j = tab2[nnz_tot + k] - 1 ; // indice de la colonne
662 double& coefficient = mat.coef( i, j );
663 if( inverse )
664 coefficient *= 1./diag[ j ] ;
665 else
666 coefficient *= diag[ j ] ;
667 }
668 nnz_tot += nnz_i;
669 }
670}
671
672
674 Matrice_Morse& mat,
675 const bool& inverse )
676{
677 const int nb_lignes = mat.nb_lignes( );
678 const auto& tab1 = mat.get_tab1( );
679 const auto& tab2 = mat.get_tab2( );
680 auto nnz_tot = 0;
681 for( int i=0; i<nb_lignes; i++ )
682 {
683 const int nnz_i = (int)(tab1[ i+1 ] - tab1[ i ]); // nnz sur la ligne i
684 for(int k=0; k<nnz_i; k++)
685 {
686 const int j = tab2[nnz_tot + k] - 1 ; // indice de la colonne
687 double& coefficient = mat.coef( i, j );
688 if( inverse )
689 coefficient *= 1./diag ;
690 else
691 coefficient *= diag ;
692 }
693 nnz_tot += nnz_i;
694 }
695}
696
698 Matrice_Morse& mat,
699 const bool& inverse )
700{
701 uniform_matdiag_mult_matmorse( diag, mat, inverse );
702}
703
705{
706
707 auto& tab1 = mat.get_set_tab1();
708 auto old_tab1 = tab1;
709 tab1.reset(), tab1.resize(nl + 1);
710 for (int i = 0; i <= nl; i++) tab1(i) = old_tab1(std::min(i, old_tab1.size_array() - 1));
711 mat.set_nb_columns(nc); //plus facile
712}
713
Classe Matrice_Base Classe de base de la hierarchie des matrices.
void set_stencil(const Stencil &stencil)
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 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
Classe Matrice_Diagonale Represente une matrice diagonale.
void dimensionner(int size)
Classe Matrice_Morse_Sym Represente une matrice M (creuse) symetrique stockee au format Morse.
bool check_sorted_symmetric_morse_matrix_structure() const
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
bool check_sorted_morse_matrix_structure() const
auto & get_set_tab2()
const auto & get_tab2() 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)
auto & get_set_coeff()
double coef(int i, int j) const
auto & get_set_tab1()
void set_symmetric(const int)
int nb_lignes() const override
Return local number of lines (=size on the current proc).
void dimensionner(int order)
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)
_SIZE_ size_array() const
_TYPE_ * addr()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
: Tableau a n entrees pour n<= 4.
Definition TRUSTTab.h:31
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