Source terms for transported scalars may be defined using the cs_user_source_terms user-defined function.
Field access and information
The following initialization block or portions thereof needs to be added for the following examples: 
  
 
  
  const cs_lnum_t  n_cells = domain->mesh->n_cells;
 
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2465
double precision, dimension(:), pointer cell_f_vol
fluid volume of each cell
Definition: mesh.f90:112
Field descriptor.
Definition: cs_field.h:131
 Indicator of variance scalars: To determine whether a scalar is a variance, the following info can be accessed: 
int cs_field_get_key_int(const cs_field_t *f, int key_id)
Return a integer value for a given key associated with a field.
Definition: cs_field.c:3213
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2719
 
- If  var_f_id == -1 , the scalar is not a variance
- If  var_f_id >= 0 , the field is the variance of the scalar with field idvar_f_id
Density
@ rho
Definition: cs_field_pointer.h:97
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
  
Example 1
Example of arbitrary source term for the scalar f, named "scalar_2" in the calculation.

appearing in the equation under the form
 In the following example:
 In the following example:
![\[A=-\frac{\rho}{\tau_f} \]](form_752.png) 
 
![\[B=\rho \cdot prod_f \]](form_753.png) 
with:
- tauf = 10.0 (in  ) (dissipation time for ) (dissipation time for ) )
- prodf = 100.0 (in ![$ [f]\cdot s^{-1} $](form_756.png) ) (production of ) (production of by unit of time) by unit of time)
which yields:
-  st_imp[i] = volume[i]*A = -volume[i]*rho/tauf 
-  st_exp[i] = volume[i]*B = volume[i]*rho*prod_f 
Body
 Source term applied to second scalar
  if (strcmp(f->
name, 
"scalar_2") == 0) {
 
 
    
 
 
      bft_printf(
" User source terms for variable %s\n",
 
 
    
 
 
    }
 
  }
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140
const char * cs_field_get_label(const cs_field_t *f)
Return a label associated with a field.
Definition: cs_field.c:4514
const cs_equation_param_t * cs_field_get_equation_param_const(const cs_field_t *f)
Access a field's equation parameters for read only.
Definition: cs_field_default.c:314
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition: cs_equation_param.h:193
int verbosity
Definition: cs_equation_param.h:213
const char * name
Definition: cs_field.h:133
Example 2
Example of arbitrary volumic heat term in the equation for enthalpy h.
In the considered example, a uniform volumic source of heating is imposed in the cells with coordinate X in [0;1.2] and Y in [3.1;4].
The global heating power if Pwatt (in  ) and the total volume of the selected cells is
) and the total volume of the selected cells is volf (in  ).
).
This yields:
-  st_imp[i] = 0 
-  st_exp[i] = volume[i]* pwatt/volf 
Body
- Warning
- It is assumed here that the thermal scalar is an enthalpy. If the scalar is a temperature. PWatt does not need to be divided by  because because is put outside the diffusion term and multiplied in the temperature equation as follows: is put outside the diffusion term and multiplied in the temperature equation as follows:
![\[ \rho C_p \norm{\vol{\celli}} \frac{dT}{dt} + ... = \norm{\vol{\celli}[i]} \frac{pwatt}{voltf} \]](form_759.png)  
 
with  pwatt = 100.0 
Apply source term
 
    
 
 
      bft_printf(
" User source terms for variable %s\n",
 
 
    
 
 
    if (z != NULL) {
 
 
      }
 
    }
 
  }
@ h
Definition: cs_field_pointer.h:91
const cs_zone_t * cs_volume_zone_by_name_try(const char *name)
Return a pointer to a volume zone based on its name if present.
Definition: cs_volume_zone.c:703
const cs_lnum_t * elt_ids
Definition: cs_zone.h:65
cs_lnum_t n_elts
Definition: cs_zone.h:64
cs_real_t f_measure
Definition: cs_zone.h:75