My Project
programmer's documentation
Boundary forces

Boundary forces

This is an example of cs_user_extra_operations which computes boundary forces

Example 1: compute total forces on a boundary zone (subset of boundary faces).

{
const cs_lnum_t n_b_faces = domain->mesh->n_b_faces;
cs_field_t *b_forces = cs_field_by_name_try("boundary_forces");
if (b_forces != NULL) {
cs_real_3_t total_b_forces = {0., 0., 0.};
cs_lnum_t n_elts, *lst_elts;
BFT_MALLOC(lst_elts, n_b_faces, cs_lnum_t);
cs_selector_get_b_face_list("2 or 3", &n_elts, lst_elts);
for (cs_lnum_t i_elt = 0; i_elt < n_elts; i_elt++) {
cs_lnum_t face_id = lst_elts[i_elt];
for (int ii = 0; ii < 3; ii++)
total_b_forces[ii] += b_forces->val[3*face_id + ii];
}
BFT_FREE(lst_elts);
/* parallel sum */
cs_parall_sum(3, CS_DOUBLE, total_b_forces);
}
}

Example 2: compute pressure forces on a boundary zone (subset of boundary faces).

{
const cs_lnum_t n_b_faces = domain->mesh->n_b_faces;
const cs_real_t *b_f_face_normal =
domain->mesh_quantities->b_f_face_normal;
cs_real_3_t total_b_p_forces = {0., 0., 0.};
cs_lnum_t n_elts, *lst_elts;
BFT_MALLOC(lst_elts, n_b_faces, cs_lnum_t);
cs_selector_get_b_face_list("2 or 3", &n_elts, lst_elts);
/* compute static pressure on selected boundary faces */
cs_real_t *p_b_val;
BFT_MALLOC(p_b_val, n_elts, cs_real_t);
cs_post_b_pressure(n_elts, lst_elts, p_b_val);
for (cs_lnum_t i_elt = 0; i_elt < n_elts; i_elt++) {
cs_lnum_t face_id = lst_elts[i_elt];
for (int ii = 0; ii < 3; ii++)
total_b_p_forces[ii] += p_b_val[i_elt]*b_f_face_normal[3*face_id+ii];
}
BFT_FREE(lst_elts);
BFT_FREE(p_b_val);
/* parallel sum */
cs_parall_sum(3, CS_DOUBLE, total_b_p_forces);
}
cs_post_b_pressure
void cs_post_b_pressure(cs_lnum_t n_b_faces, const cs_lnum_t b_face_ids[], cs_real_t pres[])
Compute pressure on a specific boundary region.
Definition: cs_post_util.c:633
cs_real_3_t
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:315
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
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_parall_sum
static void cs_parall_sum(int n, cs_datatype_t datatype, void *val)
Sum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:147
CS_DOUBLE
Definition: cs_defs.h:265
cs_field_t::val
cs_real_t * val
Definition: cs_field.h:145
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_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_selector_get_b_face_list
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
cs_field_t
Field descriptor.
Definition: cs_field.h:124