1 /*============================================================================
2 * Turbulent inflow generation
3 *============================================================================*/
4
5 /*
6 This file is part of Code_Saturne, a general-purpose CFD tool.
7
8 Copyright (C) 1998-2021 EDF S.A.
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 details.
19
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22 Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24
25 /*----------------------------------------------------------------------------*/
26
27 #include "cs_defs.h"
28
29 /*----------------------------------------------------------------------------
30 * Standard C library headers
31 *----------------------------------------------------------------------------*/
32
33 #include <assert.h>
34 #include <math.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #if defined(HAVE_MPI)
39 #include <mpi.h>
40 #endif
41
42 /*----------------------------------------------------------------------------
43 * Local headers
44 *----------------------------------------------------------------------------*/
45
46 #include "bft_mem.h"
47 #include "bft_error.h"
48 #include "bft_printf.h"
49
50 #include "cs_base.h"
51 #include "cs_field.h"
52 #include "cs_field_default.h"
53 #include "cs_field_pointer.h"
54 #include "cs_math.h"
55 #include "cs_mesh.h"
56 #include "cs_parall.h"
57 #include "cs_equation_param.h"
58 #include "cs_turbulence_bc.h"
59 #include "cs_turbulence_model.h"
60
61 /*----------------------------------------------------------------------------
62 * Header for the current file
63 *----------------------------------------------------------------------------*/
64
65 #include "cs_turbulence_inflow.h"
66
67 /*----------------------------------------------------------------------------*/
68
69 BEGIN_C_DECLS
70
71 /*! \cond DOXYGEN_SHOULD_SKIP_THIS */
72
73 /*=============================================================================
74 * Local Macro Definitions
75 *============================================================================*/
76
77 /*=============================================================================
78 * Local Structure Definitions
79 *============================================================================*/
80
81 /*============================================================================
82 * Global variables
83 *============================================================================*/
84
85 /*============================================================================
86 * Private function definitions
87 *============================================================================*/
88
89 /*=============================================================================
90 * Public function definitions
91 *============================================================================*/
92
93 /*----------------------------------------------------------------------------*/
94 /*!
95 * \brief Define mass injection for turbulent quantities based
96 * on k and epsilon values.
97 *
98 * \param[in] zone_name name of zone to which injection should be added
99 * \param[in] k turbulent kinetic energy
100 * \param[in] eps turbulent dissipation
101 */
102 /*----------------------------------------------------------------------------*/
103
104 void
cs_turbulence_inflow_volume_mass_injection_k_eps(const char * zone_name,double k,double eps)105 cs_turbulence_inflow_volume_mass_injection_k_eps(const char *zone_name,
106 double k,
107 double eps)
108 {
109 cs_turb_model_type_t iturb = cs_glob_turb_model->iturb;
110 int itytur = cs_glob_turb_model->itytur;
111
112 if (itytur == 2) {
113
114 cs_equation_add_volume_mass_injection_by_value
115 (cs_field_get_equation_param(CS_F_(k)), zone_name, &k);
116
117 cs_equation_add_volume_mass_injection_by_value
118 (cs_field_get_equation_param(CS_F_(eps)), zone_name, &eps);
119
120 }
121 else if (itytur == 3) {
122 cs_real_t val[6] = {2./3.*k, 2./3.*k, 2./3.*k, 0, 0, 0};
123
124 cs_equation_add_volume_mass_injection_by_value
125 (cs_field_get_equation_param(CS_F_(rij)), zone_name, val);
126
127 }
128 else if (iturb == CS_TURB_V2F_PHI) {
129
130 double twothirds = 2./3.;
131
132 cs_equation_add_volume_mass_injection_by_value
133 (cs_field_get_equation_param(CS_F_(k)), zone_name, &k);
134
135 cs_equation_add_volume_mass_injection_by_value
136 (cs_field_get_equation_param(CS_F_(eps)), zone_name, &eps);
137
138 cs_equation_add_volume_mass_injection_by_value
139 (cs_field_get_equation_param(CS_F_(phi)), zone_name, &twothirds);
140
141 /* There is no mass source term in the equation for f_bar */
142
143 }
144 else if (iturb == CS_TURB_K_OMEGA) {
145
146 double omega_in = eps / cs_turb_cmu / k;
147
148 cs_equation_add_volume_mass_injection_by_value
149 (cs_field_get_equation_param(CS_F_(k)), zone_name, &k);
150
151 cs_equation_add_volume_mass_injection_by_value
152 (cs_field_get_equation_param(CS_F_(omg)), zone_name, &omega_in);
153
154 }
155 }
156
157 /*----------------------------------------------------------------------------*/
158 /*!
159 * \brief Define mass injection for turbulent quantities based
160 * on a hydraulic diameter and reference velocity.
161 *
162 * \param[in] zone_name name of zone to which injection should be added
163 * \param[in] uref2 square of the reference flow velocity
164 * \param[in] dh hydraulic diameter \f$ D_H \f$
165 * \param[in] rho mass density \f$ \rho \f$
166 * \param[in] mu dynamic viscosity \f$ \nu \f$
167 */
168 /*----------------------------------------------------------------------------*/
169
170 void
cs_turbulence_inflow_volume_mass_injection_ke_hyd_diam(const char * zone_name,double uref2,double dh,double rho,double mu)171 cs_turbulence_inflow_volume_mass_injection_ke_hyd_diam(const char *zone_name,
172 double uref2,
173 double dh,
174 double rho,
175 double mu)
176 {
177 cs_real_t ustar2 = 0, k = cs_math_epzero, eps = cs_math_epzero;
178
179 /* Turbulence values */
180
181 cs_turbulence_bc_ke_hyd_diam(uref2,
182 dh,
183 rho,
184 mu,
185 &ustar2,
186 &k,
187 &eps);
188
189 cs_turbulence_inflow_volume_mass_injection_k_eps(zone_name,
190 k,
191 eps);
192 }
193
194 /*----------------------------------------------------------------------------*/
195
196 END_C_DECLS
197