9.0
general documentation
Loading...
Searching...
No Matches
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).

{
cs_field_t *b_forces = cs_field_by_name_try("boundary_stress");
if (b_forces != nullptr) {
cs_real_3_t total_b_forces = {0., 0., 0.};
const cs_real_t *b_face_surf = domain->mesh_quantities->b_face_surf;
const cs_real_3_t *bpro_forces = (cs_real_3_t *)b_forces->val;
/* get zone from its name, here "selected_wall" */
const cs_zone_t *zn = cs_boundary_zone_by_name("selected_wall");
for (cs_lnum_t e_id = 0; e_id < zn->n_elts; e_id++) {
cs_lnum_t face_id = zn->elt_ids[e_id];
for (cs_lnum_t i = 0; i < 3; i++)
total_b_forces[i] += bpro_forces[face_id][i] * b_face_surf[face_id];
}
/* parallel sum */
cs_parall_sum(3, CS_REAL_TYPE, total_b_forces);
}
}

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

{
const cs_real_3_t *b_f_face_normal
cs_real_3_t total_b_p_forces = {0., 0., 0.};
/* get zone from its name, here "selected_wall" */
const cs_zone_t *zn = cs_boundary_zone_by_name("selected_wall");
/* compute static pressure on selected boundary faces */
cs_real_t *p_b_val;
CS_MALLOC(p_b_val, zn->n_elts, cs_real_t);
cs_post_b_pressure(zn->n_elts, zn->elt_ids, p_b_val);
for (cs_lnum_t e_id = 0; e_id < zn->n_elts; e_id++) {
cs_lnum_t face_id = zn->elt_ids[e_id];
for (cs_lnum_t i = 0; i < 3; i++)
total_b_p_forces[i] += p_b_val[e_id]*b_f_face_normal[face_id][i];
}
CS_FREE(p_b_val);
/* parallel sum */
cs_parall_sum(3, CS_REAL_TYPE, total_b_p_forces);
}