9.2
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 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. */
cs_field_t *scal = cs_field("scalar1");
Field descriptor.
Definition: cs_field.h:275
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.cpp:1505
cs_field_t * cs_field(int id)
Return a pointer to a field based on its id. This function requires that a field of the given id is d...
Definition: cs_field.cpp:4295

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.
{
const cs_zone_t *zn = cs_boundary_zone_by_name("wall_s");
const cs_lnum_t n_elts = zn->n_elts;
const cs_lnum_t *elt_ids = zn->elt_ids;
int *vel_icodcl = CS_F_(vel)->bc_coeffs->icodcl;
auto vel_val_ext = CS_F_(vel)->bc_coeffs->get_val_ext_v();
auto vel_h_ext = CS_F_(vel)->bc_coeffs->get_h_ext_v();
auto vel_q_ext = CS_F_(vel)->bc_coeffs->get_q_ext_v();
int *scal_icodcl = scal->bc_coeffs->icodcl;
auto scal_val_ext = scal->bc_coeffs->get_val_ext();
auto scal_h_ext = scal->bc_coeffs->get_h_ext();
auto scal_q_ext = scal->bc_coeffs->get_q_ext();
for (cs_lnum_t elt_idx = 0; elt_idx < n_elts; elt_idx++) {
const cs_lnum_t face_id = elt_ids[elt_idx];
bc_type[face_id] = CS_SMOOTHWALL;
scal_icodcl[face_id] = CS_BC_DIRICHLET;
vel_icodcl[face_id] = CS_BC_DIRICHLET;
/* Dirichlet value */
scal_val_ext[face_id] = 10.;
vel_val_ext(face_id, 0) = 1.;
vel_val_ext(face_id, 1) = 0.;
vel_val_ext(face_id, 2) = 0.;
/* No exchange coefficient */
scal_h_ext[face_id] = cs_math_infinite_r;
vel_h_ext(face_id, 0) = cs_math_infinite_r;
vel_h_ext(face_id, 1) = cs_math_infinite_r;
vel_h_ext(face_id, 2) = cs_math_infinite_r;
/* Flux density at 0 */
scal_q_ext[face_id] = 0;
vel_q_ext(face_id, 0) = 0;
vel_q_ext(face_id, 1) = 0;
vel_q_ext(face_id, 1) = 0;
}
}
cs_span< cs_real_t > get_h_ext() const
Return a 1D span view of boundary condition external exchange coefficient.
Definition: cs_field.cpp:5931
cs_span< cs_real_t > get_val_ext() const
Return a 1D span view of boundary condition external values.
Definition: cs_field.cpp:5826
cs_span< cs_real_t > get_q_ext() const
Return a 1D span view of boundary condition prescribed flux.
Definition: cs_field.cpp:6018
int * icodcl
Definition: cs_field.h:111
cs_field_bc_coeffs_t * bc_coeffs
Definition: cs_field.h:309
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:708
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
@ vel
Definition: cs_field_pointer.h:66
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:47
static constexpr cs_real_t cs_math_infinite_r
Definition: cs_math.h:105
@ CS_BC_DIRICHLET
Definition: cs_param_types.h:506
@ CS_SMOOTHWALL
Definition: cs_parameters.h:87
Definition: cs_zone.h:51
const cs_lnum_t * elt_ids
Definition: cs_zone.h:61
cs_lnum_t n_elts
Definition: cs_zone.h:60

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.

{
const cs_zone_t *zn = cs_boundary_zone_by_name("surf_h");
const cs_lnum_t n_elts = zn->n_elts;
const cs_lnum_t *elt_ids = zn->elt_ids;
/* CAUTION: the value of bc_type must be assigned to CS_UNDEF */
for (cs_lnum_t elt_idx = 0; elt_idx < n_elts; elt_idx++) {
const cs_lnum_t face_id = elt_ids[elt_idx];
bc_type[face_id] = CS_UNDEF;
}
for (int f_id = 0; f_id < n_fields; f_id++) {
cs_field_t *f = cs_field(f_id);
if (!(f->type & CS_FIELD_VARIABLE))
continue;
int *icodcl = f->bc_coeffs->icodcl;
auto val_ext = f->bc_coeffs->get_val_ext_2d();
auto h_ext = f->bc_coeffs->get_h_ext_2d();
auto q_ext = f->bc_coeffs->get_q_ext_2d();
for (cs_lnum_t elt_idx = 0; elt_idx < n_elts; elt_idx++) {
const cs_lnum_t face_id = elt_ids[elt_idx];
icodcl[face_id] = CS_BC_NEUMANN;
for (cs_lnum_t ii = 0; ii < f->dim; ii++) {
val_ext(face_id, ii) = 0.;
h_ext(face_id, ii) = cs_math_infinite_r;
q_ext(face_id, ii) = 0.;
}
}
}
}
cs::mdspan< cs_real_t, 2, cs::layout::left > get_q_ext_2d() const
Return a 2D span view of boundary condition prescribed flux (1st dimension: face id,...
Definition: cs_field.cpp:6038
cs::mdspan< cs_real_t, 2, cs::layout::left > get_val_ext_2d() const
Return a 2D span view of boundary condition external values (1st dimension: face id,...
Definition: cs_field.cpp:5868
cs::mdspan< cs_real_t, 2, cs::layout::left > get_h_ext_2d() const
Return a 2D span view of boundary condition external exchange coefficient (1st dimension: face id,...
Definition: cs_field.cpp:5951
int type
Definition: cs_field.h:282
int dim
Definition: cs_field.h:284
@ CS_BC_NEUMANN
Definition: cs_param_types.h:511
@ CS_UNDEF
Definition: cs_parameters.h:82
#define CS_FIELD_VARIABLE
Definition: cs_field.h:66

Example 3

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

{
const cs_zone_t *zn = cs_boundary_zone_by_name("r_wall");
const cs_lnum_t n_elts = zn->n_elts;
const cs_lnum_t *elt_ids = zn->elt_ids;
if (cs_field_try("boundary_roughness") != nullptr) {
auto bpro_roughness = cs_field("boundary_roughness")->get_val_s();
for (cs_lnum_t elt_idx = 0; elt_idx < n_elts; elt_idx++) {
const cs_lnum_t face_id = elt_ids[elt_idx];
bc_type[face_id] = CS_SMOOTHWALL;
/* Boundary roughtness (in meter) */
bpro_roughness[face_id] = 0.05;
}
}
}
cs_span< cs_real_t > get_val_s(const int time_id=0) const
Return a 1D span view of field values. If the field is not a scalar a fatal error is provoked.
Definition: cs_field.cpp:5080
cs_field_t * cs_field_try(int id)
Return a pointer to a field based on its id. If no field of the given name is defined,...
Definition: cs_field.cpp:4371