1 #ifndef __CS_NAVSTO_COUPLING_H__
2 #define __CS_NAVSTO_COUPLING_H__
3 
4 /*============================================================================
5  * Functions to handle structures used as a context when solving the
6  * Navier-Stokes equations. Structures are cast on-the-fly according to the
7  * type of coupling.
8  *============================================================================*/
9 
10 /*
11   This file is part of Code_Saturne, a general-purpose CFD tool.
12 
13   Copyright (C) 1998-2021 EDF S.A.
14 
15   This program is free software; you can redistribute it and/or modify it under
16   the terms of the GNU General Public License as published by the Free Software
17   Foundation; either version 2 of the License, or (at your option) any later
18   version.
19 
20   This program is distributed in the hope that it will be useful, but WITHOUT
21   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23   details.
24 
25   You should have received a copy of the GNU General Public License along with
26   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
27   Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 */
29 
30 /*----------------------------------------------------------------------------
31  *  Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_equation.h"
35 #include "cs_field.h"
36 #include "cs_navsto_param.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
40 BEGIN_C_DECLS
41 
42 /*============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *============================================================================*/
49 
50 /* Predefined context structures depending on the settings */
51 /* ======================================================= */
52 
53 /*! \struct cs_navsto_ac_t
54  *  \brief Set of parameters specific for solving the Navier-Stokes system with
55  *         the "artificial compressibility" algorithm
56  *
57  *  All equations are not always created. It depends on the choice of the model
58  */
59 
60 typedef struct {
61 
62   cs_equation_t   *momentum; /*!< Momentum balance equation (vector-valued) */
63 
64   /*! \var zeta
65    *  Coefficient for the artificial compressibility attached to the grad-div
66    *  stabilization term
67    */
68   cs_property_t   *zeta;
69 
70 } cs_navsto_ac_t;
71 
72 /*! \struct cs_navsto_monolithic_t
73  *  \brief Set of parameters specific for solving the Navier-Stokes system with
74  *         a fully coupled monolithic algorithm
75  */
76 
77 typedef struct {
78 
79   cs_equation_t   *momentum; /*!< Momentum equation (vector-valued) */
80 
81 } cs_navsto_monolithic_t;
82 
83 /*! \struct cs_navsto_projection_t
84  *  \brief Set of parameters specific for solving the Navier-Stokes system with
85  *         an incremental projection algorithm
86  *
87  *  All equations are not always created. It depends on the choice of the model
88  */
89 
90 typedef struct {
91 
92   cs_equation_t  *prediction; /*!< Velocity prediction step related to the
93                                    momentum balance equation (vector-valued) */
94   cs_equation_t  *correction; /*!< Pressure correction step related to the mass
95                                    balance equation (scalar-valued) */
96 
97   /*! \var div_st
98    * Source term on the correction step stemming from the divergence of the
99    * predicted velocity */
100   cs_real_t      *div_st;
101 
102   /*! \var bdy_pressure_incr
103    * Pressure increment at the boundary. Used as an array to set the boundary
104    * condition arising from a Dirichlet on the pressure. */
105   cs_real_t      *bdy_pressure_incr;
106 
107   /*! \var predicted_velocity
108    * Predicted velocity field (value of the velocity at cells after the
109    * prediction step). This values may not be divergence-free.
110    */
111   cs_field_t     *predicted_velocity;
112 
113 } cs_navsto_projection_t;
114 
115 /*============================================================================
116  * Public function prototypes
117  *============================================================================*/
118 
119 /*----------------------------------------------------------------------------*/
120 /*!
121  * \brief  Allocate and initialize a context structure when the Navier-Stokes
122  *         system is coupled using an Artificial Compressibility approach
123  *
124  * \param[in]  bc     default \ref cs_param_bc_type_t for the equation
125  * \param[in]  nsp    pointer to a \ref cs_navsto_param_t structure
126  *
127  * \return a pointer to the context structure
128  */
129 /*----------------------------------------------------------------------------*/
130 
131 void *
132 cs_navsto_ac_create_context(cs_param_bc_type_t    bc,
133                             cs_navsto_param_t    *nsp);
134 
135 /*----------------------------------------------------------------------------*/
136 /*!
137  * \brief  Free the context structure related to an Artificial Compressibility
138  *         approach
139  *
140  * \param[in, out] context  pointer to a context structure cast on-the-fly
141  *
142  * \return a NULL pointer
143  */
144 /*----------------------------------------------------------------------------*/
145 
146 void *
147 cs_navsto_ac_free_context(void     *context);
148 
149 /*----------------------------------------------------------------------------*/
150 /*!
151  * \brief  Start setting-up the Navier-Stokes equations when an
152  *         Artificial Compressibility algorithm is used to coupled the system.
153  *         No mesh information is available at this stage.
154  *
155  * \param[in]      nsp         pointer to a \ref cs_navsto_param_t structure
156  * \param[in]      adv_field   pointer to a cs_adv_field_t structure
157  * \param[in, out] context     pointer to a context structure cast on-the-fly
158  */
159 /*----------------------------------------------------------------------------*/
160 
161 void
162 cs_navsto_ac_init_setup(const cs_navsto_param_t    *nsp,
163                         cs_adv_field_t             *adv_field,
164                         void                       *context);
165 
166 /*----------------------------------------------------------------------------*/
167 /*!
168  * \brief  Finalize the setup for the Navier-Stokes equations when an
169  *         Artificial Compressibility algorithm is used to coupled the system.
170  *
171  * \param[in]      nsp      pointer to a \ref cs_navsto_param_t structure
172  * \param[in, out] context  pointer to a context structure cast on-the-fly
173  */
174 /*----------------------------------------------------------------------------*/
175 
176 void
177 cs_navsto_ac_last_setup(const cs_navsto_param_t     *nsp,
178                         void                        *context);
179 
180 /*----------------------------------------------------------------------------*/
181 /*!
182  * \brief  Retrieve the pointer to the \ref cs_equation_t structure related to
183  *         the momentum equation in case of artificial compressibility coupling
184  *
185  * \param[in] context  pointer to a context structure cast on-the-fly
186  *
187  * \return a pointer to a cs_equation_t structure
188  */
189 /*----------------------------------------------------------------------------*/
190 
191 cs_equation_t *
192 cs_navsto_ac_get_momentum_eq(void       *context);
193 
194 /*----------------------------------------------------------------------------*/
195 /*!
196  * \brief  Allocate and initialize a context structure when the Navier-Stokes
197  *         system is coupled using a monolithic approach
198  *
199  * \param[in]      bc     default \ref cs_param_bc_type_t for the equation
200  * \param[in, out] nsp    pointer to a \ref cs_navsto_param_t structure
201  *
202  * \return a pointer to the context structure
203  */
204 /*----------------------------------------------------------------------------*/
205 
206 void *
207 cs_navsto_monolithic_create_context(cs_param_bc_type_t    bc,
208                                     cs_navsto_param_t    *nsp);
209 
210 /*----------------------------------------------------------------------------*/
211 /*!
212  * \brief  Free the context structure related to a monolithic approach
213  *
214  * \param[in, out] context  pointer to a context structure cast on-the-fly
215  *
216  * \return a NULL pointer
217  */
218 /*----------------------------------------------------------------------------*/
219 
220 void *
221 cs_navsto_monolithic_free_context(void             *context);
222 
223 /*----------------------------------------------------------------------------*/
224 /*!
225  * \brief  Start setting-up the Navier-Stokes equations when a monolithic
226  *         algorithm is used to coupled the system.
227  *         No mesh information is available at this stage
228  *
229  * \param[in]      nsp        pointer to a \ref cs_navsto_param_t structure
230  * \param[in]      adv_field  pointer to a cs_adv_field_t structure
231  * \param[in, out] context    pointer to a context structure cast on-the-fly
232  */
233 /*----------------------------------------------------------------------------*/
234 
235 void
236 cs_navsto_monolithic_init_setup(const cs_navsto_param_t    *nsp,
237                                 cs_adv_field_t             *adv_field,
238                                 void                       *context);
239 
240 /*----------------------------------------------------------------------------*/
241 /*!
242  * \brief  Finalize the setup for the Navier-Stokes equations when a monolithic
243  *         algorithm is used to coupled the system.
244  *
245  * \param[in]      nsp      pointer to a \ref cs_navsto_param_t structure
246  * \param[in, out] context  pointer to a context structure cast on-the-fly
247  */
248 /*----------------------------------------------------------------------------*/
249 
250 void
251 cs_navsto_monolithic_last_setup(const cs_navsto_param_t     *nsp,
252                                 void                        *context);
253 /*----------------------------------------------------------------------------*/
254 /*!
255  * \brief  Retrieve the pointer to the \ref cs_equation_t structure related to
256  *         the momentum equation in case of a monolithic coupling
257  *
258  * \param[in] context  pointer to a context structure cast on-the-fly
259  *
260  * \return a pointer to a cs_equation_t structure
261  */
262 /*----------------------------------------------------------------------------*/
263 
264 cs_equation_t *
265 cs_navsto_monolithic_get_momentum_eq(void       *context);
266 
267 /*----------------------------------------------------------------------------*/
268 /*!
269  * \brief  Allocate and initialize a context structure when the Navier-Stokes
270  *         system is coupled using an incremental Projection approach in the
271  *         the rotational form (see Minev & Guermond, 2006, JCP)
272  *
273  * \param[in]  bc     default \ref cs_param_bc_type_t for the equation
274  * \param[in]  nsp    pointer to a \ref cs_navsto_param_t structure
275  *
276  * \return a pointer to the context structure
277  */
278 /*----------------------------------------------------------------------------*/
279 
280 void *
281 cs_navsto_projection_create_context(cs_param_bc_type_t    bc,
282                                     cs_navsto_param_t    *nsp);
283 
284 /*----------------------------------------------------------------------------*/
285 /*!
286  * \brief  Free the context structure related to a Projection approach
287  *
288  * \param[in, out] context  pointer to a context structure cast on-the-fly
289  *
290  * \return a NULL pointer
291  */
292 /*----------------------------------------------------------------------------*/
293 
294 void *
295 cs_navsto_projection_free_context(void           *context);
296 
297 /*----------------------------------------------------------------------------*/
298 /*!
299  * \brief  Start setting-up the Navier-Stokes equations when a projection
300  *         algorithm is used to coupled the system.
301  *         No mesh information is available at this stage.
302  *
303  * \param[in]      nsp           pointer to a \ref cs_navsto_param_t structure
304  * \param[in]      adv_field     pointer to a cs_adv_field_t structure
305  * \param[in]      loc_id        id related to a mesh location
306  * \param[in]      has_previous  values at different time steps (true/false)
307  * \param[in, out] context       pointer to a context structure cast on-the-fly
308  */
309 /*----------------------------------------------------------------------------*/
310 
311 void
312 cs_navsto_projection_init_setup(const cs_navsto_param_t    *nsp,
313                                 cs_adv_field_t             *adv_field,
314                                 int                         loc_id,
315                                 bool                        has_previous,
316                                 void                       *context);
317 
318 /*----------------------------------------------------------------------------*/
319 /*!
320  * \brief  Finalize the setup for the Navier-Stokes equations when a
321  *         projection algorithm is used to coupled the system.
322  *         Connectivity and geometric quantities are available at this stage.
323  *
324  * \param[in]      quant    pointer to a \ref cs_cdo_quantities_t structure
325  * \param[in]      nsp      pointer to a \ref cs_navsto_param_t structure
326  * \param[in, out] context  pointer to a context structure cast on-the-fly
327  */
328 /*----------------------------------------------------------------------------*/
329 
330 void
331 cs_navsto_projection_last_setup(const cs_cdo_quantities_t  *quant,
332                                 const cs_navsto_param_t    *nsp,
333                                 void                       *context);
334 
335 /*----------------------------------------------------------------------------*/
336 /*!
337  * \brief  Retrieve the pointer to the \ref cs_equation_t structure related to
338  *         the momentum equation in case of a projection coupling
339  *
340  * \param[in] context  pointer to a context structure cast on-the-fly
341  *
342  * \return a pointer to a cs_equation_t structure
343  */
344 /*----------------------------------------------------------------------------*/
345 
346 cs_equation_t *
347 cs_navsto_projection_get_momentum_eq(void       *context);
348 
349 /*----------------------------------------------------------------------------*/
350 
351 END_C_DECLS
352 
353 #endif /* __CS_NAVSTO_COUPLING_H__ */
354