TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Modele_turbulence_scal_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 <Modele_turbulence_scal_base.h>
17#include <Modele_turbulence_hyd_base.h>
18#include <EcritureLectureSpecial.h>
19#include <Convection_Diffusion_std.h>
20#include <Discretisation_base.h>
21#include <Probleme_base.h>
22#include <Domaine.h>
23#include <Param.h>
24
25Implemente_base(Modele_turbulence_scal_base, "Modele_turbulence_scal_base", Objet_U);
26// XD turbulence_paroi_scalaire_base objet_u turbulence_paroi_scalaire_base INHERITS_BRACE Basic class for wall laws for
27// XD_CONT energy equation.
28
29// XD modele_turbulence_scal_base objet_u modele_turbulence_scal_base INHERITS_BRACE Basic class for turbulence model
30// XD_CONT for energy equation.
31
33{
34 return s << que_suis_je() << " " << le_nom();
35}
36
38{
39 Cerr << "Reading of data for a " << que_suis_je() << " scalar turbulence model" << finl;
40 Param param(que_suis_je());
41 Motcle mot = "turbulence_paroi";
42 set_param(param);
43 param.lire_avec_accolades_depuis(is);
44 const Probleme_base& le_pb = mon_equation_->probleme();
45 // lp wall law of the hydraulic turbulence model
46 const RefObjU& modele_turbulence = le_pb.equation(0).get_modele(TURBULENCE);
47 const Modele_turbulence_hyd_base& mod_turb_hydr = ref_cast(Modele_turbulence_hyd_base, modele_turbulence.valeur());
48 if (!loipar_ && mod_turb_hydr.has_loi_paroi_hyd())
49 {
50 Cerr << finl;
51 Cerr << "Keyword " << mot << " not found!" << finl;
52 Cerr << "A wall law must be read in the turbulence model for a scalar." << finl;
53 Cerr << finl;
54 exit();
55 }
56 return is;
57}
58
60{
61 param.ajouter("dt_impr_nusselt", &dt_impr_nusselt_); // XD_ADD_P floattant
62 // XD_CONT Keyword to print local values of Nusselt number and temperature near a wall during a turbulent calculation.
63 // XD_CONT The values will be printed in the _Nusselt.face file each dt_impr_nusselt time period. The local Nusselt
64 // XD_CONT expression is as follows : Nu = ((lambda+lambda_t)/lambda)*d_wall/d_eq where d_wall is the distance from
65 // XD_CONT the first mesh to the wall and d_eq is given by the wall law. This option also gives the value of d_eq and
66 // XD_CONT h = (lambda+lambda_t)/d_eq and the fluid temperature of the first mesh near the wall. NL2 For the Neumann
67 // XD_CONT boundary conditions (flux_impose), the <<equivalent>> wall temperature given by the wall law is also
68 // XD_CONT printed (Tparoi equiv.) preceded for VEF calculation by the edge temperature <<T face de bord>>.
69 param.ajouter_non_std("dt_impr_nusselt_mean_only", (this)); // XD attr dt_impr_nusselt_mean_only dt_impr_nusselt_mean_only dt_impr_nusselt_mean_only OPT This keyword is used to print the mean values of Nusselt ( obtained with the wall laws) on each boundary, into a file named datafile_ProblemName_nusselt_mean_only.out. periode refers to the printing period, this value is expressed in seconds. If you don\'t use the optional keyword boundaries, all the boundaries will be considered. If you use it, you must specify nb_boundaries which is the number of boundaries on which you want to calculate the mean values, then you have to specify their names.
70 param.ajouter_non_std("turbulence_paroi", this); // XD_ADD_P turbulence_paroi_scalaire_base
71 // XD_CONT Keyword to set the wall law.
72}
74{
75 Motcle motlu;
76 int retval = 1;
77 if (mot == "turbulence_paroi")
78 {
80 is >> loipar_.valeur();
81 }
82 else if (mot == "dt_impr_nusselt_mean_only")
83 {
84 if (loipar_->que_suis_je().contient("negligeable"))
85 Process::exit("Please remove dt_impr_nusselt option if the wall law is of Negligeable type.");
86 // XD dt_impr_nusselt_mean_only objet_lecture nul BRACE not_set
87 // XD attr dt_impr floattant dt_impr REQ not_set
88 // XD attr boundaries listchaine boundaries OPT not_set
89 Nom accolade_ouverte = "{";
90 Nom accolade_fermee = "}";
91 nom_fichier_ = Objet_U::nom_du_cas() + "_" + equation().probleme().le_nom() + "_nusselt_mean_only";
92 Domaine& dom = equation().probleme().domaine();
93 LIST(Nom) nlistbord_dom; //!< list storing all boundary names of the domain
94 int nbfr = dom.nb_front_Cl();
95 for (int b = 0; b < nbfr; b++)
96 {
97 Frontiere& org = dom.frontiere(b);
98 nlistbord_dom.add(org.le_nom());
99 }
100 is >> motlu;
101 if (motlu != accolade_ouverte)
102 {
103 Cerr << motlu << " is not a keyword understood by " << que_suis_je() << " in lire_motcle_non_standard" << finl;
104 Cerr << "A specification of kind : dt_impr_nusselt_mean_only { dt_impr periode [boundaries nb_boundaries boundary_name1 boundary_name2 ... ] } was expected." << finl;
105 exit();
106 }
107 is >> motlu;
108 if (motlu != "dt_impr")
109 {
110 Cerr << "We expected dt_impr..." << finl;
111 exit();
112 }
114
115 is >> motlu; // boundaries ou accolade_fermee ou pasbon
116 if (motlu != accolade_fermee)
117 {
118 if (motlu == "boundaries")
119 {
120 boundaries_ = 1;
121 int nb_bords = 0;
122 Nom nom_bord_lu;
123
124 // read boundaries number
125 is >> nb_bords;
126 if (nb_bords != 0)
127 {
128 // read boundaries
129 for (int i = 0; i < nb_bords; i++)
130 {
131 is >> nom_bord_lu;
132 boundaries_list_.add(Nom(nom_bord_lu));
133 // check boundary names
134 if (!nlistbord_dom.contient(boundaries_list_[i]))
135 {
136 Cerr << "Problem in the dt_impr_nusselt_mean_only instruction:" << finl;
137 Cerr << "The boundary named '" << boundaries_list_[i] << "' is not a boundary of the domain " << dom.le_nom() << "." << finl;
138 exit();
139 }
140 }
141 }
142 // read closing brace
143 is >> motlu;
144 if (motlu != accolade_fermee)
145 {
146 Cerr << "Problem in the dt_impr_nusselt_mean_only instruction:" << finl;
147 Cerr << "TRUST wants to read a '" << accolade_fermee << "' but find '" << motlu << "'!!" << finl;
148 exit();
149 }
150 }
151 else
152 {
153 Cerr << motlu << " is not a keyword understood by " << que_suis_je() << " in lire_motcle_non_standard" << finl;
154 Cerr << "A specification of kind : dt_impr_nusselt_mean_only { dt_impr periode [boundaries nb_boundaries boundary_name1 boundary_name2 ... ] } was expected." << finl;
155 exit();
156 }
157 }
158 } // fin dt_impr_nusselt_mean_only
159 else
160 retval = -1;
161 return retval;
162}
163
164/*! @brief Associates the equation passed as parameter to the turbulence model.
165 *
166 * The equation is cast to Convection_Diffusion_std.
167 *
168 * @param eqn The equation to associate with this object.
169 */
171{
172 mon_equation_ = ref_cast(Convection_Diffusion_std, eqn);
173}
174
175/*! @brief Does nothing.
176 *
177 * @param Discretized domain (unused).
178 * @param Discretized boundary conditions domain (unused).
179 */
184
185/*! @brief Discretizes the turbulence model.
186 *
187 */
189{
190 Cerr << "Turbulence scalar model discretization" << finl;
191 const Schema_Temps_base& sch = mon_equation_->schema_temps();
192 const Discretisation_base& dis = mon_equation_->discretisation();
193 const Domaine_dis_base& z = mon_equation_->domaine_dis();
194 dis.discretiser_champ("champ_elem", z, "diffusivite_turbulente", "m2/s", 1, sch.temps_courant(), diffusivite_turbulente_);
195 dis.discretiser_champ("champ_elem", z, "conductivite_turbulente", "W/m/K", 1, sch.temps_courant(), conductivite_turbulente_);
197}
198
199/*! @brief Completes the turbulence model: updates object references.
200 *
201 */
205
206/*! @brief To be overridden in derived classes that own one or more equations. Calls preparer_pas_de_temps on those equations.
207 *
208 * @param dt Time step.
209 * @return True if successful.
210 */
212{
213 return true;
214}
215
216/*! @brief Does nothing.
217 *
218 * @return Always returns 1.
219 */
221{
222 if (loipar_)
223 loipar_->init_lois_paroi();
224 mettre_a_jour(0.);
225 if (nom_fichier_!="")
226 loipar_->imprimer_premiere_ligne_nusselt(boundaries_, boundaries_list_, nom_fichier_);
227 return 1;
228}
229
230/*! @brief for PDI IO: retrieve name, type and dimensions of the fields to save/restore
231 *
232 */
234{
235 std::vector<YAML_data> data;
236 if (loipar_)
237 data = loipar_->data_a_sauvegarder();
238 return data;
239}
240
241/*! @brief Does nothing.
242 *
243 * @param os Output stream.
244 * @return Always returns 1.
245 */
247{
248 if (loipar_)
249 return loipar_->sauvegarder(os);
250 else
251 return 0;
252}
253
254/*! @brief Writes an identity string to the output stream if necessary.
255 *
256 * @param os Output stream.
257 */
259{
260 int afaire, special;
262
263 if (afaire)
264 {
265 Nom mon_ident(que_suis_je());
266 mon_ident += equation().probleme().domaine().le_nom();
267 double temps = equation().inconnue().temps();
268 mon_ident += Nom(temps, "%e");
269 os << mon_ident << finl;
270 os << que_suis_je() << finl;
271 os.flush();
272 }
273}
274
275/*! @brief Does nothing.
276 *
277 * @param is Input stream.
278 * @return Always returns 1.
279 */
281{
282
283 if (loipar_)
284 loipar_->reprendre(is);
285 return 1;
286}
287
289{
290 if (loipar_)
291 loipar_->creer_champ(motlu);
292}
293
294bool Modele_turbulence_scal_base::has_champ(const Motcle& nom, OBS_PTR(Champ_base)& ref_champ) const
295{
296 if (champs_compris_.has_champ(nom, ref_champ))
297 return true;
298
299 if (loipar_)
300 if (loipar_->has_champ(nom, ref_champ))
301 return true;
302
303 return false; /* nothing found */
304}
305
307{
308 if (champs_compris_.has_champ(nom))
309 return true;
310
311 if (loipar_)
312 if (loipar_->has_champ(nom))
313 return true;
314
315 return false; /* nothing found */
316}
317
319{
320 OBS_PTR(Champ_base) ref_champ;
321
322 if (champs_compris_.has_champ(nom, ref_champ))
323 return ref_champ;
324
325 if (loipar_)
326 if (loipar_->has_champ(nom, ref_champ))
327 return ref_champ;
328
329 throw std::runtime_error(std::string("Field ") + nom.getString() + std::string(" not found !"));
330}
331
333{
334 if (opt == DESCRIPTION)
335 Cerr << que_suis_je() << " : " << champs_compris_.liste_noms_compris() << finl;
336 else
337 nom.add(champs_compris_.liste_noms_compris());
338
339 if (loipar_)
340 loipar_->get_noms_champs_postraitables(nom, opt);
341}
342
343/*! @brief Indicates whether local Nusselt values should be printed.
344 *
345 * @param temps_courant Current time.
346 * @param temps_prec Previous time.
347 * @param dt Current time step.
348 * @param dt_nusselt Nusselt printing period.
349 * @return 1 if printing is required, 0 otherwise.
350 */
351int Modele_turbulence_scal_base::limpr_nusselt(double temps_courant, double temps_prec, double dt, double dt_nusselt) const
352{
353 const Schema_Temps_base& sch = mon_equation_->schema_temps();
354 if (sch.nb_pas_dt() == 0)
355 return 0;
356 if (dt_nusselt <= dt
357 || ((sch.temps_cpu_max_atteint() || (!get_disable_stop() && sch.stop_lu()) || sch.temps_final_atteint() || sch.nb_pas_dt_max_atteint() || sch.nb_pas_dt() == 1 || sch.stationnaire_atteint())
358 && dt_nusselt != DMAXFLOAT))
359 return 1;
360 else
361 {
362 // Voir Schema_Temps_base::limpr pour information sur epsilon et modf
363 double i, j, epsilon = 1.e-8;
364 modf(temps_courant / dt_nusselt + epsilon, &i);
365 modf(temps_prec / dt_nusselt + epsilon, &j);
366 return (i > j);
367 }
368}
369
370/*! @brief Performs printing if necessary.
371 *
372 * @param os Output stream.
373 */
375{
376 const Schema_Temps_base& sch = mon_equation_->schema_temps();
377 double temps_courant = sch.temps_courant();
378 double dt = sch.pas_de_temps();
379 if (limpr_nusselt(temps_courant, sch.temps_precedent(), dt, dt_impr_nusselt_))
380 loipar_->imprimer_nusselt(os);
381 if (limpr_nusselt(temps_courant, sch.temps_precedent(), dt, dt_impr_nusselt_mean_only_))
382 loipar_->imprimer_nusselt_mean_only(os, boundaries_, boundaries_list_, nom_fichier_);
383}
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
double temps() const
Returns the time of the field.
bool has_champ(const Motcle &nom, OBS_PTR(FIELD_TYPE)&ref_champ) const
Convection_Diffusion_std This class is the base for equations modelling the transport.
const Champ_Inc_base & inconnue() const override=0
class Discretisation_base This class represents a spatial discretization scheme, which
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, const Nom &nom, const Nom &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const
int nb_front_Cl() const
Definition Domaine.h:236
const Frontiere_t & frontiere(int i) const
Definition Domaine.h:539
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
static int is_ecriture_special(int &special, int &a_faire)
Indicates whether the special format was requested in active writing by xyz save.
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....
virtual const RefObjU & get_modele(Type_modele type) const
Probleme_base & probleme()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Frontiere.h:49
void add(const Frontiere_32_64 &)
Adds the vertices (and faces) of the given boundary to this object (Frontiere_32_64).
Base class for scalar turbulence models coupled to a Navier-Stokes convection-diffusion equation.
OBS_PTR(Convection_Diffusion_std) mon_equation_
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
virtual void mettre_a_jour(double)=0
virtual void completer()
Completes the turbulence model: updates object references.
Convection_Diffusion_std & equation()
const Champ_base & get_champ(const Motcle &nom) const override
void associer_eqn(const Equation_base &)
Associates the equation passed as parameter to the turbulence model.
virtual bool initTimeStep(double dt)
To be overridden in derived classes that own one or more equations. Calls preparer_pas_de_temps on th...
virtual void imprimer(Sortie &) const
Performs printing if necessary.
void get_noms_champs_postraitables(Noms &nom, Option opt=NONE) const override
int reprendre(Entree &) override
Does nothing.
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
virtual void associer(const Domaine_dis_base &, const Domaine_Cl_dis_base &)
Does nothing.
void creer_champ(const Motcle &motlu) override
int sauvegarder(Sortie &) const override
Does nothing.
LIST(Nom) boundaries_list_
int limpr_nusselt(double, double, double, double) const
Indicates whether local Nusselt values should be printed.
virtual void set_param(Param &) const override
virtual std::vector< YAML_data > data_a_sauvegarder() const
for PDI IO: retrieve name, type and dimensions of the fields to save/restore
virtual int preparer_calcul()
Does nothing.
virtual void discretiser()
Discretizes the turbulence model.
void a_faire(Sortie &) const
Writes an identity string to the output stream if necessary.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
An array of character strings (VECT(Nom)).
Definition Noms.h:26
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
friend class Entree
Definition Objet_U.h:71
friend class Sortie
Definition Objet_U.h:70
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
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
Definition Objet_U.cpp:145
virtual const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
void ajouter_non_std(const char *keyword, const Objet_U *value, Param::Nature nat=Param::OPTIONAL)
Register a keyword handled by Objet_U::lire_motcle_non_standard.
Definition Param.cpp:489
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Probleme_U.h:109
const Domaine & domaine() const
Returns the domain associated with the problem.
virtual const Equation_base & equation(int) const =0
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
class Schema_Temps_base
double temps_courant() const
Returns the current time.
int nb_pas_dt_max_atteint() const
Returns 1 if (the number of time steps >= maximum number of time steps).
int temps_final_atteint() const
Returns 1 if the final time has been reached (or exceeded).
double pas_de_temps() const
Returns the current time step (delta_t).
int nb_pas_dt() const
Returns the number of time steps performed.
int stop_lu() const
Returns 1 if the .stop file contains a 1, returns 0 otherwise.
int stationnaire_atteint() const
int temps_cpu_max_atteint() const
double temps_precedent() const
Returns the previous time.
Base class for output streams.
Definition Sortie.h:52
virtual Sortie & flush()
Definition Sortie.cpp:138
const Objet_U & valeur() const
Definition TRUST_Ref.h:134
static void typer_lire_turbulence_paroi_scal(OWN_PTR(Turbulence_paroi_scal_base)&, const Modele_turbulence_scal_base &, Entree &)
Reads the characteristics of the scalar wall law from an input stream.