TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Probleme_base_interface_proto.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 <Probleme_base_interface_proto.h>
17#include <Domaine_Cl_dis_base.h>
18#include <ICoCoExceptions.h>
19#include <Probleme_base.h>
20#include <Postraitement.h>
21#include <Equation_base.h>
22#include <Debog.h>
23
24using ICoCo::WrongArgument;
25using ICoCo::WrongContext;
26
28{
29 if (initialized)
30 throw WrongContext(pb.le_nom().getChar(), "initialize", "initialize should not have been called");
31
33 pb.preparer_calcul();
34 pb.domaine().initialiser(0, pb.domaine_dis(), pb); // Pour le cas de geometries variables (ex. ALE)
35 // on initialise le schema en temps avant le postraitement
36 // ainsi les sources qui dependent du pas de temps fonctionnent
39
40 initialized = true;
41}
42
44{
45 if (!initialized)
46 throw WrongContext(pb.le_nom().getChar(), "presentTime", "initialize should have been called");
47 if (terminated)
48 throw WrongContext(pb.le_nom().getChar(), "presentTime", "terminate should not have been called");
49
51 return pb.schema_temps().temps_courant();
52}
53
55{
56 if (!initialized)
57 throw WrongContext(pb.le_nom().getChar(), "initTimeStep", "initialize should have been called");
58 if (terminated)
59 throw WrongContext(pb.le_nom().getChar(), "initTimeStep", "terminate should not have been called");
60 if (dt_defined)
61 throw WrongContext(pb.le_nom().getChar(), "initTimeStep", "initTimeStep should not have been called");
62 if (dt <= 0)
63 throw WrongArgument(pb.le_nom().getChar(), "initTimeStep", "dt", "dt should be a positive real number");
64
66
67 bool ok = pb.schema_temps().initTimeStep(dt);
68 pb.domaine().set_dt(dt);
69 pb.milieu().initTimeStep(dt);
70 for (int i = 0; i < pb.nombre_d_equations(); i++)
71 ok = ok && pb.equation(i).initTimeStep(dt);
72
73 // Calculs coeffs echange sur l'instant sur lequel doivent agir les operateurs.
74 double tps = pb.schema_temps().temps_defaut();
75 for (int i = 0; i < pb.nombre_d_equations(); i++)
77
78 dt_validated = false;
79 dt_defined = true;
80 return ok;
81}
82
84{
85 if (!dt_defined)
86 throw WrongContext(pb.le_nom().getChar(), "solveTimeStep", "initTimeStep should have been called");
87
89
90 bool ok = pb.solveTimeStep_pbU(); // call mother's method
91
92 // Calculs coeffs echange sur l'instant sur lequel doivent agir les operateurs.
93 double tps = pb.schema_temps().temps_defaut();
94 for (int i = 0; i < pb.nombre_d_equations(); i++)
96
97 return ok;
98}
99
101{
102 if (!dt_defined)
103 throw WrongContext(pb.le_nom().getChar(), "iterateTimeStep", "initTimeStep should have been called");
104
105 // Update the domain
106 if(pb.domaine().getUpdateTheGrid())
107 {
109 pb.domaine().setUpdateTheGrid(false);
110 }
111
113 bool ok = pb.schema_temps().iterateTimeStep(converged);
114
115 // Calculs coeffs echange sur l'instant sur lequel doivent agir les operateurs.
116 double tps = pb.schema_temps().temps_defaut();
117 for (int i = 0; i < pb.nombre_d_equations(); i++)
119
120 return ok;
121}
122
124{
125 if (!dt_defined)
126 throw WrongContext(pb.le_nom().getChar(), "validateTimeStep", "initTimeStep should have been called");
127
131 pb.allocation();
132
133 dt_defined = false;
134 dt_validated = true;
135}
136
138{
139 if (!initialized)
140 throw WrongContext(pb.le_nom().getChar(), "terminate", "initialize should have been called");
141 if (terminated)
142 throw WrongContext(pb.le_nom().getChar(), "terminate", "terminate should not have been called");
143 if (dt_defined)
144 throw WrongContext(pb.le_nom().getChar(), "terminate", "time step should be validated or aborted first");
145
147 pb.finir();
148 pb.schema_temps().terminate();
149
150 terminated = true;
151}
152
154{
155 if (!initialized)
156 throw WrongContext(pb.le_nom().getChar(), "computeTimeStep", "initialize should have been called");
157 if (terminated)
158 throw WrongContext(pb.le_nom().getChar(), "computeTimeStep", "terminate should not have been called");
159
161 double dt = pb.schema_temps().computeTimeStep(stop);
162 return dt;
163}
164
166{
167 if (!dt_validated)
168 throw WrongContext(pb.le_nom().getChar(), "isStationary", "validateTimeStep should have been called");
169 if (terminated)
170 throw WrongContext(pb.le_nom().getChar(), "isStationary", "terminate should not have been called");
171
172 return pb.schema_temps().isStationary();
173}
174
176{
177 if (!dt_defined)
178 throw WrongContext(pb.le_nom().getChar(), "abortTimeStep", "initTimeStep should have been called");
179
181 pb.milieu().abortTimeStep();
182 dt_defined = false;
183}
184
185void Probleme_base_interface_proto::resetTimeWithDir_impl(Probleme_base& pb, double time, const std::string dirname)
186{
187 if (dt_defined)
188 throw WrongContext(pb.le_nom().getChar(), "resetTime", "resetTime can not be called inside a time step computation");
189 if (!initialized || terminated)
190 throw WrongContext(pb.le_nom().getChar(), "resetTime", "resetTime can not be called before initialize or after terminate");
191
192 bool managePostTreatments=true; // This is the default
193 if (pb.checkOutputIntEntry("skipPostTreatmentDuringReset"))
194 {
195 int val=pb.getOutputIntValue("skipPostTreatmentDuringReset");
196 if (val == 1) managePostTreatments=false;
197 }
198
199 // We postreat once before reseting:
200 if (!managePostTreatments) Cerr << pb.que_suis_je() << ": skip post-treatments in resetTime" << finl ;
201 if (managePostTreatments) pb.postraiter(true);
202
203 // Possible to create a new directory:
204 if (!dirname.empty())
205 {
206 pb.terminate(); // Close properly the problem and the output files
207 terminated = false;
208 Sortie_Fichier_base::set_root(dirname); // Create a new directory
209 pb.schema_temps().initialize(); // Initialize the time scheme (.dt_ev file)
210 }
211
212 // [ABN] Warning: when dealing with input data (like Champ_Don), resetTime() can be mapped to 'mettre_a_jour()' (we really
213 // want the input data at the given time)
214 // But when dealing with unknown fields, or computation variables, we must force the time to take the imposed value.
215 // See the various child impl. of resetTime() in the various objects below:
216 pb.schema_temps().resetTime(time);
217 pb.milieu().resetTime(time);
218
219 for (int i = 0; i < pb.nombre_d_equations(); i++)
220 pb.equation(i).resetTime(time); // will also reset fields there
221
222 if (managePostTreatments)
223 {
224 // Trigger the change of basename for the output files, and the reinit of the post:
225 pb.postraitements().resetTime(time, dirname);
227
228 // We postreat after reset:
229 pb.postraiter(true);
230 }
231}
232
234{
236 bool ok = true;
237 for (int i = 0; i < pb.nombre_d_equations(); i++)
238 ok = ok && pb.equation(i).updateGivenFields();
239 return ok;
240}
241
242// Adds the input fields names this pb understands to noms
244{
245 int n = input_fields.size();
246 Noms nouveaux_noms(n);
247 for (int i = 0; i < n; i++)
248 nouveaux_noms[i] = input_fields[i]->le_nom();
249 // GF pour contourner un bug dans add() si vecteur null
250 if (n)
251 noms.add(nouveaux_noms);
252}
253
254// Adds the input fields names this pb understands to noms
256{
257 for (int i = 0; i < pb.postraitements().size(); i++)
258 {
259 if (sub_type(Postraitement, pb.postraitements()(i).valeur()))
260 {
261 const Liste_Champ_Generique& liste_champ = ref_cast(Postraitement,pb.postraitements()(i).valeur()).champs_post_complet();
262 for (int ii = 0; ii < liste_champ.size(); ii++)
263 noms.add(liste_champ(ii)->get_nom_post());
264 }
265 }
266}
267
268OBS_PTR(Field_base) Probleme_base_interface_proto::findInputField_impl(const Probleme_base& pb, const Nom& name) const
269{
270 // WEC : there should be a better way to scan the list
271 for (int i = 0; i < input_fields.size(); i++)
272 if (input_fields[i]->le_nom() == name) return input_fields[i];
273
275 return ch;
276}
277
278OBS_PTR(Champ_Generique_base) Probleme_base_interface_proto::findOutputField_impl(const Probleme_base& pb, const Nom& name) const
279{
280 OBS_PTR(Champ_Generique_base) ch;
281 if (pb.comprend_champ_post(name)) ch = pb.get_champ_post(name);
282 return ch;
283}
284
286{
287 const Nom& name = f.le_nom();
288 for (int i = 0; i < input_fields.size(); i++)
289 {
290 if (input_fields[i]->le_nom() == name)
291 throw WrongContext(name.getChar(), "addInputField", "Field with this name is already in list");
292 }
293 input_fields.add(f);
294}
295
297{
298 if (!dt_defined)
299 throw WrongContext(pb.le_nom().getChar(), "futureTime", "initTimeStep should have been called");
300 int i = pb.schema_temps().nb_valeurs_futures();
301 return pb.schema_temps().temps_futur(i);
302}
303
class Champ_Generique_base
static void set_nom_pb_actuel(const Nom &nom)
Definition Debog.cpp:44
virtual int calculer_coeffs_echange(double temps)
Calcul des coefficients d'echange pour les problemes couples thermiques.
virtual void mettre_a_jour(double temps, Domaine_dis_base &, Probleme_base &)
virtual void initialiser(double temps, Domaine_dis_base &, Probleme_base &)
virtual void setUpdateTheGrid(bool)
virtual void validateTimeStep()
virtual bool getUpdateTheGrid()
virtual void set_dt(double &dt_)
virtual bool updateGivenFields()
virtual Domaine_Cl_dis_base & domaine_Cl_dis()
Renvoie le domaine des conditions aux limite discretisee associee a l'equation.
virtual bool initTimeStep(double dt)
Allocation et initialisation de l'inconnue et des CLs jusqu'a present+dt.
virtual void resetTime(double time)
Reset current time of the equation. Used from ICoCo. See documentation of Problem_base::resetTime().
const Nom & le_nom() const override
Renvoie le nom du champ.
classe List_Champ_Generique Represente une liste de Champ_Generique_base
virtual void resetTime(double time)
virtual void abortTimeStep()
virtual bool initTimeStep(double dt)
Definition Milieu_base.h:85
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const char * getChar() const
Definition Nom.h:91
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
classe Postraitement La classe est dotee -d une liste de champs generiques champs_post_complet_ qui c...
void resetTime(double t, const std::string dirname)
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Probleme_U.h:109
virtual bool checkOutputIntEntry(const Nom &name) const
virtual int getOutputIntValue(const Nom &name) const
void getInputFieldsNames_impl(const Probleme_base &pb, Noms &noms) const
void getOutputFieldsNames_impl(const Probleme_base &pb, Noms &noms) const
bool initTimeStep_impl(Probleme_base &pb, double dt)
bool iterateTimeStep_impl(Probleme_base &pb, bool &converged)
double futureTime_impl(const Probleme_base &pb) const
void resetTimeWithDir_impl(Probleme_base &pb, double time, std::string direname)
double presentTime_impl(const Probleme_base &pb) const
bool isStationary_impl(const Probleme_base &pb) const
double computeTimeStep_impl(const Probleme_base &pb, bool &stop) const
OBS_PTR(Field_base) findInputField_impl(const Probleme_base &pb
void addInputField_impl(Probleme_base &pb, Field_base &f)
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
int postraiter(int force=1) override
Si force=1, effectue le postraitement sans tenir compte des frequences de postraitement.
const Domaine & domaine() const
Renvoie le domaine associe au probleme.
virtual void preparer_calcul()
Prepare le calcul: initialise les parametres du milieu et prepare le calcul de chacune des equations.
void init_postraitements()
Flag le premier et le dernier postraitement pour chaque fichier Et initialise les postraitements.
Postraitements & postraitements()
virtual int comprend_champ_post(const Motcle &nom) const
virtual void allocation() const final
Verifie que la place necessaire existe sur le disque dur.
virtual void finir()
Finit le postraitement et sauve le probleme dans un fichier.
virtual const Champ_Generique_base & get_champ_post(const Motcle &nom) const
virtual const Milieu_base & milieu() const
Renvoie le milieu physique associe au probleme.
const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe au probleme.
void terminate() override
This method is called once at the end, after any other one.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
const Domaine_dis_base & domaine_dis() const
Renvoie le domaine discretise associe au probleme.
bool solveTimeStep_pbU()
virtual double computeTimeStep(bool &stop) const
virtual bool isStationary() const
Retourne 1 si lors du dernier pas de temps, le probleme n'a pas evolue.
double temps_courant() const
Renvoie le temps courant.
virtual void resetTime(double time)
virtual double temps_futur(int i) const =0
virtual void abortTimeStep()
virtual void validateTimeStep()
virtual void initialize()
virtual bool initTimeStep(double dt)
virtual int nb_valeurs_futures() const =0
virtual bool iterateTimeStep(bool &converged)
Calculate the U(n+1) unknown for each equation (if solved) of the problem with the selected time sche...
virtual double temps_defaut() const =0
static void set_root(const std::string dirname)