TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Objet_U.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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 <Objet_U.h>
17#include <Nom.h>
18
19#ifndef LATATOOLS
20#include <Memoire.h>
21#include <Interprete_bloc.h>
22#include <Lire.h>
23
26int Objet_U::axi=0;
28int Objet_U::static_obj_counter_=0;
30Interprete* Objet_U::l_interprete=0;
31
32bool Objet_U::disable_TU=false; ///< Flag to disable or not the writing of the .TU files
33bool Objet_U::stat_per_proc_perf_log=false; ///< Flag to enable the writing of the statistics detailed per processor in _csv.TU file
35
36// Permet de debugger en remontant a la creation d'un objet donne:
37static int object_id_to_track = -1;
38
39// Fonction utilitaire pour intercepter la creation d'un objet
40// ATTENTION: depuis gcc3, le compilo genere plusieurs routines pour
41// chaque constructeur: au moins Objet_U::Objet_U() et Objet_U::Objet_U$base()
42// Cela rend difficile l'utilisation de breakpoints dans ces routines.
43// Poser le breakpoint ici:
44static void object_trap(int obj_id)
45{
46 Cerr << "Objet_U::Objet_U() : object_id_=" << obj_id << finl;
47}
48
49/*! @brief Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_), et enregistre l'objet en "memoire"
50 *
51 * en lui donnant un numero _num_obj_. L'object_id_ et tres
52 * pratique pour debugger...
53 *
54 */
56 object_id_(static_obj_counter_++)
57{
58 int obj_id = object_id_;
59 if (obj_id == object_id_to_track)
60 {
61 object_trap(obj_id);
62 }
63 Memoire& memoire = Memoire::Instance();
64 _num_obj_ = memoire.add(this);
65}
66
67/*! @brief Constructeur par copie.
68 *
69 * Cree un nouveau numero d'objet (ne copie pas le numero de l'autre objet !)
70 *
71 */
73 object_id_(static_obj_counter_++)
74{
75 int obj_id = object_id_;
76 if (obj_id == object_id_to_track)
77 {
78 object_trap(obj_id);
79 }
80 Memoire& memoire = Memoire::Instance();
81 _num_obj_ = memoire.add(this);
82}
83
84/*! @brief Operateur= : ne fait rien (on conserve le numero et l'identifiant)
85 *
86 */
88{
89 return *this;
90}
91
92/*! @brief Renvoie l'identifiant unique de l'objet object_id_
93 *
94 */
96{
97 return object_id_;
98}
99
100/*! @brief renvoie la chaine identifiant la classe.
101 *
102 * @return (const Nom&) Nom identifiant la classe de l'objet
103 */
105{
106 return get_info()->name();
107}
108
109/*! @brief Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
110 *
111 * @param (Motcle& motlu) le nom du terme a lire
112 * @param (Entree& is) un flot d'entree
113 * @return (int) negative value if the keyword is not understood, otherwise positive value.
114 */
116{
117 Cerr << "The method " << __func__ << " must be overloaded in " << que_suis_je() << " !!!!" << finl;
119 return -1;
120}
121
122/*! @brief Donne des informations sur le type de l'Objet_U
123 *
124 * @return (const Type_info*) structure regroupant les informations sur le type de l'Objet_U
125 */
127{
128 return &info_obj;
129}
130
131
132/*! @brief Donne des informations sur le type de l'Objet_U
133 *
134 * @return (const Type_info*) structure regroupant les informations sur le type de l'Objet_U
135 */
137{
138 return &info_obj;
139}
140
141/*! @brief Renvoie une reference constante vers le nom du cas.
142 *
143 * Cette methode est statique.
144 *
145 */
147{
148 return get_set_nom_du_cas();
149}
150
151/*! @brief Renvoie une reference non constante vers le nom du cas (pour pouvoir le modifier).
152 *
153 * Cette methode est statique.
154 *
155 */
157{
158 // Cet objet statique est construit au premier appel
159 // a la fonction.
160 static Nom nom_du_cas_;
161 return nom_du_cas_;
162}
163
164/*! @brief methode ajoutee pour caster en python
165 *
166 */
168{
169 return ref_cast_non_const(Objet_U,obj);
170}
172{
173 return ref_cast_non_const(Objet_U,obj);
174}
175
176/*! @brief Change le numero interne de l'Objet_U
177 *
178 * @param (const int* const new_ones) tableau compose des nouveaux numeros, indexe par les anciens numeros
179 * @return (int) le nouveau numero affecte a l'Objet_U
180 */
181int Objet_U::change_num(const int* const new_ones)
182{
183 return _num_obj_=new_ones[_num_obj_];
184}
185
186
187/*! @brief Donne le nom du type de l'Objet_U
188 *
189 * @return (const char*) chaine de caracteres representant le type de l'Objet_U
190 */
191const char* Objet_U::le_type() const
192{
193 return get_info()->name();
194}
195
196/*! @brief Associe l'Objet_U a un autre Objet_U Methode virtuelle a surcharger
197 *
198 * @param (Objet_U&) l'Objet_U avec lequel doit s'effectuer l'association
199 * @return (int) code de retour
200 */
202{
203 return 0;
204}
205
206static Interprete& interprete_bidon()
207{
208 static Lire bidon;
209 return bidon;
210}
211// BM : a supprimer a terme (utiliser Interprete::objet)
213{
214 return interprete_bidon();
215}
216
217// BM : a supprimer a terme (utiliser Interprete::objet)
219{
220 return interprete_bidon();
221}
222
223/*! @brief retourne x.
224 *
225 * est_egal_a(y)
226 *
227 * @param (const Objet_U& x) Objet_U a utiliser pour la comparaison
228 * @param (const Objet_U& y) Objet_U a utiliser pour la comparaison
229 * @return (int) 1 si les deux Objet_U sont egaux, 0 sinon
230 */
231int operator==(const Objet_U& x, const Objet_U& y)
232{
233 return x.est_egal_a(y);
234}
235
236/*! @brief Comparaison de deux Objet_U x et y Renvoie 1 - x.
237 *
238 * est_egal_a(y);
239 *
240 * @param (const Objet_U& x) Objet_U a utiliser pour la comparaison
241 * @param (const Objet_U& y) Objet_U a utiliser pour la comparaison
242 * @return (int) 1 si les deux Objet_U sont differents, 0 s'ils sont egaux
243 */
244int operator!=(const Objet_U& x, const Objet_U& y)
245{
246 return (1-(x.est_egal_a(y)));
247}
248
249#endif // LATATOOLS
250
251double Objet_U::precision_geom = 1e-10;
252
253/*! @brief Destructeur, supprime l'objet de la liste d'objets enregistres dans "memoire".
254 *
255 */
257{
258#ifndef LATATOOLS
259 Memoire& memoire = Memoire::Instance();
260 memoire.suppr(_num_obj_);
261 _num_obj_ = -2; // Paranoia
262#endif
263}
264
265/*! @brief Renvoie l'indice de l'objet dans Memoire::data
266 *
267 */
269{
270#ifndef LATATOOLS
271 return _num_obj_;
272#else
273 return 0;
274#endif
275}
276
277/*! @brief Ecriture de l'objet sur un flot de sortie Methode a surcharger
278 *
279 * @param (Sortie& s) flot de sortie
280 * @return (Sortie&) flot de sortie modifie
281 */
283{
284 return s;
285}
286
287
288/*! @brief Lecture d'un Objet_U sur un flot d'entree Methode a surcharger
289 *
290 * @param (Entree& s) flot d'entree
291 * @return (Entree& s) flot d'entree modifie
292 */
294{
295 return s;
296}
297
298/*! @brief Renvoie 1 si l'objet x et *this sont une seule et meme instance (meme adresse en memoire).
299 *
300 */
301int Objet_U::est_egal_a(const Objet_U& x) const
302{
303#ifndef LATATOOLS
304 int resultat;
305 if (&x==this)
306 resultat = 1;
307 else
308 resultat = 0;
309 return resultat;
310#else
311 return 0;
312#endif
313}
314
315/*! @brief Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation
316 *
317 * @return (Nom&) le nom de l'Objet_U
318 */
319const Nom& Objet_U::le_nom() const
320{
321 static Nom inconnu="neant";
322 return inconnu;
323}
324
325/*! @brief Donne un nom a l'Objet_U Methode virtuelle a surcharger
326 *
327 * @param (const Nom&) le nom a affectuer a l'Objet_U
328 */
330{
331}
332
333/*! @brief Reprise d'un Objet_U sur un flot d'entree Methode a surcharger
334 *
335 * @param (Entree&) flot d'entree a utiliser pour la reprise
336 * @return (int) code de retour
337 */
339{
340#ifndef LATATOOLS
341 Cerr << "The method " << __func__ << " must be overloaded in " << que_suis_je() << " !!!!" << finl;
343#endif
344 return 1;
345}
346
347/*! @brief Sauvegarde d'un Objet_U sur un flot de sortie Methode a surcharger
348 *
349 * @param (Sortie&) flot de sortie a utiliser pour la sauvegarde
350 * @return (int) code de retour
351 */
353{
354#ifndef LATATOOLS
355 Cerr << "The method " << __func__ << " must be overloaded in " << que_suis_je() << " !!!!" << finl;
357#endif
358 return 0;
359}
Classe de base des objets "interprete".
Definition Interprete.h:38
Keyword to read an object, typically from a data file.
Definition Lire.h:25
La memoire de Trio-U.
Definition Memoire.h:30
static Memoire & Instance()
Retourne un pointeur sur l'instance de la memoire Cree un nouvel objet memoire si aucune instance n'a...
Definition Memoire.cpp:32
int suppr(int)
Suppression de la memoire de l'Objet_U de numero num L'Objet_U n'est pas supprime,...
Definition Memoire.cpp:105
int add(Objet_U *)
Ajoute un Objet_U dans la Memoire de TRUST.
Definition Memoire.cpp:54
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
friend int operator!=(const Objet_U &, const Objet_U &)
Comparaison de deux Objet_U x et y Renvoie 1 - x.
Definition Objet_U.cpp:244
const Objet_U & operator=(const Objet_U &)
Operateur= : ne fait rien (on conserve le numero et l'identifiant).
Definition Objet_U.cpp:87
virtual int lire_motcle_non_standard(const Motcle &motlu, Entree &is)
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
Definition Objet_U.cpp:115
friend class Entree
Definition Objet_U.h:76
virtual int associer_(Objet_U &)
Associe l'Objet_U a un autre Objet_U Methode virtuelle a surcharger.
Definition Objet_U.cpp:201
static const Type_info * info()
Donne des informations sur le type de l'Objet_U.
Definition Objet_U.cpp:136
int numero() const
Renvoie l'indice de l'objet dans Memoire::data.
Definition Objet_U.cpp:268
const Interprete & interprete() const
Definition Objet_U.cpp:212
static bool disable_TU
Flag to disable or not the writing of the .TU files.
Definition Objet_U.h:125
static int dimension
Definition Objet_U.h:99
friend class Sortie
Definition Objet_U.h:75
virtual void nommer(const Nom &)
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
Definition Objet_U.cpp:329
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
friend int operator==(const Objet_U &, const Objet_U &)
retourne x.
Definition Objet_U.cpp:231
static double precision_geom
Definition Objet_U.h:86
static bool stat_per_proc_perf_log
Flag to enable the writing of the statistics detailed per processor in _csv.TU file.
Definition Objet_U.h:126
static const Objet_U & self_cast(const Objet_U &)
methode ajoutee pour caster en python
Definition Objet_U.cpp:167
static const Nom & nom_du_cas()
Renvoie une reference constante vers le nom du cas.
Definition Objet_U.cpp:146
virtual int change_num(const int *const)
Change le numero interne de l'Objet_U.
Definition Objet_U.cpp:181
virtual int est_egal_a(const Objet_U &) const
Renvoie 1 si l'objet x et *this sont une seule et meme instance (meme adresse en memoire).
Definition Objet_U.cpp:301
const char * le_type() const
Donne le nom du type de l'Objet_U.
Definition Objet_U.cpp:191
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
virtual const Nom & le_nom() const
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Objet_U.cpp:319
static int bidim_axi
Definition Objet_U.h:102
static int format_precision_geom
Definition Objet_U.h:100
virtual int reprendre(Entree &)
Reprise d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:338
static int DEACTIVATE_SIGINT_CATCH
Definition Objet_U.h:103
static Type_info info_obj
Definition Objet_U.h:107
static Nom & get_set_nom_du_cas()
Renvoie une reference non constante vers le nom du cas (pour pouvoir le modifier).
Definition Objet_U.cpp:156
static int axi
Definition Objet_U.h:101
int get_object_id() const
Renvoie l'identifiant unique de l'objet object_id_.
Definition Objet_U.cpp:95
~Objet_U() override
Destructeur, supprime l'objet de la liste d'objets enregistres dans "memoire".
Definition Objet_U.cpp:256
virtual const Type_info * get_info() const
Donne des informations sur le type de l'Objet_U.
Definition Objet_U.cpp:126
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
virtual int sauvegarder(Sortie &) const
Sauvegarde d'un Objet_U sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:352
Classe de base de TRUST (notamment Objet_U).
Definition Process.h:50
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
modelise une information de type pour les Objet_U
Definition Type_info.h:30
const Nom & name() const
Definition Type_info.h:36