8.0
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";
/* 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 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);
}
}
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
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:3523
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2316
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:3064
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.c:1527
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2570
cs_equation_param_t * cs_field_get_equation_param(cs_field_t *f)
Access a field's equation parameters.
Definition: cs_field_default.c:280
@ p
Definition: cs_field_pointer.h:67
@ vel
Definition: cs_field_pointer.h:68
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
static cs_real_t cs_math_sq(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:222
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.c:404
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.
Definition: cs_turbulence_inflow.c:173
double precision, dimension(nozppm), save dh
hydraulic diameter
Definition: ppincl.f90:811
#define CS_FIELD_VARIABLE
Definition: cs_field.h:63
int scalar_id
Definition: keywords.h:127
Field descriptor.
Definition: cs_field.h:130
int type
Definition: cs_field.h:135
double viscl0
Definition: cs_physical_constants.h:73
double ro0
Definition: cs_physical_constants.h:72

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];
}
(" Mass rate generated in the domain: %14.5e\n"
" ----------------------------------\n"),
flucel);
_logged_mass_flux = true;
}
}
}
}
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
#define CS_REAL_TYPE
Definition: cs_defs.h:453
#define CS_UNUSED(x)
Definition: cs_defs.h:495
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
bool cs_log_default_is_active(void)
Update "active" or "inactive" flag of default log.
Definition: cs_log.c:277
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_LOG_DEFAULT
Definition: cs_log.h:50
cs_mesh_quantities_t * cs_glob_mesh_quantities
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:160
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:680
double precision, dimension(:), pointer cell_f_vol
fluid volume of each cell
Definition: mesh.f90:156
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition: cs_equation_param.h:192
int verbosity
Definition: cs_equation_param.h:212
Definition: cs_mesh_quantities.h:92
cs_real_t * cell_f_vol
Definition: cs_mesh_quantities.h:98
Definition: cs_zone.h:55
int id
Definition: cs_zone.h:59
cs_real_t measure
Definition: cs_zone.h:74
const char * name
Definition: cs_zone.h:57

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)
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:3621

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);
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:3572

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.