8.1
general documentation
Basic examples (legacy method)

The preferred method for defining boundary conditions (besides using the GUI) is to assign zone-based definitions in the cs_user_boundary_conditions_setup function (cs_user_boundary_conditions.c).

As an alternative, the same definitions may be defined in cs_user_finalize_setup_wrapper (cs_user_parameters), which is called immediately after cs_user_boundary_conditions_setup. Choosing one or the other should be based on the best balance for reability and maintainability,

Initialization

The following initialization block needs to be added for the following examples:

const cs_lnum_t n_b_faces = domain->mesh->n_b_faces;
const cs_lnum_t *b_face_cells = domain->mesh->b_face_cells;
const int n_fields = cs_field_n_fields();
const cs_real_t *bpro_rho = CS_F_(rho_b)->val;
const int keysca = cs_field_key_id("scalar_id");
const cs_zone_t *zn = NULL;
cs_real_t *vel_rcodcl1 = CS_F_(vel)->bc_coeffs->rcodcl1;
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.c:1502
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2574
@ vel
Definition: cs_field_pointer.h:68
@ rho_b
Definition: cs_field_pointer.h:98
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.c:424
real(c_double), pointer, save viscl0
reference molecular dynamic viscosity.
Definition: cstphy.f90:160
double viscl0
Definition: cs_physical_constants.h:73
Definition: cs_zone.h:55

Body

In the body, we may define several boundary conditions. Here are a few examples.

Inlet example with hydraulic diameter

Assign an inlet to boundary faces of in zone 'inlet_1'.

Warning
the <, <=, >, and >= operators may only be used with variables x, y, and z. This syntax is not a full equation interpreter, so formulas involving x, y, or z are not allowed.

Set a a Dirichlet value on the three components of $ \vect{u} $ on the faces with the selection criterion '2 and x < 0.01' and set a Dirichlet to all the scalars $ \varia $.

Turbulence example computed using equations valid for a pipe.

We will be careful to specify a hydraulic diameter adapted to the current inlet.

We will also be careful if necessary to use a more precise formula for the dynamic viscosity use in the calculation of the Reynolds number (especially if it is variable, it may be useful to take the law from cs_user_physical_properties. Here, we use by default the 'viscl0" value.

Regarding the density, we have access to its value at boundary faces (b_roh) so this value is the one used here (specifically, it is consistent with the processing in cs_user_physical_properties, in case of variable density).

zn = cs_boundary_zone_by_name("inlet_1");
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
bc_type[face_id] = CS_INLET;
vel_rcodcl1[n_b_faces*0 + face_id] = 0; /* vel_x */
vel_rcodcl1[n_b_faces*1 + face_id] = 1.1; /* vel_y */
vel_rcodcl1[n_b_faces*2 + face_id] = 0; /* vel_z */
cs_real_t uref2 = 0;
for (cs_lnum_t ii = 0; ii < 3; ii++)
uref2 += cs_math_pow2(vel_rcodcl1[n_b_faces*ii + face_id]);
uref2 = cs_math_fmax(uref2, 1e-12);
/* Turbulence example computed using equations valid for a pipe.
*
* We will be careful to specify a hydraulic diameter adapted
* to the current inlet.
* We will also be careful if necessary to use a more precise
* formula for the dynamic viscosity use in the calculation of
* the Reynolds number (especially if it is variable, it may be
* useful to take the law from 'cs_user_physical_properties'
* Here, we use by default the 'viscl0" value.
* Regarding the density, we have access to its value at boundary
* faces (b_rho) so this value is the one used here (specifically,
* it is consistent with the processing in 'cs_user_physical_properties',
* in case of variable density) */
/* Hydraulic diameter */
/* Calculation of turbulent inlet conditions using
the turbulence intensity and standard laws for a circular pipe
(their initialization is not needed here but is good practice) */
cs_real_t b_rho = bpro_rho[face_id];
uref2,
xdh,
b_rho,
}
/* Set user scalar values to 1 */
for (int f_id = 0; f_id < n_fields; f_id++) {
if (cs_field_get_key_int(f, keysca) > 0) {
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
f->bc_coeffs->rcodcl1[face_id] = 1.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.c:711
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2320
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:3068
static cs_real_t cs_math_fmax(cs_real_t x, cs_real_t y)
Compute the max value of two real values.
Definition: cs_math.h:180
static cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:238
cs_real_t cs_notebook_parameter_value_by_name(const char *name)
Return a parameter value (real).
Definition: cs_notebook.c:393
@ CS_INLET
Definition: cs_parameters.h:83
void cs_turbulence_bc_inlet_hyd_diam(cs_lnum_t face_id, double uref2, double dh, double rho, double mu)
Set inlet boundary condition values for turbulence variables based on a diameter and the reference v...
Definition: cs_turbulence_bc.c:871
cs_real_t * rcodcl1
Definition: cs_field.h:109
Field descriptor.
Definition: cs_field.h:131
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

Inlet example with turbulence intensity

Assign an inlet to boundary faces of zone 'inlet_2'.

Set a a Dirichlet value on the three components of $ \vect{u} $ on the faces with the selection criterion '3' and set a Dirichlet to all the scalars $ \varia $.

Turbulence example computed using turbulence intensity data.

We will be careful to specify a hydraulic diameter adapted to the current inlet.

Calculation of $ k $ and $ \varepsilon $ at the inlet (xkent and xeent) using the turbulence intensity and standard laws for a circular pipe (their initialization is not needed here but is good practice)

zn = cs_boundary_zone_by_name("inlet_2");
/* Hydraulic diameter: to be defined in the GUI notebook. */
/* Turbulence intensity: to be defined in the GUI notebook. */
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
bc_type[face_id] = CS_INLET;
vel_rcodcl1[n_b_faces*0 + face_id] = 0; /* vel_x */
vel_rcodcl1[n_b_faces*1 + face_id] = 1.1; /* vel_y */
vel_rcodcl1[n_b_faces*2 + face_id] = 0; /* vel_z */
cs_real_t uref2 = 0;
for (cs_lnum_t ii = 0; ii < 3; ii++)
uref2 += cs_math_pow2(vel_rcodcl1[n_b_faces*ii + face_id]);
uref2 = cs_math_fmax(uref2, 1e-12);
/* Calculation of turbulent inlet conditions using
* the turbulence intensity and standard laws for a circular pipe
* (their initialization is not needed here but is good practice) */
cs_turbulence_bc_inlet_turb_intensity(face_id, uref2, xitur, xdh);
}
/* Set user scalar values to 1 */
for (int f_id = 0; f_id < n_fields; f_id++) {
if (cs_field_get_key_int(f, keysca) > 0) {
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
f->bc_coeffs->rcodcl1[face_id] = 1.0;
}
}
}
void cs_turbulence_bc_inlet_turb_intensity(cs_lnum_t face_id, double uref2, double t_intensity, double dh)
Set inlet boundary condition values for turbulence variables based on a diameter ,...
Definition: cs_turbulence_bc.c:899

Assign an outlet to boundary faces of zone 'outlet'

Outlet:

  • zero flux for velocity and temperature, prescribed pressure
  • Note that the pressure will be set to P0 at the first
  • free outlet face (CS_OUTLET)
zn = cs_boundary_zone_by_name("outlet");
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
bc_type[face_id] = CS_OUTLET;
}
@ CS_OUTLET
Definition: cs_parameters.h:84

Wall example

Assign a wall to boundary faces of zone '5'.

Wall:

  • zero flow (zero flux for pressure)
  • friction for velocities (+ turbulent variables)
  • zero flux for scalars
/* Temperature */
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
bc_type[face_id] = CS_SMOOTHWALL;
if (th_f == NULL)
continue;
/* If temperature prescribed to 20 with wall law */
th_f->bc_coeffs->icodcl[face_id] = 5;
th_f->bc_coeffs->rcodcl1[face_id] = 20.;
/* If temperature prescribed to 50 with no wall law (simple Dirichlet)
* with exchange coefficient 8 */
th_f->bc_coeffs->icodcl[face_id] = 1;
th_f->bc_coeffs->rcodcl1[face_id] = 50.;
th_f->bc_coeffs->rcodcl2[face_id] = 8.;
/* If flux prescribed to 4. */
th_f->bc_coeffs->icodcl[face_id] = 3;
th_f->bc_coeffs->rcodcl3[face_id] = 4.;
}
@ CS_SMOOTHWALL
Definition: cs_parameters.h:87
cs_field_t * cs_thermal_model_field(void)
Definition: cs_thermal_model.c:216
cs_real_t * rcodcl2
Definition: cs_field.h:110
cs_real_t * rcodcl3
Definition: cs_field.h:111
int * icodcl
Definition: cs_field.h:108

Rough wall example

Assign a rough wall to boundary faces of zone '7'.

Wall:

  • zero flow (zero flux for pressure)
  • rough friction for velocities (+ turbulent variables)
  • zero flux for scalars
cs_real_t *bpro_roughness = NULL, *bpro_roughness_t = NULL;
if (cs_field_by_name_try("boundary_roughness") != NULL)
bpro_roughness = cs_field_by_name_try("boundary_roughness")->val;
if (cs_field_by_name_try("boundary_thermal_roughness") != NULL)
bpro_roughness_t = cs_field_by_name_try("boundary_thermal_roughness")->val;
for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
/* Wall: zero flow (zero flux for pressure)
* rough friction for velocities (+ turbulent variables)
* zero flux for scalars*/
bc_type[face_id] = CS_ROUGHWALL;
/* Roughness for velocity: 1cm */
if (bpro_roughness != NULL)
bpro_roughness[face_id] = 0.01;
/* Roughness for temperature (if required): 1cm */
if (bpro_roughness_t != NULL)
bpro_roughness_t[face_id] = 0.01;
/* If sliding wall with velocity */
CS_F_(vel)->bc_coeffs->rcodcl1[face_id] = 1.;
}
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.c:2370
@ CS_ROUGHWALL
Definition: cs_parameters.h:88
cs_real_t * val
Definition: cs_field.h:152

Symmetry example

Assign a symmetry condition to boundary faces of zone '4'

for (cs_lnum_t e_idx = 0; e_idx < zn->n_elts; e_idx++) {
const cs_lnum_t face_id = zn->elt_ids[e_idx];
bc_type[face_id] = CS_SYMMETRY;
}
@ CS_SYMMETRY
Definition: cs_parameters.h:85