TrioCFD 1.9.9_beta
TrioCFD documentation
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_ goes back down into LecFicDiffuseBase
52 /* Overridden by:
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_ goes back down into LecFicDiffuseBase
116 /* Overridden by:
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)
Sets the diffuse flag for this input stream.
Definition Entree.cpp:409
virtual istream & get_istream()
Definition Entree.cpp:41
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Nom substr_old(const int, const int) const
Returns a name using the usual substr command. NOTE: deb = 1 means the first character of the string.
Definition Nom.cpp:466
int longueur() const
Returns the number of characters in the Nom string, including the null terminator.
Definition Nom.cpp:187
Objet_U * typer(const char *nom_type)
Tries to create an instance of type "type".
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
int reprendre(Entree &is) override
Restores an Objet_U from an input stream. Virtual method to override.