TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Matrice_Sym.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_Sym.h>
17#include <TRUSTTrav.h>
18#include <TRUSTTab.h>
19
21{
22 return est_definie_;
23}
24
26{
27 est_definie_ = val;
28}
29
30void Matrice_Sym::unsymmetrize_stencil( const int nb_lines,
31 const Stencil& symmetric_stencil,
32 Stencil& stencil ) const
33{
34
35 ArrOfInt offsets( nb_lines + 1 );
36 offsets[ 0 ] = 0;
37
38 const int symmetric_stencil_size = symmetric_stencil.dimension( 0 );
39 for ( int k=0; k<symmetric_stencil_size; ++k )
40 {
41 const int line = symmetric_stencil( k, 0 );
42 const int column = symmetric_stencil( k, 1 );
43 offsets[ line + 1 ] += 1;
44 offsets[ column + 1 ] += ( line == column ) ? 0 : 1 ;
45 }
46
47 for ( int i=0; i<nb_lines; ++i )
48 {
49 offsets[ i + 1 ] += offsets[ i ];
50 }
51
52 const int stencil_size = offsets[ nb_lines ];
53 stencil.resize( stencil_size, 2 );
54
55 stencil = -1;
56
57 int index;
58 for ( int k=0; k<symmetric_stencil_size; ++k )
59 {
60 const int line = symmetric_stencil( k, 0 );
61 const int column = symmetric_stencil( k, 1 );
62
63
64 index = offsets[ line ];
65
66 assert( stencil( index, 0 ) < 0 );
67 assert( stencil( index, 1 ) < 0 );
68 assert( index < offsets[ line + 1 ] );
69
70 stencil( index, 0 ) = line;
71 stencil( index, 1 ) = column;
72
73 offsets[ line ] += 1;
74
75 if ( line != column )
76 {
77 index = offsets[ column ];
78
79 assert( stencil( index, 0 ) < 0 );
80 assert( stencil( index, 1 ) < 0 );
81 assert( index < offsets[ column + 1 ] );
82
83 stencil( index, 0 ) = column;
84 stencil( index, 1 ) = line;
85
86 offsets[ column ] += 1;
87 }
88 }
89}
90
92 const Stencil& symmetric_stencil,
93 const StencilCoeffs& symmetric_coefficients,
94 Stencil& stencil,
95 StencilCoeffs& coefficients ) const
96{
97 ArrOfInt offsets( nb_lines + 1 );
98 offsets[ 0 ] = 0;
99
100 const int symmetric_stencil_size = symmetric_stencil.dimension( 0 );
101 assert( symmetric_stencil_size == symmetric_coefficients.size_array( ) );
102 for ( int k=0; k<symmetric_stencil_size; ++k )
103 {
104 const int line = symmetric_stencil( k, 0 );
105 const int column = symmetric_stencil( k, 1 );
106 offsets[ line + 1 ] += 1;
107 offsets[ column + 1 ] += ( line == column ) ? 0 : 1 ;
108 }
109
110 for ( int i=0; i<nb_lines; ++i )
111 {
112 offsets[ i + 1 ] += offsets[ i ];
113 }
114
115 const int stencil_size = offsets[ nb_lines ];
116 stencil.resize( stencil_size, 2 );
117 coefficients.resize_array( stencil_size );
118
119 stencil = -1;
120
121 int index;
122 for ( int k=0; k<symmetric_stencil_size; ++k )
123 {
124 const int line = symmetric_stencil( k, 0 );
125 const int column = symmetric_stencil( k, 1 );
126 const double coefficient = symmetric_coefficients[ k ];
127
128 index = offsets[ line ];
129
130 assert( stencil( index, 0 ) < 0 );
131 assert( stencil( index, 1 ) < 0 );
132 assert( index < offsets[ line + 1 ] );
133
134 stencil( index, 0 ) = line;
135 stencil( index, 1 ) = column;
136 coefficients[ index ] = coefficient;
137
138 offsets[ line ] += 1;
139
140 if ( line != column )
141 {
142 index = offsets[ column ];
143
144 assert( stencil( index, 0 ) < 0 );
145 assert( stencil( index, 1 ) < 0 );
146 assert( index < offsets[ column + 1 ] );
147
148 stencil( index, 0 ) = column;
149 stencil( index, 1 ) = line;
150 coefficients[ index ] = coefficient;
151
152 offsets[ column ] += 1;
153 }
154 }
155}
void set_est_definie(int)
int get_est_definie() const
void unsymmetrize_stencil_and_coefficients(const int nb_lines, const Stencil &symmetric_stencil, const StencilCoeffs &symmetric_coefficients, Stencil &stencil, StencilCoeffs &coefficients) const
void unsymmetrize_stencil(const int nb_lines, const Stencil &symmetric_stencil, Stencil &stencil) const
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133