TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Terme_Source_Canal_RANS_LES_VEF_Face.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 <Terme_Source_Canal_RANS_LES_VEF_Face.h>
17#include <Champ_Uniforme.h>
18#include <Domaine_VEF.h>
19#include <Schema_Temps_base.h>
20#include <Probleme_base.h>
21#include <EFichier.h>
22#include <Champ_P1NC.h>
23#include <SFichier.h>
24
25Implemente_instanciable_sans_destructeur(Terme_Source_Canal_RANS_LES_VEF_Face,"Source_Canal_RANS_LES_VEF_P1NC",Source_base);
26
28{
29 //The destructor is called at initialization, so
30 //the field saving is done outside initialization
31
32 if(utemp.size()!=0)
33 {
34 SFichier fic ("utemp.dat");
35 fic << utemp;
36 }
37}
38
40{
41 return s << que_suis_je() ;
42}
43
44
45//// readOn
46//
47
49{
50 int compteur = 0;
51 Motcle mot_lu;
52 Motcle acc_ouverte("{");
53 Motcle acc_fermee("}");
54
55 // 0 => spatial average
56 // 1 => sliding temporal average (alpha average)
57 // 2 => temporal average
58 // 3 => temporal average starting at t=0
59
60 Motcles les_mots(11);
61 {
62 les_mots[0]="alpha_tau"; //source term relaxation coefficient
63 les_mots[1]="Ly"; //height of the plane channel (useful for spatial averaging)
64 les_mots[2]="t_moy_start"; //averaging start time
65 les_mots[3]="f_start"; //time from which the source term starts to be activated (weighted)
66 les_mots[4]="f_tot"; //time from which the source term is fully applied
67 les_mots[5]="type_moyenne";// 0: spatial average 1: sliding temporal average 2: temporal average
68 les_mots[6]="dir"; // forcing direction of the flow
69 les_mots[7]="u_tau"; // theoretical friction velocity
70 les_mots[8]="nu"; // molecular viscosity
71 les_mots[9]="rayon"; // cylinder radius
72 les_mots[10]="u_target"; // key for target field: 1=storage 2=reading
73 }
74 is >> mot_lu;
75 if(mot_lu != acc_ouverte)
76 {
77 Cerr << "Expected { instead of " << mot_lu
78 << " while reading the parameters of the wall law " << finl;
79 }
80 is >> mot_lu;
81 while(mot_lu != acc_fermee)
82 {
83 int rang=les_mots.search(mot_lu);
84 switch(rang)
85 {
86 case 0 :
87 is >> alpha_tau;
88 Cerr << "alpha_tau = " << alpha_tau << finl;
89 compteur++;
90 break;
91 case 1 :
92 is >> Ly;
93 Cerr << "Ly = "<< Ly << finl;
94 compteur++;
95 break;
96 case 2 :
97 is >> t_moy_start;
98 Cerr << " t_moy_start = "<< t_moy_start << finl;
99 compteur++;
100 break;
101 case 3 :
102 is >> f_start;
103 Cerr << " f_start = "<< f_start << finl;
104 compteur++;
105 break;
106 case 4 :
107 is >> f_tot;
108 Cerr << " f_tot = "<< f_tot << finl;
109 compteur++;
110 break;
111 case 5 :
112 is >> moyenne;
113 Cerr << "type_moyenne : " << moyenne << finl;
114 if(moyenne==0)
115 {
116 Cerr << " Relevance of spatial averaging in VEF? -> STOP (not implemented)" << finl;
117 exit();
118 }
119 if(moyenne==1)
120 {
121 Cerr << " YOUNES, YOUNES !!! !" << finl;
122 Cerr << " YOUNES EST PARTI !!!" << finl;
123 exit();
124 }
125 compteur++;
126 break;
127 case 6 :
128 is >> dir_nom;
129 if ( (dir_nom=="-X") || (dir_nom=="+X") ) dir=0;
130 else if( (dir_nom=="-Y") || (dir_nom=="+Y") ) dir=1;
131 else if( (dir_nom=="-Z") || (dir_nom=="+Z") ) dir=2;
132 else
133 {
134 Cerr << " ERROR when reading direction for forcing term " << finl;
135 Cerr << " 'dir' parameter has to be selected among following list : +X, -X, +Y, -Y, +Z or -Z " << finl;
136 exit();
137 }
138 Cerr << " forcing along axis: " << dir_nom << " -> component: " << dir <<finl;
139 compteur++;
140 break;
141 case 7 :
142 is >> u_tau;
143 Cerr << "friction velocity: " << u_tau << finl;
144 compteur++;
145 break;
146 case 8 :
147 is >> nu;
148 Cerr << "molecular viscosity: " << nu << finl;
149 compteur++;
150 break;
151 case 9 :
152 is >> rayon;
153 Cerr << "rayon : " << rayon << finl;
154 compteur++;
155 break;
156 case 10 :
157 is >> u_target;
158 Cerr << " u_target: " << u_target << finl;
159 compteur++;
160 break;
161 default :
162 {
163 Cerr << mot_lu << " is not a keyword understood by Source_Canal_RANS_LES_VEF_P1NC" << finl;
164 Cerr << "Understood keywords are: " << les_mots << finl;
165 exit();
166 }
167 }
168 is >> mot_lu;
169 }
170 Cerr << compteur << " keywords were read in the readOn of Source_Canal_RANS_LES_VEF_P1NC" << finl;
171
172 init();
173
174 return is;
175
176}
177
179 const Domaine_Cl_dis_base& domaine_Cl_dis)
180{
181 le_dom_VEF = ref_cast(Domaine_VEF, domaine_dis);
182 le_dom_Cl_VEF = ref_cast(Domaine_Cl_VEF, domaine_Cl_dis);
183}
184
188
190{
191 const Domaine_dis_base& zdisbase=mon_equation->inconnue().domaine_dis_base();
192 const Domaine_VEF& domaine_VEF=ref_cast(Domaine_VEF, zdisbase);
193 const DoubleTab& vitesse = mon_equation->inconnue().valeurs();
194 int nb_faces = domaine_VEF.nb_faces();
195 const DoubleTab& xv = domaine_VEF.xv();
196 const double tps = mon_equation->schema_temps().temps_courant();
197
198 double x1,x2;
199 int comp1=0;
200 int comp2=0;
201
202
203 U_RANS.resize(nb_faces,3);
204 U_RANS=0.;
205
206 utemp.resize(nb_faces,3);
207 utemp = 0.;
208
209 utemp_sum.resize(nb_faces,3);
210 utemp_sum = 0.;
211
212 if (tps > t_moy_start )
213 {
214 EFichier fic1 ("utemp.dat");
215
216 fic1 >> utemp;
217
218 // int trash;
219 //fic1 >> trash;
220
221 //for(int num_face = 0 ; num_face<nb_faces ; num_face++)
222 // {
223 // fic1 >> utemp(num_face,0) >> utemp(num_face,1) >> utemp(num_face,2);
224 // }
225 }
226
227
228 if(u_target==1) // Write target field
229 {
230 SFichier fic ("utarget.dat");
231
232 for(int num_face=0 ; num_face<nb_faces ; num_face++)
233 {
234 fic << vitesse(num_face,0) << vitesse(num_face,1) << vitesse(num_face,2);
235 }
236 }
237 if(u_target==2) // Read target field
238 {
239 EFichier fic ("vitesse_RANS.dat");
240 SFichier ficv ("verif_target.dat");
241
242 for(int num_face=0 ; num_face<nb_faces ; num_face++)
243 {
244 fic >> U_RANS(num_face,0) >> U_RANS(num_face,1) >> U_RANS(num_face,2);
245 ficv << U_RANS(num_face,0) << " " << U_RANS(num_face,1) << " " << U_RANS(num_face,2) << finl;
246 }
247 }
248 else // target field: analytical function
249 {
250 if(dir==0)
251 {
252 comp1=1 ;
253 comp2=2 ;
254 }
255 if(dir==1)
256 {
257 comp1=0 ;
258 comp2=2 ;
259 }
260 if(dir==2)
261 {
262 comp1=0 ;
263 comp2=1 ;
264 }
265
266 for(int num_face=0 ; num_face<nb_faces ; num_face++)
267 {
268 x1=xv(num_face,comp1);
269 x2=xv(num_face,comp2);
270
271 U_RANS(num_face,dir)= u_tau*(2.44*log((rayon-sqrt(x1*x1+x2*x2))*u_tau/nu)+5.32) ;
272
273 // FAT : HOT : U_RANS(num_face)= 0.1145*(2.44*log((0.077-sqrt(y*y+z*z))*0.1145/1.52e-7)+5.1) ;
274 // FAT : COLD: U_RANS(num_face)= 0.029*(2.44*log((0.077-sqrt(y*y+x*x))*0.029/6.45e-7)+5.1) ;
275 }
276 if( dir_nom=="-X" || dir_nom=="-Y" || dir_nom=="-Z") U_RANS*=-1.;
277 }
278
279}//end init
280
281
283{
284 //Cerr << "Inside mettre_a_jour" << finl;
285
286 const Domaine_VEF& domaine_VEF = le_dom_VEF.valeur();
287 // const DoubleTab& xv = domaine_VEF.xv();
288
289 const DoubleTab& vitesse = mon_equation->inconnue().valeurs();
290 const double dt = mon_equation->schema_temps().pas_de_temps();
291 const double dt_min = mon_equation->schema_temps().pas_temps_min();
292 const double tps = mon_equation->schema_temps().temps_courant();
293 int nb_faces = domaine_VEF.nb_faces();
294
295 static int cpt=0;
296
297 static double duree=0;
298
299 if(moyenne==1)
300 {
301
302 Cerr << "coded in VDF, requires VEF implementation? " << finl;
303 exit();
304
305 }// end moyenne == 1
306 else if(moyenne==2)
307 {
308 //******************************************************
309 //*************** TEMPORAL AVERAGE *********************
310 //******************************************************
311
312
313 if(tps>=t_moy_start)
314 {
315 double DT_moy=(tps-dt)-t_moy_start;
316
317 utemp*=DT_moy;
318
319 for (int num_face=0; num_face<nb_faces; num_face++)
320 for(int comp=0; comp<3; comp++)
321 {
322 utemp(num_face,comp) += dt*vitesse(num_face,comp);
323 }
324
325 utemp/=(DT_moy+dt);
326
327 // int face=123;
328 // SFichier fic_temp("utemp.dat", ios::app);
329 // SFichier fic_inst("uinst.dat", ios::app);
330 // fic_temp << tps << " " << utemp(face,0) << " "
331 // << xv(face,0) << " " << xv(face,1) << " " << xv(face,2) << finl;
332 // fic_inst << tps << " " << vitesse(face,0) << finl;
333 }
334
335
336 //***********************************************************
337 //*************** END TEMPORAL AVERAGE *****************
338 //*******************************************************
339 }
340 else if(moyenne==3)
341 {
342 //********************************************************************************
343 //*************** TIME AVERAGE (starting at t=0 or close...) *******************
344 //********************************************************************************
345
346 if(tps>0)
347 {
348 if(cpt==0)
349 {
350 for (int num_face=0; num_face<nb_faces; num_face++)
351 for(int comp=0; comp<3; comp++)
352 {
353 duree=400*dt;
354 utemp_sum(num_face,comp) = U_RANS(num_face,comp)*duree;
355 duree-=dt;
356 utemp(num_face,comp) = utemp_sum(num_face,comp)/(tps-dt_min+duree);
357
358 utemp_sum(num_face,comp) += dt*vitesse(num_face,comp);
359 utemp(num_face,comp) = vitesse(num_face,comp);
360 }
361 cpt++;
362
363 }
364 else
365 {
366 for (int num_face=0; num_face<nb_faces; num_face++)
367 for(int comp=0; comp<3; comp++)
368 {
369 utemp_sum(num_face,comp) += dt*vitesse(num_face,comp);
370 utemp(num_face,comp) = utemp_sum(num_face,comp)/(tps-dt_min+dt+duree);
371 }
372 }
373 }
374
375 }
376 else
377 {
378 Cerr << "moyenne = " << moyenne << finl;
379 Cerr << "Problem selecting the averaging type" << finl;
380 }
381
382
383}//end mettre_a_jour
384
385DoubleTab& Terme_Source_Canal_RANS_LES_VEF_Face::ajouter(DoubleTab& resu) const
386{
387 const Domaine_VEF& domaine_VEF = le_dom_VEF.valeur();
388 int nb_faces = domaine_VEF.nb_faces();
389 const DoubleVect& porosite_surf = equation().milieu().porosite_face();
390 const DoubleVect& volumes_entrelaces = domaine_VEF.volumes_entrelaces();
391 const double tps = mon_equation->schema_temps().temps_courant();
392 const double dt = mon_equation->schema_temps().pas_de_temps();
393 const double dt_min = mon_equation->schema_temps().pas_temps_min();
394
395 const DoubleTab& vitesse = mon_equation->inconnue().valeurs();
396
397 // DoubleTab resu_old(U_RANS);
398 // DoubleTab utemp_bar(utemp);
399
400 // if (sub_type(Champ_P1NC,mon_equation->inconnue()))
401 // {
402 // const Champ_P1NC& Ch = ref_cast(Champ_P1NC,mon_equation->inconnue());
403 // Ch.filtrer_L2(U_RANS_bar);
404 // Ch.filtrer_L2(utemp_bar);
405 // }
406
407 double vol = 0.;
408 SFichier fic_f("forcing_term.dat", ios::app);
409 SFichier fic_finst("finst.dat", ios::app);
410 double mbf0 = 0.; // mean body force
411 double mbf1 = 0.; // mean body force
412 double mbf2 = 0.; // mean body force
413 double mbf = 0.; //body force
414 //static int cpt = 0;
415 double coef=1.;
416 double scaling=0.;
417
418 if((tps>f_start)||((moyenne==3)&&(tps>dt_min)&&(tps>f_start)))
419 {
420 //cpt++;
421 if (tps < f_tot) coef*=(tps-f_start)/(f_tot-f_start);
422
423 for(int num_face = 0 ; num_face<nb_faces ; num_face++)
424 {
425 vol = volumes_entrelaces(num_face)*porosite_surf(num_face);
426
427 for(int comp=0; comp<3; comp++)
428 {
429 scaling=U_RANS(num_face,comp)/((U_RANS(num_face,0)*U_RANS(num_face,0)
430 +U_RANS(num_face,1)*U_RANS(num_face,1)
431 +U_RANS(num_face,2)*U_RANS(num_face,2))+1e-10);
432 // if(cpt > 150)
433 // resu(num_face,comp)=resu_old(num_face,comp);
434 // else
435 // {
436 resu(num_face,comp) = scaling*coef*((U_RANS(num_face,comp)-utemp(num_face,comp))/(alpha_tau*dt))*vol;
437 //f(num_face,comp) = /*coef**/((U_RANS_bar(num_face,comp)-utemp_bar(num_face,comp))/(alpha_tau*dt))*vol;
438 // resu_old(num_face,comp)=resu(num_face,comp);
439 // }
440 }
441
442 mbf0 += resu(num_face,0);
443 mbf1 += resu(num_face,1);
444 mbf2 += resu(num_face,2);
445 }
446
447 mbf0/=nb_faces;
448 mbf1/=nb_faces;
449 mbf2/=nb_faces;
450
451 int num_face=123;
452
453 scaling=U_RANS(num_face,0)/((U_RANS(num_face,0)*U_RANS(num_face,0)
454 +U_RANS(num_face,1)*U_RANS(num_face,1)
455 +U_RANS(num_face,2)*U_RANS(num_face,2))+1e-10);
456
457 mbf = scaling*((U_RANS(num_face,0)-utemp(num_face,0))/(alpha_tau*dt))*vol;
458
459 fic_finst << tps << " " << mbf << " " << U_RANS(num_face,0)
460 << " " << utemp(num_face,0) << " " << vitesse(num_face,0)
461 << " " << scaling << finl;
462
463 fic_f << tps << " " << mbf0 << " " << mbf1 <<" " << mbf2 << finl;
464
465 if (sub_type(Champ_P1NC,mon_equation->inconnue()))
466 {
467 const Champ_P1NC& Ch = ref_cast(Champ_P1NC,mon_equation->inconnue());
468 Ch.filtrer_resu(resu);
469 }
470
471
472 }//end if f_start
473
474 return resu;
475}
476
477DoubleTab& Terme_Source_Canal_RANS_LES_VEF_Face::calculer(DoubleTab& resu) const
478{
479 resu = 0;
480 return ajouter(resu);
481}
482
void filtrer_resu(DoubleTab &x) const
Definition Champ_P1NC.h:137
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
class Domaine_VEF
Definition Domaine_VEF.h:53
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
DoubleVect & volumes_entrelaces()
Definition Domaine_VF.h:99
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
File for reading. This class is to the C++ ifstream class what the Entree class is to the.
Definition EFichier.h:29
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Milieu_base & milieu() const =0
DoubleVect & porosite_face()
Definition Milieu_base.h:62
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
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
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
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
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
Definition SFichier.h:29
Base class for output streams.
Definition Sortie.h:52
Source_base A Source_base object is a term appearing on the right-hand side of an.
Definition Source_base.h:42
class Terme_Source_Canal_RANS_LES_VEF_Face
void mettre_a_jour(double) override
DOES NOTHING - to override in derived classes.
void associer_domaines(const Domaine_dis_base &, const Domaine_Cl_dis_base &) override