TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Solveur_Implicite_base.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 <Solveur_Implicite_base.h>
17#include <Probleme_base.h>
18#include <SChaine.h>
19#include <EChaine.h>
20
21Implemente_base(Solveur_Implicite_base, "Solveur_Implicite_base", Objet_U);
22// XD solveur_implicite_base objet_u solveur_implicite_base INHERITS_BRACE not_set
23
24Sortie& Solveur_Implicite_base::printOn(Sortie& os) const { return os; }
25
27{
28 int is_seuil_resol_lu = 0;
29 double seuil_convergence_solveur_prov = -1.;
30 Motcle accferme = "}";
31 Motcle accouverte = "{";
32 int le_solveur_est_lu = 0;
33 Motcle motlu;
34 is >> motlu;
35 if (motlu != accouverte) Process::exit("We are waiting a { !");
36 Nom le_solveur_lu_;
37 is >> motlu;
38 while (motlu != accferme)
39 {
40 if (motlu == "max_iter_implicite")
41 {
42 Cerr << motlu << finl;
43 Cerr << motlu << " is no more longer understood by Simpler but by the time scheme" << finl;
45 }
46 else if (motlu == "seuil_convergence_implicite")
47 {
48 Cerr << motlu << finl;
49 is >> param_defaut_.seuil_convergence_implicite();
50 }
51 else if (motlu == "seuil_generation_solveur")
52 {
53 Cerr << motlu << finl;
54 is_seuil_resol_lu = 1;
55 is >> param_defaut_.seuil_generation_solveur();
56 }
57 else if (motlu == "seuil_verification_solveur")
58 {
59 Cerr << motlu << finl;
60 is >> param_defaut_.seuil_verification_solveur();
61 }
62 else if (motlu == "seuil_test_preliminaire_solveur")
63 {
64 Cerr << motlu << finl;
65 is >> param_defaut_.seuil_test_preliminaire_solveur();
66 }
67 else if (motlu == "seuil_convergence_solveur")
68 {
69 Cerr << motlu << finl;
70 is_seuil_resol_lu = 1;
71 is >> seuil_convergence_solveur_prov;
72 }
73 else if (motlu == "nb_it_max")
74 {
75 is >> param_defaut_.nb_it_max();
76 }
77 else if (motlu == "seuil_convergence_variable")
78 {
79 Cerr << "Option seuil_convergence_variable is not yet understood." << finl;
81 Cerr << motlu << finl;
82 facteur_convg_ = 100;
84 }
85 else if (motlu == "controle_residu")
86 {
88 }
89 else if (motlu == "solveur")
90 {
91 le_solveur_est_lu = 1;
92 SChaine toto;
93 // redefine motlu to preserve lowercase/uppercase
94 Nom motlubis;
95 int nb_acc = 0;
96 int ok = 0;
97 while (nb_acc != 0 || !ok)
98 {
99 is >> motlubis;
100 toto << " " << motlubis;
101 if (motlubis == "}") nb_acc--;
102 else if (motlubis == "{")
103 {
104 ok = 1;
105 nb_acc++;
106 }
107 }
108 le_solveur_lu_ = Nom(toto.get_str());
109 }
110 else
111 {
112 lire(motlu, is);
113 }
114 is >> motlu;
115 }
116
117 if (seuil_convergence_solveur_prov > 0)
118 {
119 param_defaut_.set_seuil_solveur_avec_seuil_convergence_solveur(seuil_convergence_solveur_prov);
120 }
121 if ((is_seuil_resol_lu == 0) && (le_solveur_est_lu == 0))
122 {
123 Cerr << "Neither the solving object nor the threshold seuil_convergence_solveur has been indicated." << finl;
124 Cerr << "At least one of them (or both) must be specified." << finl;
126 }
127
128 if (param_defaut_.seuil_convergence_implicite() < 0)
129 param_defaut_.seuil_convergence_implicite() = DMAXFLOAT;
130
131 if (param_defaut_.seuil_verification_solveur() < 0)
132 param_defaut_.seuil_verification_solveur() = DMAXFLOAT;
133 // on laisse seuil_test_preliminaire <0
134
135 if (le_solveur_est_lu == 0)
136 {
137 SChaine toto;
138 toto << "Gmres { diag seuil " << param_defaut_.seuil_generation_solveur()
139 << " nb_it_max " << param_defaut_.nb_it_max()
140 << " controle_residu " << get_controle_residu() << " } " << finl;
141 le_solveur_lu_ = Nom(toto.get_str());
142 }
143
144 {
145 EChaine titi(le_solveur_lu_);
146 titi >> param_defaut_.solveur();
147 }
148 param_defaut_.solveur().nommer("solveur_implicite");
149 return is;
150}
151
152bool Solveur_Implicite_base::iterer_eqs(LIST(OBS_PTR(Equation_base)) eqs, int n, int& ok)
153{
154 Process::exit("Iterer_eqs not coded");
155 return false;
156}
157
159{
160 Cerr << "Keyword : " << motlu << " is not undertood in " << que_suis_je() << finl;
162 return is;
163}
164
165/*! @brief Returns the implicit parameter of the equation if it exists, creates it if it does not.
166 *
167 * .. if the parameters are empty, copies those from the simpler solver.
168 *
169 */
170OWN_PTR(Parametre_equation_base)& Solveur_Implicite_base::get_and_set_parametre_equation(Equation_base& eqn)
171{
172 OWN_PTR(Parametre_equation_base)& param = eqn.parametre_equation();
173 if (!param)
174 {
175 param.typer("Parametre_implicite");
176 }
177 if (!sub_type(Parametre_implicite,param.valeur()))
178 {
179 Cerr<<eqn.que_suis_je()<<" has parameters of type "<<param.que_suis_je()<<" not coherent with "<<que_suis_je()<<finl;
180 exit();
181 }
182
183 Parametre_implicite& param_impl = ref_cast(Parametre_implicite,param.valeur());
184 // check if there are default values to copy
185 if (param_impl.seuil_convergence_implicite()<0)
186 param_impl.seuil_convergence_implicite() = param_defaut_.seuil_convergence_implicite();
187 if (param_impl.seuil_verification_solveur()<0)
188 param_impl.seuil_verification_solveur() = param_defaut_.seuil_verification_solveur();
189 if (param_impl.seuil_test_preliminaire_lu()==0)
190 param_impl.seuil_test_preliminaire_solveur() = param_defaut_.seuil_test_preliminaire_solveur();
191 if (!param_impl.solveur())
192 param_impl.solveur() = param_defaut_.solveur();
193
194 // Some checks:
195 if (eqn.probleme().is_coupled())
196 {
197 if (param_impl.seuil_convergence_implicite()>0.1*DMAXFLOAT)
198 {
199 Cerr << finl << "Error!" << finl;
200 Cerr << "seuil_convergence_implicite option should be defined in your time scheme." << finl;
201 Cerr << "It is a mandatory option for a calculation with coupled problems." << finl;
202 exit();
203 }
204 }
205 /*
206 else if (param_impl.seuil_convergence_implicite()<0.1*DMAXFLOAT)
207 {
208 Cerr << finl << "Error!" << finl;
209 Cerr << "seuil_convergence_implicite option should be NOT be defined in your time scheme" << finl;
210 Cerr << "during calculation of a single problem." << finl;
211 Cerr << "Remove the option." << finl;
212 exit();
213 } */
214 return param;
215}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
Probleme_base & probleme()
Returns the problem associated with the equation.
A character string (Nom) in uppercase.
Definition Motcle.h:26
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
friend class Entree
Definition Objet_U.h:71
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Parametre_equation_base A Parametre_equation_base object groups the various.
double & seuil_verification_solveur()
int seuil_test_preliminaire_lu() const
double & seuil_convergence_implicite()
double & seuil_test_preliminaire_solveur()
bool is_coupled() const
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
const char * get_str() const
returns a copy of the string stored by the SChaine
Definition SChaine.cpp:72
virtual int get_controle_residu() const
virtual Entree & lire(const Motcle &, Entree &)
virtual OWN_PTR(Parametre_equation_base) &get_and_set_parametre_equation(Equation_base &)
virtual bool iterer_eqs(LIST(OBS_PTR(Equation_base)) eqs, int n, int &ok)
Parametre_implicite param_defaut_
Base class for output streams.
Definition Sortie.h:52