6.3
general documentation
Examples of data settings for volume mass injection

Injection of mass directly in the volume (based on mass source terms) can be defined for selected volume zones. Appropriate zones may be defined in the usual manner, using the GUI, or in the cs_user_zones user-defined function (see examples).

The equation for mass conservation becomes: $ \der{\rho}{t}+\divs{(\rho \vect{u})}=\Gamma $

The equation for a variable $ \varia $ becomes: $ \frac{\Delta(\rho\varia)}{\Delta t} = ... + \Gamma(\varia^{in} - \varia) $ discretized as $ \rho \dfrac{\varia^{(n+1)} - \varia^{(n)}}{\Delta t} = ... + \Gamma(\varia^{in} - \varia^{(n+1)}) $

$ \varia^{in} $ is the value of $ \varia $ associated to the injected mass.

Two options are available:

  • the mass flux is injected with the local value of variable $ \varia $: $ \varia^{in} = \varia^{(n+1)} $ (the equation for $ \varia $ is therefore not modified, and no value needs to be assigned)
  • the mass flux is injected with a specific value for $ \varia $: $ \varia^{in} $ is specified by the user

Variables to be specified by the user

Remarks
  • if no value is specified for a given variable, the local value is used in that zone.
  • if the specified mass source term value is < 0, mass is removed from the system, therefore code_saturne automatically considers $ \varia^{in}=\varia^{(n+1)}$ for variables other than pressure, whatever the values of itypsm or smacel specified by the user
  • if a scalar doesn't evolve following the standard equation $ \dfrac{\partial{(\rho \varia)}}{\partial{dt}} + \divs{(\rho \vect{u} \varia)} = ...$ (alternate convective field for instance), the source term set by this routine will not be correct (except in case of injection at the local value of the variable). The proper source term should be added directly in cs_user_source_terms.

Simulation of an inlet condition by mass source terms

When using constant values per zone, an inlet condition can easily be defined adding code similar to the following snipped in the cs_user_finalize_setup function (in cs_user_parameters.c):

cs_real_t wind = 0.1;
cs_real_t dh = 0.5;
const char z_name[] = "mass_injection";
cs_real_t ustar2 = 0, xkent = cs_math_epzero, xeent = cs_math_epzero;
/* Pressure */
double mass_in[1] = {30000};
(cs_field_get_equation_param(CS_F_(p)), z_name, mass_in);
/* Velocity */
double vel_in[3] = {0, wind, 0};
(cs_field_get_equation_param(CS_F_(vel)), z_name, vel_in);
/* Turbulence values */
(z_name,
cs_math_sq(wind),
dh,
/* Scalars */
int ks = cs_field_key_id("scalar_id");
int n_fields = cs_field_n_fields();
for (int f_id = 0; f_id < n_fields; f_id++) {
cs_field_get_key_int(f, cs_field_key_id("scalar_id")) : -1;
if (scalar_id >= 0) {
double val = 1;
(cs_field_get_equation_param(f), z_name, &val);
}
}

The value assigned to the pressure is the mass injection rate. For other variables, it is the injected value itself. Note that turbulence variable values based on a hydraulic diameter can and reference velocity easily be set using the function cs_turbulence_inflow_volume_mass_injection_ke_hyd_diam.

Advanced definitions

It is also possible to define more complex injection mass flows using an analytical function. This first requires defining a function matching the cs_analytic_func_t template, such as the one below:

static void
_define_injection(cs_real_t time,
cs_lnum_t n_elts,
const cs_lnum_t *elt_ids,
const cs_real_t *xyz,
bool dense_output,
void *input,
cs_real_t *res)
{
CS_UNUSED(time);
CS_UNUSED(xyz);
cs_field_t *f = input; /* Current field for which this injection is called */
const cs_zone_t *z = cs_volume_zone_by_name("mass_injection");
/* Injection mass flow rate */
cs_real_t xgamma = 30000;
if (z->measure <= 0)
bft_error(__FILE__, __LINE__, 0,
"In function %s: volume of zone %d (%s) is %g.",
__func__, z->id, z->name, z->measure);
/* Assume output directly to main arrays, so not handle dense case */
if (dense_output == false)
bft_error(__FILE__, __LINE__, 0,
"Function %s currently only handles dense output.",
__func__);
/* For pressure
------------ */
if (f == CS_F_(p)) {
for (cs_lnum_t i = 0; i < n_elts; i++) {
res[i] = xgamma;
}
/* Logging: compute/check the mass flow rate in the volume */
static bool _logged_mass_flux = false;
if (_logged_mass_flux == false && cs_log_default_is_active()) {
if (eqp->verbosity >= 1 || _logged_mass_flux == false) {
cs_real_t flucel = 0.;
for (cs_lnum_t i = 0; i < n_elts; i++) {
cs_lnum_t c_id = elt_ids[i];
flucel += cell_f_vol[c_id] * res[i];
}
cs_parall_sum(1, CS_REAL_TYPE, &flucel);
(" Mass rate generated in the domain: %14.5e\n"
" ----------------------------------\n"),
flucel);
_logged_mass_flux = true;
}
}
}
}

Note that this function injects mass uniformly, but also computes and logs the mass rate generated in the domain.

To use this function for a given volume injection, we define the injection as follows:

z_name,
_define_injection, // associated function
f); // input structure (use field to access info)

In this example, we have assigned the field pointer to the function input, so the function can query the field used for a given call, and could be adapted to handle different variables (which avoids requiring a different function for each variable).

Note that in an actual application, the mass balance can be checked using the balance_by_zone_compute or balance_by_zone_compute functions, so using a more complex injection function is useful only when trying to replicate the mass source terms user function behavior used in previous versions of code_saturne.

Simulation of suction by a pump

In the following example, we simulate the suction (by a pump for instance) with a total rate of 80 000 kg/s. The suction rate is supposed to be uniformly distributed on all the cells in the "suction_pump" zone.

double mass_out[1] = {-80000};
(cs_field_get_equation_param(CS_F_(p)), "suction_pump", mass_out);

As mass is removed, there is no need to define the values for variables other than pressure. Using cs_equation_add_volume_mass_injection_by_qov, ("quantity over a volume"), the prescribed value is automatically distributed over the associated zone.

vel
@ vel
Definition: cs_field_pointer.h:68
cs_turbulence_inflow_volume_mass_injection_ke_hyd_diam
void cs_turbulence_inflow_volume_mass_injection_ke_hyd_diam(const char *zone_name, double uref2, double dh, double rho, double mu)
Define mass injection for turbulent quantities based on a hydraulic diameter and reference velocity.
cs_zone_t
Definition: cs_zone.h:55
cs_glob_mesh_quantities
cs_mesh_quantities_t * cs_glob_mesh_quantities
mesh::cell_f_vol
double precision, dimension(:), pointer cell_f_vol
fluid volume of each cell
Definition: mesh.f90:156
cs_log_printf
int cs_log_printf(cs_log_t log, const char *format,...)
Print log info to a given log type.
Definition: cs_log.c:501
cs_glob_turb_model
const cs_turb_model_t * cs_glob_turb_model
cs_zone_t::measure
cs_real_t measure
Definition: cs_zone.h:74
cs_equation_param_t::verbosity
int verbosity
Definition: cs_equation_param.h:220
CS_REAL_TYPE
#define CS_REAL_TYPE
Definition: cs_defs.h:436
cs_turb_model_t::itytur
int itytur
Definition: cs_turbulence_model.h:138
CS_LOG_DEFAULT
@ CS_LOG_DEFAULT
Definition: cs_log.h:50
cs_volume_zone_by_name
const cs_zone_t * cs_volume_zone_by_name(const char *name)
Return a pointer to a volume zone based on its name if present.
Definition: cs_volume_zone.c:695
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:304
cs_field_t::type
int type
Definition: cs_field.h:130
cs_log_default_is_active
bool cs_log_default_is_active(void)
Update "active" or "inactive" flag of default log.
Definition: cs_log.c:277
cs_field_get_equation_param
cs_equation_param_t * cs_field_get_equation_param(cs_field_t *f)
Access a field's equation parameters for read only.
Definition: cs_field_default.c:233
cs_mesh_quantities_t
Definition: cs_mesh_quantities.h:89
cs_glob_fluid_properties
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.c:385
bft_error
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.c:193
cs_mesh_quantities_t::cell_f_vol
cs_real_t * cell_f_vol
Definition: cs_mesh_quantities.h:93
ppincl::dh
double precision, dimension(nozppm), save dh
hydraulic diameter
Definition: ppincl.f90:758
cs_equation_add_volume_mass_injection_by_analytic
cs_xdef_t * cs_equation_add_volume_mass_injection_by_analytic(cs_equation_param_t *eqp, const char *z_name, cs_analytic_func_t *func, void *input)
Add a new volume mass injection definition source term by initializing a cs_xdef_t structure,...
Definition: cs_equation_param.c:3964
cs_equation_param_t
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition: cs_equation_param.h:201
cs_field_get_key_struct_const_ptr
const void * cs_field_get_key_struct_const_ptr(const cs_field_t *f, int key_id)
Return a read-only pointer to a simple structure for a given key to a field.
Definition: cs_field.c:3565
cs_turb_model_t::iturb
int iturb
Definition: cs_turbulence_model.h:116
cs_math_epzero
const cs_real_t cs_math_epzero
cs_field_get_key_int
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:2991
cs_zone_t::name
const char * name
Definition: cs_zone.h:57
CS_F_
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
cs_fluid_properties_t::viscl0
double viscl0
Definition: cs_physical_constants.h:73
scalar_id
int scalar_id
Definition: keywords.h:127
optcal::itytur
integer(c_int), pointer, save itytur
Class of turbulence model (integer value iturb/10)
Definition: optcal.f90:524
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_field_by_id
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2314
cs_zone_t::id
int id
Definition: cs_zone.h:59
CS_UNUSED
#define CS_UNUSED(x)
Definition: cs_defs.h:478
cs_equation_add_volume_mass_injection_by_qov
cs_xdef_t * cs_equation_add_volume_mass_injection_by_qov(cs_equation_param_t *eqp, const char *z_name, double *quantity)
Add a new volume mass injection definition source term by initializing a cs_xdef_t structure,...
Definition: cs_equation_param.c:3916
cs_fluid_properties_t::ro0
double ro0
Definition: cs_physical_constants.h:72
cs_field_key_id
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2497
cs_turb_model_type_t
cs_turb_model_type_t
Definition: cs_turbulence_model.h:52
optcal::iturb
integer(c_int), pointer, save iturb
turbulence model
Definition: optcal.f90:521
CS_FIELD_VARIABLE
#define CS_FIELD_VARIABLE
Definition: cs_field.h:63
cs_field_t
Field descriptor.
Definition: cs_field.h:125
cs_field_n_fields
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.c:1528
cs_equation_add_volume_mass_injection_by_value
cs_xdef_t * cs_equation_add_volume_mass_injection_by_value(cs_equation_param_t *eqp, const char *z_name, double *val)
Add a new volume mass injection definition source term by initializing a cs_xdef_t structure,...
Definition: cs_equation_param.c:3868
p
@ p
Definition: cs_field_pointer.h:67