7.3
general documentation
Advanced examples

Local variables common to following examples

The following declaration and initialization block is required used for the examples of this section:

const cs_lnum_t n_b_faces = domain->mesh->n_b_faces;
const int n_fields = cs_field_n_fields();
/* Example of specific boundary conditions fully defined by the user,
* on the basis of wall conditions.
*
* We prescribe for zone 'wall_s' a wall, with in addition:
* - a Dirichlet condition on velocity (sliding wall with no-slip condition)
* - a Dirichlet condition on the first scalar. */
const cs_zone_t *zn = NULL;
cs_field_t *scal = cs_field_by_name("scalar1");

Initialization and finalization

Initialization and finalization is similar to that of the base examples

Example 1

Example of specific boundary conditions fully defined by the user, on the basis of wall conditions selection (mass flow computation, specific logging, ...)

²We prescribe for zone 'wall_s' a wall, with in addition:

  • a Dirichlet condition on velocity (sliding wall with no-slip condition)
  • a Dirichlet condition on the first scalar.
zn = cs_boundary_zone_by_name("wall_s");
cs_real_t *vel_rcodcl1 = CS_F_(vel)->bc_coeffs->rcodcl1;
cs_real_t *vel_rcodcl2 = CS_F_(vel)->bc_coeffs->rcodcl2;
cs_real_t *vel_rcodcl3 = CS_F_(vel)->bc_coeffs->rcodcl3;
for (cs_lnum_t ilelt = 0; ilelt < zn->n_elts; ilelt++) {
const cs_lnum_t face_id = zn->elt_ids[ilelt];
bc_type[face_id] = CS_SMOOTHWALL;
scal->bc_coeffs->icodcl[face_id] = 1;
CS_F_(vel)->bc_coeffs->icodcl[face_id] = 1;
/* Dirichlet value */
scal->bc_coeffs->rcodcl1[face_id] = 10.;
vel_rcodcl1[n_b_faces*0 + face_id] = 1.;
vel_rcodcl1[n_b_faces*1 + face_id] = 0.;
vel_rcodcl1[n_b_faces*2 + face_id] = 0.;
/* No exchange coefficient */
vel_rcodcl2[n_b_faces*0 + face_id] = cs_math_infinite_r;
vel_rcodcl2[n_b_faces*1 + face_id] = cs_math_infinite_r;
vel_rcodcl2[n_b_faces*2 + face_id] = cs_math_infinite_r;
/* Flux density at 0 */
scal->bc_coeffs->rcodcl3[face_id] = 0;
vel_rcodcl3[n_b_faces*0 + face_id] = 0;
vel_rcodcl3[n_b_faces*1 + face_id] = 0;
vel_rcodcl3[n_b_faces*2 + face_id] = 0;
}

Example 2

Example of specific boundary conditions fully defined by the user, with no definition of a specific type.

We prescribe at zone 'surf_h' a homogeneous Neumann condition for all variables.

zn = cs_boundary_zone_by_name("surf_h");
for (cs_lnum_t ilelt = 0; ilelt < zn->n_elts; ilelt++) {
const cs_lnum_t face_id = zn->elt_ids[ilelt];
/* CAUTION: the value of bc_type must be assigned to CS_INDEF */
bc_type[face_id] = CS_INDEF;
for (int f_id = 0; f_id < n_fields; f_id++) {
if (!(f->type & CS_FIELD_VARIABLE))
continue;
f->bc_coeffs->icodcl[face_id] = 3;
for (cs_lnum_t ii = 0; ii < f->dim; ii++) {
f->bc_coeffs->rcodcl1[n_b_faces*ii + face_id] = 0.;
f->bc_coeffs->rcodcl2[n_b_faces*ii + face_id] = cs_math_infinite_r;
f->bc_coeffs->rcodcl3[n_b_faces*ii + face_id] = 0.;
}
}
}

Example 3

Example of wall boundary condition with automatic continuous switch between rough and smooth.

zn = cs_boundary_zone_by_name("r_wall");
if (cs_field_by_name_try("boundary_roughness") != NULL) {
cs_real_t *bpro_roughness = cs_field_by_name_try("boundary_roughness")->val;
for (cs_lnum_t ilelt = 0; ilelt < zn->n_elts; ilelt++) {
const cs_lnum_t face_id = zn->elt_ids[ilelt];
bc_type[face_id] = CS_SMOOTHWALL;
/* Boundary roughtness (in meter) */
bpro_roughness[face_id] = 0.05;
}
}