7.1
general documentation
For velocity components equation (Navier-Stokes)

Additional right-hand side source terms for velocity components equation (Navier-Stokes)

Local variables and initialization

/* field structure */
const cs_field_t *f = cs_field_by_id(f_id);
/* mesh quantities */
const cs_lnum_t n_cells = cs_glob_mesh->n_cells;
/* density */
const cs_real_t *cpro_rom = CS_F_(rho)->val;

Example

Example of arbitrary source term for component $\vect{u}$:

$ \vect{S} = \tens{A} \cdot \vect{u} + \vect{B} $ appearing in the equation under the form:

$ \rho \dfrac{d\vect{u}}{dt} = \vect{S} \: (+ \text{standard Navier-Stokes terms})$

In the following example:

\[ \tens{A} = -\rho \cdot \tens{CKP} \]

\[ \vect{B} = \vect{XMMT} \]

with:

  • CKP = 1.0 (in $ s^{-1}$) (return term on velocity)
  • MMT = 100.0 (in $kg \cdot m^{-2} \cdot s^{-2}$) (momentum production by volume and time unit)

which yields:

  • st_imp[i][0][0] = volume[i] * A = - volume[i]*(rho*CKP)
  • st_exp[i][0] = volume[i] * B = volume[i]*(XMMT)

Body

if (f == CS_F_(vel)) { /* velocity */
/* cast to 3D vectors for readability */
cs_real_3_t *_st_exp = (cs_real_3_t *)st_exp;
cs_real_33_t *_st_imp = (cs_real_33_t *)st_imp;
/* Density */
const cs_real_t ckp = 10.0;
const cs_real_t xmmt = 100.0;
for (cs_lnum_t i = 0; i < n_cells; i++) {
_st_imp[i][0][0] = - cell_f_vol[i] * cpro_rom[i] * ckp;
_st_exp[i][0] = cell_f_vol[i] * cpro_rom[i] * xmmt;
}
}

Example of a boussinesq momentum source term

Example to add Boussinesq source to the z component of $\vect{u}$:

Body

if (f == CS_F_(vel) && CS_F_(t) != NULL) { /* velocity and temperature */
/* expansion coefficient and reference density */
const cs_real_t beta = 1.;
/* get temperature */
const cs_real_t *cvar_temperature = CS_F_(t)->val;
/* source term (in z direction here) */
cs_real_3_t *_st_exp = (cs_real_3_t *)st_exp;
for (cs_lnum_t i = 0; i < n_cells; i++) {
_st_exp[i][2] = cell_f_vol[i] * ro0 * beta * (cvar_temperature[i]-t0);
}
}