TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Postraitements.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 <Postraitements.h>
17#include <Postraitement.h>
18#include <unordered_set>
19
20Implemente_instanciable(Postraitements,"Postraitements|Post_processings",LIST(OWN_PTR(Postraitement_base)));
21// XD postraitements listobj postraitements INHERITS_BRACE un_postraitement NO_COMMA Keyword to use several results
22// XD_CONT files. List of objects of post-processing (with name).
23
24// XD type_postraitement_ft_lata objet_lecture nul NO_BRACE not_set
25// XD attr type chaine(into=["postraitement_ft_lata","postraitement_ftd"]) type REQ not_set
26// XD attr nom chaine nom REQ Name of the post-processing.
27// XD attr bloc bloc_lecture bloc REQ not_set
28
29// XD un_postraitement_spec objet_lecture nul NO_BRACE An object of post-processing (with type +name).
30// XD attr type_un_post type_un_post type_un_post OPT not_set
31// XD attr type_postraitement_ft_lata type_postraitement_ft_lata type_postraitement_ft_lata OPT not_set
32
33// XD liste_post listobj liste_post INHERITS_BRACE un_postraitement_spec NO_COMMA Keyword to use several results files.
34// XD_CONT List of objects of post-processing (with name)
35
36// XD liste_post_ok listobj liste_post_ok INHERITS_BRACE nom_postraitement NO_COMMA Keyword to use several results
37// XD_CONT files. List of objects of post-processing (with name)
38
39Entree& Postraitements::readOn(Entree& s)
40{
41 Process::exit("Postraitements::readOn should not be used");
42 return s;
43}
44
45Sortie& Postraitements::printOn(Sortie& s) const
46{
47 for (const auto& itr : *this)
48 {
49 const Postraitement_base& post = itr.valeur(); // valeur() car OWN_PTR
50 s << post;
51 }
52 return s;
53}
54
55// Lecture des postraitements dans le jeu de donnees TRUST
56// Au sein du probleme, la syntaxe est la suivante:
57//
58// ------------- Syntaxe 1 : Un postraitement standard
59// (syntaxe historique)
60// Lire pb {
61// ... (les equations)
62// ...
63// Postraitement {
64// ... (lecture au format readOn de Postraitement_std)
65// }
66//
67// ------------- Syntaxe 2 : Plusieurs postraitements standard
68// (syntaxe historique)
69// Lire pb {
70// ... (les equations)
71// ...
72// Postraitements {
73// nom_postraitement_1 { note: nom arbitraire
74// ... (lecture au format readOn de Postraitement_std)
75// }
76// nom_postraitement_2 {
77// ... (lecture au format readOn de Postraitement_std)
78// }
79// ...
80// }
81// ------------- Syntaxe 3 : Postraitements standard ou non standard
82// (pour utiliser le postraitement standard, utiliser
83// type_postraitement = "Postraitement_std")
84//
85// Lire pb {
86// ... (les equations)
87// ...
88// Liste_Postraitements {
89// type_postraitement nom_postraitement {
90// (type_postraitement est un le nom d'un type derive
91// de Postraitement_base, par ex Postraitement)
92// ... (lecture au format readOn du type demande)
93// }
94// type_postraitement nom_postraitement {
95// ... (lecture au format readOn du type demande)
96// }
97// ...
98// }
99//
100// La lecture commence par celle du mot cle Postraitement,
101// Postraitements ou Liste_postraitement, et on lit jusqu'a la
102// derniere accolade incluse.
103
104// Renvoie 1 si le motlu est compris (lecture d'un bloc de postraitement),
105// 0 sinon.
106
108{
109 Motcles motcles(5);
110 motcles[0] = "Postraitement|Post_processing";
111 motcles[1] = "Postraitements|Post_processings";
112 motcles[2] = "liste_postraitements";
113 motcles[3] = "liste_de_postraitements";
114 motcles[4] = "Postraitement_FT_Lata";
115
116 const int lerang = motcles.search(motlu);
117
118 // a cause du cas Liste_Postraitements (rang=2)
119 //=> obligation de creer la liste de nom de fichier associes au post
120 LIST(Nom) list_nom_post;
121 int compteur = 0 ;
122
123 if (lerang == 0)
124 {
125 // Creation et lecture d'un postraitement unique standard
126 OWN_PTR(Postraitement_base) & post = add( OWN_PTR(Postraitement_base)() );
127 if (mon_pb.que_suis_je() == "Pb_STT")
128 post.typer("Postraitement_STT");
129 else if (mon_pb.que_suis_je().contient("_IJK"))
130 post.typer("Postprocessing_IJK");
131 else
132 post.typer("Postraitement");
133 post->associer_nom_et_pb_base("neant", mon_pb);
134 is >> post.valeur();
135
136 // XXX Elie Saikali : prevent any surprise in the future ...
137 const Postraitement * z_post = dynamic_cast<const Postraitement*>(&(post.valeur()));
138
139 if (z_post && z_post->format() == "cgns")
140 cgns_post_file_names_.push_back(z_post->nom_fich().getString());
141 }
142 else if (lerang == 1 || lerang == 2 || lerang == 3 )
143 {
144 // Lecture d'une liste
145 // Lire l'accolade
146 //Nom post_which_contains_statistic("");
147 Motcle motlu2;
148 is >> motlu2;
149 if (motlu2 != "{")
150 {
151 Cerr << "Error while reading the list of Postraitements," << finl;
152 Cerr << " we expected a {" << finl;
153 exit();
154 }
155 is >> motlu2;
156 while (motlu2 != "}")
157 {
158 Motcle type, nom_du_post;
159 switch (lerang)
160 {
161 case 1:
162 {
163 type = "Postraitement";
164 nom_du_post = motlu2;
165 break;
166 }
167 case 2:
168 {
169 Cerr<<" Warning liste_postraitements obsolete option" <<finl;
170 // Le premier mot est le type, le deuxieme est le nom
171 type = motlu2;
172 is >> nom_du_post;
173 break;
174 }
175 case 3:
176 {
177 nom_du_post = motlu2;
178 is >> type ;
179 break;
180 }
181 default:
182 {
183 Cerr<< "Error in Postraitements"<<finl;
184 exit();
185 }
186 }
187 list_nom_post.add_if_not(nom_du_post);
188
189 OWN_PTR(Postraitement_base) & post = add( OWN_PTR(Postraitement_base)() );
190 post.typer(type);
191 post->associer_nom_et_pb_base(nom_du_post, mon_pb);
192 is >> post.valeur();
193
194 // XXX Elie Saikali : prevent any surprise in the future ...
195 const Postraitement * z_post = dynamic_cast<const Postraitement*>(&(post.valeur()));
196
197 if (z_post && z_post->format() == "cgns")
198 cgns_post_file_names_.push_back(z_post->nom_fich().getString());
199
200 /*
201 // Check if statistic block is defined several times
202 // Not supported yet cause, backup files will contains several
203 // statistic blocks with same name BUT different contents -> error
204 // We should change the .sauv format and generalize the statistic block name
205 if (ref_cast(Postraitement,post.valeur()).stat_demande() || ref_cast(Postraitement,post.valeur()).stat_demande_definition_champs())
206 {
207 if (post_which_contains_statistic!="")
208 {
209 Cerr << "Several statistic blocks in a same problem is not supported yet." << finl;
210 Cerr << "It seems you defined statistics in the post processing block " << nom_du_post << finl;
211 Cerr << "whereas some statistics has been defined already the in the block " << post_which_contains_statistic << finl;
212 Cerr << "Check your data file by regrouping statistics in a same prostprocessing block." << finl;
213 exit();
214 }
215 post_which_contains_statistic=nom_du_post;
216 }
217 */
218 is >> motlu2;
219 compteur++;
220 }
221
222 // test de verification pour eviter ecrasement de donnnes au fur et a mesure de leur enregistrement
223 // a cause du cas Liste_Postraitements => obligation de creer la liste de nom de fichier associes au post
224 if (list_nom_post.size()!=compteur)
225 {
226 Cerr << "You can use the same name for the storing data file in two different blocks of post-processing" << finl;
227 Cerr << "Check your datafile." << finl;
228 exit();
229 }
230 }
231 else if (lerang == 4) /* pour FT lata triocfd */
232 {
233 OWN_PTR(Postraitement_base) & post = add( OWN_PTR(Postraitement_base)() );
234 post.typer("Postraitement_FT_Lata");
235 post->associer_nom_et_pb_base("neant", mon_pb);
236 is >> post.valeur();
237 }
238 else
239 {
240 return 0;
241 }
242 return 1;
243}
244
246{
247 for (auto& itr : *this)
248 itr->postraiter(1); // On force le postraitement
249}
250
252{
253 for (auto& itr : *this)
254 itr->postraiter(0); // Postraitement si intervalle de temps ecoule
255}
256
258{
259 for (auto& itr : *this)
260 itr->mettre_a_jour(temps);
261}
262
263void Postraitements::resetTime(double t, const std::string dirname)
264{
265 for (auto& itr : *this)
266 itr->resetTime(t, dirname);
267}
268
270{
271 for (auto& itr : *this)
272 itr->init();
273}
274
276{
277 for (auto& itr : *this)
278 itr->finir();
279}
280
282{
283 int bytes = 0;
284 for (const auto& itr : *this)
285 bytes += itr->sauvegarder(os);
286 return bytes;
287}
288
290{
291 for (auto& itr : *this)
292 itr->reprendre(is);
293 return 1;
294}
295
297{
298 // XXX Elie Saikali : CGNS duplicated file_names management ...
299 if (cgns_post_file_names_.size() > 1)
300 {
301 // check & count if we have duplicated file names !
302 std::unordered_map<std::string, int> file_name_counts;
303 for (const auto &name : cgns_post_file_names_)
304 file_name_counts[name]++;
305
306 // chick if we have at least one duplicated names
307 bool has_duplicates = false;
308 for (const auto& name_to_count: file_name_counts)
309 {
310
311 const auto& count = name_to_count.second;
312 if (count > 1)
313 {
314 has_duplicates = true;
315 break;
316 }
317 }
318
319 if (has_duplicates) // si has_duplicates => on renomme SEULEMENT les doublons !
320 {
321 std::unordered_map<std::string, int> current_occurrence; // detect what is the index of duplication : 1st ? 2nd ? ...
322
323 for (auto &itr : *this)
324 {
325 Postraitement *z_post = dynamic_cast<Postraitement*>(&(itr.valeur()));
326 if (!z_post || z_post->format() != "cgns")
327 continue;
328
329 const std::string file_name = z_post->nom_fich().getString();
330
331 // only if duplicated ...
332 if (file_name_counts[file_name] > 1)
333 {
334 current_occurrence[file_name]++;
335
336 // dont change 1st file ...
337 if (current_occurrence[file_name] > 1)
338 z_post->modify_cgns_basenames_and_reinit(current_occurrence[file_name], file_name_counts[file_name]);
339 }
340 }
341 }
342 }
343
344 // on complete les posts !
345 for (auto& itr : *this)
346 itr->completer();
347}
348
350{
351 for (auto& itr : *this)
352 itr->completer_sondes();
353}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
Un tableau d'objets de la classe Motcle.
Definition Motcle.h:63
int search(const Motcle &t) const
Definition Motcle.cpp:321
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
bool contient(const Nom &nom) const
Definition Nom.h:86
const std::string & getString() const
Definition Nom.h:92
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
Classe de base pour l'ensemble des postraitements.
classe Postraitement La classe est dotee -d une liste de champs generiques champs_post_complet_ qui c...
void modify_cgns_basenames_and_reinit(const int, const int)
Nom nom_fich() const
const Nom & format() const
int reprendre(Entree &is) override
int sauvegarder(Sortie &os) const override
std::vector< std::string > cgns_post_file_names_
void resetTime(double t, const std::string dirname)
int lire_postraitements(Entree &is, const Motcle &motlu, const Probleme_base &mon_pb)
void mettre_a_jour(double temps)
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52