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 /*============================================================================
112  * Type definitions
113  *============================================================================*/
114 
115 typedef unsigned char cs_mask_t;
116 
117 /* Description of an object (property, advection field, array..) using
118  mask of bits (i.e flag) */
119 
120 typedef struct {
121 
122  cs_flag_t location; /* where is defined this object */
123  cs_flag_t state; /* nature and additional information on this object */
124 
125 } cs_desc_t;
126 
127 /* Vector-valued quantity stored using its measure (i.e. length) and
128  its direction given by a unitary vector */
129 typedef struct {
130 
131  double meas;
132  double unitv[3];
133 
134 } cs_nvec3_t;
135 
136 /* Type of numerical scheme for the discretization in space */
137 typedef enum {
138 
139  CS_SPACE_SCHEME_CDOVB, /* CDO scheme with vertex-based positionning */
140  CS_SPACE_SCHEME_CDOVCB, /* CDO scheme with vertex+cell-based positionning */
141  CS_SPACE_SCHEME_CDOFB, /* CDO cell-based scheme with hybridization */
142  CS_SPACE_SCHEME_HHO, /* Hybrid High Order scheme (CDO-FB + high-order) */
144 
146 
147 /*----------------------------------------------------------------------------*/
156 /*----------------------------------------------------------------------------*/
157 
158 typedef void
160  cs_lnum_t n_points,
161  const cs_real_t *xyz,
162  cs_real_t *retval);
163 
164 /*----------------------------------------------------------------------------*/
174 /*----------------------------------------------------------------------------*/
175 
176 typedef cs_real_t
177 (cs_timestep_func_t) (int time_iter,
178  double time);
179 
180 /*----------------------------------------------------------------------------*/
193 /*----------------------------------------------------------------------------*/
194 
195 typedef void
197  const cs_lnum_t elt_ids[],
198  const cs_real_t var_values[],
199  const void *law_param,
200  cs_real_t res_array[]);
201 
202 /*----------------------------------------------------------------------------*/
216 /*----------------------------------------------------------------------------*/
217 
218 typedef void
220  const cs_lnum_t elt_ids[],
221  const double var1_values[],
222  const double var2_values[],
223  const void *law_param,
224  cs_real_t res_array[]);
225 
226 /*============================================================================
227  * Global variables
228  *============================================================================*/
229 
230 /* Activation of the CDO/HHO module */
231 extern _Bool cs_cdo_is_activated;
232 
233 /* Separation lines: long, medium, short */
234 extern const char lsepline[80];
235 extern const char msepline[60];
236 extern const char ssepline[40];
237 
238 /* Default locations */
239 extern const cs_flag_t cs_cdo_primal_vtx;
240 extern const cs_flag_t cs_cdo_primal_face;
241 extern const cs_flag_t cs_cdo_primal_cell;
242 extern const cs_flag_t cs_cdo_dual_vtx;
243 extern const cs_flag_t cs_cdo_dual_face;
244 extern const cs_flag_t cs_cdo_dual_cell;
245 extern const cs_flag_t cs_cdo_dual_face_byc;
246 
247 /*============================================================================
248  * Static inline function prototypes
249  *============================================================================*/
250 
251 /*----------------------------------------------------------------------------*/
262 /*----------------------------------------------------------------------------*/
263 
264 static inline bool
265 cs_test_flag(cs_flag_t flag_to_check,
266  cs_flag_t reference)
267 {
268  if ((flag_to_check & reference) == reference)
269  return true;
270  else
271  return false;
272 }
273 
274 /*============================================================================
275  * Public function prototypes
276  *============================================================================*/
277 
278 /*----------------------------------------------------------------------------*/
286 /*----------------------------------------------------------------------------*/
287 
288 const char *
289 cs_base_strtf(bool boolean);
290 
291 /*----------------------------------------------------------------------------*/
298 /*----------------------------------------------------------------------------*/
299 
300 void
301 cs_nvec3(const cs_real_3_t v,
302  cs_nvec3_t *qv);
303 
304 /*----------------------------------------------------------------------------*/
305 
307 
308 #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:159
const cs_flag_t cs_cdo_dual_face_byc
Definition: cs_cdo.c:81
Definition: cs_cdo.h:120
Definition: cs_cdo.h:143
#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:115
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:177
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:196
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_cdo.h:129
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:265
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
cs_space_scheme_t
Definition: cs_cdo.h:137
cs_flag_t location
Definition: cs_cdo.h:122
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:140
double meas
Definition: cs_cdo.h:131
Definition: cs_cdo.h:142
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:219
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:123
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:141
const char ssepline[40]
Definition: cs_cdo.c:71
_Bool cs_cdo_is_activated
Definition: cs_cdo.c:64
Definition: cs_cdo.h:139
const char msepline[60]
Definition: cs_cdo.c:69
const cs_flag_t cs_cdo_dual_vtx
Definition: cs_cdo.c:78