TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Gen_de_Champs_Gen.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_Gen_de_Champs_Gen.h>
17#include <Champ_Generique_refChamp.h>
18#include <Discretisation_base.h>
19#include <Champ_Fonc_base.h>
20#include <Champs_compris.h>
21#include <Param.h>
22
23Implemente_base(Champ_Gen_de_Champs_Gen,"Champ_Gen_de_Champs_Gen",Champ_Generique_base);
24
25// XD champ_post_de_champs_post champ_generique_base champ_post_de_champs_post INHERITS_BRACE not_set
26
28{
30}
31
33{
34 exit();
35 return os;
36}
37
38// source : triggers the reading of the generic source field
39// sources_reference : triggers the reading of the name of one or more generic fields that must
40// already be defined in order to initialize a reference to that field
41// nom_source : option to name the field as a source (otherwise named by default)
43{
44 param.ajouter_non_std("source",(this)); // XD attr source champ_generique_base source OPT the source field.
45 param.ajouter_non_std("sources",(this)); // XD attr sources listchamp_generique sources OPT sources { Champ_Post.... {
46 // XD_CONT ... } Champ_Post.. { ... }}
47 param.ajouter_non_std("nom_source",(this)); // XD attr nom_source chaine nom_source OPT To name a source field with
48 // XD_CONT the nom_source keyword
49 param.ajouter_non_std("source_reference",(this)); // XD attr source_reference chaine source_reference OPT not_set
50 param.ajouter("sources_reference",&noms_sources_ref_); // XD attr sources_reference list_nom_virgule sources_reference OPT not_set
51}
52
54{
55 if (mot=="source")
56 {
57 OWN_PTR(Champ_Generique_base)& new_src = sources_.add(OWN_PTR(Champ_Generique_base)());
58 Nom typ;
59 is >> typ;
60 Journal() << "Reading a source type " << typ << finl;
61 new_src.typer(typ);
62 is >> new_src.valeur();
63 return 1;
64 }
65 else if (mot=="source_reference")
66 {
67 Nom& new_s = noms_sources_ref_.add(Nom());
68 is >> new_s;
69 Cerr<<"WARNING : obsolete option. Use now sources_reference { " << new_s<< " } instead of source_reference "<<new_s<<finl;
70 return 1;
71 }
72 else if (mot=="sources")
73 {
74 Nom accouverte="{";
75 Nom accfermee="}";
76 Nom virgule=",";
77 Nom typ;
78 is >> typ;
79 if (typ!=accouverte) Process::exit("We are waiting a { !");
80 is >> typ;
81 if(typ==accfermee)
82 {
83 Cerr<<"We should not use the keyword \"sources\" to specify a generic field"<<finl;
84 Cerr<<"of type Champ_Gen_de_Champs_Gen without specifying sources"<<finl;
85 exit();
86 }
87 while(1)
88 {
89 OWN_PTR(Champ_Generique_base)& new_src = sources_.add(OWN_PTR(Champ_Generique_base)());
90 Journal() << "Reading a source type " << typ << finl;
91 new_src.typer(typ);
92 is >> new_src.valeur();
93 is >> typ;
94 if(typ==accfermee)
95 break;
96 if(typ!=virgule)
97 {
98 Cerr << typ << " : We expected a ',' or '}'" << finl;
99 exit();
100 }
101 is >> typ;
102 }
103 return 1;
104 }
105 else if (mot=="nom_source")
106 {
107 Nom id_source;
108 is >> id_source;
109 nommer(id_source);
110 return 1;
111 }
112 else
114}
115
117{
118 sources_.vide();
119}
120
122{
123 const int n = sources_.size();
124 for (int i = 0; i < n; i++)
125 sources_[i]->mettre_a_jour(temps);
126}
127
128OWN_PTR(Champ_Fonc_base)& Champ_Gen_de_Champs_Gen::creer_espace_stockage(const Nature_du_champ& nature,
129 const int nb_comp,
130 OWN_PTR(Champ_Fonc_base)& es_tmp) const
131{
132 if (es_tmp)
133 {
134 ToDo_Kokkos("critical, call to creer_espace_stockage() is expensive on GPU (fields copy on host). Refactor like Champ_Generique_Moyenne and other advanced fields...");
135 }
136 Noms noms;
137 Noms unites;
138 for (int c=0; c<nb_comp; c++)
139 unites.add("??");
140 noms.add("bidon");
141 double temps;
142 temps = get_time();
143 const Discretisation_base& discr = get_discretisation();
144 Motcle directive = get_directive_pour_discr();
145 const Domaine_dis_base& domaine_dis = get_ref_domaine_dis_base();
146
147 discr.discretiser_champ(directive,domaine_dis,nature,noms,unites,nb_comp,temps,es_tmp);
148
149 if (directive=="pression")
150 {
151 const Domaine_Cl_dis_base& zcl = get_ref_zcl_dis_base();
152 es_tmp->completer(zcl);
153 }
154 return es_tmp;
155}
156
158{
159 // If sources_ and source_ref are empty, we should not be here
160 if ((sources_reference_.size()==0) && (sources_.size()==0))
161 {
162 Cerr << finl;
163 Cerr << "Error : The field \"" << noms_sources_ref_ << "\" is not recognized in the sources_reference option of the " << que_suis_je() << " keyword." << finl;
164 Cerr << "\"" << noms_sources_ref_ << "\" should be defined before." << finl;
165 exit();
166 }
167 int n_sources_ref=sources_reference_.size();
168 if (i<n_sources_ref)
169 {
170 if ( !sources_reference_[i])
171 {
172 Cerr << finl;
173 Cerr << "Error : The field \"" << noms_sources_ref_[0] << "\" is not recognized in the sources_reference option of the " << que_suis_je() << " keyword." << finl;
174 Cerr << "\"" << noms_sources_ref_[0] << "\" should be defined before." << finl;
175 exit();
176 }
177 return sources_reference_[i].valeur();
178 }
179 else
180 return sources_[i-n_sources_ref].valeur();
181}
182
184{
185 // To avoid recoding the same thing as get_source
186 return ref_cast_non_const(Champ_Generique_base,get_source(i));
187}
188
189
191{
192 return sources_reference_.size()+sources_.size();
193}
194
195/*! @brief for PDI IO: retrieve name, type and dimensions of the field to save/restore
196 *
197 */
199{
200 std::vector<YAML_data> data;
201 const int n = sources_.size();
202 for (int i = 0; i < n; i++)
203 {
204 std::vector<YAML_data> source_data = sources_[i]->data_a_sauvegarder();
205 data.insert(data.end(), source_data.begin(), source_data.end());
206 }
207 return data;
208}
209
210/*! @brief save the different sources
211 *
212 */
214{
215 const int n = sources_.size();
216 int bytes = 0;
217 for (int i = 0; i < n; i++)
218 bytes += sources_[i]->sauvegarder(os);
219 return bytes;
220}
221
222/*! @brief resume the different sources
223 *
224 */
226{
227 const int n = sources_.size();
228 for (int i = 0; i < n; i++)
229 sources_[i]->reprendre(is);
230 return 1;
231}
232
234{
235 int n_sources_ref=noms_sources_ref_.size();
236 if ( n_sources_ref!=sources_reference_.size())
237 {
238 sources_reference_.vide();
239 for (int i=0; i<n_sources_ref; i++)
240 {
241 OBS_PTR(Champ_Generique_base)& source_ref=sources_reference_.add(OBS_PTR(Champ_Generique_base)());
242 const Postraitement& postraitement =ref_cast(Postraitement,post);
243 source_ref = postraitement.get_champ_post(noms_sources_ref_[i]);
244 }
245 }
246 const int n = get_nb_sources();
247 for (int i = n_sources_ref ; i < n; i++)
248 {
249 Champ_Generique_base& source_a_completer = ref_cast(Champ_Generique_base,set_source(i));
250 if (sub_type(Champ_Gen_de_Champs_Gen,source_a_completer))
251 {
252 Champ_Gen_de_Champs_Gen& champ = ref_cast(Champ_Gen_de_Champs_Gen,source_a_completer);
253 const Nom& my_parent = champ.get_parent_name();
254 Nom me = my_parent == "??" ? nom_post_ : my_parent + "_" + nom_post_;
255 champ.set_parent_name(me);
256 }
257 source_a_completer.completer(post);
258 }
259
260 const Probleme_base& pb = get_ref_pb_base();
261 const Nom& nom_pb = pb.le_nom();
262 nom_pb_ = nom_pb;
263
265}
266
267//Additional methods
272
277
278
280{
281 Motcles motcles(1);
282 motcles[0] = "nom";
283 int rang = motcles.search(query);
284 switch(rang)
285 {
286 case 0:
287 {
288 Noms mots(1);
289 mots[0] = nom_post_;
290 return mots;
291 }
292 }
293 return get_source(0).get_property(query);
294}
295
296Entity Champ_Gen_de_Champs_Gen::get_localisation(const int index) const
297{
298 return get_source(0).get_localisation(index);
299}
300
302{
303 return get_source(0).get_ref_values();
304}
305
306void Champ_Gen_de_Champs_Gen::get_copy_values(DoubleTab& values) const
307{
308 const DoubleTab& val = get_ref_values();
309 // Creates a copy of the array
310 values = val;
311}
312
313void Champ_Gen_de_Champs_Gen::get_xyz_values(const DoubleTab& coords, DoubleTab& values, ArrOfBit& validity_flag) const
314{
315 throw Champ_Generique_erreur("NOT_IMPLEMENTED");
316}
317
319{
320 return get_source(0).get_ref_domain();
321}
322
324{
325 return get_source(0).get_copy_domain(domain);
326}
327
332
337
339{
341}
342
343void Champ_Gen_de_Champs_Gen::get_copy_coordinates(DoubleTab& coordinates) const
344{
345 get_source(0).get_copy_coordinates(coordinates);
346}
347
348const IntTab& Champ_Gen_de_Champs_Gen::get_ref_connectivity(Entity index1, Entity index2) const
349{
350 return get_source(0).get_ref_connectivity(index1,index2);
351}
352
353void Champ_Gen_de_Champs_Gen::get_copy_connectivity(Entity index1, Entity index2, IntTab& tab) const
354{
355 get_source(0).get_copy_connectivity(index1,index2,tab);
356}
357
359{
360 return get_source(0).get_time();
361}
362
367
372
377
379{
380 int nb_sources = get_nb_sources();
381 for (int i=0; i<nb_sources; i++)
382 {
383 if (sub_type(Champ_Gen_de_Champs_Gen,sources_[i].valeur()))
384 {
385 Champ_Gen_de_Champs_Gen& champ = ref_cast(Champ_Gen_de_Champs_Gen,sources_[i].valeur());
386 champ.nommer_sources(post);
387 champ.nommer_source();
388 }
389 else if (sub_type(Champ_Generique_refChamp,sources_[i].valeur()))
390 {
391 Champ_Generique_refChamp& champ = ref_cast(Champ_Generique_refChamp,sources_[i].valeur());
392 champ.nommer_source(post);
393 }
394 else
395 {
396 Cerr<<"There is no method nommer_source() for this type of field "<<finl;
397 Cerr<<"sources_[i]->que_suis_je()"<<finl;
398 exit();
399 }
400 }
401}
402
403//This method must be overridden for each Champ_Gen_de_Champs_Gen
408
414
415//Methods to change t_deb and t_fin for statistics restarts
416void Champ_Gen_de_Champs_Gen::fixer_serie(const double t1, const double t2)
417{
418 const int n = get_nb_sources();;
419 for (int i = 0; i < n; i++)
420 {
421 if (sub_type(Champ_Gen_de_Champs_Gen,get_source(i)))
422 {
424 source.fixer_serie(t1,t2);
425 }
426 }
427}
428
429void Champ_Gen_de_Champs_Gen::fixer_tstat_deb(const double t1, const double t2)
430{
431 const int n = get_nb_sources();;
432 for (int i = 0; i < n; i++)
433 {
434 if (sub_type(Champ_Gen_de_Champs_Gen,get_source(i)))
435 {
437 source.fixer_tstat_deb(t1,t2);
438 }
439 }
440}
441
443{
444
445 const int n = get_nb_sources();;
446 for (int i = 0; i < n; i++)
447 {
448 if (sub_type(Champ_Gen_de_Champs_Gen,get_source(i)))
449 {
451 source.lire_bidon(is);
452 }
453 }
454}
455
457{
459 return true;
460
461 if (get_source(0).has_champ_post(nom))
462 return true;
463
464 return false; /* nothing found */
465}
466
468{
471
472 if (get_source(0).has_champ_post(nom))
473 return get_source(0).get_champ_post(nom);
474
475 throw std::runtime_error(std::string("Field ") + nom.getString() + std::string(" not found !"));
476}
477
479{
481 return 1;
482 else if (get_source(0).comprend_champ_post(identifiant))
483 return 1;
484
485 return 0;
486}
487
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...
void get_copy_values(DoubleTab &) const override
Fills the values array with the discrete values of the field (creates a copy).
void mettre_a_jour(double temps) override
int sauvegarder(Sortie &os) const override
save the different sources
const IntTab & get_ref_connectivity(Entity index1, Entity index2) const override
Returns the connectivity array between the geometric entity index1 and entity index2.
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 DoubleTab & get_ref_coordinates() const override
Returns a reference to the array of coordinates of the vertices of the mesh supporting the field,...
virtual void lire_bidon(Entree &is) const
int comprend_champ_post(const Motcle &identifiant) const override
void nommer_sources(const Postraitement_base &post)
int get_info_type_post() const override
virtual void fixer_tstat_deb(const double t1, const double t2)
const Noms get_property(const Motcle &query) const override
Returns the requested property.
const Champ_Generique_base & get_champ_post(const Motcle &nom) const override
virtual OWN_PTR(Champ_Fonc_base) &creer_espace_stockage(const Nature_du_champ &nature
void completer(const Postraitement_base &post) override
int reprendre(Entree &is) override
resume the different sources
const Probleme_base & get_ref_pb_base() const override
Returns the problem that carries the target field.
void get_property_names(Motcles &list) const override
Returns the list of possible "queries" for the field.
void get_copy_coordinates(DoubleTab &) const override
std::vector< YAML_data > data_a_sauvegarder() const override
for PDI IO: retrieve name, type and dimensions of the field to save/restore
void get_copy_connectivity(Entity index1, Entity index2, IntTab &) const override
void get_xyz_values(const DoubleTab &coords, DoubleTab &values, ArrOfBit &validity_flag) const override
Computes the point value of the field at the coordinates given in coords and puts them in values.
int get_dimension() const override
Returns the dimension of the space in which the field is defined.
const Domaine & get_ref_domain() const override
Returns a ref to the domain on which the storage space will be evaluated.
void get_copy_domain(Domaine &) const override
Creates a copy of the domain on which the storage space will be evaluated.
bool has_champ_post(const Motcle &nom) const override
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
virtual Champ_Generique_base & set_source(int i)
const Motcle get_directive_pour_discr() const override
Returns the directive (champ_elem, champ_sommets, champ_face or pression) to launch the discretizatio...
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.
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
virtual void fixer_serie(const double t1, const double t2)
const DoubleTab & get_ref_values() const override
Returns a reference to the array of discrete values if it exists in memory.
class Champ_Generique_base
virtual const Noms get_property(const Motcle &query) const
Returns the requested property.
virtual const Domaine_dis_base & get_ref_domaine_dis_base() const
Returns a ref to the discretized domain on which the storage space will be evaluated.
virtual bool has_champ_post(const Motcle &nom) const
virtual void get_property_names(Motcles &list) const
Returns the list of possible "queries" for the field.
virtual const IntTab & get_ref_connectivity(Entity index1, Entity index2) const
Returns the connectivity array between the geometric entity index1 and entity index2.
virtual int comprend_champ_post(const Motcle &identifiant) const
virtual void get_copy_connectivity(Entity index1, Entity index2, IntTab &) const
virtual const Champ_Generique_base & get_champ_post(const Motcle &nom) const
virtual const Domaine_Cl_dis_base & get_ref_zcl_dis_base() const
Returns a ref to the discretized boundary conditions domain of the equation carrying the target field...
virtual double get_time() const
Returns the time of the Champ_Generique_base.
virtual int get_dimension() const
Returns the dimension of the space in which the field is defined.
virtual int get_info_type_post() const =0
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
virtual void get_copy_domain(Domaine &) const
Creates a copy of the domain on which the storage space will be evaluated.
virtual const DoubleTab & get_ref_coordinates() const
Returns a reference to the array of coordinates of the vertices of the mesh supporting the field,...
virtual const DoubleTab & get_ref_values() const
Returns a reference to the array of discrete values if it exists in memory.
virtual const Probleme_base & get_ref_pb_base() const
Returns the problem that carries the target field.
virtual Entity get_localisation(const int index=-1) const
Returns the type of geometric entities on which the discrete values are attached (NODE for a P1 field...
virtual void get_copy_coordinates(DoubleTab &) const
void nommer(const Nom &nom) override
Assigns a name to the Objet_U. Virtual method to override.
virtual const Domaine & get_ref_domain() const
Returns a ref to the domain on which the storage space will be evaluated.
virtual const Motcle get_directive_pour_discr() const
Returns the directive (champ_elem, champ_sommets, champ_face or pression) to launch the discretizatio...
virtual const Discretisation_base & get_discretisation() const
Returns the discretization associated with the problem.
OBS_PTR(Probleme_base) ref_pb_
virtual void completer(const Postraitement_base &post)=0
Special field class that encapsulates a reference to a volume field of TRUST of type Champ_base.
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
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
const std::string & getString() const
Definition Nom.h:92
An array of character strings (VECT(Nom)).
Definition Noms.h:26
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
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
Base class for all post-processing objects.
class Postraitement. The class holds -a list of generic fields champs_post_complet_ containing
virtual const Champ_Generique_base & get_champ_post(const Motcle &nom) const
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
class Probleme_base It is a Probleme_U that is not a coupling.
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
Definition Process.cpp:592
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
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