TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Pb_MED.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 <Pb_MED.h>
17#include <Champ_Fonc_MED.h>
18#include <LireMED.h>
19#include <Postraitement.h>
20#include <Interprete_bloc.h>
21#include <Domaine_dis_cache.h>
22#include <TRUST_2_MED.h>
23#include <Perf_counters.h>
24
25Implemente_instanciable(Pb_MED,"Pb_MED",Probleme_base);
26Implemente_instanciable(Pbc_MED,"Pbc_MED",Probleme_Couple);
27// XD pbc_med pb_gen_base pbc_med NO_BRACE Allows to read med files and post-process them.
28// XD attr list_info_med list_info_med list_info_med REQ not_set
29
30// XD pb_post Pb_base nul INHERITS_BRACE not_set
31// XD info_med objet_lecture nul NO_BRACE not_set
32// XD attr file_med chaine file_med REQ Name of the MED file.
33// XD attr domaine chaine domaine REQ Name of domain.
34// XD attr pb_post pb_post pb_post REQ not_set
35// XD list_info_med listobj nul INHERITS_BRACE info_med COMMA not_set
36
37
38Sortie& Pb_MED::printOn(Sortie& s ) const { return s; }
39Sortie& Pbc_MED::printOn(Sortie& s ) const { return s; }
40
42{
43
44 int nmax=10,npb=0;
45 sch_.typer("Schema_Euler_explicite");
46 //Schema_Euler_explicite& sch=ref_cast(Schema_Euler_explicite,sch_.valeur());
47 Schema_Temps_base& sch=ref_cast(Schema_Temps_base,sch_.valeur());
48 sch.changer_temps_courant(-1.);
50 //Pb_MED* listpb;
51 // Create a list of DerObjU since those are the objects that can be added to the interpreter...
52 DerObjU* listob =new DerObjU[nmax];
53 Motcle accouv("{"),accfer("}"),virg(","),motlu;
54 is >> motlu;
55 if (motlu!=accouv)
56 {
57 Cerr<<" One expects { to begin the read of Pbc_Med"<<finl;
58 exit();
59 }
60 Interprete_bloc inter;
61 while (motlu!=accfer)
62 {
63 assert((motlu==virg)||(motlu==accouv));
64 if (npb>=nmax)
65 {
66 Cerr<<"The number of coupled problems is to large"<<finl;
67 exit();
68 }
69 Nom nom_numero(npb);
70 Nom nompb("pbMED_");
71 nompb+=nom_numero;
72 DerObjU& ob= listob[npb];
73 ob.typer("Pb_MED");
74
75 inter.ajouter(nompb,ob);
76 Pb_MED& pb=ref_cast(Pb_MED,inter.objet_global(nompb));
77 pb.nommer(nompb);
78 associer_(pb);
79
81 is >> pb;
82 npb++;
83 is >> motlu;
84 if ((motlu!=accfer)&&(motlu!=virg))
85 {
86 Cerr<<"One expects } or , between the problems "<<finl;
87 Cerr<<"and not "<<motlu<<finl;
88 exit();
89 }
90 }
91
92 for (int i=0; i<nb_problemes(); i++)
93 ref_cast(Probleme_base,probleme(i)).init_postraitements();
94
95 // Reset the axi flags, since unknowns have already been processed
96 // after init to write the geometry correctly
97 bidim_axi=0;
98 axi=0;
99
100 //const Probleme_base& pb1=les_problemes[0].valeur();
101 Nom name_spe("pbMED_0");
102 const ArrOfDouble& temps_sauv=ref_cast(Pb_MED,inter.objet_global(name_spe)).temps_sauv();
103 int nbpasdetemps=temps_sauv.size_array();
104 Cerr<<"nbpasdetemps "<<nbpasdetemps<<finl;
105 for (int i=0; i<nbpasdetemps; i++)
106 {
107 statistics().begin_count(STD_COUNTERS::update_variables,statistics().get_last_opened_counter_level()+1);
109 statistics().end_count(STD_COUNTERS::update_variables);
110 schema_temps().changer_temps_courant(temps_sauv[i]);
111 postraiter();
112 }
113
114 for (int i=0; i<nb_problemes(); i++)
115 ref_cast(Probleme_base,probleme(i)).finir();
116 delete [] listob;
117 return is;
118}
119
120/*! @brief Simple call to: Probleme_base::readOn(Entree&)
121 *
122 * @param (Entree& is) an input stream
123 * @return (Entree&) the modified input stream
124 */
126{
127 // Start with this because associer from Pb_base is never called
128 save_restart_.assoscier_pb_base(*this);
129
130 dis_bidon.typer("VF_inst");
131 la_discretisation_=dis_bidon.valeur();
132 is >> nom_fic;
133 Nom nom_dom;
134 is >> nom_dom;
135
136 // strip _0000 if present and create the proper file name
137 traite_nom_fichier_med(nom_fic);
138
139 Domaine& dom=ref_cast(Domaine, Interprete::objet(nom_dom));
140 associer_domaine(dom);
141
142 // Read domain in MED file:
143 LireMED lire(nom_fic, nom_dom);
144 lire.associer_domaine(dom);
145 lire.lire_geom(true);
146 dom.reordonner();
147
148 Nom typ = "NO_FACE_Domaine_VF_inst";
149 le_domaine_dis_ = Domaine_dis_cache::Build_or_get(typ, dom);
150
151 Cerr<<"Reading the name of existing fields in "<<nom_fic<<finl;
152 read_med_field_names(nom_fic, nomschampmed, temps_sauv_);
153 Cerr<<"temps_sauv "<<temps_sauv_<<finl;
155 return is;
156}
157
158
159/*! @brief Returns the number of equations in the problem.
160 *
161 * Always equal to 1 for a standard conduction problem.
162 *
163 * @return (int) the number of equations in the problem
164 */
166{
167 return 0;
168}
169
170/*! @brief Returns the MED-type equation if i = 0,
171 *
172 * Otherwise triggers an error since the problem
173 * has only a single equation.
174 * (const version)
175 *
176 * @param (int i) the index of the equation to return
177 * @return (Equation_base&) the MED-type equation
178 */
180{
181 assert(0);
182 exit();
183 assert (i==0);
184 // for the compiler
185
186 return Probleme_base::equation("bidon");
187}
188
189/*! @brief Returns the MED-type equation if i = 0,
190 *
191 * Otherwise triggers an error since the problem
192 * has only a single equation.
193 *
194 * @param (int i) the index of the equation to return
195 * @return (Equation_base&) the MED-type equation
196 */
198{
199 assert(0);
200 exit();
201 // for the compiler
202 return Probleme_base::equation("bidon") ;
203}
204
205int Pb_MED::comprend_champ(const Motcle& mot) const
206{
207 // Cerr<<" Pb_MED::comprend_champ"<<mot <<" " <<nomschampmed<<finl;
208 int nbchampmed=nomschampmed.size();
209 int ind=0;
210 for (int ch=0; ch<nbchampmed; ch++)
211 {
212 if (mot==nomschampmed[ch]) ind= 1;
213 }
214
215 if (ind == 1)
216 return ind;
217
218 if (ind == 0)
219 {
220 Cerr << "Error when reading the data for post-processing" << finl;
221 Cerr << "The field " << mot << " is not recognized by the problem" << finl;
222 Cerr << "recognized words are "<<nomschampmed<<finl;
223 exit();
224 }
225 return -1;
226}
227
228void Pb_MED::creer_champ(const Motcle& motlu)
229{
230 Cerr<<"Pb_MED::creer_champ "<< motlu<<finl;
231 Noms liste_noms;
233 OWN_PTR(Champ_Fonc_base) toto; // we add toto and type it afterwards to avoid copies that do not work ...
234 auto& le_ch_fonc= champs_fonc_post.add(toto);
235 le_ch_fonc.typer("Champ_Fonc_MED");
236 int nbchampmed=nomschampmed.size();
237
238 Nom localisation;
239 Motcle es;
240 le_ch_fonc->nommer(motlu);
241
242 int flag=0;
243 Nom test("_");
244 test+=domaine().le_nom();
245
246 for (int ch=0; ch<nbchampmed; ch++)
247 {
248 Nom pp(nomschampmed[ch]);
249 pp.prefix(test);
250 //Cerr<<test<<" ICI "<<pp<<" "<<motlu<<finl;
251 if (motlu==pp)
252 {
253 es=pp;
254 es.prefix("_SOM");
255 if (es!=pp)
256 localisation="som";
257 else
258 {
259 es.prefix("_ELEM");
260 if (es!=pp)
261 localisation="elem";
262 }
263 Cerr<<"One wishes to read the field "<<es<<" choice "<<localisation<<" readen word in the data set "<<motlu<<finl;
264 le_ch_fonc->nommer(es);
265 flag=1;
266 }
267 }
268 Champ_Fonc_MED& chmed=ref_cast(Champ_Fonc_MED,le_ch_fonc.valeur());
269 const Domaine& dom_med = domaine();
270 chmed.creer(nom_fic,dom_med,localisation, temps_sauv_);
271
272 if (flag)
273 {
274 chmed.le_champ().nommer(le_ch_fonc->le_nom());
276 chmed.le_champ().nommer(motlu);
277 }
278
279 le_ch_fonc->nommer(motlu);
280 chmed.le_champ().nommer(motlu);
281 if (!le_ch_fonc)
282 {
283 Cerr << "Error when reading data for post-processing" << finl;
284 Cerr << "The creation of the field " << motlu << " has failed." << finl;
285 exit();
286 }
287}
288
289bool Pb_MED::has_champ(const Motcle& un_nom, OBS_PTR(Champ_base) &ref_champ) const
290{
291 for (const auto &itr : champs_fonc_post)
292 {
293 if (Motcle(itr->le_nom()) == un_nom)
294 {
295 ref_champ = Pb_MED::get_champ(un_nom);
296 return true;
297 }
298 else
299 for (int i = 0; i < itr->nb_comp(); i++)
300 if (Motcle(itr->nom_compo(i)) == un_nom)
301 {
302 ref_champ = Pb_MED::get_champ(un_nom);
303 return true;
304 }
305 }
306
307 return false; /* nothing found */
308}
309
310bool Pb_MED::has_champ(const Motcle& un_nom) const
311{
312 for (const auto &itr : champs_fonc_post)
313 {
314 if (Motcle(itr->le_nom()) == un_nom)
315 return true;
316 else
317 for (int i = 0; i < itr->nb_comp(); i++)
318 if (Motcle(itr->nom_compo(i)) == un_nom)
319 return true;
320 }
321
322 return false; /* nothing found */
323}
324
325const Champ_base& Pb_MED::get_champ(const Motcle& un_nom) const
326{
327 double temps_courant = schema_temps().temps_courant();
328
329 for (const auto &itr : champs_fonc_post)
330 {
331 Champ_Fonc_MED& ch_med = ref_cast_non_const(Champ_Fonc_MED, itr.valeur());
332 if (Motcle(itr->le_nom()) == un_nom)
333 {
334 if (ch_med.temps() != temps_courant)
335 ch_med.mettre_a_jour(temps_courant);
336
337 return ch_med.le_champ();
338 }
339 else
340 {
341 for (int i = 0; i < itr->nb_comp(); i++)
342 if (Motcle(itr->nom_compo(i)) == un_nom)
343 {
344 if (ch_med.temps() != temps_courant)
345 ch_med.mettre_a_jour(temps_courant);
346
347 return ch_med.le_champ();
348 }
349 }
350 }
351
352 Cerr<<"The indicated name "<<un_nom<<" do not correspond to a field understood by the problem"<<finl;
353 Cerr<<"Check the field name to indicate in the post-processing set"<<finl;
354 exit();
355
356 throw std::runtime_error(std::string("Field ") + un_nom.getString() + std::string(" not found !"));
357}
358
359void Pb_MED::get_noms_champs_postraitables(Noms& noms, Option opt) const
360{
361 // This method overrides the one in Probleme_base
362 if (opt == DESCRIPTION)
363 Cerr << "Pb_MED : " << nomschampmed << finl;
364 else
365 noms.add(nomschampmed);
366}
class Champ_Fonc_MED Load a field from a MED file for a given time.
int creer(const Nom &, const Domaine &dom, const Motcle &localisation, ArrOfDouble &temps_sauv)
void mettre_a_jour(double) override
Time update of the field.
virtual const Champ_Fonc_base & le_champ() const
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
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.
void corriger_unite_nom_compo()
This method will set the units and the name of components, it is not actually const!...
int postraiter(int force=1) override
Asks the problem to post-process its fields, probes, etc.
const Probleme_U & probleme(int i) const
Definition Couplage_U.h:127
int nb_problemes() const
Definition Couplage_U.h:117
void reordonner()
Definition Domaine.h:104
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
static Domaine_dis_base & Build_or_get(const Nom &type, const Domaine &dom, const Discretisation_base *disc=nullptr)
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....
void nommer(const Nom &) override
Gives a name to the field.
Objet_U & ajouter(const Nom &nom, DerObjU &object_to_add)
Adds object ob to the interpreter's object list and names it with nom.
static Objet_U & objet_global(const Nom &nom)
Searches for the requested object in the current Interprete_bloc (Interprete_bloc::interprete_courant...
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Nom & prefix(const char *const)
Definition Nom.cpp:324
const std::string & getString() const
Definition Nom.h:92
An array of character strings (VECT(Nom)).
Definition Noms.h:26
Objet_U * typer(const char *nom_type)
Tries to create an instance of type "type".
virtual void nommer(const Nom &)
Assigns a name to the Objet_U. Virtual method to override.
Definition Objet_U.cpp:327
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
static int bidim_axi
Definition Objet_U.h:97
static int axi
Definition Objet_U.h:96
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class Pb_MED Class for re-reading MED files and post-processing them.
Definition Pb_MED.h:28
const Champ_base & get_champ(const Motcle &nom) const override
Definition Pb_MED.cpp:325
const Equation_base & equation(int) const override
Returns the MED-type equation if i = 0,.
Definition Pb_MED.cpp:179
Champs_Fonc champs_fonc_post
Definition Pb_MED.h:53
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
Definition Pb_MED.cpp:289
int nombre_d_equations() const override
Returns the number of equations in the problem.
Definition Pb_MED.cpp:165
int comprend_champ(const Motcle &) const
Definition Pb_MED.cpp:205
void get_noms_champs_postraitables(Noms &nom, Option opt=NONE) const override
Definition Pb_MED.cpp:359
void creer_champ(const Motcle &motlu) override
Definition Pb_MED.cpp:228
void begin_count(const STD_COUNTERS &std_cnt, int counter_lvl=-100000)
void end_count(const std::string &custom_count_name, int count_increment=1, long int quantity_increment=0)
End the count of a counter and update the counter values.
Probleme_Couple This is the historical coupling class of TRUST.
virtual void associer_sch_tps_base(Schema_Temps_base &)
Associates a copy of the time scheme with each problem of the coupled problem.
int associer_(Objet_U &) override
Overrides Objet_U::associer_(Objet_U&): associates an object with the coupled problem,...
virtual const Schema_Temps_base & schema_temps() const
Returns the time scheme associated with the coupled problems (const version).
void nommer(const Nom &name) override
Assigns a name to the Objet_U. Virtual method to override.
Definition Probleme_U.h:108
class Probleme_base It is a Probleme_U that is not a coupling.
virtual void associer_domaine(const Domaine &)
Associates a domain with the problem.
const Domaine & domaine() const
Returns the domain associated with the problem.
Save_Restart save_restart_
virtual void associer_sch_tps_base(const Schema_Temps_base &)
Associates a time scheme with the problem.
const Schema_Temps_base & schema_temps() const
Returns the time scheme associated with the problem.
OBS_PTR(Field_base) findInputField(const Nom &name) const override
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
double temps_courant() const
Returns the current time.
virtual void changer_temps_courant(const double)
Changes the current time.
virtual int mettre_a_jour()
Updates the current time (t+=dt) and the number of time steps performed (nb_pas_dt_++).
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const