6.2
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 /*----------------------------------------------------------------------------*/
376 /*----------------------------------------------------------------------------*/
377 
378 cs_gnum_t
379 cs_equation_prepare_system(int stride,
380  cs_lnum_t x_size,
381  const cs_matrix_t *matrix,
382  const cs_range_set_t *rset,
383  bool rhs_redux,
384  cs_real_t *x,
385  cs_real_t *b);
386 
387 /*----------------------------------------------------------------------------*/
404 /*----------------------------------------------------------------------------*/
405 
406 int
408  const cs_equation_param_t *eqp,
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__ */
Store common elements used when building an algebraic system related to an equation.
time step descriptor
Definition: cs_time_step.h:64
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
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:655
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:201
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_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
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:158
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:678
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:746
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:1102
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_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:871
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
int cs_equation_solve_scalar_system(cs_lnum_t n_scatter_dofs, const cs_equation_param_t *eqp, 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:546
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:74
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:126
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:270
cs_gnum_t 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:454
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:1071
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:800
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:136
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:1138
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:641
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:1163
#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:1522
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:1321
#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:1085
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:1422
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:1220
void cs_equation_balance_destroy(cs_equation_balance_t **p_balance)
Free a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1194
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:248
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:958
cs_timer_counter_t tcb
Definition: cs_equation_common.h:204
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:713
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