8.3
general documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Basic example

Basic example

Local variables to be added

Initialization

One can get any field using cs_field_by_name function (use cs_field_by_name_try if one is not sure the field exists). "scalar1" is the name related to the first user-defined scalar variable. f->val[cell_id] is the value of this variable in cell number cell_id.

ONLY done if there is no restart computation.

const cs_lnum_t n_cells = domain->mesh->n_cells;
/* If this is restarted computation, do not reinitialize values */
if (domain->time_step->nt_prev > 0)
return;
/* Initialize "scalar1" field to 25 only if it exists */
cs_field_t *fld = cs_field_by_name_try("scalar1");
if (fld != nullptr) {
for (cs_lnum_t cell_id = 0; cell_id < n_cells; cell_id++)
fld->val[cell_id] = 25;
}
/* In the case of the EBU pre-mixed flame module the user can initialise (by example 25):
* the mixing rate
* the fresh gas mass fraction
* the mixture enthalpy */
cs_real_t *cvar_fm = CS_F_(fm)->val;
cs_real_t *cvar_ygfm = CS_F_(ygfm)->val;
for (cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
cvar_fm[c_id] = 25;
cvar_ygfm[c_id] = 25;
cvar_scalt[c_id] = 25;
}
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
cs_field_t * cs_field_by_name_try(const char *name)
Return a pointer to a field based on its name if present.
Definition: cs_field.cpp:2515
@ ygfm
Definition: cs_field_pointer.h:134
@ fm
Definition: cs_field_pointer.h:129
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
cs_field_t * cs_thermal_model_field(void)
Definition: cs_thermal_model.cpp:216
Field descriptor.
Definition: cs_field.h:131
cs_real_t * val
Definition: cs_field.h:152