My Project
programmer's documentation
cs_cdo_bc.h
Go to the documentation of this file.
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-2019 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.h"
35 #include "cs_time_step.h"
36 #include "cs_xdef.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 #define CS_CDO_BC_DEFAULT_DEF -1
47 
60 #define CS_CDO_BC_NEUMANN (1 << 0)
61 
62 #define CS_CDO_BC_HMG_NEUMANN (1 << 1)
63 
64 #define CS_CDO_BC_DIRICHLET (1 << 2)
65 
66 #define CS_CDO_BC_HMG_DIRICHLET (1 << 3)
67 
68 #define CS_CDO_BC_ROBIN (1 << 4)
69 
70 #define CS_CDO_BC_SLIDING (1 << 5)
71 
74 /*============================================================================
75  * Type definitions
76  *============================================================================*/
77 
78 /* Structure specific to store data related to the definition of boundary
79  * conditions on boundary faces.
80  *
81  * For of scalar-valued equations, only some the classical (Dirichlet, Neumann
82  * and Robin types are available. Other types of boundary conditions are
83  * possible for vector-valued equations
84  */
85 
86 typedef struct {
87 
88  bool is_steady; /* Do we need to update BC faces during the
89  computation */
90  cs_lnum_t n_b_faces; /* Number of boundary faces */
91 
92  /* Type of boundary conditions associated to a face. Size: n_b_faces */
94 
95  /* Id of the boundary condition definition or CS_BC_DEFAULT (=-1) if this face
96  is related to the default boundary condition. Size = n_b_faces */
97  short int *def_ids;
98 
99  /* List of face ids by type of boundary conditions. Homogeneous types don't
100  * need to rely on a definition since it can be the default bc. Moreover, some
101  * optimizations can be performed that's why they are stored separately
102  */
103 
104  /* Dirichlet */
109 
110  /* Neumann */
115 
116  /* Robin */
119 
120  /* Sliding wall */
123 
125 
126 /*============================================================================
127  * Global variables
128  *============================================================================*/
129 
130 /*============================================================================
131  * Public function prototypes
132  *============================================================================*/
133 
134 /*----------------------------------------------------------------------------*/
141 /*----------------------------------------------------------------------------*/
142 
143 static inline void
145  char *desc)
146 {
147  if (desc == NULL)
148  bft_error(__FILE__, __LINE__, 0,
149  " %s: Empty desciption buffer.", __func__);
150 
151  switch (bc_flag) {
152 
154  sprintf(desc, "%s", "Homogenous Dirichlet");
155  break;
156  case CS_CDO_BC_DIRICHLET:
157  sprintf(desc, "%s", "Dirichlet");
158  break;
160  sprintf(desc, "%s", "Homogeneous Neumann");
161  break;
162  case CS_CDO_BC_NEUMANN:
163  sprintf(desc, "%s", "Neumann");
164  break;
165  case CS_CDO_BC_ROBIN:
166  sprintf(desc, "%s", "Robin");
167  break;
168  case CS_CDO_BC_SLIDING:
169  sprintf(desc, "%s", "Sliding");
170  break;
171 
172  default:
173  bft_error(__FILE__, __LINE__, 0,
174  "%s: Invalid case. Please contact the support.\n", __func__);
175  break;
176  }
177 }
178 
179 /*----------------------------------------------------------------------------*/
188 /*----------------------------------------------------------------------------*/
189 
190 static inline cs_flag_t
192 {
193  cs_flag_t ret_flag;
194 
195  switch (bc_type) {
197  ret_flag = CS_CDO_BC_HMG_DIRICHLET;
198  break;
200  ret_flag = CS_CDO_BC_DIRICHLET;
201  break;
203  ret_flag = CS_CDO_BC_HMG_NEUMANN;
204  break;
205  case CS_PARAM_BC_NEUMANN:
206  ret_flag = CS_CDO_BC_NEUMANN;
207  break;
208  case CS_PARAM_BC_ROBIN:
209  ret_flag = CS_CDO_BC_ROBIN;
210  break;
211  case CS_PARAM_BC_SLIDING:
212  ret_flag = CS_CDO_BC_SLIDING;
213  break;
214 
215  default:
216  ret_flag = 0; /* Not handle automatically */
217  break;
218  }
219  return ret_flag;
220 }
221 
222 /*----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------*/
232 
233 static inline bool
235 {
236  if (flag & CS_CDO_BC_DIRICHLET)
237  return true;
238  else if (flag & CS_CDO_BC_HMG_DIRICHLET)
239  return true;
240  else
241  return false;
242 }
243 
244 /*----------------------------------------------------------------------------*/
252 /*----------------------------------------------------------------------------*/
253 
254 static inline bool
256 {
257  if (flag & CS_CDO_BC_NEUMANN)
258  return true;
259  else if (flag & CS_CDO_BC_HMG_NEUMANN)
260  return true;
261  else
262  return false;
263 }
264 
265 /*----------------------------------------------------------------------------*/
273 /*----------------------------------------------------------------------------*/
274 
275 static inline bool
277 {
278  if (flag & CS_CDO_BC_SLIDING)
279  return true;
280  else
281  return false;
282 }
283 
284 /*----------------------------------------------------------------------------*/
299 /*----------------------------------------------------------------------------*/
300 
303  bool is_steady,
304  int dim,
305  int n_defs,
306  cs_xdef_t **defs,
307  cs_lnum_t n_b_faces);
308 
309 /*----------------------------------------------------------------------------*/
317 /*----------------------------------------------------------------------------*/
318 
321 
322 /*----------------------------------------------------------------------------*/
323 
325 
326 #endif /* __CS_CDO_BC_H__ */
CS_PARAM_BC_HMG_DIRICHLET
Definition: cs_param.h:304
cs_cdo_bc_face_t::nhmg_dir_ids
cs_lnum_t * nhmg_dir_ids
Definition: cs_cdo_bc.h:108
CS_PARAM_BC_DIRICHLET
Definition: cs_param.h:305
cs_cdo_bc_face_t::n_nhmg_neu_faces
cs_lnum_t n_nhmg_neu_faces
Definition: cs_cdo_bc.h:113
cs_cdo_bc_face_t::hmg_neu_ids
cs_lnum_t * hmg_neu_ids
Definition: cs_cdo_bc.h:112
cs_xdef_t
Structure storing medata for defining a quantity in a very flexible way.
Definition: cs_xdef.h:126
CS_CDO_BC_HMG_DIRICHLET
#define CS_CDO_BC_HMG_DIRICHLET
Definition: cs_cdo_bc.h:66
CS_CDO_BC_ROBIN
#define CS_CDO_BC_ROBIN
Definition: cs_cdo_bc.h:68
cs_cdo_bc_face_t::n_b_faces
cs_lnum_t n_b_faces
Definition: cs_cdo_bc.h:90
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
CS_CDO_BC_DIRICHLET
#define CS_CDO_BC_DIRICHLET
Definition: cs_cdo_bc.h:64
cs_cdo_bc_face_t::robin_ids
cs_lnum_t * robin_ids
Definition: cs_cdo_bc.h:118
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_cdo_quantities.h
bft_error
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.c:193
cs_cdo_bc_face_define
cs_cdo_bc_face_t * cs_cdo_bc_face_define(cs_param_bc_type_t default_bc, bool is_steady, int dim, int n_defs, cs_xdef_t **defs, cs_lnum_t n_b_faces)
Define the structure which translates the BC definitions from the user viewpoint into a ready-to-use ...
Definition: cs_cdo_bc.c:143
cs_xdef.h
CS_PARAM_BC_NEUMANN
Definition: cs_param.h:307
cs_cdo_bc_is_neumann
static bool cs_cdo_bc_is_neumann(cs_flag_t flag)
Check if a flag is associated to a Neumann BC (homogeneous or not)
Definition: cs_cdo_bc.h:255
cs_cdo_bc_get_flag
static cs_flag_t cs_cdo_bc_get_flag(cs_param_bc_type_t bc_type)
Convert a cs_param_bc_type_t into a flag (enable multiple type for a same entity as required for vert...
Definition: cs_cdo_bc.h:191
cs_cdo_bc_face_t::is_steady
bool is_steady
Definition: cs_cdo_bc.h:88
cs_cdo_bc_face_t
Definition: cs_cdo_bc.h:86
cs_cdo_bc_face_t::n_hmg_neu_faces
cs_lnum_t n_hmg_neu_faces
Definition: cs_cdo_bc.h:111
cs_cdo_bc_face_t::sliding_ids
cs_lnum_t * sliding_ids
Definition: cs_cdo_bc.h:122
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_cdo_bc_face_t::n_nhmg_dir_faces
cs_lnum_t n_nhmg_dir_faces
Definition: cs_cdo_bc.h:107
cs_cdo_bc_face_t::nhmg_neu_ids
cs_lnum_t * nhmg_neu_ids
Definition: cs_cdo_bc.h:114
cs_time_step.h
cs_cdo_bc_is_dirichlet
static bool cs_cdo_bc_is_dirichlet(cs_flag_t flag)
Check if a flag is associated to a Dirichlet BC (homogeneous or not)
Definition: cs_cdo_bc.h:234
CS_CDO_BC_NEUMANN
#define CS_CDO_BC_NEUMANN
Definition: cs_cdo_bc.h:60
cs_cdo_bc_face_t::hmg_dir_ids
cs_lnum_t * hmg_dir_ids
Definition: cs_cdo_bc.h:106
cs_cdo_bc_face_t::n_sliding_faces
cs_lnum_t n_sliding_faces
Definition: cs_cdo_bc.h:121
CS_PARAM_BC_ROBIN
Definition: cs_param.h:308
cs_cdo_bc_face_t::n_robin_faces
cs_lnum_t n_robin_faces
Definition: cs_cdo_bc.h:117
cs_flag_t
unsigned short int cs_flag_t
Definition: cs_defs.h:304
CS_PARAM_BC_HMG_NEUMANN
Definition: cs_param.h:306
CS_PARAM_BC_SLIDING
Definition: cs_param.h:309
cs_cdo_bc_face_t::def_ids
short int * def_ids
Definition: cs_cdo_bc.h:97
cs_cdo_bc_is_sliding
static bool cs_cdo_bc_is_sliding(cs_flag_t flag)
Check if a flag is associated to a sliding boundary.
Definition: cs_cdo_bc.h:276
cs_cdo_bc_free
cs_cdo_bc_face_t * cs_cdo_bc_free(cs_cdo_bc_face_t *face_bc)
Free a cs_cdo_bc_face_t structure.
Definition: cs_cdo_bc.c:315
cs_cdo_bc_face_t::flag
cs_flag_t * flag
Definition: cs_cdo_bc.h:93
CS_CDO_BC_SLIDING
#define CS_CDO_BC_SLIDING
Definition: cs_cdo_bc.h:70
cs_param_bc_type_t
cs_param_bc_type_t
Definition: cs_param.h:302
cs_param.h
cs_base.h
CS_CDO_BC_HMG_NEUMANN
#define CS_CDO_BC_HMG_NEUMANN
Definition: cs_cdo_bc.h:62
cs_cdo_bc_get_desc
static void cs_cdo_bc_get_desc(cs_flag_t bc_flag, char *desc)
Convert a flag into a description.
Definition: cs_cdo_bc.h:144
cs_cdo_bc_face_t::n_hmg_dir_faces
cs_lnum_t n_hmg_dir_faces
Definition: cs_cdo_bc.h:105