TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Avanc.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 <communications.h>
17#include <Motcle.h>
18#include <Avanc.h>
19
20inline void erreur(const Nom& id)
21{
22 Cerr << finl;
23 Cerr << "The restarting has failed. The tag " << id << " has not been" << finl;
24 Cerr << "found in the restarting file. Check the restarting time in your data set." << finl;
26}
27
28inline void erreur_syn(const Nom& id,const Nom& syn_id)
29{
30 Cerr << finl;
31 Cerr << "The restarting has failed. The tag " << id << " or its synonym"<< syn_id << " has not been" << finl;
32 Cerr << "found in the restarting file. Check the restarting time in your data set." << finl;
34}
35
36extern void convert_to(const char *s, double& ob);
37double extract_time_from_string(const Nom& ident_lu, const int digits)
38{
39 double temps;
40 int length = ident_lu.longueur();
41 convert_to(ident_lu.substr_old(length-digits,digits),temps);
42 return temps;
43}
44
45// In the file fich, go up to the identifier id and return the time found
46double avancer_fichier(Entree& fich, const Nom& id, const int read_header)
47{
48 // Possible evolution:
49 // avancer_fichier(fich,id) -> fich.avancer_fichier(id);
50 // Implementation of double Entree::seek(const Nom& id):
51 // diffuse_ redescend dans LecFicDiffuseBase
52 /* Surcharge par:
53 double LecFicDiffuse::seek(const Nom& id)
54 {
55 double time;
56 diffuse_=0;
57 if (Process::je_suis_maitre()) time = Entree::seek(id);
58 diffuse_=1;
59 envoyer_broadcast(temps, 0);
60 return time;
61 }
62 */
63 double temps=0;
64 fich.set_diffuse(0); // Entree::set_diffuse() set to 1, only Lec_Diffuse_base::set_diffuse() can set to 0
66 {
67 Cerr << "Looking for the tag " << id << " in the file." << finl;
68 Nom ident_lu;
69 Nom type_lu;
70 int digits=12; // Number of digits to write the time
71 fich >> ident_lu;
72
73 if (read_header)
74 {
75 if (ident_lu!="format_sauvegarde:")
76 {
77 digits=8; // Old time format
78 }
79 else
80 {
81 // New format
82 int format;
83 fich >> format;
84 fich >> ident_lu;
85 }
86 }
87
88 fich >> type_lu;
89 while (Motcle(ident_lu) != Motcle(id))
90 {
91 DerObjU un_objet;
92 un_objet.typer(type_lu);
93 Cerr << "-> Passing object " << ident_lu << " ... " << flush;
94 un_objet.reprendre(fich);
95 Cerr << "OK" << finl;
96 temps = extract_time_from_string(ident_lu, digits);
97 if (!fich.get_istream()) erreur(id);
98 fich >> ident_lu;
99 if (id!=(Nom)"fin" && ident_lu == (Nom)"fin") erreur(id);
100 fich >> type_lu;
101 }
102 Cerr << "-> Find object " << id << " and reading data in it ..." << finl;
103 }
104 envoyer_broadcast(temps, 0);
105 fich.set_diffuse(1);
106 return temps;
107}
108
109// In the file fich, go up to the identifier id and return the time found, also check syno for backwards compatibility
110double avancer_fichier_with_syno(Entree& fich, const Nom& id, const Nom& syn_id, const int read_header)
111{
112 // Possible evolution:
113 // avancer_fichier(fich,id) -> fich.avancer_fichier(id);
114 // Implementation of double Entree::seek(const Nom& id):
115 // diffuse_ redescend dans LecFicDiffuseBase
116 /* Surcharge par:
117 double LecFicDiffuse::seek(const Nom& id)
118 {
119 double time;
120 diffuse_=0;
121 if (Process::je_suis_maitre()) time = Entree::seek(id);
122 diffuse_=1;
123 envoyer_broadcast(temps, 0);
124 return time;
125 }
126 */
127 double temps=0;
128 fich.set_diffuse(0); // Entree::set_diffuse() set to 1, only Lec_Diffuse_base::set_diffuse() can set to 0
129 if (fich.get_diffuse() || Process::je_suis_maitre())
130 {
131 Cerr << "Looking for the tag " << id << "or its synonym "<< syn_id<< " in the file." << finl;
132 Nom ident_lu;
133 Nom type_lu;
134 int digits=12; // Number of digits to write the time
135 fich >> ident_lu;
136
137 if (read_header)
138 {
139 if (ident_lu!="format_sauvegarde:")
140 {
141 digits=8; // Old time format
142 }
143 else
144 {
145 // New format
146 int format;
147 fich >> format;
148 fich >> ident_lu;
149 }
150 }
151
152 fich >> type_lu;
153 while (Motcle(ident_lu) != Motcle(id) && Motcle(ident_lu) != Motcle(syn_id))
154 {
155 DerObjU un_objet;
156 un_objet.typer(type_lu);
157 Cerr << "-> Passing object " << ident_lu << " ... " << flush;
158 un_objet.reprendre(fich);
159 Cerr << "OK" << finl;
160 temps = extract_time_from_string(ident_lu, digits);
161 if (!fich.get_istream()) erreur_syn(id,syn_id);
162 fich >> ident_lu;
163 if (id!=(Nom)"fin" && ident_lu == (Nom)"fin") erreur_syn(id,syn_id);
164 fich >> type_lu;
165 }
166 Cerr << "-> Find object " << id << " or its synonym "<< syn_id<<" and reading data in it ..." << finl;
167 }
168 envoyer_broadcast(temps, 0);
169 fich.set_diffuse(1);
170 return temps;
171}
172
173double get_last_time(Entree& fich)
174{
175 return avancer_fichier(fich, "fin", 1);
176}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
bool get_diffuse()
Definition Entree.h:99
virtual void set_diffuse(bool diffuse)
ToDo TMA : commenter.
Definition Entree.cpp:410
virtual istream & get_istream()
Definition Entree.cpp:41
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 substr_old(const int, const int) const
Retourne un nom selon la commande usuelle substr ATTENTION : deb = 1 => premier caractere de la chain...
Definition Nom.cpp:473
int longueur() const
Renvoie le nombre de caracteres de la chaine du Nom y compris le caractere zero de fin de chaine.
Definition Nom.cpp:191
Objet_U * typer(const char *nom_type)
Essaie de creer une instance du type "type".
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Definition Process.cpp:86
int reprendre(Entree &is) override
Reprise d'un Objet_U sur un flot d'entree Methode a surcharger.