TrioCFD 1.9.8
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 // On cree une liste de DerObjU car c'est eux que l'on peut ajouter a l'interprete...
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 // On oublie les axi, car les inconnues ont deja eu le traitement
96 // apres l'init pour ecrire correctement les geom
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 appel a: Probleme_base::readOn(Entree&)
121 *
122 * @param (Entree& is) un flot d'entree
123 * @return (Entree&) le flot d'entree modifie
124 */
126{
127 // On commence par ca car assoscier de Pb_base est jamais appele
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 // on retire _0000 si il existe et on cree le bon fichier
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 Renvoie le nombre d'equations du probleme.
160 *
161 * Toujours egal a 1 pour un probleme de conduction standart.
162 *
163 * @return (int) le nombre d'equations du probleme
164 */
166{
167 return 0;
168}
169
170/*! @brief Renvoie l'equation de type MED si i = 0,
171 *
172 * Provoque une erreur sinon car le probleme
173 * n'a qu'une seule equation.
174 * (version const)
175 *
176 * @param (int i) l'index de l'equation a renvoyer
177 * @return (Equation_base&) l'equation de type MED
178 */
180{
181 assert(0);
182 exit();
183 assert (i==0);
184 //pour les compilos
185
186 return Probleme_base::equation("bidon");
187}
188
189/*! @brief Renvoie l'equation de type MED si i = 0,
190 *
191 * Provoque une erreur sinon car le probleme
192 * n'a qu'une seule equation.
193 *
194 * @param (int i) l'index de l'equation a renvoyer
195 * @return (Equation_base&) l'equation de type MED
196 */
198{
199 assert(0);
200 exit();
201 //pour les compilos
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; // on ajoute toto et on le type apres pour eviter des copies qui ne marchent pas ...
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; /* rien trouve */
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; /* rien trouve */
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 //La methode surcharge celle de Probleme_base
362 if (opt == DESCRIPTION)
363 Cerr << "Pb_MED : " << nomschampmed << finl;
364 else
365 noms.add(nomschampmed);
366}
classe 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
Mise a jour en temps du champ.
virtual const Champ_Fonc_base & le_champ() const
classe Champ_Fonc_base Classe de base des champs qui sont fonction d'une grandeur calculee
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
double temps() const
Renvoie le temps du champ.
void corriger_unite_nom_compo()
cette methode va fixer les unites et le nom des compos elle n'est pas const en realite !...
int postraiter(int force=1) override
Demande au probleme de postraiter ses champs, sondes,.
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
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette 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
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
void nommer(const Nom &) override
Donne un nom au champ.
Objet_U & ajouter(const Nom &nom, DerObjU &object_to_add)
Ajoute l'objet ob a la liste des objets de l'interprete, et nomme l'objet avec nom.
static Objet_U & objet_global(const Nom &nom)
cherche l'objet demande dans l'Interprete_bloc courant (Interprete_bloc::interprete_courant()) et dan...
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Nom & prefix(const char *const)
Definition Nom.cpp:329
const std::string & getString() const
Definition Nom.h:92
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
Objet_U * typer(const char *nom_type)
Essaie de creer une instance du type "type".
virtual void nommer(const Nom &)
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
Definition Objet_U.cpp:329
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
static int bidim_axi
Definition Objet_U.h:102
static int axi
Definition Objet_U.h:101
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
Classe Pb_MED Classe pour postraiter relire des fichiers med et les postraiter.
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
Renvoie l'equation de type MED si 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
Renvoie le nombre d'equations du probleme.
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.
classe Probleme_Couple C'est la classe historique de couplage de TRUST.
virtual void associer_sch_tps_base(Schema_Temps_base &)
Associe une copie du schema en temps a chaque probleme du Probleme couple.
int associer_(Objet_U &) override
Surcharge Objet_U::associer_(Objet_U&) Associe un objet au probleme couple, en verifiant le type.
virtual const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe aux problemes couples.
void nommer(const Nom &name) override
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
Definition Probleme_U.h:108
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
virtual void associer_domaine(const Domaine &)
Associe un domaine au probleme.
const Domaine & domaine() const
Renvoie le domaine associe au probleme.
Save_Restart save_restart_
virtual void associer_sch_tps_base(const Schema_Temps_base &)
Associe un schema en temps au probleme.
const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe au probleme.
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)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
double temps_courant() const
Renvoie le temps courant.
virtual void changer_temps_courant(const double)
Change le temps courant.
virtual int mettre_a_jour()
Mise a jour du temps courant (t+=dt) et du nombre de pas de temps effectue (nb_pas_dt_++).
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ size_array() const