programmer's documentation
cs_param.h
Go to the documentation of this file.
1 #ifndef __CS_PARAM_H__
2 #define __CS_PARAM_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-2015 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_cdo.h"
35 #include "cs_quadrature.h"
36 
37 /*----------------------------------------------------------------------------*/
38 
40 
41 /*============================================================================
42  * Macro definitions
43  *============================================================================*/
44 
45 /* Tag to build parameter flag */
46 #define CS_PARAM_FLAG_UNIFORM (1 << 0) // 1: uniform (in space)
47 #define CS_PARAM_FLAG_VERTEX (1 << 1) // 2: on vertices
48 #define CS_PARAM_FLAG_EDGE (1 << 2) // 4: on edges
49 #define CS_PARAM_FLAG_FACE (1 << 3) // 8: on faces
50 #define CS_PARAM_FLAG_CELL (1 << 4) // 16: on cells
51 #define CS_PARAM_FLAG_PRIMAL (1 << 5) // 32: on primal mesh
52 #define CS_PARAM_FLAG_DUAL (1 << 6) // 64: on dual mesh
53 #define CS_PARAM_FLAG_BORDER (1 << 7) // 128: scalar-valued
54 #define CS_PARAM_FLAG_SCAL (1 << 8) // 256: scalar-valued
55 #define CS_PARAM_FLAG_VECT (1 << 9) // 512: vector-valued
56 #define CS_PARAM_FLAG_TENS (1 << 10) // 1024: tensor-valued
57 #define CS_PARAM_FLAG_SYMMET (1 << 11) // 2048: symmetric
58 #define CS_PARAM_FLAG_IMPLICIT (1 << 12) // 4096: implicit
59 #define CS_PARAM_FLAG_EXPLICIT (1 << 13) // 8192: explicit
60 #define CS_PARAM_FLAG_UNSTEADY (1 << 14) //16384: unsteady
61 
62 /*============================================================================
63  * Type definitions
64  *============================================================================*/
65 
66 typedef union {
67 
68  cs_get_t get; // definition by value
69  cs_analytic_func_t *analytic; // definition by an analytic function
70  cs_user_func_t *user_func; // definition by an user-defined function
71 
72 } cs_def_t;
73 
74 typedef enum {
75 
84 
86 
87 /* Dimension of the variable to deal with */
88 typedef enum {
89 
90  CS_PARAM_VAR_SCAL, // scalar variable (dim = 1)
91  CS_PARAM_VAR_VECT, // vector variable (dim = 3)
92  CS_PARAM_VAR_SYMTENS, // symmetric tensor variable (dim = 6)
93  CS_PARAM_VAR_TENS, // tensor variable (dim = 9)
95 
97 
98 /* MATERIAL PROPERTIES */
99 /* =================== */
100 
101 /* Material property: parametrization for conductivity, diffusion coef.
102  or viscosity */
103 typedef enum {
104 
109 
111 
112 /* Material parameter definitions */
113 typedef struct {
114 
115  char *restrict name;
116  cs_flag_t flag; /* Short descriptor (mask of bits) */
117 
118  int post_freq; /* -1 (no post-processing), 0 (at the beginning)
119  otherwise every post_freq iteration(s) */
120  int field_id; /* If post-processing is required (-1 if not used) */
121 
122  /* Material properties:
123  Uniform material. The number of values to set depends on the material
124  definition.
125  - isotropic = 1
126  - orthotropic = 3
127  - anisotropic = 9
128  Not uniform or not steady material. Values have to be defined by a
129  user function.
130  */
131 
135 
137 
138 /* DISCRETE HODGE OPERATORS */
139 /* ======================== */
140 
141 typedef enum {
142 
149 
151 
152 typedef enum {
153 
155  CS_PARAM_HODGE_ALGO_WBS, // WBS: Whitney Barycentric Subdivision
156  CS_PARAM_HODGE_ALGO_COST, // COST: COnsistency & STabilization splitting
158 
160 
161 typedef struct {
162 
163  int pty_id; /* id of the related material property */
164  bool inv_pty; /* Definition based on material property
165  or its inverse */
166 
169  double coef; /* Value of the stabilization parameter
170  if the COST algo. is used, other 0. */
171 
173 
174 /* BOUNDARY CONDITIONS */
175 /* =================== */
176 
177 /* Mathematical boundary conditions */
178 typedef enum {
179 
185 
187 
189 
190 /* Physic-driven boundary */
191 typedef enum {
192 
197 
199 
201 
202 /* Definition of the value of a boundary condition (BC)
203  One or two values may be needed according to the type of BC.
204  That's why two coefficients are used in the definition.
205  For Dirichlet or Neumann BC for instance, only one coefficient is used.
206 */
207 
208 typedef struct {
209 
210  int loc_id; // Id related to the list of border faces
211 
212  cs_param_bc_type_t bc_type; // type of mathematical BC
213  cs_param_def_type_t def_type; // Type of definition for a and b
214 
215  /* Access to the value related to the first coefficient and possibly
216  the second one */
219 
221 
222 typedef struct {
223 
226  double penalty_coef; // TODO: preliminary step
227  cs_quadra_type_t quad_type; // barycentric, higher, highest...
228 
229  int n_defs;
231 
232 } cs_param_bc_t;
233 
234 /* SOURCE TERMS */
235 /* ============ */
236 
237 /* Types of source terms */
238 typedef enum {
239 
240  CS_PARAM_SOURCE_TERM_BASIC, // in the right hand side
241  CS_PARAM_SOURCE_TERM_IMPLICIT, // in the matrix to invert
242  CS_PARAM_SOURCE_TERM_IMEX, // implicit/explicit: two contributions
243  CS_PARAM_SOURCE_TERM_MASS, // specific treatment
244  CS_PARAM_SOURCE_TERM_HEADLOSS, // specific treatment
246 
248 
249 typedef struct {
250 
251  char *restrict name; /* short description of the source term */
252 
253  int location_id; /* id of the related mesh location
254  structure */
255 
256  /* Specification related to the way of computing the source term */
257  cs_param_source_term_type_t type; /* mass, head loss... */
258  cs_param_var_type_t var_type; /* scalar, vector... */
259  cs_param_def_type_t def_type; /* by value, by function... */
260  cs_quadra_type_t quad_type; /* barycentric, higher, highest */
261 
262  /* Two potential values (implicit and explicit) */
265 
267 
268 /* ITERATIVE SOLVERS */
269 /* ================= */
270 
271 typedef enum {
272 
273  CS_PARAM_PRECOND_DIAG, // Diagonal preconditioning (also called Jacobi)
274  CS_PARAM_PRECOND_POLY1, // Neumann polynomial preconditioning (Order 1)
275  CS_PARAM_PRECOND_SSOR, // Symmetric Successive OverRelaxations
276  CS_PARAM_PRECOND_ILU0, // Incomplete LU factorization
277  CS_PARAM_PRECOND_ICC0, // Incomplete Cholesky factorization
278  CS_PARAM_PRECOND_AMG, // Algebraic MultiGrid
279  CS_PARAM_PRECOND_AS, // Additive Schwarz method
281 
283 
284 /* Type of iterative solver to use to inverse the linear system */
285 typedef enum {
286 
287  CS_PARAM_ITSOL_CG, // Conjuguate Gradient
288  CS_PARAM_ITSOL_BICG, // Bi-Conjuguate gradient
289  CS_PARAM_ITSOL_GMRES, // Generalized Minimal RESidual
290  CS_PARAM_ITSOL_AMG, // Algebraic MultiGrid
292 
294 
295 /* Description of the algorithm used to solve an equation */
296 typedef struct {
297 
298  cs_param_precond_type_t precond; // type of preconditioner
299  cs_param_itsol_type_t solver; // type of solver
300 
301  int n_max_iter; // max. number of iterations
302  double eps; // stopping criterion on accuracy
303 
304  int output_freq; // frequencdy of output into listing
305  bool resid_normalized; /* normalized or not the norm of the
306  residual used for the stopping criterion
307  */
309 
310 /*============================================================================
311  * Global variables
312  *============================================================================*/
313 
314 /*============================================================================
315  * Public function prototypes
316  *============================================================================*/
317 
318 /*----------------------------------------------------------------------------*/
322 /*----------------------------------------------------------------------------*/
323 
324 void
326 
327 /*----------------------------------------------------------------------------*/
335 /*----------------------------------------------------------------------------*/
336 
338 cs_param_pty_get(int pty_id);
339 
340 /*----------------------------------------------------------------------------*/
348 /*----------------------------------------------------------------------------*/
349 
350 int
351 cs_param_pty_get_id_by_name(const char *ref_name);
352 
353 /*----------------------------------------------------------------------------*/
357 /*----------------------------------------------------------------------------*/
358 
359 void
361 
362 /*----------------------------------------------------------------------------*/
371 /*----------------------------------------------------------------------------*/
372 
373 void
374 cs_param_pty_add(const char *name,
375  cs_param_pty_type_t type,
376  int post_freq);
377 
378 /*----------------------------------------------------------------------------*/
382 /*----------------------------------------------------------------------------*/
383 
384 void
386 
387 /*----------------------------------------------------------------------------*/
394 /*----------------------------------------------------------------------------*/
395 
396 void
397 cs_param_pty_set_by_val(const char *name,
398  cs_get_t matval);
399 
400 /*----------------------------------------------------------------------------*/
407 /*----------------------------------------------------------------------------*/
408 
409 void
410 cs_param_pty_set_by_analytic_func(const char *name,
411  cs_analytic_func_t *analytic_func);
412 
413 /*----------------------------------------------------------------------------*/
421 /*----------------------------------------------------------------------------*/
422 
423 bool
424 cs_param_pty_is_uniform(int pty_id);
425 
426 /*----------------------------------------------------------------------------*/
434 /*----------------------------------------------------------------------------*/
435 
436 const char *
437 cs_param_pty_get_name(int pty_id);
438 
439 /*----------------------------------------------------------------------------*/
450 /*----------------------------------------------------------------------------*/
451 
452 void
453 cs_param_pty_get_val(int pty_id,
454  cs_real_t t,
455  cs_real_3_t xyz,
456  bool invers,
457  cs_real_33_t *matval);
458 
459 /*----------------------------------------------------------------------------*/
463 /*----------------------------------------------------------------------------*/
464 
465 void
467 
468 /*----------------------------------------------------------------------------*/
472 /*----------------------------------------------------------------------------*/
473 
474 void
476 
477 /*----------------------------------------------------------------------------*/
486 /*----------------------------------------------------------------------------*/
487 
490  bool is_penalized);
491 
492 /*----------------------------------------------------------------------------*/
503 /*----------------------------------------------------------------------------*/
504 
505 void
507  int loc_id,
508  cs_param_bc_type_t bc_type,
509  cs_param_def_type_t def_type,
510  cs_def_t def_coef1,
511  cs_def_t def_coef2);
512 
513 /*----------------------------------------------------------------------------*/
528 /*----------------------------------------------------------------------------*/
529 
530 void
532  const char *st_name,
533  int ml_id,
535  cs_param_var_type_t var_type,
536  cs_quadra_type_t quad_type,
537  cs_param_def_type_t def_type,
538  cs_def_t imp_def,
539  cs_def_t exp_def);
540 
541 /*----------------------------------------------------------------------------*/
549 /*----------------------------------------------------------------------------*/
550 
551 const char *
553 
554 /*----------------------------------------------------------------------------*/
562 /*----------------------------------------------------------------------------*/
563 
564 const char *
566 
567 /*----------------------------------------------------------------------------*/
575 /*----------------------------------------------------------------------------*/
576 
577 const char *
579 
580 /*----------------------------------------------------------------------------*/
588 /*----------------------------------------------------------------------------*/
589 
590 const char *
592 
593 /*----------------------------------------------------------------------------*/
601 /*----------------------------------------------------------------------------*/
602 
603 const char *
605 
606 /*----------------------------------------------------------------------------*/
614 /*----------------------------------------------------------------------------*/
615 
616 const char *
618 
619 /*----------------------------------------------------------------------------*/
627 /*----------------------------------------------------------------------------*/
628 
629 const char *
631 
632 /*----------------------------------------------------------------------------*/
640 /*----------------------------------------------------------------------------*/
641 
642 const char *
644 
645 
646 /*----------------------------------------------------------------------------*/
647 
649 
650 #endif /* __CS_PARAM_H__ */
cs_quadra_type_t quad_type
Definition: cs_param.h:260
cs_param_pty_t * cs_param_pty_get(int pty_id)
Retrieve a cs_param_pty_t structure from its id.
Definition: cs_param.c:177
Definition: cs_param.h:147
cs_param_hodge_algo_t algo
Definition: cs_param.h:168
cs_param_precond_type_t precond
Definition: cs_param.h:298
#define restrict
Definition: cs_defs.h:122
cs_param_bc_def_t * defs
Definition: cs_param.h:230
int post_freq
Definition: cs_param.h:118
Definition: cs_param.h:274
cs_param_def_type_t def_type
Definition: cs_param.h:259
cs_param_pty_type_t
Definition: cs_param.h:103
Definition: cs_param.h:245
Definition: cs_param.h:276
void( cs_user_func_t)(const void *input1, const void *input2, cs_real_t cur_time, cs_real_3_t xyz, cs_get_t *output)
Definition: cs_cdo.h:84
cs_param_boundary_type_t
Definition: cs_param.h:191
Definition: cs_param.h:94
Definition: cs_param.h:92
bool cs_param_pty_is_uniform(int pty_id)
Query to know if the material property is uniform.
Definition: cs_param.c:489
Definition: cs_param.h:90
bool inv_pty
Definition: cs_param.h:164
const char * cs_param_source_term_get_type_name(const cs_param_source_term_t st_info)
Get the name related to a source term.
Definition: cs_param.c:920
Definition: cs_param.h:242
Definition: cs_param.h:287
cs_def_t def_coef1
Definition: cs_param.h:217
void cs_param_pty_set_default(void)
Add by default several material properties.
Definition: cs_param.c:230
Definition: cs_param.h:290
cs_user_func_t * user_func
Definition: cs_param.h:70
cs_param_itsol_type_t solver
Definition: cs_param.h:299
void cs_param_pty_get_val(int pty_id, cs_real_t t, cs_real_3_t xyz, bool invers, cs_real_33_t *matval)
Retrieve the 3x3 matrix related to a general material property. This value is computed at location (x...
Definition: cs_param.h:183
#define BEGIN_C_DECLS
Definition: cs_defs.h:419
Definition: cs_param.h:184
Definition: cs_param.h:91
Definition: cs_param.h:273
int pty_id
Definition: cs_param.h:163
cs_flag_t flag
Definition: cs_param.h:116
Definition: cs_param.h:154
Definition: cs_param.h:81
cs_def_t imp_def
Definition: cs_param.h:263
Definition: cs_param.h:240
void cs_param_pty_add_fields(void)
Create a field related to a material property.
Definition: cs_param.c:337
Definition: cs_param.h:195
const char * cs_param_get_precond_name(cs_param_precond_type_t precond)
Get the name of the preconditionner.
Definition: cs_param.c:1034
Definition: cs_param.h:291
cs_def_t def
Definition: cs_param.h:134
Definition: cs_param.h:249
Definition: cs_param.h:107
cs_param_pty_type_t type
Definition: cs_param.h:132
Definition: cs_param.h:277
cs_param_source_term_type_t
Definition: cs_param.h:238
Definition: cs_param.h:148
Definition: cs_param.h:143
Definition: cs_param.h:288
Definition: cs_cdo.h:63
Definition: cs_param.h:82
Definition: cs_param.h:146
Definition: cs_param.h:93
Definition: cs_param.h:193
Definition: cs_param.h:243
cs_param_def_type_t def_type
Definition: cs_param.h:133
cs_def_t def_coef2
Definition: cs_param.h:218
void cs_param_pty_set_by_analytic_func(const char *name, cs_analytic_func_t *analytic_func)
Define a material property by an analytical function.
Definition: cs_param.c:460
Definition: cs_param.h:280
Definition: cs_param.h:244
Definition: cs_param.h:157
int loc_id
Definition: cs_param.h:210
void( cs_analytic_func_t)(cs_real_t time, cs_real_3_t xyz, cs_get_t *retval)
Definition: cs_cdo.h:79
const char * cs_param_pty_get_name(int pty_id)
Retrieve the name of a material property from its id.
Definition: cs_param.c:518
Definition: cs_param.h:180
const char * cs_param_hodge_get_type_name(const cs_param_hodge_t h_info)
Get the type of discrete Hodge operator.
Definition: cs_param.c:984
int field_id
Definition: cs_param.h:120
Definition: cs_param.h:108
void cs_param_source_term_add(cs_param_source_term_t *st, const char *st_name, int ml_id, cs_param_source_term_type_t type, cs_param_var_type_t var_type, cs_quadra_type_t quad_type, cs_param_def_type_t def_type, cs_def_t imp_def, cs_def_t exp_def)
Define a source term. This source term is added to the list of source terms associated to an equation...
Definition: cs_param.c:865
int output_freq
Definition: cs_param.h:304
cs_param_bc_t * cs_param_bc_create(cs_param_bc_type_t default_bc, bool is_penalized)
Allocate and initialize a new cs_param_bc_t structure.
void cs_param_pty_finalize(void)
Free structures dedicated to the definition of material properties.
Definition: cs_param.c:774
Definition: cs_param.h:105
int n_max_iter
Definition: cs_param.h:301
Definition: cs_param.h:76
void cs_param_pty_free_all(void)
Destroy all structures related to properties.
Definition: cs_param.c:153
Definition: cs_param.h:113
int n_defs
Definition: cs_param.h:229
const char * cs_param_get_def_type_name(const cs_param_def_type_t type)
Get the name related to a type of definition.
Definition: cs_param.c:952
const char * cs_param_hodge_get_algo_name(const cs_param_hodge_t h_info)
Get the name of algorithm related to a discrete Hdoge operator.
Definition: cs_param.c:968
cs_analytic_func_t * analytic
Definition: cs_param.h:69
cs_param_precond_type_t
Definition: cs_param.h:271
cs_param_hodge_type_t type
Definition: cs_param.h:167
bool strong_enforcement
Definition: cs_param.h:225
Definition: cs_param.h:144
cs_param_itsol_type_t
Definition: cs_param.h:285
double penalty_coef
Definition: cs_param.h:226
void cs_param_pty_resume_all(void)
Resume all the cs_param_pty_t structures.
Definition: cs_param.c:692
cs_param_def_type_t def_type
Definition: cs_param.h:213
Definition: cs_param.h:106
Definition: cs_param.h:196
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
int location_id
Definition: cs_param.h:253
cs_param_bc_type_t
Definition: cs_param.h:178
const char * cs_param_source_term_get_name(const cs_param_source_term_t st_info)
Get the name related to a source term.
Definition: cs_param.c:904
Definition: cs_param.h:194
Definition: cs_param.h:80
cs_quadra_type_t
Definition: cs_quadrature.h:40
Definition: cs_param.h:79
Definition: cs_param.h:66
Definition: cs_param.h:186
Definition: cs_param.h:275
cs_quadra_type_t quad_type
Definition: cs_param.h:227
cs_param_hodge_type_t
Definition: cs_param.h:141
const char * cs_param_get_var_type_name(const cs_param_var_type_t type)
Get the name related to a type of variable.
Definition: cs_param.c:936
Definition: cs_param.h:289
cs_param_source_term_type_t type
Definition: cs_param.h:257
const char * cs_param_get_solver_name(cs_param_itsol_type_t solver)
Get the name of the solver.
Definition: cs_param.c:1000
Definition: cs_param.h:156
#define END_C_DECLS
Definition: cs_defs.h:420
char *restrict name
Definition: cs_param.h:251
double cs_real_t
Definition: cs_defs.h:296
Definition: cs_param.h:198
cs_param_bc_type_t default_bc
Definition: cs_param.h:224
void cs_param_pty_add(const char *name, cs_param_pty_type_t type, int post_freq)
Create and intialize a material property.
Definition: cs_param.c:294
cs_param_var_type_t
Definition: cs_param.h:88
Definition: cs_param.h:182
cs_def_t exp_def
Definition: cs_param.h:264
Definition: cs_param.h:83
void cs_param_pty_set_by_val(const char *name, cs_get_t matval)
Define a material property by value.
Definition: cs_param.c:393
bool resid_normalized
Definition: cs_param.h:305
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:311
cs_param_var_type_t var_type
Definition: cs_param.h:258
Definition: cs_field_pointer.h:92
void cs_param_bc_def_set(cs_param_bc_def_t *bc_def, int loc_id, cs_param_bc_type_t bc_type, cs_param_def_type_t def_type, cs_def_t def_coef1, cs_def_t def_coef2)
Set a cs_param_bc_def_t structure.
Definition: cs_param.c:828
Definition: cs_param.h:208
Definition: cs_param.h:145
cs_param_bc_type_t bc_type
Definition: cs_param.h:212
Definition: cs_param.h:241
double coef
Definition: cs_param.h:169
Definition: cs_param.h:181
Definition: cs_param.h:222
Definition: cs_param.h:278
cs_param_hodge_algo_t
Definition: cs_param.h:152
Definition: cs_param.h:161
int cs_param_pty_get_id_by_name(const char *ref_name)
Find the id related to a property definition from its name.
Definition: cs_param.c:199
double eps
Definition: cs_param.h:302
char *restrict name
Definition: cs_param.h:115
unsigned short int cs_flag_t
Definition: cs_cdo.h:50
Definition: cs_param.h:78
Definition: cs_param.h:279
cs_param_def_type_t
Definition: cs_param.h:74
Definition: cs_param.h:77
Definition: cs_param.h:296
Definition: cs_param.h:155