9.1
general documentation
cs_turbulence_bc.h
Go to the documentation of this file.
1#ifndef __CS_TURBULENCE_BC_H__
2#define __CS_TURBULENCE_BC_H__
3
4/*============================================================================
5 * Base turbulence boundary conditions.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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 "base/cs_defs.h"
35
36/*----------------------------------------------------------------------------*/
37
39
40/*=============================================================================
41 * Macro definitions
42 *============================================================================*/
43
44/*============================================================================
45 * Type definitions
46 *============================================================================*/
47
48/*============================================================================
49 * Global variables
50 *============================================================================*/
51
52/*=============================================================================
53 * Public function prototypes
54 *============================================================================*/
55
56/*----------------------------------------------------------------------------*/
57/*
58 * Initialize turbulence model boundary condition pointers.
59 */
60/*----------------------------------------------------------------------------*/
61
62void
64
65/*----------------------------------------------------------------------------*/
66/*
67 * \brief Free memory allocations for turbulence boundary condition pointers.
68 */
69/*----------------------------------------------------------------------------*/
70
71void
73
74/*----------------------------------------------------------------------------*/
75/*
76 * \brief Calculation of \f$ u^\star \f$, \f$ k \f$ and \f$\varepsilon \f$
77 * from a diameter \f$ D_H \f$ and the reference velocity \f$ U_{ref} \f$
78 * for a circular duct flow with smooth wall
79 * (use for inlet boundary conditions).
80 *
81 * Both \f$ u^\star \f$ and\f$ (k,\varepsilon )\f$ are returned, so that
82 * the user may compute other values of \f$ k \f$ and \f$ \varepsilon \f$
83 * with \f$ u^\star \f$.
84 *
85 * We use the laws from Idel'Cik, i.e.
86 * the head loss coefficient \f$ \lambda \f$ is defined by:
87 * \f[ |\dfrac{\Delta P}{\Delta x}| =
88 * \dfrac{\lambda}{D_H} \frac{1}{2} \rho U_{ref}^2 \f]
89 *
90 * then the relation reads \f$u^\star = U_{ref} \sqrt{\dfrac{\lambda}{8}}\f$.
91 * \f$\lambda \f$ depends on the hydraulic Reynolds number
92 * \f$ Re = \dfrac{U_{ref} D_H}{ \nu} \f$ and is given by:
93 * - for \f$ Re < 2000 \f$
94 * \f[ \lambda = \dfrac{64}{Re} \f]
95 *
96 * - for \f$ Re > 4000 \f$
97 * \f[ \lambda = \dfrac{1}{( 1.8 \log_{10}(Re)-1.64 )^2} \f]
98 *
99 * - for \f$ 2000 < Re < 4000 \f$, we complete by a straight line
100 * \f[ \lambda = 0.021377 + 5.3115. 10^{-6} Re \f]
101 *
102 * From \f$ u^\star \f$, we can estimate \f$ k \f$ and \f$ \varepsilon\f$
103 * from the well known formulae of developped turbulence
104 *
105 * \f[ k = \dfrac{u^{\star 2}}{\sqrt{C_\mu}} \f]
106 * \f[ \varepsilon = \dfrac{ u^{\star 3}}{(\kappa D_H /10)} \f]
107 *
108 * \param[in] uref2 square of the reference flow velocity
109 * \param[in] dh hydraulic diameter \f$ D_H \f$
110 * \param[in] rho mass density \f$ \rho \f$
111 * \param[in] mu dynamic viscosity \f$ \nu \f$
112 * \param[out] ustar2 square of friction speed
113 * \param[out] k calculated turbulent intensity \f$ k \f$
114 * \param[out] eps calculated turbulent dissipation
115 * \f$ \varepsilon \f$
116 */
117/*----------------------------------------------------------------------------*/
118
119void
121 double dh,
122 double rho,
123 double mu,
124 double *ustar2,
125 double *k,
126 double *eps);
127
128/*----------------------------------------------------------------------------*/
129/*
130 * \brief Calculation of \f$ k \f$ and \f$\varepsilon\f$
131 * from a diameter \f$ D_H \f$, a turbulent intensity \f$ I \f$
132 * and the reference velocity \f$ U_{ref} \f$
133 * for a circular duct flow with smooth wall
134 * (for inlet boundary conditions).
135 *
136 * \f[ k = 1.5 I {U_{ref}}^2 \f]
137 * \f[ \varepsilon = 10 \dfrac{{C_\mu}^{0.75} k^{1.5}}{ \kappa D_H} \f]
138 *
139 * \param[in] uref2 square of the reference flow velocity
140 * \param[in] t_intensity turbulent intensity \f$ I \f$
141 * \param[in] dh hydraulic diameter \f$ D_H \f$
142 * \param[out] k calculated turbulent intensity \f$ k \f$
143 * \param[out] eps calculated turbulent dissipation
144 * \f$ \varepsilon \f$
145 */
146/*----------------------------------------------------------------------------*/
147
148void
150 double t_intensity,
151 double dh,
152 double *k,
153 double *eps);
154
155/*----------------------------------------------------------------------------*/
156/*
157 * \brief Set inlet boundary condition values for turbulence variables based
158 * on a diameter \f$ D_H \f$ and the reference velocity \f$ U_{ref} \f$
159 * for a circular duct flow with smooth wall
160 * (use for inlet boundary conditions).
161 *
162 * We use the laws from Idel'Cik, i.e.
163 * the head loss coefficient \f$ \lambda \f$ is defined by:
164 * \f[ |\dfrac{\Delta P}{\Delta x}| =
165 * \dfrac{\lambda}{D_H} \frac{1}{2} \rho U_{ref}^2 \f]
166 *
167 * then the relation reads \f$u^\star = U_{ref} \sqrt{\dfrac{\lambda}{8}}\f$.
168 * \f$\lambda \f$ depends on the hydraulic Reynolds number
169 * \f$ Re = \dfrac{U_{ref} D_H}{ \nu} \f$ and is given by:
170 * - for \f$ Re < 2000 \f$
171 * \f[ \lambda = \dfrac{64}{Re} \f]
172 *
173 * - for \f$ Re > 4000 \f$
174 * \f[ \lambda = \dfrac{1}{( 1.8 \log_{10}(Re)-1.64 )^2} \f]
175 *
176 * - for \f$ 2000 < Re < 4000 \f$, we complete by a straight line
177 * \f[ \lambda = 0.021377 + 5.3115. 10^{-6} Re \f]
178 *
179 * From \f$ u^\star \f$, we can estimate \f$ k \f$ and \f$ \varepsilon\f$
180 * from the well known formulae of developped turbulence
181 *
182 * \param[in] face_id boundary face id
183 * \param[in] uref2 square of the reference flow velocity
184 * \param[in] dh hydraulic diameter \f$ D_H \f$
185 * \param[in] rho mass density \f$ \rho \f$
186 * \param[in] mu dynamic viscosity \f$ \nu \f$
187 */
188/*----------------------------------------------------------------------------*/
189
190void
192 double uref2,
193 double dh,
194 double rho,
195 double mu);
196
197/*----------------------------------------------------------------------------*/
198/*
199 * \brief Set inlet boundary condition values for turbulence variables based
200 * on a diameter \f$ D_H \f$, a turbulent intensity \f$ I \f$
201 * and the reference velocity \f$ U_{ref} \f$
202 * for a circular duct flow with smooth wall.
203 *
204 * \param[in] face_id boundary face id
205 * \param[in] uref2 square of the reference flow velocity
206 * \param[in] t_intensity turbulent intensity \f$ I \f$
207 * \param[in] dh hydraulic diameter \f$ D_H \f$
208 */
209/*----------------------------------------------------------------------------*/
210
211void
213 double uref2,
214 double t_intensity,
215 double dh);
216
217/*----------------------------------------------------------------------------*/
218/*
219 * \brief Set inlet boundary condition values for turbulence variables based
220 * on given k and epsilon values.
221 *
222 * \param[in] face_id boundary face id
223 * \param[in] k turbulent kinetic energy
224 * \param[in] eps turbulent dissipation
225 */
226/*----------------------------------------------------------------------------*/
227
228void
230 double k,
231 double eps);
232
233/*----------------------------------------------------------------------------*/
234/*
235 * \brief Set inlet boundary condition values for turbulence variables based
236 * on given k and epsilon or Rij values.
237 *
238 * \param[in] face_id boundary face id
239 * \param[in] k turbulent kinetic energy
240 * \param[in] eps turbulent dissipation
241 */
242/*----------------------------------------------------------------------------*/
243
244void
246 double k,
247 double rij[],
248 double eps);
249
250/*----------------------------------------------------------------------------*/
251/*
252 * \brief Set inlet boundary condition values for turbulence variables based
253 * on a diameter \f$ D_H \f$ and the reference velocity \f$ U_{ref} \f$
254 * for a circular duct flow with smooth wall, only if not already set.
255 *
256 * Apart from assigning values where not already initialized, this function
257 * is similar to \ref cs_turbulence_bc_inlet_hyd_diam.
258 *
259 * \param[in] face_id boundary face id
260 * \param[in] vel_dir velocity direction (not normalized, or NULL)
261 * \param[in] shear_dir shear direction (or NULL), it also contains the
262 * level of anisotropy (Rnt = a_nt k)
263 * \param[in] uref2 square of the reference flow velocity
264 * \param[in] dh hydraulic diameter \f$ D_H \f$
265 * \param[in] rho mass density \f$ \rho \f$
266 * \param[in] mu dynamic viscosity \f$ \nu \f$
267 */
268/*----------------------------------------------------------------------------*/
269
270void
272 double vel_dir[],
273 double shear_dir[],
274 double uref2,
275 double dh,
276 double rho,
277 double mu);
278
279/*----------------------------------------------------------------------------*/
280/*
281 * \brief Set inlet boundary condition values for turbulence variables based
282 * on a diameter \f$ D_H \f$, a turbulent intensity \f$ I \f$
283 * and the reference velocity \f$ U_{ref} \f$
284 * for a circular duct flow with smooth wall, only if not already set.
285 *
286 * Apart from assigning values where not already initialized, this function
287 * is similar to \ref cs_turbulence_bc_inlet_turb_intensity.
288 *
289 * \param[in] face_id boundary face id
290 * \param[in] uref2 square of the reference flow velocity
291 * \param[in] t_intensity turbulent intensity \f$ I \f$
292 * \param[in] dh hydraulic diameter \f$ D_H \f$
293 */
294/*----------------------------------------------------------------------------*/
295
296void
298 double uref2,
299 double t_intensity,
300 double dh);
301
302/*----------------------------------------------------------------------------*/
303/*
304 * \brief Set inlet boundary condition values for turbulence variables based
305 * on given k and epsilon values only if not already initialized.
306 *
307 * \param[in] face_id boundary face id
308 * \param[in] k turbulent kinetic energy
309 * \param[in] eps turbulent dissipation
310 * \param[in] vel_dir velocity direction
311 * \param[in] shear_dir shear direction
312 */
313/*----------------------------------------------------------------------------*/
314
315void
317 double k,
318 double eps,
319 double vel_dir[],
320 double shear_dir[]);
321
322/*----------------------------------------------------------------------------*/
323/*
324 * \brief Assign homogeneous Neumann turbulent boundary conditions to
325 * a given face.
326 *
327 * This is useful for outgoing flow.
328 */
329/*----------------------------------------------------------------------------*/
330
331void
333
334/*----------------------------------------------------------------------------*/
335
337
338/*----------------------------------------------------------------------------*/
339/*
340 * \brief Compute matrix \f$\tens{\alpha}\f$ used in the computation of the
341 * Reynolds stress tensor boundary conditions.
342 *
343 * We note \f$\tens{R}_g\f$ the Reynolds Stress tensor in the global reference
344 * frame (mesh reference frame) and \f$\tens{R}_l\f$ the Reynolds stress
345 * tensor in the local reference frame (reference frame associated to the
346 * boundary face).
347 *
348 * \f$\tens{P}_{lg}\f$ is the change of basis orthogonal matrix from local
349 * to global reference frame.
350
351 * \f$\tens{\alpha}\f$ is a 6 by 6 matrix such that:
352 * \f[
353 * \vect{R}_{g,\fib} = \tens{\alpha} \vect{R}_{g,\centip} + \vect{R}_{g}^*
354 * \f]
355 * where symetric tensors \f$\tens{R}_g\f$ have been unfolded as follows:
356 * \f[
357 * \vect{R}_g = \transpose{\left(R_{g,11},R_{g,22},R_{g,33},
358 * R_{g,12},R_{g,13},R_{g,23}\right)}
359 * \f].
360 *
361 * \f$\tens{\alpha}\f$ is defined so that \f$ \tens{R}_{g,\fib} \f$ is computed
362 * as a function of \f$\tens{R}_{g,\centip}\f$ as follows:
363 * \f[
364 * \tens{R}_{g,\fib}=\tens{P}_{lg}\tens{R}_{l,\fib}\transpose{\tens{P}_{lg}}
365 * \f]
366 *
367 * with
368 * \f[
369 * \tens{R}_{l,\fib} =
370 * \begin{bmatrix}
371 * R_{l,11,\centip} & u^* u_k & c R_{l,13,\centip}\\
372 * u^* u_k & R_{l,22,\centip} & 0 \\
373 * c R_{l,13,\centip} & 0 & R_{l,33,\centip}
374 * \end{bmatrix} +
375 * \underbrace{\begin{bmatrix}
376 * 0 & u^* u_k & 0 \\
377 * u^* u_k & 0 & 0 \\
378 * 0 & 0 & 0
379 * \end{bmatrix}}_{\tens{R}_l^*}
380 * \f]
381 *
382 * and
383 * \f$\tens{R}_{l,\centip}=\transpose{\tens{P}_{lg}}\tens{R}_{g,\centip}
384 * \tens{P}_{lg}\f$.
385 *
386 * Constant c is chosen depending on the type of the boundary face:
387 * \f$c = 0\f$ at a wall face, \f$c = 1\f$ at a symmetry face.
388 *
389 * \param[in] is_sym Constant c in description above
390 * (1 at a symmetry face, 0 at a wall face)
391 * \param[in] p_lg change of basis matrix (local to global)
392 * \param[out] alpha transformation matrix
393 */
394/*----------------------------------------------------------------------------*/
395
396#ifdef __cplusplus
397
398CS_F_HOST_DEVICE inline void
400 cs_real_t p_lg[3][3],
401 cs_real_t alpha[6][6])
402{
403 cs_real_t p_lg2[3][3];
404 for (int ii = 0; ii < 3; ii++) {
405 for (int jj = 0; jj < 3; jj++)
406 p_lg2[ii][jj] = cs::pow2(p_lg[ii][jj]);
407 }
408
409 /* alpha(i,j) for i in [1,3] and j in [1,3]: 9 terms */
410 for (int ii = 0; ii < 3; ii++) {
411 for (int jj = 0; jj < 3; jj++) {
412 alpha[jj][ii] = p_lg2[0][ii] * p_lg2[0][jj]
413 + p_lg2[1][ii] * p_lg2[1][jj]
414 + p_lg2[2][ii] * p_lg2[2][jj]
415 + 2. * is_sym * p_lg[0][ii] * p_lg[2][ii]
416 * p_lg[0][jj] * p_lg[2][jj];
417 }
418 }
419
420 /* alpha(i,j) for i in [1,3] and j in [4,6]: 9 terms */
421
422 /* Correcponding line to j */
423 const int _jj_to_kk[3] = {0, 1, 0};
424 /* Corresponding column to j*/
425 const int _jj_to_pp[3] = {1, 2, 2};
426
427 for (int ii = 0; ii < 3; ii++) {
428 for (int jj = 0; jj < 3; jj++) {
429
430 int kk = _jj_to_kk[jj];
431 int pp = _jj_to_pp[jj];
432
433 alpha[jj + 3][ii] =
434 2. * ( p_lg2[0][ii] * p_lg[0][kk] * p_lg[0][pp]
435 + p_lg2[1][ii] * p_lg[1][kk] * p_lg[1][pp]
436 + p_lg2[2][ii] * p_lg[2][kk] * p_lg[2][pp]
437 + is_sym * p_lg[2][ii] * p_lg[0][ii]
438 * ( p_lg[0][kk]*p_lg[2][pp]
439 + p_lg[2][kk]*p_lg[0][pp]));
440 }
441 }
442
443 /* alpha(i,j) for i in [4,6] and j in [1,3]: 9 terms */
444
445 for (int ii = 0; ii < 3; ii++) {
446 for (int jj = 0; jj < 3; jj++) {
447
448 int kk = _jj_to_kk[ii];
449 int pp = _jj_to_pp[ii];
450
451 /* Note: could be simplified because it is 0.5*alpha[jj+3][ii] */
452 alpha[jj][ii + 3] =
453 p_lg[0][kk] * p_lg[0][pp] * p_lg2[0][jj]
454 + p_lg[1][kk] * p_lg[1][pp] * p_lg2[1][jj]
455 + p_lg[2][kk] * p_lg[2][pp] * p_lg2[2][jj]
456 + is_sym * p_lg[2][jj] * p_lg[0][jj]
457 * ( p_lg[0][kk]*p_lg[2][pp]
458 + p_lg[2][kk]*p_lg[0][pp]);
459 }
460 }
461
462 /* alpha(i,j) for i in [4,6] and j in [4,6]: 9 terms */
463 for (int ii = 0; ii < 3; ii++) {
464 for (int jj = 0; jj < 3; jj++) {
465
466 int kk = _jj_to_kk[ii];
467 int pp = _jj_to_pp[ii];
468
469 int jj1 = _jj_to_kk[jj];
470 int jj2 = _jj_to_pp[jj];
471
472 alpha[jj + 3][ii + 3] =
473 2. * ( p_lg[0][kk] * p_lg[0][pp] * p_lg[0][jj1] * p_lg[0][jj2]
474 + p_lg[1][kk] * p_lg[1][pp] * p_lg[1][jj1] * p_lg[1][jj2]
475 + p_lg[2][kk] * p_lg[2][pp] * p_lg[2][jj1] * p_lg[2][jj2])
476 + is_sym * ( p_lg[0][kk]*p_lg[2][pp]
477 + p_lg[2][kk]*p_lg[0][pp])
478 * ( p_lg[2][jj1]*p_lg[0][jj2]
479 + p_lg[0][jj1]*p_lg[2][jj2]);
480 }
481 }
482}
483
484#endif
485
486/*----------------------------------------------------------------------------*/
487
488#endif /* __CS_TURBULENCE_BC_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
@ k
Definition: cs_field_pointer.h:72
@ mu
Definition: cs_field_pointer.h:106
@ eps
Definition: cs_field_pointer.h:73
@ rho
Definition: cs_field_pointer.h:100
@ rij
Definition: cs_field_pointer.h:75
void cs_turbulence_bc_ke_turb_intensity(double uref2, double t_intensity, double dh, double *k, double *eps)
Calculation of and from a diameter , a turbulent intensity and the reference velocity for a circu...
Definition: cs_turbulence_bc.cpp:729
void cs_turbulence_bc_inlet_hyd_diam(cs_lnum_t face_id, double uref2, double dh, double rho, double mu)
Set inlet boundary condition values for turbulence variables based on a diameter and the reference v...
Definition: cs_turbulence_bc.cpp:773
void cs_turbulence_bc_set_uninit_inlet_turb_intensity(cs_lnum_t face_id, double uref2, double t_intensity, double dh)
Set inlet boundary condition values for turbulence variables based on a diameter ,...
Definition: cs_turbulence_bc.cpp:986
void cs_turbulence_bc_inlet_k_eps(cs_lnum_t face_id, double k, double eps)
Set inlet boundary condition values for turbulence variables based on given k and epsilon values.
Definition: cs_turbulence_bc.cpp:825
void cs_turbulence_bc_free_pointers(void)
Free memory allocations for turbulence boundary condition pointers.
Definition: cs_turbulence_bc.cpp:643
void cs_turbulence_bc_set_uninit_inlet(cs_lnum_t face_num, double k, double rij[], double eps)
void cs_turbulence_bc_set_uninit_inlet_k_eps(cs_lnum_t face_id, double k, double eps, double vel_dir[], double shear_dir[])
Set inlet boundary condition values for turbulence variables based on given k and epsilon values only...
Definition: cs_turbulence_bc.cpp:1013
void cs_turbulence_bc_ke_hyd_diam(double uref2, double dh, double rho, double mu, double *ustar2, double *k, double *eps)
Calculation of , and from a diameter and the reference velocity for a circular duct flow with smo...
Definition: cs_turbulence_bc.cpp:697
void cs_turbulence_bc_init_pointers(void)
Initialize turbulence model boundary condition pointers.
Definition: cs_turbulence_bc.cpp:552
void cs_turbulence_bc_inlet_turb_intensity(cs_lnum_t face_id, double uref2, double t_intensity, double dh)
Set inlet boundary condition values for turbulence variables based on a diameter ,...
Definition: cs_turbulence_bc.cpp:801
CS_F_HOST_DEVICE void cs_turbulence_bc_rij_transform(int is_sym, cs_real_t p_lg[3][3], cs_real_t alpha[6][6])
Definition: cs_turbulence_bc.h:399
void cs_turbulence_bc_set_hmg_neumann(cs_lnum_t face_id)
Assign homogeneous Neumann turbulent boundary conditions to a given face.
Definition: cs_turbulence_bc.cpp:842
void cs_turbulence_bc_set_uninit_inlet_hyd_diam(cs_lnum_t face_id, double vel_dir[], double shear_dir[], double uref2, double dh, double rho, double mu)
Set inlet boundary condition values for turbulence variables based on a diameter and the reference v...
Definition: cs_turbulence_bc.cpp:953
CS_F_HOST_DEVICE float pow2(float x)
Compute the square of a real value.
Definition: cs_math.h:629