7.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;

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

BFT_MALLOC(gradv, n_cells_ext, cs_real_33_t);

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);

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");

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];
}
}

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

BFT_FREE(gradv);