8.0
general documentation
Volume and boundary zone definitions (cs_user_zones.c)

Volume and boundary zones may be defined using the GUI, or through the cs_user_zones (in cs_user_zones.c).

Simple volume zone example

Most zones may be defined in a simple manner using the general selection criteria, such as in the following example:

{
cs_volume_zone_define("head_loss_1",
"box[4.0, 6.0, -1e6, 2.0, 8.0, 1e6]",
}
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:577
#define CS_VOLUME_ZONE_HEAD_LOSS
Definition: cs_volume_zone.h:67

Or you can define 3 spherical source term zones based on geometrical criteria described by a rule.

{
char name[128], criteria[128];
for (int i = 0; i < 3; i++) {
double s_coords[] = {0, 0, 2.0*i};
snprintf(name, 127, "source_%d", i);
snprintf(criteria, 127, "sphere[%f, %f, %f, 0.5]",
s_coords[0], s_coords[1], s_coords[2]);
}
}
#define CS_VOLUME_ZONE_SOURCE_TERM
Definition: cs_volume_zone.h:70

Advanced volume zone examples

More complex selections can be done by defining an appropriate selection function. For example, to select cells adjacent to boundary faces belonging to a group named "G3", the following selection function must first be defined:

static void
_g3_boundary_cells(void *input,
const cs_mesh_t *m,
int location_id,
cs_lnum_t *n_elts,
cs_lnum_t **elt_ids)
{
CS_UNUSED(input);
CS_UNUSED(location_id);
/* Allocate selection list */
cs_lnum_t n_b_faces = 0;
cs_lnum_t *b_face_ids = NULL;
BFT_MALLOC(b_face_ids, m->n_b_faces, cs_lnum_t);
cs_selector_get_b_face_list("G3", &n_b_faces, b_face_ids);
char *cell_flag;
BFT_MALLOC(cell_flag, m->n_cells, char);
for (cs_lnum_t i = 0; i < m->n_cells; i++)
cell_flag[i] = 0;
/* Now that flag is built, test for adjacency */
for (cs_lnum_t i= 0; i < n_b_faces; i++) {
cs_lnum_t face_id = b_face_ids[i];
cs_lnum_t c_id = m->b_face_cells[face_id];
cell_flag[c_id] = 1;
}
/* Now build list from flag */
cs_lnum_t _n_elts = 0;
for (cs_lnum_t i = 0; i < m->n_cells; i++) {
if (cell_flag[i] != 0)
_n_elts++;
}
cs_lnum_t *_elt_ids;
BFT_MALLOC(_elt_ids, _n_elts, cs_lnum_t);
_n_elts = 0;
for (cs_lnum_t i = 0; i < m->n_cells; i++) {
if (cell_flag[i] != 0) {
_elt_ids[_n_elts] = i;
_n_elts++;
}
}
/* Free memory */
BFT_FREE(b_face_ids);
BFT_FREE(cell_flag);
/* Set return values */
*n_elts = _n_elts;
*elt_ids = _elt_ids;
}
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
#define CS_UNUSED(x)
Definition: cs_defs.h:495
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
void cs_selector_get_b_face_list(const char *criteria, cs_lnum_t *n_b_faces, cs_lnum_t b_face_list[])
Fill a list of boundary faces verifying a given selection criteria.
Definition: cs_selector.c:213
Definition: cs_mesh.h:85
cs_lnum_t * b_face_cells
Definition: cs_mesh.h:112
cs_lnum_t n_b_faces
Definition: cs_mesh.h:99
cs_lnum_t n_cells
Definition: cs_mesh.h:97

It can then simply be used in a zone definition:

{
char name[128], criteria[128];
for (int i = 0; i < 3; i++) {
double s_coords[] = {0, 0, 2.0*i};
snprintf(name, 127, "source_%d", i);
snprintf(criteria, 127, "sphere[%f, %f, %f, 0.5]",
s_coords[0], s_coords[1], s_coords[2]);
cs_volume_zone_define_by_func("G3_B", _g3_boundary_cells, NULL, 0);
}
}
int cs_volume_zone_define_by_func(const char *name, cs_mesh_location_select_t *func, void *input, int type_flag)
Define a new mesh location with an associated selection function.
Definition: cs_volume_zone.c:621
Remarks
If defined as "static", as in this example, an with no function prototype, the selection function must be defined in the same file (i.e. cs_user_zones.c), and appear before the definition of cs_user_zones. If a appropriate selection function is available in another source file, it must have non-static linkage an a function prototype must be provided (usually through an associated .h file).

Advanced boundary zone examples

You can define simple boundary zones, allowing all faces not in the "INLET" or "OUTLET" groups to be considered as walls

{
int z_id = cs_boundary_zone_define("wall", "all[]", 0);
cs_boundary_zone_define("inlet", "INLET", 0);
cs_boundary_zone_define("outlet", "OUTLET", 0);
}
int cs_boundary_zone_define(const char *name, const char *criteria, int type_flag)
Define a new boundary zone using a selection criteria string.
Definition: cs_boundary_zone.c:608
void cs_boundary_zone_set_overlay(int id, bool allow_overlay)
Set overlay behavior for a given boundary zone.
Definition: cs_boundary_zone.c:826

Or simply allow overlapping for an existing zone:

{
int z_id = cs_boundary_zone_by_name("wall")->id;
}
const cs_zone_t * cs_boundary_zone_by_name(const char *name)
Return a pointer to a boundary zone based on its name if present.
Definition: cs_boundary_zone.c:711
int id
Definition: cs_zone.h:59