8.0
general documentation
Compute vorticity field values

Compute vorticity field values

This is an example of cs_user_extra_operations which computes the vorticity field values over the whole domain.

First number of cells in the current sub-domain (or the whole domain for a sequential calculation) is retrieved. The number of cells with ghosts (i.e. including halo cells) is retrieved first, then the number of standard cells. The array that will host the velocity gradient values is finally declared, as a 3x3 real matrix array per cell.

const cs_lnum_t n_cells = cs_glob_mesh->n_cells;
cs_real_33_t *gradv;
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:341
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
cs_mesh_t * cs_glob_mesh
cs_lnum_t n_cells_with_ghosts
Definition: cs_mesh.h:151
cs_lnum_t n_cells
Definition: cs_mesh.h:97

The array hosting the gradient values has to be allocated consistantly with his type.

BFT_MALLOC(gradv, n_cells_ext, cs_real_33_t);
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62

Then the gradient of the velocity is computed. This is done as follows, by calling the appropriate field operator:

bool use_previous_t = false;
int inc = 1;
use_previous_t,
inc,
gradv);
void cs_field_gradient_vector(const cs_field_t *f, bool use_previous_t, int inc, cs_real_33_t *restrict grad)
Compute cell gradient of vector field.
Definition: cs_field_operator.c:736
@ vel
Definition: cs_field_pointer.h:68
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51

The vorticity field has to be retrieved as follows below. Note that if it doesn't exist the pointer will be set to NULL (this is the behavior of the "_try" variant of the field accesser). The vorticity field can have been added through the GUI (menu postprocessing > additional user arrays) or in cs_user_model.

cs_field_t *vort = cs_field_by_name_try("vorticity");
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.c:2366
Field descriptor.
Definition: cs_field.h:130

Finally the vorticity values are computed in each standard cell if the field "vorticity" has been well retrieved previously only. Notice the way the gradient values are accessed.

if (vort != NULL) {
for (cs_lnum_t i = 0; i < n_cells; i++) {
vort->val[i] = gradv[i][1][0] - gradv[i][0][1];
}
}
cs_real_t * val
Definition: cs_field.h:151

The array holding the gradient values has to be deallocated at the end.

BFT_FREE(gradv);
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101