1 #ifndef __CS_FLAG_H__
2 #define __CS_FLAG_H__
3 
4 /*============================================================================
5  * Manage the definition/setting of a computation
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 
30 /*----------------------------------------------------------------------------
31  *  Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_defs.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
38 BEGIN_C_DECLS
39 
40 /*============================================================================
41  * Macro definitions
42  *============================================================================*/
43 
44 /*!
45  * @name Flags specifying the type of cell
46  * @{
47  *
48  * \def CS_FLAG_BOUNDARY_CELL_BY_FACE
49  * \brief (= 1) boundary cell with at least one border face
50  *
51  * \def CS_FLAG_BOUNDARY_CELL_BY_VERTEX
52  * \brief (= 2) boundary cell with at least one border vertex
53  *
54  * \def CS_FLAG_BOUNDARY_CELL_BY_EDGE
55  * \brief (= 4) boundary cell with at least one border edge
56  *
57  * \def CS_FLAG_SOLID_CELL
58  * \brief (= 8) cell attached to a solid zone during the calculation
59  *
60  */
61 
62 #define CS_FLAG_BOUNDARY_CELL_BY_FACE     (1 << 0)
63 #define CS_FLAG_BOUNDARY_CELL_BY_VERTEX   (1 << 1)
64 #define CS_FLAG_BOUNDARY_CELL_BY_EDGE     (1 << 2)
65 #define CS_FLAG_SOLID_CELL                (1 << 3)
66 
67 /*!
68  * @}
69  * @name Flag related to the way a CDO system is built
70  * @{
71  */
72 
73 #define CS_FLAG_SYS_MASS_MATRIX  (1 << 0) /*!<  1: build a mass matrix */
74 #define CS_FLAG_SYS_SYM          (1 << 1) /*!<  2: system matrix is symmetric */
75 #define CS_FLAG_SYS_TIME_DIAG    (1 << 2) /*!<  4: lump the time term */
76 #define CS_FLAG_SYS_REAC_DIAG    (1 << 3) /*!<  8: lump the reaction term */
77 #define CS_FLAG_SYS_SOURCES_HLOC (1 << 4) /*!< 16: Hodge op. for source terms */
78 #define CS_FLAG_SYS_VECTOR       (1 << 5) /*!< 32: vector-valued variable */
79 
80 /*!
81  * @}
82  * @name Flags use to identify the nature/status of an object
83  * Apply this flag on a variable, a property or an advection field
84  * @{
85  */
86 
87 #define CS_FLAG_STATE_UNIFORM     (1 << 0) /*!<   1: uniform (in space) */
88 #define CS_FLAG_STATE_CELLWISE    (1 << 1) /*!<   2: cellwise uniform */
89 #define CS_FLAG_STATE_FACEWISE    (1 << 2) /*!<   4: uniform on each face */
90 #define CS_FLAG_STATE_STEADY      (1 << 3) /*!<   8: steady */
91 #define CS_FLAG_STATE_POTENTIAL   (1 << 4) /*!<  16: potential */
92 #define CS_FLAG_STATE_CIRCULATION (1 << 5) /*!<  32: circulation */
93 #define CS_FLAG_STATE_FLUX        (1 << 6) /*!<  64: flux */
94 #define CS_FLAG_STATE_DENSITY     (1 << 7) /*!< 128: density */
95 #define CS_FLAG_STATE_OWNER       (1 << 8) /*!< 256: owner */
96 
97 /*!
98  * @}
99  * @name Flags use to identify metadata for a quantity
100  * where is located this quantity and how to access to its values
101  * @{
102  */
103 
104 #define CS_FLAG_FULL_LOC  (1 <<  0) /*!<    1: defined on the whole location */
105 #define CS_FLAG_SCALAR    (1 <<  1) /*!<    2: scalar-valued (stride = 1) */
106 #define CS_FLAG_VECTOR    (1 <<  2) /*!<    4: vector-valued (stride = 3) */
107 #define CS_FLAG_TENSOR    (1 <<  3) /*!<    8: tensor-valued (stride = 9) */
108 #define CS_FLAG_VERTEX    (1 <<  4) /*!<   16: on vertices */
109 #define CS_FLAG_EDGE      (1 <<  5) /*!<   32: on edges */
110 #define CS_FLAG_FACE      (1 <<  6) /*!<   64: on faces */
111 #define CS_FLAG_CELL      (1 <<  7) /*!<  128: on cells */
112 #define CS_FLAG_PRIMAL    (1 <<  8) /*!<  256: on primal mesh */
113 #define CS_FLAG_DUAL      (1 <<  9) /*!<  512: on dual mesh */
114 #define CS_FLAG_BORDER    (1 << 10) /*!< 1024: located on the boundary */
115 #define CS_FLAG_BY_CELL   (1 << 11) /*!< 2048: by cell (c2e, c2f, c2v) */
116 #define CS_FLAG_BY_FACE   (1 << 12) /*!< 4096: by face (bf2v) */
117 
118 /*!
119  * @}
120  * @name Flags use to identify the type of equations requested.
121 
122  * There exists one flag for each type of space discretization.
123  * If this flag is activated, then at least one equation or system of this
124  * kind is discretized with this space discretization scheme.
125  * @{
126  */
127 
128 #define CS_FLAG_SCHEME_SCALAR  (1 << 0) /*!<  1: scheme for scalar eq. */
129 #define CS_FLAG_SCHEME_VECTOR  (1 << 1) /*!<  2: scheme for a vector eq. */
130 #define CS_FLAG_SCHEME_NAVSTO  (1 << 2) /*!<  4: Navier-Stokes system */
131 #define CS_FLAG_SCHEME_POLY0   (1 << 3) /*!<  8: lowest-order scheme */
132 #define CS_FLAG_SCHEME_POLY1   (1 << 4) /*!< 16: Linear gradient approx. */
133 #define CS_FLAG_SCHEME_POLY2   (1 << 5) /*!< 32: Quadratic gradient approx. */
134 
135 /*!
136  * @}
137  */
138 
139 /*============================================================================
140  * Type definitions
141  *============================================================================*/
142 
143 typedef unsigned char       cs_mask_t;   /* Elementary flag */
144 
145 /*============================================================================
146  * Global variables
147  *============================================================================*/
148 
149 /* Default locations */
150 extern const cs_flag_t  cs_flag_primal_vtx;
151 extern const cs_flag_t  cs_flag_primal_edge;
152 extern const cs_flag_t  cs_flag_primal_face;
153 extern const cs_flag_t  cs_flag_primal_cell;
154 extern const cs_flag_t  cs_flag_vertex; /* equal to cs_flag_primal_vtx */
155 extern const cs_flag_t  cs_flag_cell;   /* equal to cs_flag_primal_cell */
156 extern const cs_flag_t  cs_flag_boundary_face;
157 
158 extern const cs_flag_t  cs_flag_dual_vtx;
159 extern const cs_flag_t  cs_flag_dual_face;
160 extern const cs_flag_t  cs_flag_dual_cell;
161 extern const cs_flag_t  cs_flag_dual_face_byc;
162 
163 /* Part of dual cell closure belonging to a boundary primal face */
164 extern const cs_flag_t  cs_flag_dual_closure_byf;
165 
166 /* According to the extended flag defined below one can identify which set of
167  * quantities or connectivities have to be built on-the-fly and stored in a
168  * local structure possibly owned by each thread and with a cellwise scope */
169 
170 typedef unsigned int  cs_eflag_t;
171 
172 /* Store predefined flags */
173 extern const cs_eflag_t  cs_flag_need_v;
174 extern const cs_eflag_t  cs_flag_need_e;
175 extern const cs_eflag_t  cs_flag_need_f;
176 extern const cs_eflag_t  cs_flag_need_fe;
177 extern const cs_eflag_t  cs_flag_need_ef;
178 extern const cs_eflag_t  cs_flag_need_peq;
179 extern const cs_eflag_t  cs_flag_need_dfq;
180 extern const cs_eflag_t  cs_flag_need_pfq;
181 extern const cs_eflag_t  cs_flag_need_deq;
182 extern const cs_eflag_t  cs_flag_need_pfc;
183 
184 typedef enum {
185 
186   /* Compute simple and cellwise information for vertices */
187   CS_FLAG_COMP_PV      = 1 << 0,   /* = 1 */
188 
189   /* Compute cellwise quantities for vertices */
190   CS_FLAG_COMP_PVQ     = 1 << 1,   /* = 2 */
191 
192   /* Compute simple and cellwise information for edges */
193   CS_FLAG_COMP_PE      = 1 << 2,   /* = 4 */
194 
195   /* Compute cellwise quantities for edges */
196   CS_FLAG_COMP_PEQ     = 1 << 3,   /* = 8 */
197 
198   /* Compute cellwise quantities for dual faces (associated to edges) */
199   CS_FLAG_COMP_DFQ     = 1 << 4,   /* = 16 */
200 
201   /* Compute simple and cellwise information for faces */
202   CS_FLAG_COMP_PF      = 1 << 5,   /* = 32 */
203 
204   /* Compute cellwise quantities for faces */
205   CS_FLAG_COMP_PFQ     = 1 << 6,   /* = 64 */
206 
207   /* Compute cellwise quantities for dual edges (associated to faces) */
208   CS_FLAG_COMP_DEQ     = 1 << 7,   /* = 128 */
209 
210   /* Compute the cellwise connectivity edge to vertices */
211   CS_FLAG_COMP_EV      = 1 << 8,   /* = 256 */
212 
213   /* Compute cellwise connectivity face to edges */
214   CS_FLAG_COMP_FE      = 1 << 9,   /* = 512 */
215 
216   /* Compute cellwise quantities associated to the couple (face, edge) */
217   CS_FLAG_COMP_FEQ     = 1 << 10,  /* = 1024 */
218 
219   /* Compute cellwise connectivity face to vertices */
220   CS_FLAG_COMP_FV      = 1 << 11,  /* = 2048 */
221 
222   /* Compute cellwise connectivity edge to faces */
223   CS_FLAG_COMP_EF      = 1 << 12,  /* = 4096 */
224 
225   /* Compute elemental portion of dual faces associated to the couple
226      (edge, face) */
227   CS_FLAG_COMP_SEF     = 1 << 13,  /* = 8192 */
228 
229   /* Compute cellwise quantities related to the height of the pyramid with
230      basis spanned by a face and with apex the cell center */
231   CS_FLAG_COMP_HFQ     = 1 << 14,  /* = 16384 */
232 
233   /* Compute cellwise orientation of oriented edges belonging to a face */
234   CS_FLAG_COMP_FES     = 1 << 15,  /* = 32768 */
235 
236   /* Compute cellwise quantities related to the volume of the pyramid with
237      basis spanned by a face and with apex the cell center */
238   CS_FLAG_COMP_PFC     = 1 << 16,  /* = 65536 */
239 
240   /* Compute cellwise quantities related to the volume surrounding an edge */
241   CS_FLAG_COMP_PEC     = 1 << 17,  /* = 131072 */
242 
243   /* Compute cellwise diameters */
244   CS_FLAG_COMP_DIAM    = 1 << 18,  /* = 262144 */
245 
246 } cs_flag_comp_bits_t;
247 
248 /*============================================================================
249  * Public function prototypes
250  *============================================================================*/
251 
252 /*----------------------------------------------------------------------------*/
253 /*!
254  * \brief  Check if a two flag share the same pattern
255  *         Return true if the flag to check has at least the pattern of the
256  *         reference flag.
257  *
258  * \param[in]  flag_to_check   flag corresponding to the location to check
259  * \param[in]  reference       flag corresponding to the referenced support
260  *
261  * \return true or false
262  */
263 /*----------------------------------------------------------------------------*/
264 
265 static inline bool
cs_flag_test(cs_flag_t flag_to_check,cs_flag_t reference)266 cs_flag_test(cs_flag_t    flag_to_check,
267              cs_flag_t    reference)
268 {
269   if ((flag_to_check & reference) == reference)
270     return true;
271   else
272     return false;
273 }
274 
275 /*----------------------------------------------------------------------------*/
276 /*!
277  * \brief  Check if a flag has in common at least one of the given masks
278  *         Return true if the test is satisfied.
279  *
280  * \param[in]  flag_to_check   flag corresponding to the location to check
281  * \param[in]  n_masks         number of masks to check
282  * \param[in]  masks           array of masks
283  *
284  * \return true or false
285  */
286 /*----------------------------------------------------------------------------*/
287 
288 static inline bool
cs_flag_at_least(cs_flag_t flag_to_check,int n_masks,cs_flag_t masks[])289 cs_flag_at_least(cs_flag_t    flag_to_check,
290                  int          n_masks,
291                  cs_flag_t    masks[])
292 {
293   for (int i = 0; i < n_masks; i++)
294     if ((flag_to_check & masks[i]) == masks[i])
295       return true;
296   return false;
297 }
298 
299 /*----------------------------------------------------------------------------*/
300 /*!
301  * \brief  Check if a two compute flag share the same pattern
302  *         Return true if the computed flag to check has at least the pattern
303  *         of the reference compute flag.
304  *         Case of extended flags.
305  *
306  * \param[in]  flag_to_check   flag corresponding to the location to check
307  * \param[in]  reference       flag corresponding to the referenced support
308  *
309  * \return true or false
310  */
311 /*----------------------------------------------------------------------------*/
312 
313 static inline bool
cs_eflag_test(cs_eflag_t flag_to_check,cs_eflag_t reference)314 cs_eflag_test(cs_eflag_t    flag_to_check,
315               cs_eflag_t    reference)
316 {
317   if ((flag_to_check & reference) == reference)
318     return true;
319   else
320     return false;
321 }
322 
323 /*----------------------------------------------------------------------------*/
324 /*!
325  * \brief  Retrieve the label associated to a location flag
326  *
327  * \return a string
328  */
329 /*----------------------------------------------------------------------------*/
330 
331 const char *
332 cs_flag_str_location(cs_flag_t  loc);
333 
334 /*----------------------------------------------------------------------------*/
335 
336 END_C_DECLS
337 
338 #endif /* __CS_FLAG_H__ */
339