8.0
general documentation
Data setting for drift scalars

Introduction

This page provides an example of code blocks that may be used to perform a calculation with drift scalars.

Physical properties

Local variables to be added

The following local variables and associated initializations need to be defined for the examples in this section:

const cs_lnum_t n_cells = domain->mesh->n_cells;
cs_real_t *cpro_viscl = CS_F_(mu)->val;
/* Key id for drift scalar */
const int keydri = cs_field_key_id("drift_scalar_model");
/* Key id for diffusivity id */
const int kivisl = cs_field_key_id("diffusivity_id");
/* Number of fields */
const int nfld = cs_field_n_fields();
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
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
@ mu
Definition: cs_field_pointer.h:103
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
integer, save kivisl
variable diffusivity field id key for scalars
Definition: numvar.f90:193

Body

This example sets the scalar laminar diffusivity (for Brownian motion) to take thermophoresis into account.

Here is the corresponding code:

/* Loop over fields which are scalar with a drift */
for (int iflid = 0; iflid < nfld; iflid++) {
if (! (f->type & CS_FIELD_VARIABLE))
continue;
int drift_flag = cs_field_get_key_int(f, keydri);
if (drift_flag & CS_DRIFT_SCALAR_ADD_DRIFT_FLUX) {
/* Position of variables, coefficients
* ----------------------------------- */
cs_real_t *cpro_taup = NULL, *cpro_taufpt = NULL, *cpro_viscls = NULL;
/* Scalar's diffusivity (Brownian motion) */
int ifcvsl = cs_field_get_key_int(f, kivisl);
if (ifcvsl > -1)
cpro_viscls = cs_field_by_id(ifcvsl)->val;
/* Coefficients of drift scalar CHOSEN BY THE USER
Values given here are fictitious */
const cs_real_t diamp = 1.e-4; /* particle diameter */
const cs_real_t cuning = 1.; /* Cuningham correction factor */
const cs_real_t rhop = 1.e4; /* particle density */
/* Get corresponding relaxation time (cpro_taup) */
char df_name[128]; df_name[127] = '\0';
snprintf(df_name, 127, "drift_tau_%s", f->name);
cpro_taup = cs_field_by_name(df_name)->val;
/* Corresponding interaction time particle--eddies */
if (drift_flag & CS_DRIFT_SCALAR_TURBOPHORESIS) {
snprintf(df_name, 127, "drift_turb_tau_%s", f->name);
cpro_taufpt = cs_field_by_name(df_name)->val;
}
/* Computation of the relaxation time of the particles
* --------------------------------------------------- */
const cs_real_t diamp2 = cs_math_pow2(diamp);
if (diamp <= 1.e-6) {
/* Cuningham's correction for submicronic particules */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_taup[c_id] = cuning*diamp2*rhop / (18.*cpro_viscl[c_id]);
}
}
else {
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_taup[c_id] = diamp2*rhop / (18.*cpro_viscl[c_id]);
}
}
/* Compute the interaction time particle--eddies (tau_fpt)
* ------------------------------------------------------- */
if (drift_flag & CS_DRIFT_SCALAR_TURBOPHORESIS) {
const int ksigmas = cs_field_key_id("turbulent_schmidt");
/* k-epsilon or v2-f models */
if (t_mdl->itytur == 2 || t_mdl->itytur == 5) {
const cs_real_t *cvar_k = CS_F_(k)->val;
const cs_real_t *cvar_eps = CS_F_(eps)->val;
const cs_real_t turb_schmidt = cs_field_get_key_double(f, ksigmas);
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cs_real_t xk = cvar_k[c_id];
cs_real_t xeps = cvar_eps[c_id];
cpro_taufpt[c_id] = (3./2.)*(cs_turb_cmu/turb_schmidt)*xk/xeps;
}
}
/* Rij-epsilon models */
else if (t_mdl->itytur == 3) {
const cs_real_6_t *cvar_rij = (const cs_real_6_t *)(CS_F_(rij)->val);
const cs_real_t *cvar_eps = CS_F_(eps)->val;
cs_real_t beta1 = 0.5 + 3.0/(4.*cs_turb_xkappa);
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cs_real_t xk = 0.5 * ( cvar_rij[c_id][0]
+ cvar_rij[c_id][1]
+ cvar_rij[c_id][2]);
cs_real_t xeps = cvar_eps[c_id];
cpro_taufpt[c_id] = xk/xeps/beta1;
}
}
/* k-omega models */
if (t_mdl->itytur == 6) {
const cs_real_t *cvar_omg = CS_F_(omg)->val;
const cs_real_t turb_schmidt = cs_field_get_key_double(f, ksigmas);
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cs_real_t xomg = cvar_omg[c_id];
cpro_taufpt[c_id] = (3./2.)*(1./turb_schmidt)/xomg;
}
}
}
/* Brownian diffusion at cell centers
* ---------------------------------- */
/* Stop if the diffusivity is not variable */
if (ifcvsl < 0)
bft_error(__FILE__, __LINE__, 0,
"The diffusivity is uniform while a variable diffusivity\n"
"is computed.");
/* Temperature and density */
if (CS_F_(t) == NULL)
bft_error(__FILE__, __LINE__, 0,
"The temperature field on which physical properties depend\n"
"does not seem to be present.");
const cs_real_t *cvar_t = CS_F_(t)->val;
const cs_real_t *cpro_rom = CS_F_(rho)->val;
/* Homogeneous to a dynamic viscosity */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cs_real_t xvart = cvar_t[c_id];
cs_real_t rho = cpro_rom[c_id];
cs_real_t viscl = cpro_viscl[c_id];
cpro_viscls[c_id] = rho*cs_physical_constants_kb*xvart
* cuning/(3.*cs_math_pi*diamp*viscl);
}
} /* End of test on drift */
} /* End of loop on fields */
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_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:334
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
double cs_field_get_key_double(const cs_field_t *f, int key_id)
Return a floating point value for a given key associated with a field.
Definition: cs_field.c:3244
cs_field_t * cs_field_by_name(const char *name)
Return a pointer to a field based on its name.
Definition: cs_field.c:2340
@ t
Definition: cs_field_pointer.h:92
@ k
Definition: cs_field_pointer.h:70
@ eps
Definition: cs_field_pointer.h:71
@ omg
Definition: cs_field_pointer.h:80
@ rho
Definition: cs_field_pointer.h:97
@ rij
Definition: cs_field_pointer.h:73
static cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:238
const cs_real_t cs_math_pi
@ CS_DRIFT_SCALAR_ADD_DRIFT_FLUX
Definition: cs_parameters.h:117
@ CS_DRIFT_SCALAR_TURBOPHORESIS
Definition: cs_parameters.h:119
const double cs_physical_constants_kb
Definition: cs_physical_constants.c:384
double cs_turb_cmu
Definition: cs_turbulence_model.c:496
double cs_turb_xkappa
Definition: cs_turbulence_model.c:437
const cs_turb_model_t * cs_glob_turb_model
#define CS_FIELD_VARIABLE
Definition: cs_field.h:63
integer, save ksigmas
turbulent schmidt key for scalars
Definition: numvar.f90:208
Field descriptor.
Definition: cs_field.h:130
int type
Definition: cs_field.h:135
const char * name
Definition: cs_field.h:132
cs_real_t * val
Definition: cs_field.h:151
Turbulence model general options descriptor.
Definition: cs_turbulence_model.h:115
int itytur
Definition: cs_turbulence_model.h:139