1 #ifndef __CS_CDO_TURBULENCE_H__
2 #define __CS_CDO_TURBULENCE_H__
3 
4 /*============================================================================
5  * Functions to handle the resolution of the turbulence modelling
6  *============================================================================*/
7 
8 /*
9   This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11   Copyright (C) 1998-2021 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  *  Local headers
30  *----------------------------------------------------------------------------*/
31 
32 #include "cs_cdo_connect.h"
33 #include "cs_cdo_quantities.h"
34 #include "cs_equation.h"
35 #include "cs_field.h"
36 #include "cs_mesh.h"
37 #include "cs_property.h"
38 #include "cs_time_step.h"
39 #include "cs_turbulence_model.h"
40 
41 /*----------------------------------------------------------------------------*/
42 
43 BEGIN_C_DECLS
44 
45 /*============================================================================
46  * Macro definitions
47  *============================================================================*/
48 
49 #define CS_NAVSTO_TOTAL_VISCOSITY    "total_viscosity"
50 #define CS_NAVSTO_LAM_VISCOSITY      "laminar_viscosity"
51 #define CS_NAVSTO_TURB_VISCOSITY     "turbulent_viscosity"
52 
53 /*============================================================================
54  * Type definitions
55  *============================================================================*/
56 
57 /*! \struct cs_turbulence_param_t
58  *  \brief Structure storing the parameters related to the resolution of the
59  *         turbulence modelling. Several members are structures defined in
60  *         cs_turbulence_model.h as a global variable. The purpose of this
61  *         structure is to store all parameters in one place.
62  */
63 
64 typedef struct {
65 
66   /*! \var model
67    * Main set of parameters to handle turbulence modelling. This
68    * structure is shared with the legacy part.
69    */
70 
71   cs_turb_model_t            *model;
72 
73   /*! \var rans_param
74    * Main set of parameters to handle RANS modelling. This
75    * structure is shared with the legacy part.
76    * RANS means Reynolds Average Navier-Stokes
77    */
78 
79   cs_turb_rans_model_t       *rans_param;
80 
81   /*! \var les_param
82    * Main set of parameters to handle LES modelling. This
83    * structure is shared with the legacy part.
84    * LES means Large Eddy Simulation
85    */
86 
87   cs_turb_les_model_t        *les_param;
88 
89   /*! \var reference_values
90    *  Set of reference values associated to the turbulence modelling
91    */
92 
93   cs_turb_ref_values_t       *reference_values;
94 
95 } cs_turbulence_param_t;
96 
97 /*! \struct cs_turbulence_t
98  *  \brief Structure storing the parameters related to the resolution of the
99  *         turbulence modelling. Several members are structures defined in
100  *         cs_turbulence_model.h
101  */
102 
103 typedef struct _cs_turbulence_t cs_turbulence_t;
104 
105 /*============================================================================
106  * Function pointer definition
107  *============================================================================*/
108 
109 /*----------------------------------------------------------------------------*/
110 /*!
111  * \brief  Allocate and initialize the context structure related to a given
112  *         turbulence modelling
113  *
114  * \param[in]      tbm       pointer to a \ref cs_turb_model_t structure
115  *
116  * \return a pointer to a new allocated turbulence context structure
117  */
118 /*----------------------------------------------------------------------------*/
119 
120 typedef void *
121 (cs_turb_init_context_t)(const cs_turb_model_t   *tbm);
122 
123 /*----------------------------------------------------------------------------*/
124 /*!
125  * \brief  Free the context structure related to a given turbulence modelling
126  *
127  * \param[in, out]  tbc       pointer to a structure cast on-the-fly to free
128  *
129  * \return a NULL pointer
130  */
131 /*----------------------------------------------------------------------------*/
132 
133 typedef void *
134 (cs_turb_free_context_t)(void     *turb_context);
135 
136 /*----------------------------------------------------------------------------*/
137 /*!
138  * \brief  Compute for the current time step the new state for the turbulence
139  *         model. This means that all related equations are built and then
140  *         solved.
141  *
142  * \param[in]      mesh       pointer to a \ref cs_mesh_t structure
143  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
144  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
145  * \param[in]      time_step  structure managing the time stepping
146  * \param[in, out] tbs        pointer to turbulence structure
147  */
148 /*----------------------------------------------------------------------------*/
149 
150 typedef void
151 (cs_turb_compute_t)(const cs_mesh_t            *mesh,
152                     const cs_cdo_connect_t     *connect,
153                     const cs_cdo_quantities_t  *quant,
154                     const cs_time_step_t       *time_step,
155                     cs_turbulence_t            *tbs);
156 
157 /*----------------------------------------------------------------------------*/
158 /*!
159  * \brief  Update properties, arrays related to the turbulent variables
160  *
161  * \param[in]      mesh       pointer to a \ref cs_mesh_t structure
162  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
163  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
164  * \param[in]      time_step  structure managing the time stepping
165  * \param[in]      tbs        pointer to a \ref cs_turbulence_t structure
166  */
167 /*----------------------------------------------------------------------------*/
168 
169 typedef void
170 (cs_turb_update_t)(const cs_mesh_t                *mesh,
171                    const cs_cdo_connect_t         *connect,
172                    const cs_cdo_quantities_t      *quant,
173                    const cs_time_step_t           *time_step,
174                    const cs_turbulence_t          *tbs);
175 
176 /*! \struct cs_turbulence_t
177  *  \brief Structure storing the parameters related to the resolution of the
178  *         turbulence modelling. Several members are structures defined in
179  *         cs_turbulence_model.h
180  */
181 
182 struct _cs_turbulence_t {
183 
184   /*!
185    * @name Turbulence modelling
186    * Set of parameters to handle turbulence modelling.
187    * @{
188    *
189    * \var param
190    * Main set of parameters to handle turbulence modelling. The members
191    * of this structure are shared with the legacy part.
192    */
193 
194   cs_turbulence_param_t     *param;
195 
196   /*! \var mom_eq
197    * Pointer to the momentum equation structure.
198    */
199   cs_equation_t             *mom_eq;
200 
201   /*!
202    * @}
203    * @name Main properties related to the turbulence modelling
204    */
205 
206   /*! \var rho
207    *  mass density
208    */
209 
210   cs_property_t              *rho;
211 
212   /*! \var mu_t
213    *  total viscosity (dynamic turbulent + laminar)
214    */
215 
216   cs_property_t              *mu_tot;
217 
218   /*! \var mu_l
219    *  laminar viscosity
220    */
221 
222   cs_property_t              *mu_l;
223 
224   /*! \var mu_t
225    *  dynamic turbulent viscosity
226    */
227 
228   cs_property_t              *mu_t;
229 
230   /*! \var mu_tot_array
231    *  Array storing the value of the total viscosity in each cell
232    */
233   cs_real_t                  *mu_tot_array;
234 
235   /*!
236    * @}
237    * @name Main related fields
238    * @{
239    */
240 
241   /* \var mu_t_field
242    * Field related to the turbulent viscosity
243    */
244 
245   cs_field_t                 *mu_t_field;
246 
247   /*! \var rij
248    *  Reynolds stress tensor
249    */
250 
251   cs_field_t                 *rij;
252 
253   /*!
254    * @}
255    * @name Main structure and function pointers
256    *
257    * \brief The context structure is a structure cast on-the-fly and function
258    * pointers are a limited set of functions associated to the main operations
259    * for this structure: initialization, destruction, computation and update.
260    *
261    * @{
262    */
263 
264   /*! \var context
265    * Context related to the turbulence modelling. This structure is cast
266    * on-the-fly according to the modelling choices
267    */
268 
269   void                         *context;
270 
271   /*! \var init_context
272    * Function pointer to initialize the context structure
273    */
274 
275   cs_turb_init_context_t       *init_context;
276 
277   /*! \var free_context
278    * Function pointer to de-allocate memory owned by the context structure
279    */
280 
281   cs_turb_free_context_t       *free_context;
282 
283   /*! \var compute
284    * Function pointer to compute all variables related to a turbulence model
285    */
286 
287   cs_turb_compute_t            *compute;
288 
289   /*! \var compute_steady
290    * Function pointer to compute in steady mode all variables related to a
291    * turbulence model
292    */
293 
294   cs_turb_compute_t            *compute_steady;
295 
296   /*! \var update
297    * Function pointer to perform the update step (properties or arrays
298    * associated to the variables of a turbulence model are updated)
299    */
300 
301   cs_turb_update_t             *update;
302 
303 };
304 
305 /*============================================================================
306  * Public function prototypes
307  *============================================================================*/
308 
309 /*----------------------------------------------------------------------------*/
310 /*!
311  * \brief  Allocate the structure storing the set of parameters for the
312  *         turbulence modelling
313  *
314  * \return a pointer to a new allocated cs_turbulence_param_t structure
315  */
316 /*----------------------------------------------------------------------------*/
317 
318 cs_turbulence_param_t *
319 cs_turbulence_param_create(void);
320 
321 /*----------------------------------------------------------------------------*/
322 /*!
323  * \brief  Allocate the structure managing the turbulence modelling
324  *
325  * \param[in] tbp       pointer to a \ref cs_turbulence_param_t structure
326  *
327  * \return a pointer to a new allocated cs_turbulence_t structure
328  */
329 /*----------------------------------------------------------------------------*/
330 
331 cs_turbulence_t *
332 cs_turbulence_create(cs_turbulence_param_t    *tbp);
333 
334 /*----------------------------------------------------------------------------*/
335 /*!
336  * \brief  Free the structure managing the turbulence modelling
337  *
338  * \param[in, out]  p_turb_struct   pointer to the structure to free
339  */
340 /*----------------------------------------------------------------------------*/
341 
342 void
343 cs_turbulence_free(cs_turbulence_t   **p_turb_struct);
344 
345 /*----------------------------------------------------------------------------*/
346 /*!
347  * \brief  Initialize the structure managing the turbulence modelling
348  *
349  * \param[in, out]  tbs     pointer to the structure to initialize
350  * \param[in]       mom_eq  pointer to the structure mom_eq
351  */
352 /*----------------------------------------------------------------------------*/
353 
354 void
355 cs_turbulence_init_setup(cs_turbulence_t     *tbs,
356                          cs_equation_t       *mom_eq);
357 
358 /*----------------------------------------------------------------------------*/
359 /*!
360  * \brief  Finalize the setup of the turbulence modelling and especially the
361  *         equations/properties and other related quantities
362  *
363  * \param[in]      mesh       pointer to a \ref cs_mesh_t structure
364  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
365  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
366  * \param[in]      time_step  pointer to a cs_time_step_t structure
367  * \param[in, out] tbs        pointer to the turbulence main structure
368  */
369 /*----------------------------------------------------------------------------*/
370 
371 void
372 cs_turbulence_finalize_setup(const cs_mesh_t            *mesh,
373                              const cs_cdo_connect_t     *connect,
374                              const cs_cdo_quantities_t  *quant,
375                              const cs_time_step_t       *time_step,
376                              cs_turbulence_t            *tbs);
377 
378 /*----------------------------------------------------------------------------*/
379 /*!
380  * \brief  Initialize quantities related to a turbulence model.
381  *
382  * \param[in]      mesh       pointer to a \ref cs_mesh_t structure
383  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
384  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
385  * \param[in]      time_step  pointer to a cs_time_step_t structure
386  * \param[in, out] tbs        pointer to the turbulence main structure
387  */
388 /*----------------------------------------------------------------------------*/
389 
390 void
391 cs_turbulence_initialize(const cs_mesh_t            *mesh,
392                          const cs_cdo_connect_t     *connect,
393                          const cs_cdo_quantities_t  *quant,
394                          const cs_time_step_t       *time_step,
395                          cs_turbulence_t            *tbs);
396 
397 /*----------------------------------------------------------------------------*/
398 /*!
399  * \brief  Allocate and initialize the context structure related to the
400  *         k-epsilon turbulence model
401  *
402  * \param[in]  tbm         structure which defines the turbulence model
403  *
404  * \return a pointer to a new allocated context structure
405  */
406 /*----------------------------------------------------------------------------*/
407 
408 void *
409 cs_turb_init_k_eps_context(const cs_turb_model_t      *tbm);
410 
411 /*----------------------------------------------------------------------------*/
412 /*!
413  * \brief  Free the context structure related to the k-epsilon turbulence model
414  *
415  * \param[in, out]  tbc   pointer to a structure context cast on-the-fly
416  *
417  * \return a NULL pointer
418  */
419 /*----------------------------------------------------------------------------*/
420 
421 void *
422 cs_turb_free_k_eps_context(void     *tbc);
423 
424 /*----------------------------------------------------------------------------*/
425 /*!
426  * \brief  Compute for the current time step the new state for the turbulence
427  *         model. This means that all related equations are built and then
428  *         solved.
429  *
430  * \param[in]      mesh       pointer to a \ref cs_mesh_t structure
431  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
432  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
433  * \param[in]      time_step  structure managing the time stepping
434  * \param[in, out] tbs        pointer to turbulence structure
435  */
436 /*----------------------------------------------------------------------------*/
437 
438 void
439 cs_turb_compute_k_eps(const cs_mesh_t            *mesh,
440                       const cs_cdo_connect_t     *connect,
441                       const cs_cdo_quantities_t  *quant,
442                       const cs_time_step_t       *time_step,
443                       cs_turbulence_t            *tbs);
444 
445 
446 /*----------------------------------------------------------------------------*/
447 /*!
448  * \brief  Update for the current time step the new state for the turbulence
449  *         model. This is used to update the turbulent viscosity.
450  *
451  * \param[in]      mesh       pointer to a \ref cs_mesh_t structure
452  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
453  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
454  * \param[in]      time_step  structure managing the time stepping
455  * \param[in]      tbs        pointer to a \ref cs_turbulence_t structure
456  */
457 /*----------------------------------------------------------------------------*/
458 
459 void
460 cs_turb_update_k_eps(const cs_mesh_t              *mesh,
461                      const cs_cdo_connect_t       *connect,
462                      const cs_cdo_quantities_t    *quant,
463                      const cs_time_step_t         *time_step,
464                      const cs_turbulence_t        *tbs);
465 
466 /*----------------------------------------------------------------------------*/
467 
468 END_C_DECLS
469 
470 #endif /* __CS_CDO_TURBULENCE_H__ */
471