My Project
programmer's documentation
Setting porosity values: basic example

Local definitions and initialization

Mesh quantities

It may be useful to access some mesh adjacencies and quantities, in which case local pointers allow for more readable code:

const cs_lnum_2_t *i_face_cells
= (const cs_lnum_2_t *)m->i_face_cells;
const cs_real_3_t *restrict i_face_cog
const cs_real_3_t *restrict b_face_cog
const cs_real_3_t *restrict cell_cen
= (const cs_real_3_t *restrict)mq->cell_cen;
const cs_real_3_t *restrict i_face_normal
cs_real_3_t *restrict i_f_face_normal
const cs_real_3_t *restrict b_face_normal
cs_real_3_t *restrict b_f_face_normal
const cs_real_t *i_f_face_surf = mq->i_f_face_surf;
const cs_real_t *i_face_surf = mq->i_face_surf;

Associated properties

Accessing cell porosity property values is required so values may be set:

cs_real_t *cpro_porosi = cs_field_by_name("porosity")->val;

Example: define porosity by geometric zones

Individual cell porosity values can be assigned to each cell, so they may be based on groups, geometric criteria, or any other time-independent functions:

for (cs_lnum_t cell_id = 0; cell_id < m->n_cells; cell_id++) {
cs_real_t x = cell_cen[cell_id][0];
if (x < 20.)
cpro_porosi[cell_id] = 1.;
else
cpro_porosi[cell_id] = 0.5;
}
/* synchronize for use in fluid face factor calculation below */
halo_type);

Matching face equivalent surfaces should also be assigned in a corresponding manner, for interior faces:

for (cs_lnum_t face_id = 0; face_id < m->n_i_faces; face_id++) {
cs_real_t x = i_face_cog[face_id][0];
cs_real_t face_porosity = 1.;
if (x > 19.9999)
face_porosity = 0.5;
for (int i = 0; i < 3; i++)
i_f_face_normal[face_id][i] = face_porosity * i_face_normal[face_id][i];
mq->i_f_face_surf[face_id] = cs_math_3_norm(i_f_face_normal[face_id]);
}

and for boundary faces:

for (cs_lnum_t face_id = 0; face_id < m->n_b_faces; face_id++) {
cs_real_t x = b_face_cog[face_id][0];
cs_real_t face_porosity = 1.;
if (x > 19.9999)
face_porosity = 0.5;
for (int i = 0; i < 3; i++)
b_f_face_normal[face_id][i] = face_porosity * b_face_normal[face_id][i];
mq->b_f_face_surf[face_id] = cs_math_3_norm(b_f_face_normal[face_id]);
}
cs_mesh_t::n_cells
cs_lnum_t n_cells
Definition: cs_mesh.h:73
cs_mesh_quantities_t::b_f_face_normal
cs_real_t * b_f_face_normal
Definition: cs_mesh_quantities.h:102
cs_math_3_norm
static cs_real_t cs_math_3_norm(const cs_real_t v[3])
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_math.h:372
cs_field_synchronize
void cs_field_synchronize(cs_field_t *f, cs_halo_type_t halo_type)
Synchronize current parallel and periodic field values.
Definition: cs_field_operator.c:971
cs_glob_mesh_quantities
cs_mesh_quantities_t * cs_glob_mesh_quantities
restrict
#define restrict
Definition: cs_defs.h:127
cs_real_3_t
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:315
cs_mesh_quantities_t::b_face_normal
cs_real_t * b_face_normal
Definition: cs_mesh_quantities.h:98
cs_field_by_name
cs_field_t * cs_field_by_name(const char *name)
Return a pointer to a field based on its name.
Definition: cs_field.c:2331
cs_mesh_quantities_t::b_face_cog
cs_real_t * b_face_cog
Definition: cs_mesh_quantities.h:105
cs_mesh_quantities_t::b_f_face_surf
cs_real_t * b_f_face_surf
Definition: cs_mesh_quantities.h:111
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_mesh_t::i_face_cells
cs_lnum_2_t * i_face_cells
Definition: cs_mesh.h:87
cs_mesh_t::n_b_faces
cs_lnum_t n_b_faces
Definition: cs_mesh.h:75
cs_mesh_quantities_t
Definition: cs_mesh_quantities.h:90
cs_glob_mesh
cs_mesh_t * cs_glob_mesh
cs_mesh_quantities_t::i_face_cog
cs_real_t * i_face_cog
Definition: cs_mesh_quantities.h:104
cs_field_t::val
cs_real_t * val
Definition: cs_field.h:145
cs_mesh_quantities_t::i_face_surf
cs_real_t * i_face_surf
Definition: cs_mesh_quantities.h:107
cs_mesh_quantities_t::cell_cen
cs_real_t * cell_cen
Definition: cs_mesh_quantities.h:92
cs_mesh_quantities_t::i_f_face_surf
cs_real_t * i_f_face_surf
Definition: cs_mesh_quantities.h:110
CS_HALO_STANDARD
Definition: cs_halo.h:52
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_lnum_2_t
int cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:308
cs_halo_type_t
cs_halo_type_t
Definition: cs_halo.h:50
cs_mesh_quantities_t::i_face_normal
cs_real_t * i_face_normal
Definition: cs_mesh_quantities.h:96
cs_mesh_t
Definition: cs_mesh.h:63
cs_mesh_t::n_i_faces
cs_lnum_t n_i_faces
Definition: cs_mesh.h:74
cs_mesh_quantities_t::i_f_face_normal
cs_real_t * i_f_face_normal
Definition: cs_mesh_quantities.h:100