TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Post_Operateur_Eqn.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 <Champ_Post_Operateur_Eqn.h>
17#include <Probleme_base.h>
18#include <Postraitement.h>
19#include <Domaine_VF.h>
20#include <Nom.h>
21#include <Champ_Generique_refChamp.h>
22#include <Discretisation_base.h>
23#include <Equation_base.h>
24#include <Operateur_base.h>
25#include <Param.h>
26#include <MD_Vector_composite.h>
27
28Implemente_instanciable_sans_constructeur(Champ_Post_Operateur_Eqn,"Operateur_Eqn|Champ_Post_Operateur_Eqn",Champ_Generique_Operateur_base);
29// XD champ_post_operateur_eqn champ_post_de_champs_post operateur_eqn BRACE Post-process equation operators/sources
30
32{
33 return s << que_suis_je() << " " << le_nom();
34}
35Champ_Post_Operateur_Eqn::Champ_Post_Operateur_Eqn()
36{
37}
38
40{
42 param.ajouter("numero_source",&numero_source_); // XD_ADD_P entier
43 // XD_CONT the source to be post-processed (its number). If you have only one source term, numero_source will
44 // XD_CONT correspond to 0 if you want to post-process that unique source
45 param.ajouter("numero_op",&numero_op_); // XD_ADD_P entier
46 // XD_CONT numero_op will be 0 (diffusive operator) or 1 (convective operator) or 2 (gradient operator) or 3
47 // XD_CONT (divergence operator).
48 param.ajouter("numero_masse",&numero_masse_); // XD_ADD_P entier
49 // XD_CONT numero_masse will be 0 for the mass equation operator in Pb_multiphase.
50 param.ajouter_flag("sans_solveur_masse",&sans_solveur_masse_); // XD_ADD_P rien
51 // XD_CONT not_set
52 param.ajouter("compo",&compo_); // XD_ADD_P entier
53 // XD_CONT If you want to post-process only one component of a vector field, you can specify the number of the
54 // XD_CONT component after compo keyword. By default, it is set to -1 which means that all the components will be
55 // XD_CONT post-processed. This feature is not available in VDF disretization.
56}
57
59{
61
62 return s ;
63}
64
66{
67 // Applying compo to a vector
68 if ((!ref_eq_->inconnue().is_vectorial()) && (compo_ != -1 ))
69 {
70 Cerr<<"Error in Champ_Post_Operateur_Eqn::verification_cas_compo()"<<finl;
71 Cerr<<"It isn't possible to get a component from a non vectoriel field " <<finl;
73 }
74
75 // Checking compo
76 const int nb_compo= ref_eq_->inconnue().nb_comp();
77 if ((compo_<-1)||(compo_>nb_compo-1))
78 {
79 Cerr<<"Error in Champ_Post_Operateur_Eqn::verification_cas_compo()"<<finl;
80 Cerr<<"compo="<<compo_<<" is not allowed."<<" You must give a value between 0 and "<< nb_compo-1<<finl;
82 }
83 // Check that we are not in VDF
84 if (ref_eq_->discretisation().is_vdf() && (compo_ != -1 ))
85 {
86 Cerr<<"Error in Champ_Post_Operateur_Eqn::verification_cas_compo()"<<finl;
87 Cerr<<"The option compo is not available in case of VDF discretization"<<finl;
89 }
90}
91
93{
94
96
97 const Probleme_base& Pb = ref_cast(Postraitement,post).probleme();
98 int numero_eq_=-1;
99 if (sub_type(Champ_Generique_refChamp,get_source(0)))
100 {
101
102 OWN_PTR(Champ_base) espace_stockage;
103 const Champ_base& mon_champ = get_source(0).get_champ(espace_stockage);
104 if (sub_type(Champ_Inc_base,mon_champ))
105 {
106 const Champ_Inc_base& mon_champ_inc = ref_cast(Champ_Inc_base,mon_champ);
107
108 {
109
110 //Retrieving the equation before it is associated with the Champ_Inc
111 //Iterating over the problem equations and identifying the one corresponding to the unknown field
112
113 int nb_eq = Pb.nombre_d_equations();
114 int i=0;
115
116 while (i<nb_eq)
117 {
118 const Equation_base& eq_test = Pb.equation(i);
119 if ((eq_test.inconnue().le_nom() == mon_champ_inc.le_nom()))
120 {
121 numero_eq_=i;
122 break;
123 }
124 i++;
125 }
126 }
127 }
128 }
129 if (numero_eq_==-1)
130 {
131 Cerr<<"Champ_Post_Operateur_Eqn can be applied only to equation unknown."<<finl;
133 }
134
135 ref_eq_=Pb.equation(numero_eq_);
136
137 int ok=0;
138 const Equation_base& eqn=ref_eq_.valeur();
139 const MD_Vector& mdf = eqn.inconnue().valeurs().get_md_vector(),
140 md = sub_type(MD_Vector_composite, mdf.valeur()) ? ref_cast(MD_Vector_composite, mdf.valeur()).get_desc_part(0) : mdf;
141 const Domaine_VF& zvf= ref_cast( Domaine_VF,ref_eq_->domaine_dis());
142 if (md== zvf.face_sommets().get_md_vector())
143 {
144 localisation_inco_=Entity::FACE;
145 ok=1;
146 }
147 if (md== zvf.domaine().les_elems().get_md_vector())
148 {
149 localisation_inco_=Entity::ELEMENT;
150 ok=1;
151 }
152 if (md == zvf.domaine().les_sommets().get_md_vector())
153 {
154 ok=1;
155 localisation_inco_=Entity::NODE;
156 }
157 if (ok==0)
158 {
159 Cerr<<"Error in "<<que_suis_je()<<" unknown localisation"<<finl;
161 }
163}
164
166{
167 espace_stockage = ref_eq_->inconnue();
168 return espace_stockage;
169}
170
172{
173
174 OWN_PTR(Champ_Fonc_base) espace_stockage_fonc;
175 //Champ source_espace_stockage;
176
177 double temps=0.;
178 Nom directive;
179
180 switch (localisation_inco_)
181 {
182 case Entity::ELEMENT:
183 directive="CHAMP_ELEM";
184 break;
185 case Entity::NODE:
186 directive="CHAMP_SOMMETS";
187 break;
188 case Entity::FACE:
189 directive="CHAMP_FACE";
190 break;
191 default:
192 Cerr<<"error in Champ_Post_Operateur_Eqn::get_champ"<<finl;
194
195 }
196 int nb_comp = 1;
197 ref_eq_->discretisation().discretiser_champ(directive,ref_eq_->domaine_dis(),"oooo","unit", nb_comp,temps,espace_stockage_fonc);
198 espace_stockage = espace_stockage_fonc;
199 espace_stockage->fixer_nature_du_champ(scalaire);
200
201 return espace_stockage;
202}
203
205{
206 // Start by building the complete vector field
207 OWN_PTR(Champ_base) espace_stockage_complet;
208 espace_stockage_complet = get_champ_without_evaluation(espace_stockage_complet);
209 DoubleTab& es = (espace_stockage_complet->valeurs());
210
211 //if (ref_eq_->schema_temps().temps_courant()!=0)
212 {
213 if (numero_op_!=-1)
214 {
215 // some compute methods are wrong!!!! they should all be recoded as res=0 ajouter();
216 es=0;
217 Operateur().ajouter(ref_eq_->operateur(numero_op_).mon_inconnue().valeurs(),es);
218 }
219 else if (numero_source_!=-1)
220 ref_eq_->sources()(numero_source_).calculer(es);
221 else if ((numero_masse_!=-1) && ref_eq_->has_interface_blocs())
222 es=0, ref_eq_->schema_temps().ajouter_blocs({},es,ref_eq_.valeur());
224 ref_eq_->solv_masse().appliquer_impl(es); //We divide by the volume
225 // Hack: because Masse_PolyMAC_CDO_Face::appliquer_impl does not divide by the volume (mass matrix)....
226 if (ref_eq_->solv_masse().que_suis_je()=="Masse_PolyMAC_CDO_Face")
227 {
228 //Cerr << "Volumic source terms on faces with PolyMAC_CDO can't be post-processed yet." << finl;
229 Cerr << "Warning, source terms on faces with PolyMAC_CDO are post-processed as S*dV not as volumic source terms S." << finl;
230 Cerr << "Cause Masse_PolyMAC_CDO_Face::appliquer_impl do not divide per volume." << finl;
231 //Process::exit();
232 }
233 }
235 // then I retrieve only the component if it was requested
236 if (compo_>-1)
237 {
238 // prepare the storage space for a single component
239 OWN_PTR(Champ_base) espace_stockage_compo;
240 espace_stockage_compo = get_champ_compo_without_evaluation(espace_stockage_compo);
241 DoubleTab& es_compo = (espace_stockage_compo->valeurs());
242 int nb_pos = es.dimension(0);
243 for (int i=0; i<nb_pos; i++)
244 {
245 es_compo(i) = es(i,compo_);
246 }
247 espace_stockage = espace_stockage_compo;
248 }
249 else
250 espace_stockage = espace_stockage_complet;
251
252 return espace_stockage;
253}
254
256{
257//Component creation should be done dynamically (Eqn_...)
258
259 Motcles motcles(2);
260 motcles[0] = "composantes";
261 motcles[1] = "unites";
262
263 int rang = motcles.search(query);
264
265 switch(rang)
266 {
267 case 0:
268 {
269 if (compo_==-1)
270 {
271 int nb_comp= ref_eq_->inconnue().nb_comp();
272 Noms compo(nb_comp);
273 for (int i=0; i<nb_comp; i++)
274 {
275 Nom nume(i);
276 compo[i] = nom_post_+nume;
277 }
278 return compo;
279 }
280 else
281 {
282 Noms compo(1);
283 compo[0] = nom_post_;
284 return compo;
285 }
286 }
287
288 case 1:
289 {
290 if (compo_==-1)
291 {
292 int nb_comp= ref_eq_->inconnue().nb_comp();
293 Noms unites(nb_comp);
294 //Noms source_unites = get_source(0).get_property("unites");
295 for (int i=0; i<nb_comp; i++)
296 {
297 unites[i] = "unit";
298 }
299 return unites;
300 }
301 else
302 {
303 // Using a vector because the method returns Noms
304 Noms unites(1);
305 unites[0] = "unit";
306 return unites;
307 }
308 }
309
310 }
312}
313
315{
316
317 return localisation_inco_;
318
319}
320//Name the field as a source by default
321//"Eqn_" + source_field_name
323{
324 if (nom_post_=="??")
325 {
326 Nom nom_post_source;
327 //const Noms nom = get_source(0).get_property("nom");
328 nom_post_source = "Eqn_s";
329 nom_post_source += Nom(numero_source_);
330 nom_post_source += "_o" ;
331 nom_post_source += Nom(numero_op_);
332 nom_post_source += "_m" ;
333 nom_post_source += Nom(numero_masse_);
334 if (compo_!=-1)
335 {
336 Nom nume(compo_);
337 nom_post_source += nume;
338 }
339 nommer(nom_post_source);
340 }
341
342}
344{
345 return ref_eq_->operateur(numero_op_).l_op_base();
346}
347
349{
350 return ref_eq_->operateur(numero_op_).l_op_base();
351}
352
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
const Noms get_property(const Motcle &query) const override
Returns the requested property.
virtual OWN_PTR(Champ_Fonc_base) &creer_espace_stockage(const Nature_du_champ &nature
void completer(const Postraitement_base &post) override
virtual const Champ_Generique_base & get_source(int i) const
void set_param(Param &param) const override
Classe Champ_Generique_Operateur_base Base class for generic field classes dedicated to applying an o...
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.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Champ_Post_Operateur_Eqn OWN_PTR(Champ_base) intended to post-process the gradient of a generic...
void completer(const Postraitement_base &post) override
void nommer_source() override
Entity localisation_inco_
const Noms get_property(const Motcle &query) const override
Returns the requested property.
int numero_source_
const Champ_base & get_champ_compo_without_evaluation(OWN_PTR(Champ_base)&espace_stockage) const
const Champ_base & get_champ(OWN_PTR(Champ_base)&espace_stockage) const override
void set_param(Param &param) const override
int numero_masse_
int compo_
bool sans_solveur_masse_
void verification_cas_compo() const
int numero_op_
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...
const Champ_base & get_champ_without_evaluation(OWN_PTR(Champ_base)&espace_stockage) const override
const Operateur_base & Operateur() const override
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
DoubleTab_t & les_sommets()
Definition Domaine.h:113
IntTab_t & les_elems()
Definition Domaine.h:129
class Domaine_VF
Definition Domaine_VF.h:44
int face_sommets(int i, int j) const
Returns the index of the i-th vertex of face num_face.
Definition Domaine_VF.h:582
const Domaine & domaine() const
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.
virtual Nature_du_champ fixer_nature_du_champ(Nature_du_champ nat)
Sets the nature of a field: scalar, multiscalar, vectorial.
Metadata for a distributed composite vector.
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
const MD_Vector_base & valeur() const
Definition MD_Vector.h:77
A character string (Nom) in uppercase.
Definition Motcle.h:26
An array of Motcle objects.
Definition Motcle.h:63
int search(const Motcle &t) const
Definition Motcle.cpp:319
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
An array of character strings (VECT(Nom)).
Definition Noms.h:26
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
class Operateur_base This class is the base of the hierarchy of objects representing an
virtual DoubleTab & ajouter(const DoubleTab &, DoubleTab &) const
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_flag(const char *keyword, const bool *value)
Register a boolean flag whose mere presence switches it to true.
Definition Param.cpp:474
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
Base class for all post-processing objects.
class Postraitement. The class holds -a list of generic fields champs_post_complet_ containing
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
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")