TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Traitement_particulier_NS_Profils.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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 <Traitement_particulier_NS_Profils.h>
17#include <LecFicDistribueBin.h>
18#include <EcrFicCollecteBin.h>
19#include <Modele_turbulence_hyd_base.h>
20#include <Navier_Stokes_std.h>
21
22Implemente_base(Traitement_particulier_NS_Profils,"Traitement_particulier_NS_Profils",Traitement_particulier_NS_base);
23
24
25/*! @brief Prints the object to an output stream.
26 *
27 * @param is an output stream
28 * @return the modified output stream
29 */
31{
32 return is;
33}
34
35
36/*! @brief Reads the object from an input stream.
37 *
38 * @param is an input stream
39 * @return the modified input stream
40 */
42{
43 return is;
44}
45
47{
48 // Initialisation
49 IntVect Verif(8);
50 Verif=0;
51
52 // END Initialisation
53 Motcle accouverte = "{" , accfermee = "}" ;
54 Motcle motbidon, motlu;
55 is >> motbidon ;
56 if (motbidon == accouverte)
57 {
58 Motcles les_mots(8);
59 les_mots[0] = "const_profile";
60 les_mots[1] = "num_probes";
61 les_mots[2] = "dt_output";
62 les_mots[3] = "stats";
63 les_mots[4] = "profil_nu_t";
64 les_mots[5] = "reprise";
65 les_mots[6] = "reprise_nu_t";
66 les_mots[7] = "homog_dir";
67 is >> motlu;
68 while(motlu != accfermee)
69 {
70 int rang=les_mots.search(motlu);
71 switch(rang)
72 {
73 case 0 :
74 {
75 // For const_profile Constant Profile value : X, Y, Z
76 is >> motlu; // Direction of constant profile
77 if((motlu=="x")||(motlu=="X")) dir_profil = 0;
78 else if((motlu=="y")||(motlu=="Y")) dir_profil = 1;
79 else if((motlu=="z")||(motlu=="Z")) dir_profil = 2;
80 else
81 {
82 Cerr << "Wrong value for direction of profile !" << finl;
83 exit();
84 }
85 Cerr << "Profiles at constant " << motlu << finl;
86 break;
87 }
88 case 1 :
89 {
90 // Number of probes and reading of the values of the postions
91 is >> n_probes;
92 if(n_probes<1)
93 {
94 Cerr << "Error in Traitement_particulier_NS_Profils::lire" << finl;
95 Cerr << "Wrong value for number of probes (" << n_probes << ") :" << finl;
96 Cerr << "There must be at least one profile !" << finl;
97 exit();
98 }
99 positions.resize(n_probes);
100 for(int i=0; i<n_probes; i++)
101 {
102 is >> positions(i);
103 Cerr << " Probe_" << i+1 << " = " << positions(i) << finl;
104 }
105 break;
106 }
107 case 2 :
108 {
109 // For u_inst
110 is >> dt_post_inst; // time interval for printing spatial averages
111 // initialisation for spatial stats computation
112 oui_u_inst = 1;
113 Cerr << "Spatial average parameters read..." << finl;
114 Cerr << "dt_post_inst : " << dt_post_inst << finl;
115 break;
116 }
117 case 3 :
118 {
119 // For Time average
120 is >> temps_deb; // Initial time for time average statistics.
121 is >> temps_fin; // Final time for time average statistics.
122 is >> dt_post_stat; // Output intervalfor time average statistics.
123 oui_stat=1; // =1 : computing temporal stats
124 Cerr << "Reading time statitics parameters..." << finl;
125 Cerr << "Initial time : " << temps_deb << " End time : " << temps_fin << finl;
126 Cerr << "Time interval for output : " << dt_post_stat << finl;
127 // Check whether values specific to spatial stats computations have been provided
128 break;
129 }
130 case 4 :
131 {
132 // For eddy viscosity profile
133 oui_profil_nu_t = 1;
134 Cerr << "User asked for statistics on eddy-viscosity..." << finl;
135 const RefObjU& modele_turbulence = mon_equation->get_modele(TURBULENCE);
136 const Modele_turbulence_hyd_base& mod_turb = ref_cast(Modele_turbulence_hyd_base,modele_turbulence.valeur());
137 if(sub_type(Modele_turbulence_hyd_base,mod_turb))
138 Cerr << "Statistics for eddy-viscosity : OK !" << finl;
139 else
140 {
141 Cerr << "User asked for eddy-viscosity profile," << finl;
142 Cerr << "but is not defined in laminar case !" << finl;
143 Cerr << "Please check the problem type..." << finl;
144 exit();
145 }
146 break;
147 }
148 case 5 :
149 {
150 oui_repr = 1;
151 is >> fich_repr_u ; // name of the stats restart file
152 Cerr << "The time statistics file is : " << fich_repr_u << finl;
153 break;
154 }
155 case 6 :
156 {
157 // For eddy viscosity profile Reprise
158 oui_repr_nu_t = 1;
159 is >> fich_repr_nu_t ; // name of the nut stats restart file
160 Cerr << "Continuing statistics on eddy-viscosity : OK!" << finl;
161 break;
162 }
163 case 7 :
164 {
165 // For homogeneous direction specification : X, Y, Z
166 is >> motlu; // Direction of homogeneity
167 if((motlu=="x")||(motlu=="X")) homo_dir = 0;
168 else if((motlu=="y")||(motlu=="Y")) homo_dir = 1;
169 else if((motlu=="z")||(motlu=="Z")) homo_dir = 2;
170 else
171 {
172 Cerr << "Wrong value for homogeneous direction !" << finl;
173 exit();
174 }
175 Cerr << "Homogeneous direction : " << motlu << finl;
176 break;
177 }
178 default :
179 {
180 lire(motlu,is);
181 break;
182 }
183 }
184 is >> motlu;
185 }
186 is >> motlu;
187 if (motlu != accfermee)
188 {
189 Cerr << "Error while reading in Traitement_particulier_NS_Profils::lire" << finl;
190 Cerr << "We were expecting a }" << finl;
191 exit();
192 }
193 }
194 else
195 {
196 Cerr << "Error while reading in Traitement_particulier_NS_Profils" << finl;
197 Cerr << "We were expecting a {" << finl;
198 exit();
199 }
200
201 if ((oui_u_inst!=1)&&(oui_stat!=0))
202 {
203 Cerr << "User asked for time statistics :" << finl;
204 Cerr << "To do so, you also need to specify the parameters for space statistics," << finl;
205 Cerr << "since it is used for the time stats.." << finl;
206 exit();
207 }
208 if ((oui_profil_nu_t!=1)&&(oui_repr_nu_t!=0))
209 {
210 Cerr << "User asked for time statistics on nu_t :" << finl;
211 Cerr << "to do so, you also need to request the computation of space statistics," << finl;
212 Cerr << "since it is necessary for computing the temporal stats." << finl;
213 exit();
214 }
215 return is;
216}
217
218// Entree& Traitement_particulier_NS_canal::lire(const Motcle& motlu, Entree& is)
219// {
220// return is;
221// }
222
230
232{
233 if (oui_repr!=1) // this is not a stats restart, so no reading from a file
234 {
235 u_moy_temp_x.resize(n_probes,Nap);
236 u_moy_temp_x=0;
237 u_moy_temp_y.resize(n_probes,Nap);
238 u_moy_temp_y=0;
239 u_moy_temp_z.resize(n_probes,Nap);
240 u_moy_temp_z=0;
241
242 uv_moy_temp.resize(n_probes,Nap);
243 uv_moy_temp=0; // uv_moy time average
244
245 u2_moy_temp.resize(n_probes,Nap);
246 u2_moy_temp=0;
247 v2_moy_temp.resize(n_probes,Nap);
248 v2_moy_temp=0;
249 w2_moy_temp.resize(n_probes,Nap);
250 w2_moy_temp=0;
251
252 u3_moy_temp.resize(n_probes,Nap);
253 u3_moy_temp=0;
254 v3_moy_temp.resize(n_probes,Nap);
255 v3_moy_temp=0;
256 w3_moy_temp.resize(n_probes,Nap);
257 w3_moy_temp=0;
258
259 u4_moy_temp.resize(n_probes,Nap);
260 u4_moy_temp=0;
261 v4_moy_temp.resize(n_probes,Nap);
262 v4_moy_temp=0;
263 w4_moy_temp.resize(n_probes,Nap);
264 w4_moy_temp=0;
265
266 nu_t_temp.resize(n_probes,Nap);
267 nu_t_temp=0;
268 }
269}
270
272{
273 double tps = mon_equation->inconnue().temps();
274 int j,num_prof;
275 double ti,ti2;
276 Nom temps;
277 if (oui_stat == 1)
278 {
279 ifstream ficu0(fich_repr_u);
280 if (ficu0)
281 {
283 ficu >> temps;
284 u_moy_temp_x.resize(n_probes,Nap);
285 u_moy_temp_y.resize(n_probes,Nap);
286 u_moy_temp_z.resize(n_probes,Nap);
287
288 uv_moy_temp.resize(n_probes,Nap);
289 u2_moy_temp.resize(n_probes,Nap);
290 v2_moy_temp.resize(n_probes,Nap);
291 w2_moy_temp.resize(n_probes,Nap);
292
293 u3_moy_temp.resize(n_probes,Nap);
294 v3_moy_temp.resize(n_probes,Nap);
295 w3_moy_temp.resize(n_probes,Nap);
296
297 u4_moy_temp.resize(n_probes,Nap);
298 v4_moy_temp.resize(n_probes,Nap);
299 w4_moy_temp.resize(n_probes,Nap);
300
301 for(num_prof=0; num_prof<n_probes; num_prof++)
302 {
303 ficu >> Nxy(num_prof) >> Nyy(num_prof) >> Nzy(num_prof) >> Nuv(num_prof);
304 for (j=0; j<Nxy(num_prof); j++)
305 {
306 ficu >> u_moy_temp_x(num_prof,j) ;
307 ficu >> u2_moy_temp(num_prof,j);
308 }
309 for (j=0; j<Nyy(num_prof); j++)
310 {
311 ficu >> u_moy_temp_y(num_prof,j) ;
312 ficu >> v2_moy_temp(num_prof,j);
313 }
314 for (j=0; j<Nzy(num_prof); j++)
315 {
316 ficu >> u_moy_temp_z(num_prof,j);
317 ficu >> w2_moy_temp(num_prof,j);
318 }
319 for (j=0; j<Nuv(num_prof); j++)
320 ficu >> uv_moy_temp(num_prof,j) ;
321 }
322 //END reading "n_probes" profiles
323 ficu >> ti ;
324 Cerr << "ti=" << ti << finl;
325 Nom chc_ti = Nom(ti), chc_temps_deb = Nom(temps_deb);
326 Cerr << "chc_ti=" << chc_ti << " chc_temps_deb=" << chc_temps_deb << finl;
327 if (chc_ti!=chc_temps_deb)
328 {
329 if (ti > temps_deb)
330 {
331 Cerr << "problem resuming velocity stats!!" << finl;
332 Cerr << "The requested start time for stats " << temps_deb << finl;
333 Cerr << "is less than the start time of the saved stats!" << ti << finl;
334 exit();
335 }
336 else
337 {
338 if (temps_deb>=tps)
339 {
340 Cerr << "Restarting velocity stats computation from t=" << temps_deb << "s" << finl;
341 u_moy_temp_x = 0.;
342 u_moy_temp_y = 0.;
343 u_moy_temp_z = 0.;
344 uv_moy_temp = 0.;
345 u2_moy_temp = 0.;
346 v2_moy_temp = 0.;
347 w2_moy_temp = 0.;
348 oui_repr = 0;
349 }
350 else
351 {
352 Cerr << "The time at which you want to start stats has already been passed!!" << finl;
353 exit();
354 }
355 }
356 }
357 else
358 {
359 Cerr << "Continuing velocity stats computation, started at t=" << ti << "s" << finl;
360 temps_deb = ti;
361 }
362 }
363 else
364 {
365 if (tps<=temps_deb)
366 {
367 Cerr << "Stats computation has not started yet" << finl;
368 oui_repr = 0;
369 }
370 else
371 {
372 Cerr << "You must provide the file to resume the stats!!" << finl;
373 exit();
374 }
375 }
376
377 if ((oui_profil_nu_t!=0)&&(oui_repr_nu_t!=0))
378 {
379 ifstream ficu1(fich_repr_nu_t);
380 if (ficu1)
381 {
383 ficu >> temps;
384 nu_t_temp.resize(n_probes,Nap);
385 for(num_prof=0; num_prof<n_probes; num_prof++)
386 {
387 ficu >> Nuv(num_prof);
388 for (j=0; j<Nuv(num_prof); j++)
389 ficu >> nu_t_temp(num_prof,j) ;
390 }
391 ficu >> ti2 ;
392 if (ti2!=ti)
393 {
394 Cerr << "Problem : the nut stats and velocity stats are misaligned!!" << finl;
395 exit();
396 }
397 Cerr << "ti2=" << ti2 << finl;
398 Nom chc_ti2 = Nom(ti2), chc_temps_deb = Nom(temps_deb);
399 Cerr << "chc_ti2=" << chc_ti2 << " chc_temps_deb=" << chc_temps_deb << finl;
400 if (chc_ti2!=chc_temps_deb)
401 {
402 if (ti2 > temps_deb)
403 {
404 Cerr << "problem resuming nu_t stats!!" << finl;
405 Cerr << "The requested start time for stats " << temps_deb << finl;
406 Cerr << "is less than the start time of the saved stats!" << ti << finl;
407 exit();
408 }
409 else
410 {
411 if (temps_deb>=tps)
412 {
413 Cerr << "Restarting nu_t stats computation from t=" << temps_deb << "s" << finl;
414 nu_t_temp = 0.;
415 oui_repr_nu_t = 0;
416 }
417 else
418 {
419 Cerr << "The time at which you want to start stats has already been passed!" << finl;
420 exit();
421 }
422 }
423 }
424 else
425 {
426 Cerr << "Continuing nu_t stats computation, started at t=" << ti << "s" << finl;
427 temps_deb = ti2;
428 }
429 }
430 else
431 {
432 if (tps<=temps_deb)
433 {
434 Cerr << "Stats computation has not started yet" << finl;
435 oui_repr_nu_t = 0;
436 }
437 else
438 {
439 Cerr << "You must provide the file to resume the stats!" << finl;
440 exit();
441 }
442 }
443 }
444 }
445 else
446 {
447 Cerr << "No stats computation started!" << finl;
448 Cerr << "No resumption of u_moy_temp, u_et_temp and teta_moy_temp" << finl;
449 }
450}
451
453{
454 double tps = mon_equation->inconnue().temps();
455 if ( (oui_stat == 1)&&(tps>=temps_deb)&&(tps<=temps_fin) )
456 {
457 Cerr << "In Traitement_particulier_NS_canal::sauver_stat!!" << finl;
458 // Save the sum (without dividing by dt)
459 int j;
460 Nom temps = Nom(tps);
461 Nom fich_sauv_u ="u_moy_temp_";
462 fich_sauv_u+=temps;
463 fich_sauv_u+=".sauv";
464
465 // Save u_moy!!
466 EcrFicCollecteBin ficu (fich_sauv_u);
467 // EcrFicCollecte ficu (fich_sauv_u);
468 // EcrFicCollecteBin ficu ("u_moy_temp.sauv");
469 ficu << temps << finl;
470 int num_prof;
471 for(num_prof=0; num_prof<n_probes; num_prof++)
472 {
473 ficu << Nxy(num_prof) << Nyy(num_prof) << Nzy(num_prof) << Nuv(num_prof) << finl;
474 for (j=0; j<Nxy(num_prof); j++)
475 {
476 ficu << u_moy_temp_x(num_prof,j) << finl;
477 ficu << u2_moy_temp(num_prof,j) << finl;
478 }
479 for (j=0; j<Nyy(num_prof); j++)
480 {
481 ficu << u_moy_temp_y(num_prof,j) << finl;
482 ficu << v2_moy_temp(num_prof,j) << finl;
483 }
484 for (j=0; j<Nzy(num_prof); j++)
485 {
486 ficu << u_moy_temp_z(num_prof,j) << finl;
487 ficu << w2_moy_temp(num_prof,j) << finl;
488 }
489 for (j=0; j<Nuv(num_prof); j++)
490 ficu << uv_moy_temp(num_prof,j) << finl;
491 }
492 ficu << temps_deb << finl;
493 Cerr << "Saving u_moy_temp at t=" << tps << finl;
494 Cerr << "Start of stats computation at t=" << temps_deb << " to note for stats resumption!" << finl;
495
496 if (oui_profil_nu_t!=0)
497 {
498 Nom fich_sauv_nut ="nut_temp_";
499 fich_sauv_nut+=temps;
500 fich_sauv_nut+=".sauv";
501 // Save nut!!
502 EcrFicCollecteBin ficu2 (fich_sauv_nut);
503 ficu2 << temps << finl;
504 for(num_prof=0; num_prof<n_probes; num_prof++)
505 {
506 ficu2 << Nuv(num_prof) << finl;
507 for (j=0; j<Nuv(num_prof); j++)
508 ficu2 << nu_t_temp(num_prof,j) << finl;
509 }
510 ficu2 << temps_deb << finl;
511 Cerr << "Saving nu_t_temp at t=" << tps << finl;
512 Cerr << "Start of stats computation at t=" << temps_deb << " to note for stats resumption!" << finl;
513 }
514 }
515}
516
Writing to a file in binary format. This class implements the operators and virtual methods of the SF...
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Reading from a file in binary format.
Base class for the turbulence model hierarchy for Navier-Stokes equations.
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
friend class Entree
Definition Objet_U.h:71
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
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
const Objet_U & valeur() const
Definition TRUST_Ref.h:134
virtual void init_calcul_moyenne()=0
Traitement_particulier_NS_base Derives from Support_Champ_Masse_Volumique: use of rho.