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: 
The equation for a variable
becomes:
discretized as 
is the value of
associated to the injected mass.
Two options are available:
- the mass flux is injected with the local value of variable
:
(the equation for
is therefore not modified, and no value needs to be assigned)
- the mass flux is injected with a specific value for
:
is specified by the user
Variables to be specified by the user
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):
const char z_name[] = "mass_injection";
double mass_in[1] = {30000};
double vel_in[3] = {0, wind, 0};
(z_name,
for (int f_id = 0; f_id < n_fields; f_id++) {
double val = 1;
}
}
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
bool dense_output,
void *input,
{
"In function %s: volume of zone %d (%s) is %g.",
if (dense_output == false)
"Function %s currently only handles dense output.",
__func__);
res[i] = xgamma;
}
static bool _logged_mass_flux = false;
if (eqp->
verbosity >= 1 || _logged_mass_flux ==
false) {
}
(" 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
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,
f);
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_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.