programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Basic examples

Initialization and finalization

It is useful to map a field array to a local pointer for a clear and concise access, such as done here fro the velocity:

const cs_real_3_t *cvara_vel = (const cs_real_3_t *)(CS_F_(u)->val_pre);

Otherwise, the zone entries (see cs_volume_zone_t) should contain the necessary information with no additional preparation.

Body

Defining a volume zone

A volume zone may be defined using the GUI, or in the cs_user_zones user function (in cs_user_zones.c), such as the following zone determined by a geometric criterion:

{
cs_volume_zone_define("head_loss_1",
"box[4.0, 6.0, -1e6, 2.0, 8.0, 1e6]",
}

Note that if the CS_VOLUME_ZONE_HEAD_LOSS flag is not set (or the matching type set through the GUI), calls to cs_user_head_losses will ignore this zone.

Head loss examples

Note that in the following examples, we checku the zone name, so we know which zone we are dealing with using in case of multiple zones.

head loss tensor coefficients for each cell are organized as follows: cku11, cku22, cku33, cku12, cku13, cku23.

Coefficients are set to zero (then computed based on definitions provided through the GUI if this is the case) before calling this function, so setting values to zero is usually not necessary, unless we want to fully overwrite a GUI-based definition.

Note that diagonal coefficients must be positive; the calculation may crash if this is not the case.

Example 1: head losses in direction \c x

Using the previously defined zone, we define head losses in direction x

{
if (strcmp(zone->name, "head_loss_1") == 0) {
for (cs_lnum_t i = 0; i < zone->n_cells; i++) {
cs_lnum_t c_id = zone->cell_ids[i];
cs_real_t v = cs_math_3_norm(cvara_vel[c_id]);
cku[i][0] = 10.0 * v;
cku[i][1] = 0.0;
cku[i][2] = 0.0;
}
}
}

Example 2: alpha = 45 degres

3x3 tensor: Example of head losses at alpha = 45 degres x,y direction x resists by cku1 and y by cku2
cku2 = 0 represents vanes as follows: in coordinate system x, y

orthogonal_reference_frame_sketch.gif
Orthogonal reference frame sketch
{
if (strcmp(zone->name, "head_loss_1") == 0) {
/* define rotation matrix outside of loop on cells */
cs_real_t cosa = cos(alpha);
cs_real_t sina = sin(alpha);
cs_real_t ck0 = 10.0;
cs_real_t ck1 = 0.0;
cs_real_t a11 = cs_math_sq(cosa)*ck0 + cs_math_sq(sina)*ck1;
cs_real_t a22 = cs_math_sq(sina)*ck0 + cs_math_sq(cosa)*ck1;
cs_real_t a12 = cosa * sina * (ck0 - ck1);
/* compute local coefficients */
for (cs_lnum_t i = 0; i < zone->n_cells; i++) {
cs_lnum_t c_id = zone->cell_ids[i];
cs_real_t v = cs_math_3_norm(cvara_vel[c_id]);
cku[i][0] = a11 * v;
cku[i][1] = a22 * v;
cku[i][2] = 0.;
cku[i][3] = a12 * v;
cku[i][4] = 0.;
cku[i][5] = 0.;
}
}
}