Introduction
This page provides examples of code snippets that may be used to define physical variable laws.
- Warning
It is forbidden to modify turbulent viscosity visct
here (a specific subroutine is dedicated to that: usvist)
- cs_glob_fluid_properties->icp = 1 must have been specified in cs_user_parameters if we wish to define a variable specific heat cpro_cp (otherwise: memory overwrite).
- the field's diffusivity_id integer key must have been specified in cs_user_parameters if we wish to define a variable viscosity
viscls
.
- Warning
- : if the scalar is the temperature, its associated diffusivity actually corresponds to its conductivity (Lambda) in W/(m K)
The types of boundary faces at the previous time step are available (except at the first time step, where arrays itypfb
and itrifb
have not been initialized yet)
It is recommended to keep only the minimum necessary in this file (i.e. remove all unused example code)
Accessing physical properties
Base physical properties (rho, viscl, cp, ...) may be accessed as in the following snippet (see Variables and structures reference (C and Fortran) for additional information).
cs_user_physical_properties and are not to be modified here.
Molecular viscosity varying with temperature
The values of the molecular viscosity are provided as a function of the temperature. All variables are evaluated at the cell centers.
Here is the corresponding code:
for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_viscl[c_id] = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm;
}
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
Molecular volumetric viscosity varying with temperature
The values of the molecular volumetric viscosity are provided as a function of the temperature. All variables are evaluated at the cell centers.
Here is the corresponding code:
if (cpro_viscv == NULL)
"%s: cpro_viscv not available.", __func__);
for (
cs_lnum_t c_id =0; c_id < n_cells; c_id++) {
cpro_viscv[c_id] = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm;
}
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
Isobaric specific heat varying with temperature
The values of the isobaric specific heat values are provided as a function of the temperature. All variables are evaluated at the cell centers.
Here is the corresponding code:
if ((cpro_cp == NULL) || (cpro_cv == NULL))
"%s: cpro_cp or cpro_cv not available.", __func__);
for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_cp[c_id] = varac*xvart + varbc;
}
void cs_cf_thermo_cv(cs_real_t *cp, cs_real_t *xmasml, cs_real_t *cv, cs_lnum_t l_size)
Compute the isochoric specific heat:
Definition: cs_cf_thermo.c:845
Molecular thermal conductivity varying with temperature
The values of the molecular thermal conductivity are provided as a function of the temperature. All variables are evaluated at the cell centers.
Here is the corresponding code:
if (cpro_vtmpk == NULL)
"%s: cpro_vtmpk not available.", __func__);
for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_vtmpk[c_id] = (xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl);
}
Molecular diffusivity of user-defined scalars varying with temperature
The molecular diffusivity can be set for all the user-defined scalars except:
- temperature and enthalpy (already dealt with above: for these variables, the 'diffusivity' is the thermal conductivity)
- variances of the fluctuations of another scalar variable (the diffusivity is assumed to be equal to that of the associated scalar) The values of the molecular diffusivity are provided as a function of the temperature. All variables are evaluated at the cell centers.
Here is the corresponding code:
for (int f_id = 0; f_id < n_fields; f_id++) {
continue;
int sc_id = -1;
if (sc_id < 0)
continue;
continue;
for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_vscal[c_id] = (xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl);
}
}
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2320
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:3068
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.c:1502
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2574
@ t_kelvin
Definition: cs_field_pointer.h:115
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
#define CS_FIELD_VARIABLE
Definition: cs_field.h:63
int diffusivity_id
Definition: keywords.h:167
integer, save kivisl
variable diffusivity field id key for scalars
Definition: numvar.f90:190
Field descriptor.
Definition: cs_field.h:131
int type
Definition: cs_field.h:136
cs_real_t * val
Definition: cs_field.h:152