programmer's documentation
cs_param_eq.h
Go to the documentation of this file.
1 #ifndef __CS_PARAM_EQ_H__
2 #define __CS_PARAM_EQ_H__
3 
4 /*============================================================================
5  * Routines to handle the settings of a convection/diffusion equation
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  * Local headers
30  *----------------------------------------------------------------------------*/
31 
32 #include "cs_base.h"
33 #include "cs_cdo.h"
34 #include "cs_quadrature.h"
35 #include "cs_param.h"
36 
37 /*----------------------------------------------------------------------------*/
38 
40 
41 /*============================================================================
42  * Macro definitions
43  *============================================================================*/
44 
45 /* Boundary condition flag */
46 #define CS_PARAM_EQ_UNSTEADY (1 << 0) /* 1: unsteady term */
47 #define CS_PARAM_EQ_CONVECTION (1 << 1) /* 2: convection term */
48 #define CS_PARAM_EQ_DIFFUSION (1 << 2) /* 4: diffusion term */
49 #define CS_PARAM_EQ_SOURCETERM (1 << 3) /* 8: source term */
50 
51 /*============================================================================
52  * Type definitions
53  *============================================================================*/
54 
55 /* Type of equations managed by the solver */
56 typedef enum {
57 
63 
65 
66 /* Type of algorithm to get the solution of an equation */
67 typedef enum {
68 
70  CS_PARAM_EQ_ALGO_CS_ITSOL, /* Used an iterative solver
71  defined by Code_Saturne */
72  CS_PARAM_EQ_ALGO_PETSC_ITSOL, /* Used an iterative solver
73  defined by PETSc */
74  CS_PARAM_EQ_ALGO_UZAWA, // To solve sadle-point system
75  CS_PARAM_EQ_ALGO_NEWTON, // To solve non-linear system
76  CS_PARAM_EQ_ALGO_PICARD, // To solve non-linear system
78 
80 
81 /* Description of the algorithm used to solve an equation */
82 typedef struct {
83 
85 
86  int n_iters;
90 
91  double eps; /* stopping criterion on accuracy */
92 
94 
95 /* EQUATION STRUCTURE */
96 /* ================== */
97 
98 /* Convection/Diffusion/Reaction + Term Source equation */
99 typedef struct {
100 
101  char *restrict name; /* Short description */
102 
103  cs_param_eq_type_t type; /* scalar, vector, tensor... */
104  int verbosity; /* Level of detail to output */
105 
106  /* Numerical settings */
108 
109  /* Unsteady-Diffusion-Convection-Source term activated or not */
110  int flag;
111 
112  /* Variable to solve (stored in a cs_field_t structure) */
114  int field_id;
115 
116  /* Unsteady term */
118  bool is_multiplied_by_rho; /* true or false */
119 
120  /* Diffusion parameters */
122 
123  /* Convection term (TODO) */
124 
125  /* Source term(s) */
128 
129  /* Boundary conditions */
131 
132  /* High-level structure to manage/monitor the resolution of this equation */
135 
136 } cs_param_eq_t;
137 
138 
139 /* NAVSTO STRUCTURE */
140 /* ================ */
141 
142 typedef enum {
143 
148 
150 
151 typedef enum {
152 
157 
159 
160 typedef struct {
161 
164 
165  /* Steady/Reaction/Diffusion/Convection
166  If diffusion is off --> Euler equations
167  If convection is off --> Stokes equations
168  */
170 
171  /* Fields (activated according to the formulation) */
175 
176  /* Material property: rho and laminar viscosity */
177  int rho_id;
178  int lvisc_id;
179 
180  /* Source terms */
183 
186 
187  /* Boundary conditions */
192 
194 
195 /*============================================================================
196  * Global variables
197  *============================================================================*/
198 
199 /*============================================================================
200  * Public function prototypes
201  *============================================================================*/
202 
203 /*----------------------------------------------------------------------------*/
211 /*----------------------------------------------------------------------------*/
212 
213 int
214 cs_param_eq_get_id_by_name(const char *ref_name);
215 
216 /*----------------------------------------------------------------------------*/
224 /*----------------------------------------------------------------------------*/
225 
226 const cs_param_eq_t *
227 cs_param_eq_get_by_id(int eq_id);
228 
229 /*----------------------------------------------------------------------------*/
244 /*----------------------------------------------------------------------------*/
245 
246 int
247 cs_param_eq_add(const char *name,
248  const char *varname,
249  cs_param_eq_type_t type,
250  bool is_steady,
251  bool do_convection,
252  bool do_diffusion,
253  cs_param_bc_type_t default_bc_type);
254 
255 /*----------------------------------------------------------------------------*/
263 /*----------------------------------------------------------------------------*/
264 
265 void
266 cs_param_eq_set_diffusion_pty(const char *eq_name,
267  const char *pty_name);
268 
269 /*----------------------------------------------------------------------------*/
277 /*----------------------------------------------------------------------------*/
278 
279 void
280 cs_param_eq_set_algo_type(const char *eqname,
282 
283 /*----------------------------------------------------------------------------*/
292 /*----------------------------------------------------------------------------*/
293 
294 void
295 cs_param_eq_set_itsol_type(const char *name,
296  cs_param_itsol_type_t itsol,
297  cs_param_precond_type_t precond);
298 
299 /*----------------------------------------------------------------------------*/
306 /*----------------------------------------------------------------------------*/
307 
308 void
309 cs_param_eq_set_itsol_precision(const char *name,
310  double accuracy);
311 
312 /*----------------------------------------------------------------------------*/
319 /*----------------------------------------------------------------------------*/
320 
321 void
322 cs_param_eq_set_itsol_max_iter(const char *name,
323  int n_max_iter);
324 
325 /*----------------------------------------------------------------------------*/
332 /*----------------------------------------------------------------------------*/
333 
334 void
335 cs_param_eq_set_itsol_normalization(const char *name,
336  bool resid_normalized);
337 
338 /*----------------------------------------------------------------------------*/
345 /*----------------------------------------------------------------------------*/
346 
347 void
348 cs_param_eq_set_verbosity_level(const char *name,
349  int verbosity);
350 
351 /*----------------------------------------------------------------------------*/
359 /*----------------------------------------------------------------------------*/
360 
361 const char *
362 cs_param_eq_get_name(int eq_id);
363 
364 /*----------------------------------------------------------------------------*/
371 /*----------------------------------------------------------------------------*/
372 
373 void
374 cs_param_eq_set_space_scheme(const char *name,
375  cs_space_scheme_t scheme);
376 
377 /*----------------------------------------------------------------------------*/
386 /*----------------------------------------------------------------------------*/
387 
390 
391 /*----------------------------------------------------------------------------*/
400 /*----------------------------------------------------------------------------*/
401 
403 cs_param_eq_get_type(int eq_id);
404 
405 /*----------------------------------------------------------------------------*/
413 /*----------------------------------------------------------------------------*/
414 
415 void
416 cs_param_eq_hodge_diffusion_set_algo(const char *name,
417  cs_param_hodge_algo_t algo);
418 
419 /*----------------------------------------------------------------------------*/
427 /*----------------------------------------------------------------------------*/
428 
429 void
430 cs_param_eq_hodge_diffusion_set_coef(const char *name,
431  double coef);
432 
433 /*----------------------------------------------------------------------------*/
442 /*----------------------------------------------------------------------------*/
443 
444 void
445 cs_param_eq_add_scalbc_by_val(const char *eq_name,
446  const char *location_name,
447  cs_param_bc_type_t bc_type,
448  double bc_val);
449 
450 /*----------------------------------------------------------------------------*/
460 /*----------------------------------------------------------------------------*/
461 
462 void
463 cs_param_eq_add_scalbc_by_analytic(const char *eq_name,
464  const char *location_name,
465  cs_param_bc_type_t bc_type,
466  cs_analytic_func_t *func);
467 
468 /*----------------------------------------------------------------------------*/
480 /*----------------------------------------------------------------------------*/
481 
482 void
483 cs_param_eq_add_source_term_by_val(const char *eq_name,
484  const char *st_name,
485  const char *ml_name,
487  cs_get_t get_imp,
488  cs_get_t get_exp);
489 
490 /*----------------------------------------------------------------------------*/
503 /*----------------------------------------------------------------------------*/
504 
505 void
506 cs_param_eq_add_source_term_by_user(const char *eq_name,
507  const char *st_name,
508  const char *ml_name,
510  cs_quadra_type_t quad_type,
511  cs_user_func_t *imp_func,
512  cs_user_func_t *exp_func);
513 
514 /*----------------------------------------------------------------------------*/
528 /*----------------------------------------------------------------------------*/
529 
530 void
531 cs_param_eq_add_source_term_by_analytic(const char *eq_name,
532  const char *st_name,
533  const char *ml_name,
535  cs_quadra_type_t quad_type,
536  cs_analytic_func_t *imp_func,
537  cs_analytic_func_t *exp_func);
538 
539 /*----------------------------------------------------------------------------*/
543 /*----------------------------------------------------------------------------*/
544 
545 void
547 
548 /*----------------------------------------------------------------------------*/
552 /*----------------------------------------------------------------------------*/
553 
554 void
556 
557 /*----------------------------------------------------------------------------*/
564 /*----------------------------------------------------------------------------*/
565 
566 void
567 cs_param_eq_get_info(int *n_cdo_eqs);
568 
569 /*----------------------------------------------------------------------------*/
573 /*----------------------------------------------------------------------------*/
574 
575 void
577 
578 /*----------------------------------------------------------------------------*/
579 
581 
582 #endif /* __CS_PARAM_EQ_H__ */
cs_param_bc_def_t * bc_defs
Definition: cs_param_eq.h:189
Definition: cs_param_eq.h:58
int field_id
Definition: cs_param_eq.h:114
#define restrict
Definition: cs_defs.h:122
cs_param_hodge_t diffusion_hodge
Definition: cs_param_eq.h:121
Definition: cs_param_eq.h:59
Definition: cs_param_eq.h:160
cs_param_source_term_t * momentum_source_terms
Definition: cs_param_eq.h:182
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_eq_algo_type_t type
Definition: cs_param_eq.h:84
Definition: cs_param_eq.h:144
int velocity_id
Definition: cs_param_eq.h:172
void cs_param_eq_set_space_scheme(const char *name, cs_space_scheme_t scheme)
Modify the scheme used to discretized in space an equation.
Definition: cs_param_eq.c:533
cs_param_bc_t * bc
Definition: cs_param_eq.h:130
int vorticity_id
Definition: cs_param_eq.h:174
void cs_param_eq_hodge_diffusion_set_coef(const char *name, double coef)
Modify the coefficient related to an algorithm used to build the discrete Hodge operator associated t...
Definition: cs_param_eq.c:646
void cs_param_eq_set_itsol_type(const char *name, cs_param_itsol_type_t itsol, cs_param_precond_type_t precond)
Set the type of iterative solver and the type of preconditionner for solving the linear system relate...
Definition: cs_param_eq.c:380
void cs_param_eq_add_source_term_by_val(const char *eq_name, const char *st_name, const char *ml_name, cs_param_source_term_type_t type, cs_get_t get_imp, cs_get_t get_exp)
Define a source term by value(s). This source term is added to the list of source terms associated to...
Definition: cs_param_eq.c:777
cs_space_scheme_t space_scheme
Definition: cs_param_eq.h:107
#define BEGIN_C_DECLS
Definition: cs_defs.h:419
Definition: cs_param_eq.h:61
Definition: cs_param_eq.h:72
void cs_param_eq_set_diffusion_pty(const char *eq_name, const char *pty_name)
Associate a material property to the diffusion term of an equation By default, a material property eq...
Definition: cs_param_eq.c:318
cs_flag_t momentum_flag
Definition: cs_param_eq.h:169
cs_param_bc_type_t default_velocity_bc
Definition: cs_param_eq.h:190
cs_param_navsto_algo_t algo
Definition: cs_param_eq.h:163
cs_param_source_term_t * source_terms
Definition: cs_param_eq.h:127
Definition: cs_param_eq.h:62
void cs_param_eq_hodge_diffusion_set_algo(const char *name, cs_param_hodge_algo_t algo)
Modify the algorithm used to build the discrete Hodge operator related to the diffusion term...
Definition: cs_param_eq.c:619
Definition: cs_param.h:249
cs_param_source_term_type_t
Definition: cs_param.h:238
void cs_param_eq_add_source_term_by_analytic(const char *eq_name, const char *st_name, const char *ml_name, cs_param_source_term_type_t type, cs_quadra_type_t quad_type, cs_analytic_func_t *imp_func, cs_analytic_func_t *exp_func)
Define a source term by an analytic function. This source term is added to the list of source terms a...
Definition: cs_param_eq.c:927
void cs_param_eq_set_itsol_normalization(const char *name, bool resid_normalized)
Set if the residual is normalized or not.
Definition: cs_param_eq.c:460
int cs_param_eq_get_id_by_name(const char *ref_name)
Find the id related to an equation definition from its name.
Definition: cs_param_eq.c:161
Definition: cs_cdo.h:63
Definition: cs_param_eq.h:99
void cs_param_eq_get_info(int *n_cdo_eqs)
Retrieve high-level information on the setting.
Definition: cs_param_eq.c:1104
Definition: cs_param_eq.h:75
void( cs_analytic_func_t)(cs_real_t time, cs_real_3_t xyz, cs_get_t *retval)
Definition: cs_cdo.h:79
cs_space_scheme_t
Definition: cs_cdo.h:53
cs_param_navsto_formulation_t
Definition: cs_param_eq.h:142
Definition: cs_param_eq.h:74
int rho_id
Definition: cs_param_eq.h:177
void cs_param_eq_add_fields(void)
Create a field related to a variable solved in an equation.
Definition: cs_param_eq.c:987
cs_param_itsol_t itsol_info
Definition: cs_param_eq.h:134
cs_param_bc_type_t default_pressure_bc
Definition: cs_param_eq.h:191
void cs_param_eq_set_verbosity_level(const char *name, int verbosity)
Modify the level of verbosity (user function)
Definition: cs_param_eq.c:486
int n_max_cumulated_iters
Definition: cs_param_eq.h:89
Definition: cs_param_eq.h:77
cs_param_navsto_algo_t
Definition: cs_param_eq.h:151
const cs_param_eq_t * cs_param_eq_get_by_id(int eq_id)
Retrieve a pointer to a cs_param_eq_t structure.
Definition: cs_param_eq.c:196
cs_param_precond_type_t
Definition: cs_param.h:271
Definition: cs_param_eq.h:60
void cs_param_eq_set_algo_type(const char *eqname, cs_param_eq_algo_type_t algo)
Set the type of algorithm for solving the linear system related to the equation named eqname...
Definition: cs_param_eq.c:352
cs_param_hodge_t unsteady_hodge
Definition: cs_param_eq.h:117
Definition: cs_param_eq.h:147
int n_max_iters
Definition: cs_param_eq.h:87
cs_param_itsol_type_t
Definition: cs_param.h:285
int n_mass_source_terms
Definition: cs_param_eq.h:184
cs_param_eq_algo_t algo_info
Definition: cs_param_eq.h:133
int n_source_terms
Definition: cs_param_eq.h:126
int flag
Definition: cs_param_eq.h:110
void cs_param_eq_add_source_term_by_user(const char *eq_name, const char *st_name, const char *ml_name, cs_param_source_term_type_t type, cs_quadra_type_t quad_type, cs_user_func_t *imp_func, cs_user_func_t *exp_func)
Define a source term by a user-defined function. This source term is added to the list of source term...
Definition: cs_param_eq.c:857
cs_param_bc_type_t
Definition: cs_param.h:178
int pressure_id
Definition: cs_param_eq.h:173
cs_param_navsto_formulation_t formulation
Definition: cs_param_eq.h:162
cs_quadra_type_t
Definition: cs_quadrature.h:40
int verbosity
Definition: cs_param_eq.h:104
int lvisc_id
Definition: cs_param_eq.h:178
double eps
Definition: cs_param_eq.h:91
Definition: cs_param_eq.h:145
void cs_param_eq_free_all(void)
Free all definitions of equations initialized during the simulation.
Definition: cs_param_eq.c:1060
cs_param_source_term_t * mass_source_terms
Definition: cs_param_eq.h:185
char *restrict varname
Definition: cs_param_eq.h:113
cs_param_eq_type_t cs_param_eq_get_type(int eq_id)
Retrieve the type of equation associated to this equation from its id.
Definition: cs_param_eq.c:599
Definition: cs_param_eq.h:70
#define END_C_DECLS
Definition: cs_defs.h:420
Definition: cs_param_eq.h:76
void cs_param_eq_set_itsol_max_iter(const char *name, int n_max_iter)
Set the maximum number of iterations to do in an iterative solver.
Definition: cs_param_eq.c:434
int n_cumulated_iters
Definition: cs_param_eq.h:88
char *restrict name
Definition: cs_param_eq.h:101
const char * cs_param_eq_get_name(int eq_id)
Retrieve the name associated to an equation from its id.
Definition: cs_param_eq.c:513
void cs_param_eq_resume_all(void)
Resume parameters of all conv./diff./source terms equations.
Definition: cs_param_eq.c:1116
int cs_param_eq_add(const char *name, const char *varname, cs_param_eq_type_t type, bool is_steady, bool do_convection, bool do_diffusion, cs_param_bc_type_t default_bc_type)
Define and initialize a new structure to store parameters related to an equation. ...
Definition: cs_param_eq.h:154
cs_param_eq_type_t type
Definition: cs_param_eq.h:103
Definition: cs_param.h:208
Definition: cs_param_eq.h:153
Definition: cs_param_eq.h:155
bool is_multiplied_by_rho
Definition: cs_param_eq.h:118
Definition: cs_param.h:222
cs_param_eq_type_t
Definition: cs_param_eq.h:56
cs_param_hodge_algo_t
Definition: cs_param.h:152
int n_momemtum_source_terms
Definition: cs_param_eq.h:181
Definition: cs_param.h:161
Definition: cs_param_eq.h:82
void cs_param_eq_add_scalbc_by_analytic(const char *eq_name, const char *location_name, cs_param_bc_type_t bc_type, cs_analytic_func_t *func)
Define a new boundary condition for a scalar using an analytic function.
Definition: cs_param_eq.c:728
Definition: cs_param_eq.h:146
unsigned short int cs_flag_t
Definition: cs_cdo.h:50
void cs_param_eq_set_itsol_precision(const char *name, double accuracy)
Set the solver precision.
Definition: cs_param_eq.c:408
Definition: cs_param_eq.h:69
Definition: cs_param_eq.h:156
Definition: cs_param.h:296
void cs_param_eq_add_scalbc_by_val(const char *eq_name, const char *location_name, cs_param_bc_type_t bc_type, double bc_val)
Define a new boundary condition for a scalar.
Definition: cs_param_eq.c:681
int n_bc_defs
Definition: cs_param_eq.h:188
cs_space_scheme_t cs_param_eq_get_space_scheme(int eq_id)
Retrieve the numerical scheme used to discretize in space this equation from its id.
Definition: cs_param_eq.c:578
cs_param_eq_algo_type_t
Definition: cs_param_eq.h:67
int n_iters
Definition: cs_param_eq.h:86