6.3
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-2020 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 /*----------------------------------------------------------------------------*/
403 /*----------------------------------------------------------------------------*/
404 
405 int
407  const char *eqname,
408  const cs_param_sles_t slesp,
409  const cs_matrix_t *matrix,
410  const cs_range_set_t *rset,
411  cs_real_t normalization,
412  bool rhs_redux,
413  cs_sles_t *sles,
414  cs_real_t *x,
415  cs_real_t *b);
416 
417 /*----------------------------------------------------------------------------*/
425 /*----------------------------------------------------------------------------*/
426 
427 void
428 cs_equation_write_monitoring(const char *eqname,
429  const cs_equation_builder_t *eqb);
430 
431 /*----------------------------------------------------------------------------*/
442 /*----------------------------------------------------------------------------*/
443 
444 void
446  const cs_equation_builder_t *eqb,
447  cs_real_t t_eval,
448  cs_cell_builder_t *cb);
449 
450 /*----------------------------------------------------------------------------*/
465 /*----------------------------------------------------------------------------*/
466 
467 void
469  const cs_equation_builder_t *eqb,
470  const cs_cell_mesh_t *cm,
471  cs_cell_builder_t *cb);
472 
473 /*----------------------------------------------------------------------------*/
485 /*----------------------------------------------------------------------------*/
486 
487 void
489  const cs_equation_builder_t *eqb,
490  cs_hodge_t *diffusion_hodge,
491  cs_cell_builder_t *cb);
492 
493 /*----------------------------------------------------------------------------*/
504 /*----------------------------------------------------------------------------*/
505 
506 void
508  const cs_adjacency_t *c2x,
509  const cs_equation_param_t *eqp,
510  cs_lnum_t *p_dof_ids[]);
511 
512 /*----------------------------------------------------------------------------*/
529 /*----------------------------------------------------------------------------*/
530 
531 void
533  cs_cell_builder_t *cb,
534  cs_cell_sys_t *csys);
535 
536 /*----------------------------------------------------------------------------*/
553 /*----------------------------------------------------------------------------*/
554 
555 void
557  cs_cell_builder_t *cb,
558  cs_cell_sys_t *csys);
559 
560 /*----------------------------------------------------------------------------*/
568 /*----------------------------------------------------------------------------*/
569 
570 cs_real_t *
572 
573 /*----------------------------------------------------------------------------*/
579 /*----------------------------------------------------------------------------*/
580 
581 size_t
583 
584 /*----------------------------------------------------------------------------*/
593 /*----------------------------------------------------------------------------*/
594 
597  cs_lnum_t size);
598 
599 /*----------------------------------------------------------------------------*/
605 /*----------------------------------------------------------------------------*/
606 
607 void
609 
610 /*----------------------------------------------------------------------------*/
617 /*----------------------------------------------------------------------------*/
618 
619 void
622 
623 /*----------------------------------------------------------------------------*/
629 /*----------------------------------------------------------------------------*/
630 
631 void
633 
634 /*----------------------------------------------------------------------------*/
644 /*----------------------------------------------------------------------------*/
645 
646 void
648  int n_defs,
649  cs_xdef_t **defs,
650  cs_lnum_t def2v_idx[],
651  cs_lnum_t def2v_ids[]);
652 
653 /*----------------------------------------------------------------------------*/
663 /*----------------------------------------------------------------------------*/
664 
665 void
667  int n_defs,
668  cs_xdef_t **defs,
669  cs_lnum_t def2e_idx[],
670  cs_lnum_t def2e_ids[]);
671 
672 /*----------------------------------------------------------------------------*/
682 /*----------------------------------------------------------------------------*/
683 
684 void
686  int n_defs,
687  cs_xdef_t **defs,
688  cs_lnum_t def2f_idx[],
689  cs_lnum_t def2f_ids[]);
690 
691 /*----------------------------------------------------------------------------*/
700 /*----------------------------------------------------------------------------*/
701 
702 void
704  int dim,
705  int *counter,
706  cs_real_t *values);
707 
708 /*----------------------------------------------------------------------------*/
709 
711 
712 #endif /* __CS_EQUATION_COMMON_H__ */
cs_equation_init_builder
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:270
_equation_builder_t::tcb
cs_timer_counter_t tcb
Definition: cs_equation_common.h:204
cs_equation_balance_t::unsteady_term
cs_real_t * unsteady_term
Definition: cs_equation_common.h:228
cs_equation_user_hook_t
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
cs_equation_balance_t::diffusion_term
cs_real_t * diffusion_term
Definition: cs_equation_common.h:230
_equation_builder_t::tce
cs_timer_counter_t tce
Definition: cs_equation_common.h:208
cs_equation_balance_t
Definition: cs_equation_common.h:220
cs_xdef_t
Structure storing medata for defining a quantity in a very flexible way.
Definition: cs_xdef.h:154
cs_equation_write_monitoring
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:629
_equation_builder_t::tcs
cs_timer_counter_t tcs
Definition: cs_equation_common.h:206
_equation_builder_t::diff_pty_uniform
bool diff_pty_uniform
Definition: cs_equation_common.h:132
cs_source_term.h
cs_timer_counter_t
Definition: cs_timer.h:57
cs_fuel_incl::b
double precision, save b
Definition: cs_fuel_incl.f90:146
_equation_builder_t::compute_source
cs_source_term_cellwise_t * compute_source[CS_N_MAX_SOURCE_TERMS]
Definition: cs_equation_common.h:154
cs_equation_set_reaction_properties_cw
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....
Definition: cs_equation_common.c:701
cs_equation_balance_t::location
cs_flag_t location
Definition: cs_equation_common.h:223
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:493
cs_equation_get_tmpbuf
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:1059
cs_equation_sync_rhs_normalization
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:396
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:304
cs_param_resnorm_type_t
cs_param_resnorm_type_t
Definition: cs_param_types.h:716
_equation_builder_t::graddiv_pty_uniform
bool graddiv_pty_uniform
Definition: cs_equation_common.h:134
cs_equation_balance_t::size
cs_lnum_t size
Definition: cs_equation_common.h:224
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:492
cs_equation_balance_t::reaction_term
cs_real_t * reaction_term
Definition: cs_equation_common.h:229
cs_matrix_t
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:94
_equation_builder_t::sys_flag
cs_flag_t sys_flag
Definition: cs_equation_common.h:124
cs_cdo_bc.h
_equation_builder_t::reac_pty_uniform
bool reac_pty_uniform[CS_CDO_N_MAX_REACTIONS]
Definition: cs_equation_common.h:136
cs_equation_free_builder
void cs_equation_free_builder(cs_equation_builder_t **p_builder)
Free a cs_equation_builder_t structure.
Definition: cs_equation_common.c:360
cs_cdo_quantities.h
_equation_builder_t::source_mask
cs_mask_t * source_mask
Definition: cs_equation_common.h:145
mesh
Definition: mesh.f90:26
cs_equation_sync_vertex_mean_values
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:1510
cs_equation_sync_vol_def_at_faces
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:1410
CS_N_MAX_SOURCE_TERMS
#define CS_N_MAX_SOURCE_TERMS
Definition: cs_source_term.h:49
cs_source_term_cellwise_t
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
cs_equation_param_t
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition: cs_equation_param.h:201
cs_equation_balance_t::balance
cs_real_t * balance
Definition: cs_equation_common.h:225
CS_CDO_N_MAX_REACTIONS
#define CS_CDO_N_MAX_REACTIONS
Definition: cs_param_cdo.h:69
_equation_builder_t::time_pty_uniform
bool time_pty_uniform
Definition: cs_equation_common.h:135
_equation_builder_t::face_bc
cs_cdo_bc_face_t * face_bc
Definition: cs_equation_common.h:192
cs_time_step_t
time step descriptor
Definition: cs_time_step.h:64
CS_FLAG_BOUNDARY_CELL_BY_FACE
#define CS_FLAG_BOUNDARY_CELL_BY_FACE
(= 1) boundary cell with at least one border face
Definition: cs_flag.h:62
cs_cdo_bc_face_t
Definition: cs_cdo_bc.h:88
_equation_builder_t::bd_msh_flag
cs_eflag_t bd_msh_flag
Definition: cs_equation_common.h:118
_equation_builder_t::st_msh_flag
cs_eflag_t st_msh_flag
Definition: cs_equation_common.h:121
_equation_builder_t::curlcurl_pty_uniform
bool curlcurl_pty_uniform
Definition: cs_equation_common.h:133
cs_cdo_quantities_t
Definition: cs_cdo_quantities.h:124
_equation_builder_t::user_hook_function
cs_equation_user_hook_t * user_hook_function
Definition: cs_equation_common.h:177
cs_hodge_t
Structure associated to a discrete Hodge operator.
Definition: cs_hodge.h:189
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_cdo_connect_t
Definition: cs_cdo_connect.h:76
cs_range_set_t
Definition: cs_range_set.h:57
cs_equation_balance_t::source_term
cs_real_t * source_term
Definition: cs_equation_common.h:232
cs_equation_balance_reset
void cs_equation_balance_reset(cs_equation_balance_t *b)
Reset a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1126
cs_cell_builder_t
Set of local and temporary buffers useful for building the algebraic system with a cellwise process....
Definition: cs_cdo_local.h:69
cs_adjacency_t
Definition: cs_mesh_adjacencies.h:67
cs_equation_solve_scalar_system
int cs_equation_solve_scalar_system(cs_lnum_t n_scatter_dofs, const char *eqname, 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:539
cs_flag.h
cs_equation_get_tmpbuf_size
size_t cs_equation_get_tmpbuf_size(void)
Get the allocation size of the temporary buffer.
Definition: cs_equation_common.c:1073
cs_cdo_connect.h
cs_equation_balance_destroy
void cs_equation_balance_destroy(cs_equation_balance_t **p_balance)
Free a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1182
cs_mask_t
unsigned char cs_mask_t
Definition: cs_flag.h:143
cs_time_step.h
_equation_builder_t
Definition: cs_equation_common.h:106
cs_sles_t
struct _cs_sles_t cs_sles_t
Definition: cs_sles.h:68
_equation_builder_t::msh_flag
cs_eflag_t msh_flag
Definition: cs_equation_common.h:115
cs_equation_sync_vol_def_at_edges
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:1309
_equation_builder_t::init_step
bool init_step
Definition: cs_equation_common.h:108
cs_equation_builder_t
Store common elements used when building an algebraic system related to an equation.
cs_equation_balance_t::boundary_term
cs_real_t * boundary_term
Definition: cs_equation_common.h:233
_equation_builder_t::user_hook_context
void * user_hook_context
Definition: cs_equation_common.h:176
cs_equation_build_dof_enforcement
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:788
cs_equation_init_reaction_properties
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....
Definition: cs_equation_common.c:666
cs_flag_t
unsigned short int cs_flag_t
Definition: cs_defs.h:306
cs_sles.h
matrix
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
cs_matrix.h
cs_equation_balance_sync
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:1151
cs_equation_prepare_system
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:452
cs_equation_param.h
Structure and routines handling the specific settings related to a cs_equation_t structure.
cs_cell_sys_t
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_equation_common_init
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:126
cs_param_sles_t
Structure storing all metadata related to the resolution of a linear system with an iterative solver.
Definition: cs_param_types.h:736
cs_equation_enforced_internal_block_dofs
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....
Definition: cs_equation_common.c:946
cs_cell_mesh_t
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
cs_equation_sync_vol_def_at_vertices
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:1208
cs_equation_enforced_internal_dofs
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:859
cs_mesh_t
Definition: cs_mesh.h:84
cs_equation_init_properties
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:734
cs_equation_balance_create
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:1090
cs_timer.h
cs_equation_balance_t::advection_term
cs_real_t * advection_term
Definition: cs_equation_common.h:231
cs_equation_common_finalize
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:248
cs_cdo_local.h
cs_eflag_t
unsigned int cs_eflag_t
Definition: cs_flag.h:166