7.0
general documentation
cs_equation_common.h
Go to the documentation of this file.
1 #ifndef __CS_EQUATION_COMMON_H__
2 #define __CS_EQUATION_COMMON_H__
3 
4 /*============================================================================
5  * Routines to handle common equation features for building algebraic system
6  * in CDO schemes
7  *============================================================================*/
8 
9 /*
10  This file is part of Code_Saturne, a general-purpose CFD tool.
11 
12  Copyright (C) 1998-2021 EDF S.A.
13 
14  This program is free software; you can redistribute it and/or modify it under
15  the terms of the GNU General Public License as published by the Free Software
16  Foundation; either version 2 of the License, or (at your option) any later
17  version.
18 
19  This program is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22  details.
23 
24  You should have received a copy of the GNU General Public License along with
25  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
26  Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 */
28 
29 /*----------------------------------------------------------------------------
30  * Local headers
31  *----------------------------------------------------------------------------*/
32 
33 #include "cs_cdo_bc.h"
34 #include "cs_cdo_connect.h"
35 #include "cs_cdo_local.h"
36 #include "cs_cdo_quantities.h"
37 #include "cs_equation_param.h"
38 #include "cs_flag.h"
39 #include "cs_matrix.h"
40 #include "cs_time_step.h"
41 #include "cs_timer.h"
42 #include "cs_sles.h"
43 #include "cs_source_term.h"
44 
45 /*----------------------------------------------------------------------------*/
46 
48 
49 /*============================================================================
50  * Macro definitions
51  *============================================================================*/
52 
53 /* Strategy of synchronization of values shared across several cells
54  * This applies to vertices, edges and faces
55  *
56  * CS_EQUATION_SYNC_ZERO_VALUE
57  * If zero is a possible value then set this value, otherwise one takes
58  * the mean-value
59  *
60  * CS_EQUATION_SYNC_MEAN_VALUE
61  * Compute the mean-value across values to set
62  *
63  */
64 
65 #define CS_EQUATION_SYNC_ZERO_VALUE 1
66 #define CS_EQUATION_SYNC_MEAN_VALUE 2
67 
68 /*============================================================================
69  * Type definitions
70  *============================================================================*/
71 
73 
74 /*----------------------------------------------------------------------------*/
89 /*----------------------------------------------------------------------------*/
90 
91 typedef void
93  const cs_equation_builder_t *eqb,
94  const void *eq_context,
95  const cs_cell_mesh_t *cm,
96  cs_hodge_t *mass_hodge,
97  cs_hodge_t *diff_hodge,
98  cs_cell_sys_t *csys,
99  cs_cell_builder_t *cb);
100 
107 
108  bool init_step;
155 
178 
214 };
215 
216 /*
217  * Structure used to store information generated during the analysis
218  * of the balance of each term of an equation
219  */
220 typedef struct {
221 
222  /* where balance is computed: primal vertices or primal cells */
226 
227  /* Balance for each main term */
234 
236 
237 /*============================================================================
238  * Inline public function prototypes
239  *============================================================================*/
240 
241 /*----------------------------------------------------------------------------*/
250 /*----------------------------------------------------------------------------*/
251 
252 static inline cs_eflag_t
253 cs_equation_cell_mesh_flag(cs_flag_t cell_flag,
254  const cs_equation_builder_t *eqb)
255 {
256  cs_eflag_t _flag = eqb->msh_flag | eqb->st_msh_flag;
257 
258  if (cell_flag & CS_FLAG_BOUNDARY_CELL_BY_FACE)
259  _flag |= eqb->bd_msh_flag;
260 
261  return _flag;
262 }
263 
264 /*============================================================================
265  * Public function prototypes
266  *============================================================================*/
267 
268 /*----------------------------------------------------------------------------*/
285 /*----------------------------------------------------------------------------*/
286 
287 void
289  const cs_cdo_quantities_t *quant,
290  const cs_time_step_t *time_step,
291  cs_flag_t eb_flag,
292  cs_flag_t fb_flag,
293  cs_flag_t vb_flag,
294  cs_flag_t vcb_flag,
295  cs_flag_t hho_flag);
296 
297 /*----------------------------------------------------------------------------*/
306 /*----------------------------------------------------------------------------*/
307 
308 void
310 
311 /*----------------------------------------------------------------------------*/
321 /*----------------------------------------------------------------------------*/
322 
325  const cs_mesh_t *mesh);
326 
327 /*----------------------------------------------------------------------------*/
334 /*----------------------------------------------------------------------------*/
335 
336 void
338 
339 /*----------------------------------------------------------------------------*/
352 /*----------------------------------------------------------------------------*/
353 
354 void
356  cs_lnum_t rhs_size,
357  const cs_real_t rhs[],
358  double *normalization);
359 
360 /*----------------------------------------------------------------------------*/
374 /*----------------------------------------------------------------------------*/
375 
376 void
377 cs_equation_prepare_system(int stride,
378  cs_lnum_t x_size,
379  const cs_matrix_t *matrix,
380  const cs_range_set_t *rset,
381  bool rhs_redux,
382  cs_real_t *x,
383  cs_real_t *b);
384 
385 /*----------------------------------------------------------------------------*/
399 /*----------------------------------------------------------------------------*/
400 
401 int
403  const cs_param_sles_t *slesp,
404  const cs_matrix_t *matrix,
405  cs_real_t normalization,
406  cs_sles_t *sles,
407  cs_real_t *x,
408  cs_real_t *b);
409 
410 /*----------------------------------------------------------------------------*/
427 /*----------------------------------------------------------------------------*/
428 
429 int
431  const cs_param_sles_t *slesp,
432  const cs_matrix_t *matrix,
433  const cs_range_set_t *rset,
434  cs_real_t normalization,
435  bool rhs_redux,
436  cs_sles_t *sles,
437  cs_real_t *x,
438  cs_real_t *b);
439 
440 /*----------------------------------------------------------------------------*/
448 /*----------------------------------------------------------------------------*/
449 
450 void
451 cs_equation_write_monitoring(const char *eqname,
452  const cs_equation_builder_t *eqb);
453 
454 /*----------------------------------------------------------------------------*/
465 /*----------------------------------------------------------------------------*/
466 
467 void
469  const cs_equation_builder_t *eqb,
470  cs_real_t t_eval,
471  cs_cell_builder_t *cb);
472 
473 /*----------------------------------------------------------------------------*/
488 /*----------------------------------------------------------------------------*/
489 
490 void
492  const cs_equation_builder_t *eqb,
493  const cs_cell_mesh_t *cm,
494  cs_cell_builder_t *cb);
495 
496 /*----------------------------------------------------------------------------*/
508 /*----------------------------------------------------------------------------*/
509 
510 void
512  const cs_equation_builder_t *eqb,
513  cs_hodge_t *diffusion_hodge,
514  cs_cell_builder_t *cb);
515 
516 /*----------------------------------------------------------------------------*/
527 /*----------------------------------------------------------------------------*/
528 
529 void
531  const cs_adjacency_t *c2x,
532  const cs_equation_param_t *eqp,
533  cs_lnum_t *p_dof_ids[]);
534 
535 /*----------------------------------------------------------------------------*/
552 /*----------------------------------------------------------------------------*/
553 
554 void
556  cs_cell_builder_t *cb,
557  cs_cell_sys_t *csys);
558 
559 /*----------------------------------------------------------------------------*/
576 /*----------------------------------------------------------------------------*/
577 
578 void
580  cs_cell_builder_t *cb,
581  cs_cell_sys_t *csys);
582 
583 /*----------------------------------------------------------------------------*/
591 /*----------------------------------------------------------------------------*/
592 
593 cs_real_t *
595 
596 /*----------------------------------------------------------------------------*/
602 /*----------------------------------------------------------------------------*/
603 
604 size_t
606 
607 /*----------------------------------------------------------------------------*/
616 /*----------------------------------------------------------------------------*/
617 
620  cs_lnum_t size);
621 
622 /*----------------------------------------------------------------------------*/
628 /*----------------------------------------------------------------------------*/
629 
630 void
632 
633 /*----------------------------------------------------------------------------*/
640 /*----------------------------------------------------------------------------*/
641 
642 void
645 
646 /*----------------------------------------------------------------------------*/
652 /*----------------------------------------------------------------------------*/
653 
654 void
656 
657 /*----------------------------------------------------------------------------*/
667 /*----------------------------------------------------------------------------*/
668 
669 void
671  int n_defs,
672  cs_xdef_t **defs,
673  cs_lnum_t def2v_idx[],
674  cs_lnum_t def2v_ids[]);
675 
676 /*----------------------------------------------------------------------------*/
686 /*----------------------------------------------------------------------------*/
687 
688 void
690  int n_defs,
691  cs_xdef_t **defs,
692  cs_lnum_t def2e_idx[],
693  cs_lnum_t def2e_ids[]);
694 
695 /*----------------------------------------------------------------------------*/
705 /*----------------------------------------------------------------------------*/
706 
707 void
709  int n_defs,
710  cs_xdef_t **defs,
711  cs_lnum_t def2f_idx[],
712  cs_lnum_t def2f_ids[]);
713 
714 /*----------------------------------------------------------------------------*/
723 /*----------------------------------------------------------------------------*/
724 
725 void
727  int dim,
728  int *counter,
729  cs_real_t *values);
730 
731 /*----------------------------------------------------------------------------*/
732 
734 
735 #endif /* __CS_EQUATION_COMMON_H__ */
int cs_equation_solve_scalar_system(cs_lnum_t n_scatter_dofs, const cs_param_sles_t *slesp, const cs_matrix_t *matrix, const cs_range_set_t *rset, cs_real_t normalization, bool rhs_redux, cs_sles_t *sles, cs_real_t *x, cs_real_t *b)
Solve a linear system arising from CDO schemes with scalar-valued degrees of freedom.
Definition: cs_equation_common.c:601
Store common elements used when building an algebraic system related to an equation.
time step descriptor
Definition: cs_time_step.h:64
cs_timer_counter_t tcs
Definition: cs_equation_common.h:206
Definition: cs_equation_common.h:106
bool diff_pty_uniform
Definition: cs_equation_common.h:132
cs_param_resnorm_type_t
Definition: cs_param_types.h:722
unsigned char cs_mask_t
Definition: cs_flag.h:143
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources...
Definition: cs_equation_param.h:202
void cs_equation_free_builder(cs_equation_builder_t **p_builder)
Free a cs_equation_builder_t structure.
Definition: cs_equation_common.c:357
cs_source_term_cellwise_t * compute_source[CS_N_MAX_SOURCE_TERMS]
Definition: cs_equation_common.h:154
Definition: cs_mesh_adjacencies.h:67
cs_real_t * boundary_term
Definition: cs_equation_common.h:233
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
cs_real_t * balance
Definition: cs_equation_common.h:225
int cs_equation_solve_scalar_cell_system(cs_lnum_t n_dofs, const cs_param_sles_t *slesp, const cs_matrix_t *matrix, cs_real_t normalization, cs_sles_t *sles, cs_real_t *x, cs_real_t *b)
Solve a linear system arising with scalar-valued cell-based DoFs.
Definition: cs_equation_common.c:533
cs_lnum_t size
Definition: cs_equation_common.h:224
Set of local quantities and connectivities related to a mesh cell This is a key structure for all cel...
Definition: cs_cdo_local.h:159
bool graddiv_pty_uniform
Definition: cs_equation_common.h:134
void cs_equation_init_reaction_properties(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, cs_real_t t_eval, cs_cell_builder_t *cb)
Initialize all reaction properties. This function is shared across all CDO schemes. The cs_cell_builder_t structure stores the computed property values.
Definition: cs_equation_common.c:726
void cs_equation_init_properties(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, cs_hodge_t *diffusion_hodge, cs_cell_builder_t *cb)
Initialize all properties potentially useful to build the algebraic system. This function is shared a...
Definition: cs_equation_common.c:794
cs_equation_balance_t * cs_equation_balance_create(cs_flag_t location, cs_lnum_t size)
Allocate a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1150
void cs_equation_sync_rhs_normalization(cs_param_resnorm_type_t type, cs_lnum_t rhs_size, const cs_real_t rhs[], double *normalization)
Compute the value of the renormalization coefficient for the the residual norm of the linear system A...
Definition: cs_equation_common.c:393
cs_flag_t location
Definition: cs_equation_common.h:223
Definition: cs_cdo_connect.h:76
cs_mask_t * source_mask
Definition: cs_equation_common.h:145
Structure associated to a discrete Hodge operator.
Definition: cs_hodge.h:189
void cs_equation_enforced_internal_dofs(const cs_equation_param_t *eqp, cs_cell_builder_t *cb, cs_cell_sys_t *csys)
Take into account the enforcement of internal DoFs. Apply an algebraic manipulation.
Definition: cs_equation_common.c:919
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
Definition: cs_cdo_quantities.h:124
void matrix(const int *iconvp, const int *idiffp, const int *ndircp, const int *isym, const cs_real_t *thetap, const int *imucpp, const cs_real_t coefbp[], const cs_real_t cofbfp[], const cs_real_t rovsdt[], const cs_real_t i_massflux[], const cs_real_t b_massflux[], const cs_real_t i_visc[], const cs_real_t b_visc[], const cs_real_t xcpp[], cs_real_t da[], cs_real_t xa[])
Definition: cs_matrix_building.c:112
Set of arrays and local (small) dense matrices related to a mesh cell This is a key structure for bui...
Definition: cs_cdo_local.h:107
cs_real_t * advection_term
Definition: cs_equation_common.h:231
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:94
bool reac_pty_uniform[CS_CDO_N_MAX_REACTIONS]
Definition: cs_equation_common.h:136
Definition: cs_mesh.h:84
cs_flag_t sys_flag
Definition: cs_equation_common.h:124
cs_real_t * source_term
Definition: cs_equation_common.h:232
struct _cs_sles_t cs_sles_t
Definition: cs_sles.h:68
Definition: cs_equation_common.h:220
bool time_pty_uniform
Definition: cs_equation_common.h:135
void cs_equation_common_init(const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *quant, const cs_time_step_t *time_step, cs_flag_t eb_flag, cs_flag_t fb_flag, cs_flag_t vb_flag, cs_flag_t vcb_flag, cs_flag_t hho_flag)
Allocate a pointer to a buffer of size at least the n_cells for managing temporary usage of memory wh...
Definition: cs_equation_common.c:123
cs_real_t * reaction_term
Definition: cs_equation_common.h:229
cs_equation_builder_t * cs_equation_init_builder(const cs_equation_param_t *eqp, const cs_mesh_t *mesh)
Allocate a new structure to handle the building of algebraic system related to an cs_equation_t struc...
Definition: cs_equation_common.c:267
Definition: cs_cdo_bc.h:88
cs_eflag_t st_msh_flag
Definition: cs_equation_common.h:121
cs_real_t * cs_equation_get_tmpbuf(void)
Retrieve a pointer to a buffer of size at least the 2*n_cells The size of the temporary buffer can be...
Definition: cs_equation_common.c:1119
cs_cdo_bc_face_t * face_bc
Definition: cs_equation_common.h:192
Definition: cs_range_set.h:57
void cs_equation_build_dof_enforcement(cs_lnum_t n_x, const cs_adjacency_t *c2x, const cs_equation_param_t *eqp, cs_lnum_t *p_dof_ids[])
Build the list of degrees of freedom (DoFs) related to an internal enforcement. If set to NULL...
Definition: cs_equation_common.c:848
Set of local and temporary buffers useful for building the algebraic system with a cellwise process...
Definition: cs_cdo_local.h:69
Structure storing medata for defining a quantity in a very flexible way.
Definition: cs_xdef.h:154
bool curlcurl_pty_uniform
Definition: cs_equation_common.h:133
cs_eflag_t bd_msh_flag
Definition: cs_equation_common.h:118
void cs_equation_balance_reset(cs_equation_balance_t *b)
Reset a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1186
cs_eflag_t msh_flag
Definition: cs_equation_common.h:115
cs_equation_user_hook_t * user_hook_function
Definition: cs_equation_common.h:177
#define CS_CDO_N_MAX_REACTIONS
Definition: cs_param_cdo.h:70
cs_real_t * diffusion_term
Definition: cs_equation_common.h:230
void cs_equation_write_monitoring(const char *eqname, const cs_equation_builder_t *eqb)
Print a message in the performance output file related to the monitoring of equation.
Definition: cs_equation_common.c:689
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
void cs_equation_balance_sync(const cs_cdo_connect_t *connect, cs_equation_balance_t *b)
Synchronize balance terms if this is a parallel computation.
Definition: cs_equation_common.c:1211
void cs_equation_prepare_system(int stride, cs_lnum_t x_size, const cs_matrix_t *matrix, const cs_range_set_t *rset, bool rhs_redux, cs_real_t *x, cs_real_t *b)
Prepare a linear system and synchronize buffers to handle parallelism. Transfer a mesh-based descript...
Definition: cs_equation_common.c:449
#define END_C_DECLS
Definition: cs_defs.h:496
unsigned short int cs_flag_t
Definition: cs_defs.h:309
void cs_equation_sync_vertex_mean_values(const cs_cdo_connect_t *connect, int dim, int *counter, cs_real_t *values)
Compute the mean-value across ranks at each vertex.
Definition: cs_equation_common.c:1558
void cs_equation_sync_vol_def_at_edges(const cs_cdo_connect_t *connect, int n_defs, cs_xdef_t **defs, cs_lnum_t def2e_idx[], cs_lnum_t def2e_ids[])
Synchronize the volumetric definitions to consider at each edge.
Definition: cs_equation_common.c:1365
#define CS_N_MAX_SOURCE_TERMS
Definition: cs_source_term.h:49
cs_real_t * unsteady_term
Definition: cs_equation_common.h:228
bool init_step
Definition: cs_equation_common.h:108
unsigned int cs_eflag_t
Definition: cs_flag.h:166
size_t cs_equation_get_tmpbuf_size(void)
Get the allocation size of the temporary buffer.
Definition: cs_equation_common.c:1133
void cs_equation_sync_vol_def_at_faces(const cs_cdo_connect_t *connect, int n_defs, cs_xdef_t **defs, cs_lnum_t def2f_idx[], cs_lnum_t def2f_ids[])
Synchronize the volumetric definitions to consider at each face.
Definition: cs_equation_common.c:1462
void * user_hook_context
Definition: cs_equation_common.h:176
void() cs_equation_user_hook_t(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, const void *eq_context, const cs_cell_mesh_t *cm, cs_hodge_t *mass_hodge, cs_hodge_t *diff_hodge, cs_cell_sys_t *csys, cs_cell_builder_t *cb)
Generic function prototype for a hook during the cellwise building of the linear system Enable an adv...
Definition: cs_equation_common.h:92
void cs_equation_sync_vol_def_at_vertices(const cs_cdo_connect_t *connect, int n_defs, cs_xdef_t **defs, cs_lnum_t def2v_idx[], cs_lnum_t def2v_ids[])
Synchronize the volumetric definitions to consider at each vertex.
Definition: cs_equation_common.c:1268
void cs_equation_balance_destroy(cs_equation_balance_t **p_balance)
Free a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1242
Structure and routines handling the specific settings related to a cs_equation_t structure.
void cs_equation_common_finalize(void)
Allocate a pointer to a buffer of size at least the 2*n_cells for managing temporary usage of memory ...
Definition: cs_equation_common.c:245
void cs_equation_enforced_internal_block_dofs(const cs_equation_param_t *eqp, cs_cell_builder_t *cb, cs_cell_sys_t *csys)
Take into account the enforcement of internal DoFs. Case of matrices defined by blocks. Apply an algebraic manipulation.
Definition: cs_equation_common.c:1006
cs_timer_counter_t tcb
Definition: cs_equation_common.h:204
Structure storing all metadata related to the resolution of a linear system with an iterative solver...
Definition: cs_param_sles.h:62
Definition: mesh.f90:26
void cs_equation_set_reaction_properties_cw(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb)
Initialize all reaction properties. This function is shared across all CDO schemes. The cs_cell_builder_t structure stores the computed property values. If the property is uniform, a first call to the function cs_equation_init_reaction_properties or to the function cs_equation_init_properties has to be done before the loop on cells.
Definition: cs_equation_common.c:761
void() cs_source_term_cellwise_t(const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_real_t time_eval, cs_cell_builder_t *cb, void *input, double *values)
Compute the contribution for a cell related to a source term and add it to the given array of values...
Definition: cs_source_term.h:85
Definition: cs_timer.h:57
double precision, save b
Definition: cs_fuel_incl.f90:146
cs_timer_counter_t tce
Definition: cs_equation_common.h:208
#define CS_FLAG_BOUNDARY_CELL_BY_FACE
(= 1) boundary cell with at least one border face
Definition: cs_flag.h:62