TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Postraitement_FTD_base.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 <Postraitement_FTD_base.h>
17#include <Transport_Marqueur_FT.h>
18#include <Probleme_FT_Disc_gen.h>
19#include <Format_Post_Lata.h>
20#include <Format_Post_CGNS.h>
21#include <Param.h>
22
23Implemente_base(Postraitement_FTD_base, "Postraitement_FTD_base", Postraitement);
24
26
28{
29 // Verification du type du probleme
30 const Nom& type_pb = mon_probleme->que_suis_je();
31
32 if ((type_pb != "Probleme_FT_Disc_gen") && (!type_pb.debute_par("Pb_Thermohydraulique_Especes")))
33 {
34 Cerr << "Error in Postraitement_FTD_base::readOn !! " << que_suis_je() << " is not accepted for a problem of type " << type_pb << finl;
35 Cerr << "The recognized problems are :" << finl;
36 Cerr << " - Probleme_FT_Disc_gen " << finl;
37 Cerr << " - Pb_Thermohydraulique_Especes_QC " << finl;
38 Cerr << " - Pb_Thermohydraulique_Especes_Turbulent_QC " << finl;
40 }
41
43
44 if (!sub_type(Format_Post_Lata, format_post_.valeur()) && !sub_type(Format_Post_CGNS, format_post_.valeur()))
45 {
46 Cerr << "****************************************************************************" << finl;
47 Cerr << "*** WARNING WARNING ***" << finl;
48 Cerr << " You are processing a FT problem, but you are using the format " << format_post_->que_suis_je() << " !! " << finl;
49 Cerr << " The interfaces will **not** be post-processed and will be ignored." << finl << finl;
50 Cerr << " You should use the 'LATA' or 'CGNS' format (directive 'format lata /or/ cgns') if you like to visualize the interfaces." << finl;
51 Cerr << "****************************************************************************" << finl;
52 }
53
54 return is;
55}
56
58{
59 int ret_val = Postraitement::lire_motcle_non_standard(mot, is);
60
61 if (ret_val != -1) // all good we've hit standard postprocessing keywords
62 return ret_val;
63
64 if (mot=="interfaces")
65 {
68
69 // This is put here to make sure we have read all keywords anyway:
70 if(!Motcle(format_).contient("LATA") && (Motcle(format_) != "CGNS") )
71 {
72 Cerr << "**** Output format is not LATA /or/ CGNS, interfaces will be silently ignored." << finl;
73 // Nullify reference, this will skip interfaces in the rest of the process
74 refequation_interfaces.reset();
75 }
76
77 return 1;
78 }
79 else
80 return -11;
81}
82
84{
85 Motcle motlu;
86 is >> motlu;
87
88 if (refequation_interfaces)
89 {
90 Cerr << "Only one transport interface equation name can be specified for a Postraitement_FTD_base post-process." << finl;
91 Cerr << "The " << Motcle(refequation_interfaces->le_nom()) << " has already been read for the post-process " << (*this).le_nom() << finl;
92 Cerr << "Please, create a new Postraitement_ftd post-process for the " << motlu << " transport interface equation." << finl;
94 }
95
96 Cerr << "Post-processing for the interface of transport equation : " << motlu << finl;
97
98 if (sub_type(Probleme_FT_Disc_gen, mon_probleme.valeur()))
99 {
100 const Probleme_FT_Disc_gen& pb = ref_cast(Probleme_FT_Disc_gen, mon_probleme.valeur());
101 refequation_interfaces = pb.equation_interfaces(motlu);
102 }
103 else
104 for (int i = 0; i < mon_probleme->nombre_d_equations(); i++)
105 {
106 const Nom& nom_eq = mon_probleme->equation(i).le_nom();
107 if (sub_type(Transport_Interfaces_FT_Disc,mon_probleme->equation(i)) && (motlu == Motcle(nom_eq)))
108 {
109 refequation_interfaces = ref_cast(Transport_Interfaces_FT_Disc, mon_probleme->equation(i));
110 }
111 }
112
113 if (!refequation_interfaces)
114 {
115 Cerr << "No interface equation name " << motlu << " has been found. " << finl;
117 }
118
119 is >> motlu;
120 if (motlu == "no_virtuals")
121 {
122 if (Process::nproc() > 1)
123 no_virtuals_ = true;
124 is >> motlu;
125 }
126 if (motlu != "{")
127 {
128 Cerr << "ERROR: Postraitement_ft_lata::lire_entete_bloc_interface : '{' was expected after the keyword interfaces\n";
129 Cerr << " We found '" << motlu << "'" << finl;
131 }
132}
133
134/*! @brief lecture de la liste de champs aux interfaces a postraiter
135 */
137{
138 Motcle nom_champ, loc_lu;
139
140 while (1)
141 {
142 is >> nom_champ;
143 if (nom_champ == "}") break;
144
145 is >> loc_lu;
146 register_interface_field(nom_champ, loc_lu);
147 }
148}
149
151{
152 Localisation loc = SOMMETS;
153 if (loc_lu == "som")
154 loc = SOMMETS;
155 else if (loc_lu == "elem")
156 loc = ELEMENTS;
157 else
158 {
159 Cerr << "Error for Postraitement_FTD_base::register_interface_field !! '" << loc_lu << "' has been read. " << finl;
160 Cerr << " Keyword 'som' or 'elem' was expected after the field name '" << nom_champ << "'" << finl;
162 }
163
164 add_locs_required_if_not(loc_lu); // utile pour CGNS !
165
166 const Transport_Interfaces_FT_Disc& eq_interfaces = refequation_interfaces.valeur();
167
168 if (!eq_interfaces.get_champ_post_FT(nom_champ, loc, (DoubleTab*) 0) && !eq_interfaces.get_champ_post_FT(nom_champ, loc, (IntTab*) 0))
169 {
170 Cerr << "Error for Postraitement_FTD_base::register_interface_field :\n";
171 Cerr << " The field '" << nom_champ << "' is not understood for the " << (eq_interfaces.que_suis_je() == "Transport_Marqueur_FT" ? "particules" : "interfaces")
172 << " or not authorized at localisation '";
173 Nom tmp = ((loc == SOMMETS) ? "sommets" : "elements");
174 Cerr << tmp << "'" << finl;
175 eq_interfaces.get_champ_post_FT(demande_description, loc, (DoubleTab*) 0);
176 eq_interfaces.get_champ_post_FT(demande_description, loc, (IntTab*) 0);
178 }
179
181
182 if (!liste.contient_(nom_champ))
183 liste.add(nom_champ);
184}
185
186/*! @brief Override. Add the interfaces to the file output
187 *
188 */
190{
191 if (refequation_interfaces)
192 {
194 return 1;
195 }
196 return -1;
197}
198
199/*! @brief Build a reduced version of the facettes array, excluding virtual ones
200 * Also update the internal renumbering array for later usage when writing out field values.
201 */
203{
204 const Maillage_FT_Disc& mesh = refequation_interfaces->maillage_interface_pour_post();
205 const IntTab& fa7 = mesh.facettes();
206 const int nl = fa7.dimension(0), nc = fa7.dimension(1);
207
208 new_fa7.resize(0, nc);
209 int sz = 0;
210
211 // Reset renumbering
212 renum_.clear();
213
214 for (int i = 0; i < nl; i++)
215 if (!mesh.facette_virtuelle(i))
216 {
217 sz++;
218 new_fa7.resize(sz, nc);
219 renum_.push_back(i);
220 for (int j = 0; j < nc; j++)
221 new_fa7(sz - 1, j) = fa7(i, j);
222 }
223
224 return sz;
225}
226
227void Postraitement_FTD_base::filter_out_array(const DoubleTab& dtab, DoubleTab& new_dtab) const
228{
229 const int nl = static_cast<int>(renum_.size()), nc = dtab.dimension(1);
230 new_dtab.resize(nl, nc);
231
232 for (int i = 0; i < nl; i++)
233 for (int j = 0; j < nc; j++)
234 new_dtab(i, j) = dtab(renum_[i], j);
235}
236
237/*! @brief Write the Maillage_FT_Disc object into a LATA file in V2 format.
238 *
239 */
241{
242 // Determining mesh type according to equation type:
243 if (sub_type(Transport_Marqueur_FT, refequation_interfaces.valeur()))
244 id_domaine_ = "PARTICULES";
245 else if (sub_type(Transport_Interfaces_FT_Disc, refequation_interfaces.valeur()))
246 id_domaine_ = "INTERFACES";
247 else
248 {
249 Cerr << "Type " << refequation_interfaces->que_suis_je() << " not recognized" << finl;
251 }
252 const Maillage_FT_Disc& mesh = refequation_interfaces->maillage_interface_pour_post();
253 const DoubleTab& sommets = mesh.sommets();
254 const IntTab& fa7 = mesh.facettes();
255 const int dim = mesh.sommets().dimension(1);
256 Motcle type_elem = dim == 2 ? "Segment" : "Triangle";
257
258 if (sub_type(Format_Post_Lata, format_post_.valeur()))
259 {
260 Format_Post_Lata& fpl = ref_cast(Format_Post_Lata, format_post_.valeur());
261 if (no_virtuals_)
262 {
263 IntTab real_fa7;
264 filter_out_virtual_fa7(real_fa7);
265 fpl.ecrire_domaine_low_level(id_domaine_, sommets, real_fa7, type_elem);
266 }
267 else
268 fpl.ecrire_domaine_low_level(id_domaine_, sommets, fa7, type_elem);
269 }
270 else if (sub_type(Format_Post_CGNS, format_post_.valeur()))
271 {
272 Format_Post_CGNS& fpc = ref_cast(Format_Post_CGNS, format_post_.valeur());
273 if (no_virtuals_)
274 {
275 IntTab real_fa7;
276 filter_out_virtual_fa7(real_fa7);
277 fpc.ecrire_domaine_low_level(nullptr, id_domaine_, sommets, real_fa7, type_elem);
278 }
279 else
280 fpc.ecrire_domaine_low_level(nullptr, id_domaine_, sommets, fa7, type_elem);
281
282 }
283 else
284 throw std::runtime_error("Postraitement_FTD_base::ecrire_maillage_ft_disc => Unsupported post format");
285
286 return 1;
287}
288
290{
291 // specific FT fields:
292 if (!refequation_interfaces) return; /* rien a faire */
293
294 const Transport_Interfaces_FT_Disc& eq_interfaces = refequation_interfaces.valeur();
295 const Maillage_FT_Disc& mesh = eq_interfaces.maillage_interface_pour_post();
296 const double temps_courant = mon_probleme->schema_temps().temps_courant();
297
298 const int nb_sommets_local = mesh.sommets().dimension(0);
299 const int nb_facettes_local = mesh.facettes().dimension(0);
300
301 for (int num_loc = 0; num_loc < 2; num_loc++)
302 {
303 Localisation loc = SOMMETS;
304 if (num_loc == 1)
305 loc = ELEMENTS;
306
308
309 const int nb_champs = liste.size();
310 if (nb_champs == 0)
311 continue;
312
313 const char *som_elem = loc == SOMMETS ? "SOM" : "ELEM";
314
315 DoubleTab dtab;
316 IntTab itab;
317
318 for (int i = 0; i < nb_champs; i++)
319 {
320 const Motcle& nom_du_champ = liste[i];
321 if (eq_interfaces.get_champ_post_FT(nom_du_champ, loc, &dtab))
322 {
323 // ok, le champ est dans dtab
324 }
325 else if (eq_interfaces.get_champ_post_FT(nom_du_champ, loc, &itab))
326 {
327 const int n = itab.dimension(0);
328 const int m = itab.nb_dim() == 1 ? 1 : itab.dimension(1);
329 dtab.resize(n, m);
330 // copie du champ dans dtab
331 if (itab.nb_dim() == 1)
332 for (int j = 0; j < n; j++)
333 dtab(j, 0) = (double) itab(j);
334 else
335 for (int j = 0; j < n; j++)
336 for (int k = 0; k < m; k++)
337 dtab(j, k) = (double) itab(j, k);
338 }
339 else
340 {
341 // Normalement on aurait deja du detecter cette erreur a la lecture du postraitement :
342 Cerr << "Error for Postraitement_FTD_base::postprocess_field_values" << finl;
343 Cerr << "Unknown field : " << nom_du_champ << finl;
345 }
346
347 const int nb_items = dtab.dimension(0);
348 const int nb_items_attendus = loc == SOMMETS ? nb_sommets_local : nb_facettes_local;
349 const char *msg = loc == SOMMETS ? " nb_noeuds " : " nb_facettes ";
350 const int nb_compo = (dtab.nb_dim() == 1 ? 0 : dtab.dimension(1));
351 if (nb_items != nb_items_attendus)
352 {
353 Cerr << "Error for Postraitement_FTD_base::postprocess_field_values" << finl;
354 Cerr << msg << "= " << nb_items << finl;
355 Cerr << msg << "expected = " << nb_items_attendus << finl;
357 }
358 // [ABN] should I really bother with this?:
359 Noms unites(nb_compo), noms_compo;
360 std::string cp[3] = { "X", "Y", "Z" };
361 for (int nc = 0; nc < nb_compo; nc++)
362 {
363 unites.add("");
364 noms_compo.add(nc < 3 ? cp[nc] : Nom(nc));
365 }
366 Domaine dummy_dom;
367 dummy_dom.nommer(id_domaine_);
368 Nom nature = nb_compo == 1 ? "scalar" : "vectorial";
369 const int component_to_process = -1; // meaning that we always want all components
370 // For ELEMENT processing, we need to filter out virtual facettes (if requested):
371 if (loc == ELEMENTS && no_virtuals_)
372 {
373 DoubleTab new_dtab;
374 filter_out_array(dtab, new_dtab);
375 postraiter_tableau(dummy_dom, unites, noms_compo, component_to_process, temps_courant, nom_du_champ, som_elem, nature, new_dtab);
376 }
377 else
378 postraiter_tableau(dummy_dom, unites, noms_compo, component_to_process, temps_courant, nom_du_champ, som_elem, nature, dtab);
379 }
380 }
381}
void nommer(const Nom &nom) override
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Format_Post_CGNS
int ecrire_domaine_low_level(const Domaine *, const Nom &, const DoubleTab &, const IntTab &, const Motcle &)
: Classe de postraitement des champs euleriens au format lata
void ecrire_domaine_low_level(const Nom &id_dom, const DoubleTab &sommets, const IntTab &elements, const Motcle &type_elem)
Low level routine to write a mesh into a LATA file.
: class Maillage_FT_Disc Cette classe decrit un maillage:
const DoubleTab & sommets() const
renvoie le tableau des sommets (reels et virtuels) dimension(0) = nombre de sommets,
int facette_virtuelle(int i) const
Renvoie 0 si la facette m'appartient, 1 sinon.
const IntTab & facettes() const
renvoie le tableau des facettes (reelles et virtuelles) dimension(0) = nombre de facettes,
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
Un tableau d'objets de la classe Motcle.
Definition Motcle.h:63
int contient_(const char *const ch) const
Definition Motcle.cpp:333
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual int debute_par(const char *const n) const
Definition Nom.cpp:319
const Nom & le_nom() const override
Renvoie *this;.
Definition Nom.cpp:563
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
friend class Entree
Definition Objet_U.h:76
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
virtual void register_interface_field(const Motcle &nom_champ, const Motcle &loc_lu)
void filter_out_array(const DoubleTab &dtab, DoubleTab &new_dtab) const
int filter_out_virtual_fa7(IntTab &new_fa7)
Build a reduced version of the facettes array, excluding virtual ones Also update the internal renumb...
void lire_champs_interface(Entree &)
lecture de la liste de champs aux interfaces a postraiter
int ecrire_maillage_ft_disc()
Write the Maillage_FT_Disc object into a LATA file in V2 format.
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
int write_extra_mesh() override
Override. Add the interfaces to the file output.
virtual void lire_entete_bloc_interface(Entree &is)
static const char *const demande_description
classe Postraitement La classe est dotee -d une liste de champs generiques champs_post_complet_ qui c...
int postraiter_tableau(const Domaine &dom, const Noms &unites, const Noms &noms_compo, const int ncomp, const double temps, Nom nom_post, const Nom &localisation, const Nom &nature, const DoubleTab &valeurs)
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
void add_locs_required_if_not(const Motcle &)
virtual const Transport_Interfaces_FT_Disc & equation_interfaces(const Motcle &nom) const
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
Definition Process.cpp:104
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
int nb_dim() const
Definition TRUSTTab.h:199
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
virtual int get_champ_post_FT(const Motcle &champ, Postraitement_base::Localisation loc, DoubleTab *dtab=0) const
Cherche le champ discret aux interfaces dont le nom est "champ", et verifie qu'il peut etre postraite...
virtual const Maillage_FT_Disc & maillage_interface_pour_post() const
Renvoie le maillage stocke specialement pour le postraitement (si on veut postraiter un etat intermed...