programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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-2017 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_quantities.h"
36 #include "cs_cdo_time.h"
37 #include "cs_equation_param.h"
38 #include "cs_matrix.h"
39 #include "cs_time_step.h"
40 #include "cs_timer.h"
41 #include "cs_source_term.h"
42 
43 /*----------------------------------------------------------------------------*/
44 
46 
47 /*============================================================================
48  * Macro definitions
49  *============================================================================*/
50 
51 /*============================================================================
52  * Type definitions
53  *============================================================================*/
54 
55 /* Store common elements used when building an algebraic system related to
56  an equation */
57 typedef struct {
58 
59  /* Shortcut to know what to build */
60  cs_flag_t msh_flag; // Information related to cell mesh
61  cs_flag_t bd_msh_flag; // Information related to cell mesh (boundary)
62  cs_flag_t st_msh_flag; // Information related to cell mesh (source term)
63  cs_flag_t sys_flag; // Information related to the sytem
64 
65  /* Metadata related to associated properties */
68  bool reac_pty_uniform[CS_CDO_N_MAX_REACTIONS];
69 
70  /* Source terms */
71  cs_mask_t *source_mask; /* NULL if at least one source term is not
72  defined for all cells (size = n_cells) */
73 
74  /* Pointer to functions which compute the value of the source term */
76 
77  /* Boundary conditions:
78 
79  face_bc should not change during the simulation.
80  The case of a definition of the BCs which changes of type during the
81  simulation is possible but not implemented.
82  You just have to call the initialization step each time the type of BCs
83  is modified to define an updated cs_cdo_bc_t structure.
84  */
85 
86  cs_cdo_bc_t *face_bc; // list of faces sorted by type of BCs
87 
88  /* Monitoring the efficiency of the algorithm used to manipulate/build
89  an equation builder. */
90  cs_timer_counter_t tcb; /* Cumulated elapsed time for building
91  the current system */
92  /* tcb >= tcd + tca + tcr + tcs */
93  cs_timer_counter_t tcd; /* Cumulated elapsed time for building
94  diffusion terms */
95  cs_timer_counter_t tca; /* Cumulated elapsed time for building
96  advection terms */
97  cs_timer_counter_t tcr; /* Cumulated elapsed time for building
98  reaction terms */
99  cs_timer_counter_t tcs; /* Cumulated elapsed time for building
100  source terms */
101 
102  cs_timer_counter_t tce; /* Cumulated elapsed time for computing
103  all extra operations (post, balance,
104  fluxes...) */
105 
107 
108 /*============================================================================
109  * Inline public function prototypes
110  *============================================================================*/
111 
112 /*----------------------------------------------------------------------------*/
121 /*----------------------------------------------------------------------------*/
122 
123 static inline cs_flag_t
125  const cs_equation_builder_t *eqb)
126 {
127  cs_flag_t _flag = eqb->msh_flag | eqb->st_msh_flag;
128 
129  if (cell_flag & CS_FLAG_BOUNDARY)
130  _flag |= eqb->bd_msh_flag;
131 
132  return _flag;
133 }
134 
135 /*============================================================================
136  * Public function prototypes
137  *============================================================================*/
138 
139 /*----------------------------------------------------------------------------*/
155 /*----------------------------------------------------------------------------*/
156 
157 void
159  const cs_cdo_quantities_t *quant,
160  const cs_time_step_t *time_step,
161  cs_flag_t scheme_flag);
162 
163 /*----------------------------------------------------------------------------*/
175 /*----------------------------------------------------------------------------*/
176 
177 void
179 
180 /*----------------------------------------------------------------------------*/
190 /*----------------------------------------------------------------------------*/
191 
194  const cs_mesh_t *mesh);
195 
196 /*----------------------------------------------------------------------------*/
203 /*----------------------------------------------------------------------------*/
204 
205 void
207 
208 /*----------------------------------------------------------------------------*/
216 /*----------------------------------------------------------------------------*/
217 
218 void
219 cs_equation_write_monitoring(const char *eqname,
220  const cs_equation_builder_t *eqb);
221 
222 /*----------------------------------------------------------------------------*/
233 /*----------------------------------------------------------------------------*/
234 
235 void
237  const cs_equation_builder_t *eqb,
238  double *tpty_val,
239  double *rpty_vals,
240  cs_cell_builder_t *cb);
241 
242 /*----------------------------------------------------------------------------*/
251 /*----------------------------------------------------------------------------*/
252 
253 void
255  cs_lnum_t c_id,
256  cs_flag_t c_flag,
257  cs_cell_builder_t *cb);
258 
259 /*----------------------------------------------------------------------------*/
269 /*----------------------------------------------------------------------------*/
270 
271 void
273  const cs_cell_mesh_t *cm,
274  cs_flag_t c_flag,
275  cs_cell_builder_t *cb);
276 
277 /*----------------------------------------------------------------------------*/
289 /*----------------------------------------------------------------------------*/
290 
291 cs_real_t *
293  const cs_equation_param_t *eqp,
294  const cs_cdo_bc_list_t *dir,
295  cs_cell_builder_t *cb);
296 
297 /*----------------------------------------------------------------------------*/
309 /*----------------------------------------------------------------------------*/
310 
311 cs_real_t *
313  const cs_equation_param_t *eqp,
314  const cs_cdo_bc_list_t *dir,
315  cs_cell_builder_t *cb);
316 
317 /*----------------------------------------------------------------------------*/
326 /*----------------------------------------------------------------------------*/
327 
328 short int *
330 
331 /*----------------------------------------------------------------------------*/
343 /*----------------------------------------------------------------------------*/
344 
345 void
346 cs_equation_compute_neumann_sv(short int def_id,
347  short int f,
348  const cs_equation_param_t *eqp,
349  const cs_cell_mesh_t *cm,
350  cs_cell_bc_t *cbc);
351 
352 /*----------------------------------------------------------------------------*/
364 /*----------------------------------------------------------------------------*/
365 
366 void
367 cs_equation_compute_neumann_sf(short int def_id,
368  short int f,
369  const cs_equation_param_t *eqp,
370  const cs_cell_mesh_t *cm,
371  cs_cell_bc_t *cbc);
372 
373 /*----------------------------------------------------------------------------*/
385 /*----------------------------------------------------------------------------*/
386 
387 void
389  const cs_range_set_t *rset,
390  const cs_equation_param_t *eqp,
391  cs_real_t *rhs,
392  cs_real_t *sources,
394 
395 /*----------------------------------------------------------------------------*/
406 /*----------------------------------------------------------------------------*/
407 
408 void
410  const cs_range_set_t *rset,
411  const cs_equation_param_t *eqp,
412  cs_real_t *rhs,
414 
415 /*----------------------------------------------------------------------------*/
424 /*----------------------------------------------------------------------------*/
425 
426 const cs_matrix_structure_t *
428 
429 /*----------------------------------------------------------------------------*/
438 /*----------------------------------------------------------------------------*/
439 
440 const cs_matrix_assembler_t *
442 
443 /*----------------------------------------------------------------------------*/
449 /*----------------------------------------------------------------------------*/
450 
451 const cs_adjacency_t *
453 
454 /*----------------------------------------------------------------------------*/
460 /*----------------------------------------------------------------------------*/
461 
462 const cs_adjacency_t *
464 
465 /*----------------------------------------------------------------------------*/
473 /*----------------------------------------------------------------------------*/
474 
475 cs_real_t *
477 
478 /*----------------------------------------------------------------------------*/
484 /*----------------------------------------------------------------------------*/
485 
486 size_t
488 
489 /*----------------------------------------------------------------------------*/
490 
492 
493 #endif /* __CS_EQUATION_COMMON_H__ */
cs_timer_counter_t tca
Definition: cs_equation_common.h:95
Definition: cs_equation_common.h:57
time step descriptor
Definition: cs_time_step.h:51
#define CS_CDO_N_MAX_REACTIONS
Definition: cs_cdo.h:107
cs_timer_counter_t tcd
Definition: cs_equation_common.h:93
Definition: cs_cdo_bc.h:78
const cs_adjacency_t * cs_equation_get_f2f_index(void)
Get the connectivity face->faces for the local rank.
Definition: cs_equation_common.c:1595
Definition: cs_equation_param.h:101
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:66
cs_timer_counter_t tcr
Definition: cs_equation_common.h:97
void cs_equation_free_builder(cs_equation_builder_t **p_builder)
Free a cs_equation_builder_t structure.
Definition: cs_equation_common.c:671
Definition: cs_mesh_adjacencies.h:89
short int * cs_equation_tag_neumann_face(const cs_equation_param_t *eqp)
Tag each face related to a Neumann BC with its definition id. Default tag is -1 (not a Neumann face) ...
Definition: cs_equation_common.c:1159
#define BEGIN_C_DECLS
Definition: cs_defs.h:453
void cs_equation_set_diffusion_property(const cs_equation_param_t *eqp, cs_lnum_t c_id, cs_flag_t c_flag, cs_cell_builder_t *cb)
Set the diffusion property inside a cell and its related quantities.
Definition: cs_equation_common.c:788
unsigned char cs_mask_t
Definition: cs_cdo.h:126
Definition: cs_cdo_local.h:138
Definition: cs_cdo_bc.h:95
const cs_matrix_structure_t * cs_equation_get_matrix_structure(cs_space_scheme_t scheme)
Retrieve a pointer to the associated cs_matrix_structure_t according to the space scheme...
Definition: cs_equation_common.c:1500
cs_flag_t msh_flag
Definition: cs_equation_common.h:60
#define CS_FLAG_BOUNDARY
Definition: cs_cdo.h:50
Definition: cs_cdo_connect.h:55
cs_timer_counter_t tcb
Definition: cs_equation_common.h:90
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_cdo_quantities.h:89
const cs_matrix_assembler_t * cs_equation_get_matrix_assembler(cs_space_scheme_t scheme)
Retrieve a pointer to the associated cs_matrix_assembler_t according to the space scheme...
Definition: cs_equation_common.c:1545
Definition: cs_cdo_local.h:94
void cs_equation_compute_neumann_sf(short int def_id, short int f, const cs_equation_param_t *eqp, const cs_cell_mesh_t *cm, cs_cell_bc_t *cbc)
Compute the values of the Neumann BCs when DoFs are scalar-valued and attached to faces...
Definition: cs_equation_common.c:1280
Definition: cs_mesh.h:63
bool time_pty_uniform
Definition: cs_equation_common.h:67
cs_flag_t bd_msh_flag
Definition: cs_equation_common.h:61
void cs_equation_free_common_structures(cs_flag_t scheme_flag)
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:529
cs_space_scheme_t
Definition: cs_cdo.h:138
cs_flag_t st_msh_flag
Definition: cs_equation_common.h:62
const cs_adjacency_t * cs_equation_get_v2v_index(void)
Get the connectivity vertex->vertices for the local rank.
Definition: cs_equation_common.c:1581
void cs_equation_assemble_f(const cs_cell_sys_t *csys, const cs_range_set_t *rset, const cs_equation_param_t *eqp, cs_real_t *rhs, cs_matrix_assembler_values_t *mav)
Assemble a cellwise system related to cell faces into the global algebraic system.
Definition: cs_equation_common.c:1430
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:596
void cs_equation_set_diffusion_property_cw(const cs_equation_param_t *eqp, const cs_cell_mesh_t *cm, cs_flag_t c_flag, cs_cell_builder_t *cb)
Set the diffusion property inside a cell and its related quantities. Cellwise version using a cs_cell...
Definition: cs_equation_common.c:825
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:1611
Definition: cs_cdo_local.h:108
Definition: cs_range_set.h:57
cs_timer_counter_t tce
Definition: cs_equation_common.h:102
cs_real_t * cs_equation_compute_dirichlet_sf(const cs_mesh_t *mesh, const cs_equation_param_t *eqp, const cs_cdo_bc_list_t *dir, cs_cell_builder_t *cb)
Compute the values of the Dirichlet BCs when DoFs are scalar-valued and attached to faces...
Definition: cs_equation_common.c:1062
Definition: cs_cdo_local.h:71
cs_timer_counter_t tcs
Definition: cs_equation_common.h:99
cs_cdo_bc_t * face_bc
Definition: cs_equation_common.h:86
cs_flag_t sys_flag
Definition: cs_equation_common.h:63
bool diff_pty_uniform
Definition: cs_equation_common.h:66
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:702
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
void cs_equation_assemble_v(const cs_cell_sys_t *csys, const cs_range_set_t *rset, const cs_equation_param_t *eqp, cs_real_t *rhs, cs_real_t *sources, cs_matrix_assembler_values_t *mav)
Assemble a cellwise system related to cell vertices into the global algebraic system.
Definition: cs_equation_common.c:1354
#define END_C_DECLS
Definition: cs_defs.h:454
unsigned short int cs_flag_t
Definition: cs_defs.h:299
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:62
#define CS_N_MAX_SOURCE_TERMS
Definition: cs_source_term.h:51
static cs_flag_t cs_equation_get_cell_mesh_flag(cs_flag_t cell_flag, const cs_equation_builder_t *eqb)
Retrieve the flag to give for building a cs_cell_mesh_t structure.
Definition: cs_equation_common.h:124
void cs_equation_allocate_common_structures(const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *quant, const cs_time_step_t *time_step, cs_flag_t scheme_flag)
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:339
void cs_equation_init_properties(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, double *tpty_val, double *rpty_vals, cs_cell_builder_t *cb)
Initialize all properties for an algebraic system.
Definition: cs_equation_common.c:741
cs_real_t * cs_equation_compute_dirichlet_sv(const cs_mesh_t *mesh, const cs_equation_param_t *eqp, const cs_cdo_bc_list_t *dir, cs_cell_builder_t *cb)
Compute the values of the Dirichlet BCs when DoFs are scalar-valued and attached to vertices...
Definition: cs_equation_common.c:864
size_t cs_equation_get_tmpbuf_size(void)
Get the allocation size of the temporary buffer.
Definition: cs_equation_common.c:1625
void cs_equation_compute_neumann_sv(short int def_id, short int f, const cs_equation_param_t *eqp, const cs_cell_mesh_t *cm, cs_cell_bc_t *cbc)
Compute the values of the Neumann BCs when DoFs are scalar-valued and attached to vertices...
Definition: cs_equation_common.c:1205
cs_mask_t * source_mask
Definition: cs_equation_common.h:71
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition: cs_matrix.h:86
Definition: cs_timer.h:57
void( cs_source_term_cellwise_t)(const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
Compute the contribution for a cell related to a source term and add it the given array of values...
Definition: cs_source_term.h:71