TrioCFD 1.9.9_beta
TrioCFD documentation
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
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
virtual DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const
Causes an error! Must be overridden by derived classes.
class Cond_lim_base Base class for the hierarchy of classes that represent the different boundary con...
Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the domain of discretized boundary conditions to which the object belongs.
virtual Frontiere_dis_base & frontiere_dis()
Returns the discretized boundary to which the boundary conditions apply.
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
Sortie & unlockfile() override
Releases the critical resource for the next process.
Sortie & lockfile() override
Allows the calling process to block waiting for the common resource shared by all processes,...
void set_bin(bool bin) override
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
Sortie & syncfile() override
Triggers writing to disk of the data accumulated on the different processors since the last call to s...
void precision(int) override
class Ecrire_fichier_xyz_valeur This class allows to dump fields values on some boundaries into a ded...
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
Computes the centers of gravity of each face.
Definition Faces.cpp:768
virtual int nb_comp() const
Definition Field_base.h:56
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Frontiere.h:49
int_t nb_faces() const
Returns the number of faces of the boundary.
Definition Frontiere.h:59
const Faces_t & faces() const
Definition Frontiere.h:54
const Frontiere & frontiere() const
Returns the associated geometric boundary.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Nom & majuscule()
Converts the name to uppercase. Only letters 'a'-'z' are modified.
Definition Nom.cpp:176
const std::string & getString() const
Definition Nom.h:92
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
static int format_precision_geom
Definition Objet_U.h:95
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class Operateur_Statistique_tps_base
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)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
Definition Process.cpp:133
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
void setf(IOS_FORMAT code) override
Base class for output streams.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133