A method of defining an inlet condition which converges towards an infinite channel profile is based simply on feedback from values computed downstream from the inlet.
Here, we define an inlet boundary condition for a very long channel or duct with a section matching the boundary faces of zone 'INLET'.
Initialization and finalization
Initialization and finalization is similar to that of the base examples, with the addition of the mapping object, described in a specific section hereafter
Base definition
- Warning
- We assume other boundary conditions are defined before this one (ideally, using the GUI).
The base definition given here ensures initialization of a (flat) inlet profile with the required mean velocity.
- Note
- We may skip the addition of the following block in the user subroutine if we define an equivalent inlet condition using the GUI, which will ensure the appropriate initialization before entering the user function.
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];
vel_rcodcl1[n_b_faces*0 + face_id] = -fmprsc;
uref2,
xdh,
b_rho,
for (int f_id = 0; f_id < n_fields; f_id++) {
}
}
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
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
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.cpp:3275
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.cpp:2465
@ 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
static CS_F_HOST_DEVICE cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:561
static CS_F_HOST_DEVICE 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:503
@ CS_INLET
Definition: cs_parameters.h:85
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.cpp:772
real(c_double), pointer, save viscl0
reference molecular dynamic viscosity.
Definition: cstphy.f90:160
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
Mapping definition
To define the appropriate mapping object, the cs_boundary_conditions_map function is used. In this example, coordinates of the selected inlet face are shifted by a constant distance (5.95 meters along the x axis), and mapped to the corresponding mesh cells. Here, all cells are selected as point location candidates, but optionally, a restricted list of cells may be provided, which may accelerate location (or ensure it is done on a selected subset). In most cases, as in this example, a constant coordinate shift is used for all inlet points, but it is possible to define a specific shift for each face.
ple_locator_t *inlet_l = nullptr;
if (nt_cur == nt_prev) {
cs_real_t coord_shift[1][3] = {{5.95, 0, 0}};
for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++)
cells_ids[c_id] = c_id;
n_cells,
zn->n_elts,
cells_ids,
zn->elt_ids,
coord_shift,
0,
0.10);
}
#define BFT_FREE(_ptr)
Definition: bft_mem.h:90
#define BFT_MALLOC(_ptr, _ni, _type)
Definition: bft_mem.h:58
ple_locator_t * cs_boundary_conditions_map(cs_mesh_location_type_t location_type, cs_lnum_t n_location_elts, cs_lnum_t n_faces, const cs_lnum_t *location_elts, const cs_lnum_t *faces, cs_real_3_t *coord_shift, int coord_stride, double tolerance)
Locate shifted boundary face coordinates on possibly filtered cells or boundary faces for later inter...
Definition: cs_boundary_conditions.cpp:1923
@ CS_MESH_LOCATION_CELLS
Definition: cs_mesh_location.h:63
In general, when defining a pseudo-periodic boundary condition, it is assumed that the mesh is not moving, so the mapping may be defined once and for all. Hence the test on nt_cur
and nt_prev
and the save attribute for the inlet_1 pointer.
Applying the map
At all time steps after the first (possibly even the first if the flow at the mapping locations is initialized to nonzero values), the values at points mapped to inlet face centers are applied to the field->bc_coeffs->rcodcl1 values of the corresponding faces, using the cs_boundary_conditions_mapped_set function. Optionally, a normalization by be applied, ensuring the mean values initially defined are preserved. Normalization is recommended for the velocity, and possibly scalars, but not for turbulent quantities, which should adapt to the velocity.
if (nt_cur == 1) {
const int interpolate = 0;
for (int f_id = 0; f_id < n_fields; f_id++) {
continue;
normalize = 1;
inlet_l,
normalize,
interpolate,
zn->n_elts,
zn->elt_ids,
nullptr);
}
}
void cs_boundary_conditions_mapped_set(const cs_field_t *f, ple_locator_t *locator, cs_mesh_location_type_t location_type, int normalize, int interpolate, cs_lnum_t n_faces, const cs_lnum_t *faces, cs_real_t *balance_w)
Set mapped boundary conditions for a given field and mapping locator.
Definition: cs_boundary_conditions.cpp:2075
#define CS_FIELD_VARIABLE
Definition: cs_field.h:63
int type
Definition: cs_field.h:136
Finalization
At the end of the computation, it is good practice to free the mapping structure:
if (nt_cur == nt_max)
ple_locator_t * ple_locator_destroy(ple_locator_t *this_locator)