TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Precond_local.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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 <Precond_local.h>
17#include <Matrice_Bloc_Sym.h>
18
19Implemente_instanciable(Precond_local,"Precond_local",Precond_base);
20
21// printOn et readOn
23{
24 return s << le_precond_local_.que_suis_je() << finl;
25}
26
28{
30 // Pour eviter trop d'affichage (Convergence)
31 if (!le_precond_local_->limpr())
32 le_precond_local_->fixer_limpr(-1);
33 return is;
34}
35
36void Precond_local::prepare_(const Matrice_Base& la_matrice, const DoubleVect& secmem)
37{
38 le_precond_local_->reinit();
39
40 if(sub_type(Matrice_Bloc_Sym,la_matrice))
41 {
42 const Matrice_Bloc_Sym& m = ref_cast(Matrice_Bloc_Sym, la_matrice);
44 // La matrice est t'elle definie ? On regarde son bloc(0,0)
45 const Matrice_Bloc& bloc = ref_cast(Matrice_Bloc, m.get_bloc(0,0).valeur());
46 const Matrice_Morse_Sym& sous_bloc= ref_cast(Matrice_Morse_Sym, bloc.get_bloc(0,0).valeur());
47 int ok = sous_bloc.get_est_definie();
48 matrice_de_travail_.set_est_definie(ok);
49 matrice_a_resoudre_ = matrice_de_travail_;
50 }
51 else if (sub_type(Matrice_Bloc,la_matrice))
52 {
53 const Matrice_Bloc& matrice = ref_cast(Matrice_Bloc,la_matrice);
54 const Matrice& MB00 = matrice.get_bloc(0,0);
55 if(!sub_type(Matrice_Morse_Sym,MB00.valeur()))
56 {
57 Cerr<<"Precond_local::prepare_ MB00 is not of type deriving from matrice_morse_sym "
58 <<MB00->que_suis_je()<<finl;
59 exit();
60 }
61 matrice_a_resoudre_ = MB00.valeur();
62 }
63 else if (sub_type(Matrice_Morse_Sym,la_matrice))
64 {
65 matrice_a_resoudre_ = la_matrice;
66 }
67 else
68 {
69 Cerr<<"In Precond_local: prepare_, the type of the matrix " << la_matrice.que_suis_je() << finl;
70 Cerr<<"is not yet supported." << finl;
71 exit();
72 }
73 Precond_base::prepare_(la_matrice, secmem);
74}
75
77 const DoubleVect& secmem,
78 DoubleVect& solution)
79{
80 const Matrice_Base& m = matrice_a_resoudre_.valeur();
81 int ok = precond(m, secmem, solution);
82 return ok;
83}
84
86 const DoubleVect& secmem,
87 DoubleVect& solution)
88{
90 {
91 Cerr << "Precond_local::precond not coded for nproc > 1" << finl;
92 exit();
93#if 0
94 VECT(Descripteur)& desc = solution.structure().descripteur();
95 int nb_struct = desc.size();
96 if(nb_struct==1)
97 res_syst_loc_simple(mat,secmem,solution,champ);
98 else if (nb_struct==2)
99 res_syst_loc_hybride(mat,secmem,solution,champ);
100 else
101 {
102 Cerr << "Cases still not supported in Precond_local::preconditionner." << finl;
103 // PL: Il suffit de generaliser res_syst_loc_hybride comme dans NP une
104 // taille nb_struct quelconque...pour supporter P0+P1+Pa (pas le temps de le faire).
105 exit();
106 }
107#endif
108 return 0;
109 }
110 else
111 return le_precond_local_.resoudre_systeme(mat,secmem,solution);
112}
113
115 const DoubleVect& secmem,
116 DoubleVect& solution,
117 const Champ_Inc_base& champ)
118{
119 exit();
120#if 0
121 if(a_remplir_)
122 {
123 a_remplir_=0;
124 int n_reel = secmem.size();
125 la_matrice_locale_.dimensionner(n_reel,0);
126 int ii,jj;
127 int cpt=0;
128 const IntVect& tab1_tot = mat.tab1_;
129 const IntVect& tab2_tot = mat.tab2_;
130 const DoubleVect& coeff_tot = mat.coeff_;
131 IntVect& tab1_reel = la_matrice_locale_.tab1_;
132 IntVect& tab2_reel = la_matrice_locale_.tab2_;
133 DoubleVect& coeff_reel = la_matrice_locale_.coeff_;
134 tab1_reel(0)=1;
135 for(ii=0; ii<n_reel; ii++)
136 {
137 int dl = tab1_tot(ii);
138 int fl = tab1_tot(ii+1);
139 for(jj=dl; jj<fl; jj++)
140 {
141 if(tab2_tot(jj-1)<=n_reel)
142 cpt++;
143 }
144 tab1_reel(ii+1)=cpt+1;
145 }
146 la_matrice_locale_.dimensionner(n_reel,tab1_reel(n_reel)-1);
147 cpt=0;
148 for(ii=0; ii<n_reel; ii++)
149 {
150 int dl = tab1_tot(ii);
151 int fl = tab1_tot(ii+1);
152 for(jj=dl; jj<fl; jj++)
153 {
154 if(tab2_tot(jj-1)<=n_reel)
155 {
156 tab2_reel(cpt)=tab2_tot(jj-1);
157 coeff_reel(cpt++)=coeff_tot(jj-1);
158 }
159 }
160 }
161 la_matrice_locale_.set_est_definie(mat.get_est_definie());
162 }
163 le_precond_local_.resoudre_systeme(la_matrice_locale_,
164 secmem,solution,champ);
165#endif
166}
167
169 const DoubleVect& secmem,
170 DoubleVect& solution,
171 const Champ_Inc_base& champ)
172{
173 exit();
174#if 0
175 if(a_remplir_)
176 {
177 a_remplir_=0;
178 {
179 const Domaine_dis_base& zdisb = champ.domaine_dis_base();
180 const Domaine& domaine = zdisb.domaine();
181 int nb_som = domaine.nb_som();
182 int nb_elem = domaine.nb_elem();
183 int nb_elem_tot = domaine.nb_elem_tot();
184
185 la_matrice_locale_.dimensionner(nb_elem+nb_som,0);
186 int ii,jj;
187 int cpt=0;
188 const IntVect& tab1_tot = mat.tab1_;
189 const IntVect& tab2_tot = mat.tab2_;
190 const DoubleVect& coeff_tot = mat.coeff_;
191 IntVect& tab1_reel = la_matrice_locale_.tab1_;
192 IntVect& tab2_reel = la_matrice_locale_.tab2_;
193 DoubleVect& coeff_reel = la_matrice_locale_.coeff_;
194 tab1_reel(0)=1;
195 for(ii=0; ii<nb_elem; ii++)
196 {
197 int dl = tab1_tot(ii);
198 int fl = tab1_tot(ii+1);
199 for(jj=dl; jj<fl; jj++)
200 {
201 int i_col = tab2_tot(jj-1);
202 if( (i_col<=nb_elem) ||
203 ((i_col>=nb_elem_tot+1) && (i_col<=(nb_elem_tot+nb_som))) )
204 cpt++;
205 }
206 tab1_reel(ii+1)=cpt+1;
207 }
208 for(ii=nb_elem_tot; ii<(nb_elem_tot+nb_som); ii++)
209 {
210 int dl = tab1_tot(ii);
211 int fl = tab1_tot(ii+1);
212 for(jj=dl; jj<fl; jj++)
213 {
214 if(tab2_tot(jj-1)<=(nb_elem_tot+nb_som))
215 cpt++;
216 }
217 tab1_reel((ii-nb_elem_tot)+nb_elem+1)=cpt+1;
218 }
219 la_matrice_locale_.dimensionner(nb_elem+nb_som,tab1_reel(nb_elem+nb_som)-1);
220 cpt=0;
221 for(ii=0; ii<nb_elem; ii++)
222 {
223 int dl = tab1_tot(ii);
224 int fl = tab1_tot(ii+1);
225 for(jj=dl; jj<fl; jj++)
226 {
227 int i_col = tab2_tot(jj-1);
228 if(i_col<=nb_elem)
229 {
230 tab2_reel(cpt)=tab2_tot(jj-1);
231 coeff_reel(cpt++)=coeff_tot(jj-1);
232 }
233 if( (i_col>=nb_elem_tot+1) &&
234 (i_col<=(nb_elem_tot+nb_som)) )
235 {
236 tab2_reel(cpt)=tab2_tot(jj-1)-nb_elem_tot+nb_elem;
237 coeff_reel(cpt++)=coeff_tot(jj-1);
238 }
239 }
240 }
241 for(ii=nb_elem_tot; ii<(nb_elem_tot+nb_som); ii++)
242 {
243 int dl = tab1_tot(ii);
244 int fl = tab1_tot(ii+1);
245 for(jj=dl; jj<fl; jj++)
246 {
247 if(tab2_tot(jj-1)<=(nb_elem_tot+nb_som))
248 {
249 tab2_reel(cpt)=tab2_tot(jj-1)-nb_elem_tot+nb_elem;
250 coeff_reel(cpt++)=coeff_tot(jj-1);
251 }
252 }
253 }
254 la_matrice_locale_.set_est_definie(mat.get_est_definie());
255 {
256 int i,j,k,l;
257
258 const ArrOfInt& items_tot = solution.get_items_communs_tot();
259 for(i=0; i<items_tot.size_array(); i++)
260 {
261 k = items_tot[i]-nb_elem_tot+nb_elem;
262 for(j=tab1_reel[k]+1; j<tab1_reel[k+1]; j++)
263 {
264 coeff_reel(j-1) = 0. ;
265 }
266 // On parcourt les lignes au-dessus pour annuler la colonne k
267 for(j=0; j<k; j++)
268 {
269 for(l=tab1_reel[j]+1; l<tab1_reel[j+1]; l++)
270 {
271 if((tab2_reel[l-1]-1)==k)
272 {
273 coeff_reel(l-1) = 0. ;
274 }
275 }
276 }
277 }
278 }
279 }
280 }
281 VECT(Descripteur)& desc = solution.structure().descripteur();
282 int nb_struct = desc.size();
283 int ind_struct;
284 int taille=0;
285 for(ind_struct=0; ind_struct<nb_struct; ind_struct++)
286 {
287 Descripteur& desci=desc[ind_struct];
288 taille+=desci.nb();
289 }
290 DoubleTab sol_loc(taille);
291 DoubleTab sec_loc(taille);
292 int cpt=0;
293 for(ind_struct=0; ind_struct<nb_struct; ind_struct++)
294 {
295 Descripteur& desci=desc[ind_struct];
296 int i;
297 int deb=desci.deb();
298 int fin=deb+desci.nb();
299 for(i=deb; i<fin; i++)
300 {
301 sol_loc[cpt] = solution[i];
302 sec_loc[cpt] = secmem[i];
303 cpt++;
304 }
305 }
306 le_precond_local_.resoudre_systeme(la_matrice_locale_,
307 sec_loc,sol_loc,champ);
308 cpt=0;
309 for(ind_struct=0; ind_struct<nb_struct; ind_struct++)
310 {
311 Descripteur& desci=desc[ind_struct];
312 int i;
313 int deb=desci.deb();
314 int fin=deb+desci.nb();
315 for(i=deb; i<fin; i++)
316 solution[i]=sol_loc[cpt++];
317 }
318 solution.echange_espace_virtuel();
319#endif
320}
Classe Champ_Inc_base.
int_t nb_som() const
Renvoie le nombre de sommets du domaine.
Definition Domaine.h:121
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
const Domaine & domaine() const
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.
const Matrice & get_bloc(int i, int j) const override
void BlocSymToMatMorseSym(Matrice_Morse_Sym &mat) const
virtual const Matrice & get_bloc(int i, int j) const
Classe Matrice_Morse_Sym Represente une matrice M (creuse) symetrique stockee au format Morse.
DoubleVect coeff_
int get_est_definie() const
Classe Matrice Classe generique de la hierarchie des matrices.
Definition Matrice.h:34
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
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
virtual void prepare_(const Matrice_Base &, const DoubleVect &)
this method must be overloaded if some preparation is necessary.
void prepare_(const Matrice_Base &, const DoubleVect &) override
this method must be overloaded if some preparation is necessary.
Matrice_Morse_Sym la_matrice_locale_
void res_syst_loc_simple(const Matrice_Morse_Sym &mat, const DoubleVect &secmem, DoubleVect &solution, const Champ_Inc_base &champ)
int preconditionner_(const Matrice_Base &, const DoubleVect &, DoubleVect &) override
SolveurSys le_precond_local_
void res_syst_loc_hybride(const Matrice_Morse_Sym &mat, const DoubleVect &secmem, DoubleVect &solution, const Champ_Inc_base &champ)
Matrice_Morse_Sym matrice_de_travail_
int precond(const Matrice_Base &, const DoubleVect &, DoubleVect &)
static bool is_parallel()
Definition Process.cpp:110
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
_SIZE_ size_array() const
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")