programmer's documentation
Typedefs | Enumerations | Functions | Variables
cs_equation.c File Reference
#include "cs_defs.h"
#include <assert.h>
#include <string.h>
#include <float.h>
#include <stdlib.h>
#include <math.h>
#include <bft_mem.h>
#include <bft_printf.h>
#include "cs_base.h"
#include "cs_cdo.h"
#include "cs_mesh_location.h"
#include "cs_field.h"
#include "cs_multigrid.h"
#include "cs_timer_stats.h"
#include "cs_param.h"
#include "cs_cdovb_scaleq.h"
#include "cs_cdofb_scaleq.h"
#include "cs_equation.h"
Include dependency graph for cs_equation.c:

Typedefs

typedef void *( cs_equation_init_builder_t) (const cs_equation_param_t *eqp, const cs_mesh_t *mesh, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, const cs_time_step_t *time_step)
 Initialize a builder structure. More...
 
typedef void( cs_equation_compute_source_t) (void *builder)
 Compute the contribution of source terms for the current time. More...
 
typedef void( cs_equation_build_system_t) (const cs_mesh_t *mesh, const cs_real_t *field_val, double dt_cur, void *builder, cs_real_t **rhs, cs_sla_matrix_t **sla_mat)
 Build a linear system within the CDO framework. More...
 
typedef void( cs_equation_update_field_t) (const cs_real_t *solu, void *builder, cs_real_t *field_val)
 Store solution(s) of the linear system into a field structure. More...
 
typedef void( cs_equation_post_t) (const char *eqname, const cs_field_t *field, void *builder)
 Post-processing related to this equation. More...
 
typedef const double *( cs_equation_get_f_values_t) (const void *builder, const cs_field_t *field)
 Get the computed values at each face. More...
 
typedef cs_real_t *( cs_equation_get_tmpbuf_t) (void)
 Retrieve a pointer to a buffer of size at least the number of unknows. More...
 
typedef void *( cs_equation_free_builder_t) (void *builder)
 Destroy a builder structure. More...
 

Enumerations

enum  eqkey_t {
  EQKEY_HODGE_DIFF_ALGO, EQKEY_HODGE_DIFF_COEF, EQKEY_HODGE_TIME_ALGO, EQKEY_HODGE_TIME_COEF,
  EQKEY_ITSOL, EQKEY_ITSOL_EPS, EQKEY_ITSOL_MAX_ITER, EQKEY_ITSOL_RESNORM,
  EQKEY_PRECOND, EQKEY_SOLVER_FAMILY, EQKEY_SPACE_SCHEME, EQKEY_VERBOSITY,
  EQKEY_BC_ENFORCEMENT, EQKEY_BC_QUADRATURE, EQKEY_OUTPUT_FREQ, EQKEY_POST_FREQ,
  EQKEY_POST, EQKEY_ADV_OP_TYPE, EQKEY_ADV_WEIGHT_ALGO, EQKEY_ADV_WEIGHT_CRIT,
  EQKEY_ADV_FLUX_QUADRA, EQKEY_TIME_SCHEME, EQKEY_TIME_THETA, EQKEY_ERROR
}
 
enum  reakey_t {
  REAKEY_LUMPING, REAKEY_HODGE_ALGO, REAKEY_HODGE_COEF, REAKEY_INV_PTY,
  REAKEY_ERROR
}
 
enum  stkey_t { STKEY_POST, STKEY_QUADRATURE, STKEY_ERROR }
 

Functions

static void _sles_initialization (const cs_equation_t *eq)
 
static void _check_ml_name (const char *ml_name, int *p_ml_id)
 Given its name, get the id related to a cs_mesh_location_t structure. More...
 
static const char * _print_eqkey (eqkey_t key)
 Print the name of the corresponding equation key. More...
 
static const char * _print_reakey (reakey_t key)
 Print the name of the corresponding reaction term key. More...
 
static const char * _print_stkey (stkey_t key)
 Print the name of the corresponding source term key. More...
 
static eqkey_t _get_eqkey (const char *keyname)
 Get the corresponding enum from the name of an equation key. If not found, print an error message. More...
 
static reakey_t _get_reakey (const char *keyname)
 Get the corresponding enum from the name of a reaction term key. If not found, print an error message. More...
 
static stkey_t _get_stkey (const char *keyname)
 Get the corresponding enum from the name of a source term key. If not found, print an error message. More...
 
static cs_equation_param_t_create_equation_param (cs_equation_type_t type, cs_param_var_type_t var_type, cs_param_bc_type_t default_bc)
 Create a cs_equation_param_t. More...
 
cs_equation_t * cs_equation_create (const char *eqname, const char *varname, cs_equation_type_t eqtype, cs_param_var_type_t vartype, cs_param_bc_type_t default_bc)
 Define and initialize a new structure to store parameters related to an equation. More...
 
cs_equation_t * cs_equation_free (cs_equation_t *eq)
 Destroy a cs_equation_t structure. More...
 
void cs_equation_summary (const cs_equation_t *eq)
 Summary of a cs_equation_t structure. More...
 
void cs_equation_last_setup (cs_equation_t *eq)
 Assign a set of pointer functions for managing the cs_equation_t structure during the computation. More...
 
void cs_equation_set_option (cs_equation_t *eq, const char *keyname, const void *val)
 Set a parameter in a cs_equation_t structure attached to keyname. More...
 
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, time, convection) More...
 
void cs_equation_set_ic (cs_equation_t *eq, const char *def_key, void *val)
 Define the initial condition of the unknown related to this equation def_key is among "value", "analytic", "user". More...
 
void cs_equation_add_bc (cs_equation_t *eq, const char *ml_name, const char *bc_key, const char *def_key, const void *val)
 Define and initialize a new structure to store parameters related to an equation bc_key among "dirichlet", "neumann" or "robin" def_key among "value", "analytic", "user". More...
 
void cs_equation_add_reaction (cs_equation_t *eq, const char *r_name, const char *type_name, cs_property_t *property)
 Define and initialize a new structure to store parameters related to a reaction term. More...
 
void cs_equation_set_reaction_option (cs_equation_t *eq, const char *r_name, const char *keyname, const char *keyval)
 Set advanced parameters related to a reaction term keyname among "lumping", "hodge_algo", "hodge_coef"... If r_name is NULL, all reaction terms of the given equation are set according to the couple (keyname, keyval) More...
 
void cs_equation_add_source_term (cs_equation_t *eq, const char *st_name, const char *ml_name, const char *def_key, const void *val)
 Define and initialize a new structure to store parameters related to a source term def_key among "value", "analytic", "user"... More...
 
void cs_equation_set_source_term_option (cs_equation_t *eq, const char *st_name, const char *keyname, const char *keyval)
 Set advanced parameters which are members defined by default in a source term structure. keyname among "quadrature", "post"... If st_name is NULL, all source terms of the given equation are set according to keyname/keyval. More...
 
void cs_equation_create_field (cs_equation_t *eq)
 Create a field structure related to this cs_equation_t structure to an equation. More...
 
void cs_equation_init_system (const cs_mesh_t *mesh, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, const cs_time_step_t *time_step, cs_equation_t *eq)
 Initialize the values of a field according to the initial condition related to its equation. More...
 
bool cs_equation_needs_build (const cs_equation_t *eq)
 Check if one has to build the linear system. More...
 
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. More...
 
void cs_equation_solve (const cs_time_step_t *time_step, cs_equation_t *eq)
 Solve the linear system for this equation. More...
 
void cs_equation_post (const cs_time_step_t *time_step, const cs_equation_t *eq)
 Post-processing related to this equation. More...
 
bool cs_equation_is_steady (const cs_equation_t *eq)
 Return true is the given equation is steady otherwise false. More...
 
const cs_real_tcs_equation_get_face_values (const cs_equation_t *eq)
 Compute the values of the associated field at each face of the mesh If the pointer storing the values is NULL, it is alloacted inside the function. More...
 
const char * cs_equation_get_name (const cs_equation_t *eq)
 Return the name related to the given cs_equation_t structure to an equation. More...
 
cs_field_tcs_equation_get_field (const cs_equation_t *eq)
 Return the field structure associated to a cs_equation_t structure. More...
 
const cs_equation_param_tcs_equation_get_param (const cs_equation_t *eq)
 Return the cs_equation_param_t structure associated to a cs_equation_t structure. More...
 
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 (NULL if not activated). More...
 
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 (NULL if not activated). More...
 
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. More...
 
cs_param_var_type_t cs_equation_get_var_type (const cs_equation_t *eq)
 Return the type of variable solved by this equation. More...
 
cs_equation_type_t cs_equation_get_type (const cs_equation_t *eq)
 Return the type of equation for the given equation structure. More...
 

Variables

static cs_equation_algo_t _algo_info_by_default
 
static cs_param_itsol_t _itsol_info_by_default
 

Typedef Documentation

typedef void( cs_equation_build_system_t) (const cs_mesh_t *mesh, const cs_real_t *field_val, double dt_cur, void *builder, cs_real_t **rhs, cs_sla_matrix_t **sla_mat)

Build a linear system within the CDO framework.

Parameters
[in]mpointer to a cs_mesh_t structure
[in]field_valpointer to the current value of the field
[in]dt_curcurrent value of the time step
[in,out]builderpointer to builder structure
[in,out]rhspointer to a right-hand side array pointer
[in,out]sla_matpointer to cs_sla_matrix_t structure pointer
typedef void( cs_equation_compute_source_t) (void *builder)

Compute the contribution of source terms for the current time.

Parameters
[in,out]builderpointer to builder structure
typedef void*( cs_equation_free_builder_t) (void *builder)

Destroy a builder structure.

Parameters
[in,out]builderpointer to a builder structure
Returns
a NULL pointer
typedef const double*( cs_equation_get_f_values_t) (const void *builder, const cs_field_t *field)

Get the computed values at each face.

Parameters
[in]builderpointer to a builder structure
[in]fieldpointer to a cs_field_t structure
Returns
a pointer to an array of double (size n_faces)
typedef cs_real_t*( cs_equation_get_tmpbuf_t) (void)

Retrieve a pointer to a buffer of size at least the number of unknows.

Parameters
[in,out]builderpointer to a builder structure
Returns
a pointer to an array of double
typedef void*( cs_equation_init_builder_t) (const cs_equation_param_t *eqp, const cs_mesh_t *mesh, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, const cs_time_step_t *time_step)

Initialize a builder structure.

Parameters
[in]eqpointer to a cs_equation_param_t structure
[in]meshpointer to a cs_mesh_t structure
[in]connectpointer to a cs_cdo_connect_t structure
[in]quantpointer to a cs_cdo_quantities_t structure
[in]time_steptime_step structure
Returns
a pointer to a new allocated builder structure
typedef void( cs_equation_post_t) (const char *eqname, const cs_field_t *field, void *builder)

Post-processing related to this equation.

Parameters
[in]eqnamename of the equation
[in]fieldpointer to a field strufcture
[in,out]builderpointer to builder structure
typedef void( cs_equation_update_field_t) (const cs_real_t *solu, void *builder, cs_real_t *field_val)

Store solution(s) of the linear system into a field structure.

Parameters
[in]solusolution array
[in,out]builderpointer to builder structure
[in,out]field_valpointer to the current value of the field

Enumeration Type Documentation

enum eqkey_t
Enumerator
EQKEY_HODGE_DIFF_ALGO 
EQKEY_HODGE_DIFF_COEF 
EQKEY_HODGE_TIME_ALGO 
EQKEY_HODGE_TIME_COEF 
EQKEY_ITSOL 
EQKEY_ITSOL_EPS 
EQKEY_ITSOL_MAX_ITER 
EQKEY_ITSOL_RESNORM 
EQKEY_PRECOND 
EQKEY_SOLVER_FAMILY 
EQKEY_SPACE_SCHEME 
EQKEY_VERBOSITY 
EQKEY_BC_ENFORCEMENT 
EQKEY_BC_QUADRATURE 
EQKEY_OUTPUT_FREQ 
EQKEY_POST_FREQ 
EQKEY_POST 
EQKEY_ADV_OP_TYPE 
EQKEY_ADV_WEIGHT_ALGO 
EQKEY_ADV_WEIGHT_CRIT 
EQKEY_ADV_FLUX_QUADRA 
EQKEY_TIME_SCHEME 
EQKEY_TIME_THETA 
EQKEY_ERROR 
enum reakey_t
Enumerator
REAKEY_LUMPING 
REAKEY_HODGE_ALGO 
REAKEY_HODGE_COEF 
REAKEY_INV_PTY 
REAKEY_ERROR 
enum stkey_t
Enumerator
STKEY_POST 
STKEY_QUADRATURE 
STKEY_ERROR 

Function Documentation

static void _check_ml_name ( const char *  ml_name,
int *  p_ml_id 
)
static

Given its name, get the id related to a cs_mesh_location_t structure.

Parameters
[in]ml_namename of the location
[in,out]p_ml_idpointer on the id of the related mesh location
static cs_equation_param_t* _create_equation_param ( cs_equation_type_t  type,
cs_param_var_type_t  var_type,
cs_param_bc_type_t  default_bc 
)
static

Create a cs_equation_param_t.

Parameters
[in]typetype of equation
[in]var_typetype of variable (scalar, vector, tensor...)
[in]default_bctype of boundary condition set by default
Returns
a pointer to a new allocated cs_equation_param_t structure
static eqkey_t _get_eqkey ( const char *  keyname)
static

Get the corresponding enum from the name of an equation key. If not found, print an error message.

Parameters
[in]keynamename of the key
Returns
a eqkey_t
static reakey_t _get_reakey ( const char *  keyname)
static

Get the corresponding enum from the name of a reaction term key. If not found, print an error message.

Parameters
[in]keynamename of the key
Returns
a reakey_t
static stkey_t _get_stkey ( const char *  keyname)
static

Get the corresponding enum from the name of a source term key. If not found, print an error message.

Parameters
[in]keynamename of the key
Returns
a stkey_t
static const char* _print_eqkey ( eqkey_t  key)
static

Print the name of the corresponding equation key.

Parameters
[in]keyname of the key
Returns
a string
static const char* _print_reakey ( reakey_t  key)
static

Print the name of the corresponding reaction term key.

Parameters
[in]keyname of the key
Returns
a string
static const char* _print_stkey ( stkey_t  key)
static

Print the name of the corresponding source term key.

Parameters
[in]keyname of the key
Returns
a string
static void _sles_initialization ( const cs_equation_t *  eq)
static
void cs_equation_add_bc ( cs_equation_t *  eq,
const char *  ml_name,
const char *  bc_key,
const char *  def_key,
const void *  val 
)

Define and initialize a new structure to store parameters related to an equation bc_key among "dirichlet", "neumann" or "robin" def_key among "value", "analytic", "user".

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]ml_namename of the related mesh location
[in]bc_keytype of boundary condition to add
[in]def_keyway of defining the value of the bc
[in]valpointer to the value
void cs_equation_add_reaction ( cs_equation_t *  eq,
const char *  r_name,
const char *  type_name,
cs_property_t *  property 
)

Define and initialize a new structure to store parameters related to a reaction term.

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]r_namename of the source term or NULL
[in]type_nametype of reaction term to add
[in]propertypointer to a cs_property_t struct.
void cs_equation_add_source_term ( cs_equation_t *  eq,
const char *  st_name,
const char *  ml_name,
const char *  def_key,
const void *  val 
)

Define and initialize a new structure to store parameters related to a source term def_key among "value", "analytic", "user"...

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]st_namename of the source term or NULL
[in]ml_namename of the related mesh location
[in]def_keyway of defining the value of the source term
[in]valpointer to the value
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.

Parameters
[in]mpointer to a cs_mesh_t structure
[in]time_steppointer to a time step structure
[in]dt_curvalue of the current time step
[in,out]eqpointer to a cs_equation_t structure
cs_equation_t* cs_equation_create ( const char *  eqname,
const char *  varname,
cs_equation_type_t  eqtype,
cs_param_var_type_t  vartype,
cs_param_bc_type_t  default_bc 
)

Define and initialize a new structure to store parameters related to an equation.

Parameters
[in]eqnamename of the equation
[in]varnamename of the variable associated to this equation
[in]eqtypetype of equation (user, predefined...)
[in]vartypetype of variable (scalar, vector, tensor...)
[in]default_bctype of boundary condition set by default
Returns
a pointer to the new allocated cs_equation_t structure
void cs_equation_create_field ( cs_equation_t *  eq)

Create a field structure related to this cs_equation_t structure to an equation.

Parameters
[in,out]eqpointer to a cs_equation_t structure
cs_equation_t* cs_equation_free ( cs_equation_t *  eq)

Destroy a cs_equation_t structure.

Parameters
[in,out]eqpointer to a cs_equation_t structure
Returns
a NULL pointer
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 (NULL if not activated).

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a pointer to a cs_property_t structure
const cs_real_t* cs_equation_get_face_values ( const cs_equation_t *  eq)

Compute the values of the associated field at each face of the mesh If the pointer storing the values is NULL, it is alloacted inside the function.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a pointer to the values
cs_field_t* cs_equation_get_field ( const cs_equation_t *  eq)

Return the field structure associated to a cs_equation_t structure.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a cs_field_t structure or NULL if not found
const char* cs_equation_get_name ( const cs_equation_t *  eq)

Return the name related to the given cs_equation_t structure to an equation.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a name or NULL if not found
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.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a cs_equation_param_t structure or NULL if not found
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.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a cs_space_scheme_t variable
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 (NULL if not activated).

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
a pointer to a cs_property_t structure
cs_equation_type_t cs_equation_get_type ( const cs_equation_t *  eq)

Return the type of equation for the given equation structure.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
the type of the given equation
cs_param_var_type_t cs_equation_get_var_type ( const cs_equation_t *  eq)

Return the type of variable solved by this equation.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
the type of variable (sclar, vector...) associated to this equation
void cs_equation_init_system ( const cs_mesh_t mesh,
const cs_cdo_connect_t connect,
const cs_cdo_quantities_t cdoq,
const cs_time_step_t time_step,
cs_equation_t *  eq 
)

Initialize the values of a field according to the initial condition related to its equation.

Parameters
[in]meshpointer to the mesh structure
[in]connectpointer to a cs_cdo_connect_t struct.
[in]cdoqpointer to a cs_cdo_quantities_t struct.
[in]time_steppointer to a time step structure
[in,out]eqpointer to a cs_equation_t structure
bool cs_equation_is_steady ( const cs_equation_t *  eq)

Return true is the given equation is steady otherwise false.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
true or false
void cs_equation_last_setup ( cs_equation_t *  eq)

Assign a set of pointer functions for managing the cs_equation_t structure during the computation.

Parameters
[in,out]eqpointer to a cs_equation_t structure
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, time, convection)

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]keyword"time", "diffusion", "advection"
[in]pointerpointer to a given structure
bool cs_equation_needs_build ( const cs_equation_t *  eq)

Check if one has to build the linear system.

Parameters
[in]eqpointer to a cs_equation_t structure
Returns
true or false
void cs_equation_post ( const cs_time_step_t time_step,
const cs_equation_t *  eq 
)

Post-processing related to this equation.

Parameters
[in]time_steppointer to a time step structure
[in]eqpointer to a cs_equation_t structure
void cs_equation_set_ic ( cs_equation_t *  eq,
const char *  def_key,
void *  val 
)

Define the initial condition of the unknown related to this equation def_key is among "value", "analytic", "user".

Define the initial condition of the unknown related to this equation def_key is among "value", "analytic".

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]def_keyway of defining the value of the bc
[in]valpointer to the value
void cs_equation_set_option ( cs_equation_t *  eq,
const char *  keyname,
const void *  val 
)

Set a parameter in a cs_equation_t structure attached to keyname.

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]keynamename of key related to the member of eq to set
[in]valaccessor to the value to set
void cs_equation_set_reaction_option ( cs_equation_t *  eq,
const char *  r_name,
const char *  keyname,
const char *  keyval 
)

Set advanced parameters related to a reaction term keyname among "lumping", "hodge_algo", "hodge_coef"... If r_name is NULL, all reaction terms of the given equation are set according to the couple (keyname, keyval)

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]r_namename of the reaction term
[in]keynamename of the key
[in]keyvalpointer to the value to set to the key
void cs_equation_set_source_term_option ( cs_equation_t *  eq,
const char *  st_name,
const char *  keyname,
const char *  keyval 
)

Set advanced parameters which are members defined by default in a source term structure. keyname among "quadrature", "post"... If st_name is NULL, all source terms of the given equation are set according to keyname/keyval.

Set members defined by default in a source term structure keyname among "quadrature", "post"...

Parameters
[in,out]eqpointer to a cs_equation_t structure
[in]st_namename of the source term
[in]keynamename of the key
[in]keyvalpointer to the value to set to the key
void cs_equation_solve ( const cs_time_step_t time_step,
cs_equation_t *  eq 
)

Solve the linear system for this equation.

Parameters
[in]time_steppointer to a time step structure
[in,out]eqpointer to a cs_equation_t structure
void cs_equation_summary ( const cs_equation_t *  eq)

Summary of a cs_equation_t structure.

Parameters
[in]eqpointer to a cs_equation_t structure

Variable Documentation

cs_equation_algo_t _algo_info_by_default
static
Initial value:
= {
0,
50,
0,
10000,
1e-6
}
Definition: cs_equation_priv.h:73
cs_param_itsol_t _itsol_info_by_default
static
Initial value:
= {
2500,
1e-12,
150,
false
}
Definition: cs_param.h:360
Definition: cs_param.h:346