9.2
general 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).

{
cs_field_t *b_forces = cs_field_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 auto bpro_forces = b_forces->get_val_v();
/* 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);
}
}
Field descriptor.
Definition: cs_field.h:275
cs_span_2d< cs_real_t > get_val_v(const int time_id=0) const
Return a 2D span view of field values. If the field is not a vector a fatal error is provoked.
Definition: cs_field.cpp:5103
const cs_zone_t * cs_boundary_zone_by_name(const char *name)
Return a pointer to a boundary zone based on its name if present.
Definition: cs_boundary_zone.cpp:708
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
#define CS_REAL_TYPE
Definition: cs_defs.h:476
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_field_t * cs_field_try(int id)
Return a pointer to a field based on its id. If no field of the given name is defined,...
Definition: cs_field.cpp:4371
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:139
Definition: cs_zone.h:51
const cs_lnum_t * elt_ids
Definition: cs_zone.h:61
cs_lnum_t n_elts
Definition: cs_zone.h:60

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

{
const cs_real_t *b_face_surf = domain->mesh_quantities->b_face_surf;
const cs_nreal_3_t *b_face_u_normal
= domain->mesh_quantities->b_face_u_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_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_face_u_normal[face_id][i]
* b_face_surf[face_id];
}
/* parallel sum */
cs_parall_sum(3, CS_REAL_TYPE, total_b_p_forces);
}
Define a templated array class (owner of data)
Definition: cs_array.h:1118
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:375
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.cpp:578