7.1
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  * Functions 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_enforcement.h"
38 #include "cs_equation_param.h"
39 #include "cs_flag.h"
40 #include "cs_matrix.h"
41 #include "cs_time_step.h"
42 #include "cs_timer.h"
43 #include "cs_sles.h"
44 #include "cs_source_term.h"
45 
46 /*----------------------------------------------------------------------------*/
47 
49 
50 /*============================================================================
51  * Macro definitions
52  *============================================================================*/
53 
54 /* Strategy of synchronization of values shared across several cells
55  * This applies to vertices, edges and faces
56  *
57  * CS_EQUATION_SYNC_ZERO_VALUE
58  * If zero is a possible value then set this value, otherwise one takes
59  * the mean-value
60  *
61  * CS_EQUATION_SYNC_MEAN_VALUE
62  * Compute the mean-value across values to set
63  *
64  */
65 
66 #define CS_EQUATION_SYNC_ZERO_VALUE 1
67 #define CS_EQUATION_SYNC_MEAN_VALUE 2
68 
69 /*============================================================================
70  * Type definitions
71  *============================================================================*/
72 
74 
75 /*----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------*/
91 
92 typedef void
94  const cs_equation_builder_t *eqb,
95  const void *eq_context,
96  const cs_cell_mesh_t *cm,
97  cs_hodge_t *mass_hodge,
98  cs_hodge_t *diff_hodge,
99  cs_cell_sys_t *csys,
100  cs_cell_builder_t *cb);
101 
108 
109  bool init_step;
156 
164 
187 
226 };
227 
228 /*
229  * Structure used to store information generated during the analysis
230  * of the balance of each term of an equation
231  */
232 
233 typedef struct {
234 
235  /* where balance is computed: primal vertices or primal cells */
236 
240 
241  /* Balance for each main term */
242 
249 
251 
252 /*============================================================================
253  * Inline public function prototypes
254  *============================================================================*/
255 
256 /*----------------------------------------------------------------------------*/
265 /*----------------------------------------------------------------------------*/
266 
267 static inline cs_eflag_t
268 cs_equation_cell_mesh_flag(cs_flag_t cell_flag,
269  const cs_equation_builder_t *eqb)
270 {
271  cs_eflag_t _flag = eqb->msh_flag | eqb->st_msh_flag;
272 
273  if (cell_flag & CS_FLAG_BOUNDARY_CELL_BY_FACE)
274  _flag |= eqb->bd_msh_flag;
275 
276  return _flag;
277 }
278 
279 /*============================================================================
280  * Public function prototypes
281  *============================================================================*/
282 
283 /*----------------------------------------------------------------------------*/
300 /*----------------------------------------------------------------------------*/
301 
302 void
304  const cs_cdo_quantities_t *quant,
305  const cs_time_step_t *time_step,
306  cs_flag_t eb_flag,
307  cs_flag_t fb_flag,
308  cs_flag_t vb_flag,
309  cs_flag_t vcb_flag,
310  cs_flag_t hho_flag);
311 
312 /*----------------------------------------------------------------------------*/
321 /*----------------------------------------------------------------------------*/
322 
323 void
325 
326 /*----------------------------------------------------------------------------*/
336 /*----------------------------------------------------------------------------*/
337 
340  const cs_mesh_t *mesh);
341 
342 /*----------------------------------------------------------------------------*/
349 /*----------------------------------------------------------------------------*/
350 
351 void
353 
354 /*----------------------------------------------------------------------------*/
360 /*----------------------------------------------------------------------------*/
361 
362 void
364 
365 /*----------------------------------------------------------------------------*/
378 /*----------------------------------------------------------------------------*/
379 
380 void
382  cs_lnum_t rhs_size,
383  const cs_real_t rhs[],
384  double *normalization);
385 
386 /*----------------------------------------------------------------------------*/
400 /*----------------------------------------------------------------------------*/
401 
402 void
403 cs_equation_prepare_system(int stride,
404  cs_lnum_t x_size,
405  const cs_matrix_t *matrix,
406  const cs_range_set_t *rset,
407  bool rhs_redux,
408  cs_real_t *x,
409  cs_real_t *b);
410 
411 /*----------------------------------------------------------------------------*/
426 /*----------------------------------------------------------------------------*/
427 
428 int
430  const cs_param_sles_t *slesp,
431  const cs_matrix_t *matrix,
432  cs_real_t normalization,
433  cs_sles_t *sles,
434  cs_real_t *x,
435  cs_real_t *b);
436 
437 /*----------------------------------------------------------------------------*/
454 /*----------------------------------------------------------------------------*/
455 
456 int
458  const cs_param_sles_t *slesp,
459  const cs_matrix_t *matrix,
460  const cs_range_set_t *rset,
461  cs_real_t normalization,
462  bool rhs_redux,
463  cs_sles_t *sles,
464  cs_real_t *x,
465  cs_real_t *b);
466 
467 /*----------------------------------------------------------------------------*/
475 /*----------------------------------------------------------------------------*/
476 
477 void
478 cs_equation_write_monitoring(const char *eqname,
479  const cs_equation_builder_t *eqb);
480 
481 /*----------------------------------------------------------------------------*/
492 /*----------------------------------------------------------------------------*/
493 
494 void
496  const cs_equation_builder_t *eqb,
497  cs_real_t t_eval,
498  cs_cell_builder_t *cb);
499 
500 /*----------------------------------------------------------------------------*/
515 /*----------------------------------------------------------------------------*/
516 
517 void
519  const cs_equation_builder_t *eqb,
520  const cs_cell_mesh_t *cm,
521  cs_cell_builder_t *cb);
522 
523 /*----------------------------------------------------------------------------*/
535 /*----------------------------------------------------------------------------*/
536 
537 void
539  const cs_equation_builder_t *eqb,
540  cs_hodge_t *diffusion_hodge,
541  cs_cell_builder_t *cb);
542 
543 /*----------------------------------------------------------------------------*/
555 /*----------------------------------------------------------------------------*/
556 
557 void
559  const cs_adjacency_t *c2x,
560  const cs_interface_set_t *ifs,
561  const cs_equation_param_t *eqp,
562  cs_lnum_t *p_dof_ids[]);
563 
564 /*----------------------------------------------------------------------------*/
582 /*----------------------------------------------------------------------------*/
583 
584 void
586  cs_cell_builder_t *cb,
587  cs_cell_sys_t *csys);
588 
589 /*----------------------------------------------------------------------------*/
607 /*----------------------------------------------------------------------------*/
608 
609 void
611  cs_cell_builder_t *cb,
612  cs_cell_sys_t *csys);
613 
614 /*----------------------------------------------------------------------------*/
622 /*----------------------------------------------------------------------------*/
623 
624 cs_real_t *
626 
627 /*----------------------------------------------------------------------------*/
633 /*----------------------------------------------------------------------------*/
634 
635 size_t
637 
638 /*----------------------------------------------------------------------------*/
647 /*----------------------------------------------------------------------------*/
648 
651  cs_lnum_t size);
652 
653 /*----------------------------------------------------------------------------*/
659 /*----------------------------------------------------------------------------*/
660 
661 void
663 
664 /*----------------------------------------------------------------------------*/
671 /*----------------------------------------------------------------------------*/
672 
673 void
676 
677 /*----------------------------------------------------------------------------*/
683 /*----------------------------------------------------------------------------*/
684 
685 void
687 
688 /*----------------------------------------------------------------------------*/
698 /*----------------------------------------------------------------------------*/
699 
700 void
702  int n_defs,
703  cs_xdef_t **defs,
704  cs_lnum_t def2v_idx[],
705  cs_lnum_t def2v_ids[]);
706 
707 /*----------------------------------------------------------------------------*/
717 /*----------------------------------------------------------------------------*/
718 
719 void
721  int n_defs,
722  cs_xdef_t **defs,
723  cs_lnum_t def2e_idx[],
724  cs_lnum_t def2e_ids[]);
725 
726 /*----------------------------------------------------------------------------*/
736 /*----------------------------------------------------------------------------*/
737 
738 void
740  int n_defs,
741  cs_xdef_t **defs,
742  cs_lnum_t def2f_idx[],
743  cs_lnum_t def2f_ids[]);
744 
745 /*----------------------------------------------------------------------------*/
754 /*----------------------------------------------------------------------------*/
755 
756 void
758  int dim,
759  int *counter,
760  cs_real_t *values);
761 
762 /*----------------------------------------------------------------------------*/
763 
765 
766 #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:673
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:218
cs_real_t * dir_values
Definition: cs_equation_common.h:204
Definition: cs_equation_common.h:107
bool diff_pty_uniform
Definition: cs_equation_common.h:133
cs_param_resnorm_type_t
Definition: cs_param_types.h:901
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:177
cs_source_term_cellwise_t * compute_source[CS_N_MAX_SOURCE_TERMS]
Definition: cs_equation_common.h:155
Definition: cs_mesh_adjacencies.h:68
cs_real_t * boundary_term
Definition: cs_equation_common.h:248
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
cs_real_t * balance
Definition: cs_equation_common.h:239
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 No rotation is taken into account wh...
Definition: cs_equation_common.c:578
cs_lnum_t size
Definition: cs_equation_common.h:238
Set of local quantities and connectivities related to a mesh cell.
Definition: cs_cdo_local.h:202
bool graddiv_pty_uniform
Definition: cs_equation_common.h:135
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:802
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:871
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:1133
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:435
cs_flag_t location
Definition: cs_equation_common.h:237
Definition: cs_cdo_connect.h:79
void cs_equation_enforced_internal_block_dofs(const cs_equation_builder_t *eqb, 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. Update members of the cs_cell_sys_t structure related to the internal enforcement.
Definition: cs_equation_common.c:1007
cs_mask_t * source_mask
Definition: cs_equation_common.h:146
Structure associated to a discrete Hodge operator *.
Definition: cs_hodge.h:186
cs_equation_builder_t * cs_equation_builder_init(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:277
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
Definition: cs_cdo_quantities.h:129
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:111
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:146
cs_real_t * advection_term
Definition: cs_equation_common.h:246
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:93
bool reac_pty_uniform[CS_CDO_N_MAX_REACTIONS]
Definition: cs_equation_common.h:137
Definition: cs_mesh.h:84
cs_flag_t sys_flag
Definition: cs_equation_common.h:125
cs_real_t * source_term
Definition: cs_equation_common.h:247
struct _cs_sles_t cs_sles_t
Definition: cs_sles.h:68
Definition: cs_equation_common.h:233
bool time_pty_uniform
Definition: cs_equation_common.h:136
void cs_equation_builder_free(cs_equation_builder_t **p_builder)
Free a cs_equation_builder_t structure.
Definition: cs_equation_common.c:378
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:125
cs_real_t * reaction_term
Definition: cs_equation_common.h:244
void cs_equation_build_dof_enforcement(cs_lnum_t n_x, const cs_adjacency_t *c2x, const cs_interface_set_t *ifs, 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...
cs_real_t * enforced_values
Definition: cs_equation_common.h:163
Definition: cs_cdo_bc.h:88
cs_eflag_t st_msh_flag
Definition: cs_equation_common.h:122
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:1102
cs_cdo_bc_face_t * face_bc
Definition: cs_equation_common.h:201
void cs_equation_builder_reset(cs_equation_builder_t *eqb)
Free some members of a cs_equation_builder_t structure.
Definition: cs_equation_common.c:410
Definition: cs_range_set.h:57
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:61
Set of local and temporary buffers.
Definition: cs_cdo_local.h:60
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:134
cs_eflag_t bd_msh_flag
Definition: cs_equation_common.h:119
void cs_equation_balance_reset(cs_equation_balance_t *b)
Reset a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1170
cs_eflag_t msh_flag
Definition: cs_equation_common.h:116
cs_equation_user_hook_t * user_hook_function
Definition: cs_equation_common.h:186
#define CS_CDO_N_MAX_REACTIONS
Definition: cs_param_cdo.h:70
cs_real_t * diffusion_term
Definition: cs_equation_common.h:245
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:765
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
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:1195
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:491
#define END_C_DECLS
Definition: cs_defs.h:511
unsigned short int cs_flag_t
Definition: cs_defs.h:324
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:1562
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:1355
#define CS_N_MAX_SOURCE_TERMS
Definition: cs_source_term.h:49
cs_real_t * unsteady_term
Definition: cs_equation_common.h:243
bool init_step
Definition: cs_equation_common.h:109
void cs_equation_enforced_internal_dofs(const cs_equation_builder_t *eqb, cs_cell_builder_t *cb, cs_cell_sys_t *csys)
Take into account the enforcement of internal DoFs. Apply an algebraic manipulation. Update members of the cs_cell_sys_t structure related to the internal enforcement.
Definition: cs_equation_common.c:935
unsigned int cs_eflag_t
Definition: cs_flag.h:170
size_t cs_equation_get_tmpbuf_size(void)
Get the allocation size of the temporary buffer.
Definition: cs_equation_common.c:1116
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:1459
void * user_hook_context
Definition: cs_equation_common.h:185
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:93
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:1251
void cs_equation_balance_destroy(cs_equation_balance_t **p_balance)
Free a cs_equation_balance_t structure.
Definition: cs_equation_common.c:1225
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:253
cs_timer_counter_t tcb
Definition: cs_equation_common.h:216
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:837
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:70
Definition: cs_timer.h:55
double precision, save b
Definition: cs_fuel_incl.f90:146
cs_timer_counter_t tce
Definition: cs_equation_common.h:220
#define CS_FLAG_BOUNDARY_CELL_BY_FACE
(= 1) boundary cell with at least one border face
Definition: cs_flag.h:62