8.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 = nullptr;
cs_field_t *scal = cs_field_by_name("scalar1");
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
cs_field_t * cs_field_by_name(const char *name)
Return a pointer to a field based on its name.
Definition: cs_field.cpp:2489
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.cpp:1593
Field descriptor.
Definition: cs_field.h:131
Definition: cs_zone.h:55

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;
}
const cs_zone_t * cs_boundary_zone_by_name(const char *name)
Return a pointer to a boundary zone based on its name if present.
Definition: cs_boundary_zone.cpp:711
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
@ vel
Definition: cs_field_pointer.h:70
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
const cs_real_t cs_math_infinite_r
@ CS_SMOOTHWALL
Definition: cs_parameters.h:89
cs_real_t * rcodcl2
Definition: cs_field.h:110
cs_real_t * rcodcl3
Definition: cs_field.h:111
cs_real_t * rcodcl1
Definition: cs_field.h:109
int * icodcl
Definition: cs_field.h:108
cs_field_bc_coeffs_t * bc_coeffs
Definition: cs_field.h:163
const cs_lnum_t * elt_ids
Definition: cs_zone.h:65
cs_lnum_t n_elts
Definition: cs_zone.h:64

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.;
}
}
}
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.cpp:2465
@ CS_INDEF
Definition: cs_parameters.h:84
#define CS_FIELD_VARIABLE
Definition: cs_field.h:63
int type
Definition: cs_field.h:136
int dim
Definition: cs_field.h:138

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") != nullptr) {
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;
}
}
cs_field_t * cs_field_by_name_try(const char *name)
Return a pointer to a field based on its name if present.
Definition: cs_field.cpp:2515
cs_real_t * val
Definition: cs_field.h:152