1 #ifndef __CS_NAVSTO_SYSTEM_H__
2 #define __CS_NAVSTO_SYSTEM_H__
3 
4 /*============================================================================
5  * Functions to handle cs_navsto_system_t structure
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_advection_field.h"
33 #include "cs_cdo_turbulence.h"
34 #include "cs_equation.h"
35 #include "cs_field.h"
36 #include "cs_param_types.h"
37 #include "cs_property.h"
38 #include "cs_maxwell.h"
39 #include "cs_mesh.h"
40 #include "cs_navsto_param.h"
41 #include "cs_time_plot.h"
42 #include "cs_time_step.h"
43 #include "cs_thermal_system.h"
44 #include "cs_xdef.h"
45 
46 /*----------------------------------------------------------------------------*/
47 
48 BEGIN_C_DECLS
49 
50 /*============================================================================
51  * Macro definitions
52  *============================================================================*/
53 
54 /*============================================================================
55  * Function pointer definitions
56  *============================================================================*/
57 
58 /*----------------------------------------------------------------------------*/
59 /*!
60  * \brief  Allocate and initialize the context structure related to a given
61  *         discretization scheme for the resolution of the Navier-Stokes system
62  *         with a specified coupling algorithm
63  *
64  * \param[in]      nsp        pointer to a \ref cs_navsto_param_t structure
65  * \param[in]      adv_field  pointer to \ref cs_adv_field_t structure
66  * \param[in]      mflux      current values of the mass flux
67  * \param[in]      mflux_pre  current values of the mass flux
68  * \param[in]      fb_type    type of boundary for each boundary face
69  * \param[in, out] nscc       Navier-Stokes coupling context: pointer to a
70  *                            structure cast on-the-fly
71  *
72  * \return a pointer to a new allocated scheme context structure
73  */
74 /*----------------------------------------------------------------------------*/
75 
76 typedef void *
77 (cs_navsto_init_scheme_context_t)(const cs_navsto_param_t    *nsp,
78                                   cs_adv_field_t             *adv_field,
79                                   cs_real_t                  *mflux,
80                                   cs_real_t                  *mflux_pre,
81                                   cs_boundary_type_t         *fb_type,
82                                   void                       *nscc);
83 
84 /*----------------------------------------------------------------------------*/
85 /*!
86  * \brief  Free the context structure related to a given discretization scheme
87  *         for the resolution of the Navier-Stokes system with a specified
88  *         coupling algorithm
89  *
90  * \param[in, out]  scheme_context   pointer to a structure cast on-the-fly
91  *
92  * \return a NULL pointer
93  */
94 /*----------------------------------------------------------------------------*/
95 
96 typedef void *
97 (cs_navsto_free_scheme_context_t)(void     *scheme_context);
98 
99 /*----------------------------------------------------------------------------*/
100 /*!
101  * \brief  According to the model, coupling algorithm and the space
102  *         discretization, initialize the field values which are not associated
103  *         to a \ref cs_equation_t structure (which manages the initialization)
104  *
105  * \param[in]       nsp      pointer to a \ref cs_navsto_param_t structure
106  * \param[in]       quant    pointer to a \ref cs_cdo_quantities_t structure
107  * \param[in]       ts       pointer to a \ref cs_time_step_t structure
108  * \param[in, out]  field    pointer to a \ref cs_field_t structure
109  */
110 /*----------------------------------------------------------------------------*/
111 
112 typedef void
113 (cs_navsto_init_values_t)(const cs_navsto_param_t     *nsp,
114                           const cs_cdo_quantities_t   *quant,
115                           const cs_time_step_t        *ts,
116                           cs_field_t                  *field);
117 
118 /*----------------------------------------------------------------------------*/
119 /*!
120  * \brief  Compute for the current time step the new state for the
121  *         Navier-Stokes system. This means that equations are built and then
122  *         solved.
123  *
124  * \param[in]      mesh            pointer to a \ref cs_mesh_t structure
125  * \param[in]      nsp             pointer to a \ref cs_navsto_param_t structure
126  * \param[in, out] scheme_context  pointer to a structure cast on-the-fly
127  */
128 /*----------------------------------------------------------------------------*/
129 
130 typedef void
131 (cs_navsto_compute_t)(const cs_mesh_t              *mesh,
132                       const cs_navsto_param_t      *nsp,
133                       void                         *scheme_context);
134 
135 /*=============================================================================
136  * Structure definitions
137  *============================================================================*/
138 
139 /*! \struct cs_navsto_system_t
140  *  \brief  Structure managing the Navier-Stokes system
141  *
142  */
143 
144 typedef struct {
145 
146   /*! \var param
147    *  Set of parameters to handle the Navier-Stokes system
148    */
149 
150   cs_navsto_param_t          *param;
151 
152   /*! \var adv_field
153    *  Pointer to the \ref cs_adv_field_t structure storing the advection
154    *  field used in the Navier-Stokes equations
155    */
156 
157   cs_adv_field_t             *adv_field;
158 
159   /*! \var mass_flux_array
160    *  Current values of the mass flux (if this is a CDO Face-based scheme,
161    *  array is allocated to the number of faces; first interior faces then
162    *  boundary faces)
163    */
164 
165   cs_real_t                  *mass_flux_array;
166 
167   /*! \var mass_flux_array_pre
168    *  Previous values of the mass flux (if this is a CDO Face-based scheme,
169    *  array is allocated to the number of faces; first interior faces then
170    *  boundary faces)
171    */
172 
173   cs_real_t                  *mass_flux_array_pre;
174 
175   /*! \var boundary_type
176    * Array storing the type of boundary for each boundary face
177    */
178 
179   cs_boundary_type_t         *bf_type;
180 
181   /*!
182    * @name Variable fields
183    * Set of fields (resolved variables): fields are created according to the
184    * choice of model for Navier-Stokes
185    * @{
186    */
187 
188   /*! \var velocity
189    *  Velocity, vector-valued, pointer to \ref cs_field_t
190    */
191 
192   cs_field_t                 *velocity;
193 
194   /*! \var pressure
195    *  Pressure, scalar-valued, pointer to \ref cs_field_t
196    */
197 
198   cs_field_t                 *pressure;
199 
200   /*!
201    * @}
202    * @name Related systems of equations
203    * According to the modelling choice other systems of equations can
204    * be solved in a more or less coupled manner. For instance, the
205    * energy equation (with the thermal system) or the magneto-hydrodynamic
206    * equations (with the Maxwell system of equations)
207    * @{
208    */
209 
210   /*! \var turbulence
211    *  Structure storing all settings, fields or properties related to the
212    *  turbulence modelling
213    */
214 
215   cs_turbulence_t            *turbulence;
216 
217   /*!
218    * @}
219    * @name Post-processing
220    * Set of fields which are induced by the variable fields and which have
221    * meaningful information for understanding the flow. Structure maning the
222    * post-processing.
223    * @{
224    */
225 
226   /*! \var plot_writer
227    * Writer for monitoring the evolution of predefined global variables (the
228    * integral of the mass in the computational domain or the divergence of the
229    * velocity field for instance)
230    */
231 
232   cs_time_plot_t             *plot_writer;
233 
234   /*! \var velocity_divergence
235    *  Divergence of the velocity fied.
236    *  Pointer to a scalar-valued \ref cs_field_t
237    */
238 
239   cs_field_t                 *velocity_divergence;
240 
241   /*! \var pressure_gradient
242    *  Pressure gradient
243    *  Pointer to a vector-valued \ref cs_field_t
244    */
245 
246   cs_field_t                 *pressure_gradient;
247 
248   /*! \var kinetic_energy
249    *  Kinetic energy defined as \f$ 1/2 velocity \cdot velocity \f$
250    *  Pointer to a scalar-valued \ref cs_field_t
251    */
252 
253   cs_field_t                 *kinetic_energy;
254 
255   /*! \var mass_density
256    *  Mass density
257    *
258    *  Available when a Boussinesq approximation is on and a postprocessing has
259    *  been requested. Pointer to a scalar-valued \ref cs_field_t
260    */
261 
262   cs_field_t                 *mass_density;
263 
264   /*! \var mass_flux_balance
265    *  Cellwise balance of the mass flux. Useful to check settings
266    *  (injection/suction) or the expected behavior f the numerical algorithm.
267   */
268 
269   cs_field_t                 *mass_flux_balance;
270 
271   /*! \var vorticity
272    *  Vorticity of the velocity field defined as curl(velocity)
273    *  Pointer to a vector-valued \ref cs_field_t
274    */
275 
276   cs_field_t                 *vorticity;
277 
278   /*! \var helicity
279    *  Helicity is defined as \f$ \int_c velocity \cdot \f$ vorticity
280    *  Pointer to a scalar-valued \ref cs_field_t
281    */
282 
283   cs_field_t                 *helicity;
284 
285   /*! \var enstrophy
286    *  Enstrophy is defined as \f$ \int_c vorticity \cdot \f$ vorticity
287    *  Pointer to a scalar-valued \ref cs_field_t
288    */
289 
290   cs_field_t                 *enstrophy;
291 
292   /*! \var velocity_gradient
293    *  Pointer to a tensor-valued \ref cs_field_t
294    */
295 
296   cs_field_t                 *velocity_gradient;
297 
298   /*! \var stream_function_eq
299    *  Pointer to a \ref cs_equation_t structure related to the computation
300    *  of the stream function -Laplacian(psi) = vorticity_z where psi is the
301    *  scalar-valued stream function. This is relevant only for a 2D
302    *  computation
303    */
304 
305   cs_equation_t              *stream_function_eq;
306 
307   /*!
308    * @}
309    * @name Context structures to get a greater flexibility in what can be done
310    *       in the given framework
311    * @{
312    */
313 
314   /*! \var coupling_context
315    * Additional structure storing information according to the way equations
316    * of model for the Navier-Stokes system are coupled and thus solved
317    */
318 
319   void                       *coupling_context;
320 
321   /*! \var scheme_context
322    * Additional structure storing information according to the space
323    * discretization scheme used for solving the model for the Navier-Stokes
324    * system
325    */
326 
327   void                       *scheme_context;
328 
329   /*!
330    * @}
331    * @name Pointer to functions handling specific tasks
332    * @{
333    */
334 
335   /*! \var init_scheme_context
336    *  Pointer of functions related to the initialization of the context
337    *  structure related to a given discretization scheme for the resolution
338    *  of the Navier-Stokes system
339    */
340 
341   cs_navsto_init_scheme_context_t   *init_scheme_context;
342 
343   /*! \var free_scheme_context
344    *  Pointer of functions related to the destruction of the context
345    *  structure related to a given discretization scheme for the resolution
346    *  of the Navier-Stokes system
347    */
348 
349   cs_navsto_free_scheme_context_t   *free_scheme_context;
350 
351   /*! \var init_velocity
352    *  Pointer of functions related to the initialization of variable values
353    *  Case of the velocity
354    */
355 
356   cs_navsto_init_values_t           *init_velocity;
357 
358   /*! \var init_pressure
359    *  Pointer of functions related to the initialization of variable values
360    *  Case of the pressure
361    */
362   cs_navsto_init_values_t           *init_pressure;
363 
364   /*! \var compute_steady
365    *  Pointer of functions related to resolution of the Navier-Stokes steady
366    *  system. Handle the build of the system and its resolution
367    */
368 
369   cs_navsto_compute_t               *compute_steady;
370 
371   /*! \var compute
372    *  Pointer of functions related to resolution of the Navier-Stokes unsteady
373    *  system. Handle the build of the system and its resolution
374    */
375 
376   cs_navsto_compute_t               *compute;
377 
378 } cs_navsto_system_t;
379 
380 /*============================================================================
381  * Public function prototypes
382  *============================================================================*/
383 
384 /*----------------------------------------------------------------------------*/
385 /*!
386  * \brief Check if the resolution of the Navier-Stokes system has been
387  *        activated
388  *
389  * \return true or false
390  */
391 /*----------------------------------------------------------------------------*/
392 
393 bool
394 cs_navsto_system_is_activated(void);
395 
396 /*----------------------------------------------------------------------------*/
397 /*!
398  * \brief Update the flag associated to the modelling options
399  *
400  * \param[in]   with_thermal     true or false
401  */
402 /*----------------------------------------------------------------------------*/
403 
404 void
405 cs_navsto_system_update_model(bool   with_thermal);
406 
407 /*----------------------------------------------------------------------------*/
408 /*!
409  * \brief  Allocate and initialize the Navier-Stokes (NS) system
410  *
411  * \param[in] boundaries     pointer to the domain boundaries
412  * \param[in] model          type of model related to the NS system
413  * \param[in] model_flag     additional high-level model options
414  * \param[in] algo_coupling  algorithm used for solving the NS system
415  * \param[in] post_flag      predefined post-processings options
416  *
417  * \return a pointer to a new allocated cs_navsto_system_t structure
418  */
419 /*----------------------------------------------------------------------------*/
420 
421 cs_navsto_system_t *
422 cs_navsto_system_activate(const cs_boundary_t           *boundaries,
423                           cs_navsto_param_model_t        model,
424                           cs_navsto_param_model_flag_t   model_flag,
425                           cs_navsto_param_coupling_t     algo_coupling,
426                           cs_navsto_param_post_flag_t    post_flag);
427 
428 /*----------------------------------------------------------------------------*/
429 /*!
430  * \brief  Free the main structure related to the Navier-Stokes system
431  */
432 /*----------------------------------------------------------------------------*/
433 
434 void
435 cs_navsto_system_destroy(void);
436 
437 /*----------------------------------------------------------------------------*/
438 /*!
439  * \brief  Retrieve the structure storing the parameters for the Navier--Stokes
440  *         system
441  *
442  * \return NULL or the pointer to a \ref cs_navsto_param_t structure
443  */
444 /*----------------------------------------------------------------------------*/
445 
446 cs_navsto_param_t *
447 cs_navsto_system_get_param(void);
448 
449 /*----------------------------------------------------------------------------*/
450 /*!
451  * \brief  Retrieve a pointer to the equation related to the momentum equation
452  *
453  * \return NULL or the pointer
454  */
455 /*----------------------------------------------------------------------------*/
456 
457 cs_equation_t *
458 cs_navsto_system_get_momentum_eq(void);
459 
460 /*----------------------------------------------------------------------------*/
461 /*!
462  * \brief  Retrieve the advection field structure (the mass flux) related to
463  *         the Navier-Stokes system.
464  *
465  * \return a pointer to the advection field structure
466  */
467 /*----------------------------------------------------------------------------*/
468 
469 cs_adv_field_t *
470 cs_navsto_get_adv_field(void);
471 
472 /*----------------------------------------------------------------------------*/
473 /*!
474  * \brief  Retrieve the mass flux array related to the Navier-Stokes system.
475  *
476  * \param[in]  previous    if true return the previous state otherwise the
477  *                         current state.
478  *
479  * \return a pointer to an array of cs_real_t
480  */
481 /*----------------------------------------------------------------------------*/
482 
483 cs_real_t *
484 cs_navsto_get_mass_flux(bool   previous);
485 
486 /*----------------------------------------------------------------------------*/
487 /*!
488  * \brief  Start setting-up the Navier-Stokes system
489  *         At this stage, numerical settings should be completely determined
490  *         but connectivity and geometrical information is not yet available.
491  */
492 /*----------------------------------------------------------------------------*/
493 
494 void
495 cs_navsto_system_init_setup(void);
496 
497 /*----------------------------------------------------------------------------*/
498 /*!
499  * \brief  Last step of the setup of the Navier-Stokes system
500  *
501  * \param[in]  mesh       pointer to a cs_mesh_t structure
502  * \param[in]  connect    pointer to a cs_cdo_connect_t structure
503  * \param[in]  quant      pointer to a cs_cdo_quantities_t structure
504  * \param[in]  time_step  pointer to a cs_time_step_t structure
505  */
506 /*----------------------------------------------------------------------------*/
507 
508 void
509 cs_navsto_system_finalize_setup(const cs_mesh_t            *mesh,
510                                 const cs_cdo_connect_t     *connect,
511                                 const cs_cdo_quantities_t  *quant,
512                                 const cs_time_step_t       *time_step);
513 
514 /*----------------------------------------------------------------------------*/
515 /*!
516  * \brief  Define the settings for SLES related to the Navier-Stokes system
517  */
518 /*----------------------------------------------------------------------------*/
519 
520 void
521 cs_navsto_system_set_sles(void);
522 
523 /*----------------------------------------------------------------------------*/
524 /*!
525  * \brief  Initialize the scheme context structure used to build the algebraic
526  *         system. This is done after the setup step.
527  *         Set an initial value for the velocity and pressure field if needed
528  *
529  * \param[in]  mesh        pointer to a cs_mesh_t structure
530  * \param[in]  connect     pointer to a cs_cdo_connect_t structure
531  * \param[in]  quant       pointer to a cs_cdo_quantities_t structure
532  * \param[in]  time_step   pointer to a cs_time_step_t structure
533  */
534 /*----------------------------------------------------------------------------*/
535 
536 void
537 cs_navsto_system_initialize(const cs_mesh_t             *mesh,
538                             const cs_cdo_connect_t      *connect,
539                             const cs_cdo_quantities_t   *quant,
540                             const cs_time_step_t        *time_step);
541 
542 /*----------------------------------------------------------------------------*/
543 /*!
544  * \brief  Set a solid zone related to the Navier-Stokes equations
545  *
546  * \param[in] n_solid_cells    number of solid cells
547  * \param[in] solid_cell_ids   list of cell ids (local numbering)
548  */
549 /*----------------------------------------------------------------------------*/
550 
551 void
552 cs_navsto_system_set_solid_cells(cs_lnum_t          n_solid_cells,
553                                  cs_lnum_t          solid_cell_ids[]);
554 
555 /*----------------------------------------------------------------------------*/
556 /*!
557  * \brief  Update variables and related quantities when a new state of the
558  *         Navier-Stokes system has been computed
559  *
560  * \param[in] mesh       pointer to a cs_mesh_t structure
561  * \param[in] connect    pointer to a cs_cdo_connect_t structure
562  * \param[in] quant      pointer to a cs_cdo_quantities_t structure
563  * \param[in] time_step  structure managing the time stepping
564  */
565 /*----------------------------------------------------------------------------*/
566 
567 void
568 cs_navsto_system_update(const cs_mesh_t             *mesh,
569                         const cs_cdo_connect_t      *connect,
570                         const cs_cdo_quantities_t   *quant,
571                         const cs_time_step_t        *time_step);
572 
573 /*----------------------------------------------------------------------------*/
574 /*!
575  * \brief  Build, solve and update the Navier-Stokes system in case of a
576  *         steady-state approach
577  *
578  * \param[in] mesh       pointer to a cs_mesh_t structure
579  * \param[in] connect    pointer to a cs_cdo_connect_t structure
580  * \param[in] quant      pointer to a cs_cdo_quantities_t structure
581  * \param[in] time_step  structure managing the time stepping
582  */
583 /*----------------------------------------------------------------------------*/
584 
585 void
586 cs_navsto_system_compute_steady_state(const cs_mesh_t             *mesh,
587                                       const cs_cdo_connect_t      *connect,
588                                       const cs_cdo_quantities_t   *quant,
589                                       const cs_time_step_t        *time_step);
590 
591 /*----------------------------------------------------------------------------*/
592 /*!
593  * \brief  Build, solve and update the Navier-Stokes system
594  *
595  * \param[in] mesh       pointer to a cs_mesh_t structure
596  * \param[in] connect    pointer to a cs_cdo_connect_t structure
597  * \param[in] quant      pointer to a cs_cdo_quantities_t structure
598  * \param[in] time_step  structure managing the time stepping
599  */
600 /*----------------------------------------------------------------------------*/
601 
602 void
603 cs_navsto_system_compute(const cs_mesh_t             *mesh,
604                          const cs_cdo_connect_t      *connect,
605                          const cs_cdo_quantities_t   *quant,
606                          const cs_time_step_t        *time_step);
607 
608 /*----------------------------------------------------------------------------*/
609 /*!
610  * \brief  Predefined extra-operations for the Navier-Stokes system
611  *
612  * \param[in]  mesh        pointer to a cs_mesh_t structure
613  * \param[in]  connect     pointer to a cs_cdo_connect_t structure
614  * \param[in]  quant       pointer to a cs_cdo_quantities_t structure
615  * \param[in]  time_step   pointer to a cs_time_step_t structure
616  */
617 /*----------------------------------------------------------------------------*/
618 
619 void
620 cs_navsto_system_extra_op(const cs_mesh_t             *mesh,
621                           const cs_cdo_connect_t      *connect,
622                           const cs_cdo_quantities_t   *quant,
623                           const cs_time_step_t        *time_step);
624 
625 /*----------------------------------------------------------------------------*/
626 /*!
627  * \brief  Predefined post-processing output for the Navier-Stokes system.
628  *         The prototype of this function is fixed since it is a function
629  *         pointer defined in cs_post.h (\ref cs_post_time_mesh_dep_output_t)
630  *
631  * \param[in, out] input        pointer to a optional structure (here a
632  *                              cs_navsto_system_t structure)
633  * \param[in]      mesh_id      id of the output mesh for the current call
634  * \param[in]      cat_id       category id of the output mesh for this call
635  * \param[in]      ent_flag     indicate global presence of cells (ent_flag[0]),
636  *                              interior faces (ent_flag[1]), boundary faces
637  *                              (ent_flag[2]), particles (ent_flag[3]) or probes
638  *                              (ent_flag[4])
639  * \param[in]      n_cells      local number of cells of post_mesh
640  * \param[in]      n_i_faces    local number of interior faces of post_mesh
641  * \param[in]      n_b_faces    local number of boundary faces of post_mesh
642  * \param[in]      cell_ids     list of cells (0 to n-1)
643  * \param[in]      i_face_ids   list of interior faces (0 to n-1)
644  * \param[in]      b_face_ids   list of boundary faces (0 to n-1)
645  * \param[in]      time_step    pointer to a cs_time_step_t struct.
646  */
647 /*----------------------------------------------------------------------------*/
648 
649 void
650 cs_navsto_system_extra_post(void                      *input,
651                             int                        mesh_id,
652                             int                        cat_id,
653                             int                        ent_flag[5],
654                             cs_lnum_t                  n_cells,
655                             cs_lnum_t                  n_i_faces,
656                             cs_lnum_t                  n_b_faces,
657                             const cs_lnum_t            cell_ids[],
658                             const cs_lnum_t            i_face_ids[],
659                             const cs_lnum_t            b_face_ids[],
660                             const cs_time_step_t      *time_step);
661 
662 /*----------------------------------------------------------------------------*/
663 /*!
664  * \brief  Summary of the main cs_navsto_system_t structure
665  */
666 /*----------------------------------------------------------------------------*/
667 
668 void
669 cs_navsto_system_log_setup(void);
670 
671 /*----------------------------------------------------------------------------*/
672 
673 END_C_DECLS
674 
675 #endif /* __CS_NAVSTO_SYSTEM_H__ */
676