My Project
programmer's documentation
Transported scalar source terms

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:

/* field structure */
/* mesh quantities */
const cs_lnum_t n_cells = cs_glob_mesh->n_cells;

Indicator of variance scalars: To determine whether a scalar is a variance, the following info can be accessed:

int var_f_id = cs_field_get_key_int(f, cs_field_key_id("first_moment_id"));
  • 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 id var_f_id

Density

const cs_real_t *cpro_rom = CS_F_(rho)->val;

Example 1

Example of arbitrary source term for the scalar f, named "scalar_2" in the calculation.

$ S=A \cdot f+B $

appearing in the equation under the form

$ \rho \dfrac{df}{dt}=S \: \text{(+ regular other terms in the equation)} $ In the following example:

\[A=-\frac{\rho}{\tau_f} \]

\[B=\rho \cdot prod_f \]

with:

  • tauf = 10.0 (in $ s $) (dissipation time for $f$)
  • prodf = 100.0 (in $ [f]\cdot s^{-1} $) (production of $f$ 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) {
/* logging */
const cs_var_cal_opt_t *var_cal_opt
cs_field_key_id("var_cal_opt"));
if (var_cal_opt->iwarni >= 1)
bft_printf(" User source terms for variable %s\n",
/* apply source terms to all cells */
const cs_real_t tauf = 10.0;
const cs_real_t prodf = 100.0;
for (cs_lnum_t i = 0; i < n_cells; i++) {
st_imp[i] = - cell_f_vol[i]*cpro_rom[i]/tauf;
st_exp[i] = cell_f_vol[i]*cpro_rom[i]*prodf;
}
}

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 $W$) and the total volume of the selected cells is volf (in $m^3$).

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 $ C_p $ because $C_p$ 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} \]

with pwatt = 100.0

Apply source term

if (f == CS_F_(h)) { /* enthalpy */
/* logging */
const cs_var_cal_opt_t *var_cal_opt
cs_field_key_id("var_cal_opt"));
if (var_cal_opt->iwarni >= 1)
bft_printf(" User source terms for variable %s\n",
/* apply source terms in zone cells */
const cs_zone_t *z = cs_volume_zone_by_name_try("heater");
if (z != NULL) {
cs_real_t pwatt = 100.0;
cs_real_t voltf = z->f_measure;
for (cs_lnum_t i = 0; i < z->n_elts; i++) {
cs_lnum_t c_id = z->elt_ids[i];
st_exp[c_id] = cell_f_vol[c_id]*pwatt/voltf;
}
}
}
cs_volume_zone_by_name_try
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:702
cs_mesh_t::n_cells
cs_lnum_t n_cells
Definition: cs_mesh.h:73
f_id
void const int * f_id
Definition: cs_gui.h:292
cs_zone_t
Definition: cs_zone.h:55
cs_glob_mesh_quantities
cs_mesh_quantities_t * cs_glob_mesh_quantities
mesh::cell_f_vol
double precision, dimension(:), pointer cell_f_vol
Definition: mesh.f90:156
rho
Definition: cs_field_pointer.h:103
cs_field_t::name
const char * name
Definition: cs_field.h:126
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_glob_mesh
cs_mesh_t * cs_glob_mesh
cs_zone_t::f_measure
cs_real_t f_measure
Definition: cs_zone.h:75
cs_field_get_key_struct_const_ptr
const void * cs_field_get_key_struct_const_ptr(const cs_field_t *f, int key_id)
Return a read-only pointer to a simple structure for a given key to a field.
Definition: cs_field.c:3533
cs_field_get_key_int
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:2976
CS_F_
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_field_by_id
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2307
cs_mesh_quantities_t::cell_vol
cs_real_t * cell_vol
Definition: cs_mesh_quantities.h:93
cs_zone_t::elt_ids
const cs_lnum_t * elt_ids
Definition: cs_zone.h:65
cs_var_cal_opt_t
structure containing the variable calculation options.
Definition: cs_parameters.h:60
cs_field_key_id
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2490
cs_var_cal_opt_t::iwarni
int iwarni
Definition: cs_parameters.h:61
cs_zone_t::n_elts
cs_lnum_t n_elts
Definition: cs_zone.h:64
h
Definition: cs_field_pointer.h:97
cs_field_t
Field descriptor.
Definition: cs_field.h:124
bft_printf
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140
cs_field_get_label
const char * cs_field_get_label(const cs_field_t *f)
Return a label associated with a field.
Definition: cs_field.c:4257