TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
SETS.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 SETS_included
17#define SETS_included
18
19#include <Interface_blocs.h>
20#include <Solv_Petsc.h>
21#include <Simpler.h>
22#include <utility>
23#include <vector>
24#include <set>
25
26/*! @brief classe SETS (semi-implicite + etapes de stabilisation, a la TRACE)
27 *
28 * SETS ("Stability-Enhancing Two-Step")
29 *
30 * Ref : J. H. MAHAFFY, "A stability-enhancing two-step method for fluid flow calculations," Journal of Computational Physics, 46, 3, 329 (1982).
31 *
32 * @sa Simpler Piso
33 */
34class SETS: public Simpler
35{
36 Declare_instanciable_sans_constructeur(SETS);
37public:
38 SETS();
39 Entree& lire(const Motcle&, Entree&) override; /* mot-cle "criteres_convergence" */
40 int nb_valeurs_temporelles_pression() const override /* nombres de valeurs temporelles du champ de pression */
41 {
42 return 3; /* autant que les autres variables */
43 }
44
45 bool iterer_eqn(Equation_base& equation, const DoubleTab& inconnue, DoubleTab& result, double dt, int numero_iteration, int& ok) override;
46 void iterer_NS(Equation_base&, DoubleTab& current, DoubleTab& pression, double, Matrice_Morse&, double, DoubleTrav&, int nb_iter, int& converge, int& ok) override;
47
48 /* elimination par blocs d'un systeme lineaire */
49 // entree : ordre -> groupes de (variables, indice de bloc) a eliminer successivement : par ex. { { {"vitesse", 0 } }, { {"alpha", 0 }, {"temperature", 0 } } }
50 // inco_p -> nom de l'inconnue principale (ex. : "pression")
51 // mats, sec : matrices / seconds membres du systeme lineaire mats.d{incos} = {secs}
52 //
53 //
54 // sortie : A_p / b_p t.q. d{inco} = A_p.d{inco_p} + b_p
55 // valeur retour -> 1 si eliminsation reussie, 0 si singularite rencontree
56 // contraintes : - les inconnues du meme bloc doivent partager un meme MD_Vector
57 // - pour chaque bloc { i_1, i_2 }, la matrice { mats[i_j][i_k] } doit etre diagonale par blocs par rapport a ce MD_Vector
58 // - hors cette diagonale, les inconnues d'un blocs ne peuvent dependre que des blocs precedents et de inco_p
59 static int eliminer(const std::vector<std::set<std::pair<std::string, int>>> ordre, const std::string inco_p, const std::map<std::string, matrices_t>& mats, const ptabs_t& sec,
60 std::map<std::string, Matrice_Morse>& A_p, tabs_t& b_p);
61
62 /* assemblage d'un systeme en inco_p a partir des expressions d.{inco} : A_p[inco].d{inco_p} + b_p[inco] */
63 //entree : - inco_p -> l'inconnue principale
64 // - A_p, b_p -> expressions des autres inconnues calculees par eliminer()
65 // - mats, sec -> systeme lineaire contenant une equation sur inco_p (second membre dans sec[inco_p], jacobienne dans mats[inco_p])
66 //
67 //sortie : systeme matrice.d{inco_p} = secmem
68 //
69 //contraintes : toutes les autres inconnues doivent etre exprimees dans A_p / b_p
70 static void assembler(const std::string inco_p, const std::map<std::string, Matrice_Morse>& A_p, const tabs_t& b_p, const std::map<std::string, matrices_t>& mats, const ptabs_t& sec,
71 Matrice_Morse& matrice, DoubleTab& secmem, int p_degen);
72
73 double get_default_growth_factor() const override /* taux de croissance du pas de temps */
74 {
75 return 1.2; /* en cas de pas de temps rate, on remonte doucement */
76 }
77
78 int iteration_ = 0; //numero de l'iteration en cours (pour les operateurs d'evanescence)
79 int p_degen_ = -1; //1 si la pression est degeneree (milieu incompressible + pas de CLs de pression imposee)
80 int sets_; // 1 si on fait l'etape de prediction des vitesses
81
82 double unknown_positivation(const DoubleTab& uk, DoubleTab& incr); // brings to 0 unknowns that should stay positive
83
84#ifdef PETSCKSP_H
85 /* contexte pour le test de convergence */
86 struct cv_test_t
87 {
88 void *defctx; //contexte du test de convergence standard
89 SETS *obj; //l'objet
90 double eps_alpha; //critere de convergence en alpha
91 Vec t, v; //vecteurs Petsc
92 };
93 DoubleVect norm, residu; //chaque ligne vaut norm * sum alpha, espace pour le residu
94 ArrOfTID ix; //indices pour recuperer le residu
95 cv_test_t *cv_ctx = nullptr;
96 void init_cv_ctx(const DoubleTab& secmem, const DoubleVect& norm);
97#if PETSC_VERSION_GE(3,24,0)
98 static PetscErrorCode destroy_cvctx(void **mctx);
99#else
100 static PetscErrorCode destroy_cvctx(void *mctx);
101#endif
102 static PetscErrorCode convergence_test(KSP ksp, PetscInt it, PetscReal rnorm, KSPConvergedReason *reason,void *mctx);
103#endif
104
106 {
108 }
109
110protected:
111
112 int iter_min_ = 1, iter_max_ = 10; //nombre d'iterations min/max de l'etape non-lineaire
113 int first_call_ = 1; //au tout premier appel, P peut etre tres mauvais -> on ne predit pas v en SETS
114 int pressure_reduction_ = 1; //fait-on la reduction en pression?
115
116 /* criteres de convergences par inconnue (en norme Linf), modifiables par le mot-cle "criteres_convergence" */
117 std::map<std::string, double> crit_conv_;
118
119 /* matrices de la resolution semi-implicite */
120 std::map<std::string, matrices_t> mats_; // matrices : mats[nom de l'inconnue de l'equation][nom de l'autre inconnue] = matrice
121 Matrice_Bloc mat_semi_impl_; //pour stocker les matrices de mats
122 MD_Vector mdv_semi_impl_; //MD_Vector associe
123 std::map<std::string, Matrice_Morse> mat_pred_; //matrices de prediction
124
125 /* elimination en pression dv = A_p[nom de la variable]. dp + b_p[nom de la variable] */
126 std::map<std::string, Matrice_Morse> A_p_;
127
128 /* matrice en pression */
130
131 /* Newton out file */
132 bool header_written_ = false;
133 std::vector<double> incr_var_convergence_;
134};
135
136/*! @brief classe ICE (semi-implicte ICE, a la CATHARE 3D)
137 *
138 * @sa SETS
139 */
140class ICE: public SETS
141{
142 Declare_instanciable(ICE);
143public:
144 bool est_compatible_avec_th_mono() const override /* ce solveur est-il compatible avec une resolution monolithique de la thermique ? */
145 {
146 return 0; /* non: ICE est explicite en la thermique */
147 }
148 double get_default_facsec_max() const override /* facsec_max recommande */
149 {
150 return 1; /* SETS est semi-implicite */
151 }
152};
153
154#endif /* SETS_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
classe ICE (semi-implicte ICE, a la CATHARE 3D)
Definition SETS.h:141
double get_default_facsec_max() const override
Definition SETS.h:148
bool est_compatible_avec_th_mono() const override
Definition SETS.h:144
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
Definition MD_Vector.h:48
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
int sets_
Definition SETS.h:80
Entree & lire(const Motcle &, Entree &) override
Definition SETS.cpp:108
Matrice_Bloc mat_semi_impl_
Definition SETS.h:121
SETS()
Definition SETS.cpp:81
int pressure_reduction_
Definition SETS.h:114
double facsec_diffusion_for_sets() const
Definition SETS.h:105
int p_degen_
Definition SETS.h:79
std::map< std::string, Matrice_Morse > A_p_
Definition SETS.h:126
MD_Vector mdv_semi_impl_
Definition SETS.h:122
int iter_min_
Definition SETS.h:112
static int eliminer(const std::vector< std::set< std::pair< std::string, int > > > ordre, const std::string inco_p, const std::map< std::string, matrices_t > &mats, const ptabs_t &sec, std::map< std::string, Matrice_Morse > &A_p, tabs_t &b_p)
Definition SETS.cpp:695
void iterer_NS(Equation_base &, DoubleTab &current, DoubleTab &pression, double, Matrice_Morse &, double, DoubleTrav &, int nb_iter, int &converge, int &ok) override
Definition SETS.cpp:366
double unknown_positivation(const DoubleTab &uk, DoubleTab &incr)
Definition SETS.cpp:189
std::map< std::string, double > crit_conv_
Definition SETS.h:117
double get_default_growth_factor() const override
Definition SETS.h:73
static void assembler(const std::string inco_p, const std::map< std::string, Matrice_Morse > &A_p, const tabs_t &b_p, const std::map< std::string, matrices_t > &mats, const ptabs_t &sec, Matrice_Morse &matrice, DoubleTab &secmem, int p_degen)
Definition SETS.cpp:1001
int iteration_
Definition SETS.h:78
bool header_written_
Definition SETS.h:132
std::map< std::string, matrices_t > mats_
Definition SETS.h:120
int first_call_
Definition SETS.h:113
std::vector< double > incr_var_convergence_
Definition SETS.h:133
std::map< std::string, Matrice_Morse > mat_pred_
Definition SETS.h:123
int nb_valeurs_temporelles_pression() const override
Definition SETS.h:40
Matrice_Morse matrice_pression_
Definition SETS.h:129
bool iterer_eqn(Equation_base &equation, const DoubleTab &inconnue, DoubleTab &result, double dt, int numero_iteration, int &ok) override
Definition SETS.cpp:286
int iter_max_
Definition SETS.h:112
double facsec_diffusion_for_sets_