programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cs_cdo.h
Go to the documentation of this file.
1 #ifndef __CS_CDO_H__
2 #define __CS_CDO_H__
3 
4 /*============================================================================
5  * General functions or variables for the INNOV module
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2017 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_defs.h"
34 #include "cs_math.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
39 
40 /*============================================================================
41  * Macro definitions
42  *============================================================================*/
43 
44 /* Flag related to the activation (or not) of the CDO schemes */
45 #define CS_CDO_OFF -1 // CDO schemes are not used (no activation)
46 #define CS_CDO_WITH_FV 0 // CDO schemes are used as well as finite volume
47 #define CS_CDO_ONLY 1 // CDO schemes are exclusively used
48 
49 /* Flag associated to each cell */
50 #define CS_FLAG_BOUNDARY (1 << 0) // 1: cell with at least one border face
51 
52 /* Flag related to the way a CDO system is built */
53 #define CS_FLAG_SYS_HLOC_CONF (1 << 0) // 1: build conforming Hodge op.
54 #define CS_FLAG_SYS_SYM (1 << 1) // 2: system matrix is symmetric
55 #define CS_FLAG_SYS_TIME_DIAG (1 << 2) // 4: lumping/diag by construction
56 #define CS_FLAG_SYS_SOURCES_HLOC (1 << 3) // 8: source terms need a hodge op.
57 #define CS_FLAG_SYS_DEBUG (1 << 4) // 16: activate debug mode
58 
59 /* Flags use to identify the nature/status of an object (variable, property) */
60 #define CS_FLAG_STATE_UNIFORM (1 << 0) // 1: uniform (in space)
61 #define CS_FLAG_STATE_CELLWISE (1 << 1) // 2: cellwise uniform
62 #define CS_FLAG_STATE_FACEWISE (1 << 2) // 4: uniform on each face
63 #define CS_FLAG_STATE_STEADY (1 << 3) // 8: steady
64 #define CS_FLAG_STATE_POTENTIAL (1 << 4) // 16: potential
65 #define CS_FLAG_STATE_CIRCULATION (1 << 5) // 32: circulation
66 #define CS_FLAG_STATE_FLUX (1 << 6) // 64: flux
67 #define CS_FLAG_STATE_DENSITY (1 << 7) // 128: density
68 #define CS_FLAG_STATE_OWNER (1 << 8) // 256: owner
69 
70 /* Flags use to identify where is located a variable and how to access to
71  its values */
72 #define CS_FLAG_PRIMAL (1 << 0) // 1: on primal mesh
73 #define CS_FLAG_DUAL (1 << 1) // 2: on dual mesh
74 #define CS_FLAG_VERTEX (1 << 2) // 4: on vertices
75 #define CS_FLAG_EDGE (1 << 3) // 8: on edges
76 #define CS_FLAG_FACE (1 << 4) // 16: on faces
77 #define CS_FLAG_CELL (1 << 5) // 32: on cells
78 #define CS_FLAG_BORDER (1 << 6) // 64: located on the boundary
79 #define CS_FLAG_SCALAR (1 << 7) // 128: scalar-valued (stride = 1)
80 #define CS_FLAG_VECTOR (1 << 8) // 256: vector-valued (stride = 3)
81 #define CS_FLAG_TENSOR (1 << 9) // 512: tensor-valued (stride = 9)
82 #define CS_FLAG_BY_CELL (1 << 10) // 1024: by cell (c2e, c2f, c2v)
83 #define CS_FLAG_FULL_LOC (1 << 11) // 2048: defined on the whole location
84 
85 /* Flags use to identify the type of numerical schemes requested for computing
86  the different equations attached to the computational domain. If flag is
87  activated, then at least one equation solved is discretized using thiq kind
88  of numerical scheme. */
89 #define CS_SCHEME_FLAG_CDOVB (1 << 0) // 1: CDO vertex-based scheme
90 #define CS_SCHEME_FLAG_CDOVCB (1 << 1) // 2: CDO vertex+cell-based scheme
91 #define CS_SCHEME_FLAG_CDOFB (1 << 2) // 4: CDO face-based scheme
92 #define CS_SCHEME_FLAG_HHO (1 << 3) // 8: Hybrid-High Order scheme
93 #define CS_SCHEME_FLAG_SCALAR (1 << 4) // 16: scheme for scalar eq.
94 #define CS_SCHEME_FLAG_VECTOR (1 << 5) // 32: scheme for a vector eq.
95 #define CS_SCHEME_FLAG_POLY0 (1 << 6) // 64: lowest-order scheme
96 #define CS_SCHEME_FLAG_POLY1 (1 << 7) //128: approx. with linear polynomials
97 #define CS_SCHEME_FLAG_POLY2 (1 << 8) //256: approx. with quadratic poly.
98 
99 /* Size of the buffer used to collect global ids for rows and columns
100  when assembling the values in the global matrix from the local cellwise
101  matrices */
102 #define CS_CDO_ASSEMBLE_BUF_SIZE 99
103 
104 /* The following limitation only results from an optimization in the size of
105  the bit mask (can be changed if needed by changing the definition of
106  the type cs_mask_t) */
107 #define CS_CDO_N_MAX_REACTIONS 8 // Max number of reaction terms in an equation
108 
109 /* Specifications for open mp loops */
110 #define CS_CDO_OMP_CHUNK_SIZE 128
111 #define CS_CDO_OMP_SCHEDULE schedule(static, CS_CDO_OMP_CHUNK_SIZE)
112 
113 /* Number of DoFs on faces and cells according to the polynomial space */
114 #define CS_N_FACE_DOFS_0TH 1
115 #define CS_N_FACE_DOFS_1ST 3
116 #define CS_N_FACE_DOFS_2ND 6
117 
118 #define CS_N_CELL_DOFS_0TH 1
119 #define CS_N_CELL_DOFS_1ST 4
120 #define CS_N_CELL_DOFS_2ND 10
121 
122 /*============================================================================
123  * Type definitions
124  *============================================================================*/
125 
126 typedef unsigned char cs_mask_t;
127 
128 /* Vector-valued quantity stored using its measure (i.e. length) and
129  its direction given by a unitary vector */
130 typedef struct {
131 
132  double meas;
133  double unitv[3];
134 
135 } cs_nvec3_t;
136 
137 /* Type of numerical scheme for the discretization in space */
138 typedef enum {
139 
140  CS_SPACE_SCHEME_CDOVB, /* CDO scheme with vertex-based positionning */
141  CS_SPACE_SCHEME_CDOVCB, /* CDO scheme with vertex+cell-based positionning */
142  CS_SPACE_SCHEME_CDOFB, /* CDO cell-based scheme with hybridization */
143  CS_SPACE_SCHEME_HHO_P0, /* Hybrid High Order scheme; P0 approx. of gradient */
144  CS_SPACE_SCHEME_HHO_P1, /* Hybrid High Order scheme; P1 approx. of gradient */
145  CS_SPACE_SCHEME_HHO_P2, /* Hybrid High Order scheme; P2 approx. of gradient */
146 
148 
150 
151 /*----------------------------------------------------------------------------*/
166 /*----------------------------------------------------------------------------*/
167 
168 typedef void
170  cs_lnum_t n_elts,
171  const cs_lnum_t *elt_ids,
172  const cs_real_t *coords,
173  bool compact,
174  void *input,
175  cs_real_t *retval);
176 
177 /*----------------------------------------------------------------------------*/
189 /*----------------------------------------------------------------------------*/
190 
191 typedef cs_real_t
192 (cs_timestep_func_t) (int time_iter,
193  double time,
194  void *input);
195 
196 /*============================================================================
197  * Global variables
198  *============================================================================*/
199 
200 /* Activation of the CDO/HHO module */
201 extern int cs_cdo_activation_mode;
202 
203 /* Separation lines: long, medium, short */
204 extern const char lsepline[80];
205 extern const char msepline[60];
206 extern const char ssepline[40];
207 
208 /* Default locations */
209 extern const cs_flag_t cs_cdo_primal_vtx;
210 extern const cs_flag_t cs_cdo_primal_face;
211 extern const cs_flag_t cs_cdo_primal_cell;
212 extern const cs_flag_t cs_cdo_dual_vtx;
213 extern const cs_flag_t cs_cdo_dual_face;
214 extern const cs_flag_t cs_cdo_dual_cell;
215 extern const cs_flag_t cs_cdo_dual_face_byc;
216 
217 /*============================================================================
218  * Static inline function prototypes
219  *============================================================================*/
220 
221 /*----------------------------------------------------------------------------*/
232 /*----------------------------------------------------------------------------*/
233 
234 static inline bool
235 cs_test_flag(cs_flag_t flag_to_check,
236  cs_flag_t reference)
237 {
238  if ((flag_to_check & reference) == reference)
239  return true;
240  else
241  return false;
242 }
243 
244 /*============================================================================
245  * Public function prototypes
246  *============================================================================*/
247 
248 /*----------------------------------------------------------------------------*/
256 /*----------------------------------------------------------------------------*/
257 
258 static inline const char *
259 cs_base_strtf(bool boolean)
260 {
261  if (boolean)
262  return "true";
263  else
264  return "false";
265 }
266 
267 /*----------------------------------------------------------------------------*/
274 /*----------------------------------------------------------------------------*/
275 
276 static inline void
278  cs_nvec3_t *qv)
279 {
280  cs_real_t magnitude = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
281 
282  qv->meas = magnitude;
283  if (fabs(magnitude) > cs_math_zero_threshold) {
284 
285  const cs_real_t inv = 1/magnitude;
286  qv->unitv[0] = inv * v[0];
287  qv->unitv[1] = inv * v[1];
288  qv->unitv[2] = inv * v[2];
289 
290  }
291  else
292  qv->unitv[0] = qv->unitv[1] = qv->unitv[2] = 0;
293 
294 }
295 
296 #if defined(DEBUG) && !defined(NDEBUG)
297 /*----------------------------------------------------------------------------*/
306 /*----------------------------------------------------------------------------*/
307 
308 void
309 cs_dump_array_to_listing(const char *header,
310  const cs_lnum_t size,
311  const cs_real_t array[],
312  int n_cols);
313 
314 /*----------------------------------------------------------------------------*/
323 /*----------------------------------------------------------------------------*/
324 
325 void
326 cs_dump_integer_to_listing(const char *header,
327  const cs_lnum_t size,
328  const cs_lnum_t array[],
329  int n_cols);
330 #endif
331 
332 /*----------------------------------------------------------------------------*/
333 
335 
336 #endif /* __CS_CDO_H__ */
const cs_flag_t cs_cdo_dual_face_byc
Definition: cs_cdo.c:82
static void cs_nvec3(const cs_real_3_t v, cs_nvec3_t *qv)
Define a cs_nvec3_t structure from a cs_real_3_t.
Definition: cs_cdo.h:277
Definition: cs_cdo.h:147
#define BEGIN_C_DECLS
Definition: cs_defs.h:453
const cs_flag_t cs_cdo_primal_face
Definition: cs_cdo.c:77
unsigned char cs_mask_t
Definition: cs_cdo.h:126
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_cdo.h:130
static bool cs_test_flag(cs_flag_t flag_to_check, cs_flag_t reference)
Check if a two flag share the same pattern Return true if the flag to check has at least the pattern ...
Definition: cs_cdo.h:235
cs_space_scheme_t
Definition: cs_cdo.h:138
Definition: cs_cdo.h:141
double meas
Definition: cs_cdo.h:132
const char lsepline[80]
Definition: cs_cdo.c:68
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
const cs_flag_t cs_cdo_primal_cell
Definition: cs_cdo.c:78
Definition: cs_cdo.h:144
const cs_real_t cs_math_zero_threshold
const cs_flag_t cs_cdo_dual_cell
Definition: cs_cdo.c:81
double unitv[3]
Definition: cs_cdo.h:133
void( cs_analytic_func_t)(cs_real_t time, cs_lnum_t n_elts, const cs_lnum_t *elt_ids, const cs_real_t *coords, bool compact, void *input, cs_real_t *retval)
Generic function pointer for an analytic function elt_ids is optional. If not NULL, it enables to access in coords at the right location and the same thing to fill retval if compact is set to false.
Definition: cs_cdo.h:169
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
static const char * cs_base_strtf(bool boolean)
Return a string "true" or "false" according to the boolean.
Definition: cs_cdo.h:259
const cs_flag_t cs_cdo_primal_vtx
Definition: cs_cdo.c:76
#define END_C_DECLS
Definition: cs_defs.h:454
const cs_flag_t cs_cdo_dual_face
Definition: cs_cdo.c:80
unsigned short int cs_flag_t
Definition: cs_defs.h:299
int cs_cdo_activation_mode
Definition: cs_cdo.c:65
cs_real_t( cs_timestep_func_t)(int time_iter, double time, void *input)
Function which defines the time step according to the number of iteration already done...
Definition: cs_cdo.h:192
Definition: cs_cdo.h:142
const char ssepline[40]
Definition: cs_cdo.c:72
Definition: cs_cdo.h:145
Definition: cs_cdo.h:140
const char msepline[60]
Definition: cs_cdo.c:70
Definition: cs_cdo.h:143
const cs_flag_t cs_cdo_dual_vtx
Definition: cs_cdo.c:79