8.1
general documentation
Infinite channel inlet with near-inlet feedback

A second method of defining an inlet condition which converges towards an infinite channel profile is based simply on feedback from values computed at inlet cell centers (combining the inlet boundary conditions and the effect of wall friction on the inlet walls). It assumes the mesh is very regular and orthogonal, at least on the first two inlet cell layers (using a gradient correction in the case of a less regular mesh might work, but has never been tested.

Initialization and finalization

Initialization and finalization is similar to that of the base examples

const cs_lnum_t n_cells_ext = domain->mesh->n_cells_with_ghosts;
const cs_lnum_t n_b_faces = domain->mesh->n_b_faces;
const int n_fields = cs_field_n_fields();
const int keysca = cs_field_key_id("scalar_id");
const int nt_cur = domain->time_step->nt_cur;
const cs_lnum_t *b_face_cells = domain->mesh->b_face_cells;
const cs_real_3_t *restrict b_face_normal
= (const cs_real_3_t *restrict)domain->mesh_quantities->b_face_normal;
const cs_real_t *restrict b_face_surf
= ( const cs_real_t *restrict)domain->mesh_quantities->b_face_surf;
const cs_real_t *bpro_rho = CS_F_(rho_b)->val;
const cs_real_3_t *cvar_vel = (const cs_real_3_t *)CS_F_(vel)->val;
const cs_zone_t *zn = NULL;
#define restrict
Definition: cs_defs.h:139
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:334
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

Here, we define an inlet boundary condition for a very long channel or duct with a section matching the boundary faces of zone 'INLET'.

We fix a mean inlet velocity, and use a feedback loop assuming a fixed-point type behavior will allow us to reach a state matching that of a very long inlet channel.

Warning
We assume other boundary conditions are defined before this one (ideally, using the GUI).
We also assume that the mesh is orthogonal at the inlet, and we are using a RANS (not LES) computation. to the current inlet.

For EBRSM of V2f models, to avoid laminarization at the inlet, the initial velocity (at the first time step) is divided by 10 on inlet faces adjacent to the boundary, so as to ensure a velocity gradient and turbulent production. Otherwise, the initialization may fail.

zn = cs_boundary_zone_by_name("inlet");
const cs_real_t fmprsc = 1.; // mean prescribed velocity
if (nt_cur == 1) {
/* For the Rij-EBRSM model (and possibly V2f), we need a non-flat profile,
* so as to ensure turbulent production, and avoid laminarization;
* here, we simply divide the initial velocity by 10 for inlet
* faces adjacent to the wall.
* The loop below assumes wall conditions have been defined first
* (in the GUI, or in this file, before the current test). */
int *mrkcel = NULL;
BFT_MALLOC(mrkcel, n_cells_ext, int);
for (cs_lnum_t i = 0; i < n_cells_ext; i++)
mrkcel[i] = 0;
for (cs_lnum_t f_id = 0; f_id < n_b_faces; f_id++) {
if (bc_type[f_id] == CS_SMOOTHWALL) {
const cs_lnum_t c_id = b_face_cells[f_id];
mrkcel[c_id] = 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];
const cs_lnum_t c_id = b_face_cells[face_id];
bc_type[face_id] = CS_INLET;
for (int ii = 0; ii< CS_F_(vel)->dim; ii++)
CS_F_(vel)->bc_coeffs->rcodcl1[n_b_faces*ii + face_id]
= -fmprsc*b_face_normal[face_id][ii]/b_face_surf[face_id];
if (mrkcel[c_id] == 1)
CS_F_(vel)->bc_coeffs->rcodcl1[n_b_faces*0 + face_id] = fmprsc/10;
cs_real_t uref2 = 0;
for (int ii = 0; ii< CS_F_(vel)->dim; ii++)
uref2 += pow(CS_F_(vel)->bc_coeffs->rcodcl1[n_b_faces*ii + face_id], 2);
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 */
cs_real_t xdh = 1.0;
/* 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,
for (int f_id = 0; f_id < n_fields; f_id++) {
cs_field_t *fld = cs_field_by_id(f_id);
/* Here we only handle user scalar */
int sc_id = cs_field_get_key_int(fld, keysca) - 1;
if (sc_id < 0)
continue;
fld->bc_coeffs->rcodcl1[face_id] = 1;
}
}
BFT_FREE(mrkcel);
}
else {
/* Subsequent time steps
*----------------------*/
cs_real_2_t acc = {0, 0};
/* Estimate multiplier */
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];
const cs_lnum_t c_id = b_face_cells[face_id];
const cs_real_t vnrm = cs_math_3_norm(cvar_vel[c_id]);
acc[0] += vnrm*b_face_surf[face_id];
acc[1] += b_face_surf[face_id];
}
cs_real_t fmul = 0; /* zero velocity in bulk domain */
if (acc[0] > cs_math_epzero)
fmul = fmprsc/(acc[0]/acc[1]); /* estimate flow multiplier */
/* Apply BC */
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];
const cs_lnum_t c_id = b_face_cells[face_id];
const cs_real_t vnrm = cs_math_3_norm(cvar_vel[c_id]);
bc_type[face_id] = CS_INLET;
for (int ii = 0; ii< CS_F_(vel)->dim; ii++)
CS_F_(vel)->bc_coeffs->rcodcl1[n_b_faces*ii + face_id]
= -fmul*vnrm*b_face_normal[face_id][ii]/b_face_surf[face_id];
CS_F_(k)->bc_coeffs->rcodcl1[face_id] = CS_F_(k)->val[c_id];
CS_F_(eps)->bc_coeffs->rcodcl1[face_id] = CS_F_(eps)->val[c_id];
}
else if (cs_glob_turb_model->itytur == 3) {
for (cs_lnum_t ii = 0; ii< CS_F_(rij)->dim; ii++)
CS_F_(rij)->bc_coeffs->rcodcl1[n_b_faces*ii + face_id]
= CS_F_(rij)->val[c_id];
CS_F_(eps)->bc_coeffs->rcodcl1[face_id] = CS_F_(eps)->val[c_id];
CS_F_(alp_bl)->bc_coeffs->rcodcl1[face_id] = CS_F_(alp_bl)->val[c_id];
}
else if (cs_glob_turb_model->itytur == 5) {
CS_F_(k)->bc_coeffs->rcodcl1[face_id] = CS_F_(k)->val[c_id];
CS_F_(eps)->bc_coeffs->rcodcl1[face_id] = CS_F_(eps)->val[c_id];
CS_F_(phi)->bc_coeffs->rcodcl1[face_id] = CS_F_(phi)->val[c_id];
CS_F_(f_bar)->bc_coeffs->rcodcl1[face_id] = CS_F_(f_bar)->val[c_id];
CS_F_(alp_bl)->bc_coeffs->rcodcl1[face_id] = CS_F_(alp_bl)->val[c_id];
}
CS_F_(k)->bc_coeffs->rcodcl1[face_id] = CS_F_(k)->val[c_id];
CS_F_(omg)->bc_coeffs->rcodcl1[face_id] = CS_F_(omg)->val[c_id];
}
CS_F_(nusa)->bc_coeffs->rcodcl1[face_id] = CS_F_(nusa)->val[c_id];
}
for (int f_id = 0; f_id < n_fields; f_id++) {
cs_field_t *fld = cs_field_by_id(f_id);
/* Here we only handle user scalar */
int sc_id = cs_field_get_key_int(fld, keysca) - 1;
if (sc_id < 0)
continue;
fld->bc_coeffs->rcodcl1[face_id] = fld->val[c_id];
}
}
}
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
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
#define CS_REAL_TYPE
Definition: cs_defs.h:458
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:333
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
@ alp_bl
Definition: cs_field_pointer.h:77
@ nusa
Definition: cs_field_pointer.h:81
@ k
Definition: cs_field_pointer.h:70
@ eps
Definition: cs_field_pointer.h:71
@ omg
Definition: cs_field_pointer.h:80
@ rij
Definition: cs_field_pointer.h:73
@ phi
Definition: cs_field_pointer.h:75
@ f_bar
Definition: cs_field_pointer.h:76
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_3_norm(const cs_real_t v[3])
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_math.h:440
const cs_real_t cs_math_epzero
static void cs_parall_sum(int n, cs_datatype_t datatype, void *val)
Sum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:154
@ CS_INLET
Definition: cs_parameters.h:83
@ CS_SMOOTHWALL
Definition: cs_parameters.h:87
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
const cs_turb_model_t * cs_glob_turb_model
@ CS_TURB_SPALART_ALLMARAS
Definition: cs_turbulence_model.h:69
@ CS_TURB_RIJ_EPSILON_EBRSM
Definition: cs_turbulence_model.h:62
@ CS_TURB_V2F_PHI
Definition: cs_turbulence_model.h:66
@ CS_TURB_V2F_BL_V2K
Definition: cs_turbulence_model.h:67
@ CS_TURB_K_OMEGA
Definition: cs_turbulence_model.h:68
cs_real_t * rcodcl1
Definition: cs_field.h:109
Field descriptor.
Definition: cs_field.h:131
cs_real_t * val
Definition: cs_field.h:152
cs_field_bc_coeffs_t * bc_coeffs
Definition: cs_field.h:163
int iturb
Definition: cs_turbulence_model.h:117
int itytur
Definition: cs_turbulence_model.h:139
const cs_lnum_t * elt_ids
Definition: cs_zone.h:65
cs_lnum_t n_elts
Definition: cs_zone.h:64