This is an example of cs_user_extra_operations function which computes a local Nusselt number.
Local variables
Faces can be selected either using a selector (as is done here) or directly using boundary zone element ids if an appropriate zone has been defined.
const cs_lnum_t n_cells = domain->mesh->n_cells;
const cs_lnum_t n_b_faces = domain->mesh->n_b_faces;
const cs_lnum_t *b_face_cells = domain->mesh->b_face_cells;
= (
const cs_real_3_t *)domain->mesh_quantities->cell_cen;
= (
const cs_real_3_t *)domain->mesh_quantities->b_face_cog;
FILE *file = NULL;
const cs_real_t prandtl = 0.71, height = 1., qwall = 1.;
("normal[0, -1, 0, 0.1] and box[-1000, -1000, -1000, 1000, 0.01, 1000]",
&nlelt, lstelt);
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:334
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
@ t
Definition: cs_field_pointer.h:92
@ mu
Definition: cs_field_pointer.h:103
@ vel
Definition: cs_field_pointer.h:68
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.c:424
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
double precision, dimension(:), pointer volume
volume of each cell
Definition: mesh.f90:108
double precision, dimension(:,:), pointer cdgfbo
coordinates of the centers of the boundary faces
Definition: mesh.f90:104
Field descriptor.
Definition: cs_field.h:131
Fluid properties descriptor.
Definition: cs_physical_constants.h:61
Reconstruct value at selected boundary faces
Allocate a local array for the selected boundary faces.
General case (for non-orthogonal meshes)
if (iortho == 0) {
}
void cs_post_field_cell_to_b_face_values(const cs_field_t *f, cs_lnum_t n_loc_b_faces, const cs_lnum_t b_face_ids[], cs_real_t *b_val)
Compute values at a selection of boundary faces of a given field located on cells.
Definition: cs_post_util.c:874
Case of orthogonal meshes
Compute boundary value without reconstruction
for (
cs_lnum_t ielt = 0; ielt < nlelt; ielt++) {
treloc[ielt] = coefap[face_id] + coefbp[face_id] * f->
val[c_id];
}
cs_real_t * val
Definition: cs_field.h:152
- Note
- Here, we assign the non-reconstructed value.
Open file to print values and broadcast values to all parallel ranks. Values are ordered by the xabs
array values provided to the cs_parall_allgather_ordered_r, so this function is needed even when not running in parallel.
file = fopen("Nusselt.dat", "w");
}
cs_real_t *xabs = NULL, *xabsg = NULL, *xnusselt = NULL;
for (
cs_lnum_t ilelt = 0; ilelt < nlelt; ilelt ++) {
xabs[ilelt] =
cdgfbo[face_id][0];
}
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
int cs_glob_rank_id
Definition: cs_defs.c:174
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:298
void cs_parall_allgather_ordered_r(int n_elts, int n_g_elts, int stride, cs_real_t o_key[], cs_real_t array[], cs_real_t g_array[])
Build an ordered global array from each local array in each domain.
Definition: cs_parall.c:972
static void cs_parall_counter(cs_gnum_t cpt[], const int n)
Sum values of a counter on all default communicator processes.
Definition: cs_parall.h:87
Compute the bulk temperature, finalize the Nusselt number, print it and free memory not already freed before:
for (
cs_gnum_t ilelt = 0; ilelt < neltg; ilelt ++) {
int npoint = 200;
int irang1 = -1;
int irangv;
for (int ii = 0; ii < npoint; ii++) {
0.};
cell_cen,
xyz,
&c_id, &irangv);
if (c_id != c_id_prev || irangv != irang1) {
c_id_prev = c_id;
irang1 = irangv;
xtbulk += xtb;
xubulk += xub;
}
}
}
xtbulk = xbulk[0] / xbulk[1];
xubulk = xbulk[1];
xnusselt[ilelt] = qwall * 2. * height /
lambda / (tfac - xtbulk);
}
fprintf(file,
"%17.9e %17.9e\n",
xabsg[ii]*10.,
xnusselt[ii]/(0.023*pow(30000., 0.8)*pow(0.71, 0.4)));
if (file != NULL)
fclose(file);
#define CS_REAL_TYPE
Definition: cs_defs.h:458
@ lambda
Definition: cs_field_pointer.h:106
void cs_geom_closest_point(cs_lnum_t n_points, const cs_real_t point_coords[][3], const cs_real_t query_coords[3], cs_lnum_t *point_id, int *rank_id)
find the closest point of a set to a given point in space.
Definition: cs_geom.c:162
static void cs_parall_bcast(int root_rank, int n, cs_datatype_t datatype, void *val)
Broadcast values of a given datatype to all default communicator processes.
Definition: cs_parall.h:267
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:154
double cp0
Definition: cs_physical_constants.h:81