TrioCFD 1.9.9_beta
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() because OWN_PTR
50 s << post;
51 }
52 return s;
53}
54
55// Reading of post-processing objects from the TRUST data set.
56// Within the problem, the syntax is as follows:
57//
58// ------------- Syntax 1: A single standard post-processing object
59// (historical syntax)
60// Lire pb {
61// ... (the equations)
62// ...
63// Postraitement {
64// ... (read via readOn of Postraitement_std)
65// }
66//
67// ------------- Syntax 2: Several standard post-processing objects
68// (historical syntax)
69// Lire pb {
70// ... (the equations)
71// ...
72// Postraitements {
73// nom_postraitement_1 { note: arbitrary name
74// ... (read via readOn of Postraitement_std)
75// }
76// nom_postraitement_2 {
77// ... (read via readOn of Postraitement_std)
78// }
79// ...
80// }
81// ------------- Syntax 3: Standard or non-standard post-processing objects
82// (to use the standard post-processing, set
83// type_postraitement = "Postraitement_std")
84//
85// Lire pb {
86// ... (the equations)
87// ...
88// Liste_Postraitements {
89// type_postraitement nom_postraitement {
90// (type_postraitement is the name of a type derived
91// from Postraitement_base, e.g. Postraitement)
92// ... (read via readOn of the requested type)
93// }
94// type_postraitement nom_postraitement {
95// ... (read via readOn of the requested type)
96// }
97// ...
98// }
99//
100// Reading starts with the keyword Postraitement, Postraitements,
101// or Liste_postraitement, and continues until the last closing brace (inclusive).
102
103// Returns 1 if motlu is recognised (a post-processing block was read),
104// 0 otherwise.
105
107{
108 Motcles motcles(5);
109 motcles[0] = "Postraitement|Post_processing";
110 motcles[1] = "Postraitements|Post_processings";
111 motcles[2] = "liste_postraitements";
112 motcles[3] = "liste_de_postraitements";
113 motcles[4] = "Postraitement_FT_Lata";
114
115 const int lerang = motcles.search(motlu);
116
117 // a cause du cas Liste_Postraitements (rang=2)
118 //=> obligation de creer la liste de nom de fichier associes au post
119 LIST(Nom) list_nom_post;
120 int compteur = 0 ;
121
122 if (lerang == 0)
123 {
124 // Create and read a single standard post-processing object
125 OWN_PTR(Postraitement_base) & post = add( OWN_PTR(Postraitement_base)() );
126 if (mon_pb.que_suis_je() == "Pb_STT")
127 post.typer("Postraitement_STT");
128 else if (mon_pb.que_suis_je().contient("_IJK"))
129 post.typer("Postprocessing_IJK");
130 else
131 post.typer("Postraitement");
132 post->associer_nom_et_pb_base("neant", mon_pb);
133 is >> post.valeur();
134
135 // XXX Elie Saikali : prevent any surprise in the future ...
136 const Postraitement * z_post = dynamic_cast<const Postraitement*>(&(post.valeur()));
137
138 if (z_post && z_post->format() == "cgns")
139 cgns_post_file_names_.push_back(z_post->nom_fich().getString());
140 }
141 else if (lerang == 1 || lerang == 2 || lerang == 3 )
142 {
143 // Read a list
144 // Read the opening brace
145 //Nom post_which_contains_statistic("");
146 Motcle motlu2;
147 is >> motlu2;
148 if (motlu2 != "{")
149 {
150 Cerr << "Error while reading the list of Postraitements," << finl;
151 Cerr << " we expected a {" << finl;
152 exit();
153 }
154 is >> motlu2;
155 while (motlu2 != "}")
156 {
157 Motcle type, nom_du_post;
158 switch (lerang)
159 {
160 case 1:
161 {
162 type = "Postraitement";
163 nom_du_post = motlu2;
164 break;
165 }
166 case 2:
167 {
168 Cerr<<" Warning liste_postraitements obsolete option" <<finl;
169 // The first word is the type, the second is the name
170 type = motlu2;
171 is >> nom_du_post;
172 break;
173 }
174 case 3:
175 {
176 nom_du_post = motlu2;
177 is >> type ;
178 break;
179 }
180 default:
181 {
182 Cerr<< "Error in Postraitements"<<finl;
183 exit();
184 }
185 }
186 list_nom_post.add_if_not(nom_du_post);
187
188 OWN_PTR(Postraitement_base) & post = add( OWN_PTR(Postraitement_base)() );
189 post.typer(type);
190 post->associer_nom_et_pb_base(nom_du_post, mon_pb);
191 is >> post.valeur();
192
193 // XXX Elie Saikali : prevent any surprise in the future ...
194 const Postraitement * z_post = dynamic_cast<const Postraitement*>(&(post.valeur()));
195
196 if (z_post && z_post->format() == "cgns")
197 cgns_post_file_names_.push_back(z_post->nom_fich().getString());
198
199 /*
200 // Check if statistic block is defined several times
201 // Not supported yet cause, backup files will contains several
202 // statistic blocks with same name BUT different contents -> error
203 // We should change the .sauv format and generalize the statistic block name
204 if (ref_cast(Postraitement,post.valeur()).stat_demande() || ref_cast(Postraitement,post.valeur()).stat_demande_definition_champs())
205 {
206 if (post_which_contains_statistic!="")
207 {
208 Cerr << "Several statistic blocks in a same problem is not supported yet." << finl;
209 Cerr << "It seems you defined statistics in the post processing block " << nom_du_post << finl;
210 Cerr << "whereas some statistics has been defined already the in the block " << post_which_contains_statistic << finl;
211 Cerr << "Check your data file by regrouping statistics in a same prostprocessing block." << finl;
212 exit();
213 }
214 post_which_contains_statistic=nom_du_post;
215 }
216 */
217 is >> motlu2;
218 compteur++;
219 }
220
221 // Verification check to avoid data being overwritten during incremental saves.
222 // Because of the Liste_Postraitements case, a list of file names associated with each post-processing object must be built.
223 if (list_nom_post.size()!=compteur)
224 {
225 Cerr << "You can use the same name for the storing data file in two different blocks of post-processing" << finl;
226 Cerr << "Check your datafile." << finl;
227 exit();
228 }
229 }
230 else if (lerang == 4) /* pour FT lata triocfd */
231 {
232 OWN_PTR(Postraitement_base) & post = add( OWN_PTR(Postraitement_base)() );
233 post.typer("Postraitement_FT_Lata");
234 post->associer_nom_et_pb_base("neant", mon_pb);
235 is >> post.valeur();
236 }
237 else
238 {
239 return 0;
240 }
241 return 1;
242}
243
245{
246 for (auto& itr : *this)
247 itr->postraiter(1); // Force post-processing
248}
249
251{
252 for (auto& itr : *this)
253 itr->postraiter(0); // Post-process if the time interval has elapsed
254}
255
257{
258 for (auto& itr : *this)
259 itr->mettre_a_jour(temps);
260}
261
262void Postraitements::resetTime(double t, const std::string dirname)
263{
264 for (auto& itr : *this)
265 itr->resetTime(t, dirname);
266}
267
269{
270 for (auto& itr : *this)
271 itr->init();
272}
273
275{
276 for (auto& itr : *this)
277 itr->finir();
278}
279
281{
282 int bytes = 0;
283 for (const auto& itr : *this)
284 bytes += itr->sauvegarder(os);
285 return bytes;
286}
287
289{
290 for (auto& itr : *this)
291 itr->reprendre(is);
292 return 1;
293}
294
296{
297 // XXX Elie Saikali : CGNS duplicated file_names management ...
298 if (cgns_post_file_names_.size() > 1)
299 {
300 // check & count if we have duplicated file names !
301 std::unordered_map<std::string, int> file_name_counts;
302 for (const auto &name : cgns_post_file_names_)
303 file_name_counts[name]++;
304
305 // chick if we have at least one duplicated names
306 bool has_duplicates = false;
307 for (const auto& name_to_count: file_name_counts)
308 {
309
310 const auto& count = name_to_count.second;
311 if (count > 1)
312 {
313 has_duplicates = true;
314 break;
315 }
316 }
317
318 if (has_duplicates) // si has_duplicates => on renomme SEULEMENT les doublons !
319 {
320 std::unordered_map<std::string, int> current_occurrence; // detect what is the index of duplication : 1st ? 2nd ? ...
321
322 for (auto &itr : *this)
323 {
324 Postraitement *z_post = dynamic_cast<Postraitement*>(&(itr.valeur()));
325 if (!z_post || z_post->format() != "cgns")
326 continue;
327
328 const std::string file_name = z_post->nom_fich().getString();
329
330 // only if duplicated ...
331 if (file_name_counts[file_name] > 1)
332 {
333 current_occurrence[file_name]++;
334
335 // dont change 1st file ...
336 if (current_occurrence[file_name] > 1)
337 z_post->modify_cgns_basenames_and_reinit(current_occurrence[file_name], file_name_counts[file_name]);
338 }
339 }
340 }
341 }
342
343 // on complete les posts !
344 for (auto& itr : *this)
345 itr->completer();
346}
347
349{
350 for (auto& itr : *this)
351 itr->completer_sondes();
352}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
A character string (Nom) in uppercase.
Definition Motcle.h:26
An array of Motcle objects.
Definition Motcle.h:63
int search(const Motcle &t) const
Definition Motcle.cpp:319
class Nom: a character string for naming TRUST objects.
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
Returns the string identifying the class.
Definition Objet_U.cpp:104
Base class for all post-processing objects.
class Postraitement. The class holds -a list of generic fields champs_post_complet_ containing
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)
class Probleme_base It is a Probleme_U that is not a coupling.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52