1 #ifndef __CS_CDO_BC_H__
2 #define __CS_CDO_BC_H__
3 
4 /*============================================================================
5  * Manage the low-level structure dedicated to boundary conditions
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_base.h"
33 #include "cs_cdo_quantities.h"
34 #include "cs_param_types.h"
35 #include "cs_time_step.h"
36 #include "cs_xdef.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
40 BEGIN_C_DECLS
41 
42 /*============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 #define CS_CDO_BC_DEFAULT_DEF    -1
47 
48 /*!
49  * @defgroup cdo_bc_flags Flags specifying the type of boundary conditions
50  *  associated to an element
51  *
52  * Homogeneous conditions are defined separately since a flag
53  * CS_CDO_BC_HOMOGENEOUS would not enable to identify if it is associated to a
54  * Dirichlet or a Neumann boundary condition
55  *
56  * @{
57  */
58 
59 /*!  1: Neumann boundary conditions */
60 #define CS_CDO_BC_NEUMANN               (1 << 0)
61 /*!  2: Homogeneous Neumann boundary conditions */
62 #define CS_CDO_BC_HMG_NEUMANN           (1 << 1)
63 /*!  4: Dirichlet boundary conditions */
64 #define CS_CDO_BC_DIRICHLET             (1 << 2)
65 /*!  8: Homogeneous Dirichlet boundary conditions */
66 #define CS_CDO_BC_HMG_DIRICHLET         (1 << 3)
67 /*! 16: Robin boundary conditions */
68 #define CS_CDO_BC_ROBIN                 (1 << 4)
69 /*! 32: Apply a sliding condition (for vector-valued equations) */
70 #define CS_CDO_BC_SLIDING               (1 << 5)
71 /*! 64: Apply a Dirichlet on the tangential part of a vector-valued quantity */
72 #define CS_CDO_BC_TANGENTIAL_DIRICHLET  (1 << 6)
73 
74 /*! @} */
75 
76 /*============================================================================
77  * Type definitions
78  *============================================================================*/
79 
80 /* Structure specific to store data related to the definition of boundary
81  * conditions on boundary faces.
82  *
83  * For of scalar-valued equations, only some the classical (Dirichlet, Neumann
84  * and Robin types are available. Other types of boundary conditions are
85  * possible for vector-valued equations
86  */
87 
88 typedef struct {
89 
90   bool         is_steady;    /* Do we need to update BC faces during the
91                                 computation */
92   cs_lnum_t    n_b_faces;    /* Number of boundary faces */
93 
94   /* Type of boundary conditions associated to a face. Size: n_b_faces */
95   cs_flag_t   *flag;
96 
97   /* Id of the boundary condition definition or CS_BC_DEFAULT (=-1) if this face
98      is related to the default boundary condition. Size = n_b_faces */
99   short int   *def_ids;
100 
101   /* List of face ids by type of boundary conditions. Homogeneous types don't
102    * need to rely on a definition since it can be the default bc. Moreover, some
103    * optimizations can be performed that's why they are stored separately
104    */
105 
106   /* Dirichlet */
107   cs_lnum_t    n_hmg_dir_faces;
108   cs_lnum_t   *hmg_dir_ids;
109   cs_lnum_t    n_nhmg_dir_faces;
110   cs_lnum_t   *nhmg_dir_ids;
111 
112   /* Neumann */
113   cs_lnum_t    n_hmg_neu_faces;
114   cs_lnum_t   *hmg_neu_ids;
115   cs_lnum_t    n_nhmg_neu_faces;
116   cs_lnum_t   *nhmg_neu_ids;
117 
118   /* Robin */
119   cs_lnum_t    n_robin_faces;
120   cs_lnum_t   *robin_ids;
121 
122   /* Sliding wall */
123   cs_lnum_t    n_sliding_faces;
124   cs_lnum_t   *sliding_ids;
125 
126   /* Circulation */
127   cs_lnum_t    n_circulation_faces;
128   cs_lnum_t   *circulation_ids;
129 
130 } cs_cdo_bc_face_t;
131 
132 /*============================================================================
133  * Global variables
134  *============================================================================*/
135 
136 /*============================================================================
137  * Public function prototypes
138  *============================================================================*/
139 
140 /*----------------------------------------------------------------------------*/
141 /*!
142  * \brief   Convert a flag into a description
143  *
144  * \param[in]       bc_flag  flag of boundary condition
145  * \param[in, out]  desc     string storing the description of the BC
146  */
147 /*----------------------------------------------------------------------------*/
148 
149 static inline void
cs_cdo_bc_get_desc(cs_flag_t bc_flag,char * desc)150 cs_cdo_bc_get_desc(cs_flag_t   bc_flag,
151                    char       *desc)
152 {
153   if (desc == NULL)
154     bft_error(__FILE__, __LINE__, 0,
155               " %s: Empty desciption buffer.", __func__);
156 
157   switch (bc_flag) {
158 
159   case CS_CDO_BC_HMG_DIRICHLET:
160     sprintf(desc, "%s", "Homogenous Dirichlet");
161     break;
162   case CS_CDO_BC_DIRICHLET:
163     sprintf(desc, "%s", "Dirichlet");
164     break;
165   case CS_CDO_BC_HMG_NEUMANN:
166     sprintf(desc, "%s", "Homogeneous Neumann");
167     break;
168   case CS_CDO_BC_NEUMANN:
169     sprintf(desc, "%s", "Neumann");
170     break;
171   case CS_CDO_BC_ROBIN:
172     sprintf(desc, "%s", "Robin");
173     break;
174   case CS_CDO_BC_SLIDING:
175     sprintf(desc, "%s", "Sliding");
176     break;
177   case CS_CDO_BC_TANGENTIAL_DIRICHLET:
178     sprintf(desc, "%s", "Dirichlet on the tangential component");
179     break;
180 
181   default:
182     bft_error(__FILE__, __LINE__, 0,
183               "%s: Invalid case. Please contact the support.\n", __func__);
184     break;
185   }
186 }
187 
188 /*----------------------------------------------------------------------------*/
189 /*!
190  * \brief   Convert a cs_param_bc_type_t into a flag (enable multiple type for
191  *          a same entity as required for vertices and edges)
192  *
193  * \param[in] bc_type   predefined type of boundary condition
194  *
195  * \return  a flag corresponding to the given type of boundary condition
196  */
197 /*----------------------------------------------------------------------------*/
198 
199 static inline cs_flag_t
cs_cdo_bc_get_flag(cs_param_bc_type_t bc_type)200 cs_cdo_bc_get_flag(cs_param_bc_type_t   bc_type)
201 {
202   cs_flag_t  ret_flag;
203 
204   switch (bc_type) {
205   case CS_PARAM_BC_HMG_DIRICHLET:
206     ret_flag = CS_CDO_BC_HMG_DIRICHLET;
207     break;
208   case CS_PARAM_BC_DIRICHLET:
209     ret_flag = CS_CDO_BC_DIRICHLET;
210     break;
211   case CS_PARAM_BC_HMG_NEUMANN:
212     ret_flag = CS_CDO_BC_HMG_NEUMANN;
213     break;
214   case CS_PARAM_BC_NEUMANN:
215     ret_flag = CS_CDO_BC_NEUMANN;
216     break;
217   case CS_PARAM_BC_NEUMANN_FULL:
218     ret_flag = CS_CDO_BC_NEUMANN;
219     break;
220   case CS_PARAM_BC_ROBIN:
221     ret_flag = CS_CDO_BC_ROBIN;
222     break;
223   case CS_PARAM_BC_SLIDING:
224     ret_flag = CS_CDO_BC_SLIDING;
225     break;
226   case CS_PARAM_BC_CIRCULATION:
227     ret_flag = CS_CDO_BC_TANGENTIAL_DIRICHLET;
228     break;
229 
230   default:
231     ret_flag = 0;               /* Not handle automatically */
232     break;
233   }
234   return ret_flag;
235 }
236 
237 /*----------------------------------------------------------------------------*/
238 /*!
239  * \brief   Check if a flag is associated to a Dirichlet BC (homogeneous or
240  *          not)
241  *
242  * \param[in] flag     flag to test
243  *
244  * \return  true or false
245  */
246 /*----------------------------------------------------------------------------*/
247 
248 static inline bool
cs_cdo_bc_is_dirichlet(cs_flag_t flag)249 cs_cdo_bc_is_dirichlet(cs_flag_t    flag)
250 {
251   if (flag & CS_CDO_BC_DIRICHLET)
252     return true;
253   else if (flag & CS_CDO_BC_HMG_DIRICHLET)
254     return true;
255   else
256     return false;
257 }
258 
259 /*----------------------------------------------------------------------------*/
260 /*!
261  * \brief   Check if a flag is associated to a Neumann BC (homogeneous or not)
262  *
263  * \param[in] flag     flag to test
264  *
265  * \return  true or false
266  */
267 /*----------------------------------------------------------------------------*/
268 
269 static inline bool
cs_cdo_bc_is_neumann(cs_flag_t flag)270 cs_cdo_bc_is_neumann(cs_flag_t    flag)
271 {
272   if (flag & CS_CDO_BC_NEUMANN)
273     return true;
274   else if (flag & CS_CDO_BC_HMG_NEUMANN)
275     return true;
276   else
277     return false;
278 }
279 
280 /*----------------------------------------------------------------------------*/
281 /*!
282  * \brief   Check if a flag is associated to a sliding boundary
283  *
284  * \param[in] flag     flag to test
285  *
286  * \return  true or false
287  */
288 /*----------------------------------------------------------------------------*/
289 
290 static inline bool
cs_cdo_bc_is_sliding(cs_flag_t flag)291 cs_cdo_bc_is_sliding(cs_flag_t    flag)
292 {
293   if (flag & CS_CDO_BC_SLIDING)
294     return true;
295   else
296     return false;
297 }
298 
299 /*----------------------------------------------------------------------------*/
300 /*!
301  * \brief   Check if a flag is associated to a Dirichlet BC (homogeneous or
302  *          not)
303  *
304  * \param[in] flag     flag to test
305  *
306  * \return  true or false
307  */
308 /*----------------------------------------------------------------------------*/
309 
310 static inline bool
cs_cdo_bc_is_circulation(cs_flag_t flag)311 cs_cdo_bc_is_circulation(cs_flag_t    flag)
312 {
313   if (flag & CS_CDO_BC_DIRICHLET)
314     return true;
315   else if (flag & CS_CDO_BC_HMG_DIRICHLET)
316     return true;
317   else if (flag & CS_CDO_BC_TANGENTIAL_DIRICHLET)
318     return true;
319   else
320     return false;
321 }
322 
323 /*----------------------------------------------------------------------------*/
324 /*!
325  * \brief  Define the structure which translates the BC definitions from the
326  *         user viewpoint into a ready-to-use structure for setting the arrays
327  *         keeping the values of the boundary condition to set.
328  *
329  * \param[in] default_bc   type of boundary condition to set by default
330  * \param[in] is_steady    modification or not of the BC selection in time
331  * \param[in] dim          dimension of the related equation
332  * \param[in] n_defs       number of boundary definitions
333  * \param[in] defs         list of boundary condition definition
334  * \param[in] n_b_faces    number of border faces
335  *
336  * \return a pointer to a new allocated cs_cdo_bc_face_t structure
337  */
338 /*----------------------------------------------------------------------------*/
339 
340 cs_cdo_bc_face_t *
341 cs_cdo_bc_face_define(cs_param_bc_type_t    default_bc,
342                       bool                  is_steady,
343                       int                   dim,
344                       int                   n_defs,
345                       cs_xdef_t           **defs,
346                       cs_lnum_t             n_b_faces);
347 
348 /*----------------------------------------------------------------------------*/
349 /*!
350  * \brief  Free a cs_cdo_bc_face_t structure
351  *
352  * \param[in, out]  face_bc   pointer to a cs_cdo_bc_face_t structure
353  *
354  * \return a NULL pointer
355  */
356 /*----------------------------------------------------------------------------*/
357 
358 cs_cdo_bc_face_t *
359 cs_cdo_bc_free(cs_cdo_bc_face_t   *face_bc);
360 
361 /*----------------------------------------------------------------------------*/
362 
363 END_C_DECLS
364 
365 #endif /* __CS_CDO_BC_H__ */
366