7.1
general documentation
Examples of data settings for source terms with scalar in a channel

Additional right-hand side source terms for scalar equations (user scalars and specific physics scalars) with the cs_user_source_terms user-defined function.

Local variables and initialization

/* field structure */
const cs_field_t *f = cs_field_by_id(f_id);
/* local number of mesh cells */
const cs_lnum_t n_cells = cs_glob_mesh->n_cells;
/* mesh quantities */

Only apply to thermal scalar

return;

Function body

Map required fields

/* velocity */
const cs_real_3_t *cvar_vel = (const cs_real_3_t *)(CS_F_(vel)->val);

Compute bulk mean velocity

/* bulk mean velocity (x component) */
cs_real_t ubulk = 0;
for (cs_lnum_t i = 0; i < n_cells; i++)
ubulk += cvar_vel[i][0] * cell_f_vol[i];
cs_parall_sum(1, CS_DOUBLE, &ubulk); /* sum across processes if needed */

Compute source terms; we want to impose a total flux of 1 Watt.

/* Flux x Total surface / (rho Cp) */
cs_real_t tot_flux = 1.;
for (cs_lnum_t i = 0; i < n_cells; i++) {
st_imp[i] = 0.;
st_exp[i] = cell_f_vol[i] * cvar_vel[i][0] * tot_flux / ubulk;
}