TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Generique_Morceau_Equation.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#include <Champ_Generique_Morceau_Equation.h>
16#include <Domaine_VF.h>
17#include <Champ_Generique_refChamp.h>
18#include <Discretisation_base.h>
19#include <Operateur_base.h>
20#include <Operateur.h>
21#include <Synonyme_info.h>
22#include <Param.h>
23#include <Transport_K_Eps_base.h>
24#include <Modele_turbulence_hyd_K_Eps.h>
25#include <Modele_turbulence_hyd_K_Eps_Realisable.h>
26#include <Modele_turbulence_hyd_RANS_K_Eps_base.h>
27#include <Transport_K_Omega_base.h>
28#include <Modele_turbulence_hyd_K_Omega.h>
29#include <Modele_turbulence_hyd_RANS_K_Omega_base.h>
30
31
32Implemente_instanciable(Champ_Generique_Morceau_Equation,"Morceau_Equation",Champ_Gen_de_Champs_Gen);
33Add_synonym(Champ_Generique_Morceau_Equation,"Champ_Post_Morceau_Equation");
34// XD morceau_equation champ_post_de_champs_post morceau_equation BRACE To calculate a field related to a piece of
35// XD_CONT equation. For the moment, the field which can be calculated is the stability time step of an operator
36// XD_CONT equation. The problem name and the unknown of the equation should be given by Source refChamp { Pb_Champ
37// XD_CONT problem_name unknown_field_of_equation }
38
39
41{
42 return s << que_suis_je() << " " << le_nom();
43}
44
45//cf Champ_Gen_de_Champs_Gen::readOn
47{
49 return s ;
50}
51
52// type : type du morceau d equation (actuellement "operateur")
53// numero : numero du morceau d equation
54// (cas operateur : 0 (diffusion) 1 (convection) 2 (gradient) 3 (divergence))
55// option : choix de la quantite a postraiter
56// (actuellement "stabilite" pour dt_stab "flux_bords" pour flux_bords_)
57// unite : pour imposer l'unite du champ
58// compo : numero de la composante a postraiter pour le cas des "flux_bords"
59// (si plusieurs composantes)
61{
63 param.ajouter("type",&type_morceau_,Param::REQUIRED); // XD_ADD_P chaine
64 // XD_CONT can only be operateur for equation operators.
65 param.ajouter("numero",&numero_morceau_); // XD_ADD_P entier
66 // XD_CONT numero will be 0 (diffusive operator) or 1 (convective operator) or 2 (gradient operator) or 3 (divergence
67 // XD_CONT operator).
68 param.ajouter("unite", &unite_); // XD_ADD_P chaine
69 // XD_CONT will specify the field unit
70 param.ajouter("option",&option_,Param::REQUIRED); // XD_ADD_P chaine(into=["stabilite","flux_bords","flux_surfacique_bords"])
71 // XD_CONT option is stability for time steps or flux_bords for boundary fluxes or flux_surfacique_bords for boundary
72 // XD_CONT surfacic fluxes
73 param.ajouter("compo",&compo_); // XD_ADD_P entier
74 // XD_CONT compo will specify the number component of the boundary flux (for boundary fluxes, in this case compo
75 // XD_CONT permits to specify the number component of the boundary flux choosen).
76}
77
78//-Initialisation de ref_eq_
79//-Initialisation de localisation_
80//-Appel de la methode de la classe mere
82{
83 const Probleme_base& Pb = get_ref_pb_base();
84 int numero_eq_=-1;
85 if (sub_type(Champ_Generique_refChamp,get_source(0)))
86 {
87
88 OWN_PTR(Champ_base) espace_stockage;
89 const Champ_base& mon_champ = get_source(0).get_champ(espace_stockage);
90 if (sub_type(Champ_Inc_base,mon_champ))
91 {
92 const Champ_Inc_base& mon_champ_inc = ref_cast(Champ_Inc_base,mon_champ);
93
94 {
95 //On recupere l equation alors qu elle n est pas encore associee au Champ_Inc
96 //On parcours les equations du probleme et on identifie celle qui correspond au champ inconnu
97
98 int nb_eq = Pb.nombre_d_equations();
99 int i=0;
100
101 while (i<nb_eq)
102 {
103 const Equation_base& eq_test = Pb.equation(i);
104 if ((eq_test.inconnue().le_nom() == mon_champ_inc.le_nom()))
105 {
106 numero_eq_=i;
107 ref_eq_=Pb.equation(numero_eq_);
108 break;
109 }
110
111 if (mon_champ_inc.le_nom() == "K_Eps" || mon_champ_inc.le_nom() == "K_Omega")
112 {
113 if (not sub_type(Modele_turbulence_hyd_2_eq_base, eq_test.get_modele(TURBULENCE).valeur()))
114 {
115 Cerr<<"Champ_Generique_Morceau_Equation in TriocCFD: K_Eps and K_Omega can only be used with a related RANS turbulence model"<<finl;
117 }
118 // handles RANS fields in triocfd: search if turbulence models have an equation with this unknown name
119 const auto& le_mod_RANS = ref_cast(Modele_turbulence_hyd_2_eq_base, eq_test.get_modele(TURBULENCE).valeur());
120 const auto& rans_equation = le_mod_RANS.get_eq_transport();
121 if ((rans_equation.inconnue().le_nom() == mon_champ_inc.le_nom()))
122 {
123 numero_eq_=i;
124 ref_eq_=rans_equation;
125 break;
126 }
127 Cerr << "Champ_Generique_Morceau_Equation in TriocCFD: K_Eps or K_Omega was probably used with the wrong RANS turbulence model." << finl;
128 Cerr << "Check your dataset consistency." << finl;
130 }
131 i++;
132 }
133 }
134 }
135 }
136
137 if (numero_eq_==-1)
138 {
139 Cerr<<"We can apply a Champ_Generique_Morceau_Equation only to an unknown field of the problem"<<finl;
140 exit();
141 }
142 // ref_eq_ = Pb.equation(numero_eq_); // not needed, we already did that when we had the correct equation earlier...
143
145
146 //Appel de la methode de la classe mere fait apres pour que
147 //la methode nommer_source() dispose de ref_eq_ initialise
149}
150
151OWN_PTR(Champ_Fonc_base)& Champ_Generique_Morceau_Equation::creer_espace_stockage(const Nature_du_champ& nature,
152 const int nb_comp,
153 OWN_PTR(Champ_Fonc_base)& es_tmp) const
154{
155 Noms noms;
156 Noms unites;
157 for (int c=0; c<nb_comp; c++)
158 unites.add("??");
159 noms.add("bidon");
160 double temps;
161 temps = get_time();
162 const Discretisation_base& discr = get_discretisation();
163 Motcle directive;
164 if ((Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
165 directive = "champ_face"; // Pour avoir les flux_bords aux faces et non aux elements en VDF (ex: temperature)
166 else
167 directive = get_directive_pour_discr();
168 const Domaine_dis_base& domaine_dis = get_ref_domaine_dis_base();
169
170 discr.discretiser_champ(directive,domaine_dis,nature,noms,unites,nb_comp,temps,es_tmp);
171
172 if (directive=="pression")
173 {
174 const Domaine_Cl_dis_base& zcl = get_ref_zcl_dis_base();
175 es_tmp->completer(zcl);
176 }
177
178 return es_tmp;
179}
180
181/*! @brief le morceau d equation lance la discretisation du champ espace_stockage et remplit son tableau de valeurs par la methode calculer_pour_post(.
182 *
183 * ..)
184 * Rq : Ce procede differe de celui applique dans les autres Champ_Generique_base pour lesquels
185 * le remplissage du tableau de valeurs de espace_stockage n'est pas delegue
186 *
187 *
188 */
189const Champ_base& Champ_Generique_Morceau_Equation::get_champ(OWN_PTR(Champ_base)& espace_stockage) const
190{
191 OWN_PTR(Champ_Fonc_base) es_tmp;
192 Nature_du_champ nature;
193 int nb_comp = -1;
194
195 if ((Motcle(option_)=="stabilite") || (Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
196 {
197 nature = scalaire;
198 nb_comp = 1;
199 }
200 else
201 {
202 Cerr << "Error. Contact TRUST support." << finl;
204 }
205
206 espace_stockage = creer_espace_stockage(nature,nb_comp,es_tmp);
207 morceau().calculer_pour_post(espace_stockage,option_,compo_);
208 DoubleTab& es_val = espace_stockage->valeurs();
209 es_val.echange_espace_virtuel();
210 return espace_stockage;
211}
212
214{
215 OWN_PTR(Champ_Fonc_base) es_tmp;
216 Nature_du_champ nature;
217 int nb_comp = -1;
218
219 if ((Motcle(option_)=="stabilite") || (Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
220 {
221 nature = scalaire;
222 nb_comp = 1;
223 }
224
225 espace_stockage = creer_espace_stockage(nature,nb_comp,es_tmp);
226 return espace_stockage;
227}
229{
230
231 Motcles motcles(2);
232 motcles[0] = "composantes";
233 motcles[1] = "unites";
234
235 int rang = motcles.search(query);
236 switch(rang)
237 {
238 case 0:
239 {
240 Noms compo(1);
241 Nom nume((int)1);
242 compo[0] = nom_post_+nume;
243
244 return compo;
245 }
246
247 case 1:
248 {
249 Noms unites(1);
250 if (unite_ != "??")
251 {
252 unites[0] = unite_;
253 return unites;
254 }
255 if (Motcle(option_)=="stabilite")
256 unites[0] = "s";
257 else if (Motcle(option_).debute_par("FLUX_"))
258 {
259 // Tres incomplet mais bon...:
260 if (ref_eq_->inconnue().le_nom()=="vitesse")
261 {
262 if (numero_morceau_<2) unites[0]="N";
263 else if (numero_morceau_==3) unites[0]=(dimension==2 ? "m2/s" : "m3/s");
264 }
265 else if (ref_eq_->inconnue().le_nom()=="temperature") unites[0]="W";
266 if (Motcle(option_)==Motcle("flux_surfacique_bords"))
267 unites[0]+="/m2";
268 }
269 return unites;
270 }
271
272 }
274}
275
276Entity Champ_Generique_Morceau_Equation::get_localisation(const int index) const
277{
278 Entity loc;
279 //Pour initialisation
280 loc = Entity::NODE;
281
282 if (localisation_=="elem")
283 loc = Entity::ELEMENT;
284 else if (localisation_=="face")
285 loc = Entity::FACE;
286 else if (localisation_=="som")
287 loc = Entity::NODE;
288 else
289 {
290 Cerr << "Error of type : localisation should be specified to elem or som or face for the defined field " << nom_post_ << finl;
291 throw Champ_Generique_erreur("INVALID");
292 }
293 return loc;
294}
295
296//Nomme le champ en tant que source par defaut
297//nom_eq + "_" + type_morceau + "_" + type_option
299{
300 Motcle type_morceau, type_option;
301 if (Motcle(type_morceau_)=="operateur")
302 {
303 if (numero_morceau_==0)
304 type_morceau = "diffusion";
305 else if (numero_morceau_==1)
306 type_morceau = "convection";
307 else if (numero_morceau_==2)
308 type_morceau = "gradient";
309 else if (numero_morceau_==3)
310 type_morceau = "divergence";
311 else
312 {
313 Cerr<<"This operateur number is not available."<<finl;
315 }
316 }
317 else
318 {
319 Cerr<<"Currently the only pieces of equations considered for the postprocessing"<<finl;
320 Cerr<<"are of type operator"<<finl;
322 }
323
324 if (Motcle(option_)=="stabilite")
325 type_option = "dt";
326 else if (Motcle(option_)=="flux_bords")
327 {
328 type_option = "flux_bords";
329 }
330 else if (Motcle(option_)=="flux_surfacique_bords")
331 {
332 type_option = "flux_surfacique_bords";
333 }
334 else
335 {
336 Cerr<<"Currently the only options considered for a piece of equation are \"stabilite\" and \"flux_bords\"."<<finl;
338 }
339
340
341 if (nom_post_=="??")
342 {
343 Nom nom_post_source;
344 const Nom& nom_eq = ref_eq_->le_nom();
345 nom_post_source = nom_eq;
346 nom_post_source += "_";
347 nom_post_source += type_morceau;
348 nom_post_source += "_";
349 nom_post_source += type_option ;
350 if ((Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
351 {
352 Nom nume(compo_);
353 nom_post_source += nume;
354 }
355 nommer(nom_post_source);
356 }
357
358}
359
360//Rend le morceau d equation considere pour ce Champ_Generique_base
361//Actuellement seul type de morceau considere : les operateurs
362//Pour considerer d autres morceaux d equation il faudra tester type_morceau_
364{
365 int nb_operateurs = ref_eq_->nombre_d_operateurs();
366 if (numero_morceau_ >= nb_operateurs)
367 return ref_eq_->operateur_fonctionnel(numero_morceau_-nb_operateurs).l_op_base();
368
369 return ref_eq_->operateur(numero_morceau_).l_op_base();
370}
371
373{
374 int nb_operateurs = ref_eq_->nombre_d_operateurs();
375 if (numero_morceau_ >= nb_operateurs)
376 return ref_eq_->operateur_fonctionnel(numero_morceau_-nb_operateurs).l_op_base();
377
378 return ref_eq_->operateur(numero_morceau_).l_op_base();
379}
380
382{
383 Motcle directive;
384
385 if (localisation_=="elem")
386 directive = "champ_elem";
387 else if (localisation_=="face")
388 directive = "champ_face";
389 else if (localisation_=="som")
390 directive = "champ_sommets";
391 else
392 {
393 Cerr << "Error of type : localisation should be specified to elem or som or face for the defined field " << nom_post_ << finl;
394 throw Champ_Generique_erreur("INVALID");
395 }
396
397 return directive;
398}
399
classe Champ_Fonc_base Classe de base des champs qui sont fonction d'une grandeur calculee
Classe de base des champs generiques ayant comme source d'autres champs generiques L'utilisation des ...
const Noms get_property(const Motcle &query) const override
Renvoie la propriete demandee.
void completer(const Postraitement_base &post) override
const Probleme_base & get_ref_pb_base() const override
Renvoie le probleme qui porte le champ cible.
const Domaine_Cl_dis_base & get_ref_zcl_dis_base() const override
Renvoie une ref au domaine_cl_discretisee de l equation portant le champ cible.
virtual const Champ_Generique_base & get_source(int i) const
void set_param(Param &param) const override
const Discretisation_base & get_discretisation() const override
Renvoie la discretisation associee au probleme.
const Domaine_dis_base & get_ref_domaine_dis_base() const override
Renvoie une ref au domaine_discretisee du domaine sur lequel sera evalue l espace de stockage.
double get_time() const override
Renvoie le temps du Champ_Generique_base.
class Champ_Generique_Morceau_Equation OWN_PTR(Champ_base) destine a post-traiter une quantite liee a...
const Noms get_property(const Motcle &query) const override
Renvoie la propriete demandee.
void completer(const Postraitement_base &post) override
OWN_PTR(Champ_Fonc_base) &creer_espace_stockage(const Nature_du_champ &nature
const Motcle get_directive_pour_discr() const override
Renvoie la directive (champ_elem, champ_sommets, champ_face ou pression) pour lancer la discretisatio...
const Champ_base & get_champ(OWN_PTR(Champ_base)&espace_stockage) const override
const Champ_base & get_champ_without_evaluation(OWN_PTR(Champ_base)&espace_stockage) const override
Entity get_localisation(const int index=-1) const override
Renvoie le type des entites geometriques sur auxquelles les valeurs discretes sont attachees (NODE po...
virtual const Champ_base & get_champ(OWN_PTR(Champ_base) &espace_stockage) const =0
void nommer(const Nom &nom) override
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
virtual DoubleTab & valeurs()=0
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
virtual void completer(const Domaine_Cl_dis_base &zcl)
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
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const RefObjU & get_modele(Type_modele type) const
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Renvoie le nom du champ.
classe MorEqn Classe qui regroupe les fonctionnalites de liaison avec une
Definition MorEqn.h:35
virtual Motcle get_localisation_pour_post(const Nom &option) const
Definition MorEqn.cpp:43
virtual void calculer_pour_post(Champ_base &espace_stockage, const Nom &option, int comp) const
Definition MorEqn.cpp:35
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
static int dimension
Definition Objet_U.h:99
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 const Nom & le_nom() const
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Objet_U.cpp:319
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
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
@ REQUIRED
Definition Param.h:115
Classe de base pour l'ensemble des postraitements.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
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
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
const Objet_U & valeur() const
Definition TRUST_Ref.h:134