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.cpp).
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:
auto vel_val_ext =
CS_F_(
vel)->bc_coeffs->get_val_ext_v();
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.cpp:1505
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.cpp:2728
@ vel
Definition: cs_field_pointer.h:66
@ rho_b
Definition: cs_field_pointer.h:97
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:47
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.cpp:462
double viscl0
Definition: cs_physical_constants.h:75
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
on the faces with the selection criterion '2 and x < 0.01' and set a Dirichlet to all the scalars
.
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).
vel_val_ext(face_id, 0) = 0;
vel_val_ext(face_id, 1) = 0;
vel_val_ext(face_id, 2) = 0;
uref2,
xdh,
b_rho,
viscl0);
}
for (int f_id = 0; f_id < n_fields; f_id++) {
val_ext[face_id] = 1.0;
}
}
}
cs_span< cs_real_t > get_val_ext() const
Return a 1D span view of boundary condition external values.
Definition: cs_field.cpp:5826
Field descriptor.
Definition: cs_field.h:275
int get_key_int(int key_id) const
Return a integer value for a given key associated with a field.
Definition: cs_field.cpp:4507
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
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
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:902
cs_real_t cs_notebook_parameter_value_by_name(const char *name)
Return a parameter value (real).
Definition: cs_notebook.cpp:408
@ 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.cpp:745
CS_F_HOST_DEVICE T max(const T a, const T b)
Definition: cs_defs.h:735
const cs_lnum_t * elt_ids
Definition: cs_zone.h:61
cs_lnum_t n_elts
Definition: cs_zone.h:60
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
on the faces with the selection criterion '3' and set a Dirichlet to all the scalars
.
Turbulence example computed using turbulence intensity data.
We will be careful to specify a hydraulic diameter adapted to the current inlet.
Calculation of
and
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)
vel_val_ext(face_id, 0) = 0;
vel_val_ext(face_id, 1) = 1.1;
vel_val_ext(face_id, 2) = 0;
}
for (int f_id = 0; f_id < n_fields; f_id++) {
val_ext[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.cpp:773
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)
}
@ 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
}
if (th_f != nullptr) {
th_val_ext[face_id] = 20.;
th_val_ext[face_id] = 50.;
th_h_ext[face_id] = 8.;
th_q_ext[face_id] = 4.;
}
}
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_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_BC_NEUMANN
Definition: cs_param_types.h:511
@ CS_BC_DIRICHLET
Definition: cs_param_types.h:506
@ CS_BC_WALL_MODELLED
Definition: cs_param_types.h:516
@ CS_SMOOTHWALL
Definition: cs_parameters.h:87
cs_field_t * cs_thermal_model_field(void)
Definition: cs_thermal_model.cpp:180
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
if (bpro_roughness.
size() != 0)
bpro_roughness[face_id] = 0.01;
if (bpro_roughness_t.
size() != 0)
bpro_roughness_t[face_id] = 0.01;
vel_val_ext(face_id, 0) = 1.;
}
Define a templated mdspan class (non owner of data)
Definition: cs_mdspan.h:68
CS_F_HOST_DEVICE cs_lnum_t size() const
Getter for total size.
Definition: cs_mdspan.h:508
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
@ CS_ROUGHWALL
Definition: cs_parameters.h:88
Symmetry example
Assign a symmetry condition to boundary faces of zone '4'
}
@ CS_SYMMETRY
Definition: cs_parameters.h:85