My Project
programmer's documentation
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_(vel)->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 alined with an axis of the computation frame

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_elts; i++) {
cs_lnum_t c_id = zone->elt_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: head losses along a direction at 45 degrees

Necessary, we shall use here a 3x3 tensor to impose head losses at an angle $ alpha = 45^{o} $ with respect to x and y direction of the computation frame. Namely, resistance is set along components x by cku1 and y by cku2
.

Orthogonal reference frame sketch

In the present example, it is chosen to set a head loss representing friction along X and to model a vane in Y direction by setting ck1 = 0 .

{
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_elts; i++) {
cs_lnum_t c_id = zone->elt_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.;
}
}
}
cs_math_pi
const cs_real_t cs_math_pi
cs_math_3_norm
static cs_real_t cs_math_3_norm(const cs_real_t v[3])
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_math.h:372
CS_VOLUME_ZONE_HEAD_LOSS
#define CS_VOLUME_ZONE_HEAD_LOSS
Definition: cs_volume_zone.h:67
cs_real_3_t
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:315
atimbr::v
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_math_sq
static cs_real_t cs_math_sq(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:193
cs_volume_zone_define
int cs_volume_zone_define(const char *name, const char *criteria, int type_flag)
Define a new volume zone using a selection criteria string.
Definition: cs_volume_zone.c:573
CS_F_
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
vel
void const cs_int_t *const const cs_int_t *const const cs_int_t *const const cs_int_t *const const cs_int_t *const const cs_int_t *const const cs_int_t *const const cs_int_t *const const cs_real_t *const const cs_real_t *const const cs_real_t const cs_real_t const cs_real_3_t vel[]
Definition: cs_divergence.h:64
cpincl::alpha
double precision, dimension(ncharm), save alpha
Definition: cpincl.f90:99