8.0
general documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data setting for drift scalars for coal combustion

Introduction

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

Physical properties

Initialization and finalization

The following initialization block needs to be added for the following examples:

const cs_lnum_t n_cells = domain->mesh->n_cells;
const cs_lnum_t n_cells_ext = domain->mesh->n_cells_with_ghosts;
/* Number of fields */
const int n_fields = cs_field_n_fields();
/* Key id for drift scalar */
const int keydri = cs_field_key_id("drift_scalar_model");
/* Key id of the coal scalar class */
const int keyccl = cs_field_key_id("scalar_class");
cs_real_t *cpro_ym1_3 = cs_field_by_id(iym1[2])->val;
cs_real_t *cpro_ym1_5 = cs_field_by_id(iym1[4])->val;
cs_real_t *cpro_ym1_7 = cs_field_by_id(iym1[6])->val;
cs_real_t *cpro_ym1_8 = cs_field_by_id(iym1[7])->val;
cs_real_t *cpro_ym1_9 = cs_field_by_id(iym1[8])->val;
cs_real_t *cpro_ym1_11 = cs_field_by_id(iym1[10])->val;
cs_real_t *cpro_ym1_12 = cs_field_by_id(iym1[11])->val;
cs_real_t *visco;
BFT_MALLOC(visco, n_cells_ext, cs_real_t);
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
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
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_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_lagr_coal_comb_t * cs_glob_lagr_coal_comb
integer, dimension(ngazem), save iym1
mass fractions:
Definition: ppincl.f90:498
cs_real_t * val
Definition: cs_field.h:151
int * iym1
Definition: cs_lagr.h:1019

Body

Here is the corresponding code:

/* Temperature */
const cs_real_t *cpro_temp = CS_F_(t)->val;
/* Gas density */
cs_real_t *cpro_rom1 = cs_field_by_name("rho_gas")->val;
/* First initialization */
const int n_class = cs_glob_combustion_model->coal.nclacp;
cs_array_real_set_scalar(n_cells, viscl0, visco);
cs_array_real_set_scalar(n_cells, ro0, cpro_rom1);
for (int icla = 0; icla < n_class; icla++) {
char rho_name[64], diam_name[64];
snprintf(rho_name, 63, "rho_p_%02d", icla+1);
snprintf(diam_name, 63, "diam_p_%02d", icla+1);
cs_real_t *cpro_rom2 = cs_field_by_name(rho_name)->val;
cs_real_t *cpro_diam2 = cs_field_by_name(diam_name)->val;
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cpro_rom2[c_id] = rho20[icla];
cpro_diam2[c_id] = diam20[icla];
}
}
}
/*--- Gas viscosity function of temperature ---*/
/*---1-O2 2-CO 3-H2 4-N2 5-SO2 6-NH3 7-CO2-----*/
const cs_real_t aa1 = 4.0495e-6, bb1 = 6.2200e-8;
const cs_real_t cc1 = -2.3032e-11, dd1 = 4.4077e-15;
const cs_real_t aa2 = 9.9987e-6, bb2 = 5.1578e-8;
const cs_real_t cc2 = -1.8383e-11, dd2 = 3.33307e-15;
const cs_real_t aa3 = 2.8940e-6, bb3 = 2.22508e-8;
const cs_real_t cc3 = -8.041e-12, dd3 = 1.4619e-15;
const cs_real_t aa4 = 4.3093e-6, bb4 = 5.0516e-8;
const cs_real_t cc4 = -1.7869e-11, dd4 = 3.2136e-15;
const cs_real_t aa5 = -1.9889e-6, bb5 = 5.365e-8;
const cs_real_t cc5 = -1.4286e-11, dd5 = 2.1639e-15;
const cs_real_t aa6 = -1.293e-6, bb6 = 4.1194e-8;
const cs_real_t cc6 = -1.7720e-11, dd6 = 1.8699e-15;
const cs_real_t aa7 = 4.4822e-7, bb7 = 5.4327e-8;
const cs_real_t cc7 = -1.7581e-11, dd7 = 2.9979e-15;
/*--------------------------------------------------------------------
* law mu = a + b T + c T**2 + d T**3
* so cpro_viscl(iel) = a +b*xvart+c*xvart**2 + d*xvart**3
*--------------------------------------------------------------------*/
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
const cs_real_t xvart = cpro_temp[c_id];
const cs_real_t xvart2 = cs_math_pow2(cpro_temp[c_id]);
const cs_real_t xvart3 = cs_math_pow3(cpro_temp[c_id]);
const cs_real_t visco_O2 = aa1 + xvart*bb1 + cc1*xvart2 + dd1*xvart3;
const cs_real_t visco_CO = aa2 + xvart*bb2 + cc2*xvart2 + dd2*xvart3;
const cs_real_t visco_H2 = aa3 + xvart*bb3 + cc3*xvart2 + dd3*xvart3;
const cs_real_t visco_N2 = aa4 + xvart*bb4 + cc4*xvart2 + dd4*xvart3;
const cs_real_t visco_SO2 = aa5 + xvart*bb5 + cc5*xvart2 + dd5*xvart3;
const cs_real_t visco_NH3 = aa6 + xvart*bb6 + cc6*xvart2 + dd6*xvart3;
const cs_real_t visco_CO2 = aa7 + xvart*bb7 + cc7*xvart2 + dd7*xvart3;
/* Viscosity of the mixing */
visco[c_id] = ( cpro_ym1_8[c_id] * visco_O2
+ cpro_ym1_3[c_id] * visco_CO
+ cpro_ym1_5[c_id] * visco_H2
+ cpro_ym1_12[c_id]* visco_N2
+ cpro_ym1_11[c_id]* visco_SO2
+ cpro_ym1_7[c_id] * visco_NH3
+ cpro_ym1_9[c_id] * visco_CO2)
/ ( cpro_ym1_8[c_id] + cpro_ym1_3[c_id]
+ cpro_ym1_5[c_id] + cpro_ym1_12[c_id]
+ cpro_ym1_11[c_id] + cpro_ym1_7[c_id]
+ cpro_ym1_9[c_id]);
}
}
/* get x1 = 1 - sum cpro_x2 */
cs_real_t *cpro_x1 = cs_field_by_name("x_c")->val;
/* All gas scalars have the same drift as if1m(1)
*-----------------------------------------------*/
/* Loop on fields */
for (int f_id = 0; f_id < n_fields; f_id++) {
const cs_field_t *fld = cs_field_by_id(f_id);
/* Index of the scalar class (<0 if the scalar belongs to the gas phase) */
int icla = cs_field_get_key_int(fld, keyccl);
int iscdri = cs_field_get_key_int(fld, keydri);
/* We only handle here one scalar with a drift per gas class */
if ((icla < 0) && (iscdri & CS_DRIFT_SCALAR_ADD_DRIFT_FLUX)) {
/* Name of the drift scalar */
cs_real_t *cpro_taupg
= cs_field_by_composite_name("drift_tau", fld->name)->val;
/* Initialize to 0 */
cs_array_real_fill_zero(n_cells, cpro_taupg);
}
}
/* Loop over coal particle classes
* We only handle here coal class with a drift
* ------------------------------------------- */
for (int f_id = 0; f_id < n_fields; f_id++) {
const cs_field_t *fld = cs_field_by_id(f_id);
/* Index of the scalar class (<0 if the scalar belongs to the gas phase) */
int icla = cs_field_get_key_int(fld, keyccl);
int iscdri = cs_field_get_key_int(fld, keydri);
/* We only handle here one scalar with a drift per particle class */
if ((icla > -1) && (iscdri & CS_DRIFT_SCALAR_ADD_DRIFT_FLUX)) {
char rho_name[64], diam_name[64], x2_name[64];
snprintf(rho_name, 63, "rho_p_%02d", icla+1);
snprintf(diam_name, 63, "diam_p_%02d", icla+1);
snprintf(x2_name, 63, "x_p_%02d", icla+1);
cs_real_t *cpro_x2 = cs_field_by_name(x2_name)->val;
cs_real_t *cpro_rom2 = cs_field_by_name(rho_name)->val;
cs_real_t *cpro_diam2 = cs_field_by_name(diam_name)->val;
/* Name of the drift scalar */
cs_real_t *cpro_taup
= cs_field_by_composite_name("drift_tau", fld->name)->val;
/* Computation of the relaxation time of the particles
* the drift is therefore v_g = tau_p * g
* --------------------------------------------------- */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
/* Simple model for Low Reynolds Numbers */
cpro_taup[c_id] = cpro_x1[c_id] * cpro_rom2[c_id]
* cs_math_pow2(cpro_diam2[c_id])
/ (18.0*visco[c_id]);
}
/* Drift for the gas:
* tau_pg = - Sum_i X2_i v_gi */
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++)
cpro_taup[c_id] += -(cpro_taup[c_id]*cpro_x2[c_id]);
}
}
/* Free memory */
BFT_FREE(visco);
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
void cs_array_real_fill_zero(cs_lnum_t size, cs_real_t a[])
Assign zero to all elements of an array.
Definition: cs_array.c:848
void cs_array_real_set_scalar(cs_lnum_t n_elts, cs_real_t ref_val, cs_real_t a[restrict])
Assign a constant scalar value to an array.
Definition: cs_array.c:550
cs_combustion_model_t * cs_glob_combustion_model
Definition: cs_combustion_model.c:117
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
cs_field_t * cs_field_by_composite_name(const char *name_prefix, const char *name_suffix)
Return a pointer to a field based on a composite name.
Definition: cs_field.c:2390
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
#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_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:238
static cs_real_t cs_math_pow3(cs_real_t x)
Compute the cube of a real value.
Definition: cs_math.h:254
@ CS_DRIFT_SCALAR_ADD_DRIFT_FLUX
Definition: cs_parameters.h:117
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.c:404
const cs_time_step_t * cs_glob_time_step
real(c_double), pointer, save viscl0
reference molecular dynamic viscosity.
Definition: cstphy.f90:157
real(c_double), pointer, save ro0
reference density.
Definition: cstphy.f90:150
real(c_double), dimension(:), pointer, save diam20
Definition: cpincl.f90:196
real(c_double), dimension(:), pointer, save rho20
Definition: cpincl.f90:196
double rho20[CS_COMBUSTION_MAX_COAL_CLASSES]
Definition: cs_combustion_model.h:131
int nclacp
Definition: cs_combustion_model.h:113
double diam20[CS_COMBUSTION_MAX_COAL_CLASSES]
Definition: cs_combustion_model.h:125
cs_combustion_coal_model_t coal
Definition: cs_combustion_model.h:162
Field descriptor.
Definition: cs_field.h:130
const char * name
Definition: cs_field.h:132
double viscl0
Definition: cs_physical_constants.h:73
double ro0
Definition: cs_physical_constants.h:72
int nt_cur
Definition: cs_time_step.h:74