programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cs_equation.h
Go to the documentation of this file.
1 #ifndef __CS_EQUATION_H__
2 #define __CS_EQUATION_H__
3 
4 /*============================================================================
5  * Routines to handle cs_equation_t structure and its related structures
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2018 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------
29  * Local headers
30  *----------------------------------------------------------------------------*/
31 
32 #include "cs_cdo_quantities.h"
33 #include "cs_equation_param.h"
34 #include "cs_field.h"
35 #include "cs_param.h"
36 #include "cs_mesh.h"
37 #include "cs_time_step.h"
38 #include "cs_xdef.h"
39 
40 /*----------------------------------------------------------------------------*/
41 
43 
44 /*============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /*============================================================================
49  * Type definitions
50  *============================================================================*/
51 
52 typedef struct _cs_equation_t cs_equation_t;
53 
54 /* List of available keys for setting an equation */
55 typedef enum {
56 
81 
83 
84 /*============================================================================
85  * Public function prototypes
86  *============================================================================*/
87 
88 /*----------------------------------------------------------------------------*/
94 /*----------------------------------------------------------------------------*/
95 
96 int
98 
99 /*----------------------------------------------------------------------------*/
108 /*----------------------------------------------------------------------------*/
109 
110 cs_equation_t *
111 cs_equation_by_name(const char *eqname);
112 
113 /*----------------------------------------------------------------------------*/
122 /*----------------------------------------------------------------------------*/
123 
124 cs_equation_t *
125 cs_equation_by_id(int eq_id);
126 
127 /*----------------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------------*/
140 
141 cs_equation_t *
142 cs_equation_add(const char *eqname,
143  const char *varname,
144  cs_equation_type_t eqtype,
145  int dim,
146  cs_param_bc_type_t default_bc);
147 
148 /*----------------------------------------------------------------------------*/
159 /*----------------------------------------------------------------------------*/
160 
161 cs_equation_t *
162 cs_equation_add_user(const char *eqname,
163  const char *varname,
164  int dim,
165  cs_param_bc_type_t default_bc);
166 
167 /*----------------------------------------------------------------------------*/
171 /*----------------------------------------------------------------------------*/
172 
173 void
175 
176 /*----------------------------------------------------------------------------*/
181 /*----------------------------------------------------------------------------*/
182 
183 void
185 
186 /*----------------------------------------------------------------------------*/
190 /*----------------------------------------------------------------------------*/
191 
192 void
194 
195 /*----------------------------------------------------------------------------*/
201 /*----------------------------------------------------------------------------*/
202 
203 void
204 cs_equation_set_timer_stats(cs_equation_t *eq);
205 
206 /*----------------------------------------------------------------------------*/
216 /*----------------------------------------------------------------------------*/
217 
218 bool
220  bool do_profiling);
221 
222 /*----------------------------------------------------------------------------*/
230 /*----------------------------------------------------------------------------*/
231 
232 void
233 cs_equation_set_param(cs_equation_t *eq,
234  cs_equation_key_t key,
235  const char *keyval);
236 
237 /*----------------------------------------------------------------------------*/
246 /*----------------------------------------------------------------------------*/
247 
248 void
249 cs_equation_link(cs_equation_t *eq,
250  const char *keyword,
251  void *pointer);
252 
253 /*----------------------------------------------------------------------------*/
266 /*----------------------------------------------------------------------------*/
267 
268 void
269 cs_equation_add_ic_by_value(cs_equation_t *eq,
270  const char *z_name,
271  cs_real_t *val);
272 
273 /*----------------------------------------------------------------------------*/
287 /*----------------------------------------------------------------------------*/
288 
289 void
290 cs_equation_add_ic_by_qov(cs_equation_t *eq,
291  const char *z_name,
292  double quantity);
293 
294 /*----------------------------------------------------------------------------*/
307 /*----------------------------------------------------------------------------*/
308 
309 void
310 cs_equation_add_ic_by_analytic(cs_equation_t *eq,
311  const char *z_name,
312  cs_analytic_func_t *analytic,
313  void *input);
314 
315 /*----------------------------------------------------------------------------*/
326 /*----------------------------------------------------------------------------*/
327 
328 void
329 cs_equation_add_bc_by_value(cs_equation_t *eq,
330  const cs_param_bc_type_t bc_type,
331  const char *z_name,
332  cs_real_t *values);
333 
334 /*----------------------------------------------------------------------------*/
347 /*----------------------------------------------------------------------------*/
348 
349 void
350 cs_equation_add_bc_by_array(cs_equation_t *eq,
351  const cs_param_bc_type_t bc_type,
352  const char *z_name,
353  cs_flag_t loc,
354  cs_real_t *array,
355  cs_lnum_t *index);
356 
357 /*----------------------------------------------------------------------------*/
370 /*----------------------------------------------------------------------------*/
371 
372 void
373 cs_equation_add_bc_by_analytic(cs_equation_t *eq,
374  const cs_param_bc_type_t bc_type,
375  const char *z_name,
376  cs_analytic_func_t *analytic,
377  void *input);
378 
379 /*----------------------------------------------------------------------------*/
389 /*----------------------------------------------------------------------------*/
390 
391 int
392 cs_equation_add_reaction(cs_equation_t *eq,
393  cs_property_t *property);
394 
395 /*----------------------------------------------------------------------------*/
406 /*----------------------------------------------------------------------------*/
407 
408 cs_xdef_t *
409 cs_equation_add_source_term_by_val(cs_equation_t *eq,
410  const char *z_name,
411  cs_real_t *val);
412 
413 /*----------------------------------------------------------------------------*/
426 /*----------------------------------------------------------------------------*/
427 
428 cs_xdef_t *
430  const char *z_name,
431  cs_analytic_func_t *ana,
432  void *input);
433 
434 /*----------------------------------------------------------------------------*/
438 /*----------------------------------------------------------------------------*/
439 
440 void
442 
443 /*----------------------------------------------------------------------------*/
455 /*----------------------------------------------------------------------------*/
456 
457 void
459  const cs_cdo_connect_t *connect,
460  const cs_cdo_quantities_t *quant,
461  const cs_time_step_t *ts);
462 
463 /*----------------------------------------------------------------------------*/
471 /*----------------------------------------------------------------------------*/
472 
473 bool
474 cs_equation_needs_build(const cs_equation_t *eq);
475 
476 /*----------------------------------------------------------------------------*/
485 /*----------------------------------------------------------------------------*/
486 
487 void
489  const cs_time_step_t *time_step,
490  double dt_cur,
491  cs_equation_t *eq);
492 
493 /*----------------------------------------------------------------------------*/
499 /*----------------------------------------------------------------------------*/
500 
501 void
502 cs_equation_solve(cs_equation_t *eq);
503 
504 /*----------------------------------------------------------------------------*/
512 /*----------------------------------------------------------------------------*/
513 
514 bool
515 cs_equation_is_steady(const cs_equation_t *eq);
516 
517 /*----------------------------------------------------------------------------*/
525 /*----------------------------------------------------------------------------*/
526 
527 const char *
528 cs_equation_get_name(const cs_equation_t *eq);
529 
530 /*----------------------------------------------------------------------------*/
538 /*----------------------------------------------------------------------------*/
539 
540 int
541 cs_equation_get_id(const cs_equation_t *eq);
542 
543 /*----------------------------------------------------------------------------*/
551 /*----------------------------------------------------------------------------*/
552 
553 cs_field_t *
554 cs_equation_get_field(const cs_equation_t *eq);
555 
556 /*----------------------------------------------------------------------------*/
564 /*----------------------------------------------------------------------------*/
565 
566 cs_flag_t
567 cs_equation_get_flag(const cs_equation_t *eq);
568 /*----------------------------------------------------------------------------*/
577 /*----------------------------------------------------------------------------*/
578 
579 const cs_equation_param_t *
580 cs_equation_get_param(const cs_equation_t *eq);
581 
582 /*----------------------------------------------------------------------------*/
591 /*----------------------------------------------------------------------------*/
592 
594 cs_equation_get_diffusion_property(const cs_equation_t *eq);
595 
596 /*----------------------------------------------------------------------------*/
605 /*----------------------------------------------------------------------------*/
606 
608 cs_equation_get_time_property(const cs_equation_t *eq);
609 
610 /*----------------------------------------------------------------------------*/
621 /*----------------------------------------------------------------------------*/
622 
624 cs_equation_get_reaction_property(const cs_equation_t *eq,
625  const int reaction_id);
626 
627 /*----------------------------------------------------------------------------*/
636 /*----------------------------------------------------------------------------*/
637 
639 cs_equation_get_space_scheme(const cs_equation_t *eq);
640 
641 /*----------------------------------------------------------------------------*/
650 /*----------------------------------------------------------------------------*/
651 
652 int
653 cs_equation_get_space_poly_degree(const cs_equation_t *eq);
654 
655 /*----------------------------------------------------------------------------*/
663 /*----------------------------------------------------------------------------*/
664 
665 int
666 cs_equation_get_var_dim(const cs_equation_t *eq);
667 
668 /*----------------------------------------------------------------------------*/
676 /*----------------------------------------------------------------------------*/
677 
679 cs_equation_get_type(const cs_equation_t *eq);
680 
681 /*----------------------------------------------------------------------------*/
690 /*----------------------------------------------------------------------------*/
691 
692 const cs_real_t *
693 cs_equation_get_face_values(const cs_equation_t *eq);
694 
695 /*----------------------------------------------------------------------------*/
704 /*----------------------------------------------------------------------------*/
705 
706 const cs_real_t *
707 cs_equation_get_cell_values(const cs_equation_t *eq);
708 
709 /*----------------------------------------------------------------------------*/
720 /*----------------------------------------------------------------------------*/
721 
722 void
723 cs_equation_compute_flux_across_plane(const cs_equation_t *eq,
724  const char *ml_name,
725  const cs_real_3_t direction,
726  cs_real_t *diff_flux,
727  cs_real_t *conv_flux);
728 
729 /*----------------------------------------------------------------------------*/
738 /*----------------------------------------------------------------------------*/
739 
740 void
741 cs_equation_compute_diff_flux_cellwise(const cs_equation_t *eq,
742  cs_flag_t location,
743  cs_real_t *diff_flux);
744 
745 /*----------------------------------------------------------------------------*/
752 /*----------------------------------------------------------------------------*/
753 
754 void
755 cs_equation_compute_vtx_field_gradient(const cs_equation_t *eq,
756  cs_real_t *v_gradient);
757 
758 /*----------------------------------------------------------------------------*/
765 /*----------------------------------------------------------------------------*/
766 
767 void
769  double dt);
770 
771 /*----------------------------------------------------------------------------*/
772 
774 
775 #endif /* __CS_EQUATION_H__ */
void cs_equation_add_bc_by_analytic(cs_equation_t *eq, const cs_param_bc_type_t bc_type, const char *z_name, cs_analytic_func_t *analytic, void *input)
Define and initialize a new structure to set a boundary condition related to the given equation struc...
Definition: cs_equation.c:1990
Definition: cs_equation.h:57
time step descriptor
Definition: cs_time_step.h:51
cs_property_t * cs_equation_get_time_property(const cs_equation_t *eq)
Return a pointer to the cs_property_t structure associated to the unsteady term for this equation (NU...
Definition: cs_equation.c:2628
Definition: cs_equation.h:73
Definition: cs_equation.h:58
Field descriptor.
Definition: cs_field.h:124
void cs_equation_initialize(const cs_mesh_t *mesh, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *quant, const cs_time_step_t *ts)
Allocate and initialize the builder of the algebraic system. Set the initialize condition to all vari...
Definition: cs_equation.c:2247
Definition: cs_equation_param.h:101
void cs_equation_solve(cs_equation_t *eq)
Solve the linear system for this equation.
Definition: cs_equation.c:2358
Definition: cs_equation.h:61
void cs_equation_compute_flux_across_plane(const cs_equation_t *eq, const char *ml_name, const cs_real_3_t direction, cs_real_t *diff_flux, cs_real_t *conv_flux)
Compute the diffusive and convective flux accross a plane defined by a mesh location structure attach...
Definition: cs_equation.c:2831
Definition: cs_equation.h:64
#define BEGIN_C_DECLS
Definition: cs_defs.h:453
cs_equation_key_t
Definition: cs_equation.h:55
Definition: cs_equation.h:68
Definition: cs_cdo_connect.h:55
cs_xdef_t * cs_equation_add_source_term_by_analytic(cs_equation_t *eq, const char *z_name, cs_analytic_func_t *ana, void *input)
Define a new source term structure and initialize it by an analytical function.
Definition: cs_equation.c:2120
Definition: cs_equation.h:67
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_cdo_quantities.h:89
Definition: cs_equation.h:71
void cs_equation_build_system(const cs_mesh_t *mesh, const cs_time_step_t *time_step, double dt_cur, cs_equation_t *eq)
Build the linear system for this equation.
Definition: cs_equation.c:2313
void cs_equation_add_ic_by_qov(cs_equation_t *eq, const char *z_name, double quantity)
Define the initial condition for the unknown related to this equation This definition can be done on ...
Definition: cs_equation.c:1795
bool cs_equation_needs_build(const cs_equation_t *eq)
Check if one has to build the linear system.
Definition: cs_equation.c:2296
cs_property_t * cs_equation_get_reaction_property(const cs_equation_t *eq, const int reaction_id)
Return a pointer to the cs_property_t structure associated to the reaction term called r_name and rel...
Definition: cs_equation.c:2650
Definition: cs_equation.h:62
Definition: cs_equation.h:76
Definition: cs_mesh.h:63
void cs_equation_link(cs_equation_t *eq, const char *keyword, void *pointer)
Associate a material property or an advection field with an equation for a given term (diffusion...
Definition: cs_equation.c:1694
cs_equation_t * cs_equation_by_id(int eq_id)
Find the cs_equation_t structure with name eqname Return NULL if not find.
Definition: cs_equation.c:820
Definition: cs_equation.h:80
Definition: cs_equation.h:77
cs_space_scheme_t
Definition: cs_cdo.h:138
void cs_equation_log_setup(void)
Summarize all cs_equation_t structures.
Definition: cs_equation.c:1056
const cs_equation_param_t * cs_equation_get_param(const cs_equation_t *eq)
Return the cs_equation_param_t structure associated to a cs_equation_t structure. ...
Definition: cs_equation.c:2588
bool cs_equation_finalize_setup(const cs_cdo_connect_t *connect, bool do_profiling)
Assign a set of pointer functions for managing the cs_equation_t structure during the computation...
Definition: cs_equation.c:1145
Definition: cs_equation.h:63
Definition: cs_field_pointer.h:65
int cs_equation_add_reaction(cs_equation_t *eq, cs_property_t *property)
Define and initialize a new structure to store parameters related to a reaction term.
Definition: cs_equation.c:2037
void cs_equation_add_ic_by_analytic(cs_equation_t *eq, const char *z_name, cs_analytic_func_t *analytic, void *input)
Define the initial condition for the unknown related to this equation This definition can be done on ...
Definition: cs_equation.c:1838
void cs_equation_add_ic_by_value(cs_equation_t *eq, const char *z_name, cs_real_t *val)
Define the initial condition for the unknown related to this equation This definition can be done on ...
Definition: cs_equation.c:1751
void cs_equation_compute_vtx_field_gradient(const cs_equation_t *eq, cs_real_t *v_gradient)
Cellwise computation of the discrete gradient at vertices.
Definition: cs_equation.c:2920
cs_property_t * cs_equation_get_diffusion_property(const cs_equation_t *eq)
Return a pointer to the cs_property_t structure associated to the diffusion term for this equation (N...
Definition: cs_equation.c:2608
int cs_equation_get_id(const cs_equation_t *eq)
Return the id number related to the given cs_equation_t structure.
Definition: cs_equation.c:2526
Definition: cs_equation.h:69
Definition: cs_xdef.h:72
Definition: cs_equation.h:65
void cs_equation_set_param(cs_equation_t *eq, cs_equation_key_t key, const char *keyval)
Set a parameter in a cs_equation_t structure attached to keyname.
Definition: cs_equation.c:1334
cs_equation_t * cs_equation_add_user(const char *eqname, const char *varname, int dim, cs_param_bc_type_t default_bc)
Add a new user equation structure and set a first set of parameters.
Definition: cs_equation.c:950
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
cs_equation_type_t
Definition: cs_equation_param.h:62
cs_param_bc_type_t
Definition: cs_param.h:161
cs_xdef_t * cs_equation_add_source_term_by_val(cs_equation_t *eq, const char *z_name, cs_real_t *val)
Define a new source term structure and initialize it by value.
Definition: cs_equation.c:2071
const cs_real_t * cs_equation_get_face_values(const cs_equation_t *eq)
Get the values at each face of the mesh for the field unknowns related to this equation.
Definition: cs_equation.c:2753
void cs_equation_create_fields(void)
Create a field structure related to all cs_equation_t structures.
Definition: cs_equation.c:2167
const cs_real_t * cs_equation_get_cell_values(const cs_equation_t *eq)
Get the values at each cell centers for the field unknowns related to this equation.
Definition: cs_equation.c:2785
void( cs_analytic_func_t)(cs_real_t time, cs_lnum_t n_elts, const cs_lnum_t *elt_ids, const cs_real_t *coords, bool compact, void *input, cs_real_t *retval)
Generic function pointer for an analytic function elt_ids is optional. If not NULL, it enables to access in coords at the right location and the same thing to fill retval if compact is set to false.
Definition: cs_cdo.h:169
Definition: cs_equation.h:72
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
cs_space_scheme_t cs_equation_get_space_scheme(const cs_equation_t *eq)
Return the type of numerical scheme used for the discretization in space.
Definition: cs_equation.c:2675
cs_equation_type_t cs_equation_get_type(const cs_equation_t *eq)
Return the type of equation for the given equation structure.
Definition: cs_equation.c:2733
Definition: cs_equation.h:75
void cs_equation_compute_diff_flux_cellwise(const cs_equation_t *eq, cs_flag_t location, cs_real_t *diff_flux)
Cellwise computation of the diffusive flux across all cell faces. Primal or dual faces are considered...
Definition: cs_equation.c:2880
Definition: cs_equation.h:70
#define END_C_DECLS
Definition: cs_defs.h:454
unsigned short int cs_flag_t
Definition: cs_defs.h:299
Definition: cs_equation.h:59
cs_flag_t cs_equation_get_flag(const cs_equation_t *eq)
Return the flag associated to an equation.
Definition: cs_equation.c:2564
Definition: cs_equation.h:79
cs_field_t * cs_equation_get_field(const cs_equation_t *eq)
Return the field structure associated to a cs_equation_t structure.
Definition: cs_equation.c:2545
cs_equation_t * cs_equation_add(const char *eqname, const char *varname, cs_equation_type_t eqtype, int dim, cs_param_bc_type_t default_bc)
Add a new equation structure and set a first set of parameters.
Definition: cs_equation.c:843
int cs_equation_get_var_dim(const cs_equation_t *eq)
Return the dimension of the variable solved by this equation.
Definition: cs_equation.c:2714
void cs_equation_destroy_all(void)
Destroy all cs_equation_t structures.
Definition: cs_equation.c:985
Definition: cs_equation.h:74
Definition: cs_equation.h:60
void cs_equation_set_timer_stats(cs_equation_t *eq)
Create timer statistics structures to enable a "home-made" profiling.
Definition: cs_equation.c:1099
const char * cs_equation_get_name(const cs_equation_t *eq)
Return the name related to the given cs_equation_t structure.
Definition: cs_equation.c:2507
void cs_equation_extra_post_all(const cs_time_step_t *ts, double dt)
Predefined extra-operations related to all equations.
Definition: cs_equation.c:2958
cs_equation_t * cs_equation_by_name(const char *eqname)
Find the cs_equation_t structure with name eqname Return NULL if not find.
Definition: cs_equation.c:789
int cs_equation_get_space_poly_degree(const cs_equation_t *eq)
Return the max. degree used in the polynomial basis for the space discretization. ...
Definition: cs_equation.c:2695
Definition: cs_property.h:62
int cs_equation_get_n_equations(void)
Retrieve the number of equations.
Definition: cs_equation.c:772
Definition: cs_equation.h:78
void cs_equation_add_bc_by_value(cs_equation_t *eq, const cs_param_bc_type_t bc_type, const char *z_name, cs_real_t *values)
Define and initialize a new structure to set a boundary condition related to the given equation struc...
Definition: cs_equation.c:1883
void cs_equation_add_bc_by_array(cs_equation_t *eq, const cs_param_bc_type_t bc_type, const char *z_name, cs_flag_t loc, cs_real_t *array, cs_lnum_t *index)
Define and initialize a new structure to set a boundary condition related to the given equation struc...
Definition: cs_equation.c:1930
void cs_equation_log_monitoring(void)
Print a synthesis of the monitoring information in the performance file.
Definition: cs_equation.c:1031
Definition: cs_equation.h:66
bool cs_equation_is_steady(const cs_equation_t *eq)
Return true is the given equation is steady otherwise false.
Definition: cs_equation.c:2486