programmer's documentation
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-2018 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 
35 /*----------------------------------------------------------------------------*/
36 
38 
39 /*============================================================================
40  * Macro definitions
41  *============================================================================*/
42 
43 /* Flag associated to each cell */
44 #define CS_FLAG_BOUNDARY (1 << 0) // 1: cell with at least one border face
45 
46 /* Flag related to the way a CDO system is built */
47 #define CS_FLAG_SYS_DIFFUSION (1 << 0) // 1: Build the diffusion term
48 #define CS_FLAG_SYS_ADVECTION (1 << 1) // 2: Build the advection term
49 #define CS_FLAG_SYS_REACTION (1 << 2) // 4: Build the reaction term(s)
50 #define CS_FLAG_SYS_TIME (1 << 3) // 8: Build the unsteady term
51 #define CS_FLAG_SYS_SOURCETERM (1 << 4) // 16: Build the source term(s)
52 #define CS_FLAG_SYS_HLOC_CONF (1 << 5) // 32: build conforming Hodge op.
53 #define CS_FLAG_SYS_SYM (1 << 6) // 64: system matrix is symmetric
54 #define CS_FLAG_SYS_TIME_DIAG (1 << 7) // 128: lumping/diag by construction
55 #define CS_FLAG_SYS_SOURCES_HLOC (1 << 8) // 256: source terms need a hodge op.
56 #define CS_FLAG_SYS_DEBUG (1 << 9) // 512: activate debug mode
57 
58 /* Flags use to identify the nature/status of an object (variable, property) */
59 #define CS_FLAG_STATE_UNIFORM (1 << 0) // 1: uniform (in space)
60 #define CS_FLAG_STATE_CELLWISE (1 << 1) // 2: cellwise uniform
61 #define CS_FLAG_STATE_UNSTEADY (1 << 2) // 4: unsteady
62 #define CS_FLAG_STATE_POTENTIAL (1 << 3) // 8: potential
63 #define CS_FLAG_STATE_CIRCULATION (1 << 4) // 16: circulation
64 #define CS_FLAG_STATE_FLUX (1 << 5) // 32: flux
65 #define CS_FLAG_STATE_DENSITY (1 << 6) // 64: density
66 #define CS_FLAG_STATE_OWNER (1 << 7) // 128: owner
67 
68 /* Flags use to identify where is located a variable and how to access to
69  its values */
70 #define CS_FLAG_PRIMAL (1 << 0) // 1: on primal mesh
71 #define CS_FLAG_DUAL (1 << 1) // 2: on dual mesh
72 #define CS_FLAG_VERTEX (1 << 2) // 4: on vertices
73 #define CS_FLAG_EDGE (1 << 3) // 8: on edges
74 #define CS_FLAG_FACE (1 << 4) // 16: on faces
75 #define CS_FLAG_CELL (1 << 5) // 32: on cells
76 #define CS_FLAG_BORDER (1 << 6) // 64: located on the boundary
77 #define CS_FLAG_SCALAR (1 << 7) // 128: scalar-valued (stride = 1)
78 #define CS_FLAG_VECTOR (1 << 8) // 256: vector-valued (stride = 3)
79 #define CS_FLAG_TENSOR (1 << 9) // 512: tensor-valued (stride = 9)
80 #define CS_FLAG_BY_CELL (1 << 10) // 1024: by cell (c2e, c2f, c2v)
81 #define CS_FLAG_FULL_LOC (1 << 11) // 2048: defined on the whole location
82 
83 /* Flags use to identify the type of numerical schemes requested for computing
84  the different equations attached to the computational domain. If flag is
85  activated, then at least one equation solved is discretized using thiq kind
86  of numerical scheme. */
87 #define CS_SCHEME_FLAG_CDOVB (1 << 0) // 1: CDO vertex-based scheme
88 #define CS_SCHEME_FLAG_CDOVCB (1 << 1) // 2: CDO vertex+cell-based scheme
89 #define CS_SCHEME_FLAG_CDOFB (1 << 2) // 4: CDO face-based scheme
90 #define CS_SCHEME_FLAG_HHO (1 << 3) // 8: Hybrid-High Order scheme
91 #define CS_SCHEME_FLAG_SCALAR (1 << 4) // 16: scheme for scalar eq.
92 #define CS_SCHEME_FLAG_VECTOR (1 << 5) // 32: scheme for a vector eq.
93 #define CS_SCHEME_FLAG_POLY0 (1 << 6) // 64: lowest-order scheme
94 #define CS_SCHEME_FLAG_POLY1 (1 << 7) //128: approx. with linear polynomials
95 #define CS_SCHEME_FLAG_POLY2 (1 << 8) //256: approx. with quadratic poly.
96 
97 /* Size of the buffer used to collect global ids for rows and columns
98  when assembling the values in the global matrix from the local cellwise
99  matrices */
100 #define CS_CDO_ASSEMBLE_BUF_SIZE 96
101 
102 /* The following limitation only results from an optimization in the size of
103  the bit mask (can be changed if needed by changing the definition of
104  the type cs_mask_t) */
105 #define CS_CDO_N_MAX_REACTIONS 8 // Max number of reaction terms in an equation
106 
107 /* Specifications for open mp loops */
108 #define CS_CDO_OMP_CHUNK_SIZE 128
109 #define CS_CDO_OMP_SCHEDULE schedule(static, CS_CDO_OMP_CHUNK_SIZE)
110 
111 /* Avoid issues with assert in some OpenMp contructs using gcc 9 */
112 #if defined(HAVE_OPENMP) && defined(__GNUC__)
113  #if __GNUC__ == 9
114  #define CS_CDO_OMP_ASSERT(e)
115  #else
116  #define CS_CDO_OMP_ASSERT(e) assert(e)
117  #endif
118 #else
119  #define CS_CDO_OMP_ASSERT(e) assert(e)
120 #endif
121 
122 /*============================================================================
123  * Type definitions
124  *============================================================================*/
125 
126 typedef unsigned char cs_mask_t;
127 
128 /* Description of an object (property, advection field, array..) using
129  mask of bits (i.e flag) */
130 
131 typedef struct {
132 
133  cs_flag_t location; /* where is defined this object */
134  cs_flag_t state; /* nature and additional information on this object */
135 
136 } cs_desc_t;
137 
138 /* Vector-valued quantity stored using its measure (i.e. length) and
139  its direction given by a unitary vector */
140 typedef struct {
141 
142  double meas;
143  double unitv[3];
144 
145 } cs_nvec3_t;
146 
147 /* Type of numerical scheme for the discretization in space */
148 typedef enum {
149 
150  CS_SPACE_SCHEME_CDOVB, /* CDO scheme with vertex-based positionning */
151  CS_SPACE_SCHEME_CDOVCB, /* CDO scheme with vertex+cell-based positionning */
152  CS_SPACE_SCHEME_CDOFB, /* CDO cell-based scheme with hybridization */
153  CS_SPACE_SCHEME_HHO, /* Hybrid High Order scheme (CDO-FB + high-order) */
155 
157 
158 /*----------------------------------------------------------------------------*/
167 /*----------------------------------------------------------------------------*/
168 
169 typedef void
171  cs_lnum_t n_points,
172  const cs_real_t *xyz,
173  cs_real_t *retval);
174 
175 /*----------------------------------------------------------------------------*/
185 /*----------------------------------------------------------------------------*/
186 
187 typedef cs_real_t
188 (cs_timestep_func_t) (int time_iter,
189  double time);
190 
191 /*----------------------------------------------------------------------------*/
204 /*----------------------------------------------------------------------------*/
205 
206 typedef void
208  const cs_lnum_t elt_ids[],
209  const cs_real_t var_values[],
210  const void *law_param,
211  cs_real_t res_array[]);
212 
213 /*----------------------------------------------------------------------------*/
227 /*----------------------------------------------------------------------------*/
228 
229 typedef void
231  const cs_lnum_t elt_ids[],
232  const double var1_values[],
233  const double var2_values[],
234  const void *law_param,
235  cs_real_t res_array[]);
236 
237 /*============================================================================
238  * Global variables
239  *============================================================================*/
240 
241 /* Activation of the CDO/HHO module */
242 extern _Bool cs_cdo_is_activated;
243 
244 /* Separation lines: long, medium, short */
245 extern const char lsepline[80];
246 extern const char msepline[60];
247 extern const char ssepline[40];
248 
249 /* Default locations */
250 extern const cs_flag_t cs_cdo_primal_vtx;
251 extern const cs_flag_t cs_cdo_primal_face;
252 extern const cs_flag_t cs_cdo_primal_cell;
253 extern const cs_flag_t cs_cdo_dual_vtx;
254 extern const cs_flag_t cs_cdo_dual_face;
255 extern const cs_flag_t cs_cdo_dual_cell;
256 extern const cs_flag_t cs_cdo_dual_face_byc;
257 
258 /*============================================================================
259  * Static inline function prototypes
260  *============================================================================*/
261 
262 /*----------------------------------------------------------------------------*/
273 /*----------------------------------------------------------------------------*/
274 
275 static inline bool
276 cs_test_flag(cs_flag_t flag_to_check,
277  cs_flag_t reference)
278 {
279  if ((flag_to_check & reference) == reference)
280  return true;
281  else
282  return false;
283 }
284 
285 /*============================================================================
286  * Public function prototypes
287  *============================================================================*/
288 
289 /*----------------------------------------------------------------------------*/
297 /*----------------------------------------------------------------------------*/
298 
299 const char *
300 cs_base_strtf(bool boolean);
301 
302 /*----------------------------------------------------------------------------*/
309 /*----------------------------------------------------------------------------*/
310 
311 void
312 cs_nvec3(const cs_real_3_t v,
313  cs_nvec3_t *qv);
314 
315 /*----------------------------------------------------------------------------*/
316 
318 
319 #endif /* __CS_CDO_H__ */
void() cs_analytic_func_t(cs_real_t time, cs_lnum_t n_points, const cs_real_t *xyz, cs_real_t *retval)
Generic analytic function.
Definition: cs_cdo.h:170
const cs_flag_t cs_cdo_dual_face_byc
Definition: cs_cdo.c:81
Definition: cs_cdo.h:131
Definition: cs_cdo.h:154
#define BEGIN_C_DECLS
Definition: cs_defs.h:451
const cs_flag_t cs_cdo_primal_face
Definition: cs_cdo.c:76
unsigned char cs_mask_t
Definition: cs_cdo.h:126
cs_real_t() cs_timestep_func_t(int time_iter, double time)
Simple function to define the time step according to the number of iteration already done...
Definition: cs_cdo.h:188
void() cs_onevar_law_func_t(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], const cs_real_t var_values[], const void *law_param, cs_real_t res_array[])
Compute the value of a quantity according to a law depending only on one variable. This law is described by a set of parameters stored in a structure. result = law(var_value)
Definition: cs_cdo.h:207
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_cdo.h:140
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:276
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
cs_space_scheme_t
Definition: cs_cdo.h:148
cs_flag_t location
Definition: cs_cdo.h:133
const char * cs_base_strtf(bool boolean)
Return a string "true" or "false" according to the boolean.
Definition: cs_cdo.c:107
Definition: cs_cdo.h:151
double meas
Definition: cs_cdo.h:142
Definition: cs_cdo.h:153
const char lsepline[80]
Definition: cs_cdo.c:67
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
void() cs_twovar_law_func_t(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], const double var1_values[], const double var2_values[], const void *law_param, cs_real_t res_array[])
Compute the value of a quantity according to a law depending only on two variables. This law is described by a set of parameters stored in a structure. result = law(var1_value, var2_value)
Definition: cs_cdo.h:230
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.c:125
const cs_flag_t cs_cdo_primal_cell
Definition: cs_cdo.c:77
cs_flag_t state
Definition: cs_cdo.h:134
const cs_flag_t cs_cdo_dual_cell
Definition: cs_cdo.c:80
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
const cs_flag_t cs_cdo_primal_vtx
Definition: cs_cdo.c:75
#define END_C_DECLS
Definition: cs_defs.h:452
const cs_flag_t cs_cdo_dual_face
Definition: cs_cdo.c:79
unsigned short int cs_flag_t
Definition: cs_defs.h:299
Definition: cs_cdo.h:152
const char ssepline[40]
Definition: cs_cdo.c:71
_Bool cs_cdo_is_activated
Definition: cs_cdo.c:64
Definition: cs_cdo.h:150
const char msepline[60]
Definition: cs_cdo.c:69
const cs_flag_t cs_cdo_dual_vtx
Definition: cs_cdo.c:78