7.3
general documentation
cs_wall_functions.h
Go to the documentation of this file.
1 #ifndef __CS_WALL_FUNCTIONS_H__
2 #define __CS_WALL_FUNCTIONS_H__
3 
4 /*============================================================================
5  * Wall functions
6  *============================================================================*/
7 
8 /*
9  This file is part of code_saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2022 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 /*----------------------------------------------------------------------------
31  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "bft_printf.h"
35 #include "cs_base.h"
36 #include "cs_math.h"
37 #include "cs_turbulence_model.h"
38 
39 /*----------------------------------------------------------------------------*/
40 
42 
43 /*=============================================================================
44  * Local Macro definitions
45  *============================================================================*/
46 
47 /*============================================================================
48  * Type definition
49  *============================================================================*/
50 
51 /* Wall function type */
52 /*--------------------*/
53 
54 typedef enum {
55 
65 
67 
68 typedef enum {
69 
75  CS_WALL_F_S_SMOOTH_ROUGH = 4,//TODO merge with MO ?
76 
78 
79 /* Wall functions descriptor */
80 /*---------------------------*/
81 
82 typedef struct {
83 
84  cs_wall_f_type_t iwallf; /* wall function type */
85 
86  cs_wall_f_s_type_t iwalfs; /* wall function type for scalars */
87 
88  double ypluli; /* limit value of y+ for the viscous
89  sublayer */
90 
92 
93 /*============================================================================
94  * Global variables
95  *============================================================================*/
96 
97 /* Pointer to wall functions descriptor structure */
98 
100 
101 /*============================================================================
102  * Private function definitions
103  *============================================================================*/
104 
105 /*----------------------------------------------------------------------------*/
122 /*----------------------------------------------------------------------------*/
123 
124 inline static void
126  cs_real_t vel,
127  cs_real_t y,
128  int *iuntur,
129  cs_lnum_t *nsubla,
130  cs_lnum_t *nlogla,
131  cs_real_t *ustar,
132  cs_real_t *uk,
133  cs_real_t *yplus,
134  cs_real_t *ypup,
135  cs_real_t *cofimp)
136 {
137  const double ypluli = cs_glob_wall_functions->ypluli;
138 
139  const double ydvisc = y / l_visc;
140 
141  /* Compute the friction velocity ustar */
142 
143  *ustar = pow((vel/(cs_turb_apow * pow(ydvisc, cs_turb_bpow))), cs_turb_dpow);
144  *uk = *ustar;
145  *yplus = *ustar * ydvisc;
146 
147  /* In the viscous sub-layer: U+ = y+ */
148  if (*yplus <= ypluli) {
149 
150  *ustar = sqrt(vel / ydvisc);
151  *yplus = *ustar * ydvisc;
152  *uk = *ustar;
153  *ypup = 1.;
154  *cofimp = 0.;
155 
156  /* Disable the wall funcion count the cell in the viscous sub-layer */
157  *iuntur = 0;
158  *nsubla += 1;
159 
160  /* In the log layer */
161  } else {
162  *ypup = pow(vel, 2. * cs_turb_dpow-1.)
163  / pow(cs_turb_apow, 2. * cs_turb_dpow);
164  *cofimp = 1. + cs_turb_bpow
165  * pow(*ustar, cs_turb_bpow + 1. - 1./cs_turb_dpow)
166  * (pow(2., cs_turb_bpow - 1.) - 2.);
167 
168  /* Count the cell in the log layer */
169  *nlogla += 1;
170 
171  }
172 }
173 
174 /*----------------------------------------------------------------------------*/
193 /*----------------------------------------------------------------------------*/
194 
195 inline static void
197  cs_real_t l_visc,
198  cs_real_t vel,
199  cs_real_t y,
200  int *iuntur,
201  cs_lnum_t *nsubla,
202  cs_lnum_t *nlogla,
203  cs_real_t *ustar,
204  cs_real_t *uk,
205  cs_real_t *yplus,
206  cs_real_t *ypup,
207  cs_real_t *cofimp)
208 {
209  const double ypluli = cs_glob_wall_functions->ypluli;
210 
211  double ustarwer, ustarmin, ustaro, ydvisc;
212  double eps = 0.001;
213  int niter_max = 100;
214  int iter = 0;
215  double reynolds;
216 
217  /* Compute the local Reynolds number */
218 
219  ydvisc = y / l_visc;
220  reynolds = vel * ydvisc;
221 
222  /*
223  * Compute the friction velocity ustar
224  */
225 
226  /* In the viscous sub-layer: U+ = y+ */
227  if (reynolds <= ypluli * ypluli) {
228 
229  *ustar = sqrt(vel / ydvisc);
230  *yplus = *ustar * ydvisc;
231  *uk = *ustar;
232  *ypup = 1.;
233  *cofimp = 0.;
234 
235  /* Disable the wall funcion count the cell in the viscous sub-layer */
236  *iuntur = 0;
237  *nsubla += 1;
238 
239  /* In the log layer */
240  } else {
241 
242  /* The initial value is Wener or the minimun ustar to ensure convergence */
243  ustarwer = pow(fabs(vel) / cs_turb_apow / pow(ydvisc, cs_turb_bpow),
244  cs_turb_dpow);
245  ustarmin = exp(-cs_turb_cstlog * cs_turb_xkappa)/ydvisc;
246  ustaro = CS_MAX(ustarwer, ustarmin);
247  *ustar = (cs_turb_xkappa * vel + ustaro)
248  / (log(ydvisc * ustaro) + cs_turb_xkappa * cs_turb_cstlog + 1.);
249 
250  /* Iterative solving */
251  for (iter = 0; iter < niter_max
252  && fabs(*ustar - ustaro) >= eps * ustaro; iter++) {
253  ustaro = *ustar;
254  *ustar = (cs_turb_xkappa * vel + ustaro)
255  / (log(ydvisc * ustaro) + cs_turb_xkappa * cs_turb_cstlog + 1.);
256  }
257 
258  if (iter >= niter_max) {
259  bft_printf(_("WARNING: non-convergence in the computation\n"
260  "******** of the friction velocity\n\n"
261  "face id: %ld \n"
262  "friction vel: %f \n" ), (long)ifac, *ustar);
263  }
264 
265  *uk = *ustar;
266  *yplus = *ustar * ydvisc;
267  *ypup = *yplus / (log(*yplus) / cs_turb_xkappa + cs_turb_cstlog);
268  *cofimp = 1. - *ypup / cs_turb_xkappa * 1.5 / *yplus;
269 
270  /* Count the cell in the log layer */
271  *nlogla += 1;
272 
273  }
274 
275 }
276 
277 /*----------------------------------------------------------------------------
278  * Compute du+/dy+ for a given yk+.
279  *
280  * parameters:
281  * yplus <-- dimensionless distance
282  *
283  * returns:
284  * the resulting dimensionless velocity.
285  *----------------------------------------------------------------------------*/
286 
287 inline static cs_real_t
289  cs_real_t ka,
290  cs_real_t B,
291  cs_real_t cuv,
292  cs_real_t y0,
293  cs_real_t n)
294 {
295  cs_real_t uplus, f_blend;
296 
297  f_blend = exp(-0.25*cuv*pow(yp,3));
298  uplus = f_blend*yp + (log(yp)/ka +B)*(1.-exp(-pow(yp/y0,n)))*(1-f_blend);
299 
300  return uplus;
301 }
302 
303 /*----------------------------------------------------------------------------
304  * Compute du+/dy+ for a given yk+.
305  * parameters:
306  * yplus <-- dimensionless distance
307  * returns:
308  * the resulting dimensionless velocity gradient.
309  *----------------------------------------------------------------------------*/
310 
311 inline static cs_real_t
313  cs_real_t ka,
314  cs_real_t B,
315  cs_real_t cuv,
316  cs_real_t y0,
317  cs_real_t n)
318 {
319  cs_real_t dupdyp;
320 
321  dupdyp = exp(-0.25*cuv*pow(yp,3))
322  - 0.75*cuv*pow(yp,3.)*exp(-0.25*cuv*pow(yp,3.))
323  + n*(1.-exp(-0.25*cuv*pow(yp,3.)))*(pow(yp,n-1.)/pow(y0,n))
324  *exp(-pow(yp/y0,n))*((1./ka)*log(yp)+B)
325  + 0.75*cuv*pow(yp,2.)*exp(-0.25*cuv*pow(yp,3.))
326  *(1.-exp(-pow(yp/y0,n)))*((1./ka)*log(yp)+B)
327  + (1./ka/yp)*(1.-exp(-pow(yp/y0,n)))*(1-exp(-0.25*cuv*pow(yp,3.)));
328 
329  return dupdyp;
330 }
331 
332 /*----------------------------------------------------------------------------*/
355 /*----------------------------------------------------------------------------*/
356 
357 inline static void
359  cs_real_t l_visc,
360  cs_real_t t_visc,
361  cs_real_t vel,
362  cs_real_t y,
363  cs_real_t kinetic_en,
364  int *iuntur,
365  cs_lnum_t *nsubla,
366  cs_lnum_t *nlogla,
367  cs_real_t *ustar,
368  cs_real_t *uk,
369  cs_real_t *yplus,
370  cs_real_t *ypup,
371  cs_real_t *cofimp)
372 {
373  const double ypluli = cs_glob_wall_functions->ypluli;
374  double Re, g, t_visc_durb;
375  cs_real_t cstcuv, csty0, cstN;
376  cs_real_t dup1, dup2, uplus;
377 
378  /* Local constants */
379  cstcuv = 1.0674e-3;
380  csty0 = 14.5e0;
381  cstN = 2.25e0;
382 
383  /* Iterative process to determine uk through TKE law */
384  Re = sqrt(kinetic_en) * y / l_visc;
385  g = exp(-Re/11.);
386 
387  /* Comutation of uk*/
388  *uk = sqrt( (1.-g) * cs_turb_cmu025 * cs_turb_cmu025 * kinetic_en
389  + g * l_visc * vel/y);
390 
391  /* Local value of y+, estimated U+ */
392  *yplus = *uk * y / l_visc;
393  uplus = _uplus( *yplus, cs_turb_xkappa, cs_turb_cstlog, cstcuv, csty0, cstN);
394  /* Deduced velocity sclale uet*/
395  *ustar = vel / uplus;
396 
397  if (*yplus < 1.e-1) {
398 
399  *ypup = 1.0;
400  *cofimp = 0.0;
401 
402  *iuntur = 0;
403  *nsubla += 1;
404 
405  }
406  else {
407 
408  /* Dimensionless velocity gradient in y+ */
409  dup1 = _dupdyp(*yplus, cs_turb_xkappa, cs_turb_cstlog,
410  cstcuv, csty0, cstN);
411  /* Dimensionless velocity gradient in 2 x y+ */
412  dup2 = _dupdyp(2.0 * *yplus, cs_turb_xkappa,
413  cs_turb_cstlog, cstcuv, csty0, cstN);
414 
415  *ypup = *yplus / uplus;
416 
417  /* ------------------------------------------------------------
418  * Cofimp = U,F/U,I is built so that the theoretical expression
419  * of the production P_theo = dup1 * (1.0 - dup1) is equal to
420  * P_calc = mu_t,I * ((U,I - U,F + IF*dup2)/(2IF) )^2
421  * This is a generalization of the process implemented in the 2
422  * scales wall function (iwallf = 3).
423  * ------------------------------------------------------------*/
424 
425  /* Turbulent viscocity is modified for RSM so that its expression
426  * remain valid down to the wall, according to Durbin :
427  * nu_t = 0.22 * v'2 * k / eps */
428  const cs_turb_model_t *turb_model = cs_get_glob_turb_model();
429  assert(turb_model != NULL);
430  if (turb_model->itytur == 3)
431  t_visc_durb = t_visc / (kinetic_en * cs_turb_cmu ) * rnnb * 0.22;
432  else
433  t_visc_durb = t_visc;
434 
435  *cofimp
436  = 1. - *ypup * (2. * sqrt(l_visc / t_visc_durb * dup1 * (1. - dup1))
437  - dup2);
438 
439  /* log layer */
440  if (*yplus > ypluli) {
441  *nlogla += 1;
442  /* viscous sub-layer or buffer layer*/
443  } else {
444  *iuntur = 0;
445  *nsubla += 1;
446  }
447  }
448 }
449 
450 /*----------------------------------------------------------------------------*/
470 /*----------------------------------------------------------------------------*/
471 
472 inline static void
474  cs_real_t t_visc,
475  cs_real_t vel,
476  cs_real_t y,
477  cs_real_t kinetic_en,
478  int *iuntur,
479  cs_lnum_t *nsubla,
480  cs_lnum_t *nlogla,
481  cs_real_t *ustar,
482  cs_real_t *uk,
483  cs_real_t *yplus,
484  cs_real_t *ypup,
485  cs_real_t *cofimp)
486 {
487  const double ypluli = cs_glob_wall_functions->ypluli;
488 
489  double rcprod, ml_visc, Re, g;
490 
491  /* Compute the friction velocity ustar */
492 
493  /* Blending for very low values of k */
494  Re = sqrt(kinetic_en) * y / l_visc;
495  g = exp(-Re/11.);
496 
497  *uk = sqrt( (1.-g) * cs_turb_cmu025 * cs_turb_cmu025 * kinetic_en
498  + g * l_visc * vel / y);
499 
500  *yplus = *uk * y / l_visc;
501 
502  /* log layer */
503  if (*yplus > ypluli) {
504 
505  *ustar = vel / (log(*yplus) / cs_turb_xkappa + cs_turb_cstlog);
506  *ypup = *yplus / (log(*yplus) / cs_turb_xkappa + cs_turb_cstlog);
507  /* Mixing length viscosity */
508  ml_visc = cs_turb_xkappa * l_visc * *yplus;
509  rcprod = CS_MIN(cs_turb_xkappa, CS_MAX(1., sqrt(ml_visc / t_visc)) / *yplus);
510  *cofimp = 1. - *ypup / cs_turb_xkappa * ( 2. * rcprod - 1. / (2. * *yplus));
511 
512  *nlogla += 1;
513 
514  /* viscous sub-layer */
515  } else {
516 
517  if (*yplus > 1.e-12) {
518  *ustar = fabs(vel / *yplus); /* FIXME remove that: its is here only to
519  be fully equivalent to the former code. */
520  } else {
521  *ustar = 0.;
522  }
523  *ypup = 1.;
524  *cofimp = 0.;
525 
526  *iuntur = 0;
527  *nsubla += 1;
528 
529  }
530 }
531 
532 /*----------------------------------------------------------------------------*/
553 /*----------------------------------------------------------------------------*/
554 
555 inline static void
557  cs_real_t t_visc,
558  cs_real_t vel,
559  cs_real_t y,
560  cs_real_t kinetic_en,
561  int *iuntur,
562  cs_lnum_t *nsubla,
563  cs_lnum_t *nlogla,
564  cs_real_t *ustar,
565  cs_real_t *uk,
566  cs_real_t *yplus,
567  cs_real_t *dplus,
568  cs_real_t *ypup,
569  cs_real_t *cofimp)
570 {
571  CS_UNUSED(iuntur);
572 
573  const double ypluli = cs_glob_wall_functions->ypluli;
574 
575  double rcprod, ml_visc, Re, g;
576  /* Compute the friction velocity ustar */
577 
578  /* Blending for very low values of k */
579  Re = sqrt(kinetic_en) * y / l_visc;
580  g = exp(-Re/11.);
581 
582  *uk = sqrt( (1.-g) * cs_turb_cmu025 * cs_turb_cmu025 * kinetic_en
583  + g * l_visc * vel / y);
584 
585  *yplus = *uk * y / l_visc;
586 
587  /* Compute the friction velocity ustar */
588  *uk = cs_turb_cmu025 * sqrt(kinetic_en);//FIXME
589  *yplus = *uk * y / l_visc;//FIXME
590 
591  /* Log layer */
592  if (*yplus > ypluli) {
593 
594  *dplus = 0.;
595 
596  *nlogla += 1;
597 
598  /* Viscous sub-layer and therefore shift */
599  } else {
600 
601  *dplus = ypluli - *yplus;
602 
603  /* Count the cell as if it was in the viscous sub-layer */
604  *nsubla += 1;
605 
606  }
607 
608  /* Mixing length viscosity */
609  ml_visc = cs_turb_xkappa * l_visc * (*yplus + *dplus);
610  rcprod = CS_MIN(cs_turb_xkappa, CS_MAX(1., sqrt(ml_visc / t_visc)) / (*yplus + *dplus));
611 
612  *ustar = vel / (log(*yplus + *dplus) / cs_turb_xkappa + cs_turb_cstlog);
613  *ypup = *yplus / (log(*yplus + *dplus) / cs_turb_xkappa + cs_turb_cstlog);
614  *cofimp = 1. - *ypup
615  / cs_turb_xkappa * (2. * rcprod - 1. / (2. * *yplus + *dplus));
616 }
617 
618 /*----------------------------------------------------------------------------
619  * Compute u+ for a given yk+ between 0.1 and 200 according to the two
620  * scales wall functions using Van Driest mixing length.
621  * This function holds the coefficients of the polynome fitting log(u+).
622  *
623  * parameters:
624  * yplus <-- dimensionless distance
625  *
626  * returns:
627  * the resulting dimensionless velocity.
628  *----------------------------------------------------------------------------*/
629 
630 inline static cs_real_t
632 {
633  /* Coefficients of the polynome fitting log(u+) for yk < 200 */
634  static double aa[11] = {-0.0091921, 3.9577, 0.031578,
635  -0.51013, -2.3254, -0.72665,
636  2.969, 0.48506, -1.5944,
637  0.087309, 0.1987 };
638 
639  cs_real_t y1,y2,y3,y4,y5,y6,y7,y8,y9,y10, uplus;
640 
641  y1 = 0.25 * log(yplus);
642  y2 = y1 * y1;
643  y3 = y2 * y1;
644  y4 = y3 * y1;
645  y5 = y4 * y1;
646  y6 = y5 * y1;
647  y7 = y6 * y1;
648  y8 = y7 * y1;
649  y9 = y8 * y1;
650  y10 = y9 * y1;
651 
652  uplus = aa[0]
653  + aa[1] * y1
654  + aa[2] * y2
655  + aa[3] * y3
656  + aa[4] * y4
657  + aa[5] * y5
658  + aa[6] * y6
659  + aa[7] * y7
660  + aa[8] * y8
661  + aa[9] * y9
662  + aa[10] * y10;
663 
664  return exp(uplus);
665 }
666 
667 /*----------------------------------------------------------------------------*/
702 /*----------------------------------------------------------------------------*/
703 
704 inline static void
706  cs_real_t l_visc,
707  cs_real_t vel,
708  cs_real_t y,
709  cs_real_t kinetic_en,
710  int *iuntur,
711  cs_lnum_t *nsubla,
712  cs_lnum_t *nlogla,
713  cs_real_t *ustar,
714  cs_real_t *uk,
715  cs_real_t *yplus,
716  cs_real_t *ypup,
717  cs_real_t *cofimp,
718  cs_real_t *lmk,
719  cs_real_t kr,
720  bool wf)
721 {
722  double urplus, d_up, lmk15;
723 
724  if (wf)
725  *uk = sqrt(sqrt((1.-cs_turb_crij2)/cs_turb_crij1 * rnnb * kinetic_en));
726 
727  /* Set a low threshold value in case tangential velocity is zero */
728  *yplus = CS_MAX(*uk * y / l_visc, 1.e-4);
729 
730  /* Dimensionless roughness */
731  cs_real_t krp = *uk * kr / l_visc;
732 
733  /* Extension of Van Driest mixing length according to Rotta (1962) with
734  Cebeci & Chang (1978) correlation */
735  cs_real_t dyrp = 0.9 * (sqrt(krp) - krp * exp(-krp / 6.));
736  cs_real_t yrplus = *yplus + dyrp;
737 
738  if (dyrp <= 1.e-1)
739  d_up = dyrp;
740  else if (dyrp <= 200.)
741  d_up = _vdriest_dupdyp_integral(dyrp);
742  else
743  d_up = 16.088739022054590 + log(dyrp/200.) / cs_turb_xkappa;
744 
745  if (yrplus <= 1.e-1) {
746 
747  urplus = yrplus;
748 
749  if (wf) {
750  *iuntur = 0;
751  *nsubla += 1;
752 
753  *lmk = 0.;
754 
755  *ypup = 1.;
756 
757  *cofimp = 0.;
758  }
759 
760  } else if (yrplus <= 200.) {
761 
762  urplus = _vdriest_dupdyp_integral(yrplus);
763 
764  if (wf) {
765  *nlogla += 1;
766 
767  *ypup = *yplus / (urplus-d_up);
768 
769  /* Mixing length in y+ */
770  *lmk = cs_turb_xkappa * (*yplus) *(1-exp(- (*yplus) / cs_turb_vdriest));
771 
772  /* Mixing length in 3/2*y+ */
773  lmk15 = cs_turb_xkappa * 1.5 * (*yplus) *(1-exp(- 1.5 * (*yplus)
774  / cs_turb_vdriest));
775 
776  *cofimp = 1. - (2. / (1. + *lmk) - 1. / (1. + lmk15)) * *ypup;
777  }
778 
779  } else {
780 
781  urplus = 16.088739022054590 + log(yrplus/200) / cs_turb_xkappa;
782 
783  if (wf) {
784  *nlogla += 1;
785 
786  *ypup = *yplus / (urplus-d_up);
787 
788  /* Mixing length in y+ */
789  *lmk = cs_turb_xkappa * (*yplus) *(1-exp(- (*yplus) / cs_turb_vdriest));
790 
791  /* Mixing length in 3/2*y+ */
792  lmk15 = cs_turb_xkappa * 1.5 * (*yplus) *(1-exp(- 1.5 * (*yplus)
793  / cs_turb_vdriest));
794 
795  *cofimp = 1. - (2. / *lmk - 1. / lmk15) * *ypup;
796  }
797 
798  }
799 
800  *ustar = vel / (urplus-d_up);
801 }
802 
803 /*----------------------------------------------------------------------------*/
836 /*----------------------------------------------------------------------------*/
837 
838 inline static void
840  cs_real_t t_visc,
841  cs_real_t vel,
842  cs_real_t y,
843  cs_real_t rough_d,
844  cs_real_t kinetic_en,
845  int *iuntur,
846  cs_lnum_t *nsubla,
847  cs_lnum_t *nlogla,
848  cs_real_t *ustar,
849  cs_real_t *uk,
850  cs_real_t *yplus,
851  cs_real_t *dplus,
852  cs_real_t *ypup,
853  cs_real_t *cofimp)
854 {
855  CS_UNUSED(iuntur);
856 
857  const double ypluli = cs_glob_wall_functions->ypluli;
858 
859  double rcprod, ml_visc, Re, g;
860 
861  /* Compute the friction velocity ustar */
862 
863  /* Shifting of the wall distance to be consistant with
864  * the fully rough wall function
865  *
866  * ln((y+y0)/y0) = ln((y+y0)/alpha xi) + kappa * 5.2
867  *
868  * y0 = xi * exp(-kappa * 8.5)
869  * where xi is the sand grain roughness here
870  * y0 = alpha * xi * exp(-kappa * 5.2)
871  *
872  * so:
873  * alpha = exp(-kappa * (8.5 - 5.2)) = 0.25
874  *
875  */
876  cs_real_t y0 = rough_d;
877  /* Note : Sand grain roughness given by:
878  cs_real_t sg_rough = rough_d * exp(cs_turb_xkappa*cs_turb_cstlog_rough);
879  */
880 
881  /* Blending for very low values of k */
882  Re = sqrt(kinetic_en) * (y + y0) / l_visc;
883  g = exp(-Re/11.);
884 
885  *uk = sqrt( (1.-g) * cs_turb_cmu025 * cs_turb_cmu025 * kinetic_en
886  + g * l_visc * vel / (y + y0));
887 
888 
889  *yplus = *uk * y / l_visc;
890 
891  /* As for scalable wall functions, yplus is shifted of "dplus" */
892  *dplus = *uk * y0 / l_visc;
893 
894  /* Shift of the velocity profile due to roughness */
895  cs_real_t shift_vel = -log(1. + y0 * exp(cs_turb_xkappa * cs_turb_cstlog) * *uk/l_visc)
896  / cs_turb_xkappa;
897 
898  /* Log layer and shifted with the roughness */
899  if (*yplus > ypluli) {
900 
901  *nlogla += 1;
902 
903  }
904 
905  /* Viscous sub-layer and therefore shift again */
906  else {
907 
908  *dplus = ypluli - *yplus;
909  /* Count the cell as if it was in the viscous sub-layer */
910  *nsubla += 1;
911 
912  }
913 
914  cs_real_t uplus = log(*yplus + *dplus) / cs_turb_xkappa + cs_turb_cstlog + shift_vel;
915  *ustar = vel / uplus;
916 #if 0
917  bft_printf("uet=%f, u=%f, uplus=%f, yk=%f, duplus=%f\n", *ustar, vel, uplus, *yplus, 1./uplus);
918 #endif
919  *ypup = *yplus / uplus;
920 
921  /* Mixing length viscosity, compatible with both regimes */
922  ml_visc = cs_turb_xkappa * l_visc * (*yplus + *dplus);
923  rcprod = CS_MIN(cs_turb_xkappa, CS_MAX(1., sqrt(ml_visc / t_visc)) / (*yplus + *dplus));
924  *cofimp = 1. - *yplus / (cs_turb_xkappa * uplus)
925  * ( 2. * rcprod - 1. / (2. * *yplus + *dplus));
926 
927 }
928 
929 /*----------------------------------------------------------------------------*/
949 /*----------------------------------------------------------------------------*/
950 
951 inline static void
953  cs_real_t t_visc,
954  cs_real_t vel,
955  cs_real_t y,
956  int *iuntur,
957  cs_lnum_t *nsubla,
958  cs_lnum_t *nlogla,
959  cs_real_t *ustar,
960  cs_real_t *uk,
961  cs_real_t *yplus,
962  cs_real_t *dplus,
963  cs_real_t *ypup,
964  cs_real_t *cofimp)
965 {
966  CS_UNUSED(t_visc);
967  CS_UNUSED(nlogla);
968  CS_UNUSED(dplus);
969 
970  const double ypluli = cs_glob_wall_functions->ypluli;
971 
972  /* Compute the friction velocity ustar */
973 
974  *ustar = sqrt(vel * l_visc / y);
975  *yplus = *ustar * y / l_visc;
976  *uk = *ustar;
977  *ypup = 1.;
978  *cofimp = 0.;
979  *iuntur = 0;
980 
981  if (*yplus <= ypluli) {
982 
983  /* Disable the wall funcion count the cell in the viscous sub-layer */
984  *nsubla += 1;
985 
986  } else {
987 
988  /* Count the cell as if it was in the viscous sub-layer */
989  *nsubla += 1;
990 
991  }
992 }
993 
994 /*----------------------------------------------------------------------------*/
1024 /*----------------------------------------------------------------------------*/
1025 
1026 inline static void
1028  cs_real_t prl,
1029  cs_real_t prt,
1030  cs_real_t rough_t,
1031  cs_real_t uk,
1032  cs_real_t yplus,
1033  cs_real_t dplus,
1034  cs_real_t *htur,
1035  cs_real_t *yplim)
1036 {
1037  /* Local variables */
1038  double tplus;
1039  double beta2,a2;
1040  double yp2;
1041  double prlm1;
1042 
1043  const double epzero = cs_math_epzero;
1044 
1045  /*==========================================================================
1046  1. Initializations
1047  ==========================================================================*/
1048 
1049  (*htur) = CS_MAX(yplus,epzero)/CS_MAX(yplus+dplus,epzero);
1050 
1051  prlm1 = 0.1;
1052 
1053  /* Sand grain roughness is:
1054  * zeta = z0 * exp(kappa 8.5)
1055  * Then:
1056  * hp = zeta uk / nu * exp( -kappa(8.5 - 5.2))
1057  * = z0 * uk / nu * exp(kappa * 5.2)
1058  * where 5.2 is the smooth log constant, and 8.5 the rough one
1059  *
1060  * FIXME check if we should use a molecular Schmidt number
1061  */
1062  cs_real_t hp = rough_t *uk / l_visc * exp(cs_turb_xkappa*cs_turb_cstlog);
1063 
1064  /* Shift of the temperature profile due to roughness */
1065  cs_real_t shift_temp = -log(1. + hp);
1066 
1067  /*==========================================================================
1068  2. Compute htur for small Prandtl numbers
1069  ==========================================================================*/
1070 
1071  if (prl <= prlm1) {
1072  (*yplim) = prt/(prl*cs_turb_xkappa);
1073  if (yplus > (*yplim)) {
1074  tplus = prl*(*yplim) + prt/cs_turb_xkappa * (log((yplus+dplus)/(*yplim)) + shift_temp);
1075  (*htur) = prl * yplus / tplus;
1076  }
1077 
1078  /*========================================================================
1079  3. Compute htur for the model with three sub-layers
1080  ========================================================================*/
1081 
1082  } else {
1083  yp2 = sqrt(cs_turb_xkappa*1000./prt);
1084  (*yplim) = pow(1000./prl, 1./3.);
1085 
1086  a2 = 15.*pow(prl, 2./3.);
1087 
1088  if (yplus >= (*yplim) && yplus < yp2) {
1089  tplus = a2 - 500./((yplus+dplus)*(yplus+dplus));
1090  (*htur) = prl * yplus / tplus;
1091  }
1092 
1093  if (yplus >= yp2) {
1094  beta2 = a2 - 0.5 * prt /cs_turb_xkappa;
1095  tplus = beta2 + prt/cs_turb_xkappa*log((yplus+dplus)/yp2);
1096  (*htur) = prl * yplus / tplus;
1097  }
1098 
1099  }
1100 }
1101 
1102 /*----------------------------------------------------------------------------*/
1126 /*----------------------------------------------------------------------------*/
1127 
1128 inline static void
1130  cs_real_t prt,
1131  cs_real_t yplus,
1132  cs_real_t *htur)
1133 {
1134  cs_real_t prlrat = prl / prt;
1135 
1136  /* Parameters of the numerical quadrature */
1137  const int ninter_max = 100;
1138  const cs_real_t ypmax = 1.e2;
1139 
1140  /* No correction for very small yplus */
1141  if (yplus <= 0.1)
1142  *htur = 1.;
1143  else {
1144  cs_real_t ypint = CS_MIN(yplus, ypmax);
1145 
1146  /* The number of sub-intervals is taken proportional to yplus and equal to
1147  * ninter_max if yplus=ypmax */
1148 
1149  int npeff = CS_MAX((int)(ypint / ypmax * (double)(ninter_max)), 1);
1150 
1151  double dy = ypint / (double)(npeff);
1152  cs_real_t stplus = 0.;
1153  cs_real_t nut1 = 0.;
1154  cs_real_t nut2 = 0.;
1155 
1156  for (int ip = 1; ip <= npeff; ip++) {
1157  double yp = ypint * (double)(ip) / (double)(npeff);
1158  nut2 = cs_turb_xkappa * yp * (1. - exp(-yp / cs_turb_vdriest));
1159  stplus += dy / (1. + prlrat * 0.5 * (nut1 + nut2));
1160  nut1 = nut2;
1161  }
1162 
1163  if (yplus > ypint) {
1164  cs_real_t r = prlrat * cs_turb_xkappa;
1165  stplus += log( (1. + r*yplus) / (1. + r*ypint)) / r;
1166  }
1167 
1168  if (stplus >= 1.e-6)
1169  *htur = yplus / stplus;
1170  else
1171  *htur = 1.;
1172  }
1173 }
1174 
1175 /*----------------------------------------------------------------------------*/
1191 /*----------------------------------------------------------------------------*/
1192 
1193 inline static void
1195  cs_real_t prl,
1196  cs_real_t prt,
1197  cs_real_t rough_t,
1198  cs_real_t uk,
1199  cs_real_t yplus,
1200  cs_real_t dplus,
1201  cs_real_t *htur)
1202 {
1203  CS_UNUSED(prt);
1204 
1205  /* Sand grain roughness is:
1206  * zeta = z0 * exp(kappa 8.5)
1207  * Then:
1208  * hp = zeta uk / nu * exp( -kappa(8.5 - 5.2))
1209  * = z0 * uk / nu * exp(kappa * 5.2)
1210  * where 5.2 is the smooth log constant, and 8.5 the rough one
1211  *
1212  * FIXME check if we should use a molecular Schmidt number
1213  */
1214  cs_real_t hp = rough_t *uk / l_visc * exp(cs_turb_xkappa*cs_turb_cstlog);
1215  const double ypluli = cs_glob_wall_functions->ypluli;
1216  const double epzero = cs_math_epzero;
1217 
1218  (*htur) = CS_MAX(yplus,epzero)/CS_MAX(yplus+dplus,epzero);
1219 
1220  /* Shift of the temperature profile due to roughness */
1221  cs_real_t shift_temp = -log(1. + hp);
1222 
1223  if (yplus > ypluli) {
1224  cs_real_t tplus = prt * ((log(yplus+dplus) + shift_temp)/cs_turb_xkappa + cs_turb_cstlog);
1225  (*htur) = prl * yplus / tplus;
1226  }
1227 }
1228 
1229 /*============================================================================
1230  * Public function definitions for Fortran API
1231  *============================================================================*/
1232 
1233 /*----------------------------------------------------------------------------
1234  * Wrapper to cs_wall_functions_velocity.
1235  *----------------------------------------------------------------------------*/
1236 
1237 void CS_PROCF (wallfunctions, WALLFUNCTIONS)
1238 (
1239  const int *const iwallf,
1240  const cs_lnum_t *const ifac,
1241  const cs_real_t *const viscosity,
1242  const cs_real_t *const t_visc,
1243  const cs_real_t *const vel,
1244  const cs_real_t *const y,
1245  const cs_real_t *const rough_d,
1246  const cs_real_t *const rnnb,
1247  const cs_real_t *const kinetic_en,
1248  int *iuntur,
1249  cs_lnum_t *nsubla,
1250  cs_lnum_t *nlogla,
1251  cs_real_t *ustar,
1252  cs_real_t *uk,
1253  cs_real_t *yplus,
1254  cs_real_t *ypup,
1255  cs_real_t *cofimp,
1256  cs_real_t *dplus
1257 );
1258 
1259 /*----------------------------------------------------------------------------
1260  * Wrapper to cs_wall_functions_scalar.
1261  *----------------------------------------------------------------------------*/
1262 
1263 void CS_PROCF (hturbp, HTURBP)
1264 (
1265  const int *const iwalfs,
1266  const cs_real_t *const l_visc,
1267  const cs_real_t *const prl,
1268  const cs_real_t *const prt,
1269  const cs_real_t *const rough_t,
1270  const cs_real_t *const uk,
1271  const cs_real_t *const yplus,
1272  const cs_real_t *const dplus,
1273  cs_real_t *htur,
1274  cs_real_t *yplim
1275 );
1276 
1277 /*=============================================================================
1278  * Public function prototypes
1279  *============================================================================*/
1280 
1281 /*----------------------------------------------------------------------------
1282  *! \brief Provide access to cs_glob_wall_functions
1283  *----------------------------------------------------------------------------*/
1284 
1287 
1288 /*----------------------------------------------------------------------------*/
1316 /*----------------------------------------------------------------------------*/
1317 
1318 void
1320  cs_lnum_t ifac,
1321  cs_real_t l_visc,
1322  cs_real_t t_visc,
1323  cs_real_t vel,
1324  cs_real_t y,
1325  cs_real_t rough_d,
1326  cs_real_t rnnb,
1327  cs_real_t kinetic_en,
1328  int *iuntur,
1329  cs_lnum_t *nsubla,
1330  cs_lnum_t *nlogla,
1331  cs_real_t *ustar,
1332  cs_real_t *uk,
1333  cs_real_t *yplus,
1334  cs_real_t *ypup,
1335  cs_real_t *cofimp,
1336  cs_real_t *dplus);
1337 
1338 /*----------------------------------------------------------------------------*/
1363 /*----------------------------------------------------------------------------*/
1364 
1365 void
1367  cs_real_t l_visc,
1368  cs_real_t prl,
1369  cs_real_t prt,
1370  cs_real_t rough_t,
1371  cs_real_t uk,
1372  cs_real_t yplus,
1373  cs_real_t dplus,
1374  cs_real_t *htur,
1375  cs_real_t *yplim);
1376 
1377 /*----------------------------------------------------------------------------*/
1385 /*----------------------------------------------------------------------------*/
1386 
1387 void
1389  cs_real_t *st_exp,
1390  cs_real_t *st_imp);
1391 
1392 /*----------------------------------------------------------------------------*/
1393 
1395 
1396 #endif /* __CS_WALL_FUNCTIONS_H__ */
int itytur
Definition: cs_turbulence_model.h:139
double precision epzero
epsilon
Definition: cstnum.f90:40
Definition: cs_wall_functions.h:70
cs_wall_f_type_t iwallf
Definition: cs_wall_functions.h:84
static void cs_wall_functions_2scales_continuous(cs_real_t rnnb, cs_real_t l_visc, cs_real_t t_visc, cs_real_t vel, cs_real_t y, cs_real_t kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp)
Continuous law of the wall between the linear and log law, with two velocity scales based on the fric...
Definition: cs_wall_functions.h:358
static void cs_wall_functions_2scales_scalable(cs_real_t l_visc, cs_real_t t_visc, cs_real_t vel, cs_real_t y, cs_real_t kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *dplus, cs_real_t *ypup, cs_real_t *cofimp)
Scalable wall function: shift the wall if .
Definition: cs_wall_functions.h:556
cs_turb_model_t * cs_get_glob_turb_model(void)
Provide write access to turbulence model structure.
Definition: cs_turbulence_model.c:1535
#define BEGIN_C_DECLS
Definition: cs_defs.h:512
integer(c_int), pointer, save iwalfs
Wall functions for scalar.
Definition: optcal.f90:510
const cs_real_t cs_math_epzero
double cs_turb_cstlog
Definition: cs_turbulence_model.c:452
Turbulence model general options descriptor.
Definition: cs_turbulence_model.h:115
#define CS_UNUSED(x)
Definition: cs_defs.h:498
double cs_turb_cmu025
Definition: cs_turbulence_model.c:493
static cs_real_t _vdriest_dupdyp_integral(cs_real_t yplus)
Definition: cs_wall_functions.h:631
cs_wall_functions_t * cs_get_glob_wall_functions(void)
Definition: cs_wall_functions.c:296
static cs_real_t _uplus(cs_real_t yp, cs_real_t ka, cs_real_t B, cs_real_t cuv, cs_real_t y0, cs_real_t n)
Definition: cs_wall_functions.h:288
static void cs_wall_functions_s_arpaci_larsen(cs_real_t l_visc, cs_real_t prl, cs_real_t prt, cs_real_t rough_t, cs_real_t uk, cs_real_t yplus, cs_real_t dplus, cs_real_t *htur, cs_real_t *yplim)
The correction of the exchange coefficient is computed thanks to a similarity model between dynamic v...
Definition: cs_wall_functions.h:1027
double cs_turb_vdriest
Definition: cs_turbulence_model.c:441
Definition: cs_wall_functions.h:71
Definition: cs_wall_functions.h:58
double precision, dimension(ncharm), save a2
Definition: cpincl.f90:233
double cs_turb_cmu
Definition: cs_turbulence_model.c:490
Definition: cs_wall_functions.h:74
Definition: cs_wall_functions.h:57
double cs_turb_dpow
Definition: cs_turbulence_model.c:483
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
Definition: cs_field_pointer.h:68
Definition: cs_wall_functions.h:59
void hturbp(const int *const iwalfs, const cs_real_t *const l_visc, const cs_real_t *const prl, const cs_real_t *const prt, const cs_real_t *const rough_t, const cs_real_t *const uk, const cs_real_t *const yplus, const cs_real_t *const dplus, cs_real_t *htur, cs_real_t *yplim)
Definition: cs_wall_functions.c:260
double cs_turb_crij2
Definition: cs_turbulence_model.c:530
static void cs_wall_functions_s_smooth_rough(cs_real_t l_visc, cs_real_t prl, cs_real_t prt, cs_real_t rough_t, cs_real_t uk, cs_real_t yplus, cs_real_t dplus, cs_real_t *htur)
Rough Smooth Thermal Wall Function - Prototype.
Definition: cs_wall_functions.h:1194
static void cs_wall_functions_2scales_smooth_rough(cs_real_t l_visc, cs_real_t t_visc, cs_real_t vel, cs_real_t y, cs_real_t rough_d, cs_real_t kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *dplus, cs_real_t *ypup, cs_real_t *cofimp)
Two velocity scales wall function with automatic switch from rough to smooth.
Definition: cs_wall_functions.h:839
cs_wall_f_s_type_t
Definition: cs_wall_functions.h:68
double cs_turb_bpow
Definition: cs_turbulence_model.c:480
Definition: cs_wall_functions.h:61
Definition: cs_wall_functions.h:56
static void cs_wall_functions_s_vdriest(cs_real_t prl, cs_real_t prt, cs_real_t yplus, cs_real_t *htur)
The correction of the exchange coefficient is computed thanks to a numerical integration of: with ...
Definition: cs_wall_functions.h:1129
Definition: cs_wall_functions.h:73
#define CS_MIN(a, b)
Definition: cs_defs.h:475
real(c_double), pointer, save ypluli
limit value of for the viscous sublayer. ypluli depends on the chosen wall function: it is initializ...
Definition: cstphy.f90:302
integer(c_int), pointer, save iwallf
Wall functions Indicates the type of wall function used for the velocity boundary conditions on a fri...
Definition: optcal.f90:505
Definition: cs_wall_functions.h:60
double cs_turb_crij1
Definition: cs_turbulence_model.c:524
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
Definition: cs_wall_functions.h:64
static void cs_wall_functions_1scale_power(cs_real_t l_visc, cs_real_t vel, cs_real_t y, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp)
Power law: Werner & Wengle.
Definition: cs_wall_functions.h:125
static void cs_wall_functions_2scales_vdriest(cs_real_t rnnb, cs_real_t l_visc, cs_real_t vel, cs_real_t y, cs_real_t kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp, cs_real_t *lmk, cs_real_t kr, bool wf)
Two velocity scales wall function using Van Driest mixing length.
Definition: cs_wall_functions.h:705
#define END_C_DECLS
Definition: cs_defs.h:513
wall functions descriptor.
Definition: cs_wall_functions.h:82
#define _(String)
Definition: cs_defs.h:66
void cs_wall_functions_scalar(cs_wall_f_s_type_t iwalfs, cs_real_t l_visc, cs_real_t prl, cs_real_t prt, cs_real_t rough_t, cs_real_t uk, cs_real_t yplus, cs_real_t dplus, cs_real_t *htur, cs_real_t *yplim)
Compute the correction of the exchange coefficient between the fluid and the wall for a turbulent flo...
Definition: cs_wall_functions.c:530
Definition: cs_wall_functions.h:75
double cs_turb_apow
Definition: cs_turbulence_model.c:477
Definition: cs_wall_functions.h:63
#define CS_PROCF(x, y)
Definition: cs_defs.h:526
#define CS_MAX(a, b)
Definition: cs_defs.h:476
static void cs_wall_functions_2scales_log(cs_real_t l_visc, cs_real_t t_visc, cs_real_t vel, cs_real_t y, cs_real_t kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp)
Log law: piecewise linear and log, with two velocity scales based on the friction and the turbulent k...
Definition: cs_wall_functions.h:473
static void cs_wall_functions_disabled(cs_real_t l_visc, cs_real_t t_visc, cs_real_t vel, cs_real_t y, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *dplus, cs_real_t *ypup, cs_real_t *cofimp)
No wall function.
Definition: cs_wall_functions.h:952
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140
double cs_turb_xkappa
Definition: cs_turbulence_model.c:432
cs_wall_f_s_type_t iwalfs
Definition: cs_wall_functions.h:86
double precision, dimension(4, npot), save ka
Definition: ppcpfu.f90:159
Definition: cs_field_pointer.h:71
double ypluli
Definition: cs_wall_functions.h:88
static cs_real_t _dupdyp(cs_real_t yp, cs_real_t ka, cs_real_t B, cs_real_t cuv, cs_real_t y0, cs_real_t n)
Definition: cs_wall_functions.h:312
cs_wall_f_type_t
Definition: cs_wall_functions.h:54
Definition: cs_wall_functions.h:72
void cs_wall_functions_velocity(cs_wall_f_type_t iwallf, cs_lnum_t ifac, cs_real_t l_visc, cs_real_t t_visc, cs_real_t vel, cs_real_t y, cs_real_t rough_d, cs_real_t rnnb, cs_real_t kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp, cs_real_t *dplus)
Compute the friction velocity and / .
Definition: cs_wall_functions.c:330
static void cs_wall_functions_1scale_log(cs_lnum_t ifac, cs_real_t l_visc, cs_real_t vel, cs_real_t y, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp)
Log law: piecewise linear and log, with one velocity scale based on the friction. ...
Definition: cs_wall_functions.h:196
const cs_wall_functions_t * cs_glob_wall_functions
void wallfunctions(const int *const iwallf, const cs_lnum_t *const ifac, const cs_real_t *const viscosity, const cs_real_t *const t_visc, const cs_real_t *const vel, const cs_real_t *const y, const cs_real_t *const rough_d, const cs_real_t *const rnnb, const cs_real_t *const kinetic_en, int *iuntur, cs_lnum_t *nsubla, cs_lnum_t *nlogla, cs_real_t *ustar, cs_real_t *uk, cs_real_t *yplus, cs_real_t *ypup, cs_real_t *cofimp, cs_real_t *dplus)
Definition: cs_wall_functions.c:212
Definition: cs_field_pointer.h:236
void cs_immersed_boundary_wall_functions(int f_id, cs_real_t *st_exp, cs_real_t *st_imp)
Compute boundary contributions for all immersed boundaries.
Definition: cs_wall_functions.c:599
Definition: cs_wall_functions.h:62