My Project
programmer's 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-2019 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_source_term.h"
43 
44 /*----------------------------------------------------------------------------*/
45 
47 
48 /*============================================================================
49  * Macro definitions
50  *============================================================================*/
51 
52 /*============================================================================
53  * Type definitions
54  *============================================================================*/
55 
61 typedef struct {
62 
63  bool init_step;
89  bool reac_pty_uniform[CS_CDO_N_MAX_REACTIONS];
108 
151 
152 /*
153  * Structure used to store information generated during the analysis
154  * of the balance of each term of an equation
155  */
156 typedef struct {
157 
158  /* where balance is computed: primal vertices or primal cells */
162 
163  /* Balance for each main term */
170 
172 
173 /*============================================================================
174  * Inline public function prototypes
175  *============================================================================*/
176 
177 /*----------------------------------------------------------------------------*/
186 /*----------------------------------------------------------------------------*/
187 
188 static inline cs_flag_t
190  const cs_equation_builder_t *eqb)
191 {
192  cs_flag_t _flag = eqb->msh_flag | eqb->st_msh_flag;
193 
194  if (cell_flag & CS_FLAG_BOUNDARY_CELL_BY_FACE)
195  _flag |= eqb->bd_msh_flag;
196 
197  return _flag;
198 }
199 
200 /*----------------------------------------------------------------------------*/
210 /*----------------------------------------------------------------------------*/
211 
212 static inline void
214  const cs_lnum_t c_id,
215  const cs_real_t t_eval,
216  const cs_flag_t c_flag,
217  cs_cell_builder_t *cb)
218 {
220  t_eval,
221  eqp->diffusion_property,
223  cb->dpty_mat);
224 
226  cb->dpty_val = cb->dpty_mat[0][0];
227 
228  /* Set additional quantities in case of more advanced way of enforcing the
229  Dirichlet BCs */
230  if (c_flag & CS_FLAG_BOUNDARY_CELL_BY_FACE) {
233  cs_math_33_eigen((const cs_real_t (*)[3])cb->dpty_mat,
234  &(cb->eig_ratio),
235  &(cb->eig_max));
236  }
237 }
238 
239 /*----------------------------------------------------------------------------*/
250 /*----------------------------------------------------------------------------*/
251 
252 static inline void
254  const cs_cell_mesh_t *cm,
255  const cs_real_t t_eval,
256  const cs_flag_t c_flag,
257  cs_cell_builder_t *cb)
258 {
260  eqp->diffusion_property,
261  t_eval,
263  cb->dpty_mat);
264 
266  cb->dpty_val = cb->dpty_mat[0][0];
267 
268  /* Set additional quantities in case of more advanced way of enforcing the
269  Dirichlet BCs */
270  if (c_flag & CS_FLAG_BOUNDARY_CELL_BY_FACE) {
273  cs_math_33_eigen((const cs_real_t (*)[3])cb->dpty_mat,
274  &(cb->eig_ratio),
275  &(cb->eig_max));
276  }
277 }
278 
279 /*============================================================================
280  * Public function prototypes
281  *============================================================================*/
282 
283 /*----------------------------------------------------------------------------*/
299 /*----------------------------------------------------------------------------*/
300 
301 void
303  const cs_cdo_quantities_t *quant,
304  const cs_time_step_t *time_step,
305  cs_flag_t vb_flag,
306  cs_flag_t vcb_flag,
307  cs_flag_t fb_flag,
308  cs_flag_t hho_flag);
309 
310 /*----------------------------------------------------------------------------*/
319 /*----------------------------------------------------------------------------*/
320 
321 void
323 
324 /*----------------------------------------------------------------------------*/
334 /*----------------------------------------------------------------------------*/
335 
338  const cs_mesh_t *mesh);
339 
340 /*----------------------------------------------------------------------------*/
347 /*----------------------------------------------------------------------------*/
348 
349 void
351 
352 /*----------------------------------------------------------------------------*/
367 /*----------------------------------------------------------------------------*/
368 
369 cs_gnum_t
371  cs_lnum_t x_size,
372  const cs_matrix_t *matrix,
373  cs_range_set_t *rset,
374  cs_real_t *x,
375  cs_real_t *b);
376 
377 /*----------------------------------------------------------------------------*/
385 /*----------------------------------------------------------------------------*/
386 
387 void
388 cs_equation_write_monitoring(const char *eqname,
389  const cs_equation_builder_t *eqb);
390 
391 /*----------------------------------------------------------------------------*/
401 /*----------------------------------------------------------------------------*/
402 
403 void
405  const cs_equation_builder_t *eqb,
406  const cs_real_t t_eval,
407  cs_cell_builder_t *cb);
408 
409 /*----------------------------------------------------------------------------*/
424 /*----------------------------------------------------------------------------*/
425 
426 void
428  const cs_equation_builder_t *eqb,
429  const cs_real_t t_eval,
430  const cs_flag_t cell_flag,
431  const cs_cell_mesh_t *cm,
432  cs_cell_builder_t *cb);
433 
434 /*----------------------------------------------------------------------------*/
444 /*----------------------------------------------------------------------------*/
445 
446 void
448  cs_lnum_t c_id,
449  cs_real_t t_eval,
450  cs_flag_t c_flag,
451  cs_cell_builder_t *cb);
452 
453 /*----------------------------------------------------------------------------*/
464 /*----------------------------------------------------------------------------*/
465 
466 void
468  const cs_cell_mesh_t *cm,
469  cs_real_t t_eval,
470  cs_flag_t c_flag,
471  cs_cell_builder_t *cb);
472 
473 /*----------------------------------------------------------------------------*/
490 /*----------------------------------------------------------------------------*/
491 
492 void
494  cs_cell_builder_t *cb,
495  cs_cell_sys_t *csys);
496 
497 /*----------------------------------------------------------------------------*/
514 /*----------------------------------------------------------------------------*/
515 
516 void
518  cs_cell_builder_t *cb,
519  cs_cell_sys_t *csys);
520 
521 /*----------------------------------------------------------------------------*/
529 /*----------------------------------------------------------------------------*/
530 
531 cs_real_t *
533 
534 /*----------------------------------------------------------------------------*/
540 /*----------------------------------------------------------------------------*/
541 
542 size_t
544 
545 /*----------------------------------------------------------------------------*/
554 /*----------------------------------------------------------------------------*/
555 
558  cs_lnum_t size);
559 
560 /*----------------------------------------------------------------------------*/
566 /*----------------------------------------------------------------------------*/
567 
568 void
570 
571 /*----------------------------------------------------------------------------*/
578 /*----------------------------------------------------------------------------*/
579 
580 void
583 
584 /*----------------------------------------------------------------------------*/
590 /*----------------------------------------------------------------------------*/
591 
592 void
594 
595 /*----------------------------------------------------------------------------*/
596 
598 
599 #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:243
cs_equation_balance_t::unsteady_term
cs_real_t * unsteady_term
Definition: cs_equation_common.h:164
cs_equation_init_properties_cw
void cs_equation_init_properties_cw(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, const cs_real_t t_eval, const cs_flag_t cell_flag, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb)
Initialize all properties for a given cell when building the algebraic system. If the property is uni...
Definition: cs_equation_common.c:536
cs_equation_balance_t::diffusion_term
cs_real_t * diffusion_term
Definition: cs_equation_common.h:166
cs_equation_builder_t::source_mask
cs_mask_t * source_mask
Definition: cs_equation_common.h:98
cs_equation_balance_t
Definition: cs_equation_common.h:156
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:444
cs_param_hodge_t::inv_pty
bool inv_pty
Definition: cs_param_cdo.h:133
cs_cell_builder_t::eig_max
double eig_max
Definition: cs_cdo_local.h:60
cs_source_term.h
CS_PARAM_BC_ENFORCE_WEAK_SYM
Definition: cs_param.h:348
cs_timer_counter_t
Definition: cs_timer.h:57
cs_fuel_incl::b
double precision, save b
Definition: cs_fuel_incl.f90:146
cs_equation_builder_t::tcr
cs_timer_counter_t tcr
Definition: cs_equation_common.h:140
cs_cell_builder_t::dpty_val
double dpty_val
Definition: cs_cdo_local.h:64
cs_equation_balance_t::location
cs_flag_t location
Definition: cs_equation_common.h:159
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_equation_param_t::diffusion_hodge
cs_param_hodge_t diffusion_hodge
Definition: cs_equation_param.h:285
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:742
cs_equation_builder_t::tce
cs_timer_counter_t tce
Definition: cs_equation_common.h:144
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_equation_balance_t::size
cs_lnum_t size
Definition: cs_equation_common.h:160
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_equation_builder_t::msh_flag
cs_flag_t msh_flag
Definition: cs_equation_common.h:70
cs_equation_balance_t::reaction_term
cs_real_t * reaction_term
Definition: cs_equation_common.h:165
cs_matrix_t
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:90
cs_equation_builder_t::sys_flag
cs_flag_t sys_flag
Definition: cs_equation_common.h:79
cs_equation_builder_t::face_bc
cs_cdo_bc_face_t * face_bc
Definition: cs_equation_common.h:122
cs_cdo_bc.h
cs_equation_builder_t::time_pty_uniform
bool time_pty_uniform
Definition: cs_equation_common.h:88
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:325
cs_equation_builder_t::bd_msh_flag
cs_flag_t bd_msh_flag
Definition: cs_equation_common.h:73
cs_cdo_quantities.h
cs_equation_builder_t::st_msh_flag
cs_flag_t st_msh_flag
Definition: cs_equation_common.h:76
mesh
Definition: mesh.f90:26
cs_equation_builder_t::init_step
bool init_step
Definition: cs_equation_common.h:63
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 the given array of values.
Definition: cs_source_term.h:70
cs_equation_builder_t::tcb
cs_timer_counter_t tcb
Definition: cs_equation_common.h:134
cs_equation_init_properties
void cs_equation_init_properties(const cs_equation_param_t *eqp, const cs_equation_builder_t *eqb, const cs_real_t t_eval, cs_cell_builder_t *cb)
Initialize all properties for an algebraic system.
Definition: cs_equation_common.c:482
stride
void const cs_int_t const cs_int_t const cs_int_t const cs_int_t * stride
Definition: cs_sat_coupling.h:325
cs_equation_param_t
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition: cs_equation_param.h:148
cs_property_tensor_in_cell
void cs_property_tensor_in_cell(const cs_cell_mesh_t *cm, const cs_property_t *pty, cs_real_t t_eval, bool do_inversion, cs_real_3_t *tensor)
Compute the value of the tensor attached a property at the cell center Version using a cs_cell_mesh_t...
Definition: cs_property.c:1178
cs_equation_balance_t::balance
cs_real_t * balance
Definition: cs_equation_common.h:161
CS_CDO_N_MAX_REACTIONS
#define CS_CDO_N_MAX_REACTIONS
Definition: cs_param_cdo.h:69
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_cell_builder_t::eig_ratio
double eig_ratio
Definition: cs_cdo_local.h:59
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 vb_flag, cs_flag_t vcb_flag, cs_flag_t fb_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:115
cs_time_step_t
time step descriptor
Definition: cs_time_step.h:51
CS_PARAM_BC_ENFORCE_WEAK_NITSCHE
Definition: cs_param.h:347
CS_FLAG_BOUNDARY_CELL_BY_FACE
#define CS_FLAG_BOUNDARY_CELL_BY_FACE
Definition: cs_flag.h:49
cs_equation_param_t::diffusion_property
cs_property_t * diffusion_property
Definition: cs_equation_param.h:286
cs_cdo_bc_face_t
Definition: cs_cdo_bc.h:86
cs_cdo_quantities_t
Definition: cs_cdo_quantities.h:94
cs_equation_param_t::default_enforcement
cs_param_bc_enforce_t default_enforcement
Definition: cs_equation_param.h:219
cs_property_get_cell_tensor
void cs_property_get_cell_tensor(cs_lnum_t c_id, cs_real_t t_eval, const cs_property_t *pty, bool do_inversion, cs_real_3_t *tensor)
Compute the value of the tensor attached a property at the cell center.
Definition: cs_property.c:1026
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:74
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:168
cs_equation_set_diffusion_property
static void cs_equation_set_diffusion_property(const cs_equation_param_t *eqp, const cs_lnum_t c_id, const cs_real_t t_eval, const 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.h:213
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:809
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:56
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:756
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:865
cs_equation_set_diffusion_property_cw
static void cs_equation_set_diffusion_property_cw(const cs_equation_param_t *eqp, const cs_cell_mesh_t *cm, const cs_real_t t_eval, const 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.h:253
cs_mask_t
unsigned char cs_mask_t
Definition: cs_flag.h:152
cs_time_step.h
cs_cell_builder_t::dpty_mat
cs_real_33_t dpty_mat
Definition: cs_cdo_local.h:63
cs_equation_builder_t::diff_pty_uniform
bool diff_pty_uniform
Definition: cs_equation_common.h:87
cs_equation_cell_mesh_flag
static cs_flag_t cs_equation_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:189
cs_equation_builder_t
Store common elements used when building an algebraic system related to an equation.
Definition: cs_equation_common.h:61
cs_equation_builder_t::tcs
cs_timer_counter_t tcs
Definition: cs_equation_common.h:142
cs_equation_balance_t::boundary_term
cs_real_t * boundary_term
Definition: cs_equation_common.h:169
cs_flag_t
unsigned short int cs_flag_t
Definition: cs_defs.h:304
cs_equation_prepare_system
cs_gnum_t cs_equation_prepare_system(int stride, cs_lnum_t x_size, const cs_matrix_t *matrix, cs_range_set_t *rset, 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:363
cs_equation_builder_t::tca
cs_timer_counter_t tca
Definition: cs_equation_common.h:138
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:834
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:93
cs_math_33_eigen
void cs_math_33_eigen(const cs_real_t m[3][3], cs_real_t *eig_ratio, cs_real_t *eig_max)
Compute max/min eigenvalues ratio and max. eigenvalue of a 3x3 symmetric matrix with non-symmetric st...
Definition: cs_math.c:303
cs_property_is_isotropic
static bool cs_property_is_isotropic(const cs_property_t *pty)
returns true if the property is isotropic, otherwise false
Definition: cs_property.h:276
cs_equation_builder_t::tcd
cs_timer_counter_t tcd
Definition: cs_equation_common.h:136
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:653
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:146
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:588
cs_mesh_t
Definition: cs_mesh.h:63
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:773
cs_timer.h
cs_equation_balance_t::advection_term
cs_real_t * advection_term
Definition: cs_equation_common.h:167
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:221
cs_cdo_local.h