8.3
general documentation
Define user laws for physical properties with compressible module

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 dynamic viscosity viscls.
Remarks
  • This function is called at the beginning of each time step Thus, AT THE FIRST TIME STEP (non-restart case), the only values initialized before this call are those defined
  • We may define here variation laws for cell properties, for:
    • density: kg/m3
    • density at boundary faces: kg/m3)
    • molecular viscosity: kg/(m s)
    • specific heat: J/(kg degrees)
    • conductivities associated with temperatures: W/(m K)
    • dynamic diffusivities associated with other scalars: kg/(m s)
Warning
: if the scalar is the temperature, its associated dynamic 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) 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:

/* Molecular dynamic viscosity 'cpro_viscl' */
/* User-defined coefficients for the selected law.
* The values hereafter are provided as a mere example. They
* are physically meaningless. */
cs_real_t varam = -3.4016e-9;
cs_real_t varbm = 6.2332e-7;
cs_real_t varcm = -4.5577e-5;
cs_real_t vardm = 1.6935e-3;
/* Molecular dynamic viscosity mu at the cell centers, kg/(m s)
* In this example, mu is provided as a function of the temperature T:
* mu(T) = T *( T *( am * T + bm )+ cm )+ dm
* that is:
* cpro_viscl(iel) = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
const cs_real_t xvart = cvar_t[c_id];
cpro_viscl[c_id] = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm;
}
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335

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:

/* Stop if the volumetric viscosity has not been defined as variable */
if (cpro_viscv == nullptr)
bft_error(__FILE__, __LINE__, 0,
"%s: cpro_viscv not available.", __func__);
/* User-defined coefficients for the selected law.
* The values provided hereafter are provided as a mere example.
* They are physically meaningless. */
const cs_real_t varam = -3.4016e-9;
const cs_real_t varbm = 6.2332e-7;
const cs_real_t varcm = -4.5577e-5;
const cs_real_t vardm = 1.6935e-3;
/* Molecular dynamic volumetric viscosity kappa at the cell centers, kg/(m s)
* In this example, kappa is provided as a function of the temperature T:
* kappa(T) = T *( T *( am * T + bm )+ cm )+ dm
* that is:
* cpro_viscv(iel) = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm */
for (cs_lnum_t c_id =0; c_id < n_cells; c_id++) {
const cs_real_t xvart = cvar_t[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.cpp: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:

/* Stop if the isobaric or isochoric specific heat (cpro_cp or cpro_cv)
* has not been defined as variable */
if ((cpro_cp == nullptr) || (cpro_cv == nullptr))
bft_error(__FILE__, __LINE__, 0,
"%s: cpro_cp or cpro_cv not available.", __func__);
/* User-defined coefficients for the selected law.
* The values provided hereafter are provided as a mere example.
* They are physically meaningless.*/
const cs_real_t varac = 0.00001;
const cs_real_t varbc = 1000.0;
/* Isobaric specific heat cpro_cp at the cell centers, J/(kg degree)
* In this example, cpro_cp is provided as a function of the temperature T:
* cpro_cp(T) = ac * T + ab
* that is:
* cpro_cp(iel) = varac*xvart+varbc */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
const cs_real_t xvart = cvar_t[c_id];
cpro_cp[c_id] = varac*xvart + varbc;
}
/* The isochoric specific heat is deduced from the isobaric specific heat */
cs_cf_thermo_cv(cpro_cp, mix_mol_mas, cpro_cv, n_cells);
void cs_cf_thermo_cv(cs_real_t *cp, cs_real_t *xmasml, cs_real_t *cv, cs_lnum_t n_elts)
Compute the isochoric specific heat:
Definition: cs_cf_thermo.cpp:846

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:

/* Stop if the molecular thermal conductivity has not
* been defined as variable */
if (cpro_vtmpk == nullptr)
bft_error(__FILE__, __LINE__, 0,
"%s: cpro_vtmpk not available.", __func__);
/* User-defined coefficients for the selected law.
* The values provided hereafter are provided as a mere example.
* They are physically meaningless. */
cs_real_t varal = -3.3283e-7;
cs_real_t varbl = 3.6021e-5;
cs_real_t varcl = 1.2527e-4;
cs_real_t vardl = 0.589230;
/* Molecular thermal conductivity lambda at the cell centers, W/(m degree)
* In this example, lambda is provided as a function of the temperature T:
* lambda(T) = T *( T *( al * T + bl )+ cl )+ dl
* that is:
* cpro_vtmpk(iel) = xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
const cs_real_t xvart = cvar_t[c_id];
cpro_vtmpk[c_id] = (xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl);
}

Molecular dynamic diffusivity of user-defined scalars varying with temperature

The molecular dynamic 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 dynamic diffusivity are provided as a function of the temperature. All variables are evaluated at the cell centers.

Here is the corresponding code:

const int n_fields = cs_field_n_fields();
const int keysca = cs_field_key_id("scalar_id");
const int kscavr = cs_field_key_id("first_moment_id");
/* Loop on the scalars fields */
for (int f_id = 0; f_id < n_fields; f_id++) {
cs_field_t *fld = cs_field_by_id(f_id);
/* If the scalar is the temperature, it will be skipped. */
if (fld == CS_F_(t_kelvin))
continue;
/* Here we only handle user or model scalar-type variables
which are not fluctuations */
int sc_id = -1;
if (fld->type & CS_FIELD_VARIABLE)
sc_id = cs_field_get_key_int(fld, keysca) - 1;
if (sc_id < 0)
continue;
int variance_id = cs_field_get_key_int(fld, kscavr);
if (variance_id > -1 || diffusivity_id < 0)
continue;
/* User-defined coefficients for the selected law.
* The values provided hereafter are provided as a mere example.
* They are physically meaningless. */
const cs_real_t varal = -3.3283e-7;
const cs_real_t varbl = 3.6021e-5;
const cs_real_t varcl = 1.2527e-4;
const cs_real_t vardl = 0.5892300;
/* Molecular diffusivity lambda at the cell centers, kg/(m s)
* In this example, lambda is provided as a function of the temperature T:
* lambda(T) = T *( T *( al * T + bl )+ cl )+ dl
* that is:
* cpro_vscal(iel) = xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
const cs_real_t xvart = cvar_t[c_id];
cpro_vscal[c_id] = (xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl);
}
} /* End of the loop on the scalars */
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.cpp:3275
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.cpp:1593
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.cpp:2465
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.cpp:2781
@ t_kelvin
Definition: cs_field_pointer.h:117
#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:168
integer, save kivisl
variable diffusivity field id key for scalars
Definition: numvar.f90:183
Field descriptor.
Definition: cs_field.h:131
int type
Definition: cs_field.h:136
cs_real_t * val
Definition: cs_field.h:152