Scalar balance by zone
This is an example of cs_user_extra_operations which performs scalar balances on specified zones.
body
The algorithm implemented in the subroutine balance_by_zone adds up contributions of fluxes on the boundary of the sub-domain defined by the user. The different contributions are classified according to their nature (inlet, outlet, wall, symmetry...) if they are boundary faces of the whole domain or according to the sign of the mass flux if they are boundary faces of the sub-domain but internal faces of the whole domain.
To ensure calculations have physical meaning, it is best to use a spatially uniform time step (idtvar = 0 or 1).
The balance at time step n over a subdomain
of boundary
is equal to:
The first term is negative if the amount of scalar in the volume has increased (it is 0 in a steady regime).
The terms of convection and diffusion (at internal or boundary faces) are positive if the amount of scalar in the volume has increased.
In a steady regime, a positive balance thus indicates a scalar gain.
Example 1
This example computes energy balance relative to temperature. We assume that we want to compute balances (convective and diffusive) at the boundaries of the calculation domain.
The scalar considered is the temperature, nevertheless it is multiplied by the specific heat at each cell so that the computed balance is on energy, hence in Joules.
Here is the corresponding code:
void cs_balance_by_zone(const char *selection_crit, const char *scalar_name)
Compute and log the different terms of the balance of a given scalar, on a volumic zone defined by se...
Definition: cs_balance_by_zone.c:1689
Example 2
This example computes the balance relative to a scalar named "scalar1". We assume that we want to compute balances (convective and diffusive) on a box defined by two diagonally opposite points (the extrema in terms of coordinates).
The box criterion can be used as follows: box[
,
,
,
,
,
].
Here is the corresponding code:
Scalar balance through a surface
This example computes the balance relative to a scalar named "scalar1". Here is the corresponding code:
void cs_surface_balance(const char *selection_crit, const char *scalar_name, const cs_real_t normal[3])
Compute the surface balance of a given scalar.
Definition: cs_balance_by_zone.c:2404
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
Specific terms of a scalar balance
Instead of simply logging the various balance terms, it is possible to access them using the lower level functions, and the cs_balance_term_t components of the computed balance.
The following exemple shows how to access for example the mass flow components of the scalar balance:
const char criteria[] = "zone_group";
&n_selected_cells,
selected_cells);
n_selected_cells,
selected_cells,
balance);
"outlet mass flow (scalar 1): %g\n",
balance[mass_in_idx],
balance[mass_out_idx]);
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140
void cs_balance_by_zone_compute(const char *scalar_name, cs_lnum_t n_cells_sel, const cs_lnum_t cell_sel_ids[], cs_real_t balance[CS_BALANCE_N_TERMS])
Compute the different terms of the balance of a given scalar, on a volume zone defined by selected ce...
Definition: cs_balance_by_zone.c:765
cs_balance_term_t
Definition: cs_balance_by_zone.h:49
@ CS_BALANCE_MASS_OUT
Definition: cs_balance_by_zone.h:57
@ CS_BALANCE_MASS_IN
Definition: cs_balance_by_zone.h:56
@ CS_BALANCE_N_TERMS
Definition: cs_balance_by_zone.h:76
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
void cs_selector_get_cell_list(const char *criteria, cs_lnum_t *n_cells, cs_lnum_t cell_list[])
Fill a list of cells verifying a given selection criteria.
Definition: cs_selector.c:369
Head loss balance by zone
This example computes the head balance for a volume zone. Here is the corresponding code:
void cs_pressure_drop_by_zone(const char *selection_crit)
Computes one term of the head loss balance (pressure drop) on a volumic zone defined by the criterion...
Definition: cs_balance_by_zone.c:2314
Specific terms of a head balance
Instead of simply logging the various balance terms, it is possible to access them using the lower level functions, and the cs_balance_p_term_t components of the computed balance.
The following exemple shows how to access for example the mass flow components of the pressure drop computation:
{
const char criteria[] = "zone_group";
&n_selected_cells,
selected_cells);
selected_cells,
balance);
"outlet mass flow (rho.u): %g\n",
balance[rhou_in_idx],
balance[rhou_out_idx]);
}
void cs_pressure_drop_by_zone_compute(cs_lnum_t n_cells_sel, const cs_lnum_t cell_sel_ids[], cs_real_t balance[CS_BALANCE_P_N_TERMS])
Computes one term of the head loss balance (pressure drop) on a on a volume zone defined by selected ...
Definition: cs_balance_by_zone.c:1767
cs_balance_p_term_t
Definition: cs_balance_by_zone.h:83
@ CS_BALANCE_P_RHOU_IN
Definition: cs_balance_by_zone.h:93
@ CS_BALANCE_P_N_TERMS
Definition: cs_balance_by_zone.h:98
@ CS_BALANCE_P_RHOU_OUT
Definition: cs_balance_by_zone.h:94