TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Ecrire_fichier_xyz_valeur.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 <Operateur_Statistique_tps_base.h>
17#include <Ecrire_fichier_xyz_valeur.h>
18#include <Domaine_Cl_dis_base.h>
19#include <Schema_Temps_base.h>
20#include <Postraitement.h>
21#include <Equation_base.h>
22#include <EcrFicPartage.h>
23#include <Champ_base.h>
24
25Implemente_instanciable(Ecrire_fichier_xyz_valeur,"Ecrire_fichier_xyz_valeur",Objet_U);
26// XD ecrire_fichier_xyz_valeur interprete nul BRACE This keyword is used to write the values of a field only for some
27// XD_CONT boundaries in a text file with the following format: n_valeur NL2 x_1 y_1 [z_1] val_1 NL2 ... NL2 x_n y_n
28// XD_CONT [z_n] val_n NL2 The created files are named : pbname_fieldname_[boundaryname]_time.dat
29
31{
32 return os;
33}
34
36{
37 Param param(que_suis_je());
38 set_param(param);
39 param.lire_avec_accolades_depuis(is);
40
41 // we need to create fields here
42 // as only fields defined in equation or post-traiment are created when writing .dat file
43 for(auto fname : fields_names_ )
44 eqn_->probleme().creer_champ(fname);
45
46 return is;
47}
48
50{
51 param.ajouter_flag("binary_file",&binary_file_); // XD_ADD_P flag
52 // XD_CONT To write file in binary format
53 param.ajouter("dt", &dt_); // XD_ADD_P floattant
54 // XD_CONT File writing frequency
55 param.ajouter("fields", &fields_names_); // XD_ADD_P listchaine
56 // XD_CONT Names of the fields we want to write
57 param.ajouter("boundaries", &boundary_names_); // XD_ADD_P listchaine
58 // XD_CONT Names of the boundaries on which to write fields
59}
60
61
62bool Ecrire_fichier_xyz_valeur::write_field_during_current_timestep_() const
63{
64 const double timestep = eqn_->schema_temps().temps_courant();
65 const double scheme_dt = eqn_->schema_temps().pas_de_temps();
66 const double tmax = eqn_->schema_temps().temps_max();
67 const int nb_pas_dt_max = eqn_->schema_temps().nb_pas_dt_max();
68 const int nb_pas_dt = eqn_->schema_temps().nb_pas_dt();
69 const int stationnaire_atteint = eqn_->schema_temps().stationnaire_atteint();
70 int ok;
71 if (dt_<=scheme_dt || tmax<=timestep || nb_pas_dt_max<=nb_pas_dt || nb_pas_dt<=1 || stationnaire_atteint || eqn_->schema_temps().stop_lu())
72 ok=1;
73 else
74 {
75 // See Schema_Temps_base::limpr for info on epsilon and modf
76 double i, j, epsilon = 1.e-8;
77 modf(timestep/dt_ + epsilon, &i);
78 modf((timestep-scheme_dt)/dt_ + epsilon, &j);
79 ok = (i>j);
80 }
81 return (ok && dt_>0);
82}
83
84bool Ecrire_fichier_xyz_valeur::getStatField_(const Nom& fname, OBS_PTR(Champ_base)& field, OBS_PTR(Operateur_Statistique_tps_base)& op_stat) const
85{
86 bool champ_stat = false;
87
88 // Searching field among post-processing
89 for (auto &itr : eqn_->probleme().postraitements())
90 if (sub_type(Postraitement, itr.valeur()))
91 {
92 const Postraitement& post = ref_cast(Postraitement, itr.valeur());
93
94 Motcle nom_test = fname;
95 // Statistical fields are searched using an identifier.
96 // If the name indicated in the dataset is that of a statistical field,
97 // it must correspond to the name of the post-processing field.
98 post.champ_fonc(nom_test, field, op_stat);
99 if (field)
100 {
101 champ_stat = true;
102 break;
103 }
104 }
105
106 return champ_stat;
107}
108
109void Ecrire_fichier_xyz_valeur::writeValuesOnBoundary_(const Nom& fname, const std::string& bname, const DoubleTab& pos, const DoubleTab& val) const
110{
111 assert(val.dimension(0) == pos.dimension(0));
112
113 const double timestep = eqn_->schema_temps().temps_courant();
114 // Building filename
115 Nom nom_fic(eqn_->probleme().le_nom());
116 nom_fic+="_";
117 nom_fic+=fname;
118 nom_fic+="_";
119 nom_fic+=bname;
120 nom_fic+="_";
121 nom_fic+=Nom(timestep);
122 nom_fic+=".dat";
123
124 // Opening file
125 EcrFicPartage fic;
126 fic.set_bin(binary_file_);
127 fic.ouvrir(nom_fic);
128 fic.setf(ios::scientific);
130
131 // Writing file
132 const int nb_val = val.dimension(0);
133 trustIdType nb_val_tot = Process::mp_sum(nb_val);
135 {
136 if(binary_file_)
137 fic << "binary" << finl;
138 fic << nb_val_tot << finl;
139 }
140 barrier();
141 fic.lockfile();
142
143 const int nb_compo = val.dimension(1);
144 for (int i2=0; i2<nb_val; i2++)
145 {
146 // Writing coords
147 for (int j2=0; j2<dimension; j2++)
148 fic << pos(i2,j2) << " ";
149 // Writing values
150 for (int nb=0; nb<nb_compo; nb++)
151 fic << val(i2,nb) << " " ;
152 fic << finl;
153 }
154 fic.unlockfile();
155 barrier();
156 fic.syncfile();
157 fic.close();
158}
159
161{
162 if(!eqn_)
163 return;
164
165 if (!write_field_during_current_timestep_())
166 return;
167
168 for (auto fname : fields_names_ )
169 {
170 OBS_PTR(Champ_base) field;
171 OBS_PTR(Operateur_Statistique_tps_base) op_stat;
172 bool champ_stat = getStatField_(fname, field, op_stat);
173 if(!champ_stat)
174 {
175 // If the field is not a statistical field,
176 // we retrieve a Champ_base
177 field = eqn_->probleme().get_champ(fname);
178 }
179
180 const int nb_bords_post = (int)boundary_names_.size();
181 if (nb_bords_post>0) // we'd like to post-process on some boundaries only
182 {
183 int nb_cl = eqn_->domaine_Cl_dis().nb_cond_lim();
184 for (auto bname : boundary_names_ )
185 {
186 int boundary_found = 0 ; // to assess that the name of the boundary does correspond to a border
187 for (int i=0; i<nb_cl && !boundary_found; i++)
188 {
189 const Cond_lim_base& la_cl = eqn_->domaine_Cl_dis().les_conditions_limites(i);
190 const Frontiere& la_frontiere = la_cl.frontiere_dis().frontiere();
191 if (la_frontiere.le_nom() == bname)
192 {
193 boundary_found = 1;
194
195 // Array containing the centers of the boundary faces
196 DoubleTab pos;
197 la_frontiere.faces().calculer_centres_gravite(pos);
198
199 // Array containing the field values at the face centers
200 const int nb_val = la_frontiere.nb_faces();
201 int nb_compo = field->nb_comp();
202 DoubleTab val(nb_val,nb_compo);
203 val = 0.;
204 if(champ_stat)
205 {
206 DoubleTab copie(field->valeurs());
207 field->valeurs() = op_stat->calculer_valeurs();
208 field->valeur_aux(pos, val);
209 field->valeurs() = copie;
210 }
211 else
212 field->valeur_aux(pos, val);
213
214 // writing everything into the file, ND: I add majuscule() to keep pre 1.9.4 filenames
215 writeValuesOnBoundary_(fname.majuscule(), bname.getString(), pos, val);
216 }
217 }
218 if (!boundary_found)
219 {
220 Cerr << "You try to use the method Ecrire_fichier_xyz_valeur with an unknown boundary name" << finl;
221 Cerr << "The boundary named " << bname << " is not recognized"<< finl;
222 exit();
223 }
224 }
225 }
226 else // we'd like to post-process the entire domain
227 {
228 Cerr << "The option of post processing the entire domain with Ecrire_fichier_xyz_valeur is now obsolete." <<finl;
229 exit();
230 }
231 }
232}
virtual DoubleTab & valeurs()=0
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
virtual DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const
Provoque une erreur ! Doit etre surchargee par les classes derivees.
classe Cond_lim_base Classe de base pour la hierarchie des classes qui representent les differentes c...
Domaine_Cl_dis_base & domaine_Cl_dis()
Renvoie le domaine des conditions aux limites discretisee dont l'objet fait partie.
virtual Frontiere_dis_base & frontiere_dis()
Renvoie la frontiere discretisee a laquelle les conditions aux limites s'appliquent.
const Cond_lim & les_conditions_limites(int) const
Renvoie la i-ieme condition aux limites.
Sortie & unlockfile() override
Permet de debloquer la ressource critique pour leprocessus suivant.
Sortie & lockfile() override
Permet au processus appelant de bloquer en attente de la ressource commune a tous les processus qui e...
void set_bin(bool bin) override
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Ouvre le fichier avec les parametres mode et prot donnes Ces parametres sont les parametres de la met...
Sortie & syncfile() override
Provoque l'ecriture sur disque des donnees accumulees sur les differents processeurs depuis le dernie...
void precision(int) override
classe Ecrire_fichier_xyz_valeur This class allows to dump fields values on some boundaries into a de...
void set_param(Param &param) const override
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void calculer_centres_gravite(DoubleTab_t &xv) const
Calcule les centres de gravite de chaque face.
Definition Faces.cpp:776
virtual int nb_comp() const
Definition Field_base.h:56
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Frontiere.h:49
int_t nb_faces() const
Renvoie le nombre de faces de la frontiere.
Definition Frontiere.h:59
const Faces_t & faces() const
Definition Frontiere.h:54
const Frontiere & frontiere() const
Renvoie la frontiere geometrique associee.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Nom & majuscule()
Transforme le nom en majuscules Seules les lettres 'a'-'z' sont modifiees.
Definition Nom.cpp:180
const std::string & getString() const
Definition Nom.h:92
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
static int dimension
Definition Objet_U.h:99
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
static int format_precision_geom
Definition Objet_U.h:100
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
classe Operateur_Statistique_tps_base Represente des operations statistiques sur les champs.
virtual DoubleTab calculer_valeurs() const =0
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_flag(const char *keyword, const bool *value)
Register a boolean flag whose mere presence switches it to true.
Definition Param.cpp:474
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
int champ_fonc(Motcle &nom_champ, OBS_PTR(Champ_base)&mon_champ, OBS_PTR(Operateur_Statistique_tps_base)&operateur_statistique) const
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
static void barrier()
Synchronise tous les processeurs du groupe courant (attend que tous les processeurs soient arrives a ...
Definition Process.cpp:136
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
void setf(IOS_FORMAT code) override
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133