Gradient Calculation: Halo (Ghost) cells

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
rbecker
Posts: 16
Joined: Thu Jun 28, 2012 4:35 pm

Gradient Calculation: Halo (Ghost) cells

Post by rbecker »

Hello,

I need to do some gradient caluculations in cs_user_postprocess.
Is it okay to fill the value array from which I calculate the gradient up to n_cells? Or do I have to take care on the ghost cells and should fill the array with n_cells_with_ghosts values?

A skeleton of my routine:

Code: Select all

cs_field_t *u     = cs_field_by_name("velocity");

cs_real_t  *values;
cs_real_3_t *grad;

BFT_MALLOC(values,  cs_glob_mesh->n_cells_with_ghosts, cs_real_t);
BFT_MALLOC(grad,   cs_glob_mesh->n_cells_with_ghosts, cs_real_3_t);

cs_lnum_t cellid;

for (cellid=0; cellid < n_cells; cellid++) {
                values[cellid] = u->val[3*cellid+0];
}

        cs_gradient_scalar("user",
                        CS_GRADIENT_ITER,       /* gradient type */
                        cs_glob_mesh->halo_type,  /* halo type **/
                        1,                      /* inc */
                        true,                   /* recompute cocg */
                        100,                    /* sweeps */
                        0,                      /* tr_dim */
                        0,                      /* hydrostatic pressure */
                        0,                      /* w_stride */
                        1,                      /* verbosity */
                        -1,                     /* clip mode */
                        1.0e-8,                 /* epsilon */
                        0.0,                    /* extrap */
                        1.5,                    /* clip coeff */
                        NULL,                   /* external force */
                        NULL,             /* bc_coeff_a */
                        NULL,             /* bc_coeff_b */
                        values,                  /* values */
                        NULL,                   /* weight coeff */
                        NULL,                   /* cpl */
                        grad);                  /* gradient */



thank you in advance,

Kind regards, Ralf
Yvan Fournier
Posts: 4208
Joined: Mon Feb 20, 2012 3:25 pm

Re: Gradient Calculation: Halo (Ghost) cells

Post by Yvan Fournier »

Hello Ralf,

No need to synchronize ghost cells,the gradient operator handles it for you. In v 6.0+, there is also a cs_gradient_scalar_synced_input variant available, which assumes the synchronization is done before (for use for better performance when the value is reused multiple times), but the default gradient functions play it safe by syncing the field.

For existing fields, you also have higher level "cs_field_gradient" functions which might be interesting, as they use the available boundary conditions. So for velocity, unless you really want a homogeneous Neumann condition, that might be better. If you are computing the gradient of a combined field (such as rho.u), then the "low-level" solution you are uing is the only option.

Best regards,

Yvan
Post Reply