My Project
programmer's 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.

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,

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.

cs_mesh_t::n_cells
cs_lnum_t n_cells
Definition: cs_mesh.h:73
cs_field_by_name_try
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:2357
cs_glob_mesh
cs_mesh_t * cs_glob_mesh
cs_mesh_t::n_cells_with_ghosts
cs_lnum_t n_cells_with_ghosts
Definition: cs_mesh.h:127
cs_field_t::val
cs_real_t * val
Definition: cs_field.h:145
inc
void const cs_int_t *const const cs_int_t *const inc
Definition: cs_convection_diffusion.h:5386
BFT_MALLOC
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
BFT_FREE
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
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
cs_real_33_t
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:321
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
cs_field_t
Field descriptor.
Definition: cs_field.h:124
cs_field_gradient_vector
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:713
gradv
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_real_t *const const cs_real_t *const const cs_real_3_t const cs_real_33_t cs_real_3_t cs_real_33_t gradv[]
Definition: cs_gradient.h:123