TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Generique_Morceau_Equation.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#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
24Implemente_instanciable(Champ_Generique_Morceau_Equation,"Morceau_Equation",Champ_Gen_de_Champs_Gen);
25Add_synonym(Champ_Generique_Morceau_Equation,"Champ_Post_Morceau_Equation");
26// XD morceau_equation champ_post_de_champs_post morceau_equation BRACE To calculate a field related to a piece of
27// XD_CONT equation. For the moment, the field which can be calculated is the stability time step of an operator
28// XD_CONT equation. The problem name and the unknown of the equation should be given by Source refChamp { Pb_Champ
29// XD_CONT problem_name unknown_field_of_equation }
30
31
33{
34 return s << que_suis_je() << " " << le_nom();
35}
36
37//see Champ_Gen_de_Champs_Gen::readOn
39{
41 return s ;
42}
43
44// type : type of equation piece (currently "operateur")
45// numero : number of the equation piece
46// (operator case: 0 (diffusion) 1 (convection) 2 (gradient) 3 (divergence))
47// option : choice of the quantity to post-process
48// (currently "stabilite" for dt_stab, "flux_bords" for flux_bords_)
49// unite : to impose the unit of the field
50// compo : component number to post-process for the "flux_bords" case
51// (if multiple components)
53{
55 param.ajouter("type",&type_morceau_,Param::REQUIRED); // XD_ADD_P chaine
56 // XD_CONT can only be operateur for equation operators.
57 param.ajouter("numero",&numero_morceau_); // XD_ADD_P entier
58 // XD_CONT numero will be 0 (diffusive operator) or 1 (convective operator) or 2 (gradient operator) or 3 (divergence
59 // XD_CONT operator).
60 param.ajouter("unite", &unite_); // XD_ADD_P chaine
61 // XD_CONT will specify the field unit
62 param.ajouter("option",&option_,Param::REQUIRED); // XD_ADD_P chaine(into=["stabilite","flux_bords","flux_surfacique_bords"])
63 // XD_CONT option is stability for time steps or flux_bords for boundary fluxes or flux_surfacique_bords for boundary
64 // XD_CONT surfacic fluxes
65 param.ajouter("compo",&compo_); // XD_ADD_P entier
66 // XD_CONT compo will specify the number component of the boundary flux (for boundary fluxes, in this case compo
67 // XD_CONT permits to specify the number component of the boundary flux choosen).
68}
69
70//-Initialization of ref_eq_
71//-Initialization of localisation_
72//-Call to the parent class method
74{
75 const Probleme_base& Pb = get_ref_pb_base();
76 int numero_eq_=-1;
77 if (sub_type(Champ_Generique_refChamp,get_source(0)))
78 {
79
80 OWN_PTR(Champ_base) espace_stockage;
81 const Champ_base& mon_champ = get_source(0).get_champ(espace_stockage);
82 if (sub_type(Champ_Inc_base,mon_champ))
83 {
84 const Champ_Inc_base& mon_champ_inc = ref_cast(Champ_Inc_base,mon_champ);
85
86 {
87 //We retrieve the equation even though it is not yet associated with Champ_Inc
88 //We iterate over the equations of the problem and identify the one corresponding to the unknown field
89
90 int nb_eq = Pb.nombre_d_equations();
91 int i=0;
92
93 while (i<nb_eq)
94 {
95 const Equation_base& eq_test = Pb.equation(i);
96 if ((eq_test.inconnue().le_nom() == mon_champ_inc.le_nom()))
97 {
98 numero_eq_=i;
99 break;
100 }
101 i++;
102 }
103 }
104 }
105 }
106
107 if (numero_eq_==-1)
108 {
109 Cerr<<"We can apply a Champ_Generique_Morceau_Equation only to an unknown field of the problem"<<finl;
111 }
112 ref_eq_ = Pb.equation(numero_eq_);
113
115
116 //The parent class method is called after so that
117 //the nommer_source() method has ref_eq_ initialized
119}
120
121OWN_PTR(Champ_Fonc_base)& Champ_Generique_Morceau_Equation::creer_espace_stockage(const Nature_du_champ& nature,
122 const int nb_comp,
123 OWN_PTR(Champ_Fonc_base)& es_tmp) const
124{
125 Noms noms;
126 Noms unites;
127 for (int c=0; c<nb_comp; c++)
128 unites.add("??");
129 noms.add("bidon");
130 double temps;
131 temps = get_time();
133 Motcle directive;
134 if ((Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
135 directive = "champ_face"; // To have flux_bords at faces and not at elements in VDF (ex: temperature)
136 else
137 directive = get_directive_pour_discr();
138 const Domaine_dis_base& domaine_dis = get_ref_domaine_dis_base();
139
140 discr.discretiser_champ(directive,domaine_dis,nature,noms,unites,nb_comp,temps,es_tmp);
141
142 if (directive=="pression")
143 {
145 es_tmp->completer(zcl);
146 }
147
148 return es_tmp;
149}
150
151/*! @brief The equation piece triggers the discretisation of the storage space field and fills its value array via the calculer_pour_post(.
152 *
153 * ..) method
154 * Note: This procedure differs from the one applied in the other Champ_Generique_base classes, for which
155 * the filling of the espace_stockage value array is not delegated
156 *
157 *
158 */
159const Champ_base& Champ_Generique_Morceau_Equation::get_champ(OWN_PTR(Champ_base)& espace_stockage) const
160{
161 OWN_PTR(Champ_Fonc_base) es_tmp;
162 Nature_du_champ nature;
163 int nb_comp = -1;
164
165 if ((Motcle(option_)=="stabilite") || (Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
166 {
167 nature = scalaire;
168 nb_comp = 1;
169 }
170 else
171 {
172 Cerr << "Error. Contact TRUST support." << finl;
174 }
175
176 espace_stockage = creer_espace_stockage(nature,nb_comp,es_tmp);
177 morceau().calculer_pour_post(espace_stockage,option_,compo_);
178 DoubleTab& es_val = espace_stockage->valeurs();
179 es_val.echange_espace_virtuel();
180 return espace_stockage;
181}
182
184{
185 OWN_PTR(Champ_Fonc_base) es_tmp;
186 Nature_du_champ nature;
187 int nb_comp = -1;
188
189 if ((Motcle(option_)=="stabilite") || (Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
190 {
191 nature = scalaire;
192 nb_comp = 1;
193 }
194
195 espace_stockage = creer_espace_stockage(nature,nb_comp,es_tmp);
196 return espace_stockage;
197}
199{
200
201 Motcles motcles(2);
202 motcles[0] = "composantes";
203 motcles[1] = "unites";
204
205 int rang = motcles.search(query);
206 switch(rang)
207 {
208 case 0:
209 {
210 Noms compo(1);
211 Nom nume((int)1);
212 compo[0] = nom_post_+nume;
213
214 return compo;
215 }
216
217 case 1:
218 {
219 Noms unites(1);
220 if (unite_ != "??")
221 {
222 unites[0] = unite_;
223 return unites;
224 }
225 if (Motcle(option_)=="stabilite")
226 unites[0] = "s";
227 else if (Motcle(option_).debute_par("FLUX_"))
228 {
229 // Very incomplete but still...:
230 if (ref_eq_->inconnue().le_nom()=="vitesse")
231 {
232 if (numero_morceau_<2) unites[0]="N";
233 else if (numero_morceau_==3) unites[0]=(dimension==2 ? "m2/s" : "m3/s");
234 }
235 else if (ref_eq_->inconnue().le_nom()=="temperature") unites[0]="W";
236 if (Motcle(option_)==Motcle("flux_surfacique_bords"))
237 unites[0]+="/m2";
238 }
239 return unites;
240 }
241
242 }
244}
245
246Entity Champ_Generique_Morceau_Equation::get_localisation(const int index) const
247{
248 Entity loc;
249 // For initialization
250 loc = Entity::NODE;
251
252 if (localisation_=="elem")
253 loc = Entity::ELEMENT;
254 else if (localisation_=="face")
255 loc = Entity::FACE;
256 else if (localisation_=="som")
257 loc = Entity::NODE;
258 else
259 {
260 Cerr << "Error of type : localisation should be specified to elem or som or face for the defined field " << nom_post_ << finl;
261 throw Champ_Generique_erreur("INVALID");
262 }
263 return loc;
264}
265
266//Name the field as a source by default
267//nom_eq + "_" + type_morceau + "_" + type_option
269{
270 Motcle type_morceau, type_option;
271 if (Motcle(type_morceau_)=="operateur")
272 {
273 if (numero_morceau_==0)
274 type_morceau = "diffusion";
275 else if (numero_morceau_==1)
276 type_morceau = "convection";
277 else if (numero_morceau_==2)
278 type_morceau = "gradient";
279 else if (numero_morceau_==3)
280 type_morceau = "divergence";
281 else
282 {
283 Cerr<<"This operateur number is not available."<<finl;
285 }
286 }
287 else
288 {
289 Cerr<<"Currently the only pieces of equations considered for the postprocessing"<<finl;
290 Cerr<<"are of type operator"<<finl;
292 }
293
294 if (Motcle(option_)=="stabilite")
295 type_option = "dt";
296 else if (Motcle(option_)=="flux_bords")
297 {
298 type_option = "flux_bords";
299 }
300 else if (Motcle(option_)=="flux_surfacique_bords")
301 {
302 type_option = "flux_surfacique_bords";
303 }
304 else
305 {
306 Cerr<<"Currently the only options considered for a piece of equation are \"stabilite\" and \"flux_bords\"."<<finl;
308 }
309
310
311 if (nom_post_=="??")
312 {
313 Nom nom_post_source;
314 const Nom& nom_eq = ref_eq_->le_nom();
315 nom_post_source = nom_eq;
316 nom_post_source += "_";
317 nom_post_source += type_morceau;
318 nom_post_source += "_";
319 nom_post_source += type_option ;
320 if ((Motcle(option_)=="flux_bords") || (Motcle(option_)=="flux_surfacique_bords"))
321 {
322 Nom nume(compo_);
323 nom_post_source += nume;
324 }
325 nommer(nom_post_source);
326 }
327
328}
329
330//Returns the equation piece considered for this Champ_Generique_base
331//Currently the only type of piece considered: operators
332//To consider other equation pieces, type_morceau_ will need to be tested
334{
335 int nb_operateurs = ref_eq_->nombre_d_operateurs();
336 if (numero_morceau_ >= nb_operateurs)
337 return ref_eq_->operateur_fonctionnel(numero_morceau_-nb_operateurs).l_op_base();
338
339 return ref_eq_->operateur(numero_morceau_).l_op_base();
340}
341
343{
344 int nb_operateurs = ref_eq_->nombre_d_operateurs();
345 if (numero_morceau_ >= nb_operateurs)
346 return ref_eq_->operateur_fonctionnel(numero_morceau_-nb_operateurs).l_op_base();
347
348 return ref_eq_->operateur(numero_morceau_).l_op_base();
349}
350
352{
353 Motcle directive;
354
355 if (localisation_=="elem")
356 directive = "champ_elem";
357 else if (localisation_=="face")
358 directive = "champ_face";
359 else if (localisation_=="som")
360 directive = "champ_sommets";
361 else
362 {
363 Cerr << "Error of type : localisation should be specified to elem or som or face for the defined field " << nom_post_ << finl;
364 throw Champ_Generique_erreur("INVALID");
365 }
366
367 return directive;
368}
369
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
Base class of generic fields having other generic fields as source. The use of the class methods reli...
const Noms get_property(const Motcle &query) const override
Returns the requested property.
void completer(const Postraitement_base &post) override
const Probleme_base & get_ref_pb_base() const override
Returns the problem that carries the target field.
const Domaine_Cl_dis_base & get_ref_zcl_dis_base() const override
Returns a ref to the discretized boundary conditions domain of the equation carrying the target field...
virtual const Champ_Generique_base & get_source(int i) const
void set_param(Param &param) const override
const Discretisation_base & get_discretisation() const override
Returns the discretization associated with the problem.
const Domaine_dis_base & get_ref_domaine_dis_base() const override
Returns a ref to the discretized domain on which the storage space will be evaluated.
double get_time() const override
Returns the time of the Champ_Generique_base.
class Champ_Generique_Morceau_Equation OWN_PTR(Champ_base) intended to post-process a quantity relate...
const Noms get_property(const Motcle &query) const override
Returns the requested property.
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
Returns the directive (champ_elem, champ_sommets, champ_face or pression) to launch the discretizatio...
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
Returns the type of geometric entities on which the discrete values are attached (NODE for a P1 field...
virtual const Champ_base & get_champ(OWN_PTR(Champ_base) &espace_stockage) const =0
void nommer(const Nom &nom) override
Assigns a name to the Objet_U. Virtual method to override.
Special field class that encapsulates a reference to a volume field of TRUST of type Champ_base.
Class Champ_Inc_base.
virtual DoubleTab & valeurs()=0
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
virtual void completer(const Domaine_Cl_dis_base &zcl)
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
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
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 Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Returns the name of the field.
class MorEqn Class that groups the functionalities of linking with an
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
A character string (Nom) in uppercase.
Definition Motcle.h:26
An array of character strings (VECT(Nom)).
Definition Noms.h:26
static int dimension
Definition Objet_U.h:94
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 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
@ REQUIRED
Definition Param.h:115
Base class for all post-processing objects.
class Probleme_base It is a Probleme_U that is not a coupling.
virtual int nombre_d_equations() const =0
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
Base class for output streams.
Definition Sortie.h:52
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")