TrioCFD 1.9.9_beta
TrioCFD documentation
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// Allows debugging by tracing back to the creation of a given object:
37static int object_id_to_track = -1;
38
39// Utility function to intercept the creation of an object.
40// NOTE: since gcc3, the compiler generates multiple routines for
41// each constructor: at least Objet_U::Objet_U() and Objet_U::Objet_U$base().
42// This makes it difficult to use breakpoints in those routines.
43// Place the breakpoint here:
44static void object_trap(int obj_id)
45{
46 Cerr << "Objet_U::Objet_U() : object_id_=" << obj_id << finl;
47}
48
49/*! @brief Default constructor: assigns a unique identifier to the object (object_id_) and registers the object in "memory" by giving it a _num_obj_ number.
50 *
51 * object_id_ is very useful for debugging.
52 *
53 */
55 object_id_(static_obj_counter_++)
56{
57 int obj_id = object_id_;
58 if (obj_id == object_id_to_track)
59 {
60 object_trap(obj_id);
61 }
62 Memoire& memoire = Memoire::Instance();
63 _num_obj_ = memoire.add(this);
64}
65
66/*! @brief Copy constructor.
67 *
68 * Creates a new object number (does not copy the number from the other object!).
69 *
70 */
72 object_id_(static_obj_counter_++)
73{
74 int obj_id = object_id_;
75 if (obj_id == object_id_to_track)
76 {
77 object_trap(obj_id);
78 }
79 Memoire& memoire = Memoire::Instance();
80 _num_obj_ = memoire.add(this);
81}
82
83/*! @brief Assignment operator: does nothing (the number and identifier are preserved).
84 *
85 */
87{
88 return *this;
89}
90
91/*! @brief Returns the unique identifier of the object (object_id_).
92 *
93 * @return The unique object identifier.
94 */
96{
97 return object_id_;
98}
99
100/*! @brief Returns the string identifying the class.
101 *
102 * @return Name identifying the class of the object.
103 */
105{
106 return get_info()->name();
107}
108
109/*! @brief Reads non-simple-type parameters of an Objet_U from an input stream.
110 *
111 * @param motlu The name of the keyword to read.
112 * @param is An input stream.
113 * @return 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 Returns type information for the Objet_U.
123 *
124 * @return Structure containing type information for the Objet_U.
125 */
127{
128 return &info_obj;
129}
130
131
132/*! @brief Returns type information for the Objet_U (static version).
133 *
134 * @return Structure containing type information for the Objet_U.
135 */
137{
138 return &info_obj;
139}
140
141/*! @brief Returns a constant reference to the case name. This method is static.
142 *
143 * @return Constant reference to the case name.
144 */
146{
147 return get_set_nom_du_cas();
148}
149
150/*! @brief Returns a non-constant reference to the case name (to allow modification). This method is static.
151 *
152 * @return Non-constant reference to the case name.
153 */
155{
156 // This static object is constructed on the first call to the function.
157 static Nom nom_du_cas_;
158 return nom_du_cas_;
159}
160
161/*! @brief Method added for casting in Python.
162 *
163 * @param obj The object to cast.
164 * @return Constant reference to the object.
165 */
167{
168 return ref_cast_non_const(Objet_U,obj);
169}
171{
172 return ref_cast_non_const(Objet_U,obj);
173}
174
175/*! @brief Changes the internal number of the Objet_U.
176 *
177 * @param new_ones Array of new numbers, indexed by old numbers.
178 * @return The new number assigned to the Objet_U.
179 */
180int Objet_U::change_num(const int* const new_ones)
181{
182 return _num_obj_=new_ones[_num_obj_];
183}
184
185
186/*! @brief Returns the type name of the Objet_U.
187 *
188 * @return Character string representing the type of the Objet_U.
189 */
190const char* Objet_U::le_type() const
191{
192 return get_info()->name();
193}
194
195/*! @brief Associates the Objet_U with another Objet_U. Virtual method to override.
196 *
197 * @param obj The Objet_U to associate with.
198 * @return Return code.
199 */
201{
202 return 0;
203}
204
205static Interprete& interprete_bidon()
206{
207 static Lire bidon;
208 return bidon;
209}
210// BM: to be removed eventually (use Interprete::objet instead)
212{
213 return interprete_bidon();
214}
215
216// BM: to be removed eventually (use Interprete::objet instead)
218{
219 return interprete_bidon();
220}
221
222/*! @brief Returns x.est_egal_a(y).
223 *
224 * @param x First Objet_U for comparison.
225 * @param y Second Objet_U for comparison.
226 * @return 1 if the two Objet_U are equal, 0 otherwise.
227 */
228int operator==(const Objet_U& x, const Objet_U& y)
229{
230 return x.est_egal_a(y);
231}
232
233/*! @brief Returns 1 - x.est_egal_a(y).
234 *
235 * @param x First Objet_U for comparison.
236 * @param y Second Objet_U for comparison.
237 * @return 1 if the two Objet_U are different, 0 if they are equal.
238 */
239int operator!=(const Objet_U& x, const Objet_U& y)
240{
241 return (1-(x.est_egal_a(y)));
242}
243
244#endif // LATATOOLS
245
246double Objet_U::precision_geom = 1e-10;
247
248/*! @brief Destructor. Removes the object from the list of objects registered in "memory".
249 *
250 */
252{
253#ifndef LATATOOLS
254 Memoire& memoire = Memoire::Instance();
255 memoire.suppr(_num_obj_);
256 _num_obj_ = -2; // Paranoia
257#endif
258}
259
260/*! @brief Returns the index of the object in Memoire::data.
261 *
262 * @return The object's index in memory.
263 */
265{
266#ifndef LATATOOLS
267 return _num_obj_;
268#else
269 return 0;
270#endif
271}
272
273/*! @brief Writes the object to an output stream. Virtual method to override.
274 *
275 * @param s Output stream.
276 * @return Modified output stream.
277 */
279{
280 return s;
281}
282
283
284/*! @brief Reads an Objet_U from an input stream. Virtual method to override.
285 *
286 * @param s Input stream.
287 * @return Modified input stream.
288 */
290{
291 return s;
292}
293
294/*! @brief Returns 1 if x and *this are the same instance (same memory address).
295 *
296 * @param x The object to compare with.
297 * @return 1 if same instance, 0 otherwise.
298 */
299int Objet_U::est_egal_a(const Objet_U& x) const
300{
301#ifndef LATATOOLS
302 int resultat;
303 if (&x==this)
304 resultat = 1;
305 else
306 resultat = 0;
307 return resultat;
308#else
309 return 0;
310#endif
311}
312
313/*! @brief Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
314 *
315 * @return The name of the Objet_U.
316 */
317const Nom& Objet_U::le_nom() const
318{
319 static Nom inconnu="neant";
320 return inconnu;
321}
322
323/*! @brief Assigns a name to the Objet_U. Virtual method to override.
324 *
325 * @param nom The name to assign to the Objet_U.
326 */
327void Objet_U::nommer(const Nom& nom)
328{
329}
330
331/*! @brief Restores an Objet_U from an input stream. Virtual method to override.
332 *
333 * @param is Input stream to use for restoration.
334 * @return Return code.
335 */
337{
338#ifndef LATATOOLS
339 Cerr << "The method " << __func__ << " must be overloaded in " << que_suis_je() << " !!!!" << finl;
341#endif
342 return 1;
343}
344
345/*! @brief Saves an Objet_U to an output stream. Virtual method to override.
346 *
347 * @param os Output stream to use for saving.
348 * @return Return code.
349 */
351{
352#ifndef LATATOOLS
353 Cerr << "The method " << __func__ << " must be overloaded in " << que_suis_je() << " !!!!" << finl;
355#endif
356 return 0;
357}
Base class for "interpreter" objects.
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()
Returns a pointer to the memory instance. Creates a new memory object if no instance has been created...
Definition Memoire.cpp:32
int suppr(int)
Removes from memory the Objet_U with index num. The Objet_U itself is not deleted; only its pointer i...
Definition Memoire.cpp:105
int add(Objet_U *)
Adds an Objet_U to the TRUST memory.
Definition Memoire.cpp:54
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
friend int operator!=(const Objet_U &, const Objet_U &)
Returns 1 - x.est_egal_a(y).
Definition Objet_U.cpp:239
const Objet_U & operator=(const Objet_U &)
Assignment operator: does nothing (the number and identifier are preserved).
Definition Objet_U.cpp:86
virtual int lire_motcle_non_standard(const Motcle &motlu, Entree &is)
Reads non-simple-type parameters of an Objet_U from an input stream.
Definition Objet_U.cpp:115
friend class Entree
Definition Objet_U.h:71
virtual int associer_(Objet_U &)
Associates the Objet_U with another Objet_U. Virtual method to override.
Definition Objet_U.cpp:200
static const Type_info * info()
Returns type information for the Objet_U (static version).
Definition Objet_U.cpp:136
int numero() const
Returns the index of the object in Memoire::data.
Definition Objet_U.cpp:264
const Interprete & interprete() const
Definition Objet_U.cpp:211
static bool disable_TU
Flag to disable or not the writing of the .TU files.
Definition Objet_U.h:120
static int dimension
Definition Objet_U.h:94
friend class Sortie
Definition Objet_U.h:70
virtual void nommer(const Nom &)
Assigns a name to the Objet_U. Virtual method to override.
Definition Objet_U.cpp:327
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
friend int operator==(const Objet_U &, const Objet_U &)
Returns x.est_egal_a(y).
Definition Objet_U.cpp:228
static double precision_geom
Definition Objet_U.h:81
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:121
static const Objet_U & self_cast(const Objet_U &)
Method added for casting in Python.
Definition Objet_U.cpp:166
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
Definition Objet_U.cpp:145
virtual int change_num(const int *const)
Changes the internal number of the Objet_U.
Definition Objet_U.cpp:180
virtual int est_egal_a(const Objet_U &) const
Returns 1 if x and *this are the same instance (same memory address).
Definition Objet_U.cpp:299
const char * le_type() const
Returns the type name of the Objet_U.
Definition Objet_U.cpp:190
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
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
static int bidim_axi
Definition Objet_U.h:97
static int format_precision_geom
Definition Objet_U.h:95
virtual int reprendre(Entree &)
Restores an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:336
static int DEACTIVATE_SIGINT_CATCH
Definition Objet_U.h:98
static Type_info info_obj
Definition Objet_U.h:102
static Nom & get_set_nom_du_cas()
Returns a non-constant reference to the case name (to allow modification). This method is static.
Definition Objet_U.cpp:154
static int axi
Definition Objet_U.h:96
int get_object_id() const
Returns the unique identifier of the object (object_id_).
Definition Objet_U.cpp:95
~Objet_U() override
Destructor. Removes the object from the list of objects registered in "memory".
Definition Objet_U.cpp:251
virtual const Type_info * get_info() const
Returns type information for the Objet_U.
Definition Objet_U.cpp:126
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
virtual int sauvegarder(Sortie &) const
Saves an Objet_U to an output stream. Virtual method to override.
Definition Objet_U.cpp:350
Base class of TRUST (in particular Objet_U).
Definition Process.h:48
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Models type information for Objet_U objects.
Definition Type_info.h:30
const Nom & name() const
Definition Type_info.h:36